[comp.sys.amiga.tech] Amiga "Resources": Cross-post from BIX.

ewhac@well.UUCP (Leo 'Bols Ewhac' Schwab) (05/10/88)

	This is David Joiner's (talin @ BIX) posting on BIX regarding Amiga
"resources".

--------

amiga/other #322, from talin, 5411 chars, Sun May  8 23:27:05 1988
This is a comment to message 321.
--------------------------
Okay, Here's the stuff I was working on. Most of these routines
are already written and semi-tested.

SET files.
    Set files can store a variety of types of data. Each type has a
4-character name and a 4-character type, i.e. they can each be stored in a
long word.
    I call them SET files because there is already a thing on the Amiga
called 'resources' which have nothing to do with Mac 'resources'.

    A set file consists of an index, and the a number of 'sets'. Each Set
consists of one or more 'chunks'. A chunk is like a 'Hunk' in an AmigaDOS
loadfile, except that there are more different types. When a Set is loaded,
a 'ChunkList' is created, which is a linked list of chunks. The format for
a Chunk is:

    4-byte pointer to next chunk.
    2-byte length.
    2-byte type.
---> <pointer points here>
    chunk data...

    There are functions for creating and deleting ChunkLists.

    RAW MODE: A Set can be loaded in 'RAW' mode, or Normal mode. Most
of the time it doesn't make any difference, but some sets can only be
edited in raw mode, for example sets that contain executable code and
require relocation tables to be preserved.

    "Devs:System.Set" is the Global set file available to all applications.

SET functions

    MakeSetFile(filename) char *filename;
        creates a Set File with an empty index.

    file = OpenSetFile(filename) char *filename;
        opens a set file and loads it's SetMap into memory.

    CloseSetFile(file)
        closes the set file and releases all open sets.
        also, updates the file if any sets in memory were marked as changed.

    FindSet(setpath,type,id)
        find a set of the given type and id. If id == NULL, then find
    first set of that type. Returns a pointer to the map entry for that
    set.

    mapentry = LoadSet(mapentry)
        Loads the set pointed to by that map entry int ram.
        (what about single sets?)

    mapentry = GetSet(setpath,type,id,)
        equals FindSet plus LoadSet.

    newmapentry = DetachSet(mapentry)
        - clone the mapentry, and set the old map entry such that
            it is still on disk. The app is now responsible for this
            set's memory use - i.e. the set data now BELONGS to the
            application, and the set manager doesn't know about it
            any more. If someone else attempts to load the same set,
            a duplicate copy will be loaded.

    LoadSetImage(mapentry)
        loads the set without doing any relocation or referencing (i.e. RAW).

    CodeImageToSet() convert an AmigaDOS load file code image into a
        set file entry. (link library function)

    AddSet(map,name,type,chunks)
        Add a new set to a set file in memory, given a pointer to a chunklist.
    ReplaceSet(mapentry,type,chunks);
        Replaces an existing set with new data.
    DeleteSet(mapentry)
        Marks a set in the file for deletion.

    SetChanged(mapentry,bool)
        mark this set as changed, and update if needful.

    UpdateSetFile()
        Update the changes in this set file to disk.

    AllSetFiles(setpath,function,data)
        apply 'function' to all set in all set files

    AllSets(setmap,function,data)
        apply 'function' to all set entries in the given set file
        note - can function quit? (by returning zero?)

        - the above two functions can be used to search for a set, count the
            number of set types (CountTypes) or build a table of such,
            to get a count of how many sets are available, to step though them,
            etc.
    
    SetPathTop(setfile) - set the order of search (if 0 sets to system)
    ResetPathTop()
    GetPathTop()

CHUNK functions:

    LastChunk(chunklist);
        Return address of last chunk in a chunk list (MACRO).
    NthChunk(chunklist,n)
        Return the address of the Nth chunk in the chunklist.
    ChunkCount(chunklist);
        Return how many chunks in this list.
    CreateChunk(size,type,flags,lastchunk)
        Add a chunk to a (possibly NULL) chunk list.
    DeleteChunk(chunk)
        Delete a chunk (no de-linking is done) from a chunk list.
    DeleteChunkList(chunk)
        Delete an entire chunk list.
    WriteChunkList(file,chunks)
        Write a chunk list to a file in a form such that the chunk list
        can be re-created by reading the file.


OTHER STUFF
   I feel it is IMPORTANT that set files be able to store code fragments.
This is because future intuitions will have the ability to have customized
'handlers' for windows/menus/gadgets, which  should be SHARABLE between
applications.
   (And if intuition doesn't have these things, I will be compelled to
write my own window manager. Guy's got to have a hobby, you know).
   Also, it is important that sets be able to contain references to other
sets. This could be handled at the resource manager level, where sets would
contain a 'SXREF' chunk, which contains external set references to set
sets which will auto-loaded with the set specified.
   Another way it could be handled is at the structure management level.
I.e. the structure manager knows this is a NewWindow, so it knows it needs
a gadget list, a window title text, etc., which it will then go look for
in the current set context. One of the advantages of limiting set names
to 4 characters is that they can be stored in the same space as a pointer,
thus need not warp the structure to badly.