2 /******************************************************************************
4 * Module Name: asremove - Source conversion - removal functions
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 */
128 /******************************************************************************
130 * FUNCTION: AsRemoveStatement
132 * DESCRIPTION: Remove all statements that contain the given keyword.
133 * Limitations: Removes text from the start of the line that
134 * contains the keyword to the next semicolon. Currently
135 * doesn't ignore comments.
137 ******************************************************************************/
150 KeywordLength
= strlen (Keyword
);
157 SubString
= strstr (SubBuffer
, Keyword
);
161 SubBuffer
= SubString
;
163 if ((Type
== REPLACE_WHOLE_WORD
) &&
164 (!AsMatchExactWord (SubString
, KeywordLength
)))
170 /* Find start of this line */
172 while (*SubString
!= '\n')
178 /* Find end of this statement */
180 SubBuffer
= AsSkipPastChar (SubBuffer
, ';');
186 /* Find end of this line */
188 SubBuffer
= AsSkipPastChar (SubBuffer
, '\n');
194 /* If next line is blank, remove it too */
196 if (*SubBuffer
== '\n')
201 /* Remove the lines */
203 SubBuffer
= AsRemoveData (SubString
, SubBuffer
);
209 /******************************************************************************
211 * FUNCTION: AsRemoveConditionalCompile
213 * DESCRIPTION: Remove a "#ifdef" statement, and all text that it encompasses.
214 * Limitations: cannot handle nested ifdefs.
216 ******************************************************************************/
219 AsRemoveConditionalCompile (
232 KeywordLength
= strlen (Keyword
);
239 SubBuffer
= strstr (SubString
, Keyword
);
246 * Check for translation escape string -- means to ignore
247 * blocks of code while replacing
249 Comment
= strstr (SubString
, AS_START_IGNORE
);
252 (Comment
< SubBuffer
))
254 SubString
= strstr (Comment
, AS_STOP_IGNORE
);
264 /* Check for ordinary comment */
266 Comment
= strstr (SubString
, "/*");
269 (Comment
< SubBuffer
))
271 SubString
= strstr (Comment
, "*/");
281 SubString
= SubBuffer
;
282 if (!AsMatchExactWord (SubString
, KeywordLength
))
288 /* Find start of this line */
290 while (*SubString
!= '\n' && (SubString
> Buffer
))
296 /* Find the "#ifxxxx" */
298 IfPtr
= strstr (SubString
, "#if");
304 if (IfPtr
> SubBuffer
)
306 /* Not the right #if */
308 SubString
= SubBuffer
+ strlen (Keyword
);
312 /* Find closing #endif or #else */
314 EndifPtr
= strstr (SubBuffer
, "#endif");
317 /* There has to be an #endif */
322 ElsePtr
= strstr (SubBuffer
, "#else");
324 (EndifPtr
> ElsePtr
))
326 /* This #ifdef contains an #else clause */
327 /* Find end of this line */
329 SubBuffer
= AsSkipPastChar (ElsePtr
, '\n');
335 /* Remove the #ifdef .... #else code */
337 AsRemoveData (SubString
, SubBuffer
);
339 /* Next, we will remove the #endif statement */
341 EndifPtr
= strstr (SubString
, "#endif");
344 /* There has to be an #endif */
349 SubString
= EndifPtr
;
352 /* Remove the ... #endif part */
353 /* Find end of this line */
355 SubBuffer
= AsSkipPastChar (EndifPtr
, '\n');
361 /* Remove the lines */
363 SubBuffer
= AsRemoveData (SubString
, SubBuffer
);
368 /******************************************************************************
370 * FUNCTION: AsRemoveMacro
372 * DESCRIPTION: Remove every line that contains the keyword. Does not
375 ******************************************************************************/
393 SubString
= strstr (SubBuffer
, Keyword
);
397 SubBuffer
= SubString
;
399 /* Find start of the macro parameters */
401 while (*SubString
!= '(')
407 /* Remove the macro name and opening paren */
409 SubString
= AsRemoveData (SubBuffer
, SubString
);
414 if (*SubString
== '(')
418 else if (*SubString
== ')')
431 /* Remove the closing paren */
433 SubBuffer
= AsRemoveData (SubString
-1, SubString
);
439 /******************************************************************************
441 * FUNCTION: AsRemoveLine
443 * DESCRIPTION: Remove every line that contains the keyword. Does not
446 ******************************************************************************/
463 SubString
= strstr (SubBuffer
, Keyword
);
467 SubBuffer
= SubString
;
469 /* Find start of this line */
471 while (*SubString
!= '\n')
477 /* Find end of this line */
479 SubBuffer
= AsSkipPastChar (SubBuffer
, '\n');
485 /* Remove the line */
487 SubBuffer
= AsRemoveData (SubString
, SubBuffer
);
493 /******************************************************************************
495 * FUNCTION: AsReduceTypedefs
497 * DESCRIPTION: Eliminate certain typedefs
499 ******************************************************************************/
517 SubString
= strstr (SubBuffer
, Keyword
);
521 /* Remove the typedef itself */
523 SubBuffer
= SubString
+ strlen ("typedef") + 1;
524 SubBuffer
= AsRemoveData (SubString
, SubBuffer
);
526 /* Find the opening brace of the struct or union */
528 while (*SubString
!= '{')
534 /* Find the closing brace. Handles nested braces */
539 if (*SubString
== '{')
543 else if (*SubString
== '}')
556 /* Remove an extra line feed if present */
558 if (!strncmp (SubString
- 3, "\n\n", 2))
560 *(SubString
-2) = '}';
564 /* Find the end of the typedef name */
566 SubBuffer
= AsSkipUntilChar (SubString
, ';');
568 /* And remove the typedef name */
570 SubBuffer
= AsRemoveData (SubString
, SubBuffer
);
576 /******************************************************************************
578 * FUNCTION: AsRemoveEmptyBlocks
580 * DESCRIPTION: Remove any C blocks (e.g., if {}) that contain no code. This
581 * can happen as a result of removing lines such as DEBUG_PRINT.
583 ******************************************************************************/
586 AsRemoveEmptyBlocks (
592 BOOLEAN EmptyBlock
= TRUE
;
593 BOOLEAN AnotherPassRequired
= TRUE
;
594 UINT32 BlockCount
= 0;
597 while (AnotherPassRequired
)
600 AnotherPassRequired
= FALSE
;
604 if (*SubBuffer
== '{')
606 BlockStart
= SubBuffer
;
610 while (*SubBuffer
!= '}')
612 if ((*SubBuffer
!= ' ') &&
613 (*SubBuffer
!= '\n'))
623 /* Find start of the first line of the block */
625 while (*BlockStart
!= '\n')
630 /* Find end of the last line of the block */
632 SubBuffer
= AsSkipUntilChar (SubBuffer
, '\n');
638 /* Remove the block */
640 SubBuffer
= AsRemoveData (BlockStart
, SubBuffer
);
642 AnotherPassRequired
= TRUE
;
653 Gbl_MadeChanges
= TRUE
;
654 AsPrint ("Code blocks deleted", BlockCount
, Filename
);
659 /******************************************************************************
661 * FUNCTION: AsRemoveDebugMacros
663 * DESCRIPTION: Remove all "Debug" macros -- macros that produce debug output.
665 ******************************************************************************/
668 AsRemoveDebugMacros (
671 AsRemoveConditionalCompile (Buffer
, "ACPI_DEBUG_OUTPUT");
673 AsRemoveStatement (Buffer
, "ACPI_DEBUG_PRINT", REPLACE_WHOLE_WORD
);
674 AsRemoveStatement (Buffer
, "ACPI_DEBUG_PRINT_RAW", REPLACE_WHOLE_WORD
);
675 AsRemoveStatement (Buffer
, "DEBUG_EXEC", REPLACE_WHOLE_WORD
);
676 AsRemoveStatement (Buffer
, "FUNCTION_ENTRY", REPLACE_WHOLE_WORD
);
677 AsRemoveStatement (Buffer
, "PROC_NAME", REPLACE_WHOLE_WORD
);
678 AsRemoveStatement (Buffer
, "FUNCTION_TRACE", REPLACE_SUBSTRINGS
);
679 AsRemoveStatement (Buffer
, "DUMP_", REPLACE_SUBSTRINGS
);
681 AsReplaceString ("return_VOID", "return", REPLACE_WHOLE_WORD
, Buffer
);
682 AsReplaceString ("return_PTR", "return", REPLACE_WHOLE_WORD
, Buffer
);
683 AsReplaceString ("return_ACPI_STATUS", "return", REPLACE_WHOLE_WORD
, Buffer
);
684 AsReplaceString ("return_acpi_status", "return", REPLACE_WHOLE_WORD
, Buffer
);
685 AsReplaceString ("return_VALUE", "return", REPLACE_WHOLE_WORD
, Buffer
);