Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 928 lines (819 sloc) 21.993 kB
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
1 /* main.c */
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
2 /* Copyright 1995 by Steve Kirkendall */
3
4
5 #include "elvis.h"
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
6 #ifdef FEATURE_RCSID
2fe6e17 @mbert Import Elvis 2.2_1 (written by Steve Kirkendall)
authored
7 char id_main[] = "$Id: main.c,v 2.77 2004/03/19 23:10:12 steve Exp $";
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
8 #endif
9 #include <time.h> /* for time(), used to seed the random number generator */
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
10
11 #if USE_PROTOTYPES
12 static void usage(char *hint);
13 static void guiusage(void);
14 static int parseflags(int argc, char **argv);
15 static int choosegui(int argc, char **argv);
16 static void doexrc(void);
17 static void buildargs(int argc, char **argv);
18 static void startfirst(void);
19 static void init(int argc, char **argv);
20 void term(void);
8d1ac0c @mbert Import Elvis 2.1 (written by Steve Kirkendall)
authored
21 int main(int argc, char **argv);
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
22 #endif
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
23
24
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
25 /* This array contains pointers to all known GUIs. Ideally, they should be
26 * sorted so that fancy/rarely-available GUIs appear near the front of the
27 * list, and basic/universal GUIs appear near the end.
28 */
29 static GUI *allguis[] =
30 {
31 #ifdef GUI_WIN32
32 &guiwin32
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
33 #endif
34
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
35 #ifdef GUI_X11
36 &guix11,
37 #endif
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
38
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
39 #ifdef GUI_GNOME
40 &guignome,
41 #endif
42
8d1ac0c @mbert Import Elvis 2.1 (written by Steve Kirkendall)
authored
43 #ifdef GUI_PM
44 &guipm,
45 #endif
46
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
47 #ifdef GUI_TERMCAP
48 &guitermcap,
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
49 #endif
50
8d1ac0c @mbert Import Elvis 2.1 (written by Steve Kirkendall)
authored
51 #ifdef GUI_VIO
52 &guivio,
53 #endif
54
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
55 #ifdef GUI_CURSES
56 &guicurses,
57 #endif
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
58
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
59 #ifdef GUI_BIOS
60 &guibios,
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
61 #endif
62
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
63 #ifdef GUI_OPEN
64 &guiopen,
8d1ac0c @mbert Import Elvis 2.1 (written by Steve Kirkendall)
authored
65 &guiscript,
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
66 &guiquit
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
67 #endif
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
68 };
69
70 /* These flags are set according to command-line flags */
71 static char *initialcommand;
72 static char *initialtag;
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
73 static ELVBOOL initialall;
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
74 GUI *chosengui;
75
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
76 #ifdef FEATURE_STDIN
77 FILE *origstdin; /* where to read "-" from */
78 ELVBOOL stdin_not_kbd; /* if ElvTrue, then keyboard input should be adjusted */
79 #endif
80
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
81 /* Give a usage message, and then exit */
82 static void usage(hint)
83 char *hint; /* an error message */
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
84 {
85 int i;
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
86 char guinames[80];
87
88 msg(MSG_INFO, "Usage: elvis [flags] [files]...");
89 msg(MSG_INFO, "Flags: -V Verbose -- give more status information");
90 msg(MSG_INFO, " -a Create a separate window for each file");
91 msg(MSG_INFO, " -r Restart a session after a crash");
92 msg(MSG_INFO, " -R Mark new buffers as \"readonly\"");
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
93 msg(MSG_INFO, " -b Mark new buffers as \"readeol=binary\"");
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
94 msg(MSG_INFO, " -e Start in ex mode instead of vi mode");
95 msg(MSG_INFO, " -i Start in input mode instead of vi mode");
2fe6e17 @mbert Import Elvis 2.2_1 (written by Steve Kirkendall)
authored
96 msg(MSG_INFO, " -S Set security=restricted, for maximum security");
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
97 msg(MSG_INFO, " -w lines Set scroll amount to \"lines\"");
98 msg(MSG_INFO, " -f session Use \"session\" as the session file");
99 msg(MSG_INFO, " -G gui Use the \"gui\" user interface \\(see below\\)");
100 msg(MSG_INFO, " -c command Execute \"command\" after loading first file");
8d1ac0c @mbert Import Elvis 2.1 (written by Steve Kirkendall)
authored
101 msg(MSG_INFO, " -s Read a script from stdin and execute it");
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
102 msg(MSG_INFO, " -t tag Perform a tag search");
8d1ac0c @mbert Import Elvis 2.1 (written by Steve Kirkendall)
authored
103 msg(MSG_INFO, " -o logfile Send messages to logfile instead of stderr");
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
104 msg(MSG_INFO, " -B blksize Use blocks of size \"blksize\"");
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
105 msg(MSG_INFO, " +command Archaic form of \"-c command\" flag");
8d1ac0c @mbert Import Elvis 2.1 (written by Steve Kirkendall)
authored
106 msg(MSG_INFO, " - Archaic form of \"-s\" flag");
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
107 guinames[0] = '\0';
108 for (i = 0; i < QTY(allguis); i++)
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
109 {
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
110 /* space between names */
111 if (i > 0)
112 strcat(guinames, " ");
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
113
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
114 /* concatenate the gui names into a list */
115 switch ((*allguis[i]->test)())
116 {
117 case 0:
118 sprintf(guinames + strlen(guinames), "(%s)", allguis[i]->name);
119 break;
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
120
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
121 case 2:
122 sprintf(guinames + strlen(guinames), "%s?", allguis[i]->name);
123 break;
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
124
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
125 default:
126 strcat(guinames, allguis[i]->name);
127 }
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
128 }
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
129 msg(MSG_INFO, "[s]User interfaces: $1", guinames);
130 msg(MSG_INFO, "For more information about user interfaces, give the command 'elvis -G?'");
131 msg(MSG_INFO, "[s]Report bugs to $1", "kirkenda@cs.pdx.edu");
132 if (hint)
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
133 {
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
134 msg(MSG_INFO, hint);
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
135 }
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
136 if (chosengui)
137 (*chosengui->term)();
138 exit(0);
139 }
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
140
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
141 static void guiusage()
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
142 {
143 int i;
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
144 ELVBOOL found;
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
145 char *msgfmt;
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
146
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
147 msg(MSG_INFO, "user interfaces:");
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
148 for (i = 0, found = ElvFalse; i < QTY(allguis); i++)
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
149 {
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
150 switch ((*allguis[i]->test)())
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
151 {
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
152 case 0:
153 msgfmt = "[ss] -G ($1<<12) $2 \\(UNAVAILABLE\\)";
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
154 break;
155
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
156 case 2:
157 msgfmt = "[ss] -G ($1<<12) $2 \\(MAYBE\\)";
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
158 break;
159
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
160 default:
161 if (found)
162 msgfmt = "[ss] -G ($1<<12) $2";
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
163 else
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
164 msgfmt = "[ss] -G ($1<<12) $2 \\(DEFAULT\\)";
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
165 found = ElvTrue;
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
166 }
167 msg(MSG_INFO, msgfmt, allguis[i]->name, allguis[i]->desc);
168 if (allguis[i]->usage)
169 (*allguis[i]->usage)();
170 }
171 if (chosengui)
172 (*chosengui->term)();
173 exit(0);
174 }
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
175
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
176 /* parse command-line flags. Leave global variables set to reflect the
177 * flags discovered. Upon return, any arguments handled here should be
178 * deleted from argv[]; the return value is the new argc value.
179 */
180 static int parseflags(argc, argv)
181 int argc; /* number of command-line arguments */
182 char **argv; /* values of command-line arguments */
183 {
184 int i, j, del;
185 long size = 0;
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
186
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
187 /* copy argv[0] into an option so we can access it in "elvis.ini" */
188 o_program = toCHAR(argv[0]);
189
190 /* for each argument... */
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
191 for (i = 1; i < argc && strcmp(argv[i], "--"); i++)
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
192 {
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
193 /* for now, assume we'll be deleting 0 arguments */
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
194 del = 0;
195
196 /* recognize any normal flags */
197 if (argv[i][0] == '-')
198 {
8d1ac0c @mbert Import Elvis 2.1 (written by Steve Kirkendall)
authored
199 /* the "-" flag has already been processed */
200 if (!argv[i][1])
201 del = 1;
202
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
203 for (j = 1; j != 0 && argv[i][j]; j++)
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
204 {
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
205 switch (argv[i][j])
206 {
207 case 'a':
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
208 initialall = ElvTrue;
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
209 del = 1;
210 break;
211
212 case 'r':
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
213 o_recovering = ElvTrue;
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
214 del = 1;
215 break;
216
217 case 'R':
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
218 o_defaultreadonly = ElvTrue;
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
219 del = 1;
220 break;
221
222 case 'V':
8d1ac0c @mbert Import Elvis 2.1 (written by Steve Kirkendall)
authored
223 case 's':
224 /* already handled in chosengui() */
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
225 del = 1;
226 break;
227
228 case 'f':
229 if (argv[i][j + 1])
230 {
231 o_session = toCHAR(&argv[i][j + 1]);
232 del = 1;
233 }
234 else if (i + 1 < argc)
235 {
236 o_session = toCHAR(argv[i + 1]);
237 del = 2;
238 i++;
239 }
240 else
241 {
242 usage("-s requires the name of a session file");
243 }
244 j = -1; /* so we stop processing this arg */
245 break;
246
8d1ac0c @mbert Import Elvis 2.1 (written by Steve Kirkendall)
authored
247 case 'o':
248 if (argv[i][j + 1])
249 {
250 msglog(&argv[i][j + 1]);
251 del = 1;
252 }
253 else if (i + 1 < argc)
254 {
255 msglog(argv[i + 1]);
256 del = 2;
257 i++;
258 }
259 else
260 {
261 usage("-o requires the name of a log file");
262 }
263 j = -1; /* so we stop processing this arg */
264 break;
265
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
266 case 'G':
267 usage("only one \"-G gui\" is allowed");
268 break;
269
270 case 'c':
271 if (argv[i][j + 1])
272 {
273 initialcommand = &argv[i][j + 1];
274 del = 1;
275 }
276 else if (i + 1 < argc)
277 {
278 initialcommand = argv[i + 1];
279 del = 2;
280 i++;
281 }
282 else
283 {
284 usage("-c requires an initial command");
285 }
286 j = -1; /* so we stop processing this arg */
287 break;
288
289 case 't':
290 if (argv[i][j + 1])
291 {
292 initialtag = &argv[i][j + 1];
293 del = 1;
294 }
295 else if (i + 1 < argc)
296 {
297 initialtag = argv[i + 1];
298 del = 2;
299 i++;
300 }
301 else
302 {
303 usage("-t requires a tag name");
304 }
305 j = -1; /* so we stop processing this arg */
306 break;
307
308 case 'b':
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
309 o_binary = ElvTrue;
310 del = 1;
311 break;
312
313 case 'B':
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
314 if (argv[i][j + 1])
315 {
316 size = atol(&argv[i][j + 1]);
317 del = 1;
318 }
319 else if (i + 1 < argc)
320 {
321 size = atol(argv[i + 1]);
322 del = 2;
323 i++;
324 }
325 else
326 {
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
327 usage("-B requires a block size for the session file");
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
328 }
8d1ac0c @mbert Import Elvis 2.1 (written by Steve Kirkendall)
authored
329 if (size != 512 && size != 1024
330 && size != 2048 && size != 4096
331 && size != 8192)
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
332 {
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
333 usage("bad -B blksize: should be 512, 1024, 2048, 4096, or 8192");
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
334 }
335 j = -1; /* so we stop processing this arg */
336 o_blksize = size;
337 break;
338
339 case 'e':
340 case 'i':
341 o_initialstate = argv[i][j];
342 del = 1;
343 break;
344
8d1ac0c @mbert Import Elvis 2.1 (written by Steve Kirkendall)
authored
345 case 'S':
2fe6e17 @mbert Import Elvis 2.2_1 (written by Steve Kirkendall)
authored
346 o_security = 'r'; /*restricted*/
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
347 del = 1;
348 break;
349
350 case 'w':
351 if (argv[i][j + 1])
352 {
353 size = atol(&argv[i][j + 1]);
354 del = 1;
355 }
356 else if (i + 1 < argc)
357 {
358 size = atol(argv[i + 1]);
359 del = 2;
360 i++;
361 }
362 else
363 {
364 usage("-w requires a window size");
365 }
366 j = -1; /* so we stop processing this arg */
367 break;
368
369 default:
370 if (del)
371 {
372 usage(NULL);
373 }
374 j = -1;
375 }
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
376 }
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
377 }
378 else if (argv[i][0] == '+')
379 {
380 if (argv[i][1])
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
381 {
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
382 initialcommand = &argv[i][1];
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
383 }
384 else
385 {
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
386 initialcommand = "$";
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
387 }
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
388 del = 1;
389 }
390
391 /* delete arguments, if we're supposed to */
392 if (del > 0)
393 {
394 for (j = i + 1 - del; j < argc - del; j++)
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
395 {
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
396 argv[j] = argv[j + del];
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
397 }
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
398 i -= del;
399 argc -= del;
400 }
401 }
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
402
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
403 return argc;
404 }
405
406 /* Choose a GUI. If one was specified via "-G gui", then the o_gui option
407 * will be set already, and we just need to verify it. Otherwise, we need
408 * to test each GUI until we find one which tests as being available or
409 * maybe available. Call the GUI's init() function, and leave the global
410 * "gui" pointer pointing to the chosen GUI.
411 *
412 * Like parseflags(), this function should delete any arguments from argv that
413 * it uses, and return the new argc value.
414 */
415 static int choosegui(argc, argv)
416 int argc; /* number of command-line arguments */
417 char **argv; /* values of command-line arguments */
418 {
419 int i, j, val;
420
421 /* Initialize "j" just to silence a compiler warning */
422 j = 0;
423
8d1ac0c @mbert Import Elvis 2.1 (written by Steve Kirkendall)
authored
424 /* search for "-G gui" in the command line. Also watch for "-V" */
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
425 for (i = 1; i < argc; i++)
426 {
8d1ac0c @mbert Import Elvis 2.1 (written by Steve Kirkendall)
authored
427 /* skip non-flag arguments */
428 if (argv[i][0] != '-')
429 continue;
430
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
431 /* Stop looking if "--" is encountered */
432 if (argv[i][1] == '-' && !argv[i][2])
433 break;
434
8d1ac0c @mbert Import Elvis 2.1 (written by Steve Kirkendall)
authored
435 /* is it -G? -V? - or -s? */
436 if (argv[i][1] == 'G')
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
437 {
438 /* remember the gui name */
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
439 if (argv[i][2])
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
440 o_gui = toCHAR(&argv[i][2]), j = i + 1;
441 else if (i + 1 < argc)
442 o_gui = toCHAR(argv[i + 1]), j = i + 2;
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
443 else
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
444 usage("-G requires a user interface name");
445
446 /* delete the "-G" and its argument */
447 while (j < argc)
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
448 {
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
449 argv[i++] = argv[j++];
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
450 }
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
451 argv[i] = NULL;
452 argc = i;
8d1ac0c @mbert Import Elvis 2.1 (written by Steve Kirkendall)
authored
453 }
454 else if (argv[i][1] == 'V')
455 {
456 for (j = 1; argv[i][j] == 'V'; j++)
457 o_verbose++;
458 }
459 else if (argv[i][1] == '\0' || argv[i][1] == 's')
460 {
461 /* use the "script" interface */
462 o_gui = toCHAR("script");
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
463
8d1ac0c @mbert Import Elvis 2.1 (written by Steve Kirkendall)
authored
464 /* don't read any configuration files */
465 optpreset(o_elvispath, NULL, OPT_HIDE);
466 }
467 else if (!strcmp(argv[i], "-version")
468 || !strcmp(argv[i], "--version")
469 || !strcmp(argv[i], "-v"))
470 {
471 msg(MSG_INFO, "[s]elvis $1", VERSION);
472 #ifdef COPY1
473 msg(MSG_INFO, "[s]$1", COPY1);
474 #endif
475 #ifdef COPY2
476 msg(MSG_INFO, "[s]$1", COPY2);
477 #endif
478 #ifdef COPY3
479 msg(MSG_INFO, "[s]$1", COPY3);
480 #endif
481 #ifdef COPY4
482 msg(MSG_INFO, "[s]$1", COPY4);
483 #endif
484 #ifdef COPY5
485 msg(MSG_INFO, "[s]$1", COPY5);
486 #endif
487 #ifdef PORTEDBY
488 msg(MSG_INFO, "[s]$1", PORTEDBY);
489 #endif
490 exit(0);
491 }
492 else if (!strcmp(argv[i], "-help") /* old GNU */
493 || !strcmp(argv[i], "--help") /* new GNU */
494 || !strcmp(argv[i], "/?") /* DOS */
495 || !strcmp(argv[i], "-?")) /* common */
496 {
497 usage(NULL);
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
498 }
8d1ac0c @mbert Import Elvis 2.1 (written by Steve Kirkendall)
authored
499
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
500 }
501
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
502 #ifdef FEATURE_STDIN
503 /* Scan the remaining arguments for "-". Some user interfaces need
504 * to know if stdin is going to be read as a file, so they can find
505 * an alternate way to read from the keyboard.
506 */
507 for (i = 0; i < argc; i++)
508 {
509 if (!strcmp(argv[i], "-"))
510 {
511 stdin_not_kbd = ElvTrue;
512 break;
513 }
514 }
515 #endif
516
517 /* if no GUI was explicitly requested, then check for an ELVISGUI
518 * environment variable.
519 */
520 if (!o_gui)
521 o_gui = toCHAR(getenv("ELVISGUI"));
522
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
523 /* find the specified GUI, or the first available if none specified */
524 if (o_gui)
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
525 {
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
526 /* find the named GUI */
527 for (i = 0; i < QTY(allguis) && strcmp(allguis[i]->name, tochar8(o_gui)); i++)
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
528 {
529 }
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
530 if (i >= QTY(allguis))
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
531 {
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
532 if (CHARcmp(o_gui, toCHAR("?")))
533 {
534 msg(MSG_ERROR, "[s]invalid gui $1", o_gui);
535 }
536 guiusage();
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
537 }
538 }
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
539 else
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
540 {
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
541 /* Find the first GUI that is definitely available. While
542 * searching, also remember the first one that *MIGHT* be
543 * available, just in case we don't find any that are definitely
544 * available.
545 */
546 for (i = 0, j = -1; i < QTY(allguis) && (val = (*allguis[i]->test)()) != 1; i++)
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
547 {
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
548 if (val == 2 && j == -1)
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
549 {
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
550 j = i;
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
551 }
552 }
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
553
554 /* If we didn't find a definite one, use the maybe one */
555 if (i >= QTY(allguis))
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
556 {
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
557 if (j >= 0)
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
558 {
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
559 i = j;
560 }
561 else
562 {
8d1ac0c @mbert Import Elvis 2.1 (written by Steve Kirkendall)
authored
563 msg(MSG_ERROR, "no gui available");
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
564 exit(0);
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
565 }
566 }
567 }
568
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
569 /* Call the GUI's init() function */
570 argc = (*allguis[i]->init)(argc, argv);
571 if (argc <= 0)
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
572 {
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
573 exit(0);
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
574 }
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
575
576 /* Remember the chosen GUI, but don't set the official "gui" pointer
577 * yet because we want any initialization error message to go to
8d1ac0c @mbert Import Elvis 2.1 (written by Steve Kirkendall)
authored
578 * stderr instead of a window. EXCEPTION: If the gui doesn't support
579 * full screen mode, then we can set "gui" now.
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
580 */
581 chosengui = allguis[i];
582 return argc;
583 }
584
585 /* execute the initialization buffer (which may create some windows) */
586 static void doexrc()
587 {
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
588 #ifdef FEATURE_CALC
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
589 BUFFER buf; /* the buffer itself */
590 MARKBUF top; /* top of the buffer */
591 MARKBUF bottom; /* bottom of the buffer */
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
592 CHAR origsecurity;/* value of the "security" option */
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
593
594 /* If a buffer named "Elvis initialization" exists */
595 buf = bufpath(o_elvispath, INIT_FILE, toCHAR(INIT_BUF));
596 if (buf)
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
597 {
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
598 /* Temporarily make all display-mode options available */
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
599 dispinit(ElvTrue);
600
601 /* Temporarily turn off security */
602 origsecurity = o_security;
603 o_security = 'n';
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
604
605 /* Execute its contents. */
606 (void)experform((WINDOW)0, marktmp(top, buf, 0),
607 marktmp(bottom, buf, o_bufchars(buf)));
608
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
609 /* Restore the "safer" option, unless the script turned it on */
610 if (o_security == 'n' || origsecurity == 'r')
611 o_security = origsecurity;
8d1ac0c @mbert Import Elvis 2.1 (written by Steve Kirkendall)
authored
612
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
613 /* After this, only the current display-mode's options should
614 * be available.
615 */
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
616 dispinit(ElvFalse);
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
617 }
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
618 #else /* !FEATURE_CALC */
619 CHAR origsecurity;
620 char *exinit;
621 dispinit(ElvTrue);
622 origsecurity = o_security;
623 o_security = 'n';
624 exinit = getenv("EXINIT");
625 if (!exinit)
626 exinit = "so! ~/.exrc";
627 (void)exstring((WINDOW)0, toCHAR(exinit), NULL);
628 o_security |= origsecurity;
629 if (o_exrc)
630 (void)exstring((WINDOW)0, toCHAR("safely source! .exrc"), NULL);
631 dispinit(ElvFalse);
632 #endif
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
633 }
634
635 /* make the "elvis args" buffer contain file names from command line */
636 static void buildargs(argc, argv)
637 int argc; /* number of command-line arguments */
638 char **argv; /* values of command-line arguments */
639 {
640 int i;
641
642 /* skip "--", if given */
643 argc--;
644 argv++;
645 if (argc > 0 && !strcmp(argv[0], "--"))
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
646 {
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
647 argc--;
648 argv++;
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
649 }
650
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
651 /* Copy each argument to the args list. For some operating systems,
652 * we'll be expanding wildcards in each argument as we do this.
653 */
654 for (argnext = i = 0; i < argc; i++)
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
655 {
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
656 (void)exaddfilearg(&arglist, &argnext, argv[i], OSFILENAMERULES);
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
657 }
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
658
659 /* if nothing read was added, then still allocate something */
660 if (!arglist)
661 arglist = (char **)safealloc(1, sizeof(char *));
662
663 /* reset the "next" pointer */
664 argnext = 0;
665 }
666
667 /* start first file */
668 static void startfirst()
669 {
670 BUFFER buf;
671
2fe6e17 @mbert Import Elvis 2.2_1 (written by Steve Kirkendall)
authored
672 /* Initialization is done. Any autocmd events generated while loading
673 * the first buffer should be allowed to do things like alter the
674 * edit buffer or write it out.
675 */
676 o_initializing = ElvFalse;
677
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
678 /* If "Elvis args" is empty */
679 if (!arglist[0])
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
680 {
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
681 /* Create an anonymous buffer and a window for it */
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
682 buf = bufalloc(NULL, 0, ElvFalse);
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
683 assert(buf);
684 (void)(*gui->creategw)(tochar8(o_bufname(buf)), "");
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
685 }
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
686 else
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
687 {
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
688 /* Load buffers and make windows for either just the first
689 * argument, or as many of the arguments as possible.
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
690 */
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
691 assert(argnext == 0);
692 do
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
693 {
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
694 /* Create a buffer & window the first file */
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
695 buf = bufload((CHAR *)0, arglist[argnext++], ElvTrue);
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
696 assert(buf);
697 } while ((*gui->creategw)(tochar8(o_bufname(buf)), "")
698 && initialall && arglist[argnext]);
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
699 }
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
700 }
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
701
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
702 /* Perform "-c cmd" or "-t tag". If supposed to exit after that, then return
703 * TRUE; else return FALSE to continue running interactively.
704 */
705 ELVBOOL mainfirstcmd(win)
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
706 WINDOW win; /* the first window */
707 {
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
708 #ifdef FEATURE_TAGS
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
709 CHAR tagcmd[100];
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
710 #endif
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
711
712 /* If "-c cmd" was given */
713 if (initialcommand)
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
714 {
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
715 /* Execute the command */
3a9bb55 @mbert Import Elvis 2.1_3 (written by Steve Kirkendall)
authored
716 exstring(win, toCHAR(initialcommand), "-c");
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
717 }
718
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
719 #ifdef FEATURE_TAGS
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
720 /* If "-t tag" was given */
721 if (initialtag)
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
722 {
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
723 /* Compose a ":tag" command */
724 CHARcpy(tagcmd, toCHAR("tag "));
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
725 CHARncat(tagcmd, toCHAR(initialtag), QTY(tagcmd) - 5);
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
726
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
727 /* Execute the command */
3a9bb55 @mbert Import Elvis 2.1_3 (written by Steve Kirkendall)
authored
728 exstring(win, tagcmd, "-t");
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
729 }
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
730 #endif
731
732 /* clean up the state stack */
733 while (windefault
734 && windefault->state
735 && 0 != (windefault->state->flags & ELVIS_POP))
736 statepop(windefault);
737 return (ELVBOOL)(windefault && !windefault->state);
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
738 }
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
739
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
740 static void init(argc, argv)
741 int argc; /* number of command-line arguments */
742 char **argv; /* values of command-line arguments */
743 {
744 BUFFER buf;
745 char *lc; /* locale name */
746 char lcfile[100]; /* combination of locale name and file name */
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
747
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
748 #ifdef FEATURE_STDIN
749 origstdin = stdin;
750 #endif
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
751 #ifdef OSINIT
752 /* initialize the OS */
753 osinit(argv[0]);
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
754 #endif
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
755
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
756 /* initialize the random number generator */
757 srand((unsigned)time(NULL));
758
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
759 /* initialize options */
760 optglobinit();
761
762 /* Choose a GUI, and call its init() function */
763 argc = choosegui(argc, argv);
764
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
765 #ifdef FEATURE_TAGS
766 /* Make the first :tag command prefer functions over macros. This isn't
767 * critical, but it can be convenient. After the fist tag search, the
768 * preferred kind of tag will be derived from the tags that the user
769 * actually accepts, so the effect of this will either fade or be
770 * reinforced over time. Note that tsparse() clobbers the string, so
771 * we can't pass a literal directly; we must pass a copy of it.
772 */
773 strcpy(lcfile, "kind:+f");
774 tsparse(lcfile);
775 #endif
776
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
777 /* Parse command-line flags */
778 argc = parseflags(argc, argv);
779
780 /* set up the default options for windows */
781 wininit();
782
783 /* Create or restart the session file */
784 bufinit();
785
786 /* Set the "gui" pointer to the chosen gui. After this point, all
787 * error/warning/info messages will written to the window instead
788 * of stderr.
789 */
790 gui = chosengui;
791 o_gui = toCHAR(gui->name);
792
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
793 /* Disable idle color switching by default, by making the idle colors
794 * look like the normal colors. Also used "boxed" as the default
795 * selection color.
796 */
797 colorset(COLOR_FONT_IDLE, toCHAR("like normal"), ElvFalse);
798 colorset(COLOR_FONT_BOTTOM, toCHAR("like normal"), ElvFalse);
799 colorset(COLOR_FONT_NONTEXT, toCHAR("like normal"), ElvFalse);
800 colorset(COLOR_FONT_SELECTION, toCHAR("boxed"), ElvFalse);
801
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
802 /* Create the "Elvis ex history" buffer, and tweak its options */
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
803 buf = bufalloc(toCHAR(EX_BUF), (BLKNO)0, ElvTrue);
8d1ac0c @mbert Import Elvis 2.1 (written by Steve Kirkendall)
authored
804 o_inputtab(buf) = 'e';
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
805
806 /* Create the "Elvis error list" buffer, and tweak its options */
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
807 buf = bufalloc(toCHAR(ERRLIST_BUF), (BLKNO)0, ElvTrue);
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
808 o_undolevels(buf) = 0;
809
810 /* Execute the initialization buffer (which may create some windows) */
811 doexrc();
812
813 /* Load the verbose messages, plus a few others */
814 if (((lc = getenv("LC_ALL")) != NULL && *lc)
815 || ((lc = getenv("LC_MESSAGES")) != NULL && *lc)
816 || ((lc = getenv("LANG")) != NULL && *lc))
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
817 {
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
818 /* Try to find "elvis.msg" in a locale-dependent subdirectory.
819 * If you can't find it there, then look for the standard one.
820 */
821 strcpy(lcfile, dirpath(lc, MSG_FILE));
822 buf = bufpath(o_elvispath, lcfile, toCHAR(MSG_BUF));
823 if (!buf || o_bufchars(buf) == 0)
824 {
825 (void)bufpath(o_elvispath, MSG_FILE, toCHAR(MSG_BUF));
826 }
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
827 }
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
828 else
829 {
830 /* just use the standard versbose messages */
831 (void)bufpath(o_elvispath, MSG_FILE, toCHAR(MSG_BUF));
832 }
833 (void)bufpath(o_elvispath, BEFOREREAD_FILE, toCHAR(BEFOREREAD_BUF));
834 (void)bufpath(o_elvispath, AFTERREAD_FILE, toCHAR(AFTERREAD_BUF));
835 (void)bufpath(o_elvispath, BEFOREWRITE_FILE, toCHAR(BEFOREWRITE_BUF));
836 (void)bufpath(o_elvispath, AFTERWRITE_FILE, toCHAR(AFTERWRITE_BUF));
837
838 /* Store the filename arguments in a list */
839 buildargs(argc, argv);
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
840
2fe6e17 @mbert Import Elvis 2.2_1 (written by Steve Kirkendall)
authored
841 #ifdef FEATURE_PERSIST
842 bufpersistinit();
843 #endif
844
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
845 /* start the first file (i.e., make sure we have at least 1 window) */
846 startfirst();
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
847
848 #ifdef FEATURE_AUTOCMD
2fe6e17 @mbert Import Elvis 2.2_1 (written by Steve Kirkendall)
authored
849 /* if the user interface appears to be graphical, then do a GuiEnter
850 * event.
851 */
852 if (gui->movecost == 0 && gui->retitle)
853 auperform(windefault, ElvFalse, NULL, AU_GUIENTER, NULL);
854
855 /* if the normal background color has been set, then do a BgChanged
856 * event so highlight colors can be chosen relative the current
857 * background color.
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
858 */
859 if (colorinfo[COLOR_FONT_NORMAL].da.bits & COLOR_BG)
860 (void)auperform(windefault, ElvFalse, NULL, AU_BGCHANGED,
861 toCHAR(colorinfo[COLOR_FONT_NORMAL].da.bg_rgb[0] +
862 colorinfo[COLOR_FONT_NORMAL].da.bg_rgb[1] +
863 colorinfo[COLOR_FONT_NORMAL].da.bg_rgb[2]>=384
864 ? "light"
865 : "dark"));
866 #endif
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
867 }
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
868
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
869 /* Terminate elvis. By the time this function is called, all windows have
870 * been closed, and hence any buffers that can be discarded have been.
871 */
872 void term()
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
873 {
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
874 #ifdef DEBUG_ALLOC
875 int i;
8d1ac0c @mbert Import Elvis 2.1 (written by Steve Kirkendall)
authored
876 BUFFER buf, next;
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
877 #endif
878
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
879 /* Call the GUI's term() function */
880 gui->term();
881 gui = NULL;
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
882
2fe6e17 @mbert Import Elvis 2.2_1 (written by Steve Kirkendall)
authored
883 bufpersistsave(NULL);
884
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
885 /* Flush any final messages */
886 msgflush();
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
887
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
888 #ifdef DEBUG_ALLOC
889 /* Free the args list so it isn't reported as a memory leak */
890 for (i = 0; arglist[i]; i++)
891 safefree(arglist[i]);
892 safefree(arglist);
8d1ac0c @mbert Import Elvis 2.1 (written by Steve Kirkendall)
authored
893
894 /* Free all the buffers so they aren't reported as memory leaks */
895 for (buf = ((BUFFER)0); buf; buf = next)
896 {
897 next = buflist(buf);
898 if (!o_internal(buf))
899 buffree(buf);
900 }
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
901
902 # ifdef FEATURE_SPELL
903 /* free the spelling dictionaries */
904 spellfree(spelltags);
905 spellfree(spellwords);
906 # endif
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
907 #endif
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
908
8d1ac0c @mbert Import Elvis 2.1 (written by Steve Kirkendall)
authored
909 /* Close the session */
910 sesclose();
911
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
912 /* Check for any memory leaks */
913 safeterm();
914 }
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
915
8d1ac0c @mbert Import Elvis 2.1 (written by Steve Kirkendall)
authored
916 int main(argc, argv)
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
917 int argc; /* number of command-line arguments */
918 char **argv; /* values of the command-line arguments */
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
919 {
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored
920 init(argc, argv);
921 (*gui->loop)();
922 term();
923 #if !defined (GUI_WIN32)
924 exit((int)o_exitcode);
925 #endif
8d1ac0c @mbert Import Elvis 2.1 (written by Steve Kirkendall)
authored
926 return (int)o_exitcode;
6335386 @mbert Import Elvis 1.8 (written by Steve Kirkendall)
authored
927 }
Something went wrong with that request. Please try again.