allbery@ncoast.UUCP (Brandon S. Allbery) (05/31/87)
I'm trying to write a program which will read standard input or files named on the command line. (It's a program to expand tabs and formfeeds for my DuMbPrinter-105.) The main block seemed simple enough: begin if ParamCount = 0 then Process(Input) else for arg := 1 to ParamCount do begin Assign(Infile, ParamStr(arg)); Reset(Infile); Process(Infile); Close(Infile) end end. BUT -- My Turbo Pascal (3.01A) doesn't seem to recognize Input as a file. If I leave it undeclared, I get a compile error `unknown identifier or syntax error'; if I declare it, I get I/O error 02 (file not reset). Is the standard input file available as a file variable? I'd rather not have two versions of the Process procedure, one for standard input and one for a file. Thanks in advance, ++Brando -- Copyright (C) 1987 Brandon S. Allbery. Redistribution permitted only if the redistributor permits further redistribution. ---- Moderator for comp.sources.misc ---- Brandon S. Allbery {decvax,cbatt,cbosgd}!cwruecmp!ncoast!allbery Tridelta Industries {ames,mit-eddie,talcott}!necntc!ncoast!allbery 7350 Corporate Blvd. necntc!ncoast!allbery@harvard.HARVARD.EDU Mentor, OH 44060 +01 216 255 1080 (also eddie.MIT.EDU)
rassilon@eddie.MIT.EDU (Brian Preble) (06/01/87)
In article <2575@ncoast.UUCP> allbery@ncoast.UUCP (Brandon S. Allbery) writes: >I'm trying to write a program which will read standard input or files named >on the command line. (It's a program to expand tabs and formfeeds for my >DuMbPrinter-105.) The main block seemed simple enough: > ... code deleted ... > >BUT -- My Turbo Pascal (3.01A) doesn't seem to recognize Input as a file. This is true, the device name you're looking for is CON, as in Process(CON). Also, make sure that you don't try to close it. (Nothing SHOULD happen but you never know.) In addition, make sure that you've included the compiler directive B+. I know this is the default setting but it helps to make sure. This way, if you ever have to compile your software on a machine with different defaults you know it will run correctly. The main difference between B+ and B- is that B+ assigns STDIN and STDOUT to the console whereas B- assigns them to a terminal (TRM). -- Rassilon DISCLAIMER Any resemblance between the above views and those of my employer, my terminal, or the view out my window are purely coincidental. Any resemblance between the above and my own views is non-deterministic. The question of the existence of views in the absence of anyone to hold them is left as an exercise for the reader. The question of the existence of the reader is left as an exercise for the second god coefficient. (A discussion of non-orthogonal, non-integrel polytheism is beyond the scope of this article.)
rmarks@bbking.UUCP (06/02/87)
Try using the {$G2048,D-} compiler directive. Then ReadLn(..) with no file specified will read from StdInput.