From 916da0fd59b0c004bd9f7ab26441de294a843e86 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Wed, 4 Mar 2020 09:25:17 +0000 Subject: [PATCH] fixed wrong error handling in bin/mani.c --- hawk/README.md | 66 +++++++++++++++++++++++++++++++++++++++++++++++++ hawk/bin/main.c | 2 +- 2 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 hawk/README.md diff --git a/hawk/README.md b/hawk/README.md new file mode 100644 index 00000000..e897a463 --- /dev/null +++ b/hawk/README.md @@ -0,0 +1,66 @@ +# Hawk + +# Table of Contents +- [Language](#language) +- [Embedding Guide](#embedding-guide) + +#### TODO: unary bitwise not +#### TODO: fix -F or --field-separator to hawk. + + +## Language + +Hawk implements most of the AWK programming language elements with extensions. + + +### Entry Point + +You may change the entry point of your script by setting a function name with @pragma entry. + +
+@pragma entry main
+
+function main ()
+{
+	print "hello, world";
+}
+
+ +### Value + +- unitialized value +- integer +- floating-point number +- string +- byte string +- array + +### Module + + + +### Incompatibility with AWK + +#### Parameter passing + +In AWK, the caller can pass an uninitialized variable as a function parameter and get a changed value if the callled function sets it to an array. + +
+function q(a) {a[1]=20; a[2]=30;}
+BEGIN { q(x); for (i in x) print i, x[i]; }
+
+ +In Hawk, you can prefix the pramater name with & to indicate call-by-reference for the same effect. +
+function q(&a) {a[1]=20; a[2]=30;}
+BEGIN { q(x); for (i in x) print i, x[i]; }
+
+ +Alternatively, you may form an array before passing it to a function. +
+function q(a) {a[1]=20; a[2]=30;}
+BEGIN { x[3]=99; q(x); for (i in x) print i, x[i]; }'
+
+ + +## Embedding Guide diff --git a/hawk/bin/main.c b/hawk/bin/main.c index 9cc66fc8..018d8fb7 100644 --- a/hawk/bin/main.c +++ b/hawk/bin/main.c @@ -381,7 +381,7 @@ static int apply_fs_and_gvs_to_rtx (hawk_rtx_t* rtx, arg_t* arg) /* compose a string value to use to set FS to */ fs = hawk_rtx_makestrvalwithbcstr(rtx, arg->fs); - if (fs) return -1; + if (!fs) return -1; /* change FS according to the command line argument */ hawk_rtx_refupval (rtx, fs);