Home | History | Annotate | Line # | Download | only in acpisrc
asfile.c revision 1.1.1.2.4.2
      1  1.1.1.2.4.2  rmind 
      2  1.1.1.2.4.2  rmind /******************************************************************************
      3  1.1.1.2.4.2  rmind  *
      4  1.1.1.2.4.2  rmind  * Module Name: asfile - Main module for the acpi source processor utility
      5  1.1.1.2.4.2  rmind  *
      6  1.1.1.2.4.2  rmind  *****************************************************************************/
      7  1.1.1.2.4.2  rmind 
      8  1.1.1.2.4.2  rmind /*
      9  1.1.1.2.4.2  rmind  * Copyright (C) 2000 - 2011, Intel Corp.
     10  1.1.1.2.4.2  rmind  * All rights reserved.
     11  1.1.1.2.4.2  rmind  *
     12  1.1.1.2.4.2  rmind  * Redistribution and use in source and binary forms, with or without
     13  1.1.1.2.4.2  rmind  * modification, are permitted provided that the following conditions
     14  1.1.1.2.4.2  rmind  * are met:
     15  1.1.1.2.4.2  rmind  * 1. Redistributions of source code must retain the above copyright
     16  1.1.1.2.4.2  rmind  *    notice, this list of conditions, and the following disclaimer,
     17  1.1.1.2.4.2  rmind  *    without modification.
     18  1.1.1.2.4.2  rmind  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
     19  1.1.1.2.4.2  rmind  *    substantially similar to the "NO WARRANTY" disclaimer below
     20  1.1.1.2.4.2  rmind  *    ("Disclaimer") and any redistribution must be conditioned upon
     21  1.1.1.2.4.2  rmind  *    including a substantially similar Disclaimer requirement for further
     22  1.1.1.2.4.2  rmind  *    binary redistribution.
     23  1.1.1.2.4.2  rmind  * 3. Neither the names of the above-listed copyright holders nor the names
     24  1.1.1.2.4.2  rmind  *    of any contributors may be used to endorse or promote products derived
     25  1.1.1.2.4.2  rmind  *    from this software without specific prior written permission.
     26  1.1.1.2.4.2  rmind  *
     27  1.1.1.2.4.2  rmind  * Alternatively, this software may be distributed under the terms of the
     28  1.1.1.2.4.2  rmind  * GNU General Public License ("GPL") version 2 as published by the Free
     29  1.1.1.2.4.2  rmind  * Software Foundation.
     30  1.1.1.2.4.2  rmind  *
     31  1.1.1.2.4.2  rmind  * NO WARRANTY
     32  1.1.1.2.4.2  rmind  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     33  1.1.1.2.4.2  rmind  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     34  1.1.1.2.4.2  rmind  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
     35  1.1.1.2.4.2  rmind  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     36  1.1.1.2.4.2  rmind  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     37  1.1.1.2.4.2  rmind  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     38  1.1.1.2.4.2  rmind  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     39  1.1.1.2.4.2  rmind  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     40  1.1.1.2.4.2  rmind  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     41  1.1.1.2.4.2  rmind  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     42  1.1.1.2.4.2  rmind  * POSSIBILITY OF SUCH DAMAGES.
     43  1.1.1.2.4.2  rmind  */
     44  1.1.1.2.4.2  rmind 
     45  1.1.1.2.4.2  rmind #include "acpisrc.h"
     46  1.1.1.2.4.2  rmind 
     47  1.1.1.2.4.2  rmind /* Local prototypes */
     48  1.1.1.2.4.2  rmind 
     49  1.1.1.2.4.2  rmind void
     50  1.1.1.2.4.2  rmind AsDoWildcard (
     51  1.1.1.2.4.2  rmind     ACPI_CONVERSION_TABLE   *ConversionTable,
     52  1.1.1.2.4.2  rmind     char                    *SourcePath,
     53  1.1.1.2.4.2  rmind     char                    *TargetPath,
     54  1.1.1.2.4.2  rmind     int                     MaxPathLength,
     55  1.1.1.2.4.2  rmind     int                     FileType,
     56  1.1.1.2.4.2  rmind     char                    *WildcardSpec);
     57  1.1.1.2.4.2  rmind 
     58  1.1.1.2.4.2  rmind BOOLEAN
     59  1.1.1.2.4.2  rmind AsDetectLoneLineFeeds (
     60  1.1.1.2.4.2  rmind     char                    *Filename,
     61  1.1.1.2.4.2  rmind     char                    *Buffer);
     62  1.1.1.2.4.2  rmind 
     63  1.1.1.2.4.2  rmind static ACPI_INLINE int
     64  1.1.1.2.4.2  rmind AsMaxInt (int a, int b)
     65  1.1.1.2.4.2  rmind {
     66  1.1.1.2.4.2  rmind     return (a > b ? a : b);
     67  1.1.1.2.4.2  rmind }
     68  1.1.1.2.4.2  rmind 
     69  1.1.1.2.4.2  rmind 
     70  1.1.1.2.4.2  rmind /******************************************************************************
     71  1.1.1.2.4.2  rmind  *
     72  1.1.1.2.4.2  rmind  * FUNCTION:    AsDoWildcard
     73  1.1.1.2.4.2  rmind  *
     74  1.1.1.2.4.2  rmind  * DESCRIPTION: Process files via wildcards
     75  1.1.1.2.4.2  rmind  *
     76  1.1.1.2.4.2  rmind  ******************************************************************************/
     77  1.1.1.2.4.2  rmind 
     78  1.1.1.2.4.2  rmind void
     79  1.1.1.2.4.2  rmind AsDoWildcard (
     80  1.1.1.2.4.2  rmind     ACPI_CONVERSION_TABLE   *ConversionTable,
     81  1.1.1.2.4.2  rmind     char                    *SourcePath,
     82  1.1.1.2.4.2  rmind     char                    *TargetPath,
     83  1.1.1.2.4.2  rmind     int                     MaxPathLength,
     84  1.1.1.2.4.2  rmind     int                     FileType,
     85  1.1.1.2.4.2  rmind     char                    *WildcardSpec)
     86  1.1.1.2.4.2  rmind {
     87  1.1.1.2.4.2  rmind     void                    *DirInfo;
     88  1.1.1.2.4.2  rmind     char                    *Filename;
     89  1.1.1.2.4.2  rmind     char                    *SourceDirPath;
     90  1.1.1.2.4.2  rmind     char                    *TargetDirPath;
     91  1.1.1.2.4.2  rmind     char                    RequestedFileType;
     92  1.1.1.2.4.2  rmind 
     93  1.1.1.2.4.2  rmind 
     94  1.1.1.2.4.2  rmind     if (FileType == FILE_TYPE_DIRECTORY)
     95  1.1.1.2.4.2  rmind     {
     96  1.1.1.2.4.2  rmind         RequestedFileType = REQUEST_DIR_ONLY;
     97  1.1.1.2.4.2  rmind     }
     98  1.1.1.2.4.2  rmind     else
     99  1.1.1.2.4.2  rmind     {
    100  1.1.1.2.4.2  rmind         RequestedFileType = REQUEST_FILE_ONLY;
    101  1.1.1.2.4.2  rmind     }
    102  1.1.1.2.4.2  rmind 
    103  1.1.1.2.4.2  rmind     VERBOSE_PRINT (("Checking for %s source files in directory \"%s\"\n",
    104  1.1.1.2.4.2  rmind             WildcardSpec, SourcePath));
    105  1.1.1.2.4.2  rmind 
    106  1.1.1.2.4.2  rmind     /* Open the directory for wildcard search */
    107  1.1.1.2.4.2  rmind 
    108  1.1.1.2.4.2  rmind     DirInfo = AcpiOsOpenDirectory (SourcePath, WildcardSpec, RequestedFileType);
    109  1.1.1.2.4.2  rmind     if (DirInfo)
    110  1.1.1.2.4.2  rmind     {
    111  1.1.1.2.4.2  rmind         /*
    112  1.1.1.2.4.2  rmind          * Get all of the files that match both the
    113  1.1.1.2.4.2  rmind          * wildcard and the requested file type
    114  1.1.1.2.4.2  rmind          */
    115  1.1.1.2.4.2  rmind         while ((Filename = AcpiOsGetNextFilename (DirInfo)))
    116  1.1.1.2.4.2  rmind         {
    117  1.1.1.2.4.2  rmind             /* Looking for directory files, must check file type */
    118  1.1.1.2.4.2  rmind 
    119  1.1.1.2.4.2  rmind             switch (RequestedFileType)
    120  1.1.1.2.4.2  rmind             {
    121  1.1.1.2.4.2  rmind             case REQUEST_DIR_ONLY:
    122  1.1.1.2.4.2  rmind 
    123  1.1.1.2.4.2  rmind                 /* If we actually have a dir, process the subtree */
    124  1.1.1.2.4.2  rmind 
    125  1.1.1.2.4.2  rmind                 if (!AsCheckForDirectory (SourcePath, TargetPath, Filename,
    126  1.1.1.2.4.2  rmind                         &SourceDirPath, &TargetDirPath))
    127  1.1.1.2.4.2  rmind                 {
    128  1.1.1.2.4.2  rmind                     VERBOSE_PRINT (("Subdirectory: %s\n", Filename));
    129  1.1.1.2.4.2  rmind 
    130  1.1.1.2.4.2  rmind                     AsProcessTree (ConversionTable, SourceDirPath, TargetDirPath);
    131  1.1.1.2.4.2  rmind                     free (SourceDirPath);
    132  1.1.1.2.4.2  rmind                     free (TargetDirPath);
    133  1.1.1.2.4.2  rmind                 }
    134  1.1.1.2.4.2  rmind                 break;
    135  1.1.1.2.4.2  rmind 
    136  1.1.1.2.4.2  rmind             case REQUEST_FILE_ONLY:
    137  1.1.1.2.4.2  rmind 
    138  1.1.1.2.4.2  rmind                 /* Otherwise, this is a file, not a directory */
    139  1.1.1.2.4.2  rmind 
    140  1.1.1.2.4.2  rmind                 VERBOSE_PRINT (("File: %s\n", Filename));
    141  1.1.1.2.4.2  rmind 
    142  1.1.1.2.4.2  rmind                 AsProcessOneFile (ConversionTable, SourcePath, TargetPath,
    143  1.1.1.2.4.2  rmind                         MaxPathLength, Filename, FileType);
    144  1.1.1.2.4.2  rmind                 break;
    145  1.1.1.2.4.2  rmind 
    146  1.1.1.2.4.2  rmind             default:
    147  1.1.1.2.4.2  rmind                 break;
    148  1.1.1.2.4.2  rmind             }
    149  1.1.1.2.4.2  rmind         }
    150  1.1.1.2.4.2  rmind 
    151  1.1.1.2.4.2  rmind         /* Cleanup */
    152  1.1.1.2.4.2  rmind 
    153  1.1.1.2.4.2  rmind         AcpiOsCloseDirectory (DirInfo);
    154  1.1.1.2.4.2  rmind     }
    155  1.1.1.2.4.2  rmind }
    156  1.1.1.2.4.2  rmind 
    157  1.1.1.2.4.2  rmind 
    158  1.1.1.2.4.2  rmind /******************************************************************************
    159  1.1.1.2.4.2  rmind  *
    160  1.1.1.2.4.2  rmind  * FUNCTION:    AsProcessTree
    161  1.1.1.2.4.2  rmind  *
    162  1.1.1.2.4.2  rmind  * DESCRIPTION: Process the directory tree.  Files with the extension ".C" and
    163  1.1.1.2.4.2  rmind  *              ".H" are processed as the tree is traversed.
    164  1.1.1.2.4.2  rmind  *
    165  1.1.1.2.4.2  rmind  ******************************************************************************/
    166  1.1.1.2.4.2  rmind 
    167  1.1.1.2.4.2  rmind ACPI_NATIVE_INT
    168  1.1.1.2.4.2  rmind AsProcessTree (
    169  1.1.1.2.4.2  rmind     ACPI_CONVERSION_TABLE   *ConversionTable,
    170  1.1.1.2.4.2  rmind     char                    *SourcePath,
    171  1.1.1.2.4.2  rmind     char                    *TargetPath)
    172  1.1.1.2.4.2  rmind {
    173  1.1.1.2.4.2  rmind     int                     MaxPathLength;
    174  1.1.1.2.4.2  rmind 
    175  1.1.1.2.4.2  rmind 
    176  1.1.1.2.4.2  rmind     MaxPathLength = AsMaxInt (strlen (SourcePath), strlen (TargetPath));
    177  1.1.1.2.4.2  rmind 
    178  1.1.1.2.4.2  rmind     if (!(ConversionTable->Flags & FLG_NO_FILE_OUTPUT))
    179  1.1.1.2.4.2  rmind     {
    180  1.1.1.2.4.2  rmind         if (ConversionTable->Flags & FLG_LOWERCASE_DIRNAMES)
    181  1.1.1.2.4.2  rmind         {
    182  1.1.1.2.4.2  rmind             strlwr (TargetPath);
    183  1.1.1.2.4.2  rmind         }
    184  1.1.1.2.4.2  rmind 
    185  1.1.1.2.4.2  rmind         VERBOSE_PRINT (("Creating Directory \"%s\"\n", TargetPath));
    186  1.1.1.2.4.2  rmind         if (mkdir (TargetPath))
    187  1.1.1.2.4.2  rmind         {
    188  1.1.1.2.4.2  rmind             if (errno != EEXIST)
    189  1.1.1.2.4.2  rmind             {
    190  1.1.1.2.4.2  rmind                 printf ("Could not create target directory\n");
    191  1.1.1.2.4.2  rmind                 return -1;
    192  1.1.1.2.4.2  rmind             }
    193  1.1.1.2.4.2  rmind         }
    194  1.1.1.2.4.2  rmind     }
    195  1.1.1.2.4.2  rmind 
    196  1.1.1.2.4.2  rmind     /* Do the C source files */
    197  1.1.1.2.4.2  rmind 
    198  1.1.1.2.4.2  rmind     AsDoWildcard (ConversionTable, SourcePath, TargetPath, MaxPathLength,
    199  1.1.1.2.4.2  rmind             FILE_TYPE_SOURCE, "*.c");
    200  1.1.1.2.4.2  rmind 
    201  1.1.1.2.4.2  rmind     /* Do the C header files */
    202  1.1.1.2.4.2  rmind 
    203  1.1.1.2.4.2  rmind     AsDoWildcard (ConversionTable, SourcePath, TargetPath, MaxPathLength,
    204  1.1.1.2.4.2  rmind             FILE_TYPE_HEADER, "*.h");
    205  1.1.1.2.4.2  rmind 
    206  1.1.1.2.4.2  rmind     /* Do the Lex file(s) */
    207  1.1.1.2.4.2  rmind 
    208  1.1.1.2.4.2  rmind     AsDoWildcard (ConversionTable, SourcePath, TargetPath, MaxPathLength,
    209  1.1.1.2.4.2  rmind             FILE_TYPE_SOURCE, "*.l");
    210  1.1.1.2.4.2  rmind 
    211  1.1.1.2.4.2  rmind     /* Do the yacc file(s) */
    212  1.1.1.2.4.2  rmind 
    213  1.1.1.2.4.2  rmind     AsDoWildcard (ConversionTable, SourcePath, TargetPath, MaxPathLength,
    214  1.1.1.2.4.2  rmind             FILE_TYPE_SOURCE, "*.y");
    215  1.1.1.2.4.2  rmind 
    216  1.1.1.2.4.2  rmind     /* Do any ASL files */
    217  1.1.1.2.4.2  rmind 
    218  1.1.1.2.4.2  rmind     AsDoWildcard (ConversionTable, SourcePath, TargetPath, MaxPathLength,
    219  1.1.1.2.4.2  rmind             FILE_TYPE_HEADER, "*.asl");
    220  1.1.1.2.4.2  rmind 
    221  1.1.1.2.4.2  rmind     /* Do any subdirectories */
    222  1.1.1.2.4.2  rmind 
    223  1.1.1.2.4.2  rmind     AsDoWildcard (ConversionTable, SourcePath, TargetPath, MaxPathLength,
    224  1.1.1.2.4.2  rmind             FILE_TYPE_DIRECTORY, "*");
    225  1.1.1.2.4.2  rmind 
    226  1.1.1.2.4.2  rmind     return 0;
    227  1.1.1.2.4.2  rmind }
    228  1.1.1.2.4.2  rmind 
    229  1.1.1.2.4.2  rmind 
    230  1.1.1.2.4.2  rmind /******************************************************************************
    231  1.1.1.2.4.2  rmind  *
    232  1.1.1.2.4.2  rmind  * FUNCTION:    AsDetectLoneLineFeeds
    233  1.1.1.2.4.2  rmind  *
    234  1.1.1.2.4.2  rmind  * DESCRIPTION: Find LF without CR.
    235  1.1.1.2.4.2  rmind  *
    236  1.1.1.2.4.2  rmind  ******************************************************************************/
    237  1.1.1.2.4.2  rmind 
    238  1.1.1.2.4.2  rmind BOOLEAN
    239  1.1.1.2.4.2  rmind AsDetectLoneLineFeeds (
    240  1.1.1.2.4.2  rmind     char                    *Filename,
    241  1.1.1.2.4.2  rmind     char                    *Buffer)
    242  1.1.1.2.4.2  rmind {
    243  1.1.1.2.4.2  rmind     UINT32                  i = 1;
    244  1.1.1.2.4.2  rmind     UINT32                  LfCount = 0;
    245  1.1.1.2.4.2  rmind     UINT32                  LineCount = 0;
    246  1.1.1.2.4.2  rmind 
    247  1.1.1.2.4.2  rmind 
    248  1.1.1.2.4.2  rmind     if (!Buffer[0])
    249  1.1.1.2.4.2  rmind     {
    250  1.1.1.2.4.2  rmind         return FALSE;
    251  1.1.1.2.4.2  rmind     }
    252  1.1.1.2.4.2  rmind 
    253  1.1.1.2.4.2  rmind     while (Buffer[i])
    254  1.1.1.2.4.2  rmind     {
    255  1.1.1.2.4.2  rmind         if (Buffer[i] == 0x0A)
    256  1.1.1.2.4.2  rmind         {
    257  1.1.1.2.4.2  rmind             if (Buffer[i-1] != 0x0D)
    258  1.1.1.2.4.2  rmind             {
    259  1.1.1.2.4.2  rmind                 LfCount++;
    260  1.1.1.2.4.2  rmind             }
    261  1.1.1.2.4.2  rmind             LineCount++;
    262  1.1.1.2.4.2  rmind         }
    263  1.1.1.2.4.2  rmind         i++;
    264  1.1.1.2.4.2  rmind     }
    265  1.1.1.2.4.2  rmind 
    266  1.1.1.2.4.2  rmind     if (LfCount)
    267  1.1.1.2.4.2  rmind     {
    268  1.1.1.2.4.2  rmind         if (LineCount == LfCount)
    269  1.1.1.2.4.2  rmind         {
    270  1.1.1.2.4.2  rmind             if (!Gbl_IgnoreLoneLineFeeds)
    271  1.1.1.2.4.2  rmind             {
    272  1.1.1.2.4.2  rmind                 printf ("%s: ****File has UNIX format**** (LF only, not CR/LF) %u lines\n",
    273  1.1.1.2.4.2  rmind                     Filename, LfCount);
    274  1.1.1.2.4.2  rmind             }
    275  1.1.1.2.4.2  rmind         }
    276  1.1.1.2.4.2  rmind         else
    277  1.1.1.2.4.2  rmind         {
    278  1.1.1.2.4.2  rmind             printf ("%s: %u lone linefeeds in file\n", Filename, LfCount);
    279  1.1.1.2.4.2  rmind         }
    280  1.1.1.2.4.2  rmind         return TRUE;
    281  1.1.1.2.4.2  rmind     }
    282  1.1.1.2.4.2  rmind 
    283  1.1.1.2.4.2  rmind     return (FALSE);
    284  1.1.1.2.4.2  rmind }
    285  1.1.1.2.4.2  rmind 
    286  1.1.1.2.4.2  rmind 
    287  1.1.1.2.4.2  rmind /******************************************************************************
    288  1.1.1.2.4.2  rmind  *
    289  1.1.1.2.4.2  rmind  * FUNCTION:    AsConvertFile
    290  1.1.1.2.4.2  rmind  *
    291  1.1.1.2.4.2  rmind  * DESCRIPTION: Perform the requested transforms on the file buffer (as
    292  1.1.1.2.4.2  rmind  *              determined by the ConversionTable and the FileType).
    293  1.1.1.2.4.2  rmind  *
    294  1.1.1.2.4.2  rmind  ******************************************************************************/
    295  1.1.1.2.4.2  rmind 
    296  1.1.1.2.4.2  rmind void
    297  1.1.1.2.4.2  rmind AsConvertFile (
    298  1.1.1.2.4.2  rmind     ACPI_CONVERSION_TABLE   *ConversionTable,
    299  1.1.1.2.4.2  rmind     char                    *FileBuffer,
    300  1.1.1.2.4.2  rmind     char                    *Filename,
    301  1.1.1.2.4.2  rmind     ACPI_NATIVE_INT         FileType)
    302  1.1.1.2.4.2  rmind {
    303  1.1.1.2.4.2  rmind     UINT32                  i;
    304  1.1.1.2.4.2  rmind     UINT32                  Functions;
    305  1.1.1.2.4.2  rmind     ACPI_STRING_TABLE       *StringTable;
    306  1.1.1.2.4.2  rmind     ACPI_IDENTIFIER_TABLE   *ConditionalTable;
    307  1.1.1.2.4.2  rmind     ACPI_IDENTIFIER_TABLE   *LineTable;
    308  1.1.1.2.4.2  rmind     ACPI_IDENTIFIER_TABLE   *MacroTable;
    309  1.1.1.2.4.2  rmind     ACPI_TYPED_IDENTIFIER_TABLE *StructTable;
    310  1.1.1.2.4.2  rmind 
    311  1.1.1.2.4.2  rmind 
    312  1.1.1.2.4.2  rmind     switch (FileType)
    313  1.1.1.2.4.2  rmind     {
    314  1.1.1.2.4.2  rmind     case FILE_TYPE_SOURCE:
    315  1.1.1.2.4.2  rmind         Functions           = ConversionTable->SourceFunctions;
    316  1.1.1.2.4.2  rmind         StringTable         = ConversionTable->SourceStringTable;
    317  1.1.1.2.4.2  rmind         LineTable           = ConversionTable->SourceLineTable;
    318  1.1.1.2.4.2  rmind         ConditionalTable    = ConversionTable->SourceConditionalTable;
    319  1.1.1.2.4.2  rmind         MacroTable          = ConversionTable->SourceMacroTable;
    320  1.1.1.2.4.2  rmind         StructTable         = ConversionTable->SourceStructTable;
    321  1.1.1.2.4.2  rmind        break;
    322  1.1.1.2.4.2  rmind 
    323  1.1.1.2.4.2  rmind     case FILE_TYPE_HEADER:
    324  1.1.1.2.4.2  rmind         Functions           = ConversionTable->HeaderFunctions;
    325  1.1.1.2.4.2  rmind         StringTable         = ConversionTable->HeaderStringTable;
    326  1.1.1.2.4.2  rmind         LineTable           = ConversionTable->HeaderLineTable;
    327  1.1.1.2.4.2  rmind         ConditionalTable    = ConversionTable->HeaderConditionalTable;
    328  1.1.1.2.4.2  rmind         MacroTable          = ConversionTable->HeaderMacroTable;
    329  1.1.1.2.4.2  rmind         StructTable         = ConversionTable->HeaderStructTable;
    330  1.1.1.2.4.2  rmind         break;
    331  1.1.1.2.4.2  rmind 
    332  1.1.1.2.4.2  rmind     default:
    333  1.1.1.2.4.2  rmind         printf ("Unknown file type, cannot process\n");
    334  1.1.1.2.4.2  rmind         return;
    335  1.1.1.2.4.2  rmind     }
    336  1.1.1.2.4.2  rmind 
    337  1.1.1.2.4.2  rmind 
    338  1.1.1.2.4.2  rmind     Gbl_StructDefs = strstr (FileBuffer, "/* acpisrc:StructDefs");
    339  1.1.1.2.4.2  rmind     Gbl_Files++;
    340  1.1.1.2.4.2  rmind     VERBOSE_PRINT (("Processing %u bytes\n",
    341  1.1.1.2.4.2  rmind         (unsigned int) strlen (FileBuffer)));
    342  1.1.1.2.4.2  rmind 
    343  1.1.1.2.4.2  rmind     if (ConversionTable->LowerCaseTable)
    344  1.1.1.2.4.2  rmind     {
    345  1.1.1.2.4.2  rmind         for (i = 0; ConversionTable->LowerCaseTable[i].Identifier; i++)
    346  1.1.1.2.4.2  rmind         {
    347  1.1.1.2.4.2  rmind             AsLowerCaseString (ConversionTable->LowerCaseTable[i].Identifier,
    348  1.1.1.2.4.2  rmind                                 FileBuffer);
    349  1.1.1.2.4.2  rmind         }
    350  1.1.1.2.4.2  rmind     }
    351  1.1.1.2.4.2  rmind 
    352  1.1.1.2.4.2  rmind     /* Process all the string replacements */
    353  1.1.1.2.4.2  rmind 
    354  1.1.1.2.4.2  rmind     if (StringTable)
    355  1.1.1.2.4.2  rmind     {
    356  1.1.1.2.4.2  rmind         for (i = 0; StringTable[i].Target; i++)
    357  1.1.1.2.4.2  rmind         {
    358  1.1.1.2.4.2  rmind             AsReplaceString (StringTable[i].Target, StringTable[i].Replacement,
    359  1.1.1.2.4.2  rmind                     StringTable[i].Type, FileBuffer);
    360  1.1.1.2.4.2  rmind         }
    361  1.1.1.2.4.2  rmind     }
    362  1.1.1.2.4.2  rmind 
    363  1.1.1.2.4.2  rmind     if (LineTable)
    364  1.1.1.2.4.2  rmind     {
    365  1.1.1.2.4.2  rmind         for (i = 0; LineTable[i].Identifier; i++)
    366  1.1.1.2.4.2  rmind         {
    367  1.1.1.2.4.2  rmind             AsRemoveLine (FileBuffer, LineTable[i].Identifier);
    368  1.1.1.2.4.2  rmind         }
    369  1.1.1.2.4.2  rmind     }
    370  1.1.1.2.4.2  rmind 
    371  1.1.1.2.4.2  rmind     if (ConditionalTable)
    372  1.1.1.2.4.2  rmind     {
    373  1.1.1.2.4.2  rmind         for (i = 0; ConditionalTable[i].Identifier; i++)
    374  1.1.1.2.4.2  rmind         {
    375  1.1.1.2.4.2  rmind             AsRemoveConditionalCompile (FileBuffer, ConditionalTable[i].Identifier);
    376  1.1.1.2.4.2  rmind         }
    377  1.1.1.2.4.2  rmind     }
    378  1.1.1.2.4.2  rmind 
    379  1.1.1.2.4.2  rmind     if (MacroTable)
    380  1.1.1.2.4.2  rmind     {
    381  1.1.1.2.4.2  rmind         for (i = 0; MacroTable[i].Identifier; i++)
    382  1.1.1.2.4.2  rmind         {
    383  1.1.1.2.4.2  rmind             AsRemoveMacro (FileBuffer, MacroTable[i].Identifier);
    384  1.1.1.2.4.2  rmind         }
    385  1.1.1.2.4.2  rmind     }
    386  1.1.1.2.4.2  rmind 
    387  1.1.1.2.4.2  rmind     if (StructTable)
    388  1.1.1.2.4.2  rmind     {
    389  1.1.1.2.4.2  rmind         for (i = 0; StructTable[i].Identifier; i++)
    390  1.1.1.2.4.2  rmind         {
    391  1.1.1.2.4.2  rmind             AsInsertPrefix (FileBuffer, StructTable[i].Identifier, StructTable[i].Type);
    392  1.1.1.2.4.2  rmind         }
    393  1.1.1.2.4.2  rmind     }
    394  1.1.1.2.4.2  rmind 
    395  1.1.1.2.4.2  rmind     /* Process the function table */
    396  1.1.1.2.4.2  rmind 
    397  1.1.1.2.4.2  rmind     for (i = 0; i < 32; i++)
    398  1.1.1.2.4.2  rmind     {
    399  1.1.1.2.4.2  rmind         /* Decode the function bitmap */
    400  1.1.1.2.4.2  rmind 
    401  1.1.1.2.4.2  rmind         switch ((1 << i) & Functions)
    402  1.1.1.2.4.2  rmind         {
    403  1.1.1.2.4.2  rmind         case 0:
    404  1.1.1.2.4.2  rmind             /* This function not configured */
    405  1.1.1.2.4.2  rmind             break;
    406  1.1.1.2.4.2  rmind 
    407  1.1.1.2.4.2  rmind 
    408  1.1.1.2.4.2  rmind         case CVT_COUNT_TABS:
    409  1.1.1.2.4.2  rmind 
    410  1.1.1.2.4.2  rmind             AsCountTabs (FileBuffer, Filename);
    411  1.1.1.2.4.2  rmind             break;
    412  1.1.1.2.4.2  rmind 
    413  1.1.1.2.4.2  rmind 
    414  1.1.1.2.4.2  rmind         case CVT_COUNT_NON_ANSI_COMMENTS:
    415  1.1.1.2.4.2  rmind 
    416  1.1.1.2.4.2  rmind             AsCountNonAnsiComments (FileBuffer, Filename);
    417  1.1.1.2.4.2  rmind             break;
    418  1.1.1.2.4.2  rmind 
    419  1.1.1.2.4.2  rmind 
    420  1.1.1.2.4.2  rmind         case CVT_CHECK_BRACES:
    421  1.1.1.2.4.2  rmind 
    422  1.1.1.2.4.2  rmind             AsCheckForBraces (FileBuffer, Filename);
    423  1.1.1.2.4.2  rmind             break;
    424  1.1.1.2.4.2  rmind 
    425  1.1.1.2.4.2  rmind 
    426  1.1.1.2.4.2  rmind         case CVT_TRIM_LINES:
    427  1.1.1.2.4.2  rmind 
    428  1.1.1.2.4.2  rmind             AsTrimLines (FileBuffer, Filename);
    429  1.1.1.2.4.2  rmind             break;
    430  1.1.1.2.4.2  rmind 
    431  1.1.1.2.4.2  rmind 
    432  1.1.1.2.4.2  rmind         case CVT_COUNT_LINES:
    433  1.1.1.2.4.2  rmind 
    434  1.1.1.2.4.2  rmind             AsCountSourceLines (FileBuffer, Filename);
    435  1.1.1.2.4.2  rmind             break;
    436  1.1.1.2.4.2  rmind 
    437  1.1.1.2.4.2  rmind 
    438  1.1.1.2.4.2  rmind         case CVT_BRACES_ON_SAME_LINE:
    439  1.1.1.2.4.2  rmind 
    440  1.1.1.2.4.2  rmind             AsBracesOnSameLine (FileBuffer);
    441  1.1.1.2.4.2  rmind             break;
    442  1.1.1.2.4.2  rmind 
    443  1.1.1.2.4.2  rmind 
    444  1.1.1.2.4.2  rmind         case CVT_MIXED_CASE_TO_UNDERSCORES:
    445  1.1.1.2.4.2  rmind 
    446  1.1.1.2.4.2  rmind             AsMixedCaseToUnderscores (FileBuffer);
    447  1.1.1.2.4.2  rmind             break;
    448  1.1.1.2.4.2  rmind 
    449  1.1.1.2.4.2  rmind 
    450  1.1.1.2.4.2  rmind         case CVT_LOWER_CASE_IDENTIFIERS:
    451  1.1.1.2.4.2  rmind 
    452  1.1.1.2.4.2  rmind             AsLowerCaseIdentifiers (FileBuffer);
    453  1.1.1.2.4.2  rmind             break;
    454  1.1.1.2.4.2  rmind 
    455  1.1.1.2.4.2  rmind 
    456  1.1.1.2.4.2  rmind         case CVT_REMOVE_DEBUG_MACROS:
    457  1.1.1.2.4.2  rmind 
    458  1.1.1.2.4.2  rmind             AsRemoveDebugMacros (FileBuffer);
    459  1.1.1.2.4.2  rmind             break;
    460  1.1.1.2.4.2  rmind 
    461  1.1.1.2.4.2  rmind 
    462  1.1.1.2.4.2  rmind         case CVT_TRIM_WHITESPACE:
    463  1.1.1.2.4.2  rmind 
    464  1.1.1.2.4.2  rmind             AsTrimWhitespace (FileBuffer);
    465  1.1.1.2.4.2  rmind             break;
    466  1.1.1.2.4.2  rmind 
    467  1.1.1.2.4.2  rmind 
    468  1.1.1.2.4.2  rmind         case CVT_REMOVE_EMPTY_BLOCKS:
    469  1.1.1.2.4.2  rmind 
    470  1.1.1.2.4.2  rmind             AsRemoveEmptyBlocks (FileBuffer, Filename);
    471  1.1.1.2.4.2  rmind             break;
    472  1.1.1.2.4.2  rmind 
    473  1.1.1.2.4.2  rmind 
    474  1.1.1.2.4.2  rmind         case CVT_REDUCE_TYPEDEFS:
    475  1.1.1.2.4.2  rmind 
    476  1.1.1.2.4.2  rmind             AsReduceTypedefs (FileBuffer, "typedef union");
    477  1.1.1.2.4.2  rmind             AsReduceTypedefs (FileBuffer, "typedef struct");
    478  1.1.1.2.4.2  rmind             break;
    479  1.1.1.2.4.2  rmind 
    480  1.1.1.2.4.2  rmind 
    481  1.1.1.2.4.2  rmind         case CVT_SPACES_TO_TABS4:
    482  1.1.1.2.4.2  rmind 
    483  1.1.1.2.4.2  rmind             AsTabify4 (FileBuffer);
    484  1.1.1.2.4.2  rmind             break;
    485  1.1.1.2.4.2  rmind 
    486  1.1.1.2.4.2  rmind 
    487  1.1.1.2.4.2  rmind         case CVT_SPACES_TO_TABS8:
    488  1.1.1.2.4.2  rmind 
    489  1.1.1.2.4.2  rmind             AsTabify8 (FileBuffer);
    490  1.1.1.2.4.2  rmind             break;
    491  1.1.1.2.4.2  rmind 
    492  1.1.1.2.4.2  rmind         case CVT_COUNT_SHORTMULTILINE_COMMENTS:
    493  1.1.1.2.4.2  rmind 
    494  1.1.1.2.4.2  rmind #ifdef ACPI_FUTURE_IMPLEMENTATION
    495  1.1.1.2.4.2  rmind             AsTrimComments (FileBuffer, Filename);
    496  1.1.1.2.4.2  rmind #endif
    497  1.1.1.2.4.2  rmind             break;
    498  1.1.1.2.4.2  rmind 
    499  1.1.1.2.4.2  rmind         default:
    500  1.1.1.2.4.2  rmind 
    501  1.1.1.2.4.2  rmind             printf ("Unknown conversion subfunction opcode\n");
    502  1.1.1.2.4.2  rmind             break;
    503  1.1.1.2.4.2  rmind         }
    504  1.1.1.2.4.2  rmind     }
    505  1.1.1.2.4.2  rmind 
    506  1.1.1.2.4.2  rmind     if (ConversionTable->NewHeader)
    507  1.1.1.2.4.2  rmind     {
    508  1.1.1.2.4.2  rmind         AsReplaceHeader (FileBuffer, ConversionTable->NewHeader);
    509  1.1.1.2.4.2  rmind     }
    510  1.1.1.2.4.2  rmind }
    511  1.1.1.2.4.2  rmind 
    512  1.1.1.2.4.2  rmind 
    513  1.1.1.2.4.2  rmind /******************************************************************************
    514  1.1.1.2.4.2  rmind  *
    515  1.1.1.2.4.2  rmind  * FUNCTION:    AsProcessOneFile
    516  1.1.1.2.4.2  rmind  *
    517  1.1.1.2.4.2  rmind  * DESCRIPTION: Process one source file.  The file is opened, read entirely
    518  1.1.1.2.4.2  rmind  *              into a buffer, converted, then written to a new file.
    519  1.1.1.2.4.2  rmind  *
    520  1.1.1.2.4.2  rmind  ******************************************************************************/
    521  1.1.1.2.4.2  rmind 
    522  1.1.1.2.4.2  rmind ACPI_NATIVE_INT
    523  1.1.1.2.4.2  rmind AsProcessOneFile (
    524  1.1.1.2.4.2  rmind     ACPI_CONVERSION_TABLE   *ConversionTable,
    525  1.1.1.2.4.2  rmind     char                    *SourcePath,
    526  1.1.1.2.4.2  rmind     char                    *TargetPath,
    527  1.1.1.2.4.2  rmind     int                     MaxPathLength,
    528  1.1.1.2.4.2  rmind     char                    *Filename,
    529  1.1.1.2.4.2  rmind     ACPI_NATIVE_INT         FileType)
    530  1.1.1.2.4.2  rmind {
    531  1.1.1.2.4.2  rmind     char                    *Pathname;
    532  1.1.1.2.4.2  rmind     char                    *OutPathname = NULL;
    533  1.1.1.2.4.2  rmind 
    534  1.1.1.2.4.2  rmind 
    535  1.1.1.2.4.2  rmind     /* Allocate a file pathname buffer for both source and target */
    536  1.1.1.2.4.2  rmind 
    537  1.1.1.2.4.2  rmind     Pathname = calloc (MaxPathLength + strlen (Filename) + 2, 1);
    538  1.1.1.2.4.2  rmind     if (!Pathname)
    539  1.1.1.2.4.2  rmind     {
    540  1.1.1.2.4.2  rmind         printf ("Could not allocate buffer for file pathnames\n");
    541  1.1.1.2.4.2  rmind         return -1;
    542  1.1.1.2.4.2  rmind     }
    543  1.1.1.2.4.2  rmind 
    544  1.1.1.2.4.2  rmind     Gbl_FileType = FileType;
    545  1.1.1.2.4.2  rmind 
    546  1.1.1.2.4.2  rmind     /* Generate the source pathname and read the file */
    547  1.1.1.2.4.2  rmind 
    548  1.1.1.2.4.2  rmind     if (SourcePath)
    549  1.1.1.2.4.2  rmind     {
    550  1.1.1.2.4.2  rmind         strcpy (Pathname, SourcePath);
    551  1.1.1.2.4.2  rmind         strcat (Pathname, "/");
    552  1.1.1.2.4.2  rmind     }
    553  1.1.1.2.4.2  rmind 
    554  1.1.1.2.4.2  rmind     strcat (Pathname, Filename);
    555  1.1.1.2.4.2  rmind 
    556  1.1.1.2.4.2  rmind     if (AsGetFile (Pathname, &Gbl_FileBuffer, &Gbl_FileSize))
    557  1.1.1.2.4.2  rmind     {
    558  1.1.1.2.4.2  rmind         return -1;
    559  1.1.1.2.4.2  rmind     }
    560  1.1.1.2.4.2  rmind 
    561  1.1.1.2.4.2  rmind     Gbl_HeaderSize = 0;
    562  1.1.1.2.4.2  rmind     if (strstr (Filename, ".asl"))
    563  1.1.1.2.4.2  rmind     {
    564  1.1.1.2.4.2  rmind         Gbl_HeaderSize = LINES_IN_ASL_HEADER; /* Lines in default ASL header */
    565  1.1.1.2.4.2  rmind     }
    566  1.1.1.2.4.2  rmind     else if (strstr (Gbl_FileBuffer, LEGAL_HEADER_SIGNATURE))
    567  1.1.1.2.4.2  rmind     {
    568  1.1.1.2.4.2  rmind         Gbl_HeaderSize = LINES_IN_LEGAL_HEADER; /* Normal C file and H header */
    569  1.1.1.2.4.2  rmind     }
    570  1.1.1.2.4.2  rmind     else if (strstr (Gbl_FileBuffer, LINUX_HEADER_SIGNATURE))
    571  1.1.1.2.4.2  rmind     {
    572  1.1.1.2.4.2  rmind         Gbl_HeaderSize = LINES_IN_LINUX_HEADER; /* Linuxized C file and H header */
    573  1.1.1.2.4.2  rmind     }
    574  1.1.1.2.4.2  rmind 
    575  1.1.1.2.4.2  rmind     /* Process the file in the buffer */
    576  1.1.1.2.4.2  rmind 
    577  1.1.1.2.4.2  rmind     Gbl_MadeChanges = FALSE;
    578  1.1.1.2.4.2  rmind     if (!Gbl_IgnoreLoneLineFeeds && Gbl_HasLoneLineFeeds)
    579  1.1.1.2.4.2  rmind     {
    580  1.1.1.2.4.2  rmind         /*
    581  1.1.1.2.4.2  rmind          * All lone LFs will be converted to CR/LF
    582  1.1.1.2.4.2  rmind          * (when file is written, Windows version only)
    583  1.1.1.2.4.2  rmind          */
    584  1.1.1.2.4.2  rmind         printf ("Converting lone linefeeds\n");
    585  1.1.1.2.4.2  rmind         Gbl_MadeChanges = TRUE;
    586  1.1.1.2.4.2  rmind     }
    587  1.1.1.2.4.2  rmind 
    588  1.1.1.2.4.2  rmind     AsConvertFile (ConversionTable, Gbl_FileBuffer, Pathname, FileType);
    589  1.1.1.2.4.2  rmind 
    590  1.1.1.2.4.2  rmind     if (!(ConversionTable->Flags & FLG_NO_FILE_OUTPUT))
    591  1.1.1.2.4.2  rmind     {
    592  1.1.1.2.4.2  rmind         if (!(Gbl_Overwrite && !Gbl_MadeChanges))
    593  1.1.1.2.4.2  rmind         {
    594  1.1.1.2.4.2  rmind             /* Generate the target pathname and write the file */
    595  1.1.1.2.4.2  rmind 
    596  1.1.1.2.4.2  rmind             OutPathname = calloc (MaxPathLength + strlen (Filename) + 2 + strlen (TargetPath), 1);
    597  1.1.1.2.4.2  rmind             if (!OutPathname)
    598  1.1.1.2.4.2  rmind             {
    599  1.1.1.2.4.2  rmind                 printf ("Could not allocate buffer for file pathnames\n");
    600  1.1.1.2.4.2  rmind                 return -1;
    601  1.1.1.2.4.2  rmind             }
    602  1.1.1.2.4.2  rmind 
    603  1.1.1.2.4.2  rmind             strcpy (OutPathname, TargetPath);
    604  1.1.1.2.4.2  rmind             if (SourcePath)
    605  1.1.1.2.4.2  rmind             {
    606  1.1.1.2.4.2  rmind                 strcat (OutPathname, "/");
    607  1.1.1.2.4.2  rmind                 strcat (OutPathname, Filename);
    608  1.1.1.2.4.2  rmind             }
    609  1.1.1.2.4.2  rmind 
    610  1.1.1.2.4.2  rmind             AsPutFile (OutPathname, Gbl_FileBuffer, ConversionTable->Flags);
    611  1.1.1.2.4.2  rmind         }
    612  1.1.1.2.4.2  rmind     }
    613  1.1.1.2.4.2  rmind 
    614  1.1.1.2.4.2  rmind     free (Gbl_FileBuffer);
    615  1.1.1.2.4.2  rmind     free (Pathname);
    616  1.1.1.2.4.2  rmind     if (OutPathname)
    617  1.1.1.2.4.2  rmind     {
    618  1.1.1.2.4.2  rmind         free (OutPathname);
    619  1.1.1.2.4.2  rmind     }
    620  1.1.1.2.4.2  rmind 
    621  1.1.1.2.4.2  rmind     return 0;
    622  1.1.1.2.4.2  rmind }
    623  1.1.1.2.4.2  rmind 
    624  1.1.1.2.4.2  rmind 
    625  1.1.1.2.4.2  rmind /******************************************************************************
    626  1.1.1.2.4.2  rmind  *
    627  1.1.1.2.4.2  rmind  * FUNCTION:    AsCheckForDirectory
    628  1.1.1.2.4.2  rmind  *
    629  1.1.1.2.4.2  rmind  * DESCRIPTION: Check if the current file is a valid directory.  If not,
    630  1.1.1.2.4.2  rmind  *              construct the full pathname for the source and target paths.
    631  1.1.1.2.4.2  rmind  *              Checks for the dot and dot-dot files (they are ignored)
    632  1.1.1.2.4.2  rmind  *
    633  1.1.1.2.4.2  rmind  ******************************************************************************/
    634  1.1.1.2.4.2  rmind 
    635  1.1.1.2.4.2  rmind ACPI_NATIVE_INT
    636  1.1.1.2.4.2  rmind AsCheckForDirectory (
    637  1.1.1.2.4.2  rmind     char                    *SourceDirPath,
    638  1.1.1.2.4.2  rmind     char                    *TargetDirPath,
    639  1.1.1.2.4.2  rmind     char                    *Filename,
    640  1.1.1.2.4.2  rmind     char                    **SourcePath,
    641  1.1.1.2.4.2  rmind     char                    **TargetPath)
    642  1.1.1.2.4.2  rmind {
    643  1.1.1.2.4.2  rmind     char                    *SrcPath;
    644  1.1.1.2.4.2  rmind     char                    *TgtPath;
    645  1.1.1.2.4.2  rmind 
    646  1.1.1.2.4.2  rmind 
    647  1.1.1.2.4.2  rmind     if (!(strcmp (Filename, ".")) ||
    648  1.1.1.2.4.2  rmind         !(strcmp (Filename, "..")))
    649  1.1.1.2.4.2  rmind     {
    650  1.1.1.2.4.2  rmind         return -1;
    651  1.1.1.2.4.2  rmind     }
    652  1.1.1.2.4.2  rmind 
    653  1.1.1.2.4.2  rmind     SrcPath = calloc (strlen (SourceDirPath) + strlen (Filename) + 2, 1);
    654  1.1.1.2.4.2  rmind     if (!SrcPath)
    655  1.1.1.2.4.2  rmind     {
    656  1.1.1.2.4.2  rmind         printf ("Could not allocate buffer for directory source pathname\n");
    657  1.1.1.2.4.2  rmind         return -1;
    658  1.1.1.2.4.2  rmind     }
    659  1.1.1.2.4.2  rmind 
    660  1.1.1.2.4.2  rmind     TgtPath = calloc (strlen (TargetDirPath) + strlen (Filename) + 2, 1);
    661  1.1.1.2.4.2  rmind     if (!TgtPath)
    662  1.1.1.2.4.2  rmind     {
    663  1.1.1.2.4.2  rmind         printf ("Could not allocate buffer for directory target pathname\n");
    664  1.1.1.2.4.2  rmind         free (SrcPath);
    665  1.1.1.2.4.2  rmind         return -1;
    666  1.1.1.2.4.2  rmind     }
    667  1.1.1.2.4.2  rmind 
    668  1.1.1.2.4.2  rmind     strcpy (SrcPath, SourceDirPath);
    669  1.1.1.2.4.2  rmind     strcat (SrcPath, "/");
    670  1.1.1.2.4.2  rmind     strcat (SrcPath, Filename);
    671  1.1.1.2.4.2  rmind 
    672  1.1.1.2.4.2  rmind     strcpy (TgtPath, TargetDirPath);
    673  1.1.1.2.4.2  rmind     strcat (TgtPath, "/");
    674  1.1.1.2.4.2  rmind     strcat (TgtPath, Filename);
    675  1.1.1.2.4.2  rmind 
    676  1.1.1.2.4.2  rmind     *SourcePath = SrcPath;
    677  1.1.1.2.4.2  rmind     *TargetPath = TgtPath;
    678  1.1.1.2.4.2  rmind     return 0;
    679  1.1.1.2.4.2  rmind }
    680  1.1.1.2.4.2  rmind 
    681  1.1.1.2.4.2  rmind 
    682  1.1.1.2.4.2  rmind /******************************************************************************
    683  1.1.1.2.4.2  rmind  *
    684  1.1.1.2.4.2  rmind  * FUNCTION:    AsGetFile
    685  1.1.1.2.4.2  rmind  *
    686  1.1.1.2.4.2  rmind  * DESCRIPTION: Open a file and read it entirely into a an allocated buffer
    687  1.1.1.2.4.2  rmind  *
    688  1.1.1.2.4.2  rmind  ******************************************************************************/
    689  1.1.1.2.4.2  rmind 
    690  1.1.1.2.4.2  rmind int
    691  1.1.1.2.4.2  rmind AsGetFile (
    692  1.1.1.2.4.2  rmind     char                    *Filename,
    693  1.1.1.2.4.2  rmind     char                    **FileBuffer,
    694  1.1.1.2.4.2  rmind     UINT32                  *FileSize)
    695  1.1.1.2.4.2  rmind {
    696  1.1.1.2.4.2  rmind 
    697  1.1.1.2.4.2  rmind     int                     FileHandle;
    698  1.1.1.2.4.2  rmind     UINT32                  Size;
    699  1.1.1.2.4.2  rmind     char                    *Buffer;
    700  1.1.1.2.4.2  rmind 
    701  1.1.1.2.4.2  rmind 
    702  1.1.1.2.4.2  rmind     /* Binary mode leaves CR/LF pairs */
    703  1.1.1.2.4.2  rmind 
    704  1.1.1.2.4.2  rmind     FileHandle = open (Filename, O_BINARY | O_RDONLY);
    705  1.1.1.2.4.2  rmind     if (!FileHandle)
    706  1.1.1.2.4.2  rmind     {
    707  1.1.1.2.4.2  rmind         printf ("Could not open %s\n", Filename);
    708  1.1.1.2.4.2  rmind         return -1;
    709  1.1.1.2.4.2  rmind     }
    710  1.1.1.2.4.2  rmind 
    711  1.1.1.2.4.2  rmind     if (fstat (FileHandle, &Gbl_StatBuf))
    712  1.1.1.2.4.2  rmind     {
    713  1.1.1.2.4.2  rmind         printf ("Could not get file status for %s\n", Filename);
    714  1.1.1.2.4.2  rmind         goto ErrorExit;
    715  1.1.1.2.4.2  rmind     }
    716  1.1.1.2.4.2  rmind 
    717  1.1.1.2.4.2  rmind     /*
    718  1.1.1.2.4.2  rmind      * Create a buffer for the entire file
    719  1.1.1.2.4.2  rmind      * Add plenty extra buffer to accomodate string replacements
    720  1.1.1.2.4.2  rmind      */
    721  1.1.1.2.4.2  rmind     Size = Gbl_StatBuf.st_size;
    722  1.1.1.2.4.2  rmind     Gbl_TotalSize += Size;
    723  1.1.1.2.4.2  rmind 
    724  1.1.1.2.4.2  rmind     Buffer = calloc (Size * 2, 1);
    725  1.1.1.2.4.2  rmind     if (!Buffer)
    726  1.1.1.2.4.2  rmind     {
    727  1.1.1.2.4.2  rmind         printf ("Could not allocate buffer of size %u\n", Size * 2);
    728  1.1.1.2.4.2  rmind         goto ErrorExit;
    729  1.1.1.2.4.2  rmind     }
    730  1.1.1.2.4.2  rmind 
    731  1.1.1.2.4.2  rmind     /* Read the entire file */
    732  1.1.1.2.4.2  rmind 
    733  1.1.1.2.4.2  rmind     Size = read (FileHandle, Buffer, Size);
    734  1.1.1.2.4.2  rmind     if (Size == -1)
    735  1.1.1.2.4.2  rmind     {
    736  1.1.1.2.4.2  rmind         printf ("Could not read the input file %s\n", Filename);
    737  1.1.1.2.4.2  rmind         goto ErrorExit;
    738  1.1.1.2.4.2  rmind     }
    739  1.1.1.2.4.2  rmind 
    740  1.1.1.2.4.2  rmind     Buffer [Size] = 0;         /* Null terminate the buffer */
    741  1.1.1.2.4.2  rmind     close (FileHandle);
    742  1.1.1.2.4.2  rmind 
    743  1.1.1.2.4.2  rmind     /* Check for unix contamination */
    744  1.1.1.2.4.2  rmind 
    745  1.1.1.2.4.2  rmind     Gbl_HasLoneLineFeeds = AsDetectLoneLineFeeds (Filename, Buffer);
    746  1.1.1.2.4.2  rmind 
    747  1.1.1.2.4.2  rmind     /*
    748  1.1.1.2.4.2  rmind      * Convert all CR/LF pairs to LF only.  We do this locally so that
    749  1.1.1.2.4.2  rmind      * this code is portable across operating systems.
    750  1.1.1.2.4.2  rmind      */
    751  1.1.1.2.4.2  rmind     AsConvertToLineFeeds (Buffer);
    752  1.1.1.2.4.2  rmind 
    753  1.1.1.2.4.2  rmind     *FileBuffer = Buffer;
    754  1.1.1.2.4.2  rmind     *FileSize = Size;
    755  1.1.1.2.4.2  rmind 
    756  1.1.1.2.4.2  rmind     return 0;
    757  1.1.1.2.4.2  rmind 
    758  1.1.1.2.4.2  rmind 
    759  1.1.1.2.4.2  rmind ErrorExit:
    760  1.1.1.2.4.2  rmind 
    761  1.1.1.2.4.2  rmind     close (FileHandle);
    762  1.1.1.2.4.2  rmind     return -1;
    763  1.1.1.2.4.2  rmind }
    764  1.1.1.2.4.2  rmind 
    765  1.1.1.2.4.2  rmind 
    766  1.1.1.2.4.2  rmind /******************************************************************************
    767  1.1.1.2.4.2  rmind  *
    768  1.1.1.2.4.2  rmind  * FUNCTION:    AsPutFile
    769  1.1.1.2.4.2  rmind  *
    770  1.1.1.2.4.2  rmind  * DESCRIPTION: Create a new output file and write the entire contents of the
    771  1.1.1.2.4.2  rmind  *              buffer to the new file.  Buffer must be a zero terminated string
    772  1.1.1.2.4.2  rmind  *
    773  1.1.1.2.4.2  rmind  ******************************************************************************/
    774  1.1.1.2.4.2  rmind 
    775  1.1.1.2.4.2  rmind int
    776  1.1.1.2.4.2  rmind AsPutFile (
    777  1.1.1.2.4.2  rmind     char                    *Pathname,
    778  1.1.1.2.4.2  rmind     char                    *FileBuffer,
    779  1.1.1.2.4.2  rmind     UINT32                  SystemFlags)
    780  1.1.1.2.4.2  rmind {
    781  1.1.1.2.4.2  rmind     UINT32                  FileSize;
    782  1.1.1.2.4.2  rmind     int                     DestHandle;
    783  1.1.1.2.4.2  rmind     int                     OpenFlags;
    784  1.1.1.2.4.2  rmind 
    785  1.1.1.2.4.2  rmind 
    786  1.1.1.2.4.2  rmind     /* Create the target file */
    787  1.1.1.2.4.2  rmind 
    788  1.1.1.2.4.2  rmind     OpenFlags = O_TRUNC | O_CREAT | O_WRONLY | O_BINARY;
    789  1.1.1.2.4.2  rmind 
    790  1.1.1.2.4.2  rmind     if (!(SystemFlags & FLG_NO_CARRIAGE_RETURNS))
    791  1.1.1.2.4.2  rmind     {
    792  1.1.1.2.4.2  rmind         /* Put back the CR before each LF */
    793  1.1.1.2.4.2  rmind 
    794  1.1.1.2.4.2  rmind         AsInsertCarriageReturns (FileBuffer);
    795  1.1.1.2.4.2  rmind     }
    796  1.1.1.2.4.2  rmind 
    797  1.1.1.2.4.2  rmind     DestHandle = open (Pathname, OpenFlags, S_IREAD | S_IWRITE);
    798  1.1.1.2.4.2  rmind     if (DestHandle == -1)
    799  1.1.1.2.4.2  rmind     {
    800  1.1.1.2.4.2  rmind         perror ("Could not create destination file");
    801  1.1.1.2.4.2  rmind         printf ("Could not create destination file \"%s\"\n", Pathname);
    802  1.1.1.2.4.2  rmind         return -1;
    803  1.1.1.2.4.2  rmind     }
    804  1.1.1.2.4.2  rmind 
    805  1.1.1.2.4.2  rmind     /* Write the buffer to the file */
    806  1.1.1.2.4.2  rmind 
    807  1.1.1.2.4.2  rmind     FileSize = strlen (FileBuffer);
    808  1.1.1.2.4.2  rmind     write (DestHandle, FileBuffer, FileSize);
    809  1.1.1.2.4.2  rmind 
    810  1.1.1.2.4.2  rmind     close (DestHandle);
    811  1.1.1.2.4.2  rmind 
    812  1.1.1.2.4.2  rmind     return 0;
    813  1.1.1.2.4.2  rmind }
    814  1.1.1.2.4.2  rmind 
    815  1.1.1.2.4.2  rmind 
    816