home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / lang / pascal / 5315 < prev    next >
Encoding:
Text File  |  1992-09-10  |  1.6 KB  |  46 lines

  1. Xref: sparky comp.lang.pascal:5315 alt.msdos.programmer:2347
  2. Newsgroups: comp.lang.pascal,alt.msdos.programmer
  3. Path: sparky!uunet!cs.utexas.edu!torn!news.ccs.queensu.ca!slip207.telnet1.QueensU.CA!dmurdoch
  4. From: dmurdoch@mast.queensu.ca (Duncan Murdoch)
  5. Subject: Re: 3 questions
  6. Message-ID: <dmurdoch.70.716177266@mast.queensu.ca>
  7. Lines: 33
  8. Sender: news@knot.ccs.queensu.ca (Netnews control)
  9. Organization: Queen's University
  10. References: <18ot9rINN67t@matt.ksu.ksu.edu>
  11. Date: Fri, 11 Sep 1992 02:07:46 GMT
  12.  
  13. In article <18ot9rINN67t@matt.ksu.ksu.edu> holland@matt.ksu.ksu.edu (Rich 
  14. Holland) writes:
  15. >Question 3:
  16. >-----------
  17. >  I know how to detect if redirection is in effect (so don't send me the
  18. >  FAQ, Timo!  *grin*), but how do I let my programs use this?  I'd like
  19. >  to write a "File filter" that could be used like this:
  20. >
  21. >    type filename.txt | myfilter > newfile.txt     
  22. >
  23. >               or
  24. >
  25. >    myfilter filename.txt > newfile.txt
  26. >
  27. >  In other words, I'd like to figure out where my input is coming from, 
  28. >  and open a file if necessary, or just take what's passed to me via the
  29. >  pipe (if there is one)...does that make sense?
  30.  
  31. If your program's calling syntax is really that simple, then a nice trick to 
  32. get what you want is the following:
  33.  
  34.   assign(input,paramstr(1));
  35.   reset(input);
  36.  
  37. This way, if your program is called with no parameters, it reads from 
  38. standard input; if it has one parameter, it reads from that.  If you want 
  39. more complicated syntax (e.g. option flags), then you'll have to do the same 
  40. sort of thing in a more complicated way.
  41.  
  42. P.S.  Can't help you with Q1 and Q2!
  43.  
  44. Duncan Murdoch
  45. dmurdoch@mast.queensu.ca
  46.