summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--array.c7
-rw-r--r--awk.h267
-rw-r--r--awkgram.c72
-rw-r--r--awkgram.y72
-rw-r--r--builtin.c31
-rw-r--r--cint_array.c54
-rw-r--r--debug.c36
-rw-r--r--eval.c12
-rw-r--r--field.c14
-rw-r--r--gawkapi.c12
-rw-r--r--gawkapi.h21
-rw-r--r--int_array.c30
-rw-r--r--interpret.h2
-rw-r--r--io.c123
-rw-r--r--main.c9
-rw-r--r--mpfr.c2
-rw-r--r--msg.c3
-rw-r--r--node.c2
-rw-r--r--profile.c4
-rw-r--r--re.c2
-rw-r--r--str_array.c20
-rw-r--r--support/localeinfo.h8
-rw-r--r--support/pma.h8
-rw-r--r--support/random.h6
24 files changed, 436 insertions, 381 deletions
diff --git a/array.c b/array.c
index 124824b5..d8b6ca42 100644
--- a/array.c
+++ b/array.c
@@ -1347,7 +1347,7 @@ assoc_list(NODE *symbol, const char *sort_str, sort_context_t sort_ctxt)
static const struct qsort_funcs {
const char *name;
qsort_compfunc comp_func;
- assoc_kind_t kind;
+ int kind;
} sort_funcs[] = {
{ "@ind_str_asc", sort_up_index_string, AINDEX|AISTR|AASC },
{ "@ind_num_asc", sort_up_index_number, AINDEX|AINUM|AASC },
@@ -1369,13 +1369,12 @@ assoc_list(NODE *symbol, const char *sort_str, sort_context_t sort_ctxt)
NODE **list;
NODE akind;
- unsigned long num_elems, j;
- int elem_size, qi;
+ int elem_size, qi, j, num_elems;
qsort_compfunc cmp_func = 0;
INSTRUCTION *code = NULL;
extern int currule;
int save_rule = 0;
- assoc_kind_t assoc_kind = ANONE;
+ int assoc_kind = ANONE;
elem_size = 1;
diff --git a/awk.h b/awk.h
index 57d4f8bd..75feeefc 100644
--- a/awk.h
+++ b/awk.h
@@ -169,6 +169,13 @@ typedef int off_t;
/* same thing for warning */
#define warning (*(set_loc(__FILE__, __LINE__),r_warning))
+// This macro lets GDB print the bits in bit flag enums when compiled with C.
+#ifdef __cplusplus
+#define ENUM(enumtag) int
+#else
+#define ENUM(enumtag) enum enumtag
+#endif /* __cplusplus */
+
#ifdef HAVE_MPFR
#include <gmp.h>
#include <mpfr.h>
@@ -326,6 +333,90 @@ typedef struct {
afunc_t store;
} array_funcs_t;
+enum reflagvals {
+ CONSTANT = 1,
+ FS_DFLT = 2,
+};
+
+enum flagvals {
+/* type = Node_val */
+ /*
+ * STRING and NUMBER are mutually exclusive, except for the special
+ * case of an uninitialized value, represented internally by
+ * Nnull_string. They represent the type of a value as assigned.
+ * Nnull_string has both STRING and NUMBER attributes, but all other
+ * scalar values should have precisely one of these bits set.
+ *
+ * STRCUR and NUMCUR are not mutually exclusive. They represent that
+ * the particular type of value is up to date. For example,
+ *
+ * a = 5 # NUMBER | NUMCUR
+ * b = a "" # Adds STRCUR to a, since a string value
+ * # is now available. But the type hasn't changed!
+ *
+ * a = "42" # STRING | STRCUR
+ * b = a + 0 # Adds NUMCUR to a, since numeric value
+ * # is now available. But the type hasn't changed!
+ *
+ * USER_INPUT is the joker. When STRING|USER_INPUT is set, it means
+ * "this is string data, but the user may have really wanted it to be a
+ * number. If we have to guess, like in a comparison, turn it into a
+ * number if the string is indeed numeric."
+ * For example, gawk -v a=42 ....
+ * Here, `a' gets STRING|STRCUR|USER_INPUT and then when used where
+ * a number is needed, it gets turned into a NUMBER and STRING
+ * is cleared. In that case, we leave the USER_INPUT in place, so
+ * the combination NUMBER|USER_INPUT means it is a strnum a.k.a. a
+ * "numeric string".
+ *
+ * WSTRCUR is for efficiency. If in a multibyte locale, and we
+ * need to do something character based (substr, length, etc.)
+ * we create the corresponding wide character string and store it,
+ * and add WSTRCUR to the flags so that we don't have to do the
+ * conversion more than once.
+ *
+ * The NUMINT flag may be used with a value of any type -- NUMBER,
+ * STRING, or STRNUM. It indicates that the string representation
+ * equals the result of sprintf("%ld", <numeric value>). So, for
+ * example, NUMINT should NOT be set if it's a strnum or string value
+ * where the string is " 1" or "01" or "+1" or "1.0" or "0.1E1". This
+ * is a hint to indicate that an integer array optimization may be
+ * used when this value appears as a subscript.
+ *
+ * The BOOL flag indicates that this number should be converted to True
+ * or False by extensions that interchange data with other languages,
+ * via JSON, XML or some other serialization mechanism.
+ *
+ * We hope that the rest of the flags are self-explanatory. :-)
+ */
+ MALLOC = 0x0001, /* stptr can be free'd, i.e. not a field node pointing into a shared buffer */
+ STRING = 0x0002, /* assigned as string */
+ STRCUR = 0x0004, /* string value is current */
+ NUMCUR = 0x0008, /* numeric value is current */
+ NUMBER = 0x0010, /* assigned as number */
+ USER_INPUT = 0x0020, /* user input: if NUMERIC then
+ * a NUMBER */
+ BOOLVAL = 0x0040, /* this is a boolean value */
+ INTLSTR = 0x0080, /* use localized version */
+ NUMINT = 0x0100, /* numeric value is an integer */
+ INTIND = 0x0200, /* integral value is array index;
+ * lazy conversion to string.
+ */
+ WSTRCUR = 0x0400, /* wide str value is current */
+ MPFN = 0x0800, /* arbitrary-precision floating-point number */
+ MPZN = 0x01000, /* arbitrary-precision integer */
+ NO_EXT_SET = 0x02000, /* extension cannot set a value for this variable */
+ NULL_FIELD = 0x04000, /* this is the null field */
+
+/* type = Node_var_array */
+ ARRAYMAXED = 0x08000, /* array is at max size */
+ HALFHAT = 0x010000, /* half-capacity Hashed Array Tree;
+ * See cint_array.c */
+ XARRAY = 0x020000,
+ NUMCONSTSTR = 0x040000, /* have string value for numeric constant */
+ REGEX = 0x080000, /* this is a typed regex */
+};
+
/*
* NOTE - this struct is a rather kludgey -- it is packed to minimize
* space usage, at the expense of cleanliness. Alter at own risk.
@@ -357,10 +448,7 @@ typedef struct exp_node {
size_t reserved;
struct exp_node *rn;
unsigned long cnt;
- enum reflagvals {
- CONSTANT = 1,
- FS_DFLT = 2,
- } reflags;
+ ENUM(reflagvals) reflags;
} nodep;
struct {
@@ -384,84 +472,7 @@ typedef struct exp_node {
} val;
} sub;
NODETYPE type;
- enum flagvals {
- /* type = Node_val */
- /*
- * STRING and NUMBER are mutually exclusive, except for the special
- * case of an uninitialized value, represented internally by
- * Nnull_string. They represent the type of a value as assigned.
- * Nnull_string has both STRING and NUMBER attributes, but all other
- * scalar values should have precisely one of these bits set.
- *
- * STRCUR and NUMCUR are not mutually exclusive. They represent that
- * the particular type of value is up to date. For example,
- *
- * a = 5 # NUMBER | NUMCUR
- * b = a "" # Adds STRCUR to a, since a string value
- * # is now available. But the type hasn't changed!
- *
- * a = "42" # STRING | STRCUR
- * b = a + 0 # Adds NUMCUR to a, since numeric value
- * # is now available. But the type hasn't changed!
- *
- * USER_INPUT is the joker. When STRING|USER_INPUT is set, it means
- * "this is string data, but the user may have really wanted it to be a
- * number. If we have to guess, like in a comparison, turn it into a
- * number if the string is indeed numeric."
- * For example, gawk -v a=42 ....
- * Here, `a' gets STRING|STRCUR|USER_INPUT and then when used where
- * a number is needed, it gets turned into a NUMBER and STRING
- * is cleared. In that case, we leave the USER_INPUT in place, so
- * the combination NUMBER|USER_INPUT means it is a strnum a.k.a. a
- * "numeric string".
- *
- * WSTRCUR is for efficiency. If in a multibyte locale, and we
- * need to do something character based (substr, length, etc.)
- * we create the corresponding wide character string and store it,
- * and add WSTRCUR to the flags so that we don't have to do the
- * conversion more than once.
- *
- * The NUMINT flag may be used with a value of any type -- NUMBER,
- * STRING, or STRNUM. It indicates that the string representation
- * equals the result of sprintf("%ld", <numeric value>). So, for
- * example, NUMINT should NOT be set if it's a strnum or string value
- * where the string is " 1" or "01" or "+1" or "1.0" or "0.1E1". This
- * is a hint to indicate that an integer array optimization may be
- * used when this value appears as a subscript.
- *
- * The BOOL flag indicates that this number should be converted to True
- * or False by extensions that interchange data with other languages,
- * via JSON, XML or some other serialization mechanism.
- *
- * We hope that the rest of the flags are self-explanatory. :-)
- */
- MALLOC = 0x0001, /* stptr can be free'd, i.e. not a field node pointing into a shared buffer */
- STRING = 0x0002, /* assigned as string */
- STRCUR = 0x0004, /* string value is current */
- NUMCUR = 0x0008, /* numeric value is current */
- NUMBER = 0x0010, /* assigned as number */
- USER_INPUT = 0x0020, /* user input: if NUMERIC then
- * a NUMBER */
- BOOLVAL = 0x0040, /* this is a boolean value */
- INTLSTR = 0x0080, /* use localized version */
- NUMINT = 0x0100, /* numeric value is an integer */
- INTIND = 0x0200, /* integral value is array index;
- * lazy conversion to string.
- */
- WSTRCUR = 0x0400, /* wide str value is current */
- MPFN = 0x0800, /* arbitrary-precision floating-point number */
- MPZN = 0x01000, /* arbitrary-precision integer */
- NO_EXT_SET = 0x02000, /* extension cannot set a value for this variable */
- NULL_FIELD = 0x04000, /* this is the null field */
-
- /* type = Node_var_array */
- ARRAYMAXED = 0x08000, /* array is at max size */
- HALFHAT = 0x010000, /* half-capacity Hashed Array Tree;
- * See cint_array.c */
- XARRAY = 0x020000,
- NUMCONSTSTR = 0x040000, /* have string value for numeric constant */
- REGEX = 0x080000, /* this is a typed regex */
- } flags;
+ ENUM(flagvals) flags;
long valref;
} NODE;
@@ -939,8 +950,15 @@ typedef struct exp_instruction {
/* Op_store_var */
#define initval x.xn
+enum iobuf_flags {
+ IOP_IS_TTY = 1,
+ IOP_AT_EOF = 2,
+ IOP_CLOSED = 4,
+ IOP_AT_START = 8,
+};
+
typedef struct iobuf {
- awk_input_buf_t public; /* exposed to extensions */
+ awk_input_buf_t public_; /* exposed to extensions */
char *buf; /* start data buffer */
char *off; /* start of current record in buffer */
char *dataend; /* first byte in buffer to hold new data,
@@ -954,33 +972,31 @@ typedef struct iobuf {
bool valid;
int errcode;
- enum iobuf_flags {
- IOP_IS_TTY = 1,
- IOP_AT_EOF = 2,
- IOP_CLOSED = 4,
- IOP_AT_START = 8,
- } flag;
+ ENUM(iobuf_flags) flag;
} IOBUF;
typedef void (*Func_ptr)(void);
/* structure used to dynamically maintain a linked-list of open files/pipes */
+enum redirect_flags {
+ RED_NONE = 0,
+ RED_FILE = 1,
+ RED_PIPE = 2,
+ RED_READ = 4,
+ RED_WRITE = 8,
+ RED_APPEND = 16,
+ RED_FLUSH = 32,
+ RED_USED = 64, /* closed temporarily to reuse fd */
+ RED_EOF = 128,
+ RED_TWOWAY = 256,
+ RED_PTY = 512,
+ RED_SOCKET = 1024,
+ RED_TCP = 2048,
+};
+typedef enum redirect_flags redirect_flags_t;
+
struct redirect {
- enum redirect_flags {
- RED_NONE = 0,
- RED_FILE = 1,
- RED_PIPE = 2,
- RED_READ = 4,
- RED_WRITE = 8,
- RED_APPEND = 16,
- RED_FLUSH = 32,
- RED_USED = 64, /* closed temporarily to reuse fd */
- RED_EOF = 128,
- RED_TWOWAY = 256,
- RED_PTY = 512,
- RED_SOCKET = 1024,
- RED_TCP = 2048,
- } flag;
+ ENUM(redirect_flags) flag;
char *value;
FILE *ifp; /* input fp, needed for PIPES_SIMULATED */
IOBUF *iop;
@@ -991,7 +1007,7 @@ struct redirect {
const char *mode;
awk_output_buf_t output;
};
-typedef enum redirect_flags redirect_flags_t;
+
/* values for BINMODE, used as bit flags */
@@ -1005,18 +1021,19 @@ enum binmode_values {
/*
* structure for our source, either a command line string or a source file.
*/
+enum srctype {
+ SRC_CMDLINE = 1,
+ SRC_STDIN,
+ SRC_FILE,
+ SRC_INC,
+ SRC_EXTLIB
+};
typedef struct srcfile {
struct srcfile *next;
struct srcfile *prev;
- enum srctype {
- SRC_CMDLINE = 1,
- SRC_STDIN,
- SRC_FILE,
- SRC_INC,
- SRC_EXTLIB
- } stype;
+ enum srctype stype;
char *src; /* name on command line or include statement */
char *fullpath; /* full path after AWKPATH search */
time_t mtime;
@@ -1026,7 +1043,7 @@ typedef struct srcfile {
char *buf;
int *line_offset; /* offset to the beginning of each line */
int fd;
- int maxlen; /* size of the longest line */
+ size_t maxlen; /* size of the longest line */
void (*fini_func)(); /* dynamic extension of type SRC_EXTLIB */
@@ -1036,17 +1053,18 @@ typedef struct srcfile {
char *lexptr_begin;
int lasttok;
INSTRUCTION *comment; /* comment on @load line */
- const char *namespace;
+ const char *name_space;
} SRCFILE;
// structure for INSTRUCTION pool, needed mainly for debugger
+struct instruction_mem_pool {
+ struct instruction_block *block_list;
+ INSTRUCTION *free_space; // free location in active block
+ INSTRUCTION *free_list;
+};
typedef struct instruction_pool {
#define MAX_INSTRUCTION_ALLOC 4 // we don't call bcalloc with more than this
- struct instruction_mem_pool {
- struct instruction_block *block_list;
- INSTRUCTION *free_space; // free location in active block
- INSTRUCTION *free_list;
- } pool[MAX_INSTRUCTION_ALLOC];
+ struct instruction_mem_pool pool[MAX_INSTRUCTION_ALLOC];
} INSTRUCTION_POOL;
/* structure for execution context */
@@ -1155,7 +1173,7 @@ extern bool do_itrace; /* separate so can poke from a debugger */
extern SRCFILE *srcfiles; /* source files */
-extern enum do_flag_values {
+enum do_flag_values {
DO_FLAG_NONE = 0x00000,
DO_LINT_INVALID = 0x00001, /* only warn about invalid */
DO_LINT_EXTENSIONS = 0x00002, /* warn about gawk extensions */
@@ -1174,7 +1192,8 @@ extern enum do_flag_values {
DO_DEBUG = 0x04000, /* debug the program */
DO_MPFR = 0x08000, /* arbitrary-precision floating-point math */
DO_CSV = 0x10000, /* process comma-separated-value files */
-} do_flags;
+};
+extern int do_flags;
#define do_traditional (do_flags & DO_TRADITIONAL)
#define do_posix (do_flags & DO_POSIX)
@@ -1718,7 +1737,11 @@ extern void msg (const char *mesg, ...) ATTRIBUTE_PRINTF_1;
extern void error (const char *mesg, ...) ATTRIBUTE_PRINTF_1;
extern void r_warning (const char *mesg, ...) ATTRIBUTE_PRINTF_1;
extern void set_loc (const char *file, int line);
-extern void r_fatal (const char *mesg, ...) ATTRIBUTE_PRINTF_1;
+extern
+#ifdef __cplusplus
+"C"
+#endif /* __cplusplus */
+void r_fatal (const char *mesg, ...) ATTRIBUTE_PRINTF_1;
#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 2)
extern void (*lintfunc)(const char *mesg, ...) ATTRIBUTE_PRINTF_1;
#else
diff --git a/awkgram.c b/awkgram.c
index 180d29c7..b3e73175 100644
--- a/awkgram.c
+++ b/awkgram.c
@@ -75,6 +75,8 @@
#include "awk.h"
+#include <math.h>
+
#if defined(__STDC__) && __STDC__ < 1 /* VMS weirdness, maybe elsewhere */
#define signed /**/
#endif
@@ -231,8 +233,6 @@ static inline INSTRUCTION *list_append(INSTRUCTION *l, INSTRUCTION *x);
static inline INSTRUCTION *list_prepend(INSTRUCTION *l, INSTRUCTION *x);
static inline INSTRUCTION *list_merge(INSTRUCTION *l1, INSTRUCTION *l2);
-extern double fmod(double x, double y);
-
#define YYSTYPE INSTRUCTION *
#line 239 "awkgram.c"
@@ -4738,10 +4738,10 @@ yyreturnlab:
struct token {
- const char *operator; /* text to match */
- OPCODE value; /* type */
- int class; /* lexical class */
- unsigned flags; /* # of args. allowed and compatability */
+ const char *oper; /* text to match */
+ OPCODE value; /* type */
+ int lex_class; /* lexical class */
+ unsigned flags; /* # of args. allowed and compatability */
# define ARGS 0xFF /* 0, 1, 2, 3 args allowed (any combination */
# define A(n) (1<<(n))
# define VERSION_MASK 0xFF00 /* old awk is zero */
@@ -4767,7 +4767,7 @@ tokcompare(const void *l, const void *r)
lhs = (struct token *) l;
rhs = (struct token *) r;
- return strcmp(lhs->operator, rhs->operator);
+ return strcmp(lhs->oper, rhs->oper);
}
#endif
@@ -4891,10 +4891,10 @@ getfname(NODE *(*fptr)(int), bool prepend_awk)
for (i = 0; i < j; i++) {
if (tokentab[i].ptr == fptr || tokentab[i].ptr2 == fptr) {
if (prepend_awk && (tokentab[i].flags & GAWKX) != 0) {
- sprintf(buf, "awk::%s", tokentab[i].operator);
+ sprintf(buf, "awk::%s", tokentab[i].oper);
return buf;
}
- return tokentab[i].operator;
+ return tokentab[i].oper;
}
}
@@ -5470,7 +5470,7 @@ include_source(INSTRUCTION *file, void **srcfile_p)
sourcefile->lexptr_begin = lexptr_begin;
sourcefile->lexeme = lexeme;
sourcefile->lasttok = lasttok;
- sourcefile->namespace = current_namespace;
+ sourcefile->name_space = current_namespace;
/* included file becomes the current source */
sourcefile = s;
@@ -5586,7 +5586,7 @@ next_sourcefile()
lexeme = sourcefile->lexeme;
sourceline = sourcefile->srclines;
source = sourcefile->src;
- set_current_namespace(sourcefile->namespace);
+ set_current_namespace(sourcefile->name_space);
} else {
lexptr = NULL;
sourceline = 0;
@@ -5604,7 +5604,7 @@ get_src_buf()
int n;
char *scan;
bool newfile;
- int savelen;
+ size_t savelen;
struct stat sbuf;
/*
@@ -5744,7 +5744,7 @@ get_src_buf()
* of the available space.
*/
- if (savelen > sourcefile->bufsize / 2) { /* long line or token */
+ if (savelen > sourcefile->bufsize / 2u) { /* long line or token */
sourcefile->bufsize *= 2;
erealloc(sourcefile->buf, char *, sourcefile->bufsize, "get_src_buf");
scan = sourcefile->buf + (scan - lexptr_begin);
@@ -6865,9 +6865,9 @@ retry:
/* See if it is a special token. */
if ((mid = check_qualified_special(tokstart)) >= 0) {
static int warntab[sizeof(tokentab) / sizeof(tokentab[0])];
- int class = tokentab[mid].class;
+ int lex_class = tokentab[mid].lex_class;
- switch (class) {
+ switch (lex_class) {
case LEX_EVAL:
case LEX_INCLUDE:
case LEX_LOAD:
@@ -6908,12 +6908,12 @@ retry:
if (do_lint) {
if (do_lint_extensions && (tokentab[mid].flags & GAWKX) != 0 && (warntab[mid] & GAWKX) == 0) {
lintwarn(_("`%s' is a gawk extension"),
- tokentab[mid].operator);
+ tokentab[mid].oper);
warntab[mid] |= GAWKX;
}
if ((tokentab[mid].flags & NOT_POSIX) != 0 && (warntab[mid] & NOT_POSIX) == 0) {
lintwarn(_("POSIX does not allow `%s'"),
- tokentab[mid].operator);
+ tokentab[mid].oper);
warntab[mid] |= NOT_POSIX;
}
}
@@ -6921,7 +6921,7 @@ retry:
&& (warntab[mid] & NOT_OLD) == 0
) {
lintwarn(_("`%s' is not supported in old awk"),
- tokentab[mid].operator);
+ tokentab[mid].oper);
warntab[mid] |= NOT_OLD;
}
@@ -6930,7 +6930,7 @@ retry:
if ((tokentab[mid].flags & CONTINUE) != 0)
continue_allowed++;
- switch (class) {
+ switch (lex_class) {
case LEX_NAMESPACE:
want_namespace = true;
// fall through
@@ -6961,7 +6961,7 @@ retry:
case LEX_DO:
case LEX_SWITCH:
if (! do_pretty_print)
- return lasttok = class;
+ return lasttok = lex_class;
/* fall through */
case LEX_CASE:
yylval = bcalloc(tokentab[mid].value, 2, sourceline);
@@ -6991,11 +6991,11 @@ retry:
default:
make_instruction:
yylval = GET_INSTRUCTION(tokentab[mid].value);
- if (class == LEX_BUILTIN || class == LEX_LENGTH)
+ if (lex_class == LEX_BUILTIN || lex_class == LEX_LENGTH)
yylval->builtin_idx = mid;
break;
}
- return lasttok = class;
+ return lasttok = lex_class;
}
out:
if (want_param_names == FUNC_HEADER)
@@ -7090,24 +7090,24 @@ snode(INSTRUCTION *subn, INSTRUCTION *r)
args_allowed = tokentab[idx].flags & ARGS;
if (args_allowed && (args_allowed & A(nexp)) == 0) {
yyerror(_("%d is invalid as number of arguments for %s"),
- nexp, tokentab[idx].operator);
+ nexp, tokentab[idx].oper);
return NULL;
}
/* special processing for sub, gsub and gensub */
if (tokentab[idx].value == Op_sub_builtin) {
- const char *operator = tokentab[idx].operator;
+ const char *oper= tokentab[idx].oper;
r->sub_flags = 0;
arg = subn->nexti; /* first arg list */
(void) mk_rexp(arg);
- if (strcmp(operator, "gensub") != 0) {
+ if (strcmp(oper, "gensub") != 0) {
/* sub and gsub */
- if (strcmp(operator, "gsub") == 0)
+ if (strcmp(oper, "gsub") == 0)
r->sub_flags |= GSUB;
arg = arg->lasti->nexti; /* 2nd arg list */
@@ -7125,12 +7125,12 @@ snode(INSTRUCTION *subn, INSTRUCTION *r)
if (ip->opcode == Op_push_i) {
if (do_lint)
lintwarn(_("%s: string literal as last argument of substitute has no effect"),
- operator);
+ oper);
r->sub_flags |= LITERAL;
} else {
if (make_assignable(ip) == NULL)
yyerror(_("%s third parameter is not a changeable object"),
- operator);
+ oper);
else
ip->do_reference = true;
}
@@ -8949,9 +8949,9 @@ check_special(const char *name)
high = (sizeof(tokentab) / sizeof(tokentab[0])) - 1;
while (low <= high) {
mid = (low + high) / 2;
- i = *name - tokentab[mid].operator[0];
+ i = *name - tokentab[mid].oper[0];
if (i == 0)
- i = strcmp(name, tokentab[mid].operator);
+ i = strcmp(name, tokentab[mid].oper);
if (i < 0) /* token < mid */
high = mid - 1;
@@ -9026,7 +9026,7 @@ lookup_builtin(const char *name)
if (mid == -1)
return NULL;
- switch (tokentab[mid].class) {
+ switch (tokentab[mid].lex_class) {
case LEX_BUILTIN:
case LEX_LENGTH:
break;
@@ -9063,10 +9063,10 @@ install_builtins(void)
j = sizeof(tokentab) / sizeof(tokentab[0]);
for (i = 0; i < j; i++) {
- if ( (tokentab[i].class == LEX_BUILTIN
- || tokentab[i].class == LEX_LENGTH)
+ if ( (tokentab[i].lex_class == LEX_BUILTIN
+ || tokentab[i].lex_class == LEX_LENGTH)
&& (tokentab[i].flags & flags_that_must_be_clear) == 0) {
- (void) install_symbol(tokentab[i].operator, Node_builtin_func);
+ (void) install_symbol(tokentab[i].oper, Node_builtin_func);
}
}
}
@@ -9321,7 +9321,7 @@ check_qualified_special(char *token)
return i;
tok = & tokentab[i];
- if ((tok->flags & GAWKX) != 0 && tok->class == LEX_BUILTIN)
+ if ((tok->flags & GAWKX) != 0 && tok->lex_class == LEX_BUILTIN)
return -1;
else
return i;
@@ -9349,7 +9349,7 @@ check_qualified_special(char *token)
if (strcmp(ns, awk_namespace) == 0) {
i = check_special(subname);
if (i >= 0) {
- if ((tokentab[i].flags & GAWKX) != 0 && tokentab[i].class == LEX_BUILTIN)
+ if ((tokentab[i].flags & GAWKX) != 0 && tokentab[i].lex_class == LEX_BUILTIN)
; // gawk additional builtin function, is ok
else
error_ln(sourceline, _("using reserved identifier `%s' as second component of a qualified name is not allowed"), subname);
diff --git a/awkgram.y b/awkgram.y
index 74be2340..748e5ea5 100644
--- a/awkgram.y
+++ b/awkgram.y
@@ -30,6 +30,8 @@
#include "awk.h"
+#include <math.h>
+
#if defined(__STDC__) && __STDC__ < 1 /* VMS weirdness, maybe elsewhere */
#define signed /**/
#endif
@@ -186,8 +188,6 @@ static inline INSTRUCTION *list_append(INSTRUCTION *l, INSTRUCTION *x);
static inline INSTRUCTION *list_prepend(INSTRUCTION *l, INSTRUCTION *x);
static inline INSTRUCTION *list_merge(INSTRUCTION *l1, INSTRUCTION *l2);
-extern double fmod(double x, double y);
-
#define YYSTYPE INSTRUCTION *
%}
@@ -2236,10 +2236,10 @@ comma
%%
struct token {
- const char *operator; /* text to match */
- OPCODE value; /* type */
- int class; /* lexical class */
- unsigned flags; /* # of args. allowed and compatability */
+ const char *oper; /* text to match */
+ OPCODE value; /* type */
+ int lex_class; /* lexical class */
+ unsigned flags; /* # of args. allowed and compatability */
# define ARGS 0xFF /* 0, 1, 2, 3 args allowed (any combination */
# define A(n) (1<<(n))
# define VERSION_MASK 0xFF00 /* old awk is zero */
@@ -2265,7 +2265,7 @@ tokcompare(const void *l, const void *r)
lhs = (struct token *) l;
rhs = (struct token *) r;
- return strcmp(lhs->operator, rhs->operator);
+ return strcmp(lhs->oper, rhs->oper);
}
#endif
@@ -2389,10 +2389,10 @@ getfname(NODE *(*fptr)(int), bool prepend_awk)
for (i = 0; i < j; i++) {
if (tokentab[i].ptr == fptr || tokentab[i].ptr2 == fptr) {
if (prepend_awk && (tokentab[i].flags & GAWKX) != 0) {
- sprintf(buf, "awk::%s", tokentab[i].operator);
+ sprintf(buf, "awk::%s", tokentab[i].oper);
return buf;
}
- return tokentab[i].operator;
+ return tokentab[i].oper;
}
}
@@ -2968,7 +2968,7 @@ include_source(INSTRUCTION *file, void **srcfile_p)
sourcefile->lexptr_begin = lexptr_begin;
sourcefile->lexeme = lexeme;
sourcefile->lasttok = lasttok;
- sourcefile->namespace = current_namespace;
+ sourcefile->name_space = current_namespace;
/* included file becomes the current source */
sourcefile = s;
@@ -3084,7 +3084,7 @@ next_sourcefile()
lexeme = sourcefile->lexeme;
sourceline = sourcefile->srclines;
source = sourcefile->src;
- set_current_namespace(sourcefile->namespace);
+ set_current_namespace(sourcefile->name_space);
} else {
lexptr = NULL;
sourceline = 0;
@@ -3102,7 +3102,7 @@ get_src_buf()
int n;
char *scan;
bool newfile;
- int savelen;
+ size_t savelen;
struct stat sbuf;
/*
@@ -3242,7 +3242,7 @@ get_src_buf()
* of the available space.
*/
- if (savelen > sourcefile->bufsize / 2) { /* long line or token */
+ if (savelen > sourcefile->bufsize / 2u) { /* long line or token */
sourcefile->bufsize *= 2;
erealloc(sourcefile->buf, char *, sourcefile->bufsize, "get_src_buf");
scan = sourcefile->buf + (scan - lexptr_begin);
@@ -4363,9 +4363,9 @@ retry:
/* See if it is a special token. */
if ((mid = check_qualified_special(tokstart)) >= 0) {
static int warntab[sizeof(tokentab) / sizeof(tokentab[0])];
- int class = tokentab[mid].class;
+ int lex_class = tokentab[mid].lex_class;
- switch (class) {
+ switch (lex_class) {
case LEX_EVAL:
case LEX_INCLUDE:
case LEX_LOAD:
@@ -4406,12 +4406,12 @@ retry:
if (do_lint) {
if (do_lint_extensions && (tokentab[mid].flags & GAWKX) != 0 && (warntab[mid] & GAWKX) == 0) {
lintwarn(_("`%s' is a gawk extension"),
- tokentab[mid].operator);
+ tokentab[mid].oper);
warntab[mid] |= GAWKX;
}
if ((tokentab[mid].flags & NOT_POSIX) != 0 && (warntab[mid] & NOT_POSIX) == 0) {
lintwarn(_("POSIX does not allow `%s'"),
- tokentab[mid].operator);
+ tokentab[mid].oper);
warntab[mid] |= NOT_POSIX;
}
}
@@ -4419,7 +4419,7 @@ retry:
&& (warntab[mid] & NOT_OLD) == 0
) {
lintwarn(_("`%s' is not supported in old awk"),
- tokentab[mid].operator);
+ tokentab[mid].oper);
warntab[mid] |= NOT_OLD;
}
@@ -4428,7 +4428,7 @@ retry:
if ((tokentab[mid].flags & CONTINUE) != 0)
continue_allowed++;
- switch (class) {
+ switch (lex_class) {
case LEX_NAMESPACE:
want_namespace = true;
// fall through
@@ -4459,7 +4459,7 @@ retry:
case LEX_DO:
case LEX_SWITCH:
if (! do_pretty_print)
- return lasttok = class;
+ return lasttok = lex_class;
/* fall through */
case LEX_CASE:
yylval = bcalloc(tokentab[mid].value, 2, sourceline);
@@ -4489,11 +4489,11 @@ retry:
default:
make_instruction:
yylval = GET_INSTRUCTION(tokentab[mid].value);
- if (class == LEX_BUILTIN || class == LEX_LENGTH)
+ if (lex_class == LEX_BUILTIN || lex_class == LEX_LENGTH)
yylval->builtin_idx = mid;
break;
}
- return lasttok = class;
+ return lasttok = lex_class;
}
out:
if (want_param_names == FUNC_HEADER)
@@ -4588,24 +4588,24 @@ snode(INSTRUCTION *subn, INSTRUCTION *r)
args_allowed = tokentab[idx].flags & ARGS;
if (args_allowed && (args_allowed & A(nexp)) == 0) {
yyerror(_("%d is invalid as number of arguments for %s"),
- nexp, tokentab[idx].operator);
+ nexp, tokentab[idx].oper);
return NULL;
}
/* special processing for sub, gsub and gensub */
if (tokentab[idx].value == Op_sub_builtin) {
- const char *operator = tokentab[idx].operator;
+ const char *oper= tokentab[idx].oper;
r->sub_flags = 0;
arg = subn->nexti; /* first arg list */
(void) mk_rexp(arg);
- if (strcmp(operator, "gensub") != 0) {
+ if (strcmp(oper, "gensub") != 0) {
/* sub and gsub */
- if (strcmp(operator, "gsub") == 0)
+ if (strcmp(oper, "gsub") == 0)
r->sub_flags |= GSUB;
arg = arg->lasti->nexti; /* 2nd arg list */
@@ -4623,12 +4623,12 @@ snode(INSTRUCTION *subn, INSTRUCTION *r)
if (ip->opcode == Op_push_i) {
if (do_lint)
lintwarn(_("%s: string literal as last argument of substitute has no effect"),
- operator);
+ oper);
r->sub_flags |= LITERAL;
} else {
if (make_assignable(ip) == NULL)
yyerror(_("%s third parameter is not a changeable object"),
- operator);
+ oper);
else
ip->do_reference = true;
}
@@ -6447,9 +6447,9 @@ check_special(const char *name)
high = (sizeof(tokentab) / sizeof(tokentab[0])) - 1;
while (low <= high) {
mid = (low + high) / 2;
- i = *name - tokentab[mid].operator[0];
+ i = *name - tokentab[mid].oper[0];
if (i == 0)
- i = strcmp(name, tokentab[mid].operator);
+ i = strcmp(name, tokentab[mid].oper);
if (i < 0) /* token < mid */
high = mid - 1;
@@ -6524,7 +6524,7 @@ lookup_builtin(const char *name)
if (mid == -1)
return NULL;
- switch (tokentab[mid].class) {
+ switch (tokentab[mid].lex_class) {
case LEX_BUILTIN:
case LEX_LENGTH:
break;
@@ -6561,10 +6561,10 @@ install_builtins(void)
j = sizeof(tokentab) / sizeof(tokentab[0]);
for (i = 0; i < j; i++) {
- if ( (tokentab[i].class == LEX_BUILTIN
- || tokentab[i].class == LEX_LENGTH)
+ if ( (tokentab[i].lex_class == LEX_BUILTIN
+ || tokentab[i].lex_class == LEX_LENGTH)
&& (tokentab[i].flags & flags_that_must_be_clear) == 0) {
- (void) install_symbol(tokentab[i].operator, Node_builtin_func);
+ (void) install_symbol(tokentab[i].oper, Node_builtin_func);
}
}
}
@@ -6819,7 +6819,7 @@ check_qualified_special(char *token)
return i;
tok = & tokentab[i];
- if ((tok->flags & GAWKX) != 0 && tok->class == LEX_BUILTIN)
+ if ((tok->flags & GAWKX) != 0 && tok->lex_class == LEX_BUILTIN)
return -1;
else
return i;
@@ -6847,7 +6847,7 @@ check_qualified_special(char *token)
if (strcmp(ns, awk_namespace) == 0) {
i = check_special(subname);
if (i >= 0) {
- if ((tokentab[i].flags & GAWKX) != 0 && tokentab[i].class == LEX_BUILTIN)
+ if ((tokentab[i].flags & GAWKX) != 0 && tokentab[i].lex_class == LEX_BUILTIN)
; // gawk additional builtin function, is ok
else
error_ln(sourceline, _("using reserved identifier `%s' as second component of a qualified name is not allowed"), subname);
diff --git a/builtin.c b/builtin.c
index 0e609220..09bb67e8 100644
--- a/builtin.c
+++ b/builtin.c
@@ -66,12 +66,6 @@
static size_t mbc_byte_count(const char *ptr, size_t numchars);
static size_t mbc_char_count(const char *ptr, size_t numbytes);
-/* Can declare these, since we always use the random shipped with gawk */
-extern char *initstate(unsigned long seed, char *state, long n);
-extern char *setstate(char *state);
-extern long random(void);
-extern void srandom(unsigned long seed);
-
extern NODE **args_array;
extern int max_args;
extern NODE **fields_arr;
@@ -712,7 +706,7 @@ format_tree(
/* copy 'l' bytes from 's' to 'obufout' checking for space in the process */
/* difference of pointers should be of ptrdiff_t type, but let us be kind */
#define bchunk(s, l) if (l) { \
- while ((l) > ofre) { \
+ while (((size_t)(l)) > ofre) { \
size_t olen = obufout - obuf; \
erealloc(obuf, char *, osiz * 2, "format_tree"); \
ofre += osiz; \
@@ -738,7 +732,7 @@ format_tree(
}
/* Is there space for something L big in the buffer? */
-#define chksize(l) if ((l) >= ofre) { \
+#define chksize(l) if (((size_t)(l)) >= ofre) { \
size_t olen = obufout - obuf; \
size_t delta = osiz+l-ofre; \
erealloc(obuf, char *, osiz + delta, "format_tree"); \
@@ -806,6 +800,7 @@ format_tree(
bool modifier_seen[sizeof(bad_modifiers)-1];
#define modifier_index(c) (strchr(bad_modifiers, c) - bad_modifiers)
+ bool need_to_add_thousands = false;
#define INITIAL_OUT_SIZE 64
emalloc(obuf, char *, INITIAL_OUT_SIZE, "format_tree");
@@ -862,7 +857,7 @@ format_tree(
msg(_("fatal: must use `count$' on all formats or none")); \
arg = 0; /* shutup the compiler */ \
goto out; \
- } else if (cur_arg >= num_args) { \
+ } else if (cur_arg >= (size_t) num_args) { \
arg = 0; /* shutup the compiler */ \
toofew = true; \
break; \
@@ -1204,7 +1199,7 @@ out0:
prec = arg->stlen;
else {
char_count = mbc_char_count(arg->stptr, arg->stlen);
- if (! have_prec || prec > char_count)
+ if (! have_prec || (size_t) prec > char_count)
prec = char_count;
}
cp = arg->stptr;
@@ -1249,14 +1244,14 @@ out0:
* Use snprintf return value to tell if there
* is enough room in the buffer or not.
*/
- while ((i = snprintf(cpbufs[1].buf,
+ while ((size_t)(i = snprintf(cpbufs[1].buf,
cpbufs[1].bufsize, "%.0f",
tmpval)) >=
cpbufs[1].bufsize) {
if (cpbufs[1].buf == cpbufs[1].stackbuf)
cpbufs[1].buf = NULL;
if (i > 0) {
- cpbufs[1].bufsize += ((i > cpbufs[1].bufsize) ?
+ cpbufs[1].bufsize += (((size_t)i > cpbufs[1].bufsize) ?
i : cpbufs[1].bufsize);
}
else
@@ -1623,7 +1618,7 @@ mpf1:
setlocale(LC_NUMERIC, "");
#endif
- bool need_to_add_thousands = false;
+ need_to_add_thousands = false;
switch (fmt_type) {
#ifdef HAVE_MPFR
case MP_INT_WITH_PREC:
@@ -1700,7 +1695,7 @@ mpf1:
if (need_format)
lintwarn(
_("[s]printf: format specifier does not have control letter"));
- if (cur_arg < num_args)
+ if (cur_arg < (size_t)num_args)
lintwarn(
_("too many arguments supplied for format string"));
}
@@ -2141,7 +2136,7 @@ do_strftime(int nargs)
* format string, it's not failing for lack of room.
* Thanks to Paul Eggert for pointing out this issue.
*/
- if (buflen > 0 || bufsize >= 1024 * formatlen)
+ if (buflen > 0 || bufsize >= (size_t)(1024 * formatlen))
break;
bufsize *= 2;
if (bufp == buf)
@@ -2804,7 +2799,7 @@ do_match(int nargs)
subsepstr = SUBSEP_node->var_value->stptr;
subseplen = SUBSEP_node->var_value->stlen;
- for (ii = 0; ii < NUMSUBPATS(rp, t1->stptr); ii++) {
+ for (ii = 0; (size_t)ii < NUMSUBPATS(rp, t1->stptr); ii++) {
/*
* Loop over all the subpats; some of them may have
* matched even if all of them did not.
@@ -3062,7 +3057,7 @@ do_sub(int nargs, unsigned int flags)
/* do the search early to avoid work on non-match */
if (research(rp, target->stptr, 0, target->stlen, RE_NEED_START) == -1 ||
- RESTART(rp, target->stptr) > target->stlen)
+ (size_t)RESTART(rp, target->stptr) > target->stlen)
goto done;
text = target->stptr;
@@ -3205,7 +3200,7 @@ do_sub(int nargs, unsigned int flags)
) {
if (flags & GENSUB) { /* gensub, behave sanely */
if (isdigit((unsigned char) scan[1])) {
- int dig = scan[1] - '0';
+ size_t dig = scan[1] - '0';
if (dig < NUMSUBPATS(rp, target->stptr) && SUBPATSTART(rp, tp->stptr, dig) != -1) {
char *start, *end;
diff --git a/cint_array.c b/cint_array.c
index 27298fba..2037e360 100644
--- a/cint_array.c
+++ b/cint_array.c
@@ -37,7 +37,7 @@ extern NODE **is_integer(NODE *symbol, NODE *subs);
* THRESHOLD --- Maximum capacity waste; THRESHOLD >= 2^(NHAT + 1).
*/
-static int NHAT = 10;
+static size_t NHAT = 10;
static long THRESHOLD;
/*
@@ -203,7 +203,8 @@ cint_lookup(NODE *symbol, NODE *subs)
{
NODE **lhs;
long k;
- int h1 = -1, m, li;
+ int h1 = -1;
+ size_t m, li;
NODE *tn, *xn;
long cint_size, capacity;
@@ -398,20 +399,20 @@ xremove:
static NODE **
cint_copy(NODE *symbol, NODE *newsymb)
{
- NODE **old, **new;
+ NODE **old, **newtab;
size_t i;
assert(symbol->nodes != NULL);
/* allocate new table */
- ezalloc(new, NODE **, INT32_BIT * sizeof(NODE *), "cint_copy");
+ ezalloc(newtab, NODE **, INT32_BIT * sizeof(NODE *), "cint_copy");
old = symbol->nodes;
for (i = NHAT; i < INT32_BIT; i++) {
if (old[i] == NULL)
continue;
- new[i] = make_node(Node_array_tree);
- tree_copy(newsymb, old[i], new[i]);
+ newtab[i] = make_node(Node_array_tree);
+ tree_copy(newsymb, old[i], newtab[i]);
}
if (symbol->xarray != NULL) {
@@ -424,7 +425,7 @@ cint_copy(NODE *symbol, NODE *newsymb)
} else
newsymb->xarray = NULL;
- newsymb->nodes = new;
+ newsymb->nodes = newtab;
newsymb->table_size = symbol->table_size;
newsymb->array_capacity = symbol->array_capacity;
newsymb->flags = symbol->flags;
@@ -440,10 +441,11 @@ cint_list(NODE *symbol, NODE *t)
{
NODE **list = NULL;
NODE *tn, *xn;
- unsigned long k = 0, num_elems, list_size;
+ unsigned long k = 0, list_size;
+ long num_elems;
size_t j, ja, jd;
int elem_size = 1;
- assoc_kind_t assoc_kind;
+ int assoc_kind;
num_elems = symbol->table_size;
if (num_elems == 0)
@@ -482,7 +484,7 @@ cint_list(NODE *symbol, NODE *t)
tn = symbol->nodes[j];
if (tn == NULL)
continue;
- k += tree_list(tn, list + k, assoc_kind);
+ k += tree_list(tn, list + k, (assoc_kind_t) assoc_kind);
if (k >= list_size)
return list;
}
@@ -523,7 +525,7 @@ cint_dump(NODE *symbol, NODE *ndump)
fprintf(output_fp, "flags: %s\n", flags2str(symbol->flags));
}
indent(indent_level);
- fprintf(output_fp, "NHAT: %d\n", NHAT);
+ fprintf(output_fp, "NHAT: %lu\n", NHAT);
indent(indent_level);
fprintf(output_fp, "THRESHOLD: %ld\n", THRESHOLD);
indent(indent_level);
@@ -742,8 +744,8 @@ tree_lookup(NODE *symbol, NODE *tree, long k, int m, long base)
{
NODE **lhs;
NODE *tn;
- int i, n;
- size_t size;
+ int i;
+ size_t size, n;
long num = k;
/*
@@ -765,7 +767,7 @@ tree_lookup(NODE *symbol, NODE *tree, long k, int m, long base)
tree->array_base = base;
tree->array_size = size;
tree->table_size = 0; /* # of elements in the array */
- if (n > m/2) {
+ if (n > ((unsigned)m)/2) {
/* only first half of the array used */
actual_size /= 2;
tree->flags |= HALFHAT;
@@ -936,15 +938,15 @@ tree_list(NODE *tree, NODE **list, assoc_kind_t assoc_kind)
static void
tree_copy(NODE *newsymb, NODE *tree, NODE *newtree)
{
- NODE **old, **new;
+ NODE **old, **newtab;
size_t j, hsize;
hsize = tree->array_size;
if ((tree->flags & HALFHAT) != 0)
hsize /= 2;
- ezalloc(new, NODE **, hsize * sizeof(NODE *), "tree_copy");
- newtree->nodes = new;
+ ezalloc(newtab, NODE **, hsize * sizeof(NODE *), "tree_copy");
+ newtree->nodes = newtab;
newtree->array_base = tree->array_base;
newtree->array_size = tree->array_size;
newtree->table_size = tree->table_size;
@@ -955,11 +957,11 @@ tree_copy(NODE *newsymb, NODE *tree, NODE *newtree)
if (old[j] == NULL)
continue;
if (old[j]->type == Node_array_tree) {
- new[j] = make_node(Node_array_tree);
- tree_copy(newsymb, old[j], new[j]);
+ newtab[j] = make_node(Node_array_tree);
+ tree_copy(newsymb, old[j], newtab[j]);
} else {
- new[j] = make_node(Node_array_leaf);
- leaf_copy(newsymb, old[j], new[j]);
+ newtab[j] = make_node(Node_array_leaf);
+ leaf_copy(newsymb, old[j], newtab[j]);
}
}
}
@@ -1136,12 +1138,12 @@ leaf_remove(NODE *symbol, NODE *array, long k)
static void
leaf_copy(NODE *newsymb, NODE *array, NODE *newarray)
{
- NODE **old, **new;
+ NODE **old, **newtab;
long size, i;
size = array->array_size;
- ezalloc(new, NODE **, size * sizeof(NODE *), "leaf_copy");
- newarray->nodes = new;
+ ezalloc(newtab, NODE **, size * sizeof(NODE *), "leaf_copy");
+ newarray->nodes = newtab;
newarray->array_size = size;
newarray->array_base = array->array_base;
newarray->flags = array->flags;
@@ -1152,13 +1154,13 @@ leaf_copy(NODE *newsymb, NODE *array, NODE *newarray)
if (old[i] == NULL)
continue;
if (old[i]->type == Node_val)
- new[i] = dupnode(old[i]);
+ newtab[i] = dupnode(old[i]);
else {
NODE *r;
r = make_array();
r->vname = estrdup(old[i]->vname, strlen(old[i]->vname));
r->parent_array = newsymb;
- new[i] = assoc_copy(old[i], r);
+ newtab[i] = assoc_copy(old[i], r);
}
}
}
diff --git a/debug.c b/debug.c
index a0ce09b5..eb0a59a1 100644
--- a/debug.c
+++ b/debug.c
@@ -594,7 +594,8 @@ print_lines(char *src, int start_line, int nlines)
}
for (i = start_line; i < start_line + nlines; i++) {
- int supposed_len, len;
+ int supposed_len;
+ size_t len;
char *p;
sprintf(linebuf, "%-8d", i);
@@ -624,7 +625,7 @@ print_lines(char *src, int start_line, int nlines)
supposed_len = pos[i] - pos[i - 1];
len = read(s->fd, p, supposed_len);
switch (len) {
- case -1:
+ case (size_t) -1:
d_error(_("cannot read source file `%s': %s"),
src, strerror(errno));
return -1;
@@ -1091,8 +1092,7 @@ print_array(volatile NODE *arr, char *arr_name)
{
NODE *subs;
NODE **list;
- int i;
- size_t num_elems = 0;
+ size_t i, num_elems = 0;
volatile NODE *r;
volatile int ret = 0;
volatile jmp_buf pager_quit_tag_stack;
@@ -1661,7 +1661,7 @@ find_subscript(struct list_item *item, NODE **ptr)
/* cmp_val --- compare values of watched item, returns true if different; */
static int
-cmp_val(struct list_item *w, NODE *old, NODE *new)
+cmp_val(struct list_item *w, NODE *old, NODE *new_val)
{
/*
* case old new result
@@ -1679,26 +1679,26 @@ cmp_val(struct list_item *w, NODE *old, NODE *new)
if (WATCHING_ARRAY(w)) {
long size = 0;
- if (! new) /* 9 */
+ if (! new_val) /* 9 */
return true;
- if (new->type == Node_val) /* 7 */
+ if (new_val->type == Node_val) /* 7 */
return true;
- /* new->type == Node_var_array */ /* 8 */
- size = assoc_length(new);
+ /* new_val->type == Node_var_array */ /* 8 */
+ size = assoc_length(new_val);
if (w->cur_size == size)
return false;
return true;
}
- if (! old && ! new) /* 3 */
+ if (! old && ! new_val) /* 3 */
return false;
- if ((! old && new) /* 1, 2 */
- || (old && ! new)) /* 6 */
+ if ((! old && new_val) /* 1, 2 */
+ || (old && ! new_val)) /* 6 */
return true;
- if (new->type == Node_var_array) /* 5 */
+ if (new_val->type == Node_var_array) /* 5 */
return true;
- return cmp_nodes(old, new, true); /* 4 */
+ return cmp_nodes(old, new_val, true); /* 4 */
}
/* watchpoint_triggered --- check if we should stop at this watchpoint;
@@ -4356,7 +4356,7 @@ gprintf(FILE *fp, const char *format, ...)
static size_t buflen = 0;
static int bl = 0;
char *p, *q;
- int nchar;
+ size_t nchar;
#define GPRINTF_BUFSIZ 512
if (buf == NULL) {
@@ -4388,11 +4388,11 @@ gprintf(FILE *fp, const char *format, ...)
bl = 0;
for (p = buf; (q = strchr(p, '\n')) != NULL; p = q + 1) {
- int sz = (int) (q - p);
+ size_t sz = (q - p);
while (sz > 0) {
- int cnt;
- cnt = sz > screen_width ? screen_width : sz;
+ size_t cnt;
+ cnt = sz > ((size_t) screen_width) ? screen_width : sz;
/* do not print partial line before scrolling */
if (cnt < sz && (pager_lines_printed == (screen_height - 2)))
diff --git a/eval.c b/eval.c
index b46e3aae..5e414944 100644
--- a/eval.c
+++ b/eval.c
@@ -27,6 +27,8 @@
#include "awk.h"
#include <math.h>
+#include <math.h>
+
NODE **fcall_list = NULL;
long fcall_count = 0;
int currule = 0;
@@ -263,8 +265,8 @@ static const char *const nodetypes[] = {
*/
static struct optypetab {
- char *desc;
- char *operator;
+ const char *desc;
+ const char *oper;
} optypes[] = {
{ "Op_illegal", NULL },
{ "Op_times", " * " },
@@ -423,8 +425,8 @@ const char *
op2str(OPCODE op)
{
if (op >= Op_illegal && op < Op_final) {
- if (optypes[(int) op].operator != NULL)
- return optypes[(int) op].operator;
+ if (optypes[(int) op].oper != NULL)
+ return optypes[(int) op].oper;
else
fatal(_("opcode %s not an operator or keyword"),
optypes[(int) op].desc);
@@ -827,7 +829,7 @@ set_OFS()
if (OFS == NULL)
emalloc(OFS, char *, new_ofs_len + 1, "set_OFS");
- else if (OFSlen < new_ofs_len)
+ else if ((size_t) OFSlen < new_ofs_len)
erealloc(OFS, char *, new_ofs_len + 1, "set_OFS");
memcpy(OFS, OFS_node->var_value->stptr, OFS_node->var_value->stlen);
diff --git a/field.c b/field.c
index 6d07faab..31c074b1 100644
--- a/field.c
+++ b/field.c
@@ -314,12 +314,12 @@ set_record(const char *buf, size_t cnt, const awk_fieldwidth_info_t *fw)
* to place a sentinel at the end, we make sure
* databuf_size is > cnt after allocation.
*/
- if (cnt >= databuf_size) {
+ if ((unsigned long) cnt >= databuf_size) {
do {
if (databuf_size > MAX_SIZE/2)
fatal(_("input record too large"));
databuf_size *= 2;
- } while (cnt >= databuf_size);
+ } while ((unsigned long) cnt >= databuf_size);
erealloc(databuf, char *, databuf_size, "set_record");
memset(databuf, '\0', databuf_size);
}
@@ -923,7 +923,7 @@ fw_parse_field(long up_to, /* parse only up to this field number */
bool in_middle ATTRIBUTE_UNUSED)
{
char *scan = *buf;
- long nf = parse_high_water;
+ unsigned long nf = parse_high_water;
char *end = scan + len;
const awk_fieldwidth_info_t *fw;
mbstate_t mbs;
@@ -944,7 +944,7 @@ fw_parse_field(long up_to, /* parse only up to this field number */
* in practice.
*/
memset(&mbs, 0, sizeof(mbstate_t));
- while (nf < up_to && scan < end) {
+ while (nf < (unsigned long) up_to && scan < end) {
if (nf >= fw->nf) {
*buf = end;
return nf;
@@ -955,17 +955,17 @@ fw_parse_field(long up_to, /* parse only up to this field number */
scan += flen;
}
} else {
- while (nf < up_to && scan < end) {
+ while (nf < (unsigned long) up_to && scan < end) {
if (nf >= fw->nf) {
*buf = end;
return nf;
}
skiplen = fw->fields[nf].skip;
- if (skiplen > end - scan)
+ if (skiplen > (size_t) (end - scan))
skiplen = end - scan;
scan += skiplen;
flen = fw->fields[nf].len;
- if (flen > end - scan)
+ if (flen > (size_t) (end - scan))
flen = end - scan;
(*set)(++nf, scan, (long) flen, n);
scan += flen;
diff --git a/gawkapi.c b/gawkapi.c
index ab951591..ea66d63c 100644
--- a/gawkapi.c
+++ b/gawkapi.c
@@ -178,7 +178,7 @@ awk_value_to_node(const awk_value_t *retval)
mpfr_init(ext_ret_val->mpg_numbr);
tval = mpfr_set(ext_ret_val->mpg_numbr, (mpfr_srcptr) retval->num_ptr, ROUND_MODE);
IEEE_FMT(ext_ret_val->mpg_numbr, tval);
- mpfr_clear(retval->num_ptr);
+ mpfr_clear((mpfr_ptr) retval->num_ptr);
#else
fatal(_("awk_value_to_node: MPFR not supported"));
#endif
@@ -190,7 +190,7 @@ awk_value_to_node(const awk_value_t *retval)
ext_ret_val = make_number_node(MPZN);
mpz_init(ext_ret_val->mpg_i);
mpz_set(ext_ret_val->mpg_i, (mpz_ptr) retval->num_ptr);
- mpz_clear(retval->num_ptr);
+ mpz_clear((mpz_ptr) retval->num_ptr);
#else
fatal(_("awk_value_to_node: MPFR not supported"));
#endif
@@ -1241,7 +1241,7 @@ api_flatten_array_typed(awk_ext_id_t id,
awk_valtype_t index_type, awk_valtype_t value_type)
{
NODE **list;
- size_t i, j;
+ int i, j;
NODE *array = (NODE *) a_cookie;
size_t alloc_size;
@@ -1303,7 +1303,7 @@ api_release_flattened_array(awk_ext_id_t id,
|| array->type != Node_var_array
|| data == NULL
|| array != (NODE *) data->opaque1
- || data->count != array->table_size
+ || (int)data->count != array->table_size
|| data->opaque2 == NULL)
return awk_false;
@@ -1434,7 +1434,7 @@ api_get_file(awk_ext_id_t id, const char *name, size_t namelen, const char *file
currule = save_rule;
source = save_source;
}
- *ibufp = &curfile->public;
+ *ibufp = &curfile->public_;
*obufp = NULL;
return awk_true;
@@ -1483,7 +1483,7 @@ api_get_file(awk_ext_id_t id, const char *name, size_t namelen, const char *file
if ((f = redirect_string(name, namelen, 0, redirtype, &flag, fd, false)) == NULL)
return awk_false;
- *ibufp = f->iop ? & f->iop->public : NULL;
+ *ibufp = f->iop ? & f->iop->public_ : NULL;
*obufp = f->output.fp ? & f->output : NULL;
return awk_true;
}
diff --git a/gawkapi.h b/gawkapi.h
index 3047c753..10a33d89 100644
--- a/gawkapi.h
+++ b/gawkapi.h
@@ -132,14 +132,16 @@ typedef enum awk_bool {
* 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.
*/
+struct awk_field_info {
+ size_t skip; /* amount to skip before field starts */
+ size_t len; /* length of field */
+};
typedef struct {
awk_bool_t use_chars; /* false ==> use bytes */
size_t nf;
- struct awk_field_info {
- size_t skip; /* amount to skip before field starts */
- size_t len; /* length of field */
- } fields[1]; /* actual dimension should be nf */
+ /* actual dimension should be nf */
+ struct awk_field_info fields[1];
} awk_fieldwidth_info_t;
/*
@@ -411,14 +413,15 @@ typedef struct awk_value {
* one at a time, using the separate API for that purpose.
*/
+enum awk_element_actions {
+ AWK_ELEMENT_DEFAULT = 0, /* set by gawk */
+ AWK_ELEMENT_DELETE = 1 /* set by extension if
+ should be deleted */
+};
typedef struct awk_element {
/* convenience linked list pointer, not used by gawk */
struct awk_element *next;
- enum {
- AWK_ELEMENT_DEFAULT = 0, /* set by gawk */
- AWK_ELEMENT_DELETE = 1 /* set by extension if
- should be deleted */
- } flags;
+ enum awk_element_actions flags;
awk_value_t index;
awk_value_t value;
} awk_element_t;
diff --git a/int_array.c b/int_array.c
index 3a1c5966..9a982fb8 100644
--- a/int_array.c
+++ b/int_array.c
@@ -312,7 +312,7 @@ static NODE **
int_clear(NODE *symbol, NODE *subs ATTRIBUTE_UNUSED)
{
unsigned long i;
- int j;
+ size_t j;
BUCKET *b, *next;
NODE *r;
@@ -354,7 +354,7 @@ int_remove(NODE *symbol, NODE *subs)
uint32_t hash1;
BUCKET *b, *prev = NULL;
long k;
- int i;
+ size_t i;
NODE *xn = symbol->xarray;
if (symbol->table_size == 0 || symbol->buckets == NULL)
@@ -447,9 +447,9 @@ removed:
static NODE **
int_copy(NODE *symbol, NODE *newsymb)
{
- BUCKET **old, **new, **pnew;
+ BUCKET **old, **newtab, **pnew;
BUCKET *chain, *newchain;
- int j;
+ size_t j;
unsigned long i, cursize;
assert(symbol->buckets != NULL);
@@ -458,12 +458,12 @@ int_copy(NODE *symbol, NODE *newsymb)
cursize = symbol->array_size;
/* allocate new table */
- ezalloc(new, BUCKET **, cursize * sizeof(BUCKET *), "int_copy");
+ ezalloc(newtab, BUCKET **, cursize * sizeof(BUCKET *), "int_copy");
old = symbol->buckets;
for (i = 0; i < cursize; i++) {
- for (chain = old[i], pnew = & new[i]; chain != NULL;
+ for (chain = old[i], pnew = & newtab[i]; chain != NULL;
chain = chain->ainext
) {
getbucket(newchain);
@@ -507,7 +507,7 @@ int_copy(NODE *symbol, NODE *newsymb)
newsymb->xarray = NULL;
newsymb->table_size = symbol->table_size;
- newsymb->buckets = new;
+ newsymb->buckets = newtab;
newsymb->array_size = cursize;
newsymb->flags = symbol->flags;
@@ -521,10 +521,12 @@ static NODE**
int_list(NODE *symbol, NODE *t)
{
NODE **list = NULL;
- unsigned long num_elems, list_size, i, k = 0;
+ unsigned long list_size, i, k = 0;
+ long num_elems;
BUCKET *b;
NODE *r, *subs, *xn;
- int j, elem_size = 1;
+ int elem_size = 1;
+ size_t j;
long num;
static char buf[100];
assoc_kind_t assoc_kind;
@@ -758,7 +760,7 @@ static inline NODE **
int_find(NODE *symbol, long k, uint32_t hash1)
{
BUCKET *b;
- int i;
+ size_t i;
assert(symbol->buckets != NULL);
for (b = symbol->buckets[hash1]; b != NULL; b = b->ainext) {
@@ -803,9 +805,9 @@ int_insert(NODE *symbol, long k, uint32_t hash1)
static void
grow_int_table(NODE *symbol)
{
- BUCKET **old, **new;
+ BUCKET **old, **newtab;
BUCKET *chain, *next;
- int i, j;
+ size_t i, j;
unsigned long oldsize, newsize, k;
/*
@@ -841,10 +843,10 @@ grow_int_table(NODE *symbol)
}
/* allocate new table */
- ezalloc(new, BUCKET **, newsize * sizeof(BUCKET *), "grow_int_table");
+ ezalloc(newtab, BUCKET **, newsize * sizeof(BUCKET *), "grow_int_table");
old = symbol->buckets;
- symbol->buckets = new;
+ symbol->buckets = newtab;
symbol->array_size = newsize;
/* brand new hash table */
diff --git a/interpret.h b/interpret.h
index 9ffa5bbd..b4ed887e 100644
--- a/interpret.h
+++ b/interpret.h
@@ -1431,7 +1431,7 @@ match_re:
update_ERRNO_int(errcode);
if (do_traditional || ! pc->has_endfile)
fatal(_("error reading input file `%s': %s"),
- curfile->public.name, strerror(errcode));
+ curfile->public_.name, strerror(errcode));
}
JUMPTO(ni);
diff --git a/io.c b/io.c
index c595c009..3127a5f5 100644
--- a/io.c
+++ b/io.c
@@ -197,7 +197,7 @@
#define at_eof(iop) (((iop)->flag & IOP_AT_EOF) != 0)
#define has_no_data(iop) ((iop)->dataend == NULL)
#define no_data_left(iop) ((iop)->off >= (iop)->dataend)
-#define buffer_has_all_data(iop) ((iop)->dataend - (iop)->off == (iop)->public.sbuf.st_size)
+#define buffer_has_all_data(iop) ((iop)->dataend - (iop)->off == (iop)->public_.sbuf.st_size)
/*
* The key point to the design is to split out the code that searches through
@@ -406,7 +406,7 @@ after_beginfile(IOBUF **curfile)
int errcode;
bool valid;
- fname = iop->public.name;
+ fname = iop->public_.name;
errcode = iop->errcode;
valid = iop->valid;
errno = 0;
@@ -451,7 +451,7 @@ nextfile(IOBUF **curfile, bool skipping)
if (iop != NULL) {
if (at_eof(iop)) {
- assert(iop->public.fd != INVALID_HANDLE);
+ assert(iop->public_.fd != INVALID_HANDLE);
(void) iop_close(iop);
*curfile = NULL;
return 1; /* run endfile block */
@@ -498,7 +498,7 @@ nextfile(IOBUF **curfile, bool skipping)
update_ERRNO_int(errno);
iop = iop_alloc(fd, fname, errcode);
*curfile = iop_finish(iop);
- if (iop->public.fd == INVALID_HANDLE)
+ if (iop->public_.fd == INVALID_HANDLE)
iop->errcode = errcode;
else if (iop->valid)
iop->errcode = 0;
@@ -525,7 +525,7 @@ nextfile(IOBUF **curfile, bool skipping)
iop = iop_alloc(fileno(stdin), fname, 0);
*curfile = iop_finish(iop);
- if (iop->public.fd == INVALID_HANDLE) {
+ if (iop->public_.fd == INVALID_HANDLE) {
errcode = errno;
errno = 0;
update_ERRNO_int(errno);
@@ -645,21 +645,21 @@ iop_close(IOBUF *iop)
* So we remap the standard file to /dev/null.
* Thanks to Jim Meyering for the suggestion.
*/
- if (iop->public.close_func != NULL)
- iop->public.close_func(&iop->public);
-
- if (iop->public.fd != INVALID_HANDLE) {
- if (iop->public.fd == fileno(stdin)
- || iop->public.fd == fileno(stdout)
- || iop->public.fd == fileno(stderr))
- ret = remap_std_file(iop->public.fd);
+ if (iop->public_.close_func != NULL)
+ iop->public_.close_func(&iop->public_);
+
+ if (iop->public_.fd != INVALID_HANDLE) {
+ if (iop->public_.fd == fileno(stdin)
+ || iop->public_.fd == fileno(stdout)
+ || iop->public_.fd == fileno(stderr))
+ ret = remap_std_file(iop->public_.fd);
else
- ret = closemaybesocket(iop->public.fd);
+ ret = closemaybesocket(iop->public_.fd);
}
if (ret == -1)
- warning(_("close of fd %d (`%s') failed: %s"), iop->public.fd,
- iop->public.name, strerror(errno));
+ warning(_("close of fd %d (`%s') failed: %s"), iop->public_.fd,
+ iop->public_.name, strerror(errno));
/*
* Be careful -- $0 may still reference the buffer even though
* an explicit close is being done; in the future, maybe we
@@ -721,12 +721,12 @@ redflags2str(int flags)
static void
check_duplicated_redirections(const char *name, size_t len,
- redirect_flags_t oldflags, redirect_flags_t newflags)
+ redirect_flags_t oflags, redirect_flags_t nflags)
{
static struct mixture {
- redirect_flags_t common;
- redirect_flags_t mode;
- redirect_flags_t other_mode;
+ int common;
+ int mode;
+ int other_mode;
const char *message;
} mixtures[] = {
{ RED_FILE, RED_READ, RED_WRITE,
@@ -754,6 +754,9 @@ check_duplicated_redirections(const char *name, size_t len,
};
int i = 0, j = sizeof(mixtures) / sizeof(mixtures[0]);
+ int oldflags = oflags;
+ int newflags = nflags;
+
oldflags &= ~(RED_FLUSH|RED_EOF|RED_PTY);
newflags &= ~(RED_FLUSH|RED_EOF|RED_PTY);
@@ -784,8 +787,8 @@ redirect_string(const char *str, size_t explen, bool not_string,
int redirtype, int *errflg, int extfd, bool failure_fatal)
{
struct redirect *rp;
- redirect_flags_t tflag = RED_NONE;
- redirect_flags_t outflag = RED_NONE;
+ int tflag = RED_NONE;
+ int outflag = RED_NONE;
const char *direction = "to";
const char *mode;
int fd;
@@ -1143,7 +1146,7 @@ getredirect(const char *str, int len)
struct redirect *rp;
for (rp = red_head; rp != NULL; rp = rp->next)
- if (strlen(rp->value) == len && memcmp(rp->value, str, len) == 0)
+ if (strlen(rp->value) == (size_t) len && memcmp(rp->value, str, len) == 0)
return rp;
return NULL;
@@ -1327,7 +1330,7 @@ close_rp(struct redirect *rp, two_way_close_type how)
if ((rp->flag & RED_SOCKET) != 0 && rp->iop != NULL) {
#ifdef HAVE_SOCKETS
if ((rp->flag & RED_TCP) != 0)
- (void) shutdown(rp->iop->public.fd, SHUT_RD);
+ (void) shutdown(rp->iop->public_.fd, SHUT_RD);
#endif /* HAVE_SOCKETS */
(void) iop_close(rp->iop);
} else
@@ -2786,7 +2789,7 @@ gawk_popen(const char *cmd, struct redirect *rp)
if (! do_traditional && rp->iop->errcode != 0)
update_ERRNO_int(rp->iop->errcode);
(void) pclose(current);
- rp->iop->public.fd = INVALID_HANDLE;
+ rp->iop->public_.fd = INVALID_HANDLE;
iop_close(rp->iop);
rp->iop = NULL;
current = NULL;
@@ -2800,10 +2803,10 @@ gawk_popen(const char *cmd, struct redirect *rp)
static int
gawk_pclose(struct redirect *rp)
{
- int rval, aval, fd = rp->iop->public.fd;
+ int rval, aval, fd = rp->iop->public_.fd;
if (rp->iop != NULL) {
- rp->iop->public.fd = dup(fd); /* kludge to allow close() + pclose() */
+ rp->iop->public_.fd = dup(fd); /* kludge to allow close() + pclose() */
rval = iop_close(rp->iop);
}
rp->iop = NULL;
@@ -3193,12 +3196,12 @@ find_input_parser(IOBUF *iop)
awk_input_parser_t *ip, *ip2;
/* if already associated with an input parser, bail out early */
- if (iop->public.get_record != NULL || iop->public.read_func != read)
+ if (iop->public_.get_record != NULL || iop->public_.read_func != read)
return;
ip = ip2 = NULL;
for (ip2 = ip_head; ip2 != NULL; ip2 = ip2->next) {
- if (ip2->can_take_file(& iop->public)) {
+ if (ip2->can_take_file(& iop->public_)) {
if (ip == NULL)
ip = ip2; /* found first one */
else
@@ -3208,9 +3211,9 @@ find_input_parser(IOBUF *iop)
}
if (ip != NULL) {
- if (! ip->take_control_of(& iop->public))
+ if (! ip->take_control_of(& iop->public_))
warning(_("input parser `%s' failed to open `%s'"),
- ip->name, iop->public.name);
+ ip->name, iop->public_.name);
else
iop->valid = true;
}
@@ -3304,7 +3307,7 @@ find_two_way_processor(const char *name, struct redirect *rp)
awk_two_way_processor_t *tw, *tw2;
/* if already associated with i/o, bail out early */
- if ( (rp->iop != NULL && rp->iop->public.fd != INVALID_HANDLE)
+ if ( (rp->iop != NULL && rp->iop->public_.fd != INVALID_HANDLE)
|| rp->output.fp != NULL)
return false;
@@ -3322,7 +3325,7 @@ find_two_way_processor(const char *name, struct redirect *rp)
if (tw != NULL) {
if (rp->iop == NULL)
rp->iop = iop_alloc(INVALID_HANDLE, name, 0);
- if (! tw->take_control_of(name, & rp->iop->public, & rp->output)) {
+ if (! tw->take_control_of(name, & rp->iop->public_, & rp->output)) {
warning(_("two way processor `%s' failed to open `%s'"),
tw->name, name);
return false;
@@ -3361,12 +3364,12 @@ find_two_way_processor(const char *name, struct redirect *rp)
* iop->valid should be set to false in this case.
*
* Otherwise, after the second stage, iop->errcode should be
- * zero, iop->valid should be true, and iop->public.fd should
+ * zero, iop->valid should be true, and iop->public_.fd should
* not be INVALID_HANDLE.
*
* The third stage is to set up the rest of the IOBUF for
* use by get_a_record(). In this case, iop->valid must
- * be true already, and iop->public.fd cannot be INVALID_HANDLE.
+ * be true already, and iop->public_.fd cannot be INVALID_HANDLE.
*
* Checking for input parsers for command line files is delayed
* to after_beginfile() so that the BEGINFILE rule has an
@@ -3384,14 +3387,14 @@ iop_alloc(int fd, const char *name, int errno_val)
ezalloc(iop, IOBUF *, sizeof(IOBUF), "iop_alloc");
- iop->public.fd = fd;
- iop->public.name = name;
- iop->public.read_func = ( ssize_t(*)() ) read;
+ iop->public_.fd = fd;
+ iop->public_.name = name;
+ iop->public_.read_func = ( ssize_t(*)(int, void *, size_t) ) read;
iop->valid = false;
iop->errcode = errno_val;
if (fd != INVALID_HANDLE)
- fstat(fd, & iop->public.sbuf);
+ fstat(fd, & iop->public_.sbuf);
else {
#ifdef HAVE_LSTAT
int (*statf)(const char *, struct stat *) = lstat;
@@ -3402,8 +3405,8 @@ iop_alloc(int fd, const char *name, int errno_val)
* Try to fill in the stat struct. If it fails, zero
* it out.
*/
- if (statf(name, & iop->public.sbuf) < 0)
- memset(& iop->public.sbuf, 0, sizeof(struct stat));
+ if (statf(name, & iop->public_.sbuf) < 0)
+ memset(& iop->public_.sbuf, 0, sizeof(struct stat));
}
return iop;
@@ -3416,8 +3419,8 @@ iop_finish(IOBUF *iop)
{
bool isdir = false;
- if (iop->public.fd != INVALID_HANDLE) {
- if (os_isreadable(& iop->public, & isdir))
+ if (iop->public_.fd != INVALID_HANDLE) {
+ if (os_isreadable(& iop->public_, & isdir))
iop->valid = true;
else {
if (isdir)
@@ -3434,10 +3437,10 @@ iop_finish(IOBUF *iop)
* The fcntl call works for Windows, too.
*/
#if defined(F_GETFL)
- if (fcntl(iop->public.fd, F_GETFL) >= 0)
+ if (fcntl(iop->public_.fd, F_GETFL) >= 0)
#endif
- (void) close(iop->public.fd);
- iop->public.fd = INVALID_HANDLE;
+ (void) close(iop->public_.fd);
+ iop->public_.fd = INVALID_HANDLE;
}
/*
* Don't close directories: after_beginfile(),
@@ -3446,15 +3449,15 @@ iop_finish(IOBUF *iop)
}
}
- if (! iop->valid || iop->public.fd == INVALID_HANDLE)
+ if (! iop->valid || iop->public_.fd == INVALID_HANDLE)
return iop;
- if (os_isatty(iop->public.fd))
+ if (os_isatty(iop->public_.fd))
iop->flag |= IOP_IS_TTY;
- iop->readsize = iop->size = optimal_bufsize(iop->public.fd, & iop->public.sbuf);
- if (do_lint && S_ISREG(iop->public.sbuf.st_mode) && iop->public.sbuf.st_size == 0)
- lintwarn(_("data file `%s' is empty"), iop->public.name);
+ iop->readsize = iop->size = optimal_bufsize(iop->public_.fd, & iop->public_.sbuf);
+ if (do_lint && S_ISREG(iop->public_.sbuf.st_mode) && iop->public_.sbuf.st_size == 0)
+ lintwarn(_("data file `%s' is empty"), iop->public_.name);
iop->errcode = errno = 0;
iop->count = iop->scanoff = 0;
emalloc(iop->buf, char *, iop->size += 1, "iop_finish");
@@ -3747,7 +3750,7 @@ again:
if (RSre->maybe_long) {
char *matchend = iop->off + reend;
- if (iop->dataend - matchend < RS->stlen)
+ if ((size_t) (iop->dataend - matchend) < RS->stlen)
return TERMNEAREND;
}
@@ -3885,7 +3888,7 @@ csvscan(IOBUF *iop, struct recmatch *recm, SCANSTATE *state)
static inline int
retryable(IOBUF *iop)
{
- return PROCINFO_node && in_PROCINFO(iop->public.name, "RETRY", NULL);
+ return PROCINFO_node && in_PROCINFO(iop->public_.name, "RETRY", NULL);
}
/* errno_io_retry --- Does the I/O error indicate that the operation should be retried later? */
@@ -3941,10 +3944,10 @@ get_a_record(char **out, /* pointer to pointer to data */
if (read_can_timeout)
read_timeout = get_read_timeout(iop);
- if (iop->public.get_record != NULL) {
+ if (iop->public_.get_record != NULL) {
char *rt_start;
size_t rt_len;
- int rc = iop->public.get_record(out, &iop->public, errcode,
+ int rc = iop->public_.get_record(out, &iop->public_, errcode,
&rt_start, &rt_len,
field_width);
if (rc == EOF)
@@ -3963,7 +3966,7 @@ get_a_record(char **out, /* pointer to pointer to data */
/* fill initial buffer */
if (has_no_data(iop) || no_data_left(iop)) {
- iop->count = iop->public.read_func(iop->public.fd, iop->buf, iop->readsize);
+ iop->count = iop->public_.read_func(iop->public_.fd, iop->buf, iop->readsize);
if (iop->count == 0) {
iop->flag |= IOP_AT_EOF;
return EOF;
@@ -4042,7 +4045,7 @@ get_a_record(char **out, /* pointer to pointer to data */
amt_to_read = MIN(amt_to_read, SSIZE_MAX);
#endif
- iop->count = iop->public.read_func(iop->public.fd, iop->dataend, amt_to_read);
+ iop->count = iop->public_.read_func(iop->public_.fd, iop->dataend, amt_to_read);
if (iop->count == -1) {
*errcode = errno;
if (errno_io_retry() && retryable(iop))
@@ -4421,7 +4424,7 @@ get_read_timeout(IOBUF *iop)
long tmout = 0;
if (PROCINFO_node != NULL) {
- const char *name = iop->public.name;
+ const char *name = iop->public_.name;
NODE *val = NULL;
static NODE *full_idx = NULL;
static const char *last_name = NULL;
@@ -4446,8 +4449,8 @@ get_read_timeout(IOBUF *iop)
tmout = read_default_timeout; /* initialized from env. variable in init_io() */
/* overwrite read routine only if an extension has not done so */
- if ((iop->public.read_func == ( ssize_t(*)() ) read) && tmout > 0)
- iop->public.read_func = read_with_timeout;
+ if ((iop->public_.read_func == ( ssize_t(*)(int, void *, size_t) ) read) && tmout > 0)
+ iop->public_.read_func = read_with_timeout;
return tmout;
}
diff --git a/main.c b/main.c
index b177663b..72fe0dcc 100644
--- a/main.c
+++ b/main.c
@@ -117,8 +117,9 @@ SRCFILE *srcfiles; /* source files */
/*
* structure to remember variable pre-assignments
*/
+enum assign_type { PRE_ASSIGN = 1, PRE_ASSIGN_FS } type;
struct pre_assign {
- enum assign_type { PRE_ASSIGN = 1, PRE_ASSIGN_FS } type;
+ enum assign_type type;
char *val;
};
@@ -134,7 +135,7 @@ static void set_locale_stuff(void);
static bool stopped_early = false;
bool using_persistent_malloc = false;
-enum do_flag_values do_flags = DO_FLAG_NONE;
+int do_flags = DO_FLAG_NONE;
bool do_itrace = false; /* provide simple instruction trace */
bool do_optimize = true; /* apply default optimizations */
static int do_nostalgia = false; /* provide a blast from the past */
@@ -1769,7 +1770,7 @@ parse_args(int argc, char **argv)
case 'T': // --persist[=file]
#ifdef USE_PERSISTENT_MALLOC
if (optarg == NULL)
- optarg = "/some/file";
+ optarg = (char *) "/some/file";
fatal(_("Use `GAWK_PERSIST_FILE=%s gawk ...' instead of --persist."), optarg);
#else
warning(_("Persistent memory is not supported."));
@@ -1943,7 +1944,7 @@ check_pma_security(const char *pma_file)
} else if (euid == 0) {
fprintf(stderr, _("%s: fatal: using persistent memory is not allowed when running as root.\n"), myname);
exit(EXIT_FATAL);
- } else if (sbuf.st_uid != euid) {
+ } else if (sbuf.st_uid != (uid_t) euid) {
fprintf(stderr, _("%s: warning: %s is not owned by euid %d.\n"),
myname, pma_file, euid);
}
diff --git a/mpfr.c b/mpfr.c
index 21bac6cd..f82cb5e7 100644
--- a/mpfr.c
+++ b/mpfr.c
@@ -1442,7 +1442,7 @@ mpg_tofloat(mpfr_ptr mf, mpz_ptr mz)
* Always set the precision to avoid hysteresis, since do_mpfr_func
* may copy our precision.
*/
- if (prec != mpfr_get_prec(mf))
+ if (prec != (size_t) mpfr_get_prec(mf))
mpfr_set_prec(mf, prec);
mpfr_set_z(mf, mz, ROUND_MODE);
diff --git a/msg.c b/msg.c
index 3967d4ab..ba926832 100644
--- a/msg.c
+++ b/msg.c
@@ -157,6 +157,9 @@ set_loc(const char *file, int line)
/* r_fatal --- print a fatal error message */
+#ifdef __cplusplus
+extern "C"
+#endif /* __cplusplus */
void
r_fatal(const char *mesg, ...)
{
diff --git a/node.c b/node.c
index 2a476847..b637e858 100644
--- a/node.c
+++ b/node.c
@@ -279,7 +279,7 @@ r_format_val(const char *format, int index, NODE *s)
*/
long num = (long) val;
- if (num < NVAL && num >= 0) {
+ if (num < (long) NVAL && num >= 0) {
sp = (char *) values[num];
s->stlen = 1;
} else {
diff --git a/profile.c b/profile.c
index aa091c58..7f8f20b7 100644
--- a/profile.c
+++ b/profile.c
@@ -62,7 +62,7 @@ static NODE *pp_stack = NULL;
static NODE *func_params; /* function parameters */
static FILE *prof_fp; /* where to send the profile */
-static long indent_level = 0;
+static size_t indent_level = 0;
static const char tabs[] = "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t";
static const size_t tabs_len = sizeof(tabs) - 1;
@@ -132,7 +132,7 @@ init_profiling_signals()
static void
indent(exec_count_t count)
{
- int i;
+ size_t i;
if (do_profile) {
if (count == 0)
diff --git a/re.c b/re.c
index 3ebf0206..cfb49db6 100644
--- a/re.c
+++ b/re.c
@@ -49,7 +49,7 @@ make_regexp(const char *s, size_t len, bool ignorecase, bool dfa, bool canfatal)
int c, c2;
static bool first = true;
static bool no_dfa = false;
- int i;
+ size_t i;
static struct dfa* dfaregs[2] = { NULL, NULL };
static bool nul_warned = false;
diff --git a/str_array.c b/str_array.c
index 1ff8348f..fb45f0a9 100644
--- a/str_array.c
+++ b/str_array.c
@@ -329,7 +329,7 @@ str_remove(NODE *symbol, NODE *subs)
static NODE **
str_copy(NODE *symbol, NODE *newsymb)
{
- BUCKET **old, **new, **pnew;
+ BUCKET **old, **newtab, **pnew;
BUCKET *chain, *newchain;
unsigned long cursize, i;
@@ -339,12 +339,12 @@ str_copy(NODE *symbol, NODE *newsymb)
cursize = symbol->array_size;
/* allocate new table */
- ezalloc(new, BUCKET **, cursize * sizeof(BUCKET *), "str_copy");
+ ezalloc(newtab, BUCKET **, cursize * sizeof(BUCKET *), "str_copy");
old = symbol->buckets;
for (i = 0; i < cursize; i++) {
- for (chain = old[i], pnew = & new[i]; chain != NULL;
+ for (chain = old[i], pnew = & newtab[i]; chain != NULL;
chain = chain->ahnext
) {
NODE *oldval, *newsubs;
@@ -380,7 +380,7 @@ str_copy(NODE *symbol, NODE *newsymb)
}
newsymb->table_size = symbol->table_size;
- newsymb->buckets = new;
+ newsymb->buckets = newtab;
newsymb->array_size = cursize;
newsymb->flags = symbol->flags;
return NULL;
@@ -640,7 +640,7 @@ str_find(NODE *symbol, NODE *s1, size_t code1, unsigned long hash1)
static void
grow_table(NODE *symbol)
{
- BUCKET **old, **new;
+ BUCKET **old, **newtab;
BUCKET *chain, *next;
int i, j;
unsigned long oldsize, newsize, k;
@@ -679,10 +679,10 @@ grow_table(NODE *symbol)
}
/* allocate new table */
- ezalloc(new, BUCKET **, newsize * sizeof(BUCKET *), "grow_table");
+ ezalloc(newtab, BUCKET **, newsize * sizeof(BUCKET *), "grow_table");
old = symbol->buckets;
- symbol->buckets = new;
+ symbol->buckets = newtab;
symbol->array_size = newsize;
/* brand new hash table, set things up and return */
@@ -704,8 +704,8 @@ grow_table(NODE *symbol)
hash1 = chain->ahcode % newsize;
/* remove from old list, add to new */
- chain->ahnext = new[hash1];
- new[hash1] = chain;
+ chain->ahnext = newtab[hash1];
+ newtab[hash1] = chain;
}
}
efree(old);
@@ -790,7 +790,7 @@ static unsigned long
fnv1a_hash_string(const char *str, size_t len, unsigned long hsize, size_t *code)
{
/* FNV-1a */
- register unsigned ret = 2166136261U;
+ unsigned ret = 2166136261U;
while (len > 0) {
ret ^= (unsigned char) (*str++);
diff --git a/support/localeinfo.h b/support/localeinfo.h
index bd443ef4..239e8dab 100644
--- a/support/localeinfo.h
+++ b/support/localeinfo.h
@@ -49,6 +49,10 @@ struct localeinfo
wint_t sbctowc[UCHAR_MAX + 1];
};
+#ifdef __cplusplus
+extern "C" {
+#endif // __cplusplus
+
extern void init_localeinfo (struct localeinfo *);
/* Maximum number of characters that can be the case-folded
@@ -57,3 +61,7 @@ extern void init_localeinfo (struct localeinfo *);
enum { CASE_FOLDED_BUFSIZE = 32 };
extern int case_folded_counterparts (wint_t, wchar_t[CASE_FOLDED_BUFSIZE]);
+
+#ifdef __cplusplus
+}
+#endif // __cplusplus
diff --git a/support/pma.h b/support/pma.h
index 96b450f2..2d64723b 100644
--- a/support/pma.h
+++ b/support/pma.h
@@ -22,6 +22,10 @@
#ifndef PMA_H_INCLUDED
#define PMA_H_INCLUDED
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
// version strings of interface and implementation should match
#define PMA_H_VERSION "2022.10Oct.30.1667172241 (Avon 8-g1)"
extern const char pma_version[];
@@ -84,4 +88,8 @@ extern void pma_check_and_dump(void);
to be re-sparsified with fallocate (v == 0x0). */
extern void pma_set_avail_mem(const unsigned long v);
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
#endif // PMA_H_INCLUDED
diff --git a/support/random.h b/support/random.h
index a76a3adf..2bbc43f8 100644
--- a/support/random.h
+++ b/support/random.h
@@ -40,7 +40,13 @@ typedef long gawk_int32_t;
#define uint32_t gawk_uint32_t
#define int32_t gawk_int32_t
+#ifdef __cplusplus
+extern "C" {
+#endif // __cplusplus
extern char *initstate(unsigned long seed, char *state, long n);
extern char *setstate(char *state);
extern long random(void);
extern void srandom(unsigned long seed);
+#ifdef __cplusplus
+}
+#endif // __cplusplus