What is 3q?
3q is a CGI script that executes awk code that is embedded into HTML files on your web server. To be more precise 3q
- expects XML-like formatted files. You don't need to use an XML editor, HTML files where every tag is properly closed are accepted, <some-tag/> is supported.
- awk code is placed inside a `<? awk ... ?>' processing instruction. The `awk' keyword is required.
- The awk code is limited to code that can be placed in a BEGIN block which excludes user functions.
- User functions must be placed in library files that can be #use'd from the 3q script file.
How is this working?
3q is itself an awk script so there must be a trick. First 3q reads the XML file and converts this into a gawk script, static HTML/XML text is converted in printf() calls and source code inside <? awk ... ?> is passed as is. The resulting script code is then passed to a second gawk invocation as command line script. 3q relies heavily on proper shell quoting.
This idea is not new. Recently I found SQAwk on Sourceforge: http://sourceforge.net/projects/sqawk/. The basic principle is the same (quoting then executing) but for some reason this project was abandoned.
Download the script: 3q.
- The total length of the executed gawk script and passed CGI variables depends on limitations of the shell interpreter regarding the command line length. This is not longer an issue because of the usefiles modification.
- 3q uses "expensive" (in terms of CPU time) system() calls to stat() files and for script execution.