A program using the unixFile fragment will have the following structure:
INCLUDE '~beta/unixlib/unixFile' --- program: descriptor --- (# ... uf: @unixFile; do ... ('a','r') -> uf.entry.permission.add; ... #)
An example of using unixEntry: First the user is asked if symbolic links should be followed or not. If the unixEntry specified on the command line exists, it is then various other UNIX specific attributes are examined. It is examined whether the entry is a symbolic link or not, only if links should not be followed.
Finally it is attempted to change the owner of it to 675:
ORIGIN '~beta/unixlib/unixfile'; INCLUDE '~beta/sysutils/time'; ---- PROGRAM: descriptor ---- (* An example of using UnixEntry: First the user is asked if symbolic links should * be followed or not. If the UnixEntry specified on the command * line exists, it is then various other unix specific attributes are examined. * It is examined whether the entry is a symbolic link or not, only if links should * not be followed. * Finally it is attempted to change the owner of it to 675. *) (# e: @unixentry; follow: @boolean; do (if noOfArguments <> 2 //true then 'Usage: ' -> puttext; 1->arguments->puttext; ' path' -> putline; stop; if); 2 -> arguments -> e.path; 'Examine symbolic links themselves? (y/n) ' -> puttext; (Keyboard.get='n') -> e.followlinks; e.path -> puttext; (if e.exists // true then ' exists. It' -> putline; (if e.followlinks // false then (if e.isSymbolicLink // true then ' is a symbolic link' -> putline;; if); if); ' was last modified ' -> puttext; e.modtime -> formattime -> putline; ' has inode: '->puttext; e.inode -> putint; newline; ' has owner id: '->puttext; e.owner -> putint; newline; ' the owner '-> puttext; (if ('u','w') -> e.permission.has // true then 'has write permission to the disk entry' -> putline; // false then 'does not have write permission to the disk entry' -> putline; if); 'Now lets try to change the owner id to 675.' -> puttext; (*675 -> e.owner;*) ' We skipped that, since it messes up later tests, if we don\'t own the file!' -> putline; // false then ' does not exist.' -> putline; if); #)
A simple example of using unixFile: The file 'in.bet' is read word by word, and each word is printed on the output file specified on the command line. This output file has been opened with openExeWrite, meaning that the resulting file will be executable. After this, the output file is opened again, this time with openExeAppend, meaning that the output file will be executable after the line of text has been appended to it.:
ORIGIN '~beta/unixlib/unixfile'; ---- PROGRAM: descriptor ---- (* A simple example of using UnixFile: The file 'input' is read word by word, * and each word is printed on the output file specified on the command line. * This output file has been opened with OpenExeWrite, mening that the resulting * file will be executable. * After this, the output file is opened again, this time with OpenExeAppend, * meaning that the output file will be executable after the line of text * has been appended to it. *) (# inFile, outFile: @ unixfile; do (if noOfArguments <> 2 then 'Usage: ' -> puttext; 1->arguments->puttext; ' out-file' -> putline; stop; if); 2 -> arguments -> outFile.name; outFile.OpenExeWrite; 'input' -> inFile.name; inFile.OpenRead; readFile: (# do (if inFile.eos // false then inFile.getAtom -> outFile.putText; outFile.newLine; restart readFile // true then leave readFile if) #); inFile.close; outFile.close; (* Now we'll append a little too *) outfile.OpenExeAppend; 'This is one line appended' -> outfile.putline; outfile.newline; outfile.close; 'The tokens from the file \'input\' has been put into the file' -> putline; '\''->put; outFile.name -> puttext; '\', and an extra line of text has been appended.' -> putline; #)
© 1990-2002 Mjølner Informatics |
[Modified: Wednesday October 18th 2000 at 14:06]
|