home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / lang / pascal / 8498 < prev    next >
Encoding:
Internet Message Format  |  1993-01-24  |  1.7 KB

  1. Path: sparky!uunet!paladin.american.edu!gatech!news.ans.net!cmcl2!adm!news
  2. From: ISAACSON@husc3.harvard.edu (RON ISAACSON)
  3. Newsgroups: comp.lang.pascal
  4. Subject: Re: Look-a-head (input^) in TPASCAL...???
  5. Message-ID: <35202@adm.brl.mil>
  6. Date: 24 Jan 93 22:51:11 GMT
  7. Sender: news@adm.brl.mil
  8. Lines: 32
  9.  
  10. =>          Would anyone have a look-a-head routine that does the same
  11. => thing as the UNIX 'pc' compiler 'input^' because the TPASCAL gives
  12. => me an error message when I try to use this in my souce code?  Thanks
  13. => in advance to all that reply to this post.
  14.  
  15. That "file buffer variable", as it's called, is something I missed
  16. sorely when I went over to Turbo Pascal. I wrote a little function
  17. to replace it. This thing is by no means foolproof, and there are
  18. probably several modifications that could be made, but in general
  19. for just looking one byte ahead in a file this function works fine.
  20.  
  21. function filebuff(var infile : text) : char;
  22.   var
  23.     fp : longint;
  24.     ch : char;
  25.   begin
  26.     {$I-}                  { turn off i/o checking, end of file, etc.    }
  27.     fp := filepos(infile); { get the current position into the open file }
  28.     seek(infile, fp + 1);  { move the pointer ahead by one               }
  29.     read(infile, ch);      { grab a character, one ahead of the previous }
  30.     seek(infile, fp);      { go back to where we were before             }
  31.     {$I+}                  { turn i/o checking back on before exiting    }
  32.     filebuff := ch;
  33.   end;
  34.  
  35. This is the generic non-destructive non-pointer-moving file read
  36. routine. If you need something more elaborate, hopefully you get
  37. the general idea from this, and you can modify it to suit your
  38. needs. Good luck!
  39.  
  40.  - Ron Isaacson, Isaacson@Husc3.Harvard.Edu
  41.  
  42.