comparison lib-src/gnuclient.c @ 412:697ef44129c6 r21-2-14

Import from CVS: tag r21-2-14
author cvs
date Mon, 13 Aug 2007 11:20:41 +0200
parents de805c49cfc1
children
comparison
equal deleted inserted replaced
411:12e008d41344 412:697ef44129c6
24 Author: Andy Norman (ange@hplb.hpl.hp.com), based on 24 Author: Andy Norman (ange@hplb.hpl.hp.com), based on
25 'etc/emacsclient.c' from the GNU Emacs 18.52 distribution. 25 'etc/emacsclient.c' from the GNU Emacs 18.52 distribution.
26 26
27 Please mail bugs and suggestions to the XEmacs maintainer. 27 Please mail bugs and suggestions to the XEmacs maintainer.
28 */ 28 */
29
30 /* #### This file should be a windows-mode, not console-mode program under
31 Windows. (i.e. its entry point should be WinMain.) gnuattach functionality,
32 to the extent it's used at all, should be retrieved using a script that
33 calls the i.exe wrapper program, to obtain stdio handles.
34
35 #### For that matter, both the functionality of gnuclient and gnuserv
36 should be merged into XEmacs itself using a -remote arg, just like
37 Netscape and other modern programs.
38
39 --ben */
40 29
41 /* 30 /*
42 * This file incorporates new features added by Bob Weiner <weiner@mot.com>, 31 * This file incorporates new features added by Bob Weiner <weiner@mot.com>,
43 * Darrell Kindred <dkindred@cmu.edu> and Arup Mukherjee <arup@cmu.edu>. 32 * Darrell Kindred <dkindred@cmu.edu> and Arup Mukherjee <arup@cmu.edu>.
44 * GNUATTACH support added by Ben Wing <wing@xemacs.org>. 33 * GNUATTACH support added by Ben Wing <wing@xemacs.org>.
57 #include "getopt.h" 46 #include "getopt.h"
58 47
59 #include <stdio.h> 48 #include <stdio.h>
60 #include <stdlib.h> 49 #include <stdlib.h>
61 #include <sys/types.h> 50 #include <sys/types.h>
51 #define DONT_ENCAPSULATE
62 #include <sysfile.h> 52 #include <sysfile.h>
63 53
64 #ifdef HAVE_STRING_H 54 #ifdef HAVE_STRING_H
65 #include <string.h> 55 #include <string.h>
66 #endif /* HAVE_STRING_H */ 56 #endif /* HAVE_STRING_H */
129 } 119 }
130 initialize_signals (); 120 initialize_signals ();
131 } 121 }
132 122
133 void 123 void
134 initialize_signals (void) 124 initialize_signals ()
135 { 125 {
136 /* Set up signal handler to pass relevant signals to emacs process. 126 /* Set up signal handler to pass relevant signals to emacs process.
137 We used to send SIGSEGV, SIGBUS, SIGPIPE, SIGILL and others to 127 We used to send SIGSEGV, SIGBUS, SIGPIPE, SIGILL and others to
138 Emacs, but I think it's better not to. I can see no reason why 128 Emacs, but I think it's better not to. I can see no reason why
139 Emacs should SIGSEGV whenever gnuclient SIGSEGV-s, etc. */ 129 Emacs should SIGSEGV whenever gnuclient SIGSEGV-s, etc. */
198 if (filename[0] && filename[0] == '/') 188 if (filename[0] && filename[0] == '/')
199 { 189 {
200 /* Absolute (unix-style) pathname. Do nothing */ 190 /* Absolute (unix-style) pathname. Do nothing */
201 strcat (fullpath, filename); 191 strcat (fullpath, filename);
202 } 192 }
203 #ifdef CYGWIN 193 #ifdef __CYGWIN32__
204 else if (filename[0] && filename[0] == '\\' && 194 else if (filename[0] && filename[0] == '\\' &&
205 filename[1] && filename[1] == '\\') 195 filename[1] && filename[1] == '\\')
206 { 196 {
207 /* This path includes the server name (something like 197 /* This path includes the server name (something like
208 "\\server\path"), so we assume it's absolute. Do nothing to 198 "\\server\path"), so we assume it's absolute. Do nothing to
239 } /* filename_expand */ 229 } /* filename_expand */
240 230
241 /* Encase the string in quotes, escape all the backslashes and quotes 231 /* Encase the string in quotes, escape all the backslashes and quotes
242 in string. */ 232 in string. */
243 static char * 233 static char *
244 clean_string (const char *s) 234 clean_string (CONST char *s)
245 { 235 {
246 int i = 0; 236 int i = 0;
247 char *p, *res; 237 char *p, *res;
248 238
249 { 239 {
250 const char *const_p; 240 CONST char *const_p;
251 for (const_p = s; *const_p; const_p++, i++) 241 for (const_p = s; *const_p; const_p++, i++)
252 { 242 {
253 if (*const_p == '\\' || *const_p == '\"') 243 if (*const_p == '\\' || *const_p == '\"')
254 ++i; 244 ++i;
255 else if (*const_p == '\004') 245 else if (*const_p == '\004')
299 (var) = argv[i]; \ 289 (var) = argv[i]; \
300 } \ 290 } \
301 over = 1; \ 291 over = 1; \
302 } while (0) 292 } while (0)
303 293
304 /* A strdup imitation. */ 294 /* A strdup immitation. */
305 static char * 295 static char *
306 my_strdup (const char *s) 296 my_strdup (CONST char *s)
307 { 297 {
308 char *new_s = (char *) malloc (strlen (s) + 1); 298 char *new = malloc (strlen (s) + 1);
309 if (new_s) 299 if (new)
310 strcpy (new_s, s); 300 strcpy (new, s);
311 return new_s; 301 return new;
312 } 302 }
313 303
314 int 304 int
315 main (int argc, char *argv[]) 305 main (int argc, char *argv[])
316 { 306 {
668 starting_line = 1; 658 starting_line = 1;
669 --i; 659 --i;
670 } 660 }
671 filename_expand (fullpath, argv[i]); 661 filename_expand (fullpath, argv[i]);
672 #ifdef INTERNET_DOMAIN_SOCKETS 662 #ifdef INTERNET_DOMAIN_SOCKETS
673 path = (char *) malloc (strlen (remotepath) + strlen (fullpath) + 1); 663 path = malloc (strlen (remotepath) + strlen (fullpath) + 1);
674 sprintf (path, "%s%s", remotepath, fullpath); 664 sprintf (path, "%s%s", remotepath, fullpath);
675 #else 665 #else
676 path = my_strdup (fullpath); 666 path = my_strdup (fullpath);
677 #endif 667 #endif
678 sprintf (command, "(%d . %s)", starting_line, clean_string (path)); 668 sprintf (command, "(%d . %s)", starting_line, clean_string (path));