home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 3 / TheARMClub_PDCD3.iso / programs / comms_networking / irclient / !IRClient / Scripts / Internal / Classes / !Module (.txt) next >
Encoding:
RISC OS BBC BASIC V Source  |  1997-03-21  |  9.6 KB  |  341 lines

  1.  >Internal.Classes.!Module
  2.  1997 Matthew Godbolt
  3.  This file registers and administers the internal classes
  4.  Do not edit this file, if you wish to add extra fields to the
  5.  classes, simply add them in your initialisation routines. Note
  6.  that once a class has active instantiations, you cannot modify
  7.  the fields.
  8.  03 Feb 1996 : MG - Started                               v1.00
  9.  08 Feb 1997 : JF - Modified code in newListOfFilenames   v1.01
  10.  18 Feb 1997 : JF - Added PROCList_Delete                 v1.02
  11.  21 Feb 1997 : JF - Added FileList class                  v1.03
  12.  24 Feb 1997 : JF - DL moved into it's own file           v1.04
  13.  02 Mar 1997 : JF - Converted to use @ notation
  14.  02 Mar 1997 : JF - Changed syntax of Class_List          v1.05
  15.  09 Mar 1997 : JF - Added AddAtEnd to Class_List          v1.06
  16.  22 Mar 1997 : MG - Fixed bugs in File Class and AddAtEnd v1.07
  17.  Register up the internal classes needed for the rest of
  18.  initialisation
  19. Classes_Initialise
  20.  filelist
  21. / Class_Block      = 
  22. RegisterClass("Block")
  23. AddField(Class_Block,"data")
  24. 1 Class_String      = 
  25. RegisterClass("String")
  26. AddField(Class_String,"data$")
  27. . Class_File       = 
  28. RegisterClass("File")
  29. AddField(Class_File,"filehandle")
  30. AddField(Class_File,"block")
  31. AddField(Class_File,"size")
  32. AddField(Class_File,"ptr")
  33. AddField(Class_File,"writeflag")
  34. $2 Class_FileList   = 
  35. RegisterClass("FileList")
  36. AddField(Class_FileList,"filename$")
  37. AddField(Class_FileList,"filetype")
  38. AddField(Class_FileList,"objtype")
  39. AddField(Class_FileList,"length")
  40. AddField(Class_FileList,"attribs")
  41.  Sub-directory will be 0 /unless/ objtype is 2 and recursion
  42.  has been specified (or you've created it yourself)
  43. AddField(Class_FileList,"subdir")
  44.  Parent is a pointer to the name of the parent of this tree
  45.  and will be destroyed when all the items in this list die
  46. AddField(Class_FileList,"parent")
  47. 1. Class_List       = 
  48. RegisterClass("List")
  49. AddField(Class_List,"next")
  50. AddField(Class_List,"data")
  51. 5N list = 
  52. newListOfFilenames("<IRClient$Dir>.Scripts.Internal.Classes","*")
  53. list.Iterate("Class_LoadFile")
  54. Overload_Classes_Initialise
  55. Overload_Classes_Initialise
  56. Class_LoadFile(string)
  57.  string.data$<>"!Module" 
  58. StartupStatus("Loading "+string.data$)
  59.  "<IRClient$Dir>.Scripts.Internal.Classes."+string.data$
  60. Construct(class,instance)
  61.  class 
  62.  Class_File,Class_Block
  63.  Do nowt
  64.  Class_List
  65. M<   
  66.  -1 means that /this/ item is invalid - ie ignore it
  67.    instance.next=-1
  68.  Class_String
  69. Overload_Construct(class,instance)
  70. Destroy(class,instance)
  71.  class 
  72.  Class_File
  73. instance.Close
  74.  Class_Block
  75. Release(instance.data)
  76. Overload_Destroy(class,instance)
  77. Overload_Destroy(class,instance)
  78. instance.Destroy
  79. Object_Destroy
  80. Object_Construct
  81. Overload_Construct(class,instance)
  82. instance.Construct
  83.  Creates a memory-safe block of data
  84. newBlock(size)
  85.  block
  86.  block = 
  87. new(Class_Block)
  88.  block.data = 
  89. Claim(size)
  90. =block
  91.  Creates/opens a file
  92.  mode$ = ">"  for output,
  93.          ">>" to append to a file
  94.          "<"  to read from a file
  95. newFile(filename$,mode$)
  96.  file
  97.  file = 
  98. new(Class_File)
  99. ~! file.block = 
  100. newBlock(1024)
  101.  mode$ 
  102. %   file.filehandle = 
  103. (filename$)
  104.    file.writeflag  = 1
  105.  ">>"
  106. %   file.filehandle = 
  107. (filename$)
  108.  file.filehandle = 0 
  109. &    file.filehandle = 
  110. (filename$)
  111.  file.filehandle <> 0 
  112. 1    
  113. #(file.filehandle) = 
  114. #(file.filehandle)
  115. -    file.ptr        = 
  116. #(file.filehandle)
  117.    file.writeflag  = 1
  118. %   file.filehandle = 
  119. (filename$)
  120.  file.filehandle = 0 
  121.   file = 0
  122.     =file
  123.  Ensures buffered data is written to file
  124. File_Flush
  125.  @.size <> 0 
  126.  @.writeflag 
  127.  "OS_GBPB",1,@.filehandle,@.block.data,@.size,@.ptr
  128.   @.size = 0
  129.  Sets the file ptr of a file
  130. File_SetPtr(ptr)
  131. @.Flush
  132. #@.filehandle = ptr
  133.  Reads some bytes into the file, used internally
  134. File_ReadBytes(numbytes,offset)
  135.  bytes
  136. @.Flush
  137.  "OS_GBPB",3,@.filehandle,@.block.data+offset,numbytes,@.ptr 
  138.  ,,,bytes
  139. # @.size = offset+numbytes-bytes
  140.  @.ptr += numbytes-bytes
  141.  Writes a line to a file, with \n terminator
  142. File_WriteLine(string$)
  143.  address
  144.  @.writeflag 
  145. (string$)+1 > (1024-@.size) 
  146. @.Flush
  147. )  address    =  @.block.data + @.size
  148.   $address   =  string$+
  149.   @.size +=  
  150. (string$) + 1
  151.  Closes a file, used internally
  152.  To close a file externally free the file instance
  153.  fileinstance = 0
  154. File_Close
  155.  @.filehandle 
  156. @.Flush
  157.  #@.filehandle
  158.  Reads a line from a file, ignoring comments and preceding
  159.  whitespace. Comments start with a '#' as the first
  160.  non-whitespce char of a line
  161.  Returns eof$ on EOF
  162. File_ReadLine
  163.  line$
  164.  @.filehandle 
  165.  @.writeflag=0 
  166. )  ptr = 
  167. scan(@.block.data,10,@.size)
  168.  ptr = -1 
  169.  @.size = 1024 
  170.     line$=eof$
  171. (    
  172. @.ReadBytes(1024-@.size,@.size)
  173. +    ptr = 
  174. scan(@.block.data,10,@.size)
  175.  ptr = -1 
  176.      line$=eof$
  177.         
  178.  line$<>eof$ 
  179.    ?(@.block.data+ptr) = 0
  180.    line$=$@.block.data
  181.    @.size-=
  182.  line$+1
  183. memcopy(@.block.data,@.block.data+
  184.  line$+1,@.size)
  185.    line$=
  186. Strip(line$)
  187. line$,1)="#" 
  188.     line$=
  189. @.ReadLine
  190.   line$=eof$
  191. =line$
  192.  String stuff
  193. newString(s$)
  194.  string
  195.   string = 
  196. new(Class_String)
  197.  string.data$ = s$
  198. =string
  199.  Linked list stuff
  200. newList
  201. new(Class_List)
  202.  Adds an item to the head of the list
  203. List_Add(data)
  204.  thing,last
  205.  @.next=-1 
  206.   thing=@
  207.   last=0
  208.   thing = 
  209. new(Class_List)
  210.   last = @
  211.  thing.data = data
  212.  thing.next = last
  213.  @=thing
  214.  Add an item to the tail of a list
  215. List_AddAtEnd(data)
  216.  @.next=-1 
  217.  @.next=0
  218.  @.data = data
  219.  newItem,last
  220.  last=@
  221.  newItem = 
  222. new(Class_List)
  223.  last.next<>0
  224.   last=last.next
  225.  newItem.next = 0
  226.  newItem.data = data
  227.  last.next    = newItem
  228.  Returns a list of filenames in directory dir$
  229.  matching match$
  230. newListOfFilenames(dir$,match$)
  231.  list,buffer,cont,numread,file$,ptr,file
  232.  list=
  233. newList
  234.  buffer=
  235. newBlock(256)
  236.  cont<>-1
  237.  "OS_GBPB",9,dir$,buffer.data,1024,cont,256,match$ 
  238.  ,,,numread,cont
  239.   ptr=buffer.data
  240.  numread>0
  241.    file$=$ptr
  242.    t=
  243. newString(file$)
  244. list.Add(t)
  245.    ptr+=
  246.  file$+1
  247.    numread-=1
  248. )    =list
  249.  Call functions with fn$(data) as parameter
  250. List_Iterate(function$)
  251.  next,list
  252.  list=@
  253.  @.next<>-1 
  254.  list<>0
  255. 1@   
  256.  next is used in case function$ changes the state of the
  257.  linked list
  258.    next = list.next
  259. (function$)(list.data)
  260.    list = next
  261.  Deletes an item from the list
  262. List_Delete(entry)
  263.  @.next<>-1 
  264.  last,this,next
  265.  this=@
  266.  last=0
  267.  this<>0
  268.   next=this.next
  269.  this.data=entry 
  270.  last<>0 
  271.     last.next=next
  272.  next=0 
  273.      @.next=-1
  274. H        
  275.      @=next
  276. J        
  277.   last=this
  278.   this=next
  279. List_Find(key)
  280.  list,found
  281.  @.next = -1 
  282.  list = @
  283.  list 
  284.  found
  285. list.data.Compare(key) 
  286.  found=list
  287.   list = list.next
  288. =found
  289.  recurse = 0 to not recurse, <level> for the number of levels
  290.            to recurse, or -1 to recurse infinitely (dangerous)
  291. newFileList(subdir$,match$,recurse)
  292.  list,buffer,cont,numread,file$,flist,subdptr
  293. subdptr=
  294. newString(subdir$)
  295. buffer=
  296. newBlock(320)
  297. list=
  298. newList
  299.  cont<>-1
  300.  "OS_GBPB",12,dir$,buffer.data,1,cont,320,match$ 
  301.  ,,,numread,cont
  302.  numread>0 
  303. g   flist=
  304. new(Class_FileList)
  305.   flist.parent=subdptr
  306. i'  flist.filename$=$(buffer.data+24)
  307. j&  flist.filetype=!(buffer.data+20)
  308. k%  flist.attribs=!(buffer.data+20)
  309. l%  flist.objtype=!(buffer.data+16)
  310. m#  flist.length=!(buffer.data+8)
  311.  recurse<>0 
  312.  flist.objtype>1 
  313. oN   flist.subdir=
  314. newFileList(subdir$+"."+flist.filename$,match$,recurse-1)
  315.    flist.subdir=0
  316. list.Add(flist)
  317. v    =list
  318.  ***************************************************************************
  319.  **         The Object methods, callable from *any* object at all         **
  320.  ***************************************************************************
  321. Object_GetUnknownVar(var$)
  322.  Deal with the dynamic properties of all objects, and some which are
  323.  calculated rather than stored in every object
  324.  var$ 
  325.  Object.type$ is the same as calling FNGetClassName(foo)
  326.  "classname$"
  327. GetClassName(@)
  328.  "this"
  329.  "Unknown property "+
  330. GetClassName(@)+"."+var$
  331. Object_SetUnknownVarStr(var$,value$)
  332.  var$ 
  333.  "trevor$"
  334. GetClassName(@)+".trevor$ was set to "+value$
  335.  "Unknown property "+
  336. GetClassName(@)+"."+var$
  337. Object_SetUnknownVarInt(var$,value)
  338.  var$ 
  339.  "Unknown property "+
  340. GetClassName(@)+"."+var$
  341.