diff options
author | Arnold D. Robbins <arnold@skeeve.com> | 2010-07-16 13:17:58 +0300 |
---|---|---|
committer | Arnold D. Robbins <arnold@skeeve.com> | 2010-07-16 13:17:58 +0300 |
commit | e888f1834b88270590b7e04d64c03c75863e4565 (patch) | |
tree | ab679ecbf16dc4f11b90a53f4b1e0084d78c98b0 /awklib/eg | |
parent | fae4762eba9ff7bb466a600130e9c90eaac6b0bc (diff) | |
download | egawk-e888f1834b88270590b7e04d64c03c75863e4565.tar.gz egawk-e888f1834b88270590b7e04d64c03c75863e4565.tar.bz2 egawk-e888f1834b88270590b7e04d64c03c75863e4565.zip |
Move to gawk-3.1.2.
Diffstat (limited to 'awklib/eg')
-rw-r--r-- | awklib/eg/lib/grcat.c | 16 | ||||
-rw-r--r-- | awklib/eg/lib/pwcat.c | 16 | ||||
-rw-r--r-- | awklib/eg/prog/igawk.sh | 73 |
3 files changed, 60 insertions, 45 deletions
diff --git a/awklib/eg/lib/grcat.c b/awklib/eg/lib/grcat.c index 802aa639..c022dc7e 100644 --- a/awklib/eg/lib/grcat.c +++ b/awklib/eg/lib/grcat.c @@ -12,9 +12,13 @@ #if HAVE_CONFIG_H #include <config.h> #endif + +#if defined (STDC_HEADERS) +#include <stdlib.h> +#endif -#ifndef HAVE_GETPGRENT -int main() { exit(0); } +#ifndef HAVE_GETGRENT +int main() { return 0; } #else #include <stdio.h> #include <grp.h> @@ -28,8 +32,8 @@ char **argv; int i; while ((g = getgrent()) != NULL) { - printf("%s:%s:%d:", g->gr_name, g->gr_passwd, - g->gr_gid); + printf("%s:%s:%ld:", g->gr_name, g->gr_passwd, + (long) g->gr_gid); for (i = 0; g->gr_mem[i] != NULL; i++) { printf("%s", g->gr_mem[i]); if (g->gr_mem[i+1] != NULL) @@ -38,6 +42,6 @@ char **argv; putchar('\n'); } endgrent(); - exit(0); + return 0; } -#endif /* HAVE_GETPGRENT */ +#endif /* HAVE_GETGRENT */ diff --git a/awklib/eg/lib/pwcat.c b/awklib/eg/lib/pwcat.c index b9a71340..d6ad0b64 100644 --- a/awklib/eg/lib/pwcat.c +++ b/awklib/eg/lib/pwcat.c @@ -8,9 +8,17 @@ * Public Domain */ +#if HAVE_CONFIG_H +#include <config.h> +#endif + #include <stdio.h> #include <pwd.h> +#if defined (STDC_HEADERS) +#include <stdlib.h> +#endif + int main(argc, argv) int argc; @@ -19,10 +27,10 @@ char **argv; struct passwd *p; while ((p = getpwent()) != NULL) - printf("%s:%s:%d:%d:%s:%s:%s\n", - p->pw_name, p->pw_passwd, p->pw_uid, - p->pw_gid, p->pw_gecos, p->pw_dir, p->pw_shell); + printf("%s:%s:%ld:%ld:%s:%s:%s\n", + p->pw_name, p->pw_passwd, (long) p->pw_uid, + (long) p->pw_gid, p->pw_gecos, p->pw_dir, p->pw_shell); endpwent(); - exit(0); + return 0; } diff --git a/awklib/eg/prog/igawk.sh b/awklib/eg/prog/igawk.sh index 7144ce50..9fce9a50 100644 --- a/awklib/eg/prog/igawk.sh +++ b/awklib/eg/prog/igawk.sh @@ -8,49 +8,56 @@ if [ "$1" = debug ] then set -x shift -else - # cleanup on exit, hangup, interrupt, quit, termination - trap 'rm -f /tmp/ig.[se].$$' 0 1 2 3 15 fi +# A literal newline, so that program text is formmatted correctly +n=' +' + +# Initialize variables to empty +program= +opts= + while [ $# -ne 0 ] # loop over arguments do case $1 in --) shift; break;; -W) shift - set -- -W"$@" + # The ${x?'message here'} construct prints a + # diagnostic if $x is the null string + set -- -W"${@?'missing operand'}" continue;; - -[vF]) opts="$opts $1 '$2'" + -[vF]) opts="$opts $1 '${2?'missing operand'}'" shift;; -[vF]*) opts="$opts '$1'" ;; - -f) echo @include "$2" >> /tmp/ig.s.$$ + -f) program="$program$n@include ${2?'missing operand'}" shift;; - -f*) f=`echo "$1" | sed 's/-f//'` - echo @include "$f" >> /tmp/ig.s.$$ ;; + -f*) f=`expr "$1" : '-f\(.*\)'` + program="$program$n@include $f";; - -?file=*) # -Wfile or --file - f=`echo "$1" | sed 's/-.file=//'` - echo @include "$f" >> /tmp/ig.s.$$ ;; + -[W-]file=*) + f=`expr "$1" : '-.file=\(.*\)'` + program="$program$n@include $f";; - -?file) # get arg, $2 - echo @include "$2" >> /tmp/ig.s.$$ + -[W-]file) + program="$program$n@include ${2?'missing operand'}" shift;; - -?source=*) # -Wsource or --source - t=`echo "$1" | sed 's/-.source=//'` - echo "$t" >> /tmp/ig.s.$$ ;; + -[W-]source=*) + t=`expr "$1" : '-.source=\(.*\)'` + program="$program$n$t";; - -?source) # get arg, $2 - echo "$2" >> /tmp/ig.s.$$ + -[W-]source) + program="$program$n${2?'missing operand'}" shift;; - -?version) - echo igawk: version 1.0 1>&2 + -[W-]version) + echo igawk: version 2.0 1>&2 gawk --version exit 0 ;; @@ -61,21 +68,14 @@ do shift done -if [ ! -s /tmp/ig.s.$$ ] +if [ -z "$program" ] then - if [ -z "$1" ] - then - echo igawk: no program! 1>&2 - exit 1 - else - echo "$1" > /tmp/ig.s.$$ - shift - fi + program=${1?'missing program'} + shift fi -# at this point, /tmp/ig.s.$$ has the program -gawk -- ' -# process @include directives +# At this point, `program' has the program. +expand_prog=' function pathto(file, i, t, junk) { @@ -124,7 +124,10 @@ BEGIN { } close(input[stackptr]) } -}' /tmp/ig.s.$$ > /tmp/ig.e.$$ -eval gawk -f /tmp/ig.e.$$ $opts -- "$@" +}' # close quote ends `expand_prog' variable -exit $? +processed_program=`gawk -- "$expand_prog" /dev/stdin <<EOF +$program +EOF +` +eval gawk $opts -- '"$processed_program"' '"$@"' |