diff options
author | Arnold D. Robbins <arnold@skeeve.com> | 2015-03-17 22:52:04 +0200 |
---|---|---|
committer | Arnold D. Robbins <arnold@skeeve.com> | 2015-03-17 22:52:04 +0200 |
commit | 69b9c6bec08738933d79010ad8c9347e36d19bed (patch) | |
tree | e3d2790fb4a77b871234ba15784bd4e1e057981e | |
parent | 8fc0c719fc910d6931d267b5437cef9048e5a9b0 (diff) | |
parent | cd2ff61aaf4938092517880ad7655828d99a3cb9 (diff) | |
download | egawk-69b9c6bec08738933d79010ad8c9347e36d19bed.tar.gz egawk-69b9c6bec08738933d79010ad8c9347e36d19bed.tar.bz2 egawk-69b9c6bec08738933d79010ad8c9347e36d19bed.zip |
Merge branch 'master' into feature/regex-type
40 files changed, 1549 insertions, 750 deletions
@@ -1,3 +1,40 @@ +2015-03-17 Arnold D. Robbins <arnold@skeeve.com> + + * profile.c (pp_number): Allocate enough room to print the number + in all cases. Was a problem mixing -M with profiling with a really + big number. Thanks to Hermann Peifer for the bug report. + +2015-03-08 Arnold D. Robbins <arnold@skeeve.com> + + * re.c (regexflags2str): Removed. It was redundant. + + * io.c (devopen): Change the logic such that if nonfatal is true + for the socket, don't do retries. Also clean up the formatting + some. At strictopen, check if errno is ENOENT and if so, propagate + the error from getaddrinfo() up to the caller. Add explanatory + comments. + +2015-02-28 Andrew J. Schorr <aschorr@telemetry-investments.com> + + * io.c (pty_vs_pipe): Remove check for NULL PROCINFO_node, since + this is now checked inside in_PROCINFO. + +2015-02-27 Andrew J. Schorr <aschorr@telemetry-investments.com> + + * io.c (socketopen): New parameter hard_error; set it if + getaddrinfo() fails. Change fatals to warnings. + (devopen): Pass in address of boolean hard_error variable + and stop trying to open the file if hard_error is true. + Save and restore errno around call to socketopen() and + use restored errno if open() fails at strictopen. + +2015-02-27 Arnold D. Robbins <arnold@skeeve.com> + + * symbol.c (check_param_names): Fix argument order in memset() call. + * configure.ac: Use AC_SEARCH_LIBS instead of AC_CHECK_LIB. This fixes + a long-standing problem where `-lm' was used twice in the final + compilation line. + 2015-02-27 Arnold D. Robbins <arnold@skeeve.com> Start on making regexp a real type. @@ -40,6 +77,29 @@ * profile.c (pprint): Restore printing of count for rules. Bug report by Hermann Peifer. +2015-02-08 Arnold D. Robbins <arnold@skeeve.com> + + * io.c: Make it "NONFATAL" everywhere. + +2015-02-08 Andrew J. Schorr <aschorr@telemetry-investments.com> + + * awk.h (RED_NON_FATAL): Removed. + (redirect): Add new failure_fatal parameter. + (is_non_fatal_redirect): Add declaration. + * builtin.c (efwrite): Rework check for non-fatal. + (do_printf): Adjust calls to redirect. + (do_print_rec): Ditto. Move check for redirection error up. + * io.c (redflags2str): Remove RED_NON_FATAL. + (redirect): Add new failure_fatal parameter. Simplify the code. + (is_non_fatal_redirect): New function. + (do_getline_redir): Adjust calls to redirect. + +2014-12-27 Arnold D. Robbins <arnold@skeeve.com> + + * awk.h (is_non_fatal_std): Declare new function. + * io.c (is_non_fatal_std): New function. + * builtin.c (efwrite): Call it. + 2015-02-07 Arnold D. Robbins <arnold@skeeve.com> * regcomp.c, regex.c, regex.h, regex_internal.c, regex_internal.h, @@ -147,6 +207,22 @@ * profile.c (pprint): Be sure to set ip2 in all paths through the code. Thanks to GCC 4.9 for the warning. +2014-12-20 Arnold D. Robbins <arnold@skeeve.com> + + Enable non-fatal output on per-file or global basis, + via PROCINFO. + + * awk.h (RED_NON_FATAL): New redirection flag. + * builtin.c (efwrite): If RED_NON_FATAL set, just set ERRNO and return. + (do_printf): Check errflg and if set, set ERRNO and return. + (do_print): Ditto. + (do_print_rec): Ditto. + * io.c (redflags2str): Update table. + (redirect): Check for global PROCINFO["nonfatal"] or for + PROCINFO[file, "nonfatal"] and don't fail on open if set. + Add RED_NON_FATAL to flags. + (in_PROCINFO): Make smarter and more general. + 2014-12-12 Stephen Davies <sdavies@sdc.com.au> Improve comment handling in pretty printing. @@ -1,4 +1,4 @@ -Sun Sep 28 22:19:10 IDT 2014 +Wed Dec 24 20:41:38 IST 2014 ============================ There were too many files tracking different thoughts and ideas for @@ -44,9 +44,6 @@ Minor New Features Consider relaxing the strictness of --posix. - Make it possible to put print/printf + redirections into - an expression. - ? Add an optional base to strtonum, allowing 2-36. ? Optional third argument for index indicating where to start the @@ -1484,7 +1484,7 @@ extern void register_two_way_processor(awk_two_way_processor_t *processor); extern void set_FNR(void); extern void set_NR(void); -extern struct redirect *redirect(NODE *redir_exp, int redirtype, int *errflg); +extern struct redirect *redirect(NODE *redir_exp, int redirtype, int *errflg, bool failure_fatal); extern NODE *do_close(int nargs); extern int flush_io(void); extern int close_io(bool *stdio_problem); @@ -1496,6 +1496,8 @@ extern NODE *do_getline(int intovar, IOBUF *iop); extern struct redirect *getredirect(const char *str, int len); extern bool inrec(IOBUF *iop, int *errcode); extern int nextfile(IOBUF **curfile, bool skipping); +extern bool is_non_fatal_std(FILE *fp); +extern bool is_non_fatal_redirect(const char *str); /* main.c */ extern int arg_assign(char *arg, bool initing); extern int is_std_var(const char *var); @@ -129,10 +129,14 @@ wrerror: if (fp == stdout && errno == EPIPE) gawk_exit(EXIT_FATAL); + /* otherwise die verbosely */ - fatal(_("%s to \"%s\" failed (%s)"), from, - rp ? rp->value : _("standard output"), - errno ? strerror(errno) : _("reason unknown")); + if ((rp != NULL) ? is_non_fatal_redirect(rp->value) : is_non_fatal_std(fp)) + update_ERRNO_int(errno); + else + fatal(_("%s to \"%s\" failed (%s)"), from, + rp ? rp->value : _("standard output"), + errno ? strerror(errno) : _("reason unknown")); } /* do_exp --- exponential function */ @@ -1639,7 +1643,7 @@ do_printf(int nargs, int redirtype) FILE *fp = NULL; NODE *tmp; struct redirect *rp = NULL; - int errflg; /* not used, sigh */ + int errflg = 0; NODE *redir_exp = NULL; if (nargs == 0) { @@ -1650,7 +1654,7 @@ do_printf(int nargs, int redirtype) redir_exp = TOP(); if (redir_exp->type != Node_val) fatal(_("attempt to use array `%s' in a scalar context"), array_vname(redir_exp)); - rp = redirect(redir_exp, redirtype, & errflg); + rp = redirect(redir_exp, redirtype, & errflg, true); DEREF(redir_exp); decr_sp(); } @@ -1663,9 +1667,13 @@ do_printf(int nargs, int redirtype) redir_exp = PEEK(nargs); if (redir_exp->type != Node_val) fatal(_("attempt to use array `%s' in a scalar context"), array_vname(redir_exp)); - rp = redirect(redir_exp, redirtype, & errflg); + rp = redirect(redir_exp, redirtype, & errflg, true); if (rp != NULL) fp = rp->output.fp; + else if (errflg) { + update_ERRNO_int(errflg); + return; + } } else if (do_debug) /* only the debugger can change the default output */ fp = output_fp; else @@ -2078,7 +2086,7 @@ void do_print(int nargs, int redirtype) { struct redirect *rp = NULL; - int errflg; /* not used, sigh */ + int errflg = 0; FILE *fp = NULL; int i; NODE *redir_exp = NULL; @@ -2090,9 +2098,13 @@ do_print(int nargs, int redirtype) redir_exp = PEEK(nargs); if (redir_exp->type != Node_val) fatal(_("attempt to use array `%s' in a scalar context"), array_vname(redir_exp)); - rp = redirect(redir_exp, redirtype, & errflg); + rp = redirect(redir_exp, redirtype, & errflg, true); if (rp != NULL) fp = rp->output.fp; + else if (errflg) { + update_ERRNO_int(errflg); + return; + } } else if (do_debug) /* only the debugger can change the default output */ fp = output_fp; else @@ -2148,13 +2160,13 @@ do_print_rec(int nargs, int redirtype) FILE *fp = NULL; NODE *f0; struct redirect *rp = NULL; - int errflg; /* not used, sigh */ + int errflg = 0; NODE *redir_exp = NULL; assert(nargs == 0); if (redirtype != 0) { redir_exp = TOP(); - rp = redirect(redir_exp, redirtype, & errflg); + rp = redirect(redir_exp, redirtype, & errflg, true); if (rp != NULL) fp = rp->output.fp; DEREF(redir_exp); @@ -2162,6 +2174,11 @@ do_print_rec(int nargs, int redirtype) } else fp = output_fp; + if (errflg) { + update_ERRNO_int(errflg); + return; + } + if (fp == NULL) return; @@ -96,9 +96,6 @@ /* Define to 1 if you have the <libintl.h> header file. */ #undef HAVE_LIBINTL_H -/* Define to 1 if you have the `m' library (-lm). */ -#undef HAVE_LIBM - /* Define to 1 if you have a fully functional readline library. */ #undef HAVE_LIBREADLINE @@ -9592,13 +9592,12 @@ fi fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for fmod in -lm" >&5 -$as_echo_n "checking for fmod in -lm... " >&6; } -if ${ac_cv_lib_m_fmod+:} false; then : +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing fmod" >&5 +$as_echo_n "checking for library containing fmod... " >&6; } +if ${ac_cv_search_fmod+:} false; then : $as_echo_n "(cached) " >&6 else - ac_check_lib_save_LIBS=$LIBS -LIBS="-lm $LIBS" + ac_func_search_save_LIBS=$LIBS cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ @@ -9617,33 +9616,44 @@ return fmod (); return 0; } _ACEOF -if ac_fn_c_try_link "$LINENO"; then : - ac_cv_lib_m_fmod=yes -else - ac_cv_lib_m_fmod=no +for ac_lib in '' m; do + if test -z "$ac_lib"; then + ac_res="none required" + else + ac_res=-l$ac_lib + LIBS="-l$ac_lib $ac_func_search_save_LIBS" + fi + if ac_fn_c_try_link "$LINENO"; then : + ac_cv_search_fmod=$ac_res fi rm -f core conftest.err conftest.$ac_objext \ - conftest$ac_exeext conftest.$ac_ext -LIBS=$ac_check_lib_save_LIBS + conftest$ac_exeext + if ${ac_cv_search_fmod+:} false; then : + break fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_m_fmod" >&5 -$as_echo "$ac_cv_lib_m_fmod" >&6; } -if test "x$ac_cv_lib_m_fmod" = xyes; then : - cat >>confdefs.h <<_ACEOF -#define HAVE_LIBM 1 -_ACEOF +done +if ${ac_cv_search_fmod+:} false; then : - LIBS="-lm $LIBS" +else + ac_cv_search_fmod=no +fi +rm conftest.$ac_ext +LIBS=$ac_func_search_save_LIBS +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_search_fmod" >&5 +$as_echo "$ac_cv_search_fmod" >&6; } +ac_res=$ac_cv_search_fmod +if test "$ac_res" != no; then : + test "$ac_res" = "none required" || LIBS="$ac_res $LIBS" fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for isinf in -lm" >&5 -$as_echo_n "checking for isinf in -lm... " >&6; } -if ${ac_cv_lib_m_isinf+:} false; then : +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing isinf" >&5 +$as_echo_n "checking for library containing isinf... " >&6; } +if ${ac_cv_search_isinf+:} false; then : $as_echo_n "(cached) " >&6 else - ac_check_lib_save_LIBS=$LIBS -LIBS="-lm $LIBS" + ac_func_search_save_LIBS=$LIBS cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ @@ -9662,33 +9672,44 @@ return isinf (); return 0; } _ACEOF -if ac_fn_c_try_link "$LINENO"; then : - ac_cv_lib_m_isinf=yes -else - ac_cv_lib_m_isinf=no +for ac_lib in '' m; do + if test -z "$ac_lib"; then + ac_res="none required" + else + ac_res=-l$ac_lib + LIBS="-l$ac_lib $ac_func_search_save_LIBS" + fi + if ac_fn_c_try_link "$LINENO"; then : + ac_cv_search_isinf=$ac_res fi rm -f core conftest.err conftest.$ac_objext \ - conftest$ac_exeext conftest.$ac_ext -LIBS=$ac_check_lib_save_LIBS + conftest$ac_exeext + if ${ac_cv_search_isinf+:} false; then : + break fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_m_isinf" >&5 -$as_echo "$ac_cv_lib_m_isinf" >&6; } -if test "x$ac_cv_lib_m_isinf" = xyes; then : - cat >>confdefs.h <<_ACEOF -#define HAVE_LIBM 1 -_ACEOF +done +if ${ac_cv_search_isinf+:} false; then : - LIBS="-lm $LIBS" +else + ac_cv_search_isinf=no +fi +rm conftest.$ac_ext +LIBS=$ac_func_search_save_LIBS +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_search_isinf" >&5 +$as_echo "$ac_cv_search_isinf" >&6; } +ac_res=$ac_cv_search_isinf +if test "$ac_res" != no; then : + test "$ac_res" = "none required" || LIBS="$ac_res $LIBS" fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for ismod in -lm" >&5 -$as_echo_n "checking for ismod in -lm... " >&6; } -if ${ac_cv_lib_m_ismod+:} false; then : +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing ismod" >&5 +$as_echo_n "checking for library containing ismod... " >&6; } +if ${ac_cv_search_ismod+:} false; then : $as_echo_n "(cached) " >&6 else - ac_check_lib_save_LIBS=$LIBS -LIBS="-lm $LIBS" + ac_func_search_save_LIBS=$LIBS cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ @@ -9707,23 +9728,35 @@ return ismod (); return 0; } _ACEOF -if ac_fn_c_try_link "$LINENO"; then : - ac_cv_lib_m_ismod=yes -else - ac_cv_lib_m_ismod=no +for ac_lib in '' m; do + if test -z "$ac_lib"; then + ac_res="none required" + else + ac_res=-l$ac_lib + LIBS="-l$ac_lib $ac_func_search_save_LIBS" + fi + if ac_fn_c_try_link "$LINENO"; then : + ac_cv_search_ismod=$ac_res fi rm -f core conftest.err conftest.$ac_objext \ - conftest$ac_exeext conftest.$ac_ext -LIBS=$ac_check_lib_save_LIBS + conftest$ac_exeext + if ${ac_cv_search_ismod+:} false; then : + break fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_m_ismod" >&5 -$as_echo "$ac_cv_lib_m_ismod" >&6; } -if test "x$ac_cv_lib_m_ismod" = xyes; then : - cat >>confdefs.h <<_ACEOF -#define HAVE_LIBM 1 -_ACEOF +done +if ${ac_cv_search_ismod+:} false; then : - LIBS="-lm $LIBS" +else + ac_cv_search_ismod=no +fi +rm conftest.$ac_ext +LIBS=$ac_func_search_save_LIBS +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_search_ismod" >&5 +$as_echo "$ac_cv_search_ismod" >&6; } +ac_res=$ac_cv_search_ismod +if test "$ac_res" != no; then : + test "$ac_res" = "none required" || LIBS="$ac_res $LIBS" fi diff --git a/configure.ac b/configure.ac index 008c2780..7c922ccf 100644 --- a/configure.ac +++ b/configure.ac @@ -254,9 +254,9 @@ AC_CHECK_FUNC(getaddrinfo, [AC_DEFINE(HAVE_GETADDRINFO, 1, [have getaddrinfo])], [AC_DEFINE(HAVE_GETADDRINFO, 1, [have getaddrinfo])])]) -AC_CHECK_LIB(m, fmod) -AC_CHECK_LIB(m, isinf) -AC_CHECK_LIB(m, ismod) +AC_SEARCH_LIBS(fmod, m) +AC_SEARCH_LIBS(isinf, m) +AC_SEARCH_LIBS(ismod, m) dnl Don't look for libsigsegv on OSF/1, gives us severe headaches case $host_os in osf1) : ;; diff --git a/doc/ChangeLog b/doc/ChangeLog index 269c8aa7..4fb63919 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -1,6 +1,26 @@ +2015-03-17 Arnold D. Robbins <arnold@skeeve.com> + + * gawktexi.in: Turn "positive" into non-negative as appropriate. + Thanks to Nicholas Mills <nlmills@clemson.edu> for pointing out + the issue. + +2015-03-08 Arnold D. Robbins <arnold@skeeve.com> + + * gawktexi.in: Briefly describe that nonfatal I/O overrides + GAWK_SOCK_RETRIES, in the env var part and in the nonfatal I/O + part. + +2015-03-01 Arnold D. Robbins <arnold@skeeve.com> + + * gawktexi.in: Change quotes to @dfn for pseudorandom. + A last-minute O'Reilly fix. + 2015-02-27 Arnold D. Robbins <arnold@skeeve.com> * gawktexi.in: Update UPDATE-MONTH and copyright year. + Note that "the guide is definitive" quote is really + from "The Restaurant at the End of the Universe". Thanks + to Antonio Colombo for pointing this out. 2015-02-24 Arnold D. Robbins <arnold@skeeve.com> @@ -46,6 +66,7 @@ 2015-02-08 Arnold D. Robbins <arnold@skeeve.com> * gawktexi.in: O'Reilly fixes. + Make non-fatal i/o use "NONFATAL". 2015-02-06 Arnold D. Robbins <arnold@skeeve.com> @@ -106,12 +127,21 @@ * gawkinet.texi: Fix capitalization in document title. * gawktexi.in: Here we go again: Starting on more O'Reilly fixes. +2014-12-27 Arnold D. Robbins <arnold@skeeve.com> + + * gawktexi.in: Add info that nonfatal I/O works with stdout and + stderr. Revise version info and what was added when. + 2014-12-26 Antonio Giovanni Colombo <azc100@gmail.com> * gawktexi.in (Glossary): Really sort the items. 2014-12-24 Arnold D. Robbins <arnold@skeeve.com> + * gawktexi.in: Start documenting nonfatal output. + +2014-12-24 Arnold D. Robbins <arnold@skeeve.com> + * gawktexi.in: Add one more paragraph to new foreword. * gawktexi.in: Fix exponentiation in TeX mode. Thanks to Marco Curreli by way of Antonio Giovanni Colombo. diff --git a/doc/gawk.info b/doc/gawk.info index 6cddc1ba..90ae5848 100644 --- a/doc/gawk.info +++ b/doc/gawk.info @@ -246,6 +246,7 @@ entitled "GNU Free Documentation License". * Special Caveats:: Things to watch out for. * Close Files And Pipes:: Closing Input and Output Files and Pipes. +* Nonfatal:: Enabling Nonfatal Output. * Output Summary:: Output summary. * Output Exercises:: Exercises. * Values:: Constants, Variables, and Regular @@ -3013,7 +3014,8 @@ used by regular users: `GAWK_SOCK_RETRIES' Controls the number of times `gawk' attempts to retry a two-way TCP/IP (socket) connection before giving up. *Note TCP/IP - Networking::. + Networking::. Note that when nonfatal I/O is enabled (*note + Nonfatal::), `gawk' only tries to open a TCP/IP socket once. `POSIXLY_CORRECT' Causes `gawk' to switch to POSIX-compatibility mode, disabling all @@ -5098,9 +5100,9 @@ the built-in variable `FIELDWIDTHS'. Each number specifies the width of the field, _including_ columns between fields. If you want to ignore the columns between fields, you can specify the width as a separate field that is subsequently ignored. It is a fatal error to -supply a field width that is not a positive number. The following data -is the output of the Unix `w' utility. It is useful to illustrate the -use of `FIELDWIDTHS': +supply a field width that has a negative value. The following data is +the output of the Unix `w' utility. It is useful to illustrate the use +of `FIELDWIDTHS': 10:06pm up 21 days, 14:04, 23 users User tty login idle JCPU PCPU what @@ -6128,6 +6130,7 @@ function. `gawk' allows access to inherited file descriptors. * Close Files And Pipes:: Closing Input and Output Files and Pipes. +* Nonfatal:: Enabling Nonfatal Output. * Output Summary:: Output summary. * Output Exercises:: Exercises. @@ -7041,7 +7044,7 @@ that `gawk' provides: behavior. -File: gawk.info, Node: Close Files And Pipes, Next: Output Summary, Prev: Special Files, Up: Printing +File: gawk.info, Node: Close Files And Pipes, Next: Nonfatal, Prev: Special Files, Up: Printing 5.9 Closing Input and Output Redirections ========================================= @@ -7210,9 +7213,68 @@ call. See the system manual pages for information on how to decode this value. -File: gawk.info, Node: Output Summary, Next: Output Exercises, Prev: Close Files And Pipes, Up: Printing +File: gawk.info, Node: Nonfatal, Next: Output Summary, Prev: Close Files And Pipes, Up: Printing -5.10 Summary +5.10 Enabling Nonfatal Output +============================= + +This minor node describes a `gawk'-specific feature. + + In standard `awk', output with `print' or `printf' to a nonexistent +file, or some other I/O error (such as filling up the disk) is a fatal +error. + + $ gawk 'BEGIN { print "hi" > "/no/such/file" }' + error--> gawk: cmd. line:1: fatal: can't redirect to `/no/such/file' (No such file or directory) + + `gawk' makes it possible to detect that an error has occurred, +allowing you to possibly recover from the error, or at least print an +error message of your choosing before exiting. You can do this in one +of two ways: + + * For all output files, by assigning any value to + `PROCINFO["NONFATAL"]'. + + * On a per-file basis, by assigning any value to `PROCINFO[FILENAME, + "NONFATAL"]'. Here, FILENAME is the name of the file to which you + wish output to be nonfatal. + + Once you have enabled nonfatal output, you must check `ERRNO' after +every relevant `print' or `printf' statement to see if something went +wrong. It is also a good idea to initialize `ERRNO' to zero before +attempting the output. For example: + + $ gawk ' + > BEGIN { + > PROCINFO["NONFATAL"] = 1 + > ERRNO = 0 + > print "hi" > "/no/such/file" + > if (ERRNO) { + > print("Output failed:", ERRNO) > "/dev/stderr" + > exit 1 + > } + > }' + error--> Output failed: No such file or directory + + Here, `gawk' did not produce a fatal error; instead it let the `awk' +program code detect the problem and handle it. + + This mechanism works also for standard output and standard error. +For standard output, you may use `PROCINFO["-", "NONFATAL"]' or +`PROCINFO["/dev/stdout", "NONFATAL"]'. For standard error, use +`PROCINFO["/dev/stderr", "NONFATAL"]'. + + When attempting to open a TCP/IP socket (*note TCP/IP Networking::), +`gawk' tries multiple times. The `GAWK_SOCK_RETRIES' environment +variable (*note Other Environment Variables::) allows you to override +`gawk''s builtin default number of attempts. However, once nonfatal +I/O is enabled for a given socket, `gawk' only retries once, relying on +`awk'-level code to notice that there was a problem. + + +File: gawk.info, Node: Output Summary, Next: Output Exercises, Prev: Nonfatal, Up: Printing + +5.11 Summary ============ * The `print' statement prints comma-separated expressions. Each @@ -7234,11 +7296,16 @@ File: gawk.info, Node: Output Summary, Next: Output Exercises, Prev: Close Fi For coprocesses, it is possible to close only one direction of the communications. + * Normally errors with `print' or `printf' are fatal. `gawk' lets + you make output errors be nonfatal either for all files or on a + per-file basis. You must then check for errors after every + relevant output statement. + File: gawk.info, Node: Output Exercises, Prev: Output Summary, Up: Printing -5.11 Exercises +5.12 Exercises ============== 1. Rewrite the program: @@ -10866,7 +10933,7 @@ be used as an array index. including a specification of how many elements or components they contain. In such languages, the declaration causes a contiguous block of memory to be allocated for that many elements. Usually, an index in -the array must be a positive integer. For example, the index zero +the array must be a nonnegative integer. For example, the index zero specifies the first element in the array, which is actually stored at the beginning of the block of memory. Index one specifies the second element, which is stored in memory right after the first element, and @@ -10921,8 +10988,8 @@ It has elements 0-3 and 10, but doesn't have elements 4, 5, 6, 7, 8, or 9. Another consequence of associative arrays is that the indices don't -have to be positive integers. Any number, or even a string, can be an -index. For example, the following is an array that translates words +have to be nonnegative integers. Any number, or even a string, can be +an index. For example, the following is an array that translates words from English to French: Index Value @@ -11093,7 +11160,7 @@ File: gawk.info, Node: Scanning an Array, Next: Controlling Scanning, Prev: A In programs that use arrays, it is often necessary to use a loop that executes once for each element of an array. In other languages, where -arrays are contiguous and indices are limited to positive integers, +arrays are contiguous and indices are limited to nonnegative integers, this is easy: all the valid indices can be found by counting from the lowest index up to the highest. This technique won't do the job in `awk', because any number or string can be an array index. So `awk' @@ -12029,7 +12096,7 @@ numbers. (2) `mawk' uses a different seed each time. (3) Computer-generated random numbers really are not truly random. -They are technically known as "pseudorandom." This means that although +They are technically known as "pseudorandom". This means that although the numbers in a sequence appear to be random, you can in fact generate the same sequence of random numbers over and over again. @@ -21836,8 +21903,7 @@ Integer arithmetic In computers, integer values come in two flavors: "signed" and "unsigned". Signed values may be negative or positive, whereas - unsigned values are always positive (i.e., greater than or equal - to zero). + unsigned values are always greater than or equal to zero. In computer systems, integer arithmetic is exact, but the possible range of values is limited. Integer arithmetic is generally @@ -26479,6 +26545,9 @@ the current version of `gawk'. - Directories on the command line produce a warning and are skipped (*note Command-line directories::) + - Output with `print' and `printf' need not be fatal (*note + Nonfatal::) + * New keywords: - The `BEGINFILE' and `ENDFILE' special patterns (*note @@ -26994,6 +27063,8 @@ in POSIX `awk', in the order they were added to `gawk'. * The maximum number of hexdecimal digits in `\x' escapes is now two. *Note Escape Sequences::. + * Nonfatal output with `print' and `printf'. *Note Nonfatal::. + * Support for MirBSD was removed. @@ -34667,560 +34738,561 @@ Index Tag Table: Node: Top1204 -Node: Foreword342225 -Node: Foreword446669 -Node: Preface48200 -Ref: Preface-Footnote-151071 -Ref: Preface-Footnote-251178 -Ref: Preface-Footnote-351411 -Node: History51553 -Node: Names53904 -Ref: Names-Footnote-154998 -Node: This Manual55144 -Ref: This Manual-Footnote-161644 -Node: Conventions61744 -Node: Manual History64081 -Ref: Manual History-Footnote-167074 -Ref: Manual History-Footnote-267115 -Node: How To Contribute67189 -Node: Acknowledgments68318 -Node: Getting Started73184 -Node: Running gawk75623 -Node: One-shot76813 -Node: Read Terminal78077 -Node: Long80108 -Node: Executable Scripts81621 -Ref: Executable Scripts-Footnote-184410 -Node: Comments84513 -Node: Quoting86995 -Node: DOS Quoting92513 -Node: Sample Data Files93188 -Node: Very Simple95783 -Node: Two Rules100682 -Node: More Complex102568 -Node: Statements/Lines105430 -Ref: Statements/Lines-Footnote-1109885 -Node: Other Features110150 -Node: When111086 -Ref: When-Footnote-1112840 -Node: Intro Summary112905 -Node: Invoking Gawk113789 -Node: Command Line115303 -Node: Options116101 -Ref: Options-Footnote-1131896 -Ref: Options-Footnote-2132125 -Node: Other Arguments132150 -Node: Naming Standard Input135098 -Node: Environment Variables136191 -Node: AWKPATH Variable136749 -Ref: AWKPATH Variable-Footnote-1140156 -Ref: AWKPATH Variable-Footnote-2140201 -Node: AWKLIBPATH Variable140461 -Node: Other Environment Variables141717 -Node: Exit Status145235 -Node: Include Files145911 -Node: Loading Shared Libraries149500 -Node: Obsolete150927 -Node: Undocumented151619 -Node: Invoking Summary151886 -Node: Regexp153549 -Node: Regexp Usage155003 -Node: Escape Sequences157040 -Node: Regexp Operators163269 -Ref: Regexp Operators-Footnote-1170679 -Ref: Regexp Operators-Footnote-2170826 -Node: Bracket Expressions170924 -Ref: table-char-classes172939 -Node: Leftmost Longest175881 -Node: Computed Regexps177183 -Node: GNU Regexp Operators180612 -Node: Case-sensitivity184284 -Ref: Case-sensitivity-Footnote-1187169 -Ref: Case-sensitivity-Footnote-2187404 -Node: Regexp Summary187512 -Node: Reading Files188979 -Node: Records191072 -Node: awk split records191805 -Node: gawk split records196734 -Ref: gawk split records-Footnote-1201273 -Node: Fields201310 -Ref: Fields-Footnote-1204088 -Node: Nonconstant Fields204174 -Ref: Nonconstant Fields-Footnote-1206412 -Node: Changing Fields206615 -Node: Field Separators212546 -Node: Default Field Splitting215250 -Node: Regexp Field Splitting216367 -Node: Single Character Fields219717 -Node: Command Line Field Separator220776 -Node: Full Line Fields223993 -Ref: Full Line Fields-Footnote-1225514 -Ref: Full Line Fields-Footnote-2225560 -Node: Field Splitting Summary225661 -Node: Constant Size227735 -Node: Splitting By Content232318 -Ref: Splitting By Content-Footnote-1236283 -Node: Multiple Line236446 -Ref: Multiple Line-Footnote-1242327 -Node: Getline242506 -Node: Plain Getline244713 -Node: Getline/Variable247353 -Node: Getline/File248502 -Node: Getline/Variable/File249887 -Ref: Getline/Variable/File-Footnote-1251490 -Node: Getline/Pipe251577 -Node: Getline/Variable/Pipe254255 -Node: Getline/Coprocess255386 -Node: Getline/Variable/Coprocess256650 -Node: Getline Notes257389 -Node: Getline Summary260183 -Ref: table-getline-variants260595 -Node: Read Timeout261424 -Ref: Read Timeout-Footnote-1265261 -Node: Command-line directories265319 -Node: Input Summary266224 -Node: Input Exercises269609 -Node: Printing270337 -Node: Print272114 -Node: Print Examples273571 -Node: Output Separators276350 -Node: OFMT278368 -Node: Printf279723 -Node: Basic Printf280508 -Node: Control Letters282080 -Node: Format Modifiers286065 -Node: Printf Examples292071 -Node: Redirection294557 -Node: Special FD301395 -Ref: Special FD-Footnote-1304561 -Node: Special Files304635 -Node: Other Inherited Files305252 -Node: Special Network306252 -Node: Special Caveats307114 -Node: Close Files And Pipes308063 -Ref: Close Files And Pipes-Footnote-1315254 -Ref: Close Files And Pipes-Footnote-2315402 -Node: Output Summary315552 -Node: Output Exercises316550 -Node: Expressions317230 -Node: Values318419 -Node: Constants319096 -Node: Scalar Constants319787 -Ref: Scalar Constants-Footnote-1320649 -Node: Nondecimal-numbers320899 -Node: Regexp Constants323909 -Node: Using Constant Regexps324435 -Node: Variables327598 -Node: Using Variables328255 -Node: Assignment Options330166 -Node: Conversion332041 -Node: Strings And Numbers332565 -Ref: Strings And Numbers-Footnote-1335630 -Node: Locale influences conversions335739 -Ref: table-locale-affects338485 -Node: All Operators339077 -Node: Arithmetic Ops339706 -Node: Concatenation342211 -Ref: Concatenation-Footnote-1345030 -Node: Assignment Ops345137 -Ref: table-assign-ops350116 -Node: Increment Ops351426 -Node: Truth Values and Conditions354857 -Node: Truth Values355940 -Node: Typing and Comparison356989 -Node: Variable Typing357805 -Node: Comparison Operators361472 -Ref: table-relational-ops361882 -Node: POSIX String Comparison365377 -Ref: POSIX String Comparison-Footnote-1366449 -Node: Boolean Ops366588 -Ref: Boolean Ops-Footnote-1371066 -Node: Conditional Exp371157 -Node: Function Calls372895 -Node: Precedence376775 -Node: Locales380435 -Node: Expressions Summary382067 -Node: Patterns and Actions384638 -Node: Pattern Overview385758 -Node: Regexp Patterns387437 -Node: Expression Patterns387980 -Node: Ranges391760 -Node: BEGIN/END394867 -Node: Using BEGIN/END395628 -Ref: Using BEGIN/END-Footnote-1398364 -Node: I/O And BEGIN/END398470 -Node: BEGINFILE/ENDFILE400785 -Node: Empty403682 -Node: Using Shell Variables403999 -Node: Action Overview406272 -Node: Statements408598 -Node: If Statement410446 -Node: While Statement411941 -Node: Do Statement413969 -Node: For Statement415117 -Node: Switch Statement418275 -Node: Break Statement420657 -Node: Continue Statement422750 -Node: Next Statement424577 -Node: Nextfile Statement426958 -Node: Exit Statement429586 -Node: Built-in Variables431997 -Node: User-modified433130 -Ref: User-modified-Footnote-1440764 -Node: Auto-set440826 -Ref: Auto-set-Footnote-1454535 -Ref: Auto-set-Footnote-2454740 -Node: ARGC and ARGV454796 -Node: Pattern Action Summary459014 -Node: Arrays461447 -Node: Array Basics462776 -Node: Array Intro463620 -Ref: figure-array-elements465554 -Ref: Array Intro-Footnote-1468174 -Node: Reference to Elements468302 -Node: Assigning Elements470764 -Node: Array Example471255 -Node: Scanning an Array473014 -Node: Controlling Scanning476034 -Ref: Controlling Scanning-Footnote-1481428 -Node: Numeric Array Subscripts481744 -Node: Uninitialized Subscripts483929 -Node: Delete485546 -Ref: Delete-Footnote-1488295 -Node: Multidimensional488352 -Node: Multiscanning491449 -Node: Arrays of Arrays493038 -Node: Arrays Summary497792 -Node: Functions499883 -Node: Built-in500922 -Node: Calling Built-in502000 -Node: Numeric Functions503995 -Ref: Numeric Functions-Footnote-1508813 -Ref: Numeric Functions-Footnote-2509170 -Ref: Numeric Functions-Footnote-3509218 -Node: String Functions509490 -Ref: String Functions-Footnote-1532991 -Ref: String Functions-Footnote-2533120 -Ref: String Functions-Footnote-3533368 -Node: Gory Details533455 -Ref: table-sub-escapes535236 -Ref: table-sub-proposed536751 -Ref: table-posix-sub538113 -Ref: table-gensub-escapes539650 -Ref: Gory Details-Footnote-1540483 -Node: I/O Functions540634 -Ref: I/O Functions-Footnote-1547870 -Node: Time Functions548017 -Ref: Time Functions-Footnote-1558526 -Ref: Time Functions-Footnote-2558594 -Ref: Time Functions-Footnote-3558752 -Ref: Time Functions-Footnote-4558863 -Ref: Time Functions-Footnote-5558975 -Ref: Time Functions-Footnote-6559202 -Node: Bitwise Functions559468 -Ref: table-bitwise-ops560030 -Ref: Bitwise Functions-Footnote-1564358 -Node: Type Functions564530 -Node: I18N Functions565682 -Node: User-defined567329 -Node: Definition Syntax568134 -Ref: Definition Syntax-Footnote-1573793 -Node: Function Example573864 -Ref: Function Example-Footnote-1576785 -Node: Function Caveats576807 -Node: Calling A Function577325 -Node: Variable Scope578283 -Node: Pass By Value/Reference581276 -Node: Return Statement584773 -Node: Dynamic Typing587752 -Node: Indirect Calls588681 -Ref: Indirect Calls-Footnote-1598546 -Node: Functions Summary598674 -Node: Library Functions601376 -Ref: Library Functions-Footnote-1604984 -Ref: Library Functions-Footnote-2605127 -Node: Library Names605298 -Ref: Library Names-Footnote-1608756 -Ref: Library Names-Footnote-2608979 -Node: General Functions609065 -Node: Strtonum Function610168 -Node: Assert Function613190 -Node: Round Function616514 -Node: Cliff Random Function618055 -Node: Ordinal Functions619071 -Ref: Ordinal Functions-Footnote-1622134 -Ref: Ordinal Functions-Footnote-2622386 -Node: Join Function622597 -Ref: Join Function-Footnote-1624367 -Node: Getlocaltime Function624567 -Node: Readfile Function628311 -Node: Shell Quoting630283 -Node: Data File Management631684 -Node: Filetrans Function632316 -Node: Rewind Function636412 -Node: File Checking637798 -Ref: File Checking-Footnote-1639131 -Node: Empty Files639332 -Node: Ignoring Assigns641311 -Node: Getopt Function642861 -Ref: Getopt Function-Footnote-1654325 -Node: Passwd Functions654525 -Ref: Passwd Functions-Footnote-1663365 -Node: Group Functions663453 -Ref: Group Functions-Footnote-1671350 -Node: Walking Arrays671555 -Node: Library Functions Summary674561 -Node: Library Exercises675963 -Node: Sample Programs677243 -Node: Running Examples678013 -Node: Clones678741 -Node: Cut Program679965 -Node: Egrep Program689685 -Ref: Egrep Program-Footnote-1697188 -Node: Id Program697298 -Node: Split Program700974 -Ref: Split Program-Footnote-1704428 -Node: Tee Program704556 -Node: Uniq Program707345 -Node: Wc Program714764 -Ref: Wc Program-Footnote-1719014 -Node: Miscellaneous Programs719108 -Node: Dupword Program720321 -Node: Alarm Program722352 -Node: Translate Program727157 -Ref: Translate Program-Footnote-1731720 -Node: Labels Program731990 -Ref: Labels Program-Footnote-1735341 -Node: Word Sorting735425 -Node: History Sorting739495 -Node: Extract Program741330 -Node: Simple Sed748854 -Node: Igawk Program751924 -Ref: Igawk Program-Footnote-1766250 -Ref: Igawk Program-Footnote-2766451 -Ref: Igawk Program-Footnote-3766573 -Node: Anagram Program766688 -Node: Signature Program769749 -Node: Programs Summary770996 -Node: Programs Exercises772217 -Ref: Programs Exercises-Footnote-1776348 -Node: Advanced Features776439 -Node: Nondecimal Data778421 -Node: Array Sorting780011 -Node: Controlling Array Traversal780711 -Ref: Controlling Array Traversal-Footnote-1789077 -Node: Array Sorting Functions789195 -Ref: Array Sorting Functions-Footnote-1793081 -Node: Two-way I/O793277 -Ref: Two-way I/O-Footnote-1798222 -Ref: Two-way I/O-Footnote-2798408 -Node: TCP/IP Networking798490 -Node: Profiling801362 -Node: Advanced Features Summary809633 -Node: Internationalization811566 -Node: I18N and L10N813046 -Node: Explaining gettext813732 -Ref: Explaining gettext-Footnote-1818757 -Ref: Explaining gettext-Footnote-2818941 -Node: Programmer i18n819106 -Ref: Programmer i18n-Footnote-1823982 -Node: Translator i18n824031 -Node: String Extraction824825 -Ref: String Extraction-Footnote-1825956 -Node: Printf Ordering826042 -Ref: Printf Ordering-Footnote-1828828 -Node: I18N Portability828892 -Ref: I18N Portability-Footnote-1831348 -Node: I18N Example831411 -Ref: I18N Example-Footnote-1834214 -Node: Gawk I18N834286 -Node: I18N Summary834930 -Node: Debugger836270 -Node: Debugging837292 -Node: Debugging Concepts837733 -Node: Debugging Terms839543 -Node: Awk Debugging842115 -Node: Sample Debugging Session843021 -Node: Debugger Invocation843555 -Node: Finding The Bug844940 -Node: List of Debugger Commands851419 -Node: Breakpoint Control852751 -Node: Debugger Execution Control856428 -Node: Viewing And Changing Data859787 -Node: Execution Stack863163 -Node: Debugger Info864798 -Node: Miscellaneous Debugger Commands868843 -Node: Readline Support873844 -Node: Limitations874738 -Node: Debugging Summary876853 -Node: Arbitrary Precision Arithmetic878027 -Node: Computer Arithmetic879443 -Ref: table-numeric-ranges883042 -Ref: Computer Arithmetic-Footnote-1883566 -Node: Math Definitions883623 -Ref: table-ieee-formats886918 -Ref: Math Definitions-Footnote-1887522 -Node: MPFR features887627 -Node: FP Math Caution889298 -Ref: FP Math Caution-Footnote-1890348 -Node: Inexactness of computations890717 -Node: Inexact representation891676 -Node: Comparing FP Values893034 -Node: Errors accumulate894116 -Node: Getting Accuracy895548 -Node: Try To Round898252 -Node: Setting precision899151 -Ref: table-predefined-precision-strings899835 -Node: Setting the rounding mode901664 -Ref: table-gawk-rounding-modes902028 -Ref: Setting the rounding mode-Footnote-1905480 -Node: Arbitrary Precision Integers905659 -Ref: Arbitrary Precision Integers-Footnote-1910557 -Node: POSIX Floating Point Problems910706 -Ref: POSIX Floating Point Problems-Footnote-1914585 -Node: Floating point summary914623 -Node: Dynamic Extensions916810 -Node: Extension Intro918362 -Node: Plugin License919627 -Node: Extension Mechanism Outline920424 -Ref: figure-load-extension920852 -Ref: figure-register-new-function922332 -Ref: figure-call-new-function923336 -Node: Extension API Description925323 -Node: Extension API Functions Introduction926773 -Node: General Data Types931594 -Ref: General Data Types-Footnote-1937494 -Node: Memory Allocation Functions937793 -Ref: Memory Allocation Functions-Footnote-1940632 -Node: Constructor Functions940731 -Node: Registration Functions942470 -Node: Extension Functions943155 -Node: Exit Callback Functions945452 -Node: Extension Version String946700 -Node: Input Parsers947363 -Node: Output Wrappers957238 -Node: Two-way processors961751 -Node: Printing Messages964014 -Ref: Printing Messages-Footnote-1965090 -Node: Updating `ERRNO'965242 -Node: Requesting Values965982 -Ref: table-value-types-returned966709 -Node: Accessing Parameters967666 -Node: Symbol Table Access968900 -Node: Symbol table by name969414 -Node: Symbol table by cookie971434 -Ref: Symbol table by cookie-Footnote-1975579 -Node: Cached values975642 -Ref: Cached values-Footnote-1979138 -Node: Array Manipulation979229 -Ref: Array Manipulation-Footnote-1980327 -Node: Array Data Types980364 -Ref: Array Data Types-Footnote-1983019 -Node: Array Functions983111 -Node: Flattening Arrays986970 -Node: Creating Arrays993872 -Node: Extension API Variables998643 -Node: Extension Versioning999279 -Node: Extension API Informational Variables1001170 -Node: Extension API Boilerplate1002235 -Node: Finding Extensions1006044 -Node: Extension Example1006604 -Node: Internal File Description1007376 -Node: Internal File Ops1011443 -Ref: Internal File Ops-Footnote-11023194 -Node: Using Internal File Ops1023334 -Ref: Using Internal File Ops-Footnote-11025717 -Node: Extension Samples1025990 -Node: Extension Sample File Functions1027518 -Node: Extension Sample Fnmatch1035199 -Node: Extension Sample Fork1036687 -Node: Extension Sample Inplace1037902 -Node: Extension Sample Ord1039578 -Node: Extension Sample Readdir1040414 -Ref: table-readdir-file-types1041291 -Node: Extension Sample Revout1042102 -Node: Extension Sample Rev2way1042691 -Node: Extension Sample Read write array1043431 -Node: Extension Sample Readfile1045371 -Node: Extension Sample Time1046466 -Node: Extension Sample API Tests1047814 -Node: gawkextlib1048305 -Node: Extension summary1050983 -Node: Extension Exercises1054672 -Node: Language History1055394 -Node: V7/SVR3.11057050 -Node: SVR41059203 -Node: POSIX1060637 -Node: BTL1062018 -Node: POSIX/GNU1062749 -Node: Feature History1068494 -Node: Common Extensions1082220 -Node: Ranges and Locales1083592 -Ref: Ranges and Locales-Footnote-11088211 -Ref: Ranges and Locales-Footnote-21088238 -Ref: Ranges and Locales-Footnote-31088473 -Node: Contributors1088694 -Node: History summary1094234 -Node: Installation1095613 -Node: Gawk Distribution1096559 -Node: Getting1097043 -Node: Extracting1097866 -Node: Distribution contents1099503 -Node: Unix Installation1105605 -Node: Quick Installation1106288 -Node: Shell Startup Files1108699 -Node: Additional Configuration Options1109778 -Node: Configuration Philosophy1111582 -Node: Non-Unix Installation1113951 -Node: PC Installation1114409 -Node: PC Binary Installation1115729 -Node: PC Compiling1117577 -Ref: PC Compiling-Footnote-11120598 -Node: PC Testing1120707 -Node: PC Using1121883 -Node: Cygwin1125998 -Node: MSYS1126768 -Node: VMS Installation1127269 -Node: VMS Compilation1128061 -Ref: VMS Compilation-Footnote-11129290 -Node: VMS Dynamic Extensions1129348 -Node: VMS Installation Details1131032 -Node: VMS Running1133283 -Node: VMS GNV1136123 -Node: VMS Old Gawk1136858 -Node: Bugs1137328 -Node: Other Versions1141217 -Node: Installation summary1147651 -Node: Notes1148710 -Node: Compatibility Mode1149575 -Node: Additions1150357 -Node: Accessing The Source1151282 -Node: Adding Code1152717 -Node: New Ports1158874 -Node: Derived Files1163356 -Ref: Derived Files-Footnote-11168831 -Ref: Derived Files-Footnote-21168865 -Ref: Derived Files-Footnote-31169461 -Node: Future Extensions1169575 -Node: Implementation Limitations1170181 -Node: Extension Design1171429 -Node: Old Extension Problems1172583 -Ref: Old Extension Problems-Footnote-11174100 -Node: Extension New Mechanism Goals1174157 -Ref: Extension New Mechanism Goals-Footnote-11177517 -Node: Extension Other Design Decisions1177706 -Node: Extension Future Growth1179814 -Node: Old Extension Mechanism1180650 -Node: Notes summary1182412 -Node: Basic Concepts1183598 -Node: Basic High Level1184279 -Ref: figure-general-flow1184551 -Ref: figure-process-flow1185150 -Ref: Basic High Level-Footnote-11188379 -Node: Basic Data Typing1188564 -Node: Glossary1191892 -Node: Copying1223821 -Node: GNU Free Documentation License1261377 -Node: Index1286513 +Node: Foreword342291 +Node: Foreword446735 +Node: Preface48266 +Ref: Preface-Footnote-151137 +Ref: Preface-Footnote-251244 +Ref: Preface-Footnote-351477 +Node: History51619 +Node: Names53970 +Ref: Names-Footnote-155064 +Node: This Manual55210 +Ref: This Manual-Footnote-161710 +Node: Conventions61810 +Node: Manual History64147 +Ref: Manual History-Footnote-167140 +Ref: Manual History-Footnote-267181 +Node: How To Contribute67255 +Node: Acknowledgments68384 +Node: Getting Started73250 +Node: Running gawk75689 +Node: One-shot76879 +Node: Read Terminal78143 +Node: Long80174 +Node: Executable Scripts81687 +Ref: Executable Scripts-Footnote-184476 +Node: Comments84579 +Node: Quoting87061 +Node: DOS Quoting92579 +Node: Sample Data Files93254 +Node: Very Simple95849 +Node: Two Rules100748 +Node: More Complex102634 +Node: Statements/Lines105496 +Ref: Statements/Lines-Footnote-1109951 +Node: Other Features110216 +Node: When111152 +Ref: When-Footnote-1112906 +Node: Intro Summary112971 +Node: Invoking Gawk113855 +Node: Command Line115369 +Node: Options116167 +Ref: Options-Footnote-1131962 +Ref: Options-Footnote-2132191 +Node: Other Arguments132216 +Node: Naming Standard Input135164 +Node: Environment Variables136257 +Node: AWKPATH Variable136815 +Ref: AWKPATH Variable-Footnote-1140222 +Ref: AWKPATH Variable-Footnote-2140267 +Node: AWKLIBPATH Variable140527 +Node: Other Environment Variables141783 +Node: Exit Status145414 +Node: Include Files146090 +Node: Loading Shared Libraries149679 +Node: Obsolete151106 +Node: Undocumented151798 +Node: Invoking Summary152065 +Node: Regexp153728 +Node: Regexp Usage155182 +Node: Escape Sequences157219 +Node: Regexp Operators163448 +Ref: Regexp Operators-Footnote-1170858 +Ref: Regexp Operators-Footnote-2171005 +Node: Bracket Expressions171103 +Ref: table-char-classes173118 +Node: Leftmost Longest176060 +Node: Computed Regexps177362 +Node: GNU Regexp Operators180791 +Node: Case-sensitivity184463 +Ref: Case-sensitivity-Footnote-1187348 +Ref: Case-sensitivity-Footnote-2187583 +Node: Regexp Summary187691 +Node: Reading Files189158 +Node: Records191251 +Node: awk split records191984 +Node: gawk split records196913 +Ref: gawk split records-Footnote-1201452 +Node: Fields201489 +Ref: Fields-Footnote-1204267 +Node: Nonconstant Fields204353 +Ref: Nonconstant Fields-Footnote-1206591 +Node: Changing Fields206794 +Node: Field Separators212725 +Node: Default Field Splitting215429 +Node: Regexp Field Splitting216546 +Node: Single Character Fields219896 +Node: Command Line Field Separator220955 +Node: Full Line Fields224172 +Ref: Full Line Fields-Footnote-1225693 +Ref: Full Line Fields-Footnote-2225739 +Node: Field Splitting Summary225840 +Node: Constant Size227914 +Node: Splitting By Content232493 +Ref: Splitting By Content-Footnote-1236458 +Node: Multiple Line236621 +Ref: Multiple Line-Footnote-1242502 +Node: Getline242681 +Node: Plain Getline244888 +Node: Getline/Variable247528 +Node: Getline/File248677 +Node: Getline/Variable/File250062 +Ref: Getline/Variable/File-Footnote-1251665 +Node: Getline/Pipe251752 +Node: Getline/Variable/Pipe254430 +Node: Getline/Coprocess255561 +Node: Getline/Variable/Coprocess256825 +Node: Getline Notes257564 +Node: Getline Summary260358 +Ref: table-getline-variants260770 +Node: Read Timeout261599 +Ref: Read Timeout-Footnote-1265436 +Node: Command-line directories265494 +Node: Input Summary266399 +Node: Input Exercises269784 +Node: Printing270512 +Node: Print272347 +Node: Print Examples273804 +Node: Output Separators276583 +Node: OFMT278601 +Node: Printf279956 +Node: Basic Printf280741 +Node: Control Letters282313 +Node: Format Modifiers286298 +Node: Printf Examples292304 +Node: Redirection294790 +Node: Special FD301628 +Ref: Special FD-Footnote-1304794 +Node: Special Files304868 +Node: Other Inherited Files305485 +Node: Special Network306485 +Node: Special Caveats307347 +Node: Close Files And Pipes308296 +Ref: Close Files And Pipes-Footnote-1315481 +Ref: Close Files And Pipes-Footnote-2315629 +Node: Nonfatal315779 +Node: Output Summary318104 +Node: Output Exercises319325 +Node: Expressions320005 +Node: Values321194 +Node: Constants321871 +Node: Scalar Constants322562 +Ref: Scalar Constants-Footnote-1323424 +Node: Nondecimal-numbers323674 +Node: Regexp Constants326684 +Node: Using Constant Regexps327210 +Node: Variables330373 +Node: Using Variables331030 +Node: Assignment Options332941 +Node: Conversion334816 +Node: Strings And Numbers335340 +Ref: Strings And Numbers-Footnote-1338405 +Node: Locale influences conversions338514 +Ref: table-locale-affects341260 +Node: All Operators341852 +Node: Arithmetic Ops342481 +Node: Concatenation344986 +Ref: Concatenation-Footnote-1347805 +Node: Assignment Ops347912 +Ref: table-assign-ops352891 +Node: Increment Ops354201 +Node: Truth Values and Conditions357632 +Node: Truth Values358715 +Node: Typing and Comparison359764 +Node: Variable Typing360580 +Node: Comparison Operators364247 +Ref: table-relational-ops364657 +Node: POSIX String Comparison368152 +Ref: POSIX String Comparison-Footnote-1369224 +Node: Boolean Ops369363 +Ref: Boolean Ops-Footnote-1373841 +Node: Conditional Exp373932 +Node: Function Calls375670 +Node: Precedence379550 +Node: Locales383210 +Node: Expressions Summary384842 +Node: Patterns and Actions387413 +Node: Pattern Overview388533 +Node: Regexp Patterns390212 +Node: Expression Patterns390755 +Node: Ranges394535 +Node: BEGIN/END397642 +Node: Using BEGIN/END398403 +Ref: Using BEGIN/END-Footnote-1401139 +Node: I/O And BEGIN/END401245 +Node: BEGINFILE/ENDFILE403560 +Node: Empty406457 +Node: Using Shell Variables406774 +Node: Action Overview409047 +Node: Statements411373 +Node: If Statement413221 +Node: While Statement414716 +Node: Do Statement416744 +Node: For Statement417892 +Node: Switch Statement421050 +Node: Break Statement423432 +Node: Continue Statement425525 +Node: Next Statement427352 +Node: Nextfile Statement429733 +Node: Exit Statement432361 +Node: Built-in Variables434772 +Node: User-modified435905 +Ref: User-modified-Footnote-1443539 +Node: Auto-set443601 +Ref: Auto-set-Footnote-1457310 +Ref: Auto-set-Footnote-2457515 +Node: ARGC and ARGV457571 +Node: Pattern Action Summary461789 +Node: Arrays464222 +Node: Array Basics465551 +Node: Array Intro466395 +Ref: figure-array-elements468332 +Ref: Array Intro-Footnote-1470955 +Node: Reference to Elements471083 +Node: Assigning Elements473545 +Node: Array Example474036 +Node: Scanning an Array475795 +Node: Controlling Scanning478818 +Ref: Controlling Scanning-Footnote-1484212 +Node: Numeric Array Subscripts484528 +Node: Uninitialized Subscripts486713 +Node: Delete488330 +Ref: Delete-Footnote-1491079 +Node: Multidimensional491136 +Node: Multiscanning494233 +Node: Arrays of Arrays495822 +Node: Arrays Summary500576 +Node: Functions502667 +Node: Built-in503706 +Node: Calling Built-in504784 +Node: Numeric Functions506779 +Ref: Numeric Functions-Footnote-1511597 +Ref: Numeric Functions-Footnote-2511954 +Ref: Numeric Functions-Footnote-3512002 +Node: String Functions512274 +Ref: String Functions-Footnote-1535775 +Ref: String Functions-Footnote-2535904 +Ref: String Functions-Footnote-3536152 +Node: Gory Details536239 +Ref: table-sub-escapes538020 +Ref: table-sub-proposed539535 +Ref: table-posix-sub540897 +Ref: table-gensub-escapes542434 +Ref: Gory Details-Footnote-1543267 +Node: I/O Functions543418 +Ref: I/O Functions-Footnote-1550654 +Node: Time Functions550801 +Ref: Time Functions-Footnote-1561310 +Ref: Time Functions-Footnote-2561378 +Ref: Time Functions-Footnote-3561536 +Ref: Time Functions-Footnote-4561647 +Ref: Time Functions-Footnote-5561759 +Ref: Time Functions-Footnote-6561986 +Node: Bitwise Functions562252 +Ref: table-bitwise-ops562814 +Ref: Bitwise Functions-Footnote-1567142 +Node: Type Functions567314 +Node: I18N Functions568466 +Node: User-defined570113 +Node: Definition Syntax570918 +Ref: Definition Syntax-Footnote-1576577 +Node: Function Example576648 +Ref: Function Example-Footnote-1579569 +Node: Function Caveats579591 +Node: Calling A Function580109 +Node: Variable Scope581067 +Node: Pass By Value/Reference584060 +Node: Return Statement587557 +Node: Dynamic Typing590536 +Node: Indirect Calls591465 +Ref: Indirect Calls-Footnote-1601330 +Node: Functions Summary601458 +Node: Library Functions604160 +Ref: Library Functions-Footnote-1607768 +Ref: Library Functions-Footnote-2607911 +Node: Library Names608082 +Ref: Library Names-Footnote-1611540 +Ref: Library Names-Footnote-2611763 +Node: General Functions611849 +Node: Strtonum Function612952 +Node: Assert Function615974 +Node: Round Function619298 +Node: Cliff Random Function620839 +Node: Ordinal Functions621855 +Ref: Ordinal Functions-Footnote-1624918 +Ref: Ordinal Functions-Footnote-2625170 +Node: Join Function625381 +Ref: Join Function-Footnote-1627151 +Node: Getlocaltime Function627351 +Node: Readfile Function631095 +Node: Shell Quoting633067 +Node: Data File Management634468 +Node: Filetrans Function635100 +Node: Rewind Function639196 +Node: File Checking640582 +Ref: File Checking-Footnote-1641915 +Node: Empty Files642116 +Node: Ignoring Assigns644095 +Node: Getopt Function645645 +Ref: Getopt Function-Footnote-1657109 +Node: Passwd Functions657309 +Ref: Passwd Functions-Footnote-1666149 +Node: Group Functions666237 +Ref: Group Functions-Footnote-1674134 +Node: Walking Arrays674339 +Node: Library Functions Summary677345 +Node: Library Exercises678747 +Node: Sample Programs680027 +Node: Running Examples680797 +Node: Clones681525 +Node: Cut Program682749 +Node: Egrep Program692469 +Ref: Egrep Program-Footnote-1699972 +Node: Id Program700082 +Node: Split Program703758 +Ref: Split Program-Footnote-1707212 +Node: Tee Program707340 +Node: Uniq Program710129 +Node: Wc Program717548 +Ref: Wc Program-Footnote-1721798 +Node: Miscellaneous Programs721892 +Node: Dupword Program723105 +Node: Alarm Program725136 +Node: Translate Program729941 +Ref: Translate Program-Footnote-1734504 +Node: Labels Program734774 +Ref: Labels Program-Footnote-1738125 +Node: Word Sorting738209 +Node: History Sorting742279 +Node: Extract Program744114 +Node: Simple Sed751638 +Node: Igawk Program754708 +Ref: Igawk Program-Footnote-1769034 +Ref: Igawk Program-Footnote-2769235 +Ref: Igawk Program-Footnote-3769357 +Node: Anagram Program769472 +Node: Signature Program772533 +Node: Programs Summary773780 +Node: Programs Exercises775001 +Ref: Programs Exercises-Footnote-1779132 +Node: Advanced Features779223 +Node: Nondecimal Data781205 +Node: Array Sorting782795 +Node: Controlling Array Traversal783495 +Ref: Controlling Array Traversal-Footnote-1791861 +Node: Array Sorting Functions791979 +Ref: Array Sorting Functions-Footnote-1795865 +Node: Two-way I/O796061 +Ref: Two-way I/O-Footnote-1801006 +Ref: Two-way I/O-Footnote-2801192 +Node: TCP/IP Networking801274 +Node: Profiling804146 +Node: Advanced Features Summary812417 +Node: Internationalization814350 +Node: I18N and L10N815830 +Node: Explaining gettext816516 +Ref: Explaining gettext-Footnote-1821541 +Ref: Explaining gettext-Footnote-2821725 +Node: Programmer i18n821890 +Ref: Programmer i18n-Footnote-1826766 +Node: Translator i18n826815 +Node: String Extraction827609 +Ref: String Extraction-Footnote-1828740 +Node: Printf Ordering828826 +Ref: Printf Ordering-Footnote-1831612 +Node: I18N Portability831676 +Ref: I18N Portability-Footnote-1834132 +Node: I18N Example834195 +Ref: I18N Example-Footnote-1836998 +Node: Gawk I18N837070 +Node: I18N Summary837714 +Node: Debugger839054 +Node: Debugging840076 +Node: Debugging Concepts840517 +Node: Debugging Terms842327 +Node: Awk Debugging844899 +Node: Sample Debugging Session845805 +Node: Debugger Invocation846339 +Node: Finding The Bug847724 +Node: List of Debugger Commands854203 +Node: Breakpoint Control855535 +Node: Debugger Execution Control859212 +Node: Viewing And Changing Data862571 +Node: Execution Stack865947 +Node: Debugger Info867582 +Node: Miscellaneous Debugger Commands871627 +Node: Readline Support876628 +Node: Limitations877522 +Node: Debugging Summary879637 +Node: Arbitrary Precision Arithmetic880811 +Node: Computer Arithmetic882227 +Ref: table-numeric-ranges885804 +Ref: Computer Arithmetic-Footnote-1886328 +Node: Math Definitions886385 +Ref: table-ieee-formats889680 +Ref: Math Definitions-Footnote-1890284 +Node: MPFR features890389 +Node: FP Math Caution892060 +Ref: FP Math Caution-Footnote-1893110 +Node: Inexactness of computations893479 +Node: Inexact representation894438 +Node: Comparing FP Values895796 +Node: Errors accumulate896878 +Node: Getting Accuracy898310 +Node: Try To Round901014 +Node: Setting precision901913 +Ref: table-predefined-precision-strings902597 +Node: Setting the rounding mode904426 +Ref: table-gawk-rounding-modes904790 +Ref: Setting the rounding mode-Footnote-1908242 +Node: Arbitrary Precision Integers908421 +Ref: Arbitrary Precision Integers-Footnote-1913319 +Node: POSIX Floating Point Problems913468 +Ref: POSIX Floating Point Problems-Footnote-1917347 +Node: Floating point summary917385 +Node: Dynamic Extensions919572 +Node: Extension Intro921124 +Node: Plugin License922389 +Node: Extension Mechanism Outline923186 +Ref: figure-load-extension923614 +Ref: figure-register-new-function925094 +Ref: figure-call-new-function926098 +Node: Extension API Description928085 +Node: Extension API Functions Introduction929535 +Node: General Data Types934356 +Ref: General Data Types-Footnote-1940256 +Node: Memory Allocation Functions940555 +Ref: Memory Allocation Functions-Footnote-1943394 +Node: Constructor Functions943493 +Node: Registration Functions945232 +Node: Extension Functions945917 +Node: Exit Callback Functions948214 +Node: Extension Version String949462 +Node: Input Parsers950125 +Node: Output Wrappers960000 +Node: Two-way processors964513 +Node: Printing Messages966776 +Ref: Printing Messages-Footnote-1967852 +Node: Updating `ERRNO'968004 +Node: Requesting Values968744 +Ref: table-value-types-returned969471 +Node: Accessing Parameters970428 +Node: Symbol Table Access971662 +Node: Symbol table by name972176 +Node: Symbol table by cookie974196 +Ref: Symbol table by cookie-Footnote-1978341 +Node: Cached values978404 +Ref: Cached values-Footnote-1981900 +Node: Array Manipulation981991 +Ref: Array Manipulation-Footnote-1983089 +Node: Array Data Types983126 +Ref: Array Data Types-Footnote-1985781 +Node: Array Functions985873 +Node: Flattening Arrays989732 +Node: Creating Arrays996634 +Node: Extension API Variables1001405 +Node: Extension Versioning1002041 +Node: Extension API Informational Variables1003932 +Node: Extension API Boilerplate1004997 +Node: Finding Extensions1008806 +Node: Extension Example1009366 +Node: Internal File Description1010138 +Node: Internal File Ops1014205 +Ref: Internal File Ops-Footnote-11025956 +Node: Using Internal File Ops1026096 +Ref: Using Internal File Ops-Footnote-11028479 +Node: Extension Samples1028752 +Node: Extension Sample File Functions1030280 +Node: Extension Sample Fnmatch1037961 +Node: Extension Sample Fork1039449 +Node: Extension Sample Inplace1040664 +Node: Extension Sample Ord1042340 +Node: Extension Sample Readdir1043176 +Ref: table-readdir-file-types1044053 +Node: Extension Sample Revout1044864 +Node: Extension Sample Rev2way1045453 +Node: Extension Sample Read write array1046193 +Node: Extension Sample Readfile1048133 +Node: Extension Sample Time1049228 +Node: Extension Sample API Tests1050576 +Node: gawkextlib1051067 +Node: Extension summary1053745 +Node: Extension Exercises1057434 +Node: Language History1058156 +Node: V7/SVR3.11059812 +Node: SVR41061965 +Node: POSIX1063399 +Node: BTL1064780 +Node: POSIX/GNU1065511 +Node: Feature History1071347 +Node: Common Extensions1085141 +Node: Ranges and Locales1086513 +Ref: Ranges and Locales-Footnote-11091132 +Ref: Ranges and Locales-Footnote-21091159 +Ref: Ranges and Locales-Footnote-31091394 +Node: Contributors1091615 +Node: History summary1097155 +Node: Installation1098534 +Node: Gawk Distribution1099480 +Node: Getting1099964 +Node: Extracting1100787 +Node: Distribution contents1102424 +Node: Unix Installation1108526 +Node: Quick Installation1109209 +Node: Shell Startup Files1111620 +Node: Additional Configuration Options1112699 +Node: Configuration Philosophy1114503 +Node: Non-Unix Installation1116872 +Node: PC Installation1117330 +Node: PC Binary Installation1118650 +Node: PC Compiling1120498 +Ref: PC Compiling-Footnote-11123519 +Node: PC Testing1123628 +Node: PC Using1124804 +Node: Cygwin1128919 +Node: MSYS1129689 +Node: VMS Installation1130190 +Node: VMS Compilation1130982 +Ref: VMS Compilation-Footnote-11132211 +Node: VMS Dynamic Extensions1132269 +Node: VMS Installation Details1133953 +Node: VMS Running1136204 +Node: VMS GNV1139044 +Node: VMS Old Gawk1139779 +Node: Bugs1140249 +Node: Other Versions1144138 +Node: Installation summary1150572 +Node: Notes1151631 +Node: Compatibility Mode1152496 +Node: Additions1153278 +Node: Accessing The Source1154203 +Node: Adding Code1155638 +Node: New Ports1161795 +Node: Derived Files1166277 +Ref: Derived Files-Footnote-11171752 +Ref: Derived Files-Footnote-21171786 +Ref: Derived Files-Footnote-31172382 +Node: Future Extensions1172496 +Node: Implementation Limitations1173102 +Node: Extension Design1174350 +Node: Old Extension Problems1175504 +Ref: Old Extension Problems-Footnote-11177021 +Node: Extension New Mechanism Goals1177078 +Ref: Extension New Mechanism Goals-Footnote-11180438 +Node: Extension Other Design Decisions1180627 +Node: Extension Future Growth1182735 +Node: Old Extension Mechanism1183571 +Node: Notes summary1185333 +Node: Basic Concepts1186519 +Node: Basic High Level1187200 +Ref: figure-general-flow1187472 +Ref: figure-process-flow1188071 +Ref: Basic High Level-Footnote-11191300 +Node: Basic Data Typing1191485 +Node: Glossary1194813 +Node: Copying1226742 +Node: GNU Free Documentation License1264298 +Node: Index1289434 End Tag Table diff --git a/doc/gawk.texi b/doc/gawk.texi index e4cb136b..27cbcab2 100644 --- a/doc/gawk.texi +++ b/doc/gawk.texi @@ -633,6 +633,7 @@ particular records in a file and perform operations upon them. * Special Caveats:: Things to watch out for. * Close Files And Pipes:: Closing Input and Output Files and Pipes. +* Nonfatal:: Enabling Nonfatal Output. * Output Summary:: Output summary. * Output Exercises:: Exercises. * Values:: Constants, Variables, and Regular @@ -4549,6 +4550,8 @@ wait for input before returning with an error. Controls the number of times @command{gawk} attempts to retry a two-way TCP/IP (socket) connection before giving up. @xref{TCP/IP Networking}. +Note that when nonfatal I/O is enabled (@pxref{Nonfatal}), +@command{gawk} only tries to open a TCP/IP socket once. @item POSIXLY_CORRECT Causes @command{gawk} to switch to POSIX-compatibility @@ -7672,7 +7675,7 @@ variable @code{FIELDWIDTHS}. Each number specifies the width of the field, @emph{including} columns between fields. If you want to ignore the columns between fields, you can specify the width as a separate field that is subsequently ignored. -It is a fatal error to supply a field width that is not a positive number. +It is a fatal error to supply a field width that has a negative value. The following data is the output of the Unix @command{w} utility. It is useful to illustrate the use of @code{FIELDWIDTHS}: @@ -8935,6 +8938,7 @@ and discusses the @code{close()} built-in function. @command{gawk} allows access to inherited file descriptors. * Close Files And Pipes:: Closing Input and Output Files and Pipes. +* Nonfatal:: Enabling Nonfatal Output. * Output Summary:: Output summary. * Output Exercises:: Exercises. @end menu @@ -10441,6 +10445,71 @@ when closing a pipe. @end ifnotdocbook +@node Nonfatal +@section Enabling Nonfatal Output + +This @value{SECTION} describes a @command{gawk}-specific feature. + +In standard @command{awk}, output with @code{print} or @code{printf} +to a nonexistent file, or some other I/O error (such as filling up the +disk) is a fatal error. + +@example +$ @kbd{gawk 'BEGIN @{ print "hi" > "/no/such/file" @}'} +@error{} gawk: cmd. line:1: fatal: can't redirect to `/no/such/file' (No such file or directory) +@end example + +@command{gawk} makes it possible to detect that an error has +occurred, allowing you to possibly recover from the error, or +at least print an error message of your choosing before exiting. +You can do this in one of two ways: + +@itemize @bullet +@item +For all output files, by assigning any value to @code{PROCINFO["NONFATAL"]}. + +@item +On a per-file basis, by assigning any value to +@code{PROCINFO[@var{filename}, "NONFATAL"]}. +Here, @var{filename} is the name of the file to which +you wish output to be nonfatal. +@end itemize + +Once you have enabled nonfatal output, you must check @code{ERRNO} +after every relevant @code{print} or @code{printf} statement to +see if something went wrong. It is also a good idea to initialize +@code{ERRNO} to zero before attempting the output. For example: + +@example +$ @kbd{gawk '} +> @kbd{BEGIN @{} +> @kbd{ PROCINFO["NONFATAL"] = 1} +> @kbd{ ERRNO = 0} +> @kbd{ print "hi" > "/no/such/file"} +> @kbd{ if (ERRNO) @{} +> @kbd{ print("Output failed:", ERRNO) > "/dev/stderr"} +> @kbd{ exit 1} +> @kbd{ @}} +> @kbd{@}'} +@error{} Output failed: No such file or directory +@end example + +Here, @command{gawk} did not produce a fatal error; instead +it let the @command{awk} program code detect the problem and handle it. + +This mechanism works also for standard output and standard error. +For standard output, you may use @code{PROCINFO["-", "NONFATAL"]} +or @code{PROCINFO["/dev/stdout", "NONFATAL"]}. For standard error, use +@code{PROCINFO["/dev/stderr", "NONFATAL"]}. + +When attempting to open a TCP/IP socket (@pxref{TCP/IP Networking}), +@command{gawk} tries multiple times. The @env{GAWK_SOCK_RETRIES} +environment variable (@pxref{Other Environment Variables}) allows you to +override @command{gawk}'s builtin default number of attempts. However, +once nonfatal I/O is enabled for a given socket, @command{gawk} only +retries once, relying on @command{awk}-level code to notice that there +was a problem. + @node Output Summary @section Summary @@ -10469,6 +10538,12 @@ Use @code{close()} to close open file, pipe, and coprocess redirections. For coprocesses, it is possible to close only one direction of the communications. +@item +Normally errors with @code{print} or @code{printf} are fatal. +@command{gawk} lets you make output errors be nonfatal either for +all files or on a per-file basis. You must then check for errors +after every relevant output statement. + @end itemize @c EXCLUDE START @@ -12004,6 +12079,9 @@ the string constant @code{"0"} is actually true, because it is non-null. @i{The Guide is definitive. Reality is frequently inaccurate.} @author Douglas Adams, @cite{The Hitchhiker's Guide to the Galaxy} @end quotation +@c 2/2015: Antonio Colombo points out that this is really from +@c The Restaurant at the End of the Universe. But I'm going to +@c leave it alone. @cindex comparison expressions @cindex expressions, comparison @@ -15508,7 +15586,7 @@ In most other languages, arrays must be @dfn{declared} before use, including a specification of how many elements or components they contain. In such languages, the declaration causes a contiguous block of memory to be allocated for that -many elements. Usually, an index in the array must be a positive integer. +many elements. Usually, an index in the array must be a nonnegative integer. For example, the index zero specifies the first element in the array, which is actually stored at the beginning of the block of memory. Index one specifies the second element, which is stored in memory right after the @@ -15688,7 +15766,7 @@ Now the array is @dfn{sparse}, which just means some indices are missing. It has elements 0--3 and 10, but doesn't have elements 4, 5, 6, 7, 8, or 9. Another consequence of associative arrays is that the indices don't -have to be positive integers. Any number, or even a string, can be +have to be nonnegative integers. Any number, or even a string, can be an index. For example, the following is an array that translates words from English to French: @@ -15951,7 +16029,7 @@ END @{ In programs that use arrays, it is often necessary to use a loop that executes once for each element of an array. In other languages, where -arrays are contiguous and indices are limited to positive integers, +arrays are contiguous and indices are limited to nonnegative integers, this is easy: all the valid indices can be found by counting from the lowest index up to the highest. This technique won't do the job in @command{awk}, because any number or string can be an array index. @@ -17073,7 +17151,7 @@ for generating random numbers to the value @var{x}. Each seed value leads to a particular sequence of random numbers.@footnote{Computer-generated random numbers really are not truly -random. They are technically known as ``pseudorandom.'' This means +random. They are technically known as @dfn{pseudorandom}. This means that although the numbers in a sequence appear to be random, you can in fact generate the same sequence of random numbers over and over again.} Thus, if the seed is set to the same value a second time, @@ -30209,8 +30287,8 @@ The disadvantage is that their range is limited. @cindex integers, unsigned In computers, integer values come in two flavors: @dfn{signed} and @dfn{unsigned}. Signed values may be negative or positive, whereas -unsigned values are always positive (i.e., greater than or equal -to zero). +unsigned values are always greater than or equal +to zero. In computer systems, integer arithmetic is exact, but the possible range of values is limited. Integer arithmetic is generally faster than @@ -35700,6 +35778,10 @@ Indirect function calls @item Directories on the command line produce a warning and are skipped (@pxref{Command-line directories}) + +@item +Output with @code{print} and @code{printf} need not be fatal +(@pxref{Nonfatal}) @end itemize @item @@ -36579,6 +36661,10 @@ is now two. @xref{Escape Sequences}. @item +Nonfatal output with @code{print} and @code{printf}. +@xref{Nonfatal}. + +@item Support for MirBSD was removed. @end itemize diff --git a/doc/gawktexi.in b/doc/gawktexi.in index c1654af5..121a066e 100644 --- a/doc/gawktexi.in +++ b/doc/gawktexi.in @@ -628,6 +628,7 @@ particular records in a file and perform operations upon them. * Special Caveats:: Things to watch out for. * Close Files And Pipes:: Closing Input and Output Files and Pipes. +* Nonfatal:: Enabling Nonfatal Output. * Output Summary:: Output summary. * Output Exercises:: Exercises. * Values:: Constants, Variables, and Regular @@ -4460,6 +4461,8 @@ wait for input before returning with an error. Controls the number of times @command{gawk} attempts to retry a two-way TCP/IP (socket) connection before giving up. @xref{TCP/IP Networking}. +Note that when nonfatal I/O is enabled (@pxref{Nonfatal}), +@command{gawk} only tries to open a TCP/IP socket once. @item POSIXLY_CORRECT Causes @command{gawk} to switch to POSIX-compatibility @@ -7272,7 +7275,7 @@ variable @code{FIELDWIDTHS}. Each number specifies the width of the field, @emph{including} columns between fields. If you want to ignore the columns between fields, you can specify the width as a separate field that is subsequently ignored. -It is a fatal error to supply a field width that is not a positive number. +It is a fatal error to supply a field width that has a negative value. The following data is the output of the Unix @command{w} utility. It is useful to illustrate the use of @code{FIELDWIDTHS}: @@ -8535,6 +8538,7 @@ and discusses the @code{close()} built-in function. @command{gawk} allows access to inherited file descriptors. * Close Files And Pipes:: Closing Input and Output Files and Pipes. +* Nonfatal:: Enabling Nonfatal Output. * Output Summary:: Output summary. * Output Exercises:: Exercises. @end menu @@ -9937,6 +9941,71 @@ when closing a pipe. @end sidebar +@node Nonfatal +@section Enabling Nonfatal Output + +This @value{SECTION} describes a @command{gawk}-specific feature. + +In standard @command{awk}, output with @code{print} or @code{printf} +to a nonexistent file, or some other I/O error (such as filling up the +disk) is a fatal error. + +@example +$ @kbd{gawk 'BEGIN @{ print "hi" > "/no/such/file" @}'} +@error{} gawk: cmd. line:1: fatal: can't redirect to `/no/such/file' (No such file or directory) +@end example + +@command{gawk} makes it possible to detect that an error has +occurred, allowing you to possibly recover from the error, or +at least print an error message of your choosing before exiting. +You can do this in one of two ways: + +@itemize @bullet +@item +For all output files, by assigning any value to @code{PROCINFO["NONFATAL"]}. + +@item +On a per-file basis, by assigning any value to +@code{PROCINFO[@var{filename}, "NONFATAL"]}. +Here, @var{filename} is the name of the file to which +you wish output to be nonfatal. +@end itemize + +Once you have enabled nonfatal output, you must check @code{ERRNO} +after every relevant @code{print} or @code{printf} statement to +see if something went wrong. It is also a good idea to initialize +@code{ERRNO} to zero before attempting the output. For example: + +@example +$ @kbd{gawk '} +> @kbd{BEGIN @{} +> @kbd{ PROCINFO["NONFATAL"] = 1} +> @kbd{ ERRNO = 0} +> @kbd{ print "hi" > "/no/such/file"} +> @kbd{ if (ERRNO) @{} +> @kbd{ print("Output failed:", ERRNO) > "/dev/stderr"} +> @kbd{ exit 1} +> @kbd{ @}} +> @kbd{@}'} +@error{} Output failed: No such file or directory +@end example + +Here, @command{gawk} did not produce a fatal error; instead +it let the @command{awk} program code detect the problem and handle it. + +This mechanism works also for standard output and standard error. +For standard output, you may use @code{PROCINFO["-", "NONFATAL"]} +or @code{PROCINFO["/dev/stdout", "NONFATAL"]}. For standard error, use +@code{PROCINFO["/dev/stderr", "NONFATAL"]}. + +When attempting to open a TCP/IP socket (@pxref{TCP/IP Networking}), +@command{gawk} tries multiple times. The @env{GAWK_SOCK_RETRIES} +environment variable (@pxref{Other Environment Variables}) allows you to +override @command{gawk}'s builtin default number of attempts. However, +once nonfatal I/O is enabled for a given socket, @command{gawk} only +retries once, relying on @command{awk}-level code to notice that there +was a problem. + @node Output Summary @section Summary @@ -9965,6 +10034,12 @@ Use @code{close()} to close open file, pipe, and coprocess redirections. For coprocesses, it is possible to close only one direction of the communications. +@item +Normally errors with @code{print} or @code{printf} are fatal. +@command{gawk} lets you make output errors be nonfatal either for +all files or on a per-file basis. You must then check for errors +after every relevant output statement. + @end itemize @c EXCLUDE START @@ -11332,6 +11407,9 @@ the string constant @code{"0"} is actually true, because it is non-null. @i{The Guide is definitive. Reality is frequently inaccurate.} @author Douglas Adams, @cite{The Hitchhiker's Guide to the Galaxy} @end quotation +@c 2/2015: Antonio Colombo points out that this is really from +@c The Restaurant at the End of the Universe. But I'm going to +@c leave it alone. @cindex comparison expressions @cindex expressions, comparison @@ -14790,7 +14868,7 @@ In most other languages, arrays must be @dfn{declared} before use, including a specification of how many elements or components they contain. In such languages, the declaration causes a contiguous block of memory to be allocated for that -many elements. Usually, an index in the array must be a positive integer. +many elements. Usually, an index in the array must be a nonnegative integer. For example, the index zero specifies the first element in the array, which is actually stored at the beginning of the block of memory. Index one specifies the second element, which is stored in memory right after the @@ -14970,7 +15048,7 @@ Now the array is @dfn{sparse}, which just means some indices are missing. It has elements 0--3 and 10, but doesn't have elements 4, 5, 6, 7, 8, or 9. Another consequence of associative arrays is that the indices don't -have to be positive integers. Any number, or even a string, can be +have to be nonnegative integers. Any number, or even a string, can be an index. For example, the following is an array that translates words from English to French: @@ -15233,7 +15311,7 @@ END @{ In programs that use arrays, it is often necessary to use a loop that executes once for each element of an array. In other languages, where -arrays are contiguous and indices are limited to positive integers, +arrays are contiguous and indices are limited to nonnegative integers, this is easy: all the valid indices can be found by counting from the lowest index up to the highest. This technique won't do the job in @command{awk}, because any number or string can be an array index. @@ -16355,7 +16433,7 @@ for generating random numbers to the value @var{x}. Each seed value leads to a particular sequence of random numbers.@footnote{Computer-generated random numbers really are not truly -random. They are technically known as ``pseudorandom.'' This means +random. They are technically known as @dfn{pseudorandom}. This means that although the numbers in a sequence appear to be random, you can in fact generate the same sequence of random numbers over and over again.} Thus, if the seed is set to the same value a second time, @@ -29300,8 +29378,8 @@ The disadvantage is that their range is limited. @cindex integers, unsigned In computers, integer values come in two flavors: @dfn{signed} and @dfn{unsigned}. Signed values may be negative or positive, whereas -unsigned values are always positive (i.e., greater than or equal -to zero). +unsigned values are always greater than or equal +to zero. In computer systems, integer arithmetic is exact, but the possible range of values is limited. Integer arithmetic is generally faster than @@ -34791,6 +34869,10 @@ Indirect function calls @item Directories on the command line produce a warning and are skipped (@pxref{Command-line directories}) + +@item +Output with @code{print} and @code{printf} need not be fatal +(@pxref{Nonfatal}) @end itemize @item @@ -35670,6 +35752,10 @@ is now two. @xref{Escape Sequences}. @item +Nonfatal output with @code{print} and @code{printf}. +@xref{Nonfatal}. + +@item Support for MirBSD was removed. @end itemize diff --git a/extension/ChangeLog b/extension/ChangeLog index 749871dc..9d7e6173 100644 --- a/extension/ChangeLog +++ b/extension/ChangeLog @@ -1,3 +1,9 @@ +2015-03-17 Arnold D. Robbins <arnold@skeeve.com> + + * inplace.c (do_inplace_begin): Jump through more hoops to satisfy + a newer version of clang. + * inplace.3am (BUGS): Add new section and documentation. + 2015-02-26 Arnold D. Robbins <arnold@skeeve.com> * Makefile.am (EXTRA_DIST): Add rwarray0.c to the list. diff --git a/extension/inplace.3am b/extension/inplace.3am index 5ca04be2..d6339c4a 100644 --- a/extension/inplace.3am +++ b/extension/inplace.3am @@ -1,4 +1,4 @@ -.TH INPLACE 3am "Jan 15 2013" "Free Software Foundation" "GNU Awk Extension Modules" +.TH INPLACE 3am "Mar 16 2015" "Free Software Foundation" "GNU Awk Extension Modules" .SH NAME inplace \- emulate sed/perl/ruby in-place editing .SH SYNOPSIS @@ -45,7 +45,10 @@ extension concatenates that suffix onto the original filename and uses the result as a filename for renaming the original. ... .SH NOTES -... .SH BUGS +.SH BUGS +As currently written, output from an \f(CWENDFILE\fP +rule does not get redirected into the replacement file. +Neither does output from an \f(CWEND\fP rule. .SH EXAMPLE .ft CW .nf diff --git a/extension/inplace.c b/extension/inplace.c index 0693ad92..e3685e30 100644 --- a/extension/inplace.c +++ b/extension/inplace.c @@ -171,10 +171,10 @@ do_inplace_begin(int nargs, awk_value_t *result) /* N.B. chown/chmod should be more portable than fchown/fchmod */ if (chown(state.tname, sbuf.st_uid, sbuf.st_gid) < 0) { - /* jumping through hoops to silence gcc. :-( */ + /* jumping through hoops to silence gcc and clang. :-( */ int junk; junk = chown(state.tname, -1, sbuf.st_gid); - junk = junk; + ++junk; } if (chmod(state.tname, sbuf.st_mode) < 0) @@ -261,7 +261,6 @@ struct recmatch { static int iop_close(IOBUF *iop); -struct redirect *redirect(NODE *redir_exp, int redirtype, int *errflg); static void close_one(void); static int close_redir(struct redirect *rp, bool exitwarn, two_way_close_type how); #ifndef PIPES_SIMULATED @@ -727,7 +726,7 @@ redflags2str(int flags) /* redirect --- Redirection for printf and print commands */ struct redirect * -redirect(NODE *redir_exp, int redirtype, int *errflg) +redirect(NODE *redir_exp, int redirtype, int *errflg, bool failure_fatal) { struct redirect *rp; char *str; @@ -892,6 +891,12 @@ redirect(NODE *redir_exp, int redirtype, int *errflg) (void) flush_io(); os_restore_mode(fileno(stdin)); + /* + * Don't check failure_fatal; see input pipe below. + * Note that the failure happens upon failure to fork, + * using a non-existant program will still succeed the + * popen(). + */ if ((rp->output.fp = popen(str, binmode("w"))) == NULL) fatal(_("can't open pipe `%s' for output (%s)"), str, strerror(errno)); @@ -927,13 +932,11 @@ redirect(NODE *redir_exp, int redirtype, int *errflg) case redirect_twoway: direction = "to/from"; if (! two_way_open(str, rp)) { -#ifdef HAVE_SOCKETS - if (inetfile(str, NULL)) { + if (! failure_fatal || is_non_fatal_redirect(str)) { *errflg = errno; /* do not free rp, saving it for reuse (save_rp = rp) */ return NULL; } else -#endif fatal(_("can't open two way pipe `%s' for input/output (%s)"), str, strerror(errno)); } @@ -1009,11 +1012,14 @@ redirect(NODE *redir_exp, int redirtype, int *errflg) * can return -1. For output to file, * complain. The shell will complain on * a bad command to a pipe. + * + * 12/2014: Take nonfatal settings in PROCINFO into account. */ if (errflg != NULL) *errflg = errno; - if ( redirtype == redirect_output - || redirtype == redirect_append) { + if (failure_fatal && ! is_non_fatal_redirect(str) && + (redirtype == redirect_output + || redirtype == redirect_append)) { /* multiple messages make life easier for translators */ if (*direction == 'f') fatal(_("can't redirect from `%s' (%s)"), @@ -1058,6 +1064,36 @@ getredirect(const char *str, int len) return NULL; } +/* is_non_fatal_std --- return true if fp is stdout/stderr and nonfatal */ + +bool +is_non_fatal_std(FILE *fp) +{ + static const char nonfatal[] = "NONFATAL"; + + if (in_PROCINFO(nonfatal, NULL, NULL)) + return true; + + /* yucky logic. sigh. */ + if (fp == stdout) { + return ( in_PROCINFO("-", nonfatal, NULL) != NULL + || in_PROCINFO("/dev/stdout", nonfatal, NULL) != NULL); + } else if (fp == stderr) { + return (in_PROCINFO("/dev/stderr", nonfatal, NULL) != NULL); + } + + return false; +} + +/* is_non_fatal_redirect --- return true if redirected I/O should be nonfatal */ + +bool +is_non_fatal_redirect(const char *str) +{ + return in_PROCINFO("NONFATAL", NULL, NULL) != NULL + || in_PROCINFO(str, "NONFATAL", NULL) != NULL; +} + /* close_one --- temporarily close an open file to re-use the fd */ static void @@ -1430,7 +1466,7 @@ str2mode(const char *mode) static int socketopen(int family, int type, const char *localpname, - const char *remotepname, const char *remotehostname) + const char *remotepname, const char *remotehostname, bool *hard_error) { struct addrinfo *lres, *lres0; struct addrinfo lhints; @@ -1449,8 +1485,11 @@ socketopen(int family, int type, const char *localpname, lerror = getaddrinfo(NULL, localpname, & lhints, & lres); if (lerror) { - if (strcmp(localpname, "0") != 0) - fatal(_("local port %s invalid in `/inet'"), localpname); + if (strcmp(localpname, "0") != 0) { + warning(_("local port %s invalid in `/inet'"), localpname); + *hard_error = true; + return INVALID_HANDLE; + } lres0 = NULL; lres = & lhints; } else @@ -1468,7 +1507,9 @@ socketopen(int family, int type, const char *localpname, if (rerror) { if (lres0 != NULL) freeaddrinfo(lres0); - fatal(_("remote host and port information (%s, %s) invalid"), remotehostname, remotepname); + warning(_("remote host and port information (%s, %s) invalid"), remotehostname, remotepname); + *hard_error = true; + return INVALID_HANDLE; } rres0 = rres; socket_fd = INVALID_HANDLE; @@ -1577,6 +1618,7 @@ devopen(const char *name, const char *mode) char *ptr; int flag = 0; struct inet_socket_info isi; + int save_errno = 0; if (strcmp(name, "-") == 0) return fileno(stdin); @@ -1619,6 +1661,14 @@ devopen(const char *name, const char *mode) goto strictopen; } else if (inetfile(name, & isi)) { #ifdef HAVE_SOCKETS +#define DEFAULT_RETRIES 20 + static unsigned long def_retries = DEFAULT_RETRIES; + static bool first_time = true; + unsigned long retries = 0; + static long msleep = 1000; + bool hard_error = false; + bool non_fatal = is_non_fatal_redirect(name); + cp = (char *) name; /* socketopen requires NUL-terminated strings */ @@ -1626,13 +1676,6 @@ devopen(const char *name, const char *mode) cp[isi.remotehost.offset+isi.remotehost.len] = '\0'; /* remoteport comes last, so already NUL-terminated */ - { -#define DEFAULT_RETRIES 20 - static unsigned long def_retries = DEFAULT_RETRIES; - static bool first_time = true; - unsigned long retries = 0; - static long msleep = 1000; - if (first_time) { char *cp, *end; unsigned long count = 0; @@ -1658,25 +1701,41 @@ devopen(const char *name, const char *mode) msleep *= 1000; } } - retries = def_retries; + /* + * PROCINFO["NONFATAL"] or PROCINFO[name, "NONFATAL"] overrrides + * GAWK_SOCK_RETRIES. The explicit code in the program carries + * a bigger stick than the environment variable does. + */ + retries = non_fatal ? 1 : def_retries; + errno = 0; do { - openfd = socketopen(isi.family, isi.protocol, name+isi.localport.offset, name+isi.remoteport.offset, name+isi.remotehost.offset); + openfd = socketopen(isi.family, isi.protocol, name+isi.localport.offset, + name+isi.remoteport.offset, name+isi.remotehost.offset, + & hard_error); retries--; - } while (openfd == INVALID_HANDLE && retries > 0 && usleep(msleep) == 0); - } + } while (openfd == INVALID_HANDLE && ! hard_error && retries > 0 && usleep(msleep) == 0); + save_errno = errno; - /* restore original name string */ - cp[isi.localport.offset+isi.localport.len] = '/'; - cp[isi.remotehost.offset+isi.remotehost.len] = '/'; + /* restore original name string */ + cp[isi.localport.offset+isi.localport.len] = '/'; + cp[isi.remotehost.offset+isi.remotehost.len] = '/'; #else /* ! HAVE_SOCKETS */ - fatal(_("TCP/IP communications are not supported")); + fatal(_("TCP/IP communications are not supported")); #endif /* HAVE_SOCKETS */ } strictopen: - if (openfd == INVALID_HANDLE) + if (openfd == INVALID_HANDLE) { openfd = open(name, flag, 0666); + /* + * ENOENT means there is no such name in the filesystem. + * Therefore it's ok to propagate up the error from + * getaddrinfo() that's in save_errno. + */ + if (openfd == INVALID_HANDLE && errno == ENOENT && save_errno) + errno = save_errno; + } #if defined(__EMX__) || defined(__MINGW32__) if (openfd == INVALID_HANDLE && errno == EACCES) { /* On OS/2 and Windows directory access via open() is @@ -2421,7 +2480,7 @@ do_getline_redir(int into_variable, enum redirval redirtype) assert(redirtype != redirect_none); redir_exp = TOP(); - rp = redirect(redir_exp, redirtype, & redir_error); + rp = redirect(redir_exp, redirtype, & redir_error, false); DEREF(redir_exp); decr_sp(); if (rp == NULL) { @@ -3656,8 +3715,10 @@ pty_vs_pipe(const char *command) #ifdef HAVE_TERMIOS_H NODE *val; - if (PROCINFO_node == NULL) - return false; + /* + * N.B. No need to check for NULL PROCINFO_node, since the + * in_PROCINFO function now checks that for us. + */ val = in_PROCINFO(command, "pty", NULL); if (val) { if ((val->flags & MAYBE_NUM) != 0) @@ -3799,12 +3860,21 @@ in_PROCINFO(const char *pidx1, const char *pidx2, NODE **full_idx) NODE *r, *sub = NULL; NODE *subsep = SUBSEP_node->var_value; + if (PROCINFO_node == NULL || (pidx1 == NULL && pidx2 == NULL)) + return NULL; + /* full_idx is in+out parameter */ if (full_idx) sub = *full_idx; - str_len = strlen(pidx1) + subsep->stlen + strlen(pidx2); + if (pidx1 != NULL && pidx2 == NULL) + str_len = strlen(pidx1); + else if (pidx1 == NULL && pidx2 != NULL) + str_len = strlen(pidx2); + else + str_len = strlen(pidx1) + subsep->stlen + strlen(pidx2); + if (sub == NULL) { emalloc(str, char *, str_len + 1, "in_PROCINFO"); sub = make_str_node(str, str_len, ALREADY_MALLOCED); @@ -3818,8 +3888,14 @@ in_PROCINFO(const char *pidx1, const char *pidx2, NODE **full_idx) sub->stlen = str_len; } - sprintf(sub->stptr, "%s%.*s%s", pidx1, (int)subsep->stlen, - subsep->stptr, pidx2); + if (pidx1 != NULL && pidx2 == NULL) + strcpy(sub->stptr, pidx1); + else if (pidx1 == NULL && pidx2 != NULL) + strcpy(sub->stptr, pidx2); + else + sprintf(sub->stptr, "%s%.*s%s", pidx1, (int)subsep->stlen, + subsep->stptr, pidx2); + r = in_array(PROCINFO_node, sub); if (! full_idx) unref(sub); diff --git a/missing_d/ChangeLog b/missing_d/ChangeLog index 70fbde64..89dbdb4d 100644 --- a/missing_d/ChangeLog +++ b/missing_d/ChangeLog @@ -1,3 +1,9 @@ +2015-02-27 Arnold D. Robbins <arnold@skeeve.com> + + * getaddrinfo.h (gai_strerror): Add declaration. + * getaddrinfo.c (gai_strerror): New function. + (getaddrinfo): Return errno values instead of just -1. + 2014-04-08 Arnold D. Robbins <arnold@skeeve.com> * 4.1.1: Release tar ball made. diff --git a/missing_d/getaddrinfo.c b/missing_d/getaddrinfo.c index 677f27d0..f24ac598 100644 --- a/missing_d/getaddrinfo.c +++ b/missing_d/getaddrinfo.c @@ -12,6 +12,8 @@ #ifdef HAVE_ARPA_INET_H #include <arpa/inet.h> #endif +#include <errno.h> +#include <string.h> /* strerror */ #include "getaddrinfo.h" @@ -29,12 +31,12 @@ getaddrinfo(const char *hostname, const char *portname, { struct addrinfo *out; if (res == NULL) - return -1; + return EINVAL; out = (struct addrinfo *) malloc(sizeof(*out)); if (out == NULL) { *res = NULL; - return -1; + return ENOMEM; } memset(out, '\0', sizeof(*out)); @@ -42,7 +44,7 @@ getaddrinfo(const char *hostname, const char *portname, if (out->ai_addr == NULL) { free(out); *res = NULL; - return -1; + return ENOMEM; } out->ai_socktype = SOCK_STREAM; @@ -78,7 +80,7 @@ getaddrinfo(const char *hostname, const char *portname, = ((struct in_addr *)he->h_addr_list[0])->s_addr; } else { freeaddrinfo(out); - return -1; + return EADDRNOTAVAIL; } } else { if (!(out->ai_flags & AI_PASSIVE)) @@ -109,4 +111,10 @@ getaddrinfo(const char *hostname, const char *portname, return 0; } + +const char * +gai_strerror(int errcode) +{ + return strerror(errcode); +} #endif diff --git a/missing_d/getaddrinfo.h b/missing_d/getaddrinfo.h index 3d816c93..873d67df 100644 --- a/missing_d/getaddrinfo.h +++ b/missing_d/getaddrinfo.h @@ -29,3 +29,5 @@ void freeaddrinfo(struct xaddrinfo * res); int getaddrinfo(const char * hostname, const char * portname, struct xaddrinfo * hints, struct xaddrinfo ** res); + +const char *gai_strerror(int errcode); @@ -1390,16 +1390,30 @@ pp_number(NODE *n) { #define PP_PRECISION 6 char *str; + size_t count; - emalloc(str, char *, PP_PRECISION + 10, "pp_number"); #ifdef HAVE_MPFR - if (is_mpg_float(n)) - mpfr_sprintf(str, "%0.*R*g", PP_PRECISION, ROUND_MODE, n->mpg_numbr); - else if (is_mpg_integer(n)) + if (is_mpg_float(n)) { + count = mpfr_get_prec(n->mpg_numbr) / 3; /* ~ 3.22 binary digits per decimal digit */ + emalloc(str, char *, count, "pp_number"); + /* + * 3/2015: Format string used to be "%0.*R*g". That padded + * with leading zeros. But it doesn't do that for regular + * numbers in the non-MPFR case. + */ + mpfr_sprintf(str, "%.*R*g", PP_PRECISION, ROUND_MODE, n->mpg_numbr); + } else if (is_mpg_integer(n)) { + count = mpz_sizeinbase(n->mpg_i, 10) + 2; /* +1 for sign, +1 for NUL at end */ + emalloc(str, char *, count, "pp_number"); mpfr_sprintf(str, "%Zd", n->mpg_i); - else + } else #endif - sprintf(str, "%0.*g", PP_PRECISION, n->numbr); + { + count = PP_PRECISION + 10; + emalloc(str, char *, count, "pp_number"); + sprintf(str, "%0.*g", PP_PRECISION, n->numbr); + } + return str; #undef PP_PRECISION } @@ -616,40 +616,3 @@ again: done: s[length] = save; } - -/* regexflags2str --- make regex flags printable */ - -const char * -regexflags2str(int flags) -{ - static const struct flagtab regextab[] = { - { RE_BACKSLASH_ESCAPE_IN_LISTS, "RE_BACKSLASH_ESCAPE_IN_LISTS" }, - { RE_BK_PLUS_QM, "RE_BK_PLUS_QM" }, - { RE_CHAR_CLASSES, "RE_CHAR_CLASSES" }, - { RE_CONTEXT_INDEP_ANCHORS, "RE_CONTEXT_INDEP_ANCHORS" }, - { RE_CONTEXT_INDEP_OPS, "RE_CONTEXT_INDEP_OPS" }, - { RE_CONTEXT_INVALID_OPS, "RE_CONTEXT_INVALID_OPS" }, - { RE_DOT_NEWLINE, "RE_DOT_NEWLINE" }, - { RE_DOT_NOT_NULL, "RE_DOT_NOT_NULL" }, - { RE_HAT_LISTS_NOT_NEWLINE, "RE_HAT_LISTS_NOT_NEWLINE" }, - { RE_INTERVALS, "RE_INTERVALS" }, - { RE_LIMITED_OPS, "RE_LIMITED_OPS" }, - { RE_NEWLINE_ALT, "RE_NEWLINE_ALT" }, - { RE_NO_BK_BRACES, "RE_NO_BK_BRACES" }, - { RE_NO_BK_PARENS, "RE_NO_BK_PARENS" }, - { RE_NO_BK_REFS, "RE_NO_BK_REFS" }, - { RE_NO_BK_VBAR, "RE_NO_BK_VBAR" }, - { RE_NO_EMPTY_RANGES, "RE_NO_EMPTY_RANGES" }, - { RE_UNMATCHED_RIGHT_PAREN_ORD, "RE_UNMATCHED_RIGHT_PAREN_ORD" }, - { RE_NO_POSIX_BACKTRACKING, "RE_NO_POSIX_BACKTRACKING" }, - { RE_NO_GNU_OPS, "RE_NO_GNU_OPS" }, - { RE_DEBUG, "RE_DEBUG" }, - { RE_INVALID_INTERVAL_ORD, "RE_INVALID_INTERVAL_ORD" }, - { RE_ICASE, "RE_ICASE" }, - { RE_CARET_ANCHORS_HERE, "RE_CARET_ANCHORS_HERE" }, - { RE_CONTEXT_INVALID_DUP, "RE_CONTEXT_INVALID_DUP" }, - { 0, NULL } - }; - - return genflags2str(flags, regextab); -} @@ -642,7 +642,7 @@ check_param_names(void) max = func_table->table_size * 2; - memset(& n, sizeof n, 0); + memset(& n, 0, sizeof n); n.type = Node_val; n.flags = STRING|STRCUR; n.stfmt = -1; diff --git a/test/ChangeLog b/test/ChangeLog index 4cd06f03..5d9ba8d0 100644 --- a/test/ChangeLog +++ b/test/ChangeLog @@ -1,5 +1,43 @@ +2015-03-17 Arnold D. Robbins <arnold@skeeve.com> + + * Makefile.am (mpfrmemok1): New test. + * mpfrmemok1.awk, mpfrmemok1.ok: New files. + +2015-03-10 Arnold D. Robbins <arnold@skeeve.com> + + * Makefile.am (fpat4): New test. + * fpat4.awk, fpat4.ok: New files. + +2015-03-08 Arnold D. Robbins <arnold@skeeve.com> + + * nonfatal3.awk, nonfatal3.ok: Adjust for portability. + Thanks to Hermann Peifer for the report. + +2015-03-06 Arnold D. Robbins <arnold@skeeve.com> + + * charasbytes.awk, ofs1.awk, range1.awk, sortglos.awk, + sortglos.in: Remove execute permission. + +2015-03-02 Andrew J. Schorr <aschorr@telemetry-investments.com> + + * nonfatal1.awk: Do not print ERRNO, since the value appears to be + platform-dependent. Instead, print (ERRNO != ""). + * nonfatal1.ok: Update. + +2015-02-28 Andrew J. Schorr <aschorr@telemetry-investments.com> + + * Makefile.am (EXTRA_DIST): Add nonfatal3.{awk,ok}. + (GAWK_EXT_TESTS): Add nonfatal3. + * nonfatal1.awk: Replace "ti10/357" with "local:host/25", since + "local:host" should be a universally bad hostname due to the + invalid ":" character. + * nonfatal1.ok: Update. + * nonfatal3.{awk,ok}: New test for connecting to a TCP port where + nobody is listening. + 2015-02-27 Arnold D. Robbins <arnold@skeeve.com> + * nonfatal1.ok: Update after code changes. * id.ok: Updated after code change. 2015-02-26 Arnold D. Robbins <arnold@skeeve.com> @@ -17,6 +55,16 @@ * Makefile.am (profile0): New test. * profile0.awk, profile0.in, profile0.ok: New files. +2015-02-08 Arnold D. Robbins <arnold@skeeve.com> + + * nonfatal1.awk, nonfatal2.awk: String is now "NONFATAL". + +2015-02-06 Arnold D. Robbins <arnold@skeeve.com> + + * Makefile.am (nonfatal1, nonfatal2): New tests. + * nonfatal1.awk, nonfatal1.ok: New files. + * nonfatal2.awk, nonfatal2.ok: New files. + 2015-02-01 Arnold D. Robbins <arnold@skeeve.com> * Makefile.am (paramasfunc1, paramasfunc2): Now need --posix. diff --git a/test/Makefile.am b/test/Makefile.am index e752865a..d2cd0ddd 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -285,6 +285,8 @@ EXTRA_DIST = \ fpat3.awk \ fpat3.in \ fpat3.ok \ + fpat4.awk \ + fpat4.ok \ fpatnull.awk \ fpatnull.in \ fpatnull.ok \ @@ -535,6 +537,8 @@ EXTRA_DIST = \ mpfrexprange.ok \ mpfrieee.awk \ mpfrieee.ok \ + mpfrmemok1.awk \ + mpfrmemok1.ok \ mpfrnegzero.awk \ mpfrnegzero.ok \ mpfrnr.awk \ @@ -599,6 +603,12 @@ EXTRA_DIST = \ nondec.ok \ nondec2.awk \ nondec2.ok \ + nonfatal1.awk \ + nonfatal1.ok \ + nonfatal2.awk \ + nonfatal2.ok \ + nonfatal3.awk \ + nonfatal3.ok \ nonl.awk \ nonl.ok \ noparms.awk \ @@ -1038,7 +1048,7 @@ GAWK_EXT_TESTS = \ aadelete1 aadelete2 aarray1 aasort aasorti argtest arraysort \ backw badargs beginfile1 beginfile2 binmode1 charasbytes \ colonwarn clos1way crlf dbugeval delsub devfd devfd1 devfd2 dumpvars exit \ - fieldwdth fpat1 fpat2 fpat3 fpatnull fsfwfs funlen \ + fieldwdth fpat1 fpat2 fpat3 fpat4 fpatnull fsfwfs funlen \ functab1 functab2 functab3 fwtest fwtest2 fwtest3 \ genpot gensub gensub2 getlndir gnuops2 gnuops3 gnureops \ icasefs icasers id igncdym igncfs ignrcas2 ignrcase \ @@ -1047,6 +1057,7 @@ GAWK_EXT_TESTS = \ lint lintold lintwarn \ manyfiles match1 match2 match3 mbstr1 \ nastyparm next nondec nondec2 \ + nonfatal1 nonfatal2 nonfatal3 \ patsplit posix printfbad1 printfbad2 printfbad3 printfbad4 printhuge procinfs \ profile0 profile1 profile2 profile3 profile4 profile5 profile6 profile7 \ profile8 pty1 \ @@ -1062,8 +1073,8 @@ INET_TESTS = inetdayu inetdayt inetechu inetecht MACHINE_TESTS = double1 double2 fmtspcl intformat -MPFR_TESTS = mpfrnr mpfrnegzero mpfrrem mpfrrnd mpfrieee mpfrexprange \ - mpfrsort mpfrsqrt mpfrbigint +MPFR_TESTS = mpfrnr mpfrnegzero mpfrmemok1 mpfrrem mpfrrnd mpfrieee \ + mpfrexprange mpfrsort mpfrsqrt mpfrbigint LOCALE_CHARSET_TESTS = \ asort asorti backbigs1 backsmalls1 backsmalls2 \ @@ -1819,6 +1830,11 @@ mpfrrem: @$(AWK) -M -f "$(srcdir)"/$@.awk > _$@ 2>&1 @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ +mpfrmemok1: + @echo $@ + @$(AWK) -p/dev/stdout -M -f "$(srcdir)"/$@.awk 2>&1 | sed 1d > _$@ + @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ + jarebug:: @echo $@ @"$(srcdir)"/$@.sh "$(AWKPROG)" "$(srcdir)"/$@.awk "$(srcdir)"/$@.in "_$@" diff --git a/test/Makefile.in b/test/Makefile.in index 0c00973c..cf8093b8 100644 --- a/test/Makefile.in +++ b/test/Makefile.in @@ -542,6 +542,8 @@ EXTRA_DIST = \ fpat3.awk \ fpat3.in \ fpat3.ok \ + fpat4.awk \ + fpat4.ok \ fpatnull.awk \ fpatnull.in \ fpatnull.ok \ @@ -792,6 +794,8 @@ EXTRA_DIST = \ mpfrexprange.ok \ mpfrieee.awk \ mpfrieee.ok \ + mpfrmemok1.awk \ + mpfrmemok1.ok \ mpfrnegzero.awk \ mpfrnegzero.ok \ mpfrnr.awk \ @@ -856,6 +860,12 @@ EXTRA_DIST = \ nondec.ok \ nondec2.awk \ nondec2.ok \ + nonfatal1.awk \ + nonfatal1.ok \ + nonfatal2.awk \ + nonfatal2.ok \ + nonfatal3.awk \ + nonfatal3.ok \ nonl.awk \ nonl.ok \ noparms.awk \ @@ -1294,7 +1304,7 @@ GAWK_EXT_TESTS = \ aadelete1 aadelete2 aarray1 aasort aasorti argtest arraysort \ backw badargs beginfile1 beginfile2 binmode1 charasbytes \ colonwarn clos1way crlf dbugeval delsub devfd devfd1 devfd2 dumpvars exit \ - fieldwdth fpat1 fpat2 fpat3 fpatnull fsfwfs funlen \ + fieldwdth fpat1 fpat2 fpat3 fpat4 fpatnull fsfwfs funlen \ functab1 functab2 functab3 fwtest fwtest2 fwtest3 \ genpot gensub gensub2 getlndir gnuops2 gnuops3 gnureops \ icasefs icasers id igncdym igncfs ignrcas2 ignrcase \ @@ -1303,6 +1313,7 @@ GAWK_EXT_TESTS = \ lint lintold lintwarn \ manyfiles match1 match2 match3 mbstr1 \ nastyparm next nondec nondec2 \ + nonfatal1 nonfatal2 nonfatal3 \ patsplit posix printfbad1 printfbad2 printfbad3 printfbad4 printhuge procinfs \ profile0 profile1 profile2 profile3 profile4 profile5 profile6 profile7 \ profile8 pty1 \ @@ -1315,8 +1326,8 @@ GAWK_EXT_TESTS = \ EXTRA_TESTS = inftest regtest INET_TESTS = inetdayu inetdayt inetechu inetecht MACHINE_TESTS = double1 double2 fmtspcl intformat -MPFR_TESTS = mpfrnr mpfrnegzero mpfrrem mpfrrnd mpfrieee mpfrexprange \ - mpfrsort mpfrsqrt mpfrbigint +MPFR_TESTS = mpfrnr mpfrnegzero mpfrmemok1 mpfrrem mpfrrnd mpfrieee \ + mpfrexprange mpfrsort mpfrsqrt mpfrbigint LOCALE_CHARSET_TESTS = \ asort asorti backbigs1 backsmalls1 backsmalls2 \ @@ -2256,6 +2267,11 @@ mpfrrem: @$(AWK) -M -f "$(srcdir)"/$@.awk > _$@ 2>&1 @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ +mpfrmemok1: + @echo $@ + @$(AWK) -p/dev/stdout -M -f "$(srcdir)"/$@.awk 2>&1 | sed 1d > _$@ + @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ + jarebug:: @echo $@ @"$(srcdir)"/$@.sh "$(AWKPROG)" "$(srcdir)"/$@.awk "$(srcdir)"/$@.in "_$@" @@ -3476,6 +3492,11 @@ fpat3: @AWKPATH="$(srcdir)" $(AWK) -f $@.awk < "$(srcdir)"/$@.in >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ +fpat4: + @echo $@ + @AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ + @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ + fpatnull: @echo $@ @AWKPATH="$(srcdir)" $(AWK) -f $@.awk < "$(srcdir)"/$@.in >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ @@ -3636,6 +3657,21 @@ nondec: @AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ +nonfatal1: + @echo $@ + @AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ + @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ + +nonfatal2: + @echo $@ + @AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ + @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ + +nonfatal3: + @echo $@ + @AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ + @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ + patsplit: @echo $@ @AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ diff --git a/test/Maketests b/test/Maketests index adf95cc5..5011fb1f 100644 --- a/test/Maketests +++ b/test/Maketests @@ -992,6 +992,11 @@ fpat3: @AWKPATH="$(srcdir)" $(AWK) -f $@.awk < "$(srcdir)"/$@.in >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ +fpat4: + @echo $@ + @AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ + @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ + fpatnull: @echo $@ @AWKPATH="$(srcdir)" $(AWK) -f $@.awk < "$(srcdir)"/$@.in >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ @@ -1152,6 +1157,21 @@ nondec: @AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ +nonfatal1: + @echo $@ + @AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ + @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ + +nonfatal2: + @echo $@ + @AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ + @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ + +nonfatal3: + @echo $@ + @AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ + @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ + patsplit: @echo $@ @AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ diff --git a/test/charasbytes.awk b/test/charasbytes.awk index feb195c8..feb195c8 100755..100644 --- a/test/charasbytes.awk +++ b/test/charasbytes.awk diff --git a/test/fpat4.awk b/test/fpat4.awk new file mode 100644 index 00000000..79cd6a7f --- /dev/null +++ b/test/fpat4.awk @@ -0,0 +1,105 @@ +BEGIN { + false = 0 + true = 1 + + fpat[1] = "([^,]*)|(\"[^\"]+\")" + fpat[2] = fpat[1] + fpat[3] = fpat[1] + fpat[4] = "aa+" + fpat[5] = fpat[4] + fpat[6] = "[a-z]" + + data[1] = "Robbins,,Arnold," + data[2] = "Smith,,\"1234 A Pretty Place, NE\",Sometown,NY,12345-6789,USA" + data[3] = "Robbins,Arnold,\"1234 A Pretty Place, NE\",Sometown,NY,12345-6789,USA" + data[4] = "bbbaaacccdddaaaaaqqqq" + data[5] = "bbbaaacccdddaaaaaqqqqa" # should get trailing qqqa + data[6] = "aAbBcC" + + for (i = 1; i in data; i++) { + printf("Splitting: <%s>\n", data[i]) + n = mypatsplit(data[i], fields, fpat[i], seps) + m = patsplit(data[i], fields2, fpat[i], seps2) + print "n =", n, "m =", m + if (n != m) { + printf("ERROR: counts wrong!\n") > "/dev/stderr" + exit 1 + } + for (j = 1; j <= n; j++) { + printf("fields[%d] = <%s>\tfields2[%d] = <%s>\n", j, fields[j], j, fields2[j]) + if (fields[j] != fields2[j]) { + printf("ERROR: data %d, field %d mismatch!\n", i, j) > "/dev/stderr" + exit 1 + } + } + for (j = 0; j in seps; j++) { + printf("seps[%d] = <%s>\tseps2[%d] = <%s>\n", j, seps[j], j, seps2[j]) + if (seps[j] != seps2[j]) { + printf("ERROR: data %d, separator %d mismatch!\n", i, j) > "/dev/stderr" + exit 1 + } + } + } +} + +function mypatsplit(string, array, pattern, seps, + eosflag, non_empty, nf) # locals +{ + delete array + delete seps + if (length(string) == 0) + return 0 + + eosflag = non_empty = false + nf = 0 + while (match(string, pattern)) { + if (RLENGTH > 0) { # easy case + non_empty = true + if (! (nf in seps)) { + if (RSTART == 1) # match at front of string + seps[nf] = "" + else + seps[nf] = substr(string, 1, RSTART - 1) + } + array[++nf] = substr(string, RSTART, RLENGTH) + string = substr(string, RSTART+RLENGTH) + if (length(string) == 0) + break + } else if (non_empty) { + # last match was non-empty, and at the + # current character we get a zero length match, + # which we don't want, so skip over it + non_empty = false + seps[nf] = substr(string, 1, 1) + string = substr(string, 2) + } else { + # 0 length match + if (! (nf in seps)) { + if (RSTART == 1) + seps[nf] = "" + else + seps[nf] = substr(string, 1, RSTART - 1) + } + array[++nf] = "" + if (! non_empty && ! eosflag) { # prev was empty + seps[nf] = substr(string, 1, 1) + } + if (RSTART == 1) { + string = substr(string, 2) + } else { + string = substr(string, RSTART + 1) + } + non_empty = false + } + if (length(string) == 0) { + if (eosflag) + break + else + eosflag = true + } + } + if (length(string) > 0) + seps[nf] = string + + return length(array) +} diff --git a/test/fpat4.ok b/test/fpat4.ok new file mode 100644 index 00000000..b4430aba --- /dev/null +++ b/test/fpat4.ok @@ -0,0 +1,65 @@ +Splitting: <Robbins,,Arnold,> +n = 4 m = 4 +fields[1] = <Robbins> fields2[1] = <Robbins> +fields[2] = <> fields2[2] = <> +fields[3] = <Arnold> fields2[3] = <Arnold> +fields[4] = <> fields2[4] = <> +seps[0] = <> seps2[0] = <> +seps[1] = <,> seps2[1] = <,> +seps[2] = <,> seps2[2] = <,> +seps[3] = <,> seps2[3] = <,> +Splitting: <Smith,,"1234 A Pretty Place, NE",Sometown,NY,12345-6789,USA> +n = 7 m = 7 +fields[1] = <Smith> fields2[1] = <Smith> +fields[2] = <> fields2[2] = <> +fields[3] = <"1234 A Pretty Place, NE"> fields2[3] = <"1234 A Pretty Place, NE"> +fields[4] = <Sometown> fields2[4] = <Sometown> +fields[5] = <NY> fields2[5] = <NY> +fields[6] = <12345-6789> fields2[6] = <12345-6789> +fields[7] = <USA> fields2[7] = <USA> +seps[0] = <> seps2[0] = <> +seps[1] = <,> seps2[1] = <,> +seps[2] = <,> seps2[2] = <,> +seps[3] = <,> seps2[3] = <,> +seps[4] = <,> seps2[4] = <,> +seps[5] = <,> seps2[5] = <,> +seps[6] = <,> seps2[6] = <,> +Splitting: <Robbins,Arnold,"1234 A Pretty Place, NE",Sometown,NY,12345-6789,USA> +n = 7 m = 7 +fields[1] = <Robbins> fields2[1] = <Robbins> +fields[2] = <Arnold> fields2[2] = <Arnold> +fields[3] = <"1234 A Pretty Place, NE"> fields2[3] = <"1234 A Pretty Place, NE"> +fields[4] = <Sometown> fields2[4] = <Sometown> +fields[5] = <NY> fields2[5] = <NY> +fields[6] = <12345-6789> fields2[6] = <12345-6789> +fields[7] = <USA> fields2[7] = <USA> +seps[0] = <> seps2[0] = <> +seps[1] = <,> seps2[1] = <,> +seps[2] = <,> seps2[2] = <,> +seps[3] = <,> seps2[3] = <,> +seps[4] = <,> seps2[4] = <,> +seps[5] = <,> seps2[5] = <,> +seps[6] = <,> seps2[6] = <,> +Splitting: <bbbaaacccdddaaaaaqqqq> +n = 2 m = 2 +fields[1] = <aaa> fields2[1] = <aaa> +fields[2] = <aaaaa> fields2[2] = <aaaaa> +seps[0] = <bbb> seps2[0] = <bbb> +seps[1] = <cccddd> seps2[1] = <cccddd> +seps[2] = <qqqq> seps2[2] = <qqqq> +Splitting: <bbbaaacccdddaaaaaqqqqa> +n = 2 m = 2 +fields[1] = <aaa> fields2[1] = <aaa> +fields[2] = <aaaaa> fields2[2] = <aaaaa> +seps[0] = <bbb> seps2[0] = <bbb> +seps[1] = <cccddd> seps2[1] = <cccddd> +seps[2] = <qqqqa> seps2[2] = <qqqqa> +Splitting: <aAbBcC> +n = 3 m = 3 +fields[1] = <a> fields2[1] = <a> +fields[2] = <b> fields2[2] = <b> +fields[3] = <c> fields2[3] = <c> +seps[0] = <> seps2[0] = <> +seps[1] = <A> seps2[1] = <A> +seps[2] = <B> seps2[2] = <B> +seps[3] = <C> seps2[3] = <C> diff --git a/test/mpfrmemok1.awk b/test/mpfrmemok1.awk new file mode 100644 index 00000000..9331a34d --- /dev/null +++ b/test/mpfrmemok1.awk @@ -0,0 +1,7 @@ +# This program tests that -M works with profiling. +# It does not do anything real, but there should not be glibc memory +# errors and it should be valgrind-clean too. + +BEGIN { + v = 0x0100000000000000000000000000000000 +} diff --git a/test/mpfrmemok1.ok b/test/mpfrmemok1.ok new file mode 100644 index 00000000..2389a2d5 --- /dev/null +++ b/test/mpfrmemok1.ok @@ -0,0 +1,7 @@ + + # BEGIN rule(s) + + BEGIN { + 1 v = 340282366920938463463374607431768211456 + } + diff --git a/test/nonfatal1.awk b/test/nonfatal1.awk new file mode 100644 index 00000000..a9228f3a --- /dev/null +++ b/test/nonfatal1.awk @@ -0,0 +1,6 @@ +BEGIN { + PROCINFO["NONFATAL"] + # note that ":" is not a valid hostname character + print |& "/inet/tcp/0/local:host/25" + print (ERRNO != "") +} diff --git a/test/nonfatal1.ok b/test/nonfatal1.ok new file mode 100644 index 00000000..51583f2c --- /dev/null +++ b/test/nonfatal1.ok @@ -0,0 +1,2 @@ +gawk: nonfatal1.awk:4: warning: remote host and port information (local:host, 25) invalid +1 diff --git a/test/nonfatal2.awk b/test/nonfatal2.awk new file mode 100644 index 00000000..fedbba43 --- /dev/null +++ b/test/nonfatal2.awk @@ -0,0 +1,5 @@ +BEGIN { + PROCINFO["NONFATAL"] = 1 + print > "/dev/no/such/file" + print ERRNO +} diff --git a/test/nonfatal2.ok b/test/nonfatal2.ok new file mode 100644 index 00000000..ddc88691 --- /dev/null +++ b/test/nonfatal2.ok @@ -0,0 +1 @@ +No such file or directory diff --git a/test/nonfatal3.awk b/test/nonfatal3.awk new file mode 100644 index 00000000..b2a4ec9e --- /dev/null +++ b/test/nonfatal3.awk @@ -0,0 +1,6 @@ +BEGIN { + PROCINFO["NONFATAL"] + # valid host but bogus port + print |& "/inet/tcp/0/localhost/0" + print ERRNO != "" +} diff --git a/test/nonfatal3.ok b/test/nonfatal3.ok new file mode 100644 index 00000000..d00491fd --- /dev/null +++ b/test/nonfatal3.ok @@ -0,0 +1 @@ +1 diff --git a/test/ofs1.awk b/test/ofs1.awk index 83b3c2a5..83b3c2a5 100755..100644 --- a/test/ofs1.awk +++ b/test/ofs1.awk diff --git a/test/range1.awk b/test/range1.awk index aca5db50..aca5db50 100755..100644 --- a/test/range1.awk +++ b/test/range1.awk diff --git a/test/sortglos.awk b/test/sortglos.awk index e4f910d7..e4f910d7 100755..100644 --- a/test/sortglos.awk +++ b/test/sortglos.awk diff --git a/test/sortglos.in b/test/sortglos.in index b24373de..b24373de 100755..100644 --- a/test/sortglos.in +++ b/test/sortglos.in |