~vcs-imports/gawk/master

« back to all changes in this revision

Viewing changes to awklib/eg/prog/igawk.sh

  • Committer: Arnold D. Robbins
  • Date: 2010-07-16 10:09:56 UTC
  • Revision ID: git-v1:bc70de7b3302d5a81515b901cae376b8b51d2004
Tags: gawk-3.1.0
Move to gawk-3.1.0.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#! /bin/sh
2
 
 
3
2
# igawk --- like gawk but do @include processing
 
3
#
4
4
# Arnold Robbins, arnold@gnu.org, Public Domain
5
5
# July 1993
6
6
 
37
37
            f=`echo "$1" | sed 's/-.file=//'`
38
38
            echo @include "$f" >> /tmp/ig.s.$$ ;;
39
39
 
40
 
    -?file)    # get arg, $2
 
40
    -?file)      # get arg, $2
41
41
            echo @include "$2" >> /tmp/ig.s.$$
42
42
            shift;;
43
43
 
44
 
    -?source=*)    # -Wsource or --source
 
44
    -?source=*)  # -Wsource or --source
45
45
            t=`echo "$1" | sed 's/-.source=//'`
46
46
            echo "$t" >> /tmp/ig.s.$$ ;;
47
47
 
48
 
    -?source)  # get arg, $2
 
48
    -?source)    # get arg, $2
49
49
            echo "$2" >> /tmp/ig.s.$$
50
50
            shift;;
51
51
 
54
54
            gawk --version
55
55
            exit 0 ;;
56
56
 
57
 
    -[W-]*)    opts="$opts '$1'" ;;
 
57
    -[W-]*) opts="$opts '$1'" ;;
58
58
 
59
59
    *)      break;;
60
60
    esac
76
76
# at this point, /tmp/ig.s.$$ has the program
77
77
gawk -- '
78
78
# process @include directives
 
79
 
79
80
function pathto(file,    i, t, junk)
80
81
{
81
82
    if (index(file, "/") != 0)
109
110
            }
110
111
            fpath = pathto($2)
111
112
            if (fpath == "") {
112
 
                printf("igawk:%s:%d: cannot find %s\n", \
 
113
                printf("igawk:%s:%d: cannot find %s\n",
113
114
                    input[stackptr], FNR, $2) > "/dev/stderr"
114
115
                continue
115
116
            }
116
117
            if (! (fpath in processed)) {
117
118
                processed[fpath] = input[stackptr]
118
 
                input[++stackptr] = fpath
 
119
                input[++stackptr] = fpath  # push onto stack
119
120
            } else
120
 
                print $2, "included in", input[stackptr], \
121
 
                    "already included in", \
 
121
                print $2, "included in", input[stackptr],
 
122
                    "already included in",
122
123
                    processed[fpath] > "/dev/stderr"
123
124
        }
124
125
        close(input[stackptr])