aboutsummaryrefslogtreecommitdiffstats
path: root/lib-src
diff options
context:
space:
mode:
authorRichard M. Stallman1996-09-01 18:25:21 +0000
committerRichard M. Stallman1996-09-01 18:25:21 +0000
commit8f9aaa0a8170e82146984ad6aa68443ce355b7c0 (patch)
tree79efa666adde1585291af754856955c6427cd717 /lib-src
parent424aad230d50f72c862c2433285bf6fe31ababc7 (diff)
downloademacs-8f9aaa0a8170e82146984ad6aa68443ce355b7c0.tar.gz
emacs-8f9aaa0a8170e82146984ad6aa68443ce355b7c0.zip
(decode_options): New function.
(main, both versions): Call decode_options. (print_help_and_exit): New function. (VERSION): New macro
Diffstat (limited to 'lib-src')
-rw-r--r--lib-src/emacsclient.c114
1 files changed, 98 insertions, 16 deletions
diff --git a/lib-src/emacsclient.c b/lib-src/emacsclient.c
index c2940294ff9..20ba5217a5f 100644
--- a/lib-src/emacsclient.c
+++ b/lib-src/emacsclient.c
@@ -27,9 +27,86 @@ Boston, MA 02111-1307, USA. */
27#undef close 27#undef close
28#undef signal 28#undef signal
29 29
30#include <stdio.h>
31#include <getopt.h>
32
33char *getenv (), *getwd ();
34char *getcwd ();
35int geteuid ();
36
37/* This is defined with -D from the compilation command,
38 which extracts it from ../lisp/version.el. */
39
40#ifndef VERSION
41#define VERSION "unspecified"
42#endif
43
44/* Name used to invoke this program. */
45char *progname;
46
47/* Nonzero means don't wait for a response from Emacs. --nowait. */
48int nowait = 0;
49
50struct option longopts[] =
51{
52 { "nowait", no_argument, NULL, 'n' },
53 { "help", no_argument, NULL, 'H' },
54 { "version", no_argument, NULL, 'V' },
55 { 0 }
56};
57
58/* Decode the options from argv and argc.
59 Return the number of remaining arguments. */
60
61int
62decode_options (argc, argv)
63 int argc;
64 char **argv;
65{
66 while (1)
67 {
68 int opt = getopt_long (argc, argv,
69 "VHn", longopts, 0);
70
71 if (opt == EOF)
72 break;
73
74 switch (opt)
75 {
76 case 0:
77 /* If getopt returns 0, then it has already processed a
78 long-named option. We should do nothing. */
79 break;
80
81 case 'n':
82 nowait = 1;
83 break;
84
85 case 'V':
86 fprintf (stderr, "Version %s\n", VERSION);
87 exit (1);
88 break;
30 89
90 case 'H':
91 default:
92 print_help_and_exit ();
93 }
94 }
95
96 return argc;
97}
98
99print_help_and_exit ()
100{
101 fprintf (stderr,
102 "Usage: %s [-n] [--nowait] [+linenumber] filename\n",
103 progname);
104 fprintf (stderr,
105 "Report bugs to bug-gnu-emacs@prep.ai.mit.edu.\n");
106 exit (1);
107}
108
31#if !defined (HAVE_SOCKETS) && !defined (HAVE_SYSVIPC) 109#if !defined (HAVE_SOCKETS) && !defined (HAVE_SYSVIPC)
32#include <stdio.h>
33 110
34main (argc, argv) 111main (argc, argv)
35 int argc; 112 int argc;
@@ -50,7 +127,6 @@ main (argc, argv)
50#include <sys/socket.h> 127#include <sys/socket.h>
51#include <sys/un.h> 128#include <sys/un.h>
52#include <sys/stat.h> 129#include <sys/stat.h>
53#include <stdio.h>
54#include <errno.h> 130#include <errno.h>
55 131
56extern char *strerror (); 132extern char *strerror ();
@@ -67,17 +143,19 @@ main (argc, argv)
67 struct sockaddr_un server; 143 struct sockaddr_un server;
68 char *homedir, *cwd, *str; 144 char *homedir, *cwd, *str;
69 char string[BUFSIZ]; 145 char string[BUFSIZ];
146 int args_left;
70 147
71 char *getenv (), *getwd (); 148 progname = argv[0];
72 char *getcwd (); 149
73 int geteuid (); 150 /* Process options. */
74 int nowait = 0; 151 args_left = decode_options (argc, argv);
152
153 /* Advance argv and decrement argc for the options that were skipped. */
154 argv += argc - args_left;
155 argc = args_left;
75 156
76 if (argc < 2) 157 if (argc < 2)
77 { 158 print_help_and_exit ();
78 fprintf (stderr, "Usage: %s [+linenumber] filename\n", argv[0]);
79 exit (1);
80 }
81 159
82 /* 160 /*
83 * Open up an AF_UNIX socket in this person's home directory 161 * Open up an AF_UNIX socket in this person's home directory
@@ -239,14 +317,18 @@ main (argc, argv)
239 char gwdirb[BUFSIZ]; 317 char gwdirb[BUFSIZ];
240 char *cwd; 318 char *cwd;
241 char *temp; 319 char *temp;
242 char *progname = argv[0]; 320
243 int nowait = 0; 321 progname = argv[0];
322
323 /* Process options. */
324 args_left = decode_options (argc, argv);
325
326 /* Advance argv and decrement argc for the options that were skipped. */
327 argv += argc - args_left;
328 argc = args_left;
244 329
245 if (argc < 2) 330 if (argc < 2)
246 { 331 print_help_and_exit ();
247 fprintf (stderr, "Usage: %s [+linenumber] filename\n", argv[0]);
248 exit (1);
249 }
250 332
251 /* 333 /*
252 * Create a message queue using ~/.emacs-server as the path for ftok 334 * Create a message queue using ~/.emacs-server as the path for ftok