RISC OS Build EnvironmentROBE

Appendix42Appendix H: p2crc file format

Overview

The p2crc file controls how P2C translates Pascal into C. It is a line-based configuration language used by riscos-p2c and indirectly by riscos-p2cc. Most projects only need a small local override file, but understanding the structure is useful when adapting a translation to a particular Pascal dialect, runtime library, naming scheme, or output style.

Configuration structure

Search and layering model

The RISC OS port resolves configuration in layers. The home directory comes from -H, otherwise from P2C$Home, and otherwise defaults to Choices:P2C. Unless -v is used, the translator reads the file named by P2C$RC, or the standard %H/p2crc file if that variable is not set. The separator here is always a literal /, not the path-separator notation used elsewhere in RISC OS filenames.

After the system stage, a local override may be read through -c. If no explicit -c is supplied, the RISC OS port looks for a current-directory p2crc file. The standard shipped configuration normally ends by including a local site file, so installed defaults and local overrides can remain separate.

To confirm that a configuration parses and layers as intended before running a full translation, use riscos-p2c -i, which writes the fully resolved configuration to standard output, including a comment line for each file it read showing the expanded path, for example %H/p2crc => /usr/local/p2c/p2crc. This makes it possible to check the layering and substitution result without running a translation, rather than only discovering a misconfiguration through subtly wrong generated C.

Line structure

The language is line based. Each line begins with a parameter name, followed by an optional value. Parameter names are case-insensitive. Either whitespace or an equals sign may separate the name from its value. Text following # is treated as a comment.

Blank lines are ignored. Most parameters are single-valued, so the last value seen wins. Some parameters are intentionally repeatable and build lists; each occurrence adds another item rather than replacing the previous one.

The general form is:

Parameter value
Parameter = value
# comment

Values and substitutions

Values may be plain tokens, strings, file-name patterns, symbolic names, or booleans depending on the parameter. Blank values usually mean that the compiled-in default should be used instead of supplying a replacement.

The notation %H expands to the resolved P2C home directory. Many naming and path parameters also use printf-like substitutions, most importantly %s for the source file name and %S for the module name. Where a format string includes two string arguments, they may appear in either order; %s refers to one and %S to the other.

The wider set of supported flag characters for %s/ %S, taken from the header comments of the standard configuration file installed as Resources.p2crc (p2csrc/Resources/p2crc in the source tree), is:

FlagMeaning
_Convert to lower case.
^Convert to upper case.
_^Convert to lower case except capitalise the first character and any character after a non-letter.
~Insert _ between a lower-case letter and a following upper-case letter.
!Remove _ and other non-alphanumeric characters.
?Negate the _ and ^ flags if the name contains mixed case.
RRemove the file name suffix, for example foo.pas becomes foo.
/Remove the path name, the prefix up to and including the last /, \, ], or :.

Include files and embedded commands

The configuration language supports:

ConstructMeaning
IncludeRead another configuration file at that point, typically to layer site-local settings on top of the installed defaults.
Embedded commandsConfiguration commands may also be placed inside Pascal comments in the source itself, allowing a program to carry local translation hints with the code.

The common installed pattern is a system p2crc file which ends with an Include %H/loc.p2crc line so that local site adjustments stay separate from the shipped defaults.

Main parameter groups

The standard configuration file is arranged into thematic groups. These are the main groups you will encounter:

GroupPurpose
INPUT LANGUAGESelects the Pascal dialect and input assumptions, including parameters such as Language, Modula2, Integer16, and comment or token handling rules.
TARGET LANGUAGEControls the style and feature level of generated C or C++, including AnsiC, C++, structure-copy rules, macro use, and prototype style.
TARGET MACHINEDescribes machine properties which affect correct code generation, such as signedness, integer sizes, and pointer sizes.
BRACES AND PLACEMENT OF STATEMENTSControls brace style and where translated statements are emitted.
INDENTATIONDefines indentation deltas and layout depth for the emitted C source.
LINE BREAKINGControls line-length policy and the line-break cost model used by the formatter.
COMMENTS AND BLANK LINESControls whether Pascal comments and spacing are preserved, suppressed, or rewritten.
SPECIAL COMMENTSDefines comment directives such as EMBED, SKIP, NOSKIP, and type or sign annotations.
STYLISTIC OPTIONSChooses expression and declaration style, anonymous-union handling, spacing, increment style, and related output conventions.
CODING OPTIONSControls translation strategy, including flow analysis, dead-code elimination, constant folding, file handling, set handling, and string translation.
NAMING CONVENTIONSDefines generated file names, identifier formats, aliases, rename rules, helper-symbol names, and naming patterns.
TARGET LIBRARYMaps Pascal operations and standard units onto C headers, helper functions, import libraries, and interface-file search paths.
CHECKINGEnables or suppresses generated runtime checks such as bounds checks, nil checks, file-open checks, and format checks.

Practical override strategy

In normal project use, keep local overrides as small as possible. Start by choosing the source dialect, then adjust naming conventions and import paths, and only then enable or disable individual coding or checking options if the translated program needs them.

This keeps the project-specific configuration easy to review, and makes it clear which behaviours come from the installed defaults and which are genuine local changes.

Worked example

Minimal local override

This shows the shape of a small project-local override file. It changes the dialect, adjusts naming, and then includes a local import-path override.

Language TURBO
AnsiC 1
CodeName %s.c
HeaderName %s.h
Include project-extra.p2crc