Path: utzoo!attcan!uunet!husc6!uwvax!dogie!uwmcsd1!csd4.milw.wisc.edu!markh From: markh@csd4.milw.wisc.edu (Mark William Hopkins) Newsgroups: comp.lang.pascal Subject: File semantics Message-ID: <6029@uwmcsd1.UUCP> Date: 17 Jun 88 00:47:49 GMT Sender: daemon@uwmcsd1.UUCP Reply-To: markh@csd4.milw.wisc.edu (Mark William Hopkins) Organization: University of Wisconsin-Milwaukee Lines: 104 A notation is developed here to aid in representing the actions underlying the basic file operations: $ ~~~ READ buffer # ~~~ WRITE buffer @ ~~~ EOF & ~~~ EOLN for text A file can be in one of two modes, which I refer to here as the READ and WRITE modes. In the read mode a file will generally look like: A$ B@ where A and B denote a (possibly empty) string of file components. For example, in the text file T: 'The end'& 'of the '$ 'line'& 'and file'&@ The file has the format: The end of the line and file with the file window located immediately after the $ (T^ = 'l') A file in the WRITE mode has one of the two general forms: A# A# x where A is a (possibly empty) string of file components and x the file buffer. -------------------------------------------------------------------------------- For convenience, the file operations are "functionalized": get(F) becomes F := GET(F) put(F) becomes F := PUT(F) F^ := x becomes F := ADD(F, x) write(F, x) becomes F := WRITE(F, x) ( or PUT(ADD(F, x)) ) read(F, x) becomes x := F^; F := PUT(F) reset(F) becomes F := RESET(F) rewrite(F) becomes F := REWRITE Multiple read's and write's for text files are converted appropriately, e.g. read(textA, X1, X2, X3) becomes read(textA, X1); read(textA, X2); read(textA, X3) Likewise numerical I/O and string and boolean writes are converted into procedures ReadInt(F, x), ReadReal(F, x), WriteInt(F, x:FW), WriteFloat(F, x:FW1), WriteFixed(F, x:FW1:FW2) WriteBoolean(F, x:FW), WriteString(F, x:FW) Example: write(T, 'weeks.') becomes WriteString(T, 'weeks.') which becomes: write(T, 'w'); write(T, 'e'); ...; write(T, '.') or T := WRITE(T, 'w'); ...; T := WRITE(T, '.') The eoln, readln and writeln's of text are converted into the following: eoln(T) becomes T^ = & readln(T) becomes while (T^ <> &) do T := GET(T); T := GET(T) writeln(T) becomes T := WRITE(T, &) Through these means, everything all file operations can be reduced to the functions WRITE, ADD, PUT, GET, RESET, REWRITE, ( )^ and eof. -------------------------------------------------------------------------------- PUT: PUT(A#) : undefined buffer ADD: ADD(A#, x) = A# x PUT(A# y) = Ay# ADD(A# y, x) = A# y PUT(A$ B@) : wrong mode ADD(A$ B@, x) : wrong mode WRITE: WRITE(F, x) = PUT( ADD(F, x) ) REWRITE = # GET: GET(A#), GET(A# x) : wrong mode ( )^: (A#)^ : empty buffer GET(A$ xB@) = Ax$ B@ (A# x)^ = x GET(A$ @) : end of file read error (A$ xB@)^ = x (A$ @)^ : end of file RESET: RESET(A#) = $ A@ eof: eof(A#), eof(A# x) : wrong mode RESET(A# x) = $ A@ eof(A$ xB@) = false RESET(A$ B@) = $ AB@ eof(A$ @) = true