1 /*@ S-nail - a mail user agent derived from Berkeley Mail.
2 *@ Account, macro and variable handling.
4 * Copyright (c) 2000-2004 Gunnar Ritter, Freiburg i. Br., Germany.
5 * Copyright (c) 2012 - 2014 Steffen (Daode) Nurpmeso <sdaoden@users.sf.net>.
8 * Copyright (c) 1980, 1993
9 * The Regents of the University of California. All rights reserved.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. All advertising materials mentioning features or use of this software
20 * must display the following acknowledgement:
21 * This product includes software developed by the University of
22 * California, Berkeley and its contributors.
23 * 4. Neither the name of the University nor the names of its contributors
24 * may be used to endorse or promote products derived from this software
25 * without specific prior written permission.
27 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
28 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
31 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
33 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
36 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
40 #ifndef HAVE_AMALGAMATION
45 * HOWTO add a new non-dynamic binary or value option:
46 * - add an entry to nail.h:enum okeys
47 * - run create-okey-map.pl
51 /* Note: changing the hash function must be reflected in create-okey-map.pl */
52 #define MA_PRIME HSHSIZE
53 #define MA_NAME2HASH(N) torek_hash(N)
54 #define MA_HASH2PRIME(H) ((H) % MA_PRIME)
59 MA_TYPE_MASK
= MA_ACC
,
60 MA_UNDEF
= 1<<1 /* Unlink after lookup */
64 struct macro
*ma_next
;
66 struct mline
*ma_contents
;
67 size_t ma_maxlen
; /* Maximum line length */
68 enum ma_flags ma_flags
;
69 struct var
*ma_localopts
; /* `account' unroll list, for `localopts' */
75 char l_line
[VFIELD_SIZE(sizeof(size_t))];
81 char v_name
[VFIELD_SIZE(sizeof(size_t))];
96 struct var_map
const *vc_vmap
;
101 struct lostack
*s_up
; /* Outer context */
102 struct macro
*s_mac
; /* Context (`account' or `define') */
103 struct var
*s_localopts
;
104 bool_t s_unroll
; /* Unroll? */
107 /* Include the constant create-okey-map.pl output */
110 static struct macro
*_acc_curr
; /* Currently active account */
111 static struct lostack
*_localopts
; /* Currently executing macro unroll list */
113 /* TODO once we have a dynamically sized hashtable we could unite _macros and
114 * TODO _variables into a single hashtable, stripping down fun interface;
115 * TODO also, setting and clearing a variable can be easily joined */
116 static struct var
*_vars
[MA_PRIME
]; /* TODO dynamically spaced */
117 static struct macro
*_macros
[MA_PRIME
]; /* TODO dynamically spaced */
119 /* Special cased value string allocation */
120 static char * _var_vcopy(char const *str
);
121 static void _var_vfree(char *cp
);
123 /* Check for special housekeeping. */
124 static bool_t
_var_check_specials(enum okeys okey
, bool_t enable
,
127 /* If a variable name begins with a lowercase-character and contains at
128 * least one '@', it is converted to all-lowercase. This is necessary
129 * for lookups of names based on email addresses.
130 * Following the standard, only the part following the last '@' should
131 * be lower-cased, but practice has established otherwise here.
132 * Return value may have been placed in string dope (salloc()) */
133 static char const * _var_canonify(char const *vn
);
135 /* Try to reverse lookup an option name to an enum okeys mapping.
136 * Updates vcp.vc_name and vcp.vc_hash; vcp.vc_vmap is NULL if none found */
137 static bool_t
_var_revlookup(struct var_carrier
*vcp
, char const *name
);
139 /* Lookup a variable from vcp.vc_(vmap|name|hash), return wether it was found.
140 * Sets vcp.vc_prime; vcp.vc_var is NULL if not found */
141 static bool_t
_var_lookup(struct var_carrier
*vcp
);
143 /* Set variable from vcp.vc_(vmap|name|hash), return wether error occurred */
144 static bool_t
_var_set(struct var_carrier
*vcp
, char const *value
);
146 /* Clear variable from vcp.vc_(vmap|name|hash); sets vcp.vc_var to NULL,
147 * return wether error occurred */
148 static bool_t
_var_clear(struct var_carrier
*vcp
);
150 /* var_list_all(): qsort(3) helper */
151 static int _var_list_all_cmp(void const *s1
, void const *s2
);
153 /* Shared c_set() and c_setenv() impl, return wether error(s) occurred */
154 static bool_t
_var_set_env(char **ap
, bool_t issetenv
);
156 /* Does cp consist solely of WS and a } */
157 static bool_t
_is_closing_angle(char const *cp
);
159 /* Lookup for macros/accounts */
160 static struct macro
*_ma_look(char const *name
, struct macro
*data
,
163 /* Walk all lines of a macro and execute() them */
164 static int _ma_exec(struct macro
const *mp
, struct var
**unroller
);
166 /* User display helpers */
167 static int _ma_list(enum ma_flags mafl
);
170 static bool_t
_ma_define1(char const *name
, enum ma_flags mafl
);
171 static void _ma_undef1(char const *name
, enum ma_flags mafl
);
172 static void _ma_freelines(struct mline
*lp
);
174 /* Update replay-log */
175 static void _localopts_add(struct lostack
*losp
, char const *name
,
177 static void _localopts_unroll(struct var
**vapp
);
180 _var_vcopy(char const *str
)
189 len
= strlen(str
) +1;
191 memcpy(news
, str
, len
);
207 _var_check_specials(enum okeys okey
, bool_t enable
, char **val
)
222 case ok_b_skipemptybody
:
229 rv
= (val
== NULL
|| var_folder_updated(*val
, &cp
));
230 if (rv
&& cp
!= NULL
) {
232 /* It's smalloc()ed, but ensure we don't leak */
241 case ok_v_line_editor_cursor_right
:
242 if ((rv
= (val
!= NULL
&& *val
!= NULL
))) {
243 /* Set with no value? TODO very guly */
244 if (*(cp
= *val
) != '\0') {
248 c
= expand_shell_escape(&x
, FAL0
);
252 } while (*x
!= '\0');
273 _var_canonify(char const *vn
)
276 if (!upperchar(*vn
)) {
279 for (vp
= vn
; *vp
!= '\0' && *vp
!= '@'; ++vp
)
281 vn
= (*vp
== '@') ? i_strdup(vn
) : vn
;
288 _var_revlookup(struct var_carrier
*vcp
, char const *name
)
291 struct var_map
const *vmp
;
294 vcp
->vc_name
= name
= _var_canonify(name
);
295 vcp
->vc_hash
= hash
= MA_NAME2HASH(name
);
297 for (i
= hash
% _VAR_REV_PRIME
, j
= 0; j
<= _VAR_REV_LONGEST
; ++j
) {
298 ui32_t x
= _var_revmap
[i
];
299 if (x
== _VAR_REV_ILL
)
302 if (vmp
->vm_hash
== hash
&& !strcmp(_var_keydat
+ vmp
->vm_keyoff
, name
)) {
304 vcp
->vc_okey
= (enum okeys
)x
;
307 if (++i
== _VAR_REV_PRIME
) {
308 #ifdef _VAR_REV_WRAPAROUND
319 return (vcp
!= NULL
);
323 _var_lookup(struct var_carrier
*vcp
)
325 struct var
**vap
, *lvp
, *vp
;
328 vap
= _vars
+ (vcp
->vc_prime
= MA_HASH2PRIME(vcp
->vc_hash
));
330 for (lvp
= NULL
, vp
= *vap
; vp
!= NULL
; lvp
= vp
, vp
= vp
->v_link
)
331 if (!strcmp(vp
->v_name
, vcp
->vc_name
)) {
332 /* Relink as head, hope it "sorts on usage" over time.
333 * _var_clear() relies on this behaviour */
335 lvp
->v_link
= vp
->v_link
;
349 _var_set(struct var_carrier
*vcp
, char const *value
)
357 bool_t tmp
= var_clear_allow_undefined
;
358 var_clear_allow_undefined
= TRU1
;
359 err
= _var_clear(vcp
);
360 var_clear_allow_undefined
= tmp
;
366 /* Don't care what happens later on, store this in the unroll list */
367 if (_localopts
!= NULL
)
368 _localopts_add(_localopts
, vcp
->vc_name
, vcp
->vc_var
);
370 if ((vp
= vcp
->vc_var
) == NULL
) {
371 size_t l
= strlen(vcp
->vc_name
) + 1;
374 vp
= smalloc(sizeof(*vp
) - VFIELD_SIZEOF(struct var
, v_name
) + l
);
375 vp
->v_link
= _vars
[vcp
->vc_prime
];
376 _vars
[vcp
->vc_prime
] = vp
;
377 memcpy(vp
->v_name
, vcp
->vc_name
, l
);
381 vp
->v_value
= _var_vcopy(value
);
383 /* Check if update allowed XXX wasteful on error! */
384 if (vcp
->vc_vmap
!= NULL
&& vcp
->vc_vmap
->vm_special
&&
385 (err
= !_var_check_specials(vcp
->vc_okey
, TRU1
, &vp
->v_value
))) {
386 char *cp
= vp
->v_value
;
399 _var_clear(struct var_carrier
*vcp
)
404 if (!_var_lookup(vcp
)) {
405 if (!sourcing
&& !var_clear_allow_undefined
) {
406 fprintf(stderr
, tr(203, "`%s': undefined variable\n"), vcp
->vc_name
);
410 if (_localopts
!= NULL
)
411 _localopts_add(_localopts
, vcp
->vc_name
, vcp
->vc_var
);
413 /* Always listhead after _var_lookup() */
414 _vars
[vcp
->vc_prime
] = _vars
[vcp
->vc_prime
]->v_link
;
415 _var_vfree(vcp
->vc_var
->v_value
);
419 if (vcp
->vc_vmap
!= NULL
&& vcp
->vc_vmap
->vm_special
&&
420 !_var_check_specials(vcp
->vc_okey
, FAL0
, NULL
))
430 _var_list_all_cmp(void const *s1
, void const *s2
)
435 rv
= strcmp(*(char**)UNCONST(s1
), *(char**)UNCONST(s2
));
441 _var_set_env(char **ap
, bool_t issetenv
)
443 char *cp
, *cp2
, *varbuf
, c
;
447 for (; *ap
!= NULL
; ++ap
) {
450 cp2
= varbuf
= ac_alloc(strlen(cp
) +1);
451 for (; (c
= *cp
) != '=' && c
!= '\0'; ++cp
)
459 fprintf(stderr
, tr(41, "Non-null variable name required\n"));
464 if (!issetenv
&& varbuf
[0] == 'n' && varbuf
[1] == 'o')
465 errs
+= _var_vokclear(varbuf
+ 2);
467 errs
+= _var_vokset(varbuf
, (uintptr_t)cp
);
470 errs
+= (setenv(varbuf
, cp
, 1) != 0);
485 _is_closing_angle(char const *cp
)
490 while (spacechar(*cp
))
494 while (spacechar(*cp
))
502 static struct macro
*
503 _ma_look(char const *name
, struct macro
*data
, enum ma_flags mafl
)
505 enum ma_flags save_mafl
;
507 struct macro
*lmp
, *mp
;
511 mafl
&= MA_TYPE_MASK
;
512 h
= MA_NAME2HASH(name
);
513 h
= MA_HASH2PRIME(h
);
515 for (lmp
= NULL
, mp
= _macros
[h
]; mp
!= NULL
; lmp
= mp
, mp
= mp
->ma_next
) {
516 if ((mp
->ma_flags
& MA_TYPE_MASK
) == mafl
&& !strcmp(mp
->ma_name
, name
)) {
517 if (save_mafl
& MA_UNDEF
) {
519 _macros
[h
] = mp
->ma_next
;
521 lmp
->ma_next
= mp
->ma_next
;
528 data
->ma_next
= _macros
[h
];
538 _ma_exec(struct macro
const *mp
, struct var
**unroller
)
543 struct mline
const *lp
;
546 los
.s_up
= _localopts
;
547 los
.s_mac
= UNCONST(mp
);
548 los
.s_localopts
= NULL
;
552 buf
= ac_alloc(mp
->ma_maxlen
+1);
553 for (lp
= mp
->ma_contents
; lp
; lp
= lp
->l_next
) {
554 var_clear_allow_undefined
= TRU1
;
555 memcpy(buf
, lp
->l_line
, lp
->l_length
+1);
556 temporary_localopts_store
= _localopts
; /* XXX intermediate hack */
557 /* FIXME if the execute() jumps away (via INT) then our internal state
558 * FIXME is messed up, even though temporary_localopts_free() is likely
559 * FIXME to correct some of that */
560 rv
|= execute(buf
, 0, lp
->l_length
); /* XXX break if != 0 ? */
561 temporary_localopts_store
= NULL
; /* XXX intermediate hack */
562 var_clear_allow_undefined
= FAL0
;
566 _localopts
= los
.s_up
;
567 if (unroller
== NULL
) {
568 if (los
.s_localopts
!= NULL
)
569 _localopts_unroll(&los
.s_localopts
);
571 *unroller
= los
.s_localopts
;
577 _ma_list(enum ma_flags mafl
)
586 if ((fp
= Ftmp(NULL
, "listmacs", OF_RDWR
| OF_UNLINK
| OF_REGISTER
, 0600)) ==
593 mafl
&= MA_TYPE_MASK
;
594 typestr
= (mafl
& MA_ACC
) ? "account" : "define";
596 for (ti
= mc
= 0; ti
< MA_PRIME
; ++ti
)
597 for (mq
= _macros
[ti
]; mq
; mq
= mq
->ma_next
)
598 if ((mq
->ma_flags
& MA_TYPE_MASK
) == mafl
) {
601 fprintf(fp
, "%s %s {\n", typestr
, mq
->ma_name
);
602 for (lp
= mq
->ma_contents
; lp
!= NULL
; lp
= lp
->l_next
)
603 fprintf(fp
, " %s\n", lp
->l_line
);
607 page_or_print(fp
, 0);
609 mc
= (ui32_t
)ferror(fp
);
617 _ma_define1(char const *name
, enum ma_flags mafl
)
621 struct mline
*lp
, *lst
= NULL
, *lnd
= NULL
;
622 char *linebuf
= NULL
, *cp
;
623 size_t linesize
= 0, maxlen
= 0;
627 mp
= scalloc(1, sizeof *mp
);
628 mp
->ma_name
= sstrdup(name
);
632 n
= readline_input("", TRU1
, &linebuf
, &linesize
, NULL
);
636 fprintf(stderr
, tr(75, "Unterminated %s definition: \"%s\".\n"),
637 (mafl
& MA_ACC
? "account" : "macro"), mp
->ma_name
);
638 if (sourcing
&& !loading
)
642 if (_is_closing_angle(linebuf
))
646 for (cp
= linebuf
, i
= 0; i
< n
; ++cp
, ++i
)
652 while (whitechar(cp
[n
- 1]))
658 maxlen
= MAX(maxlen
, (size_t)n
);
661 lp
= scalloc(1, sizeof(*lp
) - VFIELD_SIZEOF(struct mline
, l_line
) + n
);
662 memcpy(lp
->l_line
, cp
, n
);
663 lp
->l_length
= (size_t)--n
;
670 mp
->ma_contents
= lst
;
671 mp
->ma_maxlen
= maxlen
;
673 if (_ma_look(mp
->ma_name
, mp
, mafl
) != NULL
) {
674 fprintf(stderr
, tr(76, "A %s named `%s' already exists.\n"),
675 (mafl
& MA_ACC
? "account" : "macro"), mp
->ma_name
);
676 lst
= mp
->ma_contents
;
696 _ma_undef1(char const *name
, enum ma_flags mafl
)
701 if ((mp
= _ma_look(name
, NULL
, mafl
| MA_UNDEF
)) != NULL
) {
702 _ma_freelines(mp
->ma_contents
);
706 fprintf(stderr
, tr(571, "%s `%s' is not defined\n"),
707 (mafl
& MA_ACC
? "Account" : "Macro"), name
);
712 _ma_freelines(struct mline
*lp
)
717 for (lq
= NULL
; lp
!= NULL
; ) {
729 _localopts_add(struct lostack
*losp
, char const *name
, struct var
*ovap
)
735 /* Propagate unrolling up the stack, as necessary */
736 while (!losp
->s_unroll
&& (losp
= losp
->s_up
) != NULL
)
741 /* We've found a level that wants to unroll; check wether it does it yet */
742 for (vap
= losp
->s_localopts
; vap
!= NULL
; vap
= vap
->v_link
)
743 if (!strcmp(vap
->v_name
, name
))
746 nl
= strlen(name
) + 1;
747 vl
= (ovap
!= NULL
) ? strlen(ovap
->v_value
) + 1 : 0;
748 vap
= smalloc(sizeof(*vap
) - VFIELD_SIZEOF(struct var
, v_name
) + nl
+ vl
);
749 vap
->v_link
= losp
->s_localopts
;
750 losp
->s_localopts
= vap
;
751 memcpy(vap
->v_name
, name
, nl
);
755 vap
->v_value
= vap
->v_name
+ nl
;
756 memcpy(vap
->v_value
, ovap
->v_value
, vl
);
763 _localopts_unroll(struct var
**vapp
)
765 struct lostack
*save_los
;
772 save_los
= _localopts
;
774 while (vap
!= NULL
) {
777 vok_vset(x
->v_name
, x
->v_value
);
780 _localopts
= save_los
;
785 _var_oklook(enum okeys okey
)
787 struct var_carrier vc
;
791 vc
.vc_vmap
= _var_map
+ okey
;
792 vc
.vc_name
= _var_keydat
+ _var_map
[okey
].vm_keyoff
;
793 vc
.vc_hash
= _var_map
[okey
].vm_hash
;
796 if (!_var_lookup(&vc
)) {
797 if ((rv
= getenv(vc
.vc_name
)) != NULL
) {
799 assert(vc
.vc_var
!= NULL
);
804 rv
= vc
.vc_var
->v_value
;
810 _var_okset(enum okeys okey
, uintptr_t val
)
812 struct var_carrier vc
;
816 vc
.vc_vmap
= _var_map
+ okey
;
817 vc
.vc_name
= _var_keydat
+ _var_map
[okey
].vm_keyoff
;
818 vc
.vc_hash
= _var_map
[okey
].vm_hash
;
821 rv
= _var_set(&vc
, (val
== 0x1 ? "" : (char const*)val
));
827 _var_okclear(enum okeys okey
)
829 struct var_carrier vc
;
833 vc
.vc_vmap
= _var_map
+ okey
;
834 vc
.vc_name
= _var_keydat
+ _var_map
[okey
].vm_keyoff
;
835 vc
.vc_hash
= _var_map
[okey
].vm_hash
;
838 rv
= _var_clear(&vc
);
844 _var_voklook(char const *vokey
)
846 struct var_carrier vc
;
850 _var_revlookup(&vc
, vokey
);
852 if (!_var_lookup(&vc
)) {
853 if ((rv
= getenv(vc
.vc_name
)) != NULL
) {
855 assert(vc
.vc_var
!= NULL
);
860 rv
= vc
.vc_var
->v_value
;
866 _var_vokset(char const *vokey
, uintptr_t val
)
868 struct var_carrier vc
;
872 _var_revlookup(&vc
, vokey
);
874 err
= _var_set(&vc
, (val
== 0x1 ? "" : (char const*)val
));
880 _var_vokclear(char const *vokey
)
882 struct var_carrier vc
;
886 _var_revlookup(&vc
, vokey
);
888 err
= _var_clear(&vc
);
903 if ((fp
= Ftmp(NULL
, "listvars", OF_RDWR
| OF_UNLINK
| OF_REGISTER
, 0600)) ==
909 for (no
= i
= 0; i
< MA_PRIME
; ++i
)
910 for (vp
= _vars
[i
]; vp
!= NULL
; vp
= vp
->v_link
)
912 vacp
= salloc(no
* sizeof(*vacp
));
913 for (cap
= vacp
, i
= 0; i
< MA_PRIME
; ++i
)
914 for (vp
= _vars
[i
]; vp
!= NULL
; vp
= vp
->v_link
)
918 qsort(vacp
, no
, sizeof *vacp
, &_var_list_all_cmp
);
920 i
= (ok_blook(bsdcompat
) || ok_blook(bsdset
));
921 fmt
= (i
!= 0) ? "%s\t%s\n" : "%s=\"%s\"\n";
923 for (cap
= vacp
; no
!= 0; ++cap
, --no
) {
924 char *cp
= vok_vlook(*cap
); /* XXX when lookup checks val/bin, change */
927 if (i
|| *cp
!= '\0')
928 fprintf(fp
, fmt
, *cap
, cp
);
930 fprintf(fp
, "%s\n", *cap
);
933 page_or_print(fp
, PTR2SIZE(cap
- vacp
));
942 struct var_carrier vc
;
943 char **argv
= v
, *val
;
952 for (; *argv
!= NULL
; ++argv
) {
953 memset(&vc
, 0, sizeof vc
);
954 _var_revlookup(&vc
, *argv
);
955 if (_var_lookup(&vc
)) {
956 val
= vc
.vc_var
->v_value
;
959 isenv
= ((val
= getenv(vc
.vc_name
)) != NULL
);
961 val
= UNCONST("NULL");
962 isset
= (vc
.vc_var
!= NULL
);
964 if (vc
.vc_vmap
!= NULL
) {
965 if (vc
.vc_vmap
->vm_binary
)
966 printf("%s: binary option (%d): isset=%d/environ=%d\n",
967 vc
.vc_name
, vc
.vc_okey
, isset
, isenv
);
969 printf("%s: value option (%d): isset=%d/environ=%d value<%s>\n",
970 vc
.vc_name
, vc
.vc_okey
, isset
, isenv
, val
);
972 printf("%s: isset=%d/environ=%d value<%s>\n",
973 vc
.vc_name
, isset
, isenv
, val
);
977 return (v
== NULL
? !STOP
: !OKAY
); /* xxx 1:bad 0:good -- do some */
991 err
= _var_set_env(ap
, FAL0
);
1003 if (!(err
= starting
))
1004 err
= _var_set_env(ap
, TRU1
);
1017 err
|= _var_vokclear(*ap
++);
1028 if (!(err
= starting
)) {
1030 bool_t tmp
= var_clear_allow_undefined
;
1031 var_clear_allow_undefined
= TRU1
;
1032 for (ap
= v
; *ap
!= NULL
; ++ap
) {
1033 bool_t bad
= _var_vokclear(*ap
);
1036 unsetenv(*ap
) != 0 &&
1042 var_clear_allow_undefined
= tmp
;
1055 if (args
[0] == NULL
) {
1056 rv
= _ma_list(MA_NONE
);
1060 if (args
[1] == NULL
|| args
[1][0] != '{' || args
[1][1] != '\0' ||
1062 fprintf(stderr
, tr(505, "Syntax is: define <name> {"));
1066 rv
= !_ma_define1(args
[0], MA_NONE
);
1079 if (*args
== NULL
) {
1080 fprintf(stderr
, tr(504, "`%s': required arguments are missing\n"),
1085 _ma_undef1(*args
, MA_NONE
);
1086 while (*++args
!= NULL
);
1098 char const *errs
, *name
;
1102 if (args
[0] == NULL
|| (args
[1] != NULL
&& args
[2] != NULL
)) {
1103 errs
= tr(507, "Syntax is: call <%s>\n");
1108 if ((mp
= _ma_look(*args
, NULL
, MA_NONE
)) == NULL
) {
1109 errs
= tr(508, "Undefined macro called: `%s'\n");
1114 rv
= _ma_exec(mp
, NULL
);
1119 fprintf(stderr
, errs
, name
);
1124 callhook(char const *name
, int nmail
)
1131 var
= ac_alloc(len
= strlen(name
) + 12 +1);
1132 snprintf(var
, len
, "folder-hook-%s", name
);
1133 if ((cp
= vok_vlook(var
)) == NULL
&& (cp
= ok_vlook(folder_hook
)) == NULL
) {
1137 if ((mp
= _ma_look(cp
, NULL
, MA_NONE
)) == NULL
) {
1138 fprintf(stderr
, tr(49, "Cannot call hook for folder \"%s\": "
1139 "Macro \"%s\" does not exist.\n"), name
, cp
);
1144 inhook
= nmail
? 3 : 1; /* XXX enum state machine */
1145 rv
= _ma_exec(mp
, NULL
);
1158 int rv
= 1, i
, oqf
, nqf
;
1161 if (args
[0] == NULL
) {
1162 rv
= _ma_list(MA_ACC
);
1166 if (args
[1] && args
[1][0] == '{' && args
[1][1] == '\0') {
1167 if (args
[2] != NULL
) {
1168 fprintf(stderr
, tr(517, "Syntax is: account <name> {\n"));
1171 if (!asccasecmp(args
[0], ACCOUNT_NULL
)) {
1172 fprintf(stderr
, tr(521, "Error: `%s' is a reserved name.\n"),
1176 rv
= !_ma_define1(args
[0], MA_ACC
);
1181 fprintf(stderr
, tr(518, "Cannot change account from within a hook.\n"));
1185 save_mbox_for_possible_quitstuff();
1188 if (asccasecmp(args
[0], ACCOUNT_NULL
) != 0 &&
1189 (mp
= _ma_look(args
[0], NULL
, MA_ACC
)) == NULL
) {
1190 fprintf(stderr
, tr(519, "Account `%s' does not exist.\n"), args
[0]);
1194 oqf
= savequitflags();
1195 if (_acc_curr
!= NULL
&& _acc_curr
->ma_localopts
!= NULL
)
1196 _localopts_unroll(&_acc_curr
->ma_localopts
);
1197 account_name
= (mp
!= NULL
) ? mp
->ma_name
: NULL
;
1200 if (mp
!= NULL
&& _ma_exec(mp
, &mp
->ma_localopts
) == CBAD
) {
1201 /* XXX account switch incomplete, unroll? */
1202 fprintf(stderr
, tr(520, "Switching to account `%s' failed.\n"), args
[0]);
1206 if (!starting
&& !inhook
) {
1207 nqf
= savequitflags(); /* TODO obsolete (leave -> void -> new box!) */
1208 restorequitflags(oqf
);
1209 if ((i
= setfile("%", 0)) < 0)
1211 callhook(mailname
, 0);
1212 if (i
> 0 && !ok_blook(emptystart
))
1214 announce(ok_blook(bsdcompat
) || ok_blook(bsdannounce
));
1215 restorequitflags(nqf
);
1224 c_unaccount(void *v
)
1230 if (*args
== NULL
) {
1231 fprintf(stderr
, tr(504, "`%s': required arguments are missing\n"),
1238 if (account_name
!= NULL
&& !strcmp(account_name
, *args
)) {
1239 fprintf(stderr
, tr(506,
1240 "Rejecting deletion of currently active account `%s'\n"), *args
);
1243 _ma_undef1(*args
, MA_ACC
);
1244 } while (*++args
!= NULL
);
1251 c_localopts(void *v
)
1257 if (_localopts
== NULL
) {
1258 fprintf(stderr
, tr(522,
1259 "Cannot use `localopts' but from within a `define' or `account'\n"));
1263 _localopts
->s_unroll
= (**c
== '0') ? FAL0
: TRU1
;
1271 temporary_localopts_free(void) /* XXX intermediate hack */
1273 struct lostack
*losp
;
1276 var_clear_allow_undefined
= FAL0
;
1277 losp
= temporary_localopts_store
;
1278 temporary_localopts_store
= NULL
;
1279 _localopts_unroll(&losp
->s_localopts
);
1283 /* vim:set fenc=utf-8:s-it-mode */