iASL: Add support for response files.

Windows-style response files, containing a list of additional
command line options. ACPICA BZ 801.
This commit is contained in:
Robert Moore 2009-09-01 13:08:07 -07:00
parent f32e3476e0
commit 2dfa14e186
2 changed files with 204 additions and 43 deletions

View File

@ -148,7 +148,7 @@ extern char HexLookup[];
#define ASL_LINE_BUFFER_SIZE 512
#define ASL_MSG_BUFFER_SIZE 4096
#define HEX_TABLE_LINE_SIZE 8
#define HEX_LISTING_LINE_SIZE 16
#define HEX_LISTING_LINE_SIZE 8
/* Source code buffers and pointers for error reporting */

View File

@ -150,6 +150,28 @@ AslCommandLine (
int argc,
char **argv);
static int
AslDoOptions (
int argc,
char **argv,
BOOLEAN IsResponseFile);
static void
AslMergeOptionTokens (
char *InBuffer,
char *OutBuffer);
static int
AslDoResponseFile (
char *Filename);
extern int AcpiGbl_Opterr;
extern int AcpiGbl_Optind;
#define ASL_TOKEN_SEPARATORS " \t\n"
#define ASL_SUPPORTED_OPTIONS "@:2b:cd^e:fgh^i^I:l^o:p:r:s:t:v:w:x:"
/*******************************************************************************
*
@ -168,8 +190,12 @@ Options (
void)
{
printf ("General Output:\n");
printf (" -p <prefix> Specify path/filename prefix for all output files\n");
printf ("Global:\n");
printf (" -@<file> Specify command file\n");
printf (" -I<dir> Specify additional include directory\n");
printf ("\nGeneral Output:\n");
printf (" -p<prefix> Specify path/filename prefix for all output files\n");
printf (" -va Disable all errors and warnings (summary only)\n");
printf (" -vi Less verbose errors and warnings for use with IDEs\n");
printf (" -vo Enable optimization comments\n");
@ -183,7 +209,6 @@ Options (
printf (" -t<a|c> Create AML in assembler or C hex table (*.hex)\n");
printf ("\nAML Code Generation:\n");
printf (" -I<dir> Specify additional include directory\n");
printf (" -oa Disable all optimizations (compatibility mode)\n");
printf (" -of Disable constant folding\n");
printf (" -oi Disable integer optimization to Zero/One/Ones\n");
@ -311,39 +336,149 @@ AslInitialize (
/*******************************************************************************
*
* FUNCTION: AslCommandLine
* FUNCTION: AslMergeOptionTokens
*
* PARAMETERS: argc/argv
* PARAMETERS: InBuffer - Input containing an option string
* OutBuffer - Merged output buffer
*
* RETURN: None
*
* DESCRIPTION: Command line processing
* DESCRIPTION: Remove all whitespace from an option string.
*
******************************************************************************/
static void
AslMergeOptionTokens (
char *InBuffer,
char *OutBuffer)
{
char *Token;
*OutBuffer = 0;
Token = strtok (InBuffer, ASL_TOKEN_SEPARATORS);
while (Token)
{
strcat (OutBuffer, Token);
Token = strtok (NULL, ASL_TOKEN_SEPARATORS);
}
}
/*******************************************************************************
*
* FUNCTION: AslDoResponseFile
*
* PARAMETERS: Filename - Name of the response file
*
* RETURN: Status
*
* DESCRIPTION: Open a response file and process all options within.
*
******************************************************************************/
static int
AslCommandLine (
int argc,
char **argv)
AslDoResponseFile (
char *Filename)
{
char *argv = StringBuffer2;
FILE *ResponseFile;
int OptStatus = 0;
int Opterr;
int Optind;
ResponseFile = fopen (Filename, "r");
if (!ResponseFile)
{
printf ("Could not open command file %s, %s\n",
Filename, strerror (errno));
return -1;
}
/* Must save the current GetOpt globals */
Opterr = AcpiGbl_Opterr;
Optind = AcpiGbl_Optind;
/*
* Process all lines in the response file. There must be one complete
* option per line
*/
while (fgets (StringBuffer, ASL_MSG_BUFFER_SIZE, ResponseFile))
{
/* Compress all tokens, allowing us to use a single argv entry */
AslMergeOptionTokens (StringBuffer, StringBuffer2);
/* Process the option */
AcpiGbl_Opterr = 0;
AcpiGbl_Optind = 0;
OptStatus = AslDoOptions (1, &argv, TRUE);
if (OptStatus)
{
printf ("Invalid option in command file %s: %s\n",
Filename, StringBuffer);
break;
}
}
/* Restore the GetOpt globals */
AcpiGbl_Opterr = Opterr;
AcpiGbl_Optind = Optind;
fclose (ResponseFile);
return (OptStatus);
}
/*******************************************************************************
*
* FUNCTION: AslDoOptions
*
* PARAMETERS: argc/argv - Standard argc/argv
* IsResponseFile - TRUE if executing a response file.
*
* RETURN: Status
*
* DESCRIPTION: Command line option processing
*
******************************************************************************/
static int
AslDoOptions (
int argc,
char **argv,
BOOLEAN IsResponseFile)
{
BOOLEAN BadCommandLine = FALSE;
int j;
/* Minimum command line contains at least one option or an input file */
if (argc < 2)
{
AslCompilerSignon (ASL_FILE_STDOUT);
Usage ();
exit (1);
}
/* Get the command line options */
while ((j = AcpiGetopt (argc, argv, "2b:cd^e:fgh^i^I:l^o:p:r:s:t:v:w:x:")) != EOF) switch (j)
while ((j = AcpiGetopt (argc, argv, ASL_SUPPORTED_OPTIONS)) != EOF) switch (j)
{
case '@': /* Begin a response file */
if (IsResponseFile)
{
printf ("Nested command files are not supported\n");
return -1;
}
if (AslDoResponseFile (AcpiGbl_Optarg))
{
return -1;
}
break;
case '2':
Gbl_Acpi2 = TRUE;
break;
@ -365,8 +500,7 @@ AslCommandLine (
default:
printf ("Unknown option: -b%s\n", AcpiGbl_Optarg);
BadCommandLine = TRUE;
break;
return (-1);
}
/* Produce debug output file */
@ -395,8 +529,7 @@ AslCommandLine (
default:
printf ("Unknown option: -d%s\n", AcpiGbl_Optarg);
BadCommandLine = TRUE;
break;
return (-1);
}
Gbl_DisasmFlag = TRUE;
@ -445,8 +578,7 @@ AslCommandLine (
default:
printf ("Unknown option: -h%s\n", AcpiGbl_Optarg);
BadCommandLine = TRUE;
break;
return (-1);
}
break;
@ -477,8 +609,7 @@ AslCommandLine (
default:
printf ("Unknown option: -s%s\n", AcpiGbl_Optarg);
BadCommandLine = TRUE;
break;
return (-1);
}
break;
@ -507,8 +638,7 @@ AslCommandLine (
default:
printf ("Unknown option: -l%s\n", AcpiGbl_Optarg);
BadCommandLine = TRUE;
break;
return (-1);
}
break;
@ -556,8 +686,7 @@ AslCommandLine (
default:
printf ("Unknown option: -c%s\n", AcpiGbl_Optarg);
BadCommandLine = TRUE;
break;
return (-1);
}
break;
@ -596,8 +725,7 @@ AslCommandLine (
default:
printf ("Unknown option: -s%s\n", AcpiGbl_Optarg);
BadCommandLine = TRUE;
break;
return (-1);
}
break;
@ -618,8 +746,7 @@ AslCommandLine (
default:
printf ("Unknown option: -t%s\n", AcpiGbl_Optarg);
BadCommandLine = TRUE;
break;
return (-1);
}
break;
@ -654,8 +781,7 @@ AslCommandLine (
default:
printf ("Unknown option: -v%s\n", AcpiGbl_Optarg);
BadCommandLine = TRUE;
break;
return (-1);
}
break;
@ -678,8 +804,7 @@ AslCommandLine (
default:
printf ("Unknown option: -w%s\n", AcpiGbl_Optarg);
BadCommandLine = TRUE;
break;
return (-1);
}
break;
@ -692,10 +817,46 @@ AslCommandLine (
default:
BadCommandLine = TRUE;
break;
return (-1);
}
return (0);
}
/*******************************************************************************
*
* FUNCTION: AslCommandLine
*
* PARAMETERS: argc/argv
*
* RETURN: Last argv index
*
* DESCRIPTION: Command line processing
*
******************************************************************************/
static int
AslCommandLine (
int argc,
char **argv)
{
int BadCommandLine = 0;
/* Minimum command line contains at least the command and an input file */
if (argc < 2)
{
AslCompilerSignon (ASL_FILE_STDOUT);
Usage ();
exit (1);
}
/* Process all command line options */
BadCommandLine = AslDoOptions (argc, argv, FALSE);
/* Next parameter must be the input filename */
if (!argv[AcpiGbl_Optind] &&