File: mawk.h

package info (click to toggle)
mawk 1.3.4.20260129-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 2,244 kB
  • sloc: ansic: 19,998; sh: 4,627; yacc: 1,182; awk: 903; makefile: 301
file content (307 lines) | stat: -rw-r--r-- 7,857 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
/********************************************
mawk.h
copyright 2008-2025,2026 Thomas E. Dickey
copyright 1991-1995,1996 Michael D. Brennan

This is a source file for mawk, an implementation of
the AWK programming language.

Mawk is distributed without warranty under the terms of
the GNU General Public License, version 2, 1991.
********************************************/

/*
 * $MawkId: mawk.h,v 1.79 2026/01/17 00:01:23 tom Exp $
 */

/*  mawk.h  */

#ifndef  MAWK_H
#define  MAWK_H

#include <nstd.h>

#include <stdio.h>
#include <stdarg.h>

#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif

#include <assert.h>

#ifdef HAVE_STDNORETURN_H
#include <stdnoreturn.h>
#undef GCC_NORETURN
#define GCC_NORETURN STDC_NORETURN
#endif

#include <repl.h>
#include <types.h>
#include <makebits.h>

#ifndef GCC_NORETURN
#define GCC_NORETURN		/* nothing */
#endif

#ifndef GCC_PRINTFLIKE
#define  GCC_PRINTFLIKE(fmt,var)	/* nothing */
#endif

#ifndef GCC_UNUSED
#define GCC_UNUSED		/* nothing */
#endif

#if defined(__GNUC__) && defined(_FORTIFY_SOURCE)
#define IGNORE_RC(func) ignore_unused = (int) func
extern int ignore_unused;
#else
#define IGNORE_RC(func) (void) func
#endif /* gcc workarounds */

#ifdef   DEBUG
#define  YYDEBUG  1
extern int yydebug;		/* print parse if on */
extern int dump_RE;
#endif

#if defined(MSDOS) || defined(__MINGW32__) || defined(_WINNT)
#define USE_BINMODE 1
#else
#define USE_BINMODE 0
#endif

extern short interactive_flag;
extern short posix_space_flag;
extern short traditional_flag;

#ifndef NO_INTERVAL_EXPR
extern short repetitions_flag;
#endif

/*----------------
 *  GLOBAL VARIABLES
 *----------------*/

/* a well known string */
extern STRING null_str;

/* a useful scratch area */
extern char string_buff[SPRINTF_LIMIT];

/* help with casts */
extern const int mpow2[];

 /* these are used by the parser, scanner and error messages
    from the compile  */

extern char *pfile_name;	/* program input file */
extern int current_token;
extern unsigned token_lineno;	/* lineno of current token */
extern unsigned compile_error_count;
extern int NR_flag;
extern int paren_cnt;
extern int brace_cnt;
extern int print_flag, getline_flag;
extern short mawk_state;
#define EXECUTION       1	/* other state is 0 compiling */

#ifdef LOCALE
extern char decimal_dot;
#endif

extern const char *progname;	/* for error messages */
extern unsigned rt_nr, rt_fnr;	/* ditto */

#define TABLESIZE(name) (sizeof(name)/sizeof(name[0]))

/* macro to test the type of two adjacent cells */
#define TEST2(cp)  (mpow2[(cp)->type]+mpow2[((cp)+1)->type])

/* macro to get at the string part of a CELL */
#define string(cp) ((STRING *)(cp)->ptr)

#ifdef   DEBUG
#define cell_destroy(cp)  DB_cell_destroy(cp)
#else
/* Note: type is only C_STRING to C_MBSTRN */
#define cell_destroy(cp) \
	do { \
	    if ( (cp)->type >= C_STRING && \
	         (cp)->type <= C_MBSTRN && \
		 string(cp) != NULL) { \
	        unsigned final = string(cp)->ref_cnt; \
		free_STRING(string(cp));  \
		if (final <= 1) { \
		    (cp)->ptr = NULL; \
		} \
	    } \
	} while (0)
#endif

/*  prototypes  */

extern void cast1_to_s(CELL *);
extern void cast1_to_d(CELL *);
extern void cast2_to_s(CELL *);
extern void cast2_to_d(CELL *);
extern void cast_to_RE(CELL *);
extern void cast_for_split(CELL *);
extern void check_strnum(CELL *);
extern void cast_to_REPL(CELL *);
extern Int d_to_I(double);
extern Long d_to_L(double);
extern ULong d_to_UL(double d);

#define NonNull(s)    ((s) == NULL ? "<null>" : (s))

#define d_to_i(d)     ((int)d_to_I(d))
#define d_to_l(d)     ((long)d_to_L(d))

#define IsMaxBound(n) ((n) == UNSIGNED_LIMITS || (n) == INTEGERS_LIMITS)
#define PastBound(n)  ((n) > UNSIGNED_LIMITS)

extern int test(CELL *);	/* test for null non-null */
extern CELL *cellcpy(CELL *, CELL *);
extern CELL *repl_cpy(CELL *, CELL *);
extern void DB_cell_destroy(CELL *);
extern GCC_NORETURN void overflow(const char *, unsigned);
extern GCC_NORETURN void rt_overflow(const char *, size_t);
extern GCC_NORETURN void rt_error(const char *,...) GCC_PRINTFLIKE(1,2);
extern GCC_NORETURN void mawk_exit(int);
extern void da(INST *, FILE *);
extern INST *da_this(INST *, const INST *, FILE *);
extern char *rm_escape(char *, size_t *);
extern char *re_pos_match(char *, size_t, RE_NODE *, size_t *, int);
extern char *safe_string(char *);
extern int binmode(void);

#ifndef  REXP_H
extern char *str_str(char *, size_t, const char *, size_t);
#endif

extern void parse(void);
extern void scan_cleanup(void);

#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 execute(INST *, CELL *, CELL *);
extern const char *find_kw_str(int);
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 **);
#define strtod  strtod_with_ovf_bug
#endif

#ifndef OPT_CALLX
#define OPT_CALLX 0
#endif

#if OPT_TRACE > 0
extern FILE *trace_fp;
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
#define TRACE2(params) Trace params
#endif
#endif

#ifndef TRACE
#define TRACE(params)		/* nothing */
#endif

#ifndef TRACE2
#define TRACE2(params)		/* nothing */
#endif

#if OPT_TRACE > 0
extern void TraceCell(CELL *);
extern void TraceString(STRING *);
extern void TraceString2(const char *, size_t);
#define TRACE_CELL(cp)		TraceCell(cp)
#define TRACE_STRING(cp)	TraceString(cp)
#define TRACE_STRING2(str,len)	TraceString2(str,len)
#else
#define TRACE_CELL(cp)		/* nothing */
#define TRACE_STRING(cp)	/* nothing */
#define TRACE_STRING2(str,len)	/* nothing */
#endif

#if OPT_TRACE > 0
extern void TraceFunc(const char *, CELL *, int);
#define TRACE_FUNC2(name,cp,na) TraceFunc(name,cp,na)
#define TRACE_FUNC(name,cp) TraceFunc(name,cp,cp->type)
#else
#define TRACE_FUNC2(name,cp,na)	/* nothing */
#define TRACE_FUNC(name,cp)	/* nothing */
#endif

#if OPT_TRACE > 0
extern void TraceInst(INST *, INST *);
#define TRACE_INST(cp,base) TraceInst(cp,base)
#else
#define TRACE_INST(cp,base)	/* nothing */
#endif

extern const char *da_type_name(const CELL *);
extern const char *da_op_name(const INST *);

#ifdef NO_LEAKS

extern void free_cell_data(CELL *);
extern void free_codes(const char *, INST *, size_t);
extern void no_leaks_cell(CELL *);
extern void no_leaks_cell_ptr(CELL *);
extern void no_leaks_re_ptr(PTR);

extern void array_leaks(void);
extern void bi_vars_leaks(void);
extern void cell_leaks(void);
extern void code_leaks(void);
extern void field_leaks(void);
extern void files_leaks(void);
extern void fin_leaks(void);
extern void hash_leaks(void);
extern void re_leaks(void);
extern void rexp_leaks(void);
extern void scan_leaks(void);
extern void trace_leaks(void);
extern void zmalloc_leaks(void);

#else

#define free_codes(tag, base, size) zfree(base, size)
#define no_leaks_cell(ptr)	/* nothing */
#define no_leaks_cell_ptr(ptr)	/* nothing */
#define no_leaks_re_ptr(ptr)	/* nothing */

#endif

/*
 * Do limit-checks as comparison against compile-time constant.
 */
extern size_t size_overflow(const char *, size_t);
#define SizePlus(size,plus)	((size) < (SIZE_MAX - (plus)) ? (size) + (plus) : size_overflow(#size,size))
#define SizeTimes(size,plus)	((size) < (SIZE_MAX / (plus)) ? (size) * (plus) : size_overflow(#size,size))

/*
 * Sometimes split_buff[] pointers are moved rather than copied.
 * Optimize-out the assignment to clear the pointer in the array.
 */
#ifdef NO_LEAKS
#define USED_SPLIT_BUFF(n) split_buff[n] = NULL
#else
#define USED_SPLIT_BUFF(n)	/* nothing */
#endif

#endif /* MAWK_H */