C Macros for use in SXLib Code

PROBLEM
this introduces an "exception" to the evaluator and displays the message which is provided immediately after the PROBLEM word. This string can use the same formatting strings available in printf and the relevant objects to which these apply are list after the string. The list is terminated with the word ERROR or WARN which indicate the action to take.
        PROBLEM "Object of incorrect class (%s) passed to function
                  with length %ld",
                        object->Class->name,
                        object->length
        ERROR;
      
ERROR
this is the second element in the PROBLEM - action. This singals an error and causes the evaluator to go into recover mode, displaying the message introduced by PROBLEM and entering the recover browser.
WARN
this is the second element in the PROBLEM - action. This singals the evaluator to issue the warning message supplied after the PROBLEM identifier when the evaluation completes this task. The usual warning handler is used which only displays a limited number of messages or a single message indicating the number of warnings generated in a task.
SLOT_NUM
this macro uses two arguments - the S object pointer and a character string which is the name of a slot in the object's class. It returns a long which is the number in the class representation (using 0 based counting) of that slot.
         name_slot = SLOT_NUM(obj, "name")
         if(name_slot < 0) {
           PROBLEM "Object of incorrect class passed to [function name]"
           ERROR;
         }
      
COPY_TO_RAW
this copies a C data structure to an S object of class "raw". The number of bytes to copy is determined by the type passed as the third argument. The first argument is the S object pointer into which the object will be copied. The second argument is the C structure being copied.
          Display *dpy = XOpenDisplay(NULL);
            COPY_TO_RAW(slots[dpy_slot], &dpy, Display*);
      
COPY_FROM_RAW
this copies the data in an S object of class "raw" to a C object. The number of bytes to copy is determined by the type passed as the third argument. The first argument is the S object pointer from which the object will be copied. The second argument is the C structure into which the data is copied.
          Display *dpy;
            COPY_FROM_RAW(slots[dpy_slot], &dpy, Display*);
      
ENSURE_CLASS_EXISTS
This calls the macro ENSURE_CLASS and simply forces the class into the internal list of classes recognized by the S process. It is good practice to call this as it will only force the updateing of the internal table once the first time it is called for the supplied class.
       s_object *object;
           .
           .            /* Get the object from somewhere */
           .
         ENSURE_CLASS_EXISTS(object)
      

Duncan Temple Lang<duncan@stat.Berkeley.EDU>
Last modified: Tue Mar 4 11:48:18 PST 1997