X-Git-Url: http://git.marmaro.de/?a=blobdiff_plain;f=uip%2Fshow.c;h=ff2043589e0f669c427fa831a83c8ae16f721f0b;hb=3afd424b248b00353486cc9b3d25fc1e4bc04cdd;hp=d656bf9527bde71eeb1dde83d641d4e1a70d0026;hpb=8563731b02ce9d750806f6b1769af8b399d964e8;p=mmh diff --git a/uip/show.c b/uip/show.c index d656bf9..ff20435 100644 --- a/uip/show.c +++ b/uip/show.c @@ -2,11 +2,14 @@ /* * show.c -- show/list messages * - * $Id$ + * 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 static struct swit switches[] = { #define CHECKMIMESW 0 @@ -37,9 +40,13 @@ static struct swit switches[] = { { "draft", 0 }, #define FILESW 13 { "file file", -4 }, /* interface from showfile */ -#define VERSIONSW 14 +#define FMTPROCSW 14 + { "fmtproc program", 0 }, +#define NFMTPROCSW 15 + { "nofmtproc", 0 }, +#define VERSIONSW 16 { "version", 0 }, -#define HELPSW 15 +#define HELPSW 17 { "help", 0 }, { NULL, 0 } }; @@ -49,9 +56,6 @@ static struct swit switches[] = { */ static int is_nontext(char *); -/* prototype from mhlsbr.c */ -int mhl (int, char **); - #define SHOW 0 #define NEXT 1 #define PREV 2 @@ -60,25 +64,28 @@ int mhl (int, char **); int main (int argc, char **argv) { - int draftsw = 0, headersw = 1, msgp = 0; + int draftsw = 0, headersw = 1; int nshow = 0, checkmime = 1, mime; - int vecp = 1, procp = 1, isdf = 0, mode = SHOW, msgnum; + int procp = 1, isdf = 0, mode = SHOW, msgnum; char *cp, *maildir, *file = NULL, *folder = NULL, *proc; char buf[BUFSIZ], **argp, **arguments; - char *msgs[MAXARGS], *vec[MAXARGS]; - struct msgs *mp; + struct msgs *mp = NULL; + struct msgs_array msgs = { 0, 0, NULL }; + struct msgs_array vec = { 0, 0, NULL }; #ifdef LOCALE setlocale(LC_ALL, ""); #endif invo_name = r1bindex (argv[0], '/'); + app_msgarg(&vec, NULL); /* placeholder, filled later with proc name */ + /* read user profile/context */ context_read(); - if (!strcasecmp (invo_name, "next")) { + if (!mh_strcasecmp (invo_name, "next")) { mode = NEXT; - } else if (!strcasecmp (invo_name, "prev")) { + } else if (!mh_strcasecmp (invo_name, "prev")) { mode = PREV; } arguments = getarguments (invo_name, argc, argv, 1); @@ -92,7 +99,8 @@ main (int argc, char **argv) done (1); case UNKWNSW: case NPROGSW: - vec[vecp++] = --cp; + case NFMTPROCSW: + app_msgarg(&vec, --cp); continue; case HELPSW: @@ -100,10 +108,10 @@ main (int argc, char **argv) "%s [+folder] %s[switches] [switches for showproc]", invo_name, mode == SHOW ? "[msgs] ": ""); print_help (buf, switches, 1); - done (1); + done (0); case VERSIONSW: print_version(invo_name); - done (1); + done (0); case DRFTSW: if (file) @@ -133,19 +141,20 @@ usage: continue; case FORMSW: - vec[vecp++] = --cp; + app_msgarg(&vec, --cp); if (!(cp = *argp++) || *cp == '-') adios (NULL, "missing argument to %s", argp[-2]); - vec[vecp++] = getcpy (etcpath(cp)); + app_msgarg(&vec, getcpy (etcpath(cp))); continue; case PROGSW: case LENSW: case WIDTHSW: - vec[vecp++] = --cp; + case FMTPROCSW: + app_msgarg(&vec, --cp); if (!(cp = *argp++) || *cp == '-') adios (NULL, "missing argument to %s", argp[-2]); - vec[vecp++] = cp; + app_msgarg(&vec, cp); continue; case SHOWSW: @@ -174,46 +183,47 @@ usage: if (folder) adios (NULL, "only one folder at a time!"); else - folder = path (cp + 1, *cp == '+' ? TFOLDER : TSUBCWF); + folder = pluspath (cp); } else { if (mode != SHOW) goto usage; else - msgs[msgp++] = cp; + app_msgarg(&msgs, cp); } } - procp = vecp; + procp = vec.size; if (!context_find ("path")) free (path ("./", TFOLDER)); if (draftsw || file) { - if (msgp) + if (msgs.size) adios (NULL, "only one file at a time!"); - vec[vecp++] = draftsw - ? getcpy (m_draft (folder, msgp ? msgs[0] : NULL, 1, &isdf)) - : file; + if (draftsw) + app_msgarg(&vec, getcpy (m_draft (folder, NULL, 1, &isdf))); + else + app_msgarg(&vec, file); goto go_to_it; } #ifdef WHATNOW - if (!msgp && !folder && mode == SHOW && (cp = getenv ("mhdraft")) && *cp) { + if (!msgs.size && !folder && mode == SHOW && (cp = getenv ("mhdraft")) && *cp) { draftsw++; - vec[vecp++] = cp; + app_msgarg(&vec, cp); goto go_to_it; } #endif /* WHATNOW */ - if (!msgp) { + if (!msgs.size) { switch (mode) { case NEXT: - msgs[msgp++] = "next"; + app_msgarg(&msgs, "next"); break; case PREV: - msgs[msgp++] = "prev"; + app_msgarg(&msgs, "prev"); break; default: - msgs[msgp++] = "cur"; + app_msgarg(&msgs, "cur"); break; } } @@ -234,8 +244,8 @@ usage: adios (NULL, "no messages in %s", folder); /* parse all the message ranges/sequences and set SELECTED */ - for (msgnum = 0; msgnum < msgp; msgnum++) - if (!m_convert (mp, msgs[msgnum])) + for (msgnum = 0; msgnum < msgs.size; msgnum++) + if (!m_convert (mp, msgs.msgs[msgnum])) done (1); /* @@ -250,26 +260,21 @@ usage: seq_setprev (mp); /* set the Previous-Sequence */ seq_setunseen (mp, 1); /* unset the Unseen-Sequence */ - if (mp->numsel > MAXARGS - 2) - adios (NULL, "more than %d messages for show exec", MAXARGS - 2); - for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) if (is_selected(mp, msgnum)) - vec[vecp++] = getcpy (m_name (msgnum)); + app_msgarg(&vec, getcpy (m_name (msgnum))); seq_setcur (mp, mp->hghsel); /* update current message */ seq_save (mp); /* synchronize sequences */ context_replace (pfolder, folder); /* update current folder */ context_save (); /* save the context file */ - if (headersw && vecp == 2) - printf ("(Message %s:%s)\n", folder, vec[1]); + if (headersw && vec.size == 2) + printf ("(Message %s:%s)\n", folder, vec.msgs[1]); go_to_it: ; fflush (stdout); - vec[vecp] = NULL; - /* * Decide which "proc" to use */ @@ -278,7 +283,7 @@ go_to_it: ; proc = catproc; } else { /* check if any messages are non-text MIME messages */ - if (checkmime && !getenv ("NOMHNPROC")) { + if (checkmime) { if (!draftsw && !file) { /* loop through selected messages and check for MIME */ for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) @@ -288,7 +293,7 @@ go_to_it: ; } } else { /* check the file or draft for MIME */ - if (is_nontext (vec[vecp - 1])) + if (is_nontext (vec.msgs[vec.size - 1])) mime = 1; } } @@ -303,36 +308,25 @@ go_to_it: ; if (folder && !draftsw && !file) m_putenv ("mhfolder", folder); - /* - * For backward compatibility, if the "proc" is mhn, - * then add "-show" option. Add "-file" if showing - * file or draft. - */ if (strcmp (r1bindex (proc, '/'), "mhn") == 0) { + /* Add "-file" if showing file or draft, */ if (draftsw || file) { - vec[vecp] = vec[vecp - 1]; - vec[vecp - 1] = "-file"; - vecp++; + app_msgarg(&vec, vec.msgs[vec.size - 1]); + vec.msgs[vec.size - 2] = "-file"; } - vec[vecp++] = "-show"; - vec[vecp] = NULL; - } - - /* If the "proc" is "mhshow", add "-file" if showing file or draft. - */ - if (strcmp (r1bindex (proc, '/'), "mhshow") == 0 && (draftsw || file) ) { - vec[vecp] = vec[vecp - 1]; - vec[vecp - 1] = "-file"; - vec[++vecp] = NULL; - } - - /* - * If "proc" is mhl, then run it internally - * rather than exec'ing it. - */ - if (strcmp (r1bindex (proc, '/'), "mhl") == 0) { - vec[0] = "mhl"; - mhl (vecp, vec); + /* and add -show for backward compatibility */ + app_msgarg(&vec, "-show"); + } else if (strcmp (r1bindex (proc, '/'), "mhshow") == 0) { + /* If "mhshow", add "-file" if showing file or draft. */ + if (draftsw || file) { + app_msgarg(&vec, vec.msgs[vec.size - 1]); + vec.msgs[vec.size - 2] = "-file"; + } + } else if (strcmp (r1bindex (proc, '/'), "mhl") == 0) { + /* If "mhl", then run it internally */ + vec.msgs[0] = "mhl"; + app_msgarg(&vec, NULL); + mhl (vec.size, vec.msgs); done (0); } @@ -349,29 +343,17 @@ go_to_it: ; cp = ssequal (maildir, mp->foldpath) ? mp->foldpath + strlen (maildir) : mp->foldpath; - for (msgnum = procp; msgnum < vecp; msgnum++) - vec[msgnum] = concat (cp, vec[msgnum], NULL); + for (msgnum = procp; msgnum < vec.size; msgnum++) + vec.msgs[msgnum] = concat (cp, vec.msgs[msgnum], NULL); } - vec[0] = r1bindex (proc, '/'); - execvp (proc, vec); + vec.msgs[0] = r1bindex (proc, '/'); + app_msgarg(&vec, NULL); + execvp (proc, vec.msgs); adios (proc, "unable to exec"); return 0; /* dead code to satisfy the compiler */ } -/* - * Cheat: we are loaded with adrparse, which wants a routine called - * OfficialName(). We call adrparse:getm() with the correct arguments - * to prevent OfficialName() from being called. Hence, the following - * is to keep the loader happy. - */ - -char * -OfficialName (char *name) -{ - return name; -} - /* * Check if a message or file contains any non-text parts @@ -380,7 +362,8 @@ static int is_nontext (char *msgnam) { int result, state; - char *bp, *cp, *dp; + unsigned char *bp, *dp; + char *cp; char buf[BUFSIZ], name[NAMESZ]; FILE *fp; @@ -395,7 +378,7 @@ is_nontext (char *msgnam) /* * Check Content-Type field */ - if (!strcasecmp (name, TYPE_FIELD)) { + if (!mh_strcasecmp (name, TYPE_FIELD)) { int passno; char c; @@ -450,7 +433,7 @@ invalid: if (!*bp) goto invalid; if (passno > 1) { - if ((result = (strcasecmp (bp, "plain") != 0))) + if ((result = (mh_strcasecmp (bp, "plain") != 0))) goto out; *dp = c; for (dp++; isspace (*dp); dp++) @@ -470,7 +453,7 @@ invalid: *bp = '\0'; } else { for (bp = dp; *bp; bp++) - if (isspace (*bp)) { + if (!istoken (*bp)) { *bp = '\0'; break; } @@ -482,7 +465,7 @@ invalid: /* Check the character set */ result = !check_charset (dp, strlen (dp)); } else { - if (!(result = (strcasecmp (bp, "text") != 0))) { + if (!(result = (mh_strcasecmp (bp, "text") != 0))) { *dp = c; bp = dp; passno = 2; @@ -501,7 +484,7 @@ out: /* * Check Content-Transfer-Encoding field */ - if (!strcasecmp (name, ENCODING_FIELD)) { + if (!mh_strcasecmp (name, ENCODING_FIELD)) { cp = add (buf, NULL); while (state == FLDPLUS) { state = m_getfld (state, name, buf, sizeof(buf), fp); @@ -512,9 +495,9 @@ out: for (dp = bp; istoken (*dp); dp++) continue; *dp = '\0'; - result = (strcasecmp (bp, "7bit") - && strcasecmp (bp, "8bit") - && strcasecmp (bp, "binary")); + result = (mh_strcasecmp (bp, "7bit") + && mh_strcasecmp (bp, "8bit") + && mh_strcasecmp (bp, "binary")); free (cp); if (result) {