home *** CD-ROM | disk | FTP | other *** search
- { General utility routines for corporate records }
-
- procedure menu;
- begin
- writeln('Choices:');
- writeln('R');
- writeln('N');
- writeln('Q');
- writeln('I');
- end;
-
- function GetCommand : char;
- var
- ch : char;
- begin
- readln( ch );
- if ch in ['a'..'z'] then
- GetCommand := chr( ord(ch) - ord('a') + ord('A') )
- else
- GetCommand := ch;
- end;
-
- function prompt( s : string ) : boolean;
- var
- ch : char;
- begin
- write( s, '?' );
- read( ch );
- prompt := ch in ['y','Y'];
- end;
-
- function GetNewFileName( promptstring : string; default : string ) : string;
- { Get a valid filename. Warn if clobbering existing file. }
- var
- filename : string;
- g : text;
- errorcode: integer;
- begin
- repeat
- write( promptstring, '[', default, '] ' );
- readln( filename );
- if filename = '' then
- if default = abort then
- halt
- else
- filename := default;
- if filename = abort then
- halt;
- {$I-}
- reset( g, filename );
- {$I+}
- errorCode := ioResult;
- close( g );
- if errorCode = 0 then
- begin
- write('File already exists! ');
- if prompt('Overwrite? ') then
- errorcode := FileNotFound;
- end; {if}
- until errorcode = FileNotFound;
- GetNewFilename := filename;
- end; {GetNewFilename}
-
- function GetOldFileName( promptstring : string; default : string ) : string;
- var
- filename : string;
- f : text;
- errorcode: integer;
- begin
- repeat
- write( promptstring, '[', default, '] ' );
- readln( filename );
- if filename = '' then
- filename := default;
- if filename = abort then
- halt;
- {$I-}
- reset( f, filename );
- {$I+}
- errorCode := ioResult;
- close( f );
- if errorCode <> 0 then writeln('Error ', errorCode, ' opening file!');
- until errorCode = 0;
- GetOldFileName := filename;
- end; {GetOldFileName}
-
- procedure skip( var f : text; n : integer);
- var
- ch : char;
- begin
- for n := 1 to n do
- read( f, ch );
- end; {skip}
-
- function ReadNumber( var f : text) : integer;
- { Read the next number from text file f. If there is no next number,
- return 0. Ignore commas.}
- var
- number : integer;
- ch : char;
- i : integer;
- begin
- number := 0;
- if not eof( f ) then
- begin
- read( f, ch );
- while (ch <= ' ') and (not eof(f)) do read( f, ch );
- repeat
- if ch = ',' then
- read( f, ch );
- if ch in ['0'..'9'] then
- number := number * 10 + ord( ch ) - ord( '0' );
- if not eof( f ) then
- read( f, ch )
- else
- ch := #26;
- until (not (ch in ['0'..'9']));
- if ch = '[' then {hit [PAUSE]^h^h^h^h^h^h^h}
- skip( f, 32 );
- end;
- ReadNumber := number;
- end;
-
- procedure enqueue( var c : corp; p : planet );
- var
- temp : planetptr;
- begin
- c.NumPlanets := c.NumPlanets + 1;
- new( temp );
- temp^ := p;
- if c.numplanets=0 then
- c.territory.front := temp
- else
- c.territory.rear^.next := temp;
- c.territory.rear := temp;
- end;