1 /*@ S-nail - a mail user agent derived from Berkeley Mail.
2 *@ Command input, lexing and evaluation, resource file loading and `source'ing.
3 *@ TODO PS_ROBOT requires yet PS_SOURCING, which REALLY sucks.
4 *@ TODO Commands and ghosts deserve a hashmap. Or so.
6 * Copyright (c) 2000-2004 Gunnar Ritter, Freiburg i. Br., Germany.
7 * Copyright (c) 2012 - 2016 Steffen (Daode) Nurpmeso <steffen@sdaoden.eu>.
10 * Copyright (c) 1980, 1993
11 * The Regents of the University of California. All rights reserved.
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 * 3. Neither the name of the University nor the names of its contributors
22 * may be used to endorse or promote products derived from this software
23 * without specific prior written permission.
25 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 #define n_FILE lex_input
40 #ifndef HAVE_AMALGAMATION
44 enum a_lex_input_flags
{
46 a_LEX_FREE
= 1<<0, /* Structure was allocated, free() it */
47 a_LEX_PIPE
= 1<<1, /* Open on a pipe */
48 a_LEX_MACRO
= 1<<2, /* Running a macro */
49 a_LEX_MACRO_FREE_DATA
= 1<<3, /* Lines are allocated, free(3) once done */
50 a_LEX_MACRO_X_OPTION
= 1<<4, /* Macro indeed command line -X option */
51 a_LEX_MACRO_CMD
= 1<<5, /* Macro indeed single-line: ~:COMMAND */
53 a_LEX_SUPER_MACRO
= 1<<16 /* *Not* inheriting PS_SOURCING state */
57 char const *lc_name
; /* Name of command */
58 int (*lc_func
)(void*); /* Implementor of command */
59 enum argtype lc_argtype
; /* Arglist type (see below) */
60 si16_t lc_msgflag
; /* Required flags of msgs */
61 si16_t lc_msgmask
; /* Relevant flags of msgs */
62 #ifdef HAVE_DOCSTRINGS
63 char const *lc_doc
; /* One line doc for command */
66 /* Yechh, can't initialize unions */
67 #define lc_minargs lc_msgflag /* Minimum argcount for RAWLIST */
68 #define lc_maxargs lc_msgmask /* Max argcount for RAWLIST */
71 struct a_lex_ghost
*lg_next
;
72 struct str lg_cmd
; /* Data follows after .lg_name */
73 char lg_name
[VFIELD_SIZE(0)];
76 struct a_lex_eval_ctx
{
77 struct str le_line
; /* The terminated data to _evaluate() */
78 ui32_t le_line_size
; /* May be used to store line memory size */
79 bool_t le_is_recursive
; /* Evaluation in evaluation? (collect ~:) */
81 bool_t le_add_history
; /* Enter (final) command in history? */
82 char const *le_new_content
; /* History: reenter line, start with this */
85 struct a_lex_input_stack
{
86 struct a_lex_input_stack
*li_outer
;
87 FILE *li_file
; /* File we were in */
88 void *li_cond
; /* Saved state of conditional stack */
89 ui32_t li_flags
; /* enum a_lex_input_flags */
90 ui32_t li_loff
; /* Pseudo (macro): index in .li_lines */
91 char **li_lines
; /* Pseudo content, lines unfolded */
92 char li_name
[VFIELD_SIZE(0)]; /* Name of file or macro */
95 static sighandler_type a_lex_oldpipe
;
96 static struct a_lex_ghost
*a_lex_ghosts
;
97 /* a_lex_cmd_tab[] after fun protos */
100 static struct a_lex_input_stack
*a_lex_input
;
102 /* Isolate the command from the arguments */
103 static char *a_lex_isolate(char const *comm
);
105 /* Command ghost handling */
106 static int a_lex_c_ghost(void *v
);
107 static int a_lex_c_unghost(void *v
);
109 /* Print a list of all commands */
110 static int a_lex_c_list(void *v
);
112 static int a_lex__pcmd_cmp(void const *s1
, void const *s2
);
115 static int a_lex_c_quit(void *v
);
117 /* Print the binaries version number */
118 static int a_lex_c_version(void *v
);
120 static int a_lex__version_cmp(void const *s1
, void const *s2
);
122 /* PS_STATE_PENDMASK requires some actions */
123 static void a_lex_update_pstate(void);
125 /* Evaluate a single command.
126 * .le_add_history and .le_new_content will be updated upon success.
127 * Command functions return 0 for success, 1 for error, and -1 for abort.
128 * 1 or -1 aborts a load or source, a -1 aborts the interactive command loop */
129 static int a_lex_evaluate(struct a_lex_eval_ctx
*evp
);
131 /* Get first-fit, or NULL */
132 static struct a_lex_cmd
const *a_lex__firstfit(char const *comm
);
134 /* Branch here on hangup signal and simulate "exit" */
135 static void a_lex_hangup(int s
);
137 /* The following gets called on receipt of an interrupt. Close all open files
138 * except 0, 1, 2, and the temporary. Also, unstack all source files */
139 static void a_lex_onintr(int s
);
141 /* Pop the current input back to the previous level. Update the program state.
142 * If the argument is TRUM1 then we don't alert and error out if the stack
143 * doesn't exist at all */
144 static void a_lex_unstack(bool_t eval_error
);
146 /* `source' and `source_if' (if silent_error: no pipes allowed, then) */
147 static bool_t
a_lex_source_file(char const *file
, bool_t silent_error
);
149 /* System resource file load()ing or -X command line option array traversal */
150 static bool_t
a_lex_load(struct a_lex_input_stack
*lip
);
152 /* A simplified command loop for recursed state machines */
153 static bool_t
a_commands_recursive(enum n_lexinput_flags lif
);
155 /* List of all commands, and list of commands which are specially treated
156 * and deduced in _evaluate(), but we need a list for _c_list() and
157 * print_comm_docstr() */
158 #ifdef HAVE_DOCSTRINGS
163 static struct a_lex_cmd
const a_lex_cmd_tab
[] = {
166 a_lex_special_cmd_tab
[] = {
168 DS(N_("Comment command: ignore remaining (continuable) line")) },
170 DS(N_("Print out the preceding message")) }
175 a_lex_isolate(char const *comm
){
177 while(*comm
!= '\0' &&
178 strchr("~|? \t0123456789&%@$^.:/-+*'\",;(`", *comm
) == NULL
)
181 return UNCONST(comm
);
185 a_lex_c_ghost(void *v
){
186 struct a_lex_ghost
*lgp
, *gp
;
198 if((fp
= Ftmp(NULL
, "ghost", OF_RDWR
| OF_UNLINK
| OF_REGISTER
)) == NULL
)
201 for(i
= 0, gp
= a_lex_ghosts
; gp
!= NULL
; gp
= gp
->lg_next
)
202 fprintf(fp
, "wysh ghost %s %s\n",
203 gp
->lg_name
, n_shexp_quote_cp(gp
->lg_cmd
.s
, TRU1
));
206 page_or_print(fp
, i
);
212 /* Verify the ghost name is a valid one */
213 if(*argv
[0] == '\0' || *a_lex_isolate(argv
[0]) != '\0'){
214 n_err(_("`ghost': can't canonicalize %s\n"),
215 n_shexp_quote_cp(argv
[0], FAL0
));
220 /* Show command of single ghost? */
222 for(gp
= a_lex_ghosts
; gp
!= NULL
; gp
= gp
->lg_next
)
223 if(!strcmp(argv
[0], gp
->lg_name
)){
224 printf("wysh ghost %s %s\n",
225 gp
->lg_name
, n_shexp_quote_cp(gp
->lg_cmd
.s
, TRU1
));
228 n_err(_("`ghost': no such alias: %s\n"), argv
[0]);
233 /* Define command for ghost: verify command content */
234 for(cl
= 0, i
= 1; (cp
= UNCONST(argv
[i
])) != NULL
; ++i
)
236 cl
+= strlen(cp
) +1; /* SP or NUL */
238 n_err(_("`ghost': empty command arguments after %s\n"), argv
[0]);
243 /* If the ghost already exists, recreate */
244 for(lgp
= NULL
, gp
= a_lex_ghosts
; gp
!= NULL
; lgp
= gp
, gp
= gp
->lg_next
)
245 if(!strcmp(gp
->lg_name
, argv
[0])){
247 lgp
->lg_next
= gp
->lg_next
;
249 a_lex_ghosts
= gp
->lg_next
;
254 nl
= strlen(argv
[0]) +1;
255 gp
= smalloc(sizeof(*gp
) - VFIELD_SIZEOF(struct a_lex_ghost
, lg_name
) +
257 gp
->lg_next
= a_lex_ghosts
;
259 memcpy(gp
->lg_name
, argv
[0], nl
);
260 cp
= gp
->lg_cmd
.s
= gp
->lg_name
+ nl
;
263 while(*++argv
!= NULL
)
264 if((i
= strlen(*argv
)) > 0){
265 memcpy(cp
, *argv
, i
);
276 a_lex_c_unghost(void *v
){
277 struct a_lex_ghost
*lgp
, *gp
;
278 char const **argv
, *cp
;
285 while((cp
= *argv
++) != NULL
){
286 if(cp
[0] == '*' && cp
[1] == '\0'){
287 while((gp
= a_lex_ghosts
) != NULL
){
288 a_lex_ghosts
= gp
->lg_next
;
292 for(lgp
= NULL
, gp
= a_lex_ghosts
; gp
!= NULL
;
293 lgp
= gp
, gp
= gp
->lg_next
)
294 if(!strcmp(gp
->lg_name
, cp
)){
296 lgp
->lg_next
= gp
->lg_next
;
298 a_lex_ghosts
= gp
->lg_next
;
302 n_err(_("`unghost': no such alias: %s\n"),
303 n_shexp_quote_cp(cp
, FAL0
));
313 a_lex_c_list(void *v
){
315 struct a_lex_cmd
const **cpa
, *cp
, **cursor
;
319 i
= NELEM(a_lex_cmd_tab
) + NELEM(a_lex_special_cmd_tab
) +1;
320 cpa
= salloc(sizeof(cp
) * i
);
322 for(i
= 0; i
< NELEM(a_lex_cmd_tab
); ++i
)
323 cpa
[i
] = &a_lex_cmd_tab
[i
];
327 for(j
= 0; j
< NELEM(a_lex_special_cmd_tab
); ++i
, ++j
)
328 cpa
[i
] = &a_lex_special_cmd_tab
[j
];
336 qsort(cpa
, i
, sizeof(xcp
), &a_lex__pcmd_cmp
);
339 if((fp
= Ftmp(NULL
, "list", OF_RDWR
| OF_UNLINK
| OF_REGISTER
)) == NULL
)
342 fprintf(fp
, _("Commands are:\n"));
344 for(i
= 0, cursor
= cpa
; (cp
= *cursor
++) != NULL
;){
345 if(cp
->lc_func
== &c_cmdnotsupp
)
347 if(options
& OPT_D_V
){
350 switch(cp
->lc_argtype
& ARG_ARGMASK
){
351 case ARG_MSGLIST
: argt
= N_("message-list"); break;
352 case ARG_STRLIST
: argt
= N_("a \"string\""); break;
353 case ARG_RAWLIST
: argt
= N_("old-style quoting"); break;
354 case ARG_NOLIST
: argt
= N_("no arguments"); break;
355 case ARG_NDMLIST
: argt
= N_("message-list (without a default)"); break;
356 case ARG_WYSHLIST
: argt
= N_("sh(1)ell-style quoting"); break;
357 default: argt
= N_("`wysh' for sh(1)ell-style quoting"); break;
359 #ifdef HAVE_DOCSTRINGS
360 fprintf(fp
, _("`%s'. Argument type: %s.\n\t%s\n"),
361 cp
->lc_name
, V_(argt
), V_(cp
->lc_doc
));
364 fprintf(fp
, "`%s' (%s)\n", cp
->lc_name
, argt
);
368 size_t j
= strlen(cp
->lc_name
) + 2;
375 fprintf(fp
, (*cursor
!= NULL
? "%s, " : "%s\n"), cp
->lc_name
);
380 page_or_print(fp
, l
);
388 a_lex__pcmd_cmp(void const *s1
, void const *s2
){
389 struct a_lex_cmd
const * const *cp1
, * const *cp2
;
395 rv
= strcmp((*cp1
)->lc_name
, (*cp2
)->lc_name
);
401 a_lex_c_quit(void *v
){
405 /* If we are PS_SOURCING, then return 1 so _evaluate() can handle it.
406 * Otherwise return -1 to abort command loop */
413 a_lex_c_version(void *v
){
416 char const *cp
, **arr
;
421 printf(_("%s version %s\nFeatures included (+) or not (-)\n"),
422 uagent
, ok_vlook(version
));
424 /* *features* starts with dummy byte to avoid + -> *folder* expansions */
425 i
= strlen(cp
= &ok_vlook(features
)[1]) +1;
429 arr
= salloc(sizeof(cp
) * VAL_FEATURES_CNT
);
430 for(longest
= 0, i
= 0; (cp
= n_strsep(&iop
, ',', TRU1
)) != NULL
; ++i
){
433 longest
= MAX(longest
, (int)i2
);
435 qsort(arr
, i
, sizeof(cp
), &a_lex__version_cmp
);
437 for(++longest
, i2
= 0; i
-- > 0;){
439 printf("%-*s ", longest
, cp
);
441 if(UICMP(z
, ++i2
+ longest
, >=, scrnwidth
) || i
== 0){
447 if((rv
= ferror(stdout
) != 0))
454 a_lex__version_cmp(void const *s1
, void const *s2
){
455 char const * const *cp1
, * const *cp2
;
461 rv
= strcmp(&(*cp1
)[1], &(*cp2
)[1]);
467 a_lex_update_pstate(void){
470 if(pstate
& PS_SIGWINCH_PEND
){
473 snprintf(buf
, sizeof buf
, "%d", scrnwidth
);
474 ok_vset(COLUMNS
, buf
);
475 snprintf(buf
, sizeof buf
, "%d", scrnheight
);
479 pstate
&= ~PS_PSTATE_PENDMASK
;
484 a_lex_evaluate(struct a_lex_eval_ctx
*evp
){
485 /* xxx old style(9), but also old code */
487 char _wordbuf
[2], *arglist
[MAXARGC
], *cp
, *word
;
488 struct a_lex_ghost
*gp
;
489 struct a_lex_cmd
const *cmd
;
498 line
= evp
->le_line
; /* XXX don't change original (buffer pointer) */
499 assert(line
.s
[line
.l
] == '\0');
500 evp
->le_add_history
= FAL0
;
501 evp
->le_new_content
= NULL
;
503 /* Command ghosts that refer to shell commands or macro expansion restart */
506 /* Strip the white space away from end and beginning of command */
510 for(cp
= &line
.s
[i
-1]; spacechar(*cp
); --cp
)
514 for(cp
= line
.s
; spacechar(*cp
); ++cp
)
516 line
.l
-= PTR2SIZE(cp
- line
.s
);
518 /* Ignore null commands (comments) */
522 /* Handle ! differently to get the correct lexical conventions */
526 /* Isolate the actual command; since it may not necessarily be
527 * separated from the arguments (as in `p1') we need to duplicate it to
528 * be able to create a NUL terminated version.
529 * We must be aware of several special one letter commands here */
530 else if((cp
= a_lex_isolate(cp
)) == arglist
[0] &&
531 (*cp
== '|' || *cp
== '~' || *cp
== '?'))
533 c
= (int)PTR2SIZE(cp
- arglist
[0]);
535 word
= UICMP(z
, c
, <, sizeof _wordbuf
) ? _wordbuf
: salloc(c
+1);
536 memcpy(word
, arglist
[0], c
);
539 /* Look up the command; if not found, bitch.
540 * Normally, a blank command would map to the first command in the
541 * table; while PS_SOURCING, however, we ignore blank lines to eliminate
542 * confusion; act just the same for ghosts */
544 if((pstate
& PS_ROBOT
) || gp
!= NULL
)
546 cmd
= a_lex_cmd_tab
+ 0;
550 /* XXX It may be the argument parse adjuster */
551 if(!wysh
&& c
== sizeof("wysh") -1 && !asccasecmp(word
, "wysh")){
557 /* If this is the first evaluation, check command ghosts */
559 /* TODO relink list head, so it's sorted on usage over time?
560 * TODO in fact, there should be one hashmap over all commands and ghosts
561 * TODO so that the lookup could be made much more efficient than it is
562 * TODO now (two adjacent list searches! */
563 for(gp
= a_lex_ghosts
; gp
!= NULL
; gp
= gp
->lg_next
)
564 if(!strcmp(word
, gp
->lg_name
)){
569 line
.s
= salloc(i
+ line
.l
+1);
570 memcpy(line
.s
, gp
->lg_cmd
.s
, i
);
571 memcpy(line
.s
+ i
, cp
, line
.l
);
572 line
.s
[i
+= line
.l
] = '\0';
575 line
.s
= gp
->lg_cmd
.s
;
576 line
.l
= gp
->lg_cmd
.l
;
582 if((cmd
= a_lex__firstfit(word
)) == NULL
|| cmd
->lc_func
== &c_cmdnotsupp
){
585 if(!(s
= condstack_isskip()) || (options
& OPT_D_V
))
586 n_err(_("Unknown command%s: `%s'\n"),
587 (s
? _(" (ignored due to `if' condition)") : ""), word
);
597 /* See if we should execute the command -- if a conditional we always
598 * execute it, otherwise, check the state of cond */
600 if(!(cmd
->lc_argtype
& ARG_F
) && condstack_isskip())
603 /* Process the arguments to the command, depending on the type it expects */
604 if(!(cmd
->lc_argtype
& ARG_M
) && (options
& OPT_SENDMODE
)){
605 n_err(_("May not execute `%s' while sending\n"), cmd
->lc_name
);
608 if((cmd
->lc_argtype
& ARG_S
) && !(pstate
& PS_STARTED
)){
609 n_err(_("May not execute `%s' during startup\n"), cmd
->lc_name
);
612 if((cmd
->lc_argtype
& ARG_I
) &&
613 !(options
& (OPT_INTERACTIVE
| OPT_BATCH_FLAG
))){
614 n_err(_("May not execute `%s' unless interactive or in batch mode\n"),
618 if((cmd
->lc_argtype
& ARG_R
) && (pstate
& PS_RECURSED
)){
619 n_err(_("Cannot invoke `%s' when in recursed mode (e.g., composing)\n"),
624 if((cmd
->lc_argtype
& ARG_W
) && !(mb
.mb_perm
& MB_DELE
)){
625 n_err(_("May not execute `%s' -- message file is read only\n"),
629 if((cmd
->lc_argtype
& ARG_A
) && mb
.mb_type
== MB_VOID
){
630 n_err(_("Cannot execute `%s' without active mailbox\n"), cmd
->lc_name
);
634 if(cmd
->lc_argtype
& ARG_O
)
635 OBSOLETE2(_("this command will be removed"), cmd
->lc_name
);
636 if(cmd
->lc_argtype
& ARG_V
)
637 temporary_arg_v_store
= NULL
;
639 if(wysh
&& (cmd
->lc_argtype
& ARG_ARGMASK
) != ARG_WYRALIST
)
640 n_err(_("`wysh' prefix doesn't affect `%s'\n"), cmd
->lc_name
);
641 /* TODO v15: strip PS_ARGLIST_MASK off, just in case the actual command
642 * TODO doesn't use any of those list commands which strip this mask,
643 * TODO and for now we misuse bits for checking relation to history;
644 * TODO argument state should be property of a per-command carrier instead */
645 pstate
&= ~PS_ARGLIST_MASK
;
646 switch(cmd
->lc_argtype
& ARG_ARGMASK
){
648 /* Message list defaulting to nearest forward legal message */
651 if((c
= getmsglist(cp
, n_msgvec
, cmd
->lc_msgflag
)) < 0)
654 if((n_msgvec
[0] = first(cmd
->lc_msgflag
, cmd
->lc_msgmask
)) != 0)
657 if(n_msgvec
[0] == 0){
658 if(!(pstate
& PS_HOOK_MASK
))
659 printf(_("No applicable messages\n"));
662 e
= (*cmd
->lc_func
)(n_msgvec
);
666 /* Message list with no defaults, but no error if none exist */
667 if(n_msgvec
== NULL
){
669 n_err(_("Invalid use of message list\n"));
672 if((c
= getmsglist(cp
, n_msgvec
, cmd
->lc_msgflag
)) < 0)
674 e
= (*cmd
->lc_func
)(n_msgvec
);
678 /* Just the straight string, with leading blanks removed */
679 while(whitechar(*cp
))
681 e
= (*cmd
->lc_func
)(cp
);
696 if((c
= getrawlist((c
!= 0), arglist
, NELEM(arglist
), cp
, line
.l
)) < 0){
697 n_err(_("Invalid argument list\n"));
700 if(c
< cmd
->lc_minargs
){
701 n_err(_("`%s' requires at least %d arg(s)\n"),
702 cmd
->lc_name
, cmd
->lc_minargs
);
706 if(c
> cmd
->lc_maxargs
){
707 n_err(_("`%s' takes no more than %d arg(s)\n"),
708 cmd
->lc_name
, cmd
->lc_maxargs
);
712 e
= (*cmd
->lc_func
)(arglist
);
716 /* Just the constant zero, for exiting, eg. */
717 e
= (*cmd
->lc_func
)(0);
721 DBG( n_panic(_("Implementation error: unknown argument type: %d"),
722 cmd
->lc_argtype
& ARG_ARGMASK
); )
726 if(e
== 0 && (cmd
->lc_argtype
& ARG_V
) &&
727 (cp
= temporary_arg_v_store
) != NULL
){
728 temporary_arg_v_store
= NULL
;
729 evp
->le_new_content
= cp
;
732 /* TODO v15 with PS_MSGLIST_SAW_NO the history entry is at least gabby */
733 if(!(cmd
->lc_argtype
& ARG_H
) && !(pstate
& PS_MSGLIST_SAW_NO
))
734 evp
->le_add_history
= TRU1
;
737 /* Exit the current source file on error TODO what a mess! */
739 pstate
&= ~PS_EVAL_ERROR
;
741 pstate
|= PS_EVAL_ERROR
;
742 if(e
< 0 || (pstate
& PS_ROBOT
)){ /* FIXME */
751 if((cmd
->lc_argtype
& ARG_P
) && ok_blook(autoprint
))
753 line
.s
= savestr("type");
754 line
.l
= sizeof("type") -1;
755 gp
= (struct a_lex_ghost
*)-1; /* Avoid `ghost' interpretation */
759 if(!(pstate
& (PS_SOURCING
| PS_HOOK_MASK
)) && !(cmd
->lc_argtype
& ARG_T
))
760 pstate
|= PS_SAW_COMMAND
;
762 pstate
&= ~PS_EVAL_ERROR
;
767 fprintf(stderr, "a_lex_evaluate returns %d for <%s>\n",e,line.s);
773 static struct a_lex_cmd
const *
774 a_lex__firstfit(char const *comm
){ /* TODO *hashtable*! linear list search!!! */
775 struct a_lex_cmd
const *cp
;
778 for(cp
= a_lex_cmd_tab
; PTRCMP(cp
, <, &a_lex_cmd_tab
[NELEM(a_lex_cmd_tab
)]);
780 if(*comm
== *cp
->lc_name
&& is_prefix(comm
, cp
->lc_name
))
790 NYD_X
; /* Signal handler */
798 NYD_X
; /* Signal handler */
801 safe_signal(SIGINT
, a_lex_onintr
);
803 a_lex_unstack(TRUM1
);
805 termios_state_reset();
806 close_all_files(); /* FIXME .. to outer level ONLU! */
813 n_err_sighdl(_("Interrupt\n"));
814 safe_signal(SIGPIPE
, a_lex_oldpipe
);
815 siglongjmp(srbuf
, 0); /* FIXME get rid */
819 a_lex_unstack(bool_t eval_error
){
820 struct a_lex_input_stack
*lip
;
823 if((lip
= a_lex_input
) == NULL
){
824 /* If called from a_lex_onintr(), be silent FIXME */
825 pstate
&= ~(PS_SOURCING
| PS_ROBOT
);
826 if(eval_error
== TRUM1
|| !(pstate
& PS_STARTED
))
831 if(lip
->li_flags
& a_LEX_MACRO
){
832 if(lip
->li_flags
& a_LEX_MACRO_FREE_DATA
){
835 while(*(lp
= &lip
->li_lines
[lip
->li_loff
]) != NULL
){
839 /* Part of lip's memory chunk, then */
840 if(!(lip
->li_flags
& a_LEX_MACRO_CMD
))
844 if(lip
->li_flags
& a_LEX_PIPE
)
845 /* XXX command manager should -TERM then -KILL instead of hoping
846 * XXX for exit of provider due to EPIPE / SIGPIPE */
847 Pclose(lip
->li_file
, TRU1
);
849 Fclose(lip
->li_file
);
852 if(!condstack_take(lip
->li_cond
)){
853 n_err(_("Unmatched `if' at end of %s %s\n"),
854 ((lip
->li_flags
& a_LEX_MACRO
855 ? (lip
->li_flags
& a_LEX_MACRO_CMD
? _("command") : _("macro"))
856 : _("`source'd file"))),
861 if((a_lex_input
= lip
->li_outer
) == NULL
){
862 pstate
&= ~(PS_SOURCING
| PS_ROBOT
);
864 if((a_lex_input
->li_flags
& (a_LEX_MACRO
| a_LEX_SUPER_MACRO
)) ==
865 (a_LEX_MACRO
| a_LEX_SUPER_MACRO
))
866 pstate
&= ~PS_SOURCING
;
867 assert(pstate
& PS_ROBOT
);
872 if(lip
->li_flags
& a_LEX_FREE
)
875 if(UNLIKELY(a_lex_input
!= NULL
&& eval_error
== TRUM1
))
876 a_lex_unstack(TRUM1
);
882 if(options
& OPT_D_V
)
883 n_alert(_("Stopped %s %s due to errors%s"),
885 ? (lip
->li_flags
& a_LEX_MACRO
886 ? (lip
->li_flags
& a_LEX_MACRO_CMD
887 ? _("evaluating command") : _("evaluating macro"))
888 : (lip
->li_flags
& a_LEX_PIPE
889 ? _("executing `source'd pipe")
890 : _("loading `source'd file")))
891 : (lip
->li_flags
& a_LEX_MACRO
892 ? (lip
->li_flags
& a_LEX_MACRO_X_OPTION
893 ? _("evaluating command line") : _("evaluating macro"))
894 : _("loading initialization resource"))),
896 (options
& OPT_DEBUG
? "" : _(" (enable *debug* for trace)")));
897 if(lip
->li_flags
& a_LEX_FREE
)
901 if(!(options
& OPT_INTERACTIVE
) && !(pstate
& PS_STARTED
)){
902 if(options
& OPT_D_V
)
903 n_alert(_("Non-interactive, bailing out due to errors "
904 "in startup load phase"));
911 a_lex_source_file(char const *file
, bool_t silent_error
){
912 struct a_lex_input_stack
*lip
;
921 /* Being a command argument file is space-trimmed *//* TODO v15 with
922 * TODO WYRALIST this is no longer necessary true, and for that we
923 * TODO don't set _PARSE_TRIMSPACE because we cannot! -> cmd_tab.h!! */
925 ((ispipe
= (!silent_error
&& (nlen
= strlen(file
)) > 0 &&
926 file
[--nlen
] == '|')))
930 for(nlen
= strlen(file
); nlen
> 0;){
936 nbuf
= savestrbuf(file
, nlen
);
945 if((fip
= Popen(nbuf
/* #if 0 above = savestrbuf(file, nlen)*/, "r",
946 ok_vlook(SHELL
), NULL
, COMMAND_FD_NULL
)) == NULL
){
947 if(!silent_error
|| (options
& OPT_D_V
))
951 }else if((nbuf
= fexpand(file
, FEXP_LOCAL
)) == NULL
)
953 else if((fip
= Fopen(nbuf
, "r")) == NULL
){
954 if(!silent_error
|| (options
& OPT_D_V
))
959 lip
= smalloc(sizeof(*lip
) -
960 VFIELD_SIZEOF(struct a_lex_input_stack
, li_name
) +
961 (nlen
= strlen(nbuf
) +1));
962 lip
->li_outer
= a_lex_input
;
964 lip
->li_cond
= condstack_release();
965 lip
->li_flags
= (ispipe
? a_LEX_FREE
| a_LEX_PIPE
: a_LEX_FREE
) |
966 (a_lex_input
!= NULL
&& (a_lex_input
->li_flags
& a_LEX_SUPER_MACRO
)
967 ? a_LEX_SUPER_MACRO
: 0);
968 memcpy(lip
->li_name
, nbuf
, nlen
);
970 pstate
|= PS_SOURCING
| PS_ROBOT
;
972 a_commands_recursive(n_LEXINPUT_NONE
| n_LEXINPUT_NL_ESC
);
973 /* FIXME return TRUM1 if file can't be opened, FAL0 on eval error */
976 return silent_error
? TRU1
: (fip
!= NULL
);
980 a_lex_load(struct a_lex_input_stack
*lip
){
984 assert(!(pstate
& PS_STARTED
));
985 assert(a_lex_input
== NULL
);
988 * Any errors in the start-up file shall either cause mailx to terminate
989 * with a diagnostic message and a non-zero status or to continue after
990 * writing a diagnostic message, ignoring the remainder of the lines in
991 * the start-up file. */
992 lip
->li_cond
= condstack_release();
994 /* FIXME won't work for now (PS_ROBOT needs PS_SOURCING anyway)
996 (lip->li_flags & a_LEX_MACRO_X_OPTION ? 0 : PS_SOURCING);
998 pstate
|= PS_ROBOT
| PS_SOURCING
;
999 if(options
& OPT_D_V
)
1000 n_err(_("Loading %s\n"), n_shexp_quote_cp(lip
->li_name
, FAL0
));
1002 if(!(rv
= n_commands())){
1003 if(!(options
& OPT_INTERACTIVE
)){
1004 if(options
& OPT_D_V
)
1005 n_alert(_("Non-interactive program mode, forced exit"));
1009 /* PS_EXIT handled by callers */
1015 a_commands_recursive(enum n_lexinput_flags lif
){
1016 struct a_lex_eval_ctx ev
;
1020 memset(&ev
, 0, sizeof ev
);
1022 /* FIXME sigkondom */
1023 n_COLOUR( n_colour_env_push(); )
1028 /* Read a line of commands and handle end of file specially */
1029 ev
.le_line
.l
= ev
.le_line_size
;
1030 n
= n_lex_input(lif
, NULL
, &ev
.le_line
.s
, &ev
.le_line
.l
,
1032 ev
.le_line_size
= (ui32_t
)ev
.le_line
.l
;
1033 ev
.le_line
.l
= (ui32_t
)n
;
1038 if(a_lex_evaluate(&ev
)){
1043 if((options
& OPT_BATCH_FLAG
) && ok_blook(batch_exit_on_error
)){
1044 if(exit_status
!= EXIT_OK
)
1049 n_COLOUR( n_colour_env_pop(FAL0
); )
1051 if(ev
.le_line
.s
!= NULL
)
1057 #ifdef HAVE_DOCSTRINGS
1059 n_print_comm_docstr(char const *comm
){
1060 struct a_lex_ghost
const *gp
;
1061 struct a_lex_cmd
const *cp
, *cpmax
;
1065 /* Ghosts take precedence */
1066 for(gp
= a_lex_ghosts
; gp
!= NULL
; gp
= gp
->lg_next
)
1067 if(!strcmp(comm
, gp
->lg_name
)){
1068 printf("%s -> ", comm
);
1069 comm
= gp
->lg_cmd
.s
;
1073 cpmax
= &(cp
= a_lex_cmd_tab
)[NELEM(a_lex_cmd_tab
)];
1075 for(; PTRCMP(cp
, <, cpmax
); ++cp
){
1076 if(!strcmp(comm
, cp
->lc_name
))
1077 printf("%s: %s\n", comm
, V_(cp
->lc_doc
));
1078 else if(is_prefix(comm
, cp
->lc_name
))
1079 printf("%s (%s): %s\n", comm
, cp
->lc_name
, V_(cp
->lc_doc
));
1085 if(!rv
&& PTRCMP(cpmax
, ==, &a_lex_cmd_tab
[NELEM(a_lex_cmd_tab
)])){
1086 cpmax
= &(cp
= a_lex_special_cmd_tab
)[NELEM(a_lex_special_cmd_tab
)];
1090 if(!rv
&& gp
!= NULL
){
1091 printf("%s\n", n_shexp_quote_cp(comm
, TRU1
));
1097 #endif /* HAVE_DOCSTRINGS */
1100 n_commands(void){ /* FIXME */
1101 struct a_lex_eval_ctx ev
;
1103 bool_t
volatile rv
= TRU1
;
1106 if (!(pstate
& PS_SOURCING
)) {
1107 if (safe_signal(SIGINT
, SIG_IGN
) != SIG_IGN
)
1108 safe_signal(SIGINT
, &a_lex_onintr
);
1109 if (safe_signal(SIGHUP
, SIG_IGN
) != SIG_IGN
)
1110 safe_signal(SIGHUP
, &a_lex_hangup
);
1112 a_lex_oldpipe
= safe_signal(SIGPIPE
, SIG_IGN
);
1113 safe_signal(SIGPIPE
, a_lex_oldpipe
);
1115 memset(&ev
, 0, sizeof ev
);
1117 (void)sigsetjmp(srbuf
, 1); /* FIXME get rid */
1119 char *temporary_orig_line
; /* XXX eval_ctx.le_line not yet constant */
1121 n_COLOUR( n_colour_env_pop(TRU1
); )
1123 /* TODO Unless we have our signal manager (or however we do it) child
1124 * TODO processes may have time slots where their execution isn't
1125 * TODO protected by signal handlers (in between start and setup
1126 * TODO completed). close_all_files() is only called from onintr()
1127 * TODO so those may linger possibly forever */
1128 if(!(pstate
& PS_SOURCING
))
1133 temporary_localopts_free(); /* XXX intermediate hack */
1134 sreset((pstate
& PS_SOURCING
) != 0);
1135 if (!(pstate
& PS_SOURCING
)) {
1138 /* TODO Note: this buffer may contain a password. We should redefine
1139 * TODO the code flow which has to do that */
1140 if ((cp
= termios_state
.ts_linebuf
) != NULL
) {
1141 termios_state
.ts_linebuf
= NULL
;
1142 termios_state
.ts_linesize
= 0;
1143 free(cp
); /* TODO pool give-back */
1145 /* TODO Due to expand-on-tab of NCL the buffer may grow */
1146 if (ev
.le_line
.l
> LINESIZE
* 3) {
1147 free(ev
.le_line
.s
); /* TODO pool! but what? */
1148 ev
.le_line
.s
= NULL
;
1149 ev
.le_line
.l
= ev
.le_line_size
= 0;
1153 if (!(pstate
& PS_SOURCING
) && (options
& OPT_INTERACTIVE
)) {
1156 cp
= ok_vlook(newmail
);
1157 if ((options
& OPT_TTYIN
) && cp
!= NULL
) {
1160 /* FIXME TEST WITH NOPOLL ETC. !!! */
1161 n
= (cp
!= NULL
&& strcmp(cp
, "nopoll"));
1162 if ((mb
.mb_type
== MB_FILE
&& !stat(mailname
, &st
) &&
1163 st
.st_size
> mailsize
) ||
1164 (mb
.mb_type
== MB_MAILDIR
&& n
!= 0)) {
1165 size_t odot
= PTR2SIZE(dot
- message
);
1166 ui32_t odid
= (pstate
& PS_DID_PRINT_DOT
);
1168 if (setfile(mailname
,
1170 ((mb
.mb_perm
& MB_DELE
) ? 0 : FEDIT_RDONLY
)) < 0) {
1171 exit_status
|= EXIT_ERR
;
1175 dot
= message
+ odot
;
1180 exit_status
= EXIT_OK
;
1183 /* Read a line of commands and handle end of file specially */
1185 ev
.le_line
.l
= ev
.le_line_size
;
1186 n
= n_lex_input(n_LEXINPUT_CTX_BASE
| n_LEXINPUT_NL_ESC
, NULL
,
1187 &ev
.le_line
.s
, &ev
.le_line
.l
, ev
.le_new_content
);
1188 ev
.le_line_size
= (ui32_t
)ev
.le_line
.l
;
1189 ev
.le_line
.l
= (ui32_t
)n
;
1192 /* FIXME did unstack() when PS_SOURCING, only break with PS_LOADING*/
1193 if (!(pstate
& PS_ROBOT
) &&
1194 (options
& OPT_INTERACTIVE
) && ok_blook(ignoreeof
)) {
1195 printf(_("*ignoreeof* set, use `quit' to quit.\n"));
1196 n_msleep(500, FAL0
);
1202 temporary_orig_line
= ((pstate
& PS_SOURCING
) ||
1203 !(options
& OPT_INTERACTIVE
)) ? NULL
1204 : savestrbuf(ev
.le_line
.s
, ev
.le_line
.l
);
1205 pstate
&= ~PS_HOOK_MASK
;
1206 if (a_lex_evaluate(&ev
)) {
1207 if (!(pstate
& PS_STARTED
)) /* TODO mess; join PS_EVAL_ERROR.. */
1212 if ((options
& OPT_BATCH_FLAG
) && ok_blook(batch_exit_on_error
)) {
1213 if (exit_status
!= EXIT_OK
)
1215 if ((pstate
& (PS_SOURCING
| PS_EVAL_ERROR
)) == PS_EVAL_ERROR
) {
1216 exit_status
= EXIT_ERR
;
1220 if (!(pstate
& PS_SOURCING
) && (options
& OPT_INTERACTIVE
)) {
1221 if (ev
.le_new_content
!= NULL
)
1223 /* *Can* happen since _evaluate() n_unstack()s on error! XXX no more */
1224 if (temporary_orig_line
!= NULL
)
1225 n_tty_addhist(temporary_orig_line
, !ev
.le_add_history
);
1228 if(pstate
& PS_EXIT
)
1233 if (ev
.le_line
.s
!= NULL
)
1235 if (pstate
& PS_SOURCING
)
1242 (n_lex_input
)(enum n_lexinput_flags lif
, char const *prompt
, char **linebuf
,
1243 size_t *linesize
, char const *string SMALLOC_DEBUG_ARGS
){
1244 /* TODO readline: linebuf pool!; n_lex_input should return si64_t */
1246 bool_t doprompt
, dotty
;
1251 /* Special case macro mode: never need to prompt, lines have always been
1252 * unfolded already */
1253 if(a_lex_input
!= NULL
&& (a_lex_input
->li_flags
& a_LEX_MACRO
)){
1254 if(*linebuf
!= NULL
)
1257 if((*linebuf
= a_lex_input
->li_lines
[a_lex_input
->li_loff
]) == NULL
){
1263 ++a_lex_input
->li_loff
;
1264 *linesize
= strlen(*linebuf
);
1265 if(!(a_lex_input
->li_flags
& a_LEX_MACRO_FREE_DATA
))
1266 *linebuf
= sbufdup(*linebuf
, *linesize
);
1268 iftype
= (a_lex_input
->li_flags
& a_LEX_MACRO_X_OPTION
)
1269 ? "-X OPTION" : "MACRO";
1271 pstate
|= PS_READLINE_NL
;
1274 pstate
&= ~PS_READLINE_NL
;
1276 iftype
= (!(pstate
& PS_STARTED
) ? "LOAD"
1277 : (pstate
& PS_SOURCING
) ? "SOURCE" : "READ");
1278 doprompt
= ((pstate
& (PS_STARTED
| PS_ROBOT
)) == PS_STARTED
&&
1279 (options
& OPT_INTERACTIVE
));
1280 dotty
= (doprompt
&& !ok_blook(line_editor_disable
));
1283 else if(prompt
== NULL
)
1284 prompt
= getprompt();
1286 /* Ensure stdout is flushed first anyway */
1287 if(!dotty
&& prompt
== NULL
)
1290 ifile
= (a_lex_input
!= NULL
) ? a_lex_input
->li_file
: stdin
;
1291 assert(ifile
!= NULL
);
1293 for(nold
= n
= 0;;){
1295 assert(ifile
== stdin
);
1296 if(string
!= NULL
&& (n
= (int)strlen(string
)) > 0){
1300 *linesize
= (size_t)n
+ LINESIZE
+1;
1301 *linebuf
= (srealloc
)(*linebuf
, *linesize SMALLOC_DEBUG_ARGSCALL
);
1302 memcpy(*linebuf
, string
, (size_t)n
+1);
1305 /* TODO if nold>0, don't redisplay the entire line!
1306 * TODO needs complete redesign ... */
1307 n
= (n_tty_readline
)(lif
, prompt
, linebuf
, linesize
, n
1308 SMALLOC_DEBUG_ARGSCALL
);
1310 if(prompt
!= NULL
) {
1312 fputs(prompt
, stdout
);
1316 n
= (readline_restart
)(ifile
, linebuf
, linesize
, n
1317 SMALLOC_DEBUG_ARGSCALL
);
1319 if(n
> 0 && nold
> 0){
1321 char const *cp
= *linebuf
+ nold
;
1323 while(blankspacechar(*cp
) && nold
+ i
< n
)
1326 memmove(*linebuf
+ nold
, cp
, n
- nold
- i
);
1328 (*linebuf
)[n
] = '\0';
1337 * An unquoted <backslash> at the end of a command line shall
1338 * be discarded and the next line shall continue the command */
1339 if(!(lif
& n_LEXINPUT_NL_ESC
) || (*linebuf
)[n
- 1] != '\\'){
1341 pstate
|= PS_READLINE_NL
;
1344 /* Definitely outside of quotes, thus the quoting rules are so that an
1345 * uneven number of successive backslashs at EOL is a continuation */
1349 for(j
= 1, i
= (size_t)n
- 1; i
-- > 0; ++j
)
1350 if((*linebuf
)[i
] != '\\')
1355 (*linebuf
)[nold
= --n
] = '\0';
1356 if(prompt
!= NULL
&& *prompt
!= '\0')
1357 prompt
= ".. "; /* XXX PS2 .. */
1362 (*linebuf
)[*linesize
= n
] = '\0';
1366 if(lif
& n_LEXINPUT_DROP_TRAIL_SPC
){
1370 for(cp
= &(*linebuf
)[i
= (size_t)n
];; --i
){
1372 if(!blankspacechar(c
))
1375 (*linebuf
)[n
= (int)i
] = '\0';
1378 if(lif
& n_LEXINPUT_DROP_LEAD_SPC
){
1382 for(cp
= &(*linebuf
)[0], j
= (size_t)n
, i
= 0; i
< j
; ++i
){
1384 if(!blankspacechar(c
))
1388 memcpy(&(*linebuf
)[0], &(*linebuf
)[i
], j
-= i
);
1389 (*linebuf
)[n
= (int)j
] = '\0';
1392 #endif /* 0 (notyet - must take care for backslash escaped space) */
1394 if(options
& OPT_D_VV
)
1395 n_err(_("%s %d bytes <%s>\n"), iftype
, n
, *linebuf
);
1397 if (pstate
& PS_PSTATE_PENDMASK
)
1398 a_lex_update_pstate();
1404 n_lex_input_cp(enum n_lexinput_flags lif
, char const *prompt
,
1405 char const *string
){
1406 /* FIXME n_lex_input_cp_addhist(): leaks on sigjmp without linepool */
1416 n
= n_lex_input(lif
, prompt
, &linebuf
, &linesize
, string
);
1417 if(n
> 0 && *(rv
= savestrbuf(linebuf
, (size_t)n
)) != '\0' &&
1418 (lif
& n_LEXINPUT_HIST_ADD
) && (options
& OPT_INTERACTIVE
))
1419 n_tty_addhist(rv
, ((lif
& n_LEXINPUT_HIST_GABBY
) != 0));
1428 n_load(char const *name
){
1429 struct a_lex_input_stack
*lip
;
1434 if(name
== NULL
|| *name
== '\0' || (fip
= Fopen(name
, "r")) == NULL
)
1437 i
= strlen(name
) +1;
1438 lip
= scalloc(1, sizeof(*lip
) -
1439 VFIELD_SIZEOF(struct a_lex_input_stack
, li_name
) + i
);
1441 lip
->li_flags
= a_LEX_FREE
;
1442 memcpy(lip
->li_name
, name
, i
);
1451 n_load_Xargs(char const **lines
){
1452 static char const name
[] = "-X";
1454 ui8_t buf
[sizeof(struct a_lex_input_stack
) + sizeof name
];
1455 char const *srcp
, *xsrcp
;
1457 size_t imax
, i
, len
;
1458 struct a_lex_input_stack
*lip
;
1461 memset(buf
, 0, sizeof buf
);
1463 lip
->li_flags
= a_LEX_MACRO
| a_LEX_MACRO_FREE_DATA
|
1464 a_LEX_MACRO_X_OPTION
| a_LEX_SUPER_MACRO
;
1465 memcpy(lip
->li_name
, name
, sizeof name
);
1467 /* The problem being that we want to support reverse solidus newline
1468 * escaping also within multiline -X, i.e., POSIX says:
1469 * An unquoted <backslash> at the end of a command line shall
1470 * be discarded and the next line shall continue the command
1471 * Therefore instead of "lip->li_lines = UNCONST(lines)", duplicate the
1472 * entire lines array and set _MACRO_FREE_DATA */
1473 for(imax
= 0; lines
[imax
++] != NULL
;)
1475 lip
->li_lines
= smalloc(sizeof(*lip
->li_lines
) * imax
);
1477 /* For each of the input lines.. */
1478 for(i
= len
= 0, cp
= NULL
; (srcp
= *lines
) != NULL
;){
1482 if((j
= strlen(srcp
)) == 0){
1487 /* Separate one line from a possible multiline input string */
1488 if((xsrcp
= memchr(srcp
, '\n', j
)) != NULL
){
1490 j
= PTR2SIZE(xsrcp
- srcp
);
1494 /* The (separated) string may itself indicate soft newline escaping */
1495 if((keep
= (srcp
[j
- 1] == '\\'))){
1498 /* Need an uneven number of reverse solidus */
1499 for(xk
= 1, xj
= j
- 1; xj
-- > 0; ++xk
)
1500 if(srcp
[xj
] != '\\')
1508 /* Strip any leading WS from follow lines, then */
1510 while(j
> 0 && blankspacechar(*srcp
))
1514 if(i
+ 2 >= imax
){ /* TODO need a vector (main.c, here, ++) */
1516 lip
->li_lines
= srealloc(lip
->li_lines
, sizeof(*lip
->li_lines
) *
1519 lip
->li_lines
[i
] = cp
= srealloc(cp
, len
+ j
+1);
1520 memcpy(&cp
[len
], srcp
, j
);
1521 cp
[len
+= j
] = '\0';
1530 assert(i
+ 1 < imax
);
1531 lip
->li_lines
[i
++] = cp
;
1533 lip
->li_lines
[i
] = NULL
;
1536 if(pstate
& PS_EXIT
)
1546 rv
= (a_lex_source_file(*(char**)v
, FAL0
) == TRU1
) ? 0 : 1;
1552 c_source_if(void *v
){ /* XXX obsolete?, support file tests in `if' etc.! */
1556 rv
= (a_lex_source_file(*(char**)v
, TRU1
) != FAL0
) ? 0 : 1;
1562 n_source_macro(enum n_lexinput_flags lif
, char const *name
, char **lines
){
1563 struct a_lex_input_stack
*lip
;
1568 lip
= smalloc(sizeof(*lip
) -
1569 VFIELD_SIZEOF(struct a_lex_input_stack
, li_name
) +
1570 (i
= strlen(name
) +1));
1571 lip
->li_outer
= a_lex_input
;
1572 lip
->li_file
= NULL
;
1573 lip
->li_cond
= condstack_release();
1574 lip
->li_flags
= a_LEX_FREE
| a_LEX_MACRO
| a_LEX_MACRO_FREE_DATA
|
1575 (a_lex_input
== NULL
|| (a_lex_input
->li_flags
& a_LEX_SUPER_MACRO
)
1576 ? a_LEX_SUPER_MACRO
: 0);
1578 lip
->li_lines
= lines
;
1579 memcpy(lip
->li_name
, name
, i
);
1583 rv
= a_commands_recursive(lif
);
1589 n_source_command(enum n_lexinput_flags lif
, char const *cmd
){
1590 struct a_lex_input_stack
*lip
;
1596 cmd
= sbufdup(cmd
, i
++);
1599 lip
= smalloc(sizeof(*lip
) -
1600 VFIELD_SIZEOF(struct a_lex_input_stack
, li_name
) +
1601 ial
+ 2*sizeof(char*));
1602 lip
->li_outer
= a_lex_input
;
1603 lip
->li_file
= NULL
;
1604 lip
->li_cond
= condstack_release();
1605 lip
->li_flags
= a_LEX_FREE
| a_LEX_MACRO
| a_LEX_MACRO_FREE_DATA
|
1607 (a_lex_input
== NULL
|| (a_lex_input
->li_flags
& a_LEX_SUPER_MACRO
)
1608 ? a_LEX_SUPER_MACRO
: 0);
1610 lip
->li_lines
= (void*)(lip
->li_name
+ ial
);
1611 lip
->li_lines
[0] = UNCONST(cmd
); /* dup'ed above */
1612 lip
->li_lines
[1] = NULL
;
1613 memcpy(lip
->li_name
, cmd
, i
);
1617 rv
= a_commands_recursive(lif
);
1623 n_source_may_yield_control(void){
1624 return ((options
& OPT_INTERACTIVE
) &&
1625 (pstate
& PS_STARTED
) &&
1626 (!(pstate
& PS_ROBOT
) || (pstate
& PS_RECURSED
)) && /* Ok for ~: */
1627 (a_lex_input
== NULL
|| a_lex_input
->li_outer
== NULL
));