1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/widget/xremoteclient/mozilla-xremote-client.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,99 @@ 1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 1.5 +/* vim:expandtab:shiftwidth=4:tabstop=4: 1.6 + */ 1.7 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.8 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.9 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.10 + 1.11 +#include <stdio.h> 1.12 +#include <stdlib.h> 1.13 +#include <string.h> 1.14 +#include <plgetopt.h> 1.15 +#include "XRemoteClient.h" 1.16 + 1.17 +static void print_usage(void); 1.18 + 1.19 +int main(int argc, char **argv) 1.20 +{ 1.21 + nsresult rv; 1.22 + XRemoteClient client; 1.23 + char *browser = 0; 1.24 + char *profile = 0; 1.25 + char *username = 0; 1.26 + char *command = 0; 1.27 + 1.28 + if (argc < 2) { 1.29 + print_usage(); 1.30 + return 4; 1.31 + } 1.32 + 1.33 + PLOptStatus os; 1.34 + PLOptState *opt = PL_CreateOptState(argc, argv, "ha:u:p:"); 1.35 + while (PL_OPT_EOL != (os = PL_GetNextOpt(opt))) { 1.36 + if (PL_OPT_BAD == os) { 1.37 + print_usage(); 1.38 + return 4; 1.39 + } 1.40 + 1.41 + switch (opt->option) { 1.42 + case 'h': 1.43 + print_usage(); 1.44 + return 4; 1.45 + break; 1.46 + case 'u': 1.47 + username = strdup(opt->value); 1.48 + break; 1.49 + case 'a': 1.50 + browser = strdup(opt->value); 1.51 + break; 1.52 + case 'p': 1.53 + profile = strdup(opt->value); 1.54 + break; 1.55 + case 0: 1.56 + command = strdup(opt->value); 1.57 + default: 1.58 + break; 1.59 + } 1.60 + } 1.61 + 1.62 + rv = client.Init(); 1.63 + // failed to connect to the X server 1.64 + if (NS_FAILED(rv)) 1.65 + return 1; 1.66 + 1.67 + // send the command - it doesn't get any easier than this 1.68 + bool success = false; 1.69 + char *error = 0; 1.70 + rv = client.SendCommand(browser, username, profile, command, nullptr, 1.71 + &error, &success); 1.72 + 1.73 + // failed to send command 1.74 + if (NS_FAILED(rv)) { 1.75 + fprintf(stderr, "%s: Error: Failed to send command: ", argv[0]); 1.76 + if (error) { 1.77 + fprintf(stderr, "%s\n", error); 1.78 + free(error); 1.79 + } 1.80 + else { 1.81 + fprintf(stderr, "No error string reported..\n"); 1.82 + } 1.83 + 1.84 + return 3; 1.85 + } 1.86 + 1.87 + // no running window found 1.88 + if (!success) { 1.89 + fprintf(stderr, "%s: Error: Failed to find a running server.\n", argv[0]); 1.90 + return 2; 1.91 + } 1.92 + 1.93 + // else, everything is fine. 1.94 + return 0; 1.95 +} 1.96 + 1.97 +/* static */ 1.98 +void print_usage(void) { 1.99 + fprintf(stderr, "Usage: mozilla-xremote-client [-a firefox|thunderbird|mozilla|any]\n"); 1.100 + fprintf(stderr, " [-u <username>]\n"); 1.101 + fprintf(stderr, " [-p <profile>] COMMAND\n"); 1.102 +}