Annotation of coherent/d/bin/tsort/input.c, revision 1.1.1.1

1.1       root        1: #include <stdio.h>
                      2: #include <ctype.h>
                      3: #include "tsort.h"
                      4: 
                      5: 
                      6: void
                      7: getcon(fp)
                      8: FILE *fp;
                      9: {
                     10:        register char *wrd;
                     11:        struct word *wordp1, *wordp2;
                     12:        struct wordlist *rel;
                     13:        char *getwrd();
                     14: 
                     15:        for (;;) {
                     16:                wrd = getwrd(fp);
                     17:                if (wrd == NULL)
                     18:                        break;
                     19:                wordp1 = insert(wrd);
                     20:                wrd = getwrd(fp);
                     21:                if (wrd == NULL)
                     22:                        die("odd number of fields input");
                     23:                wordp2 = insert(wrd);
                     24:                if (wordp1 != wordp2) {
                     25:                        rel = newwordl(wordp1);
                     26:                        rel->next = wordp2->ancestors;
                     27:                        wordp2->ancestors = rel;
                     28:                }
                     29:        }
                     30:        words = cmphash();
                     31: }
                     32: 
                     33: 
                     34: /*
                     35:  *     Getwrd is used to get the next word from the FILE pointed to
                     36:  *     by "fp".  Word is defined as non-white-space.  If the end of
                     37:  *     file is reached, then getwrd returns an empty string.  Note
                     38:  *     that since getwrd returns a pointer to a static area, the result
                     39:  *     must be copyied before the next call.
                     40:  */
                     41: 
                     42: static char *
                     43: getwrd(fp)
                     44: register FILE *fp;
                     45: {
                     46:        register int ch;
                     47:        static char word[MAXWORD];
                     48:        register char *wrdp;
                     49: 
                     50:        while ((ch = getc(fp)) != EOF && isascii(ch) && isspace(ch))
                     51:                ;
                     52:        if (ch == EOF)
                     53:                return (NULL);
                     54:        for (wrdp = word; !(isascii(ch) && isspace(ch)); ch = getc(fp)) {
                     55:                if (ch == EOF)
                     56:                        break;
                     57:                if (wrdp >= &word[MAXWORD - 1])
                     58:                        die("word too long");
                     59:                *wrdp++ = ch;
                     60:        }
                     61:        *wrdp = '\0';
                     62:        return (word);
                     63: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.