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

  1. /* $XConsortium: traverser.c,v 5.1 91/02/16 10:07:54 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. |
  28. |  Copyright (C) 1989,1990, 1991, National Computer Graphics Association
  29. |
  30. |  Permission is granted to any individual or institution to use, copy, or
  31. |  redistribute this software so long as it is not sold for profit, provided
  32. |  this copyright notice is retained.
  33. |
  34. |                         Developed for the
  35. |                National Computer Graphics Association
  36. |                         2722 Merrilee Drive
  37. |                         Fairfax, VA  22031
  38. |                           (703) 698-9600
  39. |
  40. |                                by
  41. |                 SimGraphics Engineering Corporation
  42. |                    1137 Huntington Drive  Unit A
  43. |                      South Pasadena, CA  91030
  44. |                           (213) 255-0900
  45. |---------------------------------------------------------------------
  46. |
  47. | Author        :    nde / SimGraphics Engineering Corportation
  48. |
  49. | File          :    traverser.c
  50. | Date          :    Fri Feb  9 10:46:55 PST 1990
  51. | Project       :    PLB
  52. |
  53. | Description    :    The traverser handling functions for build
  54. |            and execute mode.
  55. |
  56. | Status    :      Version 1.0
  57. |
  58. |            Non-bullet proof.  Executute will branch to NULL
  59. |            if given the value.  Could use this level of
  60. |            inteligence, but... the traversers are DUMB by
  61. |            design, it's up to the handling function to
  62. |            figure out what an entity dones.
  63. |
  64. \*--------------------------------------------------------------------*/
  65.  
  66. /*--------------------------------------------------------------------*\
  67. |    Table of Contents
  68. |
  69. |    void build_traverser( *BIF_Traverser_state, *BIF_All )
  70. |        :    Inserts the NULL terminated linked list of
  71. |    void execute_traverser(*BIF_Traverser_state, *BIF_All )
  72. |        :    The BIF execute traverser: FULLY DUMB.
  73. |
  74. \*--------------------------------------------------------------------*/
  75.  
  76. /*--------------------------------------------------------------------*\
  77. |    Include files
  78. \*--------------------------------------------------------------------*/
  79. #include <stdio.h>
  80. #include "bifbuild.h"
  81. #include "biftypes.h"
  82. #include "bifparse.h"
  83. #include "db_tools.h"
  84. #include "ph_map.h"
  85.  
  86. /*--------------------------------------------------------------------*\
  87. | BEGIN PROCEDURE CODE                                                
  88. \*--------------------------------------------------------------------*/
  89.  
  90. /*----------------------------------------------------------------------*\
  91. | Procedure    :    void build_traverser( *BIF_Traverser_state,
  92. |                        *BIF_All )
  93. |------------------------------------------------------------------------
  94. | Description    :    Inserts the NULL terminated linked list of
  95. |            entities into the open structure between
  96. |            insert_after and insert_after.next.  Update the
  97. |            insert after point to the end of the given list.
  98. |            Typically, lists are single entities with
  99. |            NULL nexts.
  100. |
  101. |            If the insert_after point is NULL insert at
  102. |            top_of_list.
  103. |------------------------------------------------------------------------
  104. | Return    :    
  105. \*----------------------------------------------------------------------*/
  106. build_traverser( traverser_state, bif_entity )
  107. BIF_Traverser_state *traverser_state;
  108. BIF_All *bif_entity;
  109.  
  110. {
  111.  
  112.     BIF_All *next, *end_list;
  113.     if ( traverser_state->insert_after != NULL )
  114.     {
  115.     /* Save the old next */
  116.         next = traverser_state->insert_after->any.next;
  117.  
  118.     /* Make the top of the list the next of the insert_after entity */
  119.         traverser_state->insert_after->any.next = bif_entity;
  120.     }
  121.     else
  122.     {
  123.     /* Insert at top of list*/
  124.     /* The old next in the old top_of_list ( or empty structure ) */
  125.         next = traverser_state->open_structure->top_of_list;
  126.     /* Insert the new entity */
  127.         traverser_state->open_structure->top_of_list = bif_entity;
  128.     }
  129.  
  130. /* Find the end of list */
  131.     end_list = end_of_list(bif_entity);
  132.  
  133. /* Link the end of list to the old next */
  134.     end_list->any.next = next;
  135.  
  136. /* Update the insert after point to the end of list */
  137.     traverser_state->insert_after = end_list;
  138.  
  139. }/* End BIF_build_traverser */
  140.  
  141. /*----------------------------------------------------------------------*\
  142. | Procedure    :    void execute_traverser(*BIF_Traverser_state,
  143. |                        *BIF_All )
  144. |------------------------------------------------------------------------
  145. | Description    :    The BIF execute traverser: FULLY DUMB.
  146. |            Invoke the handling function of each entity
  147. |            in the NULL terminate list.
  148. |------------------------------------------------------------------------
  149. | Return    : 
  150. \*----------------------------------------------------------------------*/
  151. execute_traverser( traverser_state, bif_entity )
  152. BIF_Traverser_state *traverser_state;
  153. BIF_All *bif_entity;
  154.  
  155. {
  156.     while ( bif_entity != NULL )
  157.     {
  158. #ifdef TEST_PRINT
  159. /* #define TRACE_TRAV */
  160. #ifdef TRACE_TRAV
  161. {
  162. char *find_keyword_token();
  163. printf("Ex:%s\n",find_keyword_token((BIF_INT)bif_entity->any.entity_type));
  164. fflush(stdout);
  165. }
  166. #endif /* TRACE_TRAV */
  167. #endif /* TEST_PRINT */
  168.         bif_entity->any.handler( traverser_state, bif_entity );
  169.         bif_entity = bif_entity->any.next;
  170.     }
  171.  
  172. } /* End BIF_execute_traverser */
  173.