Annotation of 43BSD/contrib/mh/uip/dist.c, revision 1.1

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

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.