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

  1. /* $XConsortium: db_tools.c,v 5.2 91/04/03 09:40:13 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        :    jmz / SimGraphics Engineering Corportation
  48. |
  49. | File          :    db_tools.c
  50. | Date          :    3/18/89
  51. | Project       :    PLB
  52. |
  53. | Description   :    Routines that maintain the BIF strutures list,
  54. |            find the end of lists, free data (wholesale),
  55. |            and match str_id's with the pointers.
  56. |
  57. | Status    :    Version 1.0
  58. |
  59. | Revisions    :
  60. |
  61. |    11/22/89    Paul Chek DEC:
  62. |            in expand and collapse structure, before doing
  63. |            the actual collapse or expand, close and save the
  64. |            current open structure if any.  After the collapse
  65. |            or expand reopen the structure.
  66. |
  67. |       2/90            MFC Tektronix, Inc.: PEX-SI API implementation.
  68. |
  69. |       5/90            MFC Tektronix, Inc.: PEX-SI API Binding change.
  70. |
  71. |      12/90            MFC Tektronix, Inc.: PEX-SI PEX5R1 Release.
  72. |
  73. \*--------------------------------------------------------------------*/
  74.  
  75. /*--------------------------------------------------------------------*\
  76. |    Table of Contents
  77. |
  78. |    contour_counter(int, *Real_int_union, int)
  79. |        :    Count the Contents of the Current Contour Clearly, 
  80. |    contour_sizes(int, int, *Real_int_union, *int, int)
  81. |        :    Find the size of each countour of list provided.
  82. |    BIF_All *end_of_list(*BIF_All)
  83. |        :    Find the end of the NULL terminated linked list
  84. |    void free_all_list(*BIF_All)
  85. |        :    Delete the NULL terminated linked list of entities
  86. |    BIF_Beginstructure *db_inq_str(int)
  87. |        :    Check for the existance of a given structure
  88. |    void db_add_str(*BIF_Beginstructure)
  89. |        :    Add the given structure to the data base
  90. |    BIF_Beginstructure *db_get_str(int)
  91. |        :    Get the pointer to a given structure. If the
  92. |    void db_empty_str(int)
  93. |        :    Empty the given structure (if it exsists).
  94. |    void db_clear_all()
  95. |        :    Clear all structures from memory.
  96. |    int setNextLabel(int)
  97. |        :    Set the base of the unique label range.
  98. |    int getNextLabel()
  99. |        :    Get the next unique label value.
  100. |    int addToList(int, *int, *int, int)
  101. |        :    Add the value "new" at the end of the array
  102. |    int delFromList(int, *int, *int, int)
  103. |        :    Delete the value "old" from the array
  104. |    int expandAllStructures();
  105. |        :    Expand all structures to include the "called"
  106. |    expandStructure(* BIF_Beginstructure)
  107. |        :    Expand the given structure and any descendants
  108. |    int collapseAllStructures();
  109. |        :    Collapse all structures that include the
  110. |    int collapseStructure(*BIF_Beginstructure)
  111. |        :    Collapse out the copied "called" elements from
  112. |    int openUsingLinkList(* slList);
  113. |        :    For PHIGS systems that do not support the 
  114. |
  115. \*--------------------------------------------------------------------*/
  116.  
  117. /*--------------------------------------------------------------------*\
  118. |    Include files
  119. \*--------------------------------------------------------------------*/
  120. #include <stdio.h>
  121. #include <X11/Xosdefs.h>
  122. #ifndef X_NOT_STDC_ENV
  123. #include <stdlib.h>
  124. #else
  125. char *malloc();
  126. #endif
  127. #if defined(macII) && !defined(__STDC__)  /* stdlib.h fails to define these */
  128. char *malloc();
  129. #endif /* macII */
  130. #include "biftypes.h"
  131. #include "bifparse.h"
  132. #include "new_ents.h"
  133. #include "ph_map.h"
  134.  
  135.  
  136. /*--------------------------------------------------------------------*\
  137. | Local global variables
  138. \*--------------------------------------------------------------------*/
  139. /* The root of the structures database */
  140. static BIF_Beginstructure *root_of_str_list = NULL;
  141. static int nextLabel = 1;
  142.  
  143. /*--------------------------------------------------------------------*\
  144. | BEGIN PROCEDURE CODE 
  145. \*--------------------------------------------------------------------*/
  146.  
  147. /*--------------------------------------------------------------------*\
  148. | Procedure     :    contour_counter(int, *Real_int_union, int)
  149. |-----------------------------------------------------------------------
  150. | Description   :    Count the Contents of the Current Contour Clearly, 
  151. |            Concisely, Clerically, Cleanly, Cleverly, and
  152. |            Carefully.
  153. |-----------------------------------------------------------------------
  154. | Return        :    The total number of records in the contour list
  155. \*--------------------------------------------------------------------*/
  156. contour_counter(number,list,record_size)
  157. int number, record_size;
  158. Real_int_union *list;
  159. {
  160.     int i, cont_size, total;
  161.     total = 0;
  162.     for ( i = 0; i < number; i++ )
  163.     {
  164.         cont_size = list->Int;
  165.         total += cont_size;
  166.         list += record_size * cont_size + 1;
  167. #ifdef TEST_PRINT
  168.         fprintf(stderr,"contour_counter list->Int = %d\n",list->Int);
  169.         fflush(stderr);
  170. #endif
  171.     }
  172.     return(total);
  173. } /* End procedure contour_counter */
  174.  
  175. /*--------------------------------------------------------------------*\
  176. | Procedure     :    contour_sizes(int, int, *Real_int_union,
  177. |                    *int, int)
  178. |-----------------------------------------------------------------------
  179. | Description   :    Find the size of each countour of list provided.
  180. |
  181. |    if opFlag = 0 --> fill in the sizeList 
  182. |    else test against the  sizeList.
  183. |-----------------------------------------------------------------------
  184. | Return        :    Completion status
  185. |
  186. |    if return > 0 Number of records in the contour list
  187. |    if return < 0 Number (1 base) of contour on which their
  188. |             is a size mismatch (opFlag != 0 only)
  189. \*--------------------------------------------------------------------*/
  190. contour_sizes(number,list,record_size,sizeList,opFlag)
  191. int number, record_size;
  192. Real_int_union *list;
  193. int        *sizeList;
  194. int        opFlag;
  195.  
  196. {
  197.     int i, cont_size, total;
  198.     /*------------------------------------------------------------*\
  199.     |    Find/Check/Save the sizes of each of the contours.
  200.     \*------------------------------------------------------------*/
  201.     total = 0;
  202.     for ( i = 0; (i < number) && (total > -1 ); i++ )
  203.     {
  204.         /*----------------------------------------------------*\
  205.         |    Find the size of the contour
  206.         \*----------------------------------------------------*/
  207.         cont_size = list->Int;
  208.         total += cont_size;
  209.         list += record_size * cont_size + 1;
  210.         /*----------------------------------------------------*\
  211.         |    Test or save the sizeList information
  212.         \*----------------------------------------------------*/
  213.         if ( opFlag == 0 )
  214.         {
  215.             sizeList[i] = cont_size;
  216.         }
  217.         else
  218.         {
  219.             if (cont_size != sizeList[i])
  220.                 total = -(i + 1);
  221.         }
  222.     }
  223.     return(total);
  224. } /* End procedure contour_sizes */
  225.  
  226. /*----------------------------------------------------------------------*\
  227. | Procedure     :    BIF_All *end_of_list(*BIF_All)
  228. |------------------------------------------------------------------------|
  229. | Description   :    Find the end of the NULL terminated linked list
  230. |            of entities
  231. |------------------------------------------------------------------------|
  232. | Return        :    The pointer to the last entity in the list -or-
  233. |            NULL if ent is NULL.
  234. \*----------------------------------------------------------------------*/
  235. BIF_All *end_of_list(ent)
  236. BIF_All *ent;
  237. {
  238.     BIF_All *previous;
  239. /* Walk all entities to the end of the list */
  240.     previous = ent;
  241.     while ( ent != NULL )
  242.     {
  243.         previous = ent;
  244.         ent = (ent->any).next;
  245.     }
  246.  
  247.  
  248. /* The end of the list, which is the entity "previous" to NULL */
  249.     return(previous);
  250. } /* End procedure free_all_list */ 
  251.  
  252. /*----------------------------------------------------------------------*\
  253. | Procedure     :    void free_all_list(*BIF_All)
  254. |------------------------------------------------------------------------|
  255. | Description   :    Delete the NULL terminated linked list of entities
  256. |            Assumes all entities are singly malloc'd 
  257. |------------------------------------------------------------------------|
  258. | Return        :    None
  259. \*----------------------------------------------------------------------*/
  260. void free_all_list(ent)
  261. BIF_All *ent;
  262. {
  263.     BIF_All *e_next;
  264. /* Free all entities to the end of the list */
  265.     while ( ent != NULL )
  266.     {
  267.         e_next = (ent->any).next;
  268.         free((char *)ent);
  269.         ent = e_next;
  270.     }
  271. } /* End procedure free_all_list */ 
  272.  
  273. /*----------------------------------------------------------------------*\
  274. | Procedure     :    BIF_Beginstructure *db_inq_str(int)
  275. |------------------------------------------------------------------------|
  276. | Description   :    Check for the existance of a given structure
  277. |------------------------------------------------------------------------|
  278. | Return        :    The address of the requested structure or NULL
  279. \*----------------------------------------------------------------------*/
  280. BIF_Beginstructure *db_inq_str(target_id)
  281. BIF_INT target_id;
  282. {
  283.     BIF_Beginstructure *str, *found;
  284.     found = NULL;
  285.     str = root_of_str_list;
  286.     
  287. /* Simple linear search */
  288.     found = NULL;
  289.     while( str != NULL && found == NULL )
  290.     {
  291.         if ( str->structure_id == target_id )
  292.             found = str;
  293.         else
  294.             str = &str->next->beginstructure;
  295.     }
  296. /* Tell the Calling routine what we found */
  297.     return(found);
  298. } /* End procedure db_inq_str */
  299.  
  300. /*----------------------------------------------------------------------*\
  301. | Procedure     :    void db_add_str(*BIF_Beginstructure)
  302. |------------------------------------------------------------------------|
  303. | Description   :    Add the given structure to the data base
  304. |------------------------------------------------------------------------|
  305. | Return        :    None
  306. \*----------------------------------------------------------------------*/
  307. void db_add_str(structure)
  308. BIF_Beginstructure *structure;
  309.  
  310. {
  311. /* Check for valid data */
  312.     if ( structure != NULL )
  313.     {
  314.     /* Insert at the top (order is not important */
  315.         structure->next = (BIF_All *)root_of_str_list;
  316.         root_of_str_list   = structure;
  317.     }
  318.     
  319. } /* End procedure db_add_str */
  320.  
  321. /*----------------------------------------------------------------------*\
  322. | Procedure     :    BIF_Beginstructure *db_get_str(int)
  323. |------------------------------------------------------------------------|
  324. | Description   :    Get the pointer to a given structure. If the
  325. |            structure does not exist, it is created and add
  326. |            to the structure list.
  327. |------------------------------------------------------------------------|
  328. | Return        :    The address of the requested structure
  329. \*----------------------------------------------------------------------*/
  330. BIF_Beginstructure *db_get_str(structure_id)
  331. BIF_INT structure_id;
  332. {
  333.     BIF_Beginstructure *str;
  334. /* Find out in the structure exists in the database */    
  335.     if ( ( str = db_inq_str(structure_id) ) == NULL )
  336.     {
  337.     /* It doesn't. Allocate a new BEGIN_STRUCTURE entity */
  338.         str = new_beginstructure((int)structure_id);
  339.     /* Add it to the data base */
  340.         db_add_str(str);
  341.     }
  342. /* Return the address of the structure */
  343.     return(str);
  344. } /* End procedure db_get_str */
  345.  
  346. /*----------------------------------------------------------------------*\
  347. | Procedure     :    void db_empty_str(int)
  348. |------------------------------------------------------------------------|
  349. | Description   :    Empty the given structure (if it exsists).
  350. |------------------------------------------------------------------------|
  351. | Return        :    None
  352. \*----------------------------------------------------------------------*/
  353. void db_empty_str(structure_id)
  354. int structure_id;
  355.  
  356. {
  357.     BIF_Beginstructure *str;
  358.  
  359. /* Find the structure */
  360.     if ( ( str = db_inq_str((BIF_INT)structure_id) ) != NULL )
  361.     {
  362.     /* Delete the contents */
  363.         free_all_list(str->top_of_list);
  364.         str->top_of_list = NULL;
  365.     }
  366.         
  367. } /* End procedure db_empty_str */
  368.  
  369. /*----------------------------------------------------------------------*\
  370. | Procedure     :    void db_clear_all()
  371. |------------------------------------------------------------------------|
  372. | Description   :    Clear all structures from memory.
  373. |------------------------------------------------------------------------|
  374. | Return        :    None
  375. \*----------------------------------------------------------------------*/
  376. void db_clear_all()
  377. {
  378.     BIF_Beginstructure *str;
  379.     str = root_of_str_list;
  380.     
  381. /* Clear each of the structures contents */
  382.     while( str != NULL  )
  383.     {
  384.     /* Free the contents of the BIF Structure */
  385.         free_all_list(str->top_of_list);
  386. #ifdef USING_PHIGS
  387.     /* Free the contents of the PHIGS Structure */
  388.         pempty_struct((Pint)str->structure_id);
  389. #endif /* USING_PHIGS */
  390.         str = &str->next->beginstructure;
  391.     }
  392.         
  393. /* Clear Structure Headers */
  394.     free_all_list((BIF_All *)root_of_str_list);
  395.     root_of_str_list = NULL;
  396.         
  397. } /* End procedure db_clear_all */
  398.  
  399. /*--------------------------------------------------------------------*\
  400. | Procedure     :    int setNextLabel(int)
  401. |---------------------------------------------------------------------
  402. | Description   :    Set the base of the unique label range.
  403. |            They are kept unique by allocating them sequentially
  404. |            using the getNextLabel() call. This function allows
  405. |            the base of the label range to be set.
  406. |
  407. |            CALL_STRUCTURE in PHIGs requires unique labels. 
  408. |---------------------------------------------------------------------
  409. | Return        :    Error Code ( N I )
  410. \*--------------------------------------------------------------------*/
  411. int setNextLabel(labelBase)
  412. int labelBase;
  413.  
  414. {
  415.     nextLabel = labelBase;
  416. } /* setNextLabel() */
  417.  
  418. /*--------------------------------------------------------------------*\
  419. | Procedure     :    int getNextLabel()
  420. |---------------------------------------------------------------------
  421. | Description   :    Get the next unique label value.
  422. |            They are kept unique by allocating them sequentially
  423. |            using the getNextLabel() call. This function returns
  424. |            the next label of range.
  425. |
  426. |            CALL_STRUCTURE in PHIGs requires unique labels. 
  427. |---------------------------------------------------------------------
  428. | Return        :    The next unique label
  429. \*--------------------------------------------------------------------*/
  430. int getNextLabel()
  431.  
  432. {
  433.     return( nextLabel++ );
  434. } /* getNextLabel() */
  435.  
  436.  
  437. /*--------------------------------------------------------------------*\
  438. | Procedure     :    int addToList(int, *int, *int, int)
  439. |---------------------------------------------------------------------
  440. | Description   :    Add the value "new" at the end of the array
  441. |            if it is not already there.
  442. |---------------------------------------------------------------------
  443. | Return        :    The new length of the list
  444. \*--------------------------------------------------------------------*/
  445. int addToList(new,listSize,list,listMax)
  446. int new, *listSize, *list, listMax;
  447.  
  448. {
  449.     int i, found;
  450.     /*------------------------------------------------------------*\
  451.     |    Check to see if the list is full 
  452.     \*------------------------------------------------------------*/
  453.     if ( *listSize < listMax )
  454.     {
  455.         /*----------------------------------------------------*\
  456.         |    Check if "new" already exists
  457.         \*----------------------------------------------------*/
  458.         found = 0;
  459.         for  ( i = 0 ; i < *listSize && !found ; i++ )
  460.             found = (new == list[i]);
  461.         
  462.         if ( !found )
  463.         {
  464.             /*--------------------------------------------*\
  465.             |    Add "new" to the list
  466.             \*--------------------------------------------*/
  467.             list[*listSize] = new;
  468.             *listSize += 1;
  469.         }
  470.     }
  471.     return(*listSize);
  472. } /* End addToList */
  473.  
  474. /*--------------------------------------------------------------------*\
  475. | Procedure     :    int delFromList(int, *int, *int, int)
  476. |---------------------------------------------------------------------
  477. | Description   :    Delete the value "old" from the array
  478. |            if it is there.
  479. |---------------------------------------------------------------------
  480. | Return        :    The new length of the list
  481. \*--------------------------------------------------------------------*/
  482. int delFromList(old,listSize,list)
  483. int old, *listSize, *list;
  484.  
  485. {
  486.     int i, shift;
  487.     /*----------------------------------------------------*\
  488.     |    Check if "old" exists
  489.     \*----------------------------------------------------*/
  490.     shift = 0;
  491.     for  ( i = 0 ; i < *listSize ; i++ )
  492.     {
  493.         if ( list[i] != old )
  494.         {
  495.             /* copy */
  496.             list[i-shift] = list[i];
  497.         }
  498.         else
  499.         {
  500.             /* Skip */
  501.             shift++;
  502.             *listSize -= 1;
  503.         }
  504.     }
  505.  
  506.     return(*listSize);
  507. } /* End delFromList */
  508.  
  509.  
  510. /*--------------------------------------------------------------------*\
  511. | Procedure     :    int expandAllStructures();
  512. |---------------------------------------------------------------------
  513. | Description   :    Expand all structures to include the "called"
  514. |            structure data.
  515. |---------------------------------------------------------------------
  516. | Return        :    Error Code (Not Implemented)
  517. \*--------------------------------------------------------------------*/
  518. int expandAllStructures()
  519.  
  520. {
  521.     BIF_Beginstructure *str;
  522.  
  523. #ifndef REFER_STRUCTURE_EXISTS
  524.     /*------------------------------------------------------------*\
  525.     |    For all structures...
  526.     |    expandStructure insures that children are ALWAYS 
  527.     |    exapanded before their parents.
  528.     \*------------------------------------------------------------*/
  529.     str = root_of_str_list;
  530.     while (str != NULL )
  531.     {
  532.         expandStructure(str);
  533.         str = &str->next->beginstructure;
  534.     }
  535. #endif /* REFER_STRUCTURE_EXISTS */
  536. }
  537.  
  538. /*--------------------------------------------------------------------*\
  539. | Procedure     :    expandStructure(* BIF_Beginstructure)
  540. |---------------------------------------------------------------------
  541. | Description   :    Expand the given structure and any descendants
  542. |            it may have.
  543. |---------------------------------------------------------------------
  544. | Return        :    Error Code (Not Implemented)
  545. \*--------------------------------------------------------------------*/
  546. expandStructure(str)
  547. BIF_Beginstructure *str;
  548.  
  549. {
  550.     BIF_All *ent;
  551.     BIF_Callstructure *cent;
  552.     int found, top;
  553.  
  554. #ifdef TEST_PRINT
  555. printf("expand str 0x%x \n", str);
  556. #endif /* TEST_PRINT */
  557. #ifndef REFER_STRUCTURE_EXISTS
  558.     /*------------------------------------------------------------*\
  559.     |    Initialize the list checking and see if we have been
  560.     |    here as well.
  561.     \*------------------------------------------------------------*/
  562.     if ( str == NULL )
  563.         ent = NULL;
  564.     else if ( !str->expanded )
  565.         ent = str->top_of_list;
  566.     else
  567.         ent = NULL;
  568.  
  569.     /*------------------------------------------------------------*\
  570.     |    Look for CALL_STRUCTURE entities
  571.     \*------------------------------------------------------------*/
  572.     while ( ent != NULL )
  573.     {
  574.         /* Scan the entities in the structure */
  575.         found = 0;
  576.         while ( ent != NULL && !found )
  577.         {
  578. #ifdef TEST_PRINT2
  579. printf("entity_type %d \n", ent->any.entity_type);
  580. fflush(stdout);
  581. #endif /* TEST_PRINT2 */
  582.             if ( ent->any.entity_type == CALL_STRUCTURE )
  583.                 found = 1;
  584.             else
  585.                 ent = ent->any.next;
  586.         }
  587.         
  588.         if ( ent != NULL )
  589.         {
  590.             /* We found a callstructure entity */
  591.             cent = &ent->callstructure;
  592.  
  593.             /* Expand the child (and descendants) */
  594. #ifdef TEST_PRINT
  595. printf("expanding child \n");
  596. #endif /* TEST_PRINT */
  597.             expandStructure(cent->structure_ptr);
  598. #ifdef TEST_PRINT
  599. printf("done expanding child \n");
  600. #endif /* TEST_PRINT */
  601.  
  602. #ifdef USING_PHIGS
  603.  
  604.             top = 0;
  605. #ifdef TEST_PRINT
  606. printf("popst (%d)\n",str->structure_id);
  607. fflush(stdout);
  608. #endif /* TEST_PRINT */
  609.  
  610.             {
  611.                 /* But FIRST, close and save the ID of any
  612.                    open structures */
  613.                 Pint errind, stid, ep;
  614.                 Popen_struct_status stype;
  615.                 
  616.                 pinq_open_struct(&errind, &stype, &stid);
  617.                 if (stype == PSTRUCT_OPEN) {
  618.                 pinq_elem_ptr(&errind, &ep);
  619.                 pclose_struct();
  620.                 }
  621.  
  622.                 popen_struct((Pint)str->structure_id);
  623. #ifdef TEST_PRINT
  624. printf("psep(%d)\n",top);
  625. fflush(stdout);
  626. #endif /* TEST_PRINT */
  627.                 pset_elem_ptr((Pint)top);
  628. #ifdef TEST_PRINT
  629. printf("pseplb(%d)\n",cent->startLabel);
  630. fflush(stdout);
  631. #endif /* TEST_PRINT */
  632.                 pset_elem_ptr_label((Pint)cent->startLabel);
  633. #ifdef TEST_PRINT
  634. printf("pcelst(%d)\n",cent->structure_id);
  635. fflush(stdout);
  636. #endif /* TEST_PRINT */
  637.                 pcopy_all_elems_struct((Pint)cent->structure_id);
  638. #ifdef TEST_PRINT
  639. printf("pclst()\n");
  640. fflush(stdout);
  641. #endif /* TEST_PRINT */
  642.                 pclose_struct();
  643. #ifdef TEST_PRINT
  644. printf("done.\n");
  645. fflush(stdout);
  646. #endif /* TEST_PRINT */
  647.  
  648.  
  649.                 /* If a structure was open the reopen it and
  650.                    set the element pointer */
  651.                 if (stype == PSTRUCT_OPEN) {
  652.                 popen_struct(stid);
  653.                 pset_elem_ptr(ep);
  654.                 }
  655.             }
  656. #endif /* USING_PHIGS */
  657.             ent = ent->any.next;
  658.             }
  659.         }
  660. #endif /* REFER_STRUCTURE_EXISTS */
  661.  
  662.     /* Mark the Structure as E X P A N D E D */
  663.     if ( str != NULL )
  664.         str->expanded = TRUE;
  665.  
  666. } /* End expandStructure */
  667.  
  668.  
  669. /*--------------------------------------------------------------------*\
  670. | Procedure     :    int collapseAllStructures();
  671. |---------------------------------------------------------------------
  672. | Description   :    Collapse all structures that include the
  673. |            copied "called" structure data.
  674. |---------------------------------------------------------------------
  675. | Return        :    Error Code (Not Implemented)
  676. \*--------------------------------------------------------------------*/
  677. int collapseAllStructures()
  678.  
  679. {
  680.     BIF_Beginstructure *str;
  681. #ifndef REFER_STRUCTURE_EXISTS
  682.  
  683.     /*------------------------------------------------------------*\
  684.     |    For all structures...
  685.     |    collapse them.
  686.     |    exapaneded before their parents.
  687.     \*------------------------------------------------------------*/
  688.     str = root_of_str_list;
  689.     while (str != NULL )
  690.     {
  691.         collapseStructure(str);
  692.         str = &str->next->beginstructure;
  693.     }
  694. #endif /* REFER_STRUCTURE_EXISTS */
  695. }
  696.  
  697. /*--------------------------------------------------------------------*\
  698. | Procedure     :    int collapseStructure(*BIF_Beginstructure)
  699. |---------------------------------------------------------------------
  700. | Description   :    Collapse out the copied "called" elements from
  701. |            the PHIGS structure.
  702. |---------------------------------------------------------------------
  703. | Return        :    Error Code (Not Implemented)
  704. \*--------------------------------------------------------------------*/
  705. collapseStructure(str)
  706. BIF_Beginstructure *str;
  707.  
  708. {
  709.     BIF_All *ent;
  710.     BIF_Callstructure *cent;
  711.     int found, top;
  712.  
  713.  
  714. #ifndef REFER_STRUCTURE_EXISTS
  715.     /*------------------------------------------------------------*\
  716.     |    Look for CALL_STRUCTURE entities
  717.     \*------------------------------------------------------------*/
  718.     if ( str != NULL )
  719.         ent = str->top_of_list;
  720.     else
  721.         ent = NULL;
  722.  
  723.     while ( ent != NULL )
  724.     {
  725.         /* Scan the entities in the structure */
  726.         found = 0;
  727.         while ( ent != NULL && !found )
  728.         {
  729. #ifdef TEST_PRINT
  730.         printf("entity_type %d \n", ent->any.entity_type);
  731. #endif /* TEST_PRINT */
  732.         if ( ent->any.entity_type == CALL_STRUCTURE )
  733.             found = 1;
  734.         else
  735.             ent = ent->any.next;
  736.         }
  737.         
  738.         if ( ent != NULL )
  739.         {
  740.         /* We found a callstructure entity */
  741.         cent = &ent->callstructure;
  742. #ifdef USING_PHIGS
  743.  
  744.  
  745.         {
  746.             /* But FIRST, close and save the ID of any open
  747.                structures */
  748.             Pint errind, stid, ep;
  749.             Popen_struct_status stype;
  750.                 
  751.             pinq_open_struct(&errind, &stype, &stid);
  752.             if (stype == PSTRUCT_OPEN) {
  753.             pinq_elem_ptr(&errind, &ep);
  754.             pclose_struct();
  755.             }
  756.  
  757.             /* Delete the Copied data (if any) */
  758.             popen_struct((Pint)str->structure_id);
  759.             top = 0;
  760.             pset_elem_ptr((Pint)top);
  761.             pdel_elems_labels((Pint)cent->startLabel,
  762.                     (Pint)cent->endLabel);
  763.             pcopy_all_elems_struct((Pint)cent->structure_id);
  764.             pclose_struct();
  765.  
  766.             /* If a structure was open the reopen it and
  767.                set the element pointer */
  768.             if (stype == PSTRUCT_OPEN) {
  769.             popen_struct(stid);
  770.             pset_elem_ptr(ep);
  771.             }
  772.         }
  773.  
  774. #endif /* USING_PHIGS */
  775.         ent = ent->any.next;
  776.         }
  777.     }
  778. #endif /* REFER_STRUCTURE_EXISTS */
  779.  
  780.     if ( str != NULL )
  781.         str->expanded = FALSE;
  782. } /* End collapseStructure */
  783.  
  784.  
  785. /*--------------------------------------------------------------------*\
  786. | Procedure     :    int openUsingLinkList(* slList);
  787. |---------------------------------------------------------------------
  788. | Description   :    For PHIGS systems that do not support the 
  789. |            refer structure element (extension).  A given
  790. |            expanded structure instance is referenced by
  791. |            the PHIGs structure ID containing the instance
  792. |            and a list of CALL_STRUCTURE starting labels.
  793. |
  794. |            This information is contained in the singly
  795. |            linked list passed, the data field of the
  796. |            head of the list contains the PHIGs structure id 
  797. |            with the data fields of the remainder the label
  798. |            of the invocation path.
  799. |
  800. |---------------------------------------------------------------------
  801. | Return        :    Error Code (Not Implemented)
  802. \*--------------------------------------------------------------------*/
  803. int openUsingLinkList(lnList)
  804. slList *lnList;
  805.  
  806. {
  807. #ifdef USING_PHIGS
  808.     int top = 0;
  809.  
  810.     if ( lnList != NULL )
  811.     {
  812.         /* Open the Structure */
  813. #ifdef TEST_PRINT
  814. printf("openUsingLinkList: popst(%d)\n",lnList->data);
  815. fflush(stderr);
  816. #endif /* TEST_PRINT */
  817.         popen_struct((Pint)(lnList->data));
  818.  
  819. #ifdef TEST_PRINT
  820. printf("openUsingLinkList: psep(%d)\n",top);
  821. fflush(stderr);
  822. #endif /* TEST_PRINT */
  823.         pset_elem_ptr((Pint)top);
  824.  
  825.         /* Follow the CALL invocation path */
  826.         lnList = lnList->next;
  827.         while ( lnList != NULL )
  828.         {
  829. #ifdef TEST_PRINT
  830. printf("openUsingLinkList: pseplb(%d)\n",lnList->data);
  831. fflush(stderr);
  832. #endif /* TEST_PRINT */
  833.             pset_elem_ptr_label((Pint)(lnList->data));
  834.             lnList = lnList->next;
  835.         }
  836. #ifdef TEST_PRINT
  837. printf("done.\n");
  838. fflush(stderr);
  839. #endif /* TEST_PRINT */
  840.         return(0);
  841.     }
  842.     return(-1);
  843.  
  844. #endif /* USING_PHIGS */
  845. } /* openUsingLinkList() */
  846.  
  847.