Re: [ooc-compiler] Help With I/O
Brought to you by:
mva
|
From: Michael v. A. <Mic...@de...> - 2004-05-26 19:47:40
|
Gregory Gelfond <gre...@tt...> writes: > Hello All, > > I am completely new to Oberon, and am attempting to learn the language. I > understand the basics of the language as described in Wirth's book, but am > having some difficulty in learning the oo2c library. I have the following > program: > > MODULE DisplayFile; > [...] > > I have several difficulties running this program. The program displays the > contents of the file "HelloWorld.Mod", with the exception of the last line. > How can I specify the termination condition of the loop to read "While not > end of file do"? Using your program (plus fix), I see all the lines from the input file duplicated to stdout -- as expected. "WHILE res=done DO" should definitely work. > Also, can someone explain the meaning of the third parameter 'res' of the > Files.Old function call? Opening the file may file. A "res#done" indicates an error. This should be checked. For example, when I started your program without providing the input file, I got a seg fault because `file' was NIL. `res' would indicate a "file not found" error. > Furthermore, in Wirth's book, the I/O functions that are described differ > from those present in the oo2c library. Am I correct in understanding that > these are the ones defined in the Oakwood modules? If so, what are the > benefits/drawbacks of one over the other? In general, the resemblance between the libraries of oo2c and the original documentation of the Oberon System is superficial. By necessity, any I/O library put on top of the standard C/POSIX library needs to decide whether to implement its own view of the world, or to provide a faithful representation of the low-level functions of the operating system (or C library). In a way, the Wirth I/O functions _are_ the operating system. OOC leans more in the direction of the operating system it is using, which is represented by the I/O functions of C. For example, the v2 compiler comes with a set of low-level IO modules (like IO:FileChannel and IO:SocketChannel) that are essentially one-to-one interfaces to C's open(), read(), write(), etc. As for Oakwood: The v1 compiler distribution has a set of Oak* modules that are closer to the original Oberon System modules. -- mva |