home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 300-399 / ff341.lzh / P2C / p2c.lzh / p2c1_13a / home / p2c.1 < prev    next >
Text File  |  1990-03-18  |  64KB  |  1,345 lines

  1.  
  2.  
  3.  
  4.  
  5. P2C(1)                     User Commands                    P2C(1)
  6.  
  7.  
  8.  
  9. NNAAMMEE
  10.      p2c - Pascal to C translator, version 1.13
  11.  
  12. SSYYNNOOPPSSIISS
  13.      pp22cc [ options ] [ file [ module ] ]
  14.  
  15. DDEESSCCRRIIPPTTIIOONN
  16.      _P_2_c is a tool for translating Pascal programs into C.  The
  17.      input consists of a set of source files in any of the fol-
  18.      lowing Pascal dialects: HP Pascal, Turbo/UCSD Pascal, DEC
  19.      VAX Pascal, Oregon Software Pascal/2, Macintosh Programmer's
  20.      Workshop Pascal, Sun/Berkeley Pascal.  Modula-2 syntax is
  21.      also supported.  Output is a set of ..cc and ..hh files that
  22.      comprise an equivalent program in any of several dialects of
  23.      C.  Output code may be kept machine- and dialect-
  24.      independent, or it may be targeted to a specific machine and
  25.      compiler.  Most reasonable Pascal programs are converted
  26.      into fully functional C which will compile and run with no
  27.      further modifications, although _p_2_c sometimes chooses to
  28.      generate readable code at the expense of absolute general-
  29.      ity. _P_2_c endeavors to insert notes and warning messages into
  30.      the output code to point out areas which may require human
  31.      intervention.  Output code is arranged to be readable and
  32.      efficient, and to make use of C idioms wherever possible.
  33.      The main goal of the translation is to produce C files which
  34.      are pleasant and "natural" enough to be acceptable as the
  35.      new source files for a program.  In a pinch, _p_2_c will also
  36.      serve as an ad hoc Pascal compiler.
  37.  
  38.      Code generated by _p_2_c normally does not assume characters
  39.      are signed or unsigned.  Also, it assumes iinntt is the same as
  40.      either sshhoorrtt or lloonngg but does not depend on which.  However,
  41.      if iinntt is not the same as lloonngg it is best to use a modern C
  42.      compiler which supports prototypes.  Generated code does not
  43.      require an ANSI-compatible compiler (unless ANSI-style code
  44.      is requested), but it does use various ANSI-standard library
  45.      routines.
  46.  
  47.      All generated code includes the file _<_p_2_c_/_p_2_c_._h_> which in
  48.      turn includes _<_s_t_d_i_o_._h_> and various other common resources.
  49.      Also, many translated programs will need to be linked with
  50.      the run-time library, typically _-_l_p_2_c_.
  51.  
  52.      Given a file name, _p_2_c reads from the specified file and
  53.      outputs to a file with a ..cc suffix added or substituted.
  54.      For example,
  55.  
  56.         p2c myfile.pas
  57.  
  58.      reads from _m_y_f_i_l_e_._p_a_s to produce the file _m_y_f_i_l_e_._c_. The
  59.      input file may contain a Pascal main program or a single
  60.      Pascal module (or "unit" in Turbo and UCSD Pascal
  61.  
  62.  
  63.  
  64. Formatted 90/03/11            local                             1
  65.  
  66.  
  67.  
  68.  
  69. P2C(1)                     User Commands                    P2C(1)
  70.  
  71.  
  72.  
  73.      nomenclature), or it may just contain a number of procedures
  74.      and declarations.  _P_2_c is designed to work for correct input
  75.      programs.  That is, it will accept partial programs but may
  76.      occasionally core dump if the input refers to undefined sym-
  77.      bols.
  78.  
  79.      If the input is a module, the translator will also produce a
  80.      file _m_o_d_u_l_e..hh containing a translation of the module's
  81.      interface section.  The implementation section may be omit-
  82.      ted in which case only the ..hh file will be interesting.  If
  83.      the program or module has include files, these may cause
  84.      additional ..cc files to be generated depending on the value
  85.      of the EExxppaannddIInncclluuddeess option (see below).
  86.  
  87.      If no file name is given, _p_2_c reads Pascal from the standard
  88.      input and writes the resulting C to standard output (though
  89.      a ..hh file may still be produced).  If a file name and module
  90.      name are given, the file may include several modules (or
  91.      units).  The specified module is translated; any others are
  92.      skipped.  The output files will be named _m_o_d_u_l_e..cc and
  93.      _m_o_d_u_l_e..hh_.  _P_2_c never translates more than one module per
  94.      run.
  95.  
  96.      Before starting, _p_2_c reads the file _P_2_C_:_h_o_m_e_/_p_2_c_r_c for a
  97.      number of configuration parameters.  (The actual path used
  98.      on your system may vary.  The --ii option is a handy way to
  99.      examine this file.) If the P2CRC environment variable is
  100.      set, it gives the name of a file to read instead of the sys-
  101.      tem file; this file can start with IInncclluuddee %%HH//pp22ccrrcc to
  102.      include the system file.  Next, _p_2_c attempts to read the
  103.      file _p_2_c_r_c in your directory for further configuration.  If
  104.      this file does not exist, _p_2_c looks for _._p_2_c_r_c instead.
  105.  
  106. OOPPTTIIOONNSS
  107.      --oo _c_f_i_l_e
  108.           Use _c_f_i_l_e in place of _f_i_l_e..cc or _m_o_d_u_l_e..cc as the primary
  109.           output file.  A single dash (`-o -') says to write the
  110.           C code to the standard output.
  111.  
  112.      --hh _h_f_i_l_e
  113.           Use _h_f_i_l_e in place of _m_o_d_u_l_e..hh as the output file for
  114.           interface text.  This only has effect if the input is
  115.           an HP Pascal module or a Turbo Pascal unit.
  116.  
  117.      --ss _s_f_i_l_e
  118.           Read interface text from _s_f_i_l_e before beginning the
  119.           translation.  This file typically contains one or more
  120.           modules, often with interface sections omitted for
  121.           speed, which the program or module being translated
  122.           will use.  (Typically the IImmppoorrttFFrroomm and IImmppoorrttDDiirr
  123.           parameters in _p_2_c_r_c are set up to allow _p_2_c to locate
  124.           interface text without needing any --ss options.)  If
  125.  
  126.  
  127.  
  128. Formatted 90/03/11            local                             2
  129.  
  130.  
  131.  
  132.  
  133. P2C(1)                     User Commands                    P2C(1)
  134.  
  135.  
  136.  
  137.           there are several --ss options in the command, the _s_f_i_l_e_s
  138.           are read from left to right.
  139.  
  140.      --pp_n  Display progress of translation in the form of a line
  141.           number/file name display.  This is refreshed every _n
  142.           lines, 25 by default.
  143.  
  144.      --cc _r_c_f_i_l_e
  145.           Read local configuration commands from _r_c_f_i_l_e instead
  146.           of _p_2_c_r_c or _._p_2_c_r_c_. A dash (`-c -') in place of _r_c_f_i_l_e
  147.           causes no local configuration file to be used.
  148.  
  149.      --vv   ("Vanilla.")  Do not read from the system configuration
  150.           file _P_2_C_:_h_o_m_e_/_p_2_c_r_c_. Since some of the parameters in
  151.           this file are required, your local configuration file
  152.           must include those parameters instead.  This also
  153.           suppresses the file named by the P2CRC environment
  154.           variable.
  155.  
  156.      --HH _h_o_m_e_d_i_r
  157.           Use _h_o_m_e_d_i_r instead of _P_2_C_:_h_o_m_e as the _p_2_c home direc-
  158.           tory.  The system _p_2_c_r_c file will be searched for in
  159.           this directory.
  160.  
  161.      --II_p_a_t_t_e_r_n
  162.           Add _p_a_t_t_e_r_n to the IImmppoorrttDDiirr search list of places to
  163.           find modules which are imported.  The pattern should
  164.           include a _%_s to represent the module name, and should
  165.           evaluate to a potential file name for that module's
  166.           source code.  For example, ....//%%ss..ppaass looks for
  167.           _m_o_d_u_l_e_n_a_m_e..ppaass in the parent of the current directory.
  168.  
  169.      --ii   This special option (which must be the only argument on
  170.           the command line if used) simply copies the system con-
  171.           figuration file _P_2_C_:_h_o_m_e_/_p_2_c_r_c to the standard output
  172.           in its entirety.  (It may be used with --HH, but --ii is
  173.           most useful precisely when you don't know the location
  174.           of the home directory.)
  175.  
  176.      --qq   Quiet mode.  Suppresses output of status messages dur-
  177.           ing translation.
  178.  
  179.      --EE_n  Abort translation after _n errors.  If _n is omitted it
  180.           defaults to zero, which means unlimited errors are
  181.           allowed.  Use --EE11 to make _p_2_c halt after the first
  182.           error.
  183.  
  184.      --ee   Echo the Pascal source into the output file, surrounded
  185.           by #ifdefs.  This is the same as the CCooppyySSoouurrccee parame-
  186.           ter in the _p_2_c_r_c file.
  187.  
  188.  
  189.  
  190.  
  191.  
  192. Formatted 90/03/11            local                             3
  193.  
  194.  
  195.  
  196.  
  197. P2C(1)                     User Commands                    P2C(1)
  198.  
  199.  
  200.  
  201.      --aa   Produce modern ANSI C.  This is a convenient override
  202.           for the AAnnssiiCC parameter in the _p_2_c_r_c file.
  203.  
  204.      --LL _l_a_n_g_u_a_g_e
  205.           Select input language name, such as VAX or TURBO.  This
  206.           is a convenient override for the LLaanngguuaaggee parameter.
  207.  
  208.      --VV   Verbose mode.  This causes _p_2_c to generate an addi-
  209.           tional ".log" file with further details of the transla-
  210.           tion, such as a list of warnings and notes including
  211.           those which are suppressed in the regular output.
  212.  
  213.      --MM00  Disable memory conservation.  This prevents _p_2_c from
  214.           freeing various data structures after translating each
  215.           function, in case this new conservation feature causes
  216.           unforseen problems.
  217.  
  218.      --RR   Regression testing mode.  Formats notes and warning
  219.           messages in a way that makes it easier to run _d_i_f_f(1)
  220.           on the output of _p_2_c_.
  221.  
  222.      _P_2_c also understands a few debugging options which may occa-
  223.      sionally be useful when tracking down translation problems.
  224.      The --dd_n option sets the "debug level" to _n_, a small integer
  225.      which is normally zero.  Debugging output is written into
  226.      the regular output file along with the C code; the higher
  227.      your _n_, the more "wallpaper" you get.  Also, --tt prints
  228.      debugging information at every Pascal token, --BB_n enables
  229.      line-breaker debugging, and --CC_n enables comment placement
  230.      debugging.
  231.  
  232. CCHHOOIICCEE OOFF SSOOUURRCCEE LLAANNGGUUAAGGEE
  233.      The LLaanngguuaaggee configuration parameter or --LL command-line
  234.      option tells _p_2_c which Pascal dialect to expect in the input
  235.      file.  Any language features which do not overlap between
  236.      dialects are supported all of the time.  The LLaanngguuaaggee param-
  237.      eter is consulted when a syntax or usage is detected that
  238.      has different meanings in two different dialects, and also
  239.      to determine default values for various other translation
  240.      parameters as described below.
  241.  
  242.      The following language words are supported by _p_2_c_. Names are
  243.      case-insensitive.
  244.  
  245.      HHPP   HP Pascal.  This is the default language.  All features
  246.           of HP Standard Pascal, the Pascal Workstation version,
  247.           are supported except as noted in BUGS below.  Some
  248.           features of MODCAL, HP's extended Pascal, are also sup-
  249.           ported.  This is a superset of ISO standard Pascal,
  250.           including conformant arrays and procedural parameters.
  251.  
  252.  
  253.  
  254.  
  255.  
  256. Formatted 90/03/11            local                             4
  257.  
  258.  
  259.  
  260.  
  261. P2C(1)                     User Commands                    P2C(1)
  262.  
  263.  
  264.  
  265.      HHPP--UUXX
  266.           HP Pascal, HP-UX version.  Almost identical to the "HP"
  267.           dialect.
  268.  
  269.      TTuurrbboo
  270.           Turbo Pascal 5.0 for the IBM PC.  Few conflicts with HP
  271.           Pascal, so the LLaanngguuaaggee parameter is not often needed
  272.           for Turbo.  (Most important is that the Turbo and HP
  273.           dialects use 16 and 32 bit integers, respectively.)
  274.  
  275.      UUCCSSDD UCSD Pascal.  Similar to Turbo in many ways.
  276.  
  277.      MMPPWW  Macintosh Programmer's Workshop Pascal 2.0.  Should
  278.           also do a pretty good job for Lightspeed Pascal.
  279.           Object Pascal features are not supported, nor is the
  280.           fact that cchhaarr variables are sometimes stored in 16
  281.           bits.
  282.  
  283.      VVAAXX  VAX/VMS Pascal version 3.5.  Most but not all language
  284.           features supported.  This has not yet been tested on
  285.           large programs.
  286.  
  287.      OOrreeggoonn
  288.           Oregon Software Pascal/2.  All features implemented.
  289.  
  290.      BBeerrkk Berkeley Pascal with Sun extensions.
  291.  
  292.      MMoodduullaa
  293.           Modula-2.  Based on Wirth's _P_r_o_g_r_a_m_m_i_n_g _i_n _M_o_d_u_l_a_-_2_,
  294.           3rd edition.  Proper setting of the LLaanngguuaaggee parameter
  295.           is _n_o_t optional.  Translation will be incomplete in
  296.           most cases, but should be good enough to work with.
  297.           Structure of local sub-modules is essentially ignored;
  298.           like-named identifiers may be confused.  Type WORD is
  299.           translated as an integer, but type ADDRESS is
  300.           translated as char * or void *; this may cause incon-
  301.           sistencies in the output code.
  302.  
  303.           Modula-2 modules have two parts in separate files.
  304.           Suppose these are called _f_o_o_._d_e_f (definition part) and
  305.           _f_o_o_._m_o_d (implementation part) for module _f_o_o_. Then a
  306.           pattern like %%ss..ddeeff must be included in the IImmppoorrttDDiirr
  307.           list, and LLiibbrraarryyFFiillee must be changed to refer to
  308.           _s_y_s_t_e_m_._m_2 instead of _s_y_s_t_e_m_._i_m_p_. To translate the
  309.           definition part, give the command
  310.  
  311.                p2c foo.def
  312.  
  313.           to translate the definition part into files _f_o_o_._h and
  314.           _f_o_o_._c; the latter will usually be empty.  The command
  315.  
  316.  
  317.  
  318.  
  319.  
  320. Formatted 90/03/11            local                             5
  321.  
  322.  
  323.  
  324.  
  325. P2C(1)                     User Commands                    P2C(1)
  326.  
  327.  
  328.  
  329.                p2c -s foo.def foo.mod
  330.  
  331.           will translate the implementation part into file _f_o_o_._c_.
  332.  
  333.      Even if all language features are supported for a dialect,
  334.      some predefined functions may be omitted.  In these cases,
  335.      the function call will be translated literally into C with a
  336.      warning.  Some hand modification may be required.
  337.  
  338. CCOONNFFIIGGUURRAATTIIOONN PPAARRAAMMEETTEERRSS
  339.      _P_2_c is highly configurable.  The defaults are suitable for
  340.      most applications, but customizing these parameters will
  341.      help you get the best possible translation.  Since the out-
  342.      put of _p_2_c is intended to be used as human-maintainable
  343.      source code, there are many parameters for describing the
  344.      coding style and conventions you prefer.  Others give hints
  345.      about your program that help _p_2_c to generate more correct,
  346.      efficient, or readable code.
  347.  
  348.      The _p_2_c_r_c files contain a list of parameters, one per line.
  349.      The system configuration file, which may be viewed using the
  350.      --ii option to _p_2_c_, serves as an example of the proper format.
  351.      Parameter names are case-insensitive.  If a parameter name
  352.      occurs exactly once in the system _p_2_c_r_c_, this indicates that
  353.      it must have a unique value and the last value given to it
  354.      by the configuration files is used.  Other parameters are
  355.      written several times in a row; these are lists to which
  356.      each configuration line adds an entry.
  357.  
  358.      Many _p_2_c_r_c options take a numeric value of 0 or 1, roughly
  359.      corresponding to "no" or "yes."  Sometimes a blank value or
  360.      the value "ddeeff" corresponds to an intermediate "maybe"
  361.      state.  For example, the stylistic option EExxttrraaPPaarreennss
  362.      switches between copious or minimal parentheses in expres-
  363.      sions, with the default being a nice compromise intended to
  364.      be best for readers with an average knowledge of C operator
  365.      precedences.
  366.  
  367.      Configuration options may also be embedded in the source
  368.      file in the form of Pascal comments:
  369.  
  370.           {ShortOpt=0} {AvoidName=fred}
  371.           {FuncMacro slope(x,y)=atan2(y,x)*RadDeg}
  372.  
  373.      disables automatic short-circuiting of aanndd and oorr expres-
  374.      sions, adds "_f_r_e_d" to the list of names to avoid using in
  375.      generated C code, and defines a special translation for the
  376.      Pascal program's _s_l_o_p_e function using the standard C _a_t_a_n_2
  377.      function and a constant _R_a_d_D_e_g presumably defined in the
  378.      program.  Whitespace is generally not allowed in embedded
  379.      parameters.  The `=' sign is required for embedded parame-
  380.      ters, though it is optional in _p_2_c_r_c files.  Comments within
  381.  
  382.  
  383.  
  384. Formatted 90/03/11            local                             6
  385.  
  386.  
  387.  
  388.  
  389. P2C(1)                     User Commands                    P2C(1)
  390.  
  391.  
  392.  
  393.      embedded parameters are delimited by `##'.  Numeric parame-
  394.      ters may replace `=' with `+' or `-' to increase or decrease
  395.      the parameter; list-based parameters may use `-' to remove a
  396.      name from a list rather than adding it.  Also, the parameter
  397.      name by itself in comment braces means to restore the
  398.      parameter's value that was current before the last change:
  399.  
  400.           {VarFiles=0  ## Pass FILE *'s params by value even if
  401.      VAR}
  402.           _s_o_m_e _d_e_c_l_a_r_a_t_i_o_n_s
  403.           {VarFiles    ## Back to original FILE * passing}
  404.  
  405.      causes the parameter VVaarrFFiilleess to have the value 0 for those
  406.      few declarations, without affecting the parameter's value
  407.      elsewhere in the file.
  408.  
  409.      If an embedded parameter appears in an include file or in
  410.      interface text for a module, the effect of the assignment
  411.      normally carries over to any programs that included that
  412.      file.  If the parameter name is preceded by a `*', then the
  413.      assignment is automatically undone after the source file
  414.      that contains it ends:
  415.  
  416.           {IncludeFrom strings=<p2c/strings.h>}
  417.           {*ExportSymbol=pascal_%s}
  418.           module strings;
  419.  
  420.      will record the location of the _s_t_r_i_n_g_s module's include
  421.      file for the rest of the translation, but the assignment of
  422.      EExxppoorrttSSyymmbbooll pertains only to the module itself.
  423.  
  424.      For the complete list of _p_2_c_r_c parameters, run _p_2_c with the
  425.      --ii option.  Here are some additional comments on selected
  426.      parameters:
  427.  
  428.      IImmppoorrttAAllll Because Turbo Pascal only allows one unit per
  429.                source file, _p_2_c normally stops reading past the
  430.                word _i_m_p_l_e_m_e_n_t_a_t_i_o_n in a file being scanned for
  431.                interface text.  But HP Pascal allows several
  432.                modules per file and so this would not be safe to
  433.                do.  The IImmppoorrttAAllll option lets you override the
  434.                default behavior for your Pascal dialect.
  435.  
  436.      AAnnssiiCC     This parameter selects which dialect of C to use.
  437.                If 1, all conventions of ANSI C such as proto-
  438.                types, vvooiidd ** pointers, etc. are used.  If 0, only
  439.                strict K&R (first edition) C is used.  The default
  440.                is to use "traditional UNIX C," which includes
  441.                eennuumm and vvooiidd but not vvooiidd ** or prototypes.  Once
  442.                again there are a number of other parameters which
  443.                may be used to control the individual features if
  444.                just setting AAnnssiiCC is not enough.
  445.  
  446.  
  447.  
  448. Formatted 90/03/11            local                             7
  449.  
  450.  
  451.  
  452.  
  453. P2C(1)                     User Commands                    P2C(1)
  454.  
  455.  
  456.  
  457.      CC++++       At present _p_2_c does not use much of C++ at all.
  458.                The default action is to generate code that will
  459.                compile in either language.
  460.  
  461.      UUsseeVVEExxtteerrnn
  462.                Many non-UNIX linkers prohibit variables from
  463.                being defined (not declared) by more than one
  464.                source file.  One module must declare, e.g., "int
  465.                foo;", and all others must declare "extern int
  466.                foo;".  _P_2_c accomplishes this by declaring public
  467.                variables "vveexxtteerrnn" in header files, and arranging
  468.                for the macro vveexxtteerrnn to expand to eexxtteerrnn or to
  469.                nothing when appropriate.  If you set UUsseeVVEExxtteerrnn=0
  470.                _p_2_c will instead declare variables in a simpler
  471.                way that works only on UNIX-style linkers.
  472.  
  473.      UUsseeAAnnyyppttrrMMaaccrrooss
  474.                Certain C reserved words have meanings which may
  475.                vary from one C implementation to another.  _P_2_c
  476.                uses special capitalized names for these words;
  477.                these names are defined as macros in the file
  478.                _p_2_c_._h which all translated programs include.  You
  479.                can set UUsseeAAnnyyppttrrMMaaccrrooss=0 to disable the use of
  480.                these macros.  Note that the functions of many of
  481.                these macros can also be had directly using other
  482.                parameters; for example, UUsseeCCoonnssttss allows you to
  483.                specify whether your target language recognizes
  484.                the word ccoonnsstt in constant declarations.  The
  485.                default is to use the CCoonnsstt macro instead, so that
  486.                your code will be portable to either kind of
  487.                implementation.
  488.  
  489.                SSiiggnneedd expands to the reserved word ssiiggnneedd if that
  490.                word is available, otherwise it is given a null
  491.                definition.  Similarly, CCoonnsstt expands to ccoonnsstt if
  492.                that feature is available.  The words VVoollaattiillee and
  493.                RReeggiisstteerr are also defined in _p_2_c_._h_, although _p_2_c
  494.                does not use them at present.  The word CChhaarr
  495.                expands to cchhaarr by default, but might need to be
  496.                redefined to ssiiggnneedd cchhaarr or uunnssiiggnneedd cchhaarr in a
  497.                particular implementation.  This is used for the
  498.                Pascal character type; lowercase cchhaarr is used when
  499.                the desired meaning is "byte," not "character."
  500.  
  501.                The word SSttaattiicc always expands to ssttaattiicc by
  502.                default.  This is used in situations where a func-
  503.                tion or variable is declared static to make it
  504.                local to the source file; lowercase ssttaattiicc is used
  505.                for static local variables.  Thus you can redefine
  506.                SSttaattiicc to be null if you want to force private
  507.                names to be public for purposes of debugging.
  508.  
  509.  
  510.  
  511.  
  512. Formatted 90/03/11            local                             8
  513.  
  514.  
  515.  
  516.  
  517. P2C(1)                     User Commands                    P2C(1)
  518.  
  519.  
  520.  
  521.                The word VVooiidd expands to vvooiidd in all cases; it is
  522.                used when declaring a function with no return
  523.                value.  The word AAnnyyppttrr is a typedef for vvooiidd ** or
  524.                cchhaarr ** as necessary; it represents a generic
  525.                pointer.
  526.  
  527.      UUsseePPPPMMaaccrrooss
  528.                The _p_2_c_._h header also declares two macros for
  529.                function prototyping, PPPP(x) and PPVV().  These mac-
  530.                ros are used as follows:
  531.  
  532.                     Void foo  PP( (int x, int y, Char *z) );
  533.                     Char *bar PV( );
  534.  
  535.                If prototypes are available, these macros will
  536.                expand to
  537.  
  538.                     Void foo  (int x, int y, Char *z);
  539.                     Char *bar (void);
  540.  
  541.                but if only old-style declarations are supported,
  542.                you instead get
  543.  
  544.                     Void foo  ();
  545.                     Char *bar ();
  546.  
  547.                By default, _p_2_c uses these macros for all function
  548.                declarations, but function _d_e_f_i_n_i_t_i_o_n_s are written
  549.                in old-style C.  The UUsseePPPPMMaaccrrooss parameter can be
  550.                set to 0 to disable all use of PPPP and PPVV, or it
  551.                can be set to 1 to use the macros even when defin-
  552.                ing a function.  (This is accomplished by preced-
  553.                ing each old-style definition with a PPPP-style
  554.                declaration.)  If you know your code will always
  555.                be compiled on systems that support prototyping,
  556.                it is prettier to set PPrroottoottyyppeess=1 or simply
  557.                AAnnssiiCC=1 to get true function prototypes.
  558.  
  559.      EEaattNNootteess  Notes and warning messages containing any of these
  560.                strings as sub-strings are not omitted.  Each type
  561.                of message includes an identifier like [[114455]]; you
  562.                can add this identifier to the EEaattNNootteess list to
  563.                suppress that message.  Another useful form is to
  564.                use a variable name or other identifier to
  565.                suppress warnings about that variable.  The
  566.                strings are a space-separated list, and thus may
  567.                not contain embedded spaces.  To suppress notes
  568.                around a section of code, use, e.g., _{_E_a_t_-
  569.                _N_o_t_e_s_+_[_1_4_5_]_} and _{_E_a_t_N_o_t_e_s_-_[_1_4_5_]_}_. Most notes are
  570.                generated during parsing, but to suppress those
  571.                generated during output the string may need to
  572.                remain in the list far beyond the point where it
  573.  
  574.  
  575.  
  576. Formatted 90/03/11            local                             9
  577.  
  578.  
  579.  
  580.  
  581. P2C(1)                     User Commands                    P2C(1)
  582.  
  583.  
  584.  
  585.                appears to be generated.  Use the string "1" or
  586.                "0" to disable or enable all notes, respectively.
  587.  
  588.      EExxppaannddIInncclluuddeess
  589.                The default action is to expand Pascal include
  590.                files in-line.  This may not be desirable if
  591.                include files are being used to simulate modules.
  592.                With EExxppaannddIInncclluuddeess=0, _p_2_c attempts to convert
  593.                include files containing only whole procedures and
  594.                global declarations into analogous C include
  595.                files.  This may not always work, though; if you
  596.                get error messages, don't use this option.  By
  597.                combining this option with SSttaattiiccFFuunnccttiioonnss=0, then
  598.                doing some fairly minor editing on the result, you
  599.                can convert a pseudo-modular Pascal program into a
  600.                truly modular collection of C source files.
  601.  
  602.      EElliimmDDeeaaddCCooddee
  603.                Some transformations that _p_2_c does on the program
  604.                may result in unreachable or "dead" code.  By
  605.                default _p_2_c removes such code, but sometimes it
  606.                removes more than it should.  If you have "if
  607.                false" segments which you wish to retain in C, you
  608.                may have to set EElliimmDDeeaaddCCooddee=0.
  609.  
  610.      SSkkiippIInnddiicceess
  611.                Normally Pascal arrays not based at zero are
  612.                "shifted" down for C, preserving the total size of
  613.                the array.  A Pascal array a[2..10] is translated
  614.                to a C array a[9] with references like "a[i]"
  615.                changed to "a[i-2]" everywhere.  If SSkkiippIInnddiicceess is
  616.                set to a value of 2 or higher, this array would
  617.                instead be translated to a[11] with the first two
  618.                elements never used.  This arrangement may gen-
  619.                erate incorrect code, though, for tricky source
  620.                programs.
  621.  
  622.      FFoollddCCoonnssttaannttss
  623.                Pascal non-structured constants generally
  624.                translate to ##ddeeffiinnee's in C.  Set this to 1 to
  625.                have constants instantiated directly into the
  626.                code.  This may be turned on or off around
  627.                specific constant declarations.  Set this to 0 to
  628.                force _p_2_c to make absolutely no assumptions about
  629.                the constant's value in generated code, so that
  630.                you can change the constant later in the C code
  631.                without invalidating the translation.  The default
  632.                is to allow _p_2_c to take advantage of its knowledge
  633.                of a constant's value, such as by generating code
  634.                that assumes the constant is positive.
  635.  
  636.  
  637.  
  638.  
  639.  
  640. Formatted 90/03/11            local                            10
  641.  
  642.  
  643.  
  644.  
  645. P2C(1)                     User Commands                    P2C(1)
  646.  
  647.  
  648.  
  649.      VVaarrSSttrriinnggss
  650.                In HP Pascal, a parameter of the form "var s :
  651.                string" will match a string variable of any size;
  652.                a hidden size parameter is passed which may be
  653.                accessed by the Pascal _s_t_r_m_a_x function.  You can
  654.                prevent _p_2_c from creating a hidden size parameter
  655.                by setting VVaarrSSttrriinngg=0.  (Note that each function
  656.                uses the value of VVaarrSSttrriinnggss as of the _f_i_r_s_t
  657.                declaration of the function that is parsed, which
  658.                is often in the interface section of a module.)
  659.  
  660.      PPrroottoottyyppeess
  661.                Control whether ANSI C function prototypes are
  662.                used.  Default is according to AAnnssiiCC.  This also
  663.                controls whether to include parameter names or
  664.                just their types in situations where names are
  665.                optional.  The FFuullllPPrroottoottyyppiinngg parameter allows
  666.                prototypes to be generated for declarations but
  667.                not for definitions (older versions of Lightspeed
  668.                C required this).  If you use a mixture of proto-
  669.                types and old-style definitions, types like short
  670.                and float will be promoted to int and double as
  671.                required by the ANSI standard, unless PPrroommootteeAArrggss
  672.                is used to override this.  The CCaassttAArrggss parameter
  673.                controls whether type-casts are used in function
  674.                arguments; by default they are used only if proto-
  675.                types are not available.
  676.  
  677.      SSttaattiiccLLiinnkkss
  678.                HP Pascal and Turbo Pascal each include the con-
  679.                cept of procedure or function pointers, though
  680.                with somewhat different syntaxes.  _P_2_c recognizes
  681.                both notational styles.  Another difference is
  682.                that HP's procedure pointers can point to nested
  683.                procedures, while Turbo's can point only to global
  684.                procedures.  In HP Pascal a procedure pointer must
  685.                be stored as a ssttrruucctt containing both a pure C
  686.                function pointer and a "static link," a pointer to
  687.                the parent procedure's locals.  (The static link
  688.                is NULL for global procedures.)  This notation can
  689.                be forced by setting SSttaattiiccLLiinnkkss=1.  In Turbo, the
  690.                default (SSttaattiiccLLiinnkkss=0) is to use plain C function
  691.                pointers with no static links.  A third option
  692.                (SSttaattiiccLLiinnkkss=2) uses structures with static links,
  693.                but assumes the links are always NULL when calling
  694.                through a pointer (if you need compatibility with
  695.                the HP format but know your procedures are glo-
  696.                bal).
  697.  
  698.      SSmmaallllSSeettCCoonnsstt
  699.                Pascal sets are translated into one of two for-
  700.                mats, depending on the size of the set.  If all
  701.  
  702.  
  703.  
  704. Formatted 90/03/11            local                            11
  705.  
  706.  
  707.  
  708.  
  709. P2C(1)                     User Commands                    P2C(1)
  710.  
  711.  
  712.  
  713.                elements have ordinal values in the range 0..31,
  714.                the set is translated as a single integer variable
  715.                using bit operations.  (The SSeettBBiittss parameter may
  716.                be used to change the upper limit of 31.) The
  717.                SSmmaallllSSeettCCoonnsstt parameter controls whether these
  718.                small-sets are used, and, if so, how constant sets
  719.                should be represented in C.   For larger sets, an
  720.                array of lloonngg is used.  The _s[0] element contains
  721.                the number of succeeding array elements which are
  722.                in use.  Set elements in the range 0..31 are
  723.                stored in the _s[1] array element, and so on.  Sets
  724.                are normalized so that _s[_s[0]] is nonzero for any
  725.                nonempty set.  The standard run-time library
  726.                includes all the necessary procedures for operat-
  727.                ing on sets.
  728.  
  729.      RReettuurrnnVVaalluueeNNaammee
  730.                This is one of many "naming conventions" parame-
  731.                ters.  Most of these take the form of a _p_r_i_n_t_f-
  732.                like string containing a _%_s where the relevant
  733.                information should go.  In the case of RReettuurrnn----
  734.                VVaalluueeNNaammee, the _%_s refers to a function name and
  735.                the resulting string gives the name of the vari-
  736.                able to use to hold the function's return value.
  737.                Such a variable will be made if a function con-
  738.                tains assignments to its return value buried
  739.                within the body, so that _r_e_t_u_r_n statements cannot
  740.                conveniently be used.  Some parameters (RReettuurrnn----
  741.                VVaalluueeNNaammee included) do not require the _%_s to be
  742.                present in the format string; for example, the
  743.                standard _p_2_c_r_c file stores every function's return
  744.                value in a variable called _R_e_s_u_l_t_.
  745.  
  746.      AAlltteerrnnaatteeNNaammee
  747.                _P_2_c normally translates Pascal names into C names
  748.                verbatim, but occasionally this is not possible.
  749.                A Pascal name may be a C reserved word or tradi-
  750.                tional C name like _p_u_t_c_, or there may be several
  751.                like-named things that are hidden from each other
  752.                by Pascal's scoping rules but must be global in C.
  753.                In these situations _p_2_c uses the parameter AAlltteerr----
  754.                nnaatteeNNaammee11 to generate an alternative name for the
  755.                symbol.  The default is to add an underscore to
  756.                the name.  There is also an AAlltteerrnnaatteeNNaammee22 parame-
  757.                ter for a second alternate name, and an AAlltteerrnnaa----
  758.                tteeNNaammee parameter for the _nth alternate name.  (The
  759.                value for this parameter should include both a _%_s
  760.                and a _%_d_, in either order.)  If these latter
  761.                parameters are not defined, _p_2_c applies AAlltteerrnnaa----
  762.                tteeNNaammee11 many times over.
  763.  
  764.  
  765.  
  766.  
  767.  
  768. Formatted 90/03/11            local                            12
  769.  
  770.  
  771.  
  772.  
  773. P2C(1)                     User Commands                    P2C(1)
  774.  
  775.  
  776.  
  777.      EExxppoorrttSSyymmbbooll
  778.                Symbols in the interface section for a Pascal
  779.                module are formatted according to the value of
  780.                EExxppoorrttSSyymmbbooll, if any.  It is not uncommon to use
  781.                _m_o_d_u_l_e_n_a_m_e___%_s for this symbol; the default is _%_s_,
  782.                i.e., no special treatment for exported symbols.
  783.                If you also define the EExxppoorrtt__SSyymmbbooll parameter,
  784.                that format is used instead for exported symbols
  785.                which contain an underscore character.  If _%_S
  786.                (with a capital "S") appears in the format string
  787.                it stands for the current module name.
  788.  
  789.      AAlliiaass     If the value of this parameter contains a _%_s_, it
  790.                is a format string applied to the names of exter-
  791.                nal functions or variables.  If the value does not
  792.                contain a _%_s_, it becomes the name of the next
  793.                external symbol which is declared (after which the
  794.                parameter is cleared).
  795.  
  796.      SSyynnoonnyymm   This creates a synonym for another Pascal symbol
  797.                or keyword.  The format is
  798.  
  799.                     SSyynnoonnyymm _o_l_d_-_n_a_m_e _= _n_e_w_-_n_a_m_e
  800.  
  801.                All occurrences of _o_l_d_-_n_a_m_e in the input text are
  802.                treated as if they were _n_e_w_-_n_a_m_e by the parser.
  803.                If _n_e_w_-_n_a_m_e is a keyword, _o_l_d_-_n_a_m_e will be an
  804.                equivalent keyword.  If _n_e_w_-_n_a_m_e is the name of a
  805.                predefined function, _o_l_d_-_n_a_m_e will behave in the
  806.                same way as that function, and so on.  If _n_e_w_-_n_a_m_e
  807.                is omitted, then occurrences of _o_l_d_-_n_a_m_e are
  808.                entirely ignored in the input file.  Synonyms
  809.                allow you to skip over a keyword in your dialect
  810.                of Pascal that is not understood by _p_2_c_, or to
  811.                simulate a keyword or predefined identifier of
  812.                your dialect with a similar one that _p_2_c recog-
  813.                nizes.  Note that all predefined functions are
  814.                available at all times; if you have a library rou-
  815.                tine that behaves like, e.g., Turbo Pascal's _g_e_t_-
  816.                _m_e_m procedure, you can make your routine a synonym
  817.                for _g_e_t_m_e_m even if you are not translating in
  818.                Turbo mode.
  819.  
  820.      NNaammeeOOff    This defines the name to use in C for a specific
  821.                symbol.  It must appear before the symbol is
  822.                declared in the Pascal code; it is usually placed
  823.                in the local _p_2_c_r_c file for the project.  The for-
  824.                mat is
  825.  
  826.                     NNaammeeOOff _p_a_s_c_a_l_-_n_a_m_e _= _C_-_n_a_m_e
  827.  
  828.  
  829.  
  830.  
  831.  
  832. Formatted 90/03/11            local                            13
  833.  
  834.  
  835.  
  836.  
  837. P2C(1)                     User Commands                    P2C(1)
  838.  
  839.  
  840.  
  841.                By default, Pascal names map directly onto C names
  842.                with no change (except for the various kinds of
  843.                formatting outlined above).  If the _p_a_s_c_a_l_-_n_a_m_e is
  844.                of the form _m_o_d_u_l_e_._n_a_m_e or _p_r_o_c_e_d_u_r_e_._n_a_m_e then the
  845.                command applies only to the instance of the Pascal
  846.                name that is global to that module, or local to
  847.                that procedure.  Otherwise, it applies to all
  848.                usages of the name.
  849.  
  850.      VVaarrMMaaccrroo  This is analogous to NNaammeeOOff, but specifically for
  851.                use with Pascal variables.  The righthand side can
  852.                be most any C expression; all references to the
  853.                variable are expanded into that C expression.
  854.                Names used in the C expression are taken verbatim.
  855.                There is also a CCoonnssttMMaaccrroo parameter for translat-
  856.                ing constants as arbitrary expressions.  Note that
  857.                the variable on the lefthand side must actually be
  858.                declared in the program or in a module that it
  859.                uses.  The declaration for the variable will be
  860.                omitted from the generated code unless the
  861.                Pascal-name appears in the expression:  If you ask
  862.                to replace _i with _i_+_1_, the variable _i will still
  863.                be declared but its value will be shifted accord-
  864.                ingly.  Note that if _i appears on the lefthand
  865.                side of an assignment, _p_2_c will use algebra to
  866.                "solve" for _i_.
  867.  
  868.                In all cases where _p_2_c parses C expressions, all C
  869.                operators are recognized except compound assign-
  870.                ments like `+='.  (Increment and decrement opera-
  871.                tors are allowed.) All variable and function names
  872.                are assumed to have integer type, even if they are
  873.                names that occur in the actual program.  A type-
  874.                specification operator `::' has been introduced;
  875.                it has the same precedence as `.' or `->' but the
  876.                righthand side must be a Pascal type identifier
  877.                (built-in or defined by your program previously to
  878.                when the macro definition was parsed), or an arbi-
  879.                trary Pascal type expression in parentheses.  The
  880.                lefthand argument is then considered to have the
  881.                specified type.  This may be necessary if your
  882.                macro is used in situations where the exact type
  883.                of the expression must be known (say, as the argu-
  884.                ment to a _w_r_i_t_e_l_n).
  885.  
  886.      FFiieellddMMaaccrroo
  887.                Here the lefthand side must have the form
  888.                _r_e_c_o_r_d_._f_i_e_l_d_, where _r_e_c_o_r_d is the Pascal type or
  889.                variable name for a record, and _f_i_e_l_d is a field
  890.                in that record.  The righthand side must be a C
  891.                expression generally including the name _r_e_c_o_r_d_.
  892.                All instances of that name are replaced by the
  893.  
  894.  
  895.  
  896. Formatted 90/03/11            local                            14
  897.  
  898.  
  899.  
  900.  
  901. P2C(1)                     User Commands                    P2C(1)
  902.  
  903.  
  904.  
  905.                actual record being "dotted." For example,
  906.  
  907.                     FieldMacro Rect.topLeft = topLeft(Rect)
  908.  
  909.                translates _a_[_i_]_._t_o_p_L_e_f_t into _t_o_p_L_e_f_t_(_a_[_i_]_)_, where
  910.                _a is an array of _R_e_c_t_.
  911.  
  912.      FFuunnccMMaaccrroo The lefthand side must be any Pascal function or
  913.                procedure name plus a parameter list.  The number
  914.                of parameters must match the number in the
  915.                function's uses and declaration.  Calls to the
  916.                function are replaced by the C expression on the
  917.                righthand side.  For example,
  918.  
  919.                     FuncMacro PtInRect(p,r) = PtInRect(p,&r)
  920.  
  921.                causes the second argument of _P_t_I_n_R_e_c_t to be
  922.                passed by reference, even though the declaration
  923.                says it's not.  If the function in question is
  924.                actually defined in the program or module being
  925.                translated, the FFuunnccMMaaccrroo will not affect the
  926.                definition but it will affect all calls to the
  927.                function elsewhere in the module.  FFuunnccMMaaccrrooss can
  928.                also be applied to predefined or never-defined
  929.                functions.
  930.  
  931.      IInncclluuddeeFFrroomm
  932.                This specifies that a given module's header should
  933.                be included from a given place.  The second argu-
  934.                ment may be surrounded by " " or < > as necessary;
  935.                if the second argument is omitted, no include
  936.                directive will be generated for the module.
  937.  
  938.      IImmppoorrttFFrroomm
  939.                This specifies that a given module's Pascal inter-
  940.                face text can be found in the given file.  The
  941.                named file should be either the source file for
  942.                the module, or a specially prepared file with the
  943.                implementation section removed for speed.  If no
  944.                IImmppoorrttFFrroomm entry is found for a module, the path
  945.                defined by the IImmppoorrttDDiirr list is searched.  Each
  946.                entry in the path may contain a _%_s_, which expands
  947.                to the name of the module.  The default path looks
  948.                for _%_s_._p_a_s and _%_s_._t_e_x_t in the current directory,
  949.                then for _P_2_C_:_h_o_m_e_/_%_s_._i_m_p_. (where P2C:home is the
  950.                _p_2_c home directory.)
  951.  
  952.      SSttrruuccttFFuunnccttiioonn
  953.                This parameter is a list of functions which follow
  954.                the _p_2_c semantics for structure-valued functions
  955.                (functions returning arrays, sets, and strings,
  956.                and structs in primitive C dialects).  For these
  957.  
  958.  
  959.  
  960. Formatted 90/03/11            local                            15
  961.  
  962.  
  963.  
  964.  
  965. P2C(1)                     User Commands                    P2C(1)
  966.  
  967.  
  968.  
  969.                functions, a pointer to a return-value area is
  970.                passed to the function as a special first parame-
  971.                ter.  The function stores the result in this area,
  972.                then returns a copy of the pointer.  (The standard
  973.                C function _s_t_r_c_p_y is an example of this concept.
  974.                _S_p_r_i_n_t_f also behaves this way in some dialects; it
  975.                always appears on the SSttrruuccttFFuunnccttiioonn list regard-
  976.                less of the type of implementation.)  The system
  977.                configuration file includes a list of common
  978.                structured functions so that _p_2_c's optimizer will
  979.                know how to manipulate them.
  980.  
  981.      SSttrrllaappFFuunnccttiioonn
  982.                Functions on this list are structured functions as
  983.                above, but with the ability to work in-place; that
  984.                is, the same pointer may be passed as both the
  985.                return value area and a regular parameter.
  986.  
  987.      DDeetteerrmmiinniissttiicc
  988.                Functions on this list have no side effects or
  989.                side dependencies.  An example is the _s_i_n function
  990.                in the standard math library; two calls with the
  991.                same parameter values produce the same result, and
  992.                have no effects other than returning a value.  _P_2_c
  993.                can make use of this knowledge when optimizing
  994.                code for efficiency or readability.  Functions on
  995.                this list are also assumed to be relatively fast,
  996.                so that it is acceptable to duplicate a call to
  997.                the function.
  998.  
  999.      LLeeaavveeAAlloonnee
  1000.                Functions on this list are not subjected to the
  1001.                normal built-in translation rules that _p_2_c would
  1002.                otherwise use.  For example, adding _w_r_i_t_e_l_n to
  1003.                this list would translate _w_r_i_t_e_l_n statements
  1004.                blindly into calls to a C _w_r_i_t_e_l_n_(_) function,
  1005.                rather than being translated into equivalent
  1006.                _p_r_i_n_t_f calls.  The built-in translation is also
  1007.                suppressed if the function has a FFuunnccMMaaccrroo.
  1008.  
  1009.      BBuuffffeerreeddFFiillee
  1010.                _P_2_c normally assumes binary files will use
  1011.                _r_e_a_d_/_w_r_i_t_e_, not _g_e_t_/_p_u_t_/_^ notation.  A file buffer
  1012.                variable will only be created for a file if buffer
  1013.                notation is used for it.  For global file vari-
  1014.                ables this may be detected too late (a declaration
  1015.                without buffers may already have been written).
  1016.                Such files can be listed in BBuuffffeerreeddFFiillee to force
  1017.                _p_2_c to allocate buffers for them; do this if you
  1018.                get a warning message that says it is necessary.
  1019.                Set BBuuffffeerreeddFFiillee=1 to buffer all files, in which
  1020.                case UUnnBBuuffffeerreeddFFiillee allows you to force certain
  1021.  
  1022.  
  1023.  
  1024. Formatted 90/03/11            local                            16
  1025.  
  1026.  
  1027.  
  1028.  
  1029. P2C(1)                     User Commands                    P2C(1)
  1030.  
  1031.  
  1032.  
  1033.                files _n_o_t to have buffers.
  1034.  
  1035.      CChheecckkFFiilleeEEOOFF
  1036.                Normally only file-open operations are checked for
  1037.                errors.  Additional error checking, such as read-
  1038.                past-end-of-file, can be enabled with parameters
  1039.                like CChheecckkFFiilleeEEOOFF.  These checks can make the code
  1040.                very ugly!  If I/O checking is enabled by the pro-
  1041.                gram ($$iioocchheecckk oonn$$ in HP Pascal; {{$$II++}} in Turbo;
  1042.                this is always the default state), these checks
  1043.                will generate fatal errors unless enclosed in an
  1044.                HP Pascal ttrryy-rreeccoovveerr construct.  If I/O checking
  1045.                is disabled, these will cause the global variable
  1046.                _P___i_o_r_e_s_u_l_t to be set zero or nonzero according to
  1047.                the outcome.  The default for most of these
  1048.                options is to check only when I/O checking is dis-
  1049.                abled.
  1050.  
  1051. IISSSSUUEESS
  1052.      IInntteeggeerr ssiizzee.. _P_2_c normally generates code to work with
  1053.      either 16 or 32 bit ints.  If you know your C integers will
  1054.      be 16 or 32 bits, set IInnttSSiizzee appropriately.  In particular
  1055.      setting IInnttSSiizzee=32 will generate much cleaner code: _p_2_c no
  1056.      longer must carefully cast function arguments between int
  1057.      and long.  These casts also will be unnecessary if ANSI pro-
  1058.      totypes are available.  To disable int/long casting because
  1059.      you know at least one of these cases will hold, set CCaasstt----
  1060.      LLoonnggAArrggss=0.  (The CCaassttAArrggss parameter similarly controls
  1061.      other types of casts, such as between ints and doubles.) The
  1062.      IInntteeggeerr1166 parameter controls whether Pascal integers are
  1063.      interpreted as 16 or 32 bits, or translated as native C
  1064.      integers.  The default value depends on the LLaanngguuaaggee
  1065.      selected.
  1066.  
  1067.      SSiiggnneedd//uunnssiiggnneedd cchhaarrss.. Pascal characters are normally
  1068.      "weakly" interpreted as unsigned; this is controlled by
  1069.      UUnnssiiggnneeddCChhaarr.  The default is "either," so that C's native
  1070.      cchhaarr type may be used even if its signed-ness is unknown.
  1071.      Code that uses characters outside of the range 0-127 may
  1072.      need a different setting.  Alternatively, you can use the
  1073.      types {{SSIIGGNNEEDD}} cchhaarr and {{UUNNSSIIGGNNEEDD}} cchhaarr in the few cases
  1074.      where it really matters.  These comments are controlled by
  1075.      the SSiiggnneeddCCoommmmeenntt and UUnnssiiggnneeddCCoommmmeenntt parameters.  (The type
  1076.      {{UUNNSSIIGGNNEEDD}} iinntteeggeerr is also recognized.)  The SSiiggnneeddCChhaarr
  1077.      parameter tells whether C characters are signed or unsigned
  1078.      (default is "unknown").  The HHaassSSiiggnneeddCChhaarr parameter tells
  1079.      whether the phrase "signed char" is legal in the output.  If
  1080.      it is not, _p_2_c may have to translate Pascal signed bytes
  1081.      into C shorts.
  1082.  
  1083.      SSppeecciiaall ttyyppeess.. _P_2_c understands the following predefined Pas-
  1084.      cal type names: iinntteeggeerr, signed integers depending on
  1085.  
  1086.  
  1087.  
  1088. Formatted 90/03/11            local                            17
  1089.  
  1090.  
  1091.  
  1092.  
  1093. P2C(1)                     User Commands                    P2C(1)
  1094.  
  1095.  
  1096.  
  1097.      IInntteeggeerr1166; lloonnggiinntt, signed 32-bit integers; uunnssiiggnneedd,
  1098.      unsigned 32-bit integers; sswwoorrdd, signed 16-bit integers;
  1099.      wwoorrdd, unsigned 16-bit integers; cc__iinntt, signed native C
  1100.      integers; cc__uuiinntt, unsigned native C integers; ssbbyyttee, signed
  1101.      8-bit integers; bbyyttee, unsigned 8-bit integers; rreeaall,
  1102.      floating-point numbers depending on DDoouubblleeRReeaallss; ssiinnggllee,
  1103.      single-precision floats; lloonnggrreeaall, ddoouubbllee, and eexxtteennddeedd,
  1104.      double-precision floats; ppooiinntteerr and aannyyppttrr, generic
  1105.      pointers (assignment-compatible with any pointer type);
  1106.      ssttrriinngg, generic string of length SSttrriinnggDDeeffaauulltt (normally
  1107.      255); also, the usual Pascal types cchhaarr, bboooolleeaann, and tteexxtt.
  1108.      (If your Pascal uses different names for these concepts, the
  1109.      SSyynnoonnyymm option will come in handy.)
  1110.  
  1111.      EEmmbbeeddddeedd ccooddee.. It is possible to write a Pascal comment con-
  1112.      taining C code to be embedded into the output.  See the
  1113.      descriptions of EEmmbbeeddCCoommmmeenntt and its relatives in the system
  1114.      _p_2_c_r_c file.  These techniques are helpful if you plan to do
  1115.      repeated translations of code that is still being maintained
  1116.      in Pascal.
  1117.  
  1118.      CCoommmmeennttss aanndd bbllaannkk lliinneess.. _P_2_c collects the comments in a
  1119.      procedure into a list.  All comments and statements are
  1120.      stamped with serial numbers which are used to reattach com-
  1121.      ments to statements even after code has been added, removed,
  1122.      or rearranged during translation.  "Orphan" comments
  1123.      attached to statements that have been lost are attached to
  1124.      nearby statements or emitted at the end of the procedure.
  1125.      Blank lines are treated as a kind of comment, so _p_2_c will
  1126.      also reproduce your usage of blank lines.  If the comment
  1127.      mechanism goes awry, you can disable comments with EEaattCCoomm----
  1128.      mmeennttss or disable their being attached to code with SSppiittCCoomm----
  1129.      mmeennttss.
  1130.  
  1131.      IInnddeennttaattiioonn.. _P_2_c has a number of parameters to govern inden-
  1132.      tation of code.  The default values produce the GNU Emacs
  1133.      standard indentation style, although _p_2_c can do a better job
  1134.      since it knows more about the code it is indenting.  Inden-
  1135.      tation works by applying "indentation deltas," which are
  1136.      either absolute numbers (which override the previous inden-
  1137.      tation), or signed relative numbers (which augment the pre-
  1138.      vious indentation).  A delta of "+0" specifies no change in
  1139.      indentation.  All of the indentation options are described
  1140.      in the standard _p_2_c_r_c file.
  1141.  
  1142.      LLiinnee bbrreeaakkiinngg.. _P_2_c uses an algorithm similar to the TeX
  1143.      typesetter's paragraph formatter for breaking long state-
  1144.      ments into multiple lines.  A "penalty" is assigned to vari-
  1145.      ous undesirable aspects of all possible line breaks; the
  1146.      "badness" of a set of line breaks is approximately the sum
  1147.      of all the penalties.  Chief among these are serious penal-
  1148.      ties for overrunning the desired maximum line length
  1149.  
  1150.  
  1151.  
  1152. Formatted 90/03/11            local                            18
  1153.  
  1154.  
  1155.  
  1156.  
  1157. P2C(1)                     User Commands                    P2C(1)
  1158.  
  1159.  
  1160.  
  1161.      (default 78 columns), an infinite penalty for overrunning
  1162.      the absolute maximum line length (default 90), and progres-
  1163.      sively greater penalties for breaking at operators deeply
  1164.      nested in expressions.  Parameters such as OOppBBrreeaakkPPeennaallttyy
  1165.      control the relative weights of various choices.  BBrreeaakkAArriitthh
  1166.      and its neighbors control whether the operator at a line
  1167.      break should be placed at the end of the previous line or at
  1168.      the beginning of the next.  If you don't want any oversize
  1169.      lines, define MMaaxxLLiinneeWWiiddtthh=78.
  1170.  
  1171.      Unlike TeX, _p_2_c's line breaker must actually try all possi-
  1172.      ble sets of break points.  To avoid excessive computation,
  1173.      the total penalty contributed at each decision point must
  1174.      sum to a nonnegative value; negative values are clipped up
  1175.      to zero.  This allows _p_2_c to prune away obviously undesir-
  1176.      able alternatives in advance.  The MMaaxxLLiinneeBBrreeaakkTTrriieess parame-
  1177.      ter (default 5000) controls how many alternatives to try
  1178.      before giving up and using the best so far.
  1179.  
  1180.      PPAASSCCAALL__MMAAIINN.. _P_2_c generates a call to this function at the
  1181.      front of the main program.  In the (unmodified) run-time
  1182.      library all this does is save argc and argv away because in
  1183.      both HP and Turbo these are accessed as global variables.
  1184.      If you do not wish to use this feature, define AArrggCCNNaammee to
  1185.      be _a_r_g_c_, AArrggVVNNaammee to be _a_r_g_v_, and MMaaiinnNNaammee (normally
  1186.      "PASCAL_MAIN") to be blank.  This will work if argc and argv
  1187.      are never accessed outside of your main program.
  1188.  
  1189. BBUUGGSS
  1190.      _P_2_c was designed with the idea that clean, readable output
  1191.      in most cases is worth more than guaranteed correct output
  1192.      in extreme cases.  _P_2_c is _n_o_t a compiler!  However, ideally
  1193.      the "extreme" cases would include only those which never
  1194.      arise in real life.  Thus if _p_2_c actually generates
  1195.      incorrect code I will consider it a bug, but I will not apo-
  1196.      logize for it. :-)  Below are the major remaining cases
  1197.      where this is known to occur.
  1198.  
  1199.      Certain kinds of conformant array parameters (including
  1200.      multi-dimensional conformant arrays) produce code that
  1201.      declares variable-length arrays in C.  Only a few C com-
  1202.      pilers, such as the GNU C compiler, support this language
  1203.      extension.  Otherwise some hand re-coding will be required.
  1204.  
  1205.      HP Pascal ttrryy-rreeccoovveerr structures are translated into calls
  1206.      to _T_R_Y and _R_E_C_O_V_E_R macros, which are defined to simulate the
  1207.      construct using _s_e_t_j_m_p and _l_o_n_g_j_m_p_. If this emulation does
  1208.      not work, define the symbol FFAAKKEE__TTRRYY to cause these macros
  1209.      to become "inert."  (In cases where the error is detected by
  1210.      code physically within the body of the ttrryy statement, a C
  1211.      ggoottoo to the rreeccoovveerr section is always generated.)  Also,
  1212.      local file variables in scopes which are destroyed by an
  1213.  
  1214.  
  1215.  
  1216. Formatted 90/03/11            local                            19
  1217.  
  1218.  
  1219.  
  1220.  
  1221. P2C(1)                     User Commands                    P2C(1)
  1222.  
  1223.  
  1224.  
  1225.      eessccaappee are not closed.
  1226.  
  1227.      Non-local GOTO's and ttrryy-rreeccoovveerr statements are each imple-
  1228.      mented, but may conflict if both are used at once.  Non-
  1229.      local GOTO's are fairly careful about closing files that go
  1230.      out of scope but may fail to do so in the presence of recur-
  1231.      sion.
  1232.  
  1233.      Arrays containing files are not initialized to NULL as other
  1234.      files are.  In some cases, such as file variables allocated
  1235.      by NEW, the file is initialized but not automatically closed
  1236.      by DISPOSE.
  1237.  
  1238.      LINK variables allowing sub-procedures access to their
  1239.      parents' variables are occasionally omitted by mistake, if
  1240.      the access is too indirect for _p_2_c to notice.  If this hap-
  1241.      pens, you can add an explicit reference to a parent variable
  1242.      in the sub-procedure.  A statement of the form "a:=a" will
  1243.      count as a reference but then be optimized away by _p_2_c_.
  1244.  
  1245.      Many aspects of Modula-2 are translated only superficially.
  1246.      For example, the type-compatibility properties of the _W_O_R_D
  1247.      and _A_R_R_A_Y _O_F _W_O_R_D types are only roughly modelled, as are
  1248.      the scope rules concerning modules.
  1249.  
  1250.      Parts of VAX Pascal are still untreated.  In particular, the
  1251.      _[_U_N_S_A_F_E_] attribute and a few others are not fully supported,
  1252.      nor are the semantics of the _O_P_E_N procedure.
  1253.  
  1254.      Turbo and VAX Pascal's _d_o_u_b_l_e_, _q_u_a_d_r_u_p_l_e_, and _e_x_t_e_n_d_e_d real
  1255.      types all translate to the C ddoouubbllee type.  Turbo's _c_o_m_p_u_t_a_-
  1256.      _t_i_o_n_a_l type is not supported at all.
  1257.  
  1258.      Because Pascal strings (with length bytes) are translated
  1259.      into C strings (with null terminators), certain Pascal
  1260.      string tricks will not work in the translated code.  For
  1261.      example the assignment _s_[_0_]_:_=_c_h_r_(_x_) is translated to _s_[_x_]_=_0
  1262.      on the assumption that the string is being shortened.  If _x
  1263.      is actually greater than the current length, but not of a
  1264.      recognizable form like _o_r_d_(_s_[_0_]_)_+_n_, then the generated code
  1265.      will not work.  In VAX Pascal this corresponds to performing
  1266.      arithmetic on the _L_E_N_G_T_H field of a varying-length string.
  1267.  
  1268.      Turbo Pascal's automatic clipping of strings is not sup-
  1269.      ported.  In Turbo, if a ten character string is assigned to
  1270.      a _s_t_r_i_n_g_[_8_] variable, the last two characters are silently
  1271.      removed.  The code produced by _p_2_c generally will overrun
  1272.      the target string instead!  The SSttrriinnggTTrruunnccLLiimmiitt parameter
  1273.      (80 by default if LLaanngguuaaggee=TTuurrbboo) specifies a string size
  1274.      which should be considered "short"; assignments of
  1275.      potentially-long strings to short string variables will
  1276.      cause a warning but will not automatically truncate.  The
  1277.  
  1278.  
  1279.  
  1280. Formatted 90/03/11            local                            20
  1281.  
  1282.  
  1283.  
  1284.  
  1285. P2C(1)                     User Commands                    P2C(1)
  1286.  
  1287.  
  1288.  
  1289.      cure is to use _c_o_p_y in the Pascal source to truncate the
  1290.      strings explicitly.
  1291.  
  1292. FFIILLEESS
  1293.      file._x_x_x           Pascal source files
  1294.      file.c             resulting C source file
  1295.      module.h           resulting C header file
  1296.      p2crc              local configuration file
  1297.      .p2crc             alternate local configuration file
  1298.      P2C:home/p2crc     system-wide configuration file
  1299.      P2C:home/system.impdeclarations for predefined functions
  1300.      P2C:home/system.m2 analogous declarations for Modula-2
  1301.      P2C:home/*.imp     interface text for standard modules
  1302.      P2C:home/p2c/p2c.h header file for translated programs
  1303.      P2C:home/libp2c.a  run-time library
  1304.  
  1305. AAUUTTHHOORR
  1306.      Dave Gillespie, daveg@csvax.caltech.edu.
  1307.  
  1308.      Many thanks to William Bader, Rick Koshi, Eric Raymond,
  1309.      Magne Haveraaen, Dirk Grunwald, David Barto, Paul Fisher,
  1310.      and others whose suggestions and bug reports have helped
  1311.      improve _p_2_c in countless ways.
  1312.  
  1313.  
  1314.  
  1315.  
  1316.  
  1317.  
  1318.  
  1319.  
  1320.  
  1321.  
  1322.  
  1323.  
  1324.  
  1325.  
  1326.  
  1327.  
  1328.  
  1329.  
  1330.  
  1331.  
  1332.  
  1333.  
  1334.  
  1335.  
  1336.  
  1337.  
  1338.  
  1339.  
  1340.  
  1341.  
  1342.  
  1343.  
  1344. Formatted 90/03/11            local                            21
  1345.