annotate lib-src/gnuclient.c @ 26:441bb1e64a06 r19-15b96

Import from CVS: tag r19-15b96
author cvs
date Mon, 13 Aug 2007 08:51:32 +0200
parents bcdc7deadc19
children ec9a17fef872
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 /* -*-C-*-
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 Client code to allow local and remote editing of files by XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 Copyright (C) 1989 Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 Copyright (C) 1995 Sun Microsystems, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 This file is part of XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 XEmacs is free software; you can redistribute it and/or modify it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 under the terms of the GNU General Public License as published by the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 Free Software Foundation; either version 2, or (at your option) any
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 XEmacs is distributed in the hope that it will be useful, but WITHOUT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 You should have received a copy of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 along with XEmacs; see the file COPYING. If not, write to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 Boston, MA 02111-1307, USA.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 Author: Andy Norman (ange@hplb.hpl.hp.com), based on
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 'etc/emacsclient.c' from the GNU Emacs 18.52 distribution.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 Please mail bugs and suggestions to the author at the above address.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 * This file incorporates new features added by Bob Weiner <weiner@mot.com>,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 * Darrell Kindred <dkindred@cmu.edu> and Arup Mukherjee <arup@cmu.edu>.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 * GNUATTACH support added by Ben Wing <wing@xemacs.org>.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 * Please see the note at the end of the README file for details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 * (If gnuserv came bundled with your emacs, the README file is probably
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 * ../etc/gnuserv.README relative to the directory containing this file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 #if 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 /* Hand-munged RCS header */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 static char rcsid [] = "!Header: gnuclient.c,v 2.2 95/12/12 01:39:21 wing nene !";
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 #include "gnuserv.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 #include "getopt.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 #include <stdio.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 #include <stdlib.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 #include <string.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 #include <sys/types.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 #include <unistd.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 #if !defined(SYSV_IPC) && !defined(UNIX_DOMAIN_SOCKETS) && \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 !defined(INTERNET_DOMAIN_SOCKETS)
12
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
diff changeset
55 int
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
diff changeset
56 main (int argc, char *argv[])
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 fprintf (stderr, "Sorry, the Emacs server is only "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 "supported on systems that have\n");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 fprintf (stderr, "Unix Domain sockets, Internet Domain "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 "sockets or System V IPC.\n");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 exit (1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 } /* main */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 #else /* SYSV_IPC || UNIX_DOMAIN_SOCKETS || INTERNET_DOMAIN_SOCKETS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 static char cwd[MAXPATHLEN+2]; /* current working directory when calculated */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 static char *cp = NULL; /* ptr into valid bit of cwd above */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 get_current_working_directory -- return the cwd.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 static char *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 get_current_working_directory (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 if (cp == NULL)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 { /* haven't calculated it yet */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 #ifdef BSD
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 if (getwd (cwd) == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 #else /* !BSD */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 if (getcwd (cwd,MAXPATHLEN) == NULL)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 #endif /* !BSD */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 perror (progname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 fprintf (stderr, "%s: unable to get current working directory\n",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 progname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 exit (1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 } /* if */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 /* on some systems, cwd can look like '@machine/' ... */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 /* ignore everything before the first '/' */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 for (cp = cwd; *cp && *cp != '/'; ++cp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 ;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 } /* if */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 return cp;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 } /* get_current_working_directory */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 filename_expand -- try to convert the given filename into a fully-qualified
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 pathname.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 filename_expand (char *fullpath, char *filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 /* fullpath - returned full pathname */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 /* filename - filename to expand */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 int len;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 fullpath[0] = '\0';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 if (filename[0] && filename[0] != '/')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 { /* relative filename */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 strcat (fullpath, get_current_working_directory ());
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 len = strlen (fullpath);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 if (len > 0 && fullpath[len-1] == '/') /* trailing slash already? */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 ; /* yep */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 strcat (fullpath, "/"); /* nope, append trailing slash */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 } /* if */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 strcat (fullpath,filename);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 } /* filename_expand */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129
12
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
diff changeset
130 int
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
diff changeset
131 main (int argc, char *argv[])
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 int starting_line = 1; /* line to start editing at */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 char command[MAXPATHLEN+50]; /* emacs command buffer */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 char fullpath[MAXPATHLEN+1]; /* full pathname to file */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 #ifndef GNUATTACH
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 int qflg = 0; /* quick edit, don't wait for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 * user to finish */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 int errflg = 0; /* option error */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 int c; /* char from getopt */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 int s; /* socket / msqid to server */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 int connect_type; /* CONN_UNIX, CONN_INTERNET, or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 * CONN_IPC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 #ifdef INTERNET_DOMAIN_SOCKETS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 char *hostarg = NULL; /* remote hostname */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 char thishost[HOSTNAMSZ]; /* this hostname */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 char remotepath[MAXPATHLEN+1]; /* remote pathname */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 int rflg = 0; /* pathname given on cmdline */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 u_short portarg = 0; /* port to server */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 char *ptr; /* return from getenv */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 #endif /* INTERNET_DOMAIN_SOCKETS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 #ifdef SYSV_IPC
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 struct msgbuf *msgp; /* message */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 #endif /* SYSV_IPC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 #ifdef GNUATTACH
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 char *tty;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 #ifdef INTERNET_DOMAIN_SOCKETS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 memset (remotepath, 0, sizeof (remotepath));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 #endif /* INTERNET_DOMAIN_SOCKETS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 progname = argv[0];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 while ((c = getopt (argc, argv,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 #ifdef INTERNET_DOMAIN_SOCKETS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 # ifdef GNUATTACH
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 "h:p:r"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 # else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 "h:p:r:q"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 # endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 #else /* !INTERNET_DOMAIN_SOCKETS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 # ifdef GNUATTACH
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 ""
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 # else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 "q"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 # endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 #endif /* !INTERNET_DOMAIN_SOCKETS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 )) != EOF)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 switch (c)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 #ifndef GNUATTACH
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 case 'q': /* quick mode specified */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 qflg++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 #ifdef INTERNET_DOMAIN_SOCKETS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 case 'h': /* server host name specified */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 hostarg = optarg;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 case 'r': /* remote path from server specifed */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 strcpy (remotepath,optarg);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 rflg++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 case 'p': /* port number specified */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 portarg = atoi (optarg);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 #endif /* INTERNET_DOMAIN_SOCKETS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 case '?':
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 errflg++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 } /* switch */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 if (errflg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 fprintf (stderr,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 #ifdef INTERNET_DOMAIN_SOCKETS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 # ifdef GNUATTACH
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 "usage: %s [-h hostname] [-p port] [-r pathname] "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 "[[+line] path] ...\n",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 # else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 "usage: %s [-q] [-h hostname] [-p port] [-r pathname] "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 "[[+line] path] ...\n",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 # endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 #else /* !INTERNET_DOMAIN_SOCKETS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 # ifdef GNUATTACH
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 "usage: %s [[+line] path] ...\n",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 # else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 "usage: %s [-q] [[+line] path] ...\n",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 # endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 #endif /* !INTERNET_DOMAIN_SOCKETS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 progname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 exit (1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 } /* if */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 #ifdef GNUATTACH
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 tty = ttyname (0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 if (!tty)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 fprintf (stderr, "%s: Not connected to a tty", progname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 exit (1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 #ifdef INTERNET_DOMAIN_SOCKETS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 connect_type = make_connection (hostarg, portarg, &s);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 connect_type = make_connection (NULL, (u_short) 0, &s);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 #ifdef INTERNET_DOMAIN_SOCKETS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 if (connect_type == (int) CONN_INTERNET)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 gethostname (thishost, HOSTNAMSZ);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 if (!rflg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 { /* attempt to generate a path
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 * to this machine */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 if ((ptr = getenv ("GNU_NODE")) != NULL)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 /* user specified a path */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 strcpy (remotepath, ptr);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 #if 0 /* This is really bogus... re-enable it if you must have it! */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 #if defined (hp9000s300) || defined (hp9000s800)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 else if (strcmp (thishost,hostarg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 { /* try /net/thishost */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 strcpy (remotepath, "/net/"); /* (this fails using internet
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 addresses) */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 strcat (remotepath, thishost);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 { /* same machines, no need for path */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 remotepath[0] = '\0'; /* default is the empty path */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 #endif /* INTERNET_DOMAIN_SOCKETS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 #ifdef SYSV_IPC
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 if ((msgp = (struct msgbuf *)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 malloc (sizeof *msgp + GSERV_BUFSZ)) == NULL)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 fprintf (stderr, "%s: not enough memory for message buffer\n", progname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 exit (1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 } /* if */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 msgp->mtext[0] = '\0'; /* ready for later strcats */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 #endif /* SYSV_IPC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 #ifdef GNUATTACH
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 ptr = getenv ("TERM");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 if (!ptr)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 fprintf (stderr, "%s: unknown terminal type\n", progname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 exit (1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 sprintf (command, "(server-tty-edit-files \"%s\" \"%s\" '(", tty, ptr);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 send_string (s, command);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 if (qflg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 send_string (s, "(server-edit-files-quickly '(");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 send_string (s, "(server-edit-files '(");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 for (; optind < argc; optind++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 if (*argv[optind] == '+')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 starting_line = atoi (argv[optind]);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 filename_expand (fullpath, argv[optind]);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 sprintf (command, "(%d . \"%s%s\")", starting_line,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 #ifdef INTERNET_DOMAIN_SOCKETS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 remotepath,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 #else /* !INTERNET_DOMAIN_SOCKETS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 "",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 fullpath);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 send_string (s,command);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 starting_line = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 } /* else */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 } /* for */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 send_string (s,"))");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 #ifdef SYSV_IPC
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 if (connect_type == (int) CONN_IPC)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 disconnect_from_ipc_server (s, msgp, FALSE);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 #else /* !SYSV_IPC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 if (connect_type != (int) CONN_IPC)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331 disconnect_from_server (s, FALSE);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332 #endif /* !SYSV_IPC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333
12
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
diff changeset
334 return 0;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 } /* main */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 #endif /* SYSV_IPC || UNIX_DOMAIN_SOCKETS || INTERNET_DOMAIN_SOCKETS */