termcap.c, tty.c: Some does not's
[s-mailx.git] / main.c
blobd88bd4e6788837ba59b46fb4b8486d4466327716
1 /*@ S-nail - a mail user agent derived from Berkeley Mail.
2 *@ Startup and initialization.
3 *@ This file is also used to materialize externals.
5 * Copyright (c) 2000-2004 Gunnar Ritter, Freiburg i. Br., Germany.
6 * Copyright (c) 2012 - 2017 Steffen (Daode) Nurpmeso <steffen@sdaoden.eu>.
7 */
8 /*
9 * Copyright (c) 1980, 1993
10 * The Regents of the University of California. All rights reserved.
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 * 3. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
36 #undef n_FILE
37 #define n_FILE main
38 #define n_MAIN_SOURCE
40 #include "nail.h"
42 #include <sys/ioctl.h>
44 #include <pwd.h>
46 struct a_arg{
47 struct a_arg *aa_next;
48 char const *aa_file;
51 /* (extern, but not with amalgamation, so define here) */
52 VL char const n_weekday_names[7 + 1][4] = {
53 "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", ""
55 VL char const n_month_names[12 + 1][4] = {
56 "Jan", "Feb", "Mar", "Apr", "May", "Jun",
57 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", ""
59 VL char const n_uagent[sizeof VAL_UAGENT] = VAL_UAGENT;
60 VL char const n_error[sizeof n_ERROR] = N_(n_ERROR);
61 VL char const n_path_devnull[sizeof n_PATH_DEVNULL] = n_PATH_DEVNULL;
62 VL char const n_reproducible_name[sizeof "reproducible_build"] =
63 "reproducible_build";
64 VL char const n_unirepl[sizeof n_UNIREPL] = n_UNIREPL;
65 VL char const n_empty[1] = "";
66 VL char const n_0[2] = "0";
67 VL char const n_1[2] = "1";
68 VL char const n_m1[3] = "-1";
69 VL char const n_qm[2] = "?";
70 VL char const n_em[2] = "!";
71 VL char const n_star[2] = "*";
72 VL char const n_at[2] = "@";
73 VL char const n_ns[2] = "#";
74 VL ui16_t const n_class_char[1 + 0x7F] = {
75 #define a_BC C_BLANK | C_CNTRL
76 #define a_SC C_SPACE | C_CNTRL
77 #define a_WC C_WHITE | C_CNTRL
78 /* 000 nul 001 soh 002 stx 003 etx 004 eot 005 enq 006 ack 007 bel */
79 C_CNTRL, C_CNTRL, C_CNTRL, C_CNTRL, C_CNTRL, C_CNTRL, C_CNTRL, C_CNTRL,
80 /* 010 bs 011 ht 012 nl 013 vt 014 np 015 cr 016 so 017 si */
81 C_CNTRL, a_BC, a_WC, a_SC, a_SC, a_SC, C_CNTRL, C_CNTRL,
82 /* 020 dle 021 dc1 022 dc2 023 dc3 024 dc4 025 nak 026 syn 027 etb */
83 C_CNTRL, C_CNTRL, C_CNTRL, C_CNTRL, C_CNTRL, C_CNTRL, C_CNTRL, C_CNTRL,
84 /* 030 can 031 em 032 sub 033 esc 034 fs 035 gs 036 rs 037 us */
85 C_CNTRL, C_CNTRL, C_CNTRL, C_CNTRL, C_CNTRL, C_CNTRL, C_CNTRL, C_CNTRL,
86 #undef a_WC
87 #undef a_SC
88 #undef a_BC
89 /* 040 sp 041 ! 042 " 043 # 044 $ 045 % 046 & 047 ' */
90 C_BLANK, C_PUNCT, C_PUNCT, C_PUNCT, C_PUNCT, C_PUNCT, C_PUNCT, C_PUNCT,
91 /* 050 ( 051 ) 052 * 053 + 054 , 055 - 056 . 057 / */
92 C_PUNCT, C_PUNCT, C_PUNCT, C_PUNCT, C_PUNCT, C_PUNCT, C_PUNCT, C_PUNCT,
93 /* 060 0 061 1 062 2 063 3 064 4 065 5 066 6 067 7 */
94 C_OCTAL, C_OCTAL, C_OCTAL, C_OCTAL, C_OCTAL, C_OCTAL, C_OCTAL, C_OCTAL,
95 /* 070 8 071 9 072 : 073 ; 074 < 075 = 076 > 077 ? */
96 C_DIGIT, C_DIGIT, C_PUNCT, C_PUNCT, C_PUNCT, C_PUNCT, C_PUNCT, C_PUNCT,
97 /* 100 @ 101 A 102 B 103 C 104 D 105 E 106 F 107 G */
98 C_PUNCT, C_UPPER, C_UPPER, C_UPPER, C_UPPER, C_UPPER, C_UPPER, C_UPPER,
99 /* 110 H 111 I 112 J 113 K 114 L 115 M 116 N 117 O */
100 C_UPPER, C_UPPER, C_UPPER, C_UPPER, C_UPPER, C_UPPER, C_UPPER, C_UPPER,
101 /* 120 P 121 Q 122 R 123 S 124 T 125 U 126 V 127 W */
102 C_UPPER, C_UPPER, C_UPPER, C_UPPER, C_UPPER, C_UPPER, C_UPPER, C_UPPER,
103 /* 130 X 131 Y 132 Z 133 [ 134 \ 135 ] 136 ^ 137 _ */
104 C_UPPER, C_UPPER, C_UPPER, C_PUNCT, C_PUNCT, C_PUNCT, C_PUNCT, C_PUNCT,
105 /* 140 ` 141 a 142 b 143 c 144 d 145 e 146 f 147 g */
106 C_PUNCT, C_LOWER, C_LOWER, C_LOWER, C_LOWER, C_LOWER, C_LOWER, C_LOWER,
107 /* 150 h 151 i 152 j 153 k 154 l 155 m 156 n 157 o */
108 C_LOWER, C_LOWER, C_LOWER, C_LOWER, C_LOWER, C_LOWER, C_LOWER, C_LOWER,
109 /* 160 p 161 q 162 r 163 s 164 t 165 u 166 v 167 w */
110 C_LOWER, C_LOWER, C_LOWER, C_LOWER, C_LOWER, C_LOWER, C_LOWER, C_LOWER,
111 /* 170 x 171 y 172 z 173 { 174 | 175 } 176 ~ 177 del */
112 C_LOWER, C_LOWER, C_LOWER, C_PUNCT, C_PUNCT, C_PUNCT, C_PUNCT, C_CNTRL
115 /* Our own little getopt(3) */
116 static char const *a_main_oarg;
117 static int a_main_oind, /*_oerr,*/ a_main_oopt;
119 /* Our own little getopt(3); note --help is special-treated as 'h' */
120 static int a_main_getopt(int argc, char * const argv[], char const *optstring);
122 /* */
123 static void a_main_usage(FILE *fp);
125 /* Perform basic startup initialization */
126 static void a_main_startup(void);
128 /* Grow a char** */
129 static size_t a_main_grow_cpp(char const ***cpp, size_t newsize, size_t oldcnt);
131 /* Setup some variables which we require to be valid / verified */
132 static void a_main_setup_vars(void);
134 /* We're in an interactive session - compute what the screen size for printing
135 * headers etc. should be; notify tty upon resize if *is_sighdl* is not 0.
136 * We use the following algorithm for the height:
137 * If baud rate < 1200, use 9
138 * If baud rate = 1200, use 14
139 * If baud rate > 1200, use 24 or ws_row
140 * Width is either 80 or ws_col */
141 static void a_main_setscreensize(int is_sighdl);
143 /* Ok, we are reading mail. Decide whether we are editing a mailbox or reading
144 * the system mailbox, and open up the right stuff */
145 static int a_main_rcv_mode(char const *folder, char const *Larg);
147 /* Interrupt printing of the headers */
148 static void a_main_hdrstop(int signo);
150 static int
151 a_main_getopt(int argc, char * const argv[], char const *optstring){
152 static char const *lastp;
153 char const *curp;
154 int rv/*, colon*/;
155 NYD2_ENTER;
157 a_main_oarg = NULL;
158 rv = -1;
160 /*if((colon = (optstring[0] == ':')))
161 ++optstring;*/
163 if(lastp != NULL){
164 curp = lastp;
165 lastp = NULL;
166 }else{
167 if(a_main_oind >= argc || argv[a_main_oind] == NULL ||
168 argv[a_main_oind][0] != '-' || argv[a_main_oind][1] == '\0')
169 goto jleave;
170 if(argv[a_main_oind][1] == '-' && argv[a_main_oind][2] == '\0'){
171 /* We need this in for MTA arg detection (easier) ++a_main_oind;*/
172 goto jleave;
174 curp = &argv[a_main_oind][1];
177 for(a_main_oopt = curp[0]; optstring[0] != '\0';){
178 if(optstring[0] != a_main_oopt){
179 optstring += 1 + (optstring[1] == ':');
180 continue;
183 if(optstring[1] == ':'){
184 if(curp[1] != '\0'){
185 a_main_oarg = n_UNCONST(curp + 1);
186 ++a_main_oind;
187 }else{
188 if((a_main_oind += 2) > argc){
189 /*if(!colon *//*&& _oerr*//*)*/{
190 n_err(_("%s: option requires an argument -- %c\n"),
191 argv[0], (char)a_main_oopt);
193 rv = (/*colon ? ':' :*/ '?');
194 goto jleave;
196 a_main_oarg = argv[a_main_oind - 1];
198 }else{
199 if(curp[1] != '\0')
200 lastp = curp + 1;
201 else
202 ++a_main_oind;
204 rv = a_main_oopt;
205 goto jleave;
208 /* Special support for --help, which is quite common */
209 if(a_main_oopt == '-' && !strcmp(curp, "-help") &&
210 &curp[-1] == argv[a_main_oind]){
211 ++a_main_oind;
212 rv = 'h';
213 goto jleave;
216 /* Definitive error */
217 /*if(!colon *//*&& opterr*//*)*/
218 n_err(_("%s: invalid option -- %c\n"), argv[0], a_main_oopt);
219 if(curp[1] != '\0')
220 lastp = curp + 1;
221 else
222 ++a_main_oind;
223 a_main_oarg = NULL;
224 rv = '?';
225 jleave:
226 NYD2_LEAVE;
227 return rv;
230 static void
231 a_main_usage(FILE *fp){
232 /* Stay in 24 lines */
233 char buf[64];
234 size_t i;
235 NYD2_ENTER;
237 i = strlen(n_progname);
238 i = n_MIN(i, sizeof(buf) -1);
239 if(i > 0)
240 memset(buf, ' ', i);
241 buf[i] = '\0';
243 fprintf(fp, _("%s (%s %s): send and receive Internet mail\n"),
244 n_progname, n_uagent, ok_vlook(version));
245 fprintf(fp, _(
246 "Send-only mode: send mail \"to-address\" receiver(s):\n"
247 " %s [-BdEFinv~#] [-: spec] [-A account]\n"
248 " %s [:-a attachment:] [:-b bcc-address:] [:-c cc-address:]\n"
249 " %s [-M type | -m file | -q file | -t] [-r from-address]\n"
250 " %s [:-S var[=value]:] [-s subject] [:-X cmd:]\n"
251 " %s [-.] :to-address: [-- :mta-option:]\n"),
252 n_progname, buf, buf, buf, buf);
253 fprintf(fp, _(
254 "\"Receive\" mode, starting on -u user, primary *inbox* or [$MAIL]:\n"
255 " %s [-BdEeHiNnRv~#] [-: spec] [-A account]\n"
256 " %s [-L spec] [-r from-address] [:-S var[=value]:]\n"
257 " %s [-u user] [:-X cmd:] [-- :mta-option:]\n"),
258 n_progname, buf, buf);
259 fprintf(fp, _(
260 "\"Receive\" mode, starting on -f (secondary $MBOX or [file]):\n"
261 " %s [-BdEeHiNnRv~#] [-: spec] [-A account] -f\n"
262 " %s [-L spec] [-r from-address] [:-S var[=value]:]\n"
263 " %s [:-X cmd:] [file] [-- :mta-option:]\n"),
264 n_progname, buf, buf);
266 if(fp != n_stderr)
267 putc('\n', fp);
268 fprintf(fp, _(
269 ". -d sandbox, -:/ no .rc files, -. end options and force send-mode\n"
270 ". -a attachment[=input-charset[#output-charset]]\n"
271 ". -b, -c, to-address, (-r): ex@am.ple or '(Lovely) Ex <am@p.le>'\n"
272 ". -[Mmqt]: special input data (-t: template message on stdin)\n"
273 ". -e only mail check, -H header summary; both: specification via -L\n"
274 ". -S sets variables, -X executes commands, -# enters batch mode\n"
275 ". Features: \"$ %s -Xversion -Xx\", WWW: %s\n"
276 ". Mail contact: \"$ %s %s\"\n"),
277 n_progname, ok_vlook(contact_web), n_progname, ok_vlook(contact_mail));
278 NYD2_LEAVE;
281 static void
282 a_main_startup(void){
283 char *cp;
284 NYD_ENTER;
286 n_stdin = stdin;
287 n_stdout = stdout;
288 n_stderr = stderr;
289 dflpipe = SIG_DFL;
291 a_main_oind = /*_oerr =*/ 1;
293 if((cp = strrchr(n_progname, '/')) != NULL)
294 n_progname = ++cp;
296 #ifdef HAVE_NYD
297 safe_signal(SIGABRT, &_nyd_oncrash);
298 # ifdef SIGBUS
299 safe_signal(SIGBUS, &_nyd_oncrash);
300 # endif
301 safe_signal(SIGFPE, &_nyd_oncrash);
302 safe_signal(SIGILL, &_nyd_oncrash);
303 safe_signal(SIGSEGV, &_nyd_oncrash);
304 #endif
306 /* Initialize our input, loop and command machinery */
307 n_go_init();
309 /* Set up a reasonable environment */
311 /* TODO This is wrong: interactive is STDIN/STDERR for a POSIX sh(1).
312 * TODO For now we get this wrong, all over the place, as this software
313 * TODO has always been developed with stdout as an output channel.
314 * TODO Start doing it right for at least explicit terminal-related things,
315 * TODO but v15 should use ONLY this, also for terminal input! */
316 if(isatty(STDIN_FILENO)){
317 n_psonce |= n_PSO_TTYIN;
318 #if defined HAVE_MLE || defined HAVE_TERMCAP
319 n_tty_fp = fdopen(fileno(n_stdin), "w");
320 setvbuf(n_tty_fp, NULL, _IOLBF, 0);
321 #endif
323 if(isatty(STDOUT_FILENO))
324 n_psonce |= n_PSO_TTYOUT;
325 if((n_psonce & (n_PSO_TTYIN | n_PSO_TTYOUT)) ==
326 (n_PSO_TTYIN | n_PSO_TTYOUT)){
327 n_psonce |= n_PSO_INTERACTIVE;
328 safe_signal(SIGPIPE, dflpipe = SIG_IGN);
331 /* STDOUT is always line buffered from our point of view */
332 setvbuf(n_stdout, NULL, _IOLBF, 0);
333 if(n_tty_fp == NULL)
334 n_tty_fp = n_stdout;
336 /* -- >8 -- 8< -- */
338 /* We need the endianess, runtime detected due to OPT_CROSS_BUILD */
339 /* C99 */{
340 union {ui16_t bom; ui8_t buf[2];} volatile u;
342 u.bom = 0xFEFFu;
343 if(u.buf[1] != 0xFEu)
344 n_psonce |= n_PSO_BIG_ENDIAN;
347 n_locale_init();
349 #ifdef HAVE_ICONV
350 iconvd = (iconv_t)-1;
351 #endif
352 NYD_LEAVE;
355 static size_t
356 a_main_grow_cpp(char const ***cpp, size_t newsize, size_t oldcnt){
357 /* Just use auto-reclaimed storage, it will be preserved */
358 char const **newcpp;
359 NYD_ENTER;
361 newcpp = salloc(sizeof(char*) * (newsize + 1));
363 if(oldcnt > 0)
364 memcpy(newcpp, *cpp, oldcnt * sizeof(char*));
365 *cpp = newcpp;
366 NYD_LEAVE;
367 return newsize;
370 static void
371 a_main_setup_vars(void){
372 struct passwd *pwuid;
373 char const *cp;
374 NYD_ENTER;
376 n_group_id = getgid();
377 if((pwuid = getpwuid(n_user_id = getuid())) == NULL)
378 n_panic(_("Cannot associate a name with uid %lu"), (ul_i)n_user_id);
380 /* C99 */{
381 char const *ep;
382 bool_t doenv;
384 if(!(doenv = (ep = ok_vlook(LOGNAME)) == NULL) &&
385 (doenv = (strcmp(pwuid->pw_name, ep) != 0)))
386 n_err(_("Warning: $LOGNAME (%s) not identical to user (%s)!\n"),
387 ep, pwuid->pw_name);
388 if(doenv){
389 n_pstate |= n_PS_ROOT;
390 ok_vset(LOGNAME, pwuid->pw_name);
391 n_pstate &= ~n_PS_ROOT;
394 if((ep = ok_vlook(USER)) != NULL && strcmp(pwuid->pw_name, ep)){
395 n_err(_("Warning: $USER (%s) not identical to user (%s)!\n"),
396 ep, pwuid->pw_name);
397 n_pstate |= n_PS_ROOT;
398 ok_vset(USER, pwuid->pw_name);
399 n_pstate &= ~n_PS_ROOT;
403 /* XXX myfullname = pw->pw_gecos[OPTIONAL!] -> GUT THAT; TODO pw_shell */
405 /* Ensure some variables get loaded and/or verified */
407 /* This is not automatized just as $TMPDIR is for the initial setting, since
408 * we have the pwuid at hand and can simply use it! See accmacvar.c! */
409 if((cp = ok_vlook(HOME)) == NULL){
410 cp = pwuid->pw_dir;
411 n_pstate |= n_PS_ROOT;
412 ok_vset(HOME, cp);
413 n_pstate &= ~n_PS_ROOT;
416 (void)ok_vlook(TMPDIR);
417 (void)ok_blook(POSIXLY_CORRECT);
419 /* Are we in a reproducible-builds.org environment? */
420 if(ok_vlook(SOURCE_DATE_EPOCH) != NULL){
421 n_psonce |= n_PSO_REPRODUCIBLE;
422 n_pstate |= n_PS_ROOT;
423 n_progname = n_reproducible_name;
424 ok_vset(LOGNAME, n_reproducible_name);
425 n_pstate &= ~n_PS_ROOT;
426 cp = savecat(n_reproducible_name, ": ");
427 ok_vset(log_prefix, cp);
430 if(n_psonce & n_PSO_INTERACTIVE){
431 a_main_setscreensize(FAL0);
432 #ifdef SIGWINCH
433 # ifndef TTY_WANTS_SIGWINCH
434 if(safe_signal(SIGWINCH, SIG_IGN) != SIG_IGN)
435 # endif
436 safe_signal(SIGWINCH, &a_main_setscreensize);
437 #endif
438 }else
439 n_scrnheight = n_realscreenheight = 24, n_scrnwidth = 80;
440 NYD_LEAVE;
443 static void
444 a_main_setscreensize(int is_sighdl){/* TODO globl policy; int wraps; minvals! */
445 struct termios tbuf;
446 #ifdef TIOCGWINSZ
447 struct winsize ws;
448 #elif defined TIOCGSIZE
449 struct ttysize ts;
450 #endif
451 NYD_ENTER;
453 n_scrnheight = n_realscreenheight = n_scrnwidth = 0;
455 /* (Also) POSIX: LINES and COLUMNS always override. Adjust this
456 * a little bit to be able to honour resizes during our lifetime and
457 * only honour it upon first run; abuse *is_sighdl* as an indicator */
458 if(!is_sighdl){
459 char const *cp;
461 /* We manage those variables for our child processes, so ensure they
462 * are up to date, always */
463 assert(n_psonce & n_PSO_INTERACTIVE);
464 n_pstate |= n_PS_SIGWINCH_PEND;
466 if((cp = ok_vlook(LINES)) != NULL){
467 n_idec_ui32_cp(&n_scrnheight, cp, 0, NULL);
468 n_realscreenheight = n_scrnheight;
470 if((cp = ok_vlook(COLUMNS)) != NULL)
471 n_idec_ui32_cp(&n_scrnwidth, cp, 0, NULL);
473 if(n_scrnwidth != 0 && n_scrnheight != 0)
474 goto jleave;
477 #ifdef TIOCGWINSZ
478 if(ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws) == -1)
479 ws.ws_col = ws.ws_row = 0;
480 #elif defined TIOCGSIZE
481 if(ioctl(STDOUT_FILENO, TIOCGSIZE, &ws) == -1)
482 ts.ts_lines = ts.ts_cols = 0;
483 #endif
485 if(n_scrnheight == 0){
486 speed_t ospeed;
488 ospeed = ((tcgetattr(fileno(n_tty_fp), &tbuf) == -1)
489 ? B9600 : cfgetospeed(&tbuf));
491 if(ospeed < B1200)
492 n_scrnheight = 9;
493 else if(ospeed == B1200)
494 n_scrnheight = 14;
495 #ifdef TIOCGWINSZ
496 else if(ws.ws_row != 0)
497 n_scrnheight = ws.ws_row;
498 #elif defined TIOCGSIZE
499 else if(ts.ts_lines != 0)
500 n_scrnheight = ts.ts_lines;
501 #endif
502 else
503 n_scrnheight = 24;
505 #if defined TIOCGWINSZ || defined TIOCGSIZE
506 if(0 ==
507 # ifdef TIOCGWINSZ
508 (n_realscreenheight = ws.ws_row)
509 # else
510 (n_realscreenheight = ts.ts_lines)
511 # endif
513 n_realscreenheight = 24;
514 #endif
517 if(n_scrnwidth == 0 && 0 ==
518 #ifdef TIOCGWINSZ
519 (n_scrnwidth = ws.ws_col)
520 #elif defined TIOCGSIZE
521 (n_scrnwidth = ts.ts_cols)
522 #endif
524 n_scrnwidth = 80;
526 jleave:
527 #ifdef SIGWINCH
528 if(is_sighdl){
529 assert(n_psonce & n_PSO_INTERACTIVE);
530 n_pstate |= n_PS_SIGWINCH_PEND; /* XXX Not atomic */
531 n_tty_signal(SIGWINCH);
533 #endif
534 NYD_LEAVE;
537 static sigjmp_buf a_main__hdrjmp; /* XXX */
539 static int
540 a_main_rcv_mode(char const *folder, char const *Larg){
541 int i;
542 sighandler_type prevint;
543 NYD_ENTER;
545 if(folder == NULL)
546 folder = "%";
547 #ifdef HAVE_IMAP
548 else if(*folder == '@'){
549 /* This must be treated specially to make possible invocation like
550 * -A imap -f @mailbox */
551 char const *cp;
553 cp = n_folder_query();
554 if(which_protocol(cp, FAL0, FAL0, NULL) == PROTO_IMAP)
555 n_strscpy(mailname, cp, sizeof mailname);
557 #endif
559 i = (n_poption & n_PO_QUICKRUN_MASK) ? FEDIT_RDONLY : FEDIT_NONE;
560 i = setfile(folder, i);
561 if(i < 0){
562 n_exit_status = n_EXIT_ERR; /* error already reported */
563 goto jquit;
565 if(n_poption & n_PO_QUICKRUN_MASK){
566 n_exit_status = i;
567 if(i == n_EXIT_OK && (!(n_poption & n_PO_EXISTONLY) ||
568 (n_poption & n_PO_HEADERLIST)))
569 print_header_summary(Larg);
570 goto jquit;
572 temporary_folder_hook_check(FAL0);
574 if(i > 0 && !ok_blook(emptystart)){
575 n_exit_status = n_EXIT_ERR;
576 goto jleave;
579 if(sigsetjmp(a_main__hdrjmp, 1) == 0){
580 if((prevint = safe_signal(SIGINT, SIG_IGN)) != SIG_IGN)
581 safe_signal(SIGINT, &a_main_hdrstop);
582 if(!ok_blook(quiet))
583 fprintf(n_stdout, _("%s version %s. Type `?' for help\n"),
584 n_uagent,
585 (n_psonce & n_PSO_REPRODUCIBLE
586 ? n_reproducible_name : ok_vlook(version)));
587 n_folder_announce(n_ANNOUNCE_MAIN_CALL | n_ANNOUNCE_CHANGE);
588 safe_signal(SIGINT, prevint);
591 /* Enter the command loop */
592 if(n_psonce & n_PSO_INTERACTIVE)
593 n_tty_init();
594 n_go_main_loop();
595 if(n_psonce & n_PSO_INTERACTIVE)
596 n_tty_destroy((n_psonce & n_PSO_XIT) != 0);
598 if(!(n_psonce & n_PSO_XIT)){
599 if(mb.mb_type == MB_FILE || mb.mb_type == MB_MAILDIR){
600 safe_signal(SIGHUP, SIG_IGN);
601 safe_signal(SIGINT, SIG_IGN);
602 safe_signal(SIGQUIT, SIG_IGN);
604 jquit:
605 save_mbox_for_possible_quitstuff();
606 quit(FAL0);
608 jleave:
609 NYD_LEAVE;
610 return n_exit_status;
613 static void
614 a_main_hdrstop(int signo){
615 NYD_X; /* Signal handler */
616 n_UNUSED(signo);
618 fflush(n_stdout);
619 n_err_sighdl(_("\nInterrupt\n"));
620 siglongjmp(a_main__hdrjmp, 1);
624 main(int argc, char *argv[]){
625 /* TODO Once v15 control flow/carrier rewrite took place main() should
626 * TODO be rewritten and option parsing++ should be outsourced.
627 * TODO Like so we can get rid of some stack locals etc. */
628 /* Keep in SYNC: ./nail.1:"SYNOPSIS, main() */
629 static char const optstr[] =
630 "A:a:Bb:c:dEeFfHhiL:M:m:NnO:q:Rr:S:s:tu:VvX:::~#.";
631 int i;
632 char *cp;
633 enum{
634 a_RF_NONE = 0,
635 a_RF_SET = 1<<0,
636 a_RF_SYSTEM = 1<<1,
637 a_RF_USER = 1<<2,
638 a_RF_ALL = a_RF_SYSTEM | a_RF_USER
639 } resfiles;
640 size_t oargs_size, oargs_cnt, Xargs_size, Xargs_cnt, smopts_size;
641 char const *Aarg, *emsg, *folder, *Larg, *okey, **oargs, *qf,
642 *subject, *uarg, **Xargs;
643 struct attachment *attach;
644 struct name *to, *cc, *bcc;
645 struct a_arg *a_head, *a_curr;
646 NYD_ENTER;
648 a_head = NULL;
649 n_UNINIT(a_curr, NULL);
650 to = cc = bcc = NULL;
651 attach = NULL;
652 Aarg = emsg = folder = Larg = okey = qf = subject = uarg = NULL;
653 oargs = Xargs = NULL;
654 oargs_size = oargs_cnt = Xargs_size = Xargs_cnt = smopts_size = 0;
655 resfiles = a_RF_ALL;
658 * Start our lengthy setup, finalize by setting n_PSO_STARTED
661 n_progname = argv[0];
662 a_main_startup();
664 /* Command line parsing
665 * -S variable settings need to be done twice, since the user surely wants
666 * the setting to take effect immediately, but also doesn't want it to be
667 * overwritten from within resource files */
668 while((i = a_main_getopt(argc, argv, optstr)) >= 0){
669 switch(i){
670 case 'A':
671 /* Execute an account command later on */
672 Aarg = a_main_oarg;
673 break;
674 case 'a':{
675 struct a_arg *nap;
677 n_psonce |= n_PSO_SENDMODE;
678 nap = salloc(sizeof(struct a_arg));
679 if(a_head == NULL)
680 a_head = nap;
681 else
682 a_curr->aa_next = nap;
683 nap->aa_next = NULL;
684 nap->aa_file = a_main_oarg;
685 a_curr = nap;
686 } break;
687 case 'B':
688 n_OBSOLETE(_("-B is obsolete, please use -# as necessary"));
689 break;
690 case 'b':
691 /* Get Blind Carbon Copy Recipient list */
692 n_psonce |= n_PSO_SENDMODE;
693 bcc = cat(bcc, lextract(a_main_oarg, GBCC | GFULL));
694 break;
695 case 'c':
696 /* Get Carbon Copy Recipient list */
697 n_psonce |= n_PSO_SENDMODE;
698 cc = cat(cc, lextract(a_main_oarg, GCC | GFULL));
699 break;
700 case 'd':
701 ok_bset(debug);
702 okey = "debug";
703 goto joarg;
704 case 'E':
705 n_OBSOLETE(_("-E will be removed, please use \"-Sskipemptybody\""));
706 ok_bset(skipemptybody);
707 okey = "skipemptybody";
708 goto joarg;
709 case 'e':
710 n_poption |= n_PO_EXISTONLY;
711 break;
712 case 'F':
713 n_poption |= n_PO_F_FLAG;
714 n_psonce |= n_PSO_SENDMODE;
715 break;
716 case 'f':
717 /* User is specifying file to "edit" with Mail, as opposed to reading
718 * system mailbox. If no argument is given, we read his mbox file.
719 * Check for remaining arguments later */
720 folder = "&";
721 break;
722 case 'H':
723 n_poption |= n_PO_HEADERSONLY;
724 break;
725 case 'h':
726 a_main_usage(n_stdout);
727 goto j_leave;
728 case 'i':
729 /* Ignore interrupts */
730 ok_bset(ignore);
731 okey = "ignore";
732 goto joarg;
733 case 'L':
734 Larg = a_main_oarg;
735 n_poption |= n_PO_HEADERLIST;
736 if(*Larg == '"' || *Larg == '\''){ /* TODO list.c:listspec_check() */
737 size_t j;
739 j = strlen(++Larg);
740 if(j > 0){
741 cp = savestrbuf(Larg, --j);
742 Larg = cp;
745 break;
746 case 'M':
747 if(qf != NULL && (!(n_poption & n_PO_Mm_FLAG) || qf != (char*)-1))
748 goto jeMmq;
749 n_poption_arg_Mm = a_main_oarg;
750 qf = (char*)-1;
751 if(0){
752 /* FALLTHRU*/
753 case 'm':
754 if(qf != NULL && (!(n_poption & n_PO_Mm_FLAG) || qf == (char*)-1))
755 goto jeMmq;
756 qf = a_main_oarg;
758 n_poption |= n_PO_Mm_FLAG;
759 n_psonce |= n_PSO_SENDMODE;
760 break;
761 case 'N':
762 /* Avoid initial header printing */
763 ok_bclear(header);
764 okey = "noheader";
765 goto joarg;
766 case 'n':
767 /* Don't source "unspecified system start-up file" */
768 if(resfiles & a_RF_SET){
769 emsg = N_("-n cannot be used in conjunction with -:");
770 goto jusage;
772 resfiles = a_RF_USER;
773 break;
774 case 'O':
775 /* Additional options to pass-through to MTA TODO v15-compat legacy */
776 if(n_smopts_cnt == smopts_size)
777 smopts_size = a_main_grow_cpp(&n_smopts, smopts_size + 8,
778 n_smopts_cnt);
779 n_smopts[n_smopts_cnt++] = a_main_oarg;
780 break;
781 case 'q':
782 if(qf != NULL && (n_poption & n_PO_Mm_FLAG)){
783 jeMmq:
784 emsg = N_("Only one of -M, -m or -q may be given");
785 goto jusage;
787 /* Quote file TODO drop? -Q with real quote?? what ? */
788 n_psonce |= n_PSO_SENDMODE;
789 /* Allow for now, we have to special check validity of -q- later on! */
790 qf = (a_main_oarg[0] == '-' && a_main_oarg[1] == '\0')
791 ? (char*)-1 : a_main_oarg;
792 break;
793 case 'R':
794 /* Open folders read-only */
795 n_poption |= n_PO_R_FLAG;
796 break;
797 case 'r':
798 /* Set From address. */
799 n_poption |= n_PO_r_FLAG;
800 if(a_main_oarg[0] != '\0'){
801 struct name *fa;
803 fa = nalloc(a_main_oarg, GSKIN | GFULL | GFULLEXTRA);
804 if(is_addr_invalid(fa, EACM_STRICT | EACM_NOLOG)){
805 emsg = N_("Invalid address argument with -r");
806 goto jusage;
808 n_poption_arg_r = fa;
809 /* TODO -r options is set in n_smopts, but may
810 * TODO be overwritten by setting from= in
811 * TODO an interactive session!
812 * TODO Maybe disable setting of from?
813 * TODO Warn user? Update manual!! */
814 okey = savecat("from=", fa->n_fullname);
815 goto joarg;
817 break;
818 case 'S':
819 /* Set variable (TODO twice [only if successful]) */
820 { char const *a[2];
821 bool_t b;
823 okey = a[0] = a_main_oarg;
824 a[1] = NULL;
825 n_pstate |= n_PS_ROBOT;
826 b = (c_set(a) == 0);
827 n_pstate &= ~n_PS_ROBOT;
828 if(!b)
829 break;
831 joarg:
832 if(oargs_cnt == oargs_size)
833 oargs_size = a_main_grow_cpp(&oargs, oargs_size + 8, oargs_cnt);
834 oargs[oargs_cnt++] = okey;
835 break;
836 case 's':
837 /* Subject:; take care for Debian #419840 and strip any \r and \n */
838 if(n_anyof_cp("\n\r", subject = a_main_oarg)){
839 n_err(_("-s: normalizing away invalid ASCII NL / CR bytes\n"));
840 for(subject = cp = savestr(a_main_oarg); *cp != '\0'; ++cp)
841 if(*cp == '\n' || *cp == '\r')
842 *cp = ' ';
844 n_psonce |= n_PSO_SENDMODE;
845 break;
846 case 't':
847 /* Read defined set of headers from mail to be sent */
848 n_poption |= n_PO_t_FLAG;
849 n_psonce |= n_PSO_SENDMODE;
850 break;
851 case 'u':
852 uarg = savecat("%", a_main_oarg);
853 break;
854 case 'V':
855 fprintf(n_stdout, _("%s version %s\n"), n_uagent, ok_vlook(version));
856 n_exit_status = n_EXIT_OK;
857 goto j_leave;
858 case 'v':
859 /* Be verbose */
860 ok_bset(verbose);
861 okey = "verbose";
862 goto joarg;
863 case 'X':
864 /* Add to list of commands to exec before entering normal operation */
865 if(Xargs_cnt == Xargs_size)
866 Xargs_size = a_main_grow_cpp(&Xargs, Xargs_size + 8, Xargs_cnt);
867 Xargs[Xargs_cnt++] = a_main_oarg;
868 break;
869 case ':':
870 /* Control which resource files shall be loaded */
871 if(!(resfiles & (a_RF_SET | a_RF_SYSTEM))){
872 emsg = N_("-n cannot be used in conjunction with -:");
873 goto jusage;
875 resfiles = a_RF_SET;
876 while((i = *a_main_oarg++) != '\0')
877 switch(i){
878 case 'S': case 's': resfiles |= a_RF_SYSTEM; break;
879 case 'U': case 'u': resfiles |= a_RF_USER; break;
880 case ':': case '/': resfiles &= ~a_RF_ALL; break;
881 default:
882 emsg = N_("Invalid argument of -:");
883 goto jusage;
885 break;
886 case '~':
887 /* Enable command escapes even in non-interactive mode */
888 n_poption |= n_PO_TILDE_FLAG;
889 break;
890 case '#':
891 /* Work in batch mode, even if non-interactive */
892 if(!(n_psonce & n_PSO_INTERACTIVE))
893 setvbuf(n_stdin, NULL, _IOLBF, 0);
894 n_poption |= n_PO_TILDE_FLAG | n_PO_BATCH_FLAG;
895 folder = n_path_devnull;
896 if(oargs_cnt + 10 >= oargs_size)
897 oargs_size = a_main_grow_cpp(&oargs, oargs_size + 11, oargs_cnt);
898 n_pstate |= n_PS_ROBOT; /* (be silent unsetting undefined variables) */
899 ok_vset(MAIL, folder), oargs[oargs_cnt++] = "MAIL=" n_PATH_DEVNULL;
900 ok_vset(MBOX, folder), oargs[oargs_cnt++] = "MBOX=" n_PATH_DEVNULL;
901 ok_bset(emptystart), oargs[oargs_cnt++] = "emptystart";
902 ok_bclear(errexit), oargs[oargs_cnt++] = "noerrexit";
903 ok_bclear(header), oargs[oargs_cnt++] = "noheader";
904 ok_vset(inbox, folder), oargs[oargs_cnt++] = "inbox=" n_PATH_DEVNULL;
905 ok_bclear(posix), oargs[oargs_cnt++] = "noposix";
906 ok_bset(quiet), oargs[oargs_cnt++] = "quiet";
907 ok_bset(sendwait), oargs[oargs_cnt++] = "sendwait";
908 ok_bset(typescript_mode), oargs[oargs_cnt++] = "typescript-mode";
909 n_pstate &= ~n_PS_ROBOT;
910 break;
911 case '.':
912 n_psonce |= n_PSO_SENDMODE;
913 goto jgetopt_done;
914 case '?':
915 jusage:
916 if(emsg != NULL)
917 n_err("%s\n", V_(emsg));
918 a_main_usage(n_stderr);
919 n_exit_status = n_EXIT_USE;
920 goto j_leave;
923 jgetopt_done:
926 /* The normal arguments may be followed by MTA arguments after a "--";
927 * however, -f may take off an argument, too, and before that.
928 * Since MTA arguments after "--" require *expandargv*, delay parsing off
929 * those options until after the resource files are loaded... */
930 if((cp = argv[i = a_main_oind]) == NULL)
932 else if(cp[0] == '-' && cp[1] == '-' && cp[2] == '\0')
933 ++i;
934 /* n_PO_BATCH_FLAG sets to /dev/null, but -f can still be used and sets & */
935 else if(folder != NULL && /*folder[0] == '&' &&*/ folder[1] == '\0'){
936 folder = cp;
937 if((cp = argv[++i]) != NULL){
938 if(cp[0] != '-' || cp[1] != '-' || cp[2] != '\0'){
939 emsg = N_("More than one file given with -f");
940 goto jusage;
942 ++i;
944 }else{
945 n_psonce |= n_PSO_SENDMODE;
946 for(;;){
947 to = cat(to, lextract(cp, GTO | GFULL));
948 if((cp = argv[++i]) == NULL)
949 break;
950 if(cp[0] == '-' && cp[1] == '-' && cp[2] == '\0'){
951 ++i;
952 break;
956 a_main_oind = i;
958 /* ...BUT, since we use salloc() for the MTA n_smopts storage we need to
959 * allocate the necessary space for them before we fixate that storage! */
960 while(argv[i] != NULL)
961 ++i;
962 if(n_smopts_cnt + i > smopts_size)
963 DBG(smopts_size =)
964 a_main_grow_cpp(&n_smopts, n_smopts_cnt + i + 1, n_smopts_cnt);
966 /* Check for inconsistent arguments, fix some temporaries */
967 if(n_psonce & n_PSO_SENDMODE){
968 /* XXX This is only because BATCH_FLAG sets *folder*=/dev/null
969 * XXX in order to function. Ideally that would not be needed */
970 if(folder != NULL && !(n_poption & n_PO_BATCH_FLAG)){
971 emsg = N_("Cannot give -f and people to send to.");
972 goto jusage;
974 if(uarg != NULL){
975 emsg = N_("The -u option cannot be used in send mode");
976 goto jusage;
978 if(!(n_poption & n_PO_t_FLAG) && to == NULL){
979 emsg = N_("Send options without primary recipient specified.");
980 goto jusage;
982 if((n_poption & n_PO_t_FLAG) && qf != NULL){
983 emsg = N_("The -M, -m, -q and -t options are mutual exclusive.");
984 goto jusage;
986 if(n_poption & (n_PO_EXISTONLY | n_PO_HEADERSONLY | n_PO_HEADERLIST)){
987 emsg = N_("The -e, -H and -L options cannot be used in send mode.");
988 goto jusage;
990 if(n_poption & n_PO_R_FLAG){
991 emsg = N_("The -R option is meaningless in send mode.");
992 goto jusage;
995 if(n_psonce & n_PSO_INTERACTIVE){
996 if(qf == (char*)-1){
997 if(!(n_poption & n_PO_Mm_FLAG))
998 emsg = N_("-q can't use standard input when interactive.\n");
999 goto jusage;
1002 }else{
1003 if(uarg != NULL && folder != NULL){
1004 emsg = N_("The options -u and -f (and -#) are mutually exclusive");
1005 goto jusage;
1007 if((n_poption & (n_PO_EXISTONLY | n_PO_HEADERSONLY)) ==
1008 (n_PO_EXISTONLY | n_PO_HEADERSONLY)){
1009 emsg = N_("The options -e and -H are mutual exclusive");
1010 goto jusage;
1012 if((n_poption & (n_PO_HEADERSONLY | n_PO_HEADERLIST) /* TODO OBSOLETE */
1013 ) == (n_PO_HEADERSONLY | n_PO_HEADERLIST))
1014 n_OBSOLETE(_("please use \"-e -L xy\" instead of \"-H -L xy\""));
1016 if(uarg != NULL)
1017 folder = uarg;
1021 * Likely to go, perform more setup
1024 a_main_setup_vars();
1026 /* Create memory pool snapshot; Memory is auto-reclaimed from now on */
1027 n_memory_pool_fixate();
1029 /* load() any resource files */
1030 if(resfiles & a_RF_ALL){
1031 /* *expand() returns a savestr(), but load() only uses the file name
1032 * for fopen(), so it is safe to do this */
1033 if(resfiles & a_RF_SYSTEM){
1034 bool_t nload;
1036 if((nload = ok_blook(NAIL_NO_SYSTEM_RC)))
1037 n_OBSOLETE(_("Please use $MAILX_NO_SYSTEM_RC instead of "
1038 "$NAIL_NO_SYSTEM_RC"));
1039 if(!nload && !ok_blook(MAILX_NO_SYSTEM_RC) &&
1040 !n_go_load(VAL_SYSCONFDIR "/" VAL_SYSCONFRC))
1041 goto j_leave;
1044 if((resfiles & a_RF_USER) &&
1045 !n_go_load(fexpand(ok_vlook(MAILRC), FEXP_LOCAL | FEXP_NOPROTO)))
1046 goto j_leave;
1048 if((cp = ok_vlook(NAIL_EXTRA_RC)) != NULL)
1049 n_OBSOLETE(_("Please use *mailx-extra-rc*, not *NAIL_EXTRA_RC*"));
1050 if((cp != NULL || (cp = ok_vlook(mailx_extra_rc)) != NULL) &&
1051 !n_go_load(fexpand(cp, FEXP_LOCAL | FEXP_NOPROTO)))
1052 goto j_leave;
1055 /* Ensure the -S and other command line options take precedence over
1056 * anything that may have been placed in resource files.
1057 * Our "ternary binary" option *verbose* needs special treament */
1058 if((n_poption & (n_PO_VERB | n_PO_VERBVERB)) == n_PO_VERB)
1059 n_poption &= ~n_PO_VERB;
1060 /* ..and be silent when unsetting undefined variables again */
1061 if(oargs_cnt > 0){
1062 n_pstate |= n_PS_ROBOT;
1063 oargs[oargs_cnt] = NULL;
1064 c_set(oargs);
1065 n_pstate &= ~n_PS_ROBOT;
1068 /* Cause possible umask(2) to be applied, now that any setting is
1069 * established, and before we change accounts, evaluate commands etc. */
1070 (void)ok_vlook(umask);
1072 /* Additional options to pass-through to MTA, and allowed to do so? */
1073 i = a_main_oind;
1074 if((cp = ok_vlook(expandargv)) != NULL){
1075 bool_t isfail, isrestrict;
1077 isfail = !asccasecmp(cp, "fail");
1078 isrestrict = (!isfail && !asccasecmp(cp, "restrict"));
1080 if((n_poption & n_PO_D_V) && !isfail && !isrestrict && *cp != '\0')
1081 n_err(_("Unknown *expandargv* value: %s\n"), cp);
1083 if((cp = argv[i]) != NULL){
1084 if(isfail || (isrestrict && (!(n_poption & n_PO_TILDE_FLAG) ||
1085 !(n_psonce & n_PSO_INTERACTIVE)))){
1086 n_err(_("*expandargv* doesn't allow MTA arguments; consider "
1087 "using *mta-arguments*\n"));
1088 n_exit_status = n_EXIT_USE | n_EXIT_SEND_ERROR;
1089 goto jleave;
1092 assert(n_smopts_cnt + 1 <= smopts_size);
1093 n_smopts[n_smopts_cnt++] = cp;
1094 }while((cp = argv[++i]) != NULL);
1096 }else if(argv[i] != NULL && (n_poption & n_PO_D_V))
1097 n_err(_("*expandargv* not set, ignoring given MTA arguments\n"));
1099 /* We had to wait until the resource files are loaded and any command line
1100 * setting has been restored, but get the termcap up and going before we
1101 * switch account or running commands */
1102 #ifdef n_HAVE_TCAP
1103 if((n_psonce & n_PSO_INTERACTIVE) && !(n_poption & n_PO_QUICKRUN_MASK))
1104 n_termcap_init();
1105 #endif
1107 /* Now we can set the account */
1108 if(Aarg != NULL){
1109 char const *a[2];
1111 a[0] = Aarg;
1112 a[1] = NULL;
1113 c_account(a);
1116 /* "load()" commands given on command line */
1117 if(Xargs_cnt > 0){
1118 if(!n_go_Xargs(Xargs, Xargs_cnt))
1119 goto jleave;
1122 /* Final tests */
1123 if(n_poption & n_PO_Mm_FLAG){
1124 if(qf == (char*)-1){
1125 if(!n_mimetype_check_mtname(n_poption_arg_Mm)){
1126 n_err(_("Could not find `mimetype' for -M argument: %s\n"),
1127 n_poption_arg_Mm);
1128 n_exit_status = n_EXIT_ERR;
1129 goto jleave;
1131 }else if((n_poption_arg_Mm = n_mimetype_classify_filename(qf)) == NULL){
1132 n_err(_("Could not `mimetype'-classify -m argument: %s\n"),
1133 n_shexp_quote_cp(qf, FAL0));
1134 n_exit_status = n_EXIT_ERR;
1135 goto jleave;
1136 }else if(!asccasecmp(n_poption_arg_Mm, "text/plain")) /* TODO no: magic */
1137 n_poption_arg_Mm = NULL;
1141 * We're finally completely setup and ready to go
1143 n_psonce |= n_PSO_STARTED;
1145 if(!(n_psonce & n_PSO_SENDMODE))
1146 n_exit_status = a_main_rcv_mode(folder, Larg);
1147 else{
1148 /* Now that full mailx(1)-style file expansion is possible handle the
1149 * attachments which we had delayed due to this.
1150 * This may use savestr(), but since we won't enter the command loop we
1151 * don't need to care about that */
1152 for(; a_head != NULL; a_head = a_head->aa_next){
1153 enum n_attach_error aerr;
1155 attach = n_attachment_append(attach, a_head->aa_file, &aerr, NULL);
1156 if(aerr != n_ATTACH_ERR_NONE){
1157 n_exit_status = n_EXIT_ERR;
1158 goto jleave;
1162 if(n_psonce & n_PSO_INTERACTIVE)
1163 n_tty_init();
1164 mail(to, cc, bcc, subject, attach, qf, ((n_poption & n_PO_F_FLAG) != 0));
1165 if(n_psonce & n_PSO_INTERACTIVE)
1166 n_tty_destroy((n_psonce & n_PSO_XIT) != 0);
1169 jleave:
1170 /* Be aware of identical code for `exit' command! */
1171 #ifdef n_HAVE_TCAP
1172 if((n_psonce & n_PSO_INTERACTIVE) && !(n_poption & n_PO_QUICKRUN_MASK))
1173 n_termcap_destroy();
1174 #endif
1176 j_leave:
1177 #if defined HAVE_MEMORY_DEBUG || defined HAVE_NOMEMDBG
1178 n_memory_pool_pop(NULL);
1179 #endif
1180 #if defined HAVE_DEBUG || defined HAVE_DEVEL || defined HAVE_NOMEMDBG
1181 n_memory_reset();
1182 #endif
1183 NYD_LEAVE;
1184 return n_exit_status;
1187 /* Source the others in that case! */
1188 #ifdef HAVE_AMALGAMATION
1189 # include "mk-config.h"
1190 #endif
1192 /* s-it-mode */