AcpiSrc: Fix indentation issues for macro invocations.

During the linuxizing process, some extra white spaces are added by the
"indent" program at the beginning of the line which is an invocation of a
macro and there is no ";" at the end of the line.

This patch adds new mode to AcpiSrc to remove extra spaces inserted before
invoking such macros and add an empty line between the invocations of such
macros (like the other function declarations).  This new mode is executed
after executing "indent" during the Linux release process.

The affected macros and files are:
 1. ACPI_HW_DEPENDENT_RETURN (acpixf.h):
    This macro is used as a wrapper for hardware dependent APIs to offer a
    stub when the reduced hardware is configured during compilation.
 2. ACPI_EXPORT_SYMBOL (utglobal.c):
    This macro is used by Linux to export symbols to be found by Linux
    modules.  All such invocations are well formatted except those exported
    as global variables.

This can help to reduce the source code differences between Linux and
ACPICA, and also help to automate the release process.  Lv Zheng.
This commit is contained in:
Robert Moore 2013-09-26 08:33:05 -07:00
parent e093a60d8b
commit d09bc88ad2
6 changed files with 207 additions and 8 deletions

View File

@ -88,6 +88,15 @@ acpica_exclude_paths()
echo $paths
}
acpica_indent_fixing_files()
{
files="\
drivers/acpi/acpica/utglobal.c \
include/acpi/acpixf.h \
"
echo $files
}
fulldir()
{
( cd $1; pwd )
@ -169,17 +178,50 @@ make_acpisrc()
make_tool $1 acpisrc
}
lindent_single()
{
fixup=no
fixing_files=`acpica_indent_fixing_files`
for f in $fixing_files; do
if [ $1 == $f ]; then
fixup=yes
fi
done
acpi_types="\
u8 \
u16 \
u32 \
u64 \
acpi_integer \
acpi_predefined_data \
acpi_operand_object \
acpi_event_status \
"
INDENT_FLAGS="-npro -kr -i8 -ts8 -sob -l80 -ss -ncs -il0"
for t in $acpi_types; do
INDENT_FLAGS="$INDENT_FLAGS -T $t"
done
dos2unix $1 > /dev/null 2>&1
indent $INDENT_FLAGS $1
if [ "x$fixup" == "xyes" ]; then
echo " Fixing indentation of file $1..."
$ACPISRC -idqy $1 $1 > /dev/null
fi
}
lindent()
{
(
cd $1
find . -name "*.[ch]" | xargs indent \
-npro -kr -i8 -ts8 -sob -l80 -ss -ncs -il0 \
-T u8 -T u16 -T u32 -T u64 \
-T acpi_integer \
-T acpi_predefined_data \
-T acpi_operand_object \
-T acpi_event_status
files=`find . -name "*.[ch]" | cut -c3-`
for f in $files; do
lindent_single $f
done
find . -name "*~" | xargs rm -f
)
}

View File

@ -249,6 +249,7 @@ typedef struct acpi_conversion_table
ACPI_IDENTIFIER_TABLE *SourceConditionalTable;
ACPI_IDENTIFIER_TABLE *SourceMacroTable;
ACPI_TYPED_IDENTIFIER_TABLE *SourceStructTable;
ACPI_IDENTIFIER_TABLE *SourceSpecialMacroTable;
UINT32 SourceFunctions;
ACPI_STRING_TABLE *HeaderStringTable;
@ -256,6 +257,7 @@ typedef struct acpi_conversion_table
ACPI_IDENTIFIER_TABLE *HeaderConditionalTable;
ACPI_IDENTIFIER_TABLE *HeaderMacroTable;
ACPI_TYPED_IDENTIFIER_TABLE *HeaderStructTable;
ACPI_IDENTIFIER_TABLE *HeaderSpecialMacroTable;
UINT32 HeaderFunctions;
} ACPI_CONVERSION_TABLE;
@ -268,6 +270,7 @@ extern ACPI_CONVERSION_TABLE CleanupConversionTable;
extern ACPI_CONVERSION_TABLE StatsConversionTable;
extern ACPI_CONVERSION_TABLE CustomConversionTable;
extern ACPI_CONVERSION_TABLE LicenseConversionTable;
extern ACPI_CONVERSION_TABLE IndentConversionTable;
/* Prototypes */
@ -353,6 +356,11 @@ AsRemoveEmptyBlocks (
char *Buffer,
char *Filename);
void
AsCleanupSpecialMacro (
char *Buffer,
char *Keyword);
void
AsCountSourceLines (
char *Buffer,

View File

@ -379,6 +379,7 @@ AsConvertFile (
ACPI_IDENTIFIER_TABLE *LineTable;
ACPI_IDENTIFIER_TABLE *MacroTable;
ACPI_TYPED_IDENTIFIER_TABLE *StructTable;
ACPI_IDENTIFIER_TABLE *SpecialMacroTable;
switch (FileType)
@ -391,6 +392,7 @@ AsConvertFile (
ConditionalTable = ConversionTable->SourceConditionalTable;
MacroTable = ConversionTable->SourceMacroTable;
StructTable = ConversionTable->SourceStructTable;
SpecialMacroTable = ConversionTable->SourceSpecialMacroTable;
break;
case FILE_TYPE_HEADER:
@ -401,6 +403,7 @@ AsConvertFile (
ConditionalTable = ConversionTable->HeaderConditionalTable;
MacroTable = ConversionTable->HeaderMacroTable;
StructTable = ConversionTable->HeaderStructTable;
SpecialMacroTable = ConversionTable->HeaderSpecialMacroTable;
break;
default:
@ -473,6 +476,14 @@ AsConvertFile (
}
}
if (SpecialMacroTable)
{
for (i = 0; SpecialMacroTable[i].Identifier; i++)
{
AsCleanupSpecialMacro (FileBuffer, SpecialMacroTable[i].Identifier);
}
}
/* Process the function table */
for (i = 0; i < 32; i++)

View File

@ -171,7 +171,7 @@ BOOLEAN Gbl_HasLoneLineFeeds = FALSE;
BOOLEAN Gbl_Cleanup = FALSE;
#define AS_UTILITY_NAME "ACPI Source Code Conversion Utility"
#define AS_SUPPORTED_OPTIONS "cdhlqsuv^y"
#define AS_SUPPORTED_OPTIONS "cdhilqsuv^y"
/******************************************************************************
@ -364,6 +364,7 @@ AsDisplayUsage (
ACPI_OPTION ("-c", "Generate cleaned version of the source");
ACPI_OPTION ("-h", "Insert dual-license header into all modules");
ACPI_OPTION ("-i", "Cleanup macro indentation");
ACPI_OPTION ("-l", "Generate Linux version of the source");
ACPI_OPTION ("-u", "Generate Custom source translation");
@ -436,6 +437,15 @@ main (
ConversionTable = &LicenseConversionTable;
break;
case 'i':
/* Cleanup wrong indent result */
printf ("Cleaning up macro indentation\n");
ConversionTable = &IndentConversionTable;
Gbl_IgnoreLoneLineFeeds = TRUE;
break;
case 's':
/* Statistics only */

View File

@ -683,3 +683,72 @@ AsRemoveDebugMacros (
AsReplaceString ("return_acpi_status", "return", REPLACE_WHOLE_WORD, Buffer);
AsReplaceString ("return_VALUE", "return", REPLACE_WHOLE_WORD, Buffer);
}
/******************************************************************************
*
* FUNCTION: AsCleanupSpecialMacro
*
* DESCRIPTION: For special macro invocations (invoked without ";" at the end
* of the lines), do the following:
* 1. Remove spaces appended by indent at the beginning of lines.
* 2. Add an empty line between two special macro invocations.
*
******************************************************************************/
void
AsCleanupSpecialMacro (
char *Buffer,
char *Keyword)
{
char *SubString;
char *SubBuffer;
char *LastNonSpace;
SubBuffer = Buffer;
SubString = Buffer;
while (SubString)
{
SubString = strstr (SubBuffer, Keyword);
if (SubString)
{
/* Find start of the line */
SubBuffer = SubString;
while (*(SubBuffer - 1) == ' ')
{
SubBuffer--;
}
if (*(SubBuffer - 1) == '\n')
{
/* Find last non-space character */
LastNonSpace = SubBuffer - 1;
while (isspace ((int) *LastNonSpace))
{
LastNonSpace--;
}
if (*LastNonSpace != '\\')
{
/* Remove the extra spaces */
SubString = AsRemoveData (SubBuffer, SubString);
/* Enforce an empty line between the invocations */
if (*(SubBuffer - 2) == ')')
{
AsInsertData (SubBuffer, "\n", 1);
}
}
}
SubBuffer = SubString + strlen (Keyword);
}
}
}

View File

@ -766,6 +766,18 @@ ACPI_IDENTIFIER_TABLE LinuxConditionalIdentifiers[] = {
{NULL}
};
ACPI_IDENTIFIER_TABLE LinuxSpecialMacros[] = {
{"ACPI_EXPORT_SYMBOL"},
{"ACPI_EXPORT_SYMBOL_INIT"},
{"ACPI_HW_DEPENDENT_RETURN_OK"},
{"ACPI_HW_DEPENDENT_RETURN_STATUS"},
{"ACPI_HW_DEPENDENT_RETURN_VOID"},
{NULL}
};
ACPI_CONVERSION_TABLE LinuxConversionTable = {
DualLicenseHeader,
@ -780,6 +792,7 @@ ACPI_CONVERSION_TABLE LinuxConversionTable = {
NULL,
LinuxEliminateMacros,
AcpiIdentifiers,
NULL,
(CVT_COUNT_TABS | CVT_COUNT_NON_ANSI_COMMENTS | CVT_COUNT_LINES |
CVT_CHECK_BRACES | CVT_TRIM_LINES | CVT_BRACES_ON_SAME_LINE |
CVT_MIXED_CASE_TO_UNDERSCORES | CVT_LOWER_CASE_IDENTIFIERS |
@ -793,6 +806,7 @@ ACPI_CONVERSION_TABLE LinuxConversionTable = {
LinuxConditionalIdentifiers,
NULL,
AcpiIdentifiers,
NULL,
(CVT_COUNT_TABS | CVT_COUNT_NON_ANSI_COMMENTS | CVT_COUNT_LINES |
CVT_TRIM_LINES | CVT_MIXED_CASE_TO_UNDERSCORES |
CVT_LOWER_CASE_IDENTIFIERS | CVT_TRIM_WHITESPACE |
@ -818,6 +832,7 @@ ACPI_CONVERSION_TABLE CleanupConversionTable = {
NULL,
NULL,
NULL,
NULL,
(CVT_COUNT_TABS | CVT_COUNT_NON_ANSI_COMMENTS | CVT_COUNT_LINES |
CVT_CHECK_BRACES | CVT_TRIM_LINES | CVT_TRIM_WHITESPACE),
@ -828,6 +843,7 @@ ACPI_CONVERSION_TABLE CleanupConversionTable = {
NULL,
NULL,
NULL,
NULL,
(CVT_COUNT_TABS | CVT_COUNT_NON_ANSI_COMMENTS | CVT_COUNT_LINES |
CVT_TRIM_LINES | CVT_TRIM_WHITESPACE),
};
@ -846,6 +862,7 @@ ACPI_CONVERSION_TABLE StatsConversionTable = {
NULL,
NULL,
NULL,
NULL,
(CVT_COUNT_TABS | CVT_COUNT_NON_ANSI_COMMENTS | CVT_COUNT_LINES |
CVT_COUNT_SHORTMULTILINE_COMMENTS),
@ -856,6 +873,7 @@ ACPI_CONVERSION_TABLE StatsConversionTable = {
NULL,
NULL,
NULL,
NULL,
(CVT_COUNT_TABS | CVT_COUNT_NON_ANSI_COMMENTS | CVT_COUNT_LINES |
CVT_COUNT_SHORTMULTILINE_COMMENTS),
};
@ -880,6 +898,7 @@ ACPI_CONVERSION_TABLE LicenseConversionTable = {
NULL,
NULL,
NULL,
NULL,
(CVT_COUNT_TABS | CVT_COUNT_NON_ANSI_COMMENTS | CVT_COUNT_LINES |
CVT_COUNT_SHORTMULTILINE_COMMENTS),
@ -890,6 +909,7 @@ ACPI_CONVERSION_TABLE LicenseConversionTable = {
NULL,
NULL,
NULL,
NULL,
(CVT_COUNT_TABS | CVT_COUNT_NON_ANSI_COMMENTS | CVT_COUNT_LINES |
CVT_COUNT_SHORTMULTILINE_COMMENTS),
};
@ -969,6 +989,7 @@ ACPI_CONVERSION_TABLE CustomConversionTable = {
NULL,
NULL,
NULL,
NULL,
(CVT_COUNT_TABS | CVT_COUNT_NON_ANSI_COMMENTS | CVT_COUNT_LINES |
CVT_TRIM_LINES | CVT_TRIM_WHITESPACE),
@ -979,6 +1000,44 @@ ACPI_CONVERSION_TABLE CustomConversionTable = {
NULL,
NULL,
NULL,
NULL,
(CVT_COUNT_TABS | CVT_COUNT_NON_ANSI_COMMENTS | CVT_COUNT_LINES |
CVT_TRIM_LINES | CVT_TRIM_WHITESPACE),
};
/******************************************************************************
*
* Indentation result fixup table
*
******************************************************************************/
ACPI_CONVERSION_TABLE IndentConversionTable = {
NULL,
FLG_NO_CARRIAGE_RETURNS,
NULL,
/* C source files */
NULL,
NULL,
NULL,
NULL,
NULL,
LinuxSpecialMacros,
(CVT_COUNT_TABS | CVT_COUNT_NON_ANSI_COMMENTS | CVT_COUNT_LINES |
CVT_TRIM_LINES | CVT_TRIM_WHITESPACE),
/* C header files */
NULL,
NULL,
NULL,
NULL,
NULL,
LinuxSpecialMacros,
(CVT_COUNT_TABS | CVT_COUNT_NON_ANSI_COMMENTS | CVT_COUNT_LINES |
CVT_TRIM_LINES | CVT_TRIM_WHITESPACE),
};