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

  1. /* $XConsortium: bldgeneric.c,v 5.1 91/02/16 10:07:09 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          :    bldgeneric.c
  49. | Date          :    Mon Jun 26 00:53:40 PDT 1989
  50. | Project       :    PLB
  51. | Description   :    The generic build routines. Used to simplify
  52. |                    bld_attr.c
  53. | Status        :    Version 1.0
  54. |
  55. | Revisions     :
  56. |
  57. |       2/90            MFC Tektronix, Inc.: PEX-SI API implementation.
  58. |
  59. |      12/90            MFC Tektronix, Inc.: PEX-SI PEX5R1 Release.
  60. |
  61. \*--------------------------------------------------------------------*/
  62.  
  63. /*--------------------------------------------------------------------*\
  64. |    Table of Contents
  65. |
  66. |    int bif_truecolor(float, float, float, int, int,
  67. |                (*int)(), (*int)() )
  68. |        :    Build and Store/Execute any true color entity.
  69. |    int bif_colorindex(int, int, int (*int)(), (*int)() )
  70. |        :    Receive any of the colorindex entities from 
  71. |    int bif_2_index(int, int, int, (*int)(), (*int)(), (*int)())
  72. |        :    Receive any of the index entities from a 
  73. |    int bif_index(int, int, int, (*int)(), (*int)())
  74. |        :    Receive any of the index entities from a 
  75. |    int bif_size(float, int, int, (*int)())
  76. |        :    Build, Store/Execute any float size definition
  77. |
  78. \*--------------------------------------------------------------------*/
  79.  
  80. /*---------------------------------------------------------------------*\
  81. |    Include files 
  82. \*--------------------------------------------------------------------- */
  83. #include <stdio.h>
  84. #include "biftypes.h"
  85. #include "bifbuild.h"
  86. #include "new_ents.h"
  87. #include "bifparse.h"
  88. #include "db_tools.h"
  89. #include "doentity.h"
  90. #include "bifmacro.h"
  91. #include "globals.h"
  92. #include "ph_map.h"
  93. #include "macfunct.h"
  94.  
  95. /*--------------------------------------------------------------------*\
  96. | Local global variables
  97. \*--------------------------------------------------------------------*/
  98. /* Useful statics */
  99. /* Temporary entity storage */
  100. static BIF_All temp_ent;
  101.  
  102. /*--------------------------------------------------------------------*\
  103. |    Generic True color, index color and index anything routines
  104. \*--------------------------------------------------------------------*/
  105. /*--------------------------------------------------------------------*\
  106. | Procedure    :    int bif_truecolor(float, float, float, int, int,
  107. |                (*int)(), (*int)() )
  108. |---------------------------------------------------------------------
  109. | Description    :    Build and Store/Execute any true color entity.
  110. |
  111. |            NOTE: bif_truecolor is referenced by the
  112. |            MF_TRUE_COLOR macro.
  113. |---------------------------------------------------------------------
  114. | Return    :    Error Code
  115. \*--------------------------------------------------------------------*/
  116. int bif_truecolor(c1, c2, c3, entSize, entType, entHandler, phigsFunc)
  117. float c1, c2, c3;
  118. int entSize;
  119. int entType;
  120. int (*entHandler)();
  121. void (*phigsFunc)();
  122.  
  123. {
  124.     char *find_keyword_token();
  125.     BIF_All *ent;
  126. #ifdef USING_PHIGS
  127.     Pgcolr gcolor;
  128. #endif /* USING_PHIGS */
  129. #ifdef TEST_PRINT
  130.     printf("%s: Set to %f %f %f\n",find_keyword_token((BIF_INT)entType),
  131.        c1 , c2, c3);
  132. #endif /* TEST_PRINT */
  133. #ifndef PRINT_ONLY
  134.     /*------------------------------------------------------------*\
  135.     |    All true color entities use the same structure
  136.     |    therefore we can use a common routine.
  137.     \*------------------------------------------------------------*/
  138. /* Allocate the entity */
  139.     temp_ent.truecolor.color_model = wk_info.color_model;
  140.     temp_ent.truecolor.color[0] = c1;
  141.     temp_ent.truecolor.color[1] = c2;
  142.     temp_ent.truecolor.color[2] = c3;
  143.  
  144.     ent = new_generic(&temp_ent,entSize,entType,entHandler);
  145.  
  146. /* Error check for ent == NULL ( FATAL ) */
  147.     ENT_ERROR(ent);
  148.  
  149. #ifdef TEST_PRINT
  150.     printf("push_level %d  \n", traverser_state->push_level);
  151. #endif /* TEST_PRINT */
  152. /* Build or Execute */
  153.     Traverse(traverser_state, ent);
  154.  
  155. #ifdef USING_PHIGS
  156. /* Call the entities in PHIGS */
  157.     gcolor.type = ent->truecolor.color_model;
  158.     gcolor.val.general.x = (Pfloat)ent->truecolor.color[0];
  159.     gcolor.val.general.y = (Pfloat)ent->truecolor.color[1];
  160.     gcolor.val.general.z = (Pfloat)ent->truecolor.color[2];
  161.     (*phigsFunc)(&gcolor);
  162. #endif /* USING_PHIGS */
  163.  
  164. /* Release Non-Retained Entities */
  165.   Free_NRE(traverser_state, ent);
  166.  
  167. #endif /*  PRINT_ONLY */
  168. } /* End procedure bif_truecolor */
  169.  
  170. /*--------------------------------------------------------------------*\
  171. | Procedure    :    int bif_colorindex(int, int, int
  172. |                        (*int)(), (*int)() )
  173. |---------------------------------------------------------------------
  174. | Description    :    Receive any of the colorindex entities from 
  175. |            MF_MAP_INDEX.
  176. |---------------------------------------------------------------------
  177. | Return    :    Error Code
  178. \*--------------------------------------------------------------------*/
  179. int bif_colorindex(indx, entSize, entType, entHandler, phigsFunc)
  180. int indx;
  181. int entSize;
  182. int entType;
  183. int (*entHandler)();
  184. void (*phigsFunc)();
  185.  
  186. {
  187.  
  188.     char *find_keyword_token();
  189.     BIF_All *ent;
  190. #ifdef USING_PHIGS
  191.     Pgcolr gcolor;
  192. #endif /* USING_PHIGS */
  193. #ifdef TEST_PRINT
  194.     printf("%s: Set to %d \n",find_keyword_token((BIF_INT)entType),
  195.         indx);
  196. #endif /* TEST_PRINT */
  197. #ifndef PRINT_ONLY
  198. /* Allocate the entity */
  199. #ifdef EXTERNALNOTE
  200.     /* indx is incremented by one so that color '0' does
  201.     not step on the default BG color. */
  202. #endif
  203.  
  204.     temp_ent.ind.ind = indx + 1;
  205.     ent = new_generic(&temp_ent, entSize, entType, entHandler);
  206.  
  207. /* Error check for ent == NULL ( FATAL ) */
  208.     ENT_ERROR(ent);
  209.  
  210. #ifdef TEST_PRINT
  211.     printf("push_level %d  \n", traverser_state->push_level);
  212. #endif /* TEST_PRINT */
  213. /* Build or Execute */
  214.     Traverse(traverser_state, ent);
  215.  
  216. #ifdef USING_PHIGS
  217. /* Call the entities in PHIGS */
  218.     gcolor.type = PINDIRECT;
  219.     gcolor.val.ind = (Pint)temp_ent.ind.ind;
  220.     (*phigsFunc)(&gcolor);
  221. #endif /* USING_PHIGS */
  222.  
  223. /* Release Non-Retained Entities */
  224.     Free_NRE(traverser_state, ent);
  225.  
  226. #endif /*  PRINT_ONLY */
  227. } /* End procedure bif_colorindex */
  228.  
  229. /*--------------------------------------------------------------------*\
  230. | Procedure    :    int bif_2_index(int, int, int, (*int)(), (*int)(),
  231. |                                       (*int)())
  232. |---------------------------------------------------------------------
  233. | Description    :    Receive any of the index entities from a 
  234. |            macro-function of parser receiver reference
  235. |                       and output same value to two functions.
  236. |---------------------------------------------------------------------
  237. | Return    :    Error Code
  238. \*--------------------------------------------------------------------*/
  239. int bif_2_index(indx, entSize, entType, entHandler, phigsFunc1, phigsFunc2 )
  240. int indx;
  241. int entSize;
  242. int entType;
  243. int (*entHandler)();
  244. void (*phigsFunc1)(),(*phigsFunc2)();
  245. {
  246.  
  247.     char *find_keyword_token();
  248.     BIF_All *ent;
  249. #ifdef TEST_PRINT
  250.     printf("%s: Set to %d \n",find_keyword_token((BIF_INT)entType),
  251.         indx);
  252. #endif /* TEST_PRINT */
  253. #ifndef PRINT_ONLY
  254. /* Allocate the entity */
  255.     temp_ent.ind.ind = indx;
  256.     ent = new_generic(&temp_ent, entSize, entType, entHandler);
  257.  
  258. /* Error check for ent == NULL ( FATAL ) */
  259.     ENT_ERROR(ent);
  260.  
  261. #ifdef TEST_PRINT
  262.     printf("push_level %d  \n", traverser_state->push_level);
  263. #endif /* TEST_PRINT */
  264. /* Build or Execute */
  265.     Traverse(traverser_state, ent);
  266.  
  267. #ifdef USING_PHIGS
  268. /* Call the entity in PHIGS */
  269.     (*phigsFunc1)((Pint)temp_ent.ind.ind);
  270.     (*phigsFunc2)((Pint)temp_ent.ind.ind);
  271. #endif /* USING_PHIGS */
  272.  
  273. /* Release Non-Retained Entities */
  274.     Free_NRE(traverser_state, ent);
  275.  
  276. #endif /*  PRINT_ONLY */
  277. } /* End procedure bif_2_index */
  278.  
  279. /*--------------------------------------------------------------------*\
  280. | Procedure    :    int bif_index(int, int, int, (*int)(), (*int)())
  281. |---------------------------------------------------------------------
  282. | Description    :    Receive any of the index entities from a 
  283. |            macro-function of parser receiver reference.
  284. |---------------------------------------------------------------------
  285. | Return    :    Error Code
  286. \*--------------------------------------------------------------------*/
  287. int bif_index(indx, entSize, entType, entHandler, phigsFunc)
  288. int indx;
  289. int entSize;
  290. int entType;
  291. int (*entHandler)();
  292. void (*phigsFunc)();
  293. {
  294.  
  295.     char *find_keyword_token();
  296.     BIF_All *ent;
  297. #ifdef TEST_PRINT
  298.     printf("%s: Set to %d \n",find_keyword_token((BIF_INT)entType),
  299.         indx);
  300. #endif /* TEST_PRINT */
  301. #ifndef PRINT_ONLY
  302. /* Allocate the entity */
  303.     temp_ent.ind.ind = indx;
  304.     ent = new_generic(&temp_ent, entSize, entType, entHandler);
  305.  
  306. /* Error check for ent == NULL ( FATAL ) */
  307.     ENT_ERROR(ent);
  308.  
  309. #ifdef TEST_PRINT
  310.     printf("push_level %d  \n", traverser_state->push_level);
  311. #endif /* TEST_PRINT */
  312. /* Build or Execute */
  313.     Traverse(traverser_state, ent);
  314.  
  315. #ifdef USING_PHIGS
  316. /* Call the entity in PHIGS */
  317.     (*phigsFunc)((Pint)temp_ent.ind.ind);
  318. #endif /* USING_PHIGS */
  319.  
  320. /* Release Non-Retained Entities */
  321.     Free_NRE(traverser_state, ent);
  322.  
  323. #endif /*  PRINT_ONLY */
  324. } /* End procedure bif_index */
  325.  
  326. /*--------------------------------------------------------------------*\
  327. | Procedure    :    int bif_size(float, int, int, (*int)())
  328. |--------------------------------------------------------------------|
  329. | Description    :    Build, Store/Execute any float size definition
  330. |                entity (indirectly) from the parser.
  331. |--------------------------------------------------------------------|
  332. | Return    :    Error Code (Not Implemented)
  333. \*--------------------------------------------------------------------*/
  334. int bif_size(scaleFactor,entSize,entType,entHandler,phigsFunc)
  335. float scaleFactor;
  336. int entSize;
  337. int entType;
  338. int (*entHandler)();
  339. void (*phigsFunc)();
  340.  
  341. {
  342.     char *find_keyword_token();
  343.     BIF_All *ent;
  344. #ifdef TEST_PRINT
  345.     printf("%s: Set to %f \n",find_keyword_token((BIF_INT)entType),
  346.         scaleFactor);
  347.     printf("MARKER_SIZE: Set to %f\n",scaleFactor);
  348. #endif /* TEST_PRINT */
  349. #ifndef PRINT_ONLY
  350. /* Allocate the entity */
  351.     temp_ent.size.size = scaleFactor;
  352.     ent = new_generic(&temp_ent,entSize,entType,entHandler);
  353.  
  354. /* Error check for ent == NULL ( FATAL ) */
  355.     ENT_ERROR(ent);
  356.  
  357. #ifdef TEST_PRINT
  358.     printf("push_level %d  \n", traverser_state->push_level);
  359. #endif /* TEST_PRINT */
  360. /* Build or Execute */
  361.     Traverse(traverser_state, ent);
  362.  
  363. #ifdef USING_PHIGS
  364. /* Call the entity in PHIGS */
  365.     (*phigsFunc)((Pfloat)temp_ent.size.size);
  366. #endif /* USING_PHIGS */
  367.  
  368. /* Release Non-Retained Entities */
  369.     Free_NRE(traverser_state, ent);
  370.  
  371. #endif /*  PRINT_ONLY */
  372. } /* End bif_size() */
  373.  
  374.