home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / demos / gpc / brf_except.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-02-15  |  18.8 KB  |  536 lines

  1. /* $XConsortium: brf_except.c,v 5.1 91/02/16 10:07:14 rws Exp $ */
  2. /***********************************************************
  3. Copyright(c) 1989,1990, 1991 by Sun Microsystems, Inc. and the X Consortium at M.I.T.
  4.  
  5.                         All Rights Reserved
  6.  
  7. Permission to use, copy, modify, and distribute this software and its
  8. documentation for any purpose and without fee is hereby granted,
  9. provided that the above copyright notice appear in all copies and that
  10. both that copyright notice and this permission notice appear in
  11. supporting documentation, and that the names of Sun Microsystems,
  12. the X Consortium, and MIT not be used in advertising or publicity
  13. pertaining to distribution of the software without specific, written
  14. prior permission.
  15.  
  16. SUN MICROSYSTEMS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  17. INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT
  18. SHALL SUN MICROSYSTEMS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
  19. DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  20. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  21. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  22. SOFTWARE.
  23.  
  24. ******************************************************************/
  25.  
  26. /*--------------------------------------------------------------------*\
  27. |  Copyright (C) 1989,1990, 1991, National Computer Graphics Association
  28. |
  29. |  Permission is granted to any individual or institution to use, copy, or
  30. |  redistribute this software so long as it is not sold for profit, provided
  31. |  this copyright notice is retained.
  32. |
  33. |                         Developed for the
  34. |                National Computer Graphics Association
  35. |                         2722 Merrilee Drive
  36. |                         Fairfax, VA  22031
  37. |                           (703) 698-9600
  38. |
  39. |                                by
  40. |                 SimGraphics Engineering Corporation
  41. |                    1137 Huntington Drive  Unit A
  42. |                      South Pasadena, CA  91030
  43. |                           (213) 255-0900
  44. |---------------------------------------------------------------------
  45. |
  46. | Author        :    Michael Rivero
  47. |
  48. | File          :    brf_except.c
  49. | Date          :    Sat Feb 10 10:28:21 PST 1990
  50. | Project       :    BIF Benchmark Reporting System
  51. | Description   :    Exception Handler Routines
  52. |            Reference port contains exception definitions
  53. |            for Alliant GX4000 PHIGS+ v1.4.2
  54. | Status        :    Version 1.0
  55. |
  56. | Revisions     :    
  57. |
  58. |      12/90            MFC Tektronix, Inc.: PEX-SI PEX5R1 Release.
  59. |
  60. \*--------------------------------------------------------------------*/
  61.  
  62. /*--------------------------------------------------------------------*\
  63. |    Table of Contents
  64. |
  65. |    char BRF_define_exceptions()
  66. |        :    Load the definitions for the known exceptions
  67. |    int BRF_do_exceptionsearch(*BIF_All,*BRF_state)
  68. |        :    Test for exceptions
  69. |    int BRF_do_optionaltest( *BIF_All, int)
  70. |        :    Test for exceptions in optional data groups
  71. |    int BRF_realrange( *BIF_All, int)
  72. |        :    Test if real values inside bif entity
  73. |    int BRF_intrange( *BIF_All, int)
  74. |        :    Test if int values inside bif entity
  75. |    int BRF_truecolor( *BIF_All, int)
  76. |        :    Test if is in true color mode during true color
  77. |    int BRF_pseudocolor( *BIF_All, int)
  78. |        :    Test if is in psuedo color mode during true color
  79. |
  80. \*--------------------------------------------------------------------*/
  81. #include <stdio.h>
  82. #include "biftypes.h"
  83. #include "globals.h"
  84. #include "bifparse.h"
  85. #include "brfexption.h"
  86. #include "brftypes.h"
  87. #include "brfexmacro.h"
  88.  
  89. /* where we keep the exception table info. Needs to be
  90. declared external in brf_trv.c */
  91.  
  92. BRF_exception brf_exception[MAX_EXCEPTION];
  93.  
  94. static char tmpstring[150];
  95. int charcount;
  96. int num_frames;
  97. /*--------------------------------------------------------------------*\
  98. | Procedure     :    char BRF_define_exceptions()
  99. |---------------------------------------------------------------------
  100. | Description   :    Load the definitions for the known exceptions
  101. |
  102. |---------------------------------------------------------------------
  103. | Revisions     :
  104. |
  105. |---------------------------------------------------------------------
  106. | Return        :    
  107. \*--------------------------------------------------------------------*/
  108. int BRF_define_exceptions()
  109.  
  110. {/* BRF_define_exceptions */
  111. register int i;
  112. int listptr;
  113. #ifdef EXTERNALNOTE
  114.         /*  Any special exception handlers written must be declared
  115.     in this routine in order to have a function pointer inside the
  116.     exceptions table. */
  117. #endif
  118.  
  119. extern int BRF_do_optiontest();
  120. extern int BRF_realrange();
  121. extern int BRF_intrange();
  122. extern int BRF_truecolor();
  123. extern int BRF_pseudocolor();
  124.  
  125.     listptr = 0;
  126.  
  127.         /*----------------------------------------------------------------*\
  128.         |       Set the definitions for the exception handler
  129.         \*----------------------------------------------------------------*/
  130.  
  131. #ifdef EXTERNALNOTE
  132.     /* This is where all known exceptions are stated. The only
  133.     portion of PLB not accessable to the exception tests at the top of the
  134.     BRF traversal tree are those connected with configuration issues. It
  135.     should (in theory) be possible to describe all possible exceptions
  136.     here and have them test for at the top of the BRF traversal tree.
  137.     Configuration exception code must be 'hard wired' at the point
  138.     at which configuration is set (such as init_bench.c). */
  139. #endif
  140.     
  141.     /* The format for an exception entry is as follows
  142.     brf_ex_type        The entity type integer.
  143.     brf_ex_flag        This flag is set to a degree of failure value.
  144.                 The degree codes are defined in brfexception.h.
  145.                 This value modifies the output of the exception.
  146.     brf_ex_optional[7]    Markers for optional data groups,
  147.                 used to mark the individual exceptions.
  148.     brf_ex_range[2]        Holds range values in integer form.
  149.     brf_ex_rrange[2]    Holds range values in float form.
  150.     brf_ex_custom_handler    Generic pointer to optional custom 
  151.                 exception tester code.
  152.     brf_ex_message        The actual exception message text to be
  153.                 output if this exception occurs.
  154.     */
  155.  
  156.  
  157.         /*----------------------------------------------------------------*\
  158.         |       List 1: Non-Supported Features
  159.         \*----------------------------------------------------------------*/
  160. #ifdef EXTERNALNOTE
  161.         /* These are the feature not supported in any PEX implementation
  162.            all implementation dependent exceptions are in init_bench.c */
  163.  
  164.     /* THE DEFINES FOR THESE MACROS ARE IN BRF_EX_MACRO.H */
  165. #endif
  166.  
  167.         LIST_NONSUP(PIXEL_MAP3,BRF_ERROR,"PIXEL_MAP3 Not Supported.\n");
  168.     LIST_NONSUP(TEXT_FONT,BRF_ERROR,"TEXT_FONT: Only one font is supported.\n");
  169.  
  170.         /*----------------------------------------------------------------*\
  171.         |       List 2: Optional Data Group Exceptions
  172.         \*----------------------------------------------------------------*/
  173.  
  174.  
  175.         /*----------------------------------------------------------------*\
  176.         |       List 3: Range Exceptions
  177.         \*----------------------------------------------------------------*/
  178.  
  179.  
  180.         /*----------------------------------------------------------------*\
  181.         |       List 4: True Color in Pseudo Mode
  182.         \*----------------------------------------------------------------*/
  183.  
  184.     LIST_COLORMODE(LINE_COLOR,BRF_ERROR,BRF_truecolor,"True LINE_COLOR called while in Pseudo Color Mode.\n");
  185.     LIST_COLORMODE(INTERIOR_COLOR,BRF_ERROR,BRF_truecolor,"True INTERIOR_COLOR called while in Pseudo Color Mode.\n");
  186.     LIST_COLORMODE(BACKFACE_INTERIOR_COLOR,BRF_ERROR,BRF_truecolor,"True BACKFACE_INTERIOR_COLOR called while in Pseudo Color Mode.\n");
  187.     LIST_COLORMODE(EDGE_COLOR,BRF_ERROR,BRF_truecolor,"True EDGE_COLOR called while in Pseudo Color Mode.\n");
  188.     LIST_COLORMODE(TEXT_COLOR,BRF_ERROR,BRF_truecolor,"True TEXT_COLOR called while in Pseudo Color Mode.\n");
  189.     LIST_COLORMODE(BACKGROUND_COLOR,BRF_ERROR,BRF_truecolor,"True BACKGROUND_COLOR called while in Pseudo Color Mode.\n");
  190.     LIST_COLORMODE(VERTEX_COLORS,BRF_ERROR,BRF_truecolor,"True VERTEX_COLORS called while in Pseudo Color Mode.\n");
  191.     LIST_COLORMODE(FACET_COLORS,BRF_ERROR,BRF_truecolor,"True FACET_COLORS called while in Pseudo Color Mode.\n");
  192.  
  193.     brf_num_ex_tests = listptr; /* save the number of messages */
  194.     return(TRUE);
  195.  
  196. }/* BRF_define_exceptions */
  197.  
  198.  
  199. /*--------------------------------------------------------------------*\
  200. | Procedure     :    int BRF_do_exceptionsearch(*BIF_All,*BRF_state)
  201. |---------------------------------------------------------------------
  202. | Description   :    Test for exceptions
  203. |
  204. |---------------------------------------------------------------------
  205. | Revisions     :
  206. |
  207. |---------------------------------------------------------------------
  208. | Return        :    
  209. \*--------------------------------------------------------------------*/
  210. int BRF_do_exceptionsearch(bif_entity,brf_state)
  211. BIF_All *bif_entity;
  212. BRF_state *brf_state;
  213. {/* BRF_do_exceptionsearch */
  214. register int i, j, k;
  215. int (*handlerptr)();
  216.  
  217.     charcount = 0;
  218.     num_frames = brf_state->brf_num_frames;
  219.  
  220.         /*----------------------------------------------------------------*\
  221.         |       Apply the current entity against the known exceptions.
  222.         \*----------------------------------------------------------------*/
  223.  
  224. #ifdef EXTERNALNOTE
  225.     /* This routine is called at the top of the brf traversal tree.
  226.     It takes as input the current bif_entity. The table
  227.     of known exceptions is searched, and if necassary, seperate routines
  228.     pointed to by custom_handler are executed. If an axception has
  229.     occurred, increment the exception counter in the table.
  230.     IMPORTANT NOTE. For all nested custom handlers, the BOTTOM MOST
  231.     layer of the test is the one which should increment the exception
  232.     counter. This keeps the exception output
  233.     at the ends of the branches of the decision tree.
  234.     The important points to remember are that the argument list to
  235.     the special handlers must always be identical, so if a special
  236.     handler requires more than the bif_entity pointer and the index
  237.     to the current entry on the exception table, then ALL
  238.     the handler routines will have to be changed, or you will
  239.     get a segmentation fault. */
  240.  
  241. #endif
  242.  
  243.         /*----------------------------------------------------------------*\
  244.         |       Loop through the entries in the exception table
  245.         \*----------------------------------------------------------------*/
  246.  
  247.     for(i=0;i<brf_num_ex_tests;i++)
  248.     {
  249.         /*----------------------------------------------------------------*\
  250.         |       Does the type of entity match the type of the current 
  251.     |    table entry?
  252.         \*----------------------------------------------------------------*/
  253.         if(bif_entity->entity_type==brf_exception[i].brf_ex_type)
  254.         {
  255.  
  256.         /*----------------------------------------------------------------*\
  257.         |       Is there a custom exceptions handler?
  258.         \*----------------------------------------------------------------*/
  259.             if(brf_exception[i].brf_ex_custom_handler != NULL)
  260.             {
  261.                 handlerptr = brf_exception[i].brf_ex_custom_handler;
  262.                 (*handlerptr)(bif_entity,i);
  263.  
  264.             }
  265.             else
  266.             {
  267.             /* increment this exceptions counter */
  268.                 brf_exception[i].brf_ex_numhits += num_frames;
  269.             }    /* end if custom handler */
  270.         /*----------------------------------------------------------------*\
  271.         |       Copy tmpstring to spooler.
  272.         \*----------------------------------------------------------------*/
  273.         }     /* end if entity match */
  274.     }    /* end for all table entries */
  275.  
  276. return(TRUE);
  277.  
  278. }/* BRF_do_exceptionsearch */
  279.  
  280.  
  281.  
  282. /*--------------------------------------------------------------------*\
  283. | Procedure     :    int BRF_do_optionaltest( *BIF_All, int)
  284. |---------------------------------------------------------------------
  285. | Description   :    Test for exceptions in optional data groups
  286. |
  287. |---------------------------------------------------------------------
  288. | Revisions     :
  289. |
  290. |---------------------------------------------------------------------
  291. | Return        :    
  292. \*--------------------------------------------------------------------*/
  293. int BRF_do_optiontest(bif_entity,i)
  294. BIF_All *bif_entity;
  295. int i;
  296. {/* BRF_do_optiontest*/
  297. register int j, k;
  298. int type;
  299. BIF_Withdata3 *bif_withdata3;
  300.  
  301.         /*----------------------------------------------------------------*\
  302.         |       Any optional group flags set?
  303.         \*----------------------------------------------------------------*/
  304.  
  305.     bif_withdata3 = (BIF_Withdata3 *)bif_entity;
  306.         for(j=0;j<7;j++)        /* for all optional data groups */
  307.         {
  308.            if((bif_withdata3->with_data_flag[j] > 0 ) &&  /* if optional flag */
  309.                         brf_exception[i].brf_ex_optional[j] == TRUE)
  310.                 {
  311.         brf_exception[i].brf_ex_numhits += num_frames;
  312.             } /* end if optional flag */
  313.         } /* end for all optional data groups */
  314. return(TRUE);
  315. }/* BRF_do_optiontest*/
  316.  
  317.  
  318.  
  319. /*--------------------------------------------------------------------*\
  320. | Procedure     :    int BRF_realrange( *BIF_All, int)
  321. |---------------------------------------------------------------------
  322. | Description   :    Test if real values inside bif entity
  323. |            exceed range of values in brf_exception[i].
  324. |
  325. |---------------------------------------------------------------------
  326. | Revisions     :
  327. |
  328. |---------------------------------------------------------------------
  329. | Return        :    
  330. \*--------------------------------------------------------------------*/
  331. int BRF_realrange(bif_entity,i)
  332. BIF_All *bif_entity;
  333. int i;
  334. {/* BRF_realrange */
  335. register int j, k;
  336. int type;
  337. BIF_Size *bif_size;
  338. int logic;
  339.  
  340.         /*----------------------------------------------------------------*\
  341.         |       Is the test value in size within exception range
  342.         \*----------------------------------------------------------------*/
  343.  
  344.         bif_size = (BIF_Size*)bif_entity;
  345.     logic = brf_exception[i].brf_ex_logic;
  346.  
  347.     switch(logic)
  348.     {
  349.     case TRUE:
  350.     if(brf_exception[i].brf_ex_rrange[RANGESTART] <= bif_size->size &&
  351.        brf_exception[i].brf_ex_rrange[RANGESTOP] >= bif_size->size)
  352.     {
  353.         return(TRUE);
  354.     }
  355.     else
  356.     {
  357.         brf_exception[i].brf_ex_numhits += num_frames;
  358.         } /* end if in range */
  359.     break;
  360.         case FALSE:
  361.         if(brf_exception[i].brf_ex_rrange[RANGESTART] <= bif_size->size &&
  362.            brf_exception[i].brf_ex_rrange[RANGESTOP] >= bif_size->size)
  363.         {
  364.                 brf_exception[i].brf_ex_numhits += num_frames;
  365.         }
  366.         else
  367.         {
  368.                 return(TRUE);
  369.         } /* end if in range */
  370.         break;
  371.     } /* end switch */
  372.  
  373. return(TRUE);
  374. }/* BRF_realrange */
  375.  
  376.  
  377.  
  378.  
  379. /*--------------------------------------------------------------------*\
  380. | Procedure     :    int BRF_intrange( *BIF_All, int)
  381. |---------------------------------------------------------------------
  382. | Description   :    Test if int values inside bif entity
  383. |                       exceed range of values in brf_exception[i].
  384. |
  385. |---------------------------------------------------------------------
  386. | Revisions     :
  387. |
  388. |---------------------------------------------------------------------
  389. | Return        :    
  390. \*--------------------------------------------------------------------*/
  391. int BRF_intrange(bif_entity,i)
  392. BIF_All *bif_entity;
  393. int i;
  394. {/* BRF_intrange */
  395. register int j, k;
  396. int type;
  397. BIF_Index *bif_index;
  398. int logic;
  399.  
  400.         /*----------------------------------------------------------------*\
  401.         |       Is the test value in index within exception range
  402.         \*----------------------------------------------------------------*/
  403.  
  404.         bif_index = (BIF_Index*)bif_entity;
  405.     logic = brf_exception[i].brf_ex_logic;
  406. #ifdef EXTERNALNOTE
  407.     /* here is an example of the logic field of the brf_exception
  408.     structure in use. When set to TRUE, the range function performs
  409.     as expected, issuing an exception if the value passed in from the
  410.     bif_entity structure is outside the range brf_ex_rrange[RANGESTART] - 
  411.     brf_ex_rrange[RANGESTOP]. if logic is set FALSE, the function inverts,
  412.     issuing the exception if the testvalue lies INSIDE the range. Thus,
  413.     it can be used as an exclusion test. */
  414. #endif
  415.  
  416.         switch(logic)
  417.         {
  418.         case TRUE:
  419.  
  420.         if(brf_exception[i].brf_ex_range[RANGESTART] <= bif_index->ind &&
  421.            brf_exception[i].brf_ex_range[RANGESTOP] >= bif_index->ind)
  422.         {
  423.                 return(TRUE);
  424.         }
  425.         else
  426.         {
  427.                 brf_exception[i].brf_ex_numhits += num_frames;
  428.         } /* end if in range */
  429.     break;
  430.         case FALSE:
  431.  
  432.         if(brf_exception[i].brf_ex_range[RANGESTART] <= bif_index->ind &&
  433.            brf_exception[i].brf_ex_range[RANGESTOP] >= bif_index->ind)
  434.         {
  435.                 brf_exception[i].brf_ex_numhits += num_frames;
  436.         }
  437.         else
  438.         {
  439.                 return(TRUE);
  440.         } /* end if in range */
  441.         break;
  442.         } /* end switch */
  443.  
  444.  
  445. return(TRUE);
  446. }/* BRF_intrange */
  447.  
  448.  
  449.  
  450. /*--------------------------------------------------------------------*\
  451. | Procedure     :    int BRF_truecolor( *BIF_All, int)
  452. |---------------------------------------------------------------------
  453. | Description   :    Test if is in true color mode during true color
  454. |            calls
  455. |
  456. |---------------------------------------------------------------------
  457. | Revisions     :
  458. |
  459. |---------------------------------------------------------------------
  460. | Return        :    
  461. \*--------------------------------------------------------------------*/
  462. int BRF_truecolor(bif_entity,i)
  463. BIF_All *bif_entity;
  464. int i;
  465. {/* BRF_truecolor */
  466. register int j, k;
  467. int type;
  468. BIF_Index *bif_index;
  469. int logic;
  470.  
  471.         /*----------------------------------------------------------------*\
  472.         |       Is in true color mode during true color calls?
  473.         \*----------------------------------------------------------------*/
  474.  
  475.         bif_index = (BIF_Index*)bif_entity;
  476.         logic = brf_exception[i].brf_ex_logic;
  477.  
  478.         if(wk_info.color_mode != TRUE_COLOR)
  479.         {
  480.                 brf_exception[i].brf_ex_numhits += num_frames;
  481.         }
  482.         else
  483.         {
  484.                 return(TRUE);
  485.         } 
  486.  
  487. return(TRUE);
  488. }/* BRF_truecolor */
  489.  
  490.  
  491.  
  492. /*--------------------------------------------------------------------*\
  493. | Procedure     :    int BRF_pseudocolor( *BIF_All, int)
  494. |---------------------------------------------------------------------
  495. | Description   :    Test if is in psuedo color mode during true color
  496. |                       calls
  497. |
  498. |---------------------------------------------------------------------
  499. | Revisions     :
  500. |
  501. |---------------------------------------------------------------------
  502. | Return        :    
  503. \*--------------------------------------------------------------------*/
  504. int BRF_pseudocolor(bif_entity,i)
  505. BIF_All *bif_entity;
  506. int i;
  507. {/* BRF_pseudocolor */
  508. register int j, k;
  509. int type;
  510. BIF_Index *bif_index;
  511. int logic;
  512.  
  513.         /*----------------------------------------------------------------*\
  514.         |       Is in pseudo color mode during true color calls?
  515.         \*----------------------------------------------------------------*/
  516.  
  517.         bif_index = (BIF_Index*)bif_entity;
  518.         logic = brf_exception[i].brf_ex_logic;
  519.  
  520.         if(wk_info.color_mode == TRUE_COLOR)
  521.         {
  522.                 brf_exception[i].brf_ex_numhits += num_frames;
  523.         }
  524.         else
  525.         {
  526.                 return(TRUE);
  527.         }
  528.  
  529. return(TRUE);
  530. }/* BRF_pseudocolor */
  531.  
  532.  
  533.  
  534.  
  535.  
  536.