home *** CD-ROM | disk | FTP | other *** search
/ OpenStep 4.2J (Developer) / os42jdev.iso / NextDeveloper / Source / GNU / perl / patch / x2p / a2p.h next >
Encoding:
C/C++ Source or Header  |  1995-11-17  |  8.1 KB  |  420 lines

  1. /* $RCSfile: a2p.h,v $$Revision: 4.1 $$Date: 92/08/07 18:29:09 $
  2.  *
  3.  *    Copyright (c) 1991, Larry Wall
  4.  *
  5.  *    You may distribute under the terms of either the GNU General Public
  6.  *    License or the Artistic License, as specified in the README file.
  7.  *
  8.  * $Log:    a2p.h,v $
  9.  */
  10.  
  11. #define VOIDUSED 1
  12. #include "../config.h"
  13.  
  14. #if defined(__STDC__) || defined(vax11c) || defined(_AIX) || defined(__stdc__) || defined(__cplusplus)
  15. # define STANDARD_C 1
  16. #endif
  17.  
  18. /* Use all the "standard" definitions? */
  19. #if defined(STANDARD_C) && defined(I_STDLIB)
  20. #   include <stdlib.h>
  21. #endif /* STANDARD_C */
  22.  
  23. #include <stdio.h>
  24.  
  25. #ifdef I_MATH
  26. #include <math.h>
  27. #endif
  28.  
  29. #ifdef I_SYS_TYPES
  30. #  include <sys/types.h>
  31. #endif
  32.  
  33.  
  34. #ifdef USE_NEXT_CTYPE
  35.  
  36. #if NX_CURRENT_COMPILER_RELEASE >= 400
  37. #include <objc/NXCType.h>
  38. #else /*  NX_CURRENT_COMPILER_RELEASE < 400 */
  39. #include <appkit/NXCType.h>
  40. #endif /*  NX_CURRENT_COMPILER_RELEASE >= 400 */
  41.  
  42. #else /* !USE_NEXT_CTYPE */
  43. #include <ctype.h>
  44. #endif /* USE_NEXT_CTYPE */
  45.  
  46. #define MEM_SIZE Size_t
  47.  
  48. #if defined(I_STRING) || defined(__cplusplus)
  49. #   include <string.h>
  50. #else
  51. #   include <strings.h>
  52. #endif
  53.  
  54. #ifndef HAS_BCOPY
  55. #   define bcopy(s1,s2,l) memcpy(s2,s1,l)
  56. #endif
  57. #ifndef HAS_BZERO
  58. #   define bzero(s,l) memset(s,0,l)
  59. #endif
  60.  
  61. #if !defined(HAS_STRCHR) && defined(HAS_INDEX) && !defined(strchr)
  62. #define strchr index
  63. #define strrchr rindex
  64. #endif
  65.  
  66.  
  67. #ifdef I_TIME
  68. #   include <time.h>
  69. #endif
  70.  
  71. #ifdef I_SYS_TIME
  72. #   ifdef I_SYS_TIME_KERNEL
  73. #    define KERNEL
  74. #   endif
  75. #   include <sys/time.h>
  76. #   ifdef I_SYS_TIME_KERNEL
  77. #    undef KERNEL
  78. #   endif
  79. #endif
  80.  
  81. #ifndef MSDOS
  82. #  if defined(HAS_TIMES) && defined(I_SYS_TIMES)
  83. #    include <sys/times.h>
  84. #  endif
  85. #endif
  86.  
  87. #ifndef STANDARD_C
  88. /* All of these are in stdlib.h or time.h for ANSI C */
  89. Time_t time();
  90. struct tm *gmtime(), *localtime();
  91. char *strchr(), *strrchr();
  92. char *strcpy(), *strcat();
  93. #endif /* ! STANDARD_C */
  94.  
  95. #include "handy.h"
  96. #define Nullop 0
  97.  
  98. #define OPROG        1
  99. #define OJUNK        2
  100. #define OHUNKS        3
  101. #define ORANGE        4
  102. #define OPAT        5
  103. #define OHUNK        6
  104. #define OPPAREN        7
  105. #define OPANDAND    8
  106. #define OPOROR        9
  107. #define OPNOT        10
  108. #define OCPAREN        11
  109. #define OCANDAND    12
  110. #define OCOROR        13
  111. #define OCNOT        14
  112. #define ORELOP        15
  113. #define ORPAREN        16
  114. #define OMATCHOP    17
  115. #define OMPAREN        18
  116. #define OCONCAT        19
  117. #define OASSIGN        20
  118. #define OADD        21
  119. #define OSUBTRACT    22
  120. #define OMULT        23
  121. #define ODIV        24
  122. #define OMOD        25
  123. #define OPOSTINCR    26
  124. #define OPOSTDECR    27
  125. #define OPREINCR    28
  126. #define OPREDECR    29
  127. #define OUMINUS        30
  128. #define OUPLUS        31
  129. #define OPAREN        32
  130. #define OGETLINE    33
  131. #define OSPRINTF    34
  132. #define OSUBSTR        35
  133. #define OSTRING        36
  134. #define OSPLIT        37
  135. #define OSNEWLINE    38
  136. #define OINDEX        39
  137. #define ONUM        40
  138. #define OSTR        41
  139. #define OVAR        42
  140. #define OFLD        43
  141. #define ONEWLINE    44
  142. #define OCOMMENT    45
  143. #define OCOMMA        46
  144. #define OSEMICOLON    47
  145. #define OSCOMMENT    48
  146. #define OSTATES        49
  147. #define OSTATE        50
  148. #define OPRINT        51
  149. #define OPRINTF        52
  150. #define OBREAK        53
  151. #define ONEXT        54
  152. #define OEXIT        55
  153. #define OCONTINUE    56
  154. #define OREDIR        57
  155. #define OIF        58
  156. #define OWHILE        59
  157. #define OFOR        60
  158. #define OFORIN        61
  159. #define OVFLD        62
  160. #define OBLOCK        63
  161. #define OREGEX        64
  162. #define OLENGTH        65
  163. #define OLOG        66
  164. #define OEXP        67
  165. #define OSQRT        68
  166. #define OINT        69
  167. #define ODO        70
  168. #define OPOW        71
  169. #define OSUB        72
  170. #define OGSUB        73
  171. #define OMATCH        74
  172. #define OUSERFUN    75
  173. #define OUSERDEF    76
  174. #define OCLOSE        77
  175. #define OATAN2        78
  176. #define OSIN        79
  177. #define OCOS        80
  178. #define ORAND        81
  179. #define OSRAND        82
  180. #define ODELETE        83
  181. #define OSYSTEM        84
  182. #define OCOND        85
  183. #define ORETURN        86
  184. #define ODEFINED    87
  185. #define OSTAR        88
  186.  
  187. #ifdef DOINIT
  188. char *opname[] = {
  189.     "0",
  190.     "PROG",
  191.     "JUNK",
  192.     "HUNKS",
  193.     "RANGE",
  194.     "PAT",
  195.     "HUNK",
  196.     "PPAREN",
  197.     "PANDAND",
  198.     "POROR",
  199.     "PNOT",
  200.     "CPAREN",
  201.     "CANDAND",
  202.     "COROR",
  203.     "CNOT",
  204.     "RELOP",
  205.     "RPAREN",
  206.     "MATCHOP",
  207.     "MPAREN",
  208.     "CONCAT",
  209.     "ASSIGN",
  210.     "ADD",
  211.     "SUBTRACT",
  212.     "MULT",
  213.     "DIV",
  214.     "MOD",
  215.     "POSTINCR",
  216.     "POSTDECR",
  217.     "PREINCR",
  218.     "PREDECR",
  219.     "UMINUS",
  220.     "UPLUS",
  221.     "PAREN",
  222.     "GETLINE",
  223.     "SPRINTF",
  224.     "SUBSTR",
  225.     "STRING",
  226.     "SPLIT",
  227.     "SNEWLINE",
  228.     "INDEX",
  229.     "NUM",
  230.     "STR",
  231.     "VAR",
  232.     "FLD",
  233.     "NEWLINE",
  234.     "COMMENT",
  235.     "COMMA",
  236.     "SEMICOLON",
  237.     "SCOMMENT",
  238.     "STATES",
  239.     "STATE",
  240.     "PRINT",
  241.     "PRINTF",
  242.     "BREAK",
  243.     "NEXT",
  244.     "EXIT",
  245.     "CONTINUE",
  246.     "REDIR",
  247.     "IF",
  248.     "WHILE",
  249.     "FOR",
  250.     "FORIN",
  251.     "VFLD",
  252.     "BLOCK",
  253.     "REGEX",
  254.     "LENGTH",
  255.     "LOG",
  256.     "EXP",
  257.     "SQRT",
  258.     "INT",
  259.     "DO",
  260.     "POW",
  261.     "SUB",
  262.     "GSUB",
  263.     "MATCH",
  264.     "USERFUN",
  265.     "USERDEF",
  266.     "CLOSE",
  267.     "ATAN2",
  268.     "SIN",
  269.     "COS",
  270.     "RAND",
  271.     "SRAND",
  272.     "DELETE",
  273.     "SYSTEM",
  274.     "COND",
  275.     "RETURN",
  276.     "DEFINED",
  277.     "STAR",
  278.     "89"
  279. };
  280. #else
  281. extern char *opname[];
  282. #endif
  283.  
  284. EXT int mop INIT(1);
  285.  
  286. union u_ops {
  287.     int ival;
  288.     char *cval;
  289. };
  290. #if defined(iAPX286) || defined(M_I286) || defined(I80286)     /* 80286 hack */
  291. #define OPSMAX (64000/sizeof(union u_ops))    /* approx. max segment size */
  292. #else
  293. #define OPSMAX 50000
  294. #endif                             /* 80286 hack */
  295. EXT union u_ops ops[OPSMAX];
  296.  
  297. typedef struct string STR;
  298. typedef struct htbl HASH;
  299.  
  300. #include "str.h"
  301. #include "hash.h"
  302.  
  303.  
  304. /* A string is TRUE if not "" or "0". */
  305. #define True(val) (tmps = (val), (*tmps && !(*tmps == '0' && !tmps[1])))
  306. EXT char *Yes INIT("1");
  307. EXT char *No INIT("");
  308.  
  309. #define str_true(str) (Str = (str), (Str->str_pok ? True(Str->str_ptr) : (Str->str_nok ? (Str->str_nval != 0.0) : 0 )))
  310.  
  311. #define str_peek(str) (Str = (str), (Str->str_pok ? Str->str_ptr : (Str->str_nok ? (sprintf(buf,"num(%g)",Str->str_nval),buf) : "" )))
  312. #define str_get(str) (Str = (str), (Str->str_pok ? Str->str_ptr : str_2ptr(Str)))
  313. #define str_gnum(str) (Str = (str), (Str->str_nok ? Str->str_nval : str_2num(Str)))
  314. EXT STR *Str;
  315.  
  316. #define GROWSTR(pp,lp,len) if (*(lp) < (len)) growstr(pp,lp,len)
  317.  
  318. /* Prototypes for things in a2p.c */
  319. int aryrefarg _(( int arg ));
  320. int bl _(( int arg, int maybe ));
  321. void dump _(( int branch ));
  322. int fixfargs _(( int name, int arg, int prevargs ));
  323. int fixrargs _(( char *name, int arg, int prevargs ));
  324. void fixup _(( STR *str ));
  325. int numary _(( int arg ));
  326. int oper0 _(( int type ));
  327. int oper1 _(( int type, int arg1 ));
  328. int oper2 _(( int type, int arg1, int arg2 ));
  329. int oper3 _(( int type, int arg1, int arg2, int arg3 ));
  330. int oper4 _(( int type, int arg1, int arg2, int arg3, int arg4 ));
  331. int oper5 _(( int type, int arg1, int arg2, int arg3, int arg4, int arg5 ));
  332. void putlines _(( STR *str ));
  333. void putone _(( void ));
  334. int rememberargs _(( int arg ));
  335. char * scannum _(( char *s ));
  336. char * scanpat _(( char *s ));
  337. int string _(( char *ptr, int len ));
  338. void yyerror _(( char *s ));
  339. int yylex _(( void ));
  340.  
  341. EXT int line INIT(0);
  342.  
  343. EXT FILE *rsfp;
  344. EXT char buf[2048];
  345. EXT char *bufptr INIT(buf);
  346.  
  347. EXT STR *linestr INIT(Nullstr);
  348.  
  349. EXT char tokenbuf[2048];
  350. EXT int expectterm INIT(TRUE);
  351.  
  352. #ifdef DEBUGGING
  353. EXT int debug INIT(0);
  354. EXT int dlevel INIT(0);
  355. #define YYDEBUG 1
  356. extern int yydebug;
  357. #endif
  358.  
  359. EXT STR *freestrroot INIT(Nullstr);
  360.  
  361. EXT STR str_no;
  362. EXT STR str_yes;
  363.  
  364. EXT bool do_split INIT(FALSE);
  365. EXT bool split_to_array INIT(FALSE);
  366. EXT bool set_array_base INIT(FALSE);
  367. EXT bool saw_RS INIT(FALSE);
  368. EXT bool saw_OFS INIT(FALSE);
  369. EXT bool saw_ORS INIT(FALSE);
  370. EXT bool saw_line_op INIT(FALSE);
  371. EXT bool in_begin INIT(TRUE);
  372. EXT bool do_opens INIT(FALSE);
  373. EXT bool do_fancy_opens INIT(FALSE);
  374. EXT bool lval_field INIT(FALSE);
  375. EXT bool do_chop INIT(FALSE);
  376. EXT bool need_entire INIT(FALSE);
  377. EXT bool absmaxfld INIT(FALSE);
  378. EXT bool saw_altinput INIT(FALSE);
  379.  
  380. EXT bool nomemok INIT(FALSE);
  381.  
  382. EXT char const_FS INIT(0);
  383. EXT char *namelist INIT(Nullch);
  384. EXT char fswitch INIT(0);
  385.  
  386. EXT int saw_FS INIT(0);
  387. EXT int maxfld INIT(0);
  388. EXT int arymax INIT(0);
  389. EXT char *nameary[100];
  390.  
  391. EXT STR *opens;
  392.  
  393. EXT HASH *symtab;
  394. EXT HASH *curarghash;
  395.  
  396. #define P_MIN        0
  397. #define P_LISTOP    5
  398. #define P_COMMA        10
  399. #define P_ASSIGN    15
  400. #define P_COND        20
  401. #define P_DOTDOT    25
  402. #define P_OROR        30
  403. #define P_ANDAND    35
  404. #define P_OR        40
  405. #define P_AND        45
  406. #define P_EQ        50
  407. #define P_REL        55
  408. #define P_UNI        60
  409. #define P_FILETEST    65
  410. #define P_SHIFT        70
  411. #define P_ADD        75
  412. #define P_MUL        80
  413. #define P_MATCH        85
  414. #define P_UNARY        90
  415. #define P_POW        95
  416. #define P_AUTO        100
  417. #define P_MAX        999
  418.  
  419. EXT int an;
  420.