home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / demos / gpc / listbufs.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-07-09  |  16.2 KB  |  470 lines

  1. /* $XConsortium: listbufs.c,v 5.2 91/07/10 08:40:16 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          :    listbufs.c
  50. | Date          :    3/15/89
  51. | Project       :    PLB
  52. | Description   :    Contains the functions to control data
  53. |            accumulation from the parser.
  54. | Status        :    Version 1.0
  55. |
  56. | Revisions     :    
  57. |    2/90        Staff SimGEC:
  58. |                BUFFER_OVERFLOW testing added.
  59. |                Repeated groups allowed.
  60. |                NULL current group identified.
  61. |                bif_real_list added.
  62. |
  63. \*--------------------------------------------------------------------*/
  64.  
  65. /*--------------------------------------------------------------------*\
  66. |    Table of Contents
  67. |
  68. |    int bif_intlist(BIF_INT)
  69. |        :    Recieve an int value from the parser, add to list
  70. |    int bif_real_list(BIF_REAL)
  71. |        :    Recieve a real value from the parser, add to list
  72. |    int bif_pair(BIF_REAL, BIF_REAL )
  73. |        :    Recieve a real pair from the parser, add to list
  74. |    int bif_triplet(BIF_REAL, BIF_REAL, BIF_REAL )
  75. |        :    Recieve a real triplet from the parser, add to list
  76. |    int init_triplets()
  77. |        :    Initialize the triplet list for point-accumulation
  78. |    int end_triplets(**Real_int_union)
  79. |        :    Return the results of the simple point-accumulation
  80. |    int init_groups()
  81. |        :    Initialize group accumulation headers.
  82. |    int end_groups( **Group_description )
  83. |        :    Return the number of accumulated groups and the 
  84. |    int bif_group( BIF_INT )
  85. |        :    Set the current group to the id spec. by the parser
  86. |    int init_contours( BIF_INT )
  87. |        :    Initialize the accumalator for simple contours
  88. |    int end_contours( **Real_int_union )
  89. |        :    Return the number of accumulated contours and the 
  90. |    int bif_contour( BIF_INT )
  91. |        :    Begin / end a contour (faset3 and fasetdata3 only)
  92. |
  93. \*--------------------------------------------------------------------*/
  94.  
  95. /*--------------------------------------------------------------------*\
  96. |    Include files
  97. \*--------------------------------------------------------------------*/
  98. #include <stdio.h>
  99. #include "biftypes.h"
  100. #include "bifbuild.h"
  101. #include "bifmacro.h"
  102. #include "ph_map.h"
  103.  
  104. /*--------------------------------------------------------------------*\
  105. |    Local #define
  106. \*--------------------------------------------------------------------*/
  107. #ifdef EXTERNAL_NOTE
  108.     Buffer overflow testing has been added.
  109. #endif /* EXTERNAL_NOTE */
  110.  
  111. #define INPUT_BUFFER_SIZE 125000
  112. #define MAX_GROUPS_DEFINE 500
  113.  
  114. /*--------------------------------------------------------------------*\
  115. |    Local MACROS  
  116. \*--------------------------------------------------------------------*/
  117. #define BUFFER_OVF(n)\
  118. {\
  119.     if ( (list_current + n - input_buffer) > INPUT_BUFFER_SIZE )\
  120.         ERROR("FATAL: Input Buffer Overflow.");\
  121. }
  122.  
  123. #define PRINT_MATRIX44(mat) \
  124. {\
  125.     printf("Row1: %lf %lf %lf %lf\n",mat[0][0],mat[0][1],mat[0][2],mat[0][3]);\
  126.     printf("Row2: %lf %lf %lf %lf\n",mat[1][0],mat[1][1],mat[1][2],mat[1][3]);\
  127.     printf("Row3: %lf %lf %lf %lf\n",mat[2][0],mat[2][1],mat[2][2],mat[2][3]);\
  128.     printf("Row4: %lf %lf %lf %lf\n",mat[3][0],mat[3][1],mat[3][2],mat[3][3]);\
  129. } /* End macro PRINT_MATRIX44 */
  130.  
  131. /*--------------------------------------------------------------------*\
  132. | Local global variables
  133. \*--------------------------------------------------------------------*/
  134.  
  135. static Real_int_union input_buffer[INPUT_BUFFER_SIZE];
  136. static Real_int_union *list_current, *contour_base;
  137. static int list_counter;
  138. static int number_of_groups;
  139. static int number_of_contours;
  140. static Group_description group_header[MAX_GROUPS_DEFINE];
  141. static Group_description *current_group;
  142.  
  143. /*--------------------------------------------------------------------*\
  144. | BEGIN PROCEDURE CODE
  145. \*--------------------------------------------------------------------*/
  146.  
  147. /* ****************************************
  148. * Value List Accumulation Utilities
  149. * ************************************** */
  150. /*----------------------------------------------------------------------*\
  151. | Procedure    :    int bif_intlist(BIF_INT)
  152. |------------------------------------------------------------------------|
  153. | Description    :    Recieve an int value from the parser, add to list
  154. |------------------------------------------------------------------------|
  155. | Return    :    Error Code
  156. \*----------------------------------------------------------------------*/
  157. int bif_intlist(int_value)
  158. BIF_INT int_value;
  159. {
  160. #ifdef TEST_PRINT_2
  161.     printf("Adding %d to list\n",int_value);
  162. #endif /* TEST_PRINT_2 */
  163. #ifndef PRINT_ONLY
  164.     list_counter++;
  165.     BUFFER_OVF(1);
  166.     (list_current++)->Int = int_value;
  167. #endif /* PRINT_ONLY */
  168. } /* End procedure bif_intlist */
  169.  
  170. /*----------------------------------------------------------------------*\
  171. | Procedure    :    int bif_real_list(BIF_REAL)
  172. |------------------------------------------------------------------------|
  173. | Description    :    Recieve a real value from the parser, add to list
  174. |------------------------------------------------------------------------|
  175. | Return    :    Error Code
  176. \*----------------------------------------------------------------------*/
  177. int bif_real_list(real_value) /* ver 1.0 */
  178. BIF_REAL real_value;
  179.  
  180. {
  181. #ifdef TEST_PRINT_2
  182.         printf("Adding %d to list\n",real_value);
  183.     /*--------------*/
  184. #endif /* TEST_PRINT_2 */
  185.       /*--------------*/
  186.  
  187. #ifndef PRINT_ONLY
  188.         list_counter++;
  189.     BUFFER_OVF(1);
  190.         (list_current++)->Float = real_value;
  191.     /*------------*/
  192. #endif /* PRINT_ONLY */
  193.       /*------------*/
  194. } /* End procedure bif_real_list */
  195.  
  196.  
  197. /*----------------------------------------------------------------------*\
  198. | Procedure    :    int bif_pair(BIF_REAL, BIF_REAL )
  199. |------------------------------------------------------------------------|
  200. | Description    :    Recieve a real pair from the parser, add to list
  201. |            as a triplet
  202. |------------------------------------------------------------------------|
  203. | Return    :    Error Code
  204. \*----------------------------------------------------------------------*/
  205. int bif_pair(x, y )
  206. BIF_REAL x, y;
  207. {
  208.     bif_triplet(x, y, (BIF_REAL)0.0 );
  209. }
  210.  
  211. /*----------------------------------------------------------------------* 
  212. | Procedure    :    int bif_triplet(BIF_REAL, BIF_REAL, BIF_REAL )
  213. |------------------------------------------------------------------------|
  214. | Description    :    Recieve a real triplet from the parser, add to list
  215. |------------------------------------------------------------------------|
  216. | Return    :    Error Code
  217. \*----------------------------------------------------------------------*/
  218. int bif_triplet(x, y, z )
  219. BIF_REAL x, y, z;
  220. {
  221. #ifdef TEST_PRINT_2
  222.     printf("Adding %f %f %f to list\n",x, y, z);
  223. #endif /* TEST_PRINT_2 */
  224. #ifndef PRINT_ONLY
  225.     list_counter++;
  226.     BUFFER_OVF(3);
  227.     (list_current++)->Float = x;
  228.     (list_current++)->Float = y;
  229.     (list_current++)->Float = z;
  230. #endif /* PRINT_ONLY */
  231. } /* End procedure bif_triplet */
  232.  
  233. /*----------------------------------------------------------------------*\
  234. | Procedure: int init_triplets()
  235. |------------------------------------------------------------------------|
  236. | Description: Initialize the triplet list for simple point-accumulation
  237. |------------------------------------------------------------------------|
  238. | Return: Error Code
  239. \*----------------------------------------------------------------------*/
  240. int init_triplets()
  241. {
  242. #ifdef TEST_PRINT
  243.     printf("Initializing triplet list\n");
  244. #endif /* TEST_PRINT */
  245. #ifndef PRINT_ONLY
  246.     list_counter = 0;
  247.     list_current = input_buffer;
  248. #endif /* PRINT_ONLY */
  249. } /* End procedure init_triplets */
  250.  
  251. /*----------------------------------------------------------------------*\
  252. | Procedure: int end_triplets(list_ptr)
  253. |------------------------------------------------------------------------|
  254. | Description: Return the results of the simple point-accumulation
  255. |------------------------------------------------------------------------|
  256. | Return: Number of triplets accumulated
  257. \*----------------------------------------------------------------------*/
  258. int end_triplets(list_ptr)
  259. Real_int_union *(*list_ptr);
  260. {
  261. #ifdef TEST_PRINT
  262.     printf("Ending triplet list\n");
  263. #endif /* TEST_PRINT */
  264. #ifndef PRINT_ONLY
  265.     *list_ptr = list_current - (list_counter * 3);
  266.     return(list_counter);
  267. #endif /* PRINT_ONLY */
  268. } /* End procedure end_triplets */
  269.  
  270. /*----------------------------------------------------------------------*\
  271. | Procedure: int init_groups()
  272. |------------------------------------------------------------------------|
  273. | Description: Initialize the defined accumulation groups.
  274. |        Set the current group to NULL.
  275. |------------------------------------------------------------------------|
  276. | Return: None
  277. \*----------------------------------------------------------------------*/
  278. void init_groups()
  279. {
  280. #ifdef TEST_PRINT
  281.     printf("Initializing groups\n");
  282. #endif /* TEST_PRINT */
  283.     number_of_groups = 0;
  284.     current_group    = NULL;
  285.     list_current     = input_buffer;
  286. } /* End procedure int init_groups */
  287.  
  288. /*----------------------------------------------------------------------*\
  289. | Procedure: int end_groups( group_ptr )
  290. |------------------------------------------------------------------------|
  291. | Description: Return the number of accumulated groups and the 
  292. |        pointer to the group description array
  293. |------------------------------------------------------------------------|
  294. | Return: The number of groups accumulated
  295. \*----------------------------------------------------------------------*/
  296. int end_groups(group_ptr)
  297. Group_description *(*group_ptr);
  298. {
  299. #ifdef TEST_PRINT
  300.     printf("Ending groups\n");
  301. #endif /* TEST_PRINT */
  302. #ifndef PRINT_ONLY
  303. /* Store the address of the group header array */
  304.     *group_ptr = group_header;
  305.  
  306. /* Return the number of groups */
  307.     return(number_of_groups);
  308.  
  309. #endif /* PRINT_ONLY */
  310. } /* End end_groups */
  311.  
  312. /*----------------------------------------------------------------------*\
  313. | Procedure    :    int bif_group( BIF_INT )
  314. |------------------------------------------------------------------------|
  315. | Description    :    Set the current group to the id spec. by the parser
  316. |------------------------------------------------------------------------|
  317. | Return    :    Error Code
  318. |    0    Success
  319. |    -1    Failure --- Out of groups (FATAL)
  320. \*----------------------------------------------------------------------*/
  321. int bif_group( group_id )
  322. BIF_INT group_id;
  323. {
  324.     int ret_code, found;
  325.     int group;
  326.     /* Check for BIF_END_OF_GROUP */
  327.     if ( (group_id == BIF_END_OF_GROUP) && (current_group != NULL) )
  328.     {
  329. #ifdef TEST_PRINT
  330.         printf("Ending current group\n");
  331. #endif /* TEST_PRINT */
  332. #ifndef PRINT_ONLY
  333.         /* Close out the current group. 
  334.             Get the size of the current group */
  335.         current_group->number = list_counter;
  336.         ret_code =  0; /* Success */
  337. #endif /* PRINT_ONLY */
  338.     }
  339.     else
  340.     {
  341. #ifdef TEST_PRINT
  342.         printf("Setting current group to %d\n",group_id);
  343. #endif /* TEST_PRINT */
  344. #ifndef PRINT_ONLY
  345.         /* Check if we can add another group... */
  346.         if ( number_of_groups < MAX_GROUPS_DEFINE )
  347.         {
  348.             ret_code = 0; /* Success, new group */
  349.  
  350.             /* Set up the new group */
  351.             current_group = &group_header[number_of_groups++];
  352.             current_group->list   = list_current;
  353.             current_group->number = 0;
  354.             current_group->name   = group_id;
  355.  
  356.             /* Reset the size counter */
  357.             list_counter = 0;
  358.  
  359.         }
  360.         else
  361.         /* Failure. Out of groups */
  362.             ERROR("FATAL: Out of groups.");
  363. #endif /* PRINT_ONLY */
  364.     }
  365.     
  366. #ifndef PRINT_ONLY
  367.     return( ret_code );
  368. #endif /* PRINT_ONLY */
  369. } /* End procedure bif_group */
  370.  
  371. /*----------------------------------------------------------------------*\
  372. | Procedure    :    int init_contours( BIF_INT )
  373. |------------------------------------------------------------------------|
  374. | Description    :    Initialize the accumalator for simple contours
  375. |
  376. |            Contours are used to avoid the implementation of
  377. |            nested groups.  They are used only for the
  378. |            fill_area_set (2D & 3D) entities.
  379. |------------------------------------------------------------------------|
  380. | Return    :    Error Code
  381. \*----------------------------------------------------------------------*/
  382. void init_contours( begin_or_end )
  383. BIF_INT begin_or_end ;
  384. {
  385. #ifdef TEST_PRINT
  386.     printf("Initializing contours\n");
  387. #endif /* TEST_PRINT */
  388. #ifndef PRINT_ONLY
  389. /* Clear the contour counter */
  390.     list_counter = 0;
  391. /* Initialize the list accumulation buffer */
  392.     list_current = input_buffer;
  393. #endif /* PRINT_ONLY */
  394. } /* End init_contours */
  395.  
  396. /*----------------------------------------------------------------------*\
  397. | Procedure    :    int end_contours( **Real_int_union )
  398. |------------------------------------------------------------------------|
  399. | Description    :    Return the number of accumulated contours and the 
  400. |            pointer to the contour list buffer.
  401. |
  402. |            Contours are used to avoid the implementation of
  403. |            nested groups.  They are used only for the
  404. |            fill_area_set (2D & 3D) entities.
  405. |------------------------------------------------------------------------|
  406. | Return    :    The number of contours accumulated.
  407. \*----------------------------------------------------------------------*/
  408. int end_contours(list_ptr)
  409. Real_int_union *(*list_ptr);
  410. {
  411. #ifdef TEST_PRINT
  412.     printf("Ending contours\n");
  413. #endif /* TEST_PRINT */
  414. #ifndef PRINT_ONLY
  415. /* Store the address of the list accumulation buffer */
  416.     *list_ptr = input_buffer;
  417.  
  418. /* Return the number of contours */
  419.     return(list_counter);
  420.  
  421. #endif /* PRINT_ONLY */
  422. } /* End end_contours */
  423.  
  424. /*----------------------------------------------------------------------*\
  425. | Procedure    :    int bif_contour( BIF_INT )
  426. |------------------------------------------------------------------------|
  427. | Description    :    Begin / end a contour (faset3 and fasetdata3 only)
  428. |
  429. |    BIF_P_BEGIN     begin contour
  430. |    BIF_P_END    end contour
  431. |
  432. |            Contours are used to avoid the implementation of
  433. |            nested groups.  They are used only for the
  434. |            fill_area_set (2D & 3D) entities.
  435. |------------------------------------------------------------------------|
  436. | Return    :    Error Code
  437. \*----------------------------------------------------------------------*/
  438. int bif_contour( begin_or_end )
  439. BIF_INT begin_or_end ;
  440. {
  441. #ifdef TEST_PRINT_2
  442.     BEGEND(contour);
  443. #endif /* TEST_PRINT_2 */
  444. #ifndef PRINT_ONLY
  445.     switch ( begin_or_end )
  446.     {
  447.     case BIF_P_BEGIN:
  448.     /* Start a new contour */
  449.     /* Save the contour counter */
  450.         number_of_contours = ++list_counter;
  451.     /* Save the contour size location */
  452.         contour_base = list_current;
  453.     /* Set the contour size to zero,  Just to be safe */
  454.         BUFFER_OVF(1);
  455.         (list_current++)->Int = 0;
  456.     /* Set the size counter to zero */
  457.         list_counter = 0;
  458.         break;
  459.  
  460.     case BIF_P_END:
  461.     /* End the current contour */
  462.     /* Save the contour size */
  463.         contour_base->Int = list_counter;
  464.     /* Restore the contour counter */
  465.         list_counter = number_of_contours;
  466.         break;
  467.     }
  468. #endif /* PRINT_ONLY */
  469. } /* End procedure bif_contour */
  470.