aslfiles.c revision 1.11.2.2 1 1.1 jruoho /******************************************************************************
2 1.1 jruoho *
3 1.2 christos * Module Name: aslfiles - File support functions
4 1.1 jruoho *
5 1.1 jruoho *****************************************************************************/
6 1.1 jruoho
7 1.2 christos /*
8 1.11.2.2 martin * Copyright (C) 2000 - 2020, Intel Corp.
9 1.1 jruoho * All rights reserved.
10 1.1 jruoho *
11 1.2 christos * Redistribution and use in source and binary forms, with or without
12 1.2 christos * modification, are permitted provided that the following conditions
13 1.2 christos * are met:
14 1.2 christos * 1. Redistributions of source code must retain the above copyright
15 1.2 christos * notice, this list of conditions, and the following disclaimer,
16 1.2 christos * without modification.
17 1.2 christos * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 1.2 christos * substantially similar to the "NO WARRANTY" disclaimer below
19 1.2 christos * ("Disclaimer") and any redistribution must be conditioned upon
20 1.2 christos * including a substantially similar Disclaimer requirement for further
21 1.2 christos * binary redistribution.
22 1.2 christos * 3. Neither the names of the above-listed copyright holders nor the names
23 1.2 christos * of any contributors may be used to endorse or promote products derived
24 1.2 christos * from this software without specific prior written permission.
25 1.2 christos *
26 1.2 christos * Alternatively, this software may be distributed under the terms of the
27 1.2 christos * GNU General Public License ("GPL") version 2 as published by the Free
28 1.2 christos * Software Foundation.
29 1.2 christos *
30 1.2 christos * NO WARRANTY
31 1.2 christos * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 1.2 christos * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 1.2 christos * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 1.2 christos * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 1.2 christos * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 1.2 christos * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 1.2 christos * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 1.2 christos * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 1.2 christos * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 1.2 christos * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 1.2 christos * POSSIBILITY OF SUCH DAMAGES.
42 1.2 christos */
43 1.1 jruoho
44 1.1 jruoho #include "aslcompiler.h"
45 1.1 jruoho #include "acapps.h"
46 1.1 jruoho
47 1.1 jruoho #define _COMPONENT ACPI_COMPILER
48 1.1 jruoho ACPI_MODULE_NAME ("aslfiles")
49 1.1 jruoho
50 1.1 jruoho /* Local prototypes */
51 1.1 jruoho
52 1.5 christos static FILE *
53 1.1 jruoho FlOpenIncludeWithPrefix (
54 1.1 jruoho char *PrefixDir,
55 1.5 christos ACPI_PARSE_OBJECT *Op,
56 1.1 jruoho char *Filename);
57 1.1 jruoho
58 1.1 jruoho #ifdef ACPI_OBSOLETE_FUNCTIONS
59 1.1 jruoho ACPI_STATUS
60 1.1 jruoho FlParseInputPathname (
61 1.1 jruoho char *InputFilename);
62 1.1 jruoho #endif
63 1.1 jruoho
64 1.1 jruoho
65 1.1 jruoho /*******************************************************************************
66 1.1 jruoho *
67 1.11.2.1 christos * FUNCTION: FlInitOneFile
68 1.11.2.1 christos *
69 1.11.2.1 christos * PARAMETERS: InputFilename - The user-specified ASL source file to be
70 1.11.2.1 christos * compiled
71 1.11.2.1 christos *
72 1.11.2.1 christos * RETURN: Status
73 1.11.2.1 christos *
74 1.11.2.1 christos * DESCRIPTION: Initialize global file structure for one input file. This file
75 1.11.2.1 christos * structure contains references to input, output, debugging, and
76 1.11.2.1 christos * other miscellaneous files that are associated for a single
77 1.11.2.1 christos * input ASL file.
78 1.11.2.1 christos *
79 1.11.2.1 christos ******************************************************************************/
80 1.11.2.1 christos
81 1.11.2.1 christos ACPI_STATUS
82 1.11.2.1 christos FlInitOneFile (
83 1.11.2.1 christos char *InputFilename)
84 1.11.2.1 christos {
85 1.11.2.1 christos UINT32 i;
86 1.11.2.1 christos ASL_GLOBAL_FILE_NODE *NewFileNode;
87 1.11.2.1 christos
88 1.11.2.1 christos
89 1.11.2.1 christos if (FlInputFileExists (InputFilename))
90 1.11.2.1 christos {
91 1.11.2.1 christos AslError (ASL_ERROR, ASL_MSG_DUPLICATE_INPUT_FILE, NULL, InputFilename);
92 1.11.2.1 christos return (AE_ALREADY_EXISTS);
93 1.11.2.1 christos }
94 1.11.2.1 christos
95 1.11.2.1 christos NewFileNode = ACPI_CAST_PTR (ASL_GLOBAL_FILE_NODE,
96 1.11.2.1 christos UtLocalCacheCalloc (sizeof (ASL_GLOBAL_FILE_NODE)));
97 1.11.2.1 christos
98 1.11.2.1 christos NewFileNode->ParserErrorDetected = FALSE;
99 1.11.2.1 christos NewFileNode->Next = AslGbl_FilesList;
100 1.11.2.1 christos
101 1.11.2.1 christos AslGbl_FilesList = NewFileNode;
102 1.11.2.1 christos AslGbl_Files = NewFileNode->Files;
103 1.11.2.1 christos
104 1.11.2.1 christos for (i = 0; i < ASL_NUM_FILES; i++)
105 1.11.2.1 christos {
106 1.11.2.1 christos AslGbl_Files[i].Handle = NULL;
107 1.11.2.1 christos AslGbl_Files[i].Filename = NULL;
108 1.11.2.1 christos }
109 1.11.2.1 christos
110 1.11.2.1 christos AslGbl_Files[ASL_FILE_STDOUT].Handle = stdout;
111 1.11.2.1 christos AslGbl_Files[ASL_FILE_STDOUT].Filename = "STDOUT";
112 1.11.2.1 christos
113 1.11.2.1 christos if (AslGbl_VerboseErrors)
114 1.11.2.1 christos {
115 1.11.2.1 christos AslGbl_Files[ASL_FILE_STDERR].Handle = stderr;
116 1.11.2.1 christos }
117 1.11.2.1 christos else
118 1.11.2.1 christos {
119 1.11.2.1 christos AslGbl_Files[ASL_FILE_STDERR].Handle = stdout;
120 1.11.2.1 christos }
121 1.11.2.1 christos
122 1.11.2.1 christos AslGbl_Files[ASL_FILE_STDERR].Filename = "STDERR";
123 1.11.2.1 christos return (AE_OK);
124 1.11.2.1 christos }
125 1.11.2.1 christos
126 1.11.2.1 christos
127 1.11.2.1 christos /*******************************************************************************
128 1.11.2.1 christos *
129 1.11.2.1 christos * FUNCTION: FlInputFileExists
130 1.11.2.1 christos *
131 1.11.2.1 christos * PARAMETERS: Filename - File name to be searched
132 1.11.2.1 christos *
133 1.11.2.1 christos * RETURN: Status
134 1.11.2.1 christos *
135 1.11.2.1 christos * DESCRIPTION: Returns true if the file name already exists.
136 1.11.2.1 christos *
137 1.11.2.1 christos ******************************************************************************/
138 1.11.2.1 christos
139 1.11.2.1 christos BOOLEAN
140 1.11.2.1 christos FlInputFileExists (
141 1.11.2.1 christos char *Filename)
142 1.11.2.1 christos {
143 1.11.2.1 christos ASL_GLOBAL_FILE_NODE *Current = AslGbl_FilesList;
144 1.11.2.1 christos
145 1.11.2.1 christos
146 1.11.2.1 christos while (Current)
147 1.11.2.1 christos {
148 1.11.2.1 christos if (!strcmp (Filename, Current->Files[ASL_FILE_INPUT].Filename))
149 1.11.2.1 christos {
150 1.11.2.1 christos return (TRUE);
151 1.11.2.1 christos }
152 1.11.2.1 christos
153 1.11.2.1 christos Current = Current->Next;
154 1.11.2.1 christos }
155 1.11.2.1 christos
156 1.11.2.1 christos return (FALSE);
157 1.11.2.1 christos }
158 1.11.2.1 christos
159 1.11.2.1 christos
160 1.11.2.1 christos /*******************************************************************************
161 1.11.2.1 christos *
162 1.11.2.1 christos * FUNCTION: FlSwitchFileSet
163 1.11.2.1 christos *
164 1.11.2.1 christos * PARAMETERS: Op - Parse node for the LINE asl statement
165 1.11.2.1 christos *
166 1.11.2.1 christos * RETURN: None.
167 1.11.2.1 christos *
168 1.11.2.1 christos * DESCRIPTION: Set the current line number
169 1.11.2.1 christos *
170 1.11.2.1 christos ******************************************************************************/
171 1.11.2.1 christos
172 1.11.2.1 christos ASL_FILE_SWITCH_STATUS
173 1.11.2.1 christos FlSwitchFileSet (
174 1.11.2.1 christos char *InputFilename)
175 1.11.2.1 christos {
176 1.11.2.1 christos ASL_GLOBAL_FILE_NODE *Current = AslGbl_FilesList;
177 1.11.2.1 christos char *PrevFilename = Current->Files[ASL_FILE_INPUT].Filename;
178 1.11.2.1 christos
179 1.11.2.1 christos
180 1.11.2.1 christos while (Current)
181 1.11.2.1 christos {
182 1.11.2.1 christos if (!strcmp(Current->Files[ASL_FILE_INPUT].Filename, InputFilename))
183 1.11.2.1 christos {
184 1.11.2.1 christos AslGbl_Files = Current->Files;
185 1.11.2.1 christos AslGbl_TableSignature = Current->TableSignature;
186 1.11.2.1 christos AslGbl_TableId = Current->TableId;
187 1.11.2.1 christos
188 1.11.2.1 christos if (!strcmp (InputFilename, PrevFilename))
189 1.11.2.1 christos {
190 1.11.2.1 christos return (SWITCH_TO_SAME_FILE);
191 1.11.2.1 christos }
192 1.11.2.1 christos else
193 1.11.2.1 christos {
194 1.11.2.1 christos return (SWITCH_TO_DIFFERENT_FILE);
195 1.11.2.1 christos }
196 1.11.2.1 christos }
197 1.11.2.1 christos
198 1.11.2.1 christos Current = Current->Next;
199 1.11.2.1 christos }
200 1.11.2.1 christos
201 1.11.2.1 christos return (FILE_NOT_FOUND);
202 1.11.2.1 christos }
203 1.11.2.1 christos
204 1.11.2.1 christos
205 1.11.2.1 christos /*******************************************************************************
206 1.11.2.1 christos *
207 1.11.2.1 christos * FUNCTION: FlGetFileHandle
208 1.11.2.1 christos *
209 1.11.2.1 christos * PARAMETERS: OutFileId - denotes file type of output handle
210 1.11.2.1 christos * InFileId - denotes file type of the input Filename
211 1.11.2.1 christos * Filename
212 1.11.2.1 christos *
213 1.11.2.1 christos * RETURN: File handle
214 1.11.2.1 christos *
215 1.11.2.1 christos * DESCRIPTION: Get the file handle for a particular filename/FileId. This
216 1.11.2.1 christos * function also allows the caller to specify the file Id of the
217 1.11.2.1 christos * desired type.
218 1.11.2.1 christos *
219 1.11.2.1 christos ******************************************************************************/
220 1.11.2.1 christos
221 1.11.2.1 christos FILE *
222 1.11.2.1 christos FlGetFileHandle (
223 1.11.2.1 christos UINT32 OutFileId,
224 1.11.2.1 christos UINT32 InFileId,
225 1.11.2.1 christos char *Filename)
226 1.11.2.1 christos {
227 1.11.2.1 christos ASL_GLOBAL_FILE_NODE *Current = AslGbl_FilesList;
228 1.11.2.1 christos
229 1.11.2.1 christos
230 1.11.2.1 christos if (!Filename)
231 1.11.2.1 christos {
232 1.11.2.1 christos return (NULL);
233 1.11.2.1 christos }
234 1.11.2.1 christos
235 1.11.2.1 christos while (Current)
236 1.11.2.1 christos {
237 1.11.2.1 christos if (!strcmp (Current->Files[InFileId].Filename, Filename))
238 1.11.2.1 christos {
239 1.11.2.1 christos return (Current->Files[OutFileId].Handle);
240 1.11.2.1 christos }
241 1.11.2.1 christos
242 1.11.2.1 christos Current = Current->Next;
243 1.11.2.1 christos }
244 1.11.2.1 christos
245 1.11.2.1 christos return (NULL);
246 1.11.2.1 christos }
247 1.11.2.1 christos
248 1.11.2.1 christos
249 1.11.2.1 christos /*******************************************************************************
250 1.11.2.1 christos *
251 1.11.2.1 christos * FUNCTION: FlGetFileNode
252 1.11.2.1 christos *
253 1.11.2.1 christos * PARAMETERS: FileId - File type (ID) of the input Filename
254 1.11.2.1 christos * Filename - File to search for
255 1.11.2.1 christos *
256 1.11.2.1 christos * RETURN: A global file node
257 1.11.2.1 christos *
258 1.11.2.1 christos * DESCRIPTION: Get the file node for a particular filename/FileId.
259 1.11.2.1 christos *
260 1.11.2.1 christos ******************************************************************************/
261 1.11.2.1 christos
262 1.11.2.1 christos ASL_GLOBAL_FILE_NODE *
263 1.11.2.1 christos FlGetFileNode (
264 1.11.2.1 christos UINT32 FileId,
265 1.11.2.1 christos char *Filename)
266 1.11.2.1 christos {
267 1.11.2.1 christos ASL_GLOBAL_FILE_NODE *Current = AslGbl_FilesList;
268 1.11.2.1 christos
269 1.11.2.1 christos
270 1.11.2.1 christos if (!Filename)
271 1.11.2.1 christos {
272 1.11.2.1 christos return (NULL);
273 1.11.2.1 christos }
274 1.11.2.1 christos
275 1.11.2.1 christos while (Current)
276 1.11.2.1 christos {
277 1.11.2.1 christos if (!strcmp (Current->Files[FileId].Filename, Filename))
278 1.11.2.1 christos {
279 1.11.2.1 christos return (Current);
280 1.11.2.1 christos }
281 1.11.2.1 christos
282 1.11.2.1 christos Current = Current->Next;
283 1.11.2.1 christos }
284 1.11.2.1 christos
285 1.11.2.1 christos return (NULL);
286 1.11.2.1 christos }
287 1.11.2.1 christos
288 1.11.2.1 christos
289 1.11.2.1 christos /*******************************************************************************
290 1.11.2.1 christos *
291 1.11.2.1 christos * FUNCTION: FlGetCurrentFileNode
292 1.11.2.1 christos *
293 1.11.2.1 christos * PARAMETERS: None
294 1.11.2.1 christos *
295 1.11.2.1 christos * RETURN: Global file node
296 1.11.2.1 christos *
297 1.11.2.1 christos * DESCRIPTION: Get the current input file node
298 1.11.2.1 christos *
299 1.11.2.1 christos ******************************************************************************/
300 1.11.2.1 christos
301 1.11.2.1 christos ASL_GLOBAL_FILE_NODE *
302 1.11.2.1 christos FlGetCurrentFileNode (
303 1.11.2.1 christos void)
304 1.11.2.1 christos {
305 1.11.2.2 martin ASL_GLOBAL_FILE_NODE *FileNode =
306 1.11.2.2 martin FlGetFileNode (ASL_FILE_INPUT,AslGbl_Files[ASL_FILE_INPUT].Filename);
307 1.11.2.2 martin
308 1.11.2.2 martin
309 1.11.2.2 martin if (!FileNode)
310 1.11.2.2 martin {
311 1.11.2.2 martin /*
312 1.11.2.2 martin * If the current file node does not exist after initializing the file
313 1.11.2.2 martin * node structures, something went wrong and this is an unrecoverable
314 1.11.2.2 martin * condition.
315 1.11.2.2 martin */
316 1.11.2.2 martin FlFileError (ASL_FILE_INPUT, ASL_MSG_COMPILER_INTERNAL);
317 1.11.2.2 martin AslAbort ();
318 1.11.2.2 martin }
319 1.11.2.2 martin
320 1.11.2.2 martin return (FileNode);
321 1.11.2.1 christos }
322 1.11.2.1 christos
323 1.11.2.1 christos
324 1.11.2.1 christos /*******************************************************************************
325 1.11.2.1 christos *
326 1.2 christos * FUNCTION: FlSetLineNumber
327 1.1 jruoho *
328 1.2 christos * PARAMETERS: Op - Parse node for the LINE asl statement
329 1.1 jruoho *
330 1.2 christos * RETURN: None.
331 1.1 jruoho *
332 1.2 christos * DESCRIPTION: Set the current line number
333 1.1 jruoho *
334 1.1 jruoho ******************************************************************************/
335 1.1 jruoho
336 1.1 jruoho void
337 1.2 christos FlSetLineNumber (
338 1.2 christos UINT32 LineNumber)
339 1.1 jruoho {
340 1.1 jruoho
341 1.2 christos DbgPrint (ASL_PARSE_OUTPUT, "\n#line: New line number %u (old %u)\n",
342 1.11.2.1 christos LineNumber, AslGbl_LogicalLineNumber);
343 1.1 jruoho
344 1.11.2.1 christos AslGbl_CurrentLineNumber = LineNumber;
345 1.1 jruoho }
346 1.1 jruoho
347 1.1 jruoho
348 1.1 jruoho /*******************************************************************************
349 1.1 jruoho *
350 1.2 christos * FUNCTION: FlSetFilename
351 1.1 jruoho *
352 1.1 jruoho * PARAMETERS: Op - Parse node for the LINE asl statement
353 1.1 jruoho *
354 1.1 jruoho * RETURN: None.
355 1.1 jruoho *
356 1.2 christos * DESCRIPTION: Set the current filename
357 1.1 jruoho *
358 1.1 jruoho ******************************************************************************/
359 1.1 jruoho
360 1.1 jruoho void
361 1.2 christos FlSetFilename (
362 1.2 christos char *Filename)
363 1.1 jruoho {
364 1.1 jruoho
365 1.2 christos DbgPrint (ASL_PARSE_OUTPUT, "\n#line: New filename %s (old %s)\n",
366 1.11.2.1 christos Filename, AslGbl_Files[ASL_FILE_INPUT].Filename);
367 1.2 christos
368 1.3 christos /* No need to free any existing filename */
369 1.3 christos
370 1.11.2.1 christos AslGbl_Files[ASL_FILE_INPUT].Filename = Filename;
371 1.1 jruoho }
372 1.1 jruoho
373 1.1 jruoho
374 1.1 jruoho /*******************************************************************************
375 1.1 jruoho *
376 1.1 jruoho * FUNCTION: FlAddIncludeDirectory
377 1.1 jruoho *
378 1.1 jruoho * PARAMETERS: Dir - Directory pathname string
379 1.1 jruoho *
380 1.1 jruoho * RETURN: None
381 1.1 jruoho *
382 1.1 jruoho * DESCRIPTION: Add a directory the list of include prefix directories.
383 1.1 jruoho *
384 1.1 jruoho ******************************************************************************/
385 1.1 jruoho
386 1.1 jruoho void
387 1.1 jruoho FlAddIncludeDirectory (
388 1.1 jruoho char *Dir)
389 1.1 jruoho {
390 1.1 jruoho ASL_INCLUDE_DIR *NewDir;
391 1.1 jruoho ASL_INCLUDE_DIR *NextDir;
392 1.1 jruoho ASL_INCLUDE_DIR *PrevDir = NULL;
393 1.1 jruoho UINT32 NeedsSeparator = 0;
394 1.1 jruoho size_t DirLength;
395 1.1 jruoho
396 1.1 jruoho
397 1.1 jruoho DirLength = strlen (Dir);
398 1.1 jruoho if (!DirLength)
399 1.1 jruoho {
400 1.1 jruoho return;
401 1.1 jruoho }
402 1.1 jruoho
403 1.1 jruoho /* Make sure that the pathname ends with a path separator */
404 1.1 jruoho
405 1.1 jruoho if ((Dir[DirLength-1] != '/') &&
406 1.1 jruoho (Dir[DirLength-1] != '\\'))
407 1.1 jruoho {
408 1.1 jruoho NeedsSeparator = 1;
409 1.1 jruoho }
410 1.1 jruoho
411 1.11.2.1 christos NewDir = ACPI_CAST_PTR (ASL_INCLUDE_DIR,
412 1.11.2.1 christos UtLocalCacheCalloc (sizeof (ASL_INCLUDE_DIR)));
413 1.11.2.1 christos NewDir->Dir = UtLocalCacheCalloc (DirLength + 1 + NeedsSeparator);
414 1.1 jruoho strcpy (NewDir->Dir, Dir);
415 1.1 jruoho if (NeedsSeparator)
416 1.1 jruoho {
417 1.1 jruoho strcat (NewDir->Dir, "/");
418 1.1 jruoho }
419 1.1 jruoho
420 1.1 jruoho /*
421 1.1 jruoho * Preserve command line ordering of -I options by adding new elements
422 1.1 jruoho * at the end of the list
423 1.1 jruoho */
424 1.11.2.1 christos NextDir = AslGbl_IncludeDirList;
425 1.1 jruoho while (NextDir)
426 1.1 jruoho {
427 1.1 jruoho PrevDir = NextDir;
428 1.1 jruoho NextDir = NextDir->Next;
429 1.1 jruoho }
430 1.1 jruoho
431 1.1 jruoho if (PrevDir)
432 1.1 jruoho {
433 1.1 jruoho PrevDir->Next = NewDir;
434 1.1 jruoho }
435 1.1 jruoho else
436 1.1 jruoho {
437 1.11.2.1 christos AslGbl_IncludeDirList = NewDir;
438 1.1 jruoho }
439 1.1 jruoho }
440 1.1 jruoho
441 1.1 jruoho
442 1.1 jruoho /*******************************************************************************
443 1.1 jruoho *
444 1.2 christos * FUNCTION: FlMergePathnames
445 1.2 christos *
446 1.2 christos * PARAMETERS: PrefixDir - Prefix directory pathname. Can be NULL or
447 1.2 christos * a zero length string.
448 1.2 christos * FilePathname - The include filename from the source ASL.
449 1.2 christos *
450 1.2 christos * RETURN: Merged pathname string
451 1.2 christos *
452 1.2 christos * DESCRIPTION: Merge two pathnames that (probably) have common elements, to
453 1.2 christos * arrive at a minimal length string. Merge can occur if the
454 1.2 christos * FilePathname is relative to the PrefixDir.
455 1.2 christos *
456 1.2 christos ******************************************************************************/
457 1.2 christos
458 1.2 christos char *
459 1.2 christos FlMergePathnames (
460 1.2 christos char *PrefixDir,
461 1.2 christos char *FilePathname)
462 1.2 christos {
463 1.2 christos char *CommonPath;
464 1.2 christos char *Pathname;
465 1.2 christos char *LastElement;
466 1.2 christos
467 1.2 christos
468 1.2 christos DbgPrint (ASL_PARSE_OUTPUT, "Include: Prefix path - \"%s\"\n"
469 1.2 christos "Include: FilePathname - \"%s\"\n",
470 1.2 christos PrefixDir, FilePathname);
471 1.2 christos
472 1.2 christos /*
473 1.2 christos * If there is no prefix directory or if the file pathname is absolute,
474 1.2 christos * just return the original file pathname
475 1.2 christos */
476 1.2 christos if (!PrefixDir || (!*PrefixDir) ||
477 1.2 christos (*FilePathname == '/') ||
478 1.2 christos (FilePathname[1] == ':'))
479 1.2 christos {
480 1.10 christos Pathname = UtLocalCacheCalloc (strlen (FilePathname) + 1);
481 1.2 christos strcpy (Pathname, FilePathname);
482 1.2 christos goto ConvertBackslashes;
483 1.2 christos }
484 1.2 christos
485 1.2 christos /* Need a local copy of the prefix directory path */
486 1.2 christos
487 1.10 christos CommonPath = UtLocalCacheCalloc (strlen (PrefixDir) + 1);
488 1.2 christos strcpy (CommonPath, PrefixDir);
489 1.2 christos
490 1.2 christos /*
491 1.2 christos * Walk forward through the file path, and simultaneously backward
492 1.2 christos * through the prefix directory path until there are no more
493 1.2 christos * relative references at the start of the file path.
494 1.2 christos */
495 1.2 christos while (*FilePathname && (!strncmp (FilePathname, "../", 3)))
496 1.2 christos {
497 1.2 christos /* Remove last element of the prefix directory path */
498 1.2 christos
499 1.2 christos LastElement = strrchr (CommonPath, '/');
500 1.2 christos if (!LastElement)
501 1.2 christos {
502 1.2 christos goto ConcatenatePaths;
503 1.2 christos }
504 1.2 christos
505 1.2 christos *LastElement = 0; /* Terminate CommonPath string */
506 1.2 christos FilePathname += 3; /* Point to next path element */
507 1.2 christos }
508 1.2 christos
509 1.2 christos /*
510 1.2 christos * Remove the last element of the prefix directory path (it is the same as
511 1.2 christos * the first element of the file pathname), and build the final merged
512 1.2 christos * pathname.
513 1.2 christos */
514 1.2 christos LastElement = strrchr (CommonPath, '/');
515 1.2 christos if (LastElement)
516 1.2 christos {
517 1.2 christos *LastElement = 0;
518 1.2 christos }
519 1.2 christos
520 1.2 christos /* Build the final merged pathname */
521 1.2 christos
522 1.2 christos ConcatenatePaths:
523 1.10 christos Pathname = UtLocalCacheCalloc (
524 1.6 christos strlen (CommonPath) + strlen (FilePathname) + 2);
525 1.2 christos if (LastElement && *CommonPath)
526 1.2 christos {
527 1.2 christos strcpy (Pathname, CommonPath);
528 1.2 christos strcat (Pathname, "/");
529 1.2 christos }
530 1.2 christos strcat (Pathname, FilePathname);
531 1.2 christos
532 1.2 christos /* Convert all backslashes to normal slashes */
533 1.2 christos
534 1.2 christos ConvertBackslashes:
535 1.2 christos UtConvertBackslashes (Pathname);
536 1.2 christos
537 1.2 christos DbgPrint (ASL_PARSE_OUTPUT, "Include: Merged Pathname - \"%s\"\n",
538 1.2 christos Pathname);
539 1.2 christos return (Pathname);
540 1.2 christos }
541 1.2 christos
542 1.2 christos
543 1.2 christos /*******************************************************************************
544 1.2 christos *
545 1.1 jruoho * FUNCTION: FlOpenIncludeWithPrefix
546 1.1 jruoho *
547 1.1 jruoho * PARAMETERS: PrefixDir - Prefix directory pathname. Can be a zero
548 1.1 jruoho * length string.
549 1.1 jruoho * Filename - The include filename from the source ASL.
550 1.1 jruoho *
551 1.1 jruoho * RETURN: Valid file descriptor if successful. Null otherwise.
552 1.1 jruoho *
553 1.1 jruoho * DESCRIPTION: Open an include file and push it on the input file stack.
554 1.1 jruoho *
555 1.1 jruoho ******************************************************************************/
556 1.1 jruoho
557 1.5 christos static FILE *
558 1.1 jruoho FlOpenIncludeWithPrefix (
559 1.1 jruoho char *PrefixDir,
560 1.5 christos ACPI_PARSE_OBJECT *Op,
561 1.1 jruoho char *Filename)
562 1.1 jruoho {
563 1.1 jruoho FILE *IncludeFile;
564 1.1 jruoho char *Pathname;
565 1.5 christos UINT32 OriginalLineNumber;
566 1.1 jruoho
567 1.1 jruoho
568 1.1 jruoho /* Build the full pathname to the file */
569 1.1 jruoho
570 1.2 christos Pathname = FlMergePathnames (PrefixDir, Filename);
571 1.1 jruoho
572 1.2 christos DbgPrint (ASL_PARSE_OUTPUT, "Include: Opening file - \"%s\"\n\n",
573 1.1 jruoho Pathname);
574 1.1 jruoho
575 1.1 jruoho /* Attempt to open the file, push if successful */
576 1.1 jruoho
577 1.1 jruoho IncludeFile = fopen (Pathname, "r");
578 1.2 christos if (!IncludeFile)
579 1.1 jruoho {
580 1.2 christos return (NULL);
581 1.2 christos }
582 1.1 jruoho
583 1.5 christos /*
584 1.5 christos * Check the entire include file for any # preprocessor directives.
585 1.5 christos * This is because there may be some confusion between the #include
586 1.5 christos * preprocessor directive and the ASL Include statement. A file included
587 1.5 christos * by the ASL include cannot contain preprocessor directives because
588 1.5 christos * the preprocessor has already run by the time the ASL include is
589 1.5 christos * recognized (by the compiler, not the preprocessor.)
590 1.5 christos *
591 1.5 christos * Note: DtGetNextLine strips/ignores comments.
592 1.5 christos * Save current line number since DtGetNextLine modifies it.
593 1.5 christos */
594 1.11.2.1 christos AslGbl_CurrentLineNumber--;
595 1.11.2.1 christos OriginalLineNumber = AslGbl_CurrentLineNumber;
596 1.6 christos
597 1.5 christos while (DtGetNextLine (IncludeFile, DT_ALLOW_MULTILINE_QUOTES) != ASL_EOF)
598 1.5 christos {
599 1.11.2.1 christos if (AslGbl_CurrentLineBuffer[0] == '#')
600 1.5 christos {
601 1.5 christos AslError (ASL_ERROR, ASL_MSG_INCLUDE_FILE,
602 1.5 christos Op, "use #include instead");
603 1.5 christos }
604 1.5 christos }
605 1.6 christos
606 1.11.2.1 christos AslGbl_CurrentLineNumber = OriginalLineNumber;
607 1.5 christos
608 1.5 christos /* Must seek back to the start of the file */
609 1.5 christos
610 1.5 christos fseek (IncludeFile, 0, SEEK_SET);
611 1.5 christos
612 1.2 christos /* Push the include file on the open input file stack */
613 1.1 jruoho
614 1.2 christos AslPushInputFileStack (IncludeFile, Pathname);
615 1.2 christos return (IncludeFile);
616 1.1 jruoho }
617 1.1 jruoho
618 1.1 jruoho
619 1.1 jruoho /*******************************************************************************
620 1.1 jruoho *
621 1.1 jruoho * FUNCTION: FlOpenIncludeFile
622 1.1 jruoho *
623 1.1 jruoho * PARAMETERS: Op - Parse node for the INCLUDE ASL statement
624 1.1 jruoho *
625 1.1 jruoho * RETURN: None.
626 1.1 jruoho *
627 1.1 jruoho * DESCRIPTION: Open an include file and push it on the input file stack.
628 1.1 jruoho *
629 1.1 jruoho ******************************************************************************/
630 1.1 jruoho
631 1.1 jruoho void
632 1.1 jruoho FlOpenIncludeFile (
633 1.1 jruoho ACPI_PARSE_OBJECT *Op)
634 1.1 jruoho {
635 1.1 jruoho FILE *IncludeFile;
636 1.1 jruoho ASL_INCLUDE_DIR *NextDir;
637 1.1 jruoho
638 1.1 jruoho
639 1.1 jruoho /* Op must be valid */
640 1.1 jruoho
641 1.1 jruoho if (!Op)
642 1.1 jruoho {
643 1.1 jruoho AslCommonError (ASL_ERROR, ASL_MSG_INCLUDE_FILE_OPEN,
644 1.11.2.1 christos AslGbl_CurrentLineNumber, AslGbl_LogicalLineNumber,
645 1.11.2.1 christos AslGbl_InputByteCount, AslGbl_CurrentColumn,
646 1.11.2.1 christos AslGbl_Files[ASL_FILE_INPUT].Filename, " - Null parse node");
647 1.1 jruoho
648 1.1 jruoho return;
649 1.1 jruoho }
650 1.1 jruoho
651 1.1 jruoho /*
652 1.1 jruoho * Flush out the "include ()" statement on this line, start
653 1.1 jruoho * the actual include file on the next line
654 1.1 jruoho */
655 1.2 christos AslResetCurrentLineBuffer ();
656 1.1 jruoho FlPrintFile (ASL_FILE_SOURCE_OUTPUT, "\n");
657 1.11.2.1 christos AslGbl_CurrentLineOffset++;
658 1.1 jruoho
659 1.1 jruoho
660 1.1 jruoho /* Attempt to open the include file */
661 1.1 jruoho
662 1.1 jruoho /* If the file specifies an absolute path, just open it */
663 1.1 jruoho
664 1.1 jruoho if ((Op->Asl.Value.String[0] == '/') ||
665 1.1 jruoho (Op->Asl.Value.String[0] == '\\') ||
666 1.1 jruoho (Op->Asl.Value.String[1] == ':'))
667 1.1 jruoho {
668 1.5 christos IncludeFile = FlOpenIncludeWithPrefix ("", Op, Op->Asl.Value.String);
669 1.1 jruoho if (!IncludeFile)
670 1.1 jruoho {
671 1.1 jruoho goto ErrorExit;
672 1.1 jruoho }
673 1.1 jruoho return;
674 1.1 jruoho }
675 1.1 jruoho
676 1.1 jruoho /*
677 1.1 jruoho * The include filename is not an absolute path.
678 1.1 jruoho *
679 1.1 jruoho * First, search for the file within the "local" directory -- meaning
680 1.1 jruoho * the same directory that contains the source file.
681 1.1 jruoho *
682 1.1 jruoho * Construct the file pathname from the global directory name.
683 1.1 jruoho */
684 1.6 christos IncludeFile = FlOpenIncludeWithPrefix (
685 1.11.2.1 christos AslGbl_DirectoryPath, Op, Op->Asl.Value.String);
686 1.1 jruoho if (IncludeFile)
687 1.1 jruoho {
688 1.1 jruoho return;
689 1.1 jruoho }
690 1.1 jruoho
691 1.1 jruoho /*
692 1.1 jruoho * Second, search for the file within the (possibly multiple) directories
693 1.1 jruoho * specified by the -I option on the command line.
694 1.1 jruoho */
695 1.11.2.1 christos NextDir = AslGbl_IncludeDirList;
696 1.1 jruoho while (NextDir)
697 1.1 jruoho {
698 1.6 christos IncludeFile = FlOpenIncludeWithPrefix (
699 1.6 christos NextDir->Dir, Op, Op->Asl.Value.String);
700 1.1 jruoho if (IncludeFile)
701 1.1 jruoho {
702 1.1 jruoho return;
703 1.1 jruoho }
704 1.1 jruoho
705 1.1 jruoho NextDir = NextDir->Next;
706 1.1 jruoho }
707 1.1 jruoho
708 1.1 jruoho /* We could not open the include file after trying very hard */
709 1.1 jruoho
710 1.1 jruoho ErrorExit:
711 1.11.2.1 christos snprintf (AslGbl_MsgBuffer, sizeof(AslGbl_MsgBuffer), "%s, %s", Op->Asl.Value.String, strerror (errno));
712 1.11.2.1 christos AslError (ASL_ERROR, ASL_MSG_INCLUDE_FILE_OPEN, Op, AslGbl_MsgBuffer);
713 1.1 jruoho }
714 1.1 jruoho
715 1.1 jruoho
716 1.1 jruoho /*******************************************************************************
717 1.1 jruoho *
718 1.1 jruoho * FUNCTION: FlOpenInputFile
719 1.1 jruoho *
720 1.1 jruoho * PARAMETERS: InputFilename - The user-specified ASL source file to be
721 1.1 jruoho * compiled
722 1.1 jruoho *
723 1.1 jruoho * RETURN: Status
724 1.1 jruoho *
725 1.1 jruoho * DESCRIPTION: Open the specified input file, and save the directory path to
726 1.1 jruoho * the file so that include files can be opened in
727 1.1 jruoho * the same directory.
728 1.1 jruoho *
729 1.1 jruoho ******************************************************************************/
730 1.1 jruoho
731 1.1 jruoho ACPI_STATUS
732 1.1 jruoho FlOpenInputFile (
733 1.1 jruoho char *InputFilename)
734 1.1 jruoho {
735 1.1 jruoho
736 1.1 jruoho /* Open the input ASL file, text mode */
737 1.1 jruoho
738 1.2 christos FlOpenFile (ASL_FILE_INPUT, InputFilename, "rt");
739 1.11.2.1 christos AslCompilerin = AslGbl_Files[ASL_FILE_INPUT].Handle;
740 1.1 jruoho
741 1.1 jruoho return (AE_OK);
742 1.1 jruoho }
743 1.1 jruoho
744 1.1 jruoho
745 1.1 jruoho /*******************************************************************************
746 1.1 jruoho *
747 1.1 jruoho * FUNCTION: FlOpenAmlOutputFile
748 1.1 jruoho *
749 1.1 jruoho * PARAMETERS: FilenamePrefix - The user-specified ASL source file
750 1.1 jruoho *
751 1.1 jruoho * RETURN: Status
752 1.1 jruoho *
753 1.2 christos * DESCRIPTION: Create the output filename (*.AML) and open the file. The file
754 1.1 jruoho * is created in the same directory as the parent input file.
755 1.1 jruoho *
756 1.1 jruoho ******************************************************************************/
757 1.1 jruoho
758 1.1 jruoho ACPI_STATUS
759 1.1 jruoho FlOpenAmlOutputFile (
760 1.1 jruoho char *FilenamePrefix)
761 1.1 jruoho {
762 1.1 jruoho char *Filename;
763 1.1 jruoho
764 1.1 jruoho
765 1.1 jruoho /* Output filename usually comes from the ASL itself */
766 1.1 jruoho
767 1.11.2.1 christos Filename = AslGbl_Files[ASL_FILE_AML_OUTPUT].Filename;
768 1.1 jruoho if (!Filename)
769 1.1 jruoho {
770 1.1 jruoho /* Create the output AML filename */
771 1.11 christos if (!AcpiGbl_CaptureComments)
772 1.9 christos {
773 1.9 christos Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_AML_CODE);
774 1.9 christos }
775 1.9 christos else
776 1.9 christos {
777 1.9 christos Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_CONVERT_AML);
778 1.9 christos }
779 1.1 jruoho if (!Filename)
780 1.1 jruoho {
781 1.1 jruoho AslCommonError (ASL_ERROR, ASL_MSG_OUTPUT_FILENAME,
782 1.1 jruoho 0, 0, 0, 0, NULL, NULL);
783 1.1 jruoho return (AE_ERROR);
784 1.1 jruoho }
785 1.4 christos
786 1.11.2.1 christos AslGbl_Files[ASL_FILE_AML_OUTPUT].Filename = Filename;
787 1.1 jruoho }
788 1.1 jruoho
789 1.1 jruoho /* Open the output AML file in binary mode */
790 1.1 jruoho
791 1.1 jruoho FlOpenFile (ASL_FILE_AML_OUTPUT, Filename, "w+b");
792 1.1 jruoho return (AE_OK);
793 1.1 jruoho }
794 1.1 jruoho
795 1.1 jruoho
796 1.1 jruoho /*******************************************************************************
797 1.1 jruoho *
798 1.1 jruoho * FUNCTION: FlOpenMiscOutputFiles
799 1.1 jruoho *
800 1.1 jruoho * PARAMETERS: FilenamePrefix - The user-specified ASL source file
801 1.1 jruoho *
802 1.1 jruoho * RETURN: Status
803 1.1 jruoho *
804 1.1 jruoho * DESCRIPTION: Create and open the various output files needed, depending on
805 1.1 jruoho * the command line options
806 1.1 jruoho *
807 1.1 jruoho ******************************************************************************/
808 1.1 jruoho
809 1.1 jruoho ACPI_STATUS
810 1.1 jruoho FlOpenMiscOutputFiles (
811 1.1 jruoho char *FilenamePrefix)
812 1.1 jruoho {
813 1.1 jruoho char *Filename;
814 1.1 jruoho
815 1.1 jruoho
816 1.5 christos /* Create/Open a map file if requested */
817 1.5 christos
818 1.11.2.1 christos if (AslGbl_MapfileFlag)
819 1.5 christos {
820 1.5 christos Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_MAP);
821 1.5 christos if (!Filename)
822 1.5 christos {
823 1.5 christos AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
824 1.5 christos 0, 0, 0, 0, NULL, NULL);
825 1.5 christos return (AE_ERROR);
826 1.5 christos }
827 1.5 christos
828 1.5 christos /* Open the hex file, text mode (closed at compiler exit) */
829 1.5 christos
830 1.5 christos FlOpenFile (ASL_FILE_MAP_OUTPUT, Filename, "w+t");
831 1.5 christos
832 1.5 christos AslCompilerSignon (ASL_FILE_MAP_OUTPUT);
833 1.5 christos AslCompilerFileHeader (ASL_FILE_MAP_OUTPUT);
834 1.5 christos }
835 1.5 christos
836 1.2 christos /* All done for disassembler */
837 1.2 christos
838 1.11.2.1 christos if (AslGbl_FileType == ASL_INPUT_TYPE_BINARY_ACPI_TABLE)
839 1.2 christos {
840 1.2 christos return (AE_OK);
841 1.2 christos }
842 1.2 christos
843 1.2 christos /* Create/Open a hex output file if asked */
844 1.1 jruoho
845 1.11.2.1 christos if (AslGbl_HexOutputFlag)
846 1.1 jruoho {
847 1.2 christos Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_HEX_DUMP);
848 1.2 christos if (!Filename)
849 1.2 christos {
850 1.2 christos AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
851 1.2 christos 0, 0, 0, 0, NULL, NULL);
852 1.2 christos return (AE_ERROR);
853 1.2 christos }
854 1.2 christos
855 1.2 christos /* Open the hex file, text mode */
856 1.2 christos
857 1.2 christos FlOpenFile (ASL_FILE_HEX_OUTPUT, Filename, "w+t");
858 1.2 christos
859 1.2 christos AslCompilerSignon (ASL_FILE_HEX_OUTPUT);
860 1.2 christos AslCompilerFileHeader (ASL_FILE_HEX_OUTPUT);
861 1.1 jruoho }
862 1.1 jruoho
863 1.2 christos /* Create/Open a debug output file if asked */
864 1.2 christos
865 1.11.2.1 christos if (AslGbl_DebugFlag)
866 1.2 christos {
867 1.2 christos Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_DEBUG);
868 1.2 christos if (!Filename)
869 1.2 christos {
870 1.2 christos AslCommonError (ASL_ERROR, ASL_MSG_DEBUG_FILENAME,
871 1.2 christos 0, 0, 0, 0, NULL, NULL);
872 1.2 christos return (AE_ERROR);
873 1.2 christos }
874 1.2 christos
875 1.2 christos /* Open the debug file as STDERR, text mode */
876 1.2 christos
877 1.11.2.1 christos AslGbl_Files[ASL_FILE_DEBUG_OUTPUT].Filename = Filename;
878 1.11.2.1 christos AslGbl_Files[ASL_FILE_DEBUG_OUTPUT].Handle =
879 1.2 christos freopen (Filename, "w+t", stderr);
880 1.2 christos
881 1.11.2.1 christos if (!AslGbl_Files[ASL_FILE_DEBUG_OUTPUT].Handle)
882 1.2 christos {
883 1.4 christos /*
884 1.5 christos * A problem with freopen is that on error, we no longer
885 1.5 christos * have stderr and cannot emit normal error messages.
886 1.5 christos * Emit error to stdout, close files, and exit.
887 1.4 christos */
888 1.5 christos fprintf (stdout,
889 1.5 christos "\nCould not open debug output file: %s\n\n", Filename);
890 1.5 christos
891 1.5 christos CmCleanupAndExit ();
892 1.5 christos exit (1);
893 1.2 christos }
894 1.2 christos
895 1.2 christos AslCompilerSignon (ASL_FILE_DEBUG_OUTPUT);
896 1.2 christos AslCompilerFileHeader (ASL_FILE_DEBUG_OUTPUT);
897 1.2 christos }
898 1.1 jruoho
899 1.7 christos /* Create/Open a cross-reference output file if asked */
900 1.7 christos
901 1.11.2.1 christos if (AslGbl_CrossReferenceOutput)
902 1.7 christos {
903 1.7 christos Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_XREF);
904 1.7 christos if (!Filename)
905 1.7 christos {
906 1.7 christos AslCommonError (ASL_ERROR, ASL_MSG_DEBUG_FILENAME,
907 1.7 christos 0, 0, 0, 0, NULL, NULL);
908 1.7 christos return (AE_ERROR);
909 1.7 christos }
910 1.7 christos
911 1.7 christos FlOpenFile (ASL_FILE_XREF_OUTPUT, Filename, "w+t");
912 1.7 christos
913 1.7 christos AslCompilerSignon (ASL_FILE_XREF_OUTPUT);
914 1.7 christos AslCompilerFileHeader (ASL_FILE_XREF_OUTPUT);
915 1.7 christos }
916 1.7 christos
917 1.1 jruoho /* Create/Open a listing output file if asked */
918 1.1 jruoho
919 1.11.2.1 christos if (AslGbl_ListingFlag)
920 1.1 jruoho {
921 1.1 jruoho Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_LISTING);
922 1.1 jruoho if (!Filename)
923 1.1 jruoho {
924 1.1 jruoho AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
925 1.1 jruoho 0, 0, 0, 0, NULL, NULL);
926 1.1 jruoho return (AE_ERROR);
927 1.1 jruoho }
928 1.1 jruoho
929 1.1 jruoho /* Open the listing file, text mode */
930 1.1 jruoho
931 1.2 christos FlOpenFile (ASL_FILE_LISTING_OUTPUT, Filename, "w+t");
932 1.1 jruoho
933 1.1 jruoho AslCompilerSignon (ASL_FILE_LISTING_OUTPUT);
934 1.1 jruoho AslCompilerFileHeader (ASL_FILE_LISTING_OUTPUT);
935 1.1 jruoho }
936 1.1 jruoho
937 1.5 christos /* Create the preprocessor output temp file if preprocessor enabled */
938 1.2 christos
939 1.11.2.1 christos if (AslGbl_PreprocessFlag)
940 1.2 christos {
941 1.2 christos Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_PREPROCESSOR);
942 1.2 christos if (!Filename)
943 1.2 christos {
944 1.2 christos AslCommonError (ASL_ERROR, ASL_MSG_PREPROCESSOR_FILENAME,
945 1.2 christos 0, 0, 0, 0, NULL, NULL);
946 1.2 christos return (AE_ERROR);
947 1.2 christos }
948 1.2 christos
949 1.2 christos FlOpenFile (ASL_FILE_PREPROCESSOR, Filename, "w+t");
950 1.2 christos }
951 1.2 christos
952 1.5 christos /*
953 1.5 christos * Create the "user" preprocessor output file if -li flag set.
954 1.5 christos * Note, this file contains no embedded #line directives.
955 1.5 christos */
956 1.11.2.1 christos if (AslGbl_PreprocessorOutputFlag)
957 1.5 christos {
958 1.5 christos Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_PREPROC_USER);
959 1.5 christos if (!Filename)
960 1.5 christos {
961 1.5 christos AslCommonError (ASL_ERROR, ASL_MSG_PREPROCESSOR_FILENAME,
962 1.5 christos 0, 0, 0, 0, NULL, NULL);
963 1.5 christos return (AE_ERROR);
964 1.5 christos }
965 1.5 christos
966 1.5 christos FlOpenFile (ASL_FILE_PREPROCESSOR_USER, Filename, "w+t");
967 1.5 christos }
968 1.5 christos
969 1.2 christos /* All done for data table compiler */
970 1.2 christos
971 1.11.2.1 christos if (AslGbl_FileType == ASL_INPUT_TYPE_ASCII_DATA)
972 1.2 christos {
973 1.2 christos return (AE_OK);
974 1.2 christos }
975 1.2 christos
976 1.2 christos /* Create/Open a combined source output file */
977 1.2 christos
978 1.2 christos Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_SOURCE);
979 1.2 christos if (!Filename)
980 1.2 christos {
981 1.2 christos AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
982 1.2 christos 0, 0, 0, 0, NULL, NULL);
983 1.2 christos return (AE_ERROR);
984 1.2 christos }
985 1.2 christos
986 1.2 christos /*
987 1.2 christos * Open the source output file, binary mode (so that LF does not get
988 1.2 christos * expanded to CR/LF on some systems, messing up our seek
989 1.2 christos * calculations.)
990 1.2 christos */
991 1.2 christos FlOpenFile (ASL_FILE_SOURCE_OUTPUT, Filename, "w+b");
992 1.2 christos
993 1.2 christos /*
994 1.2 christos // TBD: TEMP
995 1.11.2.1 christos // AslCompilerin = AslGbl_Files[ASL_FILE_SOURCE_OUTPUT].Handle;
996 1.2 christos */
997 1.1 jruoho /* Create/Open a assembly code source output file if asked */
998 1.1 jruoho
999 1.11.2.1 christos if (AslGbl_AsmOutputFlag)
1000 1.1 jruoho {
1001 1.1 jruoho Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_ASM_SOURCE);
1002 1.1 jruoho if (!Filename)
1003 1.1 jruoho {
1004 1.1 jruoho AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
1005 1.1 jruoho 0, 0, 0, 0, NULL, NULL);
1006 1.1 jruoho return (AE_ERROR);
1007 1.1 jruoho }
1008 1.1 jruoho
1009 1.1 jruoho /* Open the assembly code source file, text mode */
1010 1.1 jruoho
1011 1.2 christos FlOpenFile (ASL_FILE_ASM_SOURCE_OUTPUT, Filename, "w+t");
1012 1.1 jruoho
1013 1.1 jruoho AslCompilerSignon (ASL_FILE_ASM_SOURCE_OUTPUT);
1014 1.1 jruoho AslCompilerFileHeader (ASL_FILE_ASM_SOURCE_OUTPUT);
1015 1.1 jruoho }
1016 1.1 jruoho
1017 1.1 jruoho /* Create/Open a C code source output file if asked */
1018 1.1 jruoho
1019 1.11.2.1 christos if (AslGbl_C_OutputFlag)
1020 1.1 jruoho {
1021 1.1 jruoho Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_C_SOURCE);
1022 1.1 jruoho if (!Filename)
1023 1.1 jruoho {
1024 1.1 jruoho AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
1025 1.1 jruoho 0, 0, 0, 0, NULL, NULL);
1026 1.1 jruoho return (AE_ERROR);
1027 1.1 jruoho }
1028 1.1 jruoho
1029 1.1 jruoho /* Open the C code source file, text mode */
1030 1.1 jruoho
1031 1.2 christos FlOpenFile (ASL_FILE_C_SOURCE_OUTPUT, Filename, "w+t");
1032 1.1 jruoho
1033 1.1 jruoho FlPrintFile (ASL_FILE_C_SOURCE_OUTPUT, "/*\n");
1034 1.1 jruoho AslCompilerSignon (ASL_FILE_C_SOURCE_OUTPUT);
1035 1.1 jruoho AslCompilerFileHeader (ASL_FILE_C_SOURCE_OUTPUT);
1036 1.1 jruoho }
1037 1.1 jruoho
1038 1.2 christos /* Create/Open a C code source output file for the offset table if asked */
1039 1.2 christos
1040 1.11.2.1 christos if (AslGbl_C_OffsetTableFlag)
1041 1.2 christos {
1042 1.2 christos Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_C_OFFSET);
1043 1.2 christos if (!Filename)
1044 1.2 christos {
1045 1.2 christos AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
1046 1.2 christos 0, 0, 0, 0, NULL, NULL);
1047 1.2 christos return (AE_ERROR);
1048 1.2 christos }
1049 1.2 christos
1050 1.2 christos /* Open the C code source file, text mode */
1051 1.2 christos
1052 1.2 christos FlOpenFile (ASL_FILE_C_OFFSET_OUTPUT, Filename, "w+t");
1053 1.2 christos
1054 1.2 christos FlPrintFile (ASL_FILE_C_OFFSET_OUTPUT, "/*\n");
1055 1.2 christos AslCompilerSignon (ASL_FILE_C_OFFSET_OUTPUT);
1056 1.2 christos AslCompilerFileHeader (ASL_FILE_C_OFFSET_OUTPUT);
1057 1.2 christos }
1058 1.2 christos
1059 1.1 jruoho /* Create/Open a assembly include output file if asked */
1060 1.1 jruoho
1061 1.11.2.1 christos if (AslGbl_AsmIncludeOutputFlag)
1062 1.1 jruoho {
1063 1.1 jruoho Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_ASM_INCLUDE);
1064 1.1 jruoho if (!Filename)
1065 1.1 jruoho {
1066 1.1 jruoho AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
1067 1.1 jruoho 0, 0, 0, 0, NULL, NULL);
1068 1.1 jruoho return (AE_ERROR);
1069 1.1 jruoho }
1070 1.1 jruoho
1071 1.1 jruoho /* Open the assembly include file, text mode */
1072 1.1 jruoho
1073 1.2 christos FlOpenFile (ASL_FILE_ASM_INCLUDE_OUTPUT, Filename, "w+t");
1074 1.1 jruoho
1075 1.1 jruoho AslCompilerSignon (ASL_FILE_ASM_INCLUDE_OUTPUT);
1076 1.1 jruoho AslCompilerFileHeader (ASL_FILE_ASM_INCLUDE_OUTPUT);
1077 1.1 jruoho }
1078 1.1 jruoho
1079 1.1 jruoho /* Create/Open a C include output file if asked */
1080 1.1 jruoho
1081 1.11.2.1 christos if (AslGbl_C_IncludeOutputFlag)
1082 1.1 jruoho {
1083 1.1 jruoho Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_C_INCLUDE);
1084 1.1 jruoho if (!Filename)
1085 1.1 jruoho {
1086 1.1 jruoho AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
1087 1.1 jruoho 0, 0, 0, 0, NULL, NULL);
1088 1.1 jruoho return (AE_ERROR);
1089 1.1 jruoho }
1090 1.1 jruoho
1091 1.1 jruoho /* Open the C include file, text mode */
1092 1.1 jruoho
1093 1.2 christos FlOpenFile (ASL_FILE_C_INCLUDE_OUTPUT, Filename, "w+t");
1094 1.1 jruoho
1095 1.1 jruoho FlPrintFile (ASL_FILE_C_INCLUDE_OUTPUT, "/*\n");
1096 1.1 jruoho AslCompilerSignon (ASL_FILE_C_INCLUDE_OUTPUT);
1097 1.1 jruoho AslCompilerFileHeader (ASL_FILE_C_INCLUDE_OUTPUT);
1098 1.1 jruoho }
1099 1.1 jruoho
1100 1.1 jruoho /* Create a namespace output file if asked */
1101 1.1 jruoho
1102 1.11.2.1 christos if (AslGbl_NsOutputFlag)
1103 1.1 jruoho {
1104 1.1 jruoho Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_NAMESPACE);
1105 1.1 jruoho if (!Filename)
1106 1.1 jruoho {
1107 1.1 jruoho AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
1108 1.1 jruoho 0, 0, 0, 0, NULL, NULL);
1109 1.1 jruoho return (AE_ERROR);
1110 1.1 jruoho }
1111 1.1 jruoho
1112 1.1 jruoho /* Open the namespace file, text mode */
1113 1.1 jruoho
1114 1.2 christos FlOpenFile (ASL_FILE_NAMESPACE_OUTPUT, Filename, "w+t");
1115 1.1 jruoho
1116 1.1 jruoho AslCompilerSignon (ASL_FILE_NAMESPACE_OUTPUT);
1117 1.1 jruoho AslCompilerFileHeader (ASL_FILE_NAMESPACE_OUTPUT);
1118 1.1 jruoho }
1119 1.1 jruoho
1120 1.9 christos /* Create a debug file for the converter */
1121 1.9 christos
1122 1.9 christos if (AcpiGbl_DebugAslConversion)
1123 1.9 christos {
1124 1.9 christos Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_CONVERT_DEBUG);
1125 1.9 christos if (!Filename)
1126 1.9 christos {
1127 1.9 christos AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME,
1128 1.9 christos 0, 0, 0, 0, NULL, NULL);
1129 1.9 christos return (AE_ERROR);
1130 1.9 christos }
1131 1.9 christos
1132 1.9 christos /* Open the converter debug file, text mode */
1133 1.9 christos
1134 1.9 christos FlOpenFile (ASL_FILE_CONV_DEBUG_OUTPUT, Filename, "w+t");
1135 1.9 christos
1136 1.9 christos AslCompilerSignon (ASL_FILE_CONV_DEBUG_OUTPUT);
1137 1.9 christos AslCompilerFileHeader (ASL_FILE_CONV_DEBUG_OUTPUT);
1138 1.9 christos
1139 1.11.2.1 christos AcpiGbl_ConvDebugFile = AslGbl_Files[ASL_FILE_CONV_DEBUG_OUTPUT].Handle;
1140 1.9 christos }
1141 1.9 christos
1142 1.1 jruoho return (AE_OK);
1143 1.1 jruoho }
1144 1.1 jruoho
1145 1.1 jruoho
1146 1.1 jruoho #ifdef ACPI_OBSOLETE_FUNCTIONS
1147 1.1 jruoho /*******************************************************************************
1148 1.1 jruoho *
1149 1.1 jruoho * FUNCTION: FlParseInputPathname
1150 1.1 jruoho *
1151 1.1 jruoho * PARAMETERS: InputFilename - The user-specified ASL source file to be
1152 1.1 jruoho * compiled
1153 1.1 jruoho *
1154 1.1 jruoho * RETURN: Status
1155 1.1 jruoho *
1156 1.1 jruoho * DESCRIPTION: Split the input path into a directory and filename part
1157 1.1 jruoho * 1) Directory part used to open include files
1158 1.1 jruoho * 2) Filename part used to generate output filenames
1159 1.1 jruoho *
1160 1.1 jruoho ******************************************************************************/
1161 1.1 jruoho
1162 1.1 jruoho ACPI_STATUS
1163 1.1 jruoho FlParseInputPathname (
1164 1.1 jruoho char *InputFilename)
1165 1.1 jruoho {
1166 1.1 jruoho char *Substring;
1167 1.1 jruoho
1168 1.1 jruoho
1169 1.1 jruoho if (!InputFilename)
1170 1.1 jruoho {
1171 1.1 jruoho return (AE_OK);
1172 1.1 jruoho }
1173 1.1 jruoho
1174 1.1 jruoho /* Get the path to the input filename's directory */
1175 1.1 jruoho
1176 1.11.2.1 christos AslGbl_DirectoryPath = strdup (InputFilename);
1177 1.11.2.1 christos if (!AslGbl_DirectoryPath)
1178 1.1 jruoho {
1179 1.1 jruoho return (AE_NO_MEMORY);
1180 1.1 jruoho }
1181 1.1 jruoho
1182 1.11.2.1 christos Substring = strrchr (AslGbl_DirectoryPath, '\\');
1183 1.1 jruoho if (!Substring)
1184 1.1 jruoho {
1185 1.11.2.1 christos Substring = strrchr (AslGbl_DirectoryPath, '/');
1186 1.1 jruoho if (!Substring)
1187 1.1 jruoho {
1188 1.11.2.1 christos Substring = strrchr (AslGbl_DirectoryPath, ':');
1189 1.1 jruoho }
1190 1.1 jruoho }
1191 1.1 jruoho
1192 1.1 jruoho if (!Substring)
1193 1.1 jruoho {
1194 1.11.2.1 christos AslGbl_DirectoryPath[0] = 0;
1195 1.11.2.1 christos if (AslGbl_UseDefaultAmlFilename)
1196 1.1 jruoho {
1197 1.11.2.1 christos AslGbl_OutputFilenamePrefix = strdup (InputFilename);
1198 1.1 jruoho }
1199 1.1 jruoho }
1200 1.1 jruoho else
1201 1.1 jruoho {
1202 1.11.2.1 christos if (AslGbl_UseDefaultAmlFilename)
1203 1.1 jruoho {
1204 1.11.2.1 christos AslGbl_OutputFilenamePrefix = strdup (Substring + 1);
1205 1.1 jruoho }
1206 1.1 jruoho *(Substring+1) = 0;
1207 1.1 jruoho }
1208 1.1 jruoho
1209 1.11.2.1 christos UtConvertBackslashes (AslGbl_OutputFilenamePrefix);
1210 1.1 jruoho return (AE_OK);
1211 1.1 jruoho }
1212 1.1 jruoho #endif
1213