#define FMTTEST_SWITCHES \
X("form formatfile", 0, FORMSW) \
X("format string", 5, FMTSW) \
- X("dump", 0, DUMPSW) \
X("address", 0, ADDRSW) \
X("raw", 0, RAWSW) \
X("date", 0, DATESW) \
X("message", 0, MESSAGESW) \
+ X("-component-name component-text", 0, OTHERSW) \
X("dupaddrs", 0, DUPADDRSW) \
X("nodupaddrs", 0, NDUPADDRSW) \
X("ccme", 0, CCMESW) \
X("msgcur flag", 0, MSGCURSW) \
X("msgsize size", 0, MSGSIZESW) \
X("unseen flag", 0, UNSEENSW) \
+ X("dump", 0, DUMPSW) \
+ X("nodump", 0, NDUMPSW) \
+ X("trace", 0, TRACESW) \
+ X("notrace", 0, NTRACESW) \
X("version", 0, VERSIONSW) \
- X("-component-name component-text", 0, OTHERSW) \
X("help", 0, HELPSW) \
#define X(sw, minchars, id) id,
#define DEFADDRFORMAT "%<{error}%{error}: %{text}%|%(putstr(proper{text}))%>"
#define DEFDATEFORMAT "%<(nodate{text})error: %{text}%|%(putstr(pretty{text}))%>"
+/*
+ * Context structure used by the tracing routines
+ */
+
+struct trace_context {
+ int num;
+ char *str;
+ char *outbuf;
+};
+
/*
* static prototypes
*/
static void process_messages(struct format *, struct msgs_array *,
struct msgs_array *, char *, char *, int,
int, int *, struct fmt_callbacks *);
+static void test_trace(void *, struct format *, int, char *, char *);
static char *test_formataddr(char *, char *);
static char *test_concataddr(char *, char *);
static int insert(struct mailname *);
static int nodupcheck = 0; /* If set, no check for duplicates */
static int ccme = 0; /* Should I cc myself? */
static struct mailname mq; /* Mail addresses to check for duplicates */
+static char *dummy = "dummy";
int
main (int argc, char **argv)
struct comp *cptr;
struct msgs_array msgs = { 0, 0, NULL }, compargs = { 0, 0, NULL};
int dump = 0, i;
- int outputsize = 0, bufsize = 0, dupaddrs = 1;
+ int outputsize = 0, bufsize = 0, dupaddrs = 1, trace = 0;
int colwidth = -1, msgnum = -1, msgcur = -1, msgsize = -1, msgunseen = -1;
int normalize = AD_HOST;
enum mode_t mode = MESSAGE;
normalize = AD_NHST;
continue;
+ case TRACESW:
+ trace++;
+ continue;
+ case NTRACESW:
+ trace = 0;
+ continue;
+
case ADDRSW:
mode = ADDRESS;
defformat = DEFADDRFORMAT;
case DUMPSW:
dump++;
continue;
+ case NDUMPSW:
+ dump = 0;
+ continue;
}
}
invo_name);
}
+ /*
+ * If you're picking "raw" as a mode, then you have to select
+ * a format.
+ */
+
+ if (mode == RAW && form == NULL && format == NULL) {
+ adios (NULL, "You must specify a format with -form or -format when "
+ "using -raw");
+ }
+
/*
* Get new format string. Must be before chdir().
*/
nfs = new_fs (form, format, defformat);
(void) fmt_compile(nfs, &fmt, 1);
- if (dump) {
- fmt_dump(nfs, fmt);
- if (compargs.size == 0 && msgs.size == 0)
- done(0);
+ if (dump || trace) {
+ initlabels(fmt);
+ if (dump) {
+ fmt_dump(nfs, fmt);
+ if (compargs.size == 0 && msgs.size == 0)
+ done(0);
+ }
}
/*
* callback, do that now. Also, prime ismymbox if we use it.
*/
- if (dupaddrs == 0) {
+ if (dupaddrs == 0 || trace) {
memset(&cb, 0, sizeof(cb));
- cb.formataddr = test_formataddr;
- cb.concataddr = test_concataddr;
cbp = &cb;
- if (!ccme)
- ismymbox(NULL);
+
+ if (dupaddrs == 0) {
+ cb.formataddr = test_formataddr;
+ cb.concataddr = test_concataddr;
+ if (!ccme)
+ ismymbox(NULL);
+ }
+
+ if (trace) {
+ struct trace_context *ctx;
+
+ ctx = mh_xmalloc(sizeof(*ctx));
+ ctx->num = -1;
+ ctx->str = dummy;
+ ctx->outbuf = getcpy(NULL);
+
+ cb.trace_func = test_trace;
+ cb.trace_context = ctx;
+ }
}
if (mode == MESSAGE) {
}
}
+/*
+ * Our basic tracing support callback.
+ *
+ * Print out each instruction as it's executed, including the values of
+ * the num and str registers if they've changed.
+ */
+
+static void
+test_trace(void *context, struct format *fmt, int num, char *str, char *outbuf)
+{
+ struct trace_context *ctx = (struct trace_context *) context;
+ int changed = 0;
+
+ dumpone(fmt);
+
+ if (num != ctx->num) {
+ printf("num=%d", num);
+ ctx->num = num;
+ changed++;
+ }
+
+ if (str != ctx->str) {
+ if (changed++)
+ printf(" ");
+ printf("str=\"%s\"", str ? str : "NULL");
+ ctx->str = str;
+ }
+
+ if (changed)
+ printf("\n");
+
+ if (strcmp(outbuf, ctx->outbuf) != 0) {
+ printf("outbuf=\"%s\"\n", outbuf);
+ free(ctx->outbuf);
+ ctx->outbuf = getcpy(outbuf);
+ }
+}
+
static void
fmt_dump (char *nfs, struct format *fmth)
{
printf("Instruction dump of format string: \n%s\n", nfs);
- initlabels(fmth);
-
/* Dump them out! */
for (fmt = fmth; fmt; ++fmt) {
dumpone(fmt);
case FT_LS_COMP: return("LS_COMP");
case FT_LS_LIT: return("LS_LIT");
case FT_LS_GETENV: return("LS_GETENV");
- case FT_LS_DECODECOMP: return("FT_LS_DECODECOMP");
- case FT_LS_DECODE: return("FT_LS_DECODE");
+ case FT_LS_DECODECOMP: return("LS_DECODECOMP");
+ case FT_LS_DECODE: return("LS_DECODE");
case FT_LS_TRIM: return("LS_TRIM");
case FT_LV_COMP: return("LV_COMP");
case FT_LV_COMPFLAG: return("LV_COMPFLAG");