- if (iscc)
- cclist = cclist ? add (cp, add (", ", cclist)) : getcpy (cp);
- else
- tolist = tolist ? add (cp, add (", ", tolist)) : getcpy (cp);
- }
-
- if (tolist == NULL)
- adios (NULL, "usage: %s addrs ... [switches]", invo_name);
- strncpy (tmpfil, m_tmpfil (invo_name), sizeof(tmpfil));
- if ((out = fopen (tmpfil, "w")) == NULL)
- adios (tmpfil, "unable to write");
- chmod (tmpfil, 0600);
-
- SIGNAL2 (SIGINT, intrser);
-
- fprintf (out, "%sTo: %s\n", resent ? "Resent-" : "", tolist);
- if (cclist)
- fprintf (out, "%scc: %s\n", resent ? "Resent-" : "", cclist);
- if (subject)
- fprintf (out, "%sSubject: %s\n", resent ? "Resent-" : "", subject);
- if (from)
- fprintf (out, "%sFrom: %s\n", resent ? "Resent-" : "", from);
- if (!resent)
- fputs ("\n", out);
-
- if (body) {
- fprintf (out, "%s", body);
- if (*body && *(body + strlen (body) - 1) != '\n')
- fputs ("\n", out);
- } else {
- for (somebody = 0;
- (i = fread (buf, sizeof(*buf), sizeof(buf), stdin)) > 0;
- somebody++)
- if (fwrite (buf, sizeof(*buf), i, out) != i)
- adios (tmpfil, "error writing");
- if (!somebody) {
- unlink (tmpfil);
- done (1);
+
+ 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 addrs... [switches]",
+ invo_name);
+ print_help(buf, switches, 0);
+ done(1);
+ case VERSIONSW:
+ print_version(invo_name);
+ done(1);
+
+ case FROMSW:
+ if (!(from = *argp++) || *from == '-')
+ adios(NULL, "missing argument to %s",
+ argp[-2]);
+ continue;
+
+ case BODYSW:
+ if (!(body = *argp++) || *body == '-')
+ adios(NULL, "missing argument to %s",
+ argp[-2]);
+ continue;
+
+ case CCSW:
+ iscc++;
+ continue;
+
+ case SUBJSW:
+ if (!(subject = *argp++) || *subject == '-')
+ adios(NULL, "missing argument to %s",
+ argp[-2]);
+ continue;
+
+ case RESNDSW:
+ resent++;
+ continue;
+
+ case QUEUESW:
+ queued++;
+ continue;
+ }
+ }
+ if (iscc)
+ cclist = cclist ? add(cp, add(", ", cclist)) :
+ getcpy(cp);
+ else
+ tolist = tolist ? add(cp, add(", ", tolist)) :
+ getcpy(cp);
+ }
+
+ if (tolist == NULL)
+ adios(NULL, "usage: %s addrs ... [switches]", invo_name);
+
+ tfile = m_mktemp2("/tmp/", invo_name, NULL, &out);
+ if (tfile == NULL)
+ adios("mhmail", "unable to create temporary file");
+ chmod(tfile, 0600);
+ strncpy(tmpfil, tfile, sizeof(tmpfil));
+
+ SIGNAL2(SIGINT, intrser);
+
+ fprintf(out, "%sTo: %s\n", resent ? "Resent-" : "", tolist);
+ if (cclist)
+ fprintf(out, "%sCc: %s\n", resent ? "Resent-" : "", cclist);
+ if (subject)
+ fprintf(out, "%sSubject: %s\n", resent ? "Resent-" : "", subject);
+ if (from)
+ fprintf(out, "%sFrom: %s\n", resent ? "Resent-" : "", from);
+ if (!resent)
+ fputs("\n", out);
+
+ if (body) {
+ fprintf(out, "%s", body);
+ if (*body && *(body + strlen(body) - 1) != '\n')
+ fputs("\n", out);
+ } else {
+ for (somebody = 0; (i = fread(buf, sizeof(*buf), sizeof(buf),
+ stdin)) > 0; somebody++)
+ if (fwrite(buf, sizeof(*buf), i, out) != i)
+ adios(tmpfil, "error writing");
+ if (!somebody) {
+ unlink(tmpfil);
+ done(1);
+ }