[comp.lang.pascal] Printing a log of students' exercises revisited

ts@uwasa.fi (Timo Salmi) (10/31/90)

2. *****
 Q: I want to have a printed documentation of my students' Turbo
Pascal program exercises. How is all input and output directed also
to the printer?

 A1: Use a screen capturing program to put everything that comes
onto the screen into a file, and print the file. See FAQ.TXT in
/pc/ts/tsfaq11.arc (or whatever version number is the latest) for
more about these programs. Available by anonymous ftp or mail server
from uwasa.fi.

 A2: See the code in TSPAS.NWS (item: Redirecting writes to the
printer) in the /pc/ts/tspas22.arc (or whatever is the latest
version number) Turbo Pascal units package. Alternatively use USECON
and USEPRN routines in the TSUNTG unit of the same package.

 A3: The really elegant solution to the problem of getting a logfile
(or a printed list) of a Turbo Pascal run is to rewrite the
write(ln) and read(ln) device driver functions. In itself writing
such driver redirections is very advanced Turbo Pascal programming,
but when the programming has once been done, the system is extremely
easy to use as many times as you like. It goes like this. The driver
redirections are programmed into a unit (say, tpulog or tpuprn). All
that is needed after that is to include the following uses statement
into the program (the target program) which has to be logged:
      uses TPULOG;    ( or )    uses TPUPRN;
This is all there is to it. Just adding one simple line to the
target program. (If you call any other units, "uses tpulog" must
come AFTER the system units (eg Dos), but BEFORE any which you may
define yourself.)
   The reason that I have named two units here instead of just one
in the above example is that the preferred log for the target
program may be a logfile or the printer. The better solution of
these two is to use the logfile option, and then print it. The
reason is simple. If the target program itself prints something,
your printout will look confused.
   The logging also has obvious limitations. It works for standard
input and output (read(ln) and write(ln)) only. 1) It does not
support graphics, in other words it is for the textmode. 2) It does
not support direct (Crt) screen writes. 3) And, naturally it only
shows the input and output that comes to the screen. Not any other
input or output, such as from or to a file. 4) Furthermore, you are
not allowed to reassign input or output. Statements like assign
(output, '') will result in a crash, because the rewritten output
device redirections are invalidated by such statements. 5) The
device on the default drive must not be write protected, since else
the logfile cannot be written to it. But as it is, it is perfectly
suited for logging students' Turbo Pascal escapades.
   It is advisable first to test and run your target program without
"tpulog", so that if you get any strange errors you'll know whether
they are caused by the logging.
   Where to get such a unit. The code can be found in Michael
Tischer (1990), Turbo Pascal Internals, Abacus, Section 4.2. Next a
few of my own tips on this unit Tischer calls Prot. 1) The code is
in incorrect order. The code that is listed on pages 142 - 145 goes
between pages 139 and 140. 2) You can change the logfile name (const
prot_name) to lpt1 for a printed list of the target program run. In
that case it is advisable to include a test for the online status of
the printer within Tischer's unit. 3) I see no reason why the two
lines in Tischer's interface section couldn't be transferred to the
implementation section. Why have any global definitions?  But all in
all, it works like magic!

...................................................................
Prof. Timo Salmi        (Moderating at anon. ftp site 128.214.12.3)
School of Business Studies, University of Vaasa, SF-65101, Finland
Internet: ts@chyde.uwasa.fi Funet: gado::salmi Bitnet: salmi@finfun