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

  1. /* $XConsortium: bld_str.c,v 5.1 91/02/16 10:07:06 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        :    John M. Zulauf
  47. |
  48. | File          :    bif_str.c
  49. | Date          :    Tue Jun 20 11:10:12 PDT 1989
  50. | Project       :    PLB
  51. | Description   :    Functions that build structure entities
  52. | Status        :    Version 1.0
  53. |
  54. | Revisions     :
  55. |
  56. |       2/90            MFC Tektronix, Inc.: PEX-SI API implementation.
  57. |
  58. |       5/90            MFC Tektronix, Inc.: PEX-SI API Binding change.
  59. |
  60. |      12/90            MFC Tektronix, Inc.: PEX-SI PEX5R1 Release.
  61. |
  62. \*--------------------------------------------------------------------*/
  63.  
  64. /*--------------------------------------------------------------------*\
  65. |    Table of Contents
  66. |
  67. |    int bif_begstr(BIF_INT)
  68. |        :    Receive a BEGIN_STRUCTURE entity from the
  69. |    int bif_endstr()
  70. |        :    Receive an END_STRUCTURE entity from the parser
  71. |    int bif_label(BIF_INT)
  72. |        :    In the current release of PLB, labels are not
  73. |    int bif_execstr(BIF_INT)
  74. |        :    Receive an EXECUTE_STRUCTURE entity from the parser
  75. |    int bif_callstr(BIF_INT)
  76. |        :    Receive a CALL_STRUCTURE entity from the parser
  77. |    int bif_invokeatframe(BIF_INT, BIF_INT, BIF_INT, BIF_INT)
  78. |        :    Receive an invoke at frame entity from the 
  79. |
  80. \*--------------------------------------------------------------------*/
  81.  
  82. /*--------------------------------------------------------------------*\
  83. |    Include files 
  84. \*--------------------------------------------------------------------*/
  85. #include <stdio.h>
  86. #include "biftypes.h"
  87. #include "bifbuild.h"
  88. #include "new_ents.h"
  89. #include "bifparse.h"
  90. #include "db_tools.h"
  91. #include "doentity.h"
  92. #include "bifmacro.h"
  93. #include "globals.h"
  94. #include "ph_map.h"
  95.  
  96. /*--------------------------------------------------------------------*\
  97. |Local #define
  98. \*--------------------------------------------------------------------*/
  99.  
  100. /*--------------------------------------------------------------------*\
  101. |Local Globals
  102. \*--------------------------------------------------------------------*/
  103. BIF_All temp_ent;
  104.  
  105.  
  106. /*--------------------------------------------------------------------*\
  107. |    Structure Entities
  108. \*--------------------------------------------------------------------*/
  109.  
  110. /*--------------------------------------------------------------------*\
  111. | Procedure    :    int bif_begstr(BIF_INT)
  112. |---------------------------------------------------------------------
  113. | Description    :    Receive a BEGIN_STRUCTURE entity from the
  114. |            parser.
  115. |
  116. |            NOTE: This function is an exception in that it
  117. |            does NOT call the traverser but executes the
  118. |            action function directly.  ( Which is required
  119. |            unless you set the build-traverser to recogize
  120. |            this entity type or some other trailer )
  121. |---------------------------------------------------------------------
  122. | Return    :    Error Code (Not Implemented)
  123. \*--------------------------------------------------------------------*/
  124. int bif_begstr(structure_id)
  125. BIF_INT structure_id;
  126. {
  127.     BIF_Beginstructure *ent;
  128. #ifdef TEST_PRINT
  129.     printf("Begin structure %d\n",structure_id);
  130. #endif /* TEST_PRINT */
  131. #ifndef PRINT_ONLY
  132. /* Get the pointer to the structure ( allocated if new ) */
  133.     ent = db_get_str(structure_id);
  134.     
  135. /*  Check if we ran out of memory */
  136.     ENT_ERROR(ent);
  137.  
  138. /* Open the Structure in the BIF Database and in PHIGS */
  139.     do_beginstructure(traverser_state, ent);
  140.  
  141. #ifdef USING_PHIGS
  142. /* Close the Non-Retained Structure */
  143.     fxclns();
  144.     traverser_state->nrs_state = 0;
  145.  
  146. /* Open the PHIGS Structure to build */
  147.     popen_struct((Pint)structure_id);
  148. #endif /* USING_PHIGS */
  149. #endif /* PRINT_ONLY */
  150. } /* End procedure bif_begstr */
  151.  
  152. /*--------------------------------------------------------------------*\
  153. | Procedure    :    int bif_endstr()
  154. |---------------------------------------------------------------------
  155. | Description    :    Receive an END_STRUCTURE entity from the parser
  156. |
  157. |            NOTE: This function is an exception in that it
  158. |            does NOT call the traverser but executes the
  159. |            action function directly.  ( Which is required
  160. |            unless you set the build-traverser to recogize
  161. |            this entity type or some other trailer )
  162. |---------------------------------------------------------------------
  163. | Return    :    Error Code
  164. \*--------------------------------------------------------------------*/
  165. int bif_endstr()
  166. {
  167. #ifdef TEST_PRINT
  168.     printf("Ending current structure\n");
  169. #endif /* TEST_PRINT */
  170. #ifndef PRINT_ONLY
  171. /* Close the Structure in the BIF Database and in PHIGS */
  172.     do_endstructure(traverser_state,NULL);
  173.  
  174. #ifdef USING_PHIGS
  175. /* Close the PHIGS Retained structure */
  176.     pclose_struct();
  177.  
  178. /* Open the Non-Reatained Structure */
  179.     fxopns();
  180.     traverser_state->nrs_state = 1;
  181.  
  182. #endif /* USING_PHIGS */
  183. #endif /* PRINT_ONLY */
  184. } /* End procedure bif_endstr */
  185.  
  186. /*--------------------------------------------------------------------*\
  187. | Procedure     :    int bif_label(BIF_INT)
  188. |---------------------------------------------------------------------
  189. | Description   :    In the current release of PLB, labels are not
  190. |            used.  This is a dummy routine to catch the 
  191. |            parser call.
  192. |---------------------------------------------------------------------
  193. | Return        :    Error Code. (Not Implemented)
  194. \*--------------------------------------------------------------------*/
  195. int bif_label(label_id)
  196. BIF_INT label_id;
  197.  
  198. {
  199.  
  200. } /* End bif_label */
  201.  
  202.  
  203. /*--------------------------------------------------------------------*\
  204. |    * ************************************** *
  205. |        Structure Hierarchy
  206. |    * ************************************** *
  207. \*--------------------------------------------------------------------*/
  208.  
  209. /*--------------------------------------------------------------------*\
  210. |    * ************************************** *
  211. |        Invoking other structures
  212. |    * ************************************** *
  213. \*--------------------------------------------------------------------*/
  214.  
  215. /*----------------------------------------------------------------------*\
  216. | Procedure    :    int bif_execstr(BIF_INT)
  217. |------------------------------------------------------------------------|
  218. | Description    :    Receive an EXECUTE_STRUCTURE entity from the parser
  219. |
  220. |    structure_id    ID of structure to execute
  221. |------------------------------------------------------------------------|
  222. | Return    :    Error Code
  223. \*----------------------------------------------------------------------*/
  224. int bif_execstr(structure_id)
  225. BIF_INT structure_id;
  226.  
  227. {
  228.     static int ent_size = sizeof(BIF_Executestructure);
  229.     BIF_Beginstructure *str;
  230.     BIF_All *ent;
  231.  
  232. #ifdef TEST_PRINT
  233.     printf("EXECUTE_STRUCTURE : execute structure %d \n",structure_id);
  234.     fflush(stdout);
  235. #endif /* TEST_PRINT */
  236. #ifndef PRINT_ONLY
  237. /* Allocate the entity */
  238. /* Get the address of the specified structure */
  239.     str = db_get_str(structure_id);
  240. /*  Check if we ran out of memory */
  241.     ENT_ERROR(str);
  242.  
  243.  
  244. /* Allocate the entity */
  245.     temp_ent.executestructure.structure_id  = structure_id;
  246.     temp_ent.executestructure.structure_ptr = str;
  247.  
  248.     ent = new_generic(&temp_ent, ent_size, 
  249.             EXECUTE_STRUCTURE, do_executestructure);
  250.  
  251. /* Error check for ent == NULL ( FATAL ) */
  252.     ENT_ERROR(ent);
  253.  
  254. /* Build or Execute */
  255.     Traverse(traverser_state, ent);
  256.  
  257. #ifdef USING_PHIGS
  258. /* Call the entity in PHIGS */
  259.     pexec_struct((Pint)temp_ent.executestructure.structure_id);
  260. #endif /* USING_PHIGS */
  261.  
  262. /* Release Non-Retained Entities */
  263.     Free_NRE(traverser_state, ent);
  264.  
  265. #endif /* PRINT_ONLY */
  266. } /* End procedure bif_execstr */
  267.  
  268. /*----------------------------------------------------------------------*\
  269. | Procedure    :    int bif_callstr(BIF_INT)
  270. |------------------------------------------------------------------------|
  271. | Description    :    Receive a CALL_STRUCTURE entity from the parser
  272. |
  273. |    structure_id    ID of structure to call
  274. |------------------------------------------------------------------------|
  275. | Return    :    Error Code
  276. \*----------------------------------------------------------------------*/
  277. int bif_callstr(structure_id)
  278. BIF_INT structure_id;
  279. {
  280.     static int ent_size = sizeof(BIF_Callstructure);
  281.     BIF_All *ent;
  282.     BIF_Beginstructure *str;
  283.     
  284. #ifdef TEST_PRINT
  285.     printf("CALL_STRUCTURE : call structure %d \n",structure_id);
  286. #endif /* TEST_PRINT */
  287.  
  288. #ifndef PRINT_ONLY
  289. /* Allocate the entity */
  290. /* Get the address of the specified structure */
  291.     str = db_get_str(structure_id);
  292. /*  Check if we ran out of memory */
  293.     ENT_ERROR(str);
  294.  
  295.  
  296. /* Allocate the entity */
  297.     temp_ent.callstructure.structure_id  = structure_id;
  298.     temp_ent.callstructure.structure_ptr = str;
  299.     temp_ent.callstructure.startLabel  = getNextLabel();
  300.     temp_ent.callstructure.endLabel    = getNextLabel();
  301.  
  302.     ent = new_generic(&temp_ent, ent_size, 
  303.             CALL_STRUCTURE, do_callstructure);
  304.  
  305. /* Error check for ent == NULL ( FATAL ) */
  306.     ENT_ERROR(ent);
  307.  
  308. /* Build or Execute */
  309.     Traverse(traverser_state, ent);
  310.  
  311. #ifdef USING_PHIGS
  312. /* Call the entity in PHIGS */
  313. #ifdef REFER_STRUCTURE_EXISTS
  314.     fxrfst(temp_ent.callstructure.structure_id);
  315. #else /* REFER_STRUCTURE_IS_EXISTS */
  316.     if (traverser_state->nrs_state == 0)
  317.     {
  318.         /*----------------------------------------------------*\
  319.         |    Insert two reference labels for later expansion
  320.         |    and editing.
  321.         \*----------------------------------------------------*/
  322. #ifdef TEST_PRINT
  323. printf("startLabel %d\n", ent->callstructure.startLabel);
  324. printf("endLabel %d\n", ent->callstructure.endLabel);
  325. #endif /* TEST_PRINT */
  326.         plabel((Pint)ent->callstructure.startLabel);
  327.         plabel((Pint)ent->callstructure.endLabel);
  328.     }
  329.     else
  330.         /* Instant expansion into the NRS */
  331.         pcopy_all_elems_struct((Pint)ent->callstructure.structure_id);
  332. #endif /* REFER_STRUCTURE_EXISTS */
  333. #endif /* USING_PHIGS */
  334.  
  335. /* Release Non-Retained Entities */
  336.     Free_NRE(traverser_state, ent);
  337.  
  338. #endif /* PRINT_ONLY */
  339. } /* End procedure bif_callstr */
  340.  
  341.  
  342. /* Verb File */
  343.  
  344. /*--------------------------------------------------------------------*\
  345. | Procedure     :    int bif_invokeatframe(BIF_INT, BIF_INT,
  346. |                BIF_INT, BIF_INT)
  347. |---------------------------------------------------------------------
  348. | Description   :    Receive an invoke at frame entity from the 
  349. |            parser, build and store it in the test-loop
  350. |            structure.
  351. |---------------------------------------------------------------------
  352. | Return        :    Error Code (Not Implemented)
  353. \*--------------------------------------------------------------------*/
  354. int bif_invokeatframe(str_id, invoke_style, start_frame, end_frame)
  355. BIF_INT str_id;
  356. BIF_INT invoke_style;
  357. BIF_INT start_frame;
  358. BIF_INT end_frame;
  359.  
  360. {
  361.     static int ent_size = sizeof(BIF_InvokeAtFrame);
  362.     BIF_All *ent;
  363.     BIF_InvokeAtFrame *atFrame;
  364.     BIF_Executestructure *invoke_me;
  365.     char *find_keyword_token();
  366.  
  367. #ifdef TEST_PRINT
  368.     printf("INVOKE_AT_FRAME : %s Structure %d from frame %d to %d\n",
  369.         find_keyword_token(invoke_style),str_id,
  370.         start_frame,end_frame);
  371. #endif /* TEST_PRINT */
  372. #ifndef PRINT_ONLY
  373.     /*------------------------------------------------------------*\
  374.     |    This entity must be encountered while in Build mode.
  375.     |    Specifically the parser ONLY allow this entity while
  376.     |    the test-loop structure is being built
  377.     |
  378.     |    NOTE: With little additional effort/logic the invoke at
  379.     |    frame entity could be allowed to be store within
  380.     |    structures.( But the BIF spec currently does not
  381.     |    require/support/allow this.
  382.     \*------------------------------------------------------------*/
  383.     if ( traverser_state->open_structure != NULL )
  384.     {
  385.         /*----------------------------------------------------*\
  386.         |    Fill the temp_ent then allocate the entity
  387.         \*----------------------------------------------------*/
  388.         atFrame = &temp_ent.invokeatframe;
  389.  
  390.         /* The basic facts about the invocation */
  391.         atFrame->structureID = (int)str_id;
  392.         atFrame->invokeStyle = REMAP_INVOKE(invoke_style);
  393.         atFrame->startFrame  = (int)start_frame;
  394.         atFrame->endFrame    = (int)end_frame;
  395.  
  396.         /* Using these labels for editing control */
  397.         atFrame->startLabel  = getNextLabel();
  398.         atFrame->endLabel    = getNextLabel();
  399.  
  400.         /*----------------------------------------------------*\
  401.         |    Set up the Invocation Sub-entity
  402.         |
  403.         |    Get the address of the referenced structure
  404.         |    Check if we ran out of memory.
  405.         \*----------------------------------------------------*/
  406.         invoke_me               = &atFrame->invoke;
  407.         if ( invoke_style == CALL )
  408.         {
  409.             HEADER(invoke_me, CALL_STRUCTURE,
  410.                 do_callstructure, NULL);
  411.             invoke_me->startLabel = atFrame->startLabel;
  412.             invoke_me->endLabel   = atFrame->endLabel;
  413.         }
  414.         else
  415.         {
  416.             HEADER(invoke_me, EXECUTE_STRUCTURE,
  417.                 do_executestructure, NULL);
  418.         }
  419.         
  420.         invoke_me->structure_id = (int)str_id;
  421.         invoke_me->structure_ptr =
  422.             db_get_str((BIF_INT)invoke_me->structure_id);
  423.         ENT_ERROR(invoke_me->structure_ptr );
  424.  
  425.         /* Alloc and copy to a stored entity */
  426.         ent = new_generic(&temp_ent,ent_size,INVOKE_AT_FRAME,
  427.                     do_invokeatframe);
  428.  
  429.         /* Error check for ent == NULL ( FATAL ) */
  430.         ENT_ERROR(ent);
  431.  
  432.         /* Add to the open structure */
  433.         Traverse(traverser_state, ent);
  434.  
  435. #ifdef USING_PHIGS
  436.         /* Call the entity in PHIGS */
  437.         /* Insert the Edit Labels here  */
  438.         plabel((Pint)temp_ent.invokeatframe.startLabel);
  439.         plabel((Pint)temp_ent.invokeatframe.endLabel);
  440. #endif /* USING_PHIGS */
  441.     }
  442.     else
  443.     {
  444.         /* There is no immediate mode meaning to the invoke
  445.             at frame */
  446.     }
  447.  
  448.  
  449. #endif /* PRINT_ONLY */
  450. } /* End bif_invokeatframe() */
  451.  
  452.