diff options
author | Arnold D. Robbins <arnold@skeeve.com> | 2021-01-08 11:05:32 +0200 |
---|---|---|
committer | Arnold D. Robbins <arnold@skeeve.com> | 2021-01-08 11:05:32 +0200 |
commit | d562eb482f3180dcd59a332edc91027ea3844d90 (patch) | |
tree | d90bb37b1c75a6429d961031b6a3ae08559408c0 | |
parent | b4dc5fb3dc57f7fc7eaba39c5814b8bae9403b77 (diff) | |
download | egawk-d562eb482f3180dcd59a332edc91027ea3844d90.tar.gz egawk-d562eb482f3180dcd59a332edc91027ea3844d90.tar.bz2 egawk-d562eb482f3180dcd59a332edc91027ea3844d90.zip |
Improve use of types throughout.
-rw-r--r-- | ChangeLog | 56 | ||||
-rw-r--r-- | array.c | 3 | ||||
-rw-r--r-- | awk.h | 18 | ||||
-rw-r--r-- | awkgram.c | 6 | ||||
-rw-r--r-- | awkgram.y | 6 | ||||
-rw-r--r-- | builtin.c | 5 | ||||
-rw-r--r-- | cmd.h | 12 | ||||
-rw-r--r-- | command.c | 8 | ||||
-rw-r--r-- | command.y | 8 | ||||
-rw-r--r-- | debug.c | 32 | ||||
-rw-r--r-- | eval.c | 2 | ||||
-rw-r--r-- | floatcomp.c | 1 | ||||
-rw-r--r-- | gawkapi.c | 15 | ||||
-rw-r--r-- | gawkapi.h | 2 | ||||
-rw-r--r-- | interpret.h | 2 | ||||
-rw-r--r-- | io.c | 22 | ||||
-rw-r--r-- | main.c | 6 | ||||
-rw-r--r-- | mpfr.c | 6 | ||||
-rw-r--r-- | node.c | 2 | ||||
-rw-r--r-- | pc/ChangeLog | 8 | ||||
-rw-r--r-- | pc/gawkmisc.pc | 14 | ||||
-rw-r--r-- | posix/ChangeLog | 8 | ||||
-rw-r--r-- | posix/gawkmisc.c | 12 | ||||
-rw-r--r-- | profile.c | 4 | ||||
-rw-r--r-- | re.c | 2 | ||||
-rw-r--r-- | support/ChangeLog | 4 | ||||
-rw-r--r-- | support/random.h | 5 | ||||
-rw-r--r-- | vms/ChangeLog | 8 | ||||
-rw-r--r-- | vms/gawkmisc.vms | 10 |
29 files changed, 188 insertions, 99 deletions
@@ -1,3 +1,59 @@ +2021-01-08 Arnold D. Robbins <arnold@skeeve.com> + + General tightening up use of const and types. Thanks to + the C++ porting experiment. + + * array.c (null_array): Separate out multiple assignment of zero. + * awk.h: Add <math.h> here and pull it out of individual files. + (CONVFMT): Make const char *. + (quote): Make const char *. + (defpath): Make const char *. + (deflibpath): Make const char *. + (envsep): Make const char *. + (DO_FLAG_NONE): New zero enum value. + (getblock): Add a cast to the ty argument. + (make_regnode): First argument is now NODETYPE. + (gawk_name): Returns const char *. + * awkgram.y: Include argument types in read_func pointer. + (make_regnode): First argument is now NODETYPE. + * builtin.c (do_typeof): Use const char *. + (format_nan_inf): Move declaration of val to top of function. + * cmd.h (dbg_prompt, commands_prompt, eval_prompt, dgawk_prompt): + Make const char *. + (struct cmd_token): Use const char *. Rename `class' to `lex_class'. + * command.y (lex_class): Update all uses. + (find_command): Use const char *. + * debug.c (dbg_prompt, commands_prompt, eval_prompt, dgawk_prompt, + output_file): Make const char *. + (struct dbg_option): Use const char *. + (do_info): Use const char *. Cast stop.command to enum argtype. + (do_finish): Cast stop.command to enum argtype. + (do_return, do_until): Ditto. + (print_instruction, set_gawk_output, set_prompt): Add casts to + some function parameters. + * eval.c (update_ERRNO_int): Use const char *. + * gawk.api.c (valtype2str): Return const char *. + (api_get_argument): Use awk_true instead of true in return statements. + (awk_value_to_node): Move declaration of tval to top of function. + (api_release): Cast a_cookie to NODE *. + * gawkapi.h (struct awk_input): Include argument types in + read_func pointer. + * interpret.h (r_interpret): Add cast to argument in call to + do_getline_redir. + * io.c (read_with_timeout): Change second param to void * from char *. + (redirect_string): Add casts to function call parameters. + (path_info): Use const char *. + (init_awkpath): Ditto. + * main.c (CONVFMT, locale_dir): Now const char *. + (do_flags): Init to DO_FLAG_NONE instead of zero. + * mfpr.c (get_rnd_mode): Add cast to return value. + (set_round_mode): Add cast to assignment of rndm. + (do_mpfr_func): Include argument types in type of second parameter. + * node.c (r_make_number): Remove declaration of strtod. + * profile.c (pp_push): Add cast in assignment to n->type. Use + const char * for `pre' at Op_func_call. + * re.c (check_bracket_exp): Add cast to return from memchr. + 2021-01-07 Arnold D. Robbins <arnold@skeeve.com> * builtin.c (format_tree): Generalize handling of invalid @@ -111,7 +111,8 @@ null_array(NODE *symbol) symbol->type = Node_var_array; symbol->array_funcs = & null_array_func; symbol->buckets = NULL; - symbol->table_size = symbol->array_size = 0; + symbol->table_size = 0; + symbol->array_size = 0; symbol->array_capacity = 0; symbol->flags = 0; @@ -52,6 +52,7 @@ #include <limits.h> #include <ctype.h> #include <setjmp.h> +#include <math.h> #include "gettext.h" #define _(msgid) gettext(msgid) @@ -1105,7 +1106,7 @@ extern int OFSlen; extern char *ORS; extern int ORSlen; extern char *OFMT; -extern char *CONVFMT; +extern const char *CONVFMT; extern int CONVFMTidx; extern int OFMTidx; #ifdef HAVE_MPFR @@ -1146,6 +1147,7 @@ extern bool do_itrace; /* separate so can poke from a debugger */ extern SRCFILE *srcfiles; /* source files */ extern enum do_flag_values { + DO_FLAG_NONE = 0x00000, DO_LINT_INVALID = 0x00001, /* only warn about invalid */ DO_LINT_EXTENSIONS = 0x00002, /* warn about gawk extensions */ DO_LINT_ALL = 0x00004, /* warn about all things */ @@ -1214,10 +1216,10 @@ extern bool do_ieee_fmt; /* emulate IEEE 754 floating-point format */ extern const char *myname; extern const char def_strftime_format[]; -extern char quote; -extern char *defpath; -extern char *deflibpath; -extern char envsep; +extern const char quote; +extern const char *defpath; +extern const char *deflibpath; +extern const char envsep; extern char casetable[]; /* for case-independent regexp matching */ @@ -1338,7 +1340,7 @@ DEREF(NODE *r) extern void *r_getblock(int id); extern void r_freeblock(void *, int id); -#define getblock(p, id, ty) (void) (p = r_getblock(id)) +#define getblock(p, id, ty) (void) (p = (ty) r_getblock(id)) #define freeblock(p, id) (void) (r_freeblock(p, id)) #else /* MEMDEBUG */ @@ -1449,7 +1451,7 @@ extern bool is_alpha(int c); extern bool is_alnum(int c); extern bool is_letter(int c); extern bool is_identchar(int c); -extern NODE *make_regnode(int type, NODE *exp); +extern NODE *make_regnode(NODETYPE type, NODE *exp); extern bool validate_qualified_name(char *token); /* builtin.c */ extern double double_to_int(double d); @@ -1584,7 +1586,7 @@ extern void print_ext_versions(void); extern void free_api_string_copies(void); /* gawkmisc.c */ -extern char *gawk_name(const char *filespec); +extern const char *gawk_name(const char *filespec); extern void os_arg_fixup(int *argcp, char ***argvp); extern int os_devopen(const char *name, int flag); extern void os_close_on_exec(int fd, const char *name, const char *what, const char *dir); @@ -5592,7 +5592,7 @@ get_src_buf() * avoids problems with some ancient systems where * the types of arguments to read() aren't up to date. */ - static ssize_t (*readfunc)() = 0; + static ssize_t (*readfunc)(int, void *, size_t) = NULL; if (readfunc == NULL) { char *cp = getenv("AWKREADFUNC"); @@ -5603,7 +5603,7 @@ get_src_buf() * cast is to remove warnings on systems with * different return types for read. */ - readfunc = ( ssize_t(*)() ) read; + readfunc = ( ssize_t(*)(int, void *, size_t) ) read; else readfunc = read_one_line; } @@ -7763,7 +7763,7 @@ variable(int location, char *name, NODETYPE type) /* make_regnode --- make a regular expression node */ NODE * -make_regnode(int type, NODE *exp) +make_regnode(NODETYPE type, NODE *exp) { NODE *n; @@ -3090,7 +3090,7 @@ get_src_buf() * avoids problems with some ancient systems where * the types of arguments to read() aren't up to date. */ - static ssize_t (*readfunc)() = 0; + static ssize_t (*readfunc)(int, void *, size_t) = NULL; if (readfunc == NULL) { char *cp = getenv("AWKREADFUNC"); @@ -3101,7 +3101,7 @@ get_src_buf() * cast is to remove warnings on systems with * different return types for read. */ - readfunc = ( ssize_t(*)() ) read; + readfunc = ( ssize_t(*)(int, void *, size_t) ) read; else readfunc = read_one_line; } @@ -5261,7 +5261,7 @@ variable(int location, char *name, NODETYPE type) /* make_regnode --- make a regular expression node */ NODE * -make_regnode(int type, NODE *exp) +make_regnode(NODETYPE type, NODE *exp) { NODE *n; @@ -29,7 +29,6 @@ #if defined(HAVE_FCNTL_H) #include <fcntl.h> #endif -#include <math.h> #include "random.h" #include "floatmagic.h" @@ -4053,7 +4052,7 @@ NODE * do_typeof(int nargs) { NODE *arg; - char *res = NULL; + const char *res = NULL; bool deref = true; NODE *dbg; @@ -4265,6 +4264,7 @@ char * format_nan_inf(NODE *n, char format) { static char buf[100]; + double val = n->numbr; #ifdef HAVE_MPFR if (is_mpg_integer(n)) @@ -4284,7 +4284,6 @@ format_nan_inf(NODE *n, char format) /* else fallthrough */ #endif - double val = n->numbr; if (isnan(val)) { strcpy(buf, signbit(val) != 0 ? "-nan" : "+nan"); @@ -43,10 +43,10 @@ extern bool output_is_tty; extern int input_fd; extern bool input_from_tty; extern FILE *out_fp; -extern char *dbg_prompt; -extern char *commands_prompt; -extern char *eval_prompt; -extern char *dgawk_prompt; +extern const char *dbg_prompt; +extern const char *commands_prompt; +extern const char *eval_prompt; +extern const char *dgawk_prompt; enum argtype { D_illegal, @@ -148,9 +148,9 @@ typedef int (*Func_cmd)(CMDARG *, int); struct cmdtoken { const char *name; - char *abbrvn; /* abbreviation */ + const char *abbrvn; /* abbreviation */ enum argtype type; - int class; + int lex_class; Func_cmd cf_ptr; const char *help_txt; }; @@ -1703,7 +1703,7 @@ yyreduce: case 34: /* command: frame_cmd opt_integer */ #line 288 "command.y" { - if (cmdtab[cmd_idx].class == D_FRAME + if (cmdtab[cmd_idx].lex_class == D_FRAME && yyvsp[0] != NULL && yyvsp[0]->a_int < 0) yyerror(_("invalid frame number: %d"), yyvsp[0]->a_int); } @@ -2817,7 +2817,7 @@ again: add_history(h->line); #endif cmd_idx = repeat_idx; - return cmdtab[cmd_idx].class; /* repeat last command */ + return cmdtab[cmd_idx].lex_class; /* repeat last command */ } repeat_idx = -1; } @@ -2877,7 +2877,7 @@ again: arg->a_string = estrdup(lexptr_begin, lexend - lexptr_begin); append_cmdarg(arg); } - return cmdtab[cmd_idx].class; + return cmdtab[cmd_idx].lex_class; } else { yyerror(_("unknown command - `%.*s', try help"), toklen, tokstart); return '\n'; @@ -3138,7 +3138,7 @@ concat_args(CMDARG *arg, int count) static int find_command(const char *token, size_t toklen) { - char *name, *abrv; + const char *name, *abrv; int i, k; bool try_exact = true; int abrv_match = -1; @@ -286,7 +286,7 @@ command | control_cmd opt_plus_integer | frame_cmd opt_integer { - if (cmdtab[cmd_idx].class == D_FRAME + if (cmdtab[cmd_idx].lex_class == D_FRAME && $2 != NULL && $2->a_int < 0) yyerror(_("invalid frame number: %d"), $2->a_int); } @@ -1096,7 +1096,7 @@ again: add_history(h->line); #endif cmd_idx = repeat_idx; - return cmdtab[cmd_idx].class; /* repeat last command */ + return cmdtab[cmd_idx].lex_class; /* repeat last command */ } repeat_idx = -1; } @@ -1156,7 +1156,7 @@ again: arg->a_string = estrdup(lexptr_begin, lexend - lexptr_begin); append_cmdarg(arg); } - return cmdtab[cmd_idx].class; + return cmdtab[cmd_idx].lex_class; } else { yyerror(_("unknown command - `%.*s', try help"), toklen, tokstart); return '\n'; @@ -1417,7 +1417,7 @@ concat_args(CMDARG *arg, int count) static int find_command(const char *token, size_t toklen) { - char *name, *abrv; + const char *name, *abrv; int i, k; bool try_exact = true; int abrv_match = -1; @@ -54,9 +54,9 @@ static char *linebuf = NULL; /* used to print a single line of source */ static size_t linebuf_len; FILE *out_fp; -char *dbg_prompt; -char *commands_prompt = "> "; /* breakpoint or watchpoint commands list */ -char *eval_prompt = "@> "; /* awk statement(s) */ +const char *dbg_prompt; +const char *commands_prompt = "> "; /* breakpoint or watchpoint commands list */ +const char *eval_prompt = "@> "; /* awk statement(s) */ bool input_from_tty = false; int input_fd; @@ -219,7 +219,7 @@ static char line_sep; struct dbg_option { const char *name; int *num_val; - char **str_val; + const char **str_val; void (*assign)(const char *); const char *help_txt; }; @@ -244,8 +244,8 @@ static const char *history_file = DEFAULT_HISTFILE; /* debugger option related variables */ -static char *output_file = "/dev/stdout"; /* gawk output redirection */ -char *dgawk_prompt = NULL; /* initialized in interpret */ +static const char *output_file = "/dev/stdout"; /* gawk output redirection */ +const char *dgawk_prompt = NULL; /* initialized in interpret */ static int list_size = DEFAULT_LISTSIZE; /* # of lines that 'list' prints */ static int do_trace = false; static int do_save_history = true; @@ -766,7 +766,7 @@ do_info(CMDARG *arg, int cmd ATTRIBUTE_UNUSED) gprintf(out_fp, _("Number Disp Enabled Location\n\n")); for (b = breakpoints.prev; b != &breakpoints; b = b->prev) { - char *disp = "keep"; + const char *disp = "keep"; if ((b->flags & BP_ENABLE_ONCE) != 0) disp = "dis"; else if ((b->flags & BP_TEMP) != 0) @@ -3051,7 +3051,7 @@ next_step(CMDARG *arg, int cmd) stop.repeat_count = arg->a_int; else stop.repeat_count = 1; - stop.command = cmd; + stop.command = (enum argtype) cmd; return true; } @@ -3231,7 +3231,7 @@ do_finish(CMDARG *arg ATTRIBUTE_UNUSED, int cmd) fprintf(out_fp, _("Run until return from ")); print_numbered_frame(cur_frame); stop.check_func = check_finish; - stop.command = cmd; + stop.command = (enum argtype) cmd; stop.print_ret = true; return true; } @@ -3279,7 +3279,7 @@ do_return(CMDARG *arg, int cmd) assert(stop.fcall_count >= 0); stop.pc = (func->code_ptr + 1)->lasti; assert(stop.pc->opcode == Op_K_return); - stop.command = cmd; + stop.command = (enum argtype) cmd; stop.check_func = check_return; @@ -3342,7 +3342,7 @@ do_until(CMDARG *arg, int cmd) stop.sourceline = sourceline; stop.fcall_count = fcall_count - cur_frame; stop.check_func = check_until; - stop.command = cmd; + stop.command = (enum argtype) cmd; return true; } @@ -3381,7 +3381,7 @@ func: stop.pc = ip; stop.fcall_count = fcall_count - cur_frame; stop.check_func = check_until; - stop.command = cmd; + stop.command = (enum argtype) cmd; return true; } } @@ -3402,7 +3402,7 @@ func: stop.pc = ip; stop.fcall_count = fcall_count - cur_frame; stop.check_func = check_until; - stop.command = cmd; + stop.command = (enum argtype) cmd; return true; } if (ip == (rp + 1)->lasti) @@ -3873,7 +3873,7 @@ print_instruction(INSTRUCTION *pc, Func_print print_func, FILE *fp, int in_dump) case Op_var_assign: print_func(fp, "[set_%s()]", get_spec_varname(pc->assign_var)); if (pc->assign_ctxt != 0) - print_func(fp, " [assign_ctxt = %s]", opcode2str(pc->assign_ctxt)); + print_func(fp, " [assign_ctxt = %s]", opcode2str((OPCODE) pc->assign_ctxt)); print_func(fp, "\n"); break; @@ -5284,7 +5284,7 @@ set_gawk_output(const char *file) if (output_fp != stdout) { if (output_fp != stderr) { fclose(output_fp); - efree(output_file); + efree((void*) output_file); } output_fp = stdout; output_is_tty = os_isatty(fileno(stdout)); @@ -5355,7 +5355,7 @@ set_gawk_output(const char *file) static void set_prompt(const char *value) { - efree(dgawk_prompt); + efree((void *) dgawk_prompt); dgawk_prompt = estrdup(value, strlen(value)); dbg_prompt = dgawk_prompt; } @@ -1009,7 +1009,7 @@ set_TEXTDOMAIN() void update_ERRNO_int(int errcode) { - char *cp; + const char *cp; update_PROCINFO_num("errno", errcode); if (errcode) { diff --git a/floatcomp.c b/floatcomp.c index 7317fa75..e2df8c50 100644 --- a/floatcomp.c +++ b/floatcomp.c @@ -25,7 +25,6 @@ */ #include "awk.h" -#include <math.h> #ifdef HAVE_UINTMAX_T @@ -31,7 +31,7 @@ extern INSTRUCTION *main_beginfile; extern int currule; static awk_bool_t node_to_awk_value(NODE *node, awk_value_t *result, awk_valtype_t wanted); -static char *valtype2str(awk_valtype_t type); +static const char *valtype2str(awk_valtype_t type); static NODE *ns_lookup(const char *name_space, const char *name, char **full_name); /* @@ -71,7 +71,7 @@ api_get_argument(awk_ext_id_t id, size_t count, /* if type is undefined */ if (arg->type == Node_var_new) { if (wanted == AWK_UNDEFINED) - return true; + return awk_true; else if (wanted == AWK_ARRAY) { goto array; } else { @@ -82,7 +82,7 @@ api_get_argument(awk_ext_id_t id, size_t count, /* at this point, we have real type */ if (arg->type == Node_var_array || arg->type == Node_array_ref) { if (wanted != AWK_ARRAY && wanted != AWK_UNDEFINED) - return false; + return awk_false; goto array; } else goto scalar; @@ -148,6 +148,7 @@ awk_value_to_node(const awk_value_t *retval) { NODE *ext_ret_val = NULL; NODE *v; + int tval = 0; if (retval == NULL) fatal(_("awk_value_to_node: received null retval")); @@ -169,7 +170,7 @@ awk_value_to_node(const awk_value_t *retval) if (! do_mpfr) fatal(_("awk_value_to_node: not in MPFR mode")); ext_ret_val = make_number_node(MPFN); - int tval = mpfr_set(ext_ret_val->mpg_numbr, (mpfr_ptr) retval->num_ptr, ROUND_MODE); + tval = mpfr_set(ext_ret_val->mpg_numbr, (mpfr_ptr) retval->num_ptr, ROUND_MODE); IEEE_FMT(ext_ret_val->mpg_numbr, tval); #else fatal(_("awk_value_to_node: MPFR not supported")); @@ -1228,7 +1229,7 @@ api_release_flattened_array(awk_ext_id_t id, awk_array_t a_cookie, awk_flat_array_t *data) { - NODE *array = a_cookie; + NODE *array = (NODE *) a_cookie; NODE **list; size_t i, j, k; @@ -1559,13 +1560,13 @@ print_ext_versions(void) /* valtype2str --- return a printable representation of a value type */ -static char * +static const char * valtype2str(awk_valtype_t type) { static char buf[100]; // Important: keep in same order as in gawkapi.h! - static char *values[] = { + static const char *values[] = { "AWK_UNDEFINED", "AWK_NUMBER", "AWK_STRING", @@ -190,7 +190,7 @@ typedef struct awk_input { * No argument prototype on read_func to allow for older systems * whose headers are not up to date. */ - ssize_t (*read_func)(); + ssize_t (*read_func)(int, void *, size_t); /* * The close_func is called to allow the parser to free private data. diff --git a/interpret.h b/interpret.h index fedf5255..56427bab 100644 --- a/interpret.h +++ b/interpret.h @@ -1250,7 +1250,7 @@ match_re: JUMPTO(ni); case Op_K_getline_redir: - r = do_getline_redir(pc->into_var, pc->redir_type); + r = do_getline_redir(pc->into_var, (enum redirval) pc->redir_type); PUSH(r); break; @@ -310,7 +310,7 @@ static bool inetfile(const char *str, size_t len, struct inet_socket_info *isn); static NODE *in_PROCINFO(const char *pidx1, const char *pidx2, NODE **full_idx); static long get_read_timeout(IOBUF *iop); -static ssize_t read_with_timeout(int fd, char *buf, size_t size); +static ssize_t read_with_timeout(int fd, void *buf, size_t size); static bool read_can_timeout = false; static long read_timeout; @@ -896,7 +896,8 @@ redirect_string(const char *str, size_t explen, bool not_string, if (strlen(rp->value) == explen && memcmp(rp->value, str, explen) == 0) { if (do_lint) { - check_duplicated_redirections(rp->value, explen, rp->flag, tflag); + check_duplicated_redirections(rp->value, explen, + (redirect_flags_t) rp->flag, (redirect_flags_t) tflag); } if (((rp->flag & ~(RED_NOBUF|RED_EOF|RED_PTY)) == tflag @@ -920,7 +921,7 @@ redirect_string(const char *str, size_t explen, bool not_string, newstr[explen] = '\0'; str = newstr; rp->value = newstr; - rp->flag = tflag; + rp->flag = (redirect_flags_t) tflag; init_output_wrapper(& rp->output); rp->output.name = str; rp->iop = NULL; @@ -2957,8 +2958,8 @@ do_getline(int into_variable, IOBUF *iop) typedef struct { const char *envname; - char **dfltp; /* pointer to address of default path */ - char **awkpath; /* array containing library search paths */ + const char **dfltp; /* pointer to address of default path */ + const char **awkpath; /* array containing library search paths */ int max_pathlen; /* length of the longest item in awkpath */ } path_info; @@ -2977,8 +2978,9 @@ static path_info pi_awklibpath = { static void init_awkpath(path_info *pi) { - char *path; - char *start, *end, *p; + const char *path; + const char *start, *end; + char *p; int len, i; int max_path; /* (# of allocated paths)-1 */ @@ -2987,12 +2989,12 @@ init_awkpath(path_info *pi) path = pi->dfltp[0]; /* count number of separators */ - for (max_path = 0, p = path; *p; p++) + for (max_path = 0, p = (char *) path; *p; p++) if (*p == envsep) max_path++; // +3 --> 2 for null entries at front and end of path, 1 for NULL end of list - ezalloc(pi->awkpath, char **, (max_path + 3) * sizeof(char *), "init_awkpath"); + ezalloc(pi->awkpath, const char **, (max_path + 3) * sizeof(char *), "init_awkpath"); start = path; i = 0; @@ -4399,7 +4401,7 @@ get_read_timeout(IOBUF *iop) */ static ssize_t -read_with_timeout(int fd, char *buf, size_t size) +read_with_timeout(int fd, void *buf, size_t size) { #if ! defined(VMS) fd_set readfds; @@ -96,7 +96,7 @@ char *TEXTDOMAIN; * set_CONVFMT -> fmt_index -> force_string: gets NULL CONVFMT * Fun, fun, fun, fun. */ -char *CONVFMT = "%.6g"; +const char *CONVFMT = "%.6g"; NODE *Nnull_string; /* The global null string */ @@ -145,14 +145,14 @@ static void parse_args(int argc, char **argv); static void set_locale_stuff(void); static bool stopped_early = false; -enum do_flag_values do_flags = 0; +enum do_flag_values 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 */ static int do_binary = false; /* hands off my data! */ static int do_version = false; /* print version info */ static const char *locale = ""; /* default value to setlocale */ -static char *locale_dir = LOCALEDIR; /* default locale dir */ +static const char *locale_dir = LOCALEDIR; /* default locale dir */ int use_lc_numeric = false; /* obey locale for decimal point */ @@ -639,7 +639,7 @@ get_rnd_mode(const char rmode) default: break; } - return -1; + return (mpfr_rnd_t) -1; } /* @@ -651,7 +651,7 @@ void set_ROUNDMODE() { if (do_mpfr) { - mpfr_rnd_t rndm = -1; + mpfr_rnd_t rndm = (mpfr_rnd_t) -1; NODE *n; n = force_string(ROUNDMODE_node->var_value); if (n->stlen == 1) @@ -748,7 +748,7 @@ do_mpfr_atan2(int nargs) static inline NODE * do_mpfr_func(const char *name, - int (*mpfr_func)(), /* putting argument types just gets the compiler confused */ + int (*mpfr_func)(mpfr_ptr, mpfr_srcptr, mpfr_rnd_t), int nargs) { NODE *t1, *res; @@ -25,7 +25,6 @@ */ #include "awk.h" -#include "math.h" #include "floatmagic.h" /* definition of isnan */ static NODE *r_make_number(double x); @@ -61,7 +60,6 @@ r_force_number(NODE *n) char *cpend; char save; char *ptr; - extern double strtod(); if ((n->flags & NUMCUR) != 0) return n; diff --git a/pc/ChangeLog b/pc/ChangeLog index af2d2e66..22870c9d 100644 --- a/pc/ChangeLog +++ b/pc/ChangeLog @@ -1,3 +1,11 @@ +2021-01-08 Arnold D. Robbins <arnold@skeeve.com> + + * gawkmisc.pc (quote): Make const char *. + (defpath): Make const char *. + (deflibpath): Make const char *. + (envsep): Make const char *. + (gawk_name): Now returns const char *. + 2021-01-07 Arnold D. Robbins <arnold@skeeve.com> * Makefile.tst: Rebuilt. diff --git a/pc/gawkmisc.pc b/pc/gawkmisc.pc index 5f44280d..4e58b0a8 100644 --- a/pc/gawkmisc.pc +++ b/pc/gawkmisc.pc @@ -22,19 +22,19 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -char quote = '\''; -char envsep = ';'; +const char quote = '\''; +const char envsep = ';'; # ifdef DEFPATH -char *defpath = DEFPATH; +const char *defpath = DEFPATH; # else -char *defpath = ".;c:\\lib\\awk;c:\\gnu\\lib\\awk"; +const char *defpath = ".;c:\\lib\\awk;c:\\gnu\\lib\\awk"; # endif /* the Makefile should define DEFLIBPATH */ -char *deflibpath = DEFLIBPATH; +const char *deflibpath = DEFLIBPATH; #ifdef __EMX__ -#include<io.h> +#include <io.h> static int _os2_is_abs_path(const char *dirname); static char* _os2_unixroot(const char *path); @@ -61,7 +61,7 @@ static const char* _os2_unixroot_path(const char *path); /* gawk_name --- pull out the "gawk" part from how the OS called us */ -char * +const char * gawk_name(filespec) const char *filespec; { diff --git a/posix/ChangeLog b/posix/ChangeLog index 2ae8093a..05f92abc 100644 --- a/posix/ChangeLog +++ b/posix/ChangeLog @@ -1,3 +1,11 @@ +2021-01-08 Arnold D. Robbins <arnold@skeeve.com> + + * gawkmisc.c (quote): Make const char *. + (defpath): Make const char *. + (deflibpath): Make const char *. + (envsep): Make const char *. + (gawk_name): Now returns const char *. + 2020-04-14 Arnold D. Robbins <arnold@skeeve.com> * 5.1.0: Release tar ball made. diff --git a/posix/gawkmisc.c b/posix/gawkmisc.c index 16cfeb03..d2e33f41 100644 --- a/posix/gawkmisc.c +++ b/posix/gawkmisc.c @@ -24,10 +24,10 @@ #include <io.h> #endif -char quote = '\''; -char *defpath = DEFPATH; -char *deflibpath = DEFLIBPATH; -char envsep = ':'; +const char quote = '\''; +const char *defpath = DEFPATH; +const char *deflibpath = DEFLIBPATH; +const char envsep = ':'; #ifndef INVALID_HANDLE /* FIXME: is this value for INVALID_HANDLE correct? */ @@ -36,10 +36,10 @@ char envsep = ':'; /* gawk_name --- pull out the "gawk" part from how the OS called us */ -char * +const char * gawk_name(const char *filespec) { - char *p; + const char *p; /* "path/name" -> "name" */ p = strrchr(filespec, '/'); @@ -179,7 +179,7 @@ pp_push(int type, char *s, int flag, INSTRUCTION *comment) n->pp_str = s; n->pp_len = strlen(s); n->flags = flag; - n->type = type; + n->type = (NODETYPE) type; n->pp_next = pp_stack; n->pp_comment = comment; pp_stack = n; @@ -781,7 +781,7 @@ cleanup: case Op_indirect_func_call: case Op_func_call: { - char *pre; + const char *pre; int pcount; bool malloced = false; char *fname = adjust_namespace(pc->func_name, & malloced); @@ -613,7 +613,7 @@ check_bracket_exp(char *s, size_t length) sp = s; again: - sp = sp2 = memchr(sp, '[', (end - sp)); + sp = sp2 = (char *) memchr(sp, '[', (end - sp)); if (sp == NULL) goto done; diff --git a/support/ChangeLog b/support/ChangeLog index 174c65c2..7d234113 100644 --- a/support/ChangeLog +++ b/support/ChangeLog @@ -1,3 +1,7 @@ +2021-01-08 Arnold D. Robbins <arnold@skeeve.com> + + * random.h (initstate, setstate, srandom): Add declarations. + 2020-11-06 Arnold D. Robbins <arnold@skeeve.com> * dfa.h, regex_internal.c, regex_internal.h: Synced from GNULIB. diff --git a/support/random.h b/support/random.h index 84b31414..a76a3adf 100644 --- a/support/random.h +++ b/support/random.h @@ -40,4 +40,7 @@ typedef long gawk_int32_t; #define uint32_t gawk_uint32_t #define int32_t gawk_int32_t -extern long random (void); +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); diff --git a/vms/ChangeLog b/vms/ChangeLog index 39b21150..7d80c4bf 100644 --- a/vms/ChangeLog +++ b/vms/ChangeLog @@ -1,3 +1,11 @@ +2021-01-08 Arnold D. Robbins <arnold@skeeve.com> + + * gawkmisc.vms (quote): Make const char *. + (defpath): Make const char *. + (deflibpath): Make const char *. + (envsep): Make const char *. + (gawk_name): Now returns const char *. + 2020-04-14 Arnold D. Robbins <arnold@skeeve.com> * 5.1.0: Release tar ball made. diff --git a/vms/gawkmisc.vms b/vms/gawkmisc.vms index 725cf669..ff5805bd 100644 --- a/vms/gawkmisc.vms +++ b/vms/gawkmisc.vms @@ -79,10 +79,10 @@ int SYS$TRNLNM( const unsigned char * acmode, const struct item_list_3 * item_list); -char quote = '\''; -char *defpath = DEFPATH; -char *deflibpath = DEFLIBPATH; -char envsep = ','; +const char quote = '\''; +const char *defpath = DEFPATH; +const char *deflibpath = DEFLIBPATH; +const char envsep = ','; #define VMS_NAME_LEN 255 static char vms_name[VMS_NAME_LEN+1]; @@ -132,7 +132,7 @@ static int sys_trnlnm * passed exec() argv[0] and handle both cases. */ -char * +const char * gawk_name(filespec) const char *filespec; { |