(1) Documentation (changed)
(2) GetLastRegistered (added)
(3) Deregister (added)
The motivation for those changes is that the documentation is misleading. It suggests modifications to Config.odc are necessary in order to added new converters to the BB framework. That is false. New converters can be added by any module. That evokes the idea "If one creates, one must destroy" and hence the need to remove a converter from the converter's registry. To do that one needs a handle to the converter created when one calls Converters.Register. To get that handle I suggest to add the procedure "GetLastRegistered" along with the following modifications to Converters.
Code: Select all
Converter* = POINTER TO RECORD
id: INTEGER; (*added*)
next-: Converter;
imp-, exp-: Dialog.String;
storeType-: Stores.TypeName;
fileType-: Files.Type;
opts-: SET
END;
Code: Select all
VAR
list-: Converter;
doc: Converter;
numId: INTEGER; (*added*)
Code: Select all
PROCEDURE Register* (imp, exp: Dialog.String; storeType: Stores.TypeName; fileType: Files.Type; opts: SET);
VAR e, f: Converter;
BEGIN
ASSERT((imp # "") OR (exp # ""), 20); ASSERT(fileType # "", 21);
NEW(e); e.next := NIL;
e.id := numId; INC(numId); (*added*)
e.imp := imp; e.exp := exp; e.fileType := fileType; e.storeType := storeType; e.opts := opts;
IF (storeType = "") & (doc = NIL) THEN doc := e END;
IF list = NIL THEN list := e
ELSE f := list;
WHILE f.next # NIL DO f := f.next END;
f.next := e;
END
END Register;
Code: Select all
PROCEDURE Clone (c: Converter): Converter; (*added*)
VAR e: Converter;
BEGIN
NEW(e);
e^ := c^;
RETURN e
END Clone;
Code: Select all
PROCEDURE GetLastRegistered* (VAR c: Converter); (*added*)
VAR e, f: Converter;
BEGIN
IF list # NIL THEN
f := list;
WHILE f.next # NIL DO f := f.next END;
e := Clone(f); e.next := c; c := e; (*push*)
END
END GetLastRegistered;
Register
GetLastRegistered
Register
GetLastRegistered
...
Register
GetLastRegistered
Given a Converters.Converter (list) one can "Deregister" the list
Code: Select all
PROCEDURE Deregister* (VAR c: Converter); (*added*)
VAR f: Converter;
BEGIN
WHILE c # NIL DO
f := list;
WHILE (f # NIL) & (f.id # c.id) DO f := f.next END;
IF f # NIL THEN f := f.next; DEC(numId) END; (*delete c from list*)
c := c.next
END
END Deregister;
Code: Select all
BEGIN
list := NIL;
numId := 0
END Converters.
PROCEDURE Register (imp, exp: Dialog.String; storeType: Stores.TypeName;
fileType: Files.Type; opts: SET)
Register an importer which translates a file of type fileType into a store of type storeType (e.g., "TextViews.View"), an exporter which translates a store of type storeType into a file of type fileType, or both.
imp is the name of an importer command, which must have the signature of Importer.
exp is the name of an exporter command, which must have the signature of Exporter.
opts allows to express a set of options; currently only the element importAll is defined. Normally, opts is empty.
Register does not yet load the modules which contain the import/export commands. They are loaded only when needed.
The standard document converter is already installed by the BlackBox core. Other converters may be installed in any module the Config module, e.g., converters for ASCII files, Unicode files, or picture files. Config is executed upon startup of BlackBox to allow the establishment of custom configurations, such as the set of available converters.
As a result of Register, a new converter is appended to list, with fields corresponding to the parameters passed.
For each registered importer or exporter, there optionally may be a corresponding string mapping; to make the display of a list of importers/exporters more user-friendly. For example, the importer "HostTextConv.ImportText" could be mapped to the more telling name "Ascii" (in the standard file open dialog). The mapping is done in the Strings file in the Rsrc directory of the importer's subsystem, e.g., there may be the following lines in the Host/Rsrc/Strings text:
HostTextConv.ImportText Ascii
HostTextConv.ExportText Ascii
Pre
imp # "" OR exp # "" 20
fileType # "" 21