Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!cs.utexas.edu!uunet!mcsun!unido!gmdzi!jc From: jc@gmdzi.UUCP (Juergen Christoffel) Newsgroups: comp.sys.mac.programmer Subject: (MPW) Pascal formatted I/O and SF[Get|Put]File? Keywords: mpw, pascal, sfgetfile, sfputfile Message-ID: <1387@gmdzi.UUCP> Date: 23 Oct 89 18:37:14 GMT Organization: GMD - Gesellschaft fuer Mathematik und Datenverarbeitung mbH Lines: 104 I have some medium sized programs written in Standard Pascal which I want to port to the Macintosh. These programs use the Pascal file I/O routines, i.e. open, close, readln, writeln etc. Pascal files are linked to their external representation via name (that is you need to do something along open("foo.bar") to open a file). The "Macintosh way" of handling files is via SFGetFile/SFPutFile and then using FSOpen and consorts on file reference numbers. Using the pathnames returned by FSGet/PutFile doesn't work as soon as one switches folders between the files in use because these just return filenames and not the full path. Using vRefNums on the other hand prohibits the use of Pascal's formatted I/O routines. An example (doesn't work as soon as you switch folders in the FSGetFile or FSPutFile dialogs) would look like: Program foo; USES ... var infile, outfile : text; inname, outname : string[63]; ch : char; typeList : SFTypeList; where, wsize : Point; reply : SFReply; ... begin InitializeGlobals; typeList[0]:='TEXT'; SFGetFile(where, 'Source', NIL, 1, typeList, NIL, reply); if reply.good then begin inname:=reply.fName; open(infile, inname); outname:=Concat(inname, '.copy'); SFPutFile(where, 'Destination', outname, NIL, reply); if reply.good then begin outname:=reply.fName; open(outfile, outname); reset(infile); rewrite(outfile); while not eof(infile) do begin <> <> end; close(infile); close(outfile); end; end; end. Now, my existing programs do more than just put and get on files and if I'd had to convert them to use vRefNums and the ROM calls for file access I had to reinvent the whole formatted I/O routines. How should I do it? Construct full pathnames like "HD:folder1:folder2:infile.text" and use these? [As I understand Apple's technical documentation they don't recommend (cf. e.g. technote 044) using full pathnames constructed from a user's response (does this include SFGetFile selected pathnames?)] Really convert the whole I/O related stuff? (Regretfully Pascal doesn't have some equivalent of C's sprintf) Or is there a way to connect vRefNums to Pascal file variables? Maybe ARE file variables just hidden vRefNums and a coercion would help (though possibly costing compatability with future versions)? All example code (from Apple and various books) I have consulted just uses either the ROM calls or just beats about the bush. So my questions are: - What's "theRightWay"(tm ;-) for converting valid Pascal programs to valid Macintosh programs with minimal conversion efforts? - Are there any good books discussing such topics? [What's about a TechNote on this topic?] Any hints or tips are welcome; mail them and I will summarize if there's sufficient interest. Thanks, --jc ======================================================================== Juergen Christoffel, jc@gmdzi.UUCP, (++49 2241) 14-2421 German National Research Laboratory for Computer Science (GMD) Schloss Birlinghoven, Postfach 1240, D-5205 St. Augustin 1, FRG ========================================================================