1*84d9c625SLionel Sambuc /* $NetBSD: main.c,v 1.4 2013/09/04 19:44:21 tron Exp $ */
2f7cf2976SLionel Sambuc
3f7cf2976SLionel Sambuc /*
4*84d9c625SLionel Sambuc * Copyright (C) 1984-2012 Mark Nudelman
5f7cf2976SLionel Sambuc *
6f7cf2976SLionel Sambuc * You may distribute under the terms of either the GNU General Public
7f7cf2976SLionel Sambuc * License or the Less License, as specified in the README file.
8f7cf2976SLionel Sambuc *
9*84d9c625SLionel Sambuc * For more information, see the README file.
10f7cf2976SLionel Sambuc */
11f7cf2976SLionel Sambuc
12f7cf2976SLionel Sambuc
13f7cf2976SLionel Sambuc /*
14f7cf2976SLionel Sambuc * Entry point, initialization, miscellaneous routines.
15f7cf2976SLionel Sambuc */
16f7cf2976SLionel Sambuc
17f7cf2976SLionel Sambuc #include "less.h"
18f7cf2976SLionel Sambuc #if MSDOS_COMPILER==WIN32C
19f7cf2976SLionel Sambuc #include <windows.h>
20f7cf2976SLionel Sambuc #endif
21f7cf2976SLionel Sambuc
22f7cf2976SLionel Sambuc public char * every_first_cmd = NULL;
23f7cf2976SLionel Sambuc public int new_file;
24f7cf2976SLionel Sambuc public int is_tty;
25f7cf2976SLionel Sambuc public IFILE curr_ifile = NULL_IFILE;
26f7cf2976SLionel Sambuc public IFILE old_ifile = NULL_IFILE;
27f7cf2976SLionel Sambuc public struct scrpos initial_scrpos;
28f7cf2976SLionel Sambuc public int any_display = FALSE;
29f7cf2976SLionel Sambuc public POSITION start_attnpos = NULL_POSITION;
30f7cf2976SLionel Sambuc public POSITION end_attnpos = NULL_POSITION;
31f7cf2976SLionel Sambuc public int wscroll;
32f7cf2976SLionel Sambuc public char * progname;
33f7cf2976SLionel Sambuc public int quitting;
34f7cf2976SLionel Sambuc public int secure;
35f7cf2976SLionel Sambuc public int dohelp;
36f7cf2976SLionel Sambuc public int more_mode = 0;
37f7cf2976SLionel Sambuc
38f7cf2976SLionel Sambuc #if LOGFILE
39f7cf2976SLionel Sambuc public int logfile = -1;
40f7cf2976SLionel Sambuc public int force_logfile = FALSE;
41f7cf2976SLionel Sambuc public char * namelogfile = NULL;
42f7cf2976SLionel Sambuc #endif
43f7cf2976SLionel Sambuc
44f7cf2976SLionel Sambuc #if EDITOR
45f7cf2976SLionel Sambuc public char * editor;
46f7cf2976SLionel Sambuc public char * editproto;
47f7cf2976SLionel Sambuc #endif
48f7cf2976SLionel Sambuc
49f7cf2976SLionel Sambuc #if TAGS
50f7cf2976SLionel Sambuc extern char * tags;
51f7cf2976SLionel Sambuc extern char * tagoption;
52f7cf2976SLionel Sambuc extern int jump_sline;
53f7cf2976SLionel Sambuc #endif
54f7cf2976SLionel Sambuc
55f7cf2976SLionel Sambuc #ifdef WIN32
56f7cf2976SLionel Sambuc static char consoleTitle[256];
57f7cf2976SLionel Sambuc #endif
58f7cf2976SLionel Sambuc
59f7cf2976SLionel Sambuc extern int less_is_more;
60f7cf2976SLionel Sambuc extern int missing_cap;
61f7cf2976SLionel Sambuc extern int know_dumb;
62f7cf2976SLionel Sambuc extern int quit_if_one_screen;
63f7cf2976SLionel Sambuc extern int pr_type;
64f7cf2976SLionel Sambuc
65f7cf2976SLionel Sambuc
66f7cf2976SLionel Sambuc /*
67f7cf2976SLionel Sambuc * Entry point.
68f7cf2976SLionel Sambuc */
69f7cf2976SLionel Sambuc int
main(argc,argv)70f7cf2976SLionel Sambuc main(argc, argv)
71f7cf2976SLionel Sambuc int argc;
72f7cf2976SLionel Sambuc char *argv[];
73f7cf2976SLionel Sambuc {
74f7cf2976SLionel Sambuc IFILE ifile;
75f7cf2976SLionel Sambuc char *s;
76f7cf2976SLionel Sambuc
77f7cf2976SLionel Sambuc #ifdef __EMX__
78f7cf2976SLionel Sambuc _response(&argc, &argv);
79f7cf2976SLionel Sambuc _wildcard(&argc, &argv);
80f7cf2976SLionel Sambuc #endif
81f7cf2976SLionel Sambuc
82f7cf2976SLionel Sambuc progname = *argv++;
83f7cf2976SLionel Sambuc argc--;
84f7cf2976SLionel Sambuc
85f7cf2976SLionel Sambuc secure = 0;
86f7cf2976SLionel Sambuc s = lgetenv("LESSSECURE");
87f7cf2976SLionel Sambuc if (s != NULL && *s != '\0')
88f7cf2976SLionel Sambuc secure = 1;
89f7cf2976SLionel Sambuc
90f7cf2976SLionel Sambuc #ifdef WIN32
91f7cf2976SLionel Sambuc if (getenv("HOME") == NULL)
92f7cf2976SLionel Sambuc {
93f7cf2976SLionel Sambuc /*
94f7cf2976SLionel Sambuc * If there is no HOME environment variable,
95f7cf2976SLionel Sambuc * try the concatenation of HOMEDRIVE + HOMEPATH.
96f7cf2976SLionel Sambuc */
97f7cf2976SLionel Sambuc char *drive = getenv("HOMEDRIVE");
98f7cf2976SLionel Sambuc char *path = getenv("HOMEPATH");
99f7cf2976SLionel Sambuc if (drive != NULL && path != NULL)
100f7cf2976SLionel Sambuc {
101f7cf2976SLionel Sambuc char *env = (char *) ecalloc(strlen(drive) +
102f7cf2976SLionel Sambuc strlen(path) + 6, sizeof(char));
103f7cf2976SLionel Sambuc strcpy(env, "HOME=");
104f7cf2976SLionel Sambuc strcat(env, drive);
105f7cf2976SLionel Sambuc strcat(env, path);
106f7cf2976SLionel Sambuc putenv(env);
107f7cf2976SLionel Sambuc }
108f7cf2976SLionel Sambuc }
109f7cf2976SLionel Sambuc GetConsoleTitle(consoleTitle, sizeof(consoleTitle)/sizeof(char));
110f7cf2976SLionel Sambuc #endif /* WIN32 */
111f7cf2976SLionel Sambuc
112f7cf2976SLionel Sambuc /*
113f7cf2976SLionel Sambuc * Process command line arguments and LESS environment arguments.
114f7cf2976SLionel Sambuc * Command line arguments override environment arguments.
115f7cf2976SLionel Sambuc */
116f7cf2976SLionel Sambuc if (strcmp(getprogname(), "more") == 0)
117f7cf2976SLionel Sambuc more_mode = 1;
118f7cf2976SLionel Sambuc
119f7cf2976SLionel Sambuc is_tty = isatty(1);
120f7cf2976SLionel Sambuc get_term();
121f7cf2976SLionel Sambuc init_cmds();
122f7cf2976SLionel Sambuc init_charset();
123f7cf2976SLionel Sambuc init_line();
124f7cf2976SLionel Sambuc init_cmdhist();
125f7cf2976SLionel Sambuc init_option();
126f7cf2976SLionel Sambuc init_search();
127f7cf2976SLionel Sambuc
128f7cf2976SLionel Sambuc /*
129f7cf2976SLionel Sambuc * If the name of the executable program is "more",
130f7cf2976SLionel Sambuc * act like LESS_IS_MORE is set.
131f7cf2976SLionel Sambuc */
132f7cf2976SLionel Sambuc for (s = progname + strlen(progname); s > progname; s--)
133f7cf2976SLionel Sambuc {
134f7cf2976SLionel Sambuc if (s[-1] == PATHNAME_SEP[0])
135f7cf2976SLionel Sambuc break;
136f7cf2976SLionel Sambuc }
137f7cf2976SLionel Sambuc if (strcmp(s, "more") == 0)
138f7cf2976SLionel Sambuc less_is_more = 1;
139f7cf2976SLionel Sambuc
140f7cf2976SLionel Sambuc init_prompt();
141f7cf2976SLionel Sambuc
142f7cf2976SLionel Sambuc s = lgetenv(less_is_more ? "MORE" : "LESS");
143f7cf2976SLionel Sambuc if (s != NULL)
144f7cf2976SLionel Sambuc scan_option(save(s));
145f7cf2976SLionel Sambuc
146f7cf2976SLionel Sambuc #define isoptstring(s) (((s)[0] == '-' || (s)[0] == '+') && (s)[1] != '\0')
147f7cf2976SLionel Sambuc while (argc > 0 && (isoptstring(*argv) || isoptpending()))
148f7cf2976SLionel Sambuc {
149f7cf2976SLionel Sambuc s = *argv++;
150f7cf2976SLionel Sambuc argc--;
151f7cf2976SLionel Sambuc if (strcmp(s, "--") == 0)
152f7cf2976SLionel Sambuc break;
153f7cf2976SLionel Sambuc scan_option(s);
154f7cf2976SLionel Sambuc }
155f7cf2976SLionel Sambuc #undef isoptstring
156f7cf2976SLionel Sambuc
157f7cf2976SLionel Sambuc if (isoptpending())
158f7cf2976SLionel Sambuc {
159f7cf2976SLionel Sambuc /*
160f7cf2976SLionel Sambuc * Last command line option was a flag requiring a
161f7cf2976SLionel Sambuc * following string, but there was no following string.
162f7cf2976SLionel Sambuc */
163f7cf2976SLionel Sambuc nopendopt();
164f7cf2976SLionel Sambuc quit(QUIT_OK);
165f7cf2976SLionel Sambuc }
166f7cf2976SLionel Sambuc
167f7cf2976SLionel Sambuc if (less_is_more && get_quit_at_eof())
168f7cf2976SLionel Sambuc quit_if_one_screen = TRUE;
169f7cf2976SLionel Sambuc
170f7cf2976SLionel Sambuc #if EDITOR
171f7cf2976SLionel Sambuc editor = lgetenv("VISUAL");
172f7cf2976SLionel Sambuc if (editor == NULL || *editor == '\0')
173f7cf2976SLionel Sambuc {
174f7cf2976SLionel Sambuc editor = lgetenv("EDITOR");
175f7cf2976SLionel Sambuc if (editor == NULL || *editor == '\0')
176f7cf2976SLionel Sambuc editor = EDIT_PGM;
177f7cf2976SLionel Sambuc }
178f7cf2976SLionel Sambuc editproto = lgetenv("LESSEDIT");
179f7cf2976SLionel Sambuc if (editproto == NULL || *editproto == '\0')
180f7cf2976SLionel Sambuc editproto = "%E ?lm+%lm. %f";
181f7cf2976SLionel Sambuc #endif
182f7cf2976SLionel Sambuc
183f7cf2976SLionel Sambuc /*
184f7cf2976SLionel Sambuc * Call get_ifile with all the command line filenames
185f7cf2976SLionel Sambuc * to "register" them with the ifile system.
186f7cf2976SLionel Sambuc */
187f7cf2976SLionel Sambuc ifile = NULL_IFILE;
188f7cf2976SLionel Sambuc if (dohelp)
189f7cf2976SLionel Sambuc ifile = get_ifile(FAKE_HELPFILE, ifile);
190f7cf2976SLionel Sambuc while (argc-- > 0)
191f7cf2976SLionel Sambuc {
192f7cf2976SLionel Sambuc char *filename;
193f7cf2976SLionel Sambuc #if (MSDOS_COMPILER && MSDOS_COMPILER != DJGPPC)
194f7cf2976SLionel Sambuc /*
195f7cf2976SLionel Sambuc * Because the "shell" doesn't expand filename patterns,
196f7cf2976SLionel Sambuc * treat each argument as a filename pattern rather than
197f7cf2976SLionel Sambuc * a single filename.
198f7cf2976SLionel Sambuc * Expand the pattern and iterate over the expanded list.
199f7cf2976SLionel Sambuc */
200f7cf2976SLionel Sambuc struct textlist tlist;
201f7cf2976SLionel Sambuc char *gfilename;
202f7cf2976SLionel Sambuc
203f7cf2976SLionel Sambuc gfilename = lglob(*argv++);
204f7cf2976SLionel Sambuc init_textlist(&tlist, gfilename);
205f7cf2976SLionel Sambuc filename = NULL;
206f7cf2976SLionel Sambuc while ((filename = forw_textlist(&tlist, filename)) != NULL)
207f7cf2976SLionel Sambuc {
208f7cf2976SLionel Sambuc (void) get_ifile(filename, ifile);
209f7cf2976SLionel Sambuc ifile = prev_ifile(NULL_IFILE);
210f7cf2976SLionel Sambuc }
211f7cf2976SLionel Sambuc free(gfilename);
212f7cf2976SLionel Sambuc #else
213f7cf2976SLionel Sambuc filename = shell_quote(*argv);
214f7cf2976SLionel Sambuc if (filename == NULL)
215f7cf2976SLionel Sambuc filename = *argv;
216f7cf2976SLionel Sambuc argv++;
217f7cf2976SLionel Sambuc (void) get_ifile(filename, ifile);
218f7cf2976SLionel Sambuc ifile = prev_ifile(NULL_IFILE);
219*84d9c625SLionel Sambuc free(filename);
220f7cf2976SLionel Sambuc #endif
221f7cf2976SLionel Sambuc }
222f7cf2976SLionel Sambuc /*
223f7cf2976SLionel Sambuc * Set up terminal, etc.
224f7cf2976SLionel Sambuc */
225f7cf2976SLionel Sambuc if (!is_tty)
226f7cf2976SLionel Sambuc {
227f7cf2976SLionel Sambuc /*
228f7cf2976SLionel Sambuc * Output is not a tty.
229f7cf2976SLionel Sambuc * Just copy the input file(s) to output.
230f7cf2976SLionel Sambuc */
231f7cf2976SLionel Sambuc SET_BINARY(1);
232f7cf2976SLionel Sambuc if (nifile() == 0)
233f7cf2976SLionel Sambuc {
234f7cf2976SLionel Sambuc if (edit_stdin() == 0)
235f7cf2976SLionel Sambuc cat_file();
236f7cf2976SLionel Sambuc } else if (edit_first() == 0)
237f7cf2976SLionel Sambuc {
238f7cf2976SLionel Sambuc do {
239f7cf2976SLionel Sambuc cat_file();
240f7cf2976SLionel Sambuc } while (edit_next(1) == 0);
241f7cf2976SLionel Sambuc }
242f7cf2976SLionel Sambuc quit(QUIT_OK);
243f7cf2976SLionel Sambuc }
244f7cf2976SLionel Sambuc
245f7cf2976SLionel Sambuc if (missing_cap && !know_dumb && !more_mode)
246f7cf2976SLionel Sambuc error("WARNING: terminal is not fully functional", NULL_PARG);
247f7cf2976SLionel Sambuc init_mark();
248f7cf2976SLionel Sambuc open_getchr();
249f7cf2976SLionel Sambuc raw_mode(1);
250f7cf2976SLionel Sambuc init_signals(1);
251f7cf2976SLionel Sambuc
252f7cf2976SLionel Sambuc /*
253f7cf2976SLionel Sambuc * Select the first file to examine.
254f7cf2976SLionel Sambuc */
255f7cf2976SLionel Sambuc #if TAGS
256f7cf2976SLionel Sambuc if (tagoption != NULL || strcmp(tags, "-") == 0)
257f7cf2976SLionel Sambuc {
258f7cf2976SLionel Sambuc /*
259f7cf2976SLionel Sambuc * A -t option was given.
260f7cf2976SLionel Sambuc * Verify that no filenames were also given.
261f7cf2976SLionel Sambuc * Edit the file selected by the "tags" search,
262f7cf2976SLionel Sambuc * and search for the proper line in the file.
263f7cf2976SLionel Sambuc */
264f7cf2976SLionel Sambuc if (nifile() > 0)
265f7cf2976SLionel Sambuc {
266f7cf2976SLionel Sambuc error("No filenames allowed with -t option", NULL_PARG);
267f7cf2976SLionel Sambuc quit(QUIT_ERROR);
268f7cf2976SLionel Sambuc }
269f7cf2976SLionel Sambuc findtag(tagoption);
270f7cf2976SLionel Sambuc if (edit_tagfile()) /* Edit file which contains the tag */
271f7cf2976SLionel Sambuc quit(QUIT_ERROR);
272f7cf2976SLionel Sambuc /*
273f7cf2976SLionel Sambuc * Search for the line which contains the tag.
274f7cf2976SLionel Sambuc * Set up initial_scrpos so we display that line.
275f7cf2976SLionel Sambuc */
276f7cf2976SLionel Sambuc initial_scrpos.pos = tagsearch();
277f7cf2976SLionel Sambuc if (initial_scrpos.pos == NULL_POSITION)
278f7cf2976SLionel Sambuc quit(QUIT_ERROR);
279f7cf2976SLionel Sambuc initial_scrpos.ln = jump_sline;
280f7cf2976SLionel Sambuc } else
281f7cf2976SLionel Sambuc #endif
282f7cf2976SLionel Sambuc if (nifile() == 0)
283f7cf2976SLionel Sambuc {
284f7cf2976SLionel Sambuc if (edit_stdin()) /* Edit standard input */
285f7cf2976SLionel Sambuc quit(QUIT_ERROR);
286f7cf2976SLionel Sambuc } else
287f7cf2976SLionel Sambuc {
288f7cf2976SLionel Sambuc if (edit_first()) /* Edit first valid file in cmd line */
289f7cf2976SLionel Sambuc quit(QUIT_ERROR);
290f7cf2976SLionel Sambuc }
291f7cf2976SLionel Sambuc
292f7cf2976SLionel Sambuc init();
293f7cf2976SLionel Sambuc commands();
294f7cf2976SLionel Sambuc quit(QUIT_OK);
295f7cf2976SLionel Sambuc /*NOTREACHED*/
296f7cf2976SLionel Sambuc return (0);
297f7cf2976SLionel Sambuc }
298f7cf2976SLionel Sambuc
299f7cf2976SLionel Sambuc /*
300f7cf2976SLionel Sambuc * Copy a string to a "safe" place
301f7cf2976SLionel Sambuc * (that is, to a buffer allocated by calloc).
302f7cf2976SLionel Sambuc */
303f7cf2976SLionel Sambuc public char *
save(s)304f7cf2976SLionel Sambuc save(s)
305f7cf2976SLionel Sambuc char *s;
306f7cf2976SLionel Sambuc {
307f7cf2976SLionel Sambuc register char *p;
308f7cf2976SLionel Sambuc
309f7cf2976SLionel Sambuc p = (char *) ecalloc(strlen(s)+1, sizeof(char));
310f7cf2976SLionel Sambuc strcpy(p, s);
311f7cf2976SLionel Sambuc return (p);
312f7cf2976SLionel Sambuc }
313f7cf2976SLionel Sambuc
314f7cf2976SLionel Sambuc /*
315f7cf2976SLionel Sambuc * Allocate memory.
316f7cf2976SLionel Sambuc * Like calloc(), but never returns an error (NULL).
317f7cf2976SLionel Sambuc */
318f7cf2976SLionel Sambuc public VOID_POINTER
ecalloc(count,size)319f7cf2976SLionel Sambuc ecalloc(count, size)
320f7cf2976SLionel Sambuc int count;
321f7cf2976SLionel Sambuc unsigned int size;
322f7cf2976SLionel Sambuc {
323f7cf2976SLionel Sambuc register VOID_POINTER p;
324f7cf2976SLionel Sambuc
325f7cf2976SLionel Sambuc p = (VOID_POINTER) calloc(count, size);
326f7cf2976SLionel Sambuc if (p != NULL)
327f7cf2976SLionel Sambuc return (p);
328f7cf2976SLionel Sambuc error("Cannot allocate memory", NULL_PARG);
329f7cf2976SLionel Sambuc quit(QUIT_ERROR);
330f7cf2976SLionel Sambuc /*NOTREACHED*/
331f7cf2976SLionel Sambuc return (NULL);
332f7cf2976SLionel Sambuc }
333f7cf2976SLionel Sambuc
334f7cf2976SLionel Sambuc /*
335f7cf2976SLionel Sambuc * Skip leading spaces in a string.
336f7cf2976SLionel Sambuc */
337f7cf2976SLionel Sambuc public char *
skipsp(s)338f7cf2976SLionel Sambuc skipsp(s)
339f7cf2976SLionel Sambuc register char *s;
340f7cf2976SLionel Sambuc {
341f7cf2976SLionel Sambuc while (*s == ' ' || *s == '\t')
342f7cf2976SLionel Sambuc s++;
343f7cf2976SLionel Sambuc return (s);
344f7cf2976SLionel Sambuc }
345f7cf2976SLionel Sambuc
346f7cf2976SLionel Sambuc /*
347f7cf2976SLionel Sambuc * See how many characters of two strings are identical.
348f7cf2976SLionel Sambuc * If uppercase is true, the first string must begin with an uppercase
349f7cf2976SLionel Sambuc * character; the remainder of the first string may be either case.
350f7cf2976SLionel Sambuc */
351f7cf2976SLionel Sambuc public int
sprefix(ps,s,uppercase)352f7cf2976SLionel Sambuc sprefix(ps, s, uppercase)
353f7cf2976SLionel Sambuc char *ps;
354f7cf2976SLionel Sambuc char *s;
355f7cf2976SLionel Sambuc int uppercase;
356f7cf2976SLionel Sambuc {
357f7cf2976SLionel Sambuc register int c;
358f7cf2976SLionel Sambuc register int sc;
359f7cf2976SLionel Sambuc register int len = 0;
360f7cf2976SLionel Sambuc
361f7cf2976SLionel Sambuc for ( ; *s != '\0'; s++, ps++)
362f7cf2976SLionel Sambuc {
363f7cf2976SLionel Sambuc c = *ps;
364f7cf2976SLionel Sambuc if (uppercase)
365f7cf2976SLionel Sambuc {
366f7cf2976SLionel Sambuc if (len == 0 && ASCII_IS_LOWER(c))
367f7cf2976SLionel Sambuc return (-1);
368f7cf2976SLionel Sambuc if (ASCII_IS_UPPER(c))
369f7cf2976SLionel Sambuc c = ASCII_TO_LOWER(c);
370f7cf2976SLionel Sambuc }
371f7cf2976SLionel Sambuc sc = *s;
372f7cf2976SLionel Sambuc if (len > 0 && ASCII_IS_UPPER(sc))
373f7cf2976SLionel Sambuc sc = ASCII_TO_LOWER(sc);
374f7cf2976SLionel Sambuc if (c != sc)
375f7cf2976SLionel Sambuc break;
376f7cf2976SLionel Sambuc len++;
377f7cf2976SLionel Sambuc }
378f7cf2976SLionel Sambuc return (len);
379f7cf2976SLionel Sambuc }
380f7cf2976SLionel Sambuc
381f7cf2976SLionel Sambuc /*
382f7cf2976SLionel Sambuc * Exit the program.
383f7cf2976SLionel Sambuc */
384f7cf2976SLionel Sambuc public void
quit(status)385f7cf2976SLionel Sambuc quit(status)
386f7cf2976SLionel Sambuc int status;
387f7cf2976SLionel Sambuc {
388f7cf2976SLionel Sambuc static int save_status;
389f7cf2976SLionel Sambuc
390f7cf2976SLionel Sambuc /*
391f7cf2976SLionel Sambuc * Put cursor at bottom left corner, clear the line,
392f7cf2976SLionel Sambuc * reset the terminal modes, and exit.
393f7cf2976SLionel Sambuc */
394f7cf2976SLionel Sambuc if (status < 0)
395f7cf2976SLionel Sambuc status = save_status;
396f7cf2976SLionel Sambuc else
397f7cf2976SLionel Sambuc save_status = status;
398f7cf2976SLionel Sambuc quitting = 1;
399f7cf2976SLionel Sambuc edit((char*)NULL);
400f7cf2976SLionel Sambuc save_cmdhist();
401f7cf2976SLionel Sambuc if (any_display && is_tty)
402f7cf2976SLionel Sambuc clear_bot();
403f7cf2976SLionel Sambuc deinit();
404f7cf2976SLionel Sambuc flush();
405f7cf2976SLionel Sambuc raw_mode(0);
406f7cf2976SLionel Sambuc #if MSDOS_COMPILER && MSDOS_COMPILER != DJGPPC
407f7cf2976SLionel Sambuc /*
408f7cf2976SLionel Sambuc * If we don't close 2, we get some garbage from
409f7cf2976SLionel Sambuc * 2's buffer when it flushes automatically.
410f7cf2976SLionel Sambuc * I cannot track this one down RB
411f7cf2976SLionel Sambuc * The same bug shows up if we use ^C^C to abort.
412f7cf2976SLionel Sambuc */
413f7cf2976SLionel Sambuc close(2);
414f7cf2976SLionel Sambuc #endif
415f7cf2976SLionel Sambuc #ifdef WIN32
416f7cf2976SLionel Sambuc SetConsoleTitle(consoleTitle);
417f7cf2976SLionel Sambuc #endif
418f7cf2976SLionel Sambuc close_getchr();
419f7cf2976SLionel Sambuc exit(status);
420f7cf2976SLionel Sambuc }
421