Commit Graph

43 Commits

Author SHA1 Message Date
zoulasc
ffee7780fe
3 more fixes (#75)
* 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-28 13:23:54 +02:00
zoulasc
c2c8ecbedf
More minor fixes: (#73)
* More minor fixes:

- add missing initializers
- fix sign-compare warnings
- fix shadowed variable
2020-02-19 20:44:49 +02:00
Arnold D. Robbins
e6fe674b40 Restore zoulas fixes, stage 3. 2020-02-06 22:38:30 +02:00
Arnold D. Robbins
cd552112a7 Restore zoulas fixes, stages 2. 2020-02-06 22:32:55 +02:00
Arnold D. Robbins
5068d20ef6 Restore zoulas fixes, step 1. 2020-02-06 22:27:31 +02:00
Arnold D. Robbins
d7a7e4d147 Revert zoulas changes until we can keep tests passing. 2020-02-06 22:08:20 +02:00
Arnold D. Robbins
3c755f73f4 Fix closeall for portability. 2020-02-06 21:45:46 +02:00
zoulasc
110bdc6b3e
misc fixes (#69)
* 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-02-06 21:25:36 +02:00
zoulasc
6a8770929d Small fixes (#68)
* 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-24 11:11:59 +02:00
Arnold D. Robbins
5a18f63b8d Set the close-on-exec flag for file and pipe redirections. 2020-01-22 02:10:59 -07:00
Arnold D. Robbins
de6284e037 Fix Issue 60; sub/gsub follow POSIX if POSIXLY_CORRECT in the environment. 2020-01-19 20:37:33 +02:00
Martijn Dekker
fed1a562c3 Make I/O errors fatal instead of mere warnings (#63)
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.
2020-01-17 14:02:57 +02:00
Arnold D. Robbins
0b82bc6eb4 Small edits, update version and FIXES. 2019-12-11 09:24:38 +02:00
zoulasc
a96aebbbd6 Fix printf format conversions. (#59)
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-11 09:17:34 +02:00
zoulasc
ff5d67610c Fix printf formats for integers (#57)
* 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-12-08 21:41:27 +02:00
Arnold D. Robbins
108224b484 Convert variables to bool and enum. 2019-11-10 21:19:18 +02:00
Arnold D. Robbins
938b26cfae Don't use 'j' flag on %x. Remove an unnecessary cast. 2019-10-25 11:01:17 -04:00
zoulasc
0d8778bbbb more cleanups (#55)
* 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-25 10:59:09 -04:00
Arnold D. Robbins
1d6ddfd9c0 Optimize string concatenation. 2019-10-24 10:06:10 -04:00
zoulasc
6589208eaf More cleanups: (#53)
- 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-24 09:40:15 -04:00
Arnold D. Robbins
0ba1d0391d Small code formatting fix in run.c. 2019-10-08 10:30:09 +03:00
M. Warner Losh
966fdc9c29 Bring in fix from FreeBSD:
| 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-16 22:21:33 +03:00
pfg
c70b9fe882 awk: Use random(3) instead of rand(3)
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-16 22:19:56 +03:00
pfg
524219409a MFV r300961: one-true-awk: replace 0 with NULL for pointers
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-07-16 22:11:57 +03:00
Cody Mello
ae99b752af Disallow deleting SYMTAB and its elements (#43) 2019-06-17 22:08:54 +03:00
Arnold D. Robbins
9dbd1f1de3 Make getline POSIX compliant w.r.t. numeric strings. 2019-01-25 12:56:06 +02:00
onetrueawk
79f008e853
Merge branch 'master' into nf-self-assign 2019-01-21 14:20:28 -05:00
onetrueawk
5a8a060bc3
Merge branch 'master' into split-fs-from-array 2019-01-21 14:19:07 -05:00
onetrueawk
10da937340
Merge branch 'master' into subsep 2019-01-21 14:17:57 -05:00
onetrueawk
4f4701e090
Merge branch 'master' into nf-self-assign 2019-01-21 14:09:21 -05:00
onetrueawk
8dfde739e9
Merge branch 'master' into split-fs-from-array 2019-01-21 14:08:25 -05:00
onetrueawk
11c1fc61d5
Merge branch 'master' into subsep 2019-01-21 14:05:24 -05:00
onetrueawk
3222d96844
Merge branch 'master' into assign-expr 2019-01-21 14:00:32 -05:00
Cody Peter Mello
6315525dbe Rebuild fields when NF is assigned to itself 2018-09-23 17:59:52 -07:00
Cody Peter Mello
52566c0aa4 Handle numeric FS, RS, OFS, and ORS values 2018-09-23 17:35:45 -07:00
Cody Peter Mello
d45db5e9d8 Fix calling split() with a third argument that lives in the target array 2018-09-18 15:20:44 -07:00
Cody Peter Mello
97a4b7ed21 Fix issues with numeric SUBSEP and large SUBSEP values 2018-09-17 11:59:04 -07:00
Cody Peter Mello
e26237434f Fix issues with assigning during concatenation 2018-09-15 01:43:21 -07:00
Cody Peter Mello
6cf37e9d15 Check for format character precision argument before using it 2018-09-14 17:34:17 -07:00
Brian Kernighan
22aff9e657 disallow $ in printf formats 2018-08-27 08:52:34 -04:00
Arnold D. Robbins
32093f5bbf Fix multiple long-standing bugs, improve test suite. 2018-08-22 20:40:26 +03:00
Brian Kernighan
3ed9e245db set baseline so Arnold can send pull request 2018-08-15 10:45:03 -04:00
Brian Kernighan
87b94932e6 initial commit for github 2012-12-22 10:35:39 -05:00