aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArnold D. Robbins <arnold@skeeve.com>2017-03-27 21:27:50 +0300
committerArnold D. Robbins <arnold@skeeve.com>2017-03-27 21:27:50 +0300
commit61b4108f82f30deaabf03eb6dbc0e64edeffdb6e (patch)
tree1f58b098882768fe1b1e6a6ca39758f225d7895f
parent70f73831de55d63263839d5fa6ac44dbc2c38491 (diff)
downloadegawk-61b4108f82f30deaabf03eb6dbc0e64edeffdb6e.tar.gz
egawk-61b4108f82f30deaabf03eb6dbc0e64edeffdb6e.tar.bz2
egawk-61b4108f82f30deaabf03eb6dbc0e64edeffdb6e.zip
Minor edits in feature/api-parser prepatory to merging.
-rw-r--r--ChangeLog8
-rw-r--r--extension/ChangeLog6
-rw-r--r--extension/readdir.c5
-rw-r--r--extension/readdir_test.c9
-rw-r--r--field.c23
-rw-r--r--gawkapi.h8
6 files changed, 39 insertions, 20 deletions
diff --git a/ChangeLog b/ChangeLog
index a06a21f7..d740b43a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
2017-03-27 Arnold D. Robbins <arnold@skeeve.com>
+ * field.c (parse_field_func_t): New typedef. Used as needed.
+ (fw_parse_field): Edit comment about resetting shift state.
+ (set_parser): Fix leading comment's style and type of argument.
+ (set_FIELDWIDTHS): Improve the fatal error message.
+ * gawkapi.h: Minor edits in some comments.
+
+2017-03-27 Arnold D. Robbins <arnold@skeeve.com>
+
Cause EPIPE errors to stdout to generate a real SIGPIPE.
* awk.h (die_via_sigpipe): New macro.
diff --git a/extension/ChangeLog b/extension/ChangeLog
index 2773847e..a3a50cd1 100644
--- a/extension/ChangeLog
+++ b/extension/ChangeLog
@@ -1,3 +1,9 @@
+2017-03-27 Arnold D. Robbins <arnold@skeeve.com>
+
+ * readdir.c: Minor edits.
+ * readdir_test.c: Same minor edits, update copyright year,
+ bump version of extension in case this ever becomes the real one.
+
2017-03-23 Arnold D. Robbins <arnold@skeeve.com>
* readdir.c (dir_get_record): Add additional parameter to make types
diff --git a/extension/readdir.c b/extension/readdir.c
index b871d13f..2e34456e 100644
--- a/extension/readdir.c
+++ b/extension/readdir.c
@@ -51,7 +51,7 @@
#ifdef HAVE_DIRENT_H
#include <dirent.h>
#else
-#error Cannot compile the dirent extension on this system!
+#error Cannot compile the readdir extension on this system!
#endif
#ifdef __MINGW32__
@@ -137,6 +137,7 @@ ftype(struct dirent *entry, const char *dirname)
}
/* get_inode --- get the inode of a file */
+
static long long
get_inode(struct dirent *entry, const char *dirname)
{
@@ -199,7 +200,7 @@ dir_get_record(char **out, awk_input_buf_t *iobuf, int *errcode,
return EOF;
}
- ino = get_inode (dirent, iobuf->name);
+ ino = get_inode(dirent, iobuf->name);
#if __MINGW32__
len = sprintf(the_dir->buf, "%I64u/%s", ino, dirent->d_name);
diff --git a/extension/readdir_test.c b/extension/readdir_test.c
index d21b4e97..6d6ee134 100644
--- a/extension/readdir_test.c
+++ b/extension/readdir_test.c
@@ -10,7 +10,7 @@
*/
/*
- * Copyright (C) 2012-2014 the Free Software Foundation, Inc.
+ * Copyright (C) 2012-2014, 2017 the Free Software Foundation, Inc.
*
* This file is part of GAWK, the GNU implementation of the
* AWK Programming Language.
@@ -51,7 +51,7 @@
#ifdef HAVE_DIRENT_H
#include <dirent.h>
#else
-#error Cannot compile the dirent extension on this system!
+#error Cannot compile the readdir extension on this system!
#endif
#ifdef __MINGW32__
@@ -73,7 +73,7 @@
static const gawk_api_t *api; /* for convenience macros to work */
static awk_ext_id_t *ext_id;
-static const char *ext_version = "readdir extension: version 1.0";
+static const char *ext_version = "readdir extension: version 2.0";
static awk_bool_t init_readdir(void);
static awk_bool_t (*init_func)(void) = init_readdir;
@@ -142,6 +142,7 @@ ftype(struct dirent *entry, const char *dirname)
}
/* get_inode --- get the inode of a file */
+
static long long
get_inode(struct dirent *entry, const char *dirname)
{
@@ -204,7 +205,7 @@ dir_get_record(char **out, awk_input_buf_t *iobuf, int *errcode,
return EOF;
}
- ino = get_inode (dirent, iobuf->name);
+ ino = get_inode(dirent, iobuf->name);
#if __MINGW32__
len = sprintf(the_dir->buf, "%I64u", ino);
diff --git a/field.c b/field.c
index bd333c92..b5f28c17 100644
--- a/field.c
+++ b/field.c
@@ -40,15 +40,15 @@ typedef void (* Setfunc)(long, char *, long, NODE *);
/* is the API currently overriding the default parsing mechanism? */
static bool api_parser_override = false;
-static long (*parse_field)(long, char **, int, NODE *,
+typedef long (*parse_field_func_t)(long, char **, int, NODE *,
Regexp *, Setfunc, NODE *, NODE *, bool);
+static parse_field_func_t parse_field;
/*
* N.B. The normal_parse_field function pointer contains the parse_field value
* that should be used except when API field parsing is overriding the default
* field parsing mechanism.
*/
-static long (*normal_parse_field)(long, char **, int, NODE *,
- Regexp *, Setfunc, NODE *, NODE *, bool);
+static parse_field_func_t normal_parse_field;
static long re_parse_field(long, char **, int, NODE *,
Regexp *, Setfunc, NODE *, NODE *, bool);
static long def_parse_field(long, char **, int, NODE *,
@@ -771,9 +771,10 @@ fw_parse_field(long up_to, /* parse only up to this field number */
return nf;
if (gawk_mb_cur_max > 1 && fw->use_chars) {
/*
- * XXX This may be a bug. Most likely, shift state should
- * persist across all fields in a record, if not across record
- * boundaries as well.
+ * Reset the shift state for each field, since there might
+ * be who-knows-what kind of stuff in between fields,
+ * and we assume each field starts with a valid (possibly
+ * multibyte) character.
*/
memset(&mbs, 0, sizeof(mbstate_t));
while (nf < up_to) {
@@ -1104,10 +1105,10 @@ do_patsplit(int nargs)
return tmp;
}
-/* set_parser: update the current (non-API) parser */
+/* set_parser --- update the current (non-API) parser */
static void
-set_parser(long (*func)(long, char **, int, NODE *, Regexp *, Setfunc, NODE *, NODE *, bool))
+set_parser(parse_field_func_t func)
{
normal_parse_field = func;
if (! api_parser_override && parse_field != func) {
@@ -1149,7 +1150,7 @@ set_FIELDWIDTHS()
if (FIELDWIDTHS == NULL) {
emalloc(FIELDWIDTHS, awk_fieldwidth_info_t *, awk_fieldwidth_info_size(fw_alloc), "set_FIELDWIDTHS");
- FIELDWIDTHS->use_chars = awk_true;
+ FIELDWIDTHS->use_chars = true;
}
FIELDWIDTHS->nf = 0;
for (i = 0; ; i++) {
@@ -1201,8 +1202,8 @@ set_FIELDWIDTHS()
}
if (fatal_error)
- fatal(_("invalid FIELDWIDTHS value, near `%s'"),
- scan);
+ fatal(_("invalid FIELDWIDTHS value, for field %d, near `%s'"),
+ i, scan);
}
/* set_FS --- handle things when FS is assigned to */
diff --git a/gawkapi.h b/gawkapi.h
index da538115..a8d6279f 100644
--- a/gawkapi.h
+++ b/gawkapi.h
@@ -124,16 +124,18 @@ typedef enum awk_bool {
* field lengths are specified in terms of bytes or potentially multi-byte
* characters. Performance will be better if the values are supplied in
* terms of bytes. The fields[0].skip value indicates how many bytes (or
- * characters to skip) before $1, and fields[0].len is the length of $1, etc.
+ * characters) to skip before $1, and fields[0].len is the length of $1, etc.
*/
+
typedef struct {
awk_bool_t use_chars; /* false ==> use bytes */
size_t nf;
struct awk_field_info {
- size_t skip; /* # to skip before field starts */
+ size_t skip; /* amount to skip before field starts */
size_t len; /* length of field */
- } fields[1]; /* actual dimension should be nf */
+ } fields[1]; /* actual dimension should be nf */
} awk_fieldwidth_info_t;
+
/*
* This macro calculates the total struct size needed. This is useful when
* calling malloc or realloc.