Add GNU LGPL headers to all .c .C and .h files
[oweals/cde.git] / cde / osf / uil / UilSarInc.c
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 /*
40 *  (c) Copyright 1989, 1990, DIGITAL EQUIPMENT CORPORATION, MAYNARD, MASS. */
41
42 /*
43 **++
44 **  FACILITY:
45 **
46 **      User Interface Language Compiler (UIL)
47 **
48 **  ABSTRACT:
49 **
50 **      This module contain the routines for processing the INCLUDE construct.
51 **
52 **--
53 **/
54
55
56 /*
57 **
58 **  INCLUDE FILES
59 **
60 **/
61
62 #include <Xm/Xm.h>
63 #include "UilDefI.h"
64
65
66 /*
67 **
68 **  DEFINE and MACRO DEFINITIONS
69 **
70 **/
71
72
73 /*
74 **
75 **  EXTERNAL VARIABLE DECLARATIONS
76 **
77 **/
78
79
80
81 /*
82 **
83 **  GLOBAL VARIABLE DECLARATIONS
84 **
85 **/
86
87
88
89 /*
90 **
91 **  OWN VARIABLE DECLARATIONS
92 **
93 **/
94
95 \f
96 /*
97 **++
98 **  FUNCTIONAL DESCRIPTION:
99 **
100 **      This routine handles the include directive.
101 **
102 **  FORMAL PARAMETERS:
103 **
104 **      file_frame      parser stack frame that contains the name of the
105 **                      file to be included.
106 **
107 **  IMPLICIT INPUTS:
108 **
109 **      none
110 **
111 **  IMPLICIT OUTPUTS:
112 **
113 **      none
114 **
115 **  FUNCTION VALUE:
116 **
117 **      void
118 **
119 **  SIDE EFFECTS:
120 **
121 **      none
122 **
123 **--
124 **/
125
126 void    sar_include_file ( file_frame, include_frame, semi_frame )
127
128 yystype     * file_frame;
129 yystype     * include_frame;
130 yystype     * semi_frame;
131
132 {
133     sym_value_entry_type        * value_entry;
134     sym_include_file_entry_type * include_entry;
135     sym_section_entry_type      * section_entry;
136     sym_section_entry_type      * section_tail_entry;
137     char                        * buffer;
138     unsigned char                 tmp1;
139     int                           i,j;
140
141     value_entry =
142         (sym_value_entry_type *) file_frame -> value . az_symbol_entry;
143
144 /*
145  * Fix for CR 5465 - If the value_entry is not of type char_8, print an 
146  *                   error message and abort the compilation
147  */
148     if ((value_entry->b_type != sym_k_char_8_value) &&
149         (value_entry->b_type != sym_k_localized_string_value))
150       diag_issue_diagnostic (
151              d_include_file,
152              _sar_source_pos2(value_entry));
153 /*
154  * End Fix for CR 5465
155  */
156 /*
157  * If the direction is RtoL then reverse the include file.
158  */
159     if (value_entry->b_direction == XmSTRING_DIRECTION_R_TO_L) 
160         {
161         /*
162         **  Just reverse the bytes from the first to last
163         */
164         for (i=0, j=value_entry->w_length-1;  
165              i < (int)((int)value_entry->w_length>>1);  
166              i++,j--)
167             {
168             tmp1 = value_entry->value.c_value[ i ];
169             value_entry->value.c_value[ i ] = 
170                 value_entry->value.c_value[ j ];
171             value_entry->value.c_value[ j ] = tmp1;
172             }
173         }
174
175     _assert (value_entry -> header . b_tag == sym_k_value_entry,
176              "missing value entry for include");
177
178     /*
179     ** Allocate an INCLUDE entry
180     */
181
182     include_entry = (sym_include_file_entry_type *) sem_allocate_node
183                         ( sym_k_include_file_entry, sym_k_include_file_entry_size );
184
185     /*
186     ** Open the include file.  Set up a null-terminated name string.
187     */
188
189     buffer = (char *) _get_memory (value_entry -> w_length + 1);
190     _move (buffer, value_entry -> value . c_value,
191                    value_entry -> w_length);
192     buffer [value_entry -> w_length] = 0 ;
193
194     src_open_file (buffer, include_entry->full_file_name);
195
196     /*
197     **  Allocate a section entry for this include "section".
198     **  Store the source info in it
199     */
200
201     section_entry = (sym_section_entry_type *) sem_allocate_node
202                         ( sym_k_section_entry, sym_k_section_entry_size );
203
204     section_entry->header.b_type = sym_k_include_section;
205
206     _sar_save_source_info ( &section_entry->header , include_frame , semi_frame );
207
208     /*
209     ** Link this section into the current section list.
210     */
211
212     section_entry->next = (sym_entry_type *) sym_az_current_section_entry;
213     section_entry->prev_section = sym_az_current_section_entry->prev_section;
214     sym_az_current_section_entry = section_entry;
215
216     /*
217     ** Link the include intry we created earlier onto the section list
218     */
219
220     section_entry->entries = (sym_entry_type *)include_entry;
221
222     /*
223     **  Save the file name
224     */
225
226     _move (include_entry->file_name, buffer, value_entry->w_length);
227     include_entry->file_name [value_entry->w_length] =  0;
228
229     /*
230     ** Since this is an INCLUDE we want included sections to hang off
231     ** of it so we create a new place holder entry (tail) and change the
232     ** "current" section list to it.
233     */
234
235     section_tail_entry = (sym_section_entry_type *) sem_allocate_node
236                             ( sym_k_section_entry, sym_k_section_entry_size );
237
238     section_tail_entry->header.b_type = sym_k_section_tail;
239
240     include_entry->sections = section_tail_entry;
241
242     section_tail_entry->prev_section = sym_az_current_section_entry;
243     sym_az_current_section_entry = section_tail_entry;
244
245     _free_memory (buffer);
246
247 }