Tizen 2.1 base
[external/mawk.git] / bi_vars.c
1
2 /********************************************
3 bi_vars.c
4 copyright 1991, Michael D. Brennan
5
6 This is a source file for mawk, an implementation of
7 the AWK programming language.
8
9 Mawk is distributed without warranty under the terms of
10 the GNU General Public License, version 2, 1991.
11 ********************************************/
12
13 /* $Log: bi_vars.c,v $
14  * Revision 1.1.1.1  1993/07/03  18:58:09  mike
15  * move source to cvs
16  *
17  * Revision 5.2  1992/07/10  16:17:10  brennan
18  * MsDOS: remove NO_BINMODE macro
19  *
20  * Revision 5.1  1991/12/05  07:55:38  brennan
21  * 1.1 pre-release
22  *
23 */
24
25
26 /* bi_vars.c */
27
28 #include "mawk.h"
29 #include "symtype.h"
30 #include "bi_vars.h"
31 #include "field.h"
32 #include "init.h"
33 #include "memory.h"
34
35 /* the builtin variables */
36 CELL  bi_vars[NUM_BI_VAR] ;
37
38 /* the order here must match the order in bi_vars.h */
39
40 static char *bi_var_names[NUM_BI_VAR] = {
41 "NR" ,
42 "FNR" ,
43 "ARGC" ,
44 "FILENAME" ,
45 "OFS" ,
46 "ORS" ,
47 "RLENGTH" ,
48 "RSTART" ,
49 "SUBSEP"
50 #if MSDOS 
51 , "BINMODE"
52 #endif
53 } ;
54
55 /* insert the builtin vars in the hash table */
56
57 void  bi_vars_init()
58 { register int i ;
59   register SYMTAB *s ;
60
61   
62   for ( i = 0 ; i < NUM_BI_VAR ; i++ )
63   { s = insert( bi_var_names[i] ) ;
64     s->type = i <= 1 ? ST_NR : ST_VAR ; 
65     s->stval.cp = bi_vars + i ;
66     /* bi_vars[i].type = 0 which is C_NOINIT */
67   }
68
69   s = insert("ENVIRON") ;
70   s->type = ST_ENV ;
71
72   /* set defaults */
73
74   FILENAME->type = C_STRING ;
75   FILENAME->ptr = (PTR) new_STRING( "" ) ; 
76
77   OFS->type = C_STRING ;
78   OFS->ptr = (PTR) new_STRING( " " ) ;
79   
80   ORS->type = C_STRING ;
81   ORS->ptr = (PTR) new_STRING( "\n" ) ;
82
83   SUBSEP->type = C_STRING ;
84   SUBSEP->ptr =  (PTR) new_STRING( "\034" ) ;
85
86   NR->type = FNR->type = C_DOUBLE ;
87   /* dval is already 0.0 */
88
89 #if  MSDOS  
90   BINMODE->type = C_DOUBLE ;
91 #endif
92 }