|
DataMuseum.dkPresents historical artifacts from the history of: DKUUG/EUUG Conference tapes |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about DKUUG/EUUG Conference tapes Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - downloadIndex: ┃ T r ┃
Length: 1621 (0x655) Types: TextFile Names: »reverse.c«
└─⟦87ddcff64⟧ Bits:30001253 CPHDIST85 Tape, 1985 Autumn Conference Copenhagen └─ ⟦this⟧ »cph85dist/stat/src/reverse.c«
#include "unixstat.h" PGM(reverse,Reverse Lines/Fields/Characters,5.0,1985) /* Copyright (c) 1982 Gary Perlman (see Copyright file) */ #define MAXLINES 1000 #define MAXFIELDS 100 #define MAXLEN 100 char *lptr[MAXLINES]; int Rlines, Rchars, Rfields; char * revchar (s) char *s; { char buf[BUFSIZ]; char *ptr = buf; char *sptr = s; while (*sptr) sptr++; while (sptr >= s) *ptr++ = *--sptr; *ptr = NULL; return (strcpy (s, buf)); } char * revfield (line) char *line; { char array[MAXFIELDS][MAXLEN]; int ncols, ii; char *ptr = line; if ((ncols = sstrings (line, array, MAXFIELDS, MAXLEN)) > MAXFIELDS) ERRMANY (fields, MAXFIELDS) for (ii = ncols-1; ii >= 0; ii--) { strcpy (ptr, array[ii]); while (*ptr) ptr++; if (ii != 0) *ptr++ = '\t'; } *ptr = NULL; return (line); } initial (argc, argv) char **argv; { int errflg = 0; extern int optind; int C; while ((C = getopt (argc, argv, "cfl")) != EOF) switch (C) { case 'f': Rfields = 1; break; case 'l': Rlines = 1; break; case 'c': Rchars = 1; break; default: errflg++; } if (errflg) USAGE ([-cfl]) ERROPT (optind) checkstdin (Argv0); } main (argc, argv) char **argv; { char line[BUFSIZ]; int nlines = 0; char *ptr; ARGV0; if (argc == 1) Rlines = 1; initial (argc, argv); while (gets (line)) { ptr = line; if (Rchars) ptr = revchar (ptr); if (Rfields) ptr = revfield (ptr); if (Rlines) if (++nlines == MAXLINES) ERRMANY (lines, MAXLINES) else lptr[nlines-1] = strdup (ptr); else puts (ptr); } if (Rlines) while (nlines > 0) puts (lptr[--nlines]); exit (0); }