I'm using GNU Awk 3.1.6 filtering data.
I have not found if it is possible to have Interpreter Informations
like: i.e. source line number; function name; source filename.
Many thanks
Roby
As far as I know, all you can do is recompile gawk itself with "-
DDEBUG" and then run your script with "-W parsedebug" to get a trace
of the lines being parsed.
It's interesting that after 15 or so years of using awk and about 25
years of frequently using those equivalent pre-processor constructs in
C, I've never even noticed they were missing from awk. I suspect that
has something to do with the simplicity of the awk language and the
relative size/complexity of the programs I write in awk vs C. I wonder
if you're trying to use awk in a way that might better suit some other
tool/language....
Ed.
I've never had a need for those things.
When awk code is not working right, I add various print commands to dump
the questionable variables and position in the program to a log file. Then
I feed the script carefully constructed test data. This is not unlike the
technique I use with other scripting languages.
I also create separate test scripts, especially whne I'm having trouble
with regular expression matches. For example, if the task is to see is a
specific field in an HTML file matches a regex, I would construct a (gawk)
test program like this to replace $(x)~/expression/
BEGIN{ FS="[<>]" }
{
for( x = 1; x <= NF; x++ ) {
print x,$x
if( match( $x, /expression/, A )) print "match: " x, A[x]
}
}
That shows me exactly what the fields are and their field number, and also
shows what, if anything matched what field. If there are no matches, then
I run it with just parts of the expression to find which part isn't
working.
TAWK, which is no longer available, had a debugger, but I found it
slightly less useful than the above approach.
--
T.E.D. (tda...@mst.edu) MST (Missouri University of Science and Technology)
used to be UMR (University of Missouri - Rolla).
Hi, Ted.
Also you, I see, are working with debug prints.
It is a long time of fighting to avoid them with the result they are
always more invasive
and .. useful.
My original idea posing the question was to obtaion informations like
line number, function name and file source name from Interpreter.
Then add it to the line:
if( __deb ) print "|" a "|" b "|" c "<--- <funt. Name>(a, b, c)" ##
The last ## is added as a code to see immediatly the line type.
This is a service line dedicated to Debug purposes, for example.
Obviously, the __deb variable is setted in the calling line (--
assign=__debEnb=1)
The Interpreter is, generally, the best environment for having on line
all these (.. and other) informations.
I agree with you on using Debuggers (.. also I try TAWK) during the
Sofware life cycle.
So I continue to add debug prints.
Many thanks for your support
Roby
Hi, Ed.
Actually I partially resolve the problem with debug prints.
It is a long time of fighting to avoid them in different languages
(C, JAVA, SNOBOL, .., MODULA-2, Pascal and some Assemblers)
with the result they are always more invasive and .. useful.
My original idea posing the question was to obtaion informations like
line number, function name and file source name from Interpreter.
The add it to the line:
if( __deb ) print "|" a "|" b "|" c "<--- <funct. Name>(a, b, c)" ##
The last ## is added as a code to see immediatly the line type.
This is a service line dedicated to Debug purposes.
The __deb variable is setted in the calling line (--assign=__debEnb=1)
The Interpreter is, generally, the best environment for having on line
all these (.. and other) informations.
Now I have a dubt: is GAWK an Interpreter?
About your asnwer I have not checked -DDEBUG and so on.
I'll inform you asap.
Good idea to change tool/language. What are prefering you?
Right. You might want to do that something like this:
trc(fname,argc,a,b,c,d,e,f,... argv,argi,args,sep) {
if (__deb) {
argv[1]=a
argv[2]=b
argv[3]=c
....
for (argi=1; argi<=argc; argi++) {
args = args sep argv[argi]
sep = ","
}
printf "%s(%s)\n",fname,args
}
}
foo(x) {
trc("foo",1,x)
}
bar(l,m,n,o) {
trc("bar",4,l,m,n,o)
}
> The __deb variable is setted in the calling line (--assign=__debEnb=1)
Using "-v":
-v __deb=1
is more common.
>
> The Interpreter is, generally, the best environment for having on line
> all these (.. and other) informations.
>
> Now I have a dubt: is GAWK an Interpreter?
Yes.
> About your asnwer I have not checked -DDEBUG and so on.
> I'll inform you asap.
>
> Good idea to change tool/language. What are prefering you?
I typically use sed for simple changes on one line of a text file, awk
for any more complicated text manipulation that doesn't have to be
particularly fast, C for anything procedural, VFSM (with C or C++) for
anything that involves networks of communicating objects, and various
shell scripts/tools for anything involving process and/or file
manipulation.
> Many thanks for your support
No problem. What are you trying to do with awk anyway?
Ed.
>
> Roby
I have written a converter from an optimized CAD file to be compatible
with a PLC controller for a wood cutting machine. Actually I collect
about 700 lines of effective code (the total lines are about doubled)
to implement all functions.
The requests was born by the necessity to create the code for
automatica testing the application code. I'm tired to do an redo all
test following any little or stupid change. Working in this way I live
with the fear to see my application broken and the production stopped.
Is there any code in AWK like JUnit or somthing like that? Or in
general ideas for testing in this language?
About the languages you are using. What is VSFM?
I have written something in C and C++ but now I need to use the source
code available on Internet. What is the best configuration for
Windows? I refer to Open or something like that.
In parallel to this development I watch the TCL/TK as a Glue Language
to add GUI interface and other features not available in GAWK. Do you
know this language? What do you thing about that?
Many thanks
-re-
The code you have sketched is exactly what i have in my mind.
How can you read my mind :-)
I have many difficulties doing that.
Ciao e Grazie
-re-
I don't have any good answers to your other question in this thread,
but VFSM is described at http://en.wikipedia.org/wiki/Virtual_finite_state_machine.
I use a slightly different (internal/proprietary and fairly similair
to Spin, http://spinroot.com/spin/whatispin.html) version of the
language and tools than those supported by StateWorks but you'll get
the idea on that page that it's all about specifying behavior of
individual objects in abstract ways, then testing that they work
together as expected and THEN writing code to hook them into the base
after you've proven your design behaves as expected (see also the
Bridge design pattern from the GOF book - http://en.wikipedia.org/wiki/Bridge_pattern).
Ed.
This is the first time I meet this keyword.
Very interesting.
Have a nice day.
-re-
Long before things like JUnit became popular people used very simple
test frameworks for regression testing text-based tools like a complex
awk script:
The architecture of such a framework is very simple:
- A directory with a set of files with input data
- A directory with a set of files with expected output, one file per
input data file in the input directory
- A tool (script, probably in a makefile), running each file found in
the input directory through the program under test, and comparing the
output with the corresponding expected output (comparing means using
diff under Unix)
- Differences from the expected output are flagged and need manual
inspections (they might come from function enhancements in the program
under test, and need not necessarily be bugs).
- Statistics of passed/failed test cases can be recorded by the tool as
desired.
An implementation is easy, using Unix tools, but this is out of the
scope of this awk group.
/Thomas
I agree with you.
Many thanks
-re-
I have used many languages since 1970 BUT I have seen the time
involved in configuring Sw growing every day.
Anyway I need to use C sources.
So, please can you propose something under windows. Actually, under
Windows, I have installed MingW (EXE 24/04/08) and Cygwin (EXE
24/01/08).
Many thanks
Roby
> Also you, I see, are working with debug prints.
> It is a long time of fighting to avoid them with the result they are
> always more invasive
> and .. useful.
With runawk, you can create awk module like this:
debug.awk:
BEGIN {
__debug_mode = (ENVIRON ["AWKDEBUG"] != "")
}
function debug_print (msg){
if (__debug_mode)
print msg > "/dev/stderr"
}
And then use this module in your scripts.
#!/usr/bin/env runawk
#use "debug.awk"
{
...
debug_print("val=" val)
...
}
and run it like the following
env AWKDEBUG=1 ./script
This makes script a bit easier, but...
--
Best regards, Aleksey Cheusov.