|
NAMEawka - AWK language to ANSI C translator and librarySYNOPSISawka [-c fn] [-X] [-x] [-t] [-o filename] [-a args] [-w args] [-I include-dir] [-i include-file] [-L lib-dir] [-l lib-file] [-f progname] [-d] [program] [--] [exe-args]awka [-version] [-help] DESCRIPTIONAwka is two products - a translator of AWK language programs to ANSI-C, and a library of essential functions against which the translated code must be linked.The AWK language is useful for maniplation of datafiles, text retrieval and processing, and for prototyping and experimenting with algorithms. Usually AWK is implemented as an interpretive language - there are several good free interpreters available, notably gawk, mawk and 'The One True Awk' maintained by Brian Kernighan. This manpage does not explain how AWK works - refer to the SEE ALSO section at the end of this page for references. Awka is a new awk meaning it implements the AWK language as defined in Aho, Kernighan and Weinberger, The AWK Programming Language, Addison-Wesley Publishing 1988. Awka includes features from the Posix 1003.2 (draft 11.3) definition of the AWK language, but does not necessarily conform in entirety to Posix standards. Awka also provides a number of extensions not found in other implementations of AWK. AWKA OPTIONS
EXECUTABLE OPTIONSAn executable formed by compiling Awka-generated code against libawka.a will also understand several command-line arguments.
ADDITIONAL FEATURESawka contains a number of builtin functions may or may not presently be found in standard AWK implementations. The functions have been added to extend functionality, or to provide a faster method of performing tasks that AWK could otherwise undertake in an inefficient way.The new functions are:-
The SORTTYPE variable controls if and how arrays are sorted when accessed using 'for (i in j)'. The value of this variable is a bitmask, which may be set to a combination of the following values:- 0 No Sorting 1 Alphabetical Sorting 2 Numeric Sorting 4 Reverse Order A value for SORTTYPE of 5, therefore, indicates that the array is to be sorted Alphabetically, in Reverse order. Awka also supports the FIELDWIDTHS variable, which works exactly as it does in Gawk. If the FIELDWIDTHS variable is set to a space separated list of positive numbers, each field is expected to have fixed width, and awka will split up the record using the widths specified in FIELDWIDTHS. The value of FS is ignored. Assigning a value to FS overrides the use of FIELDWIDTHS, and restores the default behaviour. Awka also introduces the SAVEWIDTHS variable. This applies when FIELDWIDTHS is in use, and $0 is being rebuilt following a change to a $1..$n field variable. If the SAVEWIDTHS variable is set to a space separated list of positive numbers, each output field will be given a fixed width to match these numbers. $n values shorter than their specified width will be padded with spaces; if they are longer than their specified width they will be truncated. Additional values to those specified in SAVEWIDTHS will be separated using OFS. Awka 0.7.5 supports the inet/coprocessing features introduced in
Gawk 3.1.0. See the documentation accompanying the Gawk source, or visit
http://home.vr-web.de/Juergen.Kahrs/gawk/gawkinet.html for details on
how these work.
EXAMPLESThe command-line arguments above provide a range of ways in which awka may be used, from output of C code to stdout, through to an automatic translation compile and execution of the AWK program.(a) Producing C code:- 1. awka -f myprog.awk >myprog.c 2. awka -c main_one -f myprog.awk -f other.awk >myprog.c (b) Producing C code and an executable:- awka -X -f myprog.awk -f other.awk (c) Producing the C and Executable, run the executable:- awka -x -f myprog.awk -f other.awk -- input.txt Afterwards, you could run the executable directly, as in:- awka.out input.txt Running the same program using an interpreter such as mawk would be done as follows:- mawk -f myprog.awk -f other.awk input.txt The following will run the program, passing it -v on the command-line without it being interpreted as an 'option':- awka.out -We -v input.txt, OR awka -x -f myprog.awk -- -We -v input.txt (d) Producing and running the executable, ensuring it and the C program file are automatically removed:- awka -x -t -f myprog.awk -f other.awk -- input.txt (e) A simplistic example of how awka might be used in a Makefile:- myprog: myprog.o gcc myprog.o -lawka -lm -o myprog myprog.o: myprog.c myprog.c: myprog.awk awka -f myprog.awk >myprog.c LINKING AWKA-GENERATED CODEThe C programs produced by awka call many functions in libawka.a. This library needs to be linked with your program for a workable executable to be produced.Note that when using the -x and -X arguments this is automatically taken care of for you, so linking is only an issue when you use Awka to produce C code, which you then compile yourself. Many people many only wish to use Awka in this way, and never use awka-generated code as part of larger applications. If this is you, you needn't worry too much about this section. As well as linking to libawka.a, your program will also need to be linked to your system's math library, typically libm.a or libm.so. Typical compiler commands to link an awka executable might be as follows:- gcc myprog.c -L/usr/local/lib -I/usr/local/include -lawka -lm -o myprog OR awka -c my_main -f myprog.awk >myprog.c gcc -c myprog.c -I/usr/local/include -o myprog.o gcc -c other.c -o other.o gcc myprog.o other.o -L/usr/local/lib -lawka -lm -o myapp If you are not sure of how your compiler works you should consult the manpage for the compiler. In release 0.7.5 Awka introduced Gawk-3.1.0's inet and coprocess features. On some platforms this may require you to link to the socket and nsl libraries (-lsocket -lnsl). To check this, look at config.h after running the configure script. The #define awka_SOCKET_LIBS indicate what, if any, extra libraries are required on your system. USING awka -cThe -c option, as described previously, replaces the main() function with a function name of your choosing. You may then link this code to other C or C++ code, and thus add AWK functionality to a larger application.The command line "awka -c matrix 'BEGIN { print "what is the matrix?" }'" will produce in its output the function "int matrix(int argc, char *argv[])". Obviously, this replaces the main() function, and the argc and argv variables are used the same way - they handle what awka thinks are command-line arguments. Hence argv is an array of pointers to char *'s, and argc is the number of elements in this array. argv[0], from the command-line, holds the name of the running program. You can populate as many argv[] elements as you like to pass as input to your AWK program. Just remember this array is managed by your calling function, not by awka. That's just about it. You should be able to call your awka function (eg matrix()) as many times as you like. It will grab a little bit of memory for itself, but you should see no growing memory use with each call, as I've taken quite some time to eliminate any potential memory leaks from awka code. Oh, one more thing, exit and abort statements in your AWK program code will still exit your program altogether, so be careful of where & how you use them. GOING FURTHERAwka also allows you to create your own C functions and have them accessible in your AWK programs as if they were built-in to the AWK language. See the awka-elm and awka-elmref manpages for details on how this is done.FILESlibawka.a, libawka.so, awka, libawka.h, libdfa.a, dfa.hSEE ALSOawk(1), mawk(1), gawk(1), awka-elm(5) awka-elmref(5), cc(1), gcc(1)Aho, Kernighan and Weinberger, The AWK Programming Language, Addison-Wesley Publishing, 1988, (the AWK book), defines the language, opening with a tutorial and advancing to many interesting programs that delve into issues of software design and analysis relevant to programming in any language. The GAWK Manual, The Free Software Foundation, 1991, is a tutorial and language reference that does not attempt the depth of the AWK book and assumes the reader may be a novice programmer. The section on AWK arrays is excellent. It also discusses Posix requirements for AWK. Like you, I should probably buy & read these books some day. MISSING FEATURESawka does not implement gawk's internal variable IGNORECASE. Gawk's /dev/pid functions are also absent.Nextfile and next may not be used within functions. This will never be supported, unlike the previous features, which may be added to awka over time. Well, so I thought. As of release 0.7.3 you _can_ use these from within functions. AUTHORAndrew Sumner (andrewsumner@yahoo.com)The awka homepage is at http://awka.sourceforge.net. The latest version of awka, along with development 'snapshot' releases, are available from this page. All major releases will be announced in comp.lang.awk. If you would like to be notified of new releases, please send me an email to that effect. Make sure you preface any email messages with the word "awka" in the title so I know its not spam.
Visit the GSP FreeBSD Man Page Interface. |