| 1 | /* $Header: perl.h,v 3.0 89/10/18 15:21:21 lwall Locked $ |
| 2 | * |
| 3 | * Copyright (c) 1989, Larry Wall |
| 4 | * |
| 5 | * You may distribute under the terms of the GNU General Public License |
| 6 | * as specified in the README file that comes with the perl 3.0 kit. |
| 7 | * |
| 8 | * $Log: perl.h,v $ |
| 9 | * Revision 3.0 89/10/18 15:21:21 lwall |
| 10 | * 3.0 baseline |
| 11 | * |
| 12 | */ |
| 13 | |
| 14 | #ifndef lint |
| 15 | #define DEBUGGING |
| 16 | #endif |
| 17 | |
| 18 | #define VOIDUSED 1 |
| 19 | #include "config.h" |
| 20 | |
| 21 | #ifdef IAMSUID |
| 22 | # ifndef TAINT |
| 23 | # define TAINT |
| 24 | # endif |
| 25 | #endif |
| 26 | |
| 27 | #ifdef MEMCPY |
| 28 | extern char *memcpy(), *memset(); |
| 29 | #define bcopy(s1,s2,l) memcpy(s2,s1,l) |
| 30 | #define bzero(s,l) memset(s,0,l) |
| 31 | #endif |
| 32 | #ifndef BCMP /* prefer bcmp slightly 'cuz it doesn't order */ |
| 33 | #define bcmp(s1,s2,l) memcmp(s1,s2,l) |
| 34 | #endif |
| 35 | |
| 36 | #include <stdio.h> |
| 37 | #include <ctype.h> |
| 38 | #include <setjmp.h> |
| 39 | #include <sys/param.h> /* if this needs types.h we're still wrong */ |
| 40 | |
| 41 | #ifndef _TYPES_ /* If types.h defines this it's easy. */ |
| 42 | #ifndef major /* Does everyone's types.h define this? */ |
| 43 | #include <sys/types.h> |
| 44 | #endif |
| 45 | #endif |
| 46 | |
| 47 | #include <sys/stat.h> |
| 48 | |
| 49 | #ifdef TMINSYS |
| 50 | #include <sys/time.h> |
| 51 | #else |
| 52 | #ifdef I_SYSTIME |
| 53 | #include <sys/time.h> |
| 54 | #else |
| 55 | #include <time.h> |
| 56 | #endif |
| 57 | #endif |
| 58 | |
| 59 | #include <sys/times.h> |
| 60 | |
| 61 | #ifdef I_SYSIOCTL |
| 62 | #ifndef _IOCTL_ |
| 63 | #include <sys/ioctl.h> |
| 64 | #endif |
| 65 | #endif |
| 66 | |
| 67 | #if defined(mc300) || defined(mc500) || defined(mc700) /* MASSCOMP */ |
| 68 | #ifdef SOCKETPAIR |
| 69 | #undef SOCKETPAIR |
| 70 | #endif |
| 71 | #ifdef NDBM |
| 72 | #undef NDBM |
| 73 | #endif |
| 74 | #endif |
| 75 | |
| 76 | #ifdef NDBM |
| 77 | #include <ndbm.h> |
| 78 | #define SOME_DBM |
| 79 | #else |
| 80 | #ifdef ODBM |
| 81 | #ifdef NULL |
| 82 | #undef NULL /* suppress redefinition message */ |
| 83 | #endif |
| 84 | #include <dbm.h> |
| 85 | #ifdef NULL |
| 86 | #undef NULL |
| 87 | #endif |
| 88 | #define NULL 0 /* silly thing is, we don't even use this */ |
| 89 | #define SOME_DBM |
| 90 | #define dbm_fetch(db,dkey) fetch(dkey) |
| 91 | #define dbm_delete(db,dkey) delete(dkey) |
| 92 | #define dbm_store(db,dkey,dcontent,flags) store(dkey,dcontent) |
| 93 | #define dbm_close(db) dbmclose() |
| 94 | #define dbm_firstkey(db) firstkey() |
| 95 | #endif /* ODBM */ |
| 96 | #endif /* NDBM */ |
| 97 | #ifdef SOME_DBM |
| 98 | EXT char *dbmkey; |
| 99 | EXT int dbmlen; |
| 100 | #endif |
| 101 | |
| 102 | #if INTSIZE == 2 |
| 103 | #define htoni htons |
| 104 | #define ntohi ntohs |
| 105 | #else |
| 106 | #define htoni htonl |
| 107 | #define ntohi ntohl |
| 108 | #endif |
| 109 | |
| 110 | #ifdef I_DIRENT |
| 111 | #include <dirent.h> |
| 112 | #define DIRENT dirent |
| 113 | #else |
| 114 | #ifdef I_SYSDIR |
| 115 | #include <sys/dir.h> |
| 116 | #define DIRENT direct |
| 117 | #endif |
| 118 | #endif |
| 119 | |
| 120 | typedef struct arg ARG; |
| 121 | typedef struct cmd CMD; |
| 122 | typedef struct formcmd FCMD; |
| 123 | typedef struct scanpat SPAT; |
| 124 | typedef struct stio STIO; |
| 125 | typedef struct sub SUBR; |
| 126 | typedef struct string STR; |
| 127 | typedef struct atbl ARRAY; |
| 128 | typedef struct htbl HASH; |
| 129 | typedef struct regexp REGEXP; |
| 130 | typedef struct stabptrs STBP; |
| 131 | typedef struct stab STAB; |
| 132 | |
| 133 | #include "handy.h" |
| 134 | #include "regexp.h" |
| 135 | #include "str.h" |
| 136 | #include "util.h" |
| 137 | #include "form.h" |
| 138 | #include "stab.h" |
| 139 | #include "spat.h" |
| 140 | #include "arg.h" |
| 141 | #include "cmd.h" |
| 142 | #include "array.h" |
| 143 | #include "hash.h" |
| 144 | |
| 145 | #if defined(iAPX286) || defined(M_I286) || defined(I80286) |
| 146 | # define I286 |
| 147 | #endif |
| 148 | |
| 149 | #ifndef __STDC__ |
| 150 | #ifdef CHARSPRINTF |
| 151 | char *sprintf(); |
| 152 | #else |
| 153 | int sprintf(); |
| 154 | #endif |
| 155 | #endif |
| 156 | |
| 157 | EXT char *Yes INIT("1"); |
| 158 | EXT char *No INIT(""); |
| 159 | |
| 160 | /* "gimme" values */ |
| 161 | |
| 162 | /* Note: cmd.c assumes that it can use && to produce one of these values! */ |
| 163 | #define G_SCALAR 0 |
| 164 | #define G_ARRAY 1 |
| 165 | |
| 166 | #ifdef CRIPPLED_CC |
| 167 | int str_true(); |
| 168 | #else /* !CRIPPLED_CC */ |
| 169 | #define str_true(str) (Str = (str), \ |
| 170 | (Str->str_pok ? \ |
| 171 | ((*Str->str_ptr > '0' || \ |
| 172 | Str->str_cur > 1 || \ |
| 173 | (Str->str_cur && *Str->str_ptr != '0')) ? 1 : 0) \ |
| 174 | : \ |
| 175 | (Str->str_nok ? (Str->str_u.str_nval != 0.0) : 0 ) )) |
| 176 | #endif /* CRIPPLED_CC */ |
| 177 | |
| 178 | #ifdef DEBUGGING |
| 179 | #define str_peek(str) (Str = (str), \ |
| 180 | (Str->str_pok ? \ |
| 181 | Str->str_ptr : \ |
| 182 | (Str->str_nok ? \ |
| 183 | (sprintf(tokenbuf,"num(%g)",Str->str_u.str_nval), \ |
| 184 | (char*)tokenbuf) : \ |
| 185 | "" ))) |
| 186 | #endif |
| 187 | |
| 188 | #ifdef CRIPPLED_CC |
| 189 | char *str_get(); |
| 190 | #else |
| 191 | #ifdef TAINT |
| 192 | #define str_get(str) (Str = (str), tainted |= Str->str_tainted, \ |
| 193 | (Str->str_pok ? Str->str_ptr : str_2ptr(Str))) |
| 194 | #else |
| 195 | #define str_get(str) (Str = (str), (Str->str_pok ? Str->str_ptr : str_2ptr(Str))) |
| 196 | #endif /* TAINT */ |
| 197 | #endif /* CRIPPLED_CC */ |
| 198 | |
| 199 | #ifdef CRIPPLED_CC |
| 200 | double str_gnum(); |
| 201 | #else /* !CRIPPLED_CC */ |
| 202 | #ifdef TAINT |
| 203 | #define str_gnum(str) (Str = (str), tainted |= Str->str_tainted, \ |
| 204 | (Str->str_nok ? Str->str_u.str_nval : str_2num(Str))) |
| 205 | #else /* !TAINT */ |
| 206 | #define str_gnum(str) (Str = (str), (Str->str_nok ? Str->str_u.str_nval : str_2num(Str))) |
| 207 | #endif /* TAINT*/ |
| 208 | #endif /* CRIPPLED_CC */ |
| 209 | EXT STR *Str; |
| 210 | |
| 211 | #define GROWSTR(pp,lp,len) if (*(lp) < (len)) growstr(pp,lp,len) |
| 212 | |
| 213 | #define STR_GROW(str,len) if ((str)->str_len < (len)) str_grow(str,len) |
| 214 | |
| 215 | #ifndef BYTEORDER |
| 216 | #define BYTEORDER 01234 |
| 217 | #endif |
| 218 | |
| 219 | #ifndef HTONL |
| 220 | #if BYTEORDER != 04321 |
| 221 | #define HTONS |
| 222 | #define HTONL |
| 223 | #define NTOHS |
| 224 | #define NTOHL |
| 225 | #define MYSWAP |
| 226 | #define htons my_swap |
| 227 | #define htonl my_htonl |
| 228 | #define ntohs my_swap |
| 229 | #define ntohl my_ntohl |
| 230 | #endif |
| 231 | #else |
| 232 | #if BYTEORDER == 04321 |
| 233 | #undef HTONS |
| 234 | #undef HTONL |
| 235 | #undef NTOHS |
| 236 | #undef NTOHL |
| 237 | #endif |
| 238 | #endif |
| 239 | |
| 240 | CMD *add_label(); |
| 241 | CMD *block_head(); |
| 242 | CMD *append_line(); |
| 243 | CMD *make_acmd(); |
| 244 | CMD *make_ccmd(); |
| 245 | CMD *make_icmd(); |
| 246 | CMD *invert(); |
| 247 | CMD *addcond(); |
| 248 | CMD *addloop(); |
| 249 | CMD *wopt(); |
| 250 | CMD *over(); |
| 251 | |
| 252 | STAB *stabent(); |
| 253 | STAB *genstab(); |
| 254 | |
| 255 | ARG *stab2arg(); |
| 256 | ARG *op_new(); |
| 257 | ARG *make_op(); |
| 258 | ARG *make_match(); |
| 259 | ARG *make_split(); |
| 260 | ARG *rcatmaybe(); |
| 261 | ARG *listish(); |
| 262 | ARG *maybelistish(); |
| 263 | ARG *localize(); |
| 264 | ARG *fixeval(); |
| 265 | ARG *jmaybe(); |
| 266 | ARG *l(); |
| 267 | ARG *fixl(); |
| 268 | ARG *mod_match(); |
| 269 | ARG *make_list(); |
| 270 | ARG *cmd_to_arg(); |
| 271 | ARG *addflags(); |
| 272 | ARG *hide_ary(); |
| 273 | ARG *cval_to_arg(); |
| 274 | |
| 275 | STR *str_new(); |
| 276 | STR *stab_str(); |
| 277 | |
| 278 | int do_each(); |
| 279 | int do_subr(); |
| 280 | int do_match(); |
| 281 | int do_unpack(); |
| 282 | int eval(); /* this evaluates expressions */ |
| 283 | int do_eval(); /* this evaluates eval operator */ |
| 284 | int do_assign(); |
| 285 | |
| 286 | SUBR *make_sub(); |
| 287 | |
| 288 | FCMD *load_format(); |
| 289 | |
| 290 | char *scanpat(); |
| 291 | char *scansubst(); |
| 292 | char *scantrans(); |
| 293 | char *scanstr(); |
| 294 | char *scanreg(); |
| 295 | char *str_append_till(); |
| 296 | char *str_gets(); |
| 297 | char *str_grow(); |
| 298 | |
| 299 | bool do_open(); |
| 300 | bool do_close(); |
| 301 | bool do_print(); |
| 302 | bool do_aprint(); |
| 303 | bool do_exec(); |
| 304 | bool do_aexec(); |
| 305 | |
| 306 | int do_subst(); |
| 307 | int cando(); |
| 308 | int ingroup(); |
| 309 | |
| 310 | void str_replace(); |
| 311 | void str_inc(); |
| 312 | void str_dec(); |
| 313 | void str_free(); |
| 314 | void stab_clear(); |
| 315 | void do_join(); |
| 316 | void do_sprintf(); |
| 317 | void do_accept(); |
| 318 | void do_vecset(); |
| 319 | void savelist(); |
| 320 | void saveitem(); |
| 321 | void saveint(); |
| 322 | void savelong(); |
| 323 | void savesptr(); |
| 324 | void savehptr(); |
| 325 | void restorelist(); |
| 326 | HASH *savehash(); |
| 327 | ARRAY *saveary(); |
| 328 | |
| 329 | EXT line_t line INIT(0); |
| 330 | EXT line_t subline INIT(0); |
| 331 | EXT STR *subname INIT(Nullstr); |
| 332 | EXT int arybase INIT(0); |
| 333 | |
| 334 | struct outrec { |
| 335 | line_t o_lines; |
| 336 | char *o_str; |
| 337 | int o_len; |
| 338 | }; |
| 339 | |
| 340 | EXT struct outrec outrec; |
| 341 | EXT struct outrec toprec; |
| 342 | |
| 343 | EXT STAB *stdinstab INIT(Nullstab); |
| 344 | EXT STAB *last_in_stab INIT(Nullstab); |
| 345 | EXT STAB *defstab INIT(Nullstab); |
| 346 | EXT STAB *argvstab INIT(Nullstab); |
| 347 | EXT STAB *envstab INIT(Nullstab); |
| 348 | EXT STAB *sigstab INIT(Nullstab); |
| 349 | EXT STAB *defoutstab INIT(Nullstab); |
| 350 | EXT STAB *curoutstab INIT(Nullstab); |
| 351 | EXT STAB *argvoutstab INIT(Nullstab); |
| 352 | EXT STAB *incstab INIT(Nullstab); |
| 353 | EXT STAB *leftstab INIT(Nullstab); |
| 354 | EXT STAB *amperstab INIT(Nullstab); |
| 355 | EXT STAB *rightstab INIT(Nullstab); |
| 356 | EXT STAB *DBstab INIT(Nullstab); |
| 357 | EXT STAB *DBsub INIT(Nullstab); |
| 358 | |
| 359 | EXT HASH *defstash; /* main symbol table */ |
| 360 | EXT HASH *curstash; /* symbol table for current package */ |
| 361 | EXT HASH *debstash; /* symbol table for perldb package */ |
| 362 | |
| 363 | EXT STR *curstname; /* name of current package */ |
| 364 | |
| 365 | EXT STR *freestrroot INIT(Nullstr); |
| 366 | EXT STR *lastretstr INIT(Nullstr); |
| 367 | EXT STR *DBsingle INIT(Nullstr); |
| 368 | |
| 369 | EXT int lastspbase; |
| 370 | EXT int lastsize; |
| 371 | |
| 372 | EXT char *filename; |
| 373 | EXT char *origfilename; |
| 374 | EXT FILE *rsfp; |
| 375 | EXT char buf[1024]; |
| 376 | EXT char *bufptr; |
| 377 | EXT char *oldbufptr; |
| 378 | EXT char *oldoldbufptr; |
| 379 | EXT char *bufend; |
| 380 | |
| 381 | EXT STR *linestr INIT(Nullstr); |
| 382 | |
| 383 | EXT char record_separator INIT('\n'); |
| 384 | EXT int rslen INIT(1); |
| 385 | EXT char *ofs INIT(Nullch); |
| 386 | EXT int ofslen INIT(0); |
| 387 | EXT char *ors INIT(Nullch); |
| 388 | EXT int orslen INIT(0); |
| 389 | EXT char *ofmt INIT(Nullch); |
| 390 | EXT char *inplace INIT(Nullch); |
| 391 | EXT char *nointrp INIT(""); |
| 392 | |
| 393 | EXT bool preprocess INIT(FALSE); |
| 394 | EXT bool minus_n INIT(FALSE); |
| 395 | EXT bool minus_p INIT(FALSE); |
| 396 | EXT bool minus_a INIT(FALSE); |
| 397 | EXT bool doswitches INIT(FALSE); |
| 398 | EXT bool dowarn INIT(FALSE); |
| 399 | EXT bool allstabs INIT(FALSE); /* init all customary symbols in symbol table?*/ |
| 400 | EXT bool sawampersand INIT(FALSE); /* must save all match strings */ |
| 401 | EXT bool sawstudy INIT(FALSE); /* do fbminstr on all strings */ |
| 402 | EXT bool sawi INIT(FALSE); /* study must assume case insensitive */ |
| 403 | EXT bool sawvec INIT(FALSE); |
| 404 | |
| 405 | EXT int csh INIT(0); /* 1 if /bin/csh is there, -1 if not */ |
| 406 | |
| 407 | #ifdef TAINT |
| 408 | EXT bool tainted INIT(FALSE); /* using variables controlled by $< */ |
| 409 | #endif |
| 410 | |
| 411 | #define TMPPATH "/tmp/perl-eXXXXXX" |
| 412 | EXT char *e_tmpname; |
| 413 | EXT FILE *e_fp INIT(Nullfp); |
| 414 | |
| 415 | EXT char tokenbuf[256]; |
| 416 | EXT int expectterm INIT(TRUE); /* how to interpret ambiguous tokens */ |
| 417 | EXT int in_eval INIT(FALSE); /* trap fatal errors? */ |
| 418 | EXT int multiline INIT(0); /* $*--do strings hold >1 line? */ |
| 419 | EXT int forkprocess; /* so do_open |- can return proc# */ |
| 420 | EXT int do_undump INIT(0); /* -u or dump seen? */ |
| 421 | EXT int error_count INIT(0); /* how many errors so far, max 10 */ |
| 422 | EXT int multi_start INIT(0); /* 1st line of multi-line string */ |
| 423 | EXT int multi_end INIT(0); /* last line of multi-line string */ |
| 424 | EXT int multi_open INIT(0); /* delimiter of said string */ |
| 425 | EXT int multi_close INIT(0); /* delimiter of said string */ |
| 426 | |
| 427 | FILE *popen(); |
| 428 | /* char *str_get(); */ |
| 429 | STR *interp(); |
| 430 | void free_arg(); |
| 431 | STIO *stio_new(); |
| 432 | |
| 433 | EXT struct stat statbuf; |
| 434 | EXT struct stat statcache; |
| 435 | STAB *statstab INIT(Nullstab); |
| 436 | STR *statname; |
| 437 | EXT struct tms timesbuf; |
| 438 | EXT int uid; |
| 439 | EXT int euid; |
| 440 | EXT int gid; |
| 441 | EXT int egid; |
| 442 | UIDTYPE getuid(); |
| 443 | UIDTYPE geteuid(); |
| 444 | GIDTYPE getgid(); |
| 445 | GIDTYPE getegid(); |
| 446 | EXT int unsafe; |
| 447 | |
| 448 | #ifdef DEBUGGING |
| 449 | EXT int debug INIT(0); |
| 450 | EXT int dlevel INIT(0); |
| 451 | EXT int dlmax INIT(128); |
| 452 | EXT char *debname; |
| 453 | EXT char *debdelim; |
| 454 | #define YYDEBUG 1 |
| 455 | extern int yydebug; |
| 456 | #endif |
| 457 | EXT int perldb INIT(0); |
| 458 | |
| 459 | EXT line_t cmdline INIT(NOLINE); |
| 460 | |
| 461 | EXT STR str_undef; |
| 462 | EXT STR str_no; |
| 463 | EXT STR str_yes; |
| 464 | |
| 465 | /* runtime control stuff */ |
| 466 | |
| 467 | EXT struct loop { |
| 468 | char *loop_label; /* what the loop was called, if anything */ |
| 469 | int loop_sp; /* stack pointer to copy stuff down to */ |
| 470 | jmp_buf loop_env; |
| 471 | } *loop_stack; |
| 472 | |
| 473 | EXT int loop_ptr INIT(-1); |
| 474 | EXT int loop_max INIT(128); |
| 475 | |
| 476 | EXT jmp_buf top_env; |
| 477 | EXT jmp_buf eval_env; |
| 478 | |
| 479 | EXT char *goto_targ INIT(Nullch); /* cmd_exec gets strange when set */ |
| 480 | |
| 481 | EXT ARRAY *stack; /* THE STACK */ |
| 482 | |
| 483 | EXT ARRAY *savestack; /* to save non-local values on */ |
| 484 | |
| 485 | EXT ARRAY *tosave; /* strings to save on recursive subroutine */ |
| 486 | |
| 487 | EXT ARRAY *lineary; /* lines of script for debugger */ |
| 488 | |
| 489 | EXT ARRAY *pidstatary; /* keep pids and statuses by fd for mypopen */ |
| 490 | |
| 491 | double atof(); |
| 492 | long time(); |
| 493 | struct tm *gmtime(), *localtime(); |
| 494 | char *mktemp(); |
| 495 | char *index(), *rindex(); |
| 496 | char *strcpy(), *strcat(); |
| 497 | |
| 498 | #ifdef EUNICE |
| 499 | #define UNLINK unlnk |
| 500 | int unlnk(); |
| 501 | #else |
| 502 | #define UNLINK unlink |
| 503 | #endif |
| 504 | |
| 505 | #ifndef SETREUID |
| 506 | #ifdef SETRESUID |
| 507 | #define setreuid(r,e) setresuid(r,e,-1) |
| 508 | #define SETREUID |
| 509 | #endif |
| 510 | #endif |
| 511 | #ifndef SETREGID |
| 512 | #ifdef SETRESGID |
| 513 | #define setregid(r,e) setresgid(r,e,-1) |
| 514 | #define SETREGID |
| 515 | #endif |
| 516 | #endif |