mirror of
https://github.com/ThomasDickey/mawk-snapshots.git
synced 2026-01-26 19:09:15 +00:00
snapshot of project "mawk", label t20200828
This commit is contained in:
parent
6d9277f3d8
commit
a37fb7ed01
18
CHANGES
18
CHANGES
@ -1,4 +1,20 @@
|
||||
-- $MawkId: CHANGES,v 1.295 2020/08/22 01:07:18 tom Exp $
|
||||
-- $MawkId: CHANGES,v 1.301 2020/08/28 19:08:28 tom Exp $
|
||||
|
||||
20200828
|
||||
+ modify configure script to move gcc -Werror flags to EXTRA_CFLAGS
|
||||
to avoid breaking configure-checks.
|
||||
+ use sprintf-buffer for intermediate output of strftime, to handle
|
||||
extra-long format strings.
|
||||
+ modify MAWK_LONG_OPTIONS "ignore" to limit that to the "-xxx" options
|
||||
in this set of changes, plus the existing --lint/--lint-old options.
|
||||
+ allow -Wxxx options to use long-option format as -xxx, for better
|
||||
script-compatibility with gawk.
|
||||
+ use standard output for -Whelp, but show usage message in standard
|
||||
error when no command arguments are given.
|
||||
+ print version for -Wversion consistently in standard output.
|
||||
+ improve use of const for making tables readonly.
|
||||
+ change -W compat to -W traditional for better script-compatibility
|
||||
with gawk.
|
||||
|
||||
20200821
|
||||
+ completed first draft of mawk-code.7
|
||||
|
||||
2
MANIFEST
2
MANIFEST
@ -1,4 +1,4 @@
|
||||
MANIFEST for mawk, version t20200821
|
||||
MANIFEST for mawk, version t20200828
|
||||
--------------------------------------------------------------------------------
|
||||
MANIFEST this file
|
||||
ACKNOWLEDGMENT acknowledgements
|
||||
|
||||
52
aclocal.m4
vendored
52
aclocal.m4
vendored
@ -1,4 +1,4 @@
|
||||
dnl $MawkId: aclocal.m4,v 1.93 2020/07/30 21:28:24 tom Exp $
|
||||
dnl $MawkId: aclocal.m4,v 1.95 2020/08/28 19:08:28 tom Exp $
|
||||
dnl custom mawk macros for autoconf
|
||||
dnl
|
||||
dnl The symbols beginning "CF_MAWK_" were originally written by Mike Brennan,
|
||||
@ -476,7 +476,7 @@ fi
|
||||
|
||||
])dnl
|
||||
dnl ---------------------------------------------------------------------------
|
||||
dnl CF_CLANG_COMPILER version: 2 updated: 2013/11/19 19:23:35
|
||||
dnl CF_CLANG_COMPILER version: 3 updated: 2020/08/28 04:10:22
|
||||
dnl -----------------
|
||||
dnl Check if the given compiler is really clang. clang's C driver defines
|
||||
dnl __GNUC__ (fooling the configure script into setting $GCC to yes) but does
|
||||
@ -507,6 +507,10 @@ cf_save_CFLAGS="$cf_save_CFLAGS -Qunused-arguments"
|
||||
ifelse([$3],,CFLAGS,[$3])="$cf_save_CFLAGS"
|
||||
AC_MSG_RESULT($ifelse([$2],,CLANG_COMPILER,[$2]))
|
||||
fi
|
||||
|
||||
if test "x$CLANG_COMPILER" = "xyes" ; then
|
||||
CF_APPEND_TEXT(CFLAGS,-Wno-error=implicit-function-declaration)
|
||||
fi
|
||||
])
|
||||
dnl ---------------------------------------------------------------------------
|
||||
dnl CF_CONST_X_STRING version: 4 updated: 2020/03/10 18:53:47
|
||||
@ -644,12 +648,15 @@ then
|
||||
fi
|
||||
])dnl
|
||||
dnl ---------------------------------------------------------------------------
|
||||
dnl CF_ENABLE_WARNINGS version: 5 updated: 2017/09/29 20:01:16
|
||||
dnl CF_ENABLE_WARNINGS version: 6 updated: 2020/08/28 04:10:22
|
||||
dnl ------------------
|
||||
dnl Configure-option to enable gcc warnings
|
||||
AC_DEFUN([CF_ENABLE_WARNINGS],[
|
||||
if ( test "$GCC" = yes || test "$GXX" = yes )
|
||||
then
|
||||
CF_FIX_WARNINGS(CFLAGS)
|
||||
CF_FIX_WARNINGS(CPPFLAGS)
|
||||
CF_FIX_WARNINGS(LDFLAGS)
|
||||
AC_MSG_CHECKING(if you want to turn on gcc warnings)
|
||||
CF_ARG_ENABLE(warnings,
|
||||
[ --enable-warnings test: turn on gcc compiler warnings],
|
||||
@ -664,6 +671,40 @@ fi
|
||||
fi
|
||||
])dnl
|
||||
dnl ---------------------------------------------------------------------------
|
||||
dnl CF_FIX_WARNINGS version: 2 updated: 2020/08/28 15:08:28
|
||||
dnl ---------------
|
||||
dnl Warning flags do not belong in CFLAGS, CPPFLAGS, etc. Any of gcc's
|
||||
dnl "-Werror" flags can interfere with configure-checks. Those go into
|
||||
dnl EXTRA_CFLAGS.
|
||||
dnl
|
||||
dnl $1 = variable name to repair
|
||||
define([CF_FIX_WARNINGS],[
|
||||
if ( test "$GCC" = yes || test "$GXX" = yes )
|
||||
then
|
||||
case [$]$1 in
|
||||
(*-Werror=*)
|
||||
CF_VERBOSE(repairing $1: [$]$1)
|
||||
cf_temp_flags=
|
||||
for cf_temp_scan in [$]$1
|
||||
do
|
||||
case "x$cf_temp_scan" in
|
||||
(x-Werror=*)
|
||||
CF_APPEND_TEXT(EXTRA_CFLAGS,"$cf_temp_scan")
|
||||
;;
|
||||
(*)
|
||||
CF_APPEND_TEXT(cf_temp_flags,"$cf_temp_scan")
|
||||
;;
|
||||
esac
|
||||
done
|
||||
$1="$cf_temp_flags"
|
||||
CF_VERBOSE(... fixed [$]$1)
|
||||
CF_VERBOSE(... extra $EXTRA_CFLAGS)
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
AC_SUBST(EXTRA_CFLAGS)
|
||||
])dnl
|
||||
dnl ---------------------------------------------------------------------------
|
||||
dnl CF_GCC_ATTRIBUTES version: 18 updated: 2020/03/10 18:53:47
|
||||
dnl -----------------
|
||||
dnl Test for availability of useful gcc __attribute__ directives to quiet
|
||||
@ -791,7 +832,7 @@ CF_INTEL_COMPILER(GCC,INTEL_COMPILER,CFLAGS)
|
||||
CF_CLANG_COMPILER(GCC,CLANG_COMPILER,CFLAGS)
|
||||
])dnl
|
||||
dnl ---------------------------------------------------------------------------
|
||||
dnl CF_GCC_WARNINGS version: 37 updated: 2020/01/05 20:04:12
|
||||
dnl CF_GCC_WARNINGS version: 38 updated: 2020/08/28 15:08:28
|
||||
dnl ---------------
|
||||
dnl Check if the compiler supports useful warning options. There's a few that
|
||||
dnl we don't use, simply because they're too noisy:
|
||||
@ -834,7 +875,7 @@ then
|
||||
|
||||
AC_CHECKING([for $CC warning options])
|
||||
cf_save_CFLAGS="$CFLAGS"
|
||||
EXTRA_CFLAGS="-Wall"
|
||||
EXTRA_CFLAGS="$EXTRA_CFLAGS -Wall"
|
||||
for cf_opt in \
|
||||
wd1419 \
|
||||
wd1683 \
|
||||
@ -857,7 +898,6 @@ elif test "$GCC" = yes && test "$GCC_VERSION" != "unknown"
|
||||
then
|
||||
AC_CHECKING([for $CC warning options])
|
||||
cf_save_CFLAGS="$CFLAGS"
|
||||
EXTRA_CFLAGS=
|
||||
cf_warn_CONST=""
|
||||
test "$with_ext_const" = yes && cf_warn_CONST="Wwrite-strings"
|
||||
cf_gcc_warnings="Wignored-qualifiers Wlogical-op Wvarargs"
|
||||
|
||||
12
bi_funct.c
12
bi_funct.c
@ -11,7 +11,7 @@ the GNU General Public License, version 2, 1991.
|
||||
********************************************/
|
||||
|
||||
/*
|
||||
* $MawkId: bi_funct.c,v 1.111 2020/01/06 10:01:20 tom Exp $
|
||||
* $MawkId: bi_funct.c,v 1.113 2020/08/28 08:20:21 tom Exp $
|
||||
*/
|
||||
|
||||
#include <mawk.h>
|
||||
@ -476,7 +476,6 @@ bi_strftime(CELL *sp)
|
||||
int n_args;
|
||||
int utc;
|
||||
STRING *sval = 0; /* strftime(sval->str, timestamp, utc) */
|
||||
char buff[128];
|
||||
size_t result;
|
||||
|
||||
TRACE_FUNC("bi_strftime", sp);
|
||||
@ -517,7 +516,10 @@ bi_strftime(CELL *sp)
|
||||
else
|
||||
ptm = localtime(&rawtime);
|
||||
|
||||
result = strftime(buff, sizeof(buff) / sizeof(buff[0]), format, ptm);
|
||||
result = strftime(sprintf_buff,
|
||||
(size_t) (sprintf_limit - sprintf_buff),
|
||||
format,
|
||||
ptm);
|
||||
TRACE(("...bi_strftime (%s, \"%d.%d.%d %d.%d.%d %d\", %d) ->%s\n",
|
||||
format,
|
||||
ptm->tm_year,
|
||||
@ -528,12 +530,12 @@ bi_strftime(CELL *sp)
|
||||
ptm->tm_sec,
|
||||
ptm->tm_isdst,
|
||||
utc,
|
||||
buff));
|
||||
sprintf_buff));
|
||||
|
||||
if (sval)
|
||||
free_STRING(sval);
|
||||
|
||||
sp->ptr = (PTR) new_STRING1(buff, result);
|
||||
sp->ptr = (PTR) new_STRING1(sprintf_buff, result);
|
||||
|
||||
while (n_args > 1) {
|
||||
n_args--;
|
||||
|
||||
129
da.c
129
da.c
@ -11,7 +11,7 @@ the GNU General Public License, version 2, 1991.
|
||||
********************************************/
|
||||
|
||||
/*
|
||||
* $MawkId: da.c,v 1.25 2020/07/19 12:55:52 tom Exp $
|
||||
* $MawkId: da.c,v 1.29 2020/08/24 08:26:08 tom Exp $
|
||||
*/
|
||||
|
||||
/* da.c */
|
||||
@ -48,75 +48,74 @@ static void add_to_regex_list(PTR);
|
||||
|
||||
typedef struct {
|
||||
char op;
|
||||
const char *name;
|
||||
const char name[12];
|
||||
} OP_NAME;
|
||||
|
||||
static const char *find_bi_name(PF_CP);
|
||||
/* *INDENT-OFF* */
|
||||
static const OP_NAME simple_code[] =
|
||||
|
||||
{
|
||||
{_STOP, "stop"},
|
||||
{FE_PUSHA, "fe_pusha"},
|
||||
{FE_PUSHI, "fe_pushi"},
|
||||
{A_LENGTH, "a_length"},
|
||||
{A_TEST, "a_test"},
|
||||
{A_DEL, "a_del"},
|
||||
{DEL_A, "del_a"},
|
||||
{POP_AL, "pop_al"},
|
||||
{_POP, "pop"},
|
||||
{_ADD, "add"},
|
||||
{_SUB, "sub"},
|
||||
{_MUL, "mul"},
|
||||
{_DIV, "div"},
|
||||
{_MOD, "mod"},
|
||||
{_POW, "pow"},
|
||||
{_NOT, "not"},
|
||||
{_UMINUS, "uminus"},
|
||||
{_UPLUS, "uplus"},
|
||||
{_TEST, "test"},
|
||||
{_CAT, "cat"},
|
||||
{_ASSIGN, "assign"},
|
||||
{_ADD_ASG, "add_asg"},
|
||||
{_SUB_ASG, "sub_asg"},
|
||||
{_MUL_ASG, "mul_asg"},
|
||||
{_DIV_ASG, "div_asg"},
|
||||
{_MOD_ASG, "mod_asg"},
|
||||
{_POW_ASG, "pow_asg"},
|
||||
{NF_PUSHI, "nf_pushi"},
|
||||
{F_ASSIGN, "f_assign"},
|
||||
{F_ADD_ASG, "f_add_asg"},
|
||||
{F_SUB_ASG, "f_sub_asg"},
|
||||
{F_MUL_ASG, "f_mul_asg"},
|
||||
{F_DIV_ASG, "f_div_asg"},
|
||||
{F_MOD_ASG, "f_mod_asg"},
|
||||
{F_POW_ASG, "f_pow_asg"},
|
||||
{_POST_INC, "post_inc"},
|
||||
{_POST_DEC, "post_dec"},
|
||||
{_PRE_INC, "pre_inc"},
|
||||
{_PRE_DEC, "pre_dec"},
|
||||
{F_POST_INC, "f_post_inc"},
|
||||
{F_POST_DEC, "f_post_dec"},
|
||||
{F_PRE_INC, "f_pre_inc"},
|
||||
{F_PRE_DEC, "f_pre_dec"},
|
||||
{_EQ, "eq"},
|
||||
{_NEQ, "neq"},
|
||||
{_LT, "lt"},
|
||||
{_LTE, "lte"},
|
||||
{_GT, "gt"},
|
||||
{_GTE, "gte"},
|
||||
{_MATCH2, "match2"},
|
||||
{_EXIT, "exit"},
|
||||
{_EXIT0, "exit0"},
|
||||
{_NEXT, "next"},
|
||||
{_NEXTFILE, "nextfile"},
|
||||
{_RET, "ret"},
|
||||
{_RET0, "ret0"},
|
||||
{_OMAIN, "omain"},
|
||||
{_JMAIN, "jmain"},
|
||||
{OL_GL, "ol_gl"},
|
||||
{OL_GL_NR, "ol_gl_nr"},
|
||||
{_HALT, (char *) 0}
|
||||
{ _STOP, "stop" },
|
||||
{ FE_PUSHA, "fe_pusha" },
|
||||
{ FE_PUSHI, "fe_pushi" },
|
||||
{ A_LENGTH, "a_length" },
|
||||
{ A_TEST, "a_test" },
|
||||
{ A_DEL, "a_del" },
|
||||
{ DEL_A, "del_a" },
|
||||
{ POP_AL, "pop_al" },
|
||||
{ _POP, "pop" },
|
||||
{ _ADD, "add" },
|
||||
{ _SUB, "sub" },
|
||||
{ _MUL, "mul" },
|
||||
{ _DIV, "div" },
|
||||
{ _MOD, "mod" },
|
||||
{ _POW, "pow" },
|
||||
{ _NOT, "not" },
|
||||
{ _UMINUS, "uminus" },
|
||||
{ _UPLUS, "uplus" },
|
||||
{ _TEST, "test" },
|
||||
{ _CAT, "cat" },
|
||||
{ _ASSIGN, "assign" },
|
||||
{ _ADD_ASG, "add_asg" },
|
||||
{ _SUB_ASG, "sub_asg" },
|
||||
{ _MUL_ASG, "mul_asg" },
|
||||
{ _DIV_ASG, "div_asg" },
|
||||
{ _MOD_ASG, "mod_asg" },
|
||||
{ _POW_ASG, "pow_asg" },
|
||||
{ NF_PUSHI, "nf_pushi" },
|
||||
{ F_ASSIGN, "f_assign" },
|
||||
{ F_ADD_ASG, "f_add_asg" },
|
||||
{ F_SUB_ASG, "f_sub_asg" },
|
||||
{ F_MUL_ASG, "f_mul_asg" },
|
||||
{ F_DIV_ASG, "f_div_asg" },
|
||||
{ F_MOD_ASG, "f_mod_asg" },
|
||||
{ F_POW_ASG, "f_pow_asg" },
|
||||
{ _POST_INC, "post_inc" },
|
||||
{ _POST_DEC, "post_dec" },
|
||||
{ _PRE_INC, "pre_inc" },
|
||||
{ _PRE_DEC, "pre_dec" },
|
||||
{ F_POST_INC, "f_post_inc" },
|
||||
{ F_POST_DEC, "f_post_dec" },
|
||||
{ F_PRE_INC, "f_pre_inc" },
|
||||
{ F_PRE_DEC, "f_pre_dec" },
|
||||
{ _EQ, "eq" },
|
||||
{ _NEQ, "neq" },
|
||||
{ _LT, "lt" },
|
||||
{ _LTE, "lte" },
|
||||
{ _GT, "gt" },
|
||||
{ _GTE, "gte" },
|
||||
{ _MATCH2, "match2" },
|
||||
{ _EXIT, "exit" },
|
||||
{ _EXIT0, "exit0" },
|
||||
{ _NEXT, "next" },
|
||||
{ _NEXTFILE, "nextfile" },
|
||||
{ _RET, "ret" },
|
||||
{ _RET0, "ret0" },
|
||||
{ _OMAIN, "omain" },
|
||||
{ _JMAIN, "jmain" },
|
||||
{ OL_GL, "ol_gl" },
|
||||
{ OL_GL_NR, "ol_gl_nr" },
|
||||
{ _HALT, "" }
|
||||
} ;
|
||||
/* *INDENT-ON* */
|
||||
|
||||
@ -531,7 +530,7 @@ static const OP_NAME other_codes[] = {
|
||||
{ _PUSHINT, "pushint" },
|
||||
{ _PUSHS, "pushs" },
|
||||
{ _RANGE, "range" },
|
||||
{ _HALT, 0 },
|
||||
{ _HALT, "" }
|
||||
};
|
||||
/* *INDENT-ON* */
|
||||
|
||||
|
||||
32
error.c
32
error.c
@ -1,6 +1,6 @@
|
||||
/********************************************
|
||||
error.c
|
||||
copyright 2008-2014,2016 Thomas E. Dickey
|
||||
copyright 2008-2016,2020 Thomas E. Dickey
|
||||
copyright 1991-1994,1995 Michael D. Brennan
|
||||
|
||||
This is a source file for mawk, an implementation of
|
||||
@ -11,7 +11,7 @@ the GNU General Public License, version 2, 1991.
|
||||
********************************************/
|
||||
|
||||
/*
|
||||
* $MawkId: error.c,v 1.23 2016/09/29 23:00:43 tom Exp $
|
||||
* $MawkId: error.c,v 1.24 2020/08/25 20:08:35 tom Exp $
|
||||
*/
|
||||
|
||||
#include <mawk.h>
|
||||
@ -23,7 +23,7 @@ unsigned rt_nr, rt_fnr;
|
||||
/* *INDENT-OFF* */
|
||||
static const struct token_str {
|
||||
short token;
|
||||
const char *str;
|
||||
const char str[12];
|
||||
} token_str[] = {
|
||||
{ EOF, "end of file" },
|
||||
{ NL, "end of line" },
|
||||
@ -52,7 +52,7 @@ static const struct token_str {
|
||||
{ LTE, "<=" },
|
||||
{ GT, ">" },
|
||||
{ GTE, ">=" },
|
||||
{ MATCH, string_buff },
|
||||
{ MATCH, "" }, /* string_buff */
|
||||
{ PLUS, "+" },
|
||||
{ MINUS, "-" },
|
||||
{ MUL, "*" },
|
||||
@ -61,18 +61,18 @@ static const struct token_str {
|
||||
{ POW, "^" },
|
||||
{ NOT, "!" },
|
||||
{ COMMA, "," },
|
||||
{ INC_or_DEC, string_buff },
|
||||
{ DOUBLE, string_buff },
|
||||
{ STRING_, string_buff },
|
||||
{ ID, string_buff },
|
||||
{ FUNCT_ID, string_buff },
|
||||
{ BUILTIN, string_buff },
|
||||
{ IO_OUT, string_buff },
|
||||
{ INC_or_DEC, "" }, /* string_buff */
|
||||
{ DOUBLE, "" }, /* string_buff */
|
||||
{ STRING_, "" }, /* string_buff */
|
||||
{ ID, "" }, /* string_buff */
|
||||
{ FUNCT_ID, "" }, /* string_buff */
|
||||
{ BUILTIN, "" }, /* string_buff */
|
||||
{ IO_OUT, "" }, /* string_buff */
|
||||
{ IO_IN, "<" },
|
||||
{ PIPE, "|" },
|
||||
{ DOLLAR, "$" },
|
||||
{ FIELD, "$" },
|
||||
{ 0, (char *) 0 }
|
||||
{ 0, "" }
|
||||
};
|
||||
/* *INDENT-ON* */
|
||||
|
||||
@ -116,7 +116,7 @@ yyerror(const char *s GCC_UNUSED)
|
||||
|
||||
for (p = token_str; p->token; p++)
|
||||
if (current_token == p->token) {
|
||||
ss = p->str;
|
||||
ss = p->str[0] ? p->str : string_buff;
|
||||
break;
|
||||
}
|
||||
|
||||
@ -175,7 +175,7 @@ yyerror(const char *s GCC_UNUSED)
|
||||
messages if errnum > 0 */
|
||||
|
||||
void
|
||||
errmsg(int errnum, const char *format,...)
|
||||
errmsg(int errnum, const char *format, ...)
|
||||
{
|
||||
va_list args;
|
||||
|
||||
@ -200,7 +200,7 @@ errmsg(int errnum, const char *format,...)
|
||||
}
|
||||
|
||||
void
|
||||
compile_error(const char *format,...)
|
||||
compile_error(const char *format, ...)
|
||||
{
|
||||
va_list args;
|
||||
const char *s0, *s1;
|
||||
@ -253,7 +253,7 @@ rt_where(void)
|
||||
}
|
||||
|
||||
void
|
||||
rt_error(const char *format,...)
|
||||
rt_error(const char *format, ...)
|
||||
{
|
||||
va_list args;
|
||||
|
||||
|
||||
804
init.c
804
init.c
@ -11,7 +11,7 @@ the GNU General Public License, version 2, 1991.
|
||||
********************************************/
|
||||
|
||||
/*
|
||||
* $MawkId: init.c,v 1.50 2020/07/25 14:37:45 tom Exp $
|
||||
* $MawkId: init.c,v 1.66 2020/08/27 00:14:36 tom Exp $
|
||||
*/
|
||||
|
||||
/* init.c */
|
||||
@ -33,25 +33,22 @@ typedef enum {
|
||||
#if USE_BINMODE
|
||||
W_BINMODE,
|
||||
#endif
|
||||
W_COMPAT,
|
||||
W_DUMP,
|
||||
W_EXEC,
|
||||
W_HELP,
|
||||
W_INTERACTIVE,
|
||||
W_POSIX,
|
||||
W_RANDOM,
|
||||
W_RE_INTERVAL,
|
||||
W_SPRINTF,
|
||||
W_USAGE
|
||||
W_TRADITIONAL,
|
||||
W_USAGE,
|
||||
W__IGNORE
|
||||
} W_OPTIONS;
|
||||
|
||||
static void process_cmdline(int, char **);
|
||||
static void set_ARGV(int, char **, int);
|
||||
static void bad_option(char *);
|
||||
static void no_program(void);
|
||||
|
||||
#ifdef MSDOS
|
||||
#if HAVE_REARGV
|
||||
void reargv(int *, char ***);
|
||||
extern void reargv(int *, char ***);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@ -64,37 +61,6 @@ short interactive_flag = 0;
|
||||
progname = p ? p+1 : argv[0] ; }
|
||||
#endif
|
||||
|
||||
void
|
||||
initialize(int argc, char **argv)
|
||||
{
|
||||
|
||||
SET_PROGNAME();
|
||||
|
||||
bi_vars_init(); /* load the builtin variables */
|
||||
bi_funct_init(); /* load the builtin functions */
|
||||
kw_init(); /* load the keywords */
|
||||
field_init();
|
||||
|
||||
#if USE_BINMODE
|
||||
{
|
||||
char *p = getenv("MAWKBINMODE");
|
||||
|
||||
if (p)
|
||||
set_binmode(atoi(p));
|
||||
}
|
||||
#endif
|
||||
|
||||
process_cmdline(argc, argv);
|
||||
|
||||
code_init();
|
||||
fpe_init();
|
||||
set_stdio();
|
||||
|
||||
#if USE_BINMODE
|
||||
stdout_init();
|
||||
#endif
|
||||
}
|
||||
|
||||
int dump_code_flag = 0; /* if on dump internal code */
|
||||
short posix_space_flag = 0;
|
||||
|
||||
@ -108,6 +74,32 @@ short repetitions_flag = 1;
|
||||
#ifdef DEBUG
|
||||
int dump_RE = 1; /* if on dump compiled REs */
|
||||
#endif
|
||||
/* *INDENT-OFF* */
|
||||
static const struct {
|
||||
W_OPTIONS code;
|
||||
int mode; /* 0=mawk, 1=both, 2=gawk */
|
||||
int args; /* nonzero if argument */
|
||||
const char name[20];
|
||||
} w_options[] = {
|
||||
{ W_VERSION, 1, 0, "version" },
|
||||
#if USE_BINMODE
|
||||
{ W_BINMODE, 0, 0, "binmode" },
|
||||
#endif
|
||||
{ W_DUMP, 0, 0, "dump" },
|
||||
{ W_EXEC, 1, 1, "exec" },
|
||||
{ W_HELP, 1, 0, "help" },
|
||||
{ W_INTERACTIVE, 0, 0, "interactive" },
|
||||
{ W_POSIX, 1, 0, "posix" },
|
||||
{ W_RANDOM, 0, 1, "random" },
|
||||
{ W_RE_INTERVAL, 2, 0, "re-interval" },
|
||||
{ W_SPRINTF, 0, 1, "sprintf" },
|
||||
{ W_TRADITIONAL, 1, 0, "traditional" },
|
||||
{ W_USAGE, 0, 0, "usage" },
|
||||
{ W__IGNORE, 2, 0, "lint" },
|
||||
{ W__IGNORE, 2, 0, "lint-old" },
|
||||
{ W__IGNORE, 2, 0, "non-decimal-data" },
|
||||
};
|
||||
/* *INDENT-ON* */
|
||||
|
||||
static void
|
||||
no_program(void)
|
||||
@ -116,9 +108,9 @@ no_program(void)
|
||||
}
|
||||
|
||||
static void
|
||||
usage(void)
|
||||
usage(FILE *fp)
|
||||
{
|
||||
static const char *msg[] =
|
||||
static const char msg[][80] =
|
||||
{
|
||||
"Usage: mawk [Options] [Program] [file ...]",
|
||||
"",
|
||||
@ -153,7 +145,7 @@ usage(void)
|
||||
};
|
||||
size_t n;
|
||||
for (n = 0; n < TABLESIZE(msg); ++n) {
|
||||
fprintf(stderr, "%s\n", msg[n]);
|
||||
fprintf(fp, "%s\n", msg[n]);
|
||||
}
|
||||
mawk_exit(0);
|
||||
}
|
||||
@ -171,7 +163,7 @@ ok_abbrev(const char *fullName, const char *partName, int partLen)
|
||||
UChar ch = (UChar) partName[n];
|
||||
if (isalpha(ch))
|
||||
ch = (UChar) toupper(ch);
|
||||
if (ch != (UChar) fullName[n]) {
|
||||
if (ch != (UChar) toupper(fullName[n])) {
|
||||
result = 0;
|
||||
break;
|
||||
}
|
||||
@ -200,131 +192,16 @@ haveValue(char *value)
|
||||
return result;
|
||||
}
|
||||
|
||||
static void
|
||||
bad_option(char *s)
|
||||
{
|
||||
#ifndef NO_GAWK_OPTIONS
|
||||
enum {
|
||||
GLOP_POSIX = 0
|
||||
,GLOP_HELP
|
||||
,GLOP_RE_INTERVAL
|
||||
,GLOP_TRADITIONAL
|
||||
,GLOP_VERSION
|
||||
};
|
||||
#define DATA(name,code) { "--" name, code }
|
||||
static const struct {
|
||||
const char name[15];
|
||||
int code;
|
||||
} table[] = {
|
||||
DATA("help", GLOP_HELP),
|
||||
DATA("posix", GLOP_POSIX),
|
||||
DATA("re-interval", GLOP_RE_INTERVAL),
|
||||
DATA("traditional", GLOP_TRADITIONAL),
|
||||
DATA("version", GLOP_VERSION),
|
||||
};
|
||||
#undef DATA
|
||||
int match = -1;
|
||||
size_t n;
|
||||
for (n = 0; n < TABLESIZE(table); ++n) {
|
||||
if (!strcmp(s, table[n].name)) {
|
||||
match = table[n].code;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (match >= 0) {
|
||||
switch (match) {
|
||||
case GLOP_HELP:
|
||||
usage();
|
||||
break;
|
||||
case GLOP_POSIX:
|
||||
posix_space_flag = 1;
|
||||
break;
|
||||
case GLOP_TRADITIONAL:
|
||||
posix_space_flag = 0;
|
||||
enable_repetitions(0);
|
||||
break;
|
||||
case GLOP_RE_INTERVAL:
|
||||
enable_repetitions(1);
|
||||
break;
|
||||
case GLOP_VERSION:
|
||||
print_version();
|
||||
break;
|
||||
}
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
errmsg(0, "not an option: %s", s);
|
||||
if (strcmp(s, "--lint")
|
||||
&& strcmp(s, "--lint-old")
|
||||
#ifndef NO_GAWK_OPTIONS
|
||||
&& strcmp(s, "--posix")
|
||||
&& strcmp(s, "--re-interval")
|
||||
&& strcmp(s, "--traditional")
|
||||
#endif
|
||||
) {
|
||||
mawk_exit(2);
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
allow_long_options(char *arg)
|
||||
{
|
||||
static int result = -1;
|
||||
|
||||
if (result < 0) {
|
||||
|
||||
char *env = getenv("MAWK_LONG_OPTIONS");
|
||||
result = 0;
|
||||
if (env != 0) {
|
||||
switch (*env) {
|
||||
default:
|
||||
case 'e': /* error */
|
||||
bad_option(arg);
|
||||
break;
|
||||
case 'w': /* warn */
|
||||
errmsg(0, "ignored option: %s", arg);
|
||||
break;
|
||||
case 'i': /* ignore */
|
||||
break;
|
||||
case 'a': /* allow */
|
||||
result = 1;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
bad_option(arg);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static W_OPTIONS
|
||||
parse_w_opt(char *source, char **next)
|
||||
parse_w_opt(char *source, char **next, int *args)
|
||||
{
|
||||
#define DATA(name) { W_##name, #name }
|
||||
static const struct {
|
||||
W_OPTIONS code;
|
||||
const char *name;
|
||||
} w_options[] = {
|
||||
DATA(VERSION),
|
||||
#if USE_BINMODE
|
||||
DATA(BINMODE),
|
||||
#endif
|
||||
DATA(COMPAT),
|
||||
DATA(DUMP),
|
||||
DATA(EXEC),
|
||||
DATA(HELP),
|
||||
DATA(INTERACTIVE),
|
||||
DATA(POSIX),
|
||||
DATA(RANDOM),
|
||||
DATA(SPRINTF),
|
||||
DATA(USAGE)
|
||||
};
|
||||
#undef DATA
|
||||
W_OPTIONS result = W_UNKNOWN;
|
||||
int n;
|
||||
int match = -1;
|
||||
const char *first;
|
||||
|
||||
*args = 0;
|
||||
|
||||
/* forgive and ignore empty options */
|
||||
while (*source == ',') {
|
||||
++source;
|
||||
@ -336,9 +213,12 @@ parse_w_opt(char *source, char **next)
|
||||
++source;
|
||||
}
|
||||
for (n = 0; n < (int) TABLESIZE(w_options); ++n) {
|
||||
if (w_options[n].mode > 1)
|
||||
continue;
|
||||
if (ok_abbrev(w_options[n].name, first, (int) (source - first))) {
|
||||
if (match >= 0) {
|
||||
errmsg(0, "? ambiguous -W value: %s vs %s\n",
|
||||
errmsg(0, "? ambiguous -W value: \"%.*s\" (%s vs %s)",
|
||||
(int) (source - first), first,
|
||||
w_options[match].name,
|
||||
w_options[n].name);
|
||||
} else {
|
||||
@ -358,237 +238,227 @@ parse_w_opt(char *source, char **next)
|
||||
}
|
||||
*next = source;
|
||||
|
||||
if (match >= 0)
|
||||
if (match >= 0) {
|
||||
result = w_options[match].code;
|
||||
*args = w_options[match].args;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static void
|
||||
process_cmdline(int argc, char **argv)
|
||||
static W_OPTIONS
|
||||
parse_long_opt(char *source, char **next, int *args)
|
||||
{
|
||||
int i, j, nextarg;
|
||||
char *optArg;
|
||||
char *optNext;
|
||||
PFILE dummy; /* starts linked list of filenames */
|
||||
PFILE *tail = &dummy;
|
||||
size_t length;
|
||||
int n;
|
||||
W_OPTIONS result = W_UNKNOWN;
|
||||
const char *first = source;
|
||||
char mark;
|
||||
|
||||
if (argc <= 1)
|
||||
usage();
|
||||
*args = 0;
|
||||
|
||||
for (i = 1; i < argc && argv[i][0] == '-'; i = nextarg) {
|
||||
if (argv[i][1] == 0) /* - alone */
|
||||
{
|
||||
if (!pfile_name)
|
||||
no_program();
|
||||
break; /* the for loop */
|
||||
}
|
||||
/* safe to look at argv[i][2] */
|
||||
|
||||
/*
|
||||
* Check for "long" options and decide how to handle them.
|
||||
*/
|
||||
if (strlen(argv[i]) > 2 && !strncmp(argv[i], "--", (size_t) 2)) {
|
||||
if (!allow_long_options(argv[i])) {
|
||||
nextarg = i + 1;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (argv[i][2] == 0) {
|
||||
if (i == argc - 1 && argv[i][1] != '-') {
|
||||
if (strchr("WFvf", argv[i][1])) {
|
||||
errmsg(0, "option %s lacks argument", argv[i]);
|
||||
mawk_exit(2);
|
||||
}
|
||||
bad_option(argv[i]);
|
||||
}
|
||||
|
||||
optArg = argv[i + 1];
|
||||
nextarg = i + 2;
|
||||
} else { /* argument glued to option */
|
||||
optArg = &argv[i][2];
|
||||
nextarg = i + 1;
|
||||
}
|
||||
|
||||
switch (argv[i][1]) {
|
||||
|
||||
case 'W':
|
||||
for (j = 0; j < (int) strlen(optArg); j = (int) (optNext - optArg)) {
|
||||
switch (parse_w_opt(optArg + j, &optNext)) {
|
||||
case W_VERSION:
|
||||
print_version();
|
||||
break;
|
||||
#if USE_BINMODE
|
||||
case W_BINMODE:
|
||||
if (haveValue(optNext)) {
|
||||
set_binmode(atoi(optNext + 1));
|
||||
optNext = skipValue(optNext);
|
||||
} else {
|
||||
errmsg(0, "missing value for -W binmode");
|
||||
mawk_exit(2);
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
case W_COMPAT:
|
||||
enable_repetitions(0);
|
||||
posix_space_flag = 0;
|
||||
break;
|
||||
|
||||
case W_DUMP:
|
||||
dump_code_flag = 1;
|
||||
break;
|
||||
|
||||
case W_EXEC:
|
||||
if (pfile_name) {
|
||||
errmsg(0, "-W exec is incompatible with -f");
|
||||
mawk_exit(2);
|
||||
} else if (nextarg == argc) {
|
||||
no_program();
|
||||
}
|
||||
if (haveValue(optNext)) {
|
||||
pfile_name = optNext + 1;
|
||||
i = nextarg;
|
||||
} else {
|
||||
pfile_name = argv[nextarg];
|
||||
i = nextarg + 1;
|
||||
}
|
||||
goto no_more_opts;
|
||||
|
||||
case W_INTERACTIVE:
|
||||
interactive_flag = 1;
|
||||
setbuf(stdout, (char *) 0);
|
||||
break;
|
||||
|
||||
case W_POSIX:
|
||||
posix_space_flag = 1;
|
||||
break;
|
||||
|
||||
case W_RANDOM:
|
||||
if (haveValue(optNext)) {
|
||||
int x = atoi(optNext + 1);
|
||||
CELL c[2];
|
||||
|
||||
memset(c, 0, sizeof(c));
|
||||
c[1].type = C_DOUBLE;
|
||||
c[1].dval = (double) x;
|
||||
/* c[1] is input, c[0] is output */
|
||||
bi_srand(c + 1);
|
||||
optNext = skipValue(optNext);
|
||||
} else {
|
||||
errmsg(0, "missing value for -W random");
|
||||
mawk_exit(2);
|
||||
}
|
||||
break;
|
||||
|
||||
case W_SPRINTF:
|
||||
if (haveValue(optNext)) {
|
||||
int x = atoi(optNext + 1);
|
||||
|
||||
if (x > (int) sizeof(string_buff)) {
|
||||
if (sprintf_buff != string_buff &&
|
||||
sprintf_buff != 0) {
|
||||
zfree(sprintf_buff,
|
||||
(size_t) (sprintf_limit - sprintf_buff));
|
||||
}
|
||||
sprintf_buff = (char *) zmalloc((size_t) x);
|
||||
sprintf_limit = sprintf_buff + x;
|
||||
}
|
||||
optNext = skipValue(optNext);
|
||||
} else {
|
||||
errmsg(0, "missing value for -W sprintf");
|
||||
mawk_exit(2);
|
||||
}
|
||||
break;
|
||||
|
||||
case W_HELP:
|
||||
/* FALLTHRU */
|
||||
case W_USAGE:
|
||||
usage();
|
||||
/* NOTREACHED */
|
||||
break;
|
||||
case W_UNKNOWN:
|
||||
errmsg(0, "vacuous option: -W %s", optArg + j);
|
||||
break;
|
||||
}
|
||||
while (*optNext == '=') {
|
||||
errmsg(0, "unexpected option value %s", optArg + j);
|
||||
optNext = skipValue(optNext);
|
||||
}
|
||||
}
|
||||
while (*source != '\0' && *source != '=') {
|
||||
++source;
|
||||
}
|
||||
mark = *source;
|
||||
*source = '\0';
|
||||
for (n = 0; n < (int) TABLESIZE(w_options); ++n) {
|
||||
if (!strcmp(first, w_options[n].name)) {
|
||||
result = w_options[n].code;
|
||||
*args = w_options[n].args;
|
||||
break;
|
||||
}
|
||||
}
|
||||
*source = mark;
|
||||
*next = source;
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
* mawk allows the -W option to have multiple parts, separated by commas. It
|
||||
* does that, to allow multiple -W options in a "sharpbang" line.
|
||||
*
|
||||
* Regarding "sharpbang:
|
||||
* While that is also referred to as a "shebang" or "hashbang" line, those
|
||||
* terms appear to have taken hold after Larry Wall referred to it as
|
||||
* "sharpbang" for changes to rn in 1985. mawk's manual page refers to "magic
|
||||
* number", which is still older, but "sharpbang" is more descriptive. Both
|
||||
* "sharpbang" and "magic number" were used in 4.3BSD, which of course predates
|
||||
* mawk.
|
||||
*
|
||||
* Within each comma-separated chunk, we can have an option value.
|
||||
* For instance:
|
||||
* -Wname1
|
||||
* -Wname1=value1
|
||||
* -Wname1=value1,name2
|
||||
* -Wname1=value1,name2=value2
|
||||
*
|
||||
* The corresponding long-options are blank-separated, but the "=" mark can
|
||||
* be used:
|
||||
* --name1
|
||||
* --name1 value1
|
||||
* --name1=value1
|
||||
* --name1=value1 --name2
|
||||
* --name1=value1 --name2=value2
|
||||
* --name1=value1 --name2 value2
|
||||
*
|
||||
* The caller has to allow for these cases, by checking the updated "value"
|
||||
* after each call.
|
||||
*/
|
||||
static int
|
||||
handle_w_opt(W_OPTIONS code, int glue, char *option, char **value)
|
||||
{
|
||||
char *optNext = *value;
|
||||
int result = 1;
|
||||
int wantArg = 0;
|
||||
|
||||
switch (code) {
|
||||
case W_VERSION:
|
||||
print_version(stdout);
|
||||
break;
|
||||
#if USE_BINMODE
|
||||
case W_BINMODE:
|
||||
wantArg = 1;
|
||||
if (optNext != 0) {
|
||||
set_binmode(atoi(optNext));
|
||||
wantArg = 2;
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
case W_TRADITIONAL:
|
||||
enable_repetitions(0);
|
||||
posix_space_flag = 0;
|
||||
break;
|
||||
|
||||
case W_DUMP:
|
||||
dump_code_flag = 1;
|
||||
break;
|
||||
|
||||
case W_EXEC:
|
||||
if (pfile_name) {
|
||||
errmsg(0, "-W exec is incompatible with -f");
|
||||
mawk_exit(2);
|
||||
}
|
||||
wantArg = 1;
|
||||
if (optNext != 0) {
|
||||
pfile_name = optNext;
|
||||
wantArg = 2;
|
||||
} else {
|
||||
no_program();
|
||||
}
|
||||
result = 0; /* no_more_opts */
|
||||
break;
|
||||
|
||||
case W_INTERACTIVE:
|
||||
interactive_flag = 1;
|
||||
setbuf(stdout, (char *) 0);
|
||||
break;
|
||||
|
||||
case W_POSIX:
|
||||
posix_space_flag = 1;
|
||||
break;
|
||||
|
||||
case W_RANDOM:
|
||||
wantArg = 1;
|
||||
if (optNext != 0) {
|
||||
int x = atoi(optNext);
|
||||
CELL c[2];
|
||||
|
||||
memset(c, 0, sizeof(c));
|
||||
c[1].type = C_DOUBLE;
|
||||
c[1].dval = (double) x;
|
||||
/* c[1] is input, c[0] is output */
|
||||
bi_srand(c + 1);
|
||||
wantArg = 2;
|
||||
}
|
||||
break;
|
||||
|
||||
#ifndef NO_INTERVAL_EXPR
|
||||
case 'r':
|
||||
enable_repetitions(1);
|
||||
break;
|
||||
case W_RE_INTERVAL:
|
||||
enable_repetitions(1);
|
||||
break;
|
||||
#endif
|
||||
|
||||
case 'v':
|
||||
if (!is_cmdline_assign(optArg)) {
|
||||
errmsg(0, "improper assignment: -v %s", optArg);
|
||||
mawk_exit(2);
|
||||
case W_SPRINTF:
|
||||
wantArg = 1;
|
||||
if (optNext != 0) {
|
||||
int x = atoi(optNext);
|
||||
|
||||
if (x > (int) sizeof(string_buff)) {
|
||||
if (sprintf_buff != string_buff &&
|
||||
sprintf_buff != 0) {
|
||||
zfree(sprintf_buff,
|
||||
(size_t) (sprintf_limit - sprintf_buff));
|
||||
}
|
||||
sprintf_buff = (char *) zmalloc((size_t) x);
|
||||
sprintf_limit = sprintf_buff + x;
|
||||
}
|
||||
break;
|
||||
wantArg = 2;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'F':
|
||||
case W_HELP:
|
||||
/* FALLTHRU */
|
||||
case W_USAGE:
|
||||
usage(stdout);
|
||||
/* NOTREACHED */
|
||||
break;
|
||||
case W_UNKNOWN:
|
||||
errmsg(0, "vacuous option: -W \"%s\"", option);
|
||||
break;
|
||||
case W__IGNORE:
|
||||
break;
|
||||
}
|
||||
if (wantArg) {
|
||||
if (wantArg == 1) {
|
||||
int length = (int) (skipValue(option) - option);
|
||||
errmsg(0, "missing value for -W \"%.*s\"", length, option);
|
||||
mawk_exit(2);
|
||||
}
|
||||
optNext = skipValue(optNext);
|
||||
} else {
|
||||
while (glue) {
|
||||
errmsg(0, "unexpected option value \"%s\"", option);
|
||||
optNext = skipValue(optNext);
|
||||
glue = haveValue(optNext);
|
||||
}
|
||||
}
|
||||
*value = optNext;
|
||||
return result;
|
||||
}
|
||||
|
||||
rm_escape(optArg, &length); /* recognize escape sequences */
|
||||
cell_destroy(FS);
|
||||
FS->type = C_STRING;
|
||||
FS->ptr = (PTR) new_STRING1(optArg, length);
|
||||
cast_for_split(cellcpy(&fs_shadow, FS));
|
||||
break;
|
||||
static void
|
||||
bad_option(const char *s)
|
||||
{
|
||||
errmsg(0, "not an option: %s", s);
|
||||
mawk_exit(2);
|
||||
}
|
||||
|
||||
case '-':
|
||||
if (argv[i][2] != 0) {
|
||||
bad_option(argv[i]);
|
||||
}
|
||||
i++;
|
||||
goto no_more_opts;
|
||||
|
||||
case 'f':
|
||||
/* first file goes in pfile_name ; any more go
|
||||
on a list */
|
||||
if (!pfile_name)
|
||||
pfile_name = optArg;
|
||||
else {
|
||||
tail = tail->link = ZMALLOC(PFILE);
|
||||
tail->fname = optArg;
|
||||
}
|
||||
break;
|
||||
static int
|
||||
allow_long_options(char *arg, W_OPTIONS seen)
|
||||
{
|
||||
char *env = getenv("MAWK_LONG_OPTIONS");
|
||||
int result = 0;
|
||||
|
||||
if (env != 0) {
|
||||
switch (*env) {
|
||||
default:
|
||||
bad_option(argv[i]);
|
||||
case 'e': /* error */
|
||||
bad_option(arg);
|
||||
break;
|
||||
case 'w': /* warn */
|
||||
errmsg(0, "ignored option: %s", arg);
|
||||
break;
|
||||
case 'i': /* ignore */
|
||||
result = (seen != W_UNKNOWN);
|
||||
break;
|
||||
case 'a': /* allow */
|
||||
result = 1;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
result = (seen != W_UNKNOWN);
|
||||
}
|
||||
|
||||
no_more_opts:
|
||||
|
||||
tail->link = (PFILE *) 0;
|
||||
pfile_list = dummy.link;
|
||||
|
||||
if (pfile_name) {
|
||||
set_ARGV(argc, argv, i);
|
||||
scan_init((char *) 0);
|
||||
} else { /* program on command line */
|
||||
if (i == argc)
|
||||
no_program();
|
||||
set_ARGV(argc, argv, i + 1);
|
||||
|
||||
#if defined(MSDOS) && ! HAVE_REARGV /* reversed quotes */
|
||||
{
|
||||
char *p;
|
||||
|
||||
for (p = argv[i]; *p; p++)
|
||||
if (*p == '\'')
|
||||
*p = '\"';
|
||||
}
|
||||
#endif
|
||||
scan_init(argv[i]);
|
||||
/* #endif */
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/* argv[i] = ARGV[i] */
|
||||
@ -622,6 +492,163 @@ set_ARGV(int argc, char **argv, int i)
|
||||
ARGC->dval = argi.dval;
|
||||
}
|
||||
|
||||
static void
|
||||
process_cmdline(int argc, char **argv)
|
||||
{
|
||||
int i, j, nextarg;
|
||||
char *curArg;
|
||||
char *optArg;
|
||||
char *optNext;
|
||||
PFILE dummy; /* starts linked list of filenames */
|
||||
PFILE *tail = &dummy;
|
||||
size_t length;
|
||||
|
||||
if (argc <= 1)
|
||||
usage(stderr);
|
||||
|
||||
for (i = 1; i < argc && *(curArg = argv[i]) == '-'; i = nextarg) {
|
||||
if (curArg[1] == 0) {
|
||||
/* "-" alone */
|
||||
if (!pfile_name)
|
||||
no_program();
|
||||
break; /* the for loop */
|
||||
}
|
||||
/* safe to look at argv[i][2] */
|
||||
|
||||
/*
|
||||
* Check for "long" options and decide how to handle them.
|
||||
*/
|
||||
if (strlen(curArg) > 2 && !strncmp(curArg, "--", (size_t) 2)) {
|
||||
char *name = curArg + 2;
|
||||
int args;
|
||||
W_OPTIONS code = parse_long_opt(name, &optNext, &args);
|
||||
nextarg = i + 1;
|
||||
if (allow_long_options(curArg, code)) {
|
||||
int glue = haveValue(optNext);
|
||||
char *optValue = (glue
|
||||
? (optNext + 1)
|
||||
: (args
|
||||
? argv[nextarg++]
|
||||
: NULL));
|
||||
if (!handle_w_opt(code, glue, name, &optValue)) {
|
||||
goto no_more_opts;
|
||||
}
|
||||
optNext = optValue;
|
||||
} else {
|
||||
bad_option(curArg);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (curArg[2] == 0) {
|
||||
if (i == argc - 1 && curArg[1] != '-') {
|
||||
if (strchr("WFvf", curArg[1])) {
|
||||
errmsg(0, "option %s lacks argument", curArg);
|
||||
mawk_exit(2);
|
||||
}
|
||||
bad_option(curArg);
|
||||
}
|
||||
|
||||
optArg = argv[i + 1];
|
||||
nextarg = i + 2;
|
||||
} else { /* argument glued to option */
|
||||
optArg = &curArg[2];
|
||||
nextarg = i + 1;
|
||||
}
|
||||
|
||||
switch (curArg[1]) {
|
||||
|
||||
case 'W':
|
||||
for (j = 0; j < (int) strlen(optArg); j = (int) (optNext - optArg)) {
|
||||
char *name = optArg + j;
|
||||
int args = 0;
|
||||
W_OPTIONS code = parse_w_opt(name, &optNext, &args);
|
||||
int glue = haveValue(optNext);
|
||||
char *optValue = (glue
|
||||
? (optNext + 1)
|
||||
: ((strchr(optNext, ',') == NULL)
|
||||
? (args && argv[nextarg]
|
||||
? argv[nextarg++]
|
||||
: NULL)
|
||||
: NULL));
|
||||
if (!handle_w_opt(code, glue, name, &optValue))
|
||||
goto no_more_opts;
|
||||
optNext = optValue;
|
||||
}
|
||||
break;
|
||||
|
||||
#ifndef NO_INTERVAL_EXPR
|
||||
case 'r':
|
||||
enable_repetitions(1);
|
||||
break;
|
||||
#endif
|
||||
|
||||
case 'v':
|
||||
if (!is_cmdline_assign(optArg)) {
|
||||
errmsg(0, "improper assignment: -v %s", optArg);
|
||||
mawk_exit(2);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'F':
|
||||
|
||||
rm_escape(optArg, &length); /* recognize escape sequences */
|
||||
cell_destroy(FS);
|
||||
FS->type = C_STRING;
|
||||
FS->ptr = (PTR) new_STRING1(optArg, length);
|
||||
cast_for_split(cellcpy(&fs_shadow, FS));
|
||||
break;
|
||||
|
||||
case '-':
|
||||
if (curArg[2] != 0) {
|
||||
bad_option(curArg);
|
||||
}
|
||||
i++;
|
||||
goto no_more_opts;
|
||||
|
||||
case 'f':
|
||||
/* first file goes in pfile_name ; any more go
|
||||
on a list */
|
||||
if (!pfile_name)
|
||||
pfile_name = optArg;
|
||||
else {
|
||||
tail = tail->link = ZMALLOC(PFILE);
|
||||
tail->fname = optArg;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
bad_option(curArg);
|
||||
}
|
||||
}
|
||||
|
||||
no_more_opts:
|
||||
|
||||
tail->link = (PFILE *) 0;
|
||||
pfile_list = dummy.link;
|
||||
|
||||
if (pfile_name) {
|
||||
set_ARGV(argc, argv, i);
|
||||
scan_init((char *) 0);
|
||||
} else { /* program on command line */
|
||||
if (i == argc)
|
||||
no_program();
|
||||
set_ARGV(argc, argv, i + 1);
|
||||
|
||||
#if defined(MSDOS) && ! HAVE_REARGV /* reversed quotes */
|
||||
{
|
||||
char *p;
|
||||
|
||||
for (p = curArg; *p; p++)
|
||||
if (*p == '\'')
|
||||
*p = '\"';
|
||||
}
|
||||
#endif
|
||||
scan_init(curArg);
|
||||
/* #endif */
|
||||
}
|
||||
}
|
||||
|
||||
/*----- ENVIRON ----------*/
|
||||
|
||||
#ifdef DECL_ENVIRON
|
||||
@ -659,6 +686,37 @@ load_environ(ARRAY ENV)
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
initialize(int argc, char **argv)
|
||||
{
|
||||
|
||||
SET_PROGNAME();
|
||||
|
||||
bi_vars_init(); /* load the builtin variables */
|
||||
bi_funct_init(); /* load the builtin functions */
|
||||
kw_init(); /* load the keywords */
|
||||
field_init();
|
||||
|
||||
#if USE_BINMODE
|
||||
{
|
||||
char *p = getenv("MAWKBINMODE");
|
||||
|
||||
if (p)
|
||||
set_binmode(atoi(p));
|
||||
}
|
||||
#endif
|
||||
|
||||
process_cmdline(argc, argv);
|
||||
|
||||
code_init();
|
||||
fpe_init();
|
||||
set_stdio();
|
||||
|
||||
#if USE_BINMODE
|
||||
stdout_init();
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef NO_LEAKS
|
||||
typedef struct _all_arrays {
|
||||
struct _all_arrays *next;
|
||||
|
||||
6
init.h
6
init.h
@ -1,6 +1,6 @@
|
||||
/********************************************
|
||||
init.h
|
||||
copyright 2009-2012,2016, Thomas E. Dickey
|
||||
copyright 2009-2016,2020, Thomas E. Dickey
|
||||
copyright 1991, Michael D. Brennan
|
||||
|
||||
This is a source file for mawk, an implementation of
|
||||
@ -11,7 +11,7 @@ the GNU General Public License, version 2, 1991.
|
||||
********************************************/
|
||||
|
||||
/*
|
||||
* $MawkId: init.h,v 1.6 2016/09/30 23:37:13 tom Exp $
|
||||
* $MawkId: init.h,v 1.7 2020/08/26 00:52:06 tom Exp $
|
||||
*/
|
||||
|
||||
/* init.h */
|
||||
@ -47,7 +47,7 @@ void fpe_init(void);
|
||||
void load_environ(ARRAY);
|
||||
void set_stdio(void);
|
||||
|
||||
void print_version(void);
|
||||
void print_version(FILE *fp);
|
||||
int is_cmdline_assign(char *);
|
||||
|
||||
#endif /* INIT_H */
|
||||
|
||||
12
kw.c
12
kw.c
@ -1,6 +1,6 @@
|
||||
/********************************************
|
||||
kw.c
|
||||
copyright 2008-2012,2016, Thomas E. Dickey
|
||||
copyright 2008-2016,2020, Thomas E. Dickey
|
||||
copyright 1991-1993, Michael D. Brennan
|
||||
|
||||
This is a source file for mawk, an implementation of
|
||||
@ -11,7 +11,7 @@ the GNU General Public License, version 2, 1991.
|
||||
********************************************/
|
||||
|
||||
/*
|
||||
* $MawkId: kw.c,v 1.7 2016/09/29 23:02:51 tom Exp $
|
||||
* $MawkId: kw.c,v 1.8 2020/08/25 20:33:33 tom Exp $
|
||||
*/
|
||||
|
||||
/* kw.c */
|
||||
@ -23,7 +23,7 @@ the GNU General Public License, version 2, 1991.
|
||||
/* *INDENT-OFF* */
|
||||
static const struct kw
|
||||
{
|
||||
const char *text;
|
||||
const char text[12];
|
||||
short kw;
|
||||
}
|
||||
keywords[] =
|
||||
@ -51,7 +51,7 @@ keywords[] =
|
||||
{ "sub", SUB },
|
||||
{ "gsub", GSUB },
|
||||
{ "function", FUNCTION },
|
||||
{ (char *) 0, 0 }
|
||||
{ "", 0 }
|
||||
};
|
||||
/* *INDENT-ON* */
|
||||
|
||||
@ -62,7 +62,7 @@ kw_init(void)
|
||||
register const struct kw *p = keywords;
|
||||
register SYMTAB *q;
|
||||
|
||||
while (p->text) {
|
||||
while (p->text[0]) {
|
||||
q = insert(p->text);
|
||||
q->type = ST_KEYWORD;
|
||||
q->stval.kw = p++->kw;
|
||||
@ -75,7 +75,7 @@ find_kw_str(int kw_token)
|
||||
{
|
||||
const struct kw *p;
|
||||
|
||||
for (p = keywords; p->text; p++)
|
||||
for (p = keywords; p->text[0]; p++)
|
||||
if (p->kw == kw_token)
|
||||
return p->text;
|
||||
/* search failed */
|
||||
|
||||
22
man/mawk.1
22
man/mawk.1
@ -1,4 +1,4 @@
|
||||
.\" $MawkId: mawk.1,v 1.56 2020/08/21 23:54:28 tom Exp $
|
||||
.\" $MawkId: mawk.1,v 1.58 2020/08/26 22:11:20 tom Exp $
|
||||
.\" ###########################################################################
|
||||
.\" # copyright 2008-2019,2020, Thomas E. Dickey
|
||||
.\" # copyright 1996, Michael D. Brennan
|
||||
@ -11,7 +11,7 @@
|
||||
.\" ###########################################################################
|
||||
.ds N Mawk
|
||||
.ds n mawk
|
||||
.TH MAWK 1 "2020-08-21" "Version 1.3.4" "USER COMMANDS"
|
||||
.TH MAWK 1 "2020-08-26" "Version 1.3.4" "USER COMMANDS"
|
||||
.\" strings
|
||||
.ds ex \fIexpr\fR
|
||||
.\" Bulleted paragraph
|
||||
@ -120,10 +120,6 @@ Implementation specific options are prefaced with
|
||||
\fB\*n\fP
|
||||
provides these:
|
||||
.TP
|
||||
\-\fBW \fRcompat
|
||||
Omit features such as interval expressions which were not supported by
|
||||
traditional \fIawk\fP.
|
||||
.TP
|
||||
\-\fBW \fRdump
|
||||
writes an assembler like listing of the internal
|
||||
representation of the program to stdout and exits 0
|
||||
@ -175,6 +171,10 @@ More than rare use of this option indicates
|
||||
\fB\*n\fP
|
||||
should be recompiled.
|
||||
.TP
|
||||
\-\fBW \fRtraditional
|
||||
Omit features such as interval expressions which were not supported by
|
||||
traditional \fIawk\fP.
|
||||
.TP
|
||||
\-\fBW \fRusage
|
||||
prints a usage message to stderr and exits (same as \*(``\-\fBW\ \fRhelp\*('').
|
||||
.TP
|
||||
@ -434,7 +434,7 @@ meaning in regular expressions are
|
||||
\\ ^ $ . [ ] | ( ) * + ? { }
|
||||
.sp
|
||||
.fi
|
||||
If the command line option \fI-W compat\fP is used, these are omitted:
|
||||
If the command line option \fI-W traditional\fP is used, these are omitted:
|
||||
.nf
|
||||
.sp
|
||||
{ }
|
||||
@ -1941,13 +1941,19 @@ GNU-style long options:
|
||||
allow
|
||||
\fB\*N\fP allows the option to be checked against the (small) set of
|
||||
long options it recognizes.
|
||||
.IP
|
||||
The long names from the \fB\-W\fP option are recognized,
|
||||
e.g.,
|
||||
\fB\-\-version\fP is derived from
|
||||
\fB\-Wversion\fP.
|
||||
.TP
|
||||
error
|
||||
\fB\*N\fP prints an error message and exits.
|
||||
This is the default.
|
||||
.TP
|
||||
ignore
|
||||
\fB\*N\fP ignores the option.
|
||||
\fB\*N\fP ignores the option,
|
||||
unless it happens to be one of the one it recognizes.
|
||||
.TP
|
||||
warn
|
||||
Print an warning message and otherwise ignore the option.
|
||||
|
||||
40
man/mawk.doc
40
man/mawk.doc
@ -46,32 +46,28 @@ OOPPTTIIOONNSS
|
||||
tation of AWK. Implementation specific options are prefaced with --WW.
|
||||
mmaawwkk provides these:
|
||||
|
||||
-WW compat
|
||||
Omit features such as interval expressions which were not sup-
|
||||
ported by traditional _a_w_k.
|
||||
|
||||
-WW dump
|
||||
writes an assembler like listing of the internal representation
|
||||
of the program to stdout and exits 0 (on successful compila-
|
||||
writes an assembler like listing of the internal representation
|
||||
of the program to stdout and exits 0 (on successful compila-
|
||||
tion).
|
||||
|
||||
-WW exec _f_i_l_e
|
||||
Program text is read from _f_i_l_e and this is the last option.
|
||||
|
||||
This is a useful alternative to -ff on systems that support the
|
||||
##!! "magic number" convention for executable scripts. Those
|
||||
implicitly pass the pathname of the script itself as the final
|
||||
parameter, and expect no more than one "-" option on the ##!!
|
||||
This is a useful alternative to -ff on systems that support the
|
||||
##!! "magic number" convention for executable scripts. Those
|
||||
implicitly pass the pathname of the script itself as the final
|
||||
parameter, and expect no more than one "-" option on the ##!!
|
||||
line. Because mmaawwkk can combine multiple -WW options separated by
|
||||
commas, you can use this option when an additional -WW option is
|
||||
commas, you can use this option when an additional -WW option is
|
||||
needed.
|
||||
|
||||
-WW help
|
||||
prints a usage message to stderr and exits (same as "-WW usage").
|
||||
|
||||
-WW interactive
|
||||
sets unbuffered writes to stdout and line buffered reads from
|
||||
stdin. Records from stdin are lines regardless of the value of
|
||||
sets unbuffered writes to stdout and line buffered reads from
|
||||
stdin. Records from stdin are lines regardless of the value of
|
||||
RRSS.
|
||||
|
||||
-WW posix
|
||||
@ -82,14 +78,18 @@ OOPPTTIIOONNSS
|
||||
The original "posix_space" is recognized, but deprecated.
|
||||
|
||||
-WW random=_n_u_m
|
||||
calls ssrraanndd with the given parameter (and overrides the auto-
|
||||
calls ssrraanndd with the given parameter (and overrides the auto-
|
||||
seeding behavior).
|
||||
|
||||
-WW sprintf=_n_u_m
|
||||
adjusts the size of mmaawwkk's internal sprintf buffer to _n_u_m bytes.
|
||||
More than rare use of this option indicates mmaawwkk should be
|
||||
More than rare use of this option indicates mmaawwkk should be
|
||||
recompiled.
|
||||
|
||||
-WW traditional
|
||||
Omit features such as interval expressions which were not sup-
|
||||
ported by traditional _a_w_k.
|
||||
|
||||
-WW usage
|
||||
prints a usage message to stderr and exits (same as "-WW help").
|
||||
|
||||
@ -242,7 +242,7 @@ TTHHEE AAWWKK LLAANNGGUUAAGGEE
|
||||
|
||||
\ ^ $ . [ ] | ( ) * + ? { }
|
||||
|
||||
If the command line option _-_W _c_o_m_p_a_t is used, these are omitted:
|
||||
If the command line option _-_W _t_r_a_d_i_t_i_o_n_a_l is used, these are omitted:
|
||||
|
||||
{ }
|
||||
|
||||
@ -1130,10 +1130,14 @@ EENNVVIIRROONNMMEENNTT VVAARRIIAABBLLEESS
|
||||
allow MMaawwkk allows the option to be checked against the (small)
|
||||
set of long options it recognizes.
|
||||
|
||||
The long names from the --WW option are recognized, e.g.,
|
||||
----vveerrssiioonn is derived from --WWvveerrssiioonn.
|
||||
|
||||
error MMaawwkk prints an error message and exits. This is the de-
|
||||
fault.
|
||||
|
||||
ignore MMaawwkk ignores the option.
|
||||
ignore MMaawwkk ignores the option, unless it happens to be one of
|
||||
the one it recognizes.
|
||||
|
||||
warn Print an warning message and otherwise ignore the op-
|
||||
tion.
|
||||
@ -1180,4 +1184,4 @@ AAUUTTHHOORR
|
||||
|
||||
|
||||
|
||||
Version 1.3.4 2020-08-21 MAWK(1)
|
||||
Version 1.3.4 2020-08-26 MAWK(1)
|
||||
|
||||
40
man/mawk.txt
40
man/mawk.txt
@ -46,32 +46,28 @@ OPTIONS
|
||||
tation of AWK. Implementation specific options are prefaced with -W.
|
||||
mawk provides these:
|
||||
|
||||
-W compat
|
||||
Omit features such as interval expressions which were not sup-
|
||||
ported by traditional awk.
|
||||
|
||||
-W dump
|
||||
writes an assembler like listing of the internal representation
|
||||
of the program to stdout and exits 0 (on successful compila-
|
||||
writes an assembler like listing of the internal representation
|
||||
of the program to stdout and exits 0 (on successful compila-
|
||||
tion).
|
||||
|
||||
-W exec file
|
||||
Program text is read from file and this is the last option.
|
||||
|
||||
This is a useful alternative to -f on systems that support the
|
||||
#! "magic number" convention for executable scripts. Those
|
||||
implicitly pass the pathname of the script itself as the final
|
||||
parameter, and expect no more than one "-" option on the #!
|
||||
This is a useful alternative to -f on systems that support the
|
||||
#! "magic number" convention for executable scripts. Those
|
||||
implicitly pass the pathname of the script itself as the final
|
||||
parameter, and expect no more than one "-" option on the #!
|
||||
line. Because mawk can combine multiple -W options separated by
|
||||
commas, you can use this option when an additional -W option is
|
||||
commas, you can use this option when an additional -W option is
|
||||
needed.
|
||||
|
||||
-W help
|
||||
prints a usage message to stderr and exits (same as "-W usage").
|
||||
|
||||
-W interactive
|
||||
sets unbuffered writes to stdout and line buffered reads from
|
||||
stdin. Records from stdin are lines regardless of the value of
|
||||
sets unbuffered writes to stdout and line buffered reads from
|
||||
stdin. Records from stdin are lines regardless of the value of
|
||||
RS.
|
||||
|
||||
-W posix
|
||||
@ -82,14 +78,18 @@ OPTIONS
|
||||
The original "posix_space" is recognized, but deprecated.
|
||||
|
||||
-W random=num
|
||||
calls srand with the given parameter (and overrides the auto-
|
||||
calls srand with the given parameter (and overrides the auto-
|
||||
seeding behavior).
|
||||
|
||||
-W sprintf=num
|
||||
adjusts the size of mawk's internal sprintf buffer to num bytes.
|
||||
More than rare use of this option indicates mawk should be
|
||||
More than rare use of this option indicates mawk should be
|
||||
recompiled.
|
||||
|
||||
-W traditional
|
||||
Omit features such as interval expressions which were not sup-
|
||||
ported by traditional awk.
|
||||
|
||||
-W usage
|
||||
prints a usage message to stderr and exits (same as "-W help").
|
||||
|
||||
@ -242,7 +242,7 @@ THE AWK LANGUAGE
|
||||
|
||||
\ ^ $ . [ ] | ( ) * + ? { }
|
||||
|
||||
If the command line option -W compat is used, these are omitted:
|
||||
If the command line option -W traditional is used, these are omitted:
|
||||
|
||||
{ }
|
||||
|
||||
@ -1130,10 +1130,14 @@ ENVIRONMENT VARIABLES
|
||||
allow Mawk allows the option to be checked against the (small)
|
||||
set of long options it recognizes.
|
||||
|
||||
The long names from the -W option are recognized, e.g.,
|
||||
--version is derived from -Wversion.
|
||||
|
||||
error Mawk prints an error message and exits. This is the de-
|
||||
fault.
|
||||
|
||||
ignore Mawk ignores the option.
|
||||
ignore Mawk ignores the option, unless it happens to be one of
|
||||
the one it recognizes.
|
||||
|
||||
warn Print an warning message and otherwise ignore the op-
|
||||
tion.
|
||||
@ -1180,4 +1184,4 @@ AUTHOR
|
||||
|
||||
|
||||
|
||||
Version 1.3.4 2020-08-21 MAWK(1)
|
||||
Version 1.3.4 2020-08-26 MAWK(1)
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
mawk-cur (1.3.4-20200821) unstable; urgency=low
|
||||
mawk-cur (1.3.4-20200828) unstable; urgency=low
|
||||
|
||||
* maintenance updates
|
||||
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
Summary: mawk - pattern scanning and text processing language
|
||||
%define AppProgram mawk
|
||||
%define AppVersion 1.3.4
|
||||
%define AppRelease 20200821
|
||||
# $MawkId: mawk.spec,v 1.80 2020/08/18 22:45:04 tom Exp $
|
||||
%define AppRelease 20200828
|
||||
# $MawkId: mawk.spec,v 1.81 2020/08/22 08:40:48 tom Exp $
|
||||
Name: %{AppProgram}
|
||||
Version: %{AppVersion}
|
||||
Release: %{AppRelease}
|
||||
|
||||
@ -11,9 +11,9 @@ the GNU General Public License, version 2, 1991.
|
||||
*/
|
||||
|
||||
/*
|
||||
* $MawkId: patchlev.h,v 1.106 2020/08/18 22:45:04 tom Exp $
|
||||
* $MawkId: patchlev.h,v 1.107 2020/08/22 08:40:48 tom Exp $
|
||||
*/
|
||||
#define PATCH_BASE 1
|
||||
#define PATCH_LEVEL 3
|
||||
#define PATCH_STRING ".4"
|
||||
#define DATE_STRING "20200821"
|
||||
#define DATE_STRING "20200828"
|
||||
|
||||
6
rexp0.c
6
rexp0.c
@ -12,7 +12,7 @@ the GNU General Public License, version 2, 1991.
|
||||
********************************************/
|
||||
|
||||
/*
|
||||
* $MawkId: rexp0.c,v 1.43 2020/07/30 22:36:55 tom Exp $
|
||||
* $MawkId: rexp0.c,v 1.44 2020/08/25 19:34:57 tom Exp $
|
||||
*/
|
||||
|
||||
/* lexical scanner */
|
||||
@ -521,7 +521,7 @@ lookup_cclass(char **start)
|
||||
static CCLASS *cclass_data[CCLASS_xdigit];
|
||||
static const struct {
|
||||
CCLASS_ENUM code;
|
||||
const char *name;
|
||||
const char name[8];
|
||||
unsigned size;
|
||||
} cclass_table[] = {
|
||||
CCLASS_DATA(alnum),
|
||||
@ -915,7 +915,7 @@ store_bvp(BV * bvp)
|
||||
#define isoctal(x) ((x)>='0'&&(x)<='7')
|
||||
|
||||
#define NOT_HEX 16
|
||||
static char hex_val['f' - 'A' + 1] =
|
||||
static const char hex_val['f' - 'A' + 1] =
|
||||
{
|
||||
10, 11, 12, 13, 14, 15, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
|
||||
6
rexpdb.c
6
rexpdb.c
@ -1,6 +1,6 @@
|
||||
/********************************************
|
||||
rexpdb.c
|
||||
copyright 2008-2014,2016, Thomas E. Dickey
|
||||
copyright 2008-2016,2020, Thomas E. Dickey
|
||||
copyright 1991,1993, Michael D. Brennan
|
||||
|
||||
This is a source file for mawk, an implementation of
|
||||
@ -11,7 +11,7 @@ the GNU General Public License, version 2, 1991.
|
||||
********************************************/
|
||||
|
||||
/*
|
||||
* $MawkId: rexpdb.c,v 1.16 2016/09/30 21:27:07 tom Exp $
|
||||
* $MawkId: rexpdb.c,v 1.17 2020/08/25 19:52:24 tom Exp $
|
||||
*/
|
||||
|
||||
#include "rexp.h"
|
||||
@ -19,7 +19,7 @@ the GNU General Public License, version 2, 1991.
|
||||
|
||||
/* print a machine for debugging */
|
||||
|
||||
static const char *xlat[] =
|
||||
static const char xlat[][12] =
|
||||
{
|
||||
"M_STR",
|
||||
"M_CLASS",
|
||||
|
||||
28
version.c
28
version.c
@ -11,7 +11,7 @@ the GNU General Public License, version 2, 1991.
|
||||
********************************************/
|
||||
|
||||
/*
|
||||
* $MawkId: version.c,v 1.29 2020/07/19 15:02:30 tom Exp $
|
||||
* $MawkId: version.c,v 1.31 2020/08/26 00:50:58 tom Exp $
|
||||
*/
|
||||
|
||||
#include "mawk.h"
|
||||
@ -28,32 +28,34 @@ Copyright 1991-1996,2014, Michael D. Brennan\n\n"
|
||||
|
||||
/* print VERSION and exit */
|
||||
void
|
||||
print_version(void)
|
||||
print_version(FILE *fp)
|
||||
{
|
||||
printf(VERSION_STRING, PATCH_BASE, PATCH_LEVEL, PATCH_STRING, DATE_STRING);
|
||||
fflush(stdout);
|
||||
fprintf(fp, VERSION_STRING, PATCH_BASE, PATCH_LEVEL, PATCH_STRING, DATE_STRING);
|
||||
fflush(fp);
|
||||
|
||||
#define SHOW_RANDOM "random-funcs:"
|
||||
#if defined(NAME_RANDOM)
|
||||
fprintf(stderr, FMT_S, SHOW_RANDOM, NAME_RANDOM);
|
||||
fprintf(fp, FMT_S, SHOW_RANDOM, NAME_RANDOM);
|
||||
#else
|
||||
fprintf(stderr, FMT_S, SHOW_RANDOM, "internal");
|
||||
fprintf(fp, FMT_S, SHOW_RANDOM, "internal");
|
||||
#endif
|
||||
|
||||
#define SHOW_REGEXP "regex-funcs:"
|
||||
#ifdef LOCAL_REGEXP
|
||||
fprintf(stderr, FMT_S, SHOW_REGEXP, "internal");
|
||||
fprintf(fp, FMT_S, SHOW_REGEXP, "internal");
|
||||
#else
|
||||
fprintf(stderr, FMT_S, SHOW_REGEXP, "external");
|
||||
fprintf(fp, FMT_S, SHOW_REGEXP, "external");
|
||||
#endif
|
||||
|
||||
fprintf(stderr, "\ncompiled limits:\n");
|
||||
fprintf(stderr, FMT_N, "sprintf buffer", (double) SPRINTF_LIMIT);
|
||||
fprintf(stderr, FMT_N, "maximum-integer", (double) MAX__INT);
|
||||
fprintf(fp, "\ncompiled limits:\n");
|
||||
fprintf(fp, FMT_N, "sprintf buffer", (double) SPRINTF_LIMIT);
|
||||
fprintf(fp, FMT_N, "maximum-integer", (double) MAX__INT);
|
||||
#if 0
|
||||
/* we could show these, but for less benefit: */
|
||||
fprintf(stderr, FMT_N, "maximum-unsigned", (double) MAX__UINT);
|
||||
fprintf(stderr, FMT_N, "maximum-long", (double) MAX__LONG);
|
||||
fprintf(fp, FMT_N, "maximum-unsigned", (double) MAX__UINT);
|
||||
fprintf(fp, FMT_N, "maximum-long", (double) MAX__LONG);
|
||||
fprintf(fp, "\nactual limits:\n");
|
||||
fprintf(fp, FMT_N, "sprintf buffer", (double) (sprintf_limit - sprintf_buff));
|
||||
#endif
|
||||
mawk_exit(0);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user