NFORenum has a code-beautifier in the works. This is the style that I intend to have that beautifier obey in its output. Comments are welcome; post them here.
Canon format for the beginnings of sprites, always. Single space between bytes in a sprite and between adjacent quoted strings, unless otherwise noted. Everything in hex unless otherwise noted.
0 * 0 00 <feat> <num-info> <num-ids> <id> <prop> <value[s]> <prop> <value[s]> <prop> <value[s]>
|If <num-ids> is greater than 1, whitespace should be inserted as necessary so that all <values> are aligned in columns, one column for each ID. Line breaks are usually omitted if <num-ids>==1. Unless otherwise noted, everything is to appear in hex.|
No line breaks in a <prop> <value[s]> line, regardless of the max line length.
0A <numlayouts> <size> <layout-entry> <layout-entry> <layout-entry> ... 00 80 ...
|Special case for industry prop 0A. <layout-entry> is any of the various <xoffs> <yoffs> ... formats.|
0E <num> <data1> <data2> <data3> ...
|Special case for station prop 0E.|
0D <table-id> <numtables> <table> <table> <table> ...
|Special case for bridge prop 0D.|
<prop> <value> <value> <value> ...
|Special case for all other variable-sized props. All variable-sized props are ignored for purposes of column alignment, and all force line-breaks, even if <num-info> is 1.|
All variable-sized props that use a format with line-breaks in <value> (that is, any format other than this one) have a double line-break between <value>s.
0 * 0 00 08 01 <num-ids> 00 09 "__00" "__01" "__02" ... "__10" "__11" "__12" ... ...
|Special case for the cargo translation table. Linebreaks every eight or sixteen entries, depending on requested width. No line-breaks if the whole action can fit on a single line, no linebreak before the 09, ever.|
0 * 0 02 07/09 <num-sprites> <groundsprite> <buildingsprite> ... <buildingsprite> ... ...
|Standard action 2s for houses and industry tiles, in the extended format.|
0 * 0 02 <id> <feat> <type> <var> <varadjust> <n-var> <set-id> <low-range> <high-range> <set-id> <low-range> <high-range> ... <default>
|Variational action 2s in the basic format. All hex, no line breaks if <n-var> is 0 or 1.|
0 * 0 02 <id> <feat> <type> <var> <varadjust> <op> <var> <varadjust> <op> ... <var> <varadjust> <n-var> <set-id> <low-range> <high-range> <set-id> <low-range> <high-range> ... <default>
|Variational action 2s in the basic format. All hex, no line breaks after <n-var> if it is 0 or 1.|
All other action2s are currently intended to be all-hex, no extra line-breaks. Rand2s have no line breaks in <r-ID>s.
0 * 0 04 <feat> <langs> <num-ent> <offset> "String #1" 00 "String #2 (A really long " "string)" 00 "String #3" 0D "contains line breaks" 00 "AStringThatWasTypedBySomeoneWithABro" "kenSpacebar" 00 ...
|The first line break will be omitted if <num-ent> is 1.|
Double 0D and double 00 do not have line breaks between them.
The following characters are never to be quoted: 00..1F, 22, 7B..A0, AA, AC, AD, AF, and B4..B8, unless part of a UTF-8 character sequence.
(See comments on line-breaking following this table.)
|07/09/0D||No linebreaks and entirely in hex, unless they contain GRFIDs or cargo labels, which are to be quoted as for actions 0 and 8.|
|08||Strings are to be quoted as in action 4. The first two bytes of the GRFID are quoted if both are printable, unless the GRFID is FF FF FF FF|
|0B||Strings are to be quoted as in action 4; line break between <message> and <data> if both exist.|
0 * 0 0E <num> <grfid> ...
|As in action 8, the GRFIDs are to have the first two characters quoted if printable. Line breaks may only occur between GRFIDs.|
0 * 0 0F <ID> <stylenames> <num-parts> <textcount> <firstbit> <bitcount> <probablity> <part/ID> <probablity> <part/ID> ... <textcount> <firstbit> <bitcount> ...
|The strings in <stylenames> are to be broken as in action 4, with the line break before the first <langs> byte omitted if there is only one name, and with the line-break before <num-parts> omitted if this is not a final definition.|
0 * 0 10 <label> <comment>
|<label> always in hex, <comment> never touched.|
0 * 0 FE <grfid> <number>
|(binary import) <grfid> quoted as in 8, FE and <number> in hex.|
0 * 0 00 <table>
|Entirely in hex, line breaks afer each 32 bytes in <table>.|
Actions 1, 3, 5, 6, A, 11, and 12 are currently intended to be formatted with no linebreaks, and entirely in hex.
A maxmimum line-length will be configurable; the default will be 78 characters. NFORenum will begin looking for a place to insert a line break starting fifteen characters (Note: "characters", not "bytes") before the specified length. When looking for a place to add a line breaks necessary for not exceeding the maximum line length, (that is, those not mentioned in the above style table) they will be placed after the first space or non-printable found, or immediately upon reaching the maximum line length.
Notwithstanding the above, linebreaks will never be inserted in the middle of a quoted UTF-8 sequence or a GRFid.
Line breaks inserted in this way will be immediately followed by a tab, while line breaks inserted due to format are followed by zero or three spaces. Tabs-stops are every eight spaces.
"Never touched" specifications are always overridden by line-breaking rules and may be overriden by specifying that no high-ASCII characters be quoted.
Current options, ranges and defaults are as follows:
|MAXLEN||0..255||78||0 means max line length is infinite.|
|QUOTEHIGHASCII||on/off||on||These two are independent. HIGHASCII controls characters > 7F that are not part of a UTF-8 sequence, while UTF8 controls bytes > 7F that are part of a UTF-8 encoded character.|
|LEADINGSPACE||1..32||2,5,8||Three settings, setting number of spaces to be added after line breaks, depeding on what requests them. (Sprites in the style table are shown as if this was set to 0,3,6)|
GETCOOKIE and SETCOOKIE are also available for acquiring and returning a magic cookie for saving and restoring all beautifier options in one go.
Comments and blank lines shall be handled as follows:
Comments are attached to the byte that they follow, and are never moved. If the style calls for a blank line, it will be added after a trailing comment, but before any comments on a seperate line.
Blank lines will not be moved, but additional carriage returns will not be added.
Last Update: 2006/02/15 08:20 GMT
* Changed comment spec to match actual behaviour.
* Eliminated overlength is never-touched; now it's all-hex.
* Updated LEADINGSPACE spec.
* Eliminated a line break in some action Fs.
* Linebreaks now begin fifteen characters before max len, to accomodate 12-character GRFids and UTF-8 sequences.
2006/02/12 05:50 GMT
* Added LEADINGSPACE option and GETCOOKIE/SETCOOKIE options, and note about action 12.
2006/02/11 00:12 GMT
* Started Changelog