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

Defined functions

main defined in line 31; never used
make_comp defined in line 145; used 1 times

Defined variables

switches defined in line 9; used 3 times

Defined macros

COMPSW defined in line 10; never used
HELPSW defined in line 21; never used
INPLSW defined in line 13; never used
NINPLSW defined in line 15; never used
TEXTSW defined in line 18; never used
Last modified: 1985-09-08
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1187
Valid CSS Valid XHTML 1.0 Strict