1: /* scan.c - display a one-line "scan" listing */
   2: 
   3: #include "../h/mh.h"
   4: #include "../h/formatsbr.h"
   5: #include "../h/scansbr.h"
   6: #include "../zotnet/tws.h"
   7: #include <errno.h>
   8: #include <stdio.h>
   9: 
  10: /*  */
  11: 
  12: static struct swit switches[] = {
  13: #define CLRSW   0
  14:     "clear", 0,
  15: #define NCLRSW  1
  16:     "noclear", 0,
  17: 
  18: #define FORMSW  2
  19:     "form formatfile", 0,
  20: #define FMTSW   3
  21:     "format string", 5,
  22: 
  23: #define HEADSW  4
  24:     "header", 0,
  25: #define NHEADSW 5
  26:     "noheader", 0,
  27: 
  28: #define WIDSW   6
  29:     "width columns", 0,
  30: 
  31: #ifdef  BERK
  32: #define REVSW   7
  33:     "reverse", 0,
  34: #define NREVSW  8
  35:     "noreverse", 0,
  36: 
  37: #define HELPSW  9
  38: #else   not BERK
  39: #define HELPSW  7
  40: #endif	not BERK
  41:     "help", 4,
  42: 
  43:     NULL, NULL
  44: };
  45: 
  46: /*  */
  47: 
  48: extern int errno;
  49: 
  50: 
  51: void    clear_screen ();
  52: 
  53: /*  */
  54: 
  55: /* ARGSUSED */
  56: 
  57: main (argc, argv)
  58: int     argc;
  59: char   *argv[];
  60: {
  61:      int    clearflag = 0,
  62:         hdrflag = 0,
  63:         width = 0,
  64:             msgp = 0,
  65:         ontty,
  66:         state,
  67:             msgnum;
  68: #ifdef  BERK
  69:     register int    revflag = 0,
  70:             firstlim,
  71:             lastlim,
  72:             incr;
  73: #endif  BERK
  74:     char   *cp,
  75:            *maildir,
  76:            *folder = NULL,
  77:        *form = NULL,
  78:        *format = NULL,
  79:             buf[100],
  80:           **ap,
  81:           **argp,
  82:            *nfs,
  83:            *arguments[MAXARGS],
  84:            *msgs[MAXARGS];
  85:     struct msgs *mp;
  86:     FILE * in;
  87: 
  88:     invo_name = r1bindex (argv[0], '/');
  89:     if ((cp = m_find (invo_name)) != NULL) {
  90:     ap = brkstring (cp = getcpy (cp), " ", "\n");
  91:     ap = copyip (ap, arguments);
  92:     }
  93:     else
  94:     ap = arguments;
  95:     (void) copyip (argv + 1, ap);
  96:     argp = arguments;
  97: 
  98: /*  */
  99: 
 100:     while (cp = *argp++) {
 101:     if (*cp == '-')
 102:         switch (smatch (++cp, switches)) {
 103:         case AMBIGSW:
 104:             ambigsw (cp, switches);
 105:             done (1);
 106:         case UNKWNSW:
 107:             adios (NULLCP, "-%s unknown", cp);
 108:         case HELPSW:
 109:             (void) sprintf (buf, "%s [+folder] [msgs] [switches]",
 110:                 invo_name);
 111:             help (buf, switches);
 112:             done (1);
 113: 
 114:         case CLRSW:
 115:             clearflag++;
 116:             continue;
 117:         case NCLRSW:
 118:             clearflag = 0;
 119:             continue;
 120: 
 121:         case FORMSW:
 122:             if (!(form = *argp++) || *form == '-')
 123:             adios (NULLCP, "missing argument to %s", argp[-2]);
 124:             format = NULL;
 125:             continue;
 126:         case FMTSW:
 127:             if (!(format = *argp++) || *format == '-')
 128:             adios (NULLCP, "missing argument to %s", argp[-2]);
 129:             form = NULL;
 130:             continue;
 131: 
 132:         case HEADSW:
 133:             hdrflag++;
 134:             continue;
 135:         case NHEADSW:
 136:             hdrflag = 0;
 137:             continue;
 138: 
 139:         case WIDSW:
 140:             if (!(cp = *argp++) || *cp == '-')
 141:             adios (NULLCP, "missing argument to %s", argp[-2]);
 142:             width = atoi (cp);
 143:             continue;
 144: #ifdef  BERK
 145:         case REVSW:
 146:             revflag++;
 147:             continue;
 148:         case NREVSW:
 149:             revflag = 0;
 150:             continue;
 151: #endif  BERK
 152:         }
 153:     if (*cp == '+' || *cp == '@') {
 154:         if (folder)
 155:         adios (NULLCP, "only one folder at a time!");
 156:         else
 157:         folder = path (cp + 1, *cp == '+' ? TFOLDER : TSUBCWF);
 158:     }
 159:     else
 160:         msgs[msgp++] = cp;
 161:     }
 162: 
 163: /*  */
 164: 
 165:     if (!m_find ("path"))
 166:     free (path ("./", TFOLDER));
 167:     if (!msgp)
 168:     msgs[msgp++] = "all";
 169:     if (!folder)
 170:     folder = m_getfolder ();
 171:     maildir = m_maildir (folder);
 172: 
 173:     if (chdir (maildir) == NOTOK)
 174:     adios (maildir, "unable to change directory to");
 175:     if (!(mp = m_gmsg (folder)))
 176:     adios (NULLCP, "unable to read folder %s", folder);
 177:     if (mp -> hghmsg == 0)
 178:     adios (NULLCP, "no messages in %s", folder);
 179: 
 180:     for (msgnum = 0; msgnum < msgp; msgnum++)
 181:     if (!m_convert (mp, msgs[msgnum]))
 182:         done(1);
 183:     m_setseq (mp);
 184: 
 185:     m_replace (pfolder, folder);
 186:     m_sync (mp);
 187:     m_update ();
 188: 
 189:     nfs = new_fs (form, format, FORMAT);
 190: 
 191:     ontty = isatty (fileno (stdout));
 192: 
 193: /*  */
 194: 
 195: #ifdef  BERK
 196:     if (revflag) {
 197:     firstlim = mp -> hghsel;
 198:     lastlim = mp -> lowsel;
 199:     incr = -1;
 200:     }
 201:     else {
 202:     firstlim = mp -> lowsel;
 203:     lastlim = mp -> hghsel;
 204:     incr = 1;
 205:     }
 206: 
 207:     for (msgnum = firstlim;
 208:         (revflag ? msgnum >= lastlim : msgnum <= lastlim);
 209:         msgnum += incr)
 210: #else   not BERK
 211:     for (msgnum = mp -> lowsel; msgnum <= mp -> hghsel; msgnum++)
 212: #endif  not BERK
 213:     if (mp -> msgstats[msgnum] & SELECTED) {
 214:         if ((in = fopen (cp = m_name (msgnum), "r")) == NULL) {
 215:         if (errno != EACCES)
 216:             admonish (cp, "unable to open message");
 217:         else
 218:             printf ("%*d  unreadable\n", DMAXFOLDER, msgnum);
 219:         free (cp);
 220:         continue;
 221:         }
 222: 
 223:         if (hdrflag)
 224:         printf ("Folder %-32s%s\n\n", folder, dtimenow ());
 225:         switch (state = scan (in, msgnum, 0, nfs, width,
 226:             msgnum == mp -> curmsg,
 227:             hdrflag, 0L, 1)) {
 228:         case SCNMSG:
 229:         case SCNERR:
 230:             break;
 231: 
 232:         default:
 233:             adios (NULLCP, "scan() botch (%d)", state);
 234: 
 235:         case SCNEOF:
 236:             printf ("%*d  empty\n", DMAXFOLDER, msgnum);
 237:             break;
 238:         }
 239:         hdrflag = 0;
 240:         (void) fclose (in);
 241:         if (ontty)
 242:         (void) fflush (stdout);
 243:     }
 244: 
 245: /*  */
 246: 
 247:     if (clearflag)
 248:     clear_screen ();
 249: 
 250:     done (0);
 251: }

Defined functions

main defined in line 57; never used

Defined variables

switches defined in line 12; used 3 times

Defined macros

CLRSW defined in line 13; never used
FMTSW defined in line 20; never used
FORMSW defined in line 18; never used
HEADSW defined in line 23; never used
HELPSW defined in line 39; never used
NCLRSW defined in line 15; never used
NHEADSW defined in line 25; never used
NREVSW defined in line 34; never used
REVSW defined in line 32; never used
WIDSW defined in line 28; never used
Last modified: 1986-04-21
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1154
Valid CSS Valid XHTML 1.0 Strict