aboutsummaryrefslogtreecommitdiff
path: root/run.c
AgeCommit message (Collapse)Author
2020-12-08Rework floating point conversions. (#98)Arnold Robbins
2020-10-13Make it compile with g++.Arnold D. Robbins
2020-08-16Additional fixes for DJGPP.Arnold D. Robbins
2020-08-07printf: The argument p shall be a pointer to void. (#93)Chris
2020-08-04Fix Issue #92; see FIXES.Arnold D. Robbins
2020-07-30Move exclusively to bison as parser generator.Arnold D. Robbins
2020-07-27Avoid using stdio streams after they have been closed. (#89)Todd C. Miller
* In closeall(), skip stdin and flush std{err,out} instead of closing. Otherwise awk could fclose(stdin) twice (it may appear more than once) and closing stderr means awk cannot report errors with other streams. For example, "awk 'BEGIN { getline < "-" }' < /dev/null" will call fclose(stdin) twice, with undefined results. * If closefile() is called on std{in,out,err}, freopen() /dev/null instead. Otherwise, awk will continue trying to perform I/O on a closed stdio stream, the behavior of which is undefined.
2020-07-02Fix regression with changed SUBSEP in subscript (#86)Tim van der Molen
Commit 0d8778bbbb415810bfd126694a38b6bf4b71e79c reintroduced a regression that was fixed in commit 97a4b7ed215ae6446d13fe0eab15b5b3ae4da7da. The length of SUBSEP needs to be rechecked after calling execute(), in case SUBSEP itself has been changed. Co-authored-by: Tim van der Molen <tim@kariliq.nl>
2020-07-02Fix concatenation regression (#85)Tim van der Molen
The optimization in commit 1d6ddfd9c0ed7119c0601474cded3a385068e886 reintroduced the regression that was fixed in commit e26237434fb769d9c1ea239101eb5b24be588eea. Co-authored-by: Tim van der Molen <tim@kariliq.nl>
2020-06-25Rename dprintf to DPRINTF and use C99 cpp variadic arguments. (#82)Todd C. Miller
POSIX specifies a dprintf function that operates on an fd instead of a stdio stream. Using upper case for macros is more idiomatic too. We no longer need to use an extra set of parentheses for debugging printf statements.
2020-06-12Clear errno before using errcheck() to avoid spurious errors. (#80)Todd C. Miller
The errcheck() function treats an errno of ERANGE or EDOM as something to report, so make sure errno is set to zero before invoking a function to check so that a previous such errno value won't result in a false positive. This could happen simply due to input line fields that looked enough like floating-point input to trigger ERANGE. Reported by Jordan Geoghegan, fix from Philip Guenther.
2020-02-283 more fixes (#75)zoulasc
* LC_NUMERIC radix issue. According to https://pubs.opengroup.org/onlinepubs/7990989775/xcu/awk.html The period character is the character recognized in processing awk programs. Make it so that during output we also print the period character, since this is what other awk implementations do, and it makes sense from an interoperability point of view. * print "T.builtin" in the error message * Fix backslash continuation line handling. * Keep track of RS processing so we apply the regex properly only once per record.
2020-02-19More minor fixes: (#73)zoulasc
* More minor fixes: - add missing initializers - fix sign-compare warnings - fix shadowed variable
2020-02-06Restore zoulas fixes, stage 3.Arnold D. Robbins
2020-02-06Restore zoulas fixes, stages 2.Arnold D. Robbins
2020-02-06Restore zoulas fixes, step 1.Arnold D. Robbins
2020-02-06Revert zoulas changes until we can keep tests passing.Arnold D. Robbins
2020-02-06Fix closeall for portability.Arnold D. Robbins
2020-02-06misc fixes (#69)zoulasc
* Add a test for german case folding. * Add a function to copy a string with a string with a larger allocation (to be used by the case folding routines) * Add printf attributes to the printf-like functions and fix one format warning * Cleanup the tempfree macro * make more functions static * rename fp to frp (FRame Pointer) to avoid shadowing with fp (File Pointer). * add more const * fix indent in UPLUS case * add locale-aware case folding * make nfiles size_t * fix bugs in file closing: - compare fclose to EOF and pclose to -1 - use nfiles instead of FOPEN_MAX in closeall - don't close files we did not open (0,1,2) fpurge/fflush instead * - use NUL instead of 0 for char comparisons - add ISWS() macro - use continue; instead of ; * Check for existance of the german locale before using it. * Add missing parentheses, thanks Arnold.
2020-01-24Small fixes (#68)zoulasc
* sprinkle const, static * account for lineno in unput * Add an EMPTY string that is used when a non-const empty string is needed. * make inputFS static and dynamically allocated * Simplify and in the process avoid -Wwritable-strings * make fs const to avoid -Wwritable-strings
2020-01-22Set the close-on-exec flag for file and pipe redirections.Arnold D. Robbins
2020-01-19Fix Issue 60; sub/gsub follow POSIX if POSIXLY_CORRECT in the environment.Arnold D. Robbins
2020-01-17Make I/O errors fatal instead of mere warnings (#63)Martijn Dekker
An input/output error indicates a fatal condition, even if it occurs when closing a file. Awk should not return success on I/O error, but treat I/O errors as it already treats write errors. Test case: $ (trap '' PIPE; awk 'BEGIN { print "hi"; }'; echo "E $?" >&2) | : awk: i/o error occurred while closing /dev/stdout source line number 1 E 2 The test case pipes a line into a dummy command that reads no input, with SIGPIPE ignored so we rely on awk's own I/O checking. No write error is detected, because the pipe is buffered; the broken pipe is only detected as an I/O error on closing stdout. Before this commit, "E 0" was printed (indicating status 0/success) because an I/O error merely produced a warning. A shell script was unable to detect the I/O error using the exit status.
2019-12-11Small edits, update version and FIXES.Arnold D. Robbins
2019-12-11Fix printf format conversions. (#59)zoulasc
Further simplify printf % parsing by eating the length specifiers during the copy phase, and substitute 'j' when finalizing the format. Add some more tests for this.
2019-12-08Fix printf formats for integers (#57)zoulasc
* More cleanups: - sprinkle const - add a macro (setptr) that cheats const to temporarily NUL terminate strings remove casts from allocations - use strdup instead of strlen+strcpy - use x = malloc(sizeof(*x)) instead of x = malloc(sizeof(type of *x))) - add -Wcast-qual (and casts through unitptr_t in the two macros we cheat (xfree, setptr)). * More cleanups: - add const - use bounded sscanf - use snprintf instead of sprintf * More cleanup: - use snprintf/strlcat instead of sprintf/strcat - use %j instead of %l since we are casting to intmax_t/uintmax_t * Merge the 3 copies of the code that evaluated array strings with separators and convert them to keep track of lengths and use memcpy instead of strcat. * Fix formats for 32 bit machines broken by previous commit. We use intmax_t to provide maximum range for both 32 and 64 bit machines.
2019-11-10Convert variables to bool and enum.Arnold D. Robbins
2019-10-25Don't use 'j' flag on %x. Remove an unnecessary cast.Arnold D. Robbins
2019-10-25more cleanups (#55)zoulasc
* More cleanups: - sprinkle const - add a macro (setptr) that cheats const to temporarily NUL terminate strings remove casts from allocations - use strdup instead of strlen+strcpy - use x = malloc(sizeof(*x)) instead of x = malloc(sizeof(type of *x))) - add -Wcast-qual (and casts through unitptr_t in the two macros we cheat (xfree, setptr)). * More cleanups: - add const - use bounded sscanf - use snprintf instead of sprintf * More cleanup: - use snprintf/strlcat instead of sprintf/strcat - use %j instead of %l since we are casting to intmax_t/uintmax_t * Merge the 3 copies of the code that evaluated array strings with separators and convert them to keep track of lengths and use memcpy instead of strcat.
2019-10-24Optimize string concatenation.Arnold D. Robbins
2019-10-24More cleanups: (#53)zoulasc
- sprinkle const - add a macro (setptr) that cheats const to temporarily NUL terminate strings remove casts from allocations - use strdup instead of strlen+strcpy - use x = malloc(sizeof(*x)) instead of x = malloc(sizeof(type of *x))) - add -Wcast-qual (and casts through unitptr_t in the two macros we cheat (xfree, setptr)).
2019-10-08Small code formatting fix in run.c.Arnold D. Robbins
2019-07-16Bring in fix from FreeBSD:M. Warner Losh
| r323964 | imp | 2017-09-23 23:04:02 -0600 (Sat, 23 Sep 2017) | 6 lines | | Fix %c for floating values that become 0 when coerced to int. | | Obtained from: OpenBSD run.c 1.36 (From Jeremy Devenport) | Sponsored by: Netflix | Differential Revision: https://reviews.freebsd.org/D12379
2019-07-16awk: Use random(3) instead of rand(3)pfg
While none of them is considered even near to cryptographic level, random(3) is a better random generator than rand(3). Use random(3) for awk as is done in other systems. Thanks to Chenguang Li for discussing this in the lists and submitting the patch upstream. PR: 193147 MFC after: 5 weeks git-svn-id: svn+ssh://svn.freebsd.org/base/head@271879 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f
2019-07-16MFV r300961: one-true-awk: replace 0 with NULL for pointerspfg
Also remove a redundant semicolon. Also had to rebase on upstream pull. git-svn-id: svn+ssh://svn.freebsd.org/base/head@301289 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f
2019-06-17Disallow deleting SYMTAB and its elements (#43)Cody Mello
2019-01-25Make getline POSIX compliant w.r.t. numeric strings.Arnold D. Robbins
2019-01-21Merge branch 'master' into nf-self-assignonetrueawk
2019-01-21Merge branch 'master' into split-fs-from-arrayonetrueawk
2019-01-21Merge branch 'master' into subseponetrueawk
2019-01-21Merge branch 'master' into nf-self-assignonetrueawk
2019-01-21Merge branch 'master' into split-fs-from-arrayonetrueawk
2019-01-21Merge branch 'master' into subseponetrueawk
2019-01-21Merge branch 'master' into assign-expronetrueawk
2018-09-23Rebuild fields when NF is assigned to itselfCody Peter Mello
2018-09-23Handle numeric FS, RS, OFS, and ORS valuesCody Peter Mello
2018-09-18Fix calling split() with a third argument that lives in the target arrayCody Peter Mello
2018-09-17Fix issues with numeric SUBSEP and large SUBSEP valuesCody Peter Mello
2018-09-15Fix issues with assigning during concatenationCody Peter Mello
2018-09-14Check for format character precision argument before using itCody Peter Mello