inm501@csc.anu.edu.au (04/13/91)
Can someone give me a hand? I am not familiar with Pascal and Macintosh I/O system. Someone gave me a Pascal program running on Sun4 so that I can get it to run on the Mac. This program is supposed to read a text file something to it and write it out again. I compiled the program with Think Pascal without any problem. I saved it as an application. When I run it, it is expecting interactive input from the terminal. How do I get it to read input and output file name interactively? I don't want any window or anything. At the top of the original program it has "Program program_name(input, output)". Does it mean the default names are input and output? Do I have to get rid of them? Sorry about asking such trivial questions ... Thanks anyway. Ida
cjp310@coombs.anu.edu.au (Chris @ SSDA ...) (04/13/91)
inm501@csc.anu.edu.au writes: > Can someone give me a hand? I am not familiar with Pascal and >Macintosh I/O system. Someone gave me a Pascal program running on Sun4 so >that I can get it to run on the Mac. This program is supposed to read a text >file something to it and write it out again. I compiled the program with >Think Pascal without any problem. I saved it as an application. When I >run it, it is expecting interactive input from the terminal. > How do I get it to read input and output file name interactively? I >don't want any window or anything. At the top of the original program it has >"Program program_name(input, output)". Does it mean the default names are >input and output? Do I have to get rid of them? > Sorry about asking such trivial questions ... Thanks anyway. >Ida Ida, Its all in the manual :-) - you know the one you get when you buy it... Chris -- -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= Chris Patterson | Ph: +61 6 2492185 Social Science Data Archives | AARNet: Chris@coombs.anu.edu.oz Australian National University | "I wonder what happens if I ..."
jmatthews@desire.wright.edu (04/15/91)
In article <1991Apr13.080239.1@csc.anu.edu.au>, inm501@csc.anu.edu.au writes: > > Can someone give me a hand? I am not familiar with Pascal and > Macintosh I/O system. Someone gave me a Pascal program running on Sun4 so > that I can get it to run on the Mac. This program is supposed to read a text > file something to it and write it out again. I compiled the program with > Think Pascal without any problem. I saved it as an application. When I > run it, it is expecting interactive input from the terminal. > > How do I get it to read input and output file name interactively? I > don't want any window or anything. At the top of the original program it has > "Program program_name(input, output)". Does it mean the default names are > input and output? Do I have to get rid of them? > > Sorry about asking such trivial questions ... Thanks anyway. > > Ida The file variable parameters in the program stament program foo (input, output); are what the system uses when you call Read, ReadLn, Write or WriteLn without specifying a file variable. By default in THINK Pascal, input comes from the keyboard and output goes to a window named TEXT. Unless you use Apple's Macintosh Programmer's Workshop (MPW), the Mac has no command line interface. As a result, there's no way to redirect input or output from outside a program. Alternatively, you can use the TEXT window for interactive I/O. This works from within the THINK environment or in stand alone code. program test; var wRect: Rect; theEvent: EventRecord; begin {by default THINK Pascal initializes some ToolBox managers for you} InitCursor; wRect := ScreenBits.bounds; InsetRect(wRect, 100, 100); SetTextRect(wRect); ShowText; {your code here} WriteLn('Press any key or the mouse button to end...'); repeat until GetNextEvent(mDownMask + keyDownMask, theEvent) end. The built-in procedures SetTextRect and ShowText give you some control over the location and size of the TEXT window. You can then prompt for input and output files eg. var fName: Str255; Write('What file do you want to process? '); ReadLn(fName); This works as long as the file is in the same directory as the program (or you don't mind typing full pathnames). To get around this, call the ToolBox function SFGetFile. Before opening the file call the ToolBox function SetVol using the vRefNum returned by SFGetFile in its reply record. Use nil for the file name. eg. var sReply: SFReply; tList: SFTypeList; err: OSErr; SFGetFile(sfPt, '', nil, -1, tList, nil, sReply); err := SetVol(nil, sReply.vRefNum); reset(f,sReply.fName); This should get you going until you have time to decide if you need a more elaborate interface. o----------------------------------------------------------------------------o | John B. Matthews, jmatthews@desire.wright.edu, am103@cleveland.freenet.edu | | "Say...what's a mountain goat doing way up here in a cloud bank?" - Larson | o----------------------------------------------------------------------------o
kpmiller@uokmax.ecn.uoknor.edu (Kent P Miller) (04/18/91)
Actually, if you are doing standard I/O, (or at least O) your writeln statement automagically pulls up the ShowText; window. I don't know if you can readln from there. Kent -- ----------------------- Kent Miller KENT@aardvark.ucs.uoknor.edu Bitnet -> KENT@uokucsvx