GithubHelp home page GithubHelp logo

noyesno / awka Goto Github PK

View Code? Open in Web Editor NEW
98.0 9.0 8.0 1.68 MB

Revive awka - Awk to C Compiler

Home Page: https://project.noyesno.net/awka/

C 81.19% C++ 1.26% Yacc 2.95% Awk 8.55% Perl 0.99% Tcl 1.06% Shell 0.14% Makefile 2.01% M4 0.87% Raku 0.10% Python 0.88%
awk awk2c compiler awka code-generator awk-script translator

awka's Introduction

Awka

C/C++ CI

This is a fork and enhanced version of Awka.

Awka - Open Source, AWK to C Conversion

Awka is not an interpreter like Gawk, Mawk or Nawk, but instead it converts the program to ANSI-C, then compiles this using gcc or a native C compiler to create a binary executable.

-- http://awka.sourceforge.net/index.html

  • Awka has two main parts: a translator and a library.
  • awka translate a Awk script into C code
  • libawka is used as link library to compile the generated C code.

Why compile Awk script into C program?

  • C program probably run faster.
  • "AWK programs are limited to what the interpreter provides".
  • "C code can be compiled with other code into a larger application."
  • "migrate stable functions from AWK to C" to impove performance.
  • Reuse existing C functions in Awk script.
  • A way of protect your Awk script.

Actually, the mixing use of Awk and C provide provide an interesting way of writing programs.

Revive Awka

Awka is an "old" project. Its last change 0.7.5 was on June 20 2001.

And to fill my usage requirement, some of my update to the code go much furhter than traditional "Awk".

What's new in "Revive Awka"?

  • Fix bugs in awka-0.7.5
  • Add libawka builtin function fseek and ftell to increase performance.
  • Add glob style matching, which shold be faster than regular expression in many case.
  • Lazy calling of line split function to increase performance.
  • Use nstring other than NULL terminated C string to avoid string copy.

What to do next?

  • Continue bug fixing.
  • Continue libawka performance improvement.
  • Support flexibl synax in the "Awk" script.
    • For example, add direct Tcl language support.
  • Make it thread safe to support processing multiple files in parallel.

awka's People

Contributors

noyesno avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

awka's Issues

How to compile this program on Big Sur?

My OS is Big Sur. I got the following error. Does anybody know how to fix it?

$ gcc --version
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/4.2.1
Apple clang version 12.0.5 (clang-1205.0.22.11)
Target: x86_64-apple-darwin20.5.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
$ make
cd awka; make
make[1]: Entering directory '/tmp/awka/awka'
gcc -O -Dawka_LIBDIR=\"/usr/local/lib\" -Dawka_INCDIR=\"/usr/local/include\"   -c -o translate.o translate.c
translate.c:111:11: warning: using the result of an assignment as a condition without parentheses [-Wparentheses]
  while(c = *p++){
        ~~^~~~~~
translate.c:111:11: note: place parentheses around the assignment to silence this warning
  while(c = *p++){
          ^
        (       )
translate.c:111:11: note: use '==' to turn this assignment into an equality comparison
  while(c = *p++){
          ^
          ==
1 warning generated.
gcc -O -Dawka_LIBDIR=\"/usr/local/lib\" -Dawka_INCDIR=\"/usr/local/include\"   -c -o awka.o awka.c
expect 8 shift/reduce conflicts
bison -y  -d parse.y
parse.y: warning: 8 shift/reduce conflicts [-Wconflicts-sr]
parse.y: note: rerun with option '-Wcounterexamples' to generate conflict counterexamples
mv y.tab.c parse.c
if cmp -s y.tab.h parse.h ;\
then rm y.tab.h ;\
else mv y.tab.h parse.h ; fi
gcc -O -Dawka_LIBDIR=\"/usr/local/lib\" -Dawka_INCDIR=\"/usr/local/include\"   -c -o parse.o parse.c
gcc -O -Dawka_LIBDIR=\"/usr/local/lib\" -Dawka_INCDIR=\"/usr/local/include\"   -c -o scan.o scan.c
scan.c:1128:19: warning: initializing 'unsigned char *' with an expression of type 'char *' converts between pointers to integer types with different sign [-Wpointer-sign]
   unsigned char *s = e_flag ? rm_escape(string_buff) : string_buff ;
                  ^   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
scan.c:1130:34: warning: passing 'unsigned char *' to parameter of type 'char *' converts between pointers to integer types with different sign [-Wpointer-sign]
   yylval.ptr = (PTR) new_STRING(s);
                                 ^
./memory.h:35:33: note: passing argument to parameter here
STRING *PROTO(new_STRING, (char*)) ;
                                ^
2 warnings generated.
gcc -O -Dawka_LIBDIR=\"/usr/local/lib\" -Dawka_INCDIR=\"/usr/local/include\"   -c -o memory.o memory.c
gcc -O -Dawka_LIBDIR=\"/usr/local/lib\" -Dawka_INCDIR=\"/usr/local/include\"   -c -o hash.o hash.c
gcc -O -Dawka_LIBDIR=\"/usr/local/lib\" -Dawka_INCDIR=\"/usr/local/include\"   -c -o code.o code.c
gcc -O -Dawka_LIBDIR=\"/usr/local/lib\" -Dawka_INCDIR=\"/usr/local/include\"   -c -o bi_funct.o bi_funct.c
bi_funct.c:164:27: warning: using the result of an assignment as a condition without parentheses [-Wparentheses]
            while (target = strchr(target, k))
                   ~~~~~~~^~~~~~~~~~~~~~~~~~~
bi_funct.c:164:27: note: place parentheses around the assignment to silence this warning
            while (target = strchr(target, k))
                          ^
                   (                         )
bi_funct.c:164:27: note: use '==' to turn this assignment into an equality comparison
            while (target = strchr(target, k))
                          ^
                          ==
bi_funct.c:172:18: warning: using the result of an assignment as a condition without parentheses [-Wparentheses]
   while (target = strchr(target, k))
          ~~~~~~~^~~~~~~~~~~~~~~~~~~
bi_funct.c:172:18: note: place parentheses around the assignment to silence this warning
   while (target = strchr(target, k))
                 ^
          (                         )
bi_funct.c:172:18: note: use '==' to turn this assignment into an equality comparison
   while (target = strchr(target, k))
                 ^
                 ==
2 warnings generated.
gcc -O -Dawka_LIBDIR=\"/usr/local/lib\" -Dawka_INCDIR=\"/usr/local/include\"   -c -o da.o da.c
gcc -O -Dawka_LIBDIR=\"/usr/local/lib\" -Dawka_INCDIR=\"/usr/local/include\"   -c -o error.o error.c
gcc -O -Dawka_LIBDIR=\"/usr/local/lib\" -Dawka_INCDIR=\"/usr/local/include\"   -c -o init.o init.c
gcc -O -Dawka_LIBDIR=\"/usr/local/lib\" -Dawka_INCDIR=\"/usr/local/include\"   -c -o bi_vars.o bi_vars.c
gcc -O -Dawka_LIBDIR=\"/usr/local/lib\" -Dawka_INCDIR=\"/usr/local/include\"   -c -o cast.o cast.c
gcc -O -Dawka_LIBDIR=\"/usr/local/lib\" -Dawka_INCDIR=\"/usr/local/include\"   -c -o print.o print.c
print.c:52:11: error: expected parameter declarator
int PROTO(sprintf, (char *, const char *,...)) ;
          ^
print.c:52:11: error: expected ')'
print.c:52:11: note: to match this '('
print.c:52:11: error: conflicting types for '__builtin___sprintf_chk'
int PROTO(sprintf, (char *, const char *,...)) ;
          ^
print.c:52:11: note: '__builtin___sprintf_chk' is a builtin with type 'int (char *, int, unsigned long, const char *, ...)'
3 errors generated.
make[1]: *** [<builtin>: print.o] Error 1
make[1]: Leaving directory '/tmp/awka/awka'
make: *** [Makefile:48: awka_exe] Error 2

Awka produces incorrect code.

Hi, I tried to build but all test cases fail , and also the generated C code contains syntax errors like the following:

error: expected expression before ',' token
, awka_arg1(a_TEMP, arka_dol0(0)));

any suggestion?

compile issue

I have a problem compiling your software.

Here is small info about my environment:
OS: ubuntu 16.04
gcc: 5.4.0

The summary of an error is like:

make[1]: *** No rule to make target 'strfunc.o', needed by 'libawka.a'. Stop.
make[1]: Leaving directory '/home/gawi/Desktop/tmp/Martyn/awka/lib'
Makefile:45: recipe for target 'libawka' failed
make: *** [libawka] Error 2

In the attachment you can find output of ./configure and make commands:

Supporting all gawk functions

It seems that some gawk functions are not supported by awka. Could those functions be supported?

$ awk 'BEGIN { x=x; print typeof(x) }'
unassigned
$ awka 'BEGIN { x=x; print typeof(x) }' > a.c
$ gcc -lawka a.c
a.c:16:44: error: implicit declaration of function 'typeof_fn' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
  awka_print(NULL, 0, 0, awka_arg1(a_TEMP, typeof_fn(awka_arg1(a_TEMP, x_awk))));
                                           ^
a.c:16:44: warning: incompatible integer to pointer conversion passing 'int' to parameter of type 'a_VAR *' [-Wint-conversion]
  awka_print(NULL, 0, 0, awka_arg1(a_TEMP, typeof_fn(awka_arg1(a_TEMP, x_awk))));
                                           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/local/include/libawka.h:1405:35: note: passing argument to parameter here
a_VARARG * awka_arg1(char, a_VAR *);
                                  ^
1 warning and 1 error generated.

does not compile

I just tried ./configure && make all but is failed.

cd awka; make
make[1]: Entering directory 'awka'
gcc -O -Dawka_LIBDIR=\"/usr/local/lib\" -Dawka_INCDIR=\"/usr/local/include\"   -c -o translate.o translate.c
gcc -O -Dawka_LIBDIR=\"/usr/local/lib\" -Dawka_INCDIR=\"/usr/local/include\"   -c -o awka.o awka.c
gcc -O -Dawka_LIBDIR=\"/usr/local/lib\" -Dawka_INCDIR=\"/usr/local/include\"   -c -o parse.o parse.c
gcc -O -Dawka_LIBDIR=\"/usr/local/lib\" -Dawka_INCDIR=\"/usr/local/include\"   -c -o scan.o scan.c
gcc -O -Dawka_LIBDIR=\"/usr/local/lib\" -Dawka_INCDIR=\"/usr/local/include\"   -c -o memory.o memory.c
gcc -O -Dawka_LIBDIR=\"/usr/local/lib\" -Dawka_INCDIR=\"/usr/local/include\"   -c -o hash.o hash.c
gcc -O -Dawka_LIBDIR=\"/usr/local/lib\" -Dawka_INCDIR=\"/usr/local/include\"   -c -o code.o code.c
gcc -O -Dawka_LIBDIR=\"/usr/local/lib\" -Dawka_INCDIR=\"/usr/local/include\"   -c -o bi_funct.o bi_funct.c
gcc -O -Dawka_LIBDIR=\"/usr/local/lib\" -Dawka_INCDIR=\"/usr/local/include\"   -c -o da.o da.c
gcc -O -Dawka_LIBDIR=\"/usr/local/lib\" -Dawka_INCDIR=\"/usr/local/include\"   -c -o error.o error.c
gcc -O -Dawka_LIBDIR=\"/usr/local/lib\" -Dawka_INCDIR=\"/usr/local/include\"   -c -o init.o init.c
gcc -O -Dawka_LIBDIR=\"/usr/local/lib\" -Dawka_INCDIR=\"/usr/local/include\"   -c -o bi_vars.o bi_vars.c
gcc -O -Dawka_LIBDIR=\"/usr/local/lib\" -Dawka_INCDIR=\"/usr/local/include\"   -c -o cast.o cast.c
gcc -O -Dawka_LIBDIR=\"/usr/local/lib\" -Dawka_INCDIR=\"/usr/local/include\"   -c -o print.o print.c
gcc -O -Dawka_LIBDIR=\"/usr/local/lib\" -Dawka_INCDIR=\"/usr/local/include\"   -c -o kw.o kw.c
gcc -O -Dawka_LIBDIR=\"/usr/local/lib\" -Dawka_INCDIR=\"/usr/local/include\"   -c -o jmp.o jmp.c
gcc -O -Dawka_LIBDIR=\"/usr/local/lib\" -Dawka_INCDIR=\"/usr/local/include\"   -c -o field.o field.c
gcc -O -Dawka_LIBDIR=\"/usr/local/lib\" -Dawka_INCDIR=\"/usr/local/include\"   -c -o re_cmpl.o re_cmpl.c
gcc -O -Dawka_LIBDIR=\"/usr/local/lib\" -Dawka_INCDIR=\"/usr/local/include\"   -c -o preprocess.o preprocess.c
gcc -O -Dawka_LIBDIR=\"/usr/local/lib\" -Dawka_INCDIR=\"/usr/local/include\"   -c -o zmalloc.o zmalloc.c
gcc -O -Dawka_LIBDIR=\"/usr/local/lib\" -Dawka_INCDIR=\"/usr/local/include\"   -c -o msg.o msg.c
gcc -O -Dawka_LIBDIR=\"/usr/local/lib\" -Dawka_INCDIR=\"/usr/local/include\"   -c -o scancode.o scancode.c
gcc -O -Dawka_LIBDIR=\"/usr/local/lib\" -Dawka_INCDIR=\"/usr/local/include\"   -c -o fcall.o fcall.c
gcc -O -Dawka_LIBDIR=\"/usr/local/lib\" -Dawka_INCDIR=\"/usr/local/include\"   -c -o version.o version.c
gcc -O -Dawka_LIBDIR=\"/usr/local/lib\" -Dawka_INCDIR=\"/usr/local/include\" translate.o awka.o parse.o scan.o memory.o hash.o code.o bi_funct.o da.o error.o init.o bi_vars.o cast.o print.o kw.o jmp.o field.o re_cmpl.o preprocess.o zmalloc.o msg.o scancode.o fcall.o version.o -o awka
/usr/bin/ld: code.o:(.bss+0x80): multiple definition of `awak_input_text'; scan.o:(.bss+0x40): first defined here
/usr/bin/ld: bi_funct.o:(.bss+0x0): multiple definition of `awak_input_text'; scan.o:(.bss+0x40): first defined here
/usr/bin/ld: error.o:(.bss+0x8): multiple definition of `line_pos'; scan.o:(.bss+0x48): first defined here
/usr/bin/ld: init.o:(.bss+0x90): multiple definition of `awak_input_text'; scan.o:(.bss+0x40): first defined here
/usr/bin/ld: bi_vars.o:(.bss+0x1f8): multiple definition of `awak_input_text'; scan.o:(.bss+0x40): first defined here
/usr/bin/ld: cast.o:(.bss+0x0): multiple definition of `line_pos'; scan.o:(.bss+0x48): first defined here
/usr/bin/ld: print.o:(.bss+0x0): multiple definition of `line_pos'; scan.o:(.bss+0x48): first defined here
/usr/bin/ld: kw.o:(.bss+0x0): multiple definition of `awak_input_text'; scan.o:(.bss+0x40): first defined here
/usr/bin/ld: jmp.o:(.bss+0x8): multiple definition of `awak_input_text'; scan.o:(.bss+0x40): first defined here
/usr/bin/ld: field.o:(.bss+0x1898): multiple definition of `line_pos'; scan.o:(.bss+0x48): first defined here
/usr/bin/ld: field.o:(.bss+0x18a0): multiple definition of `awak_input_text'; scan.o:(.bss+0x40): first defined here
/usr/bin/ld: re_cmpl.o:(.bss+0x0): multiple definition of `line_pos'; scan.o:(.bss+0x48): first defined here
collect2: error: ld returned 1 exit status
make[1]: *** [Makefile:44: awka] Error 1
make[1]: Leaving directory '/home/mrloyal/Sync/pawk/awka/awka'
make: *** [Makefile:48: awka_exe] Error 2

Why is `alength()` instead of `length()` used?

I see awka uses alength() instead of length(). But other awk implementation support length(). Is it better to rename alength() to length() so that awk code works with other awk implementations still works with awka?

$ awka 'BEGIN { a["a"]=1; print alength(a) }' > a.c
$ gcc -lawka -o a.out a.c
$ ./a.out
$  awka 'BEGIN { a["a"]=1; print length(a) }'
awka: line 1: illegal reference to array a
$ mawk 'BEGIN { a["a"]=1; print length(a) }'
1
$ gawk 'BEGIN { a["a"]=1; print length(a) }'
1

Failed to compile awk program with #

See error below.

$ cat a.awk

function f(x) {
#
return x
}
{ print $0, f($0) }
$ awka $(< a.awk )
awka: line 2: missing } near end of file
$ gawk -f ./a.awk  <<< 1
1 1

doesn't compile on OpenBSD 7.2 amd64

git clone https://github.com/noyesno/awka
cd awka
./configure
creating cache ./config.cache
checking for gcc... gcc
checking whether we are using GNU C... yes
checking how to run the C preprocessor... gcc -E
checking for log in -lm... yes
checking checking for inline... __inline__
checking for gawk... no
checking for mawk... mawk
checking for ash... no
checking for sh... sh
checking for byacc... no
checking for bison... no
checking for yacc... yacc
checking for ar... ar
checking for ranlib... ranlib
checking for cmp... cmp
checking compiler supports void*... yes
checking compiler groks prototypes... yes
checking for working const... yes
checking for stddef.h... yes
getting size_t from <stddef.h>
checking for fcntl.h... yes
checking for errno.h... yes
checking for time.h... yes
checking for stdarg.h... yes
checking for netdb.h... yes
checking for netinet/in.h... yes
checking for sys/socket.h... yes
checking for unistd.h... yes
checking for memcpy... yes
checking for strchr... yes
checking for strstr... yes
checking for strerror... yes
checking for vfprintf... yes
checking for fmod... yes
checking for matherr... no
checking for limits.h... yes
checking for gethostbyname... yes
checking for connect... yes
checking where to find the socket library calls... the standard library
checking whether time.h and sys/time.h may both be included... yes
checking whether struct tm is in sys/time.h or time.h... time.h
checking for tm_zone in struct tm... yes
checking for time... yes
checking for mktime... yes
checking for asctime... yes
checking for localtime... yes
checking for gmtime... yes
checking for .exe extension... no
/* config.h -- generated by configure */
#ifndef CONFIG_H
#define CONFIG_H

#define HAVE_SOCKETS 1
#define HAVE_SYS_SOCKET_H
#define HAVE_UNISTD_H
#define HAVE_NETDB_H
#define HAVE_NETINET_IN_H
#define HAVE_FCNTL_H

#define awka_MATHLIB "-lm"
#define INLINE __inline__
#define SIZE_T_STDDEF_H 1
#define NO_MATHERR 1
#define NO_FPRINTF_IN_STDIO 1
#define NO_SPRINTF_IN_STDIO 1
#define awka_SOCKET_LIBS ""
#define awka_CC "gcc"
#define awka_CFLAGS "-O"
#define awka_shell "sh"

#define HAVE_REAL_PIPES 1
/* #define NO_BIN_CHARS */
/* #define MEM_DEBUG */
#endif /* CONFIG_H */
updating cache ./config.cache
creating ./config.status
creating Makefile
creating lib/Makefile
creating awka/Makefile
creating test/Makefile
creating benchmark/Makefile
gmake
cd awka; gmake
gmake[1]: Entering directory '/tmp/awka/awka'
gcc -O -Dawka_LIBDIR=\"/usr/local/lib\" -Dawka_INCDIR=\"/usr/local/include\"   -c -o translate.o translate.c
gcc -O -Dawka_LIBDIR=\"/usr/local/lib\" -Dawka_INCDIR=\"/usr/local/include\"   -c -o awka.o awka.c
gcc -O -Dawka_LIBDIR=\"/usr/local/lib\" -Dawka_INCDIR=\"/usr/local/include\"   -c -o parse.o parse.c
gcc -O -Dawka_LIBDIR=\"/usr/local/lib\" -Dawka_INCDIR=\"/usr/local/include\"   -c -o scan.o scan.c
gcc -O -Dawka_LIBDIR=\"/usr/local/lib\" -Dawka_INCDIR=\"/usr/local/include\"   -c -o memory.o memory.c
gcc -O -Dawka_LIBDIR=\"/usr/local/lib\" -Dawka_INCDIR=\"/usr/local/include\"   -c -o hash.o hash.c
gcc -O -Dawka_LIBDIR=\"/usr/local/lib\" -Dawka_INCDIR=\"/usr/local/include\"   -c -o code.o code.c
gcc -O -Dawka_LIBDIR=\"/usr/local/lib\" -Dawka_INCDIR=\"/usr/local/include\"   -c -o bi_funct.o bi_funct.c
gcc -O -Dawka_LIBDIR=\"/usr/local/lib\" -Dawka_INCDIR=\"/usr/local/include\"   -c -o da.o da.c
gcc -O -Dawka_LIBDIR=\"/usr/local/lib\" -Dawka_INCDIR=\"/usr/local/include\"   -c -o error.o error.c
gcc -O -Dawka_LIBDIR=\"/usr/local/lib\" -Dawka_INCDIR=\"/usr/local/include\"   -c -o init.o init.c
gcc -O -Dawka_LIBDIR=\"/usr/local/lib\" -Dawka_INCDIR=\"/usr/local/include\"   -c -o bi_vars.o bi_vars.c
gcc -O -Dawka_LIBDIR=\"/usr/local/lib\" -Dawka_INCDIR=\"/usr/local/include\"   -c -o cast.o cast.c
gcc -O -Dawka_LIBDIR=\"/usr/local/lib\" -Dawka_INCDIR=\"/usr/local/include\"   -c -o print.o print.c
gcc -O -Dawka_LIBDIR=\"/usr/local/lib\" -Dawka_INCDIR=\"/usr/local/include\"   -c -o kw.o kw.c
gcc -O -Dawka_LIBDIR=\"/usr/local/lib\" -Dawka_INCDIR=\"/usr/local/include\"   -c -o jmp.o jmp.c
gcc -O -Dawka_LIBDIR=\"/usr/local/lib\" -Dawka_INCDIR=\"/usr/local/include\"   -c -o field.o field.c
gcc -O -Dawka_LIBDIR=\"/usr/local/lib\" -Dawka_INCDIR=\"/usr/local/include\"   -c -o re_cmpl.o re_cmpl.c
gcc -O -Dawka_LIBDIR=\"/usr/local/lib\" -Dawka_INCDIR=\"/usr/local/include\"   -c -o preprocess.o preprocess.c
gcc -O -Dawka_LIBDIR=\"/usr/local/lib\" -Dawka_INCDIR=\"/usr/local/include\"   -c -o zmalloc.o zmalloc.c
gcc -O -Dawka_LIBDIR=\"/usr/local/lib\" -Dawka_INCDIR=\"/usr/local/include\"   -c -o fcall.o fcall.c
gcc -O -Dawka_LIBDIR=\"/usr/local/lib\" -Dawka_INCDIR=\"/usr/local/include\"   -c -o version.o version.c
gcc -O -Dawka_LIBDIR=\"/usr/local/lib\" -Dawka_INCDIR=\"/usr/local/include\" translate.o awka.o parse.o scan.o memory.o hash.o code.o bi_funct.o da.o error.o init.o bi_vars.o cast.o print.o kw.o jmp.o field.o re_cmpl.o preprocess.o zmalloc.o msg.o scancode.o fcall.o version.o -o awka
ld: error: duplicate symbol: awak_input_text
>>> defined at scan.c
>>>            scan.o:(awak_input_text)
>>> defined at code.c
>>>            code.o:(.bss+0x80)

ld: error: duplicate symbol: awak_input_text
>>> defined at scan.c
>>>            scan.o:(awak_input_text)
>>> defined at bi_funct.c
>>>            bi_funct.o:(.bss+0x0)

ld: error: duplicate symbol: line_pos
>>> defined at scan.c
>>>            scan.o:(line_pos)
>>> defined at error.c
>>>            error.o:(.bss+0x8)

ld: error: duplicate symbol: awak_input_text
>>> defined at scan.c
>>>            scan.o:(awak_input_text)
>>> defined at init.c
>>>            init.o:(.bss+0x90)

ld: error: duplicate symbol: awak_input_text
>>> defined at scan.c
>>>            scan.o:(awak_input_text)
>>> defined at bi_vars.c
>>>            bi_vars.o:(.bss+0x1F8)

ld: error: duplicate symbol: line_pos
>>> defined at scan.c
>>>            scan.o:(line_pos)
>>> defined at cast.c
>>>            cast.o:(.bss+0x0)

ld: error: duplicate symbol: line_pos
>>> defined at scan.c
>>>            scan.o:(line_pos)
>>> defined at print.c
>>>            print.o:(.bss+0x0)

ld: error: duplicate symbol: awak_input_text
>>> defined at scan.c
>>>            scan.o:(awak_input_text)
>>> defined at kw.c
>>>            kw.o:(.bss+0x0)

ld: error: duplicate symbol: awak_input_text
>>> defined at scan.c
>>>            scan.o:(awak_input_text)
>>> defined at jmp.c
>>>            jmp.o:(.bss+0x8)

ld: error: duplicate symbol: line_pos
>>> defined at scan.c
>>>            scan.o:(line_pos)
>>> defined at field.c
>>>            field.o:(.bss+0x1898)

ld: error: duplicate symbol: awak_input_text
>>> defined at scan.c
>>>            scan.o:(awak_input_text)
>>> defined at field.c
>>>            field.o:(.bss+0x18A0)

ld: error: duplicate symbol: line_pos
>>> defined at scan.c
>>>            scan.o:(line_pos)
>>> defined at re_cmpl.c
>>>            re_cmpl.o:(.bss+0x0)
collect2: error: ld returned 1 exit status
gmake[1]: *** [Makefile:44: awka] Error 1
gmake[1]: Leaving directory '/tmp/awka/awka'
gmake: *** [Makefile:48: awka_exe] Error 2

Also please note that awka from https://awka.sourceforge.net/index.html does compile fine (and does generate c code from awk code, however the generated c code doesn't compile)

incompatibility between gawk and awka for match

https://github.com/jlp765/awka/tree/enhancement/more

I used the above version. But I think it should be the same as the main version for this issue. See below.

$ awk_code='BEGIN { print match("abc", /(a)/, a); print length(a), a[1]; for(k in a) print k, a[k] }'
$ awka "$awk_code" > "$tmpdir"/a.c
$ gcc -lawka -o "$tmpdir"/a.out "$tmpdir"/a.c
$ "$tmpdir"/a.out
1
2 a
0 a
1 a
main.sh> awk -e "$awk_code"
1
6 a
0start 1
0length 1
1start 1
1length 1
0 a
1 a

Is switch supported?

I see the following error. Is it because switch is not supported?

$ cat a.awk
function f(x) {
  switch(x) {
  case "a": return 1;
  default: return 0;
  }
}
{ print $0, f($0) }
$ gawk -f ./a.awk  <<< a
a 1
$ awka -f ./a.awk
awka: ./a.awk: line 2:   switch(x) {
awka: ./a.awk: line 2:             ^ syntax error at or near {
awka: ./a.awk: line 4:   default: return 0;
awka: ./a.awk: line 4:          ^ syntax error at or near :
awka: ./a.awk: line 6: }
awka: ./a.awk: line 6: ^ syntax error at or near }

Adding support of @include

@include is not supported by awka. Could the support it be added? Thanks.

$ seq 3 | gawk -e '@include "./f.awk"; { print f($1) }'
1
2
3
$ awka '@include "./f.awk"; { print f($1) }'
awka: line 1: @include \"./f.awk\"; { print f($1) }
awka: line 1: ^ unexpected character '@'

Incorrect output

Just discovered awka - potentially very useful in bioinformatics where huge amounts of TSV data are processed. It failed my first simple test, though, a small script I wrote to elucidate awk's logic in comparing numbers.

compare.awk:

BEGIN {
    x="10"
    y="9"
    printf("%s\n", x < y);  # Always 1
    
    x=10
    y=9
    printf("%s\n", x < y);  # Always 0

    getline x < "xy.txt"
    getline y < "xy.txt"
    printf("%s %s\n", x, y);
    printf("%s\n", x < y);  # awk 1, mawk and gawk 0
}

#!/bin/sh -e

for awk in awk gawk mawk 'awka -x'; do
    echo $awk
    $awk -f compare.awk
done

Output:

sh -c  ./awk-test 
awk
1
0
10 9
0
gawk
1
0
10 9
1
mawk
1
0
10 9
1
awka -x
1
0
 
1

xy.txt:

9
10

Warn on possible mistake in Awk script and Generated C code.

make test is running clean on FreeBSD now, except for one warning in generated code:

cmp ./backgsub.ok _backgsub && rm -f _backgsub
x.c:269:5: warning: expression result unused [-Wunused-value]
    !strcmp(awka_gets(awka_doln(nf_tight_awk->dval, 0)), "N/A");
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 warning generated.
cmp ./tweakfld.ok _tweakfld && rm -f _tweakfld

It's due to testcase "tweakfld.awk" has below code. Should consider update the testcase.

The -Wunused-value compiler option is useful. Will consider added as default in awka.

# set TIGHT/LOOSE to N/A if it is not one of the two allowed values
function tight_na() {
    if( $nf_tight !~ /TIGHT|LOOSE/ ) {
        $nf_tight == "N/A"  ;# -- Result NOT Used Here
    }
}

Originally posted by @noyesno in #2 (comment)

Create a release

Please create a release of this so it can be distributed by packagers! Thank you

inconsistency between awka and gawk for `==`

See the difference below. I'd consider that this is a bug of awka that should be fixed.

$ awka '{ print $1 + 0 == $1 }' > a.c
$ gcc -lawka -o a.out a.c
$ builtin printf '%s\n'a | ./a.out
1
$ builtin printf '%s\n' .0 b c | gawk '{ print $1 + 0 == $1 }'
0

Support of ==

The following code does not work. Can it be fixed?

$ cat a.awk
function f(x) {
	return x == "a"
}
{ print $0, f($0) }
$ awka -f  a.awk  > a.c
$ gcc -lawka a.c
Undefined symbols for architecture x86_64:
  "_awka_strncpy", referenced from:
      _main in a-860d69.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.