home *** CD-ROM | disk | FTP | other *** search
/ CGI How-To / CGI HOW-TO.iso / chap6 / 6_1 / direc_c / handler.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-06-15  |  1.5 KB  |  67 lines

  1.  
  2. #include "handler.h"
  3.  
  4.  
  5. void directiveHandler(String ts,String as,String et,Dictionary td)
  6. {
  7.     String argString = 0;
  8.     String endTag = 0;
  9.     String type;
  10.     void (*handler)();
  11.     
  12.     /* Find out what type of directive this is. */
  13.     type = dict_valueForKey(td,"TYPE");
  14.     
  15.     /* Determine the registered type name, and look for a handler */
  16.     if(type->string)
  17.     {
  18.         String registeredType;
  19.         
  20.         registeredType = string_alloc(strlen(type->string));
  21.         
  22.         string_setStringValue(registeredType , "directive."); 
  23.         string_appendString(registeredType , type->string); 
  24.     
  25.         /* See if there is an endtag or a handler registered*/
  26.         endTag = dict_valueForKey(endTags, registeredType->string);
  27.         
  28.         handler = dict_valueForKey(handlerDict, registeredType->string);
  29.         
  30.         string_free(registeredType);
  31.     }
  32.     
  33.     /* If there is a handler, use it */
  34.     if(handler)
  35.     {
  36.         /* If there is an end tag, parse up to it
  37.          * be sure to remove the end tag from the body text.
  38.          */
  39.         if(endTag && endTag->string)
  40.         {
  41.             char * finalPointy = 0;
  42.             
  43.             argString = mainHtmlParser(endTag->string);
  44.             
  45.             /* Get rid of the end tag */
  46.             
  47.             if(endTag->string[0] == '<')/* this is a real tag */
  48.             {
  49.                 finalPointy = strrchr(argString->string,'<');
  50.                 
  51.                 /* End the string at the final <, thus removing the end tag */
  52.                 if(finalPointy) *finalPointy = '\0';
  53.             }
  54.         }
  55.         
  56.         /* Call the handler */
  57.         handler(ts,argString,endTag,td);
  58.     }
  59.     else /* No handler, return an empty string, this removes the directive */
  60.     {
  61.         string_setStringValue(ts,"");
  62.     }
  63.     
  64.     /* Clean up */
  65.     string_free(argString);
  66. }
  67.