mirror of git://gcc.gnu.org/git/gcc.git
restore old algorighm for char_macro_*_fix routines
From-SVN: r34271
This commit is contained in:
parent
26e903eefb
commit
22e50c5bb9
|
|
@ -1,6 +1,7 @@
|
||||||
2000-05-30 Bruce Korb <bkorb@gnu.org>
|
2000-05-30 Bruce Korb <bkorb@gnu.org>
|
||||||
|
|
||||||
* fixinc/tests/*: Added expected result files for fixinc's make check
|
* fixinc/tests/*: Added expected result files for fixinc's make check
|
||||||
|
* fixinc/fixfixes(char_macro_*_fix): Restore original algorithm
|
||||||
|
|
||||||
2000-05-30 Richard Henderson <rth@cygnus.com>
|
2000-05-30 Richard Henderson <rth@cygnus.com>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ Here are the rules:
|
||||||
4. Do not read anything from stdin. It is closed.
|
4. Do not read anything from stdin. It is closed.
|
||||||
|
|
||||||
5. Write to stderr only in the event of a reportable error
|
5. Write to stderr only in the event of a reportable error
|
||||||
In such an event, call "exit(1)".
|
In such an event, call "exit (EXIT_FAILURE)".
|
||||||
|
|
||||||
6. You have access to the fixDescList entry for the fix in question.
|
6. You have access to the fixDescList entry for the fix in question.
|
||||||
This may be useful, for example, if there are interesting strings
|
This may be useful, for example, if there are interesting strings
|
||||||
|
|
@ -59,6 +59,10 @@ Boston, MA 02111-1307, USA. */
|
||||||
|
|
||||||
#include "fixlib.h"
|
#include "fixlib.h"
|
||||||
|
|
||||||
|
tSCC zNeedsArg[] = "fixincl error: `%s' needs %s argument (c_fix_arg[%d])\n";
|
||||||
|
|
||||||
|
#define EXIT_BROKEN 3
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
const char* fix_name;
|
const char* fix_name;
|
||||||
void (*fix_proc)();
|
void (*fix_proc)();
|
||||||
|
|
@ -192,7 +196,6 @@ format_write (format, text, av)
|
||||||
*/
|
*/
|
||||||
FIX_PROC_HEAD( format_fix )
|
FIX_PROC_HEAD( format_fix )
|
||||||
{
|
{
|
||||||
tSCC zBad[] = "fixincl error: `%s' needs %s c_fix_arg\n";
|
|
||||||
tCC* pz_pat = p_fixd->patch_args[2];
|
tCC* pz_pat = p_fixd->patch_args[2];
|
||||||
tCC* pz_fmt = p_fixd->patch_args[1];
|
tCC* pz_fmt = p_fixd->patch_args[1];
|
||||||
const char *p;
|
const char *p;
|
||||||
|
|
@ -204,8 +207,8 @@ FIX_PROC_HEAD( format_fix )
|
||||||
*/
|
*/
|
||||||
if (pz_fmt == (tCC*)NULL)
|
if (pz_fmt == (tCC*)NULL)
|
||||||
{
|
{
|
||||||
fprintf( stderr, zBad, p_fixd->fix_name, "replacement-format" );
|
fprintf( stderr, zNeedsArg, p_fixd->fix_name, "replacement format", 0 );
|
||||||
exit( 3 );
|
exit (EXIT_BROKEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -220,8 +223,8 @@ FIX_PROC_HEAD( format_fix )
|
||||||
{
|
{
|
||||||
if (ct-- <= 0)
|
if (ct-- <= 0)
|
||||||
{
|
{
|
||||||
fprintf( stderr, zBad, p_fixd->fix_name, "search-text" );
|
fprintf( stderr, zNeedsArg, p_fixd->fix_name, "search text", 1 );
|
||||||
exit( 3 );
|
exit (EXIT_BROKEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pTD->type == TT_EGREP)
|
if (pTD->type == TT_EGREP)
|
||||||
|
|
@ -271,71 +274,72 @@ FIX_PROC_HEAD( char_macro_use_fix )
|
||||||
{
|
{
|
||||||
/* This regexp looks for a traditional-syntax #define (# in column 1)
|
/* This regexp looks for a traditional-syntax #define (# in column 1)
|
||||||
of an object-like macro. */
|
of an object-like macro. */
|
||||||
static const char zPatFmt[] =
|
static const char pat[] =
|
||||||
#ifdef __STDC__
|
"^#[ \t]*define[ \t]+[_A-Za-z][_A-Za-z0-9]*[ \t]+";
|
||||||
/*
|
|
||||||
* Match up to the replacement text
|
|
||||||
*/
|
|
||||||
"^#[ \t]*define[ \t]+[_A-Za-z][_A-Za-z0-9]*[ \t]+"
|
|
||||||
/*
|
|
||||||
* Match the replacement macro name and openening parenthesis
|
|
||||||
*/
|
|
||||||
"[_A-Z][_A-Z0-9]*%s[A-Z]*\\("
|
|
||||||
/*
|
|
||||||
* Match the single character that must be single-quoted,
|
|
||||||
* plus some other non-name type character
|
|
||||||
*/
|
|
||||||
"([A-Za-z])[^a-zA-Z0-9_]"
|
|
||||||
#else
|
|
||||||
/*
|
|
||||||
* Indecipherable gobbeldygook:
|
|
||||||
*/
|
|
||||||
|
|
||||||
"^#[ \t]*define[ \t]+[_A-Za-z][_A-Za-z0-9]*[ \t]+[_A-Z][_A-Z0-9]*\
|
|
||||||
%s[A-Z]*\\(([A-Za-z])[^a-zA-Z0-9_]"
|
|
||||||
#endif
|
|
||||||
;
|
|
||||||
|
|
||||||
# define SUB_PAT_CT 1
|
|
||||||
char *pz_pat;
|
|
||||||
|
|
||||||
static regex_t re;
|
static regex_t re;
|
||||||
|
|
||||||
regmatch_t rm[SUB_PAT_CT+1];
|
const char* str = p_fixd->patch_args[1];
|
||||||
|
regmatch_t rm[1];
|
||||||
|
const char *p, *limit;
|
||||||
|
size_t len;
|
||||||
|
|
||||||
if (p_fixd->patch_args[1] == NULL)
|
if (str == NULL)
|
||||||
{
|
{
|
||||||
fprintf (stderr, "%s needs macro-name-string argument",
|
fprintf (stderr, zNeedsArg, p_fixd->fix_name, "ioctl type", 0);
|
||||||
p_fixd->fix_name);
|
exit (EXIT_BROKEN);
|
||||||
exit(3);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
asprintf (&pz_pat, zPatFmt, p_fixd->patch_args[1]);
|
len = strlen (str);
|
||||||
if (!pz_pat)
|
compile_re (pat, &re, 1, "macro pattern", "char_macro_use_fix");
|
||||||
|
|
||||||
|
for (p = text;
|
||||||
|
regexec (&re, p, 1, rm, 0) == 0;
|
||||||
|
p = limit + 1)
|
||||||
{
|
{
|
||||||
fprintf( stderr, "Virtual memory exhausted\n" );
|
/* p + rm[0].rm_eo is the first character of the macro replacement.
|
||||||
exit(3);
|
Find the end of the macro replacement, and the STR we were
|
||||||
|
sent to look for within the replacement. */
|
||||||
|
p += rm[0].rm_eo;
|
||||||
|
limit = p - 1;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
limit = strchr (limit + 1, '\n');
|
||||||
|
if (!limit)
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
while (limit[-1] == '\\');
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
if (*p == str[0] && !strncmp (p+1, str+1, len-1))
|
||||||
|
goto found;
|
||||||
|
}
|
||||||
|
while (++p < limit - len);
|
||||||
|
/* Hit end of line. */
|
||||||
|
continue;
|
||||||
|
|
||||||
|
found:
|
||||||
|
/* Found STR on this line. If the macro needs fixing,
|
||||||
|
the next few chars will be whitespace or uppercase,
|
||||||
|
then an open paren, then a single letter. */
|
||||||
|
while ((isspace (*p) || isupper (*p)) && p < limit) p++;
|
||||||
|
if (*p++ != '(')
|
||||||
|
continue;
|
||||||
|
if (!isalpha (*p))
|
||||||
|
continue;
|
||||||
|
if (isalnum (p[1]) || p[1] == '_')
|
||||||
|
continue;
|
||||||
|
|
||||||
|
/* Splat all preceding text into the output buffer,
|
||||||
|
quote the character at p, then proceed. */
|
||||||
|
fwrite (text, 1, p - text, stdout);
|
||||||
|
putchar ('\'');
|
||||||
|
putchar (*p);
|
||||||
|
putchar ('\'');
|
||||||
|
text = p + 1;
|
||||||
}
|
}
|
||||||
|
done:
|
||||||
compile_re (pz_pat, &re, 1, "macro pattern", "char_macro_use_fix");
|
|
||||||
free (pz_pat);
|
|
||||||
|
|
||||||
while (regexec (&re, text, SUB_PAT_CT+1, rm, 0) == 0)
|
|
||||||
{
|
|
||||||
const char* pz = text + rm[1].rm_so;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Write up to, but not including, the character we must quote
|
|
||||||
*/
|
|
||||||
fwrite( text, 1, rm[1].rm_so, stdout );
|
|
||||||
fputc( '\'', stdout );
|
|
||||||
fputc( *(pz++), stdout );
|
|
||||||
fputc( '\'', stdout );
|
|
||||||
text = pz;
|
|
||||||
}
|
|
||||||
|
|
||||||
fputs (text, stdout);
|
fputs (text, stdout);
|
||||||
# undef SUB_PAT_CT
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -352,107 +356,88 @@ FIX_PROC_HEAD( char_macro_use_fix )
|
||||||
you provide as the `c_fix_arg' argument. */
|
you provide as the `c_fix_arg' argument. */
|
||||||
FIX_PROC_HEAD( char_macro_def_fix )
|
FIX_PROC_HEAD( char_macro_def_fix )
|
||||||
{
|
{
|
||||||
static const char zPatFmt[] =
|
/* This regexp looks for any traditional-syntax #define (# in column 1). */
|
||||||
#ifdef __STDC__
|
static const char pat[] =
|
||||||
/*
|
"^#[ \t]*define[ \t]+";
|
||||||
* Find a #define name and opening parenthesis
|
|
||||||
*/
|
|
||||||
"^#[ \t]*define[ \t]+[_A-Z][A-Z0-9_]*%s[A-Z]*\\("
|
|
||||||
/*
|
|
||||||
* The next character must match a later one
|
|
||||||
*/
|
|
||||||
"([a-zA-Z])" /* rm[1] */
|
|
||||||
/*
|
|
||||||
* now match over a comma, the argument list, intervening white space
|
|
||||||
* an opening parenthesis, and on through a single quote character
|
|
||||||
*/
|
|
||||||
"[ \t]*,[^)]*\\)[ \t]+\\([^']*'"
|
|
||||||
/*
|
|
||||||
* Match the character that must match the remembered char above
|
|
||||||
*/
|
|
||||||
"([a-zA-Z])'" /* rm[2] */
|
|
||||||
#else
|
|
||||||
/*
|
|
||||||
* Indecipherable gobbeldygook:
|
|
||||||
*/
|
|
||||||
|
|
||||||
"^#[ \t]*define[ \t]+[_A-Z][A-Z0-9_]*%s[A-Z]*\\(\
|
|
||||||
([a-zA-Z])[ \t]*,[^)]*\\)[ \t]+\\([^']*'([a-zA-Z])'"
|
|
||||||
#endif
|
|
||||||
;
|
|
||||||
|
|
||||||
char *pz_pat;
|
|
||||||
|
|
||||||
static regex_t re;
|
static regex_t re;
|
||||||
# define SUB_PAT_CT 2
|
|
||||||
regmatch_t rm[SUB_PAT_CT+1];
|
|
||||||
const char *p;
|
|
||||||
int rerr;
|
|
||||||
|
|
||||||
if (p_fixd->patch_args[1] == NULL)
|
const char* str = p_fixd->patch_args[1];
|
||||||
|
regmatch_t rm[1];
|
||||||
|
const char *p, *limit;
|
||||||
|
char arg;
|
||||||
|
size_t len;
|
||||||
|
|
||||||
|
if (str == NULL)
|
||||||
{
|
{
|
||||||
fprintf (stderr, "%s needs macro-name-string argument",
|
fprintf (stderr, zNeedsArg, p_fixd->fix_name, "ioctl type", 0);
|
||||||
p_fixd->fix_name);
|
exit (EXIT_BROKEN);
|
||||||
exit(3);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
asprintf (&pz_pat, zPatFmt, p_fixd->patch_args[1]);
|
len = strlen (str);
|
||||||
if (!pz_pat)
|
compile_re (pat, &re, 1, "macro pattern", "fix_char_macro_defines");
|
||||||
|
|
||||||
|
for (p = text;
|
||||||
|
regexec (&re, p, 1, rm, 0) == 0;
|
||||||
|
p = limit + 1)
|
||||||
{
|
{
|
||||||
fprintf (stderr, "Virtual memory exhausted\n");
|
/* p + rm[0].rm_eo is the first character of the macro name.
|
||||||
exit(3);
|
Find the end of the macro replacement, and the STR we were
|
||||||
|
sent to look for within the name. */
|
||||||
|
p += rm[0].rm_eo;
|
||||||
|
limit = p - 1;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
limit = strchr (limit + 1, '\n');
|
||||||
|
if (!limit)
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
while (limit[-1] == '\\');
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
if (*p == str[0] && !strncmp (p+1, str+1, len-1))
|
||||||
|
goto found;
|
||||||
|
p++;
|
||||||
|
}
|
||||||
|
while (isalpha (*p) || isalnum (*p) || *p == '_');
|
||||||
|
/* Hit end of macro name without finding the string. */
|
||||||
|
continue;
|
||||||
|
|
||||||
|
found:
|
||||||
|
/* Found STR in this macro name. If the macro needs fixing,
|
||||||
|
there may be a few uppercase letters, then there will be an
|
||||||
|
open paren with _no_ intervening whitespace, and then a
|
||||||
|
single letter. */
|
||||||
|
while (isupper (*p) && p < limit) p++;
|
||||||
|
if (*p++ != '(')
|
||||||
|
continue;
|
||||||
|
if (!isalpha (*p))
|
||||||
|
continue;
|
||||||
|
if (isalnum (p[1]) || p[1] == '_')
|
||||||
|
continue;
|
||||||
|
|
||||||
|
/* The character at P is the one to look for in the following
|
||||||
|
text. */
|
||||||
|
arg = *p;
|
||||||
|
p += 2;
|
||||||
|
|
||||||
|
while (p < limit)
|
||||||
|
{
|
||||||
|
if (p[-1] == '\'' && p[0] == arg && p[1] == '\'')
|
||||||
|
{
|
||||||
|
/* Remove the quotes from this use of ARG. */
|
||||||
|
p--;
|
||||||
|
fwrite (text, 1, p - text, stdout);
|
||||||
|
putchar (arg);
|
||||||
|
p += 3;
|
||||||
|
text = p;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
p++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
done:
|
||||||
compile_re (pz_pat, &re, 1, "macro pattern", "char_macro_def_fix");
|
|
||||||
|
|
||||||
#ifdef DEBUG
|
|
||||||
if ((rerr = regexec (&re, text, SUB_PAT_CT+1, rm, 0)) != 0)
|
|
||||||
{
|
|
||||||
fprintf( stderr, "Match error %d:\n%s\n", rerr, pz_pat );
|
|
||||||
exit(3);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
free (pz_pat);
|
|
||||||
|
|
||||||
while ((rerr = regexec (&re, text, SUB_PAT_CT+1, rm, 0)) == 0)
|
|
||||||
{
|
|
||||||
const char* pz = text + rm[2].rm_so;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Write up to, but not including, the opening single quote.
|
|
||||||
*/
|
|
||||||
fwrite( text, 1, rm[2].rm_so-1, stdout );
|
|
||||||
|
|
||||||
/*
|
|
||||||
* The character inside the single quotes must match the
|
|
||||||
* first single-character macro argument
|
|
||||||
*/
|
|
||||||
if (text[ rm[1].rm_so ] != *pz)
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
* Advance text past what we have written out and continue
|
|
||||||
*/
|
|
||||||
text = pz-1;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* emit the now unquoted character
|
|
||||||
*/
|
|
||||||
putchar( *pz );
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Point text to the character after the closing single quote
|
|
||||||
*/
|
|
||||||
text = pz+2;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Emit the rest of the text
|
|
||||||
*/
|
|
||||||
fputs (text, stdout);
|
fputs (text, stdout);
|
||||||
# undef SUB_PAT_CT
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Fix for machine name #ifdefs that are not in the namespace reserved
|
/* Fix for machine name #ifdefs that are not in the namespace reserved
|
||||||
|
|
@ -636,9 +621,9 @@ apply_fix( p_fixd, filname )
|
||||||
break;
|
break;
|
||||||
if (--ct <= 0)
|
if (--ct <= 0)
|
||||||
{
|
{
|
||||||
fprintf (stderr, "fixincludes error: the `%s' fix is unknown\n",
|
fprintf (stderr, "fixincl error: the `%s' fix is unknown\n",
|
||||||
fixname );
|
fixname );
|
||||||
exit (3);
|
exit (EXIT_BROKEN);
|
||||||
}
|
}
|
||||||
pfe++;
|
pfe++;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -832,7 +832,8 @@ fix = {
|
||||||
select = "define[ \t]+[A-Z0-9_]+CTRL\\([a-zA-Z],";
|
select = "define[ \t]+[A-Z0-9_]+CTRL\\([a-zA-Z],";
|
||||||
c_fix = char_macro_def;
|
c_fix = char_macro_def;
|
||||||
c_fix_arg = "CTRL";
|
c_fix_arg = "CTRL";
|
||||||
test_text = "#define BSD43_CTRL(n, x) (('n'<<8)+x)";
|
test_text = "#define BSD43_CTRL(n, x) (('n'<<8)+x)\n"
|
||||||
|
"#define _CTRL(c) ('c'&037)";
|
||||||
};
|
};
|
||||||
|
|
||||||
fix = {
|
fix = {
|
||||||
|
|
@ -840,7 +841,7 @@ fix = {
|
||||||
select = "define[ \t]+[A-Z0-9_]+[ \t]+[A-Z0-9_]+CTRL[ \t]*\\( *[^,']";
|
select = "define[ \t]+[A-Z0-9_]+[ \t]+[A-Z0-9_]+CTRL[ \t]*\\( *[^,']";
|
||||||
c_fix = char_macro_use;
|
c_fix = char_macro_use;
|
||||||
c_fix_arg = "CTRL";
|
c_fix_arg = "CTRL";
|
||||||
test_text = "#define TIOCFOO BSD43_CTRL(T, 1)";
|
test_text = "#define TCTRLFOO BSD43_CTRL(T, 1)";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1097,7 +1098,9 @@ fix = {
|
||||||
"\\( *[^,']";
|
"\\( *[^,']";
|
||||||
c_fix = char_macro_use;
|
c_fix = char_macro_use;
|
||||||
c_fix_arg = "IO";
|
c_fix_arg = "IO";
|
||||||
test_text = "#define TIOCFOO BSD43__IOWR(T, 1)";
|
test_text = "#define TIOCFOO BSD43__IOWR(T, 1)\n"
|
||||||
|
"#define TIOCFOO \\\\\n"
|
||||||
|
"BSD43__IOWR(T, 1) /* Some are multi-line */";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1796,22 +1799,6 @@ fix = {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Sony NEWSOS 5.0 does not support the complete ANSI C standard.
|
|
||||||
*/
|
|
||||||
#ifdef SONY
|
|
||||||
fix = {
|
|
||||||
hackname = sony_stdio;
|
|
||||||
files = stdio.h;
|
|
||||||
test = " -x /bin/sony";
|
|
||||||
test = " ! -z \"`if /bin/sony ; then echo true ; fi`\"";
|
|
||||||
sed = "s/__filbuf/_filbuf/g\n"
|
|
||||||
"s/__flsbuf/_flsbuf/g\n"
|
|
||||||
"s/__iob/_iob/g";
|
|
||||||
};
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Incorrect #include in Sony News-OS 3.2.
|
* Incorrect #include in Sony News-OS 3.2.
|
||||||
*/
|
*/
|
||||||
|
|
@ -2719,9 +2706,9 @@ fix = {
|
||||||
select = "in_port_t";
|
select = "in_port_t";
|
||||||
#ifndef SVR5
|
#ifndef SVR5
|
||||||
mach = "*-*-sysv4*";
|
mach = "*-*-sysv4*";
|
||||||
mach = "i[34567]86-*-sysv5*";
|
mach = "i?86-*-sysv5*";
|
||||||
mach = "i[34567]86-*-udk*";
|
mach = "i?86-*-udk*";
|
||||||
mach = "i[34567]86-*-solaris2.[0-4]";
|
mach = "i?86-*-solaris2.[0-4]";
|
||||||
mach = "powerpcle-*-solaris2.[0-4]";
|
mach = "powerpcle-*-solaris2.[0-4]";
|
||||||
mach = "sparc-*-solaris2.[0-4]";
|
mach = "sparc-*-solaris2.[0-4]";
|
||||||
#endif /* SVR5 */
|
#endif /* SVR5 */
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue