FORMAT |
![]() ![]() ![]() |
The FORMAT command reformats QMBasic source programs to aid readability.
Format
FORMAT {file.name} {record.name} {CASE}
where
If the record.name is omitted and select list 0 is active, this is used as the source of record names to be formatted. Entries in this select list with a .H suffix are ignored. Thus the command
SELECT BP
is adequate to construct the select list.
The FORMAT command reformats a QMBasic program to comply with a conventional indentation standard. Programs may be entered with no regard to indentation and subsequently tidied up using FORMAT.
FORMAT will not move line breaks. Statements must be correctly delimited. The format actions performed are:
The PROGRAM, FUNCTION or SUBROUTINE statement and compiler directives are adjusted to start at the leftmost column.
Statements inside conditional blocks (THEN, ELSE, ON ERROR, LOCKED, CASE, etc.) are indented by three columns.
WHILE and UNTIL statements are aligned with their corresponding LOOP or FOR statement.
Multiple spaces between language elements are reduced to a single space.
Spaces before commas in statements or argument lists are removed. A single space will follow such a comma.
Labels are aligned to the left margin and any further text except comments is moved to the next line.
A comment on the same line as a statement is not moved unless not to do so would place it over the statement or with less than one space before the semicolon.
Lines holding left aligned comments are not changed.
Comment lines which commence with spaces are moved to the alignment of the surrounding code except where the preceding line was a comment (excluding trailing comments) in which case the line is aligned with the preceding line.
EQUate and $DEFINE lines are unchanged to preserve possible user defined column alignment.
The CASE option converts all language elements, labels and data names to lowercase. Names corresponding to EQUate or $DEFINEd tokens retain the casing of the definition.
Where a $INCLUDE directive is encountered, the include record is read to establish any EQUATE or $DEFINE tokens in it. All references to these tokens in the record being formatted are converted to upper case. The include record itself is not changed.
If FORMAT fails because of faulty syntax such as unmatched THEN and END statements, the source record remains unchanged. Diagnostic messages to aid location of such errors are displayed.
Example
1 2 3 4 5 12345678901234567890123456789012345678901234567890123456789 SUBROUTINE GET.DATE(PROMPT.TEXT, VALUE) LOOP DISPLAY PROMPT.TEXT:;* Prompt for date INPUT NEW.DATE VALUE = ICONV(NEW.DATE,"DDMY");* Convert the date WHILE STATUS() REPEAT END
A program initially entered as above, after formatting becomes
1 2 3 4 5 12345678901234567890123456789012345678901234567890123456789 SUBROUTINE GET.DATE(PROMPT.TEXT, VALUE) LOOP DISPLAY PROMPT.TEXT : ;* Prompt for date INPUT NEW.DATE VALUE = ICONV(NEW.DATE, "DDMY") ;* Convert the date WHILE STATUS() REPEAT END
With the CASE option this becomes
1 2 3 4 5 12345678901234567890123456789012345678901234567890123456789 subroutine get.date(prompt.text, value) loop display prompt.text : ;* Prompt for date input new.date value = iconv(new.date, "DDMY") ;* Convert the date while status() repeat end |