Commit 192babfd by Theodore Papadopoulo Committed by Jeff Law

toplev.c (read_integral_parameter): Constify.

        * toplev.c (read_integral_parameter): Constify.  Better control of
        error messages.
        (main): Use read_integral_parameter to set optimize, id_clash_len,
        larger_than_size, and the debugging level.
        * toplev.h (read_integral_parameter): Update prototype.

From-SVN: r25856
parent 9c30c0e7
Fri Mar 19 01:54:30 1999 Theodore Papadopoulo <Theodore.Papadopoulo@sophia.inria.fr>
* toplev.c (read_integral_parameter): Constify. Better control of
error messages.
(main): Use read_integral_parameter to set optimize, id_clash_len,
larger_than_size, and the debugging level.
* toplev.h (read_integral_parameter): Update prototype.
Fri Mar 19 01:42:05 1999 Zack Weinberg <zack@rabi.phys.columbia.edu> Fri Mar 19 01:42:05 1999 Zack Weinberg <zack@rabi.phys.columbia.edu>
* system.h: Use putc_unlocked, fputc_unlocked, and * system.h: Use putc_unlocked, fputc_unlocked, and
......
...@@ -1246,25 +1246,30 @@ FILE *rtl_dump_file = NULL; ...@@ -1246,25 +1246,30 @@ FILE *rtl_dump_file = NULL;
/* Decode the string P as an integral parameter. /* Decode the string P as an integral parameter.
If the string is indeed an integer return its numeric value else If the string is indeed an integer return its numeric value else
issue an Invalid Option error for the option PNAME and return DEFVAL. */ issue an Invalid Option error for the option PNAME and return DEFVAL.
If PNAME is zero just return DEFVAL, do not call error. */
int int
read_integral_parameter (p, pname, defval) read_integral_parameter (p, pname, defval)
char *p; const char *p;
char *pname; const char *pname;
int defval; const int defval;
{ {
char *endp = p; const char *endp = p;
while (*endp) while (*endp)
{ {
if (*endp >= '0' && *endp <= '9') if (*endp >= '0' && *endp <= '9')
endp++; endp++;
else else
{ break;
error ("Invalid option `%s'", pname); }
return defval;
} if (*endp != 0)
{
if (pname != 0)
error ("Invalid option `%s'", pname);
return defval;
} }
return atoi (p); return atoi (p);
...@@ -4713,7 +4718,6 @@ main (argc, argv) ...@@ -4713,7 +4718,6 @@ main (argc, argv)
{ {
/* Handle -Os, -O2, -O3, -O69, ... */ /* Handle -Os, -O2, -O3, -O69, ... */
char *p = &argv[i][2]; char *p = &argv[i][2];
int c;
if ((p[0] == 's') && (p[1] == 0)) if ((p[0] == 's') && (p[1] == 0))
{ {
...@@ -4724,12 +4728,10 @@ main (argc, argv) ...@@ -4724,12 +4728,10 @@ main (argc, argv)
} }
else else
{ {
while ((c = *p++)) const int optimize_val = read_integral_parameter (p, p - 2, -1);
if (! (c >= '0' && c <= '9')) if (optimize_val != -1)
break;
if (c == 0)
{ {
optimize = atoi (&argv[i][2]); optimize = optimize_val;
optimize_size = 0; optimize_size = 0;
} }
} }
...@@ -4996,16 +4998,7 @@ main (argc, argv) ...@@ -4996,16 +4998,7 @@ main (argc, argv)
} }
else if (str[0] == 'O') else if (str[0] == 'O')
{ {
register char *p = str+1; /* Already been treated above. Do nothing. */
if (*p == 's')
p++;
else
while (*p && *p >= '0' && *p <= '9')
p++;
if (*p == '\0')
;
else
error ("Invalid option `%s'", argv[i]);
} }
else if (!strcmp (str, "pedantic")) else if (!strcmp (str, "pedantic"))
pedantic = 1; pedantic = 1;
...@@ -5058,39 +5051,23 @@ main (argc, argv) ...@@ -5058,39 +5051,23 @@ main (argc, argv)
; ;
else if (!strncmp (p, "id-clash-", 9)) else if (!strncmp (p, "id-clash-", 9))
{ {
char *endp = p + 9; const int id_clash_val
= read_integral_parameter (p + 9, p - 2, -1);
while (*endp) if (id_clash_val != -1)
{ {
if (*endp >= '0' && *endp <= '9') id_clash_len = id_clash_val;
endp++; warn_id_clash = 1;
else
{
error ("Invalid option `%s'", argv[i]);
goto id_clash_lose;
}
} }
warn_id_clash = 1;
id_clash_len = atoi (str + 10);
id_clash_lose: ;
} }
else if (!strncmp (p, "larger-than-", 12)) else if (!strncmp (p, "larger-than-", 12))
{ {
char *endp = p + 12; const int larger_than_val
= read_integral_parameter (p + 12, p - 2, -1);
while (*endp) if (larger_than_val != -1)
{ {
if (*endp >= '0' && *endp <= '9') larger_than_size = larger_than_val;
endp++; warn_larger_than = 1;
else
{
error ("Invalid option `%s'", argv[i]);
goto larger_than_lose;
}
} }
warn_larger_than = 1;
larger_than_size = atoi (str + 13);
larger_than_lose: ;
} }
else else
error ("Invalid option `%s'", argv[i]); error ("Invalid option `%s'", argv[i]);
...@@ -5118,7 +5095,6 @@ main (argc, argv) ...@@ -5118,7 +5095,6 @@ main (argc, argv)
} }
else if (str[0] == 'g') else if (str[0] == 'g')
{ {
unsigned len;
unsigned level; unsigned level;
/* A lot of code assumes write_symbols == NO_DEBUG if the /* A lot of code assumes write_symbols == NO_DEBUG if the
debugging level is 0 (thus -gstabs1 -gstabs0 would lose track debugging level is 0 (thus -gstabs1 -gstabs0 would lose track
...@@ -5136,48 +5112,43 @@ main (argc, argv) ...@@ -5136,48 +5112,43 @@ main (argc, argv)
"none", "stabs", "coff", "dwarf-1", "dwarf-2", "xcoff" "none", "stabs", "coff", "dwarf-1", "dwarf-2", "xcoff"
}; };
/* The maximum admissible debug level value. */
static const unsigned max_debug_level = 3;
/* Look up STR in the table. */ /* Look up STR in the table. */
for (da = debug_args; da->arg; da++) for (da = debug_args; da->arg; da++)
{ {
if (! strncmp (str, da->arg, strlen (da->arg))) const int da_len = strlen (da->arg);
if (! strncmp (str, da->arg, da_len))
{ {
enum debug_info_type type = da->debug_type; enum debug_info_type type = da->debug_type;
char *p, *q; const char *p = str + da_len;
p = str + strlen (da->arg);
if (*p && (*p < '0' || *p > '9')) if (*p && (*p < '0' || *p > '9'))
continue; continue;
len = p - str;
q = p; level = read_integral_parameter (p, 0,
while (*q && (*q >= '0' && *q <= '9')) max_debug_level + 1);
q++; if (da_len > 1 && !strncmp (str, "gdwarf", da_len))
if (*p)
{ {
level = atoi (p); error ("use -gdwarf -g%d for DWARF v1, level %d",
if (len > 1 && !strncmp (str, "gdwarf", len)) level, level);
{ if (level == 2)
error ("use -gdwarf -g%d for DWARF v1, level %d", error ("use -gdwarf-2 for DWARF v2");
level, level);
if (level == 2)
error ("use -gdwarf-2 for DWARF v2");
}
} }
else
level = 2; /* default debugging info level */ if (level > max_debug_level)
if (*q || level > 3)
{ {
warning ("invalid debug level specification in option: `-%s'", warning ("ignoring option `%s' due to invalid debug level specification",
str); str - 1);
/* ??? This error message is incorrect in the case of level = debug_info_level;
-g4 -g. */
warning ("no debugging information will be generated");
level = 0;
} }
if (type == NO_DEBUG) if (type == NO_DEBUG)
{ {
type = PREFERRED_DEBUGGING_TYPE; type = PREFERRED_DEBUGGING_TYPE;
if (len > 1 && strncmp (str, "ggdb", len) == 0) if (da_len > 1 && strncmp (str, "ggdb", da_len) == 0)
{ {
#if defined (DWARF2_DEBUGGING_INFO) && !defined (LINKER_DOES_NOT_WORK_WITH_DWARF2) #if defined (DWARF2_DEBUGGING_INFO) && !defined (LINKER_DOES_NOT_WORK_WITH_DWARF2)
type = DWARF2_DEBUG; type = DWARF2_DEBUG;
...@@ -5231,8 +5202,19 @@ main (argc, argv) ...@@ -5231,8 +5202,19 @@ main (argc, argv)
} }
else if (str[0] == 'G') else if (str[0] == 'G')
{ {
g_switch_set = TRUE; const int g_switch_val = (str[1] != '\0') ?
g_switch_value = atoi ((str[1] != '\0') ? str+1 : argv[++i]); read_integral_parameter(str + 1, 0, -1) :
read_integral_parameter(argv[++i], 0, -1);
if (g_switch_val != -1)
{
g_switch_set = TRUE;
g_switch_value = g_switch_val;
}
else
{
error("Invalid option `-%s'",str);
}
} }
else if (!strncmp (str, "aux-info", 8)) else if (!strncmp (str, "aux-info", 8))
{ {
......
...@@ -26,7 +26,8 @@ union tree_node; ...@@ -26,7 +26,8 @@ union tree_node;
struct rtx_def; struct rtx_def;
#endif #endif
extern int read_integral_parameter PROTO ((char *, char *, int)); extern int read_integral_parameter PROTO ((const char *, const char *,
const int));
extern int count_error PROTO ((int)); extern int count_error PROTO ((int));
extern void strip_off_ending PROTO ((char *, int)); extern void strip_off_ending PROTO ((char *, int));
extern void print_time PROTO ((const char *, int)); extern void print_time PROTO ((const char *, int));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment