- int state, i, pid, compnum;
- char *cp, *msg = NULL, **argp, **arguments;
- char *sargv[16], buf[BUFSIZ], name[NAMESZ];
- FILE *in;
-
-#ifdef LOCALE
- setlocale(LC_ALL, "");
-#endif
- invo_name = r1bindex (argv[0], '/');
-
- /* foil search of user profile/context */
- if (context_foil (NULL) == -1)
- done (1);
-
- mts_init (invo_name);
- arguments = getarguments (invo_name, argc, argv, 0);
- argp = arguments;
-
- while ((cp = *argp++)) {
- if (*cp == '-') {
- switch (smatch (++cp, switches)) {
- case AMBIGSW:
- ambigsw (cp, switches);
- done (1);
- case UNKWNSW:
- adios (NULL, "-%s unknown", cp);
-
- case HELPSW:
- snprintf (buf, sizeof(buf), "%s [switches] file", invo_name);
- print_help (buf, switches, 1);
- done (1);
- case VERSIONSW:
- print_version(invo_name);
- done (1);
-
- case DEBUGSW:
- debug++;
- continue;
-
- case DISTSW:
- msgstate = resent;
- continue;
-
- case WHOMSW:
- whomflg++;
- continue;
-
- case FILTSW:
- if (!(filter = *argp++) || *filter == '-')
- adios (NULL, "missing argument to %s", argp[-2]);
- continue;
- case NFILTSW:
- filter = NULL;
- continue;
-
- case REMVSW:
- rmflg++;
- continue;
- case NREMVSW:
- rmflg = 0;
- continue;
-
- case BACKSW:
- backflg++;
- continue;
- case NBACKSW:
- backflg = 0;
- continue;
-
- case VERBSW:
- verbose++;
- continue;
- case NVERBSW:
- verbose = 0;
- continue;
-
- case WATCSW:
- watch++;
- continue;
- case NWATCSW:
- watch = 0;
- continue;
-
- case PUSHSW:
- pushflg++;
- continue;
- case NPUSHSW:
- pushflg = 0;
- continue;
-
- case ALIASW:
- if (!(cp = *argp++) || *cp == '-')
- adios (NULL, "missing argument to %s", argp[-2]);
- if (aliasflg < 0)
- alias (AliasFile);/* load default aka's */
- aliasflg = 1;
- if ((state = alias(cp)) != AK_OK)
- adios (NULL, "aliasing error in file %s - %s",
- cp, akerror(state) );
- continue;
- case NALIASW:
- aliasflg = 0;
- continue;
-
- case WIDTHSW:
- if (!(cp = *argp++) || *cp == '-')
- adios (NULL, "missing argument to %s", argp[-2]);
- outputlinelen = atoi (cp);
- if (outputlinelen <= 10)
- outputlinelen = 72;
- continue;
-
- case LIBSW:
- case ANNOSW:
- /* -library & -idanno switch ignored */
- if (!(cp = *argp++) || *cp == '-')
- adios (NULL, "missing argument to %s", argp[-2]);
- continue;
- }
- }
- if (msg)
- adios (NULL, "only one message at a time!");
- else
- msg = cp;
- }
-
- if (aliasflg < 0)
- alias (AliasFile); /* load default aka's */
-
- if (!msg)
- adios (NULL, "usage: %s [switches] file", invo_name);
-
- if ((in = fopen (msg, "r")) == NULL)
- adios (msg, "unable to open");
-
- start_headers ();
- if (debug) {
- verbose++;
- out = stdout;
- }
- else {
- mktemp (tmpfil);
- if ((out = fopen (tmpfil, "w")) == NULL)
- adios (tmpfil, "unable to create");
- chmod (tmpfil, 0600);
- }
-
- hdrtab = (msgstate == normal) ? NHeaders : RHeaders;
-
- for (compnum = 1, state = FLD;;) {
- switch (state = m_getfld (state, name, buf, sizeof(buf), in)) {
- case FLD:
- compnum++;
- putfmt (name, buf, out);
- continue;
-
- case FLDPLUS:
- compnum++;
- cp = add (buf, cp);
- while (state == FLDPLUS) {
- state = m_getfld (state, name, buf, sizeof(buf), in);
- cp = add (buf, cp);
+ enum state state;
+ struct field f = {{0}};
+ int compnum;
+ char *cp, *msg = NULL, **argp, **arguments;
+ char **sargv, buf[BUFSIZ];
+ FILE *in;
+
+ setlocale(LC_ALL, "");
+ invo_name = mhbasename(argv[0]);
+
+ context_read();
+
+ arguments = getarguments(invo_name, argc, argv, 0);
+ argp = arguments;
+
+ while ((cp = *argp++)) {
+ if (*cp == '-') {
+ switch (smatch(++cp, switches)) {
+ case AMBIGSW:
+ ambigsw(cp, switches);
+ exit(EX_USAGE);
+ case UNKWNSW:
+ adios(EX_USAGE, NULL, "-%s unknown", cp);
+
+ case HELPSW:
+ snprintf(buf, sizeof(buf),
+ "%s [switches] file",
+ invo_name);
+ print_help(buf, switches, 1);
+ exit(argc == 2 ? EX_OK : EX_USAGE);
+ case VERSIONSW:
+ print_version(invo_name);
+ exit(argc == 2 ? EX_OK : EX_USAGE);
+
+ case DEBUGSW:
+ debug++;
+ continue;
+
+ case DISTSW:
+ msgstate = resent;
+ continue;
+
+ case VERBSW:
+ verbose++;
+ continue;
+ case NVERBSW:
+ verbose = 0;
+ continue;
+ }