Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cornell!rochester!uhura.cc.rochester.edu!ur-valhalla!chan From: chan@galaxy.ee.rochester.edu (Daniel Chan) Newsgroups: comp.lang.pascal Subject: Re: DUEL OUTPUT Message-ID: <1868@valhalla.ee.rochester.edu> Date: 5 Mar 89 05:32:37 GMT References: <18461@adm.BRL.MIL> <1265@sdcc15.ucsd.edu> Sender: usenet@valhalla.ee.rochester.edu Reply-To: chan@ee.rochester.edu (Daniel Chan) Organization: UR Dept. of Electrical Engg, Rochester NY 14627 Lines: 84 >From: pa1804@sdcc15.ucsd.edu (pa1804) Date: 4 Mar 89 23:41:57 GMT Organization: University of California, San Diego >In article <18461@adm.BRL.MIL>, pmancini@lynx.northeastern.edu writes: > > I would like to know what is (if possible) standard > implementation in PASCAL to send text output simultaneously > to the screen and to a LST device or file. I hate having to > write lines twice, such as; > > writeln('abcdefg12345'); {goes to screen} > writeln(lst,'abcdefg12345'); {goes to printer} > > Is there anyway I can send the output to both without > writing the line twice? In programs which print a lot of text > to the screen and the printer it gets very tedious typing everything > over and over again. ! You can write a procedure that will send the output to both ! the screen and the other output device: ! ! ! ! ! Procedure WriteAll { pass variables that are necessary } ! ! Begin { WriteAll } ! ! writeln(argument); { this goes to the screen } ! ! writeln(OutputDevice1, argument); ! { this goes to OutputDevice1 } ! ! writeln(OutputDevice2, argument); ! { this goes to OutputDevice2} ! ! end; { WriteAll } ! ! .. ! .. ! .. ! .. ! ! begin { main program } ! ! .. ! .. ! WriteAll; ( variables ) ! .. ! .. ! end. { main program } ! ! ! ! ! As you can see, by using the procedure WriteAll you can ! send output to as many destinations as you want. ! ! ! ! George Chen ! ! pa1804@sdcc15.UCSD.EDU PO BOX 4474 La Jolla, CA 92037 The problem is not that simple when you have something like: writeln ("abcdefg34"); writeln (345, "abcd"); writeln ("345", 1.2E-3); It's also very painful to create a procedure for each combination of arguments you want to write. You need a function (like sprintf in C) that takes arguments like write/writeln and returns a string of what the output looks like. You can then use that string as an argument to WriteAll. This method is slightly less painful than duplicating every write/writeln. It works even better if you want your output to go to more than two places. Also there was a posting couple of days ago about logging both input and output. Hope all these will help. -dan.