|
|
1.1 ! root 1: /* dp.c - parse dates 822-style */ ! 2: ! 3: #include "../h/mh.h" ! 4: #include "../h/formatsbr.h" ! 5: #include "../zotnet/tws.h" ! 6: #include <stdio.h> ! 7: ! 8: ! 9: #define NDATES 100 ! 10: ! 11: #define WIDTH 78 ! 12: #define WBUFSIZ BUFSIZ ! 13: ! 14: #define FORMAT "%<(nodate{text})error: %{text}%|%(putstr(pretty{text}))%>" ! 15: ! 16: /* */ ! 17: ! 18: static struct swit switches[] = { ! 19: #define FORMSW 0 ! 20: "form formatfile", 0, ! 21: #define FMTSW 1 ! 22: "format string", 5, ! 23: ! 24: #define WIDSW 2 ! 25: "width columns", 0, ! 26: ! 27: #define HELPSW 3 ! 28: "help", 4, ! 29: ! 30: NULL, NULL ! 31: }; ! 32: ! 33: /* */ ! 34: ! 35: static struct format *fmt; ! 36: ! 37: static int dat[4]; ! 38: ! 39: /* */ ! 40: ! 41: /* ARGSUSED */ ! 42: ! 43: main (argc, argv) ! 44: int argc; ! 45: char **argv; ! 46: { ! 47: int datep = 0, ! 48: width = 0, ! 49: status = 0; ! 50: char *cp, ! 51: *form = NULL, ! 52: *format = NULL, ! 53: *nfs, ! 54: buf[80], ! 55: **ap, ! 56: **argp, ! 57: *arguments[MAXARGS], ! 58: *dates[NDATES]; ! 59: ! 60: invo_name = r1bindex (argv[0], '/'); ! 61: if ((cp = m_find (invo_name)) != NULL) { ! 62: ap = brkstring (cp = getcpy (cp), " ", "\n"); ! 63: ap = copyip (ap, arguments); ! 64: } ! 65: else ! 66: ap = arguments; ! 67: (void) copyip (argv + 1, ap); ! 68: argp = arguments; ! 69: ! 70: /* */ ! 71: ! 72: while (cp = *argp++) { ! 73: if (*cp == '-') ! 74: switch (smatch (++cp, switches)) { ! 75: case AMBIGSW: ! 76: ambigsw (cp, switches); ! 77: done (1); ! 78: case UNKWNSW: ! 79: adios (NULLCP, "-%s unknown", cp); ! 80: case HELPSW: ! 81: (void) sprintf (buf, "%s [switches] dates ...", invo_name); ! 82: help (buf, switches); ! 83: done (1); ! 84: ! 85: case FORMSW: ! 86: if (!(form = *argp++) || *form == '-') ! 87: adios (NULLCP, "missing argument to %s", argp[-2]); ! 88: format = NULL; ! 89: continue; ! 90: case FMTSW: ! 91: if (!(format = *argp++) || *format == '-') ! 92: adios (NULLCP, "missing argument to %s", argp[-2]); ! 93: form = NULL; ! 94: continue; ! 95: ! 96: case WIDSW: ! 97: if (!(cp = *argp++) || *cp == '-') ! 98: adios (NULLCP, "missing argument to %s", argp[-2]); ! 99: width = atoi (cp); ! 100: continue; ! 101: } ! 102: if (datep > NDATES) ! 103: adios (NULLCP, "more than %d dates", NDATES); ! 104: else ! 105: dates[datep++] = cp; ! 106: } ! 107: dates[datep] = NULL; ! 108: ! 109: /* */ ! 110: ! 111: if (datep == 0) ! 112: adios (NULLCP, "usage: %s [switches] dates ...", invo_name); ! 113: ! 114: nfs = new_fs (form, format, FORMAT); ! 115: if (width == 0) { ! 116: if ((width = sc_width ()) < WIDTH / 2) ! 117: width = WIDTH / 2; ! 118: width -= 2; ! 119: } ! 120: if (width > WBUFSIZ) ! 121: width = WBUFSIZ; ! 122: (void) fmt_compile (nfs, &fmt); ! 123: dat[0] = dat[1] = dat[2] = 0; ! 124: dat[3] = width; ! 125: ! 126: for (datep = 0; dates[datep]; datep++) ! 127: status += process (dates[datep], width); ! 128: ! 129: m_update (); ! 130: ! 131: done (status); ! 132: } ! 133: ! 134: /* */ ! 135: ! 136: static int process (date, length) ! 137: register char *date; ! 138: int length; ! 139: { ! 140: int status = 0; ! 141: char buffer[WBUFSIZ + 1]; ! 142: register struct comp *cptr; ! 143: ! 144: FINDCOMP (cptr, "text"); ! 145: if (cptr) ! 146: cptr -> c_text = date; ! 147: (void) fmtscan (fmt, buffer, length, dat); ! 148: (void) fputs (buffer, stdout); ! 149: ! 150: return status; ! 151: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.