mirror of git://gcc.gnu.org/git/gcc.git
argv.c (consume_whitespace): New function.
2009-10-08 Daniel Gutson <dgutson@codesourcery.com> Daniel Jacobowitz <dan@codesourcery.com> Pedro Alves <pedro@codesourcery.com> libiberty/ * argv.c (consume_whitespace): New function. (only_whitespace): New function. (buildargv): Always use ISSPACE by calling consume_whitespace. (expandargv): Skip empty files. Do not stop at the first empty argument (calling only_whitespace).. * testsuite/test-expandargv.c: (test_data): Test empty lines and empty arguments. (run_tests): Fix false positives due to shorter arguments. Co-Authored-By: Daniel Jacobowitz <dan@codesourcery.com> Co-Authored-By: Pedro Alves <pedro@codesourcery.com> From-SVN: r152560
This commit is contained in:
parent
38bf8621d9
commit
70277b3073
|
@ -1,3 +1,17 @@
|
||||||
|
2009-10-08 Daniel Gutson <dgutson@codesourcery.com>
|
||||||
|
Daniel Jacobowitz <dan@codesourcery.com>
|
||||||
|
Pedro Alves <pedro@codesourcery.com>
|
||||||
|
|
||||||
|
libiberty/
|
||||||
|
* argv.c (consume_whitespace): New function.
|
||||||
|
(only_whitespace): New function.
|
||||||
|
(buildargv): Always use ISSPACE by calling consume_whitespace.
|
||||||
|
(expandargv): Skip empty files. Do not stop at the first empty
|
||||||
|
argument (calling only_whitespace)..
|
||||||
|
* testsuite/test-expandargv.c: (test_data): Test empty lines
|
||||||
|
and empty arguments.
|
||||||
|
(run_tests): Fix false positives due to shorter arguments.
|
||||||
|
|
||||||
2009-09-30 Martin Thuresson <martint@google.com>
|
2009-09-30 Martin Thuresson <martint@google.com>
|
||||||
|
|
||||||
* regex.c (byte_re_match_2_internal): Split declaration and
|
* regex.c (byte_re_match_2_internal): Split declaration and
|
||||||
|
|
|
@ -119,6 +119,24 @@ void freeargv (char **vector)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
consume_whitespace (const char **input)
|
||||||
|
{
|
||||||
|
while (ISSPACE (**input))
|
||||||
|
{
|
||||||
|
(*input)++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
only_whitespace (const char* input)
|
||||||
|
{
|
||||||
|
while (*input != EOS && ISSPACE (*input))
|
||||||
|
input++;
|
||||||
|
|
||||||
|
return (*input == EOS);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
||||||
@deftypefn Extension char** buildargv (char *@var{sp})
|
@deftypefn Extension char** buildargv (char *@var{sp})
|
||||||
|
@ -179,10 +197,8 @@ char **buildargv (const char *input)
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
/* Pick off argv[argc] */
|
/* Pick off argv[argc] */
|
||||||
while (ISBLANK (*input))
|
consume_whitespace (&input);
|
||||||
{
|
|
||||||
input++;
|
|
||||||
}
|
|
||||||
if ((maxargc == 0) || (argc >= (maxargc - 1)))
|
if ((maxargc == 0) || (argc >= (maxargc - 1)))
|
||||||
{
|
{
|
||||||
/* argv needs initialization, or expansion */
|
/* argv needs initialization, or expansion */
|
||||||
|
@ -278,10 +294,7 @@ char **buildargv (const char *input)
|
||||||
argc++;
|
argc++;
|
||||||
argv[argc] = NULL;
|
argv[argc] = NULL;
|
||||||
|
|
||||||
while (ISSPACE (*input))
|
consume_whitespace (&input);
|
||||||
{
|
|
||||||
input++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
while (*input != EOS);
|
while (*input != EOS);
|
||||||
}
|
}
|
||||||
|
@ -420,8 +433,17 @@ expandargv (int *argcp, char ***argvp)
|
||||||
goto error;
|
goto error;
|
||||||
/* Add a NUL terminator. */
|
/* Add a NUL terminator. */
|
||||||
buffer[len] = '\0';
|
buffer[len] = '\0';
|
||||||
/* Parse the string. */
|
/* If the file is empty or contains only whitespace, buildargv would
|
||||||
file_argv = buildargv (buffer);
|
return a single empty argument. In this context we want no arguments,
|
||||||
|
instead. */
|
||||||
|
if (only_whitespace (buffer))
|
||||||
|
{
|
||||||
|
file_argv = (char **) xmalloc (sizeof (char *));
|
||||||
|
file_argv[0] = NULL;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
/* Parse the string. */
|
||||||
|
file_argv = buildargv (buffer);
|
||||||
/* If *ARGVP is not already dynamically allocated, copy it. */
|
/* If *ARGVP is not already dynamically allocated, copy it. */
|
||||||
if (!argv_dynamic)
|
if (!argv_dynamic)
|
||||||
{
|
{
|
||||||
|
@ -434,7 +456,7 @@ expandargv (int *argcp, char ***argvp)
|
||||||
}
|
}
|
||||||
/* Count the number of arguments. */
|
/* Count the number of arguments. */
|
||||||
file_argc = 0;
|
file_argc = 0;
|
||||||
while (file_argv[file_argc] && *file_argv[file_argc])
|
while (file_argv[file_argc])
|
||||||
++file_argc;
|
++file_argc;
|
||||||
/* Now, insert FILE_ARGV into ARGV. The "+1" below handles the
|
/* Now, insert FILE_ARGV into ARGV. The "+1" below handles the
|
||||||
NULL terminator at the end of ARGV. */
|
NULL terminator at the end of ARGV. */
|
||||||
|
|
|
@ -107,6 +107,38 @@ const char *test_data[] = {
|
||||||
ARGV0,
|
ARGV0,
|
||||||
0,
|
0,
|
||||||
|
|
||||||
|
/* Test 4 - Check for options beginning with an empty line. */
|
||||||
|
"\na\nb", /* Test 4 data */
|
||||||
|
ARGV0,
|
||||||
|
"@test-expandargv-4.lst",
|
||||||
|
0,
|
||||||
|
ARGV0,
|
||||||
|
"a",
|
||||||
|
"b",
|
||||||
|
0,
|
||||||
|
|
||||||
|
/* Test 5 - Check for options containing an empty argument. */
|
||||||
|
"a\n''\nb", /* Test 5 data */
|
||||||
|
ARGV0,
|
||||||
|
"@test-expandargv-5.lst",
|
||||||
|
0,
|
||||||
|
ARGV0,
|
||||||
|
"a",
|
||||||
|
"",
|
||||||
|
"b",
|
||||||
|
0,
|
||||||
|
|
||||||
|
/* Test 6 - Check for options containing a quoted newline. */
|
||||||
|
"a\n'a\n\nb'\nb", /* Test 6 data */
|
||||||
|
ARGV0,
|
||||||
|
"@test-expandargv-6.lst",
|
||||||
|
0,
|
||||||
|
ARGV0,
|
||||||
|
"a",
|
||||||
|
"a\n\nb",
|
||||||
|
"b",
|
||||||
|
0,
|
||||||
|
|
||||||
0 /* Test done marker, don't remove. */
|
0 /* Test done marker, don't remove. */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -246,7 +278,7 @@ run_tests (const char **test_data)
|
||||||
/* Compare each of the argv's ... */
|
/* Compare each of the argv's ... */
|
||||||
else
|
else
|
||||||
for (k = 0; k < argc_after; k++)
|
for (k = 0; k < argc_after; k++)
|
||||||
if (strncmp (argv_before[k], argv_after[k], strlen(argv_after[k])) != 0)
|
if (strcmp (argv_before[k], argv_after[k]) != 0)
|
||||||
{
|
{
|
||||||
printf ("FAIL: test-expandargv-%d. Arguments don't match.\n", i);
|
printf ("FAIL: test-expandargv-%d. Arguments don't match.\n", i);
|
||||||
failed++;
|
failed++;
|
||||||
|
|
Loading…
Reference in New Issue