summaryrefslogtreecommitdiffstats
path: root/usr.bin/tn3270/distribution/utilities/cross.c
blob: 191aac0bb881d463af3e5797888161865c76d931 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*
        This program is, essentially, a cross product generator.  It takes
        an input file which is said to consist of a number of lines, and
        expands each line.  A line like
                (a,b)(c,d)
        will be expanded to lines like
                ac
                ad
                bc
                bd
        (without regard for the ORDER of the output; ie: the lines can appear
        in any order).

        Parenthesis can be nested, so
                (a,b)(c(d,e),f)
        will produce
                acd
                ace
                af
                bcd
                bce
                bf
 */


#include <stdio.h>

char leftParen,                         /* The left parenthesis character */
        rightParen;                     /* The right parenthesis character */


/* Finds next occurrence of 'character' at this level of nesting.
        Returns 0 if no such character found.
 */

char *
ThisLevel(string, character)
char *string, character;
{
        int level;                      /* Level 0 is OUR level */

        level = 0;

        while (*string != '\0') {
                if (*string == leftParen)
                        level++;
                else if (*string == rightParen) {
                        level--;
                        if (level < 0)
                                return(0);
                }
                if ((level == 0) && (*string == character))
                                return(string);
                string++;
        }
OpenPOWER on IntegriCloud