New file. Source for fmtcheck command. It is
planned as a replacement for fmtdump, providing a broader set of options for debugging user formats. Currently only dump (listing) mode is implemented.
Showing
1 changed file
with
97 additions
and
0 deletions
mh/fmtcheck.c
0 → 100644
1 | /* GNU mailutils - a suite of utilities for electronic mail | ||
2 | Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc. | ||
3 | |||
4 | This program is free software; you can redistribute it and/or modify | ||
5 | it under the terms of the GNU General Public License as published by | ||
6 | the Free Software Foundation; either version 2, or (at your option) | ||
7 | any later version. | ||
8 | |||
9 | This program is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU General Public License | ||
15 | along with this program; if not, write to the Free Software | ||
16 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ | ||
17 | |||
18 | /* fmtcheck */ | ||
19 | |||
20 | #include <mh.h> | ||
21 | |||
22 | const char *argp_program_version = "fmtcheck (" PACKAGE_STRING ")"; | ||
23 | static char doc[] = "GNU MH fmtcheck"; | ||
24 | static char args_doc[] = ""; | ||
25 | |||
26 | /* GNU options */ | ||
27 | static struct argp_option options[] = { | ||
28 | {"form", 'F', "FILE", 0, "Read format from given file"}, | ||
29 | {"format", 't', "FORMAT", 0, "Use this format string"}, | ||
30 | {"dump", 'd', NULL, 0, "Dump the listing of compiled format code"}, | ||
31 | { "\nUse -help switch to obtain the list of traditional MH options. ", 0, 0, OPTION_DOC, "" }, | ||
32 | |||
33 | { 0 } | ||
34 | }; | ||
35 | |||
36 | /* Traditional MH options */ | ||
37 | struct mh_option mh_option[] = { | ||
38 | {"form", 4, 'F', MH_OPT_ARG, "formatfile"}, | ||
39 | {"format", 5, 't', MH_OPT_ARG, "string"}, | ||
40 | { 0 } | ||
41 | }; | ||
42 | |||
43 | char *format_str; | ||
44 | static mh_format_t format; | ||
45 | |||
46 | typedef int (*action_fp) __P((void)); | ||
47 | |||
48 | static int | ||
49 | action_dump () | ||
50 | { | ||
51 | if (!format_str) | ||
52 | { | ||
53 | mh_error ("format string not specified"); | ||
54 | return 1; | ||
55 | } | ||
56 | mh_format_dump (&format); | ||
57 | return 0; | ||
58 | } | ||
59 | |||
60 | static action_fp action = action_dump; | ||
61 | |||
62 | static int | ||
63 | opt_handler (int key, char *arg, void *unused) | ||
64 | { | ||
65 | switch (key) | ||
66 | { | ||
67 | case 'F': | ||
68 | mh_read_formfile (arg, &format_str); | ||
69 | break; | ||
70 | |||
71 | case 't': | ||
72 | format_str = arg; | ||
73 | break; | ||
74 | |||
75 | case 'd': | ||
76 | action = action_dump; | ||
77 | break; | ||
78 | |||
79 | default: | ||
80 | return 1; | ||
81 | } | ||
82 | return 0; | ||
83 | } | ||
84 | |||
85 | int | ||
86 | main (int argc, char **argv) | ||
87 | { | ||
88 | mh_argp_parse (argc, argv, options, mh_option, args_doc, doc, | ||
89 | opt_handler, NULL, NULL); | ||
90 | |||
91 | if (format_str && mh_format_parse (format_str, &format)) | ||
92 | { | ||
93 | mh_error ("Bad format string"); | ||
94 | exit (1); | ||
95 | } | ||
96 | return (*action) (); | ||
97 | } |
-
Please register or sign in to post a comment