]> diplodocus.org Git - nmh/blob - sbr/fmt_scan.c
Update the instructions for subscribing to the nmh-workers list
[nmh] / sbr / fmt_scan.c
1
2 /*
3 * fmt_scan.c -- format string interpretation
4 *
5 * $Id$
6 *
7 * This code is Copyright (c) 2002, by the authors of nmh. See the
8 * COPYRIGHT file in the root directory of the nmh distribution for
9 * complete copyright information.
10 */
11
12 #include <h/mh.h>
13 #include <h/addrsbr.h>
14 #include <h/fmt_scan.h>
15 #include <h/tws.h>
16 #include <h/fmt_compile.h>
17
18 #ifdef TIME_WITH_SYS_TIME
19 # include <sys/time.h>
20 # include <time.h>
21 #else
22 # ifdef TM_IN_SYS_TIME
23 # include <sys/time.h>
24 # else
25 # include <time.h>
26 # endif
27 #endif
28
29 #define NFMTS MAXARGS
30
31 extern char *formataddr (); /* hook for custom address formatting */
32
33 #ifdef LBL
34 struct msgs *fmt_current_folder; /* current folder (set by main program) */
35 #endif
36
37 extern int fmt_norm; /* defined in sbr/fmt_def.c = AD_NAME */
38 struct mailname fmt_mnull;
39
40 /*
41 * static prototypes
42 */
43 static int match (char *, char *);
44 static char *get_x400_friendly (char *, char *, int);
45 static int get_x400_comp (char *, char *, char *, int);
46
47
48 /*
49 * test if string "sub" appears anywhere in
50 * string "str" (case insensitive).
51 */
52
53 static int
54 match (char *str, char *sub)
55 {
56 int c1, c2;
57 char *s1, *s2;
58
59 #ifdef LOCALE
60 while ((c1 = *sub)) {
61 c1 = (isalpha(c1) && isupper(c1)) ? tolower(c1) : c1;
62 while ((c2 = *str++) && c1 != ((isalpha(c2) && isupper(c2)) ? tolower(c2) : c2))
63 ;
64 if (! c2)
65 return 0;
66 s1 = sub + 1; s2 = str;
67 while ((c1 = *s1++) && ((isalpha(c1) && isupper(c1)) ? tolower(c1) : c1) == ((isalpha(c2 =*s2++) && isupper(c2)) ? tolower(c2) : c2))
68 ;
69 if (! c1)
70 return 1;
71 }
72 #else
73 while ((c1 = *sub)) {
74 while ((c2 = *str++) && (c1 | 040) != (c2 | 040))
75 ;
76 if (! c2)
77 return 0;
78 s1 = sub + 1; s2 = str;
79 while ((c1 = *s1++) && (c1 | 040) == (*s2++ | 040))
80 ;
81 if (! c1)
82 return 1;
83 }
84 #endif
85 return 1;
86 }
87
88 /*
89 * macros to format data
90 */
91 #define PUTDF(cp, num, wid, fill)\
92 if (cp + wid < ep) {\
93 if ((i = (num)) < 0)\
94 i = -(num);\
95 if ((c = (wid)) < 0)\
96 c = -c;\
97 sp = cp + c;\
98 do {\
99 *--sp = (i % 10) + '0';\
100 i /= 10;\
101 } while (i > 0 && sp > cp);\
102 if (i > 0)\
103 *sp = '?';\
104 else if ((num) < 0 && sp > cp)\
105 *--sp = '-';\
106 while (sp > cp)\
107 *--sp = fill;\
108 cp += c;\
109 }
110
111 #ifdef LOCALE
112 #define PUTSF(cp, str, wid, fill) {\
113 ljust = 0;\
114 if ((i = (wid)) < 0) {\
115 i = -i;\
116 ljust++;\
117 }\
118 if ((sp = (str))) {\
119 if (ljust) {\
120 c = strlen(sp);\
121 if (c > i)\
122 sp += c - i;\
123 else {\
124 while( --i >= c && cp < ep)\
125 *cp++ = fill;\
126 i++;\
127 }\
128 } else {\
129 while ((c = (unsigned char) *sp) && (iscntrl(c) || isspace(c)))\
130 sp++;\
131 }\
132 while ((c = (unsigned char) *sp++) && --i >= 0 && cp < ep)\
133 if (!iscntrl(c) && !isspace(c)) \
134 *cp++ = c;\
135 else {\
136 while ((c = (unsigned char) *sp) && (iscntrl(c) || isspace(c)))\
137 sp++;\
138 *cp++ = ' ';\
139 }\
140 }\
141 if (!ljust)\
142 while( --i >= 0 && cp < ep)\
143 *cp++ = fill;\
144 }
145
146 #define PUTS(cp, str) {\
147 if ((sp = (str))) {\
148 while ((c = (unsigned char) *sp) && (iscntrl(c) || isspace(c)))\
149 sp++;\
150 while((c = (unsigned char) *sp++) && cp < ep)\
151 if (!iscntrl(c) && !isspace(c)) \
152 *cp++ = c;\
153 else {\
154 while ((c = (unsigned char) *sp) && (iscntrl(c) || isspace(c)))\
155 sp++;\
156 *cp++ = ' ';\
157 }\
158 }\
159 }
160
161 #else /* LOCALE */
162 #define PUTSF(cp, str, wid, fill) {\
163 ljust = 0;\
164 if ((i = (wid)) < 0) {\
165 i = -i;\
166 ljust++;\
167 }\
168 if (sp = (str)) {\
169 if (ljust) {\
170 c = strlen(sp);\
171 if (c > i)\
172 sp += c - i;\
173 else {\
174 while( --i >= c && cp < ep)\
175 *cp++ = fill;\
176 i++;\
177 }\
178 } else {\
179 while ((c = *sp) && c <= 32)\
180 sp++;\
181 }\
182 while ((c = *sp++) && --i >= 0 && cp < ep)\
183 if (c > 32) \
184 *cp++ = c;\
185 else {\
186 while ((c = *sp) && c <= 32)\
187 sp++;\
188 *cp++ = ' ';\
189 }\
190 }\
191 if (!ljust)\
192 while( --i >= 0 && cp < ep)\
193 *cp++ = fill;\
194 }
195
196 #define PUTS(cp, str) {\
197 if (sp = (str)) {\
198 while ((c = *sp) && c <= 32)\
199 sp++;\
200 while( (c = *sp++) && cp < ep)\
201 if ( c > 32 ) \
202 *cp++ = c;\
203 else {\
204 while ( (c = *sp) && c <= 32 )\
205 sp++;\
206 *cp++ = ' ';\
207 }\
208 }\
209 }
210
211 #endif /* LOCALE */
212
213
214 static char *lmonth[] = { "January", "February","March", "April",
215 "May", "June", "July", "August",
216 "September","October", "November","December" };
217
218 static char *
219 get_x400_friendly (char *mbox, char *buffer, int buffer_len)
220 {
221 char given[BUFSIZ], surname[BUFSIZ];
222
223 if (mbox == NULL)
224 return NULL;
225 if (*mbox == '"')
226 mbox++;
227 if (*mbox != '/')
228 return NULL;
229
230 if (get_x400_comp (mbox, "/PN=", buffer, buffer_len)) {
231 for (mbox = buffer; (mbox = strchr(mbox, '.')); )
232 *mbox++ = ' ';
233
234 return buffer;
235 }
236
237 if (!get_x400_comp (mbox, "/S=", surname, sizeof(surname)))
238 return NULL;
239
240 if (get_x400_comp (mbox, "/G=", given, sizeof(given)))
241 snprintf (buffer, buffer_len, "%s %s", given, surname);
242 else
243 snprintf (buffer, buffer_len, "%s", surname);
244
245 return buffer;
246 }
247
248 static int
249 get_x400_comp (char *mbox, char *key, char *buffer, int buffer_len)
250 {
251 int idx;
252 char *cp;
253
254 if ((idx = stringdex (key, mbox)) < 0
255 || !(cp = strchr(mbox += idx + strlen (key), '/')))
256 return 0;
257
258 snprintf (buffer, buffer_len, "%*.*s", cp - mbox, cp - mbox, mbox);
259 return 1;
260 }
261
262 struct format *
263 fmt_scan (struct format *format, char *scanl, int width, int *dat)
264 {
265 char *cp, *ep, *sp;
266 char *savestr, *str = NULL;
267 char buffer[BUFSIZ], buffer2[BUFSIZ];
268 int i, c, ljust, n;
269 int value = 0;
270 time_t t;
271 struct format *fmt;
272 struct comp *comp;
273 struct tws *tws;
274 struct mailname *mn;
275
276 cp = scanl;
277 ep = scanl + width - 1;
278
279 for (fmt = format; fmt->f_type != FT_DONE; fmt++)
280 switch (fmt->f_type) {
281 case FT_PARSEADDR:
282 case FT_PARSEDATE:
283 fmt->f_comp->c_flags &= ~CF_PARSED;
284 break;
285 }
286
287 fmt = format;
288
289 while (cp < ep) {
290 switch (fmt->f_type) {
291
292 case FT_COMP:
293 PUTS (cp, fmt->f_comp->c_text);
294 break;
295 case FT_COMPF:
296 PUTSF (cp, fmt->f_comp->c_text, fmt->f_width, fmt->f_fill);
297 break;
298
299 case FT_LIT:
300 sp = fmt->f_text;
301 while( (c = *sp++) && cp < ep)
302 *cp++ = c;
303 break;
304 case FT_LITF:
305 sp = fmt->f_text;
306 ljust = 0;
307 i = fmt->f_width;
308 if (i < 0) {
309 i = -i;
310 ljust++; /* XXX should do something with this */
311 }
312 while( (c = *sp++) && --i >= 0 && cp < ep)
313 *cp++ = c;
314 while( --i >= 0 && cp < ep)
315 *cp++ = fmt->f_fill;
316 break;
317
318 case FT_STR:
319 PUTS (cp, str);
320 break;
321 case FT_STRF:
322 PUTSF (cp, str, fmt->f_width, fmt->f_fill);
323 break;
324 case FT_STRFW:
325 adios (NULL, "internal error (FT_STRFW)");
326
327 case FT_NUM:
328 n = snprintf(cp, ep - cp, "%d", value);
329 if (n >= 0) cp += n;
330 break;
331 case FT_NUMF:
332 PUTDF (cp, value, fmt->f_width, fmt->f_fill);
333 break;
334
335 case FT_CHAR:
336 *cp++ = fmt->f_char;
337 break;
338
339 case FT_DONE:
340 goto finished;
341
342 case FT_IF_S:
343 if (!(value = (str && *str))) {
344 fmt += fmt->f_skip;
345 continue;
346 }
347 break;
348
349 case FT_IF_S_NULL:
350 if (!(value = (str == NULL || *str == 0))) {
351 fmt += fmt->f_skip;
352 continue;
353 }
354 break;
355
356 case FT_IF_V_EQ:
357 if (value != fmt->f_value) {
358 fmt += fmt->f_skip;
359 continue;
360 }
361 break;
362
363 case FT_IF_V_NE:
364 if (value == fmt->f_value) {
365 fmt += fmt->f_skip;
366 continue;
367 }
368 break;
369
370 case FT_IF_V_GT:
371 if (value <= fmt->f_value) {
372 fmt += fmt->f_skip;
373 continue;
374 }
375 break;
376
377 case FT_IF_MATCH:
378 if (!(value = (str && match (str, fmt->f_text)))) {
379 fmt += fmt->f_skip;
380 continue;
381 }
382 break;
383
384 case FT_V_MATCH:
385 if (str)
386 value = match (str, fmt->f_text);
387 else
388 value = 0;
389 break;
390
391 case FT_IF_AMATCH:
392 if (!(value = (str && uprf (str, fmt->f_text)))) {
393 fmt += fmt->f_skip;
394 continue;
395 }
396 break;
397
398 case FT_V_AMATCH:
399 value = uprf (str, fmt->f_text);
400 break;
401
402 case FT_S_NONNULL:
403 value = (str != NULL && *str != 0);
404 break;
405
406 case FT_S_NULL:
407 value = (str == NULL || *str == 0);
408 break;
409
410 case FT_V_EQ:
411 value = (fmt->f_value == value);
412 break;
413
414 case FT_V_NE:
415 value = (fmt->f_value != value);
416 break;
417
418 case FT_V_GT:
419 value = (fmt->f_value > value);
420 break;
421
422 case FT_GOTO:
423 fmt += fmt->f_skip;
424 continue;
425
426 case FT_NOP:
427 break;
428
429 case FT_LS_COMP:
430 str = fmt->f_comp->c_text;
431 break;
432 case FT_LS_LIT:
433 str = fmt->f_text;
434 break;
435 case FT_LS_GETENV:
436 if (!(str = getenv (fmt->f_text)))
437 str = "";
438 break;
439 case FT_LS_CFIND:
440 if (!(str = context_find (fmt->f_text)))
441 str = "";
442 break;
443
444 case FT_LS_DECODECOMP:
445 if (decode_rfc2047(fmt->f_comp->c_text, buffer2))
446 str = buffer2;
447 else
448 str = fmt->f_comp->c_text;
449 break;
450
451 case FT_LS_DECODE:
452 if (str && decode_rfc2047(str, buffer2))
453 str = buffer2;
454 break;
455
456 case FT_LS_TRIM:
457 if (str) {
458 char *xp;
459
460 strncpy(buffer, str, sizeof(buffer));
461 str = buffer;
462 while (isspace(*str))
463 str++;
464 ljust = 0;
465 if ((i = fmt->f_width) < 0) {
466 i = -i;
467 ljust++;
468 }
469
470 if (!ljust && i > 0 && strlen(str) > i)
471 str[i] = '\0';
472 xp = str;
473 xp += strlen(str) - 1;
474 while (xp > str && isspace(*xp))
475 *xp-- = '\0';
476 if (ljust && i > 0 && strlen(str) > i)
477 str += strlen(str) - i;
478 }
479 break;
480
481 case FT_LV_COMPFLAG:
482 value = (fmt->f_comp->c_flags & CF_TRUE) != 0;
483 break;
484 case FT_LV_COMP:
485 value = (comp = fmt->f_comp)->c_text ? atoi(comp->c_text) : 0;
486 break;
487 case FT_LV_LIT:
488 value = fmt->f_value;
489 break;
490 case FT_LV_DAT:
491 value = dat[fmt->f_value];
492 break;
493 case FT_LV_STRLEN:
494 if (str != NULL)
495 value = strlen(str);
496 else
497 value = 0;
498 break;
499 case FT_LV_CHAR_LEFT:
500 value = width - (cp - scanl);
501 break;
502 case FT_LV_PLUS_L:
503 value += fmt->f_value;
504 break;
505 case FT_LV_MINUS_L:
506 value = fmt->f_value - value;
507 break;
508 case FT_LV_DIVIDE_L:
509 if (fmt->f_value)
510 value = value / fmt->f_value;
511 else
512 value = 0;
513 break;
514 case FT_LV_MODULO_L:
515 if (fmt->f_value)
516 value = value % fmt->f_value;
517 else
518 value = 0;
519 break;
520 case FT_SAVESTR:
521 savestr = str;
522 break;
523
524 case FT_LV_SEC:
525 value = fmt->f_comp->c_tws->tw_sec;
526 break;
527 case FT_LV_MIN:
528 value = fmt->f_comp->c_tws->tw_min;
529 break;
530 case FT_LV_HOUR:
531 value = fmt->f_comp->c_tws->tw_hour;
532 break;
533 case FT_LV_MDAY:
534 value = fmt->f_comp->c_tws->tw_mday;
535 break;
536 case FT_LV_MON:
537 value = fmt->f_comp->c_tws->tw_mon + 1;
538 break;
539 case FT_LS_MONTH:
540 str = tw_moty[fmt->f_comp->c_tws->tw_mon];
541 break;
542 case FT_LS_LMONTH:
543 str = lmonth[fmt->f_comp->c_tws->tw_mon];
544 break;
545 case FT_LS_ZONE:
546 str = dtwszone (fmt->f_comp->c_tws);
547 break;
548 case FT_LV_YEAR:
549 value = fmt->f_comp->c_tws->tw_year;
550 break;
551 case FT_LV_WDAY:
552 if (!(((tws = fmt->f_comp->c_tws)->tw_flags) & (TW_SEXP|TW_SIMP)))
553 set_dotw (tws);
554 value = tws->tw_wday;
555 break;
556 case FT_LS_DAY:
557 if (!(((tws = fmt->f_comp->c_tws)->tw_flags) & (TW_SEXP|TW_SIMP)))
558 set_dotw (tws);
559 str = tw_dotw[tws->tw_wday];
560 break;
561 case FT_LS_WEEKDAY:
562 if (!(((tws = fmt->f_comp->c_tws)->tw_flags) & (TW_SEXP|TW_SIMP)))
563 set_dotw (tws);
564 str = tw_ldotw[tws->tw_wday];
565 break;
566 case FT_LV_YDAY:
567 value = fmt->f_comp->c_tws->tw_yday;
568 break;
569 case FT_LV_ZONE:
570 value = fmt->f_comp->c_tws->tw_zone;
571 break;
572 case FT_LV_CLOCK:
573 if ((value = fmt->f_comp->c_tws->tw_clock) == 0)
574 value = dmktime(fmt->f_comp->c_tws);
575 break;
576 case FT_LV_RCLOCK:
577 if ((value = fmt->f_comp->c_tws->tw_clock) == 0)
578 value = dmktime(fmt->f_comp->c_tws);
579 value = time((time_t *) 0) - value;
580 break;
581 case FT_LV_DAYF:
582 if (!(((tws = fmt->f_comp->c_tws)->tw_flags) & (TW_SEXP|TW_SIMP)))
583 set_dotw (tws);
584 switch (fmt->f_comp->c_tws->tw_flags & TW_SDAY) {
585 case TW_SEXP:
586 value = 1; break;
587 case TW_SIMP:
588 value = 0; break;
589 default:
590 value = -1; break;
591 }
592 case FT_LV_ZONEF:
593 if ((fmt->f_comp->c_tws->tw_flags & TW_SZONE) == TW_SZEXP)
594 value = 1;
595 else
596 value = -1;
597 break;
598 case FT_LV_DST:
599 value = fmt->f_comp->c_tws->tw_flags & TW_DST;
600 break;
601 case FT_LS_822DATE:
602 str = dasctime (fmt->f_comp->c_tws , TW_ZONE);
603 break;
604 case FT_LS_PRETTY:
605 str = dasctime (fmt->f_comp->c_tws, TW_NULL);
606 break;
607
608 case FT_LS_PERS:
609 str = fmt->f_comp->c_mn->m_pers;
610 break;
611 case FT_LS_MBOX:
612 str = fmt->f_comp->c_mn->m_mbox;
613 break;
614 case FT_LS_HOST:
615 str = fmt->f_comp->c_mn->m_host;
616 break;
617 case FT_LS_PATH:
618 str = fmt->f_comp->c_mn->m_path;
619 break;
620 case FT_LS_GNAME:
621 str = fmt->f_comp->c_mn->m_gname;
622 break;
623 case FT_LS_NOTE:
624 str = fmt->f_comp->c_mn->m_note;
625 break;
626 case FT_LS_822ADDR:
627 str = adrformat( fmt->f_comp->c_mn );
628 break;
629 case FT_LV_HOSTTYPE:
630 value = fmt->f_comp->c_mn->m_type;
631 break;
632 case FT_LV_INGRPF:
633 value = fmt->f_comp->c_mn->m_ingrp;
634 break;
635 case FT_LV_NOHOSTF:
636 value = fmt->f_comp->c_mn->m_nohost;
637 break;
638 case FT_LS_ADDR:
639 case FT_LS_FRIENDLY:
640 if ((mn = fmt->f_comp->c_mn) == &fmt_mnull) {
641 str = fmt->f_comp->c_text;
642 break;
643 }
644 if (fmt->f_type == FT_LS_ADDR)
645 goto unfriendly;
646 if ((str = mn->m_pers) == NULL) {
647 if ((str = mn->m_note)) {
648 strncpy (buffer, str, sizeof(buffer));
649 str = buffer;
650 if (*str == '(')
651 str++;
652 sp = str + strlen(str) - 1;
653 if (*sp == ')') {
654 *sp-- = '\0';
655 while (sp >= str)
656 if (*sp == ' ')
657 *sp-- = '\0';
658 else
659 break;
660 }
661 } else if (!(str = get_x400_friendly (mn->m_mbox,
662 buffer, sizeof(buffer)))) {
663 unfriendly: ;
664 switch (mn->m_type) {
665 case LOCALHOST:
666 str = mn->m_mbox;
667 break;
668 case UUCPHOST:
669 snprintf (buffer, sizeof(buffer), "%s!%s",
670 mn->m_host, mn->m_mbox);
671 str = buffer;
672 break;
673 default:
674 if (mn->m_mbox) {
675 snprintf (buffer, sizeof(buffer), "%s@%s",
676 mn->m_mbox, mn->m_host);
677 str= buffer;
678 }
679 else
680 str = mn->m_text;
681 break;
682 }
683 }
684 }
685 break;
686
687
688 /* UNQUOTEs RFC-2822 quoted-string and quoted-pair */
689 case FT_LS_UNQUOTE:
690 if (str) {
691 int m;
692 strncpy(buffer, str, sizeof(buffer));
693 str = buffer;
694
695 /* we will parse from buffer to buffer2 */
696 n = 0; /* n is the input position in str */
697 m = 0; /* m is the ouput position in buffer2 */
698
699 while ( str[n] != '\0') {
700 switch ( str[n] ) {
701 case '\\':
702 n++;
703 if ( str[n] != '\0')
704 buffer2[m++] = str[n++];
705 break;
706 case '"':
707 n++;
708 break;
709 default:
710 buffer2[m++] = str[n++];
711 break;
712 }
713 }
714 buffer2[m] = '\0';
715 str = buffer2;
716 }
717 break;
718
719 case FT_LOCALDATE:
720 comp = fmt->f_comp;
721 if ((t = comp->c_tws->tw_clock) == 0)
722 t = dmktime(comp->c_tws);
723 tws = dlocaltime(&t);
724 *comp->c_tws = *tws;
725 break;
726
727 case FT_GMTDATE:
728 comp = fmt->f_comp;
729 if ((t = comp->c_tws->tw_clock) == 0)
730 t = dmktime(comp->c_tws);
731 tws = dgmtime(&t);
732 *comp->c_tws = *tws;
733 break;
734
735 case FT_PARSEDATE:
736 comp = fmt->f_comp;
737 if (comp->c_flags & CF_PARSED)
738 break;
739 if ((sp = comp->c_text) && (tws = dparsetime(sp))) {
740 *comp->c_tws = *tws;
741 comp->c_flags &= ~CF_TRUE;
742 } else if ((comp->c_flags & CF_DATEFAB) == 0) {
743 memset ((char *) comp->c_tws, 0, sizeof *comp->c_tws);
744 comp->c_flags = CF_TRUE;
745 }
746 comp->c_flags |= CF_PARSED;
747 break;
748
749 case FT_FORMATADDR:
750 /* hook for custom address list formatting (see replsbr.c) */
751 str = formataddr (savestr, str);
752 break;
753
754 case FT_PUTADDR:
755 /* output the str register as an address component,
756 * splitting it into multiple lines if necessary. The
757 * value reg. contains the max line length. The lit.
758 * field may contain a string to prepend to the result
759 * (e.g., "To: ")
760 */
761 {
762 char *lp, *lastb;
763 int indent, wid, len;
764
765 lp = str;
766 wid = value;
767 len = strlen (str);
768 sp = fmt->f_text;
769 indent = strlen (sp);
770 wid -= indent;
771 while( (c = *sp++) && cp < ep)
772 *cp++ = c;
773 while (len > wid) {
774 /* try to break at a comma; failing that, break at a
775 * space.
776 */
777 lastb = 0; sp = lp + wid;
778 while (sp > lp && (c = *--sp) != ',') {
779 if (! lastb && isspace(c))
780 lastb = sp - 1;
781 }
782 if (sp == lp) {
783 if (! (sp = lastb)) {
784 sp = lp + wid - 1;
785 while (*sp && *sp != ',' && !isspace(*sp))
786 sp++;
787 if (*sp != ',')
788 sp--;
789 }
790 }
791 len -= sp - lp + 1;
792 while (cp < ep && lp <= sp)
793 *cp++ = *lp++;
794 while (isspace(*lp))
795 lp++, len--;
796 if (*lp) {
797 if (cp < ep)
798 *cp++ = '\n';
799 for (i=indent; cp < ep && i > 0; i--)
800 *cp++ = ' ';
801 }
802 }
803 PUTS (cp, lp);
804 }
805 break;
806
807 case FT_PARSEADDR:
808 comp = fmt->f_comp;
809 if (comp->c_flags & CF_PARSED)
810 break;
811 if (comp->c_mn != &fmt_mnull)
812 mnfree (comp->c_mn);
813 if ((sp = comp->c_text) && (sp = getname(sp)) &&
814 (mn = getm (sp, NULL, 0, fmt_norm, NULL))) {
815 comp->c_mn = mn;
816 while (getname(""))
817 ;
818 comp->c_flags |= CF_PARSED;
819 } else {
820 while (getname("")) /* XXX */
821 ;
822 comp->c_mn = &fmt_mnull;
823 }
824 break;
825
826 case FT_MYMBOX:
827 /*
828 * if there's no component, we say true. Otherwise we
829 * say "true" only if we can parse the address and it
830 * matches one of our addresses.
831 */
832 comp = fmt->f_comp;
833 if (comp->c_mn != &fmt_mnull)
834 mnfree (comp->c_mn);
835 if ((sp = comp->c_text) && (sp = getname(sp)) &&
836 (mn = getm (sp, NULL, 0, AD_NAME, NULL))) {
837 comp->c_mn = mn;
838 if (ismymbox(mn))
839 comp->c_flags |= CF_TRUE;
840 else
841 comp->c_flags &= ~CF_TRUE;
842 while ((sp = getname(sp)))
843 if ((comp->c_flags & CF_TRUE) == 0 &&
844 (mn = getm (sp, NULL, 0, AD_NAME, NULL)))
845 if (ismymbox(mn))
846 comp->c_flags |= CF_TRUE;
847 } else {
848 while (getname("")) /* XXX */
849 ;
850 if (comp->c_text == 0)
851 comp->c_flags |= CF_TRUE;
852 else
853 comp->c_flags &= ~CF_TRUE;
854 comp->c_mn = &fmt_mnull;
855 }
856 break;
857
858 case FT_ADDTOSEQ:
859 #ifdef LBL
860 /* If we're working on a folder (as opposed to a file), add the
861 * current msg to sequence given in literal field. Don't
862 * disturb string or value registers.
863 */
864 if (fmt_current_folder)
865 seq_addmsg(fmt_current_folder, fmt->f_text, dat[0], -1);
866 #endif
867 break;
868 }
869 fmt++;
870 }
871 #ifndef JLR
872 finished:;
873 if (cp[-1] != '\n')
874 *cp++ = '\n';
875 *cp = 0;
876 return ((struct format *)0);
877 #else /* JLR */
878 if (cp[-1] != '\n')
879 *cp++ = '\n';
880 while (fmt->f_type != FT_DONE)
881 fmt++;
882
883 finished:;
884 *cp = '\0';
885 return (fmt->f_value ? ++fmt : (struct format *) 0);
886
887 #endif /* JLR */
888 }