]>
diplodocus.org Git - nmh/blob - uip/fmttest.c
39f4ecc42d3e1e20f7b9e82e06ff72102bc42d0f
1 /* fmttest.c -- A program to help test and debug format instructions
3 * This code is Copyright (c) 2012, by the authors of nmh. See the
4 * COPYRIGHT file in the root directory of the nmh distribution for
5 * complete copyright information.
9 #include "sbr/snprintb.h"
10 #include "sbr/getcpy.h"
11 #include "sbr/m_convert.h"
12 #include "sbr/getfolder.h"
13 #include "sbr/folder_read.h"
14 #include "sbr/folder_free.h"
15 #include "sbr/context_save.h"
16 #include "sbr/context_replace.h"
17 #include "sbr/context_find.h"
18 #include "sbr/brkstring.h"
19 #include "sbr/ambigsw.h"
21 #include "sbr/print_version.h"
22 #include "sbr/print_help.h"
23 #include "sbr/seq_getnum.h"
24 #include "sbr/error.h"
25 #include "h/fmt_scan.h"
26 #include "h/fmt_compile.h"
28 #include "h/scansbr.h"
29 #include "h/addrsbr.h"
31 #include "sbr/m_maildir.h"
32 #include "sbr/terminal.h"
34 #define FMTTEST_SWITCHES \
35 X("form formatfile", 0, FORMSW) \
36 X("format string", 5, FMTSW) \
37 X("address", 0, ADDRSW) \
39 X("date", 0, DATESW) \
40 X("message", 0, MESSAGESW) \
41 X("file", 0, FILESW) \
42 X("nofile", 0, NFILESW) \
43 X("-component-name component-text", 0, OTHERSW) \
44 X("dupaddrs", 0, DUPADDRSW) \
45 X("nodupaddrs", 0, NDUPADDRSW) \
46 X("ccme", 0, CCMESW) \
47 X("noccme", 0, NCCMESW) \
48 X("outsize size-in-characters", 0, OUTSIZESW) \
49 X("width column-width", 0, WIDTHSW) \
50 X("msgnum number", 0, MSGNUMSW) \
51 X("msgcur flag", 0, MSGCURSW) \
52 X("msgsize size", 0, MSGSIZESW) \
53 X("unseen flag", 0, UNSEENSW) \
54 X("dump", 0, DUMPSW) \
55 X("nodump", 0, NDUMPSW) \
56 X("trace", 0, TRACESW) \
57 X("notrace", 0, NTRACESW) \
58 X("version", 0, VERSIONSW) \
59 X("help", 0, HELPSW) \
61 #define X(sw, minchars, id) id,
62 DEFINE_SWITCH_ENUM(FMTTEST
);
65 #define X(sw, minchars, id) { sw, minchars, id },
66 DEFINE_SWITCH_ARRAY(FMTTEST
, switches
);
70 * An array containing labels used for branch instructions
73 static struct format
**lvec
= NULL
;
75 static int lallocated
= 0;
77 enum mode_t
{ MESSAGE
, ADDRESS
, DATE
, RAW
};
78 #define DEFADDRFORMAT "%<{error}%{error}: %{text}%|%(putstr(proper{text}))%>"
79 #define DEFDATEFORMAT "%<(nodate{text})error: %{text}%|%(putstr(pretty{text}))%>"
82 * Context structure used by the tracing routines
85 struct trace_context
{
94 static void fmt_dump (char *, struct format
*);
95 static void dumpone(struct format
*);
96 static void initlabels(struct format
*);
97 static int findlabel(struct format
*);
98 static void assignlabel(struct format
*);
99 static char *f_typestr(int);
100 static char *c_typestr(int);
101 static char *c_flagsstr(int);
102 static void litputs(const char *);
103 static void litputc(char);
104 static void process_addresses(struct format
*, struct msgs_array
*,
105 charstring_t
, int, int *,
106 struct fmt_callbacks
*);
107 static void process_raw(struct format
*, struct msgs_array
*, charstring_t
,
108 int, int *, struct fmt_callbacks
*);
109 static void process_messages(struct format
*, struct msgs_array
*,
110 struct msgs_array
*, charstring_t
, char *, int,
111 int, int *, struct fmt_callbacks
*);
112 static void process_single_file(FILE *, struct msgs_array
*, int *, int,
113 struct format
*, charstring_t
, int,
114 struct fmt_callbacks
*);
115 static void test_trace(void *, struct format
*, int, char *, const char *);
116 static char *test_formataddr(char *, char *);
117 static char *test_concataddr(char *, char *);
118 static int insert(struct mailname
*);
119 static void mlistfree(void);
121 static bool nodupcheck
; /* If set, no check for duplicates */
122 static bool ccme
; /* Should I cc myself? */
123 static struct mailname mq
; /* Mail addresses to check for duplicates */
124 static char *dummy
= "dummy";
127 main (int argc
, char **argv
)
129 char *cp
, *form
= NULL
, *format
= NULL
, *defformat
= FORMAT
, *folder
= NULL
;
130 char buf
[BUFSIZ
], *nfs
, **argp
, **arguments
;
134 struct msgs_array msgs
= { 0, 0, NULL
}, compargs
= { 0, 0, NULL
};
138 bool dupaddrs
= true;
141 int colwidth
= -1, msgnum
= -1, msgcur
= -1, msgsize
= -1, msgunseen
= -1;
142 enum mode_t mode
= MESSAGE
;
144 struct fmt_callbacks cb
, *cbp
= NULL
;
146 if (nmh_init(argv
[0], true, true)) { return 1; }
148 arguments
= getarguments (invo_name
, argc
, argv
, 1);
151 while ((cp
= *argp
++)) {
154 * A -- means that we have a component name (like pick);
155 * save the component name and the next argument for the text.
159 die("missing component name after --");
160 app_msgarg(&compargs
, cp
);
161 /* Grab next argument for component text */
163 die("missing argument to %s", argp
[-2]);
164 app_msgarg(&compargs
, cp
);
167 switch (smatch (cp
, switches
)) {
169 ambigsw (cp
, switches
);
172 die("-%s unknown", cp
);
175 snprintf (buf
, sizeof(buf
), "%s [switches]", invo_name
);
176 print_help (buf
, switches
, 1);
179 print_version(invo_name
);
182 die("internal argument error!");
186 if (!(cp
= *argp
++) || *cp
== '-')
187 die("missing argument to %s", argp
[-2]);
188 if (strcmp(cp
, "max") == 0)
189 outputsize
= INT_MAX
;
190 else if (strcmp(cp
, "width") == 0)
191 outputsize
= sc_width();
193 outputsize
= atoi(cp
);
197 if (!(form
= *argp
++) || *form
== '-')
198 die("missing argument to %s", argp
[-2]);
202 if (!(format
= *argp
++) || *format
== '-')
203 die("missing argument to %s", argp
[-2]);
216 defformat
= DEFADDRFORMAT
;
228 defformat
= DEFDATEFORMAT
;
253 if (!(cp
= *argp
++) || *cp
== '-')
254 die("missing argument to %s", argp
[-2]);
258 if (!(cp
= *argp
++) || *cp
== '-')
259 die("missing argument to %s", argp
[-2]);
263 if (!(cp
= *argp
++) || *cp
== '-')
264 die("missing argument to %s", argp
[-2]);
268 if (!(cp
= *argp
++) || *cp
== '-')
269 die("missing argument to %s", argp
[-2]);
273 if (!(cp
= *argp
++) || *cp
== '-')
274 die("missing argument to %s", argp
[-2]);
275 msgunseen
= atoi(cp
);
289 * Only interpret as a folder if we're in message mode
292 if (mode
== MESSAGE
&& !files
&& (*cp
== '+' || *cp
== '@')) {
294 die("only one folder at a time!");
295 folder
= pluspath (cp
);
297 app_msgarg(&msgs
, cp
);
301 * Here's our weird heuristic:
303 * - We allow -dump without any other arguments.
304 * - If you've given any component arguments, we don't require any
306 * - The arguments are interpreted as folders/messages _if_ we're in
307 * message mode, otherwise pass as strings in the text component.
310 if (!dump
&& compargs
.size
== 0 && msgs
.size
== 0) {
311 die("usage: [switches] [+folder] msgs | strings...");
315 * If you're picking "raw" as a mode, then you have to select
319 if (mode
== RAW
&& form
== NULL
&& format
== NULL
) {
320 die("You must specify a format with -form or -format when "
325 * Get new format string. Must be before chdir().
327 nfs
= new_fs (form
, format
, defformat
);
328 (void) fmt_compile(nfs
, &fmt
, 1);
334 if (compargs
.size
== 0 && msgs
.size
== 0)
339 buffer
= charstring_create(BUFSIZ
);
341 if (outputsize
== 0) {
343 outputsize
= sc_width();
345 outputsize
= INT_MAX
;
351 dat
[3] = colwidth
== -1 ? outputsize
: colwidth
;
355 * If we want to provide our own formataddr, concactaddr, or tracing
356 * callback, do that now. Also, prime ismymbox if we use it.
359 if (!dupaddrs
|| trace
) {
364 cb
.formataddr
= test_formataddr
;
365 cb
.concataddr
= test_concataddr
;
371 struct trace_context
*ctx
;
376 ctx
->outbuf
= mh_xstrdup("");
378 cb
.trace_func
= test_trace
;
379 cb
.trace_context
= ctx
;
383 if (mode
== MESSAGE
) {
384 process_messages(fmt
, &compargs
, &msgs
, buffer
, folder
, outputsize
,
388 for (i
= 0; i
< compargs
.size
; i
+= 2) {
389 cptr
= fmt_findcomp(compargs
.msgs
[i
]);
391 cptr
->c_text
= getcpy(compargs
.msgs
[i
+ 1]);
395 if (mode
== ADDRESS
) {
396 process_addresses(fmt
, &msgs
, buffer
, outputsize
, dat
, cbp
);
397 } else /* Fall-through for RAW or DATE */
398 process_raw(fmt
, &msgs
, buffer
, outputsize
, dat
, cbp
);
401 charstring_free(buffer
);
409 * Process each address with fmt_scan().
415 struct pqpair
*pq_next
;
419 process_addresses(struct format
*fmt
, struct msgs_array
*addrs
,
420 charstring_t buffer
, int outwidth
, int *dat
,
421 struct fmt_callbacks
*cb
)
424 char *cp
, error
[BUFSIZ
];
426 struct pqpair
*p
, *q
;
439 for (i
= 0; i
< addrs
->size
; i
++) {
440 (q
= &pq
)->pq_next
= NULL
;
441 while ((cp
= getname(addrs
->msgs
[i
]))) {
443 if ((mp
= getm(cp
, NULL
, 0, error
, sizeof(error
))) == NULL
) {
444 p
->pq_text
= mh_xstrdup(cp
);
445 p
->pq_error
= mh_xstrdup(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");
457 c
->c_text
= p
->pq_text
;
460 c
= fmt_findcomp("error");
463 c
->c_text
= p
->pq_error
;
467 fmt_scan(fmt
, buffer
, outwidth
, dat
, cb
);
468 fputs(charstring_buffer(buffer
), stdout
);
480 * Process messages and run them through the format engine. A lot taken
485 process_messages(struct format
*fmt
, struct msgs_array
*comps
,
486 struct msgs_array
*msgs
, charstring_t buffer
, char *folder
,
487 int outwidth
, int files
, int *dat
,
488 struct fmt_callbacks
*cb
)
490 int i
, msgnum
, msgsize
= dat
[2], num
= dat
[0], cur
= dat
[1];
491 int num_unseen_seq
= 0;
492 ivector_t seqnum
= ivector_create (0);
498 * If 'files' is set, short-circuit everything else and just process
503 for (i
= 0; i
< msgs
->size
; i
++) {
504 if ((in
= fopen(cp
= msgs
->msgs
[i
], "r")) == NULL
) {
505 admonish(cp
, "unable to open file");
508 process_single_file(in
, comps
, dat
, msgsize
, fmt
, buffer
,
516 folder
= getfolder(1);
518 maildir
= m_maildir(folder
);
520 if (chdir(maildir
) < 0)
521 adios(maildir
, "unable to change directory to");
523 if (!(mp
= folder_read(folder
, 1)))
524 die("unable to read folder %s", folder
);
527 die("no messages in %s", folder
);
529 for (i
= 0; i
< msgs
->size
; i
++)
530 if (!m_convert(mp
, msgs
->msgs
[i
]))
532 seq_setprev(mp
); /* set the Previous-Sequence */
534 context_replace(pfolder
, folder
); /* update current folder */
535 seq_save(mp
); /* synchronize message sequences */
536 context_save(); /* save the context file */
539 * We want to set the unseen flag if requested, so we have to check
540 * the unseen sequence as well.
544 if ((cp
= context_find(usequence
)) && *cp
) {
548 ap
= brkstring(dp
, " ", "\n");
549 for (i
= 0; ap
&& *ap
; i
++, ap
++)
550 ivector_push_back (seqnum
, seq_getnum(mp
, *ap
));
557 for (msgnum
= mp
->lowsel
; msgnum
<= mp
->hghsel
; msgnum
++) {
558 if (is_selected(mp
, msgnum
)) {
559 if ((in
= fopen(cp
= m_name(msgnum
), "r")) == NULL
) {
560 admonish(cp
, "unable to open message");
570 dat
[1] = msgnum
== mp
->curmsg
;
573 * Check to see if this is in the unseen sequence
577 for (i
= 0; i
< num_unseen_seq
; i
++) {
578 if (in_sequence(mp
, ivector_at (seqnum
, i
), msgnum
)) {
585 * Read in the message and process the components
588 process_single_file(in
, comps
, dat
, msgsize
, fmt
, buffer
,
593 ivector_free (seqnum
);
598 * Process a single file in message mode
602 process_single_file(FILE *in
, struct msgs_array
*comps
, int *dat
, int msgsize
,
603 struct format
*fmt
, charstring_t buffer
, int outwidth
,
604 struct fmt_callbacks
*cb
)
607 char name
[NAMESZ
], rbuf
[NMH_BUFSIZ
];
608 m_getfld_state_t gstate
;
613 * Get our size if we didn't include one
619 if (fstat(fileno(in
), &st
) < 0)
626 * Initialize everything else
637 * Read in the message and process the components
640 gstate
= m_getfld_state_init(in
);
642 bufsz
= sizeof(rbuf
);
643 state
= m_getfld2(&gstate
, name
, rbuf
, &bufsz
);
647 i
= fmt_addcomptext(name
, rbuf
);
649 while (state
== FLDPLUS
) {
650 bufsz
= sizeof(rbuf
);
651 state
= m_getfld2(&gstate
, name
, rbuf
, &bufsz
);
652 fmt_appendcomp(i
, name
, rbuf
);
656 while (state
== FLDPLUS
) {
657 bufsz
= sizeof(rbuf
);
658 state
= m_getfld2(&gstate
, name
, rbuf
, &bufsz
);
663 if (fmt_findcomp("body")) {
664 if ((i
= strlen(rbuf
)) < outwidth
) {
665 bufsz
= min (outwidth
, (int) sizeof rbuf
- i
);
666 m_getfld2(&gstate
, name
, rbuf
+ i
, &bufsz
);
669 fmt_addcomptext("body", rbuf
);
679 m_getfld_state_destroy(&gstate
);
682 * Do this now to override any components in the original message
685 for (i
= 0; i
< comps
->size
; i
+= 2) {
686 c
= fmt_findcomp(comps
->msgs
[i
]);
689 c
->c_text
= getcpy(comps
->msgs
[i
+ 1]);
693 fmt_scan(fmt
, buffer
, outwidth
, dat
, cb
);
694 fputs(charstring_buffer (buffer
), stdout
);
699 * Run text through the format engine with no special processing
703 process_raw(struct format
*fmt
, struct msgs_array
*text
, charstring_t buffer
,
704 int outwidth
, int *dat
, struct fmt_callbacks
*cb
)
718 c
= fmt_findcomp("text");
720 for (i
= 0; i
< text
->size
; i
++) {
723 c
->c_text
= getcpy(text
->msgs
[i
]);
726 fmt_scan(fmt
, buffer
, outwidth
, dat
, cb
);
727 fputs(charstring_buffer (buffer
), stdout
);
733 * Our basic tracing support callback.
735 * Print out each instruction as it's executed, including the values of
736 * the num and str registers if they've changed.
740 test_trace(void *context
, struct format
*fmt
, int num
, char *str
,
743 struct trace_context
*ctx
= (struct trace_context
*) context
;
744 bool changed
= false;
748 if (num
!= ctx
->num
) {
749 printf("num=%d", num
);
754 if (str
!= ctx
->str
) {
758 fputs("str=", stdout
);
766 if (strcmp(outbuf
, ctx
->outbuf
) != 0) {
767 fputs("outbuf=", stdout
);
771 ctx
->outbuf
= mh_xstrdup(outbuf
);
776 fmt_dump (char *nfs
, struct format
*fmth
)
780 printf("Instruction dump of format string: \n%s\n", nfs
);
783 for (fmt
= fmth
; fmt
; ++fmt
) {
785 if (fmt
->f_type
== FT_DONE
&& fmt
->f_value
== 0)
791 dumpone(struct format
*fmt
)
795 if ((i
= findlabel(fmt
)) >= 0)
799 fputs(f_typestr((int)fmt
->f_type
), stdout
);
801 switch (fmt
->f_type
) {
807 fputs(", comp ", stdout
);
808 litputs(fmt
->f_comp
->c_name
);
809 if (fmt
->f_comp
->c_type
)
810 printf(", c_type %s", c_typestr(fmt
->f_comp
->c_type
));
811 if (fmt
->f_comp
->c_flags
)
812 printf(", c_flags %s", c_flagsstr(fmt
->f_comp
->c_flags
));
839 fputs(", c_name ", stdout
);
840 litputs(fmt
->f_comp
->c_name
);
841 if (fmt
->f_comp
->c_type
)
842 printf(", c_type %s", c_typestr(fmt
->f_comp
->c_type
));
843 if (fmt
->f_comp
->c_flags
)
844 printf(", c_flags %s", c_flagsstr(fmt
->f_comp
->c_flags
));
863 fputs(", c_name ", stdout
);
864 litputs(fmt
->f_comp
->c_name
);
865 if (fmt
->f_comp
->c_type
)
866 printf(", c_type %s", c_typestr(fmt
->f_comp
->c_type
));
867 if (fmt
->f_comp
->c_flags
)
868 printf(", c_flags %s", c_flagsstr(fmt
->f_comp
->c_flags
));
872 printf(", width %d, fill '", fmt
->f_width
);
873 litputc(fmt
->f_fill
);
874 fputs("' name ", stdout
);
875 litputs(fmt
->f_comp
->c_name
);
876 if (fmt
->f_comp
->c_type
)
877 printf(", c_type %s", c_typestr(fmt
->f_comp
->c_type
));
878 if (fmt
->f_comp
->c_flags
)
879 printf(", c_flags %s", c_flagsstr(fmt
->f_comp
->c_flags
));
884 printf(", width %d, fill '", fmt
->f_width
);
885 litputc(fmt
->f_fill
);
891 litputs(fmt
->f_text
);
895 printf(", width %d, fill '", fmt
->f_width
);
896 litputc(fmt
->f_fill
);
898 litputs(fmt
->f_text
);
904 litputc(fmt
->f_char
);
913 fputs(" continue else goto", stdout
);
916 i
= findlabel(fmt
+ fmt
->f_skip
);
923 i
= findlabel(fmt
+ fmt
->f_skip
);
924 printf(" %d continue else goto L%d", fmt
->f_value
, i
);
933 case FT_LV_MULTIPLY_L
:
936 printf(" value %d", fmt
->f_value
);
940 fputs(" str ", stdout
);
941 litputs(fmt
->f_text
);
945 fputs(" getenv ", stdout
);
946 litputs(fmt
->f_text
);
949 case FT_LS_DECODECOMP
:
950 fputs(", comp ", stdout
);
951 litputs(fmt
->f_comp
->c_name
);
958 printf(", width %d", fmt
->f_width
);
962 printf(", value dat[%d]", fmt
->f_value
);
969 * Iterate over all instructions and assign labels to the targets of
974 initlabels(struct format
*fmth
)
976 struct format
*fmt
, *addr
;
980 for (fmt
= fmth
; fmt
; ++fmt
) {
990 addr
= fmt
+ fmt
->f_skip
;
991 if (findlabel(addr
) < 0)
994 if (fmt
->f_type
== FT_DONE
&& fmt
->f_value
== 0)
1001 findlabel(struct format
*addr
)
1005 for (i
= 0; i
< lused
; ++i
)
1006 if (addr
== lvec
[i
])
1012 assignlabel(struct format
*addr
)
1014 if (lused
>= lallocated
) {
1016 lvec
= (struct format
**)
1017 mh_xrealloc(lvec
, sizeof(struct format
*) * lallocated
);
1020 lvec
[lused
++] = addr
;
1026 static char buf
[32];
1029 case FT_COMP
: return "COMP";
1030 case FT_COMPF
: return "COMPF";
1031 case FT_LIT
: return "LIT";
1032 case FT_LITF
: return "LITF";
1033 case FT_CHAR
: return "CHAR";
1034 case FT_NUM
: return "NUM";
1035 case FT_NUMF
: return "NUMF";
1036 case FT_STR
: return "STR";
1037 case FT_STRF
: return "STRF";
1038 case FT_STRFW
: return "STRFW";
1039 case FT_STRLIT
: return "STRLIT";
1040 case FT_STRLITZ
: return "STRLITZ";
1041 case FT_PUTADDR
: return "PUTADDR";
1042 case FT_LS_COMP
: return "LS_COMP";
1043 case FT_LS_LIT
: return "LS_LIT";
1044 case FT_LS_GETENV
: return "LS_GETENV";
1045 case FT_LS_CFIND
: return "LS_CFIND";
1046 case FT_LS_DECODECOMP
: return "LS_DECODECOMP";
1047 case FT_LS_DECODE
: return "LS_DECODE";
1048 case FT_LS_TRIM
: return "LS_TRIM";
1049 case FT_LV_COMP
: return "LV_COMP";
1050 case FT_LV_COMPFLAG
: return "LV_COMPFLAG";
1051 case FT_LV_LIT
: return "LV_LIT";
1052 case FT_LV_DAT
: return "LV_DAT";
1053 case FT_LV_STRLEN
: return "LV_STRLEN";
1054 case FT_LV_PLUS_L
: return "LV_PLUS_L";
1055 case FT_LV_MINUS_L
: return "LV_MINUS_L";
1056 case FT_LV_MULTIPLY_L
: return "LV_MULTIPLY_L";
1057 case FT_LV_DIVIDE_L
: return "LV_DIVIDE_L";
1058 case FT_LV_MODULO_L
: return "LV_MODULO_L";
1059 case FT_LV_CHAR_LEFT
: return "LV_CHAR_LEFT";
1060 case FT_LS_MONTH
: return "LS_MONTH";
1061 case FT_LS_LMONTH
: return "LS_LMONTH";
1062 case FT_LS_ZONE
: return "LS_ZONE";
1063 case FT_LS_DAY
: return "LS_DAY";
1064 case FT_LS_WEEKDAY
: return "LS_WEEKDAY";
1065 case FT_LS_822DATE
: return "LS_822DATE";
1066 case FT_LS_PRETTY
: return "LS_PRETTY";
1067 case FT_LS_KILO
: return "LS_KILO";
1068 case FT_LS_KIBI
: return "LS_KIBI";
1069 case FT_LV_SEC
: return "LV_SEC";
1070 case FT_LV_MIN
: return "LV_MIN";
1071 case FT_LV_HOUR
: return "LV_HOUR";
1072 case FT_LV_MDAY
: return "LV_MDAY";
1073 case FT_LV_MON
: return "LV_MON";
1074 case FT_LV_YEAR
: return "LV_YEAR";
1075 case FT_LV_YDAY
: return "LV_YDAY";
1076 case FT_LV_WDAY
: return "LV_WDAY";
1077 case FT_LV_ZONE
: return "LV_ZONE";
1078 case FT_LV_CLOCK
: return "LV_CLOCK";
1079 case FT_LV_RCLOCK
: return "LV_RCLOCK";
1080 case FT_LV_DAYF
: return "LV_DAYF";
1081 case FT_LV_DST
: return "LV_DST";
1082 case FT_LV_ZONEF
: return "LV_ZONEF";
1083 case FT_LS_PERS
: return "LS_PERS";
1084 case FT_LS_MBOX
: return "LS_MBOX";
1085 case FT_LS_HOST
: return "LS_HOST";
1086 case FT_LS_PATH
: return "LS_PATH";
1087 case FT_LS_GNAME
: return "LS_GNAME";
1088 case FT_LS_NOTE
: return "LS_NOTE";
1089 case FT_LS_ADDR
: return "LS_ADDR";
1090 case FT_LS_822ADDR
: return "LS_822ADDR";
1091 case FT_LS_FRIENDLY
: return "LS_FRIENDLY";
1092 case FT_LV_HOSTTYPE
: return "LV_HOSTTYPE";
1093 case FT_LV_INGRPF
: return "LV_INGRPF";
1094 case FT_LS_UNQUOTE
: return "LS_UNQUOTE";
1095 case FT_LV_NOHOSTF
: return "LV_NOHOSTF";
1096 case FT_LOCALDATE
: return "LOCALDATE";
1097 case FT_GMTDATE
: return "GMTDATE";
1098 case FT_PARSEDATE
: return "PARSEDATE";
1099 case FT_PARSEADDR
: return "PARSEADDR";
1100 case FT_FORMATADDR
: return "FORMATADDR";
1101 case FT_CONCATADDR
: return "CONCATADDR";
1102 case FT_MYMBOX
: return "MYMBOX";
1103 case FT_GETMYMBOX
: return "GETMYMBOX";
1104 case FT_GETMYADDR
: return "GETMYADDR";
1105 case FT_SAVESTR
: return "SAVESTR";
1106 case FT_DONE
: return "DONE";
1107 case FT_PAUSE
: return "PAUSE";
1108 case FT_NOP
: return "NOP";
1109 case FT_GOTO
: return "GOTO";
1110 case FT_IF_S_NULL
: return "IF_S_NULL";
1111 case FT_IF_S
: return "IF_S";
1112 case FT_IF_V_EQ
: return "IF_V_EQ";
1113 case FT_IF_V_NE
: return "IF_V_NE";
1114 case FT_IF_V_GT
: return "IF_V_GT";
1115 case FT_IF_MATCH
: return "IF_MATCH";
1116 case FT_IF_AMATCH
: return "IF_AMATCH";
1117 case FT_S_NULL
: return "S_NULL";
1118 case FT_S_NONNULL
: return "S_NONNULL";
1119 case FT_V_EQ
: return "V_EQ";
1120 case FT_V_NE
: return "V_NE";
1121 case FT_V_GT
: return "V_GT";
1122 case FT_V_MATCH
: return "V_MATCH";
1123 case FT_V_AMATCH
: return "V_AMATCH";
1125 snprintf(buf
, sizeof(buf
), "/* ??? #%d */", t
);
1133 static char buf
[64];
1135 snprintb(buf
, sizeof(buf
), t
, CT_BITS
);
1142 static char buf
[64];
1144 snprintb(buf
, sizeof(buf
), t
, CF_BITS
);
1149 litputs(const char *s
)
1157 fputs("<nil>", stdout
);
1164 printf("\\x%02x", (unsigned char) c
);
1165 } else if (c
< 0x20 || c
== 0177) {
1169 } else if (c
== '\f') {
1172 } else if (c
== '\n') {
1175 } else if (c
== '\r') {
1178 } else if (c
== '\t') {
1183 putchar(c
^ 0x40); /* DEL to ?, others to alpha */
1190 * Routines/code to support the duplicate address suppression code, adapted
1194 static char *buf
; /* our current working buffer */
1195 static char *bufend
; /* end of working buffer */
1196 static char *last_dst
; /* buf ptr at end of last call */
1197 static unsigned int bufsiz
=0; /* current size of buf */
1199 #define BUFINCR 512 /* how much to expand buf when if fills */
1201 #define CPY(s) { cp = (s); while ((*dst++ = *cp++)) ; --dst; }
1204 * check if there's enough room in buf for str.
1205 * add more mem if needed
1207 #define CHECKMEM(str) \
1208 if ((len = strlen (str)) >= bufend - dst) {\
1210 int n = last_dst - buf;\
1211 bufsiz += ((dst + len - bufend) / BUFINCR + 1) * BUFINCR;\
1212 buf = mh_xrealloc (buf, bufsiz);\
1214 last_dst = buf + n;\
1215 bufend = buf + bufsiz;\
1220 * These are versions of similar routines from replsbr.c; the purpose is
1221 * to suppress duplicate addresses from being added to a list when building
1222 * up addresses for the %(formataddr) format function. This is used by
1223 * repl to prevent duplicate addresses from being added to the "to" line.
1224 * See replsbr.c for more information.
1226 * We can't use the functions in replsbr.c directly because they are slightly
1227 * different and depend on the rest of replsbr.c
1230 test_formataddr (char *orig
, char *str
)
1238 struct mailname
*mp
= NULL
;
1240 /* if we don't have a buffer yet, get one */
1242 buf
= mh_xmalloc (BUFINCR
);
1243 last_dst
= buf
; /* XXX */
1244 bufsiz
= BUFINCR
- 6; /* leave some slop */
1245 bufend
= buf
+ bufsiz
;
1248 * If "orig" points to our buffer we can just pick up where we
1249 * left off. Otherwise we have to copy orig into our buffer.
1253 else if (!orig
|| !*orig
) {
1257 dst
= last_dst
; /* XXX */
1262 /* concatenate all the new addresses onto 'buf' */
1263 for (isgroup
= false; (cp
= getname (str
)); ) {
1264 if ((mp
= getm (cp
, NULL
, 0, error
, sizeof(error
))) == NULL
) {
1265 fprintf(stderr
, "bad address \"%s\" -- %s\n", cp
, error
);
1268 if (isgroup
&& (mp
->m_gname
|| !mp
->m_ingrp
)) {
1273 /* if we get here we're going to add an address */
1279 CHECKMEM (mp
->m_gname
);
1283 sp
= adrformat (mp
);
1299 * The companion to test_formataddr(); it behaves the same way, except doesn't
1300 * do duplicate address detection.
1303 test_concataddr(char *orig
, char *str
)
1308 cp
= test_formataddr(orig
, str
);
1314 insert (struct mailname
*np
)
1316 struct mailname
*mp
;
1321 if (np
->m_mbox
== NULL
)
1324 for (mp
= &mq
; mp
->m_next
; mp
= mp
->m_next
) {
1325 if (!strcasecmp (FENDNULL(np
->m_host
),
1326 FENDNULL(mp
->m_next
->m_host
)) &&
1327 !strcasecmp (FENDNULL(np
->m_mbox
),
1328 FENDNULL(mp
->m_next
->m_mbox
)))
1331 if (!ccme
&& ismymbox (np
))
1340 * Reset our duplicate address list
1346 struct mailname
*mp
, *mp2
;
1348 for (mp
= mq
.m_next
; mp
; mp
= mp2
) {