-
Notifications
You must be signed in to change notification settings - Fork 0
/
bi_vars.c
84 lines (64 loc) · 1.71 KB
/
bi_vars.c
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
/********************************************
bi_vars.c
copyright 1991,2014-2016 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 3, 2007.
If you import elements of this code into another product,
you agree to not name that product mawk.
********************************************/
/* bi_vars.c */
#include "mawk.h"
#include "table.h"
#include "bi_vars.h"
#include "field.h"
#include "init.h"
#include "types_string.h"
/* the builtin variables */
CELL bi_vars[NUM_BI_VAR];
/* the order here must match the order in bi_vars.h */
static const char * bi_var_names[NUM_BI_VAR] = {
"NR",
"FNR",
"ARGC",
"FILENAME",
"OFS",
"ORS",
"RLENGTH",
"RSTART",
"SUBSEP"
#if MSDOS
,
"BINMODE"
#endif
};
/* insert the builtin vars in the hash table */
void
bi_vars_init( void )
{
register int i;
register SYMTAB * s;
for ( i = 0; i < NUM_BI_VAR; i++ ) {
s = insert( bi_var_names[i] );
s->type = i <= 1 ? ST_NR : ST_VAR;
s->stval.cp = bi_vars + i;
/* bi_vars[i].type = 0 which is C_NOINIT */
}
s = insert( "ENVIRON" );
s->type = ST_ENV;
/* set defaults */
FILENAME->type = C_STRING;
FILENAME->ptr = (void *)new_STRING( "" );
OFS->type = C_STRING;
OFS->ptr = (void *)new_STRING( " " );
ORS->type = C_STRING;
ORS->ptr = (void *)new_STRING( "\n" );
SUBSEP->type = C_STRING;
SUBSEP->ptr = (void *)new_STRING( "\034" );
NR->type = FNR->type = C_DOUBLE;
/* dval is already 0.0 */
#if MSDOS
BINMODE->type = C_DOUBLE;
#endif
}