part of shnell – a source to source compiler enhancement tool
© Jens Gustedt, 2019
frontend for source-to-source amendment with #pragma
Usage: $0 file1 [file2 ...]
The result of the processing is written to stdout.
Coding and configuration
The following code is needed to enable the sh-module framework.SRC="$_" . "${0%%/${0##*/}}/import.sh"
imports We are using the following components of the sh-module system:
Imports
The following sh
-modules are imported:
Details
Tuning Per default the output is indented by using astyle
, if that is found in the executable path. You can use other programs for that, they just have to read the source on stdin and produce the output on stdout.
STYLE=whereis -b "${STYLE:-astyle}"
Per default, all #pragma
are annotated with a #line
directive early in the game. By that later compilation phase can always refer to the lines in the orginal source file in case of errors.
This has the disadvantage of making the output a bit ugly. You may switch this feature off by giving an empty environment variable ${PHASE2}
, for example by prefixing the command with PHASE2=
.
export PHASE2="${PHASE2-`shnlpath phase2`}"
Unicode
The tools for shnell all suppose that the source characters set englobes ASCII, and, if they are present, that other characters are encoded with UTF-8. To ease the handling of that we recognize the \uXXXX
and \UXXXXXXXX
notations from the C standard for Unicode code points. If the tools in the tools-c
directory are successfully compiled:
Before processing,
tools-undump8
is used to temporarily rewrite all\uXXXX
and\UXXXXXXXX
to UTF-8. Thereby tools such assed
will be able to categorize Unicode characters properly, e.g to know if they are punctuation or alpha-numeric.After processing,
tools-dump8
is used to rewrite all UTF-8 into\uXXXX
and\UXXXXXXXX
such that they can be fed into and any complying compiler, even if they don’t support UTF-8 input.
See tokenize
for more details on special characters, in particular on operators such as ≤
or →
that are rewritten to their classical C digraphs such as <=
or ->
.