X-Git-Url: https://diplodocus.org/git/nmh/blobdiff_plain/aad5d20016b28bb8c28592c1ebe4213aafaa43c3..670a0d84c25b458bbb348d2a1ecee178cfa6c226:/uip/show.c diff --git a/uip/show.c b/uip/show.c index f8910785..699b77b0 100644 --- a/uip/show.c +++ b/uip/show.c @@ -1,14 +1,40 @@ -/* - * show.c -- show/list messages +/* show.c -- show/list messages * * This code is Copyright (c) 2002, by the authors of nmh. See the * COPYRIGHT file in the root directory of the nmh distribution for * complete copyright information. */ -#include -#include -#include +#include "h/mh.h" +#include "mhlsbr.h" +#include "sbr/m_name.h" +#include "sbr/m_getfld.h" +#include "sbr/getarguments.h" +#include "sbr/seq_setunseen.h" +#include "sbr/seq_setprev.h" +#include "sbr/seq_setcur.h" +#include "sbr/seq_save.h" +#include "sbr/smatch.h" +#include "sbr/r1bindex.h" +#include "sbr/uprf.h" +#include "sbr/check_charset.h" +#include "sbr/m_draft.h" +#include "sbr/m_convert.h" +#include "sbr/getfolder.h" +#include "sbr/folder_read.h" +#include "sbr/context_save.h" +#include "sbr/context_replace.h" +#include "sbr/context_find.h" +#include "sbr/ambigsw.h" +#include "sbr/path.h" +#include "sbr/print_version.h" +#include "sbr/print_help.h" +#include "sbr/arglist.h" +#include "sbr/error.h" +#include "h/mime.h" +#include "h/done.h" +#include "h/utils.h" +#include "sbr/m_maildir.h" #define SHOW_SWITCHES \ X("checkmime", 0, CHECKMIMESW) \ @@ -32,8 +58,17 @@ /* \ * switches for mhlproc \ */ \ - X("concat", -6, CONCATSW) \ - X("noconcat", -8, NCONCATSW) \ + X("concat", 0, CONCATSW) \ + X("noconcat", 0, NCONCATSW) \ + /* \ + * switches for mhshow \ + */ \ + X("part number", 0, PARTSW) \ + X("type content", 0, TYPESW) \ + X("prefer content", 0, PREFERSW) \ + X("markform file", 0, MARKFORMSW) \ + X("rcache policy", 0, RCACHESW) \ + X("wcache policy", 0, WCACHESW) \ #define X(sw, minchars, id) id, DEFINE_SWITCH_ENUM(SHOW); @@ -56,8 +91,11 @@ static int is_nontext(char *); int main (int argc, char **argv) { - int draftsw = 0, headersw = 1; - int nshow = 0, checkmime = 1, mime = 0; + bool draftsw = false; + bool headersw = true; + bool nshow = false; + bool checkmime = true; + bool mime = false; int isdf = 0, mode = SHOW, msgnum; char *cp, *maildir, *file = NULL, *folder = NULL, *proc, *program; char buf[BUFSIZ], **argp, **arguments; @@ -65,7 +103,7 @@ main (int argc, char **argv) struct msgs_array msgs = { 0, 0, NULL }; struct msgs_array vec = { 0, 0, NULL }, non_mhl_vec = { 0, 0, NULL }; - if (nmh_init(argv[0], 1)) { return 1; } + if (nmh_init(argv[0], true, true)) { return 1; } if (!strcasecmp (invo_name, "next")) { mode = NEXT; @@ -83,10 +121,11 @@ main (int argc, char **argv) done (1); case HEADSW: - headersw = 1; + headersw = true; goto non_mhl_switches; case NHEADSW: - headersw = 0; + headersw = false; + /* FALLTHRU */ case CONCATSW: case NCONCATSW: non_mhl_switches: @@ -112,73 +151,76 @@ non_mhl_switches: case DRFTSW: if (file) - adios (NULL, "only one file at a time!"); - draftsw++; + die("only one file at a time!"); + draftsw = true; if (mode == SHOW) continue; usage: - adios (NULL, - "usage: %s [+folder] [switches] [switches for showproc]", + die( "usage: %s [+folder] [switches] [switches for showproc]", invo_name); case FILESW: if (mode != SHOW) goto usage; if (draftsw || file) - adios (NULL, "only one file at a time!"); + die("only one file at a time!"); if (!(cp = *argp++) || *cp == '-') - adios (NULL, "missing argument to %s", argp[-2]); + die("missing argument to %s", argp[-2]); file = path (cp, TFILE); continue; case FORMSW: app_msgarg(&vec, --cp); if (!(cp = *argp++) || *cp == '-') - adios (NULL, "missing argument to %s", argp[-2]); - app_msgarg(&vec, getcpy (etcpath(cp))); + die("missing argument to %s", argp[-2]); + app_msgarg(&vec, mh_xstrdup(etcpath(cp))); continue; case PROGSW: case LENSW: case WIDTHSW: case FMTPROCSW: + case PARTSW: + case TYPESW: + case PREFERSW: + case MARKFORMSW: + case RCACHESW: + case WCACHESW: app_msgarg(&vec, --cp); if (!(cp = *argp++) || *cp == '-') - adios (NULL, "missing argument to %s", argp[-2]); + die("missing argument to %s", argp[-2]); app_msgarg(&vec, cp); continue; case SHOWSW: if (!(showproc = *argp++) || *showproc == '-') - adios (NULL, "missing argument to %s", argp[-2]); - nshow = 0; + die("missing argument to %s", argp[-2]); + nshow = false; continue; case NSHOWSW: - nshow++; + nshow = true; continue; case SHOWMIMESW: if (!(showmimeproc = *argp++) || *showmimeproc == '-') - adios (NULL, "missing argument to %s", argp[-2]); - nshow = 0; + die("missing argument to %s", argp[-2]); + nshow = false; continue; case CHECKMIMESW: - checkmime++; + checkmime = true; continue; case NOCHECKMIMESW: - checkmime = 0; + checkmime = false; continue; } } if (*cp == '+' || *cp == '@') { if (folder) - adios (NULL, "only one folder at a time!"); - else - folder = pluspath (cp); + die("only one folder at a time!"); + folder = pluspath (cp); } else { if (mode != SHOW) goto usage; - else - app_msgarg(&msgs, cp); + app_msgarg(&msgs, cp); } } @@ -187,12 +229,12 @@ usage: if (draftsw || file) { if (msgs.size) - adios (NULL, "only one file at a time!"); + die("only one file at a time!"); if (draftsw) - app_msgarg(&vec, getcpy (m_draft (folder, NULL, 1, &isdf))); + app_msgarg(&vec, mh_xstrdup(m_draft(folder, NULL, 1, &isdf))); else app_msgarg(&vec, file); - headersw = 0; + headersw = false; goto go_to_it; } @@ -219,11 +261,11 @@ usage: /* read folder and create message structure */ if (!(mp = folder_read (folder, 1))) - adios (NULL, "unable to read folder %s", folder); + die("unable to read folder %s", folder); /* check for empty folder */ if (mp->nummsg == 0) - adios (NULL, "no messages in %s", folder); + die("no messages in %s", folder); /* parse all the message ranges/sequences and set SELECTED */ for (msgnum = 0; msgnum < msgs.size; msgnum++) @@ -244,7 +286,7 @@ usage: for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) if (is_selected(mp, msgnum)) - app_msgarg(&vec, getcpy (m_name (msgnum))); + app_msgarg(&vec, mh_xstrdup(m_name (msgnum))); seq_setcur (mp, mp->hghsel); /* update current message */ seq_save (mp); /* synchronize sequences */ @@ -265,13 +307,13 @@ go_to_it: ; /* loop through selected messages and check for MIME */ for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) if (is_selected (mp, msgnum) && is_nontext (m_name (msgnum))) { - mime = 1; + mime = true; break; } } else { /* check the file or draft for MIME */ if (is_nontext (vec.msgs[vec.size - 1])) - mime = 1; + mime = true; } } @@ -283,7 +325,7 @@ go_to_it: ; } if (folder && !draftsw && !file) - m_putenv ("mhfolder", folder); + setenv("mhfolder", folder, 1); if (strcmp (r1bindex (proc, '/'), "cat") == 0) { @@ -353,16 +395,16 @@ is_nontext (char *msgnam) { int result, state; char *bp, *dp, *cp; - char buf[BUFSIZ], name[NAMESZ]; + char buf[NMH_BUFSIZ], name[NAMESZ]; FILE *fp; - m_getfld_state_t gstate = 0; + m_getfld_state_t gstate; if ((fp = fopen (msgnam, "r")) == NULL) return 0; - + gstate = m_getfld_state_init(fp); for (;;) { int bufsz = sizeof buf; - switch (state = m_getfld (&gstate, name, buf, &bufsz, fp)) { + switch (state = m_getfld2(&gstate, name, buf, &bufsz)) { case FLD: case FLDPLUS: /* @@ -372,10 +414,10 @@ is_nontext (char *msgnam) int passno; char c; - cp = add (buf, NULL); + cp = mh_xstrdup(buf); while (state == FLDPLUS) { bufsz = sizeof buf; - state = m_getfld (&gstate, name, buf, &bufsz, fp); + state = m_getfld2(&gstate, name, buf, &bufsz); cp = add (buf, cp); } bp = cp; @@ -399,7 +441,7 @@ invalid: continue; case '(': i++; - /* and fall... */ + continue; default: continue; case ')': @@ -432,7 +474,7 @@ invalid: if (*dp) { if ((result = !uprf (dp, "charset"))) goto out; - dp += sizeof("charset") - 1; + dp += LEN("charset"); while (isspace ((unsigned char) *dp)) dp++; if (*dp++ != '=') @@ -477,10 +519,10 @@ out: * Check Content-Transfer-Encoding field */ if (!strcasecmp (name, ENCODING_FIELD)) { - cp = add (buf, NULL); + cp = mh_xstrdup(buf); while (state == FLDPLUS) { bufsz = sizeof buf; - state = m_getfld (&gstate, name, buf, &bufsz, fp); + state = m_getfld2(&gstate, name, buf, &bufsz); cp = add (buf, cp); } for (bp = cp; isspace ((unsigned char) *bp); bp++) @@ -507,7 +549,7 @@ out: */ while (state == FLDPLUS) { bufsz = sizeof buf; - state = m_getfld (&gstate, name, buf, &bufsz, fp); + state = m_getfld2(&gstate, name, buf, &bufsz); } break;