home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 3 / TheARMClub_PDCD3.iso / hensa / programming / perl / perl_1 / Perl5001 / SWEchanges < prev   
Encoding:
Text File  |  1996-03-04  |  7.3 KB  |  202 lines

  1. Mods to Perl by S.W.Ellacott@brighton.ac.uk.
  2.  
  3. Compiled Perl without internet..
  4.     changed all the INET #defines in config.h
  5.     also had to change IOCTL in unixish.h
  6.     Had to define the macro EBADF in config.h as it seemed to be
  7.     undefined.
  8.      Note that my compiler would not accept the defn of fileno in acorn.c,
  9.      since ANSI C does not allow access to the filehandle. So I fudged it 
  10.      by calling the soft copy of  stdio.h.
  11.      
  12. ..but with syscall,
  13.      defined HAS_SYSCALL in config.h
  14.      recompiled pp_sys with a macro redefining 'syscall' to 'swi':
  15.      used the swi veneer from the utils library (NOT the _kernel).
  16.      See below for an example program using the call.
  17.  
  18.  
  19. Implemented dbm support by porting gdbm 1.7.3 and making it into a module.
  20. *NB.* All file protection commands are ignored.
  21.  
  22. This module goes into system:modules. All the code and stuff is in directory
  23. gdbm-1_7_3. The module is called gdbm and a copy is in the directory.
  24. It uses an official Acorn allocated swi chunk starting at 0x4cc40. For the 
  25. swis provided, see  RDBM_FIle in directory riscos.pm, or the header and code
  26. in gdbm-1_7_3. It could of course be used from any language, not just Perl.
  27.  
  28. The gdbm-1_7_3 directory also contains the actual gdbm routines as a library
  29. file GdbmLib. Note that all file protection commands are ignored, and some 
  30. initialisations do not work correctly. However the ordinary 'open' is OK.
  31.  
  32. The Perl interface package is called RDBM_FIle in directory riscos.pm,
  33. since GDBM_File is used for the UNIX implementation.
  34.  
  35. In order to make dbmopen work, I also had to put a new version of 
  36. AnyDBM_File in lib.pm. If no pathname for the database is provided, it
  37. defaults to '<PerlArchLib$Dir>.work.rdbm.' so this directory must exist.
  38. If you want to change this, alter $workdir in the RDBM_File package.
  39.  
  40. The RiscosLib package in riscos.pm is the beginning of a riscos library. At
  41. the moment it provides subroutines to create a register mask for syscall
  42. and to implement SWINumberFromString. See the RDBM_File package for example
  43. of  usage. SWINumberFromString is straightforward: just give it the swi name
  44. and it returns the number. For regmask, provide a list of input registers
  45. $in, and output registers $out. Note that they are sent to regmask by 
  46. reference. The parameters of syscall are, in order, the swinumber, the mask,
  47. the input registers and the output registers. Perl decides whether they are
  48. integers or strings. But output integers are called by reference which 
  49. requires a fudge: see the parameter $len in the program below. If you do not
  50. call the X form of the swi, register 0 is also returned by syscall. If the
  51. X form is used, syscall returns the os_error pointer, but I don't know if
  52. you can do anything with it.
  53.  
  54. I hope I've cured the backtick bug (see below) but it is difficult to be sure
  55. as the bug is not easily repeatable. Please let me know if you still have
  56. problems. Backtick now does not use popen. If this was the cause (and I'm
  57. far from certain) other pipe operations might be suspect. Note that some
  58. backtick calls return a control O as the last character. This seems to do
  59. no harm, but you might need to watch out when parsing the output.
  60.  
  61. I've cured the fileglob bug. This was definitely a pipe problem - now the
  62. fileglob calls OS_GBPB 9. Pathnames are premitted, but if directories are
  63. wildcarded only the first matching directory is used. This seems to be a
  64. property of OS_GBPB. If the directory name is invalid, a error is generated.
  65. Of course, if there is no pathname, the CSD is used. The names of all
  66. matching objects, including directories, are returned.
  67.  
  68. Most of the filetests now behave sensibly. The following is (I hope!) the
  69. defined behaviour. Note that filetests are defined *only* for filenames, not
  70. filehandles. The reason for this is that fstat is rather hard to implement
  71. on an ANSI C system. If sombody wants to try, let me know! You have to keep
  72. track of which FILE * refers to which physical file. Use of filetests for
  73. filehandles will produce a warning.
  74.  
  75.     -e <filename> returns TRUE if the <filename> exists, even if it is
  76.        a directory, and FALSE otherwise (as before, and as UNIX).
  77.        
  78.     -T <filename> returns TRUE if the <filename> is a file with filetype
  79.        'Text' (0xFFF) and FALSE if it does not exist, has a different
  80.        filetype, or is a directory.
  81.        (This is different from UNIX, and rather more sensible).
  82.        Testing a filehandle causes a fatal error for -T.
  83.        
  84.     -B As -T except that it is TRUE if the filetype is *not* 'Text'.
  85.     
  86.     -f <filename> returns true if the file exists and is not a directory.
  87.        (as UNIX).
  88.        
  89.     -d <filename> returns true if the object exists and is a directory.
  90.        (as UNIX).
  91.        
  92.     -s and -z work like UNIX. i.e. -z gives TRUE if file has zero size,
  93.        and -s returns the size.
  94.     
  95.     -M returns the age of the file in days (like UNIX). Divide by 86400
  96.        to get minutes.
  97.        
  98.     -A and -C (the other time tests) return undef.
  99.     
  100.     -r, -w return true if the file is private read/writeable
  101.        respectively. (They refer to effective uid under UNIX.)
  102.        
  103.     -R, -W return true if the file is public read/writeable
  104.        respectively. (They refer to real uid under UNIX.)
  105.        
  106.     -x, -o, -X  -O return TRUE if the object exists (i.e. they are
  107.     exactly equivalent to -e).
  108.  
  109. All the other filetests return undef. The pipe test -p, socket test -S and
  110. teletype test -t might be fixed in a later version, as may testing of 
  111. filehandles. The other tests don't really make any sense under RISCOS.
  112.  
  113.  
  114. I've made an Impression version of the manual using HTMLload. See 
  115. manual.impression.
  116.  
  117. Steve Ellacott
  118.  
  119. Follows: Perl scripts to test syscall and dbm. Other examples and test
  120. programs may be found in the pl.tests directory.
  121.  
  122. ----------------------Program to demonstrate syscall-------------------------
  123.  
  124. use RiscosLib;
  125.  
  126. $buffer = ' ' x 255;
  127.  
  128. # Getting the SWI number
  129. $str="OS_SWINumberToString";
  130. $no = SWINumberFromString($str);
  131. print "Swi number for \'$str\' is $no\n";
  132.  
  133.  
  134. # Calculation of the register mask;
  135. @in = (0 .. 2);
  136. @out = (2);
  137. $mask = ®mask(\@in,\@out);
  138. print "The mask is $mask\n";
  139.  
  140. # Fudge to return integer values
  141. $len = ' 'x4;                 # Reserve space for an integer
  142. syscall($no,$mask,0x3C,$buffer,255,$len);# Perl passes address as a parameter
  143. $len = unpack("i",$len);         # Interpret the result as an integer
  144. $len -= 1;                 # We don't want the null
  145. $buffer = substr($buffer, 0, $len);
  146. print "Buffer is $buffer\n";
  147. -----------------------------------------------------------------------------
  148. ----------------------Program to demonstrate dbm-----------------------------
  149.  
  150. use RDBM_File;
  151. dbmopen(%array2,'db2', 0);
  152.  
  153. $i = 0;
  154. tie(%array,RDBM_File,dbname, 0);
  155.  
  156. for ('a' .. 'd') {
  157.     $array{$_} = "Value for $_";
  158.     print $i++, "\t$array{$_}\n";
  159. }
  160.  
  161.  
  162.  
  163. $i = 0;
  164. for ('aa' .. 'ad') {
  165.     $array2{$_} = "Value for $_";
  166.     print $i++, "\t$array2{$_}\n";
  167. }
  168.  
  169.  
  170. print "Entry for a\n" if  exists $array{'a'};
  171. print "Deleting entry for a\nEntry was:";
  172. print delete($array{'a'});print"\n";
  173. print "Entry for a\n" if  exists $array{'a'};
  174.  
  175. @keys = keys(%array);
  176.  
  177. foreach $key ( sort(@keys) ) {
  178.     print"$key: $array{$key}\n";
  179. }
  180.  
  181. @keys = keys(%array2);
  182.  
  183. foreach $key ( sort(@keys) ) {
  184.     print"$key: $array2{$key}\n";
  185. }
  186.  
  187. print "Clearing array2\n";
  188. %array2=();
  189. print "Now try and list it again\n";
  190.  
  191. @keys = keys(%array2);
  192.  
  193. foreach $key ( sort(@keys) ) {
  194.     print"$key: $array2{$key}\n";
  195. }
  196.  
  197. print"That's all folks\n";
  198.  
  199. dbmclose(%array2);
  200. untie(%array);
  201. -----------------------------------------------------------------------------
  202.