diff options
-rwxr-xr-x | cppawk | 11 | ||||
-rw-r--r-- | cppawk.1 | 51 | ||||
-rw-r--r-- | testcases | 20 |
3 files changed, 77 insertions, 5 deletions
@@ -105,6 +105,17 @@ while [ $# -gt 0 ] ; do --prepro-only ) prepro_only=y ;; + --prepro=* ) + prepro=${1#*=} + ;; + --awk=* ) + awk=${1#*=} + case $awk in + gawk | mawk | */gawk | */mawk ) + prepro_opts="$prepro_opts -U__gawk__ -D__$(basename "$awk")__=1" + ;; + esac + ;; -U* | -D* | -I* | -iquote* ) prepro_opts="$prepro_opts $(quote "$1")" ;; @@ -1,10 +1,13 @@ .TH cppawk 1 "18 March 2022" "Beta Version" "cppawk manual" + .SH NAME cppawk \- wrapper for awk, with C preprocessing + .SH SYNOPSIS -cppawk [cpp and awk options ] +cppawk [cpp, awk and cppawk options] [awk arguments] + +cppawk --prepro-only [cpp, awk and cppawk options] -cppawk --prepro-only [cpp and awk options] .SH DESCRIPTION .B cppawk is a shell script which passes awk code through the standalone @@ -42,18 +45,44 @@ When installation is configured to use GNU Awk, which is the default, the preprocessor symbol .BI __gawk__ -is predefined with a value of 1. +is predefined with a value of 1. See the +.BI --awk +option. .SH OPTIONS Any option not described here is assumed to be an Awk option which takes no argument, and is consequently passed through to the .B awk program. + .IP "\fB\-\-\fR" End of options: any subsequent argument is the first non-option argument, even if it looks like an option. + .IP "\fB\-\-prepro\-only\fR" Do not run the preprocessed Awk program; dump the preprocessed code to standard output. + +.IP "\fB\-\-awk=\fR\fIpath\fR" +Specify alternative Awk implementation. If it contains no slashes, then +.BI PATH +is searched to find the program. If the base name of the program is +.BI gawk +or +.BI mawk, +then, respectively, one of the preprocessor symbols +.BI __gawk__ +or +.BI __mawk__ +is predefined, with a value of 1. This happens immediately when this +option is processed, so can be counter-acted by a subsequent +.BI -U +option. + +.IP "\fB\-\-prepro=\fR\fIpath\fR" +Specify alternative preprocessor. If it contains no slashes, then +.BI PATH +is searched to find the program. + .IP "\fB\-f\fR \fIfilename\fR" Read the awk program from .I filename @@ -63,6 +92,7 @@ argument. The program is preprocessed to a temporary file, and is then invoked on this file. The file is deleted when .B awk terminates. + .IP "\fB\-M\fR, \fB\--bignum\fR" These two equivalent GNU Awk options are passed through to .BR awk , @@ -70,6 +100,7 @@ which will understand them if it is GNU Awk. Using either of them causes the preprocessor symbol .BI __bignum__ to be defined with the value 1. + .IP "\fB\-P\fR, \fB\--posix\fR" These two equivalent GNU Awk options are passed through to .BR awk , @@ -77,6 +108,7 @@ which will understand them if it is GNU Awk. Using either of them causes the preprocessor symbol .BI __posix__ to be defined with the value 1. + .IP "\fB\-M...\fR Any optional argument beginning with .BI -M @@ -85,12 +117,14 @@ message and failed termination. The intent is that the .BI -M family of options that are supported by GNU cpp are not supported by .BR cppawk . + .IP "\fB-F\fR, \fB-v\fR, \fB-E\fR, \fB-i\fR, \fB-l\fR, \fB-L\fR" These standard and GNU Awk options are recognizes by .B cppawk as requiring an argument. They are validated for the presence of the required argument, and passed to .BR awk . + .IP "\fB-U...\fR, \fB-D...\fR, \fB-I...\fR, \fB-iquote...\fR" Options which match these patterns are passed to the .B cpp @@ -143,6 +177,7 @@ contains: .SH "SEE ALSO" awk(1), cpp(6) + .SH BUGS The .BI -f @@ -177,13 +212,18 @@ which is why works at all; however, there may be corner cases where some issue arises because of this. -The choices of +The default choices of .B gawk and .B cpp are fixed in the source code; users must edit .B cppawk -to select alternative implementations or locations of these tools. +to select alternative implementations or locations of these tools, +if they don't wish to use the +.BI --awk +and +.BI --prepro +command line options. The C preprocessor's .BR "#include \(dq...\(dq" @@ -220,5 +260,6 @@ command line. .SH AUTHOR Kaz Kylheku <kaz@kylheku.com> + .SH COPYRIGHT Copyright 2022, BSD2 License. @@ -178,3 +178,23 @@ foo_bar #endif' | grep foo_bar : foo_bar +-- +32: +./cppawk --awk='printf "[%.2s]"' foo +: +[-f][/t][--] +-- +33: +./cppawk --prepro-only --prepro='printf %.3s' abc +: +-iq-D_-I.- +-- +34: +./cppawk --prepro-only --awk=mawk mawk=__mawk__ | grep mawk +: +mawk=1 +-- +35: +./cppawk --prepro-only --awk=mawk gawk=__gawk__ | grep gawk +: +gawk=__gawk__ |