11a39cfb0SJung-uk Kim /******************************************************************************
21a39cfb0SJung-uk Kim *
31a39cfb0SJung-uk Kim * Module Name: adfile - Application-level disassembler file support routines
41a39cfb0SJung-uk Kim *
51a39cfb0SJung-uk Kim *****************************************************************************/
61a39cfb0SJung-uk Kim
70d84335fSJung-uk Kim /******************************************************************************
80d84335fSJung-uk Kim *
90d84335fSJung-uk Kim * 1. Copyright Notice
100d84335fSJung-uk Kim *
11*804fe266SJung-uk Kim * Some or all of this work - Copyright (c) 1999 - 2024, Intel Corp.
121a39cfb0SJung-uk Kim * All rights reserved.
131a39cfb0SJung-uk Kim *
140d84335fSJung-uk Kim * 2. License
150d84335fSJung-uk Kim *
160d84335fSJung-uk Kim * 2.1. This is your license from Intel Corp. under its intellectual property
170d84335fSJung-uk Kim * rights. You may have additional license terms from the party that provided
180d84335fSJung-uk Kim * you this software, covering your right to use that party's intellectual
190d84335fSJung-uk Kim * property rights.
200d84335fSJung-uk Kim *
210d84335fSJung-uk Kim * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
220d84335fSJung-uk Kim * copy of the source code appearing in this file ("Covered Code") an
230d84335fSJung-uk Kim * irrevocable, perpetual, worldwide license under Intel's copyrights in the
240d84335fSJung-uk Kim * base code distributed originally by Intel ("Original Intel Code") to copy,
250d84335fSJung-uk Kim * make derivatives, distribute, use and display any portion of the Covered
260d84335fSJung-uk Kim * Code in any form, with the right to sublicense such rights; and
270d84335fSJung-uk Kim *
280d84335fSJung-uk Kim * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
290d84335fSJung-uk Kim * license (with the right to sublicense), under only those claims of Intel
300d84335fSJung-uk Kim * patents that are infringed by the Original Intel Code, to make, use, sell,
310d84335fSJung-uk Kim * offer to sell, and import the Covered Code and derivative works thereof
320d84335fSJung-uk Kim * solely to the minimum extent necessary to exercise the above copyright
330d84335fSJung-uk Kim * license, and in no event shall the patent license extend to any additions
340d84335fSJung-uk Kim * to or modifications of the Original Intel Code. No other license or right
350d84335fSJung-uk Kim * is granted directly or by implication, estoppel or otherwise;
360d84335fSJung-uk Kim *
370d84335fSJung-uk Kim * The above copyright and patent license is granted only if the following
380d84335fSJung-uk Kim * conditions are met:
390d84335fSJung-uk Kim *
400d84335fSJung-uk Kim * 3. Conditions
410d84335fSJung-uk Kim *
420d84335fSJung-uk Kim * 3.1. Redistribution of Source with Rights to Further Distribute Source.
430d84335fSJung-uk Kim * Redistribution of source code of any substantial portion of the Covered
440d84335fSJung-uk Kim * Code or modification with rights to further distribute source must include
450d84335fSJung-uk Kim * the above Copyright Notice, the above License, this list of Conditions,
460d84335fSJung-uk Kim * and the following Disclaimer and Export Compliance provision. In addition,
470d84335fSJung-uk Kim * Licensee must cause all Covered Code to which Licensee contributes to
480d84335fSJung-uk Kim * contain a file documenting the changes Licensee made to create that Covered
490d84335fSJung-uk Kim * Code and the date of any change. Licensee must include in that file the
500d84335fSJung-uk Kim * documentation of any changes made by any predecessor Licensee. Licensee
510d84335fSJung-uk Kim * must include a prominent statement that the modification is derived,
520d84335fSJung-uk Kim * directly or indirectly, from Original Intel Code.
530d84335fSJung-uk Kim *
540d84335fSJung-uk Kim * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
550d84335fSJung-uk Kim * Redistribution of source code of any substantial portion of the Covered
560d84335fSJung-uk Kim * Code or modification without rights to further distribute source must
570d84335fSJung-uk Kim * include the following Disclaimer and Export Compliance provision in the
580d84335fSJung-uk Kim * documentation and/or other materials provided with distribution. In
590d84335fSJung-uk Kim * addition, Licensee may not authorize further sublicense of source of any
600d84335fSJung-uk Kim * portion of the Covered Code, and must include terms to the effect that the
610d84335fSJung-uk Kim * license from Licensee to its licensee is limited to the intellectual
620d84335fSJung-uk Kim * property embodied in the software Licensee provides to its licensee, and
630d84335fSJung-uk Kim * not to intellectual property embodied in modifications its licensee may
640d84335fSJung-uk Kim * make.
650d84335fSJung-uk Kim *
660d84335fSJung-uk Kim * 3.3. Redistribution of Executable. Redistribution in executable form of any
670d84335fSJung-uk Kim * substantial portion of the Covered Code or modification must reproduce the
680d84335fSJung-uk Kim * above Copyright Notice, and the following Disclaimer and Export Compliance
690d84335fSJung-uk Kim * provision in the documentation and/or other materials provided with the
700d84335fSJung-uk Kim * distribution.
710d84335fSJung-uk Kim *
720d84335fSJung-uk Kim * 3.4. Intel retains all right, title, and interest in and to the Original
730d84335fSJung-uk Kim * Intel Code.
740d84335fSJung-uk Kim *
750d84335fSJung-uk Kim * 3.5. Neither the name Intel nor any other trademark owned or controlled by
760d84335fSJung-uk Kim * Intel shall be used in advertising or otherwise to promote the sale, use or
770d84335fSJung-uk Kim * other dealings in products derived from or relating to the Covered Code
780d84335fSJung-uk Kim * without prior written authorization from Intel.
790d84335fSJung-uk Kim *
800d84335fSJung-uk Kim * 4. Disclaimer and Export Compliance
810d84335fSJung-uk Kim *
820d84335fSJung-uk Kim * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
830d84335fSJung-uk Kim * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
840d84335fSJung-uk Kim * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
850d84335fSJung-uk Kim * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
860d84335fSJung-uk Kim * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
870d84335fSJung-uk Kim * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
880d84335fSJung-uk Kim * PARTICULAR PURPOSE.
890d84335fSJung-uk Kim *
900d84335fSJung-uk Kim * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
910d84335fSJung-uk Kim * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
920d84335fSJung-uk Kim * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
930d84335fSJung-uk Kim * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
940d84335fSJung-uk Kim * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
950d84335fSJung-uk Kim * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
960d84335fSJung-uk Kim * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
970d84335fSJung-uk Kim * LIMITED REMEDY.
980d84335fSJung-uk Kim *
990d84335fSJung-uk Kim * 4.3. Licensee shall not export, either directly or indirectly, any of this
1000d84335fSJung-uk Kim * software or system incorporating such software without first obtaining any
1010d84335fSJung-uk Kim * required license or other approval from the U. S. Department of Commerce or
1020d84335fSJung-uk Kim * any other agency or department of the United States Government. In the
1030d84335fSJung-uk Kim * event Licensee exports any such software from the United States or
1040d84335fSJung-uk Kim * re-exports any such software from a foreign destination, Licensee shall
1050d84335fSJung-uk Kim * ensure that the distribution and export/re-export of the software is in
1060d84335fSJung-uk Kim * compliance with all laws, regulations, orders, or other restrictions of the
1070d84335fSJung-uk Kim * U.S. Export Administration Regulations. Licensee agrees that neither it nor
1080d84335fSJung-uk Kim * any of its subsidiaries will export/re-export any technical data, process,
1090d84335fSJung-uk Kim * software, or service, directly or indirectly, to any country for which the
1100d84335fSJung-uk Kim * United States government or any agency thereof requires an export license,
1110d84335fSJung-uk Kim * other governmental approval, or letter of assurance, without first obtaining
1120d84335fSJung-uk Kim * such license, approval or letter.
1130d84335fSJung-uk Kim *
1140d84335fSJung-uk Kim *****************************************************************************
1150d84335fSJung-uk Kim *
1160d84335fSJung-uk Kim * Alternatively, you may choose to be licensed under the terms of the
1170d84335fSJung-uk Kim * following license:
1180d84335fSJung-uk Kim *
119d244b227SJung-uk Kim * Redistribution and use in source and binary forms, with or without
120d244b227SJung-uk Kim * modification, are permitted provided that the following conditions
121d244b227SJung-uk Kim * are met:
122d244b227SJung-uk Kim * 1. Redistributions of source code must retain the above copyright
123d244b227SJung-uk Kim * notice, this list of conditions, and the following disclaimer,
124d244b227SJung-uk Kim * without modification.
125d244b227SJung-uk Kim * 2. Redistributions in binary form must reproduce at minimum a disclaimer
126d244b227SJung-uk Kim * substantially similar to the "NO WARRANTY" disclaimer below
127d244b227SJung-uk Kim * ("Disclaimer") and any redistribution must be conditioned upon
128d244b227SJung-uk Kim * including a substantially similar Disclaimer requirement for further
129d244b227SJung-uk Kim * binary redistribution.
130d244b227SJung-uk Kim * 3. Neither the names of the above-listed copyright holders nor the names
131d244b227SJung-uk Kim * of any contributors may be used to endorse or promote products derived
132d244b227SJung-uk Kim * from this software without specific prior written permission.
1331a39cfb0SJung-uk Kim *
1340d84335fSJung-uk Kim * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1350d84335fSJung-uk Kim * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1360d84335fSJung-uk Kim * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1370d84335fSJung-uk Kim * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
1380d84335fSJung-uk Kim * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
1390d84335fSJung-uk Kim * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
1400d84335fSJung-uk Kim * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
1410d84335fSJung-uk Kim * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
1420d84335fSJung-uk Kim * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
1430d84335fSJung-uk Kim * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
1440d84335fSJung-uk Kim * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1450d84335fSJung-uk Kim *
1460d84335fSJung-uk Kim * Alternatively, you may choose to be licensed under the terms of the
147d244b227SJung-uk Kim * GNU General Public License ("GPL") version 2 as published by the Free
148d244b227SJung-uk Kim * Software Foundation.
1491a39cfb0SJung-uk Kim *
1500d84335fSJung-uk Kim *****************************************************************************/
1511a39cfb0SJung-uk Kim
152313a0c13SJung-uk Kim #include <contrib/dev/acpica/compiler/aslcompiler.h>
153ab6f3bf9SJung-uk Kim #include <contrib/dev/acpica/include/acpi.h>
154ab6f3bf9SJung-uk Kim #include <contrib/dev/acpica/include/accommon.h>
155ab6f3bf9SJung-uk Kim #include <contrib/dev/acpica/include/acapps.h>
1561a39cfb0SJung-uk Kim
1571a39cfb0SJung-uk Kim #include <stdio.h>
1581a39cfb0SJung-uk Kim
1591a39cfb0SJung-uk Kim
1601a39cfb0SJung-uk Kim #define _COMPONENT ACPI_TOOLS
1611a39cfb0SJung-uk Kim ACPI_MODULE_NAME ("adfile")
1621a39cfb0SJung-uk Kim
163a9f12690SJung-uk Kim /* Local prototypes */
164a9f12690SJung-uk Kim
16542fecd12SJung-uk Kim static INT32
166a9f12690SJung-uk Kim AdWriteBuffer (
167a9f12690SJung-uk Kim char *Filename,
168a9f12690SJung-uk Kim char *Buffer,
169a9f12690SJung-uk Kim UINT32 Length);
1701a39cfb0SJung-uk Kim
17142fecd12SJung-uk Kim static char FilenameBuf[20];
1721a39cfb0SJung-uk Kim
173f556842eSJung-uk Kim
1741a39cfb0SJung-uk Kim /******************************************************************************
1751a39cfb0SJung-uk Kim *
1761a39cfb0SJung-uk Kim * FUNCTION: AfGenerateFilename
1771a39cfb0SJung-uk Kim *
1781a39cfb0SJung-uk Kim * PARAMETERS: Prefix - prefix string
1791a39cfb0SJung-uk Kim * TableId - The table ID
1801a39cfb0SJung-uk Kim *
1811a39cfb0SJung-uk Kim * RETURN: Pointer to the completed string
1821a39cfb0SJung-uk Kim *
1831a39cfb0SJung-uk Kim * DESCRIPTION: Build an output filename from an ACPI table ID string
1841a39cfb0SJung-uk Kim *
1851a39cfb0SJung-uk Kim ******************************************************************************/
1861a39cfb0SJung-uk Kim
1871a39cfb0SJung-uk Kim char *
AdGenerateFilename(char * Prefix,char * TableId)1881a39cfb0SJung-uk Kim AdGenerateFilename (
1891a39cfb0SJung-uk Kim char *Prefix,
1901a39cfb0SJung-uk Kim char *TableId)
1911a39cfb0SJung-uk Kim {
192a9f12690SJung-uk Kim UINT32 i;
193a9f12690SJung-uk Kim UINT32 j;
1941a39cfb0SJung-uk Kim
1951a39cfb0SJung-uk Kim
1961a39cfb0SJung-uk Kim for (i = 0; Prefix[i]; i++)
1971a39cfb0SJung-uk Kim {
1981a39cfb0SJung-uk Kim FilenameBuf[i] = Prefix[i];
1991a39cfb0SJung-uk Kim }
2001a39cfb0SJung-uk Kim
2011a39cfb0SJung-uk Kim FilenameBuf[i] = '_';
2021a39cfb0SJung-uk Kim i++;
2031a39cfb0SJung-uk Kim
2041a39cfb0SJung-uk Kim for (j = 0; j < 8 && (TableId[j] != ' ') && (TableId[j] != 0); i++, j++)
2051a39cfb0SJung-uk Kim {
2061a39cfb0SJung-uk Kim FilenameBuf[i] = TableId[j];
2071a39cfb0SJung-uk Kim }
2081a39cfb0SJung-uk Kim
2091a39cfb0SJung-uk Kim FilenameBuf[i] = 0;
210f8146b88SJung-uk Kim strcat (FilenameBuf, FILE_SUFFIX_BINARY_TABLE);
2118ef1a331SJung-uk Kim return (FilenameBuf);
2121a39cfb0SJung-uk Kim }
2131a39cfb0SJung-uk Kim
2141a39cfb0SJung-uk Kim
2151a39cfb0SJung-uk Kim /******************************************************************************
2161a39cfb0SJung-uk Kim *
2171a39cfb0SJung-uk Kim * FUNCTION: AfWriteBuffer
2181a39cfb0SJung-uk Kim *
2191a39cfb0SJung-uk Kim * PARAMETERS: Filename - name of file
2201a39cfb0SJung-uk Kim * Buffer - data to write
2211a39cfb0SJung-uk Kim * Length - length of data
2221a39cfb0SJung-uk Kim *
2231a39cfb0SJung-uk Kim * RETURN: Actual number of bytes written
2241a39cfb0SJung-uk Kim *
2251a39cfb0SJung-uk Kim * DESCRIPTION: Open a file and write out a single buffer
2261a39cfb0SJung-uk Kim *
2271a39cfb0SJung-uk Kim ******************************************************************************/
2281a39cfb0SJung-uk Kim
22942fecd12SJung-uk Kim static INT32
AdWriteBuffer(char * Filename,char * Buffer,UINT32 Length)2301a39cfb0SJung-uk Kim AdWriteBuffer (
2311a39cfb0SJung-uk Kim char *Filename,
2321a39cfb0SJung-uk Kim char *Buffer,
2331a39cfb0SJung-uk Kim UINT32 Length)
2341a39cfb0SJung-uk Kim {
235ed17e06eSJung-uk Kim FILE *File;
2361a39cfb0SJung-uk Kim ACPI_SIZE Actual;
2371a39cfb0SJung-uk Kim
2381a39cfb0SJung-uk Kim
239ed17e06eSJung-uk Kim File = fopen (Filename, "wb");
240ed17e06eSJung-uk Kim if (!File)
2411a39cfb0SJung-uk Kim {
242ed17e06eSJung-uk Kim printf ("Could not open file %s\n", Filename);
2431a39cfb0SJung-uk Kim return (-1);
2441a39cfb0SJung-uk Kim }
2451a39cfb0SJung-uk Kim
246ed17e06eSJung-uk Kim Actual = fwrite (Buffer, 1, (size_t) Length, File);
247ed17e06eSJung-uk Kim if (Actual != Length)
248ed17e06eSJung-uk Kim {
249ed17e06eSJung-uk Kim printf ("Could not write to file %s\n", Filename);
250ed17e06eSJung-uk Kim }
251ed17e06eSJung-uk Kim
252ed17e06eSJung-uk Kim fclose (File);
253a9f12690SJung-uk Kim return ((INT32) Actual);
2541a39cfb0SJung-uk Kim }
2551a39cfb0SJung-uk Kim
2561a39cfb0SJung-uk Kim
2571a39cfb0SJung-uk Kim /******************************************************************************
2581a39cfb0SJung-uk Kim *
2591a39cfb0SJung-uk Kim * FUNCTION: AfWriteTable
2601a39cfb0SJung-uk Kim *
2611a39cfb0SJung-uk Kim * PARAMETERS: Table - pointer to the ACPI table
2621a39cfb0SJung-uk Kim * Length - length of the table
2631a39cfb0SJung-uk Kim * TableName - the table signature
2641a39cfb0SJung-uk Kim * OemTableID - from the table header
2651a39cfb0SJung-uk Kim *
2661a39cfb0SJung-uk Kim * RETURN: None
2671a39cfb0SJung-uk Kim *
2681a39cfb0SJung-uk Kim * DESCRIPTION: Dump the loaded tables to a file (or files)
2691a39cfb0SJung-uk Kim *
2701a39cfb0SJung-uk Kim ******************************************************************************/
2711a39cfb0SJung-uk Kim
2721a39cfb0SJung-uk Kim void
AdWriteTable(ACPI_TABLE_HEADER * Table,UINT32 Length,char * TableName,char * OemTableId)2731a39cfb0SJung-uk Kim AdWriteTable (
2741a39cfb0SJung-uk Kim ACPI_TABLE_HEADER *Table,
2751a39cfb0SJung-uk Kim UINT32 Length,
2761a39cfb0SJung-uk Kim char *TableName,
2771a39cfb0SJung-uk Kim char *OemTableId)
2781a39cfb0SJung-uk Kim {
2791a39cfb0SJung-uk Kim char *Filename;
2801a39cfb0SJung-uk Kim
2811a39cfb0SJung-uk Kim
2821a39cfb0SJung-uk Kim Filename = AdGenerateFilename (TableName, OemTableId);
2831a39cfb0SJung-uk Kim AdWriteBuffer (Filename, (char *) Table, Length);
2841a39cfb0SJung-uk Kim
2851a39cfb0SJung-uk Kim AcpiOsPrintf ("Table [%s] written to \"%s\"\n", TableName, Filename);
2861a39cfb0SJung-uk Kim }
2871a39cfb0SJung-uk Kim
2881a39cfb0SJung-uk Kim
2891a39cfb0SJung-uk Kim /*******************************************************************************
2901a39cfb0SJung-uk Kim *
2911a39cfb0SJung-uk Kim * FUNCTION: FlGenerateFilename
2921a39cfb0SJung-uk Kim *
2931a39cfb0SJung-uk Kim * PARAMETERS: InputFilename - Original ASL source filename
2941a39cfb0SJung-uk Kim * Suffix - New extension.
2951a39cfb0SJung-uk Kim *
2961a39cfb0SJung-uk Kim * RETURN: New filename containing the original base + the new suffix
2971a39cfb0SJung-uk Kim *
2981a39cfb0SJung-uk Kim * DESCRIPTION: Generate a new filename from the ASL source filename and a new
2991a39cfb0SJung-uk Kim * extension. Used to create the *.LST, *.TXT, etc. files.
3001a39cfb0SJung-uk Kim *
3011a39cfb0SJung-uk Kim ******************************************************************************/
3021a39cfb0SJung-uk Kim
3031a39cfb0SJung-uk Kim char *
FlGenerateFilename(char * InputFilename,char * Suffix)3041a39cfb0SJung-uk Kim FlGenerateFilename (
3051a39cfb0SJung-uk Kim char *InputFilename,
3061a39cfb0SJung-uk Kim char *Suffix)
3071a39cfb0SJung-uk Kim {
3081a39cfb0SJung-uk Kim char *Position;
3091a39cfb0SJung-uk Kim char *NewFilename;
310313a0c13SJung-uk Kim char *DirectoryPosition;
3111a39cfb0SJung-uk Kim
3121a39cfb0SJung-uk Kim
3131a39cfb0SJung-uk Kim /*
314313a0c13SJung-uk Kim * Copy the original filename to a new buffer. Leave room for the worst
315313a0c13SJung-uk Kim * case where we append the suffix, an added dot and the null terminator.
3161a39cfb0SJung-uk Kim */
31767d9aa44SJung-uk Kim NewFilename = UtLocalCacheCalloc ((ACPI_SIZE)
3181a39cfb0SJung-uk Kim strlen (InputFilename) + strlen (Suffix) + 2);
3191a39cfb0SJung-uk Kim strcpy (NewFilename, InputFilename);
3201a39cfb0SJung-uk Kim
3211a39cfb0SJung-uk Kim /* Try to find the last dot in the filename */
3221a39cfb0SJung-uk Kim
323313a0c13SJung-uk Kim DirectoryPosition = strrchr (NewFilename, '/');
3241a39cfb0SJung-uk Kim Position = strrchr (NewFilename, '.');
325313a0c13SJung-uk Kim
326313a0c13SJung-uk Kim if (Position && (Position > DirectoryPosition))
3271a39cfb0SJung-uk Kim {
3281a39cfb0SJung-uk Kim /* Tack on the new suffix */
3291a39cfb0SJung-uk Kim
3301a39cfb0SJung-uk Kim Position++;
3311a39cfb0SJung-uk Kim *Position = 0;
3321a39cfb0SJung-uk Kim strcat (Position, Suffix);
3331a39cfb0SJung-uk Kim }
3341a39cfb0SJung-uk Kim else
3351a39cfb0SJung-uk Kim {
3361a39cfb0SJung-uk Kim /* No dot, add one and then the suffix */
3371a39cfb0SJung-uk Kim
3381a39cfb0SJung-uk Kim strcat (NewFilename, ".");
3391a39cfb0SJung-uk Kim strcat (NewFilename, Suffix);
3401a39cfb0SJung-uk Kim }
3411a39cfb0SJung-uk Kim
3428ef1a331SJung-uk Kim return (NewFilename);
3431a39cfb0SJung-uk Kim }
3441a39cfb0SJung-uk Kim
3451a39cfb0SJung-uk Kim
3461a39cfb0SJung-uk Kim /*******************************************************************************
3471a39cfb0SJung-uk Kim *
3481a39cfb0SJung-uk Kim * FUNCTION: FlStrdup
3491a39cfb0SJung-uk Kim *
3501a39cfb0SJung-uk Kim * DESCRIPTION: Local strdup function
3511a39cfb0SJung-uk Kim *
3521a39cfb0SJung-uk Kim ******************************************************************************/
3531a39cfb0SJung-uk Kim
3541a39cfb0SJung-uk Kim static char *
FlStrdup(char * String)3551a39cfb0SJung-uk Kim FlStrdup (
3561a39cfb0SJung-uk Kim char *String)
3571a39cfb0SJung-uk Kim {
3581a39cfb0SJung-uk Kim char *NewString;
3591a39cfb0SJung-uk Kim
3601a39cfb0SJung-uk Kim
36167d9aa44SJung-uk Kim NewString = UtLocalCacheCalloc ((ACPI_SIZE) strlen (String) + 1);
3621a39cfb0SJung-uk Kim strcpy (NewString, String);
3631a39cfb0SJung-uk Kim return (NewString);
3641a39cfb0SJung-uk Kim }
3651a39cfb0SJung-uk Kim
3661a39cfb0SJung-uk Kim
3671a39cfb0SJung-uk Kim /*******************************************************************************
3681a39cfb0SJung-uk Kim *
3691a39cfb0SJung-uk Kim * FUNCTION: FlSplitInputPathname
3701a39cfb0SJung-uk Kim *
3711a39cfb0SJung-uk Kim * PARAMETERS: InputFilename - The user-specified ASL source file to be
3721a39cfb0SJung-uk Kim * compiled
3731a39cfb0SJung-uk Kim * OutDirectoryPath - Where the directory path prefix is
3741a39cfb0SJung-uk Kim * returned
3751a39cfb0SJung-uk Kim * OutFilename - Where the filename part is returned
3761a39cfb0SJung-uk Kim *
3771a39cfb0SJung-uk Kim * RETURN: Status
3781a39cfb0SJung-uk Kim *
3791a39cfb0SJung-uk Kim * DESCRIPTION: Split the input path into a directory and filename part
3801a39cfb0SJung-uk Kim * 1) Directory part used to open include files
3811a39cfb0SJung-uk Kim * 2) Filename part used to generate output filenames
3821a39cfb0SJung-uk Kim *
3831a39cfb0SJung-uk Kim ******************************************************************************/
3841a39cfb0SJung-uk Kim
3851a39cfb0SJung-uk Kim ACPI_STATUS
FlSplitInputPathname(char * InputPath,char ** OutDirectoryPath,char ** OutFilename)3861a39cfb0SJung-uk Kim FlSplitInputPathname (
3871a39cfb0SJung-uk Kim char *InputPath,
3881a39cfb0SJung-uk Kim char **OutDirectoryPath,
3891a39cfb0SJung-uk Kim char **OutFilename)
3901a39cfb0SJung-uk Kim {
3911a39cfb0SJung-uk Kim char *Substring;
3921a39cfb0SJung-uk Kim char *DirectoryPath;
3931a39cfb0SJung-uk Kim char *Filename;
3941a39cfb0SJung-uk Kim
3951a39cfb0SJung-uk Kim
3967cf3e94aSJung-uk Kim if (OutDirectoryPath)
3977cf3e94aSJung-uk Kim {
3981a39cfb0SJung-uk Kim *OutDirectoryPath = NULL;
3997cf3e94aSJung-uk Kim }
4001a39cfb0SJung-uk Kim
4011a39cfb0SJung-uk Kim if (!InputPath)
4021a39cfb0SJung-uk Kim {
4031a39cfb0SJung-uk Kim return (AE_OK);
4041a39cfb0SJung-uk Kim }
4051a39cfb0SJung-uk Kim
4061a39cfb0SJung-uk Kim /* Get the path to the input filename's directory */
4071a39cfb0SJung-uk Kim
4081a39cfb0SJung-uk Kim DirectoryPath = FlStrdup (InputPath);
4091a39cfb0SJung-uk Kim if (!DirectoryPath)
4101a39cfb0SJung-uk Kim {
4111a39cfb0SJung-uk Kim return (AE_NO_MEMORY);
4121a39cfb0SJung-uk Kim }
4131a39cfb0SJung-uk Kim
414a7a3b383SJung-uk Kim /* Convert backslashes to slashes in the entire path */
415a7a3b383SJung-uk Kim
416a7a3b383SJung-uk Kim UtConvertBackslashes (DirectoryPath);
417a7a3b383SJung-uk Kim
418a7a3b383SJung-uk Kim /* Backup to last slash or colon */
419a7a3b383SJung-uk Kim
4201a39cfb0SJung-uk Kim Substring = strrchr (DirectoryPath, '/');
4211a39cfb0SJung-uk Kim if (!Substring)
4221a39cfb0SJung-uk Kim {
4231a39cfb0SJung-uk Kim Substring = strrchr (DirectoryPath, ':');
4241a39cfb0SJung-uk Kim }
425a7a3b383SJung-uk Kim
426a7a3b383SJung-uk Kim /* Extract the simple filename */
4271a39cfb0SJung-uk Kim
4281a39cfb0SJung-uk Kim if (!Substring)
4291a39cfb0SJung-uk Kim {
430a7a3b383SJung-uk Kim Filename = FlStrdup (DirectoryPath);
4311a39cfb0SJung-uk Kim DirectoryPath[0] = 0;
4321a39cfb0SJung-uk Kim }
4331a39cfb0SJung-uk Kim else
4341a39cfb0SJung-uk Kim {
4351a39cfb0SJung-uk Kim Filename = FlStrdup (Substring + 1);
4361a39cfb0SJung-uk Kim *(Substring+1) = 0;
4371a39cfb0SJung-uk Kim }
4381a39cfb0SJung-uk Kim
4391a39cfb0SJung-uk Kim if (!Filename)
4401a39cfb0SJung-uk Kim {
4411a39cfb0SJung-uk Kim return (AE_NO_MEMORY);
4421a39cfb0SJung-uk Kim }
4431a39cfb0SJung-uk Kim
4447cf3e94aSJung-uk Kim if (OutDirectoryPath)
4457cf3e94aSJung-uk Kim {
4461a39cfb0SJung-uk Kim *OutDirectoryPath = DirectoryPath;
4477cf3e94aSJung-uk Kim }
448313a0c13SJung-uk Kim
449313a0c13SJung-uk Kim if (OutFilename)
450313a0c13SJung-uk Kim {
4511a39cfb0SJung-uk Kim *OutFilename = Filename;
4521a39cfb0SJung-uk Kim return (AE_OK);
4531a39cfb0SJung-uk Kim }
454313a0c13SJung-uk Kim
455313a0c13SJung-uk Kim return (AE_OK);
456313a0c13SJung-uk Kim }
457835b56bfSJung-uk Kim
458835b56bfSJung-uk Kim
459835b56bfSJung-uk Kim /*******************************************************************************
460835b56bfSJung-uk Kim *
461835b56bfSJung-uk Kim * FUNCTION: FlGetFileBasename
462835b56bfSJung-uk Kim *
463835b56bfSJung-uk Kim * PARAMETERS: FilePathname - File path to be split
464835b56bfSJung-uk Kim *
465835b56bfSJung-uk Kim * RETURN: The extracted base name of the file, in upper case
466835b56bfSJung-uk Kim *
467835b56bfSJung-uk Kim * DESCRIPTION: Extract the file base name (the file name with no extension)
468835b56bfSJung-uk Kim * from the input pathname.
469835b56bfSJung-uk Kim *
470835b56bfSJung-uk Kim * Note: Any backslashes in the pathname should be previously
471835b56bfSJung-uk Kim * converted to forward slashes before calling this function.
472835b56bfSJung-uk Kim *
473835b56bfSJung-uk Kim ******************************************************************************/
474835b56bfSJung-uk Kim
475835b56bfSJung-uk Kim char *
FlGetFileBasename(char * FilePathname)476835b56bfSJung-uk Kim FlGetFileBasename (
477835b56bfSJung-uk Kim char *FilePathname)
478835b56bfSJung-uk Kim {
479835b56bfSJung-uk Kim char *FileBasename;
480835b56bfSJung-uk Kim char *Substring;
481835b56bfSJung-uk Kim
482835b56bfSJung-uk Kim
483835b56bfSJung-uk Kim /* Backup to last slash or colon */
484835b56bfSJung-uk Kim
485835b56bfSJung-uk Kim Substring = strrchr (FilePathname, '/');
486835b56bfSJung-uk Kim if (!Substring)
487835b56bfSJung-uk Kim {
488835b56bfSJung-uk Kim Substring = strrchr (FilePathname, ':');
489835b56bfSJung-uk Kim }
490835b56bfSJung-uk Kim
491835b56bfSJung-uk Kim /* Extract the full filename (base + extension) */
492835b56bfSJung-uk Kim
493835b56bfSJung-uk Kim if (Substring)
494835b56bfSJung-uk Kim {
495835b56bfSJung-uk Kim FileBasename = FlStrdup (Substring + 1);
496835b56bfSJung-uk Kim }
497835b56bfSJung-uk Kim else
498835b56bfSJung-uk Kim {
499835b56bfSJung-uk Kim FileBasename = FlStrdup (FilePathname);
500835b56bfSJung-uk Kim }
501835b56bfSJung-uk Kim
502835b56bfSJung-uk Kim /* Remove the filename extension if present */
503835b56bfSJung-uk Kim
504835b56bfSJung-uk Kim Substring = strchr (FileBasename, '.');
505835b56bfSJung-uk Kim if (Substring)
506835b56bfSJung-uk Kim {
507835b56bfSJung-uk Kim *Substring = 0;
508835b56bfSJung-uk Kim }
509835b56bfSJung-uk Kim
510835b56bfSJung-uk Kim AcpiUtStrupr (FileBasename);
511835b56bfSJung-uk Kim return (FileBasename);
512835b56bfSJung-uk Kim }
513