class FILE < $OSTREAM
****
Buffered file. Uses the C standard "FILE". To avoid buffering penalties, read or write entire files using an FSTR. For systems which do funny things for linefeeds and cntl-z, this is a text file, not a binary finle, for which you should use BFILE.
___f:_FILE_:=__FILE::open_for_read("test_file");
___line:_STR_:=_f.get_line;_--_gets_the_next_line
__
A more convenient way to parse files is to read them into a string and then use a STR_CURSOR on them. This may even have significantly better performance
___f2:_FILE_:=_FILE::open_for_read("test_file");
___whole_file:_STR_:=_f2.str;__--_The_whole_file_as_a_string
___cursor:_STR_CURSOR_:=_whole_file.cursor;
___next_integer:_INT_:=_cursor.get_int;_--_Get_an_integer_from_the_file
_____________________--_string
___next_word:_STR_:=_cursor.get_word;____--_Read_a_word_from_the_file
_


Flattened version is here

Ancestors
$OSTREAM



Public


Features
end;
return r
end;
**** Delete a file.
end;
**** The size of self in characters. -1 for error.
return self;
r::=new; r.fp:=RUNTIME::fopen(nm,"w+");
open_for_update(nm:STR):SAME
**** A new object representing the file named `nm' accessible for reading and writing.
end;
current_loc:INT
**** The current location in the file.
end;
fsize::=size;
r.loc:=bsize;
return #FSTR(1);
seek_from_front(start);
end;
**** Create a new file with name `nm' and default permissions. File is truncated and opened for writing.
open_for_append(nm:STR):SAME
**** A new object representing the file named `nm' accessible for appending. File is created if not existing.
end;
r::=new;
r.fp:=stderr_macro;
**** This is a hack, to get around the void representation of "".
RUNTIME::fputc(c,fp)
end;
**** This is a hack, to get around the void representation of "".
get_up_to(sc:CHAR):STR
**** A string buffer containing the characters up to the next c.
return get_line.str;
**** Append the string "s" to the file
end;
end;
builtin FILE_CLEAR;
**** for reading and appending. File is created if not existing.
**** A file object for stdin.
stdout_macro:EXT_OB
stdout:SAME
**** A file object for stdout.
stderr_macro:EXT_OB
seek_from_front(current);
plus(s);
RUNTIME::fputc(c,fp);


Private

fs::=fwrite_str(ss,ss.length,fp)
**** cases are handled by the proper overloading. Hence, this is the most general case and we call str. BV (4/26/96)