1 /*@ S-nail - a mail user agent derived from Berkeley Mail.
2 *@ Account, macro and variable handling.
3 *@ HOWTO add a new non-dynamic boolean or value option:
4 *@ - add an entry to nail.h:enum okeys
5 *@ - run mk-okey-map.pl
6 *@ - update the manual!
7 *@ TODO . should be recursive environment based.
8 *@ TODO Otherwise, the `localopts' should be an attribute of the lex-input.c
9 *@ TODO command context, so that it belongs to the execution context
10 *@ TODO we are running in, instead of being global data. See, e.g.,
11 *@ TODO the a_LEX_SPLICE comment in lex-input.c.
12 *@ TODO . once we can have non-fatal !0 returns for commands, we should
13 *@ TODO return error if "(environ)? unset" goes for non-existent.
15 * Copyright (c) 2000-2004 Gunnar Ritter, Freiburg i. Br., Germany.
16 * Copyright (c) 2012 - 2017 Steffen (Daode) Nurpmeso <steffen@sdaoden.eu>.
19 * Copyright (c) 1980, 1993
20 * The Regents of the University of California. All rights reserved.
22 * Redistribution and use in source and binary forms, with or without
23 * modification, are permitted provided that the following conditions
25 * 1. Redistributions of source code must retain the above copyright
26 * notice, this list of conditions and the following disclaimer.
27 * 2. Redistributions in binary form must reproduce the above copyright
28 * notice, this list of conditions and the following disclaimer in the
29 * documentation and/or other materials provided with the distribution.
30 * 3. Neither the name of the University nor the names of its contributors
31 * may be used to endorse or promote products derived from this software
32 * without specific prior written permission.
34 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
35 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
36 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
37 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
38 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
39 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
40 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
41 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
42 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
43 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
47 #define n_FILE accmacvar
49 #ifndef HAVE_AMALGAMATION
53 #if !defined HAVE_SETENV && !defined HAVE_PUTENV
54 # error Exactly one of HAVE_SETENV and HAVE_PUTENV
57 /* Special "pseudo macro" that stabs you from the back */
58 #define a_AMV_MACKY_MACK ((struct a_amv_mac*)-1)
60 /* Note: changing the hash function must be reflected in mk-okey-map.pl */
61 #define a_AMV_PRIME HSHSIZE
62 #define a_AMV_NAME2HASH(N) torek_hash(N)
63 #define a_AMV_HASH2PRIME(H) ((H) % a_AMV_PRIME)
67 a_AMV_MF_ACCOUNT
= 1<<0, /* This macro is an `account' */
68 a_AMV_MF_TYPE_MASK
= a_AMV_MF_ACCOUNT
,
69 a_AMV_MF_UNDEF
= 1<<1, /* Unlink after lookup */
70 a_AMV_MF_DELETE
= 1<<7, /* Delete in progress, free once refcnt==0 */
74 /* mk-okey-map.pl ensures that _VIRT implies _RDONLY and _NODEL, and that
75 * _IMPORT implies _ENV; it doesn't verify anything... */
78 a_AMV_VF_BOOL
= 1<<0, /* ok_b_* */
79 a_AMV_VF_VIRT
= 1<<1, /* "Stateless" automatic variable */
80 a_AMV_VF_NOLOPTS
= 1<<2, /* May not be tracked by `localopts' */
81 a_AMV_VF_RDONLY
= 1<<3, /* May not be set by user */
82 a_AMV_VF_NODEL
= 1<<4, /* May not be deleted */
83 a_AMV_VF_NOTEMPTY
= 1<<5, /* May not be assigned an empty value */
84 a_AMV_VF_NOCNTRLS
= 1<<6, /* Value may not contain control characters */
85 a_AMV_VF_NUM
= 1<<7, /* Value must be a 32-bit number */
86 a_AMV_VF_POSNUM
= 1<<8, /* Value must be positive 32-bit number */
87 a_AMV_VF_LOWER
= 1<<9, /* Values will be stored in a lowercase version */
88 a_AMV_VF_VIP
= 1<<10, /* Wants _var_check_vips() evaluation */
89 a_AMV_VF_IMPORT
= 1<<11, /* Import ONLY from environ (pre n_PSO_STARTED) */
90 a_AMV_VF_ENV
= 1<<12, /* Update environment on change */
91 a_AMV_VF_I3VAL
= 1<<13, /* Has an initial value */
92 a_AMV_VF_DEFVAL
= 1<<14, /* Has a default value */
93 a_AMV_VF_LINKED
= 1<<15, /* `environ' linked */
94 a_AMV_VF__MASK
= (1<<(15+1)) - 1
97 /* We support some special parameter names for one-letter variable names;
98 * note these have counterparts in the code that manages shell expansion!
99 * Macro-local variables are solely backed by n_var_vlook(), and besides there
100 * is only a_amv_var_revlookup() which knows about them.
101 * The ARGV $[1-9][0-9]* variables are also special, but they are special ;] */
102 enum a_amv_var_special_category
{
103 a_AMV_VSC_NONE
, /* Normal variable, no special treatment */
104 a_AMV_VSC_GLOBAL
, /* ${[?!]} are specially mapped, but global */
105 a_AMV_VSC_MULTIPLEX
, /* ${^.*} circumflex accent multiplexer */
106 a_AMV_VSC_MAC
, /* ${[*@#]} macro argument access */
107 a_AMV_VSC_MAC_ARGV
/* ${[1-9][0-9]*} macro ARGV access */
110 enum a_amv_var_special_type
{
112 a_AMV_VST_QM
, /* ? */
113 a_AMV_VST_EM
, /* ! */
115 /* This is special in that it is a multiplex indicator, the ^ is followed by
116 * a normal variable */
117 a_AMV_VST_CACC
, /* ^ (circumflex accent) */
119 a_AMV_VST_STAR
, /* * */
120 a_AMV_VST_AT
, /* @ */
121 a_AMV_VST_NOSIGN
/* # */
124 enum a_amv_var_vip_mode
{
131 struct a_amv_mac
*am_next
;
132 ui32_t am_maxlen
; /* of any line in .am_line_dat */
133 ui32_t am_line_cnt
; /* of *.am_line_dat (but NULL terminated) */
134 struct a_amv_mac_line
**am_line_dat
; /* TODO use deque? */
135 struct a_amv_var
*am_lopts
; /* `localopts' unroll list */
136 ui32_t am_refcnt
; /* 0-based for `un{account,define}' purposes */
137 ui8_t am_flags
; /* enum a_amv_mac_flags */
138 char am_name
[n_VFIELD_SIZE(3)]; /* of this macro */
140 n_CTA(a_AMV_MF__MAX
<= UI8_MAX
, "Enumeration excesses storage datatype");
142 struct a_amv_mac_line
{
144 ui32_t aml_prespc
; /* Number of leading SPC, for display purposes */
145 char aml_dat
[n_VFIELD_SIZE(0)];
148 struct a_amv_mac_call_args
{
149 char const *amca_name
; /* For MACKY_MACK, this is *0*! */
150 struct a_amv_mac
*amca_amp
; /* "const", but for am_refcnt */
151 struct a_amv_var
**amca_unroller
;
152 void (*amca_hook_pre
)(void *);
154 bool_t amca_lopts_on
;
155 bool_t amca_ps_hook_mask
;
157 ui16_t amca_argc
; /* Max is SI16_MAX */
158 char const **amca_argv
;
161 struct a_amv_lostack
{
162 struct a_amv_lostack
*as_global_saved
; /* Saved global XXX due to jump */
163 struct a_amv_mac_call_args
*as_amcap
;
164 struct a_amv_lostack
*as_up
; /* Outer context */
165 struct a_amv_var
*as_lopts
;
166 bool_t as_unroll
; /* Unrolling enabled? */
171 struct a_amv_var
*av_link
;
174 char *av_env
; /* Actively managed putenv(3) memory */
176 ui16_t av_flags
; /* enum a_amv_var_flags */
177 char av_name
[n_VFIELD_SIZE(6)];
179 n_CTA(a_AMV_VF__MASK
<= UI16_MAX
, "Enumeration excesses storage datatype");
181 struct a_amv_var_map
{
184 ui16_t avm_flags
; /* enum a_amv_var_flags */
186 n_CTA(a_AMV_VF__MASK
<= UI16_MAX
, "Enumeration excesses storage datatype");
188 struct a_amv_var_virt
{
191 struct a_amv_var
const *avv_var
;
194 struct a_amv_var_defval
{
197 char const *avdv_value
; /* Only for !BOOL (otherwise plain existence) */
200 struct a_amv_var_carrier
{
201 char const *avc_name
;
204 struct a_amv_var
*avc_var
;
205 struct a_amv_var_map
const *avc_map
;
208 ui8_t avc_special_cat
;
209 /* Numerical parameter name if .avc_special_cat=a_AMV_VSC_MAC_ARGV,
210 * otherwise a enum a_amv_var_special_type */
211 ui16_t avc_special_prop
;
214 /* Include the constant mk-okey-map.pl output, and the generated version data */
215 #include "gen-version.h"
216 #include "gen-okeys.h"
218 /* The currently active account */
219 static struct a_amv_mac
*a_amv_acc_curr
;
221 static struct a_amv_mac
*a_amv_macs
[a_AMV_PRIME
]; /* TODO dynamically spaced */
223 /* Unroll list of currently running macro stack */
224 static struct a_amv_lostack
*a_amv_lopts
;
226 static struct a_amv_var
*a_amv_vars
[a_AMV_PRIME
]; /* TODO dynamically spaced */
228 /* TODO We really deserve localopts support for *folder-hook*s, so hack it in
229 * TODO today via a static lostack, it should be a field in mailbox, once that
230 * TODO is a real multi-instance object */
231 static struct a_amv_var
*a_amv_folder_hook_lopts
;
233 /* TODO Rather ditto (except for storage -> cmd_ctx), compose hooks */
234 static struct a_amv_var
*a_amv_compose_lopts
;
236 /* Lookup for macros/accounts: if newamp is not NULL it will be linked in the
237 * map, if _MF_UNDEF is set a possibly existing entry will be removed (first).
238 * Returns NULL if a lookup failed, or if newamp was set, the found entry in
239 * plain lookup cases or when _UNDEF was performed on a currently active entry
240 * (the entry will have been unlinked, and the _MF_DELETE will be honoured once
241 * the reference count reaches 0), and (*)-1 if an _UNDEF was performed */
242 static struct a_amv_mac
*a_amv_mac_lookup(char const *name
,
243 struct a_amv_mac
*newamp
, enum a_amv_mac_flags amf
);
245 /* `call', `call_if' */
246 static int a_amv_mac_call(void *v
, bool_t silent_nexist
);
248 /* Execute a macro; amcap must reside in LOFI memory */
249 static bool_t
a_amv_mac_exec(struct a_amv_mac_call_args
*amcap
);
251 static void a_amv_mac__finalize(void *vp
);
253 /* User display helpers */
254 static bool_t
a_amv_mac_show(enum a_amv_mac_flags amf
);
256 /* _def() returns error for faulty definitions and already existing * names,
257 * _undef() returns error if a named thing doesn't exist */
258 static bool_t
a_amv_mac_def(char const *name
, enum a_amv_mac_flags amf
);
259 static bool_t
a_amv_mac_undef(char const *name
, enum a_amv_mac_flags amf
);
262 static void a_amv_mac_free(struct a_amv_mac
*amp
);
264 /* Update replay-log */
265 static void a_amv_lopts_add(struct a_amv_lostack
*alp
, char const *name
,
266 struct a_amv_var
*oavp
);
267 static void a_amv_lopts_unroll(struct a_amv_var
**avpp
);
269 /* Special cased value string allocation */
270 static char *a_amv_var_copy(char const *str
);
271 static void a_amv_var_free(char *cp
);
273 /* Check for special housekeeping. _VIP_SET_POST and _VIP_CLEAR do not fail
274 * (or propagate errors), _VIP_SET_PRE may and should case abortion */
275 static bool_t
a_amv_var_check_vips(enum a_amv_var_vip_mode avvm
,
276 enum okeys okey
, char const *val
);
278 /* _VF_NOCNTRLS, _VF_NUM / _VF_POSNUM */
279 static bool_t
a_amv_var_check_nocntrls(char const *val
);
280 static bool_t
a_amv_var_check_num(char const *val
, bool_t posnum
);
282 /* If a variable name begins with a lowercase-character and contains at
283 * least one '@', it is converted to all-lowercase. This is necessary
284 * for lookups of names based on email addresses.
285 * Following the standard, only the part following the last '@' should
286 * be lower-cased, but practice has established otherwise here */
287 static char const *a_amv_var_canonify(char const *vn
);
289 /* Try to reverse lookup an option name to an enum okeys mapping.
290 * Updates .avc_name and .avc_hash; .avc_map is NULL if none found */
291 static bool_t
a_amv_var_revlookup(struct a_amv_var_carrier
*avcp
,
294 /* Lookup a variable from .avc_(map|name|hash), return whether it was found.
295 * Sets .avc_prime; .avc_var is NULL if not found.
296 * Here it is where we care for _I3VAL and _DEFVAL, too.
297 * An _I3VAL will be "consumed" as necessary anyway, but it won't be used to
298 * create a new variable if i3val_nonew is true; if i3val_nonew is TRUM1 then
299 * we set .avc_var to -1 and return true if that was the case, otherwise we'll
300 * return FAL0, then! */
301 static bool_t
a_amv_var_lookup(struct a_amv_var_carrier
*avcp
,
304 /* Lookup functions for special category variables, _mac drives all macro etc.
305 * local special categories */
306 static char const *a_amv_var_vsc_global(struct a_amv_var_carrier
*avcp
);
307 static char const *a_amv_var_vsc_multiplex(struct a_amv_var_carrier
*avcp
);
308 static char const *a_amv_var_vsc_mac(struct a_amv_var_carrier
*avcp
);
310 /* Set var from .avc_(map|name|hash), return success */
311 static bool_t
a_amv_var_set(struct a_amv_var_carrier
*avcp
, char const *value
,
314 static bool_t
a_amv_var__putenv(struct a_amv_var_carrier
*avcp
,
315 struct a_amv_var
*avp
);
317 /* Clear var from .avc_(map|name|hash); sets .avc_var=NULL, return success */
318 static bool_t
a_amv_var_clear(struct a_amv_var_carrier
*avcp
, bool_t force_env
);
320 static bool_t
a_amv_var__clearenv(char const *name
, char *value
);
322 /* List all variables */
323 static void a_amv_var_show_all(void);
325 static int a_amv_var__show_cmp(void const *s1
, void const *s2
);
327 /* Actually do print one, return number of lines written */
328 static size_t a_amv_var_show(char const *name
, FILE *fp
, struct n_string
*msgp
);
330 /* Shared c_set() and c_environ():set impl, return success */
331 static bool_t
a_amv_var_c_set(char **ap
, bool_t issetenv
);
333 static struct a_amv_mac
*
334 a_amv_mac_lookup(char const *name
, struct a_amv_mac
*newamp
,
335 enum a_amv_mac_flags amf
){
336 struct a_amv_mac
*amp
, **ampp
;
338 enum a_amv_mac_flags save_amf
;
342 amf
&= a_AMV_MF_TYPE_MASK
;
343 h
= a_AMV_NAME2HASH(name
);
344 h
= a_AMV_HASH2PRIME(h
);
345 ampp
= &a_amv_macs
[h
];
347 for(amp
= *ampp
; amp
!= NULL
; ampp
= &(*ampp
)->am_next
, amp
= amp
->am_next
){
348 if((amp
->am_flags
& a_AMV_MF_TYPE_MASK
) == amf
&&
349 !strcmp(amp
->am_name
, name
)){
350 if(n_LIKELY((save_amf
& a_AMV_MF_UNDEF
) == 0))
353 *ampp
= amp
->am_next
;
355 if(amp
->am_refcnt
> 0){
356 amp
->am_flags
|= a_AMV_MF_DELETE
;
357 if(n_poption
& n_PO_D_V
)
358 n_err(_("Delayed deletion of currently active %s: %s\n"),
359 (amp
->am_flags
& a_AMV_MF_ACCOUNT
? "account" : "define"),
363 amp
= (struct a_amv_mac
*)-1;
370 ampp
= &a_amv_macs
[h
];
371 newamp
->am_next
= *ampp
;
381 a_amv_mac_call(void *v
, bool_t silent_nexist
){
383 struct a_amv_mac
*amp
;
387 name
= *(char const**)v
;
389 if((amp
= a_amv_mac_lookup(name
, NULL
, a_AMV_MF_NONE
)) != NULL
){
390 struct a_amv_mac_call_args
*amcap
;
392 amcap
= n_lofi_alloc(sizeof *amcap
);
393 memset(amcap
, 0, sizeof *amcap
);
394 amcap
->amca_name
= name
;
395 amcap
->amca_amp
= amp
;
400 for(argc
= 0, argv
= v
; *++argv
!= NULL
; ++argc
)
403 amcap
->amca_argc
= argc
;
404 amcap
->amca_argv
= &(argv
= v
)[1];
407 rv
= (a_amv_mac_exec(amcap
) == FAL0
);
408 }else if((rv
= (silent_nexist
== FAL0
)))
409 n_err(_("Undefined macro `call'ed: %s\n"), n_shexp_quote_cp(name
, FAL0
));
415 a_amv_mac_exec(struct a_amv_mac_call_args
*amcap
){
416 struct a_amv_lostack
*losp
;
417 struct a_amv_mac_line
**amlp
;
418 char **args_base
, **args
;
419 struct a_amv_mac
*amp
;
423 amp
= amcap
->amca_amp
;
424 assert(amp
!= NULL
&& amp
!= a_AMV_MACKY_MACK
);
426 /* XXX Unfortunately we yet need to dup the macro lines! :( */
427 args_base
= args
= smalloc(sizeof(*args
) * (amp
->am_line_cnt
+1));
428 for(amlp
= amp
->am_line_dat
; *amlp
!= NULL
; ++amlp
)
429 *(args
++) = sbufdup((*amlp
)->aml_dat
, (*amlp
)->aml_len
);
432 losp
= n_lofi_alloc(sizeof *losp
);
433 losp
->as_global_saved
= a_amv_lopts
;
434 if((losp
->as_amcap
= amcap
)->amca_unroller
== NULL
){
435 losp
->as_up
= losp
->as_global_saved
;
436 losp
->as_lopts
= NULL
;
439 losp
->as_lopts
= *amcap
->amca_unroller
;
441 losp
->as_unroll
= amcap
->amca_lopts_on
;
444 if(amcap
->amca_hook_pre
!= NULL
)
445 n_PS_ROOT_BLOCK((*amcap
->amca_hook_pre
)(amcap
->amca_hook_arg
));
446 rv
= n_source_macro(n_LEXINPUT_NONE
, amp
->am_name
, args_base
,
447 &a_amv_mac__finalize
, losp
);
453 a_amv_mac__finalize(void *vp
){
454 struct a_amv_mac
*amp
;
455 struct a_amv_mac_call_args
*amcap
;
456 struct a_amv_lostack
*losp
;
460 a_amv_lopts
= losp
->as_global_saved
;
462 if((amcap
= losp
->as_amcap
)->amca_unroller
== NULL
){
463 if(losp
->as_lopts
!= NULL
)
464 a_amv_lopts_unroll(&losp
->as_lopts
);
466 *amcap
->amca_unroller
= losp
->as_lopts
;
468 if(amcap
->amca_ps_hook_mask
)
469 n_pstate
&= ~n_PS_HOOK_MASK
;
471 if((amp
= amcap
->amca_amp
) != a_AMV_MACKY_MACK
&& amp
!= NULL
&&
472 --amp
->am_refcnt
== 0 && (amp
->am_flags
& a_AMV_MF_DELETE
))
481 a_amv_mac_show(enum a_amv_mac_flags amf
){
482 size_t lc
, mc
, ti
, i
;
490 if((fp
= Ftmp(NULL
, "deflist", OF_RDWR
| OF_UNLINK
| OF_REGISTER
)) ==
492 n_perr(_("Can't create temporary file for `define' or `account' listing"),
497 amf
&= a_AMV_MF_TYPE_MASK
;
498 typestr
= (amf
& a_AMV_MF_ACCOUNT
) ? "account" : "define";
500 for(lc
= mc
= ti
= 0; ti
< a_AMV_PRIME
; ++ti
){
501 struct a_amv_mac
*amp
;
503 for(amp
= a_amv_macs
[ti
]; amp
!= NULL
; amp
= amp
->am_next
){
504 if((amp
->am_flags
& a_AMV_MF_TYPE_MASK
) == amf
){
505 struct a_amv_mac_line
**amlpp
;
512 fprintf(fp
, "%s %s {\n", typestr
, amp
->am_name
);
513 for(amlpp
= amp
->am_line_dat
; *amlpp
!= NULL
; ++lc
, ++amlpp
){
514 for(i
= (*amlpp
)->aml_prespc
; i
> 0; --i
)
516 fputs((*amlpp
)->aml_dat
, fp
);
525 page_or_print(fp
, lc
);
527 rv
= (ferror(fp
) == 0);
535 a_amv_mac_def(char const *name
, enum a_amv_mac_flags amf
){
537 ui32_t line_cnt
, maxlen
;
539 struct linelist
*ll_next
;
540 struct a_amv_mac_line
*ll_amlp
;
541 } *llp
, *ll_head
, *ll_tail
;
542 union {size_t s
; int i
; ui32_t ui
; size_t l
;} n
;
543 struct a_amv_mac
*amp
;
547 memset(&line
, 0, sizeof line
);
551 /* TODO We should have our input state machine which emits Line events,
552 * TODO and hook different consumers dependent on our content, as stated
553 * TODO in i think lex_input; */
554 /* Read in the lines which form the macro content */
555 for(ll_tail
= ll_head
= NULL
, line_cnt
= maxlen
= 0;;){
559 n
.i
= n_lex_input(n_LEXINPUT_CTX_DEFAULT
| n_LEXINPUT_NL_ESC
, n_empty
,
560 &line
.s
, &line
.l
, NULL
);
564 n_err(_("Unterminated %s definition: %s\n"),
565 (amf
& a_AMV_MF_ACCOUNT
? "account" : "macro"), name
);
569 /* Trim WS, remember amount of leading spaces for display purposes */
570 for(cp
= line
.s
, leaspc
= 0; n
.ui
> 0; ++cp
, --n
.ui
)
572 leaspc
= (leaspc
+ 8u) & ~7u;
577 for(; n
.ui
> 0 && spacechar(cp
[n
.ui
- 1]); --n
.ui
)
582 maxlen
= n_MAX(maxlen
, n
.ui
);
585 /* Is is the closing brace? */
589 if(n_LIKELY(++line_cnt
< UI32_MAX
)){
590 struct a_amv_mac_line
*amlp
;
592 llp
= salloc(sizeof *llp
);
596 ll_tail
->ll_next
= llp
;
599 llp
->ll_amlp
= amlp
= smalloc(n_VSTRUCT_SIZEOF(struct a_amv_mac_line
,
601 amlp
->aml_len
= n
.ui
-1;
602 amlp
->aml_prespc
= leaspc
;
603 memcpy(amlp
->aml_dat
, cp
, n
.ui
);
605 n_err(_("Too much content in %s definition: %s\n"),
606 (amf
& a_AMV_MF_ACCOUNT
? "account" : "macro"), name
);
611 /* Create the new macro */
612 n
.s
= strlen(name
) +1;
613 amp
= smalloc(n_VSTRUCT_SIZEOF(struct a_amv_mac
, am_name
) + n
.s
);
615 amp
->am_maxlen
= maxlen
;
616 amp
->am_line_cnt
= line_cnt
;
619 amp
->am_lopts
= NULL
;
620 memcpy(amp
->am_name
, name
, n
.s
);
622 struct a_amv_mac_line
**amlpp
;
624 amp
->am_line_dat
= amlpp
= smalloc(sizeof(*amlpp
) * ++line_cnt
);
625 for(llp
= ll_head
; llp
!= NULL
; llp
= llp
->ll_next
)
626 *amlpp
++ = llp
->ll_amlp
;
630 /* Create entry, replace a yet existing one as necessary */
631 a_amv_mac_lookup(name
, amp
, amf
| a_AMV_MF_UNDEF
);
640 for(llp
= ll_head
; llp
!= NULL
; llp
= llp
->ll_next
)
643 free(amp
->am_line_dat
);
650 a_amv_mac_undef(char const *name
, enum a_amv_mac_flags amf
){
651 struct a_amv_mac
*amp
;
657 if(n_LIKELY(name
[0] != '*' || name
[1] != '\0')){
658 if((amp
= a_amv_mac_lookup(name
, NULL
, amf
| a_AMV_MF_UNDEF
)) == NULL
){
659 n_err(_("%s not defined: %s\n"),
660 (amf
& a_AMV_MF_ACCOUNT
? "Account" : "Macro"), name
);
664 struct a_amv_mac
**ampp
, *lamp
;
666 for(ampp
= a_amv_macs
; PTRCMP(ampp
, <, &a_amv_macs
[n_NELEM(a_amv_macs
)]);
668 for(lamp
= NULL
, amp
= *ampp
; amp
!= NULL
;){
669 if((amp
->am_flags
& a_AMV_MF_TYPE_MASK
) == amf
){
670 /* xxx Expensive but rare: be simple */
671 a_amv_mac_lookup(amp
->am_name
, NULL
, amf
| a_AMV_MF_UNDEF
);
672 amp
= (lamp
== NULL
) ? *ampp
: lamp
->am_next
;
684 a_amv_mac_free(struct a_amv_mac
*amp
){
685 struct a_amv_mac_line
**amlpp
;
688 for(amlpp
= amp
->am_line_dat
; *amlpp
!= NULL
; ++amlpp
)
690 free(amp
->am_line_dat
);
696 a_amv_lopts_add(struct a_amv_lostack
*alp
, char const *name
,
697 struct a_amv_var
*oavp
){
698 struct a_amv_var
*avp
;
702 /* Propagate unrolling up the stack, as necessary */
707 if((alp
= alp
->as_up
) == NULL
)
711 /* Check whether this variable is handled yet */
712 for(avp
= alp
->as_lopts
; avp
!= NULL
; avp
= avp
->av_link
)
713 if(!strcmp(avp
->av_name
, name
))
716 nl
= strlen(name
) +1;
717 vl
= (oavp
!= NULL
) ? strlen(oavp
->av_value
) +1 : 0;
718 avp
= smalloc(n_VSTRUCT_SIZEOF(struct a_amv_var
, av_name
) + nl
+ vl
);
719 avp
->av_link
= alp
->as_lopts
;
721 memcpy(avp
->av_name
, name
, nl
);
723 avp
->av_value
= NULL
;
729 avp
->av_value
= &avp
->av_name
[nl
];
730 avp
->av_flags
= oavp
->av_flags
;
731 memcpy(avp
->av_value
, oavp
->av_value
, vl
);
733 avp
->av_env
= (oavp
->av_env
== NULL
) ? NULL
: sstrdup(oavp
->av_env
);
741 a_amv_lopts_unroll(struct a_amv_var
**avpp
){
742 struct a_amv_lostack
*save_alp
;
743 struct a_amv_var
*x
, *avp
;
749 save_alp
= a_amv_lopts
;
754 n_PS_ROOT_BLOCK(n_var_vset(x
->av_name
, (uintptr_t)x
->av_value
));
757 a_amv_lopts
= save_alp
;
762 a_amv_var_copy(char const *str
){
768 news
= n_UNCONST(n_empty
);
769 else if(str
[1] == '\0'){
771 news
= n_UNCONST(n_1
);
772 else if(str
[0] == '0')
773 news
= n_UNCONST(n_0
);
776 }else if(str
[2] == '\0' && str
[0] == '-' && str
[1] == '1')
777 news
= n_UNCONST(n_m1
);
780 len
= strlen(str
) +1;
782 memcpy(news
, str
, len
);
789 a_amv_var_free(char *cp
){
791 if(cp
[0] != '\0' && cp
!= n_0
&& cp
!= n_1
&& cp
!= n_m1
)
797 a_amv_var_check_vips(enum a_amv_var_vip_mode avvm
, enum okeys okey
,
804 if(avvm
== a_AMV_VIP_SET_PRE
){
809 /* Note this gets called from main.c during initialization, and they
810 * simply set this to pw_dir as a fallback: don't verify _that_ call.
812 if(!(n_pstate
& n_PS_ROOT
) && !n_is_dir(val
, TRU1
)){
813 n_err(_("$HOME is not a directory or not accessible: %s\n"),
814 n_shexp_quote_cp(val
, FAL0
));
819 if(!n_is_dir(val
, TRU1
)){
820 n_err(_("$TMPDIR is not a directory or not accessible: %s\n"),
821 n_shexp_quote_cp(val
, FAL0
));
829 n_idec_ui64_cp(&uib
, val
, 0, NULL
);
830 if(uib
& ~0777u){ /* (is valid _VF_POSNUM) */
831 n_err(_("Invalid *umask* setting: %s\n"), val
);
837 }else if(avvm
== a_AMV_VIP_SET_POST
){
842 n_poption
|= n_PO_DEBUG
;
845 /* Invalidate any resolved folder then, too
848 n_PS_ROOT_BLOCK(ok_vclear(folder_resolved
));
851 n_poption
|= n_PO_MEMDEBUG
;
853 case ok_b_POSIXLY_CORRECT
: /* <-> *posix* */
854 if(!(n_pstate
& n_PS_ROOT
))
855 n_PS_ROOT_BLOCK(ok_bset(posix
));
857 case ok_b_posix
: /* <-> $POSIXLY_CORRECT */
858 if(!(n_pstate
& n_PS_ROOT
))
859 n_PS_ROOT_BLOCK(ok_bset(POSIXLY_CORRECT
));
861 case ok_b_skipemptybody
:
862 n_poption
|= n_PO_E_FLAG
;
864 case ok_b_typescript_mode
:
865 ok_bset(colour_disable
);
866 ok_bset(line_editor_disable
);
867 if(!(n_psonce
& n_PSO_STARTED
))
868 ok_bset(termcap_disable
);
873 n_idec_ui64_cp(&uib
, val
, 0, NULL
);
878 n_poption
|= (n_poption
& n_PO_VERB
) ? n_PO_VERBVERB
: n_PO_VERB
;
886 n_poption
&= ~n_PO_DEBUG
;
889 /* Invalidate any resolved folder then, too
892 n_PS_ROOT_BLOCK(ok_vclear(folder_resolved
));
895 n_poption
&= ~n_PO_MEMDEBUG
;
897 case ok_b_POSIXLY_CORRECT
: /* <-> *posix* */
898 if(!(n_pstate
& n_PS_ROOT
))
899 n_PS_ROOT_BLOCK(ok_bclear(posix
));
901 case ok_b_posix
: /* <-> $POSIXLY_CORRECT */
902 if(!(n_pstate
& n_PS_ROOT
))
903 n_PS_ROOT_BLOCK(ok_bclear(POSIXLY_CORRECT
));
905 case ok_b_skipemptybody
:
906 n_poption
&= ~n_PO_E_FLAG
;
909 n_poption
&= ~(n_PO_VERB
| n_PO_VERBVERB
);
918 a_amv_var_check_nocntrls(char const *val
){
922 while((c
= *val
++) != '\0')
930 a_amv_var_check_num(char const *val
, bool_t posnum
){
931 /* TODO The internal/environment variables which are num= or posnum= should
932 * TODO gain special lookup functions, or the return should be void* and
933 * TODO castable to integer; i.e. no more strtoX() should be needed.
934 * TODO I.e., the result of this function should instead be stored */
940 if(*val
!= '\0'){ /* Would be _VF_NOTEMPTY if not allowed */
942 enum n_idec_state ids
;
944 ids
= n_idec_cp(&uib
, val
, 0,
945 (posnum
? n_IDEC_MODE_SIGNED_TYPE
: n_IDEC_MODE_NONE
), NULL
);
946 if((ids
& (n_IDEC_STATE_EMASK
| n_IDEC_STATE_CONSUMED
)
947 ) != n_IDEC_STATE_CONSUMED
)
949 /* TODO Unless we store integers we need to look and forbid, because
950 * TODO callee may not be able to swallow, e.g., "-1" */
951 if(posnum
&& (ids
& n_IDEC_STATE_SEEN_MINUS
))
959 a_amv_var_canonify(char const *vn
){
964 for(vp
= vn
; *vp
!= '\0' && *vp
!= '@'; ++vp
)
966 vn
= (*vp
== '@') ? i_strdup(vn
) : vn
;
973 a_amv_var_revlookup(struct a_amv_var_carrier
*avcp
, char const *name
){
975 struct a_amv_var_map
const *avmp
;
979 /* It may be a special a.k.a. macro-local or one-letter parameter */
981 if(n_UNLIKELY(digitchar(c
))){
982 /* (Inline dec. atoi, ugh) */
983 for(j
= (ui8_t
)c
- '0', i
= 1;; ++i
){
988 goto jno_special_param
;
989 j
= j
* 10 + (ui8_t
)c
- '0';
992 avcp
->avc_special_cat
= a_AMV_VSC_MAC_ARGV
;
995 }else if(n_UNLIKELY(name
[1] == '\0')){
999 avcp
->avc_special_cat
= a_AMV_VSC_GLOBAL
;
1000 j
= (c
== '?') ? a_AMV_VST_QM
: a_AMV_VST_EM
;
1001 goto jspecial_param
;
1005 avcp
->avc_special_cat
= a_AMV_VSC_MAC
;
1007 goto jspecial_param
;
1009 avcp
->avc_special_cat
= a_AMV_VSC_MAC
;
1011 goto jspecial_param
;
1013 avcp
->avc_special_cat
= a_AMV_VSC_MAC
;
1014 j
= a_AMV_VST_NOSIGN
;
1015 goto jspecial_param
;
1021 avcp
->avc_special_cat
= a_AMV_VSC_MULTIPLEX
;
1023 goto jspecial_param
;
1026 /* Normal reverse lookup, walk over the hashtable */
1028 avcp
->avc_special_cat
= a_AMV_VSC_NONE
;
1029 avcp
->avc_name
= name
= a_amv_var_canonify(name
);
1030 avcp
->avc_hash
= hash
= a_AMV_NAME2HASH(name
);
1032 for(i
= hash
% a_AMV_VAR_REV_PRIME
, j
= 0; j
<= a_AMV_VAR_REV_LONGEST
; ++j
){
1035 if((x
= a_amv_var_revmap
[i
]) == a_AMV_VAR_REV_ILL
)
1038 avmp
= &a_amv_var_map
[x
];
1039 if(avmp
->avm_hash
== hash
&&
1040 !strcmp(&a_amv_var_names
[avmp
->avm_keyoff
], name
)){
1041 avcp
->avc_map
= avmp
;
1042 avcp
->avc_okey
= (enum okeys
)x
;
1046 if(++i
== a_AMV_VAR_REV_PRIME
){
1047 #ifdef a_AMV_VAR_REV_WRAPAROUND
1054 avcp
->avc_map
= NULL
;
1058 return (avcp
!= NULL
);
1060 /* All these are mapped to *--special-param* */
1062 avcp
->avc_name
= name
;
1063 avcp
->avc_special_prop
= (ui16_t
)j
;
1064 avmp
= &a_amv_var_map
[a_AMV_VAR__SPECIAL_PARAM_MAP_IDX
];
1065 avcp
->avc_hash
= avmp
->avm_hash
;
1066 avcp
->avc_map
= avmp
;
1067 avcp
->avc_okey
= ok_v___special_param
;
1072 a_amv_var_lookup(struct a_amv_var_carrier
*avcp
, bool_t i3val_nonew
){
1075 struct a_amv_var_map
const *avmp
;
1076 struct a_amv_var
*avp
;
1080 struct a_amv_var
**avpp
, *lavp
;
1082 avpp
= &a_amv_vars
[avcp
->avc_prime
= a_AMV_HASH2PRIME(avcp
->avc_hash
)];
1084 for(lavp
= NULL
, avp
= *avpp
; avp
!= NULL
; lavp
= avp
, avp
= avp
->av_link
)
1085 if(!strcmp(avp
->av_name
, avcp
->avc_name
)){
1086 /* Relink as head, hope it "sorts on usage" over time.
1087 * _clear() relies on this behaviour */
1089 lavp
->av_link
= avp
->av_link
;
1090 avp
->av_link
= *avpp
;
1097 /* If this is not an assembled variable we need to consider some special
1098 * initialization cases and eventually create the variable anew */
1099 if(n_LIKELY((avmp
= avcp
->avc_map
) != NULL
)){
1100 /* Does it have an import-from-environment flag? */
1101 if(n_UNLIKELY((avmp
->avm_flags
& (a_AMV_VF_IMPORT
| a_AMV_VF_ENV
)) != 0)){
1102 if(n_LIKELY((cp
= getenv(avcp
->avc_name
)) != NULL
)){
1103 /* May be better not to use that one, though? */
1104 bool_t isempty
, isbltin
;
1106 isempty
= (*cp
== '\0' &&
1107 (avmp
->avm_flags
& a_AMV_VF_NOTEMPTY
) != 0);
1108 isbltin
= ((avmp
->avm_flags
& (a_AMV_VF_I3VAL
| a_AMV_VF_DEFVAL
)
1111 if(n_UNLIKELY(isempty
)){
1114 }else if(n_LIKELY(*cp
!= '\0')){
1115 if(n_UNLIKELY((avmp
->avm_flags
& a_AMV_VF_NOCNTRLS
) &&
1116 !a_amv_var_check_nocntrls(cp
))){
1117 n_err(_("Ignoring environment, control characters "
1118 "invalid in variable: %s\n"), avcp
->avc_name
);
1121 if(n_UNLIKELY((avmp
->avm_flags
& a_AMV_VF_NUM
) &&
1122 !a_amv_var_check_num(cp
, FAL0
))){
1123 n_err(_("Environment variable value not a number "
1124 "or out of range: %s\n"), avcp
->avc_name
);
1127 if(n_UNLIKELY((avmp
->avm_flags
& a_AMV_VF_POSNUM
) &&
1128 !a_amv_var_check_num(cp
, TRU1
))){
1129 n_err(_("Environment variable value not a number, "
1130 "negative or out of range: %s\n"), avcp
->avc_name
);
1139 /* A first-time init switch is to be handled now and here */
1140 if(n_UNLIKELY((avmp
->avm_flags
& a_AMV_VF_I3VAL
) != 0)){
1141 static struct a_amv_var_defval
const **arr
,
1142 *arr_base
[a_AMV_VAR_I3VALS_CNT
+1];
1146 arr
[i
= a_AMV_VAR_I3VALS_CNT
] = NULL
;
1148 arr
[i
] = &a_amv_var_i3vals
[i
];
1151 for(i
= 0; arr
[i
] != NULL
; ++i
)
1152 if(arr
[i
]->avdv_okey
== avcp
->avc_okey
){
1153 cp
= (avmp
->avm_flags
& a_AMV_VF_BOOL
) ? n_empty
1154 : arr
[i
]->avdv_value
;
1155 /* Remove this entry, hope entire block becomes no-op asap */
1157 arr
[i
] = arr
[i
+ 1];
1158 while(arr
[i
++] != NULL
);
1162 if(i3val_nonew
== TRUM1
)
1163 avp
= (struct a_amv_var
*)-1;
1168 /* The virtual variables */
1169 if(n_UNLIKELY((avmp
->avm_flags
& a_AMV_VF_VIRT
) != 0)){
1170 for(i
= 0; i
< a_AMV_VAR_VIRTS_CNT
; ++i
)
1171 if(a_amv_var_virts
[i
].avv_okey
== avcp
->avc_okey
){
1172 avp
= n_UNCONST(a_amv_var_virts
[i
].avv_var
);
1178 /* Place this last because once it is set first the variable will never
1179 * be removed again and thus match in the first block above */
1181 if(n_UNLIKELY(avmp
->avm_flags
& a_AMV_VF_DEFVAL
) != 0){
1182 for(i
= 0; i
< a_AMV_VAR_DEFVALS_CNT
; ++i
)
1183 if(a_amv_var_defvals
[i
].avdv_okey
== avcp
->avc_okey
){
1184 cp
= (avmp
->avm_flags
& a_AMV_VF_BOOL
) ? n_empty
1185 : a_amv_var_defvals
[i
].avdv_value
;
1194 avcp
->avc_var
= avp
;
1196 return (avp
!= NULL
);
1199 /* E.g., $TMPDIR may be set to non-existent, so we need to be able to catch
1200 * that and redirect to a possible default value */
1201 if((avmp
->avm_flags
& a_AMV_VF_VIP
) &&
1202 !a_amv_var_check_vips(a_AMV_VIP_SET_PRE
, avcp
->avc_okey
, cp
)){
1204 if(avmp
->avm_flags
& (a_AMV_VF_IMPORT
| a_AMV_VF_ENV
))
1205 unsetenv(avcp
->avc_name
);
1207 if(n_UNLIKELY(avmp
->avm_flags
& a_AMV_VF_DEFVAL
) != 0)
1211 struct a_amv_var
**avpp
;
1214 l
= strlen(avcp
->avc_name
) +1;
1216 avp
= smalloc(n_VSTRUCT_SIZEOF(struct a_amv_var
, av_name
) + l
);
1217 avp
->av_link
= *(avpp
= &a_amv_vars
[avcp
->avc_prime
]);
1219 memcpy(avp
->av_name
, avcp
->avc_name
, l
);
1223 avp
->av_flags
= avmp
->avm_flags
;
1224 avp
->av_value
= a_amv_var_copy(cp
);
1226 if(avp
->av_flags
& a_AMV_VF_ENV
)
1227 a_amv_var__putenv(avcp
, avp
);
1228 if(avmp
->avm_flags
& a_AMV_VF_VIP
)
1229 a_amv_var_check_vips(a_AMV_VIP_SET_POST
, avcp
->avc_okey
, cp
);
1235 a_amv_var_vsc_global(struct a_amv_var_carrier
*avcp
){
1239 struct a_amv_var_map
const *avmp
;
1242 /* Not function local, TODO but lazy evaluted for now */
1243 if(avcp
->avc_special_prop
== a_AMV_VST_QM
){
1244 avmp
= &a_amv_var_map
[a_AMV_VAR__QM_MAP_IDX
];
1245 avcp
->avc_okey
= ok_v___qm
;
1246 ep
= &n_pstate_ex_no
;
1248 avmp
= &a_amv_var_map
[a_AMV_VAR__EM_MAP_IDX
];
1249 avcp
->avc_okey
= ok_v___em
;
1250 ep
= &n_pstate_err_no
;
1253 /* XXX Oh heaven, we are responsible to ensure that $?/! is up-to-date
1254 * XXX and represents n_pstate_err_no; TODO unfortunately
1255 * TODO we could num=1 ok_v___[qe]m, but the thing is still a string
1256 * TODO and thus conversion takes places over and over again; also
1257 * TODO for now that would have to occur before we set _that_ value
1258 * TODO so let's special treat it until we store ints as such */
1261 case 0: rv
= n_0
; break;
1262 case 1: rv
= n_1
; break;
1264 snprintf(itoabuf
, sizeof itoabuf
, "%d", *ep
);
1268 n_PS_ROOT_BLOCK(n_var_okset(avcp
->avc_okey
, (uintptr_t)rv
));
1270 avcp
->avc_hash
= avmp
->avm_hash
;
1271 avcp
->avc_map
= avmp
;
1273 rv
= a_amv_var_lookup(avcp
, TRU1
) ? avcp
->avc_var
->av_value
: NULL
;
1279 a_amv_var_vsc_multiplex(struct a_amv_var_carrier
*avcp
){
1286 i
= strlen(rv
= &avcp
->avc_name
[1]);
1288 /* ERR, ERRDOC, ERRNAME, plus *-NAME variants */
1289 if(rv
[0] == 'E' && i
>= 3 && rv
[1] == 'R' && rv
[2] == 'R'){
1291 e
= n_pstate_err_no
;
1293 }else if(rv
[3] == '-'){
1294 e
= n_err_from_name(&rv
[4]);
1297 case 0: rv
= n_0
; break;
1298 case 1: rv
= n_1
; break;
1300 snprintf(itoabuf
, sizeof itoabuf
, "%d", e
);
1301 rv
= savestr(itoabuf
); /* XXX yet, cannot do numbers */
1306 if(!memcmp(&rv
[3], "DOC", 3)){
1309 case '\0': e
= n_pstate_err_no
; break;
1310 case '-': e
= n_err_from_name(&rv
[1]); break;
1313 rv
= n_err_to_doc(e
);
1315 }else if(i
>= 7 && !memcmp(&rv
[3], "NAME", 4)){
1318 case '\0': e
= n_pstate_err_no
; break;
1319 case '-': e
= n_err_from_name(&rv
[1]); break;
1322 rv
= n_err_to_name(e
);
1336 a_amv_var_vsc_mac(struct a_amv_var_carrier
*avcp
){
1338 struct a_amv_mac_call_args
*amcap
;
1344 /* These may occur only in a macro.. */
1345 if(n_UNLIKELY(a_amv_lopts
== NULL
))
1348 amcap
= a_amv_lopts
->as_amcap
;
1350 /* ..in a `call'ed macro only, to be exact. Or in a_AMV_MACKY_MACK */
1351 if(!(ismacky
= (amcap
->amca_amp
== a_AMV_MACKY_MACK
)) &&
1352 (amcap
->amca_ps_hook_mask
||
1353 (assert(amcap
->amca_amp
!= NULL
),
1354 (amcap
->amca_amp
->am_flags
& a_AMV_MF_TYPE_MASK
1355 ) == a_AMV_MF_ACCOUNT
)))
1358 if(avcp
->avc_special_cat
== a_AMV_VSC_MAC_ARGV
){
1359 if(avcp
->avc_special_prop
> 0){
1360 if(amcap
->amca_argc
>= avcp
->avc_special_prop
)
1361 rv
= amcap
->amca_argv
[avcp
->avc_special_prop
- 1];
1363 rv
= amcap
->amca_name
;
1365 rv
= (a_amv_lopts
->as_up
!= NULL
1366 ? a_amv_lopts
->as_up
->as_amcap
->amca_name
: n_empty
);
1370 /* MACKY_MACK doesn't know about [*@#] */
1374 switch(avcp
->avc_special_prop
){
1375 case a_AMV_VST_STAR
:
1379 for(i
= l
= 0; i
< amcap
->amca_argc
; ++i
)
1380 l
+= strlen(amcap
->amca_argv
[i
]) + 1;
1386 rv
= cp
= salloc(l
);
1387 for(i
= l
= 0; i
< amcap
->amca_argc
; ++i
){
1388 l
= strlen(amcap
->amca_argv
[i
]);
1389 memcpy(cp
, amcap
->amca_argv
[i
], l
);
1396 case a_AMV_VST_NOSIGN
:{
1399 rv
= cp
= salloc(sizeof("65535"));
1400 snprintf(cp
, sizeof("65535"), "%hu", amcap
->amca_argc
);
1411 if(n_poption
& n_PO_D_V
)
1412 n_err(_("Cannot use macro local variable in this context: %s\n"),
1413 n_shexp_quote_cp(avcp
->avc_name
, FAL0
));
1418 a_amv_var_set(struct a_amv_var_carrier
*avcp
, char const *value
,
1420 struct a_amv_var
*avp
;
1422 struct a_amv_var_map
const *avmp
;
1427 rv
= a_amv_var_clear(avcp
, force_env
);
1431 if((avmp
= avcp
->avc_map
) != NULL
){
1434 /* Validity checks */
1435 if(n_UNLIKELY((avmp
->avm_flags
& a_AMV_VF_RDONLY
) != 0 &&
1436 !(n_pstate
& n_PS_ROOT
))){
1437 value
= N_("Variable is read-only: %s\n");
1440 if(n_UNLIKELY((avmp
->avm_flags
& a_AMV_VF_NOTEMPTY
) && *value
== '\0')){
1441 value
= N_("Variable must not be empty: %s\n");
1444 if(n_UNLIKELY((avmp
->avm_flags
& a_AMV_VF_NOCNTRLS
) != 0 &&
1445 !a_amv_var_check_nocntrls(value
))){
1446 value
= N_("Variable forbids control characters: %s\n");
1449 if(n_UNLIKELY((avmp
->avm_flags
& a_AMV_VF_NUM
) &&
1450 !a_amv_var_check_num(value
, FAL0
))){
1451 value
= N_("Variable value not a number or out of range: %s\n");
1454 if(n_UNLIKELY((avmp
->avm_flags
& a_AMV_VF_POSNUM
) &&
1455 !a_amv_var_check_num(value
, TRU1
))){
1456 value
= _("Variable value not a number, negative, "
1457 "or out of range: %s\n");
1460 if(n_UNLIKELY((avmp
->avm_flags
& a_AMV_VF_IMPORT
) != 0 &&
1461 !(n_psonce
& n_PSO_STARTED
) && !(n_pstate
& n_PS_ROOT
))){
1462 value
= N_("Variable cannot be set in a resource file: %s\n");
1466 /* Any more complicated inter-dependency? */
1467 if(n_UNLIKELY((avmp
->avm_flags
& a_AMV_VF_VIP
) != 0 &&
1468 !a_amv_var_check_vips(a_AMV_VIP_SET_PRE
, avcp
->avc_okey
, value
))){
1469 value
= N_("Assignment of variable aborted: %s\n");
1471 n_err(V_(value
), avcp
->avc_name
);
1475 /* Transformations */
1476 if(n_UNLIKELY(avmp
->avm_flags
& a_AMV_VF_LOWER
)){
1479 oval
= savestr(value
);
1481 for(; (c
= *oval
) != '\0'; ++oval
)
1482 *oval
= lowerconv(c
);
1487 a_amv_var_lookup(avcp
, TRU1
);
1489 /* Don't care what happens later on, store this in the unroll list */
1490 if(a_amv_lopts
!= NULL
&&
1491 (avmp
== NULL
|| !(avmp
->avm_flags
& a_AMV_VF_NOLOPTS
)))
1492 a_amv_lopts_add(a_amv_lopts
, avcp
->avc_name
, avcp
->avc_var
);
1494 if((avp
= avcp
->avc_var
) == NULL
){
1495 struct a_amv_var
**avpp
;
1498 l
= strlen(avcp
->avc_name
) +1;
1499 avcp
->avc_var
= avp
= smalloc(n_VSTRUCT_SIZEOF(struct a_amv_var
, av_name
1501 avp
->av_link
= *(avpp
= &a_amv_vars
[avcp
->avc_prime
]);
1506 memcpy(avp
->av_name
, avcp
->avc_name
, l
);
1507 avp
->av_flags
= (avmp
!= NULL
) ? avmp
->avm_flags
: 0;
1508 oval
= n_UNCONST(n_empty
);
1510 oval
= avp
->av_value
;
1513 avp
->av_value
= a_amv_var_copy(value
);
1515 /* Via `set' etc. the user may give even boolean options non-boolean
1516 * values, ignore that and force boolean */
1517 if(avp
->av_flags
& a_AMV_VF_BOOL
){
1518 if(!(n_pstate
& n_PS_ROOT
) && (n_poption
& n_PO_D_VV
) &&
1520 n_err(_("Ignoring value of boolean variable: %s: %s\n"),
1521 avcp
->avc_name
, value
);
1522 avp
->av_value
= n_UNCONST(n_1
);
1524 avp
->av_value
= a_amv_var_copy(value
);
1527 if(force_env
&& !(avp
->av_flags
& a_AMV_VF_ENV
))
1528 avp
->av_flags
|= a_AMV_VF_LINKED
;
1529 if(avp
->av_flags
& (a_AMV_VF_ENV
| a_AMV_VF_LINKED
))
1530 rv
= a_amv_var__putenv(avcp
, avp
);
1531 if(avp
->av_flags
& a_AMV_VF_VIP
)
1532 a_amv_var_check_vips(a_AMV_VIP_SET_POST
, avcp
->avc_okey
, value
);
1533 a_amv_var_free(oval
);
1540 a_amv_var__putenv(struct a_amv_var_carrier
*avcp
, struct a_amv_var
*avp
){
1548 rv
= (setenv(avcp
->avc_name
, avp
->av_value
, 1) == 0);
1550 cp
= sstrdup(savecatsep(avcp
->avc_name
, '=', avp
->av_value
));
1552 if((rv
= (putenv(cp
) == 0))){
1555 if((ocp
= avp
->av_env
) != NULL
)
1566 a_amv_var_clear(struct a_amv_var_carrier
*avcp
, bool_t force_env
){
1567 struct a_amv_var
**avpp
, *avp
;
1568 struct a_amv_var_map
const *avmp
;
1574 if(n_LIKELY((avmp
= avcp
->avc_map
) != NULL
)){
1575 if(n_UNLIKELY((avmp
->avm_flags
& a_AMV_VF_NODEL
) != 0 &&
1576 !(n_pstate
& n_PS_ROOT
))){
1577 n_err(_("Variable may not be unset: %s\n"), avcp
->avc_name
);
1580 if(n_UNLIKELY((avmp
->avm_flags
& a_AMV_VF_VIP
) != 0 &&
1581 !a_amv_var_check_vips(a_AMV_VIP_CLEAR
, avcp
->avc_okey
, NULL
))){
1582 n_err(_("Clearance of variable aborted: %s\n"), avcp
->avc_name
);
1589 if(n_UNLIKELY(!a_amv_var_lookup(avcp
, TRUM1
))){
1592 rv
= a_amv_var__clearenv(avcp
->avc_name
, NULL
);
1593 }else if(!(n_pstate
& (n_PS_ROOT
| n_PS_ROBOT
)) && (n_poption
& n_PO_D_V
))
1594 n_err(_("Can't unset undefined variable: %s\n"), avcp
->avc_name
);
1596 }else if(avcp
->avc_var
== (struct a_amv_var
*)-1){
1597 avcp
->avc_var
= NULL
;
1603 if(a_amv_lopts
!= NULL
&&
1604 (avmp
== NULL
|| !(avmp
->avm_flags
& a_AMV_VF_NOLOPTS
)))
1605 a_amv_lopts_add(a_amv_lopts
, avcp
->avc_name
, avcp
->avc_var
);
1607 avp
= avcp
->avc_var
;
1608 avcp
->avc_var
= NULL
;
1609 avpp
= &a_amv_vars
[avcp
->avc_prime
];
1610 assert(*avpp
== avp
); /* (always listhead after lookup()) */
1611 *avpp
= (*avpp
)->av_link
;
1619 envval
= avp
->av_env
;
1621 if((avp
->av_flags
& (a_AMV_VF_ENV
| a_AMV_VF_LINKED
)) || envval
!= NULL
)
1622 rv
= a_amv_var__clearenv(avp
->av_name
, envval
);
1624 a_amv_var_free(avp
->av_value
);
1627 /* XXX Fun part, extremely simple-minded for now: if this variable has
1628 * XXX a default value, immediately reinstantiate it! TODO Heh? */
1629 if(n_UNLIKELY(avmp
!= NULL
&& (avmp
->avm_flags
& a_AMV_VF_DEFVAL
) != 0))
1630 a_amv_var_lookup(avcp
, TRU1
);
1637 a_amv_var__clearenv(char const *name
, char *value
){
1639 extern char **environ
;
1651 for(ecpp
= environ
; *ecpp
!= NULL
; ++ecpp
)
1656 while(*ecpp
++ != NULL
);
1666 a_amv_var_show_all(void){
1667 struct n_string msg
, *msgp
;
1670 struct a_amv_var
*avp
;
1671 char const **vacp
, **cap
;
1674 if((fp
= Ftmp(NULL
, "setlist", OF_RDWR
| OF_UNLINK
| OF_REGISTER
)) == NULL
){
1675 n_perr(_("Can't create temporary file for `set' listing"), 0);
1679 /* We need to instantiate first-time-inits and default values here, so that
1680 * they will be regular members of our _vars[] table */
1681 for(i
= a_AMV_VAR_I3VALS_CNT
; i
-- > 0;)
1682 n_var_oklook(a_amv_var_i3vals
[i
].avdv_okey
);
1683 for(i
= a_AMV_VAR_DEFVALS_CNT
; i
-- > 0;)
1684 n_var_oklook(a_amv_var_defvals
[i
].avdv_okey
);
1686 for(no
= i
= 0; i
< a_AMV_PRIME
; ++i
)
1687 for(avp
= a_amv_vars
[i
]; avp
!= NULL
; avp
= avp
->av_link
)
1689 no
+= a_AMV_VAR_VIRTS_CNT
;
1691 vacp
= salloc(no
* sizeof(*vacp
));
1693 for(cap
= vacp
, i
= 0; i
< a_AMV_PRIME
; ++i
)
1694 for(avp
= a_amv_vars
[i
]; avp
!= NULL
; avp
= avp
->av_link
)
1695 *cap
++ = avp
->av_name
;
1696 for(i
= a_AMV_VAR_VIRTS_CNT
; i
-- > 0;)
1697 *cap
++ = a_amv_var_virts
[i
].avv_var
->av_name
;
1700 qsort(vacp
, no
, sizeof *vacp
, &a_amv_var__show_cmp
);
1703 msgp
= n_string_reserve(n_string_creat(msgp
), 80);
1704 for(i
= 0, cap
= vacp
; no
!= 0; ++cap
, --no
)
1705 i
+= a_amv_var_show(*cap
, fp
, msgp
);
1708 page_or_print(fp
, i
);
1715 a_amv_var__show_cmp(void const *s1
, void const *s2
){
1719 rv
= strcmp(*(char**)n_UNCONST(s1
), *(char**)n_UNCONST(s2
));
1725 a_amv_var_show(char const *name
, FILE *fp
, struct n_string
*msgp
){
1726 struct a_amv_var_carrier avc
;
1732 msgp
= n_string_trunc(msgp
, 0);
1735 a_amv_var_revlookup(&avc
, name
);
1736 isset
= a_amv_var_lookup(&avc
, FAL0
);
1738 if(n_poption
& n_PO_D_V
){
1739 if(avc
.avc_map
== NULL
){
1740 msgp
= n_string_push_cp(msgp
, "#assembled variable with value");
1747 {a_AMV_VF_VIRT
, "virtual"},
1748 {a_AMV_VF_RDONLY
, "read-only"},
1749 {a_AMV_VF_NODEL
, "nodelete"},
1750 {a_AMV_VF_NOTEMPTY
, "notempty"},
1751 {a_AMV_VF_NOCNTRLS
, "no-control-chars"},
1752 {a_AMV_VF_NUM
, "number"},
1753 {a_AMV_VF_POSNUM
, "positive-number"},
1754 {a_AMV_VF_IMPORT
, "import-environ-first\0"},
1755 {a_AMV_VF_ENV
, "sync-environ"},
1756 {a_AMV_VF_I3VAL
, "initial-value"},
1757 {a_AMV_VF_DEFVAL
, "default-value"},
1758 {a_AMV_VF_LINKED
, "`environ' link"}
1761 for(tp
= tbase
; PTRCMP(tp
, <, &tbase
[n_NELEM(tbase
)]); ++tp
)
1762 if(isset
? (avc
.avc_var
->av_flags
& tp
->flag
)
1763 : (avc
.avc_map
->avm_flags
& tp
->flag
)){
1764 msgp
= n_string_push_c(msgp
, (i
++ == 0 ? '#' : ','));
1765 msgp
= n_string_push_cp(msgp
, tp
->msg
);
1769 msgp
= n_string_push_cp(msgp
, "\n ");
1772 if(!isset
|| (avc
.avc_var
->av_flags
& a_AMV_VF_RDONLY
)){
1773 msgp
= n_string_push_cp(msgp
, "#");
1775 if(avc
.avc_map
!= NULL
&& (avc
.avc_map
->avm_flags
& a_AMV_VF_BOOL
))
1776 msgp
= n_string_push_cp(msgp
, "boolean; ");
1777 msgp
= n_string_push_cp(msgp
, "variable not set: ");
1778 msgp
= n_string_push_cp(msgp
, n_shexp_quote_cp(name
, FAL0
));
1783 n_UNINIT(quote
, NULL
);
1784 if(!(avc
.avc_var
->av_flags
& a_AMV_VF_BOOL
)){
1785 quote
= n_shexp_quote_cp(avc
.avc_var
->av_value
, TRU1
);
1786 if(strcmp(quote
, avc
.avc_var
->av_value
))
1787 msgp
= n_string_push_cp(msgp
, "wysh ");
1788 }else if(n_poption
& n_PO_D_V
)
1789 msgp
= n_string_push_cp(msgp
, "wysh ");
1790 if(avc
.avc_var
->av_flags
& a_AMV_VF_LINKED
)
1791 msgp
= n_string_push_cp(msgp
, "environ ");
1792 msgp
= n_string_push_cp(msgp
, "set ");
1793 msgp
= n_string_push_cp(msgp
, name
);
1794 if(!(avc
.avc_var
->av_flags
& a_AMV_VF_BOOL
)){
1795 msgp
= n_string_push_c(msgp
, '=');
1796 msgp
= n_string_push_cp(msgp
, quote
);
1797 }else if(n_poption
& n_PO_D_V
)
1798 msgp
= n_string_push_cp(msgp
, " #boolean");
1801 msgp
= n_string_push_c(msgp
, '\n');
1802 fputs(n_string_cp(msgp
), fp
);
1804 return (i
> 0 ? 2 : 1);
1808 a_amv_var_c_set(char **ap
, bool_t issetenv
){
1809 char *cp
, *cp2
, *varbuf
, c
;
1815 while((cp
= *ap
++) != NULL
){
1817 cp2
= varbuf
= salloc(strlen(cp
) +1);
1819 for(; (c
= *cp
) != '=' && c
!= '\0'; ++cp
){
1820 if(cntrlchar(c
) || spacechar(c
)){
1821 n_err(_("Variable name with control character ignored: %s\n"),
1830 cp
= n_UNCONST(n_empty
);
1835 n_err(_("Empty variable name ignored\n"));
1838 struct a_amv_var_carrier avc
;
1841 if((isunset
= (varbuf
[0] == 'n' && varbuf
[1] == 'o')))
1842 varbuf
= &varbuf
[2];
1844 a_amv_var_revlookup(&avc
, varbuf
);
1847 errs
+= !a_amv_var_clear(&avc
, issetenv
);
1849 errs
+= !a_amv_var_set(&avc
, cp
, issetenv
);
1864 if((args
= v
)[0] == NULL
){
1865 rv
= (a_amv_mac_show(a_AMV_MF_NONE
) == FAL0
);
1869 if(args
[1] == NULL
|| args
[1][0] != '{' || args
[1][1] != '\0' ||
1871 n_err(_("Synopsis: define: <name> {\n"));
1875 rv
= (a_amv_mac_def(args
[0], a_AMV_MF_NONE
) == FAL0
);
1882 c_undefine(void *v
){
1890 rv
|= !a_amv_mac_undef(*args
, a_AMV_MF_NONE
);
1891 while(*++args
!= NULL
);
1901 rv
= a_amv_mac_call(v
, FAL0
);
1911 rv
= a_amv_mac_call(v
, TRU1
);
1918 struct a_amv_mac_call_args
*amcap
;
1919 struct a_amv_mac
*amp
;
1921 int rv
, i
, oqf
, nqf
;
1926 if((args
= v
)[0] == NULL
){
1927 rv
= (a_amv_mac_show(a_AMV_MF_ACCOUNT
) == FAL0
);
1931 if(args
[1] && args
[1][0] == '{' && args
[1][1] == '\0'){
1932 if(args
[2] != NULL
){
1933 n_err(_("Synopsis: account: <name> {\n"));
1936 if(!asccasecmp(args
[0], ACCOUNT_NULL
)){
1937 n_err(_("`account': cannot use reserved name: %s\n"),
1941 rv
= (a_amv_mac_def(args
[0], a_AMV_MF_ACCOUNT
) == FAL0
);
1945 if(n_pstate
& n_PS_HOOK_MASK
){
1946 n_err(_("`account': can't change account from within a hook\n"));
1950 save_mbox_for_possible_quitstuff();
1953 if(asccasecmp(args
[0], ACCOUNT_NULL
) != 0 &&
1954 (amp
= a_amv_mac_lookup(args
[0], NULL
, a_AMV_MF_ACCOUNT
)) == NULL
){
1955 n_err(_("`account': account does not exist: %s\n"), args
[0]);
1959 oqf
= savequitflags();
1961 if(a_amv_acc_curr
!= NULL
){
1962 if(a_amv_acc_curr
->am_lopts
!= NULL
)
1963 a_amv_lopts_unroll(&a_amv_acc_curr
->am_lopts
);
1964 /* For accounts this lingers */
1965 --a_amv_acc_curr
->am_refcnt
;
1966 if(a_amv_acc_curr
->am_flags
& a_AMV_MF_DELETE
)
1967 a_amv_mac_free(a_amv_acc_curr
);
1970 a_amv_acc_curr
= amp
;
1974 assert(amp
->am_lopts
== NULL
);
1975 amcap
= n_lofi_alloc(sizeof *amcap
);
1976 memset(amcap
, 0, sizeof *amcap
);
1977 amcap
->amca_name
= amp
->am_name
;
1978 amcap
->amca_amp
= amp
;
1979 amcap
->amca_unroller
= &
->am_lopts
;
1980 amcap
->amca_lopts_on
= TRU1
;
1981 ++amp
->am_refcnt
; /* We may not run 0 to avoid being deleted! */
1982 ok
= a_amv_mac_exec(amcap
);
1984 /* XXX account switch incomplete, unroll? */
1985 n_err(_("`account': failed to switch to account: %s\n"), amp
->am_name
);
1990 n_PS_ROOT_BLOCK((amp
!= NULL
? ok_vset(account
, amp
->am_name
)
1991 : ok_vclear(account
)));
1993 if((n_psonce
& n_PSO_STARTED
) && !(n_pstate
& n_PS_HOOK_MASK
)){
1994 nqf
= savequitflags(); /* TODO obsolete (leave -> void -> new box!) */
1995 restorequitflags(oqf
);
1996 if((i
= setfile("%", 0)) < 0)
1998 temporary_folder_hook_check(FAL0
);
1999 if(i
> 0 && !ok_blook(emptystart
))
2001 announce(ok_blook(bsdcompat
) || ok_blook(bsdannounce
));
2002 restorequitflags(nqf
);
2011 c_unaccount(void *v
){
2019 rv
|= !a_amv_mac_undef(*args
, a_AMV_MF_ACCOUNT
);
2020 while(*++args
!= NULL
);
2026 c_localopts(void *v
){
2033 if(a_amv_lopts
== NULL
){
2034 n_err(_("Cannot use `localopts' in this context "
2035 "(not in `define' or `account', nor special hook)\n"));
2041 if(n_pstate
& (n_PS_HOOK
| n_PS_COMPOSE_MODE
)){
2042 if(n_poption
& n_PO_D_V
)
2043 n_err(_("Cannot turn off `localopts' for compose-mode hooks\n"));
2047 a_amv_lopts
->as_unroll
= (boolify(*(argv
= v
), UIZ_MAX
, FAL0
) > 0);
2060 if(a_amv_lopts
!= NULL
){
2062 struct a_amv_mac
const *amp
;
2063 struct a_amv_mac_call_args
*amcap
;
2065 amp
= (amcap
= a_amv_lopts
->as_amcap
)->amca_amp
;
2066 if(amp
== NULL
|| amcap
->amca_ps_hook_mask
||
2067 (amp
->am_flags
& a_AMV_MF_TYPE_MASK
) == a_AMV_MF_ACCOUNT
)
2076 if((n_idec_si16_cp(&sib
, v
, 10, NULL
2077 ) & (n_IDEC_STATE_EMASK
| n_IDEC_STATE_CONSUMED
)
2078 ) != n_IDEC_STATE_CONSUMED
|| sib
< 0){
2079 n_err(_("`shift': invalid argument: %s\n"), v
);
2085 if(i
> (j
= amcap
->amca_argc
)){
2086 n_err(_("`shift': cannot shift %hu of %hu parameters\n"), i
, j
);
2092 amcap
->amca_argc
= j
;
2093 amcap
->amca_argv
+= i
;
2098 n_err(_("Can only use `shift' in a `call'ed macro\n"));
2111 if(a_amv_lopts
!= NULL
){
2114 n_source_force_eof();
2116 if((argv
= v
)[0] != NULL
){
2119 if((n_idec_si32_cp(&i
, argv
[0], 10, NULL
2120 ) & (n_IDEC_STATE_EMASK
| n_IDEC_STATE_CONSUMED
)
2121 ) == n_IDEC_STATE_CONSUMED
&& i
>= 0)
2122 n_pstate_var__em
= argv
[0];
2124 n_err(_("`return': argument one is invalid: %s\n"), argv
[0]);
2126 if(argv
[1] != NULL
){
2127 if((n_idec_si32_cp(&i
, argv
[1], 10, NULL
2128 ) & (n_IDEC_STATE_EMASK
| n_IDEC_STATE_CONSUMED
)
2129 ) == n_IDEC_STATE_CONSUMED
&& i
>= 0)
2132 n_err(_("`return': argument two is invalid: %s\n"), argv
[1]);
2133 n_pstate_var__em
= n_1
;
2139 n_pstate_var__em
= n_0
;
2142 n_err(_("Can only use `return' in a macro\n"));
2148 temporary_folder_hook_check(bool_t nmail
){ /* TODO temporary, v15: drop */
2149 struct a_amv_mac_call_args
*amcap
;
2150 struct a_amv_mac
*amp
;
2158 var
= salloc(len
= strlen(mailname
) + sizeof("folder-hook-") -1 +1);
2160 /* First try the fully resolved path */
2161 snprintf(var
, len
, "folder-hook-%s", mailname
);
2162 if((cp
= n_var_vlook(var
, FAL0
)) != NULL
)
2165 /* If we are under *folder*, try the usual +NAME syntax, too */
2166 if(displayname
[0] == '+'){
2169 for(x
= &mailname
[len
]; x
!= mailname
; --x
)
2171 snprintf(var
, len
, "folder-hook-+%s", x
);
2172 if((cp
= n_var_vlook(var
, FAL0
)) != NULL
)
2178 /* Plain *folder-hook* is our last try */
2179 if((cp
= ok_vlook(folder_hook
)) == NULL
)
2183 if((amp
= a_amv_mac_lookup(cp
, NULL
, a_AMV_MF_NONE
)) == NULL
){
2184 n_err(_("Cannot call *folder-hook* for %s: macro does not exist: %s\n"),
2185 n_shexp_quote_cp(displayname
, FAL0
), cp
);
2190 amcap
= n_lofi_alloc(sizeof *amcap
);
2191 memset(amcap
, 0, sizeof *amcap
);
2192 amcap
->amca_name
= cp
;
2193 amcap
->amca_amp
= amp
;
2194 n_pstate
&= ~n_PS_HOOK_MASK
;
2196 amcap
->amca_unroller
= NULL
;
2197 n_pstate
|= n_PS_HOOK_NEWMAIL
;
2199 amcap
->amca_unroller
= &a_amv_folder_hook_lopts
;
2200 n_pstate
|= n_PS_HOOK
;
2202 amcap
->amca_lopts_on
= TRU1
;
2203 amcap
->amca_ps_hook_mask
= TRU1
;
2204 rv
= a_amv_mac_exec(amcap
);
2205 n_pstate
&= ~n_PS_HOOK_MASK
;
2213 temporary_folder_hook_unroll(void){ /* XXX intermediate hack */
2215 if(a_amv_folder_hook_lopts
!= NULL
){
2216 void *save
= a_amv_lopts
;
2219 a_amv_lopts_unroll(&a_amv_folder_hook_lopts
);
2220 a_amv_folder_hook_lopts
= NULL
;
2227 temporary_compose_mode_hook_call(char const *macname
,
2228 void (*hook_pre
)(void *), void *hook_arg
){
2229 /* TODO compose_mode_hook_call() temporary, v15: generalize; see a_LEX_SPLICE
2230 * TODO comment in lex-input.c for the right way of doing things! */
2231 static struct a_amv_lostack
*cmh_losp
;
2232 struct a_amv_mac_call_args
*amcap
;
2233 struct a_amv_mac
*amp
;
2238 if(macname
== (char*)-1){
2239 a_amv_mac__finalize(cmh_losp
);
2241 }else if(macname
!= NULL
&&
2242 (amp
= a_amv_mac_lookup(macname
, NULL
, a_AMV_MF_NONE
)) == NULL
)
2243 n_err(_("Cannot call *on-compose-**: macro does not exist: %s\n"),
2246 amcap
= n_lofi_alloc(sizeof *amcap
);
2247 memset(amcap
, 0, sizeof *amcap
);
2248 amcap
->amca_name
= (macname
!= NULL
) ? macname
2249 : "on-compose-splice-shell";
2250 amcap
->amca_amp
= amp
;
2251 amcap
->amca_unroller
= &a_amv_compose_lopts
;
2252 amcap
->amca_hook_pre
= hook_pre
;
2253 amcap
->amca_hook_arg
= hook_arg
;
2254 amcap
->amca_lopts_on
= TRU1
;
2255 amcap
->amca_ps_hook_mask
= TRU1
;
2256 n_pstate
&= ~n_PS_HOOK_MASK
;
2257 n_pstate
|= n_PS_HOOK
;
2259 a_amv_mac_exec(amcap
);
2261 cmh_losp
= n_lofi_alloc(sizeof *cmh_losp
);
2262 cmh_losp
->as_global_saved
= a_amv_lopts
;
2263 cmh_losp
->as_up
= NULL
;
2264 cmh_losp
->as_lopts
= *(cmh_losp
->as_amcap
= amcap
)->amca_unroller
;
2265 cmh_losp
->as_unroll
= TRU1
;
2266 a_amv_lopts
= cmh_losp
;
2273 temporary_compose_mode_hook_unroll(void){ /* XXX intermediate hack */
2275 if(a_amv_compose_lopts
!= NULL
){
2276 void *save
= a_amv_lopts
;
2279 a_amv_lopts_unroll(&a_amv_compose_lopts
);
2280 a_amv_compose_lopts
= NULL
;
2287 n_var_is_user_writable(char const *name
){
2288 struct a_amv_var_carrier avc
;
2289 struct a_amv_var_map
const *avmp
;
2293 a_amv_var_revlookup(&avc
, name
);
2294 if((avmp
= avc
.avc_map
) == NULL
)
2297 rv
= ((avmp
->avm_flags
& (a_AMV_VF_BOOL
| a_AMV_VF_RDONLY
)) == 0);
2303 n_var_oklook(enum okeys okey
){
2304 struct a_amv_var_carrier avc
;
2306 struct a_amv_var_map
const *avmp
;
2309 avc
.avc_map
= avmp
= &a_amv_var_map
[okey
];
2310 avc
.avc_name
= a_amv_var_names
+ avmp
->avm_keyoff
;
2311 avc
.avc_hash
= avmp
->avm_hash
;
2312 avc
.avc_okey
= okey
;
2314 if(a_amv_var_lookup(&avc
, FAL0
))
2315 rv
= avc
.avc_var
->av_value
;
2323 n_var_okset(enum okeys okey
, uintptr_t val
){
2324 struct a_amv_var_carrier avc
;
2326 struct a_amv_var_map
const *avmp
;
2329 avc
.avc_map
= avmp
= &a_amv_var_map
[okey
];
2330 avc
.avc_name
= a_amv_var_names
+ avmp
->avm_keyoff
;
2331 avc
.avc_hash
= avmp
->avm_hash
;
2332 avc
.avc_okey
= okey
;
2334 ok
= a_amv_var_set(&avc
, (val
== 0x1 ? n_empty
: (char const*)val
), FAL0
);
2340 n_var_okclear(enum okeys okey
){
2341 struct a_amv_var_carrier avc
;
2343 struct a_amv_var_map
const *avmp
;
2346 avc
.avc_map
= avmp
= &a_amv_var_map
[okey
];
2347 avc
.avc_name
= a_amv_var_names
+ avmp
->avm_keyoff
;
2348 avc
.avc_hash
= avmp
->avm_hash
;
2349 avc
.avc_okey
= okey
;
2351 rv
= a_amv_var_clear(&avc
, FAL0
);
2357 n_var_vlook(char const *vokey
, bool_t try_getenv
){
2358 struct a_amv_var_carrier avc
;
2362 a_amv_var_revlookup(&avc
, vokey
);
2364 switch((enum a_amv_var_special_category
)avc
.avc_special_cat
){
2365 default: /* silence CC */
2366 case a_AMV_VSC_NONE
:
2367 if(a_amv_var_lookup(&avc
, FAL0
))
2368 rv
= avc
.avc_var
->av_value
;
2369 /* Only check the environment for something that is otherwise unknown */
2370 else if(try_getenv
&& avc
.avc_map
== NULL
)
2375 case a_AMV_VSC_GLOBAL
:
2376 rv
= a_amv_var_vsc_global(&avc
);
2378 case a_AMV_VSC_MULTIPLEX
:
2379 rv
= a_amv_var_vsc_multiplex(&avc
);
2382 case a_AMV_VSC_MAC_ARGV
:
2383 rv
= a_amv_var_vsc_mac(&avc
);
2391 n_var_vexplode(void const **cookie
){
2393 /* These may occur only in a macro.. */
2394 *cookie
= (a_amv_lopts
!= NULL
) ? a_amv_lopts
->as_amcap
->amca_argv
: NULL
;
2396 return (*cookie
!= NULL
);
2400 n_var_vset(char const *vokey
, uintptr_t val
){
2401 struct a_amv_var_carrier avc
;
2405 a_amv_var_revlookup(&avc
, vokey
);
2407 ok
= a_amv_var_set(&avc
, (val
== 0x1 ? n_empty
: (char const*)val
), FAL0
);
2413 n_var_vclear(char const *vokey
){
2414 struct a_amv_var_carrier avc
;
2418 a_amv_var_revlookup(&avc
, vokey
);
2420 ok
= a_amv_var_clear(&avc
, FAL0
);
2427 n_var_xoklook(enum okeys okey
, struct url
const *urlp
,
2428 enum okey_xlook_mode oxm
){
2429 struct a_amv_var_carrier avc
;
2430 struct str
const *us
;
2433 struct a_amv_var_map
const *avmp
;
2436 assert(oxm
& (OXM_PLAIN
| OXM_H_P
| OXM_U_H_P
));
2438 /* For simplicity: allow this case too */
2439 if(!(oxm
& (OXM_H_P
| OXM_U_H_P
))){
2444 avc
.avc_map
= avmp
= &a_amv_var_map
[okey
];
2445 avc
.avc_name
= a_amv_var_names
+ avmp
->avm_keyoff
;
2446 avc
.avc_okey
= okey
;
2448 us
= (oxm
& OXM_U_H_P
) ? &urlp
->url_u_h_p
: &urlp
->url_h_p
;
2449 nlen
= strlen(avc
.avc_name
);
2450 nbuf
= n_lofi_alloc(nlen
+ 1 + us
->l
+1);
2451 memcpy(nbuf
, avc
.avc_name
, nlen
);
2454 /* One of .url_u_h_p and .url_h_p we test in here */
2455 memcpy(nbuf
+ nlen
, us
->s
, us
->l
+1);
2456 avc
.avc_name
= a_amv_var_canonify(nbuf
);
2457 avc
.avc_hash
= a_AMV_NAME2HASH(avc
.avc_name
);
2458 if(a_amv_var_lookup(&avc
, FAL0
))
2463 us
= &urlp
->url_h_p
;
2464 memcpy(nbuf
+ nlen
, us
->s
, us
->l
+1);
2465 avc
.avc_name
= a_amv_var_canonify(nbuf
);
2466 avc
.avc_hash
= a_AMV_NAME2HASH(avc
.avc_name
);
2467 if(a_amv_var_lookup(&avc
, FAL0
)){
2469 rv
= avc
.avc_var
->av_value
;
2475 rv
= (oxm
& OXM_PLAIN
) ? n_var_oklook(okey
) : NULL
;
2482 #endif /* HAVE_SOCKETS */
2490 if(*(ap
= v
) == NULL
){
2491 a_amv_var_show_all();
2494 err
= !a_amv_var_c_set(ap
, FAL0
);
2505 for(err
= 0, ap
= v
; *ap
!= NULL
; ++ap
)
2506 err
|= !n_var_vclear(*ap
);
2516 if(*(ap
= v
) == NULL
)
2519 struct n_string msg
, *msgp
= &msg
;
2521 msgp
= n_string_creat(msgp
);
2522 for(; *ap
!= NULL
; ++ap
)
2523 a_amv_var_show(*ap
, n_stdout
, msgp
);
2527 return (v
== NULL
? !STOP
: !OKAY
); /* xxx 1:bad 0:good -- do some */
2532 struct a_amv_var_carrier avc
;
2536 sighandler_type sigint
;
2539 sigint
= safe_signal(SIGINT
, SIG_IGN
);
2541 for(err
= 0, argv
= v
; *argv
!= NULL
; ++argv
){
2542 memset(&avc
, 0, sizeof avc
);
2544 a_amv_var_revlookup(&avc
, *argv
);
2546 if(avc
.avc_map
!= NULL
){
2547 if(avc
.avc_map
->avm_flags
& a_AMV_VF_BOOL
){
2548 n_err(_("`varedit': cannot edit boolean variable: %s\n"),
2552 if(avc
.avc_map
->avm_flags
& a_AMV_VF_RDONLY
){
2553 n_err(_("`varedit': cannot edit read-only variable: %s\n"),
2559 a_amv_var_lookup(&avc
, FAL0
);
2561 if((of
= Ftmp(NULL
, "varedit", OF_RDWR
| OF_UNLINK
| OF_REGISTER
)) ==
2563 n_perr(_("`varedit': can't create temporary file, bailing out"), 0);
2566 }else if(avc
.avc_var
!= NULL
&& *(val
= avc
.avc_var
->av_value
) != '\0' &&
2567 sizeof *val
!= fwrite(val
, strlen(val
), sizeof *val
, of
)){
2568 n_perr(_("`varedit' failed to write old value to temporary file"), 0);
2575 nf
= run_editor(of
, (off_t
)-1, 'e', FAL0
, NULL
, NULL
, SEND_MBOX
, sigint
);
2585 base
= salloc((size_t)l
+1);
2587 for(l
= 0, val
= base
; (c
= getc(nf
)) != EOF
; ++val
)
2588 if(c
== '\n' || c
== '\r'){
2592 *val
= (char)(uc_i
)c
;
2598 if(!a_amv_var_set(&avc
, base
, FAL0
))
2603 n_err(_("`varedit': can't start $EDITOR, bailing out\n"));
2609 safe_signal(SIGINT
, sigint
);
2616 struct a_amv_var_carrier avc
;
2622 if((islnk
= is_asccaseprefix(*(ap
= v
), "link")) ||
2623 is_asccaseprefix(*ap
, "unlink")){
2624 for(err
= 0; *++ap
!= NULL
;){
2625 a_amv_var_revlookup(&avc
, *ap
);
2627 if(a_amv_var_lookup(&avc
, FAL0
) && (islnk
||
2628 (avc
.avc_var
->av_flags
& a_AMV_VF_LINKED
))){
2630 avc
.avc_var
->av_flags
&= ~a_AMV_VF_LINKED
;
2632 }else if(avc
.avc_var
->av_flags
& (a_AMV_VF_ENV
| a_AMV_VF_LINKED
)){
2633 if(n_poption
& n_PO_D_V
)
2634 n_err(_("`environ': link: already established: %s\n"), *ap
);
2637 avc
.avc_var
->av_flags
|= a_AMV_VF_LINKED
;
2638 if(!(avc
.avc_var
->av_flags
& a_AMV_VF_ENV
))
2639 a_amv_var__putenv(&avc
, avc
.avc_var
);
2641 n_err(_("`environ': unlink: no link established: %s\n"), *ap
);
2644 char const *evp
= getenv(*ap
);
2647 err
|= !a_amv_var_set(&avc
, evp
, TRU1
);
2649 n_err(_("`environ': link: cannot link to non-existent: %s\n"),
2655 }else if(is_asccaseprefix(*ap
, "set"))
2656 err
= !a_amv_var_c_set(++ap
, TRU1
);
2657 else if(is_asccaseprefix(*ap
, "unset")){
2658 for(err
= 0; *++ap
!= NULL
;){
2659 a_amv_var_revlookup(&avc
, *ap
);
2661 if(!a_amv_var_clear(&avc
, TRU1
))
2665 n_err(_("Synopsis: environ: <link|set|unset> <variable>...\n"));
2673 c_vexpr(void *v
){ /* TODO POSIX expr(1) comp. exit status; overly complicat. */
2674 /* This needs to be here because we need to apply MACKY_MACK for
2675 * search+replace regular expression support :( */
2677 enum n_idec_state ids
;
2679 char op
, varbuf
[64 + 64 / 8 +1];
2680 char const **argv
, *varname
, *varres
, *cp
;
2685 a_ISDECIMAL
= 1<<3, /* Print only decimal result */
2688 a_UNSIGNED
= 1<<6, /* Unsigned right shift (share bit ok) */
2695 varname
= (n_pstate
& n_PS_ARGMOD_VPUT
) ? *argv
++ : NULL
;
2696 n_UNINIT(varres
, n_empty
);
2698 if((cp
= argv
[0])[0] == '\0')
2708 if(argv
[1] == NULL
|| argv
[2] != NULL
)
2711 if(*(cp
= *++argv
) == '\0')
2713 else if(((ids
= n_idec_si64_cp(&lhv
, cp
, 0, NULL
)
2714 ) & (n_IDEC_STATE_EMASK
| n_IDEC_STATE_CONSUMED
)
2715 ) != n_IDEC_STATE_CONSUMED
){
2716 if(!(ids
& n_IDEC_STATE_EOVERFLOW
) || !(f
& a_SATURATED
))
2735 if(argv
[1] == NULL
|| argv
[2] == NULL
|| argv
[3] != NULL
)
2740 if(*(cp
= *++argv
) == '\0')
2742 else if(((ids
= n_idec_si64_cp(&lhv
, cp
, 0, NULL
)
2743 ) & (n_IDEC_STATE_EMASK
| n_IDEC_STATE_CONSUMED
)
2744 ) != n_IDEC_STATE_CONSUMED
){
2745 if(!(ids
& n_IDEC_STATE_EOVERFLOW
) || !(f
& a_SATURATED
))
2751 if(*(cp
= *++argv
) == '\0')
2753 else if(((ids
= n_idec_si64_cp(&rhv
, cp
, 0, NULL
)
2754 ) & (n_IDEC_STATE_EMASK
| n_IDEC_STATE_CONSUMED
)
2755 ) != n_IDEC_STATE_CONSUMED
){
2756 if(!(ids
& n_IDEC_STATE_EOVERFLOW
) || !(f
& a_SATURATED
))
2768 if(rhv
!= SI64_MIN
){
2779 if(SI64_MAX
- rhv
< lhv
)
2785 if(rhv
!= SI64_MIN
){
2796 if(SI64_MIN
+ rhv
> lhv
){
2798 if(!(f
& a_SATURATED
))
2799 goto jenum_overflow
;
2801 lhv
= (lhv
< 0 || xop
== '-') ? SI64_MIN
: SI64_MAX
;
2806 /* Will the result be positive? */
2807 if((lhv
< 0) == (rhv
< 0)){
2812 if(rhv
!= 0 && lhv
!= 0 && SI64_MAX
/ rhv
> lhv
){
2813 if(!(f
& a_SATURATED
))
2814 goto jenum_overflow
;
2821 if(lhv
!= 0 && SI64_MIN
/ lhv
< rhv
){
2822 if(!(f
& a_SATURATED
))
2823 goto jenum_overflow
;
2829 if(rhv
!= 0 && lhv
!= 0 && SI64_MIN
/ rhv
< lhv
){
2830 if(!(f
& a_SATURATED
))
2831 goto jenum_overflow
;
2841 if(!(f
& a_SATURATED
))
2850 if(!(f
& a_SATURATED
))
2870 if(rhv
> 63){ /* xxx 63? */
2871 if(!(f
& a_SATURATED
))
2872 goto jenum_overflow
;
2877 else if(f
& a_UNSIGNED
)
2878 lhv
= (ui64_t
)lhv
>> (ui8_t
)rhv
;
2888 }else if(cp
[2] == '\0' && cp
[1] == '@'){
2892 }else if(cp
[0] == '<'){
2904 }else if(cp
[0] == '>'){
2920 }else if(is_asccaseprefix(cp
, "length")){
2921 f
|= a_ISNUM
| a_ISDECIMAL
;
2922 if(argv
[1] == NULL
|| argv
[2] != NULL
)
2925 i
= strlen(*++argv
);
2926 if(UICMP(64, i
, >, SI64_MAX
))
2927 goto jestr_overflow
;
2929 }else if(is_asccaseprefix(cp
, "hash")){
2930 f
|= a_ISNUM
| a_ISDECIMAL
;
2931 if(argv
[1] == NULL
|| argv
[2] != NULL
)
2934 i
= torek_hash(*++argv
);
2936 }else if(is_asccaseprefix(cp
, "file-expand")){
2937 if(argv
[1] == NULL
|| argv
[2] != NULL
)
2940 if((varres
= fexpand(argv
[1], FEXP_NVAR
| FEXP_NOPROTO
)) == NULL
)
2942 }else if(is_asccaseprefix(cp
, "random")){
2943 if(argv
[1] == NULL
|| argv
[2] != NULL
)
2946 if((n_idec_si64_cp(&lhv
, argv
[1], 0, NULL
2947 ) & (n_IDEC_STATE_EMASK
| n_IDEC_STATE_CONSUMED
)
2948 ) != n_IDEC_STATE_CONSUMED
|| lhv
< 0 || lhv
> PATH_MAX
)
2952 varres
= getrandstring((size_t)lhv
);
2953 }else if(is_asccaseprefix(cp
, "find")){
2954 f
|= a_ISNUM
| a_ISDECIMAL
;
2955 if(argv
[1] == NULL
|| argv
[2] == NULL
|| argv
[3] != NULL
)
2958 if((cp
= strstr(argv
[1], argv
[2])) == NULL
)
2960 i
= PTR2SIZE(cp
- argv
[1]);
2961 if(UICMP(64, i
, >, SI64_MAX
))
2962 goto jestr_overflow
;
2964 }else if(is_asccaseprefix(cp
, "ifind")){
2965 f
|= a_ISNUM
| a_ISDECIMAL
;
2966 if(argv
[1] == NULL
|| argv
[2] == NULL
|| argv
[3] != NULL
)
2969 if((cp
= asccasestr(argv
[1], argv
[2])) == NULL
)
2971 i
= PTR2SIZE(cp
- argv
[1]);
2972 if(UICMP(64, i
, >, SI64_MAX
))
2973 goto jestr_overflow
;
2975 }else if(is_asccaseprefix(cp
, "substring")){
2976 if(argv
[1] == NULL
|| argv
[2] == NULL
)
2978 if(argv
[3] != NULL
&& argv
[4] != NULL
)
2981 i
= strlen(varres
= *++argv
);
2983 if(*(cp
= *++argv
) == '\0')
2985 else if((n_idec_si64_cp(&lhv
, cp
, 0, NULL
2986 ) & (n_IDEC_STATE_EMASK
| n_IDEC_STATE_CONSUMED
)
2987 ) != n_IDEC_STATE_CONSUMED
)
2989 if(UICMP(64, i
, >=, lhv
)){
2993 if(n_poption
& n_PO_D_V
)
2994 n_err(_("`vexpr': substring: offset argument too large: %s\n"),
2995 n_shexp_quote_cp(argv
[-1], FAL0
));
2999 if(argv
[1] != NULL
){
3000 if(*(cp
= *++argv
) == '\0')
3002 else if((n_idec_si64_cp(&lhv
, cp
, 0, NULL
3003 ) & (n_IDEC_STATE_EMASK
| n_IDEC_STATE_CONSUMED
)
3004 ) != n_IDEC_STATE_CONSUMED
)
3006 if(UICMP(64, i
, >=, lhv
)){
3007 if(UICMP(64, i
, !=, lhv
))
3008 varres
= savestrbuf(varres
, (size_t)lhv
);
3010 if(n_poption
& n_PO_D_V
)
3011 n_err(_("`vexpr': substring: length argument too large: %s\n"),
3012 n_shexp_quote_cp(argv
[-2], FAL0
));
3017 }else if(is_asccaseprefix(cp
, "regex")) Jregex
:{
3018 regmatch_t rema
[1 + n_VEXPR_REGEX_MAX
];
3022 f
|= a_ISNUM
| a_ISDECIMAL
;
3023 if(argv
[1] == NULL
|| argv
[2] == NULL
||
3024 (argv
[3] != NULL
&& argv
[4] != NULL
))
3027 reflrv
= REG_EXTENDED
;
3029 reflrv
|= REG_ICASE
;
3030 if((reflrv
= regcomp(&re
, argv
[2], reflrv
))){
3031 n_err(_("`vexpr': invalid regular expression: %s: %s\n"),
3032 n_shexp_quote_cp(argv
[2], FAL0
), n_regex_err_to_doc(&re
, reflrv
));
3036 reflrv
= regexec(&re
, argv
[1], n_NELEM(rema
), rema
, 0);
3038 if(reflrv
== REG_NOMATCH
)
3041 /* Search only? Else replace, which is a bit */
3042 if(argv
[3] == NULL
){
3043 if(UICMP(64, rema
[0].rm_so
, >, SI64_MAX
))
3044 goto jestr_overflow
;
3045 lhv
= (si64_t
)rema
[0].rm_so
;
3047 /* We need to setup some kind of pseudo macro environment for this */
3048 struct a_amv_lostack los
;
3049 struct a_amv_mac_call_args amca
;
3050 char const **reargv
;
3052 memset(&amca
, 0, sizeof amca
);
3053 amca
.amca_name
= savestrbuf(&argv
[1][rema
[0].rm_so
],
3054 rema
[0].rm_eo
- rema
[0].rm_so
);
3055 amca
.amca_amp
= a_AMV_MACKY_MACK
;
3056 for(i
= 1; rema
[i
].rm_so
!= -1 && i
< n_NELEM(rema
); ++i
)
3058 amca
.amca_argc
= (ui32_t
)i
- 1;
3060 reargv
= salloc(sizeof(char*) * i
);
3061 for(i
= 1; rema
[i
].rm_so
!= -1 && i
< n_NELEM(rema
); ++i
)
3062 *reargv
++ = savestrbuf(&argv
[1][rema
[i
].rm_so
],
3063 rema
[i
].rm_eo
- rema
[i
].rm_so
);
3066 hold_all_sigs(); /* TODO DISLIKE! */
3067 los
.as_global_saved
= a_amv_lopts
;
3068 los
.as_amcap
= &amca
;
3069 los
.as_up
= los
.as_global_saved
;
3070 los
.as_lopts
= NULL
;
3071 los
.as_unroll
= FAL0
;
3076 struct n_string s_b
;
3077 enum n_shexp_state shs
;
3079 templ
.s
= n_UNCONST(argv
[3]);
3081 shs
= n_shexp_parse_token((n_SHEXP_PARSE_LOG
|
3082 n_SHEXP_PARSE_IGNORE_EMPTY
| n_SHEXP_PARSE_QUOTE_AUTO_FIXED
|
3083 n_SHEXP_PARSE_QUOTE_AUTO_DSQ
),
3084 n_string_creat_auto(&s_b
), &templ
, NULL
);
3085 if((shs
& (n_SHEXP_STATE_ERR_MASK
| n_SHEXP_STATE_STOP
)
3086 ) == n_SHEXP_STATE_STOP
){
3087 varres
= n_string_cp(&s_b
);
3088 n_string_drop_ownership(&s_b
);
3093 a_amv_lopts
= los
.as_global_saved
;
3094 rele_all_sigs(); /* TODO DISLIKE! */
3098 f
&= ~(a_ISNUM
| a_ISDECIMAL
);
3100 }else if(is_asccaseprefix(argv
[0], "iregex")){
3103 #endif /* HAVE_REGEX */
3109 /* Generate the variable value content for numerics.
3110 * Anticipate in our handling below! (Don't do needless work) */
3112 if((f
& a_ISNUM
) && ((f
& a_ISDECIMAL
) || varname
!= NULL
)){
3113 snprintf(varbuf
, sizeof varbuf
, "%" PRId64
, lhv
);
3117 if(varname
== NULL
){
3118 /* If there was no error and we are printing a numeric result, print some
3119 * more bases for the fun of it */
3120 if((f
& (a_ERR
| a_ISNUM
| a_ISDECIMAL
)) == a_ISNUM
){
3123 for(j
= 1, i
= 0; i
< 64; ++i
){
3124 varbuf
[63 + 64 / 8 -j
- i
] = (lhv
& ((ui64_t
)1 << i
)) ? '1' : '0';
3125 if((i
& 7) == 7 && i
!= 63){
3127 varbuf
[63 + 64 / 8 -j
- i
] = ' ';
3130 varbuf
[64 + 64 / 8 -1] = '\0';
3131 fprintf(n_stdout
, "%s\n0%" PRIo64
" | 0x%" PRIX64
" | %" PRId64
"\n",
3132 varbuf
, lhv
, lhv
, lhv
);
3134 fprintf(n_stdout
, "%s\n", varres
);
3135 }else if(!n_var_vset(varname
, (uintptr_t)varres
))
3136 f
|= a_ERR
| a_SOFTERR
;
3137 else if(!(f
& a_SOFTERR
))
3138 n_pstate_var__em
= n_0
;
3140 return (f
& a_ERR
) ? 1 : 0;
3145 f
&= ~(a_ISNUM
| a_ISDECIMAL
);
3146 f
|= a_SOFTERR
| a_ISNUM
;
3151 n_err(_("`vexpr': invalid subcommand: %s\n"),
3152 n_shexp_quote_cp(*argv
, FAL0
));
3156 n_err(_("Synopsis: vexpr: <target-variable> <operator> <:argument:>\n"));
3160 n_err(_("`vexpr': numeric argument invalid or out of range: %s\n"),
3161 n_shexp_quote_cp(*argv
, FAL0
));
3165 n_err(_("`vexpr': expression overflows datatype: %" PRId64
" %c %" PRId64
3166 "\n"), lhv
, op
, rhv
);
3170 n_err(_("`vexpr': string length or offset overflows datatype\n"));