|
|
1.1 ! root 1: /* anno.c - annotate messages */ ! 2: ! 3: #include "../h/mh.h" ! 4: #include <ctype.h> ! 5: #include <stdio.h> ! 6: ! 7: static void make_comp(); ! 8: ! 9: /* */ ! 10: ! 11: static struct swit switches[] = { ! 12: #define COMPSW 0 ! 13: "component field", 0, ! 14: ! 15: #define INPLSW 1 ! 16: "inplace", 0, ! 17: #define NINPLSW 2 ! 18: "noinplace", 0, ! 19: ! 20: #define TEXTSW 3 ! 21: "text body", 0, ! 22: ! 23: #define HELPSW 4 ! 24: "help", 4, ! 25: ! 26: NULL, NULL ! 27: }; ! 28: ! 29: /* */ ! 30: ! 31: /* ARGSUSED */ ! 32: ! 33: main(argc, argv) ! 34: int argc; ! 35: char **argv; ! 36: { ! 37: int inplace = 0, ! 38: msgp = 0, ! 39: msgnum; ! 40: char *cp, ! 41: *maildir, ! 42: *comp = NULL, ! 43: *text = NULL, ! 44: *folder = NULL, ! 45: buf[100], ! 46: **ap, ! 47: **argp, ! 48: *arguments[MAXARGS], ! 49: *msgs[MAXARGS]; ! 50: struct msgs *mp; ! 51: ! 52: invo_name = r1bindex (argv[0], '/'); ! 53: if ((cp = m_find (invo_name)) != NULL) { ! 54: ap = brkstring (cp = getcpy (cp), " ", "\n"); ! 55: ap = copyip (ap, arguments); ! 56: } ! 57: else ! 58: ap = arguments; ! 59: (void) copyip (argv + 1, ap); ! 60: argp = arguments; ! 61: ! 62: /* */ ! 63: ! 64: while (cp = *argp++) { ! 65: if (*cp == '-') ! 66: switch (smatch (++cp, switches)) { ! 67: case AMBIGSW: ! 68: ambigsw (cp, switches); ! 69: done (1); ! 70: case UNKWNSW: ! 71: adios (NULLCP, "-%s unknown", cp); ! 72: case HELPSW: ! 73: (void) sprintf (buf, "%s [+folder] [msgs] [switches]", ! 74: invo_name); ! 75: help (buf, switches); ! 76: done (1); ! 77: ! 78: case COMPSW: ! 79: if (comp) ! 80: adios (NULLCP, "only one component at a time!"); ! 81: if (!(comp = *argp++) || *comp == '-') ! 82: adios (NULLCP, "missing argument to %s", argp[-2]); ! 83: continue; ! 84: ! 85: case INPLSW: ! 86: inplace++; ! 87: continue; ! 88: case NINPLSW: ! 89: inplace = 0; ! 90: continue; ! 91: ! 92: case TEXTSW: ! 93: if (text) ! 94: adios (NULLCP, "only one body at a time!"); ! 95: if (!(text = *argp++) || *text == '-') ! 96: adios (NULLCP, "missing argument to %s", argp[-2]); ! 97: continue; ! 98: } ! 99: if (*cp == '+' || *cp == '@') { ! 100: if (folder) ! 101: adios (NULLCP, "only one folder at a time!"); ! 102: else ! 103: folder = path (cp + 1, *cp == '+' ? TFOLDER : TSUBCWF); ! 104: } ! 105: else ! 106: msgs[msgp++] = cp; ! 107: } ! 108: ! 109: /* */ ! 110: ! 111: if (!m_find ("path")) ! 112: free (path ("./", TFOLDER)); ! 113: if (!msgp) ! 114: msgs[msgp++] = "cur"; ! 115: if (!folder) ! 116: folder = m_getfolder (); ! 117: maildir = m_maildir (folder); ! 118: ! 119: if (chdir (maildir) == NOTOK) ! 120: adios (maildir, "unable to change directory to"); ! 121: if (!(mp = m_gmsg (folder))) ! 122: adios (NULLCP, "unable to read folder %s", folder); ! 123: if (mp -> hghmsg == 0) ! 124: adios (NULLCP, "no messages in %s", folder); ! 125: ! 126: for (msgnum = 0; msgnum < msgp; msgnum++) ! 127: if (!m_convert (mp, msgs[msgnum])) ! 128: done (1); ! 129: ! 130: make_comp (&comp); ! 131: ! 132: for (msgnum = mp -> lowsel; msgnum <= mp -> hghsel; msgnum++) ! 133: if (mp -> msgstats[msgnum] & SELECTED) ! 134: (void) annotate (m_name (msgnum), comp, text, inplace); ! 135: ! 136: m_replace (pfolder, folder); ! 137: if (mp -> lowsel != mp -> curmsg) ! 138: m_setcur (mp, mp -> lowsel); ! 139: m_sync (mp); ! 140: m_update (); ! 141: ! 142: done (0); ! 143: } ! 144: ! 145: /* */ ! 146: ! 147: static void ! 148: make_comp(ap) ! 149: register char **ap; ! 150: { ! 151: register char *cp; ! 152: char buffer[BUFSIZ]; ! 153: ! 154: if (*ap == NULL) { ! 155: printf ("Enter component name: "); ! 156: (void) fflush (stdout); ! 157: ! 158: if (fgets (buffer, sizeof buffer, stdin) == NULL) ! 159: done (1); ! 160: *ap = trimcpy (buffer); ! 161: } ! 162: ! 163: if ((cp = *ap + strlen (*ap) - 1) > *ap && *cp == ':') ! 164: *cp = NULL; ! 165: if (strlen (*ap) == 0) ! 166: adios (NULLCP, "null component name"); ! 167: if (**ap == '-') ! 168: adios (NULLCP, "invalid component name %s", *ap); ! 169: if (strlen (*ap) >= NAMESZ) ! 170: adios (NULLCP, "too large component name %s", *ap); ! 171: ! 172: for (cp = *ap; *cp; cp++) ! 173: if (!isalnum (*cp) && *cp != '-') ! 174: adios (NULLCP, "invalid component name %s", *ap); ! 175: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.