8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-23 21:23:03 +01:00

Fix of isql command line parser: check for repeated switches or database name.

This commit is contained in:
mkubecek 2006-03-28 04:31:35 +00:00
parent 4c9e95c6cf
commit 4a94466a5a
5 changed files with 69 additions and 38 deletions

View File

@ -168,44 +168,48 @@ enum switch_id {
#ifdef DEV_BUILD
SWITCH_EXTRACTTBL,
#endif
// this id has to be the last
SWITCH_UNKNOWN
};
bool switch_used[SWITCH_UNKNOWN];
struct switch_info {
switch_id id; // switch id
const char* text; // canonical switch name
unsigned int abbrlen; // minimum abbreviation length
switch_argtype argtype; // argument type (SWARG_NONE if none)
int usage_id; // message id for usage text
bool allow_dup; // switch can be used more then once
};
switch_info switches[] = {
#ifdef DEV_BUILD
{ SWITCH_EXTRACTTBL, "xt", 2, SWARG_NONE, -1 },
{ SWITCH_EXTRACTTBL, "xt", 2, SWARG_NONE, -1, false },
#endif
{ SWITCH_EXTRACTALL, "a", 1, SWARG_NONE, 11 },
{ SWITCH_BAIL, "bail", 1, SWARG_NONE, 104 },
{ SWITCH_CACHE, "cache", 1, SWARG_INTEGER, 111 },
{ SWITCH_CHARSET, "charset", 2, SWARG_STRING, 122 },
{ SWITCH_DATABASE, "d", 1, SWARG_STRING, 123 },
{ SWITCH_ECHO, "echo", 1, SWARG_NONE, 124 },
{ SWITCH_EXTRACT, "extract", 2, SWARG_NONE, 125 },
{ SWITCH_INPUT, "input", 1, SWARG_STRING, 126 },
{ SWITCH_MERGE, "merge", 1, SWARG_NONE, 127 },
{ SWITCH_MERGE2, "m2", 2, SWARG_NONE, 128 },
{ SWITCH_NOAUTOCOMMIT, "noautocommit", 1, SWARG_NONE, 129 },
{ SWITCH_NOWARN, "nowarn", 3, SWARG_NONE, 130 },
{ SWITCH_OUTPUT, "output", 1, SWARG_STRING, 131 },
{ SWITCH_PAGE, "page", 3, SWARG_INTEGER, 132 },
{ SWITCH_PASSWORD, "password", 1, SWARG_STRING, 133 },
{ SWITCH_QUIET, "quiet", 1, SWARG_NONE, 134 },
{ SWITCH_ROLE, "role", 1, SWARG_STRING, 135 },
{ SWITCH_ROLE2, "r2", 2, SWARG_STRING, 136 },
{ SWITCH_SQLDIALECT, "s", 1, SWARG_INTEGER, 137 },
{ SWITCH_TERM, "term", 1, SWARG_STRING, 138 },
{ SWITCH_USER, "user", 1, SWARG_STRING, 139 },
{ SWITCH_EXTRACT, "x", 1, SWARG_NONE, 140 },
{ SWITCH_VERSION, "z", 1, SWARG_NONE, 141 }
{ SWITCH_EXTRACTALL, "a", 1, SWARG_NONE, 11, false },
{ SWITCH_BAIL, "bail", 1, SWARG_NONE, 104, false },
{ SWITCH_CACHE, "cache", 1, SWARG_INTEGER, 111, false },
{ SWITCH_CHARSET, "charset", 2, SWARG_STRING, 122, false },
{ SWITCH_DATABASE, "d", 1, SWARG_STRING, 123, false },
{ SWITCH_ECHO, "echo", 1, SWARG_NONE, 124, false },
{ SWITCH_EXTRACT, "extract", 2, SWARG_NONE, 125, false },
{ SWITCH_INPUT, "input", 1, SWARG_STRING, 126, true },
{ SWITCH_MERGE, "merge", 1, SWARG_NONE, 127, false },
{ SWITCH_MERGE2, "m2", 2, SWARG_NONE, 128, false },
{ SWITCH_NOAUTOCOMMIT, "noautocommit", 1, SWARG_NONE, 129, false },
{ SWITCH_NOWARN, "nowarn", 3, SWARG_NONE, 130, false },
{ SWITCH_OUTPUT, "output", 1, SWARG_STRING, 131, false },
{ SWITCH_PAGE, "page", 3, SWARG_INTEGER, 132, false },
{ SWITCH_PASSWORD, "password", 1, SWARG_STRING, 133, false },
{ SWITCH_QUIET, "quiet", 1, SWARG_NONE, 134, false },
{ SWITCH_ROLE, "role", 1, SWARG_STRING, 135, false },
{ SWITCH_ROLE2, "r2", 2, SWARG_STRING, 136, false },
{ SWITCH_SQLDIALECT, "s", 1, SWARG_INTEGER, 137, false },
{ SWITCH_TERM, "term", 1, SWARG_STRING, 138, false },
{ SWITCH_USER, "user", 1, SWARG_STRING, 139, false },
{ SWITCH_EXTRACT, "x", 1, SWARG_NONE, 140, false },
{ SWITCH_VERSION, "z", 1, SWARG_NONE, 141, false }
};
@ -5560,6 +5564,10 @@ static processing_state parse_arg(int argc,
bool istable = false;
#endif
for (int j = 0; j < SWITCH_UNKNOWN; j++) {
switch_used[j] = false;
}
int i = 1;
const char* s = argv[i];
while (i < argc) {
@ -5577,6 +5585,14 @@ static processing_state parse_arg(int argc,
if (!fb_utils::strnicmp(s + 1, switches[j].text, swlen) && (swlen >= switches[j].abbrlen))
{
swid = switches[j].id;
if (switch_used[swid] && !switches[j].allow_dup)
{
ISQL_msg_get(USAGE_DUPSW, errbuf, s + 1);
STDERROUT(errbuf);
ret = ps_ERR;
break;
}
switch_used[swid] = true;
if (switches[j].argtype != SWARG_NONE)
{
swarg_str = argv[++i];
@ -5590,12 +5606,12 @@ static processing_state parse_arg(int argc,
long value = strtol(swarg_str, &err, 10);
if (*err) {
// conversion error
ISQL_msg_get(USAGE_NOTINT, errbuf, swarg_str);
ISQL_msg_get(USAGE_NOTINT, errbuf, swarg_str, s + 1);
STDERROUT(errbuf);
ret = ps_ERR;
}
else if ((value < INT_MIN) || (value > INT_MAX)) {
ISQL_msg_get(USAGE_RANGE, errbuf, swarg_str);
ISQL_msg_get(USAGE_RANGE, errbuf, swarg_str, s + 1);
STDERROUT(errbuf);
ret = ps_ERR;
}
@ -5709,7 +5725,7 @@ static processing_state parse_arg(int argc,
case SWITCH_CACHE:
if (swarg_int <= 0) {
ISQL_msg_get(USAGE_RANGE, errbuf, swarg_str);
ISQL_msg_get(USAGE_RANGE, errbuf, swarg_str, s + 1);
STDERROUT(errbuf);
ret = ps_ERR;
}
@ -5772,12 +5788,20 @@ static processing_state parse_arg(int argc,
else
{
// This is not a switch, it is a db_name
STRARGNCPY(isqlGlob.global_Db_name, s, sizeof(isqlGlob.global_Db_name) - 1);
if (isqlGlob.global_Db_name[0]) {
// We already have a database name
ISQL_msg_get(USAGE_DUPDB, errbuf, isqlGlob.global_Db_name, s);
STDERROUT(errbuf);
ret = ps_ERR;
}
else {
STRARGNCPY(isqlGlob.global_Db_name, s, sizeof(isqlGlob.global_Db_name) - 1);
#ifdef DEV_BUILD
// If there is a table name, it follows
if (istable && (s = argv[++i]) && *s)
STRARGNCPY(tabname, s, WORDLENGTH - 1);
// If there is a table name, it follows
if (istable && (s = argv[++i]) && *s)
STRARGNCPY(tabname, s, WORDLENGTH - 1);
#endif
}
}
// Quit the loop of interpreting if we got an error

View File

@ -231,9 +231,11 @@ const int MSG_FUNCTIONS = 118; // Functions:
const int EXACTLINE = 119; // At line %d in file %s
const int AFTERLINE = 120; // After line %d in file %s
const int USAGE = 1; // usage: syntax
const int USAGE_NOARG = 142; // usage: missing argument of "%s"
const int USAGE_NOTINT = 143; // usage: argument "%s" is not an integer
const int USAGE_RANGE = 144; // usage: value %s is out of range
const int USAGE_NOARG = 142; // usage: missing argument for "%s"
const int USAGE_NOTINT = 143; // usage: argument "%s" for switch "%s" is not an integer
const int USAGE_RANGE = 144; // usage: value "%s" for switch "%s" is out of range
const int USAGE_DUPSW = 145; // usage: switch "%s" or its equivalent used more than once
const int USAGE_DUPDB = 146; // usage: more than one database name: "%s", "%s"
// Initialize types

View File

@ -22,7 +22,7 @@ INSERT INTO FACILITIES (LAST_CHANGE, FACILITY, FAC_CODE, MAX_NUMBER) VALUES ('20
/*
INSERT INTO FACILITIES (LAST_CHANGE, FACILITY, FAC_CODE, MAX_NUMBER) VALUES ('1996-11-07 13:38:43', 'GJRN', 16, 241);
*/
INSERT INTO FACILITIES (LAST_CHANGE, FACILITY, FAC_CODE, MAX_NUMBER) VALUES ('2006-03-26 00:31:22', 'ISQL', 17, 145);
INSERT INTO FACILITIES (LAST_CHANGE, FACILITY, FAC_CODE, MAX_NUMBER) VALUES ('2006-03-26 21:42:44', 'ISQL', 17, 147);
INSERT INTO FACILITIES (LAST_CHANGE, FACILITY, FAC_CODE, MAX_NUMBER) VALUES ('1998-11-04 11:06:15', 'GSEC', 18, 91);
INSERT INTO FACILITIES (LAST_CHANGE, FACILITY, FAC_CODE, MAX_NUMBER) VALUES ('2002-03-05 02:30:12', 'LICENSE', 19, 60);
INSERT INTO FACILITIES (LAST_CHANGE, FACILITY, FAC_CODE, MAX_NUMBER) VALUES ('2002-03-05 02:31:54', 'DOS', 20, 74);

View File

@ -1167,6 +1167,9 @@ INSERT INTO HISTORY (CHANGE_NUMBER, CHANGE_WHO, CHANGE_DATE, FAC_CODE, NUMBER, O
INSERT INTO HISTORY (CHANGE_NUMBER, CHANGE_WHO, CHANGE_DATE, FAC_CODE, NUMBER, OLD_TEXT, OLD_ACTION, OLD_EXPLANATION, LOCALE) VALUES (1164, 'mkubecek', '2006-03-24 01:20:04', 17, 134, ' -q do not show the welcome message "Use CONNECT..."', NULL, NULL, 'c_pg');
INSERT INTO HISTORY (CHANGE_NUMBER, CHANGE_WHO, CHANGE_DATE, FAC_CODE, NUMBER, OLD_TEXT, OLD_ACTION, OLD_EXPLANATION, LOCALE) VALUES (1165, 'mkubecek', '2006-03-24 01:23:37', 17, 138, ' -t <terminator> command terminator (set term)', NULL, NULL, 'c_pg');
INSERT INTO HISTORY (CHANGE_NUMBER, CHANGE_WHO, CHANGE_DATE, FAC_CODE, NUMBER, OLD_TEXT, OLD_ACTION, OLD_EXPLANATION, LOCALE) VALUES (1166, 'mkubecek', '2006-03-24 01:25:21', 17, 139, ' -u <user> user name', NULL, NULL, 'c_pg');
INSERT INTO HISTORY (CHANGE_NUMBER, CHANGE_WHO, CHANGE_DATE, FAC_CODE, NUMBER, OLD_TEXT, OLD_ACTION, OLD_EXPLANATION, LOCALE) VALUES (1167, 'mkubecek', '2006-03-26 13:08:09', 17, 142, 'missing argument of switch "%s"', NULL, NULL, 'c_pg');
INSERT INTO HISTORY (CHANGE_NUMBER, CHANGE_WHO, CHANGE_DATE, FAC_CODE, NUMBER, OLD_TEXT, OLD_ACTION, OLD_EXPLANATION, LOCALE) VALUES (1168, 'mkubecek', '2006-03-26 13:08:09', 17, 143, 'argument "%s" is not an integer', NULL, NULL, 'c_pg');
INSERT INTO HISTORY (CHANGE_NUMBER, CHANGE_WHO, CHANGE_DATE, FAC_CODE, NUMBER, OLD_TEXT, OLD_ACTION, OLD_EXPLANATION, LOCALE) VALUES (1169, 'mkubecek', '2006-03-26 13:08:09', 17, 144, 'value "%s" is out of range', NULL, NULL, 'c_pg');
COMMIT WORK;

View File

@ -3026,8 +3026,10 @@ INSERT INTO MESSAGES (SYMBOL, ROUTINE, MODULE, TRANS_NOTES, FAC_CODE, NUMBER, FL
INSERT INTO MESSAGES (SYMBOL, ROUTINE, MODULE, TRANS_NOTES, FAC_CODE, NUMBER, FLAGS, TEXT, "ACTION", EXPLANATION) VALUES ('USAGE_USER', 'ISQL_main', 'isql.epp', NULL, 17, 139, NULL, ' -u(ser) <user> user name', NULL, NULL);
INSERT INTO MESSAGES (SYMBOL, ROUTINE, MODULE, TRANS_NOTES, FAC_CODE, NUMBER, FLAGS, TEXT, "ACTION", EXPLANATION) VALUES ('USAGE_XTRACT', 'ISQL_main', 'isql.epp', NULL, 17, 140, NULL, ' -x extract metadata', NULL, NULL);
INSERT INTO MESSAGES (SYMBOL, ROUTINE, MODULE, TRANS_NOTES, FAC_CODE, NUMBER, FLAGS, TEXT, "ACTION", EXPLANATION) VALUES ('USAGE_VERSION', 'ISQL_main', 'isql.epp', NULL, 17, 141, NULL, ' -z show program and server version', NULL, NULL);
INSERT INTO MESSAGES (SYMBOL, ROUTINE, MODULE, TRANS_NOTES, FAC_CODE, NUMBER, FLAGS, TEXT, "ACTION", EXPLANATION) VALUES ('USAGE_NOARG', 'ISQL_main', 'isql.epp', NULL, 17, 142, NULL, 'missing argument of switch "%s"', NULL, NULL);
INSERT INTO MESSAGES (SYMBOL, ROUTINE, MODULE, TRANS_NOTES, FAC_CODE, NUMBER, FLAGS, TEXT, "ACTION", EXPLANATION) VALUES ('USAGE_NOTINT', 'ISQL_main', 'isql.epp', NULL, 17, 143, NULL, 'argument "%s" is not an integer', NULL, NULL);
INSERT INTO MESSAGES (SYMBOL, ROUTINE, MODULE, TRANS_NOTES, FAC_CODE, NUMBER, FLAGS, TEXT, "ACTION", EXPLANATION) VALUES ('USAGE_RANGE', 'ISQL_main', 'isql.epp', NULL, 17, 144, NULL, 'value "%s" is out of range', NULL, NULL);
INSERT INTO MESSAGES (SYMBOL, ROUTINE, MODULE, TRANS_NOTES, FAC_CODE, NUMBER, FLAGS, TEXT, "ACTION", EXPLANATION) VALUES ('USAGE_NOARG', 'ISQL_main', 'isql.epp', NULL, 17, 142, NULL, 'missing argument for switch "%s"', NULL, NULL);
INSERT INTO MESSAGES (SYMBOL, ROUTINE, MODULE, TRANS_NOTES, FAC_CODE, NUMBER, FLAGS, TEXT, "ACTION", EXPLANATION) VALUES ('USAGE_NOTINT', 'ISQL_main', 'isql.epp', NULL, 17, 143, NULL, 'argument "%s" for switch "%s" is not an integer', NULL, NULL);
INSERT INTO MESSAGES (SYMBOL, ROUTINE, MODULE, TRANS_NOTES, FAC_CODE, NUMBER, FLAGS, TEXT, "ACTION", EXPLANATION) VALUES ('USAGE_RANGE', 'ISQL_main', 'isql.epp', NULL, 17, 144, NULL, 'value "%s" for switch "%s" is out of range', NULL, NULL);
INSERT INTO MESSAGES (SYMBOL, ROUTINE, MODULE, TRANS_NOTES, FAC_CODE, NUMBER, FLAGS, TEXT, "ACTION", EXPLANATION) VALUES ('USAGE_DUPSW', 'ISQL_main', 'isql.epp', NULL, 17, 145, NULL, 'switch "%s" or its equivalent used more than once', NULL, NULL);
INSERT INTO MESSAGES (SYMBOL, ROUTINE, MODULE, TRANS_NOTES, FAC_CODE, NUMBER, FLAGS, TEXT, "ACTION", EXPLANATION) VALUES ('USAGE_DUPDB', 'ISQL_main', 'isql.epp', NULL, 17, 146, NULL, 'more than one database name: "%s", "%s"', NULL, NULL);
COMMIT WORK;