]>
diplodocus.org Git - nmh/blob - uip/fmttest.c
3 * fmttest.c -- A program to help test and debug format instructions
5 * This code is Copyright (c) 2012, by the authors of nmh. See the
6 * COPYRIGHT file in the root directory of the nmh distribution for
7 * complete copyright information.
11 #include <h/fmt_scan.h>
12 #include <h/fmt_compile.h>
14 #include <h/scansbr.h>
15 #include <h/addrsbr.h>
17 #define FMTTEST_SWITCHES \
18 X("form formatfile", 0, FORMSW) \
19 X("format string", 5, FMTSW) \
20 X("address", 0, ADDRSW) \
22 X("date", 0, DATESW) \
23 X("message", 0, MESSAGESW) \
24 X("-component-name component-text", 0, OTHERSW) \
25 X("dupaddrs", 0, DUPADDRSW) \
26 X("nodupaddrs", 0, NDUPADDRSW) \
27 X("ccme", 0, CCMESW) \
28 X("noccme", 0, NCCMESW) \
29 X("normalize", 0, NORMSW) \
30 X("nonormalize", 0, NNORMSW) \
31 X("outsize size-in-characters", 0, OUTSIZESW) \
32 X("bufsize size-in-bytes", 0, BUFSZSW) \
33 X("width column-width", 0, WIDTHSW) \
34 X("msgnum number", 0, MSGNUMSW) \
35 X("msgcur flag", 0, MSGCURSW) \
36 X("msgsize size", 0, MSGSIZESW) \
37 X("unseen flag", 0, UNSEENSW) \
38 X("dump", 0, DUMPSW) \
39 X("nodump", 0, NDUMPSW) \
40 X("trace", 0, TRACESW) \
41 X("notrace", 0, NTRACESW) \
42 X("version", 0, VERSIONSW) \
43 X("help", 0, HELPSW) \
45 #define X(sw, minchars, id) id,
46 DEFINE_SWITCH_ENUM(FMTTEST
);
49 #define X(sw, minchars, id) { sw, minchars, id },
50 DEFINE_SWITCH_ARRAY(FMTTEST
, switches
);
54 * An array containing labels used for branch instructions
57 static struct format
**lvec
= NULL
;
59 static int lallocated
= 0;
61 enum mode_t
{ MESSAGE
, ADDRESS
, RAW
};
62 #define DEFADDRFORMAT "%<{error}%{error}: %{text}%|%(putstr(proper{text}))%>"
63 #define DEFDATEFORMAT "%<(nodate{text})error: %{text}%|%(putstr(pretty{text}))%>"
66 * Context structure used by the tracing routines
69 struct trace_context
{
78 static void fmt_dump (char *, struct format
*);
79 static void dumpone(struct format
*);
80 static void initlabels(struct format
*);
81 static int findlabel(struct format
*);
82 static void assignlabel(struct format
*);
83 static char *f_typestr(int);
84 static char *c_typestr(int);
85 static char *c_flagsstr(int);
86 static void litputs(char *);
87 static void litputc(char);
88 static void process_addresses(struct format
*, struct msgs_array
*, char *,
89 int, int, int *, int, struct fmt_callbacks
*);
90 static void process_raw(struct format
*, struct msgs_array
*, char *,
91 int, int, int *, struct fmt_callbacks
*);
92 static void process_messages(struct format
*, struct msgs_array
*,
93 struct msgs_array
*, char *, char *, int,
94 int, int *, struct fmt_callbacks
*);
95 static void test_trace(void *, struct format
*, int, char *, char *);
96 static char *test_formataddr(char *, char *);
97 static char *test_concataddr(char *, char *);
98 static int insert(struct mailname
*);
99 static void mlistfree(void);
101 static int nodupcheck
= 0; /* If set, no check for duplicates */
102 static int ccme
= 0; /* Should I cc myself? */
103 static struct mailname mq
; /* Mail addresses to check for duplicates */
104 static char *dummy
= "dummy";
107 main (int argc
, char **argv
)
109 char *cp
, *form
= NULL
, *format
= NULL
, *defformat
= FORMAT
, *folder
= NULL
;
110 char buf
[BUFSIZ
], *nfs
, **argp
, **arguments
, *buffer
;
113 struct msgs_array msgs
= { 0, 0, NULL
}, compargs
= { 0, 0, NULL
};
115 int outputsize
= 0, bufsize
= 0, dupaddrs
= 1, trace
= 0;
116 int colwidth
= -1, msgnum
= -1, msgcur
= -1, msgsize
= -1, msgunseen
= -1;
117 int normalize
= AD_HOST
;
118 enum mode_t mode
= MESSAGE
;
120 struct fmt_callbacks cb
, *cbp
= NULL
;
123 setlocale(LC_ALL
, "");
125 invo_name
= r1bindex (argv
[0], '/');
127 /* read user profile/context */
130 arguments
= getarguments (invo_name
, argc
, argv
, 1);
133 while ((cp
= *argp
++)) {
136 * A -- means that we have a component name (like pick);
137 * save the component name and the next argument for the text.
141 adios(NULL
, "missing component name after --");
142 app_msgarg(&compargs
, cp
);
143 /* Grab next argument for component text */
145 adios(NULL
, "missing argument to %s", argp
[-2]);
146 app_msgarg(&compargs
, cp
);
149 switch (smatch (cp
, switches
)) {
151 ambigsw (cp
, switches
);
154 adios (NULL
, "-%s unknown", cp
);
157 snprintf (buf
, sizeof(buf
), "%s [switches]", invo_name
);
158 print_help (buf
, switches
, 1);
161 print_version(invo_name
);
164 adios(NULL
, "internal argument error!");
168 if (!(cp
= *argp
++) || *cp
== '-')
169 adios(NULL
, "missing argument to %s", argp
[-2]);
170 if (strcmp(cp
, "max") == 0)
172 else if (strcmp(cp
, "width") == 0)
173 outputsize
= sc_width();
175 outputsize
= atoi(cp
);
178 if (!(cp
= *argp
++) || *cp
== '-')
179 adios(NULL
, "missing argument to %s", argp
[-2]);
184 if (!(form
= *argp
++) || *form
== '-')
185 adios (NULL
, "missing argument to %s", argp
[-2]);
189 if (!(format
= *argp
++) || *format
== '-')
190 adios (NULL
, "missing argument to %s", argp
[-2]);
210 defformat
= DEFADDRFORMAT
;
222 defformat
= DEFDATEFORMAT
;
240 if (!(cp
= *argp
++) || *cp
== '-')
241 adios(NULL
, "missing argument to %s", argp
[-2]);
245 if (!(cp
= *argp
++) || *cp
== '-')
246 adios(NULL
, "missing argument to %s", argp
[-2]);
250 if (!(cp
= *argp
++) || *cp
== '-')
251 adios(NULL
, "missing argument to %s", argp
[-2]);
255 if (!(cp
= *argp
++) || *cp
== '-')
256 adios(NULL
, "missing argument to %s", argp
[-2]);
260 if (!(cp
= *argp
++) || *cp
== '-')
261 adios(NULL
, "missing argument to %s", argp
[-2]);
262 msgunseen
= atoi(cp
);
276 * Only interpret as a folder if we're in message mode
279 if (mode
== MESSAGE
&& (*cp
== '+' || *cp
== '@')) {
281 adios (NULL
, "only one folder at a time!");
283 folder
= pluspath (cp
);
285 app_msgarg(&msgs
, cp
);
289 * Here's our weird heuristic:
291 * - We allow -dump without any other arguments.
292 * - If you've given any component arguments, we don't require any
294 * - The arguments are interpreted as folders/messages _if_ we're in
295 * message mode, otherwise pass as strings in the text component.
298 if (!dump
&& compargs
.size
== 0 && msgs
.size
== 0) {
299 adios (NULL
, "usage: [switches] [+folder] msgs | strings...",
304 * If you're picking "raw" as a mode, then you have to select
308 if (mode
== RAW
&& form
== NULL
&& format
== NULL
) {
309 adios (NULL
, "You must specify a format with -form or -format when "
314 * Get new format string. Must be before chdir().
316 nfs
= new_fs (form
, format
, defformat
);
317 (void) fmt_compile(nfs
, &fmt
, 1);
323 if (compargs
.size
== 0 && msgs
.size
== 0)
329 * If we don't specify a buffer size, allocate a default one.
335 buffer
= mh_xmalloc(bufsize
);
338 outputsize
= bufsize
- 1; /* For the trailing NUL */
339 else if (outputsize
== 0) {
341 outputsize
= sc_width();
343 outputsize
= bufsize
- 1;
349 dat
[3] = colwidth
== -1 ? outputsize
: colwidth
;
353 * If we want to provide our own formataddr, concactaddr, or tracing
354 * callback, do that now. Also, prime ismymbox if we use it.
357 if (dupaddrs
== 0 || trace
) {
358 memset(&cb
, 0, sizeof(cb
));
362 cb
.formataddr
= test_formataddr
;
363 cb
.concataddr
= test_concataddr
;
369 struct trace_context
*ctx
;
371 ctx
= mh_xmalloc(sizeof(*ctx
));
374 ctx
->outbuf
= getcpy(NULL
);
376 cb
.trace_func
= test_trace
;
377 cb
.trace_context
= ctx
;
381 if (mode
== MESSAGE
) {
382 process_messages(fmt
, &compargs
, &msgs
, buffer
, folder
, bufsize
,
383 outputsize
, dat
, cbp
);
386 for (i
= 0; i
< compargs
.size
; i
+= 2) {
387 cptr
= fmt_findcomp(compargs
.msgs
[i
]);
389 cptr
->c_text
= getcpy(compargs
.msgs
[i
+ 1]);
393 if (mode
== ADDRESS
) {
394 fmt_norm
= normalize
;
395 process_addresses(fmt
, &msgs
, buffer
, bufsize
, outputsize
,
396 dat
, normalize
, cbp
);
398 process_raw(fmt
, &msgs
, buffer
, bufsize
, outputsize
, dat
, cbp
);
408 * Process each address with fmt_scan().
414 struct pqpair
*pq_next
;
418 process_addresses(struct format
*fmt
, struct msgs_array
*addrs
, char *buffer
,
419 int bufsize
, int outwidth
, int *dat
, int norm
,
420 struct fmt_callbacks
*cb
)
423 char *cp
, error
[BUFSIZ
];
425 struct pqpair
*p
, *q
;
438 for (i
= 0; i
< addrs
->size
; i
++) {
439 (q
= &pq
)->pq_next
= NULL
;
440 while ((cp
= getname(addrs
->msgs
[i
]))) {
441 if ((p
= (struct pqpair
*) calloc ((size_t) 1, sizeof(*p
))) == NULL
)
442 adios (NULL
, "unable to allocate pqpair memory");
443 if ((mp
= getm(cp
, NULL
, 0, norm
, error
)) == NULL
) {
444 p
->pq_text
= getcpy(cp
);
445 p
->pq_error
= getcpy(error
);
447 p
->pq_text
= getcpy(mp
->m_text
);
450 q
= (q
->pq_next
= p
);
453 for (p
= pq
.pq_next
; p
; p
= q
) {
454 c
= fmt_findcomp("text");
458 c
->c_text
= p
->pq_text
;
461 c
= fmt_findcomp("error");
465 c
->c_text
= p
->pq_error
;
469 fmt_scan(fmt
, buffer
, bufsize
, outwidth
, dat
, cb
);
470 fputs(buffer
, stdout
);
484 * Process messages and run them through the format engine. A lot taken
489 process_messages(struct format
*fmt
, struct msgs_array
*comps
,
490 struct msgs_array
*msgs
, char *buffer
, char *folder
,
491 int bufsize
, int outwidth
, int *dat
, struct fmt_callbacks
*cb
)
493 int i
, state
, msgnum
, msgsize
= dat
[2], num
= dat
[0], cur
= dat
[1];
494 int num_unseen_seq
= 0, seqnum
[NUMATTRS
];
495 char *maildir
, *cp
, name
[NAMESZ
], rbuf
[BUFSIZ
];
499 m_getfld_state_t gstate
= 0;
503 folder
= getfolder(1);
505 maildir
= m_maildir(folder
);
507 if (chdir(maildir
) < 0)
508 adios(maildir
, "unable to change directory to");
510 if (!(mp
= folder_read(folder
, 1)))
511 adios(NULL
, "unable to read folder %s", folder
);
514 adios(NULL
, "no messages in %s", folder
);
516 for (i
= 0; i
< msgs
->size
; i
++)
517 if (!m_convert(mp
, msgs
->msgs
[i
]))
519 seq_setprev(mp
); /* set the Previous-Sequence */
521 context_replace(pfolder
, folder
); /* update curren folder */
522 seq_save(mp
); /* synchronize message sequences */
523 context_save(); /* save the context file */
526 * We want to set the unseen flag if requested, so we have to check
527 * the unseen sequence as well.
531 if ((cp
= context_find(usequence
)) && *cp
) {
535 ap
= brkstring(dp
, " ", "\n");
536 for (i
= 0; ap
&& *ap
; i
++, ap
++)
537 seqnum
[i
] = seq_getnum(mp
, *ap
);
545 for (msgnum
= mp
->lowsel
; msgnum
<= mp
->hghsel
; msgnum
++) {
546 if (is_selected(mp
, msgnum
)) {
547 if ((in
= fopen(cp
= m_name(msgnum
), "r")) == NULL
) {
548 admonish(cp
, "unable to open message");
558 dat
[1] = msgnum
== mp
->curmsg
;
561 * Get our size if we didn't include one
567 if (fstat(fileno(in
), &st
) < 0)
574 * Check to see if this is in the unseen sequence
578 for (i
= 0; i
< num_unseen_seq
; i
++) {
579 if (in_sequence(mp
, seqnum
[i
], msgnum
)) {
586 * Read in the message and process the components
589 for (state
= FLD
;;) {
590 bufsz
= sizeof(rbuf
);
591 state
= m_getfld(&gstate
, name
, rbuf
, &bufsz
, in
);
595 i
= fmt_addcomptext(name
, rbuf
);
597 while (state
== FLDPLUS
) {
598 bufsz
= sizeof(rbuf
);
599 state
= m_getfld(&gstate
, name
, rbuf
, &bufsz
, in
);
600 fmt_appendcomp(i
, name
, rbuf
);
604 while (state
== FLDPLUS
) {
605 bufsz
= sizeof(rbuf
);
606 state
= m_getfld(&gstate
, name
, rbuf
, &bufsz
, in
);
611 if (fmt_findcomp("body")) {
612 if ((i
= strlen(rbuf
)) < outwidth
) {
613 bufsz
= outwidth
- 1;
614 state
= m_getfld(&gstate
, name
, rbuf
+ i
,
618 fmt_addcomptext("body", rbuf
);
628 m_getfld_state_destroy(&gstate
);
631 * Do this now to override any components in the original message
634 for (i
= 0; i
< comps
->size
; i
+= 2) {
635 c
= fmt_findcomp(comps
->msgs
[i
]);
639 c
->c_text
= getcpy(comps
->msgs
[i
+ 1]);
643 fmt_scan(fmt
, buffer
, bufsize
, outwidth
, dat
, cb
);
644 fputs(buffer
, stdout
);
654 * Run text through the format engine with no special processing
658 process_raw(struct format
*fmt
, struct msgs_array
*text
, char *buffer
,
659 int bufsize
, int outwidth
, int *dat
, struct fmt_callbacks
*cb
)
673 c
= fmt_findcomp("text");
675 for (i
= 0; i
< text
->size
; i
++) {
677 if (c
->c_text
!= NULL
)
679 c
->c_text
= getcpy(text
->msgs
[i
]);
682 fmt_scan(fmt
, buffer
, bufsize
, outwidth
, dat
, cb
);
683 fputs(buffer
, stdout
);
689 * Our basic tracing support callback.
691 * Print out each instruction as it's executed, including the values of
692 * the num and str registers if they've changed.
696 test_trace(void *context
, struct format
*fmt
, int num
, char *str
, char *outbuf
)
698 struct trace_context
*ctx
= (struct trace_context
*) context
;
703 if (num
!= ctx
->num
) {
704 printf("num=%d", num
);
709 if (str
!= ctx
->str
) {
712 printf("str=\"%s\"", str
? str
: "NULL");
719 if (strcmp(outbuf
, ctx
->outbuf
) != 0) {
720 printf("outbuf=\"%s\"\n", outbuf
);
722 ctx
->outbuf
= getcpy(outbuf
);
727 fmt_dump (char *nfs
, struct format
*fmth
)
731 printf("Instruction dump of format string: \n%s\n", nfs
);
734 for (fmt
= fmth
; fmt
; ++fmt
) {
736 if (fmt
->f_type
== FT_DONE
&& fmt
->f_value
== 0)
742 dumpone(struct format
*fmt
)
746 if ((i
= findlabel(fmt
)) >= 0)
750 fputs(f_typestr((int)fmt
->f_type
), stdout
);
752 switch (fmt
->f_type
) {
759 litputs(fmt
->f_comp
->c_name
);
760 if (fmt
->f_comp
->c_type
)
761 printf(", c_type %s", c_typestr(fmt
->f_comp
->c_type
));
762 if (fmt
->f_comp
->c_flags
)
763 printf(", c_flags %s", c_flagsstr(fmt
->f_comp
->c_flags
));
791 litputs(fmt
->f_comp
->c_name
);
792 if (fmt
->f_comp
->c_type
)
793 printf(", c_type %s", c_typestr(fmt
->f_comp
->c_type
));
794 if (fmt
->f_comp
->c_flags
)
795 printf(", c_flags %s", c_flagsstr(fmt
->f_comp
->c_flags
));
813 litputs(fmt
->f_comp
->c_name
);
814 if (fmt
->f_comp
->c_type
)
815 printf(", c_type %s", c_typestr(fmt
->f_comp
->c_type
));
816 if (fmt
->f_comp
->c_flags
)
817 printf(", c_flags %s", c_flagsstr(fmt
->f_comp
->c_flags
));
821 printf(", width %d, fill '", fmt
->f_width
);
822 litputc(fmt
->f_fill
);
824 litputs(fmt
->f_comp
->c_name
);
825 if (fmt
->f_comp
->c_type
)
826 printf(", c_type %s", c_typestr(fmt
->f_comp
->c_type
));
827 if (fmt
->f_comp
->c_flags
)
828 printf(", c_flags %s", c_flagsstr(fmt
->f_comp
->c_flags
));
833 printf(", width %d, fill '", fmt
->f_width
);
834 litputc(fmt
->f_fill
);
843 litputs(fmt
->f_text
);
847 printf(", width %d, fill '", fmt
->f_width
);
848 litputc(fmt
->f_fill
);
850 litputs(fmt
->f_text
);
856 litputc(fmt
->f_char
);
865 printf(" continue else goto");
867 i
= findlabel(fmt
+ fmt
->f_skip
);
874 i
= findlabel(fmt
+ fmt
->f_skip
);
875 printf(" %d continue else goto L%d", fmt
->f_value
, i
);
886 printf(" value %d", fmt
->f_value
);
891 litputs(fmt
->f_text
);
896 litputs(fmt
->f_text
);
899 case FT_LS_DECODECOMP
:
901 litputs(fmt
->f_comp
->c_name
);
908 printf(", width %d", fmt
->f_width
);
912 printf(", value dat[%d]", fmt
->f_value
);
919 * Iterate over all instructions and assign labels to the targets of
924 initlabels(struct format
*fmth
)
926 struct format
*fmt
, *addr
;
930 for (fmt
= fmth
; fmt
; ++fmt
) {
940 addr
= fmt
+ fmt
->f_skip
;
941 if (findlabel(addr
) < 0)
944 if (fmt
->f_type
== FT_DONE
&& fmt
->f_value
== 0)
951 findlabel(struct format
*addr
)
955 for (i
= 0; i
< lused
; ++i
)
962 assignlabel(struct format
*addr
)
964 if (lused
>= lallocated
) {
966 lvec
= (struct format
**)
967 mh_xrealloc(lvec
, sizeof(struct format
*) * lallocated
);
970 lvec
[lused
++] = addr
;
979 case FT_COMP
: return("COMP");
980 case FT_COMPF
: return("COMPF");
981 case FT_LIT
: return("LIT");
982 case FT_LITF
: return("LITF");
984 case FT_LIT_FORCE
: return("LIT_FORCE");
986 case FT_CHAR
: return("CHAR");
987 case FT_NUM
: return("NUM");
988 case FT_NUMF
: return("NUMF");
989 case FT_STR
: return("STR");
990 case FT_STRF
: return("STRF");
991 case FT_STRFW
: return("STRFW");
992 case FT_PUTADDR
: return("PUTADDR");
993 case FT_STRLIT
: return("STRLIT");
994 case FT_STRLITZ
: return("STRLITZ");
995 case FT_LS_COMP
: return("LS_COMP");
996 case FT_LS_LIT
: return("LS_LIT");
997 case FT_LS_GETENV
: return("LS_GETENV");
998 case FT_LS_DECODECOMP
: return("LS_DECODECOMP");
999 case FT_LS_DECODE
: return("LS_DECODE");
1000 case FT_LS_TRIM
: return("LS_TRIM");
1001 case FT_LV_COMP
: return("LV_COMP");
1002 case FT_LV_COMPFLAG
: return("LV_COMPFLAG");
1003 case FT_LV_LIT
: return("LV_LIT");
1004 case FT_LV_DAT
: return("LV_DAT");
1005 case FT_LV_STRLEN
: return("LV_STRLEN");
1006 case FT_LV_PLUS_L
: return("LV_PLUS_L");
1007 case FT_LV_MINUS_L
: return("LV_MINUS_L");
1008 case FT_LV_DIVIDE_L
: return("LV_DIVIDE_L");
1009 case FT_LV_MODULO_L
: return("LV_MODULO_L");
1010 case FT_LV_CHAR_LEFT
: return("LV_CHAR_LEFT");
1011 case FT_LS_MONTH
: return("LS_MONTH");
1012 case FT_LS_LMONTH
: return("LS_LMONTH");
1013 case FT_LS_ZONE
: return("LS_ZONE");
1014 case FT_LS_DAY
: return("LS_DAY");
1015 case FT_LS_WEEKDAY
: return("LS_WEEKDAY");
1016 case FT_LS_822DATE
: return("LS_822DATE");
1017 case FT_LS_PRETTY
: return("LS_PRETTY");
1018 case FT_LV_SEC
: return("LV_SEC");
1019 case FT_LV_MIN
: return("LV_MIN");
1020 case FT_LV_HOUR
: return("LV_HOUR");
1021 case FT_LV_MDAY
: return("LV_MDAY");
1022 case FT_LV_MON
: return("LV_MON");
1023 case FT_LV_YEAR
: return("LV_YEAR");
1024 case FT_LV_YDAY
: return("LV_YDAY");
1025 case FT_LV_WDAY
: return("LV_WDAY");
1026 case FT_LV_ZONE
: return("LV_ZONE");
1027 case FT_LV_CLOCK
: return("LV_CLOCK");
1028 case FT_LV_RCLOCK
: return("LV_RCLOCK");
1029 case FT_LV_DAYF
: return("LV_DAYF");
1030 case FT_LV_DST
: return("LV_DST");
1031 case FT_LV_ZONEF
: return("LV_ZONEF");
1032 case FT_LS_ADDR
: return("LS_ADDR");
1033 case FT_LS_PERS
: return("LS_PERS");
1034 case FT_LS_MBOX
: return("LS_MBOX");
1035 case FT_LS_HOST
: return("LS_HOST");
1036 case FT_LS_PATH
: return("LS_PATH");
1037 case FT_LS_GNAME
: return("LS_GNAME");
1038 case FT_LS_NOTE
: return("LS_NOTE");
1039 case FT_LS_822ADDR
: return("LS_822ADDR");
1040 case FT_LS_FRIENDLY
: return("LS_FRIENDLY");
1041 case FT_LV_HOSTTYPE
: return("LV_HOSTTYPE");
1042 case FT_LV_INGRPF
: return("LV_INGRPF");
1043 case FT_LS_UNQUOTE
: return("LS_UNQUOTE");
1044 case FT_LV_NOHOSTF
: return("LV_NOHOSTF");
1045 case FT_LOCALDATE
: return("LOCALDATE");
1046 case FT_GMTDATE
: return("GMTDATE");
1047 case FT_PARSEDATE
: return("PARSEDATE");
1048 case FT_PARSEADDR
: return("PARSEADDR");
1049 case FT_FORMATADDR
: return("FORMATADDR");
1050 case FT_CONCATADDR
: return("CONCATADDR");
1051 case FT_MYMBOX
: return("MYMBOX");
1053 case FT_ADDTOSEQ
: return("ADDTOSEQ");
1055 case FT_SAVESTR
: return("SAVESTR");
1057 case FT_PAUSE
: return ("PAUSE");
1059 case FT_DONE
: return("DONE");
1060 case FT_NOP
: return("NOP");
1061 case FT_GOTO
: return("GOTO");
1062 case FT_IF_S_NULL
: return("IF_S_NULL");
1063 case FT_IF_S
: return("IF_S");
1064 case FT_IF_V_EQ
: return("IF_V_EQ");
1065 case FT_IF_V_NE
: return("IF_V_NE");
1066 case FT_IF_V_GT
: return("IF_V_GT");
1067 case FT_IF_MATCH
: return("IF_MATCH");
1068 case FT_IF_AMATCH
: return("IF_AMATCH");
1069 case FT_S_NULL
: return("S_NULL");
1070 case FT_S_NONNULL
: return("S_NONNULL");
1071 case FT_V_EQ
: return("V_EQ");
1072 case FT_V_NE
: return("V_NE");
1073 case FT_V_GT
: return("V_GT");
1074 case FT_V_MATCH
: return("V_MATCH");
1075 case FT_V_AMATCH
: return("V_AMATCH");
1077 snprintf(buf
, sizeof(buf
), "/* ??? #%d */", t
);
1082 #define FNORD(v, s) if (t & (v)) { \
1091 static char buf
[64];
1094 if (t
& ~(CT_ADDR
|CT_DATE
))
1095 printf(buf
, "0x%x ", t
);
1098 FNORD(CT_ADDR
, "ADDR");
1099 FNORD(CT_DATE
, "DATE");
1108 static char buf
[64];
1111 if (t
& ~(CF_TRUE
|CF_PARSED
|CF_DATEFAB
|CF_TRIMMED
))
1112 printf(buf
, "0x%x ", t
);
1115 FNORD(CF_TRUE
, "TRUE");
1116 FNORD(CF_PARSED
, "PARSED");
1117 FNORD(CF_DATEFAB
, "DATEFAB");
1118 FNORD(CF_TRIMMED
, "TRIMMED");
1133 fputs("<nil>", stdout
);
1144 if (c
< 0x20 || c
== 0177) {
1148 } else if (c
== '\f') {
1151 } else if (c
== '\n') {
1154 } else if (c
== '\r') {
1157 } else if (c
== '\t') {
1162 putc(c
^ 0x40, stdout
); /* DEL to ?, others to alpha */
1169 * Routines/code to support the duplicate address suppression code, adapted
1173 static char *buf
; /* our current working buffer */
1174 static char *bufend
; /* end of working buffer */
1175 static char *last_dst
; /* buf ptr at end of last call */
1176 static unsigned int bufsiz
=0; /* current size of buf */
1178 #define BUFINCR 512 /* how much to expand buf when if fills */
1180 #define CPY(s) { cp = (s); while ((*dst++ = *cp++)) ; --dst; }
1183 * check if there's enough room in buf for str.
1184 * add more mem if needed
1186 #define CHECKMEM(str) \
1187 if ((len = strlen (str)) >= bufend - dst) {\
1189 int n = last_dst - buf;\
1190 bufsiz += ((dst + len - bufend) / BUFINCR + 1) * BUFINCR;\
1191 buf = mh_xrealloc (buf, bufsiz);\
1193 last_dst = buf + n;\
1194 bufend = buf + bufsiz;\
1199 * These are versions of similar routines from replsbr.c; the purpose is
1200 * to suppress duplicate addresses from being added to a list when building
1201 * up addresses for the %(formataddr) format function. This is used by
1202 * repl to prevent duplicate addresses from being added to the "to" line.
1203 * See replsbr.c for more information.
1205 * We can't use the functions in replsbr.c directly because they are slightly
1206 * different and depend on the rest of replsbr.c
1209 test_formataddr (char *orig
, char *str
)
1213 register int isgroup
;
1217 register struct mailname
*mp
= NULL
;
1219 /* if we don't have a buffer yet, get one */
1221 buf
= mh_xmalloc (BUFINCR
);
1222 last_dst
= buf
; /* XXX */
1223 bufsiz
= BUFINCR
- 6; /* leave some slop */
1224 bufend
= buf
+ bufsiz
;
1227 * If "orig" points to our buffer we can just pick up where we
1228 * left off. Otherwise we have to copy orig into our buffer.
1232 else if (!orig
|| !*orig
) {
1236 dst
= last_dst
; /* XXX */
1241 /* concatenate all the new addresses onto 'buf' */
1242 for (isgroup
= 0; (cp
= getname (str
)); ) {
1243 if ((mp
= getm (cp
, NULL
, 0, AD_NAME
, error
)) == NULL
) {
1244 fprintf(stderr
, "bad address \"%s\" -- %s\n", cp
, error
);
1247 if (isgroup
&& (mp
->m_gname
|| !mp
->m_ingrp
)) {
1252 /* if we get here we're going to add an address */
1258 CHECKMEM (mp
->m_gname
);
1262 sp
= adrformat (mp
);
1278 * The companion to test_formataddr(); it behaves the same way, except doesn't
1279 * do duplicate address detection.
1282 test_concataddr(char *orig
, char *str
)
1287 cp
= test_formataddr(orig
, str
);
1293 insert (struct mailname
*np
)
1295 struct mailname
*mp
;
1300 if (np
->m_mbox
== NULL
)
1303 for (mp
= &mq
; mp
->m_next
; mp
= mp
->m_next
) {
1304 if (!strcasecmp (np
->m_host
? np
->m_host
: "",
1305 mp
->m_next
->m_host
? mp
->m_next
->m_host
: "") &&
1306 !strcasecmp (np
->m_mbox
? np
->m_mbox
: "",
1307 mp
->m_next
->m_mbox
? mp
->m_next
->m_mbox
: ""))
1310 if (!ccme
&& ismymbox (np
))
1319 * Reset our duplicate address list
1325 struct mailname
*mp
, *mp2
;
1327 for (mp
= mq
.m_next
; mp
; mp
= mp2
->m_next
) {