summaryrefslogtreecommitdiff
path: root/perl.h
blob: 9b877f3e309a6b1f694118c6822e9da0728049bc (plain)
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
/* $Header: perl.h,v 1.0.1.3 88/01/28 10:24:17 root Exp $
 *
 * $Log:	perl.h,v $
 * Revision 1.0.1.3  88/01/28  10:24:17  root
 * patch8: added eval operator.
 * 
 * Revision 1.0.1.2  88/01/24  03:53:47  root
 * patch 2: hid str_peek() in #ifdef DEBUGGING.
 * 
 * Revision 1.0.1.1  88/01/21  21:29:23  root
 * No longer defines STDSTDIO--gets it from config.h now.
 * 
 * Revision 1.0  87/12/18  13:05:38  root
 * Initial revision
 * 
 */

#define DEBUGGING

#define VOIDUSED 1
#include "config.h"

#ifndef BCOPY
#   define bcopy(s1,s2,l) memcpy(s2,s1,l);
#   define bzero(s,l) memset(s,0,l);
#endif

#include <stdio.h>
#include <ctype.h>
#include <setjmp.h>
#include <sys/types.h>
#include <sys/stat.h>

#ifdef TMINSYS
#include <sys/time.h>
#else
#include <time.h>
#endif

#include <sys/times.h>

typedef struct arg ARG;
typedef struct cmd CMD;
typedef struct formcmd FCMD;
typedef struct scanpat SPAT;
typedef struct stab STAB;
typedef struct stio STIO;
typedef struct string STR;
typedef struct atbl ARRAY;
typedef struct htbl HASH;

#include "str.h"
#include "form.h"
#include "stab.h"
#include "spat.h"
#include "arg.h"
#include "cmd.h"
#include "array.h"
#include "hash.h"

#ifdef CHARSPRINTF
    char *sprintf();
#else
    int sprintf();
#endif

/* A string is TRUE if not "" or "0". */
#define True(val) (tmps = (val), (*tmps && !(*tmps == '0' && !tmps[1])))
EXT char *Yes INIT("1");
EXT char *No INIT("");

#define str_true(str) (Str = (str), (Str->str_pok ? True(Str->str_ptr) : (Str->str_nok ? (Str->str_nval != 0.0) : 0 )))

#ifdef DEBUGGING
#define str_peek(str) (Str = (str), (Str->str_pok ? Str->str_ptr : (Str->str_nok ? (sprintf(buf,"num(%g)",Str->str_nval),buf) : "" )))
#endif

#define str_get(str) (Str = (str), (Str->str_pok ? Str->str_ptr : str_2ptr(Str)))
#define str_gnum(str) (Str = (str), (Str->str_nok ? Str->str_nval : str_2num(Str)))
EXT STR *Str;

#define GROWSTR(pp,lp,len) if (*(lp) < (len)) growstr(pp,lp,len)

CMD *add_label();
CMD *block_head();
CMD *append_line();
CMD *make_acmd();
CMD *make_ccmd();
CMD *invert();
CMD *addcond();
CMD *addloop();
CMD *wopt();

SPAT *stab_to_spat();

STAB *stabent();

ARG *stab_to_arg();
ARG *op_new();
ARG *make_op();
ARG *make_lval();
ARG *make_match();
ARG *make_split();
ARG *flipflip();

STR *arg_to_str();
STR *str_new();
STR *stab_str();
STR *eval();		/* this evaluates expressions */
STR *do_eval();		/* this evaluates eval operator */

FCMD *load_format();

char *scanpat();
char *scansubst();
char *scantrans();
char *scanstr();
char *scanreg();
char *reg_get();
char *str_append_till();
char *str_gets();

bool do_match();
bool do_open();
bool do_close();
bool do_print();

int do_subst();

void str_free();
void freearg();

EXT int line INIT(0);
EXT int arybase INIT(0);

struct outrec {
    int o_lines;
    char *o_str;
    int o_len;
};

EXT struct outrec outrec;
EXT struct outrec toprec;

EXT STAB *last_in_stab INIT(Nullstab);
EXT STAB *defstab INIT(Nullstab);
EXT STAB *argvstab INIT(Nullstab);
EXT STAB *envstab INIT(Nullstab);
EXT STAB *sigstab INIT(Nullstab);
EXT STAB *defoutstab INIT(Nullstab);
EXT STAB *curoutstab INIT(Nullstab);
EXT STAB *argvoutstab INIT(Nullstab);

EXT STR *freestrroot INIT(Nullstr);

EXT FILE *rsfp;
EXT char buf[1024];
EXT char *bufptr INIT(buf);

EXT STR *linestr INIT(Nullstr);

EXT char record_separator INIT('\n');
EXT char *ofs INIT(Nullch);
EXT char *ors INIT(Nullch);
EXT char *ofmt INIT(Nullch);
EXT char *inplace INIT(Nullch);

EXT char tokenbuf[256];
EXT int expectterm INIT(TRUE);
EXT int lex_newlines INIT(FALSE);
EXT int in_eval INIT(FALSE);

FILE *popen();
/* char *str_get(); */
STR *interp();
void free_arg();
STIO *stio_new();

EXT struct stat statbuf;
EXT struct tms timesbuf;

#ifdef DEBUGGING
EXT int debug INIT(0);
EXT int dlevel INIT(0);
EXT char debname[40];
EXT char debdelim[40];
#define YYDEBUG;
extern int yydebug;
#endif

EXT STR str_no;
EXT STR str_yes;

/* runtime control stuff */

EXT struct loop {
    char *loop_label;
    jmp_buf loop_env;
} loop_stack[32];

EXT int loop_ptr INIT(-1);

EXT jmp_buf top_env;
EXT jmp_buf eval_env;

EXT char *goto_targ INIT(Nullch);	/* cmd_exec gets strange when set */

double atof();
long time();
struct tm *gmtime(), *localtime();

#ifdef EUNICE
#define UNLINK(f) while (unlink(f) >= 0)
#else
#define UNLINK unlink
#endif