home *** CD-ROM | disk | FTP | other *** search
RISC OS BBC BASIC V Source | 1997-03-21 | 9.6 KB | 341 lines |
- >Internal.Classes.!Module
- 1997 Matthew Godbolt
- This file registers and administers the internal classes
- Do not edit this file, if you wish to add extra fields to the
- classes, simply add them in your initialisation routines. Note
- that once a class has active instantiations, you cannot modify
- the fields.
- 03 Feb 1996 : MG - Started v1.00
- 08 Feb 1997 : JF - Modified code in newListOfFilenames v1.01
- 18 Feb 1997 : JF - Added PROCList_Delete v1.02
- 21 Feb 1997 : JF - Added FileList class v1.03
- 24 Feb 1997 : JF - DL moved into it's own file v1.04
- 02 Mar 1997 : JF - Converted to use @ notation
- 02 Mar 1997 : JF - Changed syntax of Class_List v1.05
- 09 Mar 1997 : JF - Added AddAtEnd to Class_List v1.06
- 22 Mar 1997 : MG - Fixed bugs in File Class and AddAtEnd v1.07
- Register up the internal classes needed for the rest of
- initialisation
- Classes_Initialise
- filelist
- / Class_Block =
- RegisterClass("Block")
- AddField(Class_Block,"data")
- 1 Class_String =
- RegisterClass("String")
- AddField(Class_String,"data$")
- . Class_File =
- RegisterClass("File")
- AddField(Class_File,"filehandle")
- AddField(Class_File,"block")
- AddField(Class_File,"size")
- AddField(Class_File,"ptr")
- AddField(Class_File,"writeflag")
- $2 Class_FileList =
- RegisterClass("FileList")
- AddField(Class_FileList,"filename$")
- AddField(Class_FileList,"filetype")
- AddField(Class_FileList,"objtype")
- AddField(Class_FileList,"length")
- AddField(Class_FileList,"attribs")
- Sub-directory will be 0 /unless/ objtype is 2 and recursion
- has been specified (or you've created it yourself)
- AddField(Class_FileList,"subdir")
- Parent is a pointer to the name of the parent of this tree
- and will be destroyed when all the items in this list die
- AddField(Class_FileList,"parent")
- 1. Class_List =
- RegisterClass("List")
- AddField(Class_List,"next")
- AddField(Class_List,"data")
- 5N list =
- newListOfFilenames("<IRClient$Dir>.Scripts.Internal.Classes","*")
- list.Iterate("Class_LoadFile")
- Overload_Classes_Initialise
- Overload_Classes_Initialise
- Class_LoadFile(string)
- string.data$<>"!Module"
- StartupStatus("Loading "+string.data$)
- "<IRClient$Dir>.Scripts.Internal.Classes."+string.data$
- Construct(class,instance)
- class
- Class_File,Class_Block
- Do nowt
- Class_List
- M<
- -1 means that /this/ item is invalid - ie ignore it
- instance.next=-1
- Class_String
- Overload_Construct(class,instance)
- Destroy(class,instance)
- class
- Class_File
- instance.Close
- Class_Block
- Release(instance.data)
- Overload_Destroy(class,instance)
- Overload_Destroy(class,instance)
- instance.Destroy
- Object_Destroy
- Object_Construct
- Overload_Construct(class,instance)
- instance.Construct
- Creates a memory-safe block of data
- newBlock(size)
- block
- block =
- new(Class_Block)
- block.data =
- Claim(size)
- =block
- Creates/opens a file
- mode$ = ">" for output,
- ">>" to append to a file
- "<" to read from a file
- newFile(filename$,mode$)
- file
- file =
- new(Class_File)
- ~! file.block =
- newBlock(1024)
- mode$
- % file.filehandle =
- (filename$)
- file.writeflag = 1
- ">>"
- % file.filehandle =
- (filename$)
- file.filehandle = 0
- & file.filehandle =
- (filename$)
- file.filehandle <> 0
- 1
- #(file.filehandle) =
- #(file.filehandle)
- - file.ptr =
- #(file.filehandle)
- file.writeflag = 1
- % file.filehandle =
- (filename$)
- file.filehandle = 0
- file = 0
- =file
- Ensures buffered data is written to file
- File_Flush
- @.size <> 0
- @.writeflag
- "OS_GBPB",1,@.filehandle,@.block.data,@.size,@.ptr
- @.size = 0
- Sets the file ptr of a file
- File_SetPtr(ptr)
- @.Flush
- #@.filehandle = ptr
- Reads some bytes into the file, used internally
- File_ReadBytes(numbytes,offset)
- bytes
- @.Flush
- "OS_GBPB",3,@.filehandle,@.block.data+offset,numbytes,@.ptr
- ,,,bytes
- # @.size = offset+numbytes-bytes
- @.ptr += numbytes-bytes
- Writes a line to a file, with \n terminator
- File_WriteLine(string$)
- address
- @.writeflag
- (string$)+1 > (1024-@.size)
- @.Flush
- ) address = @.block.data + @.size
- $address = string$+
- @.size +=
- (string$) + 1
- Closes a file, used internally
- To close a file externally free the file instance
- fileinstance = 0
- File_Close
- @.filehandle
- @.Flush
- #@.filehandle
- Reads a line from a file, ignoring comments and preceding
- whitespace. Comments start with a '#' as the first
- non-whitespce char of a line
- Returns eof$ on EOF
- File_ReadLine
- line$
- @.filehandle
- @.writeflag=0
- ) ptr =
- scan(@.block.data,10,@.size)
- ptr = -1
- @.size = 1024
- line$=eof$
- (
- @.ReadBytes(1024-@.size,@.size)
- + ptr =
- scan(@.block.data,10,@.size)
- ptr = -1
- line$=eof$
-
- line$<>eof$
- ?(@.block.data+ptr) = 0
- line$=$@.block.data
- @.size-=
- line$+1
- memcopy(@.block.data,@.block.data+
- line$+1,@.size)
- line$=
- Strip(line$)
- line$,1)="#"
- line$=
- @.ReadLine
- line$=eof$
- =line$
- String stuff
- newString(s$)
- string
- string =
- new(Class_String)
- string.data$ = s$
- =string
- Linked list stuff
- newList
- new(Class_List)
- Adds an item to the head of the list
- List_Add(data)
- thing,last
- @.next=-1
- thing=@
- last=0
- thing =
- new(Class_List)
- last = @
- thing.data = data
- thing.next = last
- @=thing
- Add an item to the tail of a list
- List_AddAtEnd(data)
- @.next=-1
- @.next=0
- @.data = data
- newItem,last
- last=@
- newItem =
- new(Class_List)
- last.next<>0
- last=last.next
- newItem.next = 0
- newItem.data = data
- last.next = newItem
- Returns a list of filenames in directory dir$
- matching match$
- newListOfFilenames(dir$,match$)
- list,buffer,cont,numread,file$,ptr,file
- list=
- newList
- buffer=
- newBlock(256)
- cont<>-1
- "OS_GBPB",9,dir$,buffer.data,1024,cont,256,match$
- ,,,numread,cont
- ptr=buffer.data
- numread>0
- file$=$ptr
- t=
- newString(file$)
- list.Add(t)
- ptr+=
- file$+1
- numread-=1
- ) =list
- Call functions with fn$(data) as parameter
- List_Iterate(function$)
- next,list
- list=@
- @.next<>-1
- list<>0
- 1@
- next is used in case function$ changes the state of the
- linked list
- next = list.next
- (function$)(list.data)
- list = next
- Deletes an item from the list
- List_Delete(entry)
- @.next<>-1
- last,this,next
- this=@
- last=0
- this<>0
- next=this.next
- this.data=entry
- last<>0
- last.next=next
- next=0
- @.next=-1
- H
- @=next
- J
- last=this
- this=next
- List_Find(key)
- list,found
- @.next = -1
- list = @
- list
- found
- list.data.Compare(key)
- found=list
- list = list.next
- =found
- recurse = 0 to not recurse, <level> for the number of levels
- to recurse, or -1 to recurse infinitely (dangerous)
- newFileList(subdir$,match$,recurse)
- list,buffer,cont,numread,file$,flist,subdptr
- subdptr=
- newString(subdir$)
- buffer=
- newBlock(320)
- list=
- newList
- cont<>-1
- "OS_GBPB",12,dir$,buffer.data,1,cont,320,match$
- ,,,numread,cont
- numread>0
- g flist=
- new(Class_FileList)
- flist.parent=subdptr
- i' flist.filename$=$(buffer.data+24)
- j& flist.filetype=!(buffer.data+20)
- k% flist.attribs=!(buffer.data+20)
- l% flist.objtype=!(buffer.data+16)
- m# flist.length=!(buffer.data+8)
- recurse<>0
- flist.objtype>1
- oN flist.subdir=
- newFileList(subdir$+"."+flist.filename$,match$,recurse-1)
- flist.subdir=0
- list.Add(flist)
- v =list
- ***************************************************************************
- ** The Object methods, callable from *any* object at all **
- ***************************************************************************
- Object_GetUnknownVar(var$)
- Deal with the dynamic properties of all objects, and some which are
- calculated rather than stored in every object
- var$
- Object.type$ is the same as calling FNGetClassName(foo)
- "classname$"
- GetClassName(@)
- "this"
- "Unknown property "+
- GetClassName(@)+"."+var$
- Object_SetUnknownVarStr(var$,value$)
- var$
- "trevor$"
- GetClassName(@)+".trevor$ was set to "+value$
- "Unknown property "+
- GetClassName(@)+"."+var$
- Object_SetUnknownVarInt(var$,value)
- var$
- "Unknown property "+
- GetClassName(@)+"."+var$
-