1 /******************************************************************************
3 * Module Name: asfile - Main module for the acpi source processor utility
5 *****************************************************************************/
7 /******************************************************************************
11 * Some or all of this work - Copyright (c) 1999 - 2021, Intel Corp.
12 * All rights reserved.
16 * 2.1. This is your license from Intel Corp. under its intellectual property
17 * rights. You may have additional license terms from the party that provided
18 * you this software, covering your right to use that party's intellectual
21 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22 * copy of the source code appearing in this file ("Covered Code") an
23 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24 * base code distributed originally by Intel ("Original Intel Code") to copy,
25 * make derivatives, distribute, use and display any portion of the Covered
26 * Code in any form, with the right to sublicense such rights; and
28 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29 * license (with the right to sublicense), under only those claims of Intel
30 * patents that are infringed by the Original Intel Code, to make, use, sell,
31 * offer to sell, and import the Covered Code and derivative works thereof
32 * solely to the minimum extent necessary to exercise the above copyright
33 * license, and in no event shall the patent license extend to any additions
34 * to or modifications of the Original Intel Code. No other license or right
35 * is granted directly or by implication, estoppel or otherwise;
37 * The above copyright and patent license is granted only if the following
42 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43 * Redistribution of source code of any substantial portion of the Covered
44 * Code or modification with rights to further distribute source must include
45 * the above Copyright Notice, the above License, this list of Conditions,
46 * and the following Disclaimer and Export Compliance provision. In addition,
47 * Licensee must cause all Covered Code to which Licensee contributes to
48 * contain a file documenting the changes Licensee made to create that Covered
49 * Code and the date of any change. Licensee must include in that file the
50 * documentation of any changes made by any predecessor Licensee. Licensee
51 * must include a prominent statement that the modification is derived,
52 * directly or indirectly, from Original Intel Code.
54 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55 * Redistribution of source code of any substantial portion of the Covered
56 * Code or modification without rights to further distribute source must
57 * include the following Disclaimer and Export Compliance provision in the
58 * documentation and/or other materials provided with distribution. In
59 * addition, Licensee may not authorize further sublicense of source of any
60 * portion of the Covered Code, and must include terms to the effect that the
61 * license from Licensee to its licensee is limited to the intellectual
62 * property embodied in the software Licensee provides to its licensee, and
63 * not to intellectual property embodied in modifications its licensee may
66 * 3.3. Redistribution of Executable. Redistribution in executable form of any
67 * substantial portion of the Covered Code or modification must reproduce the
68 * above Copyright Notice, and the following Disclaimer and Export Compliance
69 * provision in the documentation and/or other materials provided with the
72 * 3.4. Intel retains all right, title, and interest in and to the Original
75 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76 * Intel shall be used in advertising or otherwise to promote the sale, use or
77 * other dealings in products derived from or relating to the Covered Code
78 * without prior written authorization from Intel.
80 * 4. Disclaimer and Export Compliance
82 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
90 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
99 * 4.3. Licensee shall not export, either directly or indirectly, any of this
100 * software or system incorporating such software without first obtaining any
101 * required license or other approval from the U. S. Department of Commerce or
102 * any other agency or department of the United States Government. In the
103 * event Licensee exports any such software from the United States or
104 * re-exports any such software from a foreign destination, Licensee shall
105 * ensure that the distribution and export/re-export of the software is in
106 * compliance with all laws, regulations, orders, or other restrictions of the
107 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108 * any of its subsidiaries will export/re-export any technical data, process,
109 * software, or service, directly or indirectly, to any country for which the
110 * United States government or any agency thereof requires an export license,
111 * other governmental approval, or letter of assurance, without first obtaining
112 * such license, approval or letter.
114 *****************************************************************************
116 * Alternatively, you may choose to be licensed under the terms of the
119 * Redistribution and use in source and binary forms, with or without
120 * modification, are permitted provided that the following conditions
122 * 1. Redistributions of source code must retain the above copyright
123 * notice, this list of conditions, and the following disclaimer,
124 * without modification.
125 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
126 * substantially similar to the "NO WARRANTY" disclaimer below
127 * ("Disclaimer") and any redistribution must be conditioned upon
128 * including a substantially similar Disclaimer requirement for further
129 * binary redistribution.
130 * 3. Neither the names of the above-listed copyright holders nor the names
131 * of any contributors may be used to endorse or promote products derived
132 * from this software without specific prior written permission.
134 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
135 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
136 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
137 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
138 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
139 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
140 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
141 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
142 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
143 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
144 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
146 * Alternatively, you may choose to be licensed under the terms of the
147 * GNU General Public License ("GPL") version 2 as published by the Free
148 * Software Foundation.
150 *****************************************************************************/
154 /* Local prototypes */
158 ACPI_CONVERSION_TABLE
*ConversionTable
,
166 AsDetectLoneLineFeeds (
171 AsCheckForNonPrintableChars (
175 static ACPI_INLINE
int
176 AsMaxInt (int a
, int b
)
178 return (a
> b
? a
: b
);
182 /******************************************************************************
184 * FUNCTION: AsDoWildcard
186 * DESCRIPTION: Process files via wildcards
188 ******************************************************************************/
192 ACPI_CONVERSION_TABLE
*ConversionTable
,
203 char RequestedFileType
;
206 if (FileType
== FILE_TYPE_DIRECTORY
)
208 RequestedFileType
= REQUEST_DIR_ONLY
;
212 RequestedFileType
= REQUEST_FILE_ONLY
;
215 VERBOSE_PRINT (("Checking for %s source files in directory \"%s\"\n",
216 WildcardSpec
, SourcePath
));
218 /* Open the directory for wildcard search */
220 DirInfo
= AcpiOsOpenDirectory (SourcePath
, WildcardSpec
, RequestedFileType
);
224 * Get all of the files that match both the
225 * wildcard and the requested file type
227 while ((Filename
= AcpiOsGetNextFilename (DirInfo
)))
229 /* Looking for directory files, must check file type */
231 switch (RequestedFileType
)
233 case REQUEST_DIR_ONLY
:
235 /* If we actually have a dir, process the subtree */
237 if (!AsCheckForDirectory (SourcePath
, TargetPath
, Filename
,
238 &SourceDirPath
, &TargetDirPath
))
240 VERBOSE_PRINT (("Subdirectory: %s\n", Filename
));
242 AsProcessTree (ConversionTable
, SourceDirPath
, TargetDirPath
);
243 free (SourceDirPath
);
244 free (TargetDirPath
);
248 case REQUEST_FILE_ONLY
:
250 /* Otherwise, this is a file, not a directory */
252 VERBOSE_PRINT (("File: %s\n", Filename
));
254 AsProcessOneFile (ConversionTable
, SourcePath
, TargetPath
,
255 MaxPathLength
, Filename
, FileType
);
266 AcpiOsCloseDirectory (DirInfo
);
271 /******************************************************************************
273 * FUNCTION: AsProcessTree
275 * DESCRIPTION: Process the directory tree. Files with the extension ".C" and
276 * ".H" are processed as the tree is traversed.
278 ******************************************************************************/
282 ACPI_CONVERSION_TABLE
*ConversionTable
,
289 MaxPathLength
= AsMaxInt (strlen (SourcePath
), strlen (TargetPath
));
291 if (!(ConversionTable
->Flags
& FLG_NO_FILE_OUTPUT
))
293 if (ConversionTable
->Flags
& FLG_LOWERCASE_DIRNAMES
)
295 AcpiUtStrlwr (TargetPath
);
298 VERBOSE_PRINT (("Creating Directory \"%s\"\n", TargetPath
));
299 if (mkdir (TargetPath
))
303 printf ("Could not create target directory\n");
309 /* Do the C source files */
311 AsDoWildcard (ConversionTable
, SourcePath
, TargetPath
, MaxPathLength
,
312 FILE_TYPE_SOURCE
, "*.c");
314 /* Do the C header files */
316 AsDoWildcard (ConversionTable
, SourcePath
, TargetPath
, MaxPathLength
,
317 FILE_TYPE_HEADER
, "*.h");
319 /* Do the Lex file(s) */
321 AsDoWildcard (ConversionTable
, SourcePath
, TargetPath
, MaxPathLength
,
322 FILE_TYPE_SOURCE
, "*.l");
324 /* Do the yacc file(s) */
326 AsDoWildcard (ConversionTable
, SourcePath
, TargetPath
, MaxPathLength
,
327 FILE_TYPE_SOURCE
, "*.y");
329 /* Do any ASL files */
331 AsDoWildcard (ConversionTable
, SourcePath
, TargetPath
, MaxPathLength
,
332 FILE_TYPE_HEADER
, "*.asl");
334 /* Do any subdirectories */
336 AsDoWildcard (ConversionTable
, SourcePath
, TargetPath
, MaxPathLength
,
337 FILE_TYPE_DIRECTORY
, "*");
343 /******************************************************************************
345 * FUNCTION: AsDetectLoneLineFeeds
347 * DESCRIPTION: Find LF without CR.
349 ******************************************************************************/
352 AsDetectLoneLineFeeds (
358 UINT32 LineCount
= 0;
368 if (Buffer
[i
] == 0x0A)
370 if (Buffer
[i
-1] != 0x0D)
382 if (LineCount
== LfCount
)
384 if (!Gbl_IgnoreLoneLineFeeds
)
386 printf ("%s: ****File has UNIX format**** (LF only, not CR/LF) %u lines\n",
392 printf ("%s: %u lone linefeeds in file\n", Filename
, LfCount
);
402 /******************************************************************************
404 * FUNCTION: AsConvertFile
406 * DESCRIPTION: Perform the requested transforms on the file buffer (as
407 * determined by the ConversionTable and the FileType).
409 ******************************************************************************/
413 ACPI_CONVERSION_TABLE
*ConversionTable
,
416 ACPI_NATIVE_INT FileType
)
420 ACPI_STRING_TABLE
*StringTable
;
421 ACPI_IDENTIFIER_TABLE
*ConditionalTable
;
422 ACPI_IDENTIFIER_TABLE
*LineTable
;
423 ACPI_TYPED_IDENTIFIER_TABLE
*StructTable
;
424 ACPI_IDENTIFIER_TABLE
*SpecialMacroTable
;
425 char *SpdxHeader
=NULL
;
430 case FILE_TYPE_SOURCE
:
432 Functions
= ConversionTable
->SourceFunctions
;
433 StringTable
= ConversionTable
->SourceStringTable
;
434 LineTable
= ConversionTable
->SourceLineTable
;
435 ConditionalTable
= ConversionTable
->SourceConditionalTable
;
436 StructTable
= ConversionTable
->SourceStructTable
;
437 SpecialMacroTable
= ConversionTable
->SourceSpecialMacroTable
;
438 SpdxHeader
= ConversionTable
->SourceSpdxHeader
;
441 case FILE_TYPE_HEADER
:
443 Functions
= ConversionTable
->HeaderFunctions
;
444 StringTable
= ConversionTable
->HeaderStringTable
;
445 LineTable
= ConversionTable
->HeaderLineTable
;
446 ConditionalTable
= ConversionTable
->HeaderConditionalTable
;
447 StructTable
= ConversionTable
->HeaderStructTable
;
448 SpecialMacroTable
= ConversionTable
->HeaderSpecialMacroTable
;
449 SpdxHeader
= ConversionTable
->HeaderSpdxHeader
;
452 case FILE_TYPE_PATCH
:
454 Functions
= ConversionTable
->PatchFunctions
;
455 StringTable
= ConversionTable
->PatchStringTable
;
456 LineTable
= ConversionTable
->PatchLineTable
;
457 ConditionalTable
= ConversionTable
->PatchConditionalTable
;
458 StructTable
= ConversionTable
->PatchStructTable
;
459 SpecialMacroTable
= ConversionTable
->PatchSpecialMacroTable
;
464 printf ("Unknown file type, cannot process\n");
469 Gbl_StructDefs
= strstr (FileBuffer
, "/* acpisrc:StructDefs");
471 VERBOSE_PRINT (("Processing %u bytes\n",
472 (unsigned int) strlen (FileBuffer
)));
476 AsRemoveExtraLines (FileBuffer
, Filename
);
477 AsRemoveSpacesAfterPeriod (FileBuffer
, Filename
);
480 if (ConversionTable
->LowerCaseTable
)
482 for (i
= 0; ConversionTable
->LowerCaseTable
[i
].Identifier
; i
++)
484 AsLowerCaseString (ConversionTable
->LowerCaseTable
[i
].Identifier
,
489 /* Process all the string replacements */
493 for (i
= 0; StringTable
[i
].Target
; i
++)
495 AsReplaceString (StringTable
[i
].Target
, StringTable
[i
].Replacement
,
496 StringTable
[i
].Type
, FileBuffer
);
502 for (i
= 0; LineTable
[i
].Identifier
; i
++)
504 AsRemoveLine (FileBuffer
, LineTable
[i
].Identifier
);
508 if (ConditionalTable
)
510 for (i
= 0; ConditionalTable
[i
].Identifier
; i
++)
512 AsRemoveConditionalCompile (FileBuffer
, ConditionalTable
[i
].Identifier
);
516 #ifdef _OBSOLETE_FUNCTIONS
519 for (i
= 0; MacroTable
[i
].Identifier
; i
++)
521 AsRemoveMacro (FileBuffer
, MacroTable
[i
].Identifier
);
528 for (i
= 0; StructTable
[i
].Identifier
; i
++)
530 AsInsertPrefix (FileBuffer
, StructTable
[i
].Identifier
,
531 StructTable
[i
].Type
);
535 if (SpecialMacroTable
)
537 for (i
= 0; SpecialMacroTable
[i
].Identifier
; i
++)
539 AsCleanupSpecialMacro (FileBuffer
, SpecialMacroTable
[i
].Identifier
);
543 /* Process the function table */
545 for (i
= 0; i
< 32; i
++)
547 /* Decode the function bitmap */
549 switch (((UINT32
) 1 << i
) & Functions
)
553 /* This function not configured */
558 AsCountTabs (FileBuffer
, Filename
);
561 case CVT_COUNT_NON_ANSI_COMMENTS
:
563 AsCountNonAnsiComments (FileBuffer
, Filename
);
566 case CVT_CHECK_BRACES
:
568 AsCheckForBraces (FileBuffer
, Filename
);
573 AsTrimLines (FileBuffer
, Filename
);
576 case CVT_COUNT_LINES
:
578 AsCountSourceLines (FileBuffer
, Filename
);
581 case CVT_BRACES_ON_SAME_LINE
:
583 AsBracesOnSameLine (FileBuffer
);
586 case CVT_MIXED_CASE_TO_UNDERSCORES
:
588 AsMixedCaseToUnderscores (FileBuffer
, Filename
);
591 case CVT_LOWER_CASE_IDENTIFIERS
:
593 AsLowerCaseIdentifiers (FileBuffer
);
596 case CVT_REMOVE_DEBUG_MACROS
:
598 AsRemoveDebugMacros (FileBuffer
);
601 case CVT_TRIM_WHITESPACE
:
603 AsTrimWhitespace (FileBuffer
);
606 case CVT_REMOVE_EMPTY_BLOCKS
:
608 AsRemoveEmptyBlocks (FileBuffer
, Filename
);
611 case CVT_REDUCE_TYPEDEFS
:
613 AsReduceTypedefs (FileBuffer
, "typedef union");
614 AsReduceTypedefs (FileBuffer
, "typedef struct");
617 case CVT_SPACES_TO_TABS4
:
619 AsTabify4 (FileBuffer
);
622 case CVT_SPACES_TO_TABS8
:
624 AsTabify8 (FileBuffer
);
627 case CVT_COUNT_SHORTMULTILINE_COMMENTS
:
629 #ifdef ACPI_FUTURE_IMPLEMENTATION
630 AsTrimComments (FileBuffer
, Filename
);
636 printf ("Unknown conversion subfunction opcode\n");
641 if (ConversionTable
->NewHeader
)
643 AsReplaceHeader (FileBuffer
, ConversionTable
->NewHeader
);
647 AsDoSpdxHeader (FileBuffer
, SpdxHeader
);
651 /*******************************************************************************
653 * FUNCTION: AsCheckForNonPrintableChars
655 * PARAMETERS: FileBuffer - Buffer with contents of entire file
656 * FileSize - Size of the file and buffer
658 * RETURN: TRUE if there are no non-printable characters
660 * DESCRIPTION: Scan a file for any non-printable ASCII bytes.
662 ******************************************************************************/
665 AsCheckForNonPrintableChars (
669 BOOLEAN Found
= TRUE
;
674 /* Scan entire file for any non-printable characters */
676 for (i
= 0; i
< FileSize
; i
++)
678 Byte
= FileBuffer
[i
];
679 if (!isprint (Byte
) && !isspace (Byte
))
681 printf ( "Non-printable character (0x%2.2X) "
682 "at file offset: %8u (0x%X)\n", Byte
, i
, i
);
691 /******************************************************************************
693 * FUNCTION: AsProcessOneFile
695 * DESCRIPTION: Process one source file. The file is opened, read entirely
696 * into a buffer, converted, then written to a new file.
698 ******************************************************************************/
702 ACPI_CONVERSION_TABLE
*ConversionTable
,
707 ACPI_NATIVE_INT FileType
)
714 /* Allocate a file pathname buffer for both source and target */
716 Pathname
= calloc (MaxPathLength
+ strlen (Filename
) + 2, 1);
719 printf ("Could not allocate buffer for file pathnames\n");
723 Gbl_FileType
= FileType
;
725 /* Generate the source pathname and read the file */
729 strcpy (Pathname
, SourcePath
);
730 strcat (Pathname
, "/");
733 strcat (Pathname
, Filename
);
734 if (AsGetFile (Pathname
, &Gbl_FileBuffer
, &Gbl_FileSize
))
740 /* Exit now if simply checking the file for printable ascii chars */
749 if (strstr (Filename
, ".asl"))
751 Gbl_HeaderSize
= LINES_IN_ASL_HEADER
; /* Lines in default ASL header */
753 else if (strstr (Gbl_FileBuffer
, LEGAL_HEADER_SIGNATURE
))
755 Gbl_HeaderSize
= LINES_IN_LEGAL_HEADER
; /* Normal C file and H header */
757 else if (strstr (Gbl_FileBuffer
, LINUX_HEADER_SIGNATURE
))
759 Gbl_HeaderSize
= LINES_IN_LINUX_HEADER
; /* Linuxized C file and H header */
762 /* Process the file in the buffer */
764 Gbl_MadeChanges
= FALSE
;
765 if (!Gbl_IgnoreLoneLineFeeds
&& Gbl_HasLoneLineFeeds
)
768 * All lone LFs will be converted to CR/LF
769 * (when file is written, Windows version only)
771 printf ("Converting lone linefeeds\n");
772 Gbl_MadeChanges
= TRUE
;
775 AsConvertFile (ConversionTable
, Gbl_FileBuffer
, Pathname
, FileType
);
777 if (!(ConversionTable
->Flags
& FLG_NO_FILE_OUTPUT
))
779 if (!(Gbl_Overwrite
&& !Gbl_MadeChanges
))
781 /* Generate the target pathname and write the file */
783 OutPathname
= calloc (MaxPathLength
+
784 strlen (Filename
) + 2 + strlen (TargetPath
), 1);
787 printf ("Could not allocate buffer for file pathnames\n");
792 strcpy (OutPathname
, TargetPath
);
795 strcat (OutPathname
, "/");
796 strcat (OutPathname
, Filename
);
799 AsPutFile (OutPathname
, Gbl_FileBuffer
, ConversionTable
->Flags
);
805 free (Gbl_FileBuffer
);
813 /******************************************************************************
815 * FUNCTION: AsCheckForDirectory
817 * DESCRIPTION: Check if the current file is a valid directory. If not,
818 * construct the full pathname for the source and target paths.
819 * Checks for the dot and dot-dot files (they are ignored)
821 ******************************************************************************/
824 AsCheckForDirectory (
835 if (!(strcmp (Filename
, ".")) ||
836 !(strcmp (Filename
, "..")))
841 SrcPath
= calloc (strlen (SourceDirPath
) + strlen (Filename
) + 2, 1);
844 printf ("Could not allocate buffer for directory source pathname\n");
848 TgtPath
= calloc (strlen (TargetDirPath
) + strlen (Filename
) + 2, 1);
851 printf ("Could not allocate buffer for directory target pathname\n");
856 strcpy (SrcPath
, SourceDirPath
);
857 strcat (SrcPath
, "/");
858 strcat (SrcPath
, Filename
);
860 strcpy (TgtPath
, TargetDirPath
);
861 strcat (TgtPath
, "/");
862 strcat (TgtPath
, Filename
);
864 *SourcePath
= SrcPath
;
865 *TargetPath
= TgtPath
;
870 /******************************************************************************
872 * FUNCTION: AsGetFile
874 * DESCRIPTION: Open a file and read it entirely into a an allocated buffer
876 ******************************************************************************/
890 /* Binary mode leaves CR/LF pairs */
892 File
= fopen (Filename
, "rb");
895 printf ("Could not open file %s\n", Filename
);
899 /* Need file size to allocate a buffer */
901 Size
= CmGetFileSize (File
);
902 if (Size
== ACPI_UINT32_MAX
)
904 printf ("Could not get file size for %s\n", Filename
);
909 * Create a buffer for the entire file
910 * Add plenty extra buffer to accommodate string replacements
912 Gbl_TotalSize
+= Size
;
914 Buffer
= calloc (Size
* 2, 1);
917 printf ("Could not allocate buffer of size %u\n", Size
* 2);
921 /* Read the entire file */
923 Actual
= fread (Buffer
, 1, Size
, File
);
926 printf ("Could not read the input file %s (%u bytes)\n",
931 Buffer
[Size
] = 0; /* Null terminate the buffer */
934 /* This option checks the entire file for non-printable chars */
938 if (AsCheckForNonPrintableChars (Buffer
, Size
))
940 printf ("File contains only printable ASCII characters\n");
947 /* Check for unix contamination */
949 Gbl_HasLoneLineFeeds
= AsDetectLoneLineFeeds (Filename
, Buffer
);
952 * Convert all CR/LF pairs to LF only. We do this locally so that
953 * this code is portable across operating systems.
955 AsConvertToLineFeeds (Buffer
);
957 *FileBuffer
= Buffer
;
970 /******************************************************************************
972 * FUNCTION: AsPutFile
974 * DESCRIPTION: Create a new output file and write the entire contents of the
975 * buffer to the new file. Buffer must be a zero terminated string
977 ******************************************************************************/
991 /* Create the target file */
993 if (!(SystemFlags
& FLG_NO_CARRIAGE_RETURNS
))
995 /* Put back the CR before each LF */
997 AsInsertCarriageReturns (FileBuffer
);
1000 File
= fopen (Pathname
, "w+b");
1003 perror ("Could not create destination file");
1004 printf ("Could not create destination file \"%s\"\n", Pathname
);
1008 /* Write the buffer to the file */
1010 FileSize
= strlen (FileBuffer
);
1011 Actual
= fwrite (FileBuffer
, 1, FileSize
, File
);
1012 if (Actual
!= FileSize
)
1014 printf ("Error writing output file \"%s\"\n", Pathname
);