|
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 p ┃
Length: 1916 (0x77c) Types: TextFile Names: »parseline.c«
└─⟦87ddcff64⟧ Bits:30001253 CPHDIST85 Tape, 1985 Autumn Conference Copenhagen └─ ⟦this⟧ »cph85dist/stat/src/parseline.c«
/*LINTLIBRARY*/ #include <stdio.h> #include <ctype.h> #ifndef MSDOS static char sccsfid[] = "@(#) parseline.c 5.1 (unix|stat) 2/22/85"; #endif /* Copyright (c) 1982 Gary Perlman (see Copyright file) */ /* parseline reads from line into array, an array of maxstrings pointers. It returns the number of strings read in, or maxstrings + 1 if some information is discarded. The input string is clobbered for space. */ parseline (line, array, maxstrings) register char *line; char **array; { int nstrings = 0; /* number of strings read in */ int qchar; /* quote character */ while (isspace (*line)) line++; while (*line) { qchar = (*line == '"' || *line == '\'') ? *line++ : '\0'; array[nstrings] = line; while (*line && (qchar ? (*line != qchar) : (!isspace (*line)))) line++; if (*line) *line++ = '\0'; while (isspace (*line)) line++; if (++nstrings == maxstrings) return (maxstrings + (*line ? 1 : 0)); } return (nstrings); } #ifdef STANDALONE #define MAX 100 main () { int ncols; int col; char *array[MAX]; char line[BUFSIZ]; while (fgets (line, BUFSIZ, stdin)) { ncols = parseline (stdin, array, MAX); printf ("%3d ", ncols); for (col = 0; col < ncols; col++) { printquote (array[col]); putchar (' '); } putchar ('\n'); } exit (0); } printquote (s) char *s; { char *ptr; int squote = 0; /* is there a single quote in string? */ int dquote = 0; /* is there a double quote in string? */ int space = 0; /* is there a space in string? */ for (ptr = s; *ptr; ptr++) { if (*ptr == '\'') squote++; else if (*ptr == '"') dquote++; else if (*ptr == ' ') space++; } if (space == 0 && *s != '\'' && *s != '"') printf ("%s", s); else if (dquote && !squote) printf ("'%s'", s); else if (squote && !dquote) printf ("\"%s\"", s); else /* can't quote this properly! */ printf ("%s"); } #endif