UilSarInc.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. /*
  2. * CDE - Common Desktop Environment
  3. *
  4. * Copyright (c) 1993-2012, The Open Group. All rights reserved.
  5. *
  6. * These libraries and programs are free software; you can
  7. * redistribute them and/or modify them under the terms of the GNU
  8. * Lesser General Public License as published by the Free Software
  9. * Foundation; either version 2 of the License, or (at your option)
  10. * any later version.
  11. *
  12. * These libraries and programs are distributed in the hope that
  13. * they will be useful, but WITHOUT ANY WARRANTY; without even the
  14. * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  15. * PURPOSE. See the GNU Lesser General Public License for more
  16. * details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with these librararies and programs; if not, write
  20. * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
  21. * Floor, Boston, MA 02110-1301 USA
  22. */
  23. /*
  24. * @OSF_COPYRIGHT@
  25. * COPYRIGHT NOTICE
  26. * Copyright (c) 1990, 1991, 1992, 1993 Open Software Foundation, Inc.
  27. * ALL RIGHTS RESERVED (MOTIF). See the file named COPYRIGHT.MOTIF for
  28. * the full copyright text.
  29. */
  30. /*
  31. * HISTORY
  32. */
  33. #ifdef REV_INFO
  34. #ifndef lint
  35. static char rcsid[] = "$TOG: UilSarInc.c /main/12 1997/03/12 15:21:31 dbl $"
  36. #endif
  37. #endif
  38. /*
  39. * (c) Copyright 1989, 1990, DIGITAL EQUIPMENT CORPORATION, MAYNARD, MASS. */
  40. /*
  41. **++
  42. ** FACILITY:
  43. **
  44. ** User Interface Language Compiler (UIL)
  45. **
  46. ** ABSTRACT:
  47. **
  48. ** This module contain the routines for processing the INCLUDE construct.
  49. **
  50. **--
  51. **/
  52. /*
  53. **
  54. ** INCLUDE FILES
  55. **
  56. **/
  57. #include <Xm/Xm.h>
  58. #include "UilDefI.h"
  59. /*
  60. **
  61. ** DEFINE and MACRO DEFINITIONS
  62. **
  63. **/
  64. /*
  65. **
  66. ** EXTERNAL VARIABLE DECLARATIONS
  67. **
  68. **/
  69. /*
  70. **
  71. ** GLOBAL VARIABLE DECLARATIONS
  72. **
  73. **/
  74. /*
  75. **
  76. ** OWN VARIABLE DECLARATIONS
  77. **
  78. **/
  79. /*
  80. **++
  81. ** FUNCTIONAL DESCRIPTION:
  82. **
  83. ** This routine handles the include directive.
  84. **
  85. ** FORMAL PARAMETERS:
  86. **
  87. ** file_frame parser stack frame that contains the name of the
  88. ** file to be included.
  89. **
  90. ** IMPLICIT INPUTS:
  91. **
  92. ** none
  93. **
  94. ** IMPLICIT OUTPUTS:
  95. **
  96. ** none
  97. **
  98. ** FUNCTION VALUE:
  99. **
  100. ** void
  101. **
  102. ** SIDE EFFECTS:
  103. **
  104. ** none
  105. **
  106. **--
  107. **/
  108. void sar_include_file ( file_frame, include_frame, semi_frame )
  109. yystype * file_frame;
  110. yystype * include_frame;
  111. yystype * semi_frame;
  112. {
  113. sym_value_entry_type * value_entry;
  114. sym_include_file_entry_type * include_entry;
  115. sym_section_entry_type * section_entry;
  116. sym_section_entry_type * section_tail_entry;
  117. char * buffer;
  118. unsigned char tmp1;
  119. int i,j;
  120. value_entry =
  121. (sym_value_entry_type *) file_frame -> value . az_symbol_entry;
  122. /*
  123. * Fix for CR 5465 - If the value_entry is not of type char_8, print an
  124. * error message and abort the compilation
  125. */
  126. if ((value_entry->b_type != sym_k_char_8_value) &&
  127. (value_entry->b_type != sym_k_localized_string_value))
  128. diag_issue_diagnostic (
  129. d_include_file,
  130. _sar_source_pos2(value_entry));
  131. /*
  132. * End Fix for CR 5465
  133. */
  134. /*
  135. * If the direction is RtoL then reverse the include file.
  136. */
  137. if (value_entry->b_direction == XmSTRING_DIRECTION_R_TO_L)
  138. {
  139. /*
  140. ** Just reverse the bytes from the first to last
  141. */
  142. for (i=0, j=value_entry->w_length-1;
  143. i < (int)((int)value_entry->w_length>>1);
  144. i++,j--)
  145. {
  146. tmp1 = value_entry->value.c_value[ i ];
  147. value_entry->value.c_value[ i ] =
  148. value_entry->value.c_value[ j ];
  149. value_entry->value.c_value[ j ] = tmp1;
  150. }
  151. }
  152. _assert (value_entry -> header . b_tag == sym_k_value_entry,
  153. "missing value entry for include");
  154. /*
  155. ** Allocate an INCLUDE entry
  156. */
  157. include_entry = (sym_include_file_entry_type *) sem_allocate_node
  158. ( sym_k_include_file_entry, sym_k_include_file_entry_size );
  159. /*
  160. ** Open the include file. Set up a null-terminated name string.
  161. */
  162. buffer = (char *) _get_memory (value_entry -> w_length + 1);
  163. _move (buffer, value_entry -> value . c_value,
  164. value_entry -> w_length);
  165. buffer [value_entry -> w_length] = 0 ;
  166. src_open_file (buffer, include_entry->full_file_name);
  167. /*
  168. ** Allocate a section entry for this include "section".
  169. ** Store the source info in it
  170. */
  171. section_entry = (sym_section_entry_type *) sem_allocate_node
  172. ( sym_k_section_entry, sym_k_section_entry_size );
  173. section_entry->header.b_type = sym_k_include_section;
  174. _sar_save_source_info ( &section_entry->header , include_frame , semi_frame );
  175. /*
  176. ** Link this section into the current section list.
  177. */
  178. section_entry->next = (sym_entry_type *) sym_az_current_section_entry;
  179. section_entry->prev_section = sym_az_current_section_entry->prev_section;
  180. sym_az_current_section_entry = section_entry;
  181. /*
  182. ** Link the include intry we created earlier onto the section list
  183. */
  184. section_entry->entries = (sym_entry_type *)include_entry;
  185. /*
  186. ** Save the file name
  187. */
  188. _move (include_entry->file_name, buffer, value_entry->w_length);
  189. include_entry->file_name [value_entry->w_length] = 0;
  190. /*
  191. ** Since this is an INCLUDE we want included sections to hang off
  192. ** of it so we create a new place holder entry (tail) and change the
  193. ** "current" section list to it.
  194. */
  195. section_tail_entry = (sym_section_entry_type *) sem_allocate_node
  196. ( sym_k_section_entry, sym_k_section_entry_size );
  197. section_tail_entry->header.b_type = sym_k_section_tail;
  198. include_entry->sections = section_tail_entry;
  199. section_tail_entry->prev_section = sym_az_current_section_entry;
  200. sym_az_current_section_entry = section_tail_entry;
  201. _free_memory (buffer);
  202. }