home *** CD-ROM | disk | FTP | other *** search
-
- (*
- * readbas.inc - Library to read "basic" format data files
- *
- * (C) 1987 Samuel H. Smith, 20-Jun-87 (rev. 20-Dec-87)
- *
- *)
-
-
- (* --------------------------------------------------------- *)
- procedure openfile(name: anystring);
- (* open a file for "basic" style parsing *)
- begin
- if length(name) = 0 then
- begin
- ok := false;
- exit;
- end;
-
- assignText(curfd,name);
- {$i-} reset(curfd); {$i+}
- ok := ioresult = 0;
- end;
-
-
- (* --------------------------------------------------------- *)
- function endfile: boolean;
- (* check for end of file on the current data file *)
- begin
- endfile := eof(curfd);
- end;
-
-
-
- (* --------------------------------------------------------- *)
- procedure closefile;
- (* close the data file *)
- begin
- close(curfd);
- end;
-
-
- (* --------------------------------------------------------- *)
- procedure getline(var line: longstring;
- len: integer{;
- what: anystring});
- (* get a full line from the "basic" file *)
- var
- buf: longstring;
-
- begin
- repeat
- if endfile then
- buf := 'EOF'
- else
- readln(curfd,buf);
- until line[1] <> '#';
-
- line := copy(buf,1,len);
-
- { if TESTING then writeln(con,' ',what,' = ',line);
- if length(buf) > len then writeln(con,what,' TOO LONG, buf=',buf); }
- end;
-
-
- (* --------------------------------------------------------- *)
- procedure getstr(var str: longstring;
- len: integer{;
- what: anystring});
- (* get a string of characters from the "basic" file. a string ends in
- either "," or crlf *)
- var
- c: char;
- buf: longstring;
- label
- comment;
-
- begin
- if endfile then
- buf := 'EOF'
- else
-
- begin
- comment:
- buf := '';
- if endfile then
- c := #26
- else
- read(curfd,c);
-
- while (c = ' ') do
- read(curfd,c);
-
- if c = '#' then
- begin
- readln(curfd,buf);
- goto comment;
- end;
-
- while (c <> ',') and (c <> #13) and (c <> #26) do
- begin
- inc(buf[0]);
- buf[length(buf)] := c;
- read(curfd,c);
- end;
-
- if c = #13 then
- read(curfd,c);
- end;
-
- str := copy(buf,1,len);
-
- { if TESTING and (what<>'') then writeln(con,' ',what,' = ',str);
- if length(buf) > len then writeln(con,what,' TOO LONG, buf=',buf); }
- end;
-
-
- (* --------------------------------------------------------- *)
- procedure getstrd(var str: longstring);
- (* get a directory string from the "basic" file. check special case
- for no trailing "\" in the root directory *)
- begin
- getstr(str,65);
- stoupper(str);
-
- if str[length(str)] = '\' then
- dec(str[0]); {remove trailing "\" from ramdisks and such}
- end;
-
-
- (* --------------------------------------------------------- *)
- procedure getint(var i: integer{;
- what: anystring});
- (* get a string and convert it into an integer *)
- var
- buf: longstring;
-
- begin
- getstr(buf,sizeof(buf));
- i := atoi(buf);
-
- { if TESTING then writeln(con,' ',what,' = ',i);}
- end;
-
-
- (* --------------------------------------------------------- *)
- procedure getflag(var f: boolean{;
- what: anystring});
- (* get a string and convert it into a true/false flag *)
- var
- buf: longstring;
-
- begin
- getstr(buf,sizeof(buf));
- f := (buf[1] = '-') or (buf[1] = 'Y');
-
- { if TESTING then writeln(con,' ',what,' = ',f); }
- end;
-
-
- (* --------------------------------------------------------- *)
- procedure vgetstr(var str: varstring);
- (* get a variable allocation string of characters from the "basic"
- file. a string ends in either "," or crlf *)
- var
- temp: longstring;
- begin
- getstr(temp,sizeof(temp)-1);
- savestr(str,temp);
- end;
-
-
- (* --------------------------------------------------------- *)
- procedure vgetstrd(var str: varstring);
- (* get a variable allocation string and format as a directory *)
- var
- temp: longstring;
- begin
- getstr(temp,sizeof(temp));
- if temp[length(temp)] = '\' then
- dec(temp[0]); {remove trailing "\" from ramdisks and such}
- savestr(str,temp);
- end;
-
-
-