1: /* comp.c - compose a message */
   2: 
   3: #include "../h/mh.h"
   4: #include <stdio.h>
   5: #include <sys/types.h>
   6: #include <sys/stat.h>
   7: 
   8: /*  */
   9: 
  10: static struct swit switches[] = {
  11: #define DFOLDSW 0
  12:     "draftfolder +folder", 0,
  13: #define DMSGSW  1
  14:     "draftmessage msg", 0,
  15: #define NDFLDSW 2
  16:     "nodraftfolder", 0,
  17: 
  18: #define EDITRSW 3
  19:     "editor editor", 0,
  20: #define NEDITSW 4
  21:     "noedit", 0,
  22: 
  23: #define FILESW  5
  24:     "file file", 0,
  25: #define FORMSW  6
  26:     "form formfile", 0,
  27: 
  28: #define USESW   7
  29:     "use", 0,
  30: #define NUSESW  8
  31:     "nouse", 0,
  32: 
  33: #define WHATSW  9
  34:     "whatnowproc program", 0,
  35: #define NWHATSW 10
  36:     "nowhatnowproc", 0,
  37: 
  38: #define HELPSW  11
  39:     "help", 4,
  40: 
  41: 
  42:     NULL, NULL
  43: };
  44: 
  45: /*  */
  46: 
  47: static struct swit aqrunl[] = {
  48: #define NOSW    0
  49:     "quit", 0,
  50: #define YESW    1
  51:     "replace", 0,
  52: #define USELSW  2
  53:     "use", 0,
  54: #define LISTDSW 3
  55:     "list", 0,
  56: #define REFILSW 4
  57:     "refile +folder", 0,
  58: #define NEWSW   5
  59:     "new", 0,
  60: 
  61:     NULL, NULL
  62: };
  63: 
  64: 
  65: static struct swit aqrul[] = {
  66:     "quit", 0,
  67:     "replace", 0,
  68:     "use", 0,
  69:     "list", 0,
  70:     "refile", 0,
  71: 
  72:     NULL, NULL
  73: };
  74: 
  75: /*  */
  76: 
  77: /* ARGSUSED */
  78: 
  79: main (argc, argv)
  80: int     argc;
  81: char   *argv[];
  82: {
  83:     int     use = NOUSE,
  84:             nedit = 0,
  85:         nwhat = 0,
  86:             i,
  87:             in,
  88:         isdf = 0,
  89:             out;
  90:     char   *cp,
  91:            *cwd,
  92:            *maildir,
  93:            *dfolder = NULL,
  94:            *ed = NULL,
  95:            *file = NULL,
  96:            *form = NULL,
  97:            *folder = NULL,
  98:            *msg = NULL,
  99:             buf[BUFSIZ],
 100:             drft[BUFSIZ],
 101:           **ap,
 102:           **argp,
 103:            *arguments[MAXARGS];
 104:     struct msgs *mp = NULL;
 105:     struct stat st;
 106: 
 107:     invo_name = r1bindex (argv[0], '/');
 108:     if ((cp = m_find (invo_name)) != NULL) {
 109:     ap = brkstring (cp = getcpy (cp), " ", "\n");
 110:     ap = copyip (ap, arguments);
 111:     }
 112:     else
 113:     ap = arguments;
 114:     (void) copyip (argv + 1, ap);
 115:     argp = arguments;
 116: 
 117: /*  */
 118: 
 119:     while (cp = *argp++) {
 120:     if (*cp == '-')
 121:         switch (smatch (++cp, switches)) {
 122:         case AMBIGSW:
 123:             ambigsw (cp, switches);
 124:             done (1);
 125:         case UNKWNSW:
 126:             adios (NULLCP, "-%s unknown", cp);
 127:         case HELPSW:
 128:             (void) sprintf (buf, "%s [+folder] [msg] [switches]",
 129:                 invo_name);
 130:             help (buf, switches);
 131:             done (1);
 132: 
 133:         case EDITRSW:
 134:             if (!(ed = *argp++) || *ed == '-')
 135:             adios (NULLCP, "missing argument to %s", argp[-2]);
 136:             nedit = 0;
 137:             continue;
 138:         case NEDITSW:
 139:             nedit++;
 140:             continue;
 141: 
 142:         case WHATSW:
 143:             if (!(whatnowproc = *argp++) || *whatnowproc == '-')
 144:             adios (NULLCP, "missing argument to %s", argp[-2]);
 145:             nwhat = 0;
 146:             continue;
 147:         case NWHATSW:
 148:             nwhat++;
 149:             continue;
 150: 
 151:         case FORMSW:
 152:             if (!(form = *argp++) || *form == '-')
 153:             adios (NULLCP, "missing argument to %s", argp[-2]);
 154:             continue;
 155: 
 156:         case USESW:
 157:             use++;
 158:             continue;
 159:         case NUSESW:
 160:             use = NOUSE;
 161:             continue;
 162: 
 163:         case FILESW:    /* compatibility */
 164:             if (file)
 165:             adios (NULLCP, "only one file at a time!");
 166:             if (!(file = *argp++) || *file == '-')
 167:             adios (NULLCP, "missing argument to %s", argp[-2]);
 168:             continue;
 169: 
 170:         case DFOLDSW:
 171:             if (dfolder)
 172:             adios (NULLCP, "only one draft folder at a time!");
 173:             if (!(cp = *argp++) || *cp == '-')
 174:             adios (NULLCP, "missing argument to %s", argp[-2]);
 175:             dfolder = path (*cp == '+' || *cp == '@' ? cp + 1 : cp,
 176:                 *cp != '@' ? TFOLDER : TSUBCWF);
 177:             continue;
 178:         case DMSGSW:
 179:             if (file)
 180:             adios (NULLCP, "only one draft message at a time!");
 181:             if (!(file = *argp++) || *file == '-')
 182:             adios (NULLCP, "missing argument to %s", argp[-2]);
 183:             continue;
 184:         case NDFLDSW:
 185:             dfolder = NULL;
 186:             isdf = NOTOK;
 187:             continue;
 188:         }
 189:     if (*cp == '+' || *cp == '@') {
 190:         if (folder)
 191:         adios (NULLCP, "only one folder at a time!");
 192:         else
 193:         folder = path (cp + 1, *cp == '+' ? TFOLDER : TSUBCWF);
 194:     }
 195:     else
 196:         if (msg)
 197:         adios (NULLCP, "only one message at a time!");
 198:         else
 199:         msg = cp;
 200:     }
 201: 
 202: /*  */
 203: 
 204:     cwd = getcpy (pwd ());
 205: 
 206:     if (!m_find ("path"))
 207:     free (path ("./", TFOLDER));
 208: 
 209:     if ((dfolder || m_find ("Draft-Folder")) && !folder && msg && !file)
 210:     file = msg, msg = NULL;
 211:     if (form && (folder || msg))
 212:         adios (NULLCP, "can't mix forms and folders/msgs");
 213: 
 214:     if (folder || msg) {
 215:     if (!msg)
 216:         msg = "cur";
 217:     if (!folder)
 218:         folder = m_getfolder ();
 219:     maildir = m_maildir (folder);
 220: 
 221:     if (chdir (maildir) == NOTOK)
 222:         adios (maildir, "unable to change directory to");
 223:     if (!(mp = m_gmsg (folder)))
 224:         adios (NULLCP, "unable to read folder %s", folder);
 225:     if (mp -> hghmsg == 0)
 226:         adios (NULLCP, "no messages in %s", folder);
 227: 
 228:     if (!m_convert (mp, msg))
 229:         done (1);
 230:     m_setseq (mp);
 231: 
 232:     if (mp -> numsel > 1)
 233:         adios (NULLCP, "only one message at a time!");
 234: 
 235:     if ((in = open (form = getcpy (m_name (mp -> lowsel)), 0)) == NOTOK)
 236:         adios (form, "unable to open message");
 237:     }
 238:     else
 239:     if (form) {
 240:         if ((in = open (libpath (form), 0)) == NOTOK)
 241:         adios (form, "unable to open form file");
 242:     }
 243:     else {
 244:         if ((in = open (libpath (components), 0)) == NOTOK)
 245:         adios (components, "unable to open default components file");
 246:         form = components;
 247:     }
 248: 
 249: /*  */
 250: 
 251: try_it_again: ;
 252:     (void) strcpy (drft, m_draft (dfolder, file, use, &isdf));
 253:     if ((out = open (drft, 0)) != NOTOK) {
 254:     i = fdcompare (in, out);
 255:     (void) close (out);
 256:     if (use || i)
 257:         goto edit_it;
 258: 
 259:     if (stat (drft, &st) == NOTOK)
 260:         adios (drft, "unable to stat");
 261:     printf ("Draft \"%s\" exists (%ld bytes).", drft, st.st_size);
 262:     for (i = LISTDSW; i != YESW;) {
 263:         if (!(argp = getans ("\nDisposition? ", isdf ? aqrunl : aqrul)))
 264:         done (1);
 265:         switch (i = smatch (*argp, isdf ? aqrunl : aqrul)) {
 266:         case NOSW:
 267:             done (0);
 268:         case NEWSW:
 269:             file = NULL;
 270:             use = NOUSE;
 271:             goto try_it_again;
 272:         case YESW:
 273:             break;
 274:         case USELSW:
 275:             use++;
 276:             goto edit_it;
 277:         case LISTDSW:
 278:             (void) showfile (++argp, drft);
 279:             break;
 280:         case REFILSW:
 281:             if (refile (++argp, drft) == 0)
 282:             i = YESW;
 283:             break;
 284:         default:
 285:             advise (NULLCP, "say what?");
 286:             break;
 287:         }
 288:     }
 289:     }
 290:     else
 291:     if (use)
 292:         adios (drft, "unable to open");
 293: 
 294:     if ((out = creat (drft, m_gmprot ())) == NOTOK)
 295:     adios (drft, "unable to create");
 296:     cpydata (in, out, form, drft);
 297:     (void) close (in);
 298:     (void) close (out);
 299: 
 300: edit_it: ;
 301:     m_update ();
 302: 
 303:     if (nwhat)
 304:     done (0);
 305:     (void) m_whatnow (ed, nedit, use, drft, NULLCP, 0, NULLMP, NULLCP, 0, cwd);
 306:     done (1);
 307: }

Defined functions

main defined in line 79; never used

Defined variables

aqrul defined in line 65; used 2 times
aqrunl defined in line 47; used 2 times
switches defined in line 10; used 3 times

Defined macros

DFOLDSW defined in line 11; never used
DMSGSW defined in line 13; never used
EDITRSW defined in line 18; never used
FILESW defined in line 23; never used
FORMSW defined in line 25; never used
HELPSW defined in line 38; never used
LISTDSW defined in line 54; used 1 times
NDFLDSW defined in line 15; never used
NEDITSW defined in line 20; never used
NEWSW defined in line 58; never used
NOSW defined in line 48; never used
NUSESW defined in line 30; never used
NWHATSW defined in line 35; never used
REFILSW defined in line 56; never used
USELSW defined in line 52; never used
USESW defined in line 28; never used
WHATSW defined in line 33; never used
YESW defined in line 50; used 2 times
Last modified: 1985-10-10
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 855
Valid CSS Valid XHTML 1.0 Strict