From b231782442d62c947f1e89ba67f1819374275ef9 Mon Sep 17 00:00:00 2001 From: Stephen Heumann Date: Sat, 12 Feb 2022 21:36:39 -0600 Subject: [PATCH] Add option to use a custom pre-include file. This is a file that will be included before the source file is processed. If specified, it is used instead of the default .h file. --- Scanner.pas | 24 +++++++++++++++++++++--- cc.notes | 25 +++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 3 deletions(-) diff --git a/Scanner.pas b/Scanner.pas index c7004a1..3bd09db 100644 --- a/Scanner.pas +++ b/Scanner.pas @@ -240,6 +240,7 @@ type var charStrPrefix: charStrPrefixEnum; {prefix of character/string literal} + customDefaultName: stringPtr; {name of custom pre-included default file} dateStr: longStringPtr; {macro date string} doingCommandLine: boolean; {are we processing the cc= command line?} doingPPExpression: boolean; {are we processing a preprocessor expression?} @@ -2143,7 +2144,10 @@ var begin {OpenFile} if default then begin {get the file name} - workString := defaultName; + if customDefaultName <> nil then + workString := customDefaultName^ + else + workString := defaultName; gotName := true; end {if} else @@ -3354,7 +3358,7 @@ var begin {DoDefaultsDotH} name := defaultName; -if GetFileType(name) <> -1 then +if (customDefaultName <> nil) or (GetFileType(name) <> -1) then DoInclude(true); end; {DoDefaultsDotH} @@ -4112,6 +4116,7 @@ lintIsError := true; {lint messages are considered errors} fenvAccess := false; {not accessing fp environment} charStrPrefix := prefix_none; {no char/str prefix seen} mergingStrings := false; {not currently merging strings} +customDefaultName := nil; {no custom default name} pragmaKeepFile := nil; {no #pragma keep file so far} {error codes for lint messages} @@ -4353,7 +4358,20 @@ repeat else FlagErrorAndSkip; end {if} - else {not -d, -i: flag the error} + else if lch in ['p','P'] then begin + NextCh; {get the filename} + if lch = '"' then begin + GetString; + if customDefaultName = nil then + new(customDefaultName) + else + Error(108); + LongToPString(customDefaultName, token.sval); + end {if} + else + FlagErrorAndSkip; + end {if} + else {not -d, -i, -p: flag the error} FlagErrorAndSkip; end {if} else if lch <> chr(0) then begin diff --git a/cc.notes b/cc.notes index db525c8..5260f3b 100644 --- a/cc.notes +++ b/cc.notes @@ -47,6 +47,9 @@ Updated by Stephen Heumann and Kelvin Sherlock, 2017-2022 15. New option to print file names in error messages. See "File Names in Error Messages." + 16. New option to include a custom file before processing the + source file. See "Custom Pre-Include File." + 2.1.1 B3 1. Bugs squashed. See bug notes, below. 2.1.0 1. Bugs squashed. See bug notes, below. @@ -118,6 +121,8 @@ p. 128 The ASML, ASMLG, ASSEMBLE, CMPL, CMPLG, COMPILE, and RUN commands now accept a new flag, +F. The +F flag causes the compiler to include the file name in any error messages that it prints. It is currently only effective for ORCA/C. +There is also a new option, -p, which can be used within the cc= portion of the command line to specify a custom pre-include file. See "Custom Pre-Include File," below. + p. 233 Identifiers may now contain universal character names, a type of escape sequence that can denote a Unicode character. See "New Language Features," below. @@ -634,6 +639,24 @@ File Names in Error Messages When ORCA/C prints out error messages, it can now optionally include the name of the file containing the error. This can help you to understand whether an error is in the main source file or an include file. To enable this option, use the new +F flag to the ASML, ASMLG, ASSEMBLE, CMPL, CMPLG, COMPILE, or RUN commands. +Custom Pre-Include File +----------------------- + +ORCA/C supports a new command-line option to specify a custom file that will be included before the main source file is processed. This is specified by using a new option, -p, within the cc= portion of the command line. The -p option is immediately followed by the name of the file to include, given as a quoted string. For example, using the command line option + + cc=(-p"myconfig.h") + +is similar to starting the source file with + + #include "myconfig.h" + +However, the file name specified on the command line is used as-is rather than being subject to the usual header search rules. + +Only one pre-include file may be specified. If the -p option is used, then the default .h file (described below) will not be included. If you still wish to include the default .h file, you can explicitly write #include within your custom pre-include file or your source file. + +Like the default .h file, the custom pre-include file is primarily intended to contain pragmas or other preprocessor directives, but it may contain any C source code. The difference is that the custom pre-include file can be customized for a specific source file or project. + + Locales ------- @@ -1197,6 +1220,8 @@ The only differences are that the file doesn't have to exist (and if it doesn't You can put absolutely anything you like in this file. The intent is to use it for pragmas or other preprocessor directives that you would like to become defaults for all of your programs, but there is no restriction that prevents you from putting other things in the file. +As of ORCA/C 2.2.0 B6, a custom pre-include file may also be used, as described above. If one is specified, it will be included instead of the default .h file. + WARNING: If you add a defaults.h file, be sure and delete all .sym files. .sym files are created by the compiler to make recompiling programs faster. They need to be recreated with the new information from the defaults.h file, but the compiler will not notice the presence of the defaults.h file if it is using a .sym file created when the defaults.h file did not exist.