home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / amiga / programm / libs / lib_coll.lha / COMMODIT.ZOO / Commodities / manual < prev    next >
Encoding:
Text File  |  1987-07-08  |  36.0 KB  |  895 lines

  1. :bk=0
  2.  
  3.     Commodities Exchange Reference Manual 
  4.         version 0.3, March 18, 1987
  5.  
  6.     This manual and Commodities Exchange were written by Jim Mackraz.
  7.  
  8.     Copyright 1987, Jim Mackraz.  No part of this manual or
  9.     accompanying software may be sold for profit or included in
  10.     any for-profit product without written authorization from
  11.     the author.
  12.  
  13.     Free and at-cost distribution of this package is welcome. 
  14.     The source code for "commodities.library" is not to be compiled
  15.     for any reason without written consent of the author.  All users
  16.     of the Commodities Exchange are urged to respect the standards put
  17.     forth in the documentation.
  18.  
  19.  
  20.     -----    PREFACE        --------------------------------------------
  21.  
  22.     This manual is the first draft of the programmer's reference to
  23.     Commodities Exchange.  It accompanies a release which might
  24.     best be called "Alpha 2" but will be referred to as "Version
  25.     0.3."  As the body of the manual describes, every attempt
  26.     has been made to provide a complete system which will enable
  27.     applications to be written in an upwardly compatible way.
  28.  
  29.     The end of this document contains sort of an Appendix on the
  30.     major improvement of Version 0.3: InvertKeyMap() and the
  31.     improvement to ParseIX().   Also, AddIEvents() is new.
  32.     See also the function descriptions.
  33.  
  34.     More features and utilities will address new areas.
  35.  
  36.     The contents of a release are described in a file named README
  37.     on the release disk.
  38.  
  39.     In addition to this document, required reading includes
  40.     the collected function references, the application #include
  41.     files, and the example applications provided.  Familiarity
  42.     with the input.device, in particular the contents of the
  43.     include file devices/inputevent.h is necessary.  Exec Lists,
  44.     Messages and Message Ports play a fundamental role in the system,
  45.     and must also be understood.  The source for the scanned support
  46.     library, cx_support.lib, is also educational.
  47.  
  48.     The author wishes to warmly thank Neil Katin for his indispensible
  49.     aid and suggestions, and Andy Finkel for being a patient, yet
  50.     constant encouragement to complete the project.  Also, the team
  51.     at Meridian Software have been very helpful and encouraging.
  52.  
  53.     The eventual distribution path for commodities.library has
  54.     yet to be determined.  The attempt at a copyright notice
  55.     above is trying to express these intentions:
  56.  
  57.     -The library may be distributed in object form for free.
  58.  
  59.     -No one makes money off of this without written consent,
  60.      which will be quite easily obtained.
  61.  
  62.     -I don't want the source to the library itself compiled;
  63.      I want control over that.  Any example application or
  64.      scanned library function may be freely used for non-for-
  65.      profit programs.
  66.  
  67.     -I hope people write programs which handle errors carefully,
  68.      use the ToolTypes as described, and look real sharp.
  69.  
  70.     -Later versions of the library and controller may be shareware,
  71.      but arrangements can be made with anyone wishing to use
  72.      the library with a commercial product.
  73.  
  74.     Lastly, I want to encourage all feedback possible.  In particular,
  75.     I would be glad to recommend approaches to your envisioned
  76.     applications, and will enhance the library to support
  77.     needed features as I become aware of them.  This manual is
  78.     also undoubtedly lacking.  Please forgive this first draft and
  79.     feel welcome in giving advice for its revision.
  80.  
  81.     Please contact me by mail or in person:
  82.         Jim Mackraz
  83.         7101 Rainbow Dr. #8
  84.         San Jose, CA  95129
  85.  
  86.  
  87.     -----    INTRODUCTION    -------------------------------------
  88.  
  89.     Commodities Exchange has as its major component an Amiga
  90.     Exec Library, named "commodities.library."  If this library
  91.     is put in logical volume LIBS:, it can be opened and used
  92.     by application programs to gain access to input in a
  93.     very flexible way.
  94.  
  95.     In particular, an application of Commodities can monitor the
  96.     Amiga input stream coming from the input.device without using
  97.     an Intuition Window or a Console.  This gives rise to the
  98.     following motivational paragraphs.
  99.  
  100.     The Amiga computer provides a low-overhead, message-based
  101.     multi-tasking operating environment, complete with a
  102.     multi-threaded DOS and Graphics/Windows environment.  No
  103.     other PC provides this, yet the impact sometimes seems to
  104.     be lost on the personal computing community at large.
  105.  
  106.     To some degree, this is explained by surrogate multi-tasking
  107.     providing a high degree of satisfaction on popular competitors
  108.     such as the Apple Macintosh and IBM PC.  Small programs
  109.     called Desk Accessories, Pop-Up programs, Resident programs,
  110.     Terminate-and-Stay-Resident programs and the like provide multiple
  111.     application capability, with some limits.
  112.  
  113.     Technical problems with the ad hoc methods of providing these
  114.     functions on existing microcomputers find their way to the
  115.     user, who must often empirically determine what programs may
  116.     safely coexist, and in what order they must be "loaded."
  117.  
  118.     Most of the technical problems in writing such programs are
  119.     non-existent on the Amiga.  In particular, using disk
  120.     operating system services in pop-up programs is a black art
  121.     on an IBM PC.  A principle area of difficulty or awkwardness
  122.     is the monitoring of input, be it for the purpose of 
  123.     triggering a pop-up program, performing spelling checking as
  124.     words are typed, or translating keystrokes into sequences.
  125.  
  126.     On the Amiga, the input problem is fundamentally solved by
  127.     the input.device which provides an endorsed means of adding
  128.     "input handlers."  Unfortunately, without standards, arbitrary
  129.     use of input handlers by uncooperative programs can quickly
  130.     lead to incompatibilities or "load-order dependence" even 
  131.     on the Amiga.  Furthermore, writing input handlers is far
  132.     from trivial, especially using "small model" compilation as
  133.     provided by Aztec C.
  134.  
  135.     Which brings us to the goal of the Commodities Exchange.
  136.     Commodities consists of a single input handler which precedes
  137.     the Intuition input handler.  Like Intuition, Commodities
  138.     will route input events to multiple applications.  Commodities
  139.     applications typically are interested in input regardless of
  140.     what Window is active, and thus Commodities is used as a
  141.     simple, standardized way of managing the input of a "Resident"
  142.     type program.
  143.  
  144.     Taken with the standards described in this document for 
  145.     user-specification of the input which triggers an action,
  146.     and for establishing the priority of individual Commodities
  147.     applications, it is hoped that many high-quality, mutually
  148.     co-existent "Resident" programs will be created by the
  149.     amazing Amiga programming community.
  150.  
  151.     Next we describe the end-user's view of several Commodities
  152.     applications.  The source code for these is provided with
  153.     the release.  These programs together illustrate the most 
  154.     common principles of Commodities, and will serve as examples
  155.     for the rest of this manual.
  156.  
  157.  
  158.     -----    SOME EXAMPLES    ------------------------------------
  159.  
  160.     To run any of the following examples, the user must put
  161.     a copy of the file "commodities.library" into his or her
  162.     LIBS: directory, where it will be found when the program
  163.     begins execution.
  164.  
  165.     All applications below would normally be started from the
  166.     Workbench by opening (double-clicking) their icon.  As we
  167.     shall see, information in the icon is used to configure the
  168.     programs.
  169.  
  170.  
  171.     --    IHELP    --
  172.  
  173.     This application is just in its infancy, I swear.  Its purpose
  174.     is to provide keyboard control of Intuition window operations,
  175.     to lessen (ultimately to eliminate) the need for using the mouse
  176.     while doing keyboard intensive work, such as writing software or
  177.     documents. 
  178.     
  179.     This program was the prime motivation for the Commodities Exchange. 
  180.     It is the author's firm belief that managing a multi-tasking
  181.     user interface is too important a task to assign exclusively to a
  182.     low-bandwidth device such as a mouse.
  183.  
  184.     Currently, IHelp provides three functions:
  185.  
  186.     CYCLE -- this function causes the rearmost application window
  187.     on the Workbench to be brought to the front and Activated.
  188.  
  189.     MAKESMALL -- the active window is shrunk to its minimum dimensions.
  190.  
  191.     MAKEBIG    -- the active window is made the maximum size possible
  192.     respecting its limits and the edge of the screen.
  193.  
  194.     Each of these functions is assigned to an input event, typically
  195.     a keystroke such as a function key.  Pressing the proper key
  196.     causes the action to take place regardless of which window
  197.     is active or what use the active window may be making of keyboard
  198.     input.
  199.  
  200.     In order to allow the user the ability to associate keystrokes
  201.     (or other events) with these actions, the ToolType fields in
  202.     the program (Tool) icon are used.  The user selects (but does
  203.     not open) the icon for IHelp, and selects "Info" from the
  204.     Workbench menu.  The subsequent display allows the addition,
  205.     editing, and deletion of parameter strings called ToolTypes.
  206.  
  207.     To assign the three functions above to new keystrokes, ToolType
  208.     items are added or edited to read, for example:
  209.  
  210.     CYCLE=f1
  211.     MAKEBIG=alt f5
  212.     MAKESMALL=shift alt f5
  213.  
  214.     The icon is saved, and the next time IHelp is loaded these
  215.     keystrokes prescribed by the user will be associated with
  216.     the program's actions.
  217.  
  218.  
  219.     --    NOCAPSLOCK    --
  220.  
  221.     This application is almost invisible to the user.  It monitors
  222.     all keystrokes and insures that the CAPSLOCK key on the keyboard
  223.     never has any effect (regardless of what its little red light
  224.     says).
  225.  
  226.     The shift keys still function normally, but the frequent annoying
  227.     effects of inadvertant pressing of the CAPSLOCK key are no more.
  228.  
  229.     This program provides nothing the user would want to change, 
  230.     so no ToolType fields in its icon are used.
  231.  
  232.  
  233.     --    AUTOPOINT2    --
  234.  
  235.     This function was inspired by Jude Katsch's Autopoint, which
  236.     is a program to emulate SunWindows style window activation.
  237.  
  238.     Whenever the mouse is moved (without a button depressed) this
  239.     program triese to activate the window under the mouse pointer
  240.     if it is not already active.
  241.  
  242.     The tricky part of this program was to make it work with the
  243.     Workbench Rename gadget, which it does nicely.
  244.  
  245.     Again, no ToolType fields are used.
  246.  
  247.     -----    COMMODITIES COMPONENTS    -------------------------------
  248.  
  249.     The Commodities Exchange consists of several identifiable
  250.     components which we introduce now.
  251.  
  252.  
  253.     --    commodities.library    --
  254.     This is an Amiga Exec library which creates an input handler
  255.     when it is initialized.  It provides a large number of functions
  256.     to manipulate Commodities Objects and Messages, the building
  257.     blocks of a Commodities application.  All access to data
  258.     used by this library is done procedurally: no internal data 
  259.     structures are read or modified directly by application programs.
  260.  
  261.     The functions provided by the library fall into classes:
  262.         -Object Creation/Deletion
  263.         -Object Linking
  264.         -Object Data Access/Modify
  265.         -Object Type-specific Functions
  266.         -Input Event Matching Utilities
  267.         -Message Routing/Disposing
  268.  
  269.     The library must be opened (using the Exec function OpenLibrary())
  270.     by each Commodities application.
  271.  
  272.     All parameters to the library, following Amiga library convention,
  273.     are thirty-two bit quantities.  Small-integer users must remember
  274.     that integers and characters are not promoted to thirty-two
  275.     bits by the compiler, so casts must be used.  In particular,
  276.     don't forget to cast boolean and priority values to (LONG).
  277.  
  278.  
  279.     --    Controller program    --
  280.     An application program will be used to see the loaded Commodities
  281.     and their functions.  It will be possible to use this program
  282.     to terminate an application.  It is an unrealized design goal
  283.     to write the controller using public information and interface
  284.     functions so that it would be upwardly object compatible.
  285.     In fact, the controller, if it exists at all, is very rudimentary
  286.     at the present time.
  287.  
  288.  
  289.     --    Support Scanned Library    --
  290.     A "scanned" library is also provided.  Its name is "cx_support.lib."
  291.     A scanned library contains functions which are linked into the
  292.     executable file of an application.  Included are interface routines
  293.     to commodities.library and some utility functions.  The functions
  294.     are all compatible with Aztec C conventions, and are compiled
  295.     "small code, small data, small integer."
  296.  
  297.  
  298.     --    Include Files    --
  299.     Various include files are provided.  For applications, the file
  300.     "cxusr.h" contains the principle information and itself includes
  301.     the other application include files.  The file "cx.h," if you ever
  302.     see it, contains library private data structures and constants
  303.     which are not guaranteed to be compatible from release to release.
  304.     They should not be used by any Commodities applications.
  305.  
  306.     Assembler versions of the include files don't exist yet.
  307.  
  308.  
  309.     --    Source Examples    --
  310.     As mentioned, the source for the programs IHelp, NoCapsLock, and
  311.     AutoPoint2 is provided.
  312.  
  313.  
  314.     --    Commodities Applications    --
  315.     You write these.  They open "commodities.library" and perhaps
  316.     use functions in the scanned library.  They create and interconnect
  317.     objects (see below) in such a way that particular events cause
  318.     desired actions or notifications.
  319.  
  320.     -----    COMMODITIES OVERVIEW    -------------------------------
  321.  
  322.  
  323.     --    Objects and Messages    --
  324.     The basic building block is the Commodities Exchange Object,
  325.     or CxObj.  Each object is of some particular 'type' which
  326.     corresponds to the primitive action that occur when a Commodities
  327.     Message arrives at the object.  The objects are connected together
  328.     in a large tree structure and messages corresponding to input events
  329.     rattle down different paths in the tree, triggering different actions
  330.     as they encounter different objects.
  331.  
  332.     One particular object type is the Custom object, which calls an
  333.     application provided function when a CxMsg arrives, so that
  334.     programmers can provide virtually any function not available with
  335.     the standard CxObj types.
  336.  
  337.     A Commodities Exchange Message, or CxMsg, corresponds with few
  338.     exceptions to a single Input Event.  When such a message arrives
  339.     at a CxObj, an action takes place.  This action might be
  340.     the sending of an Exec message to an application message port, the
  341.     diversion of the CxMsg down a sub-tree, or the calling of
  342.     an application-provided function. 
  343.     
  344.     All objects can be disabled (inactivated), which inhibits any
  345.     action being taken when a CxMsg arrives.  The message simply
  346.     proceeds along to its default next destination.
  347.  
  348.     Each CxObj is itself an Exec Node; one finds objects linked
  349.     together in linear lists.  Each object also contains a List
  350.     Header, which we refer to as its "personal list," so branching
  351.     off from any object can be another list.  So although the entire
  352.     linked structure of CxObj's is indeed a tree, there is a definite
  353.     preferred--or default--direction at each node of the tree.
  354.  
  355.     Starting with a Master List of CxObj's, CxMsg's tend to visit
  356.     every object in a list in turn, but certain objects can divert
  357.     them "90 degrees" whence they head off down another list, normally
  358.     the "personal list" of the CxObj performing the diversion.
  359.  
  360.     When (and if) the CxMsg reaches the end of a list, it proceeds
  361.     from where it was diverted.  A stack is maintained for
  362.     each CxMsg to record and recover from multiple diversions.
  363.  
  364.  
  365.     --    Brokers and Application Sub-Trees    --
  366.     The CxObj's in the Master List are a special lot.  They
  367.     are called Commodities Brokers (get it?) and are typically in
  368.     one-to-one correspondence with application programs.  They
  369.     are "representatives" of the application programs; the
  370.     sub-tree starting with the personal list of a Broker consists
  371.     of the CxObj's created by the application.
  372.  
  373.     When it is enabled, a Broker will divert ALL CxMsg's it receives
  374.     down its personal list, into the network of objects the
  375.     application has set up.
  376.  
  377.     Support is provided for preventing the creation of duplicate
  378.     brokers.  This gives the application an easy way of determining
  379.     during its initialization if there is another copy of itself
  380.     already running.  The new copy can terminate, and it can be
  381.     arranged that the existing copy be notified that a restart
  382.     attempt was made.  A resident but dormant pop-up notepad program
  383.     might take such a notification that it should open up a window
  384.     and swing into action.
  385.  
  386.  
  387.     --    Standard Objects    --
  388.     The actions performed by CxObj's of the standard types are intended
  389.     to be primitive.  An application wishing to receive an Exec message
  390.     when a particular keystroke occurs must create three CxObj's for
  391.     the task: one to filter the CxMsg's for one corresponding to 
  392.     the keystroke, and attached to its list, a CxObj to send off
  393.     an Exec Message and another (optional) to swallow the CxMsg.
  394.  
  395.     These three are in addition to the application's (single) broker.
  396.  
  397.     A filter acts by diverting a select set of CxMsg's down its
  398.     personal list, where they will encounter the other two objects
  399.     who unconditionally perform their action.
  400.  
  401.     Here is a summary of the CxObj types and a brief description
  402.     of each:
  403.  
  404.         Broker    --    only CxObj's on Master List
  405.                     contain a description of the application
  406.                     diverts everything down its personal list
  407.         Filter    --    if CxMsg matches some expression, divert 
  408.         TypeFilter-    if CxMsg has type in specified set, divert
  409.         Signal    --    signals some task when any CxMsg arrives
  410.         Sender    --    sends copy of CxMsg to some port (asynchronous)
  411.         Translate-    replaces CxMsg with a chain of zero or more
  412.                     new input event CxMsg's
  413.         Debug    --    dumps message contents to debug device (kprintf)
  414.         Custom    --    calls a programmer-provided function (synchronous)
  415.  
  416.     There is a more detailed description in the Function Reference
  417.     sections for the functions which create the various types of 
  418.     CxObj.
  419.  
  420.  
  421.     --    Custom Objects    --
  422.     Custom objects take a unique action.  They call a function
  423.     provided by the application SYNCHRONOUSLY with the execution of
  424.     the Commodities handler.  The delicacy of this cannot be over-
  425.     emphasized.  The function will execute as part of the input.device
  426.     task.  No DOS or Intuition functions may be called.  Although
  427.     the handoff saves and restores all registers, no assumptions
  428.     can be made about the values of registers upon entry.  For
  429.     Aztec C functions, it is sufficient (and necessary!) to call
  430.     the function geta4() (Aztec provided) to establish the context
  431.     register for the routine.
  432.  
  433.     All such functions should be kept quick and simple, with a
  434.     MINIMUM of stack usage.  A Custom CxObj is the only way to
  435.     directly modify input events as their CxMsg's proceed
  436.     through the Commodities network, but uses other than that 
  437.     should be thought about long and hard and again.
  438.  
  439.  
  440.     --    Input Events and Matching Conditions    --
  441.     As mentioned above, most CxMsgs correspond to InputEvents.
  442.     Now is a good time to reread the Chapter 9, The Input Device,
  443.     in the ROM Kernel Reference Manual, volume 2.  See also
  444.     the include file devices/inputevent.h.
  445.  
  446.     Each input event which reaches the Commodities handler is neatly
  447.     copied into a CxMsg and sent through the CxObj network.
  448.     If it makes it all the way through (i.e., to the end of the Master
  449.     List) the contents--which may have been changed by some object--
  450.     are copied into an input event and sent along to subsequent
  451.     input handlers, including Intuition, and along to Window
  452.     (i.e., non-Commodities) applications.
  453.  
  454.     Flow of an input event CxMsg is determined by its interactions
  455.     with filter objects.  Each filter object has a "matching condition"
  456.     assigned by the application which determines which messages will
  457.     be diverted down the filter's personal list (those that match).
  458.  
  459.     The internal representation of this matching condition is private,
  460.     but can be specified by two mechanisms.  Enhancements and additions
  461.     to these mechanisms can be expected; provisions for upward
  462.     compatibility are made for both.
  463.  
  464.     We spend some time going through the currently available capabilities
  465.     in some detail, since they have avoided documentation elsewhere.
  466.  
  467.  
  468.     -- Input Description Strings --
  469.     NOTE: This material is significantly changed for version 0.3
  470.  
  471.     These are the character strings found in the ToolTypes fields
  472.     described in the introduction to the sample program IHelp.
  473.  
  474.     Each string described a subset of input events.
  475.  
  476.     [class] [{[-](qual | syn)}] [[-]upstroke] [highmap|ansicode]
  477.  
  478.     which means an optional class (default is RAWKEY), zero or
  479.     more qualifiers, and a mandatory code value,  where "class,"
  480.     "qualifier," and "code" in lower case, from the following list:
  481.  
  482.     class    --     
  483.         one of the strings: 
  484.         rawkey, rawmouse, event, pointerpos, timer, newprefs,
  485.         diskremoved, diskinserted.
  486.  
  487.         If not specified, the class is taken to be "rawkey."
  488.  
  489.     qual    --
  490.         one of the strings: 
  491.         shift, rshift, capslock, control, lalt, ralt, lcommand, rcommand,
  492.         numericpad, repeat, midbutton, rbutton, leftbutton, relativemouse,
  493.  
  494.         A preceding '-' means that the value of the corresponding
  495.         qualifier is to be considered irrelevant.
  496.  
  497.     syn        -- (synonym)
  498.         one of the strings: shift, caps, alt
  499.         shift    (means "left or right shift"), caps    (means "either shift
  500.         or capslock"), alt (means "either alt key").
  501.  
  502.     upstroke--     (literally "upstroke")
  503.         if this token is absent, only downstrokes are considered
  504.         for rawmouse (mousebuttons) and rawkey events.  If it is
  505.         present alone, only upstrokes count.  If it preceded by
  506.         '-' it means that both up and down strokes are included.
  507.  
  508.     highmap    --
  509.         one of the strings: 
  510.         space, backspace, tab, enter, return, esc, del, up, down,
  511.         right, left, help, f1, f2, f3, f4, f5, f6, f7, f8, f9, f10.
  512.  
  513.     ansicode --
  514.         a single character token is interpreted as a character code,
  515.         which is looked up in the system default keymap. 
  516.  
  517.     Examples of strings are:
  518.  
  519.         "lshift right alt f2"
  520.         "alt shift a"
  521.         "-shift -alt -control help" (help key with or without qualifiers)
  522.         "rawmouse rbutton"        (mouse move with menu button down)
  523.  
  524.     Enhancements to the grammar are anticipated.  Every attempt
  525.     will be made to be compatibile with the input descriptions
  526.     of the early version.
  527.  
  528.     --    Input Expressions    --
  529.     Applications can also use a powerful binary specification of
  530.     the matching condition for a filter.  In the future, perhaps
  531.     a more powerful specification may be developed so the data 
  532.     structures for the Input Expressions (type IX) are tagged with
  533.     their version number.  This will allow easy handling of different
  534.     specification types co-existing in a future Commodities
  535.     version.
  536.  
  537.     The Version 2 IX structure is as follows and the conditions that
  538.     it specifies a match with an InputEvent are described:
  539.  
  540.     typedef struct {
  541.         UBYTE    ix_Version;
  542.         UBYTE    ix_Class;
  543.  
  544.         UWORD    ix_Code;
  545.         UWORD    ix_CodeMask;
  546.  
  547.         UWORD    ix_Qualifier;
  548.         UWORD    ix_QualMask;
  549.         UWORD    ix_QualSame;
  550.     } IX;
  551.  
  552.     ix_Version -- must be set to the manifest constant IX_VERSION
  553.     found in the same include file ("ix.h") as the structure
  554.     definition.
  555.  
  556.     ix_Class  -- must exactly equal the ie_Class field of an InputEvent
  557.     to match.
  558.  
  559.     ix_Code, ix_CodeMask -- for every bit set in ix_CodeMask, the
  560.     state of the corresponding bits in ix_Code and ie_Code in the
  561.     InputEvent must match.  Note that whether a keystroke or mouse
  562.     button action is a down- or upstroke is encoded in the
  563.     ie_Code field of the InputEvent (IE_CODE_UPPREFIX).
  564.  
  565.     ix_Qualifier, ix_QualMask, ix_QualSame -- the fields ix_QualMask
  566.     and ix_QualMask work in the same way as for the Code: the Mask
  567.     indicates the "do care" bits in ie_Qualifier, with ix_Qualifier
  568.     specifying the required settings for those bits.  The ix_QualSame
  569.     field is used to express simple synonyms in the ie_Qualifier.
  570.     Using this, you can specify that left- and right Shift- are
  571.     equivalent and whether the CAPSLOCK qualifier is also equivalent.
  572.     Left- and right-Alt can also be made equivalent.
  573.  
  574.  
  575.     --    Message Routing    --
  576.     So far a few points have come out about routing CxMsg's:
  577.  
  578.     -In the absence of some action diverting them, after visiting
  579.      a CxObj, they will proceed to the next node in the same list.
  580.  
  581.     -They may be diverted down the "personal list" of some CxObj,
  582.      normally the list belonging to the object doing the diverting.
  583.      Diverting consists of pushing the address of the current CxObj
  584.      onto an internal stack and routing to the first CxObj in the list.
  585.  
  586.     -When they reach the end of a list of CxObj's, the address of a
  587.      CxObj is popped off of their stack, and they proceed to the
  588.      Successor of that object.
  589.  
  590.      Reaching the end of the Master List sends the CxMsg to an internal
  591.      "Zero Object" which disposes of the message, first recovering
  592.      InputEvents from the contents of input event messages.
  593.  
  594.     Application programs (using Custom Objects) can route a message
  595.     two ways: diverting it down the list of some object, or by routing
  596.     it directly to another object.  Future functions may be provided
  597.     for independently pushing or popping the routing stack.
  598.  
  599.     Note that it makes no sense and is indicative of greater misunder-
  600.     standing to try to route a message sent to a port by a sender
  601.     CxObj.
  602.  
  603.  
  604.     -----    The Examples, Revisited        ----------------------------
  605.     With the background so far, it is helpful to consider the object
  606.     structure used by the example programs discussed above.
  607.  
  608.  
  609.     -- IHelp --
  610.     IHelp has three "hotkeys."  These are triads of objects discussed
  611.     briefly above.  There is a routine in the support library that
  612.     creates these groups of objects easily.
  613.  
  614.     A hotkey triad, to review, consists of a filter object, which
  615.     is the "trigger" for the hotkey.  Attached to its personal list
  616.     is a sender which sends a notification message to a port allocated
  617.     by IHelp. 
  618.     
  619.     The ID field of the several senders differ, so that IHelp can
  620.     easily tell from which sender the messages were sent.  IHelp
  621.     pays no attention to the data part of the messages it is sent.
  622.  
  623.     Following the sender in the personal list of the filter is a
  624.     translator object which translates the trigger CxMsg to NULL,
  625.     in effect swallowing it.
  626.  
  627.     IHelp, like all good Commodities, has a Broker, and the filter
  628.     objects at the head of the hotkeys are all attached to its list.
  629.  
  630.  
  631.     --    NoCapsLock    --
  632.     Attached to the Broker list of this application is a single filter
  633.     which watches for all RAWKEY events which have the CAPSLOCK bit
  634.     set.  It diverts them down its list where a single custom object
  635.     can be found.
  636.  
  637.     This custom object modifies the InputEvent included in each CxMsg
  638.     it encounters, clearing the CAPSLOCK bit.  It has no effect on
  639.     other Qualifier bits, so even if the CapsLock key is active, the
  640.     shift keys will function normally.
  641.  
  642.  
  643.     --    Autopoint2    --
  644.     Attached to the Broker is a single filter, watching for RAWMOUSE
  645.     events with neither mouse button depressed.  CxMsgs carrying such
  646.     events are diverted down to a signal CxObj, which wakes up the
  647.     AutoPoint task.  Once awakened it does magic.
  648.  
  649.     Note that a signal is just the ticket for this function, saving the
  650.     overhead of creating, sending, and replying to an Exec message.
  651.     
  652.  
  653.     -----    More Details    ----------------------------------------
  654.  
  655.     --    Error Handling    --
  656.     A well-behaved program must always check that functions which
  657.     create CxObj's succeed, since each object requires some dynamically
  658.     allocated memory.  To make this a little less tedious, it is
  659.     possible to get by testing if entire list of objects was created
  660.     successfully, and to recover gracefully if not.  See the examples.
  661.     And check for and handle all errors, OK?
  662.  
  663.  
  664.     --    ToolTypes and the Commodities Environment    --
  665.     Some functions are provided to make it easy to use ToolTypes
  666.     for providing user control over the parameters of your
  667.     application.  Please let the user specify the input description
  668.     for major semantic actions in your programs. 
  669.     
  670.     Also, even if there is no obvious reason in some cases, let the
  671.     user set the priority for your broker.  That is the key step to
  672.     making the functioning of a group of Commodities applications
  673.     independent of the order in which they were loaded.
  674.  
  675.     Note that the functions provided also support command line
  676.     argument parsing so Commodities can be started from the
  677.     CLI with full user control (this is especially useful for
  678.     starting up a batch of applications from an Execute script file).
  679.  
  680.  
  681.     --    Library version    --
  682.     Be sure to specify a non-zero version number to the OpenLibrary()
  683.     call when opening Commodities.  This insures that the end user
  684.     does not use your program with a version of the library that
  685.     doesn't support new features you are depending on.
  686.  
  687.  
  688.     --    Terminating a Commodities Application    --
  689.     As is shown in the examples, the proper terminating condition of a
  690.     Commodities application is the receipt of the Control-E break signal.
  691.  
  692.     This signal will be sent by controller software to the task which
  693.     created a Broker when the user indicates that that Broker's program
  694.     is to be terminated.  It is also easy to send such a signal to 
  695.     a background task started from the CLI.  Use the "Status" command
  696.     to find the tasks CLI ID, and then say "Break task <n> E" where
  697.     <n> is the number from the Status output.
  698.  
  699.     Developing a Commodities application is made more convenient 
  700.     using this convention (we often test them in the foreground,
  701.     and typing Control-E usually works long before the rest of the
  702.     program), and we also don't waste function keys or other input
  703.     combinations on termination commands.
  704.  
  705.  
  706.     --    Pools and Alerts    --
  707.     The internal data structures used by the Commodities library are
  708.     allocated and managed by a common "Pool" mechanism.  Normally,
  709.     this mechanism is invisible to the programmer and end-user.  It
  710.     is used to manage data storage for Commodities objects, messages,
  711.     Exec messages, and InputEvents.
  712.  
  713.     In the early releases of Commodities, however, this one included,
  714.     a recoverable alert will be put up if a program corrupts the
  715.     secret header of a Commodities data structure, or uses an invalid
  716.     handle in certain operations.  Another recoverable alert is
  717.     posted when commodities.library expunges (which is done when the
  718.     last application closes the library) if all data structures are
  719.     not returned to Commodities before this time.  The frequent
  720.     causes for this are not replying to all the Exec messages Commodities
  721.     senders send to you, and not deleting all the objects that you
  722.     have created.
  723.  
  724.     To properly reply all Exec messages sent to your program, a sequence
  725.     like that used in IHelp is advised:
  726.  
  727.         DeleteCxObjAll(broker);
  728.         while (msg = GetMsg(port)) ReplyMsg(msg);
  729.         CloseLibrary(CxBase);
  730.  
  731.  
  732.     -----    Future Versions and Compatibility    -------------------
  733.     As stated in the Preface, this version of Commodities Exchange is
  734.     not complete, with a few important things not present.  In this
  735.     section we discuss things to come and compatibility issues.
  736.  
  737.  
  738.     -- Controller    --
  739.     Prominent in its absence is the controller application that will
  740.     allow the user to view (the brokers of) all the Commodities
  741.     applications, experiment with their priority, temporarily disable
  742.     them, and terminate them.
  743.  
  744.     It was a design goal to provide enough procedural interface through
  745.     the library to allow a "legal" application to walk through the
  746.     Commodities object tree and report what it sees, but implementation
  747.     of that interfered with the main functions of the library.
  748.  
  749.     Until at least a rudimentary controller is made available, Commodities
  750.     applications are best started from the CLI, so that they may be
  751.     terminated by the CLI "Break" command (using the Control-E signal).
  752.  
  753.     Note that the "ToolTypes" parameter environment can be specified
  754.     on the CLI command line, like so:
  755.         run ihelp "CYCLEBACK=alt shift f5"
  756.  
  757.  
  758.     -- User Visible Filters    --
  759.     Another dream for the controller is that it could report on some
  760.     of the hotkeys or other event triggers that an application had
  761.     installed.  This would provide, for example, an easy way for the
  762.     user to see exactly what key cycles the windows in IHelp.
  763.  
  764.     To accomplish this, an extension will need to be made of the
  765.     Filter, with the application further specifying descriptive text
  766.     for user-visible filters, and whether the user may modify the
  767.     event matching condition, and what restrictions apply to his
  768.     modifications.  Prototypes of this have been played with, but
  769.     the inclusion into the library will have to wait.  Existing
  770.     filters will always be compatible, but even those that should
  771.     be visible to the user never will be.
  772.  
  773.  
  774.     --    Active Window Knowledge    --
  775.     It is in the plans to hang another Commodities input handler
  776.     on the input.device handler chain, but FOLLOWING Intuition 
  777.     instead of preceeding (but preceding the Console).
  778.  
  779.     This would allow a keystroke enhancer to make different translations
  780.     for different windows.  Another use of such a thing would be to
  781.     allow non-interactive programs (i.e., those with no window) be
  782.     informed of a preferences change.
  783.  
  784.     This will manifest itself as a new flag bit that can be set in
  785.     the NewBroker structure to indicate post-Intuition processing,
  786.     and a new kind of filter which only diverts events if a particular
  787.     window is active.
  788.  
  789.     Religiously setting all undefined NewBroker.nb_Flags bits to zero
  790.     will insure compatibility with this change.
  791.  
  792.  
  793.     --    BindCommodities    --
  794.     In spite of the lack of a controller today, the preferred method
  795.     of starting a Commodities application and establishing a parameter
  796.     environment will be through the use of icons.
  797.  
  798.     In the meantime, one can start up several Commodities applications
  799.     with a batch file (which can't be run from the start-up script since
  800.     jobs left in the background prevent the Initial CLI from closing).
  801.  
  802.     When we make it to icons, we will need a way to start up a collection
  803.     of Commodities by referencing their icons.  Neil "Workbench" Katin,
  804.     author also of BindDrivers, pledges a similar program which will 
  805.     start every program with an icon in some specified drawer, with
  806.     their start-up environment being identical to that when started
  807.     from the Workbench.
  808.  
  809.     Such a program will have myriad uses (starting notepads, etc.) but
  810.     our interest will be in starting a directory full of Commodities
  811.     applications.
  812.  
  813.  
  814.     --    Timer Support    --
  815.     Right now, events of type IECLASS_TIMER don't go through the
  816.     Commodities object network, largely because there wasn't time
  817.     to profile the performance of the system, and they are a frequent
  818.     and low-payoff burden.
  819.  
  820.     A new standard object, the "One-Shot Timer Filter," will someday
  821.     exist, which will be set to some unsigned integer value by the
  822.     application.  Each time a TIMER event passes its way, it will
  823.     decrement the count.  When the count reaches zero, ONE timer
  824.     CxMsg will be diverted down the filter's personal list, and
  825.     the filter will then become dormant until the count is reset.
  826.  
  827.  
  828.     --    Profile and Downcode    --
  829.     We don't know how slow this beast is, especially with lots and
  830.     lots of objects.  Existing profilers don't apply to Exec library
  831.     code, and there hasn't been any time to do something about it.
  832.  
  833.     With the timers eliminated, the author's experience hacking Intuition
  834.     indicates that human-schedule input is pretty slow, and that any
  835.     input-response bottleneck typically occur on the output side of
  836.     the fence.  That is to say, we hope it's fast enough.  There
  837.     are several routines which are prime contestants for assembly
  838.     language downcoding.
  839.  
  840.     If there is sufficient uproar, we will break apart the library
  841.     interface functions of the scanned library into separate files,
  842.     so that your program will only link in just the interface code
  843.     it needs.
  844.  
  845.  
  846.     -- Keystroke Programmers    --
  847.     Although lots of features are present to make writing a keystroke
  848.     macro utility much easier, reports of direct experience returned
  849.     to the author will undoubtedly show areas of needed change.  We
  850.     will try to be most responsive to people forging new ground.
  851.  
  852.  
  853.     -- More CxMsg Types    --
  854.     There are only two types of Commodities Messages currently:
  855.     CXM_IEVENT, by far the most common; and CXM_UNIQUE, which notifies
  856.     Brokers who are interested that another attempt was made to start
  857.     their applications.
  858.  
  859.     More may be coming, perhaps in support of Post-Intuition Commodities.
  860.     Program defensively by not assuming anything about the type of
  861.     a CxMsg unless that message has passed through a filter of some
  862.     sort.
  863.  
  864.  
  865.     --    Support for More Languages    --
  866.     Commodities Exchange was developed under Aztec-C, and the scanned
  867.     library cx_support.lib is an Aztec convention, small model library.
  868.  
  869.     Amiga type naming, as found in exec/types.h, are used exclusively
  870.     in commodities.library, but some 'ints' sneaked into cx_support.lib.
  871.  
  872.     Support for other compilers, languages, and assembler should be
  873.     done someday.  Particularly lacking are assembler include files.
  874.  
  875.  
  876.     --    Documentation    --
  877.     Hopefully, the state of this manual will succumb to revision.
  878.  
  879.     APPENDIX (for now)
  880.  
  881.     Three big changes have been added:
  882.     
  883.     The function InvertKeyMap() converts an ANSI character code
  884.     to the InputEvent that maps to it (using KeyMaps).  This function
  885.     is used by the function InvertString() which translates a special
  886.     extension of ANSI character strings into a chain of input events. 
  887.  
  888.     ParseIX() has been greatly enhances (and tested a little).  See
  889.     the description above, in this document.
  890.  
  891.     AddIEvents() provides a trivial method of adding a chain of 
  892.     input events to the Input Food Chain starting before Commodities.
  893.  
  894.     See the function descriptions for more information.
  895.