|
|
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: static int process(); ! 40: ! 41: /* */ ! 42: ! 43: /* ARGSUSED */ ! 44: ! 45: main(argc, argv) ! 46: int argc; ! 47: char **argv; ! 48: { ! 49: int datep = 0, ! 50: width = 0, ! 51: status = 0; ! 52: char *cp, ! 53: *form = NULL, ! 54: *format = NULL, ! 55: *nfs, ! 56: buf[80], ! 57: **ap, ! 58: **argp, ! 59: *arguments[MAXARGS], ! 60: *dates[NDATES]; ! 61: ! 62: invo_name = r1bindex (argv[0], '/'); ! 63: if ((cp = m_find (invo_name)) != NULL) { ! 64: ap = brkstring (cp = getcpy (cp), " ", "\n"); ! 65: ap = copyip (ap, arguments); ! 66: } ! 67: else ! 68: ap = arguments; ! 69: (void) copyip (argv + 1, ap); ! 70: argp = arguments; ! 71: ! 72: /* */ ! 73: ! 74: while (cp = *argp++) { ! 75: if (*cp == '-') ! 76: switch (smatch (++cp, switches)) { ! 77: case AMBIGSW: ! 78: ambigsw (cp, switches); ! 79: done (1); ! 80: case UNKWNSW: ! 81: adios (NULLCP, "-%s unknown", cp); ! 82: case HELPSW: ! 83: (void) sprintf (buf, "%s [switches] dates ...", invo_name); ! 84: help (buf, switches); ! 85: done (1); ! 86: ! 87: case FORMSW: ! 88: if (!(form = *argp++) || *form == '-') ! 89: adios (NULLCP, "missing argument to %s", argp[-2]); ! 90: format = NULL; ! 91: continue; ! 92: case FMTSW: ! 93: if (!(format = *argp++) || *format == '-') ! 94: adios (NULLCP, "missing argument to %s", argp[-2]); ! 95: form = NULL; ! 96: continue; ! 97: ! 98: case WIDSW: ! 99: if (!(cp = *argp++) || *cp == '-') ! 100: adios (NULLCP, "missing argument to %s", argp[-2]); ! 101: width = atoi (cp); ! 102: continue; ! 103: } ! 104: if (datep > NDATES) ! 105: adios (NULLCP, "more than %d dates", NDATES); ! 106: else ! 107: dates[datep++] = cp; ! 108: } ! 109: dates[datep] = NULL; ! 110: ! 111: /* */ ! 112: ! 113: if (datep == 0) ! 114: adios (NULLCP, "usage: %s [switches] dates ...", invo_name); ! 115: ! 116: nfs = new_fs (form, format, FORMAT); ! 117: if (width == 0) { ! 118: if ((width = sc_width ()) < WIDTH / 2) ! 119: width = WIDTH / 2; ! 120: width -= 2; ! 121: } ! 122: if (width > WBUFSIZ) ! 123: width = WBUFSIZ; ! 124: (void) fmt_compile (nfs, &fmt); ! 125: dat[0] = dat[1] = dat[2] = 0; ! 126: dat[3] = width; ! 127: ! 128: for (datep = 0; dates[datep]; datep++) ! 129: status += process (dates[datep], width); ! 130: ! 131: m_update (); ! 132: ! 133: done (status); ! 134: } ! 135: ! 136: /* */ ! 137: ! 138: static int ! 139: process(date, length) ! 140: register char *date; ! 141: int length; ! 142: { ! 143: int status = 0; ! 144: char buffer[WBUFSIZ + 1]; ! 145: register struct comp *cptr; ! 146: ! 147: FINDCOMP (cptr, "text"); ! 148: if (cptr) ! 149: cptr -> c_text = date; ! 150: (void) fmtscan (fmt, buffer, length, dat); ! 151: (void) fputs (buffer, stdout); ! 152: ! 153: return status; ! 154: } ! 155: ! 156: /* ! 157: * XXX We need to force config.o to be linked in to get around ! 158: * library order problems ! 159: */ ! 160: /* XXX don't bother if linking with the shared library */ ! 161: #ifndef SHARED ! 162: static void ! 163: kludge() ! 164: { ! 165: (void)libpath((char *)0); ! 166: } ! 167: #endif
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.