Re: runawk: awk wrapper that help implements modules
am 09.10.2007 11:33:25 von Aleksey Cheusov> I suspect that, however well I have tried to visually scan
> the C source and documentation, I probably am misconstruing
> the finer nuances of runawk.c. Would you clarify some points
> by comparing and contrasting it to the following programs?
> "awkfe.c": canonical #!, manage PATH, implement #include
> ftp://ftp.freefriends.org/arnold/Awkstuff/awkfe
I used it years ago. I've found awkfe.c somewhere. AFAIR
sombody mentioned it in this conference.
awkfe has several problems.
1) It seems it has no maintainer.
2) It has no VERSIONED tarball. I cannot package it or at least
package with no version is a strange package.
3) It is buggy. I don't believe in things
written once and forever. Illustration:
0 ~> gcc -o awkfe awkfe.c
awkfe.c: In function 'help':
awkfe.c:45: warning: incompatible implicit declaration of built-in function 'exit'
awkfe.c: In function 'main':
awkfe.c:173: error: conflicting types for 'sys_errlist'
/usr/include/bits/sys_errlist.h:28: error: previous declaration of 'sys_errlist' was here
awkfe.c:219: warning: assignment makes pointer from integer without a cast
awkfe.c:224: warning: incompatible implicit declaration of built-in function 'exit'
awkfe.c:229: warning: assignment makes pointer from integer without a cast
awkfe.c:236: warning: incompatible implicit declaration of built-in function 'exit'
awkfe.c:250: warning: incompatible implicit declaration of built-in function 'exit'
awkfe.c:264: warning: incompatible implicit declaration of built-in function 'exit'
awkfe.c:316: warning: incompatible implicit declaration of built-in function 'exit'
awkfe.c:350: warning: incompatible implicit declaration of built-in function 'exit'
1 ~>
3) awkfe's #include directive is not the similar to runawk's #use
#use doesn't check all modules for duplications and include every
module only once. awkfe's #include is similar to cpp's #include.
I don't like it.
4) runawk support -e option that may be used like this
#!/bin/sh
runawk -e '
#use "assert.awk"
{
assert(NF == 2, "Two tokens required")
print $2, $1
}
'
> "awkfe.c": AFAIK, manage command-line, #include, scripts
> http://www.longtail.co.jp/pck/main/awkfe.htm # in Japanese
I speak Russian, Belarusian and English, but not Japanese :)
> http://www.longtail.co.jp/pck/awkfe.zip # a compiled GUI PC executable
> in Japanese
Oops. I don't use Windows.
> Although named similarly, they are have different approaches
> to solve the same solution, at least insofar the former is a
> command-line developer's frontend, and the latter is more a
> user-level GUI frontend. (It's inaccessible except for the
> above Japanese version and documentation).
runawk doesn't concerns GUI in any way.
> Some notes:
> (1) POSIX specifies that "#"-directives (#include, #define, ...)
> allow intervening whitespace between the octothorpe ("#")
> and the directive as long as it appears on column 1 of the
> line. I cannot determine that runawk.c allows this.
Yes. In runawk neither spaces nor tabs are allowed between # sign
and 'use' or 'interp'. Do you think it whould be better to allow them?
> (2) Is it ameniable to your specification to allow runawk to
> invoke a macro substitution engine, a la cpp(1) or m4(1),
> via a command-line option? If runawk were awk code, I would
> point you to m1.awk, and suggest an inclusion of its code at:
Do you mean preprocessing source file before runnig?
Bad news about m4 is that -P option available in GNU m4 and NetBSD m4
is not portable. From m4(1)
-P, --prefix-builtins
force a `m4_' prefix to all builtins
> "m1.awk"
> http://www.ddj.com/dept/cpp/200001791
> http://www.ddj.com/article/printableArticle.jhtml?articleID= 200001791&dept_url=/dept/cpp/
> ... but otherwise it is more appropriate to call it via
> popen(3), instead of merging its functionality into your own
> codebase.
I agree with this. runawk allows you to set the interpreter
using #interp directive. Macros can be allowed there.
> (3) Does runawk allow what in ksh(1) is the feature called
> autoloading? The envvar AWKPATH is for finding the n/awk(1)
> executable, and not as ksh(1)'s "FPATH", right?
AWKPATH variable is used for finding .awk modules like GNU awk does.
> (4) How does "#use" work? I though n/awk(1) does not allow
> forward references.
README file describes this. Main file is processed
like this (approximate not formal description!).
process_file (file)
while l = read_line_from (file)
if (l ~ /^#use ".*"/)
module = substring_between_double_quotes (l)
if (module is not cmd yet)
process_file (module)
end
cmd += " -f " module
end
end
end
cmd="/path/to/awk"
process_file (main_program_file)
cmd += " --"
call (cmd)
> (5) Could runawk be generalized to function as awkfe.c
> (the first one) does, allowing primary and secondary "#!"
> lines, like its documented example:
> #!/usr/local/bin/awkfe
> #!/usr/bin/awk -f
I don't think that this way of setting not default interpreter is good.
Runawk provides #interp directive for this.
> Other programs address this problem, including:
> shebangwrapper:
> http://sf.net/projects/shebangwrapper/
I'll see it.
> P.S. Would you multipost (a request I don't make often!)
> this thread to comp.unix.shell?
done
--
Best regards, Aleksey Cheusov.