home *** CD-ROM | disk | FTP | other *** search
-
- **** Question about CONCURRENT i/o to the SAME file.
-
- I am trying to do the following in Franz-Lisp:-
- I have a file which has some stuff in it (= it is non-empty).
- First, I want to *append* something to it (that is, I want
- to write something FROM its end-of-file; I want to preserve
- its original contents).
- Then, I want to read something from the start-of-the-file.
- Then, I want to *append* something-new to the new-version
- of this file.
-
- Now, I have tried the following:-
- Lets say that the file name is fn.
- TRY #1 : setq portout (outfile 'fn)
- fseek portout
- (filestat:size (filestat 'fn)) ;Filestat take only 2 param.
- 0)
- (defun p-raj () (patom "Hi-raj" portout))
- (p-raj)
- (p-raj)
- ----------------
- The problem with this is that the
- >setq portout (outfile 'fn)
- seems to AUTOMATICALLY and PERMANENTLY
- put the r/w-cursor at the START of the file
- (without my permission). Also, once this is
- done, FSEEK become impotent. It will always
- send back a zero. Also, a FILEPOS has no effect.
- Basically, you cannot move the @<@!!# cursor
- unless you write (and therefore overwrite the
- original contents) something to the file.
- Note however that, if I had not done
- setq portout (outfile 'fn)
- then,
- >(filestat:size (filestat 'fn))
- does return the true (unix) size of the file.
- @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
- TRY #2 : (setq inout (infile 'fn))
- (fileopen 'fn 'w+) ; FILEOPEN takes only 2 parameters.
- ; you can also try the following
- ; (fileopen 'fn 'a+)
- (filepos portio)
- [this gives back a zero, which is ok.]
- (filestat:size (filestat 'junk))
- [this does give its true size, say 232 blocks.]
- (filepos portio (filestat:size (filestat 'junk)))
- [this does put the r/w-cursor at 232.]
- (filepos portio)
- [this confirms that.]
- (patom "IS this really going to get appended ?" portio)
- [this prints the above string on the TERMINAL,
- not onto the file fn.]
- (filepos portio)
- [the cursor is STILL at 232.]
- -----------
- Basically, I think that the reason it wont write to the file fn,
- in this second case is that the <inout> was defined
- for reading and not for writing.
- {Is this the correct impression ?}
-
- [I have tried many many different permutations also.]
-
- SO, in brief, a <setq pi (outfile..>
- automatically puts the cursor at the start-of-the-file;
- and the FILEOPEN, FILEPOS, FSEEK dont seem to have any effect.
- and, a <setq po (infile...>
- never allows me to write onto the file atall
- even if I do a <FILEOPEN 'fn 'w+>.
-
- >>>>>> QUESTION: What am I missing here ?? <<<<<<
-
- Thanks in advance.
-
-
- --- raj doshi, University of Minnesota
-
- doshi%umn.csnet@csnet-relay.arpa
-
- Raj Doshi
- 2030 Wilson Avenue, Apt #27
- Saint Paul, MN 55119
- (612)-739-2353
- (612)-739-2151
-
-
-
-
-