Short: Fully functional AT&T awk for all Amigas Author: AT&T Uploader: torsten diku dk (Torsten Poulin) Type: util/cli Architecture: m68k-amigaos Version 1.0 of a fully functional Amiga port of the April 22, 1994 version of AT&T awk compiled with SAS/C 6.51. ------------------------------------------------------------------ The AT&T supplied code is 100% unchanged! The file "amiga.c" contains all the necessary adaptions to the AmigaDOS environment. I have run the "awk.g.y" and "awk.lx.l" files through yacc and lex respectively on an HP-UX workstation. The resulting C sources seem to build okay on the Amiga. The included smakefile does not attempt to recreate them. My advice is: do not delete "y.tab.c", "y.tab.h", and "lex.yy.c"! To rebuild using SAS/C 6.51, just unpack the Amiga and AT&T source to the same directory and type smake. Pipes are implemented in a very simplistic way. In fact they are not really pipes at all. Instead they are simulated using temporary files in the T: directory. This may change in the future, Matthew Dillon's FifoLib looks like a promising candidate. The awk ENVIRON array holds copies of the local shell variables, but only under AmigaDOS 2.04+. Yes, awk should work with all versions of AmigaDOS. Command line arguments are treated a bit differently than with most Amiga programs. Both the usual " as well as ' can be used to quote arguments: awk "BEGIN { *"date*" |getline d; print d }" awk 'BEGIN { "date" |getline d; print d }' Personally I tend to prefer the latter form, as it resembles the examples in A.V.Aho et al. "The AWK Programming Language". The escape character is the asterisk usually used in AmigaDOS. I tried using a backslash, but at least with WShell it caused more trouble than it is worth, because WShell (by necessity) tries to be clever about the contents of the command line. Liberal use of escapes may be necessary when using single quotes, depending on which shell you use, e.g., awk 'BEGIN { "date" *|getline d *; print d }' The blanks before the asterisks are significant in WShell. If you don't want to bother with all these pitfalls, you can of course always put your script in a file and use the -f option... Arguments are treated like AmigaDOS patterns, and expanded, if (1) they are not surrounded by single or double quotes, and (2) they contain at least one of the eight characters "~#?*%([|", and (3) awk is run under AmigaDOS V36+ OR arp.library is installed. The program works with pre-V36 AmigaDOS even if arp.library isn't installed, but it will not expand patterns. It will not attempt to open arp.library if running under V36+. This example prints the total number of characters, words, and lines in the files in the current directory: awk "{ nc+=length($0)+1; nw+=NF} END { print nc, nw, NR }" #?.txt With a little extra work, it can be turned into a clone of the UNIX wc command :-) A word of warning. If an AmigaDOS pattern doesn't match any filenames, it expands to nothing, possibly causing an awk script to seem like it is hanging, while it is in fact just waiting for input from stdin. In that case you can just press Ctrl-\ (end of file). Before I forget it, awk is pure and can be made resident. Comments, questions and bug reports concerning this port can be sent to me at the following address: Torsten Poulin Banebrinken 99, 2, 77 DK-2400 København NV Denmark or via e-mail: torsten@diku.dk (preferred) Please note that my snail-mail address will change sometime this autumn. The Danish Mail will forward any letters to me for half a year after that, though. Have fun, Torsten P.S. awk is copyrighted by AT&T. Please refer to the copyright notices in the source and documentation files for details.