snapshot of project "mawk", label t20230725

This commit is contained in:
Thomas E. Dickey 2023-07-25 23:42:42 +00:00
parent 3c50bf6450
commit 25b53a1ae2
No known key found for this signature in database
GPG Key ID: CC2AF4472167BE03
47 changed files with 1766 additions and 1674 deletions

View File

@ -1,10 +1,15 @@
-- $MawkId: CHANGES,v 1.348 2023/07/16 23:11:31 tom Exp $
-- $MawkId: CHANGES,v 1.351 2023/07/25 23:33:45 tom Exp $
NOTE:
The regular expression changes begun in 2020 are incomplete, e.g., do
not handle a mixture of grouping and brace expressions. Fixing that
issue is needed before a new stable release.
20230725
+ use da_string more consistently in dumps.
+ improve scanner to some type-checks of arrays versus scalars by
deferring this into the runtime execution (report by Rajeev V Pillai).
20230716
+ modify scanner to accommodate scripts which use the same name for
some function-parameters as for a function (report by Kaz Kylheku).

View File

@ -1,4 +1,4 @@
MANIFEST for mawk, version t20230716
MANIFEST for mawk, version t20230725
--------------------------------------------------------------------------------
MANIFEST this file
ACKNOWLEDGMENT acknowledgements

View File

@ -11,7 +11,7 @@ the GNU General Public License, version 2, 1991.
********************************************/
/*
* $MawkId: bi_funct.c,v 1.117 2023/04/04 23:39:23 tom Exp $
* $MawkId: bi_funct.c,v 1.118 2023/07/24 08:23:33 tom Exp $
*/
#include <mawk.h>
@ -54,7 +54,6 @@ the GNU General Public License, version 2, 1991.
const BI_REC bi_funct[] =
{ /* info to load builtins */
{ "length", bi_length, 0, 1 }, /* special must come first */
{ "index", bi_index, 2, 2 },
{ "substr", bi_substr, 2, 3 },
{ "sprintf", bi_sprintf, 1, 255 },
@ -93,12 +92,7 @@ bi_funct_init(void)
register const BI_REC *p;
register SYMTAB *stp;
/* length is special (posix bozo) */
stp = insert(bi_funct->name);
stp->type = ST_LENGTH;
stp->stval.bip = bi_funct;
for (p = bi_funct + 1; p->name; p++) {
for (p = bi_funct; p->name; p++) {
stp = insert(p->name);
stp->type = ST_BUILTIN;
stp->stval.bip = p;
@ -128,11 +122,6 @@ bi_length(CELL *sp)
TRACE_FUNC("bi_length", sp);
if (sp->type == 0)
cellcpy(sp, field);
else
sp--;
if (sp->type < C_STRING)
cast1_to_s(sp);
len = string(sp)->len;
@ -144,6 +133,18 @@ bi_length(CELL *sp)
return_CELL("bi_length", sp);
}
/* length (size) of an array */
CELL *
bi_alength(CELL *sp)
{
TRACE_FUNC("bi_alength", sp);
sp->type = C_DOUBLE;
sp->dval = (double) ((ARRAY) sp->ptr)->size;
return_CELL("bi_alength", sp);
}
char *
str_str(char *target, size_t target_len, const char *key, size_t key_len)
{

View File

@ -1,6 +1,6 @@
/********************************************
bi_funct.h
copyright 2009-2012,2016 Thomas E. Dickey
copyright 2009-2016,2023 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: bi_funct.h,v 1.6 2016/09/29 23:13:04 tom Exp $
* $MawkId: bi_funct.h,v 1.7 2023/07/23 15:32:26 tom Exp $
*/
#ifndef BI_FUNCT_H
@ -27,6 +27,7 @@ void bi_init(void);
CELL *bi_print(CELL *);
CELL *bi_printf(CELL *);
CELL *bi_length(CELL *);
CELL *bi_alength(CELL *); /* length/size of an array */
CELL *bi_index(CELL *);
CELL *bi_substr(CELL *);
CELL *bi_sprintf(CELL *);

View File

@ -1,6 +1,6 @@
/********************************************
bi_vars.c
copyright 2009,2010, Thomas E. Dickey
copyright 2009-2010,2023 Thomas E. Dickey
copyright 1991-1992,1993, Michael D. Brennan
This is a source file for mawk, an implementation of
@ -11,17 +11,7 @@ the GNU General Public License, version 2, 1991.
********************************************/
/*
* $MawkId: bi_vars.c,v 1.10 2010/12/10 17:00:00 tom Exp $
* @Log: bi_vars.c,v @
* Revision 1.1.1.1 1993/07/03 18:58:09 mike
* move source to cvs
*
* Revision 5.2 1992/07/10 16:17:10 brennan
* MsDOS: remove NO_BINMODE macro
*
* Revision 5.1 1991/12/05 07:55:38 brennan
* 1.1 pre-release
*
* $MawkId: bi_vars.c,v 1.11 2023/07/22 22:28:00 tom Exp $
*/
/* bi_vars.c */

View File

@ -1,6 +1,6 @@
/********************************************
bi_vars.h
copyright 2010, Thomas E. Dickey
copyright 2010,2023 Thomas E. Dickey
copyright 1993, Michael D. Brennan
This is a source file for mawk, an implementation of
@ -11,17 +11,7 @@ the GNU General Public License, version 2, 1991.
********************************************/
/*
* $MawkId: bi_vars.h,v 1.8 2010/12/10 17:00:00 tom Exp $
* @Log: bi_vars.h,v @
* Revision 1.1.1.1 1993/07/03 18:58:09 mike
* move source to cvs
*
* Revision 5.2 1992/07/10 16:17:10 brennan
* MsDOS: remove NO_BINMODE macro
*
* Revision 5.1 1991/12/05 07:59:05 brennan
* 1.1 pre-release
*
* $MawkId: bi_vars.h,v 1.9 2023/07/22 22:28:10 tom Exp $
*/
/* bi_vars.h */

11
code.c
View File

@ -1,6 +1,6 @@
/********************************************
code.c
copyright 2009-2016,2019, Thomas E. Dickey
copyright 2009-2019,2023, 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: code.c,v 1.39 2019/02/02 01:09:45 tom Exp $
* $MawkId: code.c,v 1.40 2023/07/24 20:08:54 tom Exp $
*/
#include "mawk.h"
@ -40,9 +40,9 @@ INST *execution_start = 0;
void
code_grow(void)
{
unsigned oldsize = (unsigned) (code_limit - code_base);
unsigned newsize = PAGESZ + oldsize;
unsigned delta = (unsigned) (code_ptr - code_base);
size_t oldsize = (size_t) (code_limit - code_base);
size_t newsize = PAGESZ + oldsize;
size_t delta = (size_t) (code_ptr - code_base);
if (code_ptr > code_limit)
bozo("CODEWARN is too small");
@ -286,6 +286,7 @@ free_codes(const char *tag, INST * base, size_t size)
case A_PUSHA:
case L_PUSHA:
case L_PUSHI:
case _LENGTH:
case _BUILTIN:
case _PRINT:
case _PUSHA:

7
code.h
View File

@ -1,6 +1,6 @@
/********************************************
code.h
copyright 2009-2012,2019, Thomas E. Dickey
copyright 2009-2019,2023, 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: code.h,v 1.11 2019/01/30 00:49:25 tom Exp $
* $MawkId: code.h,v 1.12 2023/07/24 08:22:18 tom Exp $
*/
/* code.h */
@ -103,8 +103,9 @@ typedef enum {
,_POW
,_NOT
,_TEST
,A_LENGTH
,A_TEST
,_LENGTH
,A_LENGTH
,A_DEL
,ALOOP
,A_CAT

162
da.c
View File

@ -1,6 +1,6 @@
/********************************************
da.c
copyright 2008-2020,2021, Thomas E. Dickey
copyright 2008-2021,2023, 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: da.c,v 1.30 2021/05/29 00:00:01 tom Exp $
* $MawkId: da.c,v 1.35 2023/07/25 22:21:08 tom Exp $
*/
/* da.c */
@ -58,7 +58,6 @@ 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" },
@ -124,39 +123,67 @@ static const char *jfmt = "%s%s%03d\n";
static const char *tab2 = "\t\t";
void
da_string(FILE *fp, const char *str, size_t len)
da_string2(FILE *fp, const char *value, size_t length, int delim)
{
size_t n;
fputc('"', fp);
for (n = 0; n < len; ++n) {
UChar ch = (UChar) str[n];
fputc(delim, fp);
for (n = 0; n < length; ++n) {
UChar ch = (UChar) value[n];
switch (ch) {
case '\\':
fprintf(fp, "\\\\");
fputc(ch, fp);
break;
case '"':
fprintf(fp, "\"");
case '\a': /* alert, ascii 7 */
fputs("\\\\", fp);
break;
case '\b': /* backspace, ascii 8 */
fputs("\\b", fp);
break;
case '\t': /* tab, ascii 9 */
fputs("\\t", fp);
break;
case '\n': /* newline, ascii 10 */
fputs("\\n", fp);
break;
case '\v': /* vertical tab, ascii 11 */
fputs("\\v", fp);
break;
case '\f': /* formfeed, ascii 12 */
fputs("\\f", fp);
break;
case '\r': /* carriage return, ascii 13 */
fputs("\\r", fp);
break;
default:
if (ch >= 32 && ch < 127)
fprintf(fp, "%c", ch);
if (ch == delim)
fprintf(fp, "\\%c", ch);
else if (ch >= 32 && ch < 127)
fputc(ch, fp);
else
fprintf(fp, "\\%03o", ch);
break;
}
}
fputc('"', fp);
fputc(delim, fp);
}
void
da_string(FILE *fp, const STRING * sparm, int delim)
{
da_string2(fp, sparm->str, sparm->len, delim);
}
#define NORMAL_FORM "%03ld .\t"
#define ADJUST_FORM "# patching %s\n .\t"
INST *
da_this(INST * p, INST * start, FILE *fp)
{
CELL *cp;
/* print the relative code address (label) */
fprintf(fp, "%03ld ", (long) (p - start));
fprintf(fp, ".\t");
fprintf(fp, NORMAL_FORM, (long) (p - start));
switch ((MAWK_OPCODES) (p++->op)) {
@ -165,8 +192,9 @@ da_this(INST * p, INST * start, FILE *fp)
switch (cp->type) {
case C_RE:
add_to_regex_list(cp->ptr);
fprintf(fp, "pushc\t%p\t/%s/\n", cp->ptr,
re_uncompile(cp->ptr));
fprintf(fp, "pushc\t%p\t", cp->ptr);
da_string(fp, re_uncompile(cp->ptr), '/');
fputc('\n', fp);
break;
case C_SPACE:
@ -176,13 +204,18 @@ da_this(INST * p, INST * start, FILE *fp)
case C_SNULL:
fprintf(fp, "pushc\tnull split\n");
break;
case C_REPL:
fprintf(fp, "pushc\trepl\t%s\n",
repl_uncompile(cp));
fprintf(fp, "pushc\trepl\t");
da_string(fp, repl_uncompile(cp), '"');
fputc('\n', fp);
break;
case C_REPLV:
fprintf(fp, "pushc\treplv\t%s\n",
repl_uncompile(cp));
fprintf(fp, "pushc\treplv\t");
da_string(fp, repl_uncompile(cp), '"');
fputc('\n', fp);
break;
default:
@ -194,21 +227,19 @@ da_this(INST * p, INST * start, FILE *fp)
case _PUSHD:
fprintf(fp, "pushd\t%.6g\n", *(double *) p++->ptr);
break;
case _PUSHS:
{
STRING *sval = (STRING *) p++->ptr;
fprintf(fp, "pushs\t");
da_string(fp, sval->str, sval->len);
fprintf(fp, "\n");
break;
}
fprintf(fp, "pushs\t");
da_string(fp, (STRING *) p++->ptr, '"');
fputc('\n', fp);
break;
case _MATCH0:
case _MATCH1:
add_to_regex_list(p->ptr);
fprintf(fp, "match%d\t%p\t/%s/\n",
p[-1].op == _MATCH1, p->ptr,
re_uncompile(p->ptr));
fprintf(fp, "match%d\t%p\t", p[-1].op == _MATCH1, p->ptr);
da_string(fp, re_uncompile(p->ptr), '/');
fputc('\n', fp);
p++;
break;
@ -284,6 +315,54 @@ da_this(INST * p, INST * start, FILE *fp)
reverse_find(ST_ARRAY, &p++->ptr));
break;
case A_LENGTH:
{
SYMTAB *stp = (SYMTAB *) p++->ptr;
fprintf(fp, ADJUST_FORM, type_to_str(stp->type));
switch (stp->type) {
case ST_VAR:
fprintf(fp, "pushi\t%s\t# defer_alen\n", stp->name);
break;
case ST_ARRAY:
fprintf(fp, "a_pusha\t%s\t# defer_alen\n", stp->name);
p[1].ptr = (PTR) bi_alength;
break;
case ST_NONE:
fprintf(fp, "pushi\t%s\t# defer_alen\n", "@missing");
break;
default:
bozo("da A_LENGTH");
/* NOTREACHED */
}
}
break;
case _LENGTH:
{
DEFER_LEN *dl = (DEFER_LEN *) p++->ptr;
FBLOCK *fbp = dl->fbp;
short offset = dl->offset;
int type = fbp->typev[offset];
fprintf(fp, ADJUST_FORM, type_to_str(type));
switch (type) {
case ST_LOCAL_VAR:
fprintf(fp, "lpushi\t%s %u\t# defer_len\n",
fbp->name, offset);
break;
case ST_LOCAL_ARRAY:
fprintf(fp, "la_pusha\t%s %u\t# defer_len\n",
fbp->name, offset);
p[1].ptr = (PTR) bi_alength;
break;
case ST_LOCAL_NONE:
fprintf(fp, "pushi\t%s\t# defer_len\n", "@missing");
break;
default:
bozo("da _LENGTH");
/* NOTREACHED */
}
}
break;
case _PUSHINT:
fprintf(fp, "pushint\t%d\n", p++->op);
break;
@ -352,6 +431,7 @@ da_this(INST * p, INST * start, FILE *fp)
(long) (p - start + p[3].op));
p += 4;
break;
default:
{
const OP_NAME *q = simple_code;
@ -378,19 +458,21 @@ da(INST * p, FILE *fp)
fflush(fp);
}
/* *INDENT-OFF* */
static struct
static const struct
{
PF_CP action ;
const char *name ;
const char name[10] ;
}
special_cases[] =
{
{bi_split, "split"},
{bi_match, "match"},
{bi_getline, "getline"},
{bi_sub, "sub"},
{bi_gsub, "gsub"},
{(PF_CP) 0, (char *) 0}
{ bi_split, "split" },
{ bi_length, "length" },
{ bi_alength, "alength" },
{ bi_match, "match" },
{ bi_getline, "getline" },
{ bi_sub, "sub" },
{ bi_gsub, "gsub" },
{ (PF_CP) 0, "" }
} ;
/* *INDENT-ON* */
@ -530,6 +612,8 @@ static const OP_NAME other_codes[] = {
{ _PUSHINT, "pushint" },
{ _PUSHS, "pushs" },
{ _RANGE, "range" },
{ _LENGTH, "defer_len" },
{ A_LENGTH, "defer_alen" },
{ _HALT, "" }
};
/* *INDENT-ON* */

12
error.c
View File

@ -1,6 +1,6 @@
/********************************************
error.c
copyright 2008-2016,2020 Thomas E. Dickey
copyright 2008-2020,2023 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.24 2020/08/25 20:08:35 tom Exp $
* $MawkId: error.c,v 1.25 2023/07/24 21:18:55 tom Exp $
*/
#include <mawk.h>
@ -102,11 +102,6 @@ missing(int c, const char *n, unsigned ln)
errmsg(0, "%s%sline %u: missing %c near %s", s0, s1, ln, c, n);
}
/* we won't use s as input
(yacc and bison force this).
We will use s for storage to keep lint or the compiler
off our back.
*/
void
yyerror(const char *s GCC_UNUSED)
{
@ -320,9 +315,6 @@ type_to_str(int type)
case ST_FUNCT:
retval = "function";
break;
case ST_LENGTH:
retval = "length";
break;
case ST_LOCAL_VAR:
retval = "local variable";
break;

103
execute.c
View File

@ -1,6 +1,6 @@
/********************************************
execute.c
copyright 2008-2018,2020, Thomas E. Dickey
copyright 2008-2020,2023, Thomas E. Dickey
copyright 1991-1995,1996, Michael D. Brennan
This is a source file for mawk, an implementation of
@ -11,20 +11,20 @@ the GNU General Public License, version 2, 1991.
********************************************/
/*
* $MawkId: execute.c,v 1.47 2020/09/11 23:32:09 tom Exp $
* $MawkId: execute.c,v 1.48 2023/07/25 22:25:27 tom Exp $
*/
#include "mawk.h"
#include "files.h"
#include "code.h"
#include "memory.h"
#include "symtype.h"
#include "field.h"
#include "bi_funct.h"
#include "bi_vars.h"
#include "regexp.h"
#include "repl.h"
#include "fin.h"
#include <mawk.h>
#include <files.h>
#include <code.h>
#include <memory.h>
#include <symtype.h>
#include <field.h>
#include <bi_funct.h>
#include <bi_vars.h>
#include <regexp.h>
#include <repl.h>
#include <fin.h>
#include <math.h>
@ -99,9 +99,7 @@ clear_aloop_stack(ALOOP_STATE * top)
} while (top);
}
static INST *restart_label; /* control flow labels */
INST *next_label;
static CELL tc; /*useful temp */
INST *next_label; /* control flow label */
void
execute(INST * cdp, /* code ptr, start execution here */
@ -109,6 +107,10 @@ execute(INST * cdp, /* code ptr, start execution here */
CELL *fp) /* frame ptr into eval_stack for
user defined functions */
{
static INST *restart_label; /* control flow label */
static CELL tc; /*useful temp */
static CELL missing; /* no value (use zero) */
/* some useful temporaries */
CELL *cp;
int t;
@ -350,6 +352,69 @@ execute(INST * cdp, /* code ptr, start execution here */
}
break;
case A_LENGTH:
/* parameter for length() was ST_NONE; improve it here */
{
SYMTAB *stp = (SYMTAB *) cdp->ptr;
cdp--;
TRACE(("patching %s\n", type_to_str(stp->type)));
switch (stp->type) {
case ST_VAR:
cdp[0].op = _PUSHI;
cdp[1].ptr = stp->stval.cp;
break;
case ST_ARRAY:
cdp[0].op = A_PUSHA;
cdp[1].ptr = stp->stval.array;
assert(cdp[2].op == _BUILTIN);
cdp[3].ptr = (PTR) bi_alength;
break;
case ST_NONE:
cdp[0].op = _PUSHI;
cdp[1].ptr = &missing;
break;
default:
bozo("execute A_LENGTH");
/* NOTREACHED */
}
}
/* resume, interpreting the updated code */
break;
case _LENGTH:
/* parameter for length() was ST_LOCAL_NONE; improve it here */
{
DEFER_LEN *dl = (DEFER_LEN *) cdp->ptr;
FBLOCK *fbp = dl->fbp;
short offset = dl->offset;
int type = fbp->typev[offset];
ZFREE(dl);
cdp--;
TRACE(("patching %s\n", type_to_str(type)));
switch (type) {
case ST_LOCAL_VAR:
cdp[0].op = L_PUSHI;
cdp[1].op = offset;
break;
case ST_LOCAL_ARRAY:
cdp[0].op = LA_PUSHA;
cdp[1].op = offset;
assert(cdp[2].op == _BUILTIN);
cdp[3].ptr = (PTR) bi_alength;
break;
case ST_LOCAL_NONE:
cdp[0].op = _PUSHI;
cdp[1].ptr = &missing;
break;
default:
bozo("execute _LENGTH");
/* NOTREACHED */
}
}
/* resume, interpreting the updated code */
break;
case SET_ALOOP:
{
ALOOP_STATE *ap = ZMALLOC(ALOOP_STATE);
@ -1026,12 +1091,6 @@ execute(INST * cdp, /* code ptr, start execution here */
sp->dval = t ? 1.0 : 0.0;
break;
case A_LENGTH:
dec_sp();
sp->type = C_DOUBLE;
sp->dval = (double) (((ARRAY) ((sp + 0)->ptr))->size);
break;
case A_TEST:
/* entry : sp[0].ptr-> an array
sp[-1] is an expression

10
fcall.c
View File

@ -1,6 +1,6 @@
/********************************************
fcall.c
copyright 2009-2012,2020 Thomas E. Dickey
copyright 2009-2020,2023 Thomas E. Dickey
copyright 1991-1993,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: fcall.c,v 1.11 2020/01/07 00:47:38 tom Exp $
* $MawkId: fcall.c,v 1.12 2023/07/25 21:04:05 tom Exp $
*/
#include "mawk.h"
@ -139,8 +139,10 @@ call_arg_check(FBLOCK * callee,
callee->typev[q->arg_num] = (char) q->type;
} else if (q->type != callee->typev[q->arg_num]) {
token_lineno = q->call_lineno;
compile_error("type error in arg(%d) in call to %s",
q->arg_num + 1, callee->name);
compile_error("type error in arg(%d) in call to %s (actual %s vs %s)",
q->arg_num + 1, callee->name,
type_to_str(q->type),
type_to_str(callee->typev[q->arg_num]));
}
ZFREE(q);

View File

@ -1,6 +1,6 @@
/********************************************
field.c
copyright 2008-2020,2021 Thomas E. Dickey
copyright 2008-2021,2023 Thomas E. Dickey
copyright 1991-1995,2014 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: field.c,v 1.39 2021/05/29 00:00:11 tom Exp $
* $MawkId: field.c,v 1.41 2023/07/23 11:33:56 tom Exp $
*/
/* field.c */
@ -106,7 +106,7 @@ set_rs_shadow(void)
CELL c;
STRING *sval;
char *s;
SLen len;
size_t len;
if (posix_space_flag && mawk_state == EXECUTION)
scan_code['\n'] = SC_UNEXPECTED;
@ -207,7 +207,7 @@ field_init(void)
}
void
set_field0(char *s, size_t len)
set_field0(const char *s, size_t len)
{
cell_destroy(&field[0]);
nf = -1;

View File

@ -1,6 +1,6 @@
/********************************************
field.h
copyright 2009-2014,2020 Thomas E. Dickey
copyright 2009-2020,2023 Thomas E. Dickey
copyright 1991-1995,2014 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: field.h,v 1.13 2020/09/07 12:13:20 tom Exp $
* $MawkId: field.h,v 1.15 2023/07/23 11:33:56 tom Exp $
*/
/* field.h */
@ -22,10 +22,10 @@ the GNU General Public License, version 2, 1991.
#include "nstd.h"
#include "types.h"
extern void set_field0(char *, size_t);
extern void set_field0(const char *, size_t);
extern void split_field0(void);
extern void field_assign(CELL *, CELL *);
extern char *is_string_split(PTR, SLen *);
extern char *is_string_split(PTR, size_t *);
extern void slow_cell_assign(CELL *, CELL *);
extern CELL *slow_field_ptr(int);
extern int field_addr_to_index(CELL *);

16
fin.h
View File

@ -1,6 +1,6 @@
/********************************************
fin.h
copyright 2009-2010,2014 Thomas E. Dickey
copyright 2009-2014,2023 Thomas E. Dickey
copyright 1991-1992,1993, Michael D. Brennan
This is a source file for mawk, an implementation of
@ -11,18 +11,8 @@ the GNU General Public License, version 2, 1991.
********************************************/
/*
* $MawkId: fin.h,v 1.13 2014/09/13 01:01:10 tom Exp $
* @Log: fin.h,v @
* Revision 1.1.1.1 1993/07/03 18:58:13 mike
* move source to cvs
*
* Revision 5.2 1992/01/06 08:16:24 brennan
* setmode() proto for MSDOS
*
* Revision 5.1 91/12/05 07:59:20 brennan
* 1.1 pre-release
*
*/
* $MawkId: fin.h,v 1.14 2023/07/22 22:27:30 tom Exp $
*/
/* fin.h */

View File

@ -1,6 +1,6 @@
/********************************************
fpe_check.c
copyright 2008-2010,2013 Thomas E. Dickey
copyright 2008-2013,2023 Thomas E. Dickey
copyright 1996, Michael D. Brennan
This is a source file for mawk, an implementation of
@ -15,28 +15,8 @@ the GNU General Public License, version 2, 1991.
*/
/*
* $MawkId: fpe_check.c,v 1.16 2013/12/27 00:44:59 tom Exp $
* @Log: fpe_check.c,v @
* Revision 1.7 1996/08/30 00:07:14 mike
* Modifications to the test and implementation of the bug fix for
* solaris overflow in strtod.
*
* Revision 1.6 1996/08/25 19:25:46 mike
* Added test for solaris strtod overflow bug.
*
* Revision 1.5 1996/08/11 22:10:39 mike
* Some systems blow the !(d==d) test for a NAN. Added a work around.
*
* Revision 1.4 1995/01/09 01:22:28 mike
* check sig handler ret type to make fpe_check.c more robust
*
* Revision 1.3 1994/12/18 20:54:00 mike
* check NetBSD mathlib defines
*
* Revision 1.2 1994/12/14 14:37:26 mike
* add messages to user
*
*/
* $MawkId: fpe_check.c,v 1.17 2023/07/22 22:27:46 tom Exp $
*/
#include <stdlib.h>
#include <stdio.h>

17
jmp.h
View File

@ -1,6 +1,6 @@
/********************************************
jmp.h
copyright 2009,2010 Thomas E. Dickey
copyright 2009-2010,2023 Thomas E. Dickey
copyright 1991, Michael D. Brennan
This is a source file for mawk, an implementation of
@ -11,20 +11,7 @@ the GNU General Public License, version 2, 1991.
********************************************/
/*
* $MawkId: jmp.h,v 1.5 2010/12/10 17:00:00 tom Exp $
* @Log: jmp.h,v @
* Revision 1.2 1995/04/21 14:20:19 mike
* move_level variable to fix bug in arglist patching of moved code.
*
* Revision 1.1.1.1 1993/07/03 18:58:15 mike
* move source to cvs
*
* Revision 5.2 1993/01/09 19:03:44 mike
* code_pop checks if the resolve_list needs relocation
*
* Revision 5.1 1991/12/05 07:59:24 brennan
* 1.1 pre-release
*
* $MawkId: jmp.h,v 1.6 2023/07/22 22:28:22 tom Exp $
*/
#ifndef MAWK_JMP_H

46
kw.c
View File

@ -1,6 +1,6 @@
/********************************************
kw.c
copyright 2008-2020,2021, Thomas E. Dickey
copyright 2008-2021,2023, Thomas E. Dickey
copyright 1991-1993, Michael D. Brennan
This is a source file for mawk, an implementation of
@ -11,15 +11,16 @@ the GNU General Public License, version 2, 1991.
********************************************/
/*
* $MawkId: kw.c,v 1.9 2021/05/29 00:17:26 tom Exp $
* $MawkId: kw.c,v 1.10 2023/07/24 08:10:12 tom Exp $
*/
/* kw.c */
#include "mawk.h"
#include "symtype.h"
#include "parse.h"
#include "init.h"
#include <mawk.h>
#include <symtype.h>
#include <parse.h>
#include <init.h>
/* *INDENT-OFF* */
static const struct kw
{
@ -28,29 +29,30 @@ static const struct kw
}
keywords[] =
{
{ "print", PRINT },
{ "printf", PRINTF },
{ "do", DO },
{ "while", WHILE },
{ "for", FOR },
{ "break", BREAK },
{ "continue", CONTINUE },
{ "if", IF },
{ "else", ELSE },
{ "in", IN },
{ "delete", DELETE },
{ "split", SPLIT },
{ "match", MATCH_FUNC },
{ "BEGIN", BEGIN },
{ "END", END },
{ "break", BREAK },
{ "continue", CONTINUE },
{ "delete", DELETE },
{ "do", DO },
{ "else", ELSE },
{ "exit", EXIT },
{ "for", FOR },
{ "function", FUNCTION },
{ "getline", GETLINE },
{ "gsub", GSUB },
{ "if", IF },
{ "in", IN },
{ "length", LENGTH },
{ "match", MATCH_FUNC },
{ "next", NEXT },
{ "nextfile", NEXTFILE },
{ "print", PRINT },
{ "printf", PRINTF },
{ "return", RETURN },
{ "getline", GETLINE },
{ "split", SPLIT },
{ "sub", SUB },
{ "gsub", GSUB },
{ "function", FUNCTION },
{ "while", WHILE },
{ "", 0 }
};
/* *INDENT-ON* */

15
mawk.h
View File

@ -1,6 +1,6 @@
/********************************************
mawk.h
copyright 2008-2020,2021 Thomas E. Dickey
copyright 2008-2021,2023 Thomas E. Dickey
copyright 1991-1995,1996 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: mawk.h,v 1.62 2021/05/28 22:02:11 tom Exp $
* $MawkId: mawk.h,v 1.63 2023/07/20 00:11:29 tom Exp $
*/
/* mawk.h */
@ -170,18 +170,19 @@ extern char *str_str(char *, size_t, const char *, size_t);
extern void parse(void);
extern void scan_cleanup(void);
#ifndef YYBYACC
#ifndef YYBYACC
extern int yylex(void);
#endif
extern void yyerror(const char *);
extern GCC_NORETURN void bozo(const char *);
extern void errmsg(int, const char *,...) GCC_PRINTFLIKE(2,3);
extern void compile_error(const char *,...) GCC_PRINTFLIKE(1,2);
extern void errmsg(int, const char *, ...) GCC_PRINTFLIKE(2,3);
extern void compile_error(const char *, ...) GCC_PRINTFLIKE(1,2);
extern void execute(INST *, CELL *, CELL *);
extern const char *find_kw_str(int);
extern void da_string(FILE *fp, const char *, size_t);
extern void da_string(FILE *fp, const STRING *, int);
extern void da_string2(FILE *fp, const char *, size_t, int);
#ifdef HAVE_STRTOD_OVF_BUG
extern double strtod_with_ovf_bug(const char *, char **);
@ -189,7 +190,7 @@ extern double strtod_with_ovf_bug(const char *, char **);
#endif
#if OPT_TRACE > 0
extern void Trace(const char *,...) GCC_PRINTFLIKE(1,2);
extern void Trace(const char *, ...) GCC_PRINTFLIKE(1,2);
extern void TraceVA(const char *, va_list);
#define TRACE(params) Trace params
#if OPT_TRACE > 1

View File

@ -1,6 +1,6 @@
/********************************************
memory.c
copyright 2009,2010 Thomas E. Dickey
copyright 2009-2010,2023 Thomas E. Dickey
copyright 1991-1992,1993 Michael D. Brennan
This is a source file for mawk, an implementation of
@ -11,20 +11,7 @@ the GNU General Public License, version 2, 1991.
********************************************/
/*
* $MawkId: memory.c,v 1.8 2010/12/10 17:00:00 tom Exp $
* @Log: memory.c,v @
* Revision 1.2 1993/07/17 13:23:08 mike
* indent and general code cleanup
*
* Revision 1.1.1.1 1993/07/03 18:58:17 mike
* move source to cvs
*
* Revision 5.2 1993/01/01 21:30:48 mike
* split new_STRING() into new_STRING and new_STRING0
*
* Revision 5.1 1991/12/05 07:56:21 brennan
* 1.1 pre-release
*
* $MawkId: memory.c,v 1.9 2023/07/22 22:28:36 tom Exp $
*/
/* memory.c */

View File

@ -1,6 +1,6 @@
/********************************************
memory.h
copyright 2009,2010, Thomas E. Dickey
copyright 2009-2010,2023 Thomas E. Dickey
copyright 1991,1993, Michael D. Brennan
This is a source file for mawk, an implementation of
@ -11,17 +11,7 @@ the GNU General Public License, version 2, 1991.
********************************************/
/*
* $MawkId: memory.h,v 1.9 2010/12/10 17:00:00 tom Exp $
* @Log: memory.h,v @
* Revision 1.1.1.1 1993/07/03 18:58:17 mike
* move source to cvs
*
* Revision 5.2 1993/01/01 21:30:48 mike
* split new_STRING() into new_STRING and new_STRING0
*
* Revision 5.1 1991/12/05 07:59:28 brennan
* 1.1 pre-release
*
* $MawkId: memory.h,v 1.10 2023/07/22 22:28:48 tom Exp $
*/
/* memory.h */

View File

@ -1,6 +1,6 @@
/********************************************
dosexec.c
copyright 2009,2010,2014, Thomas E. Dickey
copyright 2009-2014,2023, Thomas E. Dickey
copyright 1991-1994,1995, Michael D. Brennan
This is a source file for mawk, an implementation of
@ -11,31 +11,7 @@ the GNU General Public License, version 2, 1991.
********************************************/
/*
* $MawkId: dosexec.c,v 1.5 2014/09/14 22:29:49 tom Exp $
*
* @Log: dosexec.c,v @
* Revision 1.3 1995/08/20 16:37:22 mike
* exit(1) -> exit(2)
*
* Revision 1.2 1994/10/08 18:50:03 mike
* remove SM_DOS
*
* Revision 1.1.1.1 1993/07/03 18:58:47 mike
* move source to cvs
*
* Revision 1.4 1992/12/05 22:29:43 mike
* dos patch 112d:
* don't use string_buff
* check COMSPEC
*
* Revision 1.3 1992/07/10 16:21:57 brennan
* store exit code of input pipes
*
* Revision 1.2 1991/11/16 10:27:18 brennan
* BINMODE
*
* Revision 1.1 91/10/29 09:45:56 brennan
* Initial revision
* $MawkId: dosexec.c,v 1.6 2023/07/25 21:27:16 tom Exp $
*/
/* system() and pipes() for MSDOS and Win32 console */

25
nstd.h
View File

@ -1,6 +1,6 @@
/********************************************
nstd.h
copyright 2009-2012,2017 Thomas E. Dickey
copyright 2009-2017,2023 Thomas E. Dickey
copyright 1995, Michael D. Brennan
This is a source file for mawk, an implementation of
@ -18,27 +18,8 @@ the GNU General Public License, version 2, 1991.
*/
/*
* $MawkId: nstd.h,v 1.11 2017/10/17 01:19:15 tom Exp $
* @Log: nstd.h,v @
* Revision 1.6 1995/06/18 19:42:22 mike
* Remove some redundant declarations and add some prototypes
*
* Revision 1.5 1995/04/20 20:26:56 mike
* beta improvements from Carl Mascott
*
* Revision 1.4 1994/12/11 22:08:24 mike
* add STDC_MATHERR
*
* Revision 1.3 1993/07/15 23:56:09 mike
* general cleanup
*
* Revision 1.2 1993/07/07 00:07:43 mike
* more work on 1.2
*
* Revision 1.1 1993/07/04 12:38:06 mike
* Initial revision
*
*/
* $MawkId: nstd.h,v 1.12 2023/07/22 22:27:11 tom Exp $
*/
#ifndef NSTD_H
#define NSTD_H 1

View File

@ -1,3 +1,21 @@
mawk-cur (1.3.4-20230725) unstable; urgency=low
* maintenance updates
-- Thomas E. Dickey <dickey@invisible-island.net> Mon, 17 Jul 2023 16:42:46 -0400
mawk-cur (1.3.4-20230716) unstable; urgency=low
* maintenance updates
-- Thomas E. Dickey <dickey@invisible-island.net> Sun, 16 Jul 2023 18:20:07 -0400
mawk-cur (1.3.4-20230712) unstable; urgency=low
* maintenance updates
-- Thomas E. Dickey <dickey@invisible-island.net> Wed, 12 Jul 2023 19:23:14 -0400
mawk-cur (1.3.4-20230525) unstable; urgency=low
* maintenance updates

View File

@ -2,7 +2,7 @@
# $FreeBSD: head/lang/mawk/Makefile 516890 2019-11-06 14:17:48Z wen $
PORTNAME= mawk
DISTVERSION= 1.3.4.20230525
DISTVERSION= 1.3.4.20230725
CATEGORIES= lang
MASTER_SITES= https://invisible-island.net/archives/${PORTNAME}/ \
https://invisible-mirror.net/archives/${PORTNAME}/

View File

@ -1,9 +1,9 @@
Summary: mawk - pattern scanning and text processing language
%global AppProgram mawk
%global AppVersion 1.3.4
%global AppPatched 20230525
%global AppPatched 20230725
%global MySite https://invisible-island.net
# $MawkId: mawk.spec,v 1.103 2023/05/25 23:29:39 tom Exp $
# $MawkId: mawk.spec,v 1.104 2023/07/25 23:29:43 tom Exp $
Name: %{AppProgram}
Version: %{AppVersion}
Release: %{AppPatched}

2424
parse.c

File diff suppressed because it is too large Load Diff

155
parse.y
View File

@ -1,6 +1,6 @@
/********************************************
parse.y
copyright 2008-2016,2020, Thomas E. Dickey
copyright 2008-2020,2023, Thomas E. Dickey
copyright 1991-1994,1995, Michael D. Brennan
This is a source file for mawk, an implementation of
@ -11,25 +11,29 @@ the GNU General Public License, version 2, 1991.
********************************************/
/*
* $MawkId: parse.y,v 1.24 2023/07/11 23:05:34 tom Exp $
* $MawkId: parse.y,v 1.28 2023/07/25 19:03:52 tom Exp $
*/
%{
#include <stdio.h>
#include "mawk.h"
#include "symtype.h"
#include "code.h"
#include "memory.h"
#include "bi_funct.h"
#include "bi_vars.h"
#include "jmp.h"
#include "field.h"
#include "files.h"
#include <mawk.h>
#include <symtype.h>
#include <code.h>
#include <memory.h>
#include <bi_funct.h>
#include <bi_vars.h>
#include <jmp.h>
#include <field.h>
#include <files.h>
#define YYMAXDEPTH 200
#define YYMAXDEPTH 200
#if defined(YYBYACC) && (YYBYACC < 2)
extern int yylex(void);
#endif
extern void eat_nl(void);
static SYMTAB *save_arglist(const char *);
static int init_arglist(void);
static void RE_as_arg(void);
@ -335,10 +339,10 @@ p_expr : DOUBLE
{ $$ = code_offset ; code2(_PUSHS, $1) ; }
| ID %prec AND /* anything less than IN */
{ check_var($1) ;
$$ = code_offset ;
if ( is_local($1) )
{ code2op(L_PUSHI, $1->offset) ; }
else code2(_PUSHI, $1->stval.cp) ;
$$ = code_offset ;
if ( is_local($1) )
{ code2op(L_PUSHI, $1->offset) ; }
else code2(_PUSHI, $1->stval.cp) ;
}
| LPAREN expr RPAREN
@ -413,30 +417,7 @@ args : expr %prec LPAREN
;
builtin :
BUILTIN mark LPAREN ID RPAREN
{ const BI_REC *p = $1 ;
$$ = $2 ;
if ( (int)p->min_args > 1 || (int)p->max_args < 1 )
compile_error(
"wrong number of arguments in call to %s" ,
p->name ) ;
/* if we have length(array), emit a different code */
if ( p->fp == bi_length && is_array($4) ) {
check_array($4) ;
code_array($4) ;
{ code1(_PUSHINT) ; code1(1) ; }
code1(A_LENGTH) ;
} else {
check_var($4);
if ( is_local($4) )
{ code1(L_PUSHI); code1($4->offset) ; }
else { code2(_PUSHI, $4->stval.cp) ; }
if ( p->min_args != p->max_args ) /* variable args */
{ code1(_PUSHINT) ; code1(1) ; }
code2(_BUILTIN, p->fp) ;
}
}
| BUILTIN mark LPAREN arglist RPAREN
BUILTIN mark LPAREN arglist RPAREN
{ const BI_REC *p = $1 ;
$$ = $2 ;
if ( (int)p->min_args > $4 || (int)p->max_args < $4 )
@ -447,12 +428,6 @@ builtin :
{ code1(_PUSHINT) ; code1($4) ; }
code2(_BUILTIN , p->fp) ;
}
| LENGTH /* this is an irritation */
{
$$ = code_offset ;
code1(_PUSHINT) ; code1(0) ;
code2(_BUILTIN, $1->fp) ;
}
;
/* an empty production to store the code_ptr */
@ -484,7 +459,7 @@ pr_args : arglist { code2op(_PUSHINT, $1) ; }
;
arg2 : expr COMMA expr
{ $$ = (ARG2_REC*) zmalloc(sizeof(ARG2_REC)) ;
{ $$ = ZMALLOC(ARG2_REC) ;
$$->start = $1 ;
$$->cnt = 2 ;
}
@ -816,8 +791,9 @@ split_back : RPAREN
{
if ( CDP($2) == code_ptr - 2 )
{
if ( code_ptr[-2].op == _MATCH0 )
if ( code_ptr[-2].op == _MATCH0 ) {
RE_as_arg() ;
}
else
if ( code_ptr[-2].op == _PUSHS )
{ CELL *cp = ZMALLOC(CELL) ;
@ -833,7 +809,69 @@ split_back : RPAREN
}
;
/* distinguish length vs length(string) vs length(array) */
p_expr : LENGTH
{ $$ = code_offset ;
code2(_PUSHI,field) ;
code2(_BUILTIN,bi_length) ;
}
| LENGTH LPAREN RPAREN
{ $$ = code_offset ;
code2(_PUSHI,field) ;
code2(_BUILTIN,bi_length) ;
}
| LENGTH LPAREN expr RPAREN
{ $$ = $3 ;
code2(_BUILTIN,bi_length) ;
}
| LENGTH LPAREN ID RPAREN
{
SYMTAB* stp = $3;
$$ = code_offset;
switch (stp->type) {
case ST_VAR:
code2(_PUSHI, stp->stval.cp);
code2(_BUILTIN, bi_length);
break;
case ST_ARRAY:
code2(A_PUSHA, stp->stval.array);
code2(_BUILTIN, bi_alength);
break;
case ST_LOCAL_VAR:
code2op(L_PUSHI, stp->offset);
code2(_BUILTIN, bi_length);
break;
case ST_LOCAL_ARRAY:
code2op(LA_PUSHA, stp->offset);
code2(_BUILTIN, bi_alength);
break;
case ST_NONE:
/* defer_alen */
code2(A_LENGTH, stp);
code2(_BUILTIN, bi_length);
break;
case ST_LOCAL_NONE:
/* defer_len */
{
DEFER_LEN* pi = ZMALLOC(DEFER_LEN);
pi->fbp = active_funct;
pi->offset = stp->offset;
code2(_LENGTH, pi);
code2(_BUILTIN, bi_length);
}
break;
default:
type_error(stp);
break;
}
}
;
/* match(expr, RE) */
@ -993,8 +1031,8 @@ funct_start : funct_head LPAREN f_arglist RPAREN
(INST *) zmalloc(INST_BYTES(PAGESZ));
code_limit = code_base + PAGESZ ;
code_warn = code_limit - CODEWARN ;
improve_arglist($1->name);
free_arglist();
improve_arglist($1->name);
free_arglist();
}
;
@ -1004,8 +1042,7 @@ funct_head : FUNCTION ID
if ( $2->type == ST_NONE )
{
$2->type = ST_FUNCT ;
fbp = $2->stval.fbp =
(FBLOCK *) zmalloc(sizeof(FBLOCK)) ;
fbp = $2->stval.fbp = ZMALLOC(FBLOCK) ;
fbp->name = $2->name ;
fbp->code = (INST*) 0 ;
}
@ -1015,7 +1052,7 @@ funct_head : FUNCTION ID
/* this FBLOCK will not be put in
the symbol table */
fbp = (FBLOCK*) zmalloc(sizeof(FBLOCK)) ;
fbp = ZMALLOC(FBLOCK) ;
fbp->name = "" ;
}
$$ = fbp ;
@ -1034,7 +1071,7 @@ f_arglist : /* empty */ { $$ = init_arglist() ; }
f_args : ID
{ init_arglist();
$1 = save_arglist($1->name) ;
$1 = save_arglist($1->name) ;
$1->offset = 0 ;
$$ = 1 ;
}
@ -1080,7 +1117,7 @@ call_args : LPAREN RPAREN
{ $$ = $2 ;
$$->link = $1 ;
$$->arg_num = (short) ($1 ? $1->arg_num+1 : 0) ;
$$->call_lineno = token_lineno;
$$->call_lineno = token_lineno;
}
;
@ -1100,14 +1137,14 @@ ca_front : LPAREN
$$->type = CA_EXPR ;
$$->arg_num = (short) ($1 ? $1->arg_num+1 : 0) ;
$$->call_offset = code_offset ;
$$->call_lineno = token_lineno;
$$->call_lineno = token_lineno;
}
| ca_front ID COMMA
{ $$ = ZMALLOC(CA_REC) ;
$$->type = ST_NONE ;
$$->link = $1 ;
$$->arg_num = (short) ($1 ? $1->arg_num+1 : 0) ;
$$->call_lineno = token_lineno;
$$->call_lineno = token_lineno;
code_call_id($$, $2) ;
}
@ -1187,7 +1224,7 @@ save_arglist(const char *s)
CA_REC *saveit = ZMALLOC(CA_REC);
if (saveit != 0) {
CA_REC *p, *q;
CA_REC *p, *q;
int arg_num = 0;
for (p = active_arglist, q = 0; p != 0; q = p, p = p->link) {

View File

@ -11,9 +11,9 @@ the GNU General Public License, version 2, 1991.
*/
/*
* $MawkId: patchlev.h,v 1.131 2023/05/25 23:29:39 tom Exp $
* $MawkId: patchlev.h,v 1.132 2023/07/25 23:29:43 tom Exp $
*/
#define PATCH_BASE 1
#define PATCH_LEVEL 3
#define PATCH_STRING ".4"
#define DATE_STRING "20230525"
#define DATE_STRING "20230725"

View File

@ -11,7 +11,7 @@ the GNU General Public License, version 2, 1991.
********************************************/
/*
* $MawkId: print.c,v 1.43 2023/05/26 00:08:54 tom Exp $
* $MawkId: print.c,v 1.44 2023/07/23 15:14:06 tom Exp $
*/
#include "mawk.h"
@ -105,8 +105,7 @@ print_cell(CELL *p, FILE *fp)
*/
CELL *
bi_print(
CELL *sp) /* stack ptr passed in */
bi_print(CELL *sp) /* stack ptr passed in */
{
register CELL *p;
register int k;

View File

@ -1,6 +1,6 @@
/********************************************
re_cmpl.c
copyright 2008-2016,2020, Thomas E. Dickey
copyright 2008-2020,2023, Thomas E. Dickey
copyright 1991-1994,2014, 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: re_cmpl.c,v 1.32 2020/09/25 08:11:16 tom Exp $
* $MawkId: re_cmpl.c,v 1.34 2023/07/20 00:32:26 tom Exp $
*/
/* re_cmpl.c */
@ -98,14 +98,14 @@ re_compile(STRING * sval)
/* this is only used by da() */
char *
STRING *
re_uncompile(PTR m)
{
register RE_NODE *p;
for (p = re_list; p; p = p->link)
if (p->re.compiled == cast_to_re(m))
return p->sval->str;
return p->sval;
#ifdef DEBUG
bozo("non compiled machine");
#else
@ -364,7 +364,7 @@ repl_compile(STRING * sval)
/* return the string for a CELL or type REPL or REPLV,
this is only used by da() */
char *
const STRING *
repl_uncompile(CELL *cp)
{
register REPL_NODE *p = repl_list;
@ -372,7 +372,7 @@ repl_uncompile(CELL *cp)
if (cp->type == C_REPL) {
while (p) {
if (p->cp->type == C_REPL && p->cp->ptr == cp->ptr)
return p->sval->str;
return p->sval;
else
p = p->link;
}
@ -381,7 +381,7 @@ repl_uncompile(CELL *cp)
if (p->cp->type == C_REPLV &&
memcmp(cp->ptr, p->cp->ptr, cp->vcnt * sizeof(STRING *))
== 0)
return p->sval->str;
return p->sval;
else
p = p->link;
}

8
repl.h
View File

@ -1,6 +1,6 @@
/********************************************
repl.h
copyright 2009-2014,2020, Thomas E. Dickey
copyright 2009-2020,2023, 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: repl.h,v 1.9 2020/07/17 23:16:52 tom Exp $
* $MawkId: repl.h,v 1.11 2023/07/20 00:32:26 tom Exp $
*/
/* repl.h */
@ -36,10 +36,10 @@ typedef struct re_data {
#define refRE_DATA(re) ((PTR) &(re))
PTR re_compile(STRING *);
char *re_uncompile(PTR);
STRING *re_uncompile(PTR);
CELL *repl_compile(STRING *);
char *repl_uncompile(CELL *);
const STRING *repl_uncompile(CELL *);
void re_destroy(PTR);
void repl_destroy(CELL *);
CELL *replv_cpy(CELL *, CELL *);

6
rexp.c
View File

@ -1,6 +1,6 @@
/********************************************
rexp.c
copyright 2008-2017,2020, Thomas E. Dickey
copyright 2008-2020,2023, Thomas E. Dickey
copyright 1991-1993,1996, 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: rexp.c,v 1.34 2020/10/23 08:07:50 tom Exp $
* $MawkId: rexp.c,v 1.35 2023/07/24 20:46:40 tom Exp $
*/
/* op precedence parser for regular expressions */
@ -348,7 +348,7 @@ REdestroy(STATE * ptr)
int n = 0;
STATE *q = ptr;
TRACE(("REdestroy %p\n", ptr));
TRACE(("REdestroy %p\n", (void *) ptr));
while (!done) {
TRACE(("...%d type %d\n", n, q->s_type));
switch (q->s_type) {

6
rexp.h
View File

@ -1,6 +1,6 @@
/********************************************
rexp.h
copyright 2008-2020,2021, Thomas E. Dickey
copyright 2008-2021,2023, Thomas E. Dickey
copyright 2010, Jonathan Nieder
copyright 1991,2014, Michael D. Brennan
@ -12,7 +12,7 @@ the GNU General Public License, version 2, 1991.
********************************************/
/*
* $MawkId: rexp.h,v 1.39 2021/05/28 08:23:39 tom Exp $
* $MawkId: rexp.h,v 1.40 2023/07/23 11:32:20 tom Exp $
*/
#ifndef REXP_H
@ -61,7 +61,7 @@ typedef UChar BV[32]; /* bit vector */
typedef struct {
SType s_type;
SLen s_len; /* used for M_STR */
size_t s_len; /* used for M_STR */
union {
char *str; /* string */
BV *bvp; /* class */

View File

@ -11,7 +11,7 @@ the GNU General Public License, version 2, 1991.
********************************************/
/*
* $MawkId: rexp1.c,v 1.23 2023/07/13 08:09:35 tom Exp $
* $MawkId: rexp1.c,v 1.24 2023/07/23 11:30:35 tom Exp $
*/
/* re machine operations */
@ -90,7 +90,7 @@ RE_str(char *str, size_t len)
MACHINE x;
new_TWO(M_STR, &x);
x.start->s_len = (SLen) len;
x.start->s_len = len;
x.start->s_data.str = str;
return x;
}

View File

@ -1,6 +1,6 @@
/********************************************
rexp3.c
copyright 2008-2017,2020, Thomas E. Dickey
copyright 2008-2020,2023, Thomas E. Dickey
copyright 2010, Jonathan Nieder
copyright 1991-1992,1993, Michael D. Brennan
@ -12,7 +12,7 @@ the GNU General Public License, version 2, 1991.
********************************************/
/*
* $MawkId: rexp3.c,v 1.48 2020/10/22 22:45:12 tom Exp $
* $MawkId: rexp3.c,v 1.50 2023/07/24 20:43:39 tom Exp $
*/
/* match a string against a machine */
@ -206,7 +206,7 @@ REmatch(char *str, /* string to test */
case M_STR + U_ON + END_ON:
TRACE2(("@%d, now %03d\n", __LINE__, (int) (m - machine)));
t = (int) ((SLen) (str_end - s) - m->s_len);
t = (int) ((size_t) (str_end - s) - m->s_len);
if (t < 0 || memcmp(ts = s + t, m->s_data.str, (size_t) m->s_len)) {
RE_FILL();
}

View File

@ -1,6 +1,6 @@
/*
regexp_system.c
copyright 2009-2010,2014 Thomas E. Dickey
copyright 2009-2014,2023 Thomas E. Dickey
copyright 2005, Aleksey Cheusov
This is a source file for mawk, an implementation of
@ -11,14 +11,14 @@ the GNU General Public License, version 2, 1991.
*/
/*
* $MawkId: rexp4.c,v 1.8 2014/08/22 00:52:21 tom Exp $
* $MawkId: rexp4.c,v 1.9 2023/07/23 11:32:20 tom Exp $
*/
#include "mawk.h"
#include "rexp.h"
#include "field.h"
char *
is_string_split(PTR q, SLen * lenp)
is_string_split(PTR q, size_t * lenp)
{
STATE *p = (STATE *) q;

View File

@ -1,6 +1,6 @@
/********************************************
rexpdb.c
copyright 2008-2016,2020, Thomas E. Dickey
copyright 2008-2020,2023, 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.23 2020/10/23 23:32:39 tom Exp $
* $MawkId: rexpdb.c,v 1.24 2023/07/20 00:10:52 tom Exp $
*/
#include "rexp.h"
@ -67,7 +67,7 @@ REmprint(STATE * m, FILE *f)
switch (p->s_type) {
case M_STR:
fprintf(f, "\t");
da_string(f, p->s_data.str, (size_t) p->s_len);
da_string2(f, p->s_data.str, (size_t) p->s_len, '"');
break;
case M_1J:

27
scan.c
View File

@ -12,7 +12,7 @@ the GNU General Public License, version 2, 1991.
********************************************/
/*
* $MawkId: scan.c,v 1.50 2023/07/16 23:38:30 tom Exp $
* $MawkId: scan.c,v 1.52 2023/07/25 19:12:26 tom Exp $
*/
#include "mawk.h"
@ -420,7 +420,7 @@ yylex(void)
case SC_ESCAPE:
while (scan_code[NextUChar(c)] == SC_SPACE) {
; /* empty */
};
}
if (c == '\n') {
token_lineno = ++lineno;
goto reswitch;
@ -533,8 +533,8 @@ yylex(void)
ct_ret(RBOX);
case SC_MATCH:
string_buff[1] = '~';
string_buff[0] = 0;
string_buff[0] = '~';
string_buff[1] = 0;
yylval.ival = 1;
ct_ret(MATCH);
@ -675,7 +675,7 @@ yylex(void)
while (scan_code[NextUChar(c)] == SC_SPACE) {
; /* empty */
};
}
if (scan_code[c] != SC_DIGIT &&
scan_code[c] != SC_DOT) {
un_next();
@ -726,8 +726,7 @@ yylex(void)
/* check for function call before defined */
if (next() == CHR_LPAREN) {
stp->type = ST_FUNCT;
stp->stval.fbp = (FBLOCK *)
zmalloc(sizeof(FBLOCK));
stp->stval.fbp = ZMALLOC(FBLOCK);
stp->stval.fbp->name = stp->name;
stp->stval.fbp->code = (INST *) 0;
stp->stval.fbp->size = 0;
@ -780,20 +779,6 @@ yylex(void)
current_token = BUILTIN;
break;
case ST_LENGTH:
yylval.bip = stp->stval.bip;
/* check for length alone, this is an ugly
hack */
while (scan_code[NextUChar(c)] == SC_SPACE) {
; /* empty */
};
un_next();
current_token = c == CHR_LPAREN ? BUILTIN : LENGTH;
break;
case ST_FIELD:
yylval.cp = stp->stval.cp;
current_token = FIELD;

8
scan.h
View File

@ -12,13 +12,13 @@ the GNU General Public License, version 2, 1991.
********************************************/
/*
* $MawkId: scan.h,v 1.6 2023/07/16 19:21:02 tom Exp $
* $MawkId: scan.h,v 1.7 2023/07/23 08:56:43 tom Exp $
*/
/* scan.h */
#ifndef SCAN_H_INCLUDED
#define SCAN_H_INCLUDED 1
#ifndef MAWK_SCAN_H
#define MAWK_SCAN_H
#include <stdio.h>
@ -34,4 +34,4 @@ extern void eat_nl(void);
/* in error.c */
extern void unexpected_char(void);
#endif /* SCAN_H_INCLUDED */
#endif /* MAWK_SCAN_H */

View File

@ -1,5 +1,6 @@
/********************************************
scancode.h
copyright 2023, Thomas E. Dickey
copyright 2009, Jonathan Nieder
copyright 1991, Michael D. Brennan
@ -11,8 +12,7 @@ the GNU General Public License, version 2, 1991.
********************************************/
/*
* $MawkId: scancode.h,v 1.2 2010/12/10 17:00:00 tom Exp $
* @Log: scancode.h,v @
* $MawkId: scancode.h,v 1.3 2023/07/22 22:31:02 tom Exp $
*/
/* scancode.h */
@ -24,39 +24,41 @@ extern char scan_code[256];
/* the scan codes to compactify the main switch */
#define SC_SPACE 1
#define SC_NL 2
#define SC_SEMI_COLON 3
#define SC_FAKE_SEMI_COLON 4
#define SC_LBRACE 5
#define SC_RBRACE 6
#define SC_QMARK 7
#define SC_COLON 8
#define SC_OR 9
#define SC_AND 10
#define SC_PLUS 11
#define SC_MINUS 12
#define SC_MUL 13
#define SC_DIV 14
#define SC_MOD 15
#define SC_POW 16
#define SC_LPAREN 17
#define SC_RPAREN 18
#define SC_LBOX 19
#define SC_RBOX 20
#define SC_IDCHAR 21
#define SC_DIGIT 22
#define SC_DQUOTE 23
#define SC_ESCAPE 24
#define SC_COMMENT 25
#define SC_EQUAL 26
#define SC_NOT 27
#define SC_LT 28
#define SC_GT 29
#define SC_COMMA 30
#define SC_DOT 31
#define SC_MATCH 32
#define SC_DOLLAR 33
#define SC_UNEXPECTED 34
typedef enum {
SC_SPACE = 1
,SC_NL
,SC_SEMI_COLON
,SC_FAKE_SEMI_COLON
,SC_LBRACE
,SC_RBRACE
,SC_QMARK
,SC_COLON
,SC_OR
,SC_AND
,SC_PLUS
,SC_MINUS
,SC_MUL
,SC_DIV
,SC_MOD
,SC_POW
,SC_LPAREN
,SC_RPAREN
,SC_LBOX
,SC_RBOX
,SC_IDCHAR
,SC_DIGIT
,SC_DQUOTE
,SC_ESCAPE
,SC_COMMENT
,SC_EQUAL
,SC_NOT
,SC_LT
,SC_GT
,SC_COMMA
,SC_DOT
,SC_MATCH
,SC_DOLLAR
,SC_UNEXPECTED
} SCAN_CODES;
#endif /* SCANCODE_H_INCLUDED */

12
split.h
View File

@ -1,6 +1,6 @@
/********************************************
split.h
copyright 2014, Thomas E. Dickey
copyright 2014,2023 Thomas E. Dickey
copyright 2014, Michael D. Brennan
This is a source file for mawk, an implementation of
@ -11,18 +11,18 @@ the GNU General Public License, version 2, 1991.
********************************************/
/*
* $MawkId: split.h,v 1.2 2014/09/14 21:34:37 tom Exp $
* $MawkId: split.h,v 1.4 2023/07/23 08:58:07 tom Exp $
*/
/* split.h */
#ifndef SCAN_H
#define SCAN_H
#ifndef MAWK_SPLIT_H
#define MAWK_SPLIT_H
extern size_t null_split(const char *s, size_t slen);
extern size_t re_split(char *s, size_t slen, PTR re);
extern size_t space_split(const char *s, size_t slen);
extern void transfer_to_array(CELL cp[], size_t cnt);
extern void transfer_to_fields(size_t);
extern void transfer_to_fields(size_t cnt);
#endif /* SCAN_H */
#endif /* MAWK_SPLIT_H */

View File

@ -1,6 +1,6 @@
/********************************************
symtype.h
copyright 2009-2016,2020, Thomas E. Dickey
copyright 2009-2020,2023, 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: symtype.h,v 1.20 2020/01/07 02:20:06 tom Exp $
* $MawkId: symtype.h,v 1.21 2023/07/24 21:40:11 tom Exp $
*/
/* types related to symbols are defined here */
@ -73,7 +73,6 @@ typedef enum {
,ST_FUNCT
,ST_NR /* NR is special */
,ST_ENV /* and so is ENVIRON */
,ST_LENGTH /* ditto and bozo */
,ST_LOCAL_NONE
,ST_LOCAL_VAR
,ST_LOCAL_ARRAY
@ -132,6 +131,12 @@ typedef struct fcall {
short arg_cnt_checked;
} FCALL_REC;
/* defer analysis from length() parameter for forward-references */
typedef struct {
short offset;
FBLOCK *fbp;
} DEFER_LEN;
extern FCALL_REC *resolve_list;
extern void resolve_fcalls(void);

View File

@ -1,7 +1,7 @@
#!/bin/sh
# $MawkId: fpe_test,v 1.8 2022/12/29 15:20:09 tom Exp $
# $MawkId: fpe_test,v 1.9 2023/07/25 21:27:38 tom Exp $
###############################################################################
# copyright 2009-2010,2022, Thomas E. Dickey
# copyright 2009-2022,2023, Thomas E. Dickey
# copyright 2010, Guido Berhoerster
# copyright 1994,1995, Michael D. Brennan
#
@ -14,14 +14,6 @@
# tests if mawk has been compiled to correctly handle
# floating point exceptions
#
# @Log: fpe_test,v @
# Revision 1.3 1995/08/29 14:17:18 mike
# exit 2 changes
#
# Revision 1.2 1994/12/18 18:51:55 mike
# recognize NAN printed as ? for hpux
#
PROG="${MAWK:-../mawk}"

11
trace.c
View File

@ -1,6 +1,6 @@
/********************************************
trace.c
copyright 2012-2016,2019 Thomas E. Dickey
copyright 2012-2019,2023 Thomas E. Dickey
This is a source file for mawk, an implementation of
the AWK programming language.
@ -10,7 +10,7 @@ the GNU General Public License, version 2, 1991.
********************************************/
/*
* $MawkId: trace.c,v 1.16 2019/02/02 02:02:33 tom Exp $
* $MawkId: trace.c,v 1.18 2023/07/24 20:42:21 tom Exp $
*/
#include <mawk.h>
#include <repl.h>
@ -68,7 +68,9 @@ TraceCell(CELL *cp)
TRACE(("split on the empty string\n"));
break;
case C_RE:
TRACE(("a regular expression at %p: %s\n", cp->ptr, re_uncompile(cp->ptr)));
TRACE(("a regular expression at %p: ", cp->ptr));
da_string(trace_fp, re_uncompile(cp->ptr), '/');
fputc('\n', trace_fp);
break;
case C_REPL:
TRACE(("a replacement string at %p: ", cp->ptr));
@ -144,7 +146,6 @@ TraceInst(INST * p, INST * base)
case ALOOP:
case A_CAT:
case A_DEL:
case A_LENGTH:
case A_TEST:
case DEL_A:
case FE_PUSHA:
@ -166,6 +167,8 @@ TraceInst(INST * p, INST * base)
case LA_PUSHA:
case L_PUSHA:
case L_PUSHI:
case _LENGTH:
case A_LENGTH:
case NF_PUSHI:
case OL_GL:
case OL_GL_NR:

View File

@ -1,6 +1,6 @@
/********************************************
types.h
copyright 2009-2014,2016 Thomas E. Dickey
copyright 2009-2016,2023 Thomas E. Dickey
copyright 1991-1993,2014 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: types.h,v 1.13 2016/09/27 00:59:29 tom Exp $
* $MawkId: types.h,v 1.14 2023/07/23 11:32:20 tom Exp $
*/
/* types.h */
@ -90,6 +90,5 @@ typedef union {
/* regex types */
typedef int SType;
typedef size_t SLen;
#endif /* MAWK_TYPES_H */

View File

@ -1,6 +1,6 @@
/********************************************
zmalloc.h
copyright 2009,2010, Thomas E. Dickey
copyright 2009-2010,2023 Thomas E. Dickey
copyright 1991,1993, Michael D. Brennan
This is a source file for mawk, an implementation of
@ -11,25 +11,13 @@ the GNU General Public License, version 2, 1991.
********************************************/
/*
* $MawkId: zmalloc.h,v 1.7 2010/12/10 17:00:00 tom Exp $
* @Log: zmalloc.h,v @
* Revision 1.2 1993/07/04 12:52:22 mike
* start on autoconfig changes
*
* Revision 1.1.1.1 1993/07/03 18:58:23 mike
* move source to cvs
*
* Revision 5.1 1991/12/05 07:59:41 brennan
* 1.1 pre-release
*
* $MawkId: zmalloc.h,v 1.8 2023/07/25 21:20:54 tom Exp $
*/
/* zmalloc.h */
#ifndef ZMALLOC_H
#define ZMALLOC_H
#include "nstd.h"
#include <nstd.h>
extern PTR zmalloc(size_t);
extern void zfree(PTR, size_t);