info-mac@uw-beaver.UUCP (08/21/84)
From: DSMITH@RUTGERS.ARPA We will be using MacPascal as the coding tool for the first two undergraduate course in CS. This requires that students turn in assignments by presenting a listing of their program, a listing of the test data on which it was run, and the output produced. In order to achieve these goals we have, in the past, used the file i/o available in Pascal. Can this be done in MacPascal? I have been unable to find any documentation which asserts or denies the existance of file handling capabilities. Specifically, 1 - Can files be created under program control? If so, where may I find a description of the syntax for doing so? 2 - Can a file be read under program control? If so , ... 3 - Is it possible to print a file created by a MacPascal program using the print facility inside the MacPascal file window? Any inforamtion would be greatly appreciated. Don -------
info-mac@uw-beaver (info-mac) (08/22/84)
From: Stuart Reges <REGES@SU-SCORE.ARPA>
I run the intro Pascal courses at Stanford, so I am looking at MacPascal as
well.
I have been playing with external files in MacPascal and find they pretty much
do the right thing. Files created by one program can be read as data for other
programs, even non-TEXT files. The only trick involved in creating external
files is to give a name to the file when using RESET or REWRITE, as in:
rewrite (outfile, 'stuff');
reset (infile, 'stuff');
MacPascal doesn't like you to reassign OUTPUT. It is possible to do so,
however, if you first CLOSE it:
close (output);
rewrite (output, 'stuff');
Apparently it assigns OUTPUT to the TEXT window, so you have to undo this
first. The final release might not require this kludge.
One nice file demo I like is to have a structure like this:
type person = RECORD
name: string;
age : integer;
sex : CHAR;
end;
var f: file of person;
And then to use the Observe window to watch f^.name, f^.age and f^.sex as you
do a series of GETs on a file you have created. There are a few minor bugs in
the beta release, but I expect these will be fixed.
About printing, there is nothing really difficult about it, so I'm not sure why
there is no facility for it. For some reason I had taken this for granted up
to now. The documentation for the beta release makes no mention of it and
there seems to be no facility for doing it directly.
I have four suggestions. Here they are, ranked from worst to best:
o You can generate an external file and then use MacPascal to OPEN it
and PRINT it. The problem is that it tries to format it as a
program.
o You can generate an external file and then use MacWrite to OPEN it
and PRINT it. This requires many disk swaps if you have only one
drive.
o You can directly assign the output channel to the printer by saying
something like:
rewrite (outfile, 'printer:');
or, as explained above, if you are using OUTPUT you can use this
kludge:
close (output);
rewrite (output, 'printer:');
o You can generate an external file and then use the following program
in MacPascal to print it:
program Print (input, output);
var FileName, OneLine: string;
infile, outfile : text;
begin
write ('File to print? ');
readln (FileName);
reset (infile, FileName);
rewrite (outfile, 'printer:');
while not eof (infile) do begin
readln (infile, OneLine);
writeln (outfile, OneLine);
end;
writeln ('All done now.');
end.
I haven't actually tested the last two of these because I don't have a printer
handy. I will test them tonight and let you know. I'm pretty sure they work,
though, because there seems to be a device called "PRINTER:".
-------info-mac@uw-beaver (info-mac) (08/29/84)
From: singer@harvard.ARPA (Andrew Singer)
Stuart Reges' responses concerning file usage and printing from
Macintosh Pascal are quite correct. Some points, however:
1. Having to close INPUT and/or OUTPUT before reopening them to
disk files or devices is not a "kludge". These files are
implicitly opened at program startup time to the keyboard
and TEXT window respectively, and must be closed before
they can be reopened. The following, however, is a kludge:
If you close OUTPUT, say, reopen it on a file or device
and subsequently close it again, OUTPUT (or INPUT) will
implicitly be reopened to the TEXT window (or the keyboard).
Unfortunately, once you've gotten this far you cannot
subsequently close and reopen it again.
2. No variation on PRINT, PRINTING, or PRINTER will appear in the
index for the reference manual. The documentation had to be
prepared last March and, while it was possible to patch in
"extra features" at the last minute, making changes to the
index would have been more difficult than you could imagine.
I don't know who at Think told Stuart Reges otherwise, but
that's the way it is.
3. The final release copy of Macintosh Pascal will include two
utility propgrams (written in Macintosh Pascal, of course):
a text file printing utility and a mini text file editor.
The print utility is essentially the same as Stuart's program,
except that it additionally sets up the printer to print in a
proportionally spaced font and to use vertical forms that
result in a "perf skip" of about 6 lines. Those who would
prefer to print with a monospaced font can, with the aid
of an ImageWriter manual, modify the program appropriately.
The text editor is fairly simple and straightforward to use
and, as a program, probably impossible to understand or modify.
It can be used not only to examine text files created by
Macintosh Pascal, but also to create data files to be used as
program input. Be warned, however, that it was written in some
haste. Certain safeguards that should have been taken, to keep
the Macintosh Memory Manager from blowing you away, were not in
fact taken. If you have a substantial amount of data to edit, I
recommend that you back up the file first. If you have a copy of
MacWrite, I recommend using that even more strongly. You can
make a MacWrite file readable by Macintosh Pascal by using the
"Save As..." menu item and checking the "Text Only" indicator
in the dialog box that it will present to you.
Jon F. Hueras, Think Technologies, Inc.
<singer@harvard>