home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / bsd_srcs / usr.bin / lisp / lispnews / text0379.txt < prev    next >
Encoding:
Text File  |  1985-11-10  |  3.4 KB  |  89 lines

  1.  
  2. **** Question about CONCURRENT i/o to the SAME file.
  3.  
  4. I am trying to do the following in Franz-Lisp:-
  5.      I have a file which has some stuff in it (= it is non-empty).
  6.      First, I want to  *append* something to it (that is, I want
  7.         to write something FROM its end-of-file;  I want to preserve
  8.         its original contents).
  9.      Then, I want to read something from the start-of-the-file.
  10.      Then, I want to  *append*  something-new to the new-version
  11.         of this file.
  12.  
  13. Now, I have tried the following:-
  14.      Lets say that the file name is fn.
  15.      TRY #1 :  setq portout (outfile 'fn)
  16.                fseek portout 
  17.                      (filestat:size (filestat 'fn)) ;Filestat take only 2 param.
  18.                      0)
  19.                (defun p-raj () (patom "Hi-raj" portout))
  20.                (p-raj) 
  21.                (p-raj)
  22.                ----------------
  23.                The problem with this is that the
  24.                     >setq portout (outfile 'fn)
  25.                     seems to AUTOMATICALLY and PERMANENTLY 
  26.                     put the r/w-cursor at the START of the file
  27.                     (without my permission).  Also, once this is
  28.                     done, FSEEK become impotent.  It will always
  29.                     send back a zero.  Also, a FILEPOS has no effect.
  30.                     Basically, you cannot move the @<@!!# cursor
  31.                     unless you write  (and therefore overwrite the
  32.                     original contents) something to the file.
  33.                        Note however that, if I had not done
  34.                        setq portout (outfile 'fn)
  35.                        then, 
  36.                            >(filestat:size (filestat 'fn))
  37.                        does return the true (unix) size of the file.
  38.                @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  39.      TRY #2 :  (setq inout (infile 'fn))
  40.                (fileopen 'fn 'w+)  ; FILEOPEN takes only 2 parameters.
  41.                ; you can also try the following
  42.                ; (fileopen 'fn 'a+)
  43.                (filepos portio)
  44.            [this gives back a zero, which is ok.]
  45.                (filestat:size (filestat 'junk))
  46.            [this does give its true size, say 232 blocks.]
  47.                (filepos portio (filestat:size (filestat 'junk)))
  48.            [this does put the r/w-cursor at 232.]
  49.                (filepos portio)
  50.                    [this confirms that.]
  51.                (patom "IS this really going to get appended ?" portio)
  52.            [this prints the above string on the TERMINAL,
  53.             not onto the file fn.]
  54.                (filepos portio)
  55.            [the cursor is STILL at 232.]
  56.            -----------
  57.            Basically, I think that the reason it wont write to the file fn,
  58.            in this second case is that the <inout> was defined
  59.            for reading and not for writing.
  60.            {Is this the correct impression ?}
  61.  
  62. [I have tried many many different permutations also.]
  63.  
  64. SO, in brief, a <setq pi (outfile..>
  65.          automatically puts the cursor at the start-of-the-file;
  66.     and the FILEOPEN, FILEPOS, FSEEK dont seem to have any effect.
  67.     and, a <setq po (infile...> 
  68.      never allows me to write onto the file atall
  69.      even if I do a  <FILEOPEN 'fn 'w+>.
  70.  
  71. >>>>>>   QUESTION: What am I missing here ??  <<<<<<
  72.  
  73. Thanks in advance. 
  74.  
  75.  
  76. --- raj doshi,  University of Minnesota
  77.       
  78.                 doshi%umn.csnet@csnet-relay.arpa
  79.                
  80.         Raj Doshi
  81.         2030 Wilson Avenue, Apt #27
  82.         Saint Paul, MN 55119
  83.         (612)-739-2353
  84.         (612)-739-2151
  85.  
  86.  
  87.  
  88.  
  89.