Add some input validation code to various functions

darcs-hash:20060222154152-ac50b-608032284165f099beecd1cd4f7c6bb2b45df432.gz
This commit is contained in:
axel
2006-02-23 01:41:52 +10:00
parent 3afead1827
commit ca04fc745d
11 changed files with 225 additions and 84 deletions

26
main.c
View File

@@ -122,6 +122,10 @@ int main( int argc, char **argv )
"command", required_argument, 0, 'c'
}
,
{
"debug-level", required_argument, 0, 'd'
}
,
{
"interactive", no_argument, 0, 'i'
}
@@ -152,14 +156,14 @@ int main( int argc, char **argv )
int opt = getopt_long( argc,
argv,
"hilvc:p:",
"hilvc:p:d:",
long_options,
&opt_index );
#else
int opt = getopt( argc,
argv,
"hilvc:p:" );
"hilvc:p:d:" );
#endif
if( opt == -1 )
break;
@@ -174,6 +178,22 @@ int main( int argc, char **argv )
is_interactive_session = 0;
break;
case 'd':
{
char *end;
int tmp = strtol(optarg, &end, 10);
if( tmp >= 0 && tmp <=10 && !*end )
{
debug_level=tmp;
}
else
{
debug( 0, _(L"Invalid value '%s' for debug level switch"), optarg );
exit(1);
}
break;
}
case 'h':
cmd = "help";
break;
@@ -233,7 +253,7 @@ int main( int argc, char **argv )
wchar_t *cmd_wcs = str2wcs( cmd );
res = eval( cmd_wcs, 0, TOP );
free(cmd_wcs);
reader_exit(0);
reader_exit(0);
}
else
{