Annotation of 43BSDReno/usr.bin/tn3270/distribution/utilities/cross.c, revision 1.1

1.1     ! root        1: /*
        !             2:         This program is, essentially, a cross product generator.  It takes
        !             3:         an input file which is said to consist of a number of lines, and
        !             4:         expands each line.  A line like
        !             5:                 (a,b)(c,d)
        !             6:         will be expanded to lines like
        !             7:                 ac
        !             8:                 ad
        !             9:                 bc
        !            10:                 bd
        !            11:         (without regard for the ORDER of the output; ie: the lines can appear
        !            12:         in any order).
        !            13: 
        !            14:         Parenthesis can be nested, so
        !            15:                 (a,b)(c(d,e),f)
        !            16:         will produce
        !            17:                 acd
        !            18:                 ace
        !            19:                 af
        !            20:                 bcd
        !            21:                 bce
        !            22:                 bf
        !            23:  */
        !            24: 
        !            25: 
        !            26: #include <stdio.h>
        !            27: 
        !            28: char leftParen,                         /* The left parenthesis character */
        !            29:         rightParen;                     /* The right parenthesis character */
        !            30: 
        !            31: 
        !            32: /* Finds next occurrence of 'character' at this level of nesting.
        !            33:         Returns 0 if no such character found.
        !            34:  */
        !            35: 
        !            36: char *
        !            37: ThisLevel(string, character)
        !            38: char *string, character;
        !            39: {
        !            40:         int level;                      /* Level 0 is OUR level */
        !            41: 
        !            42:         level = 0;
        !            43: 
        !            44:         while (*string != '\0') {
        !            45:                 if (*string == leftParen)
        !            46:                         level++;
        !            47:                 else if (*string == rightParen) {
        !            48:                         level--;
        !            49:                         if (level < 0)
        !            50:                                 return(0);
        !            51:                 }
        !            52:                 if ((level == 0) && (*string == character))
        !            53:                                 return(string);
        !            54:                 string++;
        !            55:         }

unix.superglobalmegacorp.com

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