[comp.lang.pascal] Read Files, How?

jlg0805@uxa.cso.uiuc.edu (05/30/90)

On standard Pascal, how can one interactively input a file name, then
ask the program to read the file; ask the program to load another 
file and repeat the same thing.

as my understanding, the external file name shoud appear in the program
header.  However, this only works if actually there is a file with that
very name.  If files have different names, then the machine gives an
error. (mine is a sequent running unix), telling me "file not existent" 
or something like that.

how to solve this problem? i hope it is not that one recompiles the 
program for each new file.


--The profs never teach useful practical things but stuff like AVL trees
  in class. :-(

J.Liang
jlg0805@uxa.cso.uiuc.edu


 

bigelow@hpfcso.HP.COM (Jim Bigelow) (05/31/90)

jlg0805@uxa.cso.uiuc.edu / 11:17 pm  May 29, 1990 / asked:

> On standard Pascal, how can one interactively input a file name, then
> ask the program to read the file; ask the program to load another 
> file and repeat the same thing.

HP pascal on UNIX associates the arguments on the command line with
the files declared in the program header.

Jim Bigelow
S300 HP Pascal
Colorado Language Lab
Hewlett Packard

reagan@hiyall.enet.dec.com (John R. Reagan) (05/31/90)

In article <50800002@uxa.cso.uiuc.edu>, jlg0805@uxa.cso.uiuc.edu writes...
> 
>On standard Pascal, how can one interactively input a file name, then
>ask the program to read the file; ask the program to load another 
>file and repeat the same thing.
> 
>as my understanding, the external file name shoud appear in the program
>header.  However, this only works if actually there is a file with that
>very name.  If files have different names, then the machine gives an
>error. (mine is a sequent running unix), telling me "file not existent" 
>or something like that.
> 
>how to solve this problem? i hope it is not that one recompiles the 
>program for each new file.
> 
> 
>--The profs never teach useful practical things but stuff like AVL trees
>  in class. :-(
> 
>J.Liang
>jlg0805@uxa.cso.uiuc.edu
> 
> 
> 

Unextended Pascal (aka classic standard Pascal) had static binding
of files in the program header to external files in the file system.
It is upto an implementation to tell you how to set up this binding 
(like setting up aliases or environment variables, etc.)  However, it 
is still static for that invocation of the image.  You want dynamic binding 
(the ability to break a binding and recreate a new one in the same program 
based on some user input).

The sad news is that you can't do that in old unextended Pascal.  You'll
have to rely on vendor extensions (such as OPEN routines, etc.) or run
the program over again with a different static binding (I wouldn't think
you'd have to recompile).

In the Extended Pascal standard, there are now new routines called
BIND and UNBIND that perform much the same concept as some OPEN extensions.
Extended Pascal's binding allows you to do exactly what you want (of course
all file operations are implementation-defined in the sense that filenames
on one system might not be the same on other system...).

---
John Reagan
Digital Equipment Corporation
reagan@hiyall.dec.com
---

steve@taumet.COM (Stephen Clamage) (05/31/90)

In article <50800002@uxa.cso.uiuc.edu> jlg0805@uxa.cso.uiuc.edu writes:
>
>On standard Pascal, how can one interactively input a file name, then
>ask the program to read the file; ask the program to load another 
>file and repeat the same thing.
>how to solve this problem? i hope it is not that one recompiles the 
>program for each new file.

This is something which varies among different Pascal implementations.
You have to read the manual for each different compiler to find out
how best to do it.  I know of no compilers where mentioning the file
name in the program header is either necessary or sufficient.

>--The profs never teach useful practical things but stuff like AVL trees
>  in class. :-(

Pardon me, but I don't think you should be going to college to find out
how to open a file in, say, Turbo Pascal.  You can get that information
in 5 minutes or less by glancing at the manual.

If you get a thorough grounding in theory, you can write any kind of
program on any kind of system.  While you may never need to implement
an AVL tree, you still learn a lot about how to think about programming
while studying them.
-- 

Steve Clamage, TauMetric Corp, steve@taumet.com

toriver@solan.unit.no (Tor Iver Wilhelmsen) (06/01/90)

You could try to COPY to the console and PIPE through your program.
For a binary file, this would look like:
   COPY datafile.bin con /b | yourprog
Disclaimer: I have not tried this myself, so I do not know if it will
work.
--------------------------------------------------------------------
"My plan worked! How did that happen?" - Groo, very occasionaly
toriver@solan.unit.no   pumpkin@norunit.sintef.no
pumpkin@norunit.bitnet
--------------------------------------------------------------------