diff --git a/ase/test/awk/awk.c b/ase/test/awk/awk.c index 002bcbd7..c7ef05ee 100644 --- a/ase/test/awk/awk.c +++ b/ase/test/awk/awk.c @@ -1,5 +1,5 @@ /* - * $Id: awk.c,v 1.113 2006-11-15 06:00:08 bacon Exp $ + * $Id: awk.c,v 1.114 2006-11-17 06:51:27 bacon Exp $ */ #include @@ -99,7 +99,7 @@ static FILE* fopen_t (const ase_char_t* path, const ase_char_t* mode) #endif } -static int __sprintf ( +static int __awk_sprintf ( ase_char_t* buf, ase_size_t len, const ase_char_t* fmt, ...) { int n; @@ -118,7 +118,7 @@ static int __sprintf ( return n; } -static int __aprintf (const ase_char_t* fmt, ...) +static int __awk_aprintf (const ase_char_t* fmt, ...) { int n; va_list ap; @@ -144,7 +144,7 @@ static int __aprintf (const ase_char_t* fmt, ...) return n; } -static int __dprintf (const ase_char_t* fmt, ...) +static int __awk_dprintf (const ase_char_t* fmt, ...) { int n; va_list ap; @@ -288,7 +288,7 @@ static ase_ssize_t process_extio_pipe ( else if (epa->mode == ASE_AWK_IO_PIPE_WRITE) mode = ASE_T("w"); else return -1; /* TODO: any way to set the error number? */ -xp_printf (ASE_T("opending %s of type %d (pipe)\n"), epa->name, epa->type); + __awk_dprintf (ASE_T("opending %s of type %d (pipe)\n"), epa->name, epa->type); handle = popen_t (epa->name, mode); if (handle == NULL) return -1; epa->handle = (void*)handle; @@ -297,7 +297,7 @@ xp_printf (ASE_T("opending %s of type %d (pipe)\n"), epa->name, epa->type); case ASE_AWK_IO_CLOSE: { -xp_printf (ASE_T("closing %s of type (pipe) %d\n"), epa->name, epa->type); + __awk_dprintf (ASE_T("closing %s of type (pipe) %d\n"), epa->name, epa->type); fclose ((FILE*)epa->handle); epa->handle = NULL; return 0; @@ -356,7 +356,7 @@ static ase_ssize_t process_extio_file ( mode = ASE_T("a"); else return -1; /* TODO: any way to set the error number? */ -xp_printf (ASE_T("opending %s of type %d (file)\n"), epa->name, epa->type); + __awk_dprintf (ASE_T("opending %s of type %d (file)\n"), epa->name, epa->type); handle = fopen_t (epa->name, mode); if (handle == NULL) return -1; @@ -366,7 +366,7 @@ xp_printf (ASE_T("opending %s of type %d (file)\n"), epa->name, epa->type); case ASE_AWK_IO_CLOSE: { -xp_printf (ASE_T("closing %s of type %d (file)\n"), epa->name, epa->type); + __awk_dprintf (ASE_T("closing %s of type %d (file)\n"), epa->name, epa->type); fclose ((FILE*)epa->handle); epa->handle = NULL; return 0; @@ -466,7 +466,7 @@ static ase_ssize_t process_extio_console ( FILE* fp = fopen_t (infiles[infile_no], ASE_T("r")); if (fp == ASE_NULL) { -xp_printf (ASE_T("failed to open the next console of type %x - fopen failure\n"), epa->type); + __awk_dprintf (ASE_T("failed to open the next console of type %x - fopen failure\n"), epa->type); return -1; } @@ -475,7 +475,7 @@ xp_printf (ASE_T("failed to open the next console of type %x - fopen failure\n") epa->handle != stdout && epa->handle != stderr) fclose (epa->handle); -xp_printf (ASE_T("open the next console [%s]\n"), infiles[infile_no]); + __awk_dprintf (ASE_T("open the next console [%s]\n"), infiles[infile_no]); epa->handle = fp; } @@ -516,20 +516,20 @@ static int open_extio_console (ase_awk_extio_t* epa) /* epa->name is always empty for console */ xp_assert (epa->name[0] == ASE_T('\0')); -xp_printf (ASE_T("opening console[%s] of type %x\n"), epa->name, epa->type); + __awk_dprintf (ASE_T("opening console[%s] of type %x\n"), epa->name, epa->type); if (epa->mode == ASE_AWK_IO_CONSOLE_READ) { if (infiles[infile_no] == ASE_NULL) { /* no more input file */ -xp_printf (ASE_T("console - no more file\n"));; + __awk_dprintf (ASE_T("console - no more file\n"));; return 0; } if (infiles[infile_no][0] == ASE_T('\0')) { -xp_printf (ASE_T(" console(r) - \n")); + __awk_dprintf (ASE_T(" console(r) - \n")); epa->handle = stdin; } else @@ -539,11 +539,11 @@ xp_printf (ASE_T(" console(r) - \n")); FILE* fp = fopen_t (infiles[infile_no], ASE_T("r")); if (fp == ASE_NULL) { -xp_printf (ASE_T("failed to open console of type %x - fopen failure\n"), epa->type); + __awk_dprintf (ASE_T("cannot open console of type %x - fopen failure\n"), epa->type); return -1; } -xp_printf (ASE_T(" console(r) - %s\n"), infiles[infile_no]); + __awk_dprintf (ASE_T(" console(r) - %s\n"), infiles[infile_no]); if (ase_awk_setconsolename ( epa->run, infiles[infile_no], ase_awk_strlen(infiles[infile_no])) == -1) @@ -560,7 +560,7 @@ xp_printf (ASE_T(" console(r) - %s\n"), infiles[infile_no]); } else if (epa->mode == ASE_AWK_IO_CONSOLE_WRITE) { -xp_printf (ASE_T(" console(w) - \n")); + __awk_dprintf (ASE_T(" console(w) - \n")); /* TODO: does output console has a name??? */ /*ase_awk_setconsolename (ASE_T(""));*/ epa->handle = stdout; @@ -572,7 +572,7 @@ xp_printf (ASE_T(" console(w) - \n")); static int close_extio_console (ase_awk_extio_t* epa) { -xp_printf (ASE_T("closing console of type %x\n"), epa->type); + __awk_dprintf (ASE_T("closing console of type %x\n"), epa->type); if (epa->handle != ASE_NULL && epa->handle != stdin && @@ -590,7 +590,8 @@ static int next_extio_console (ase_awk_extio_t* epa) { int n; FILE* fp = epa->handle; -xp_printf (ASE_T("switching console[%s] of type %x\n"), epa->name, epa->type); + + __awk_dprintf (ASE_T("switching console[%s] of type %x\n"), epa->name, epa->type); n = open_extio_console(epa); if (n == -1) return -1; @@ -639,16 +640,16 @@ static void __on_run_start (ase_awk_t* awk, void* handle, void* arg) app_awk = awk; app_run = handle; - xp_printf (ASE_T("AWK PRORAM ABOUT TO START...\n")); + __awk_dprintf (ASE_T("AWK PRORAM ABOUT TO START...\n")); } static void __on_run_end (ase_awk_t* awk, void* handle, int errnum, void* arg) { if (errnum != ASE_AWK_ENOERR) { - xp_printf (ASE_T("AWK PRORAM ABOUT TO END WITH AN ERROR - %d - %s\n"), errnum, ase_awk_geterrstr (errnum)); + __awk_dprintf (ASE_T("AWK PRORAM ABOUT TO END WITH AN ERROR - %d - %s\n"), errnum, ase_awk_geterrstr (errnum)); } - else xp_printf (ASE_T("AWK PRORAM ENDED SUCCESSFULLY\n")); + else __awk_dprintf (ASE_T("AWK PRORAM ENDED SUCCESSFULLY\n")); app_awk = NULL; app_run = NULL; @@ -815,9 +816,9 @@ static int __main (int argc, ase_char_t* argv[]) syscas.memcpy = memcpy; syscas.memset = memset; syscas.pow = __awk_pow; - syscas.sprintf = __sprintf; - syscas.aprintf = __aprintf; - syscas.dprintf = __dprintf; + syscas.sprintf = __awk_sprintf; + syscas.aprintf = __awk_aprintf; + syscas.dprintf = __awk_dprintf; syscas.abort = abort; #ifdef _WIN32 diff --git a/ase/test/awk/emp-001.awk b/ase/test/awk/emp-001.awk new file mode 100644 index 00000000..83354291 --- /dev/null +++ b/ase/test/awk/emp-001.awk @@ -0,0 +1 @@ +$3 > 0 { print $1, $2 * $3; } diff --git a/ase/test/awk/emp-002.awk b/ase/test/awk/emp-002.awk new file mode 100644 index 00000000..06607ada --- /dev/null +++ b/ase/test/awk/emp-002.awk @@ -0,0 +1 @@ +$3 == 0 { print $1; } diff --git a/ase/test/awk/emp-003.awk b/ase/test/awk/emp-003.awk new file mode 100644 index 00000000..fcfbe32c --- /dev/null +++ b/ase/test/awk/emp-003.awk @@ -0,0 +1 @@ +{ print NF, $1, $NF; } diff --git a/ase/test/awk/emp-004.awk b/ase/test/awk/emp-004.awk new file mode 100644 index 00000000..30bc76fb --- /dev/null +++ b/ase/test/awk/emp-004.awk @@ -0,0 +1 @@ +{ print NR, $0; } diff --git a/ase/test/awk/emp-005.awk b/ase/test/awk/emp-005.awk new file mode 100644 index 00000000..9ed5d9bc --- /dev/null +++ b/ase/test/awk/emp-005.awk @@ -0,0 +1 @@ +{ print "total pay for", $1, "is", $2 * $3; } diff --git a/ase/test/awk/emp-006.awk b/ase/test/awk/emp-006.awk new file mode 100644 index 00000000..035b20b5 --- /dev/null +++ b/ase/test/awk/emp-006.awk @@ -0,0 +1 @@ +{ printf ("total pay for %s is $%.2f\n", $1, $2 * $3); } diff --git a/ase/test/awk/emp-007.awk b/ase/test/awk/emp-007.awk new file mode 100644 index 00000000..4c7a7b63 --- /dev/null +++ b/ase/test/awk/emp-007.awk @@ -0,0 +1 @@ +{ printf ("%-8s $%6.2f\n", $1, $2 * $3); } diff --git a/ase/test/awk/emp-008.awk b/ase/test/awk/emp-008.awk new file mode 100644 index 00000000..73c4bd78 --- /dev/null +++ b/ase/test/awk/emp-008.awk @@ -0,0 +1 @@ +$2 >= 5 diff --git a/ase/test/awk/emp-009.awk b/ase/test/awk/emp-009.awk new file mode 100644 index 00000000..a8bd5dff --- /dev/null +++ b/ase/test/awk/emp-009.awk @@ -0,0 +1 @@ +$2 * $3 > 50 { printf ("$%.2f for %s\n", $2 * $3, $1); } diff --git a/ase/test/awk/emp-010.awk b/ase/test/awk/emp-010.awk new file mode 100644 index 00000000..ec5dc961 --- /dev/null +++ b/ase/test/awk/emp-010.awk @@ -0,0 +1 @@ +$1 == "Susie" diff --git a/ase/test/awk/emp-011.awk b/ase/test/awk/emp-011.awk new file mode 100644 index 00000000..a37ed825 --- /dev/null +++ b/ase/test/awk/emp-011.awk @@ -0,0 +1 @@ +/Susie/ diff --git a/ase/test/awk/emp-012.awk b/ase/test/awk/emp-012.awk new file mode 100644 index 00000000..c5c84049 --- /dev/null +++ b/ase/test/awk/emp-012.awk @@ -0,0 +1 @@ +$2 >= 4 || $3 >= 20 diff --git a/ase/test/awk/emp-013.awk b/ase/test/awk/emp-013.awk new file mode 100644 index 00000000..83a08fbd --- /dev/null +++ b/ase/test/awk/emp-013.awk @@ -0,0 +1,2 @@ +$2 >= 4 +$3 >= 20 diff --git a/ase/test/awk/emp-014.awk b/ase/test/awk/emp-014.awk new file mode 100644 index 00000000..a210459a --- /dev/null +++ b/ase/test/awk/emp-014.awk @@ -0,0 +1 @@ +!($2 < 4 && $3 < 20) diff --git a/ase/test/awk/emp-015.awk b/ase/test/awk/emp-015.awk new file mode 100644 index 00000000..81d81580 --- /dev/null +++ b/ase/test/awk/emp-015.awk @@ -0,0 +1,5 @@ +NF != 3 { print $0, "number of fields is not equal to 3"; } +$2 < 3.35 { print $0, "rate is below minimum wage"; } +$2 > 10 { print $0, "rate exceeds $10 per hour"; } +$3 < 0 { print $0, "negative hours worked"; } +$3 > 60 { print $0, "too many hours worked"; } diff --git a/ase/test/awk/emp-016.awk b/ase/test/awk/emp-016.awk new file mode 100644 index 00000000..22e0700e --- /dev/null +++ b/ase/test/awk/emp-016.awk @@ -0,0 +1,2 @@ +BEGIN { print "NAME RATE HOURS"; print ""; } + { print; } diff --git a/ase/test/awk/emp-017.awk b/ase/test/awk/emp-017.awk new file mode 100644 index 00000000..69408a07 --- /dev/null +++ b/ase/test/awk/emp-017.awk @@ -0,0 +1,2 @@ +$3 > 15 { emp = emp + 1; } +END { print emp, "employees worked more than 15 hours"; } diff --git a/ase/test/awk/emp-018.awk b/ase/test/awk/emp-018.awk new file mode 100644 index 00000000..dd952bb8 --- /dev/null +++ b/ase/test/awk/emp-018.awk @@ -0,0 +1 @@ +END { print NR, "employees"; } diff --git a/ase/test/awk/emp-019.awk b/ase/test/awk/emp-019.awk new file mode 100644 index 00000000..3b63999b --- /dev/null +++ b/ase/test/awk/emp-019.awk @@ -0,0 +1,5 @@ + { pay = pay + $2 * $3; } +END { print NR, "employees"; + print "total pay is", pay; + print "average pay is", pay/NR; +} diff --git a/ase/test/awk/emp-020.awk b/ase/test/awk/emp-020.awk new file mode 100644 index 00000000..e0e1b1aa --- /dev/null +++ b/ase/test/awk/emp-020.awk @@ -0,0 +1,2 @@ +$2 > maxrate { maxrate = $2; maxemp = $1; } +END { print "highest hourly rage:", maxrate, "for", maxemp; }