annotate lib-src/gnuclient.c @ 2:ac2d302a0011 r19-15b2

Import from CVS: tag r19-15b2
author cvs
date Mon, 13 Aug 2007 08:46:35 +0200
parents 376386a54a3c
children bcdc7deadc19
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)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 main ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 fprintf (stderr, "Sorry, the Emacs server is only "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 "supported on systems that have\n");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 fprintf (stderr, "Unix Domain sockets, Internet Domain "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 "sockets or System V IPC.\n");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 exit (1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 } /* main */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 #else /* SYSV_IPC || UNIX_DOMAIN_SOCKETS || INTERNET_DOMAIN_SOCKETS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 static char cwd[MAXPATHLEN+2]; /* current working directory when calculated */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 static char *cp = NULL; /* ptr into valid bit of cwd above */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67
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 get_current_working_directory -- return the cwd.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 static char *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 get_current_working_directory (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 if (cp == NULL)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 { /* haven't calculated it yet */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 #ifdef BSD
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 if (getwd (cwd) == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 #else /* !BSD */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 if (getcwd (cwd,MAXPATHLEN) == NULL)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 #endif /* !BSD */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 perror (progname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 fprintf (stderr, "%s: unable to get current working directory\n",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 progname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 exit (1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 } /* if */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 /* on some systems, cwd can look like '@machine/' ... */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 /* ignore everything before the first '/' */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 for (cp = cwd; *cp && *cp != '/'; ++cp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 ;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 } /* if */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 return cp;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 } /* get_current_working_directory */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99
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 filename_expand -- try to convert the given filename into a fully-qualified
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 pathname.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 filename_expand (char *fullpath, char *filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 /* fullpath - returned full pathname */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 /* filename - filename to expand */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 int len;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 fullpath[0] = '\0';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 if (filename[0] && filename[0] != '/')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 { /* relative filename */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 strcat (fullpath, get_current_working_directory ());
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 len = strlen (fullpath);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 if (len > 0 && fullpath[len-1] == '/') /* trailing slash already? */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 ; /* yep */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 strcat (fullpath, "/"); /* nope, append trailing slash */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 } /* if */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 strcat (fullpath,filename);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 } /* filename_expand */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 main (int argc, char **argv)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 int starting_line = 1; /* line to start editing at */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 char command[MAXPATHLEN+50]; /* emacs command buffer */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 char fullpath[MAXPATHLEN+1]; /* full pathname to file */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 #ifndef GNUATTACH
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 int qflg = 0; /* quick edit, don't wait for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 * user to finish */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 int errflg = 0; /* option error */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 int c; /* char from getopt */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 int s; /* socket / msqid to server */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 int connect_type; /* CONN_UNIX, CONN_INTERNET, or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 * CONN_IPC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 #ifdef INTERNET_DOMAIN_SOCKETS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 char *hostarg = NULL; /* remote hostname */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 char thishost[HOSTNAMSZ]; /* this hostname */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 char remotepath[MAXPATHLEN+1]; /* remote pathname */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 int rflg = 0; /* pathname given on cmdline */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 u_short portarg = 0; /* port to server */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 char *ptr; /* return from getenv */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 #endif /* INTERNET_DOMAIN_SOCKETS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 #ifdef SYSV_IPC
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 struct msgbuf *msgp; /* message */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 #endif /* SYSV_IPC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 #ifdef GNUATTACH
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 char *tty;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 #ifdef INTERNET_DOMAIN_SOCKETS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 memset (remotepath, 0, sizeof (remotepath));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 #endif /* INTERNET_DOMAIN_SOCKETS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 progname = argv[0];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 while ((c = getopt (argc, argv,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 #ifdef INTERNET_DOMAIN_SOCKETS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 # ifdef GNUATTACH
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 "h:p:r"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 # else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 "h:p:r:q"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 # endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 #else /* !INTERNET_DOMAIN_SOCKETS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 # ifdef GNUATTACH
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 ""
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 # else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 "q"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 # endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 #endif /* !INTERNET_DOMAIN_SOCKETS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 )) != EOF)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 switch (c)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 #ifndef GNUATTACH
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 case 'q': /* quick mode specified */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 qflg++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 #ifdef INTERNET_DOMAIN_SOCKETS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 case 'h': /* server host name specified */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 hostarg = optarg;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 case 'r': /* remote path from server specifed */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 strcpy (remotepath,optarg);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 rflg++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 case 'p': /* port number specified */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 portarg = atoi (optarg);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 #endif /* INTERNET_DOMAIN_SOCKETS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 case '?':
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 errflg++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 } /* switch */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 if (errflg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 fprintf (stderr,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 #ifdef INTERNET_DOMAIN_SOCKETS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 # ifdef GNUATTACH
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 "usage: %s [-h hostname] [-p port] [-r pathname] "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 "[[+line] path] ...\n",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 # else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 "usage: %s [-q] [-h hostname] [-p port] [-r pathname] "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 "[[+line] path] ...\n",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 # endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 #else /* !INTERNET_DOMAIN_SOCKETS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 # ifdef GNUATTACH
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 "usage: %s [[+line] path] ...\n",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 # else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 "usage: %s [-q] [[+line] path] ...\n",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 # endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 #endif /* !INTERNET_DOMAIN_SOCKETS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 progname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 exit (1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 } /* if */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 #ifdef GNUATTACH
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 tty = ttyname (0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 if (!tty)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 fprintf (stderr, "%s: Not connected to a tty", progname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 exit (1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 #ifdef INTERNET_DOMAIN_SOCKETS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 connect_type = make_connection (hostarg, portarg, &s);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 connect_type = make_connection (NULL, (u_short) 0, &s);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 #ifdef INTERNET_DOMAIN_SOCKETS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 if (connect_type == (int) CONN_INTERNET)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 gethostname (thishost, HOSTNAMSZ);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 if (!rflg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 { /* attempt to generate a path
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 * to this machine */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 if ((ptr = getenv ("GNU_NODE")) != NULL)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 /* user specified a path */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 strcpy (remotepath, ptr);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 #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
256 #if defined (hp9000s300) || defined (hp9000s800)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 else if (strcmp (thishost,hostarg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 { /* try /net/thishost */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 strcpy (remotepath, "/net/"); /* (this fails using internet
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 addresses) */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 strcat (remotepath, thishost);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 #endif
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 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 { /* same machines, no need for path */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 remotepath[0] = '\0'; /* default is the empty path */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 #endif /* INTERNET_DOMAIN_SOCKETS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 #ifdef SYSV_IPC
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 if ((msgp = (struct msgbuf *)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 malloc (sizeof *msgp + GSERV_BUFSZ)) == NULL)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 fprintf (stderr, "%s: not enough memory for message buffer\n", progname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 exit (1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 } /* if */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 msgp->mtext[0] = '\0'; /* ready for later strcats */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 #endif /* SYSV_IPC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 #ifdef GNUATTACH
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 ptr = getenv ("TERM");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 if (!ptr)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 fprintf (stderr, "%s: unknown terminal type\n", progname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 exit (1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 sprintf (command, "(server-tty-edit-files \"%s\" \"%s\" '(", tty, ptr);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 send_string (s, command);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 if (qflg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 send_string (s, "(server-edit-files-quickly '(");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 send_string (s, "(server-edit-files '(");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 for (; optind < argc; optind++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 if (*argv[optind] == '+')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 starting_line = atoi (argv[optind]);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 filename_expand (fullpath, argv[optind]);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 sprintf (command, "(%d . \"%s%s\")", starting_line,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 #ifdef INTERNET_DOMAIN_SOCKETS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 remotepath,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 #else /* !INTERNET_DOMAIN_SOCKETS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 "",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 fullpath);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 send_string (s,command);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 starting_line = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 } /* else */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 } /* for */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 send_string (s,"))");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 #ifdef SYSV_IPC
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 if (connect_type == (int) CONN_IPC)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 disconnect_from_ipc_server (s, msgp, FALSE);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 #else /* !SYSV_IPC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 if (connect_type != (int) CONN_IPC)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 disconnect_from_server (s, FALSE);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331 #endif /* !SYSV_IPC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 exit (0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 } /* main */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 #endif /* SYSV_IPC || UNIX_DOMAIN_SOCKETS || INTERNET_DOMAIN_SOCKETS */