Enable WANT_QUOTE_FOLD, *_ASSERT -> *_DEBUG, more cleanup
[s-mailx.git] / acmava.c
blob6d82bbaa7b107c42c9d04cf5049aa750abd9ee2e
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 - 2013 Steffen "Daode" Nurpmeso <sdaoden@users.sf.net>.
6 */
7 /*
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
13 * are met:
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
37 * SUCH DAMAGE.
40 #include "nail.h"
43 * TODO in general it would be nice if it would be possible to define "macros"
44 * TODO etc. inside of other "macros"
47 #define MA_PRIME HSHSIZE
48 #define MA_HASH(S) (strhash(S) % MA_PRIME)
50 enum ma_flags {
51 MA_NONE = 0,
52 MA_ACC = 1<<0,
53 MA_TYPE_MASK = MA_ACC,
54 MA_UNDEF = 1<<1 /* Unlink after lookup */
57 struct macro {
58 struct macro *ma_next;
59 char *ma_name;
60 struct line *ma_contents;
61 size_t ma_maxlen; /* Maximum line length */
62 enum ma_flags ma_flags;
63 struct var *ma_localopts; /* `account' unroll list, for `localopts' */
66 struct line {
67 struct line *l_next;
68 size_t l_length;
69 char l_line[VFIELD_SIZE(sizeof(size_t))];
72 struct var {
73 struct var *v_link;
74 char *v_name;
75 char *v_value;
78 struct lostack {
79 struct lostack *s_up; /* Outer context */
80 struct macro *s_mac; /* Context (`account' or `define') */
81 struct var *s_localopts;
82 bool_t s_unroll; /* Unroll? */
85 static struct macro *_acc_curr; /* Currently active account */
86 static struct lostack *_localopts; /* Currently executing macro unroll list */
88 /* TODO once we have a dynamically sized hashtable we could unite _macros and
89 * TODO _variables into a single hashtable, stripping down fun interface;
90 * TODO also, setting and clearing a variable can be easily joined */
91 static struct macro *_macros[MA_PRIME]; /* TODO dynamically spaced */
92 static struct var *_vars[MA_PRIME]; /* TODO dynamically spaced */
94 /* Special cased value string allocation */
95 static char * _vcopy(char const *str);
96 static void _vfree(char *cp);
98 /* Check for special housekeeping. */
99 static bool_t _check_special_vars(char const *name, bool_t enable,
100 char **val);
102 /* If a variable name begins with a lowercase-character and contains at
103 * least one '@', it is converted to all-lowercase. This is necessary
104 * for lookups of names based on email addresses.
106 * Following the standard, only the part following the last '@' should
107 * be lower-cased, but practice has established otherwise here */
108 static char const * _canonify(char const *vn);
110 /* Locate a variable and return its variable node */
111 static struct var * _lookup(char const *name, ui_it h, bool_t hisset);
113 /* Line *cp* consists solely of WS and a } */
114 static bool_t _is_closing_angle(char const *cp);
116 /* Lookup for macros/accounts */
117 static struct macro *_malook(char const *name, struct macro *data,
118 enum ma_flags mafl);
120 /* Walk all lines of a macro and execute() them */
121 static int _maexec(struct macro const *mp, struct var **unroll_store);
123 /* User display helpers */
124 static int _list_macros(enum ma_flags mafl);
126 /* */
127 static bool_t _define1(char const *name, enum ma_flags mafl);
128 static void _undef1(char const *name, enum ma_flags mafl);
129 static void _freelines(struct line *lp);
131 /* qsort(3) helper */
132 static int __var_list_all_cmp(void const *s1, void const *s2);
134 /* Update replay-log */
135 static void _localopts_add(struct lostack *losp, char const *name,
136 struct var *ovap);
137 static void _localopts_unroll(struct var **vapp);
139 static char *
140 _vcopy(char const *str)
142 char *news;
143 size_t len;
145 if (*str == '\0')
146 news = UNCONST("");
147 else {
148 len = strlen(str) + 1;
149 news = smalloc(len);
150 memcpy(news, str, len);
152 return news;
155 static void
156 _vfree(char *cp)
158 if (*cp != '\0')
159 free(cp);
162 static bool_t
163 _check_special_vars(char const *name, bool_t enable, char **val)
165 /* TODO _check_special_vars --> value cache */
166 char *cp = NULL;
167 bool_t rv = TRU1;
168 int flag = 0;
170 if (strcmp(name, "debug") == 0)
171 flag = OPT_DEBUG;
172 else if (strcmp(name, "header") == 0)
173 flag = OPT_N_FLAG, enable = ! enable;
174 else if (strcmp(name, "skipemptybody") == 0)
175 flag = OPT_E_FLAG;
176 else if (strcmp(name, "verbose") == 0)
177 flag = OPT_VERBOSE;
178 else if (strcmp(name, "prompt") == 0)
179 flag = OPT_NOPROMPT, enable = ! enable;
180 else if (strcmp(name, "folder") == 0) {
181 rv = var_folder_updated(*val, &cp);
182 if (rv && cp != NULL) {
183 _vfree(*val);
184 /* It's smalloc()ed, but ensure we don't leak */
185 if (*cp == '\0') {
186 *val = UNCONST("");
187 free(cp);
188 } else
189 *val = cp;
192 #ifdef HAVE_NCL
193 else if (strcmp(name, "line-editor-cursor-right") == 0) {
194 char const *x = cp = *val;
195 int c;
196 while (*x != '\0') {
197 c = expand_shell_escape(&x, FAL0);
198 if (c < 0)
199 break;
200 *cp++ = (char)c;
202 *cp++ = '\0';
204 #endif
206 if (flag) {
207 if (enable)
208 options |= flag;
209 else
210 options &= ~flag;
212 return rv;
215 static char const *
216 _canonify(char const *vn)
218 if (! upperchar(*vn)) {
219 char const *vp;
221 for (vp = vn; *vp != '\0' && *vp != '@'; ++vp)
223 vn = (*vp == '@') ? i_strdup(vn) : vn;
225 return vn;
228 static struct var *
229 _lookup(char const *name, ui_it h, bool_t hisset)
231 struct var **vap, *lvp, *vp;
233 if (! hisset)
234 h = MA_HASH(name);
235 vap = _vars + h;
237 for (lvp = NULL, vp = *vap; vp != NULL; lvp = vp, vp = vp->v_link)
238 if (*vp->v_name == *name && strcmp(vp->v_name, name) == 0) {
239 /* Relink as head, hope it "sorts on usage" over time */
240 if (lvp != NULL) {
241 lvp->v_link = vp->v_link;
242 vp->v_link = *vap;
243 *vap = vp;
245 goto jleave;
247 vp = NULL;
248 jleave:
249 return vp;
252 static bool_t
253 _is_closing_angle(char const *cp)
255 bool_t rv = FAL0;
256 while (spacechar(*cp))
257 ++cp;
258 if (*cp++ != '}')
259 goto jleave;
260 while (spacechar(*cp))
261 ++cp;
262 rv = (*cp == '\0');
263 jleave:
264 return rv;
267 static struct macro *
268 _malook(char const *name, struct macro *data, enum ma_flags mafl)
270 enum ma_flags save_mafl;
271 ui_it h;
272 struct macro *lmp, *mp;
274 save_mafl = mafl;
275 mafl &= MA_TYPE_MASK;
276 h = MA_HASH(name);
278 for (lmp = NULL, mp = _macros[h]; mp != NULL; lmp = mp, mp = mp->ma_next) {
279 if ((mp->ma_flags & MA_TYPE_MASK) == mafl &&
280 strcmp(mp->ma_name, name) == 0) {
281 if (save_mafl & MA_UNDEF) {
282 if (lmp == NULL)
283 _macros[h] = mp->ma_next;
284 else
285 lmp->ma_next = mp->ma_next;
287 goto jleave;
291 if (data != NULL) {
292 data->ma_next = _macros[h];
293 _macros[h] = data;
294 mp = NULL;
296 jleave:
297 return mp;
300 static int
301 _maexec(struct macro const *mp, struct var **unroll_store)
303 struct lostack los;
304 int rv = 0;
305 struct line const *lp;
306 char *buf = ac_alloc(mp->ma_maxlen + 1);
308 los.s_up = _localopts;
309 los.s_mac = UNCONST(mp);
310 los.s_localopts = NULL;
311 los.s_unroll = FAL0;
312 _localopts = &los;
314 for (lp = mp->ma_contents; lp; lp = lp->l_next) {
315 unset_allow_undefined = TRU1;
316 memcpy(buf, lp->l_line, lp->l_length + 1);
317 rv |= execute(buf, 0, lp->l_length); /* XXX break if != 0 ? */
318 unset_allow_undefined = FAL0;
321 _localopts = los.s_up;
322 if (unroll_store == NULL)
323 _localopts_unroll(&los.s_localopts);
324 else
325 *unroll_store = los.s_localopts;
327 ac_free(buf);
328 return rv;
331 static int
332 _list_macros(enum ma_flags mafl)
334 FILE *fp;
335 char *cp;
336 char const *typestr;
337 struct macro *mq;
338 ui_it ti, mc;
339 struct line *lp;
341 if ((fp = Ftemp(&cp, "Ra", "w+", 0600, 1)) == NULL) {
342 perror("tmpfile");
343 return 1;
345 rm(cp);
346 Ftfree(&cp);
348 mafl &= MA_TYPE_MASK;
349 typestr = (mafl & MA_ACC) ? "account" : "define";
351 for (ti = mc = 0; ti < MA_PRIME; ++ti)
352 for (mq = _macros[ti]; mq; mq = mq->ma_next)
353 if ((mq->ma_flags & MA_TYPE_MASK) == mafl) {
354 if (++mc > 1)
355 fputc('\n', fp);
356 fprintf(fp, "%s %s {\n", typestr, mq->ma_name);
357 for (lp = mq->ma_contents; lp; lp = lp->l_next)
358 fprintf(fp, " %s\n", lp->l_line);
359 fputs("}\n", fp);
361 if (mc)
362 page_or_print(fp, 0);
364 mc = (ui_it)ferror(fp);
365 Fclose(fp);
366 return (int)mc;
369 static bool_t
370 _define1(char const *name, enum ma_flags mafl)
372 bool_t rv = FAL0;
373 struct macro *mp;
374 struct line *lp, *lst = NULL, *lnd = NULL;
375 char *linebuf = NULL, *cp;
376 size_t linesize = 0, maxlen = 0;
377 int n, i;
379 mp = scalloc(1, sizeof *mp);
380 mp->ma_name = sstrdup(name);
381 mp->ma_flags = mafl;
383 for (;;) {
384 n = readline_input(LNED_LF_ESC, "", &linebuf, &linesize);
385 if (n <= 0) {
386 fprintf(stderr, tr(75, "Unterminated %s definition: \"%s\".\n"),
387 (mafl & MA_ACC ? "account" : "macro"), mp->ma_name);
388 if (sourcing)
389 unstack();
390 goto jerr;
392 if (_is_closing_angle(linebuf))
393 break;
395 /* Trim WS */
396 for (cp = linebuf, i = 0; i < n; ++cp, ++i)
397 if (! whitechar(*cp))
398 break;
399 if (i == n)
400 continue;
401 n -= i;
402 while (whitechar(cp[n - 1]))
403 if (--n == 0)
404 break;
405 if (n == 0)
406 continue;
408 maxlen = MAX(maxlen, (size_t)n);
409 cp[n++] = '\0';
411 lp = scalloc(1, sizeof(*lp) - VFIELD_SIZEOF(struct line, l_line) + n);
412 memcpy(lp->l_line, cp, n);
413 lp->l_length = (size_t)--n;
414 if (lst != NULL) {
415 lnd->l_next = lp;
416 lnd = lp;
417 } else
418 lst = lnd = lp;
420 mp->ma_contents = lst;
421 mp->ma_maxlen = maxlen;
423 if (_malook(mp->ma_name, mp, mafl) != NULL) {
424 if (! (mafl & MA_ACC)) {
425 fprintf(stderr, tr(76, "A macro named \"%s\" already exists.\n"),
426 mp->ma_name);
427 lst = mp->ma_contents;
428 goto jerr;
430 _undef1(mp->ma_name, MA_ACC);
431 _malook(mp->ma_name, mp, MA_ACC);
434 rv = TRU1;
435 jleave:
436 if (linebuf != NULL)
437 free(linebuf);
438 return rv;
439 jerr:
440 if (lst != NULL)
441 _freelines(lst);
442 free(mp->ma_name);
443 free(mp);
444 goto jleave;
447 static void
448 _undef1(char const *name, enum ma_flags mafl)
450 struct macro *mp;
452 if ((mp = _malook(name, NULL, mafl | MA_UNDEF)) != NULL) {
453 _freelines(mp->ma_contents);
454 free(mp->ma_name);
455 free(mp);
459 static void
460 _freelines(struct line *lp)
462 struct line *lq;
464 for (lq = NULL; lp != NULL; ) {
465 if (lq != NULL)
466 free(lq);
467 lq = lp;
468 lp = lp->l_next;
470 if (lq)
471 free(lq);
474 static int
475 __var_list_all_cmp(void const *s1, void const *s2)
477 return strcmp(*(char**)UNCONST(s1), *(char**)UNCONST(s2));
480 static void
481 _localopts_add(struct lostack *losp, char const *name, struct var *ovap)
483 struct var *vap;
484 size_t nl, vl;
486 /* Propagate unrolling up the stack, as necessary */
487 while (! losp->s_unroll && (losp = losp->s_up) != NULL)
489 if (losp == NULL)
490 goto jleave;
492 /* We have found a level that wants to unroll; check wether it does it yet */
493 for (vap = losp->s_localopts; vap != NULL; vap = vap->v_link)
494 if (strcmp(vap->v_name, name) == 0)
495 goto jleave;
497 nl = strlen(name) + 1;
498 vl = (ovap != NULL) ? strlen(ovap->v_value) + 1 : 0;
499 vap = smalloc(sizeof(*vap) + nl + vl);
500 vap->v_link = losp->s_localopts;
501 losp->s_localopts = vap;
502 vap->v_name = (char*)(vap + 1);
503 memcpy(vap->v_name, name, nl);
504 if (vl == 0)
505 vap->v_value = NULL;
506 else {
507 vap->v_value = (char*)(vap + 1) + nl;
508 memcpy(vap->v_value, ovap->v_value, vl);
510 jleave:
514 static void
515 _localopts_unroll(struct var **vapp)
517 struct lostack *save_los;
518 struct var *x, *vap;
520 vap = *vapp;
521 *vapp = NULL;
523 save_los = _localopts;
524 _localopts = NULL;
525 while (vap != NULL) {
526 x = vap;
527 vap = vap->v_link;
528 var_assign(x->v_name, x->v_value);
529 free(x);
531 _localopts = save_los;
534 void
535 var_assign(char const *name, char const *val)
537 struct var *vp;
538 ui_it h;
539 char *oval;
541 if (val == NULL) {
542 bool_t tmp = unset_allow_undefined;
543 unset_allow_undefined = TRU1;
544 var_unset(name);
545 unset_allow_undefined = tmp;
546 goto jleave;
549 name = _canonify(name);
550 h = MA_HASH(name);
551 vp = _lookup(name, h, TRU1);
553 /* Don't care what happens later on, store this in the unroll list */
554 if (_localopts != NULL)
555 _localopts_add(_localopts, name, vp);
557 if (vp == NULL) {
558 vp = (struct var*)scalloc(1, sizeof *vp);
559 vp->v_name = _vcopy(name);
560 vp->v_link = _vars[h];
561 _vars[h] = vp;
562 oval = UNCONST("");
563 } else
564 oval = vp->v_value;
565 vp->v_value = _vcopy(val);
567 /* Check if update allowed XXX wasteful on error! */
568 if (! _check_special_vars(name, TRU1, &vp->v_value)) {
569 char *cp = vp->v_value;
570 vp->v_value = oval;
571 oval = cp;
573 if (*oval != '\0')
574 _vfree(oval);
575 jleave:
580 var_unset(char const *name)
582 int ret = 1;
583 ui_it h;
584 struct var *vp;
586 name = _canonify(name);
587 h = MA_HASH(name);
588 vp = _lookup(name, h, TRU1);
590 if (vp == NULL) {
591 if (! sourcing && ! unset_allow_undefined) {
592 fprintf(stderr, tr(203, "\"%s\": undefined variable\n"), name);
593 goto jleave;
595 } else {
596 if (_localopts != NULL)
597 _localopts_add(_localopts, name, vp);
599 /* Always listhead after _lookup() */
600 _vars[h] = _vars[h]->v_link;
601 _vfree(vp->v_name);
602 _vfree(vp->v_value);
603 free(vp);
605 _check_special_vars(name, FAL0, NULL);
607 ret = 0;
608 jleave:
609 return ret;
612 char *
613 var_lookup(char const *name, bool_t look_environ)
615 struct var *vp;
616 char *rv;
618 name = _canonify(name);
619 if ((vp = _lookup(name, 0, FAL0)) != NULL)
620 rv = vp->v_value;
621 else if (! look_environ)
622 rv = NULL;
623 else if ((rv = getenv(name)) != NULL && *rv != '\0')
624 rv = savestr(rv);
625 return rv;
628 void
629 var_list_all(void)
631 FILE *fp;
632 char *cp, **vacp, **cap;
633 struct var *vp;
634 size_t no, i;
635 char const *fmt;
637 if ((fp = Ftemp(&cp, "Ra", "w+", 0600, 1)) == NULL) {
638 perror("tmpfile");
639 goto jleave;
641 rm(cp);
642 Ftfree(&cp);
644 for (no = i = 0; i < MA_PRIME; ++i)
645 for (vp = _vars[i]; vp != NULL; vp = vp->v_link)
646 ++no;
647 vacp = salloc(no * sizeof(*vacp));
648 for (cap = vacp, i = 0; i < MA_PRIME; ++i)
649 for (vp = _vars[i]; vp != NULL; vp = vp->v_link)
650 *cap++ = vp->v_name;
652 if (no > 1)
653 qsort(vacp, no, sizeof *vacp, &__var_list_all_cmp);
655 i = (boption("bsdcompat") || boption("bsdset"));
656 fmt = (i != 0) ? "%s\t%s\n" : "%s=\"%s\"\n";
658 for (cap = vacp; no != 0; ++cap, --no) {
659 cp = value(*cap); /* TODO internal lookup; binary? value? */
660 if (cp == NULL)
661 cp = UNCONST("");
662 if (i || *cp != '\0')
663 fprintf(fp, fmt, *cap, cp);
664 else
665 fprintf(fp, "%s\n", *cap);
668 page_or_print(fp, (size_t)(cap - vacp));
669 Fclose(fp);
670 jleave:
675 cdefine(void *v)
677 int rv = 1;
678 char **args = v;
679 char const *errs;
681 if (args[0] == NULL) {
682 errs = tr(504, "Missing macro name to `define'");
683 goto jerr;
685 if (args[1] == NULL || strcmp(args[1], "{") || args[2] != NULL) {
686 errs = tr(505, "Syntax is: define <name> {");
687 goto jerr;
689 rv = ! _define1(args[0], MA_NONE);
690 jleave:
691 return rv;
692 jerr:
693 fprintf(stderr, "%s\n", errs);
694 goto jleave;
698 cundef(void *v)
700 int rv = 1;
701 char **args = v;
703 if (*args == NULL) {
704 fprintf(stderr, tr(506, "Missing macro name to `undef'\n"));
705 goto jleave;
708 _undef1(*args, MA_NONE);
709 while (*++args);
710 rv = 0;
711 jleave:
712 return rv;
716 ccall(void *v)
718 int rv = 1;
719 char **args = v;
720 char const *errs, *name;
721 struct macro *mp;
723 if (args[0] == NULL || (args[1] != NULL && args[2] != NULL)) {
724 errs = tr(507, "Syntax is: call <%s>\n");
725 name = "name";
726 goto jerr;
729 if ((mp = _malook(*args, NULL, MA_NONE)) == NULL) {
730 errs = tr(508, "Undefined macro called: \"%s\"\n");
731 name = *args;
732 goto jerr;
735 rv = _maexec(mp, NULL);
736 jleave:
737 return rv;
738 jerr:
739 fprintf(stderr, errs, name);
740 goto jleave;
744 callhook(char const *name, int nmail)
746 int len, rv;
747 struct macro *mp;
748 char *var, *cp;
750 var = ac_alloc(len = strlen(name) + 13);
751 snprintf(var, len, "folder-hook-%s", name);
752 if ((cp = value(var)) == NULL && (cp = value("folder-hook")) == NULL) {
753 rv = 0;
754 goto jleave;
756 if ((mp = _malook(cp, NULL, MA_NONE)) == NULL) {
757 fprintf(stderr, tr(49, "Cannot call hook for folder \"%s\": "
758 "Macro \"%s\" does not exist.\n"), name, cp);
759 rv = 1;
760 goto jleave;
763 inhook = nmail ? 3 : 1;
764 rv = _maexec(mp, NULL);
765 inhook = 0;
766 jleave:
767 ac_free(var);
768 return rv;
772 cdefines(void *v)
774 (void)v;
775 return _list_macros(MA_NONE);
779 c_account(void *v)
781 char **args = v;
782 struct macro *mp;
783 int rv = 1, i, oqf, nqf;
785 if (args[0] == NULL) {
786 rv = _list_macros(MA_ACC);
787 goto jleave;
790 if (args[1] && args[1][0] == '{' && args[1][1] == '\0') {
791 if (args[2] != NULL) {
792 fprintf(stderr, tr(517, "Syntax is: account <name> {\n"));
793 goto jleave;
795 if (asccasecmp(args[0], ACCOUNT_NULL) == 0) {
796 fprintf(stderr, tr(521, "Error: `%s' is a reserved name.\n"),
797 ACCOUNT_NULL);
798 goto jleave;
800 rv = ! _define1(args[0], MA_ACC);
801 goto jleave;
804 if (inhook) {
805 fprintf(stderr, tr(518, "Cannot change account from within a hook.\n"));
806 goto jleave;
809 save_mbox_for_possible_quitstuff();
811 mp = NULL;
812 if (asccasecmp(args[0], ACCOUNT_NULL) != 0 &&
813 (mp = _malook(args[0], NULL, MA_ACC)) == NULL) {
814 fprintf(stderr, tr(519, "Account `%s' does not exist.\n"), args[0]);
815 goto jleave;
818 oqf = savequitflags();
819 if (_acc_curr != NULL)
820 _localopts_unroll(&_acc_curr->ma_localopts);
821 account_name = (mp != NULL) ? mp->ma_name : NULL;
822 _acc_curr = mp;
824 if (mp != NULL && _maexec(mp, &mp->ma_localopts) == CBAD) {
825 /* XXX account switch incomplete, unroll? */
826 fprintf(stderr, tr(520, "Switching to account `%s' failed.\n"), args[0]);
827 goto jleave;
830 if (! starting && ! inhook) {
831 nqf = savequitflags(); /* TODO obsolete (leave -> void -> new box!) */
832 restorequitflags(oqf);
833 if ((i = setfile("%", 0)) < 0)
834 goto jleave;
835 callhook(mailname, 0);
836 if (i > 0 && ! boption("emptystart"))
837 goto jleave;
838 announce(boption("bsdcompat") || boption("bsdannounce"));
839 restorequitflags(nqf);
841 rv = 0;
842 jleave:
843 return rv;
847 c_localopts(void *v)
849 int rv = 1;
850 char **c = v;
852 if (_localopts == NULL) {
853 fprintf(stderr, tr(522,
854 "Cannot use `localopts' but from within a `define' or `account'\n"));
855 goto jleave;
858 _localopts->s_unroll = (**c == '0') ? FAL0 : TRU1;
859 rv = 0;
860 jleave:
861 return rv;
864 /* vim:set fenc=utf-8:s-it-mode */