Skip to content

Instantly share code, notes, and snippets.

@sealfin
Created January 20, 2014 17:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sealfin/8524998 to your computer and use it in GitHub Desktop.
Save sealfin/8524998 to your computer and use it in GitHub Desktop.
This program will enumerate the format command characters in the file 'metal_help.mhlp', viz. characters preceded by three '@' characters.
'T'
'C'
'L'
'N'
't'
'B'
'n'
'I'
'E'
This program will now quit.
{$R+}
program mhlp_file_format_analyser_I( output );
label
l_END;
const
k_F_PATH = 'metal_help.mhlp';
var
f : text;
numberOfAtCharacters : 0..3;
formatCommandCharactersEnumerated : set of char;
c : char;
begin
writeln( 'This program will enumerate the format command characters in the file ''', k_F_PATH, ''', viz. characters preceded by three ''@'' characters.' );
writeln;
assign( f, k_F_PATH );
{$I-}
reset( f );
if ioresult <> 0 then begin
{$I+}
writeln( 'Sorry, an error occurred: the file ''', k_F_PATH, ''' could not be opened; please ensure that the file is in the same folder as this program and try running this program again.' );
goto l_END
end;
numberOfAtCharacters := 0;
formatCommandCharactersEnumerated := [];
while not eof( f ) do begin
read( f, c );
if eoln( f ) then begin
readln( f );
numberOfAtCharacters := 0
end;
if numberOfAtCharacters = 3 then begin
if not ( c in formatCommandCharactersEnumerated ) then begin
writeln( '''', c, '''' );
formatCommandCharactersEnumerated := formatCommandCharactersEnumerated + [ c ]
end;
numberOfAtCharacters := 0
end
else
if c = '@' then
numberOfAtCharacters := numberOfAtCharacters + 1
else
numberOfAtCharacters := 0
end;
close( f );
l_END:writeln;
writeln( 'This program will now quit.' )
end.
@sealfin
Copy link
Author

sealfin commented Jan 20, 2014

mhlp format analyser I.out is the result of analysing the .mhlp file which comes with METAL BASIC 1.7.3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment