trans.h.1
上传用户:upcnvip
上传日期:2007-01-06
资源大小:474k
文件大小:47k
源码类别:

编译器/解释器

开发平台:

C/C++

  1. /* "p2c", a Pascal to C translator, version 1.14.
  2.    Copyright (C) 1989 David Gillespie.
  3.    Author's address: daveg@csvax.caltech.edu; 256-80 Caltech/Pasadena CA 91125.
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation (any version).
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; see the file COPYING.  If not, write to
  13. the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
  14. #ifdef __STDC__
  15. # define PP(x)  x             /* use true prototypes */
  16. # define PV()   (void)
  17. # define Anyptr void
  18. # define __CAT__(a,b)a##b
  19. #else
  20. # define PP(x)  ()            /* use old-style declarations */
  21. # define PV()   ()
  22. # define Anyptr char
  23. # define __ID__(a)a
  24. # define __CAT__(a,b)__ID__(a)b
  25. #endif
  26. #define Static                /* For debugging purposes */
  27. #include <stdio.h>
  28. /* If the following heuristic fails, compile -DBSD=0 for non-BSD systems,
  29.    or -DBSD=1 for BSD systems. */
  30. #ifdef M_XENIX
  31. # define BSD 0
  32. #endif
  33. #ifdef FILE       /* a #define in BSD, a typedef in SYSV (hp-ux, at least) */
  34. # ifndef BSD
  35. #  define BSD 1
  36. # endif
  37. #endif
  38. #ifdef BSD
  39. # if !BSD
  40. #  undef BSD
  41. # endif
  42. #endif
  43. #ifdef __STDC__
  44. # include <stddef.h>
  45. # include <stdlib.h>
  46. # include <limits.h>
  47. #else
  48. # ifndef BSD
  49. #  include <malloc.h>
  50. #  include <memory.h>
  51. #  include <values.h>
  52. # endif
  53. # define EXIT_SUCCESS 0
  54. # define EXIT_FAILURE 1
  55. # define CHAR_BIT 8
  56. # define LONG_MAX (((unsigned long)~0L) >> 1)
  57. # define LONG_MIN (- LONG_MAX - 1)
  58. #endif
  59. #ifdef BSD
  60. # include <strings.h>
  61. # define memcpy(a,b,n) bcopy(b,a,n)
  62. # define memcmp(a,b,n) bcmp(a,b,n)
  63. char *malloc(), *realloc();
  64. #else
  65. # include <string.h>
  66. #endif
  67. #include <ctype.h>
  68. #ifdef __GNUC__      /* Fast, in-line version of strcmp */
  69. # define strcmp(a,b) ({ char *_aa = (a), *_bb = (b); int _diff;  
  70. for (;;) {    
  71.     if (!*_aa && !*_bb) { _diff = 0; break; }   
  72.                             if (*_aa++ != *_bb++)    
  73. { _diff = _aa[-1] - _bb[-1]; break; }   
  74. } _diff; })
  75. #endif
  76. #if defined(HASDUMPS) && defined(define_globals)
  77. # define DEFDUMPS
  78. #endif
  79. /* Constants */
  80. #undef MININT      /* we want the Pascal definitions, not the local C definitions */
  81. #undef MAXINT
  82. #define MININT     0x80000000
  83. #define MAXINT     0x7fffffff
  84. #ifndef EXIT_SUCCESS
  85. # define EXIT_SUCCESS  0
  86. # define EXIT_FAILURE  1
  87. #endif
  88. #ifndef P2C_HOME
  89. # ifdef citPWS
  90. #  define    P2C_HOME        "/lib/p2c"
  91. # else
  92. #  define    P2C_HOME        "/usr/local/p2c"     /* sounds reasonable... */
  93. # endif
  94. #endif
  95. #ifdef define_globals
  96. char *p2c_home = P2C_HOME;
  97. #else
  98. extern char *p2c_home;
  99. #endif
  100. #define P2C_VERSION  "1.14"
  101. /* Types */
  102. #ifdef __STDC__
  103. typedef void *anyptr;
  104. #else
  105. typedef char *anyptr;
  106. #endif
  107. typedef unsigned char uchar;
  108. /* Ought to rearrange token assignments at the next full re-compile */
  109. typedef enum E_token {
  110.     TOK_NONE,
  111.     /* reserved words */
  112.     TOK_AND, TOK_ARRAY, TOK_BEGIN, TOK_CASE, TOK_CONST,
  113.     TOK_DIV, TOK_DO, TOK_DOWNTO, TOK_ELSE, TOK_END,
  114.     TOK_FILE, TOK_FOR, TOK_FUNCTION, TOK_GOTO, TOK_IF,
  115.     TOK_IN, TOK_LABEL, TOK_MOD, TOK_NIL, TOK_NOT,
  116.     TOK_OF, TOK_OR, TOK_PACKED, TOK_PROCEDURE, TOK_PROGRAM,
  117.     TOK_RECORD, TOK_REPEAT, TOK_SET, TOK_THEN, TOK_TO,
  118.     TOK_TYPE, TOK_UNTIL, TOK_VAR, TOK_WHILE, TOK_WITH,
  119.     /* symbols */
  120.     TOK_DOLLAR, TOK_STRLIT, TOK_LPAR, TOK_RPAR, TOK_STAR,
  121.     TOK_PLUS, TOK_COMMA, TOK_MINUS, TOK_DOT, TOK_DOTS,
  122.     TOK_SLASH, TOK_INTLIT, TOK_REALLIT, TOK_COLON, TOK_ASSIGN,
  123.     TOK_SEMI, TOK_NE, TOK_LT, TOK_GT, TOK_LE, TOK_GE,
  124.     TOK_EQ, TOK_LBR, TOK_RBR, TOK_HAT,
  125.     TOK_INCLUDE, TOK_ENDIF,
  126.     TOK_IDENT, TOK_MININT, TOK_EOF,
  127.     /* C symbols */
  128.     TOK_ARROW, TOK_AMP, TOK_VBAR, TOK_BANG,
  129.     TOK_TWIDDLE, TOK_PERC, TOK_QM,
  130.     TOK_LTLT, TOK_GTGT, TOK_EQEQ, TOK_BANGEQ,
  131.     TOK_PLPL, TOK_MIMI, TOK_ANDAND, TOK_OROR,
  132.     TOK_LBRACE, TOK_RBRACE, TOK_CHARLIT,
  133.     /* HP Pascal tokens */
  134.     TOK_ANYVAR, TOK_EXPORT, TOK_IMPLEMENT, TOK_IMPORT, TOK_MODULE,
  135.     TOK_OTHERWISE, TOK_RECOVER, TOK_TRY,
  136.     /* Turbo Pascal tokens */
  137.     TOK_SHL, TOK_SHR, TOK_XOR, TOK_INLINE, TOK_ABSOLUTE,
  138.     TOK_INTERRUPT, TOK_ADDR, TOK_HEXLIT,
  139.     /* Oregon Software Pascal tokens */
  140.     TOK_ORIGIN, TOK_INTFONLY,
  141.     /* VAX Pascal tokens */
  142.     TOK_REM, TOK_VALUE, TOK_VARYING, TOK_OCTLIT, TOK_COLONCOLON,
  143.     TOK_STARSTAR,
  144.     /* Modula-2 tokens */
  145.     TOK_BY, TOK_DEFINITION, TOK_ELSIF, TOK_FROM, TOK_LOOP,
  146.     TOK_POINTER, TOK_QUALIFIED, TOK_RETURN,
  147.     /* UCSD Pascal tokens */
  148.     TOK_SEGMENT,
  149.     TOK_LAST
  150. } Token;
  151. #ifdef define_globals
  152. char *toknames[(int)TOK_LAST] = { "",
  153.     "AND", "ARRAY", "BEGIN", "CASE", "CONST",
  154.     "DIV", "DO", "DOWNTO", "ELSE", "END",
  155.     "FILE", "FOR", "FUNCTION", "GOTO", "IF",
  156.     "IN", "LABEL", "MOD", "NIL", "NOT",
  157.     "OF", "OR", "PACKED", "PROCEDURE", "PROGRAM",
  158.     "RECORD", "REPEAT", "SET", "THEN", "TO",
  159.     "TYPE", "UNTIL", "VAR", "WHILE", "WITH",
  160.     "a '$'", "a string literal", "a '('", "a ')'", "a '*'",
  161.     "a '+'", "a comma", "a '-'", "a '.'", "'..'",
  162.     "a '/'", "an integer", "a real number", "a colon", "a ':='",
  163.     "a semicolon", "a '<>'", "a '<'", "a '>'", "a '<='", "a '>='",
  164.     "an '='", "a '['", "a ']'", "a '^'",
  165.     "an "include" file", "$end$",
  166.     "an identifier", "an integer", "end of file",
  167.     "an '->'", "an '&'", "a '|'", "a '!'", 
  168.     "a '~'", "a '%'", "a '?'",
  169.     "a '<<'", "a '>>'", "a '=='", "a '!='",
  170.     "a '++'", "a '--'", "a '&&'", "a '||'",
  171.     "a '{'", "a '}'", "a character literal",
  172.     "ANYVAR", "EXPORT", "IMPLEMENT", "IMPORT", "MODULE",
  173.     "OTHERWISE", "RECOVER", "TRY",
  174.     "SHL", "SHR", "XOR", "INLINE", "ABSOLUTE",
  175.     "INTERRUPT", "an '@'", "a hex integer",
  176.     "ORIGIN", "INTF-ONLY",
  177.     "REM", "VALUE", "VARYING", "an octal integer", "a '::'",
  178.     "a '**'",
  179.     "BY", "DEFINITION", "ELSIF", "FROM", "LOOP",
  180.     "POINTER", "QUALIFIED", "RETURN",
  181.     "SEGMENT"
  182. } ;
  183. #else
  184. extern char *toknames[];
  185. #endif /*define_globals*/
  186. typedef struct S_strlist {
  187.     struct S_strlist *next;
  188.     long value;
  189.     char s[1];
  190. } Strlist;
  191. typedef struct S_value {
  192.     struct S_type *type;
  193.     long i;
  194.     char *s;
  195. } Value;
  196. /* "Symbol" notes:
  197.  *
  198.  * The symbol table is used for several things.  Mainly it records all
  199.  * identifiers in the Pascal program (normally converted to upper case).
  200.  * Also used for recording certain properties about C and Pascal names.
  201.  *
  202.  * The symbol table is a hash table of binary trees.
  203.  */
  204. #define AVOIDNAME  0x1         /* Avoid this name in C code */
  205. #define WARNNAME   0x2        /* Warn if using this name in C code */
  206. #define AVOIDGLOB  0x4        /* Avoid C name except private to module */
  207. #define NOSIDEEFF  0x8        /* Function by this name has no side effects */
  208. #define STRUCTF    0x10        /* Function by this name is a StructFunction */
  209. #define STRLAPF    0x20        /* Function by this name is a StrlapFunction */
  210. #define LEAVEALONE 0x40        /* Do not use custom handler for function */
  211. #define DETERMF    0x80        /* Function by this name is Deterministic */
  212. #define FMACREC    0x100       /* Used by FieldMacro stuff */
  213. #define AVOIDFIELD 0x200       /* Avoid this name as a struct field name */
  214. #define NEEDSTATIC 0x400       /* This name must be declared static */
  215. #define KWPOSS     0x800       /* This word may be a keyword */
  216. #define FUNCBREAK  0x7000      /* Line breaking flags (see sys.p2crc) */
  217. # define FALLBREAK  0x1000     /*  Break at all commas if at any */
  218. # define FSPCARG1   0x2000     /*  First argument is special */
  219. # define FSPCARG2   0x3000     /*  First two arguments are special */
  220. # define FSPCARG3   0x4000     /*  First three arguments are special */
  221. #define WARNLIBR   0x8000      /* Warn for all uses of this library function */
  222. #define FWDPARAM   0x10000     /* Was a param name for forward-declared func */
  223. #define SSYNONYM   0x20000     /* Symbol is a synonym for another */
  224. typedef struct S_symbol {
  225.     struct S_symbol *left;     /* Left pointer in binary tree */
  226.     struct S_symbol *right;    /* Right pointer in binary tree */
  227.     struct S_meaning *mbase;   /* First normal meaning for this symbol */
  228.     struct S_meaning *fbase;   /* First record-field meaning for this symbol */
  229.     Strlist *symbolnames;      /* List of NameOf's for this name */
  230.     long flags;        /* (above) */
  231.     Token kwtok;        /* Token, if symbol is a keyword */
  232.     char name[1];              /* Pascal name (actually variable-sized) */
  233. } Symbol;
  234. /* "Meaning" notes:
  235.  *
  236.  * This represents one meaning of a symbol (see below).  Meanings are
  237.  * organized in a tree of contexts (i.e., scopes), and also in linked
  238.  * lists of meanings per symbol.  Fields described in the following are
  239.  * undefined for kinds where they are not listed.  Other fields are
  240.  * defined in all kinds of meanings.
  241.  *
  242.  * MK_MODULE:  Program, module, or unit.
  243.  *    mp->anyvarflag = 1 if main program, 0 if module.
  244.  *    mp->cbase => First meaning in module's context.
  245.  *
  246.  * MK_CONST:  Pascal CONST.
  247.  *    mp->type => Type of constant, same as mp->constdefn->type & mp->val.type.
  248.  *    mp->anyvarflag = 1 if FoldConstants was true when defined.
  249.  *    mp->constdefn => Expression for the value of the constant.
  250.  *    mp->val = Value of the const, if can be evaluated, else val.type is NULL.
  251.  *    mp->xnext => Next constant in enumeration, else NULL.
  252.  *    mp->isreturn = 1 if constant was declared as a macro (with #define).
  253.  *
  254.  * MK_TYPE:  Pascal type name.
  255.  *    mp->type => Type which name represents.
  256.  *
  257.  * MK_VAR:  Normal variable.
  258.  *    mp->type => Type of variable.
  259.  *    mp->constdefn => Initializer for variable, else NULL.
  260.  *    mp->varstructflag = 1 if variable is in parent function's varstruct.
  261.  *    mp->isforward = 1 if should be declared static.
  262.  *    mp->isfunction = 1 if should be declared extern.
  263.  *    mp->namedfile = 1 if this file variable has a shadow file-name variable.
  264.  *    mp->bufferedfile = 1 if this file variable has a shadow buffer variable.
  265.  *    mp->val.s => name format string if temporary var, else NULL.
  266.  *
  267.  * MK_VARREF:  Variable always referenced through a pointer.
  268.  *    mp->type => Type "pointer to T" where T is type of variable.
  269.  *    mp->constdefn => Initializer for the pointer, else NULL.
  270.  *    (Others same as for MK_VAR.)
  271.  *
  272.  * MK_VARMAC:  Variable which has a VarMacro.
  273.  *    mp->type => Type of variable.
  274.  *    mp->constdefn => Expression for VarMacro definition.
  275.  *    (Others same as for MK_VAR.)
  276.  *
  277.  * MK_SPVAR:  Special variable.
  278.  *    mp->handler => C function to parse and translate the special variable.
  279.  *
  280.  * MK_FIELD:  Record/struct field name.
  281.  *    mp->ctx, cbase = unused (unlike other meanings).
  282.  *    mp->cnext => Next field in record or variant.
  283.  *    mp->type => Type of field (base type if a bit-field).
  284.  *    mp->rectype => Type of containing record.
  285.  *    mp->constdefn => Expression for definition if FieldMacro, else NULL.
  286.  *    mp->val.i = Number of bits if bit-field, or 0 if normal field.
  287.  *    mp->val.type => True type of bit-field, else same as mp->type.
  288.  *    mp->isforward = 1 if tag field for following variant, else 0.
  289.  *    mp->namedfile = 1 if this file field has a shadow file-name field.
  290.  *    mp->bufferedfile = 1 if this file field has a shadow buffer field.
  291.  *
  292.  * MK_VARIANT:  Header for variant record case.
  293.  *    mp->ctx => First field in variant (unlike other meanings).
  294.  *    mp->cbase = unused (unlike other meanings).
  295.  *    mp->cnext => Next variant in record (or next sub-variant in variant).
  296.  *    mp->rectype => Type of containing record.
  297.  *    mp->val = Tag value of variant.
  298.  *
  299.  * MK_LABEL:  Statement label.
  300.  *    mp->val.i => Case number if used by non-local gotos, else -1.
  301.  *    mp->xnext => MK_VAR representing associated jmp_buf variable.
  302.  *    (All optional fields are unused.)
  303.  *
  304.  * MK_FUNCTION:  Procedure or function.
  305.  *    mp->type => TK_FUNCTION type.
  306.  *    mp->cbase => First meaning in procedure's context (when isfunction is 1,
  307.  *    this will always be the return-value meaning.)
  308.  *    mp->val.i => Body of the function (cast to Stmt *).
  309.  *    mp->constdefn => Expression for definition if FuncMacro, else NULL.
  310.  *    mp->handler => C function to adjust parse tree if predefined, else NULL.
  311.  *    mp->isfunction = 1 if function, 0 if procedure.
  312.  *    mp->isforward = 1 if function has been declared forward.
  313.  *    mp->varstructflag = 1 if function has a varstruct.
  314.  *    mp->needvarstruct = 1 if no varstruct yet but may need one.
  315.  *    mp->namedfile = 1 if function should be declared "inline".
  316.  *
  317.  * MK_SPECIAL:  Special, irregular built-in function.
  318.  *    mp->handler => C function to parse and translate the special function.
  319.  *    mp->constdefn => Expression for definition if FuncMacro, else NULL.
  320.  *    mp->isfunction = 1 if function, 0 if procedure.
  321.  *
  322.  * MK_PARAM:  Procedure or function parameter, or function return value.
  323.  *    mp->type => Type of parameter.
  324.  *    mp->isreturn = 1 if a function return value (not on parameter list).
  325.  *    mp->xnext => Next parameter of function.
  326.  *    mp->fakeparam = 1 if a fake parameter (e.g., conformant array size).
  327.  *    mp->othername => Name of true param if this one is a local copy.
  328.  *    mp->rectype => Type of true param if this one is a local copy.
  329.  *      If a normal copy param, will be "pointer to" mp->type.
  330.  *      If copied for varstruct reasons, will be same as mp->type.
  331.  *    mp->varstructflag = 1 if variable is in parent function's varstruct.
  332.  *
  333.  * MK_VARPARAM:  VAR parameter, or StructFunction return value.
  334.  *    mp->type => Type "pointer to T" where T is type of parameter.
  335.  *    mp->anyvarflag = 1 if no type checking is to be applied to parameter.
  336.  *    mp->isreturn = 1 if a StructFunction return value (will be first param).
  337.  *    (Others same as for MK_PARAM.)
  338.  *
  339.  * MK_VARPARAM with mp->type == tp_anyptr:  Turbo "typeless var" parameter.
  340.  *    mp->type = tp_anyptr.
  341.  *    mp->anyvarflag = 1.
  342.  *    (Others same as for MK_PARAM.)
  343.  *
  344.  * MK_VARPARAM with mp->type == tp_strptr:  HP Pascal "var s:string" parameter.
  345.  *    mp->type = tp_strptr.
  346.  *    mp->anyvarflag = 1 if a separate "strmax" parameter is passed.
  347.  *    (Others same as for MK_PARAM.)
  348.  *
  349.  * MK_SYNONYM:  Meaning which should be treated as identical to another.
  350.  *    mp->xnext => Actual meaning to be used.
  351.  *
  352.  */
  353. enum meaningkind {
  354.     MK_NONE, MK_SPECIAL,
  355.     MK_MODULE, MK_FUNCTION, MK_CONST, MK_VAR, MK_TYPE,
  356.     MK_FIELD, MK_LABEL, MK_VARIANT,
  357.     MK_PARAM, MK_VARPARAM, MK_VARREF, MK_VARMAC,
  358.     MK_SPVAR, MK_SYNONYM,
  359.     MK_LAST
  360. } ;
  361. #ifdef DEFDUMPS
  362. char *meaningkindnames[(int)MK_LAST] = {
  363.     "MK_NONE", "MK_SPECIAL",
  364.     "MK_MODULE", "MK_FUNCTION", "MK_CONST", "MK_VAR", "MK_TYPE",
  365.     "MK_FIELD", "MK_LABEL", "MK_VARIANT",
  366.     "MK_PARAM", "MK_VARPARAM", "MK_VARREF", "MK_VARMAC",
  367.     "MK_SPVAR", "MK_SYNONYM"
  368. } ;
  369. #endif /*DEFDUMPS*/
  370. typedef struct S_meaning {
  371.     struct S_meaning *snext;   /* Next meaning for this symbol */
  372.     struct S_meaning *cnext;   /* Next meaning in this meaning's context */
  373.     struct S_meaning *cbase;   /* First meaning in this context */
  374.     struct S_meaning *ctx;     /* Context of this meaning */
  375.     struct S_meaning *xnext;   /* (above) */
  376.     struct S_symbol *sym;      /* Symbol of which this is a meaning */
  377.     struct S_type *type;       /* (above) */
  378.     struct S_type *rectype;    /* (above) */
  379.     struct S_expr *constdefn;  /* (above) */
  380.     enum meaningkind kind;     /* Kind of meaning */
  381.     unsigned needvarstruct:1,  /* (above) */
  382.              varstructflag:1,  /* (above) */
  383.              wasdeclared:1,    /* Declaration has been written for meaning */
  384.              istemporary:1,    /* Is a temporary variable */
  385.              isforward:1,      /* (above) */
  386.              isfunction:1,     /* (above) */
  387.              anyvarflag:1,     /* (above) */
  388.              isactive:1,       /* Meaning is currently in scope */
  389.              exported:1,       /* Meaning is visible outside this module */
  390.              warnifused:1,     /* WarnNames was 1 when meaning was declared */
  391.              dumped:1,        /* Has been dumped (for debugging) */
  392.              isreturn:1,       /* (above) */
  393.              fakeparam:1,      /* (above) */
  394.              namedfile:1,      /* (above) */
  395.              bufferedfile:1,   /* (above) */
  396.              volatilequal:1,   /* Object has C "volatile" qualifier */
  397.              constqual:1,      /* Object has C "const" qualifier */
  398.              dummy17:1, dummy18:1, dummy19:1, 
  399.      dummy20:1, dummy21:1, dummy22:1, dummy23:1, dummy24:1, dummy25:1, 
  400.      dummy26:1, dummy27:1, dummy28:1, dummy29:1, dummy30:1, dummy31:1;
  401.     Value val;        /* (above) */
  402.     int refcount;        /* Number of references to meaning in program */
  403.     char *name;        /* Print name (i.e., C name) of the meaning */
  404.     char *othername;        /* (above) */
  405.     struct S_expr *(*handler)();   /* Custom translator for procedure */
  406.     Strlist *comments;        /* Comments associated with meaning */
  407. } Meaning;
  408. /* "Type" notes:
  409.  *
  410.  * This struct represents a data type.  Types are stored in a strange
  411.  * cross between Pascal and C semantics.  (This usually works out okay.)
  412.  *
  413.  * TK_INTEGER:  Base integer type.
  414.  *    The following types are TK_INTEGER:
  415.  *        tp_integer, tp_unsigned, tp_int, tp_uint, tp_sint.
  416.  *    All other integer types are represented by subranges.
  417.  *    tp->smin => Minimum value for integer.
  418.  *    tp->smax => Maximum value for integer.
  419.  *
  420.  * TK_CHAR:  Base character type.
  421.  *    The following types are TK_CHAR:  tp_char, tp_schar, tp_uchar.
  422.  *    All other character types are represented by subranges.
  423.  *    tp->smin => Minimum value for character.
  424.  *    tp->smax => Maximum value for character.
  425.  *
  426.  * TK_BOOLEAN:  Boolean type.
  427.  *    The only TK_BOOLEAN type is tp_boolean.
  428.  *    tp->smin => "False" expression.
  429.  *    tp->smax => "True" expression.
  430.  *
  431.  * TK_REAL:  Real types.
  432.  *    The only TK_REAL types are tp_real, tp_longreal, and/or the SINGLE type.
  433.  *
  434.  * TK_VOID:  C "void" type.
  435.  *    The only TK_VOID type is tp_void.
  436.  *
  437.  * TK_SUBR:  Subrange of ordinal type.
  438.  *    tp->basetype => a TK_INTEGER, TK_CHAR, TK_BOOLEAN, or TK_ENUM type.
  439.  *    tp->smin => Minimum ordinal value for subrange.
  440.  *    tp->smax => Maximum ordinal value for subrange.
  441.  *
  442.  * TK_ENUM:  Enumerated type.
  443.  *    tp->fbase => First enumeration constant.
  444.  *    tp->smin => Minimum value (zero).
  445.  *    tp->smax => Maximum value (number of choices minus 1).
  446.  *
  447.  * TK_POINTER:  Pointer type.
  448.  *    tp->basetype => Base type of pointer.
  449.  *    Only one pointer type is ever generated for a given other type;
  450.  *    each tp->pointertype points back to that type if it has been generated.
  451.  *
  452.  * TK_STRING:  Pascal string or VARYING OF CHAR type.
  453.  *    tp->basetype => tp_char.
  454.  *    tp->indextype => TK_SUBR from 0 to maximum string length.
  455.  *    tp->structdefd = 1 if type is for a conformant VARYING OF CHAR parameter.
  456.  *
  457.  * TK_RECORD:  Pascal record/C struct type.
  458.  *    tp->fbase => First field in record.
  459.  *    tp->structdefd = 1 if struct type has been declared in output.
  460.  *
  461.  * TK_ARRAY with smax == NULL:  Normal array type.
  462.  *    tp->basetype => Element type of array.
  463.  *    tp->indextype => Index type (usually a TK_SUBR).
  464.  *    tp->smin => Integer constant if SkipIndices was used, else NULL.
  465.  *    tp->smax = NULL.
  466.  *    tp->structdefd = 1 if type is for a conformant array parameter.
  467.  *
  468.  * TK_ARRAY with smax != NULL:  Large packed array type.
  469.  *    tp->basetype => Element type of C array (tp_ubyte/tp_sbyte/tp_sshort).
  470.  *    tp->indextype => Index type (usually a TK_SUBR).
  471.  *    tp->smin => Integer constant is SkipIndices was used, else NULL.
  472.  *    tp->smax => EK_TYPENAME for element type of Pascal array.
  473.  *    tp->escale = log-base-two of number of bits per packed element, else 0.
  474.  *    tp->issigned = 1 if packed array elements are signed, 0 if unsigned.
  475.  *    tp->structdefd = 1 if type is for a conformant array parameter.
  476.  *
  477.  * TK_SMALLARRAY:  Packed array fitting within a single integer.
  478.  *    (Same as for packed TK_ARRAY.)
  479.  *
  480.  * TK_SET:  Normal set type.
  481.  *    tp->basetype => tp_integer.
  482.  *    tp->indextype => Element type of the set.
  483.  *
  484.  * TK_SMALLSET:  Set fitting within a single integer.
  485.  *    (Same as for TK_SET.)
  486.  *
  487.  * TK_FILE:  File type (corresponds to C "FILE" type).
  488.  *    tp->basetype => Type of file elements, or tp_abyte if UCSD untyped file.
  489.  *    A Pascal "file" variable is represented as a TK_POINTER to a TK_FILE.
  490.  *
  491.  * TK_FUNCTION:  Procedure or procedure-pointer type.
  492.  *    tp->basetype => Return type of function, or tp_void if procedure.
  493.  *    tp->issigned = 1 if type has a generic static link.
  494.  *    tp->fbase => First argument (or StructFunction return buffer pointer).
  495.  *
  496.  * TK_PROCPTR:  Procedure pointer with static link.
  497.  *    tp->basetype => TK_FUNCTION type.
  498.  *    tp->fbase => Internal Meaning struct associated with basetype.
  499.  *    tp->escale = Value of StaticLinks when type was declared.
  500.  *
  501.  * TK_CPROCPTR:  Procedure pointer without static link.
  502.  *    tp->basetype => TK_FUNCTION type.
  503.  *    tp->fbase => Internal Meaning struct associated with basetype.
  504.  *    tp->escale = Value of StaticLinks = 0.
  505.  *
  506.  * TK_SPECIAL:  Special strange data type.
  507.  *    Only TK_SPECIAL type at present is tp_jmp_buf.
  508.  *
  509.  */
  510. enum typekind {
  511.     TK_NONE,
  512.     TK_INTEGER, TK_CHAR, TK_BOOLEAN, TK_REAL, TK_VOID,
  513.     TK_SUBR, TK_ENUM, TK_POINTER, TK_STRING,
  514.     TK_RECORD, TK_ARRAY, TK_SET, TK_FILE, TK_FUNCTION,
  515.     TK_PROCPTR, TK_SMALLSET, TK_SMALLARRAY, TK_CPROCPTR,
  516.     TK_SPECIAL,
  517.     TK_LAST
  518. } ;
  519. #ifdef DEFDUMPS
  520. char *typekindnames[(int)TK_LAST] = {
  521.     "TK_NONE",
  522.     "TK_INTEGER", "TK_CHAR", "TK_BOOLEAN", "TK_REAL", "TK_VOID",
  523.     "TK_SUBR", "TK_ENUM", "TK_POINTER", "TK_STRING",
  524.     "TK_RECORD", "TK_ARRAY", "TK_SET", "TK_FILE", "TK_FUNCTION",
  525.     "TK_PROCPTR", "TK_SMALLSET", "TK_SMALLARRAY", "TK_CPROCPTR",
  526.     "TK_SPECIAL"
  527. } ;
  528. #endif /*DEFDUMPS*/
  529. typedef struct S_type {
  530.     enum typekind kind;        /* Kind of type */
  531.     struct S_type *basetype;   /* (above) */
  532.     struct S_type *indextype;  /* (above) */
  533.     struct S_type *pointertype; /* Pointer to this type */
  534.     struct S_meaning *meaning; /* Name of this type, if any */
  535.     struct S_meaning *fbase;   /* (above) */
  536.     struct S_expr *smin;       /* (above) */
  537.     struct S_expr *smax;       /* (above) */
  538.     unsigned issigned:1,       /* (above) */
  539.              dumped:1,         /* Has been dumped (for debugging) */
  540.              structdefd:1;     /* (above) */
  541.     short escale;              /* (above) */
  542. } Type;
  543. /* "Expr" notes:
  544.  *
  545.  * Expression trees generally reflect C notation and semantics.  For example,
  546.  * EK_ASSIGN is not generated for string arguments; these would get an
  547.  * EK_BICALL to strcpy instead.
  548.  *
  549.  * The data type of each expression node is stored in its "val.type" field.
  550.  * The rest of the "val" field is used only when shown below.
  551.  * The "nargs" field always contains the number of arguments; the "args"
  552.  * array is allocated to that size and will contain non-NULL Expr pointers.
  553.  *
  554.  * EK_EQ, EK_NE, EK_LT, EK_GT, EK_LE, EK_GE:  Relational operators.
  555.  *    ep->nargs = 2.
  556.  *
  557.  * EK_PLUS:  Addition.
  558.  *    ep->nargs >= 2.
  559.  *
  560.  * EK_NEG:  Negation.
  561.  *    ep->nargs = 1.
  562.  *
  563.  * EK_TIMES:  Multiplication.
  564.  *    ep->nargs >= 2.
  565.  *
  566.  * EK_DIVIDE:  Real division.
  567.  *    ep->nargs = 2.
  568.  *
  569.  * EK_DIV:  Integer division.
  570.  *    ep->nargs = 2.
  571.  *
  572.  * EK_MOD:  Integer modulo (C "%" operator).
  573.  *    ep->nargs = 2.
  574.  *
  575.  * EK_OR, EK_AND:  Logical operators (C "&&" and "||").
  576.  *    ep->nargs = 2.
  577.  *
  578.  * EK_NOT:  Logical NOT (C "!" operator).
  579.  *    ep->nargs = 1.
  580.  *
  581.  * EK_BAND, EK_BOR, EK_BXOR:  Bitwise operators (C "&", "|", "^").
  582.  *    ep->nargs = 2.
  583.  *
  584.  * EK_BNOT:  Bitwise NOT (C "~" operator).
  585.  *    ep->nargs = 1.
  586.  *
  587.  * EK_LSH, EK_RSH:  Shift operators.
  588.  *    ep->nargs = 2.
  589.  *
  590.  * EK_HAT:  Pointer dereference.
  591.  *    ep->nargs = 1.
  592.  *
  593.  * EK_INDEX:  Array indexing.
  594.  *    ep->nargs = 2.
  595.  *
  596.  * EK_CAST:  "Soft" type cast, change data type retaining value.
  597.  *    ep->type => New data type.
  598.  *    ep->nargs = 1.
  599.  *
  600.  * EK_ACTCAST:  "Active" type cast, performs a computation as result of cast.
  601.  *    ep->type => New data type.
  602.  *    ep->nargs = 1.
  603.  *
  604.  * EK_LITCAST:  Literal type cast.
  605.  *    ep->nargs = 2.
  606.  *    ep->args[0] => EK_TYPENAME expression for name of new data type.
  607.  *    ep->args[1] => Argument of cast.
  608.  *
  609.  * EK_DOT:  Struct field extraction.
  610.  *    ep->nargs = 1.  (Only one of the following will be nonzero:)
  611.  *    ep->val.i => MK_FIELD being extracted (cast to Meaning *), else 0.
  612.  *    ep->val.s => Literal name of field being extracted, else NULL.
  613.  *
  614.  * EK_COND:  C conditional expression.
  615.  *    ep->nargs = 3.
  616.  *    ep->args[0] => Condition expression.
  617.  *    ep->args[1] => "Then" expression.
  618.  *    ep->args[2] => "Else" expression.
  619.  *
  620.  * EK_ADDR:  Address-of operator.
  621.  *    ep->nargs = 1.
  622.  *
  623.  * EK_SIZEOF:  Size-of operator.
  624.  *    ep->nargs = 1.
  625.  *    ep->args[0] => Argument expression, may be EK_TYPENAME.
  626.  *
  627.  * EK_CONST:  Literal constant.
  628.  *    ep->nargs = 0 or 1.
  629.  *    ep->val = Value of constant.
  630.  *    ep->args[0] => EK_NAME of printf format string for constant, if any.
  631.  *
  632.  * EK_LONGCONST:  Literal constant, type "long int".
  633.  *    (Same as for EK_CONST.)
  634.  *
  635.  * EK_VAR:  Variable name.
  636.  *    ep->nargs = 0.
  637.  *    ep->val.i => Variable being referenced (cast to Meaning *).
  638.  *
  639.  * EK_ASSIGN:  Assignment operator.
  640.  *    ep->nargs = 2.
  641.  *    ep->args[0] => Destination l-value expression.
  642.  *    ep->args[1] => Source expression.
  643.  *
  644.  * EK_POSTINC, EK_POSTDEC:  Post-increment/post-decrement operators.
  645.  *    ep->nargs = 1.
  646.  *
  647.  * EK_MACARG:  Placeholder for argument in expression for FuncMacro, etc.
  648.  *    ep->nargs = 0.
  649.  *    ep->val.i = Code selecting which argument.
  650.  *
  651.  * EK_CHECKNIL:  Null-pointer check.
  652.  *    ep->nargs = 1.
  653.  *
  654.  * EK_BICALL:  Call to literal function name.
  655.  *    ep->val.s => Name of function.
  656.  *
  657.  * EK_STRUCTCONST:  Structured constant.
  658.  *    ep->nargs = Number of elements in constant.
  659.  *    (Note:  constdefn points to an EK_CONST whose val.i points to this.)
  660.  *
  661.  * EK_STRUCTOF:  Repeated element in structured constant.
  662.  *    ep->nargs = 1.
  663.  *    ep->val.i = Number of repetitions.
  664.  *
  665.  * EK_COMMA:  C comma operator.
  666.  *    ep->nargs >= 2.
  667.  *
  668.  * EK_NAME:  Literal variable name.
  669.  *    ep->nargs = 0.
  670.  *    ep->val.s => Name of variable.
  671.  *
  672.  * EK_CTX:  Name of a context, with static links.
  673.  *    ep->nargs = 0.
  674.  *    ep->val.i => MK_FUNCTION or MK_MODULE to name (cast to Meaning *).
  675.  *
  676.  * EK_SPCALL:  Special function call.
  677.  *    ep->nargs = 1 + number of arguments to function.
  678.  *    ep->args[0] => Expression which is the function to call.
  679.  *
  680.  * EK_TYPENAME:  Type name.
  681.  *    ep->nargs = 0.
  682.  *    ep->val.type => Type whose name should be printed.
  683.  *
  684.  * EK_FUNCTION:  Normal function call.
  685.  *    ep->val.i => MK_FUNCTION being called (cast to Meaning *).
  686.  *
  687.  */
  688. enum exprkind {
  689.     EK_EQ, EK_NE, EK_LT, EK_GT, EK_LE, EK_GE,
  690.     EK_PLUS, EK_NEG, EK_TIMES, EK_DIVIDE,
  691.     EK_DIV, EK_MOD,
  692.     EK_OR, EK_AND, EK_NOT,
  693.     EK_BAND, EK_BOR, EK_BXOR, EK_BNOT, EK_LSH, EK_RSH,
  694.     EK_HAT, EK_INDEX, EK_CAST, EK_DOT, EK_COND,
  695.     EK_ADDR, EK_SIZEOF, EK_ACTCAST,
  696.     EK_CONST, EK_VAR, EK_FUNCTION,
  697.     EK_ASSIGN, EK_POSTINC, EK_POSTDEC, EK_CHECKNIL,
  698.     EK_MACARG, EK_BICALL, EK_STRUCTCONST, EK_STRUCTOF,
  699.     EK_COMMA, EK_LONGCONST, EK_NAME, EK_CTX, EK_SPCALL,
  700.     EK_LITCAST, EK_TYPENAME,
  701.     EK_LAST
  702. } ;
  703. #ifdef DEFDUMPS
  704. char *exprkindnames[(int)EK_LAST] = {
  705.     "EK_EQ", "EK_NE", "EK_LT", "EK_GT", "EK_LE", "EK_GE",
  706.     "EK_PLUS", "EK_NEG", "EK_TIMES", "EK_DIVIDE",
  707.     "EK_DIV", "EK_MOD",
  708.     "EK_OR", "EK_AND", "EK_NOT",
  709.     "EK_BAND", "EK_BOR", "EK_BXOR", "EK_BNOT", "EK_LSH", "EK_RSH",
  710.     "EK_HAT", "EK_INDEX", "EK_CAST", "EK_DOT", "EK_COND",
  711.     "EK_ADDR", "EK_SIZEOF", "EK_ACTCAST",
  712.     "EK_CONST", "EK_VAR", "EK_FUNCTION",
  713.     "EK_ASSIGN", "EK_POSTINC", "EK_POSTDEC", "EK_CHECKNIL",
  714.     "EK_MACARG", "EK_BICALL", "EK_STRUCTCONST", "EK_STRUCTOF",
  715.     "EK_COMMA", "EK_LONGCONST", "EK_NAME", "EK_CTX", "EK_SPCALL",
  716.     "EK_LITCAST", "EK_TYPENAME"
  717. } ;
  718. #endif /*DEFDUMPS*/
  719. typedef struct S_expr {
  720.     enum exprkind kind;
  721.     short nargs;
  722.     Value val;
  723.     struct S_expr *args[1];    /* (Actually, variable-sized) */
  724. } Expr;
  725. /* "Stmt" notes.
  726.  *
  727.  * Statements form linked lists along the "next" pointers.
  728.  * All other pointers are NULL and unused unless shown below.
  729.  *
  730.  * SK_ASSIGN:  Assignment or function call (C expression statement).
  731.  *    sp->exp1 => Expression to be evaluated.
  732.  *
  733.  * SK_RETURN:  C "return" statement.
  734.  *    sp->exp1 => Value to return, else NULL.
  735.  *
  736.  * SK_CASE:  C "switch" statement.
  737.  *    sp->exp1 => Switch selector expression.
  738.  *    sp->stm1 => List of SK_CASELABEL statements, followed by list of
  739.  *   statements that make up the "default:" clause.
  740.  *
  741.  * SK_CASELABEL:  C "case" label.
  742.  *    sp->exp1 => Case value.
  743.  *    sp->stm1 => List of SK_CASELABELs labelling the same clause, followed
  744.  *                by list of statements in that clause.
  745.  *
  746.  * SK_CASECHECK:  Case-value-range-error, occurs in "default:" clause.
  747.  *
  748.  * SK_IF:  C "if" statement.
  749.  *    sp->exp1 => Conditional expression.
  750.  *    sp->exp2 => Constant expression, "1" if this "if" should be else-if'd
  751.  *   on to parent "if".  NULL => follow ElseIf parameter.
  752.  *    sp->stm1 => "Then" clause.
  753.  *    sp->stm2 => "Else" clause.
  754.  *
  755.  * SK_FOR:  C "for" statement.
  756.  *    sp->exp1 => Initialization expression (may be NULL).
  757.  *    sp->exp2 => Conditional expression (may be NULL).
  758.  *    sp->exp3 => Iteration expression (may be NULL).
  759.  *    sp->stm1 => Loop body.
  760.  *
  761.  * SK_REPEAT:  C "do-while" statement.
  762.  *    sp->exp1 => Conditional expression (True = continue loop).
  763.  *    sp->stm1 => Loop body.
  764.  *
  765.  * SK_WHILE:  C "while" statement.
  766.  *    sp->exp1 => Conditional expression.
  767.  *    sp->stm1 => Loop body.
  768.  *
  769.  * SK_BREAK:  C "break" statement.
  770.  *
  771.  * SK_CONTINUE:  C "continue" statement.
  772.  *
  773.  * SK_TRY:  HP Pascal TRY-RECOVER statement.
  774.  *    sp->exp1->val.i = Global serial number of the TRY statement.
  775.  *    sp->exp2 = Non-NULL if must generate a label for RECOVER block.
  776.  *    sp->stm1 => TRY block.
  777.  *    sp->stm2 => RECOVER block.
  778.  *
  779.  * SK_GOTO:  C "goto" statement.
  780.  *    sp->exp1 => EK_NAME for the label number or name.
  781.  *
  782.  * SK_LABEL:  C statement label.
  783.  *    sp->exp1 => EK_NAME for the label number of name.
  784.  *
  785.  * SK_HEADER:  Function/module header.
  786.  *    sp->exp1 => EK_VAR pointing to MK_FUNCTION or MK_MODULE.
  787.  *    (This always comes first in a context's statement list.)
  788.  *
  789.  * SK_BODY:  Body of function/module.
  790.  *    sp->stm1 => SK_HEADER that begins the body.
  791.  *    (This exists only during fixblock.)
  792.  *
  793.  */
  794. enum stmtkind {
  795.     SK_ASSIGN, SK_RETURN,
  796.     SK_CASE, SK_CASELABEL, SK_IF,
  797.     SK_FOR, SK_REPEAT, SK_WHILE, SK_BREAK, SK_CONTINUE,
  798.     SK_TRY, SK_GOTO, SK_LABEL,
  799.     SK_HEADER, SK_CASECHECK, SK_BODY,
  800.     SK_LAST
  801. } ;
  802. #ifdef DEFDUMPS
  803. char *stmtkindnames[(int)SK_LAST] = {
  804.     "SK_ASSIGN", "SK_RETURN",
  805.     "SK_CASE", "SK_CASELABEL", "SK_IF",
  806.     "SK_FOR", "SK_REPEAT", "SK_WHILE", "SK_BREAK", "SK_CONTINUE",
  807.     "SK_TRY", "SK_GOTO", "SK_LABEL",
  808.     "SK_HEADER", "SK_CASECHECK", "SK_BODY"
  809. } ;
  810. #endif /*DEFDUMPS*/
  811. typedef struct S_stmt {
  812.     enum stmtkind kind;
  813.     struct S_stmt *next, *stm1, *stm2;
  814.     struct S_expr *exp1, *exp2, *exp3;
  815.     long serial;
  816. } Stmt;
  817. /* Flags for out_declarator(): */
  818. #define ODECL_CHARSTAR      0x1
  819. #define ODECL_FREEARRAY     0x2
  820. #define ODECL_FUNCTION      0x4
  821. #define ODECL_HEADER        0x8
  822. #define ODECL_FORWARD       0x10
  823. /* Flags for fixexpr(): */
  824. #define ENV_EXPR    0       /* return value needed */
  825. #define ENV_STMT    1       /* return value ignored */
  826. #define ENV_BOOL    2       /* boolean return value needed */
  827. /* Flags for defmacro(): */
  828. #define MAC_VAR     0       /* VarMacro */
  829. #define MAC_CONST   1       /* ConstMacro */
  830. #define MAC_FIELD   2       /* FieldMacro */
  831. #define MAC_FUNC    3       /* FuncMacro */
  832. #define FMACRECname  "<rec>"
  833. /* Kinds of comment lines: */
  834. #define CMT_SHIFT   24
  835. #define CMT_MASK    ((1L<<CMT_SHIFT)-1)
  836. #define CMT_KMASK   ((1<<(32-CMT_SHIFT))-1)
  837. #define CMT_DONE    0       /* comment that has already been printed */
  838. #define CMT_PRE     1       /* comment line preceding subject */
  839. #define CMT_POST    2       /* comment line following subject */
  840. #define CMT_TRAIL   4       /* comment at end of line of code */
  841. #define CMT_ONBEGIN 6       /* comment on "begin" of procedure */
  842. #define CMT_ONEND   7       /* comment on "end" of procedure */
  843. #define CMT_ONELSE  8       /* comment on "else" keyword */
  844. #define CMT_NOT     256     /* negation of above, for searches */
  845. #ifdef define_globals
  846. char *CMT_NAMES[] = { "DONE", "PRE", "POST", "3", "TRAIL", "5",
  847.                       "BEGIN", "END", "ELSE" };
  848. #else
  849. extern char *CMT_NAMES[];
  850. #endif
  851. #define getcommentkind(cmt)  (((cmt)->value >> CMT_SHIFT) & CMT_KMASK)
  852. /* Kinds of operator line-breaking: */
  853. #define BRK_LEFT     0x1
  854. #define BRK_RIGHT    0x2
  855. #define BRK_LPREF    0x4
  856. #define BRK_RPREF    0x8
  857. #define BRK_ALLNONE  0x10
  858. #define BRK_HANG     0x20
  859. /* Translation parameters: */
  860. #ifdef define_parameters
  861. # define extern
  862. #endif /* define_parameters */
  863. extern enum {
  864.     UNIX_ANY, UNIX_BSD, UNIX_SYSV
  865. } which_unix;
  866. extern enum {
  867.     LANG_HP, LANG_UCSD, LANG_TURBO, LANG_OREGON, LANG_VAX,
  868.     LANG_MODULA, LANG_MPW, LANG_BERK
  869. } which_lang;
  870. extern short debug, tokentrace, quietmode, cmtdebug, copysource;
  871. extern int showprogress, maxerrors;
  872. extern short hpux_lang, integer16, doublereals, pascalenumsize;
  873. extern short needsignedbyte, unsignedchar, importall;
  874. extern short nestedcomments, pascalsignif, pascalcasesens;
  875. extern short dollar_idents, ignorenonalpha, modula2;
  876. extern short ansiC, cplus, signedchars, signedfield, signedshift;
  877. extern short hassignedchar, voidstar, symcase, ucconsts, csignif;
  878. extern short copystructs, usevextern, implementationmodules;
  879. extern short useAnyptrMacros, usePPMacros;
  880. extern short sprintf_value;
  881. extern char codefnfmt[40], modulefnfmt[40], logfnfmt[40];
  882. extern char headerfnfmt[40], headerfnfmt2[40], includefnfmt[40];
  883. extern char constformat[40], moduleformat[40], functionformat[40];
  884. extern char varformat[40], fieldformat[40], typeformat[40];
  885. extern char enumformat[40], symbolformat[40];
  886. extern char p2c_h_name[40], exportsymbol[40], export_symbol[40];
  887. extern char externalias[40];
  888. extern char memcpyname[40], sprintfname[40];
  889. extern char roundname[40], divname[40], modname[40], remname[40];
  890. extern char strposname[40], strcicmpname[40];
  891. extern char strsubname[40], strdeletename[40], strinsertname[40];
  892. extern char strmovename[40], strpadname[40];
  893. extern char strltrimname[40], strrtrimname[40], strrptname[40];
  894. extern char absname[40], oddname[40], evenname[40], swapname[40];
  895. extern char mallocname[40], freename[40], freervaluename[40];
  896. extern char randrealname[40], randintname[40], randomizename[40];
  897. extern char skipspacename[40], readlnname[40], freopenname[40];
  898. extern char eofname[40], eolnname[40], fileposname[40], maxposname[40];
  899. extern char setunionname[40], setintname[40], setdiffname[40];
  900. extern char setinname[40], setaddname[40], setaddrangename[40];
  901. extern char setremname[40];
  902. extern char setequalname[40], subsetname[40], setxorname[40];
  903. extern char setcopyname[40], setexpandname[40], setpackname[40];
  904. extern char getbitsname[40], clrbitsname[40], putbitsname[40];
  905. extern char declbufname[40], declbufncname[40];
  906. extern char resetbufname[40], setupbufname[40];
  907. extern char getfbufname[40], chargetfbufname[40], arraygetfbufname[40];
  908. extern char putfbufname[40], charputfbufname[40], arrayputfbufname[40];
  909. extern char getname[40], chargetname[40], arraygetname[40];
  910. extern char putname[40], charputname[40], arrayputname[40];
  911. extern char storebitsname[40], signextname[40];
  912. extern char filenotfoundname[40], filenotopenname[40];
  913. extern char filewriteerrorname[40], badinputformatname[40], endoffilename[40];
  914. extern short strcpyleft;
  915. extern char language[40], target[40];
  916. extern int sizeof_char, sizeof_short, sizeof_integer, sizeof_pointer, 
  917.            sizeof_double, sizeof_float, sizeof_enum, sizeof_int, sizeof_long;
  918. extern short size_t_long;
  919. extern int setbits, defaultsetsize, seek_base, integerwidth, realwidth;
  920. extern short quoteincludes, expandincludes, collectnest;
  921. extern int phystabsize, intabsize, linewidth, maxlinewidth;
  922. extern int majorspace, minorspace, functionspace, minfuncspace;
  923. extern int casespacing, caselimit;
  924. extern int returnlimit, breaklimit, continuelimit;
  925. extern short nullstmtline, shortcircuit, shortopt, usecommas, elseif;
  926. extern short usereturns, usebreaks, infloopstyle, reusefieldnames;
  927. extern short bracesalways, braceline, bracecombine, braceelse, braceelseline;
  928. extern short newlinefunctions;
  929. extern short eatcomments, spitcomments, spitorphancomments;
  930. extern short commentafter, blankafter;
  931. extern int tabsize, blockindent, bodyindent, argindent;
  932. extern int switchindent, caseindent, labelindent;
  933. extern int openbraceindent, closebraceindent;
  934. extern int funcopenindent, funccloseindent;
  935. extern int structindent, structinitindent, extrainitindent;
  936. extern int constindent, commentindent, bracecommentindent, commentoverindent;
  937. extern int declcommentindent;
  938. extern int minspacing, minspacingthresh;
  939. extern int extraindent, bumpindent;
  940. extern double overwidepenalty, overwideextrapenalty;
  941. extern double commabreakpenalty, commabreakextrapenalty;
  942. extern double assignbreakpenalty, assignbreakextrapenalty;
  943. extern double specialargbreakpenalty;
  944. extern double opbreakpenalty, opbreakextrapenalty, exhyphenpenalty;
  945. extern double morebreakpenalty, morebreakextrapenalty;
  946. extern double parenbreakpenalty, parenbreakextrapenalty;
  947. extern double qmarkbreakpenalty, qmarkbreakextrapenalty;
  948. extern double wrongsidepenalty, earlybreakpenalty, extraindentpenalty;
  949. extern double bumpindentpenalty, nobumpindentpenalty;
  950. extern double indentamountpenalty, sameindentpenalty;
  951. extern double showbadlimit;
  952. extern long maxalts;
  953. extern short breakbeforearith, breakbeforerel, breakbeforelog;
  954. extern short breakbeforedot, breakbeforeassign;
  955. extern short for_allornone;
  956. extern short extraparens, breakparens, returnparens;
  957. extern short variablearrays, stararrays;
  958. extern short spaceexprs, implicitzero, starindex;
  959. extern int casetabs;
  960. extern short starfunctions, mixfields, alloczeronil, postincrement;
  961. extern short mixvars, mixtypes, mixinits, nullcharconst, castnull, addindex;
  962. extern short highcharints, highcharbits, hasstaticlinks;
  963. extern short mainlocals, storefilenames, addrstdfiles, readwriteopen;
  964. extern short charfiletext, messagestderr, literalfilesflag;
  965. extern short printfonly, mixwritelns, usegets, newlinespace, binarymode;
  966. extern char openmode[40], filenamefilter[40];
  967. extern short atan2flag, div_po2, mod_po2, assumebits, assumesigns;
  968. extern short fullstrwrite, fullstrread, whilefgets, buildreads, buildwrites;
  969. extern short foldconsts, foldstrconsts, useconsts, useundef;
  970. extern short elimdeadcode, offsetforloops, forevalorder;
  971. extern short smallsetconst, bigsetconst, lelerange, unsignedtrick;
  972. extern short useisalpha, useisspace, usestrncmp;
  973. extern short casecheck, arraycheck, rangecheck, nilcheck, malloccheck;
  974. extern short checkfileopen, checkfileisopen, checkfilewrite;
  975. extern short checkreadformat, checkfileeof, checkstdineof, checkfileseek;
  976. extern short squeezesubr, useenum, enumbyte, packing, packsigned, keepnulls;
  977. extern short compenums, formatstrings, alwayscopyvalues;
  978. extern short use_static, var_static, void_args, prototypes, fullprototyping;
  979. extern short procptrprototypes, promote_enums;
  980. extern short castargs, castlongargs, promoteargs;
  981. extern short varstrings, varfiles, copystructfuncs;
  982. extern long skipindices;
  983. extern short stringleaders;
  984. extern int stringceiling, stringdefault, stringtrunclimit, longstringsize;
  985. extern short warnnames, warnmacros;
  986. extern Strlist *importfrom, *importdirs, *includedirs, *includefrom;
  987. extern Strlist *librfiles, *bufferedfiles, *unbufferedfiles;
  988. extern Strlist *externwords, *cexternwords;
  989. extern Strlist *varmacros, *constmacros, *fieldmacros;
  990. extern Strlist *funcmacros, *funcmacroargs, *nameoflist;
  991. extern Strlist *specialmallocs, *specialfrees, *specialsizeofs;
  992. extern Strlist *initialcalls, *eatnotes, *literalfiles;
  993. extern char fixedcomment[40], permanentcomment[40], interfacecomment[40];
  994. extern char embedcomment[40],  skipcomment[40], noskipcomment[40];
  995. extern char signedcomment[40], unsignedcomment[40];
  996. extern char name_RETV[40], name_STRMAX[40], name_LINK[40];
  997. extern char name_COPYPAR[40], name_TEMP[40], name_DUMMY[40];
  998. extern char name_LOC[40], name_VARS[40], name_STRUCT[40];
  999. extern char name_FAKESTRUCT[40], name_AHIGH[40], name_ALOW[40];
  1000. extern char name_UNION[40], name_VARIANT[40], name_LABEL[40], name_LABVAR[40];
  1001. extern char name_WITH[40], name_FOR[40], name_ENUM[40];
  1002. extern char name_PTR[40], name_STRING[40], name_SET[40];
  1003. extern char name_PROCEDURE[40], name_MAIN[40], name_UNITINIT[40];
  1004. extern char name_HSYMBOL[40], name_GSYMBOL[40];
  1005. extern char name_SETBITS[40], name_UCHAR[40], name_SCHAR[40];
  1006. extern char name_BOOLEAN[40], name_TRUE[40], name_FALSE[40], name_NULL[40];
  1007. extern char name_ESCAPECODE[40], name_IORESULT[40];
  1008. extern char name_ARGC[40], name_ARGV[40];
  1009. extern char name_ESCAPE[40], name_ESCIO[40], name_CHKIO[40], name_SETIO[40];
  1010. extern char name_OUTMEM[40], name_CASECHECK[40], name_NILCHECK[40];
  1011. extern char name_FNSIZE[40], name_FNVAR[40];
  1012. extern char alternatename1[40], alternatename2[40], alternatename[40];
  1013. #ifndef define_parameters
  1014. extern
  1015. #endif
  1016. struct rcstruct {
  1017.     char kind;
  1018.     char chgmode;
  1019.     char *name;
  1020.     anyptr ptr;
  1021.     long def;
  1022. } rctable[]
  1023. #ifdef define_parameters
  1024.    = {
  1025.     'S', 'R', "DEBUG",           (anyptr) &debug,             0,
  1026.     'I', 'R', "SHOWPROGRESS",    (anyptr) &showprogress,      0,
  1027.     'S', 'V', "TOKENTRACE",      (anyptr) &tokentrace,        0,
  1028.     'S', 'V', "QUIET",           (anyptr) &quietmode,         0,
  1029.     'S', 'V', "COPYSOURCE",      (anyptr) &copysource,        0,
  1030.     'I', 'R', "MAXERRORS",  (anyptr) &maxerrors,       0,
  1031.     'X', ' ', "INCLUDE",         (anyptr) NULL,               2,
  1032. /* INPUT LANGUAGE */
  1033.     'U', 'T', "LANGUAGE",        (anyptr)  language,         40,
  1034.     'S', 'V', "MODULA2",         (anyptr) &modula2,          -1,
  1035.     'S', 'T', "INTEGER16",       (anyptr) &integer16,        -1,
  1036.     'S', 'T', "DOUBLEREALS",     (anyptr) &doublereals,      -1,
  1037.     'S', 'V', "UNSIGNEDCHAR",    (anyptr) &unsignedchar,     -1,
  1038.     'S', 'V', "NEEDSIGNEDBYTE",  (anyptr) &needsignedbyte,    0,
  1039.     'S', 'V', "PASCALENUMSIZE",  (anyptr) &pascalenumsize,   -1,
  1040.     'S', 'V', "NESTEDCOMMENTS",  (anyptr) &nestedcomments,   -1,
  1041.     'S', 'V', "IMPORTALL",       (anyptr) &importall,        -1,
  1042.     'S', 'V', "IMPLMODULES",     (anyptr) &implementationmodules, -1,
  1043.     'A', 'V', "EXTERNWORDS",  (anyptr) &externwords,       0,
  1044.     'A', 'V', "CEXTERNWORDS",  (anyptr) &cexternwords,      0,
  1045.     'S', 'V', "PASCALSIGNIF",    (anyptr) &pascalsignif,     -1,
  1046.     'S', 'V', "PASCALCASESENS",  (anyptr) &pascalcasesens,   -1,
  1047.     'S', 'V', "DOLLARIDENTS",    (anyptr) &dollar_idents,    -1,
  1048.     'S', 'V', "IGNORENONALPHA",  (anyptr) &ignorenonalpha,   -1,
  1049.     'I', 'V', "SEEKBASE",        (anyptr) &seek_base,        -1,
  1050.     'I', 'R', "INPUTTABSIZE",    (anyptr) &intabsize,         8,
  1051. /* TARGET LANGUAGE */
  1052.     'S', 'T', "ANSIC",           (anyptr) &ansiC,            -1,
  1053.     'S', 'T', "C++",             (anyptr) &cplus,            -1,
  1054.     'S', 'T', "VOID*",           (anyptr) &voidstar,         -1,
  1055.     'S', 'T', "HASSIGNEDCHAR",   (anyptr) &hassignedchar,    -1,
  1056.     'S', 'V', "CASTNULL",        (anyptr) &castnull,         -1,
  1057.     'S', 'V', "COPYSTRUCTS",     (anyptr) &copystructs,      -1,
  1058.     'S', 'V', "VARIABLEARRAYS",  (anyptr) &variablearrays,   -1,
  1059.     'S', 'V', "REUSEFIELDNAMES", (anyptr) &reusefieldnames,   1,
  1060.     'S', 'V', "USEVEXTERN",      (anyptr) &usevextern,        1,
  1061.     'S', 'V', "CSIGNIF",         (anyptr) &csignif,          -1,
  1062.     'S', 'V', "USEANYPTRMACROS", (anyptr) &useAnyptrMacros,  -1,
  1063.     'S', 'V', "USEPPMACROS",     (anyptr) &usePPMacros,      -1,
  1064. /* TARGET MACHINE */
  1065.     'U', 'T', "TARGET",          (anyptr)  target,           40,
  1066.     'S', 'T', "SIGNEDCHAR",      (anyptr) &signedchars,      -1,
  1067.     'S', 'T', "SIGNEDFIELD",     (anyptr) &signedfield,      -1,
  1068.     'S', 'T', "SIGNEDSHIFT",     (anyptr) &signedshift,      -1,
  1069.     'I', 'T', "CHARSIZE",        (anyptr) &sizeof_char,       0,
  1070.     'I', 'T', "SHORTSIZE",       (anyptr) &sizeof_short,      0,
  1071.     'I', 'T', "INTSIZE",         (anyptr) &sizeof_int,        0,
  1072.     'I', 'T', "LONGSIZE",        (anyptr) &sizeof_long,       0,
  1073.     'I', 'T', "PTRSIZE",         (anyptr) &sizeof_pointer,    0,
  1074.     'I', 'T', "DOUBLESIZE",      (anyptr) &sizeof_double,     0,
  1075.     'I', 'T', "FLOATSIZE",       (anyptr) &sizeof_float,      0,
  1076.     'I', 'T', "ENUMSIZE",        (anyptr) &sizeof_enum,       0,
  1077.     'S', 'T', "SIZE_T_LONG",     (anyptr) &size_t_long,      -1,
  1078. /* BRACES */
  1079.     'S', 'V', "NULLSTMTLINE",    (anyptr) &nullstmtline,      0,
  1080.     'S', 'V', "BRACESALWAYS",    (anyptr) &bracesalways,     -1,
  1081.     'S', 'V', "BRACELINE",       (anyptr) &braceline,        -1,
  1082.     'S', 'V', "BRACECOMBINE",    (anyptr) &bracecombine,      0,
  1083.     'S', 'V', "BRACEELSE",       (anyptr) &braceelse,         0,
  1084.     'S', 'V', "BRACEELSELINE",   (anyptr) &braceelseline,     0,
  1085.     'S', 'V', "ELSEIF",          (anyptr) &elseif,           -1,
  1086.     'S', 'V', "NEWLINEFUNCS",    (anyptr) &newlinefunctions,  0,
  1087. /* INDENTATION */
  1088.     'I', 'R', "PHYSTABSIZE",     (anyptr) &phystabsize,       8,
  1089.     'D', 'R', "INDENT",          (anyptr) &tabsize,           2,
  1090.     'D', 'R', "BLOCKINDENT",     (anyptr) &blockindent,       0,
  1091.     'D', 'R', "BODYINDENT",      (anyptr) &bodyindent,        0,
  1092.     'D', 'R', "FUNCARGINDENT",   (anyptr) &argindent,      1000,
  1093.     'D', 'R', "OPENBRACEINDENT", (anyptr) &openbraceindent,   0,
  1094.     'D', 'R', "CLOSEBRACEINDENT",(anyptr) &closebraceindent,  0,
  1095.     'D', 'R', "FUNCOPENINDENT",  (anyptr) &funcopenindent,    0,
  1096.     'D', 'R', "FUNCCLOSEINDENT", (anyptr) &funccloseindent,   0,
  1097.     'D', 'R', "SWITCHINDENT",    (anyptr) &switchindent,      0,
  1098.     'D', 'R', "CASEINDENT",      (anyptr) &caseindent,       -2,
  1099.     'D', 'R', "LABELINDENT",     (anyptr) &labelindent,    1000,
  1100.     'D', 'R', "STRUCTINDENT",    (anyptr) &structindent,      0,
  1101.     'D', 'R', "STRUCTINITINDENT",(anyptr) &structinitindent,  0,
  1102.     'D', 'R', "EXTRAINITINDENT", (anyptr) &extrainitindent,   2,
  1103.     'I', 'R', "EXTRAINDENT",     (anyptr) &extraindent,       2,
  1104.     'I', 'R', "BUMPINDENT",      (anyptr) &bumpindent,        1,
  1105.     'D', 'R', "CONSTINDENT",     (anyptr) &constindent,    1024,
  1106.     'D', 'R', "COMMENTINDENT",   (anyptr) &commentindent,     3,
  1107.     'D', 'R', "BRACECOMMENTINDENT",(anyptr)&bracecommentindent, 2,
  1108.     'D', 'R', "DECLCOMMENTINDENT",(anyptr)&declcommentindent, -999,
  1109.     'D', 'R', "COMMENTOVERINDENT",(anyptr)&commentoverindent, 4,  /*1000*/
  1110.     'I', 'R', "MINSPACING",      (anyptr) &minspacing,        2,
  1111.     'I', 'R', "MINSPACINGTHRESH",(anyptr) &minspacingthresh, -1,
  1112. /* LINE BREAKING */
  1113.     'I', 'R', "LINEWIDTH",       (anyptr) &linewidth,        78,
  1114.     'I', 'R', "MAXLINEWIDTH",    (anyptr) &maxlinewidth,     90,
  1115.     'R', 'V', "OVERWIDEPENALTY",       (anyptr) &overwidepenalty,         2500,
  1116.     'R', 'V', "OVERWIDEEXTRAPENALTY",  (anyptr) &overwideextrapenalty,     100,
  1117.     'R', 'V', "COMMABREAKPENALTY",     (anyptr) &commabreakpenalty,       1000,
  1118.     'R', 'V', "COMMABREAKEXTRAPENALTY",(anyptr) &commabreakextrapenalty,   500,
  1119.     'R', 'V', "ASSIGNBREAKPENALTY",    (anyptr) &assignbreakpenalty,      5000,
  1120.     'R', 'V', "ASSIGNBREAKEXTRAPENALTY",(anyptr)&assignbreakextrapenalty, 3000,
  1121.     'R', 'V', "SPECIALARGBREAKPENALTY",(anyptr) &specialargbreakpenalty,   500,
  1122.     'R', 'V', "OPBREAKPENALTY",        (anyptr) &opbreakpenalty,          2500,
  1123.     'R', 'V', "OPBREAKEXTRAPENALTY",   (anyptr) &opbreakextrapenalty,     2000,
  1124.     'R', 'V', "EXHYPHENPENALTY",       (anyptr) &exhyphenpenalty,         1000,
  1125.     'R', 'V', "MOREBREAKPENALTY",      (anyptr) &morebreakpenalty,        -500,
  1126.     'R', 'V', "MOREBREAKEXTRAPENALTY", (anyptr) &morebreakextrapenalty,   -300,