DataMuseum.dk

Presents historical artifacts from the history of:

DKUUG/EUUG Conference tapes

This is an automatic "excavation" of a thematic subset of
artifacts from Datamuseum.dk's BitArchive.

See our Wiki for more about DKUUG/EUUG Conference tapes

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - download
Index: ┃ T p

⟦89588c431⟧ TextFile

    Length: 2147 (0x863)
    Types: TextFile
    Names: »parse.c«

Derivation

└─⟦87ddcff64⟧ Bits:30001253 CPHDIST85 Tape, 1985 Autumn Conference Copenhagen
    └─ ⟦this⟧ »cph85dist/rman/daemon/parse.c« 

TextFile

#ifndef lint
static char *RCSid = "$Header: parse.c,v 1.3 85/08/04 16:35:30 broome Exp $";
#endif

/*
 * $Log:    parse.c,v $
 * Revision 1.3  85/08/04  16:35:30  broome
 * Cleaned up a little, added comma as delimiter so that config file can
 * be more freely formatted.
 * 
 * Revision 1.2  85/07/06  16:56:04  broome
 * 
 * Revision 1.1  85/06/25  11:23:41  broome
 * Initial revision
 */

#define iswhite(c)   (c==' '||c=='\t'||c=='\n'||c=='\r'||c=='\0'||c==',')
/*
 *  Turn a line buffer into a pointer to a set 
 *  of strings, just like ``argv[]'', and return argc.
 */

parse (buf, array)
char  *buf;
char ***array;
{
    char **argv;
    char *s;
    char word[132];
    int  argc = 0;
    int  i = 0, j;

    argv = *array;
    if (argv != (char **) 0) {   /* have to free up space taken by old array */
        do 
            free (argv[i]);                  /* free up each element */
        while (argv[i++] != (char *) 0);
        free (argv);                         /* and then free argv itslef */
    }

    /*
     *  Count and null-terminate each word.
     */
    for (s = buf; *s; s++) 
        if (!iswhite (*s) && iswhite(*(s+1)))   /* the end of each word */
            argc++;
        else if (iswhite (*s))
            *s = '\0';
    
    /*
     *  Now malloc up space for the strings plus the null at the end.
     */
    if ((argv = (char **) malloc ((argc+1) * sizeof(char *))) == (char **) 0) {
        perror ("parse: cannot malloc space for argv[]");
        exit (1);
    }

    /*
     *  And copy the contents in.
     */

    i = 0;
    for (s = buf, j = 0; j < argc; s++) {
        if (!iswhite (*s) && iswhite(*(s+1))) {  /* the end of each word */
            word[i++] = *s;
            word[i] = '\0';
            if ((argv[j] = (char *)malloc (i+1)) == (char *) 0) {
                perror ("parse: cannot malloc mem for word");
                exit (1);
            }
            strcpy (argv[j++], word);
            i = 0;
        } else if (!iswhite (*s))
            word[i++] = *s;
    }
    argv[j] = (char *) 0;   /* and a null at the end of it all */
    *array = argv;

    return (argc);
}