2 /******************************************************************************
4 * Module Name: asconvrt - Source conversion code
6 *****************************************************************************/
8 /******************************************************************************
12 * Some or all of this work - Copyright (c) 1999 - 2009, Intel Corp.
13 * All rights reserved.
17 * 2.1. This is your license from Intel Corp. under its intellectual property
18 * rights. You may have additional license terms from the party that provided
19 * you this software, covering your right to use that party's intellectual
22 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
23 * copy of the source code appearing in this file ("Covered Code") an
24 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
25 * base code distributed originally by Intel ("Original Intel Code") to copy,
26 * make derivatives, distribute, use and display any portion of the Covered
27 * Code in any form, with the right to sublicense such rights; and
29 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
30 * license (with the right to sublicense), under only those claims of Intel
31 * patents that are infringed by the Original Intel Code, to make, use, sell,
32 * offer to sell, and import the Covered Code and derivative works thereof
33 * solely to the minimum extent necessary to exercise the above copyright
34 * license, and in no event shall the patent license extend to any additions
35 * to or modifications of the Original Intel Code. No other license or right
36 * is granted directly or by implication, estoppel or otherwise;
38 * The above copyright and patent license is granted only if the following
43 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
44 * Redistribution of source code of any substantial portion of the Covered
45 * Code or modification with rights to further distribute source must include
46 * the above Copyright Notice, the above License, this list of Conditions,
47 * and the following Disclaimer and Export Compliance provision. In addition,
48 * Licensee must cause all Covered Code to which Licensee contributes to
49 * contain a file documenting the changes Licensee made to create that Covered
50 * Code and the date of any change. Licensee must include in that file the
51 * documentation of any changes made by any predecessor Licensee. Licensee
52 * must include a prominent statement that the modification is derived,
53 * directly or indirectly, from Original Intel Code.
55 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
56 * Redistribution of source code of any substantial portion of the Covered
57 * Code or modification without rights to further distribute source must
58 * include the following Disclaimer and Export Compliance provision in the
59 * documentation and/or other materials provided with distribution. In
60 * addition, Licensee may not authorize further sublicense of source of any
61 * portion of the Covered Code, and must include terms to the effect that the
62 * license from Licensee to its licensee is limited to the intellectual
63 * property embodied in the software Licensee provides to its licensee, and
64 * not to intellectual property embodied in modifications its licensee may
67 * 3.3. Redistribution of Executable. Redistribution in executable form of any
68 * substantial portion of the Covered Code or modification must reproduce the
69 * above Copyright Notice, and the following Disclaimer and Export Compliance
70 * provision in the documentation and/or other materials provided with the
73 * 3.4. Intel retains all right, title, and interest in and to the Original
76 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
77 * Intel shall be used in advertising or otherwise to promote the sale, use or
78 * other dealings in products derived from or relating to the Covered Code
79 * without prior written authorization from Intel.
81 * 4. Disclaimer and Export Compliance
83 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
84 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
85 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
86 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
87 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
88 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
91 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
92 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
93 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
94 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
95 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
96 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
97 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
100 * 4.3. Licensee shall not export, either directly or indirectly, any of this
101 * software or system incorporating such software without first obtaining any
102 * required license or other approval from the U. S. Department of Commerce or
103 * any other agency or department of the United States Government. In the
104 * event Licensee exports any such software from the United States or
105 * re-exports any such software from a foreign destination, Licensee shall
106 * ensure that the distribution and export/re-export of the software is in
107 * compliance with all laws, regulations, orders, or other restrictions of the
108 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
109 * any of its subsidiaries will export/re-export any technical data, process,
110 * software, or service, directly or indirectly, to any country for which the
111 * United States government or any agency thereof requires an export license,
112 * other governmental approval, or letter of assurance, without first obtaining
113 * such license, approval or letter.
115 *****************************************************************************/
119 /* Local prototypes */
122 AsCheckAndSkipLiterals (
131 /* Opening signature of the Intel legal header */
133 char *HeaderBegin
= "/******************************************************************************\n *\n * 1. Copyright Notice";
136 /******************************************************************************
138 * FUNCTION: AsMatchExactWord
140 * DESCRIPTION: Check previous and next characters for whitespace
142 ******************************************************************************/
153 NextChar
= Word
[WordLength
];
154 PrevChar
= * (Word
-1);
156 if (isalnum (NextChar
) ||
158 isalnum (PrevChar
) ||
168 /******************************************************************************
172 * DESCRIPTION: Common formatted print
174 ******************************************************************************/
188 printf ("-- %4u %28.28s : %s\n", Count
, Message
, Filename
);
192 /******************************************************************************
194 * FUNCTION: AsCheckAndSkipLiterals
196 * DESCRIPTION: Generic routine to skip comments and quoted string literals.
197 * Keeps a line count.
199 ******************************************************************************/
202 AsCheckAndSkipLiterals (
207 char *SubBuffer
= Buffer
;
211 /* Ignore comments */
213 if ((SubBuffer
[0] == '/') &&
214 (SubBuffer
[1] == '*'))
216 LiteralEnd
= strstr (SubBuffer
, "*/");
217 SubBuffer
+= 2; /* Get past comment opening */
224 while (SubBuffer
< LiteralEnd
)
226 if (*SubBuffer
== '\n')
234 SubBuffer
+= 2; /* Get past comment close */
237 /* Ignore quoted strings */
239 else if (*SubBuffer
== '\"')
242 LiteralEnd
= AsSkipPastChar (SubBuffer
, '\"');
251 (*TotalLines
) += NewLines
;
257 /******************************************************************************
259 * FUNCTION: AsAsCheckForBraces
261 * DESCRIPTION: Check for an open brace after each if statement
263 ******************************************************************************/
270 char *SubBuffer
= Buffer
;
274 UINT32 TotalLines
= 1;
280 SubBuffer
= AsCheckAndSkipLiterals (SubBuffer
, &TotalLines
);
282 if (*SubBuffer
== '\n')
286 else if (!(strncmp (" if", SubBuffer
, 3)))
289 NextBrace
= strstr (SubBuffer
, "{");
290 NextSemicolon
= strstr (SubBuffer
, ";");
291 NextIf
= strstr (SubBuffer
, " if");
294 (NextSemicolon
&& (NextBrace
> NextSemicolon
)) ||
295 (NextIf
&& (NextBrace
> NextIf
)))
301 printf ("Missing braces for <if>, line %d: %s\n", TotalLines
, Filename
);
305 else if (!(strncmp (" else if", SubBuffer
, 8)))
308 NextBrace
= strstr (SubBuffer
, "{");
309 NextSemicolon
= strstr (SubBuffer
, ";");
310 NextIf
= strstr (SubBuffer
, " if");
313 (NextSemicolon
&& (NextBrace
> NextSemicolon
)) ||
314 (NextIf
&& (NextBrace
> NextIf
)))
320 printf ("Missing braces for <if>, line %d: %s\n", TotalLines
, Filename
);
324 else if (!(strncmp (" else", SubBuffer
, 5)))
327 NextBrace
= strstr (SubBuffer
, "{");
328 NextSemicolon
= strstr (SubBuffer
, ";");
329 NextIf
= strstr (SubBuffer
, " if");
332 (NextSemicolon
&& (NextBrace
> NextSemicolon
)) ||
333 (NextIf
&& (NextBrace
> NextIf
)))
339 printf ("Missing braces for <else>, line %d: %s\n", TotalLines
, Filename
);
349 /******************************************************************************
351 * FUNCTION: AsTrimLines
353 * DESCRIPTION: Remove extra blanks from the end of source lines. Does not
356 ******************************************************************************/
363 char *SubBuffer
= Buffer
;
364 char *StartWhiteSpace
= NULL
;
365 UINT32 SpaceCount
= 0;
370 while (*SubBuffer
!= '\n')
377 if (*SubBuffer
== ' ')
379 if (!StartWhiteSpace
)
381 StartWhiteSpace
= SubBuffer
;
386 StartWhiteSpace
= NULL
;
394 SpaceCount
+= (SubBuffer
- StartWhiteSpace
);
396 /* Remove the spaces */
398 SubBuffer
= AsRemoveData (StartWhiteSpace
, SubBuffer
);
399 StartWhiteSpace
= NULL
;
409 Gbl_MadeChanges
= TRUE
;
410 AsPrint ("Extraneous spaces removed", SpaceCount
, Filename
);
415 /******************************************************************************
417 * FUNCTION: AsTrimWhitespace
419 * DESCRIPTION: Remove "excess" blank lines - any more than 2 blank lines.
420 * this can happen during the translation when lines are removed.
422 ******************************************************************************/
428 int ReplaceCount
= 1;
433 ReplaceCount
= AsReplaceString ("\n\n\n\n", "\n\n\n", REPLACE_SUBSTRINGS
, Buffer
);
438 /******************************************************************************
440 * FUNCTION: AsReplaceHeader
442 * DESCRIPTION: Replace the default Intel legal header with a new header
444 ******************************************************************************/
455 /* Find the original header */
457 SubBuffer
= strstr (Buffer
, HeaderBegin
);
463 /* Find the end of the original header */
465 TokenEnd
= strstr (SubBuffer
, "*/");
466 TokenEnd
= AsSkipPastChar (TokenEnd
, '\n');
468 /* Delete old header, insert new one */
470 AsReplaceData (SubBuffer
, TokenEnd
- SubBuffer
, NewHeader
, strlen (NewHeader
));
474 /******************************************************************************
476 * FUNCTION: AsReplaceString
478 * DESCRIPTION: Replace all instances of a target string with a replacement
479 * string. Returns count of the strings replaced.
481 ******************************************************************************/
494 int ReplacementLength
;
495 int ReplaceCount
= 0;
498 TargetLength
= strlen (Target
);
499 ReplacementLength
= strlen (Replacement
);
506 /* Find the target string */
508 SubString1
= strstr (SubBuffer
, Target
);
515 * Check for translation escape string -- means to ignore
516 * blocks of code while replacing
518 SubString2
= strstr (SubBuffer
, AS_START_IGNORE
);
521 (SubString2
< SubString1
))
523 /* Find end of the escape block starting at "Substring2" */
525 SubString2
= strstr (SubString2
, AS_STOP_IGNORE
);
528 /* Didn't find terminator */
533 /* Move buffer to end of escape block and continue */
535 SubBuffer
= SubString2
;
538 /* Do the actual replace if the target was found */
542 if ((Type
& REPLACE_MASK
) == REPLACE_WHOLE_WORD
)
544 if (!AsMatchExactWord (SubString1
, TargetLength
))
546 SubBuffer
= SubString1
+ 1;
551 SubBuffer
= AsReplaceData (SubString1
, TargetLength
, Replacement
, ReplacementLength
);
553 if ((Type
& EXTRA_INDENT_C
) &&
556 SubBuffer
= AsInsertData (SubBuffer
, " ", 8);
567 /******************************************************************************
569 * FUNCTION: AsConvertToLineFeeds
573 ******************************************************************************/
576 AsConvertToLineFeeds (
588 /* Find the target string */
590 SubString
= strstr (SubBuffer
, "\r\n");
596 SubBuffer
= AsReplaceData (SubString
, 1, NULL
, 0);
602 /******************************************************************************
604 * FUNCTION: AsInsertCarriageReturns
608 ******************************************************************************/
611 AsInsertCarriageReturns (
623 /* Find the target string */
625 SubString
= strstr (SubBuffer
, "\n");
631 SubBuffer
= AsInsertData (SubString
, "\r", 1);
638 /******************************************************************************
640 * FUNCTION: AsBracesOnSameLine
642 * DESCRIPTION: Move opening braces up to the same line as an if, for, else,
643 * or while statement (leave function opening brace on separate
646 ******************************************************************************/
653 char *SubBuffer
= Buffer
;
655 char *StartOfThisLine
;
657 BOOLEAN BlockBegin
= TRUE
;
662 /* Ignore comments */
664 if ((SubBuffer
[0] == '/') &&
665 (SubBuffer
[1] == '*'))
667 SubBuffer
= strstr (SubBuffer
, "*/");
677 /* Ignore quoted strings */
679 if (*SubBuffer
== '\"')
682 SubBuffer
= AsSkipPastChar (SubBuffer
, '\"');
689 if (!strncmp ("\n}", SubBuffer
, 2))
692 * A newline followed by a closing brace closes a function
693 * or struct or initializer block
699 * Move every standalone brace up to the previous line
700 * Check for digit will ignore initializer lists surrounded by braces.
701 * This will work until we we need more complex detection.
703 if ((*SubBuffer
== '{') && !isdigit (SubBuffer
[1]))
712 * Backup to previous non-whitespace
714 Beginning
= SubBuffer
- 1;
715 while ((*Beginning
== ' ') ||
716 (*Beginning
== '\n'))
721 StartOfThisLine
= Beginning
;
722 while (*StartOfThisLine
!= '\n')
728 * Move the brace up to the previous line, UNLESS:
730 * 1) There is a conditional compile on the line (starts with '#')
731 * 2) Previous line ends with an '=' (Start of initializer block)
732 * 3) Previous line ends with a comma (part of an init list)
733 * 4) Previous line ends with a backslash (part of a macro)
735 if ((StartOfThisLine
[1] != '#') &&
736 (*Beginning
!= '\\') &&
737 (*Beginning
!= '/') &&
738 (*Beginning
!= '{') &&
739 (*Beginning
!= '=') &&
744 Length
= strlen (SubBuffer
);
746 Gbl_MadeChanges
= TRUE
;
748 #ifdef ADD_EXTRA_WHITESPACE
749 AsReplaceData (Beginning
, SubBuffer
- Beginning
, " {\n", 3);
751 /* Find non-whitespace start of next line */
753 Next
= SubBuffer
+ 1;
754 while ((*Next
== ' ') ||
760 /* Find non-whitespace start of this line */
763 while ((*StartOfThisLine
== ' ') ||
764 (*StartOfThisLine
== '\t'))
770 * Must be a single-line comment to need more whitespace
771 * Even then, we don't need more if the previous statement
774 if ((Next
[0] == '/') &&
778 (!strncmp (StartOfThisLine
, "else if", 7) ||
779 !strncmp (StartOfThisLine
, "else while", 10) ||
780 strncmp (StartOfThisLine
, "else", 4)))
782 AsReplaceData (Beginning
, SubBuffer
- Beginning
, " {\n", 3);
786 AsReplaceData (Beginning
, SubBuffer
- Beginning
, " {", 2);
798 /******************************************************************************
800 * FUNCTION: AsTabify4
802 * DESCRIPTION: Convert the text to tabbed text. Alignment of text is
805 ******************************************************************************/
811 char *SubBuffer
= Buffer
;
813 UINT32 SpaceCount
= 0;
819 if (*SubBuffer
== '\n')
828 /* Ignore comments */
830 if ((SubBuffer
[0] == '/') &&
831 (SubBuffer
[1] == '*'))
833 SubBuffer
= strstr (SubBuffer
, "*/");
843 /* Ignore quoted strings */
845 if (*SubBuffer
== '\"')
848 SubBuffer
= AsSkipPastChar (SubBuffer
, '\"');
856 if (*SubBuffer
== ' ')
864 NewSubBuffer
= (SubBuffer
+ 1) - 4;
865 *NewSubBuffer
= '\t';
868 /* Remove the spaces */
870 SubBuffer
= AsRemoveData (NewSubBuffer
, SubBuffer
+ 1);
873 if ((Column
% 4) == 0)
888 /******************************************************************************
890 * FUNCTION: AsTabify8
892 * DESCRIPTION: Convert the text to tabbed text. Alignment of text is
895 ******************************************************************************/
901 char *SubBuffer
= Buffer
;
903 char *CommentEnd
= NULL
;
904 UINT32 SpaceCount
= 0;
907 UINT32 LastLineTabCount
= 0;
908 UINT32 LastLineColumnStart
= 0;
909 UINT32 ThisColumnStart
= 0;
910 UINT32 ThisTabCount
= 0;
911 char *FirstNonBlank
= NULL
;
916 if (*SubBuffer
== '\n')
918 /* This is a standalone blank line */
920 FirstNonBlank
= NULL
;
930 /* Find the first non-blank character on this line */
932 FirstNonBlank
= SubBuffer
;
933 while (*FirstNonBlank
== ' ')
939 * This mechanism limits the difference in tab counts from
940 * line to line. It helps avoid the situation where a second
941 * continuation line (which was indented correctly for tabs=4) would
942 * get indented off the screen if we just blindly converted to tabs.
944 ThisColumnStart
= FirstNonBlank
- SubBuffer
;
946 if (LastLineTabCount
== 0)
950 else if (ThisColumnStart
== LastLineColumnStart
)
952 ThisTabCount
= LastLineTabCount
-1;
956 ThisTabCount
= LastLineTabCount
+ 1;
962 /* Check if we are in a comment */
964 if ((SubBuffer
[0] == '*') &&
965 (SubBuffer
[1] == '/'))
970 if (*SubBuffer
== '\n')
974 LastLineTabCount
= TabCount
;
977 FirstNonBlank
= NULL
;
978 LastLineColumnStart
= ThisColumnStart
;
985 /* Check for comment open */
987 if ((SubBuffer
[0] == '/') &&
988 (SubBuffer
[1] == '*'))
990 /* Find the end of the comment, it must exist */
992 CommentEnd
= strstr (SubBuffer
, "*/");
998 /* Toss the rest of this line or single-line comment */
1000 while ((SubBuffer
< CommentEnd
) &&
1001 (*SubBuffer
!= '\n'))
1006 if (*SubBuffer
== '\n')
1010 LastLineTabCount
= TabCount
;
1013 FirstNonBlank
= NULL
;
1014 LastLineColumnStart
= ThisColumnStart
;
1021 /* Ignore quoted strings */
1023 if ((!CommentEnd
) && (*SubBuffer
== '\"'))
1026 SubBuffer
= AsSkipPastChar (SubBuffer
, '\"');
1034 if (*SubBuffer
!= ' ')
1036 /* Not a space, skip to end of line */
1038 SubBuffer
= AsSkipUntilChar (SubBuffer
, '\n');
1045 LastLineTabCount
= TabCount
;
1049 FirstNonBlank
= NULL
;
1050 LastLineColumnStart
= ThisColumnStart
;
1060 if (SpaceCount
>= 4)
1062 /* Replace this group of spaces with a tab character */
1066 NewSubBuffer
= SubBuffer
- 3;
1068 if (TabCount
<= ThisTabCount
? (ThisTabCount
+1) : 0)
1070 *NewSubBuffer
= '\t';
1076 /* Remove the spaces */
1078 SubBuffer
= AsRemoveData (NewSubBuffer
, SubBuffer
);
1088 /******************************************************************************
1090 * FUNCTION: AsCountLines
1092 * DESCRIPTION: Count the number of lines in the input buffer. Also count
1093 * the number of long lines (lines longer than 80 chars).
1095 ******************************************************************************/
1102 char *SubBuffer
= Buffer
;
1104 UINT32 LineCount
= 0;
1105 UINT32 LongLineCount
= 0;
1110 EndOfLine
= AsSkipUntilChar (SubBuffer
, '\n');
1113 Gbl_TotalLines
+= LineCount
;
1117 if ((EndOfLine
- SubBuffer
) > 80)
1120 VERBOSE_PRINT (("long: %.80s\n", SubBuffer
));
1124 SubBuffer
= EndOfLine
+ 1;
1129 VERBOSE_PRINT (("%d Lines longer than 80 found in %s\n", LongLineCount
, Filename
));
1130 Gbl_LongLines
+= LongLineCount
;
1133 Gbl_TotalLines
+= LineCount
;
1138 /******************************************************************************
1140 * FUNCTION: AsCountTabs
1142 * DESCRIPTION: Simply count the number of tabs in the input file buffer
1144 ******************************************************************************/
1152 UINT32 TabCount
= 0;
1155 for (i
= 0; Buffer
[i
]; i
++)
1157 if (Buffer
[i
] == '\t')
1165 AsPrint ("Tabs found", TabCount
, Filename
);
1166 Gbl_Tabs
+= TabCount
;
1169 AsCountLines (Buffer
, Filename
);
1173 /******************************************************************************
1175 * FUNCTION: AsCountNonAnsiComments
1177 * DESCRIPTION: Count the number of "//" comments. This type of comment is
1180 ******************************************************************************/
1183 AsCountNonAnsiComments (
1187 char *SubBuffer
= Buffer
;
1188 UINT32 CommentCount
= 0;
1193 SubBuffer
= strstr (SubBuffer
, "//");
1203 AsPrint ("Non-ANSI Comments found", CommentCount
, Filename
);
1204 Gbl_NonAnsiComments
+= CommentCount
;
1209 /******************************************************************************
1211 * FUNCTION: AsCountSourceLines
1213 * DESCRIPTION: Count the number of C source lines. Defined by 1) not a
1214 * comment, and 2) not a blank line.
1216 ******************************************************************************/
1219 AsCountSourceLines (
1223 char *SubBuffer
= Buffer
;
1224 UINT32 LineCount
= 0;
1225 UINT32 WhiteCount
= 0;
1226 UINT32 CommentCount
= 0;
1231 /* Detect comments (// comments are not used, non-ansii) */
1233 if ((SubBuffer
[0] == '/') &&
1234 (SubBuffer
[1] == '*'))
1238 /* First line of multi-line comment is often just whitespace */
1240 if (SubBuffer
[0] == '\n')
1250 /* Find end of comment */
1252 while (SubBuffer
[0] && SubBuffer
[1] &&
1253 !(((SubBuffer
[0] == '*') &&
1254 (SubBuffer
[1] == '/'))))
1256 if (SubBuffer
[0] == '\n')
1265 /* A linefeed followed by a non-linefeed is a valid source line */
1267 else if ((SubBuffer
[0] == '\n') &&
1268 (SubBuffer
[1] != '\n'))
1273 /* Two back-to-back linefeeds indicate a whitespace line */
1275 else if ((SubBuffer
[0] == '\n') &&
1276 (SubBuffer
[1] == '\n'))
1284 /* Adjust comment count for legal header */
1286 if (Gbl_HeaderSize
< CommentCount
)
1288 CommentCount
-= Gbl_HeaderSize
;
1289 Gbl_HeaderLines
+= Gbl_HeaderSize
;
1292 Gbl_SourceLines
+= LineCount
;
1293 Gbl_WhiteLines
+= WhiteCount
;
1294 Gbl_CommentLines
+= CommentCount
;
1296 VERBOSE_PRINT (("%d Comment %d White %d Code %d Lines in %s\n",
1297 CommentCount
, WhiteCount
, LineCount
, LineCount
+WhiteCount
+CommentCount
, Filename
));
1301 /******************************************************************************
1303 * FUNCTION: AsInsertPrefix
1305 * DESCRIPTION: Insert struct or union prefixes
1307 ******************************************************************************/
1322 char LowerKeyword
[128];
1328 case SRC_TYPE_STRUCT
:
1329 InsertString
= "struct ";
1332 case SRC_TYPE_UNION
:
1333 InsertString
= "union ";
1340 strcpy (LowerKeyword
, Keyword
);
1341 strlwr (LowerKeyword
);
1345 InsertLength
= strlen (InsertString
);
1346 KeywordLength
= strlen (Keyword
);
1351 /* Find an instance of the keyword */
1353 SubString
= strstr (SubBuffer
, LowerKeyword
);
1360 SubBuffer
= SubString
;
1362 /* Must be standalone word, not a substring */
1364 if (AsMatchExactWord (SubString
, KeywordLength
))
1366 /* Make sure the keyword isn't already prefixed with the insert */
1368 if (!strncmp (SubString
- InsertLength
, InsertString
, InsertLength
))
1370 /* Add spaces if not already at the end-of-line */
1372 if (*(SubBuffer
+ KeywordLength
) != '\n')
1374 /* Already present, add spaces after to align structure members */
1377 /* ONLY FOR C FILES */
1378 AsInsertData (SubBuffer
+ KeywordLength
, " ", 8);
1384 /* Make sure the keyword isn't at the end of a struct/union */
1385 /* Note: This code depends on a single space after the brace */
1387 if (*(SubString
- 2) == '}')
1392 /* Prefix the keyword with the insert string */
1394 Gbl_MadeChanges
= TRUE
;
1395 StrLength
= strlen (SubString
);
1397 /* Is there room for insertion */
1399 EndKeyword
= SubString
+ strlen (LowerKeyword
);
1402 while (EndKeyword
[TrailingSpaces
] == ' ')
1408 * Use "if (TrailingSpaces > 1)" if we want to ignore casts
1410 SubBuffer
= SubString
+ InsertLength
;
1412 if (TrailingSpaces
> InsertLength
)
1414 /* Insert the keyword */
1416 memmove (SubBuffer
, SubString
, KeywordLength
);
1418 /* Insert the keyword */
1420 memmove (SubString
, InsertString
, InsertLength
);
1424 AsInsertData (SubString
, InsertString
, InsertLength
);
1429 SubBuffer
+= KeywordLength
;
1433 #ifdef ACPI_FUTURE_IMPLEMENTATION
1434 /******************************************************************************
1436 * FUNCTION: AsTrimComments
1438 * DESCRIPTION: Finds 3-line comments with only a single line of text
1440 ******************************************************************************/
1447 char *SubBuffer
= Buffer
;
1451 UINT32 ShortCommentCount
= 0;
1456 /* Find comment open, within procedure level */
1458 SubBuffer
= strstr (SubBuffer
, " /*");
1464 /* Find comment terminator */
1466 Ptr1
= strstr (SubBuffer
, "*/");
1472 /* Find next EOL (from original buffer) */
1474 Ptr2
= strstr (SubBuffer
, "\n");
1480 /* Ignore one-line comments */
1484 /* Normal comment, ignore and continue; */
1490 /* Examine multi-line comment */
1498 Ptr2
= strstr (Ptr2
, "\n");
1511 ShortCommentCount
++;
1518 if (ShortCommentCount
)
1520 AsPrint ("Short Comments found", ShortCommentCount
, Filename
);