未验证 提交 920750b8 编写于 作者: sangshuduo's avatar sangshuduo 提交者: GitHub

Hotfix/sangshuduo/td 6294 taosdemo long arg (#7644)

* [TD-6294]<fix>: taosdemo support long arg

fix conflict with develop branch.

* fix few words.

* declare default child tables number.

* add support email prompt.

* support the way no space between param and value

* fix uncatched status.

* fix -PP arg.
Co-authored-by: NShuduo Sang <sdsang@taosdata.com>
上级 3a46cbd9
......@@ -806,10 +806,14 @@ static void printHelp() {
"Give this help list");
printf("%s%s%s%s\n", indent, " --usage\t", "\t\t",
"Give a short usage message");
printf("%s%s\n", indent, "-V, --version\t\t\tPrint version info.");
printf("%s%s\n", indent, "-V, --version\t\t\tPrint program version.");
/* printf("%s%s%s%s\n", indent, "-D", indent,
"Delete database if exists. 0: no, 1: yes, default is 1");
*/
printf("\nMandatory or optional arguments to long options are also mandatory or optional\n\
for any corresponding short options.\n\
\n\
Report bugs to <support@taosdata.com>.\n");
}
static bool isStringNumber(char *input)
......@@ -827,6 +831,12 @@ static bool isStringNumber(char *input)
return true;
}
static void errorUnreconized(char *program, char *wrong_arg)
{
fprintf(stderr, "%s: unrecognized options '%s'\n", program, wrong_arg);
fprintf(stderr, "Try `taosdemo --help' or `taosdemo --usage' for more information.\n");
}
static void errorPrintReqArg(char *program, char *wrong_arg)
{
fprintf(stderr,
......@@ -857,23 +867,31 @@ static void errorPrintReqArg3(char *program, char *wrong_arg)
static void parse_args(int argc, char *argv[], SArguments *arguments) {
for (int i = 1; i < argc; i++) {
if ((strcmp(argv[i], "-f") == 0)
if ((0 == strncmp(argv[i], "-f", strlen("-f")))
|| (0 == strncmp(argv[i], "--file", strlen("--file")))) {
if (2 == strlen(argv[i])) {
arguments->demo_mode = false;
if (NULL == argv[i+1]) {
errorPrintReqArg3(argv[0], "f");
if (2 == strlen(argv[i])) {
if (i+1 == argc) {
errorPrintReqArg(argv[0], "f");
exit(EXIT_FAILURE);
}
arguments->metaFile = argv[++i];
} else if (0 == strncmp(argv[i], "-f", strlen("-f"))) {
arguments->metaFile = (char *)(argv[i] + strlen("-f"));
} else if (strlen("--file") == strlen(argv[i])) {
if (i+1 == argc) {
errorPrintReqArg3(argv[0], "--file");
exit(EXIT_FAILURE);
}
arguments->metaFile = argv[++i];
} else if (0 == strncmp(argv[i], "--file=", strlen("--file="))) {
arguments->metaFile = (char *)(argv[i] + strlen("--file="));
} else {
errorUnreconized(argv[0], argv[i]);
exit(EXIT_FAILURE);
}
} else if ((strcmp(argv[i], "-c") == 0)
} else if ((0 == strncmp(argv[i], "-c", strlen("-c")))
|| (0 == strncmp(argv[i], "--config-dir", strlen("--config-dir")))) {
if (2 == strlen(argv[i])) {
if (argc == i+1) {
......@@ -881,13 +899,21 @@ static void parse_args(int argc, char *argv[], SArguments *arguments) {
exit(EXIT_FAILURE);
}
tstrncpy(configDir, argv[++i], TSDB_FILENAME_LEN);
} else if (0 == strncmp(argv[i], "-c", strlen("-c"))) {
tstrncpy(configDir, (char *)(argv[i] + strlen("-")), TSDB_FILENAME_LEN);
} else if (strlen("--config-dir") == strlen(argv[i])) {
if (argc == i+1) {
errorPrintReqArg3(argv[0], "--config-dir");
exit(EXIT_FAILURE);
}
tstrncpy(configDir, argv[++i], TSDB_FILENAME_LEN);
} else if (0 == strncmp(argv[i], "--config-dir=", strlen("--config-dir="))) {
tstrncpy(configDir, (char *)(argv[i] + strlen("--config-dir=")), TSDB_FILENAME_LEN);
} else {
errorUnreconized(argv[0], argv[i]);
exit(EXIT_FAILURE);
}
} else if ((strcmp(argv[i], "-h") == 0)
} else if ((0 == strncmp(argv[i], "-h", strlen("-h")))
|| (0 == strncmp(argv[i], "--host", strlen("--host")))) {
if (2 == strlen(argv[i])) {
if (argc == i+1) {
......@@ -895,13 +921,23 @@ static void parse_args(int argc, char *argv[], SArguments *arguments) {
exit(EXIT_FAILURE);
}
arguments->host = argv[++i];
} else if (0 == strncmp(argv[i], "-h", strlen("-h"))) {
arguments->host = (char *)(argv[i] + strlen("-h"));
} else if (strlen("--host") == strlen(argv[i])) {
if (argc == i+1) {
errorPrintReqArg3(argv[0], "--host");
exit(EXIT_FAILURE);
}
arguments->host = argv[++i];
} else if (0 == strncmp(argv[i], "--host=", strlen("--host="))) {
arguments->host = (char *)(argv[i] + strlen("--host="));
} else {
errorUnreconized(argv[0], argv[i]);
exit(EXIT_FAILURE);
}
} else if ((strcmp(argv[i], "-P") == 0)
} else if (strcmp(argv[i], "-PP") == 0) {
arguments->performance_print = true;
} else if ((0 == strncmp(argv[i], "-P", strlen("-P")))
|| (0 == strncmp(argv[i], "--port", strlen("--port")))) {
if (2 == strlen(argv[i])) {
if (argc == i+1) {
......@@ -912,15 +948,28 @@ static void parse_args(int argc, char *argv[], SArguments *arguments) {
exit(EXIT_FAILURE);
}
arguments->port = atoi(argv[++i]);
} else if (strlen("--port") == strlen(argv[i])) {
errorPrintReqArg3(argv[0], "--port");
exit(EXIT_FAILURE);
} else if (0 == strncmp(argv[i], "--port=", strlen("--port="))) {
if (isStringNumber((char *)(argv[i] + strlen("--port=")))) {
arguments->port = atoi((char *)(argv[i]+strlen("--port=")));
}
} else if (0 == strncmp(argv[i], "-P", strlen("-P"))) {
if (isStringNumber((char *)(argv[i] + strlen("-P")))) {
arguments->port = atoi((char *)(argv[i]+strlen("-P")));
}
} else if (strlen("--port") == strlen(argv[i])) {
if (argc == i+1) {
errorPrintReqArg3(argv[0], "--port");
exit(EXIT_FAILURE);
} else if (!isStringNumber(argv[i+1])) {
errorPrintReqArg2(argv[0], "--port");
exit(EXIT_FAILURE);
}
arguments->port = atoi(argv[++i]);
} else {
errorUnreconized(argv[0], argv[i]);
exit(EXIT_FAILURE);
}
} else if ((strcmp(argv[i], "-I") == 0)
} else if ((0 == strncmp(argv[i], "-I", strlen("-I")))
|| (0 == strncmp(argv[i], "--interface", strlen("--interface")))) {
if (2 == strlen(argv[i])) {
if (argc == i+1) {
......@@ -938,9 +987,6 @@ static void parse_args(int argc, char *argv[], SArguments *arguments) {
exit(EXIT_FAILURE);
}
i++;
} else if (strlen("--interface") == strlen(argv[i])) {
errorPrintReqArg3(argv[0], "--interface");
exit(EXIT_FAILURE);
} else if (0 == strncmp(argv[i], "--interface=", strlen("--interface="))) {
if (0 == strcasecmp((char *)(argv[i] + strlen("--interface=")), "taosc")) {
arguments->iface = TAOSC_IFACE;
......@@ -952,8 +998,38 @@ static void parse_args(int argc, char *argv[], SArguments *arguments) {
errorPrintReqArg3(argv[0], "--interface");
exit(EXIT_FAILURE);
}
} else if (0 == strncmp(argv[i], "-I", strlen("-I"))) {
if (0 == strcasecmp((char *)(argv[i] + strlen("-I")), "taosc")) {
arguments->iface = TAOSC_IFACE;
} else if (0 == strcasecmp((char *)(argv[i] + strlen("-I")), "rest")) {
arguments->iface = REST_IFACE;
} else if (0 == strcasecmp((char *)(argv[i] + strlen("-I")), "stmt")) {
arguments->iface = STMT_IFACE;
} else {
errorPrintReqArg3(argv[0], "-I");
exit(EXIT_FAILURE);
}
} else if ((strcmp(argv[i], "-u") == 0)
} else if (strlen("--interface") == strlen(argv[i])) {
if (argc == i+1) {
errorPrintReqArg3(argv[0], "--interface");
exit(EXIT_FAILURE);
}
if (0 == strcasecmp(argv[i+1], "taosc")) {
arguments->iface = TAOSC_IFACE;
} else if (0 == strcasecmp(argv[i+1], "rest")) {
arguments->iface = REST_IFACE;
} else if (0 == strcasecmp(argv[i+1], "stmt")) {
arguments->iface = STMT_IFACE;
} else {
errorPrintReqArg3(argv[0], "--interface");
exit(EXIT_FAILURE);
}
i++;
} else {
errorUnreconized(argv[0], argv[i]);
exit(EXIT_FAILURE);
}
} else if ((0 == strncmp(argv[i], "-u", strlen("-u")))
|| (0 == strncmp(argv[i], "--user", strlen("--user")))) {
if (2 == strlen(argv[i])) {
if (argc == i+1) {
......@@ -961,13 +1037,21 @@ static void parse_args(int argc, char *argv[], SArguments *arguments) {
exit(EXIT_FAILURE);
}
arguments->user = argv[++i];
} else if (0 == strncmp(argv[i], "-u", strlen("-u"))) {
arguments->user = (char *)(argv[i++] + strlen("-u"));
} else if (0 == strncmp(argv[i], "--user=", strlen("--user="))) {
arguments->user = (char *)(argv[i++] + strlen("--user="));
} else if (strlen("--user") == strlen(argv[i])) {
if (argc == i+1) {
errorPrintReqArg3(argv[0], "--user");
exit(EXIT_FAILURE);
} else if (0 == strncmp(argv[i], "--user=", strlen("--user="))) {
arguments->user = (char *)(argv[i++] + strlen("--user="));
}
} else if ((strncmp(argv[i], "-p", 2) == 0)
arguments->user = argv[++i];
} else {
errorUnreconized(argv[0], argv[i]);
exit(EXIT_FAILURE);
}
} else if ((0 == strncmp(argv[i], "-p", strlen("-p")))
|| (0 == strcmp(argv[i], "--password"))) {
if ((strlen(argv[i]) == 2) || (0 == strcmp(argv[i], "--password"))) {
printf("Enter password: ");
......@@ -979,21 +1063,29 @@ static void parse_args(int argc, char *argv[], SArguments *arguments) {
} else {
tstrncpy(arguments->password, (char *)(argv[i] + 2), SHELL_MAX_PASSWORD_LEN);
}
} else if ((strcmp(argv[i], "-o") == 0)
} else if ((0 == strncmp(argv[i], "-o", strlen("-o")))
|| (0 == strncmp(argv[i], "--output", strlen("--output")))) {
if (2 == strlen(argv[i])) {
if (argc == i+1) {
errorPrintReqArg3(argv[0], "o");
errorPrintReqArg3(argv[0], "--output");
exit(EXIT_FAILURE);
}
arguments->output_file = argv[++i];
} else if (0 == strncmp(argv[i], "--output=", strlen("--output="))) {
arguments->output_file = (char *)(argv[i++] + strlen("--output="));
} else if (0 == strncmp(argv[i], "-o", strlen("-o"))) {
arguments->output_file = (char *)(argv[i++] + strlen("-o"));
} else if (strlen("--output") == strlen(argv[i])) {
if (argc == i+1) {
errorPrintReqArg3(argv[0], "--output");
exit(EXIT_FAILURE);
} else if (0 == strncmp(argv[i], "--output=", strlen("--output="))) {
arguments->output_file = (char *)(argv[i++] + strlen("--output="));
}
} else if ((strcmp(argv[i], "-s") == 0)
arguments->output_file = argv[++i];
} else {
errorUnreconized(argv[0], argv[i]);
exit(EXIT_FAILURE);
}
} else if ((0 == strncmp(argv[i], "-s", strlen("-s")))
|| (0 == strncmp(argv[i], "--sql-file", strlen("--sql-file")))) {
if (2 == strlen(argv[i])) {
if (argc == i+1) {
......@@ -1001,13 +1093,21 @@ static void parse_args(int argc, char *argv[], SArguments *arguments) {
exit(EXIT_FAILURE);
}
arguments->sqlFile = argv[++i];
} else if (0 == strncmp(argv[i], "--sql-file=", strlen("--sql-file="))) {
arguments->host = (char *)(argv[i++] + strlen("--sql-file="));
} else if (0 == strncmp(argv[i], "-s", strlen("-s"))) {
arguments->host = (char *)(argv[i++] + strlen("-s"));
} else if (strlen("--sql-file") == strlen(argv[i])) {
if (argc == i+1) {
errorPrintReqArg3(argv[0], "--sql-file");
exit(EXIT_FAILURE);
} else if (0 == strncmp(argv[i], "--sql-file=", strlen("--sql-file="))) {
arguments->host = (char *)(argv[i++] + strlen("--sql-file="));
}
} else if ((strcmp(argv[i], "-q") == 0)
arguments->sqlFile = argv[++i];
} else {
errorUnreconized(argv[0], argv[i]);
exit(EXIT_FAILURE);
}
} else if ((0 == strncmp(argv[i], "-q", strlen("-q")))
|| (0 == strncmp(argv[i], "--query-mode", strlen("--query-mode")))) {
if (2 == strlen(argv[i])) {
if (argc == i+1) {
......@@ -1018,9 +1118,6 @@ static void parse_args(int argc, char *argv[], SArguments *arguments) {
exit(EXIT_FAILURE);
}
arguments->async_mode = atoi(argv[++i]);
} else if (strlen("--query-mode") == strlen(argv[i])) {
errorPrintReqArg3(argv[0], "--query-mode");
exit(EXIT_FAILURE);
} else if (0 == strncmp(argv[i], "--query-mode=", strlen("--query-mode="))) {
if (isStringNumber((char *)(argv[i] + strlen("--query-mode=")))) {
arguments->async_mode = atoi((char *)(argv[i]+strlen("--query-mode=")));
......@@ -1028,8 +1125,27 @@ static void parse_args(int argc, char *argv[], SArguments *arguments) {
errorPrintReqArg2(argv[0], "--query-mode");
exit(EXIT_FAILURE);
}
} else if (0 == strncmp(argv[i], "-q", strlen("-q"))) {
if (isStringNumber((char *)(argv[i] + strlen("-q")))) {
arguments->async_mode = atoi((char *)(argv[i]+strlen("-q")));
} else {
errorPrintReqArg2(argv[0], "-q");
exit(EXIT_FAILURE);
}
} else if (strlen("--query-mode") == strlen(argv[i])) {
if (argc == i+1) {
errorPrintReqArg3(argv[0], "--query-mode");
exit(EXIT_FAILURE);
} else if (!isStringNumber(argv[i+1])) {
errorPrintReqArg2(argv[0], "--query-mode");
exit(EXIT_FAILURE);
}
arguments->async_mode = atoi(argv[++i]);
} else {
errorUnreconized(argv[0], argv[i]);
exit(EXIT_FAILURE);
}
} else if ((strcmp(argv[i], "-T") == 0)
} else if ((0 == strncmp(argv[i], "-T", strlen("-T")))
|| (0 == strncmp(argv[i], "--threads", strlen("--threads")))) {
if (2 == strlen(argv[i])) {
if (argc == i+1) {
......@@ -1040,9 +1156,6 @@ static void parse_args(int argc, char *argv[], SArguments *arguments) {
exit(EXIT_FAILURE);
}
arguments->num_of_threads = atoi(argv[++i]);
} else if (strlen("--threads") == strlen(argv[i])) {
errorPrintReqArg3(argv[0], "--threads");
exit(EXIT_FAILURE);
} else if (0 == strncmp(argv[i], "--threads=", strlen("--threads="))) {
if (isStringNumber((char *)(argv[i] + strlen("--threads=")))) {
arguments->num_of_threads = atoi((char *)(argv[i]+strlen("--threads=")));
......@@ -1050,8 +1163,27 @@ static void parse_args(int argc, char *argv[], SArguments *arguments) {
errorPrintReqArg2(argv[0], "--threads");
exit(EXIT_FAILURE);
}
} else if (0 == strncmp(argv[i], "-T", strlen("-T"))) {
if (isStringNumber((char *)(argv[i] + strlen("-T")))) {
arguments->num_of_threads = atoi((char *)(argv[i]+strlen("-T")));
} else {
errorPrintReqArg2(argv[0], "-T");
exit(EXIT_FAILURE);
}
} else if ((strcmp(argv[i], "-i") == 0)
} else if (strlen("--threads") == strlen(argv[i])) {
if (argc == i+1) {
errorPrintReqArg3(argv[0], "--threads");
exit(EXIT_FAILURE);
} else if (!isStringNumber(argv[i+1])) {
errorPrintReqArg2(argv[0], "--threads");
exit(EXIT_FAILURE);
}
arguments->num_of_threads = atoi(argv[++i]);
} else {
errorUnreconized(argv[0], argv[i]);
exit(EXIT_FAILURE);
}
} else if ((0 == strncmp(argv[i], "-i", strlen("-i")))
|| (0 == strncmp(argv[i], "--insert-interval", strlen("--insert-interval")))) {
if (2 == strlen(argv[i])) {
if (argc == i+1) {
......@@ -1062,25 +1194,34 @@ static void parse_args(int argc, char *argv[], SArguments *arguments) {
exit(EXIT_FAILURE);
}
arguments->insert_interval = atoi(argv[++i]);
} else if (strlen("--insert-interval")== strlen(argv[i])) {
errorPrintReqArg3(argv[0], "--insert-interval");
exit(EXIT_FAILURE);
} else if (0 == strncmp(argv[i], "--insert-interval=", strlen("--insert-interval="))) {
if (isStringNumber((char *)(argv[i] + 18))) {
if (isStringNumber((char *)(argv[i] + strlen("--insert-interval=")))) {
arguments->insert_interval = atoi((char *)(argv[i]+strlen("--insert-interval=")));
} else {
errorPrintReqArg3(argv[0], "--insert-innterval");
exit(EXIT_FAILURE);
}
} else if (0 == strncmp(argv[i], "-i", strlen("-i"))) {
if (isStringNumber((char *)(argv[i] + strlen("-i")))) {
arguments->insert_interval = atoi((char *)(argv[i]+strlen("-i")));
} else {
errorPrintReqArg3(argv[0], "-i");
exit(EXIT_FAILURE);
}
if ((argc == i+1) ||
(!isStringNumber(argv[i+1]))) {
printHelp();
errorPrint("%s", "\n\t-i need a number following!\n");
} else if (strlen("--insert-interval")== strlen(argv[i])) {
if (argc == i+1) {
errorPrintReqArg3(argv[0], "--insert-interval");
exit(EXIT_FAILURE);
} else if (!isStringNumber(argv[i+1])) {
errorPrintReqArg2(argv[0], "--insert-interval");
exit(EXIT_FAILURE);
}
arguments->insert_interval = atoi(argv[++i]);
} else if ((strcmp(argv[i], "-S") == 0)
} else {
errorUnreconized(argv[0], argv[i]);
exit(EXIT_FAILURE);
}
} else if ((0 == strncmp(argv[i], "-S", strlen("-S")))
|| (0 == strncmp(argv[i], "--time-step", strlen("--time-step")))) {
if (2 == strlen(argv[i])) {
if (argc == i+1) {
......@@ -1091,9 +1232,6 @@ static void parse_args(int argc, char *argv[], SArguments *arguments) {
exit(EXIT_FAILURE);
}
arguments->async_mode = atoi(argv[++i]);
} else if (strlen("--time-step") == strlen(argv[i])) {
errorPrintReqArg3(argv[0], "--time-step");
exit(EXIT_FAILURE);
} else if (0 == strncmp(argv[i], "--time-step=", strlen("--time-step="))) {
if (isStringNumber((char *)(argv[i] + strlen("--time-step=")))) {
arguments->async_mode = atoi((char *)(argv[i]+strlen("--time-step=")));
......@@ -1101,6 +1239,25 @@ static void parse_args(int argc, char *argv[], SArguments *arguments) {
errorPrintReqArg2(argv[0], "--time-step");
exit(EXIT_FAILURE);
}
} else if (0 == strncmp(argv[i], "-S", strlen("-S"))) {
if (isStringNumber((char *)(argv[i] + strlen("-S")))) {
arguments->async_mode = atoi((char *)(argv[i]+strlen("-S")));
} else {
errorPrintReqArg2(argv[0], "-S");
exit(EXIT_FAILURE);
}
} else if (strlen("--time-step") == strlen(argv[i])) {
if (argc == i+1) {
errorPrintReqArg3(argv[0], "--time-step");
exit(EXIT_FAILURE);
} else if (!isStringNumber(argv[i+1])) {
errorPrintReqArg2(argv[0], "--time-step");
exit(EXIT_FAILURE);
}
arguments->async_mode = atoi(argv[++i]);
} else {
errorUnreconized(argv[0], argv[i]);
exit(EXIT_FAILURE);
}
} else if (strcmp(argv[i], "-qt") == 0) {
if ((argc == i+1)
......@@ -1110,9 +1267,9 @@ static void parse_args(int argc, char *argv[], SArguments *arguments) {
exit(EXIT_FAILURE);
}
arguments->query_times = atoi(argv[++i]);
} else if ((strcmp(argv[i], "-B") == 0)
} else if ((0 == strncmp(argv[i], "-B", strlen("-B")))
|| (0 == strncmp(argv[i], "--interlace-rows", strlen("--interlace-rows")))) {
if (2 == strlen(argv[i])) {
if (strlen("-B") == strlen(argv[i])) {
if (argc == i+1) {
errorPrintReqArg(argv[0], "B");
exit(EXIT_FAILURE);
......@@ -1121,9 +1278,6 @@ static void parse_args(int argc, char *argv[], SArguments *arguments) {
exit(EXIT_FAILURE);
}
arguments->interlace_rows = atoi(argv[++i]);
} else if (strlen("--interlace-rows")== strlen(argv[i])) {
errorPrintReqArg3(argv[0], "--interlace-rows");
exit(EXIT_FAILURE);
} else if (0 == strncmp(argv[i], "--interlace-rows=", strlen("--interlace-rows="))) {
if (isStringNumber((char *)(argv[i] + strlen("--interlace-rows=")))) {
arguments->interlace_rows = atoi((char *)(argv[i]+strlen("--interlace-rows=")));
......@@ -1131,10 +1285,29 @@ static void parse_args(int argc, char *argv[], SArguments *arguments) {
errorPrintReqArg2(argv[0], "--interlace-rows");
exit(EXIT_FAILURE);
}
} else if (0 == strncmp(argv[i], "-B", strlen("-B"))) {
if (isStringNumber((char *)(argv[i] + strlen("-B")))) {
arguments->interlace_rows = atoi((char *)(argv[i]+strlen("-B")));
} else {
errorPrintReqArg2(argv[0], "-B");
exit(EXIT_FAILURE);
}
} else if (strlen("--interlace-rows")== strlen(argv[i])) {
if (argc == i+1) {
errorPrintReqArg3(argv[0], "--interlace-rows");
exit(EXIT_FAILURE);
} else if (!isStringNumber(argv[i+1])) {
errorPrintReqArg2(argv[0], "--interlace-rows");
exit(EXIT_FAILURE);
}
arguments->interlace_rows = atoi(argv[++i]);
} else {
errorUnreconized(argv[0], argv[i]);
exit(EXIT_FAILURE);
}
} else if ((strcmp(argv[i], "-r") == 0)
} else if ((0 == strncmp(argv[i], "-r", strlen("-r")))
|| (0 == strncmp(argv[i], "--rec-per-req", 13))) {
if (2 == strlen(argv[i])) {
if (strlen("-r") == strlen(argv[i])) {
if (argc == i+1) {
errorPrintReqArg(argv[0], "r");
exit(EXIT_FAILURE);
......@@ -1143,9 +1316,6 @@ static void parse_args(int argc, char *argv[], SArguments *arguments) {
exit(EXIT_FAILURE);
}
arguments->num_of_RPR = atoi(argv[++i]);
} else if (strlen("--rec-per-req")== strlen(argv[i])) {
errorPrintReqArg3(argv[0], "--rec-per-req");
exit(EXIT_FAILURE);
} else if (0 == strncmp(argv[i], "--rec-per-req=", strlen("--rec-per-req="))) {
if (isStringNumber((char *)(argv[i] + strlen("--rec-per-req=")))) {
arguments->num_of_RPR = atoi((char *)(argv[i]+strlen("--rec-per-req=")));
......@@ -1153,8 +1323,27 @@ static void parse_args(int argc, char *argv[], SArguments *arguments) {
errorPrintReqArg2(argv[0], "--rec-per-req");
exit(EXIT_FAILURE);
}
} else if (0 == strncmp(argv[i], "-r", strlen("-r"))) {
if (isStringNumber((char *)(argv[i] + strlen("-r")))) {
arguments->num_of_RPR = atoi((char *)(argv[i]+strlen("-r")));
} else {
errorPrintReqArg2(argv[0], "-r");
exit(EXIT_FAILURE);
}
} else if (strlen("--rec-per-req")== strlen(argv[i])) {
if (argc == i+1) {
errorPrintReqArg3(argv[0], "--rec-per-req");
exit(EXIT_FAILURE);
} else if (!isStringNumber(argv[i+1])) {
errorPrintReqArg2(argv[0], "--rec-per-req");
exit(EXIT_FAILURE);
}
arguments->num_of_RPR = atoi(argv[++i]);
} else {
errorUnreconized(argv[0], argv[i]);
exit(EXIT_FAILURE);
}
} else if ((strcmp(argv[i], "-t") == 0)
} else if ((0 == strncmp(argv[i], "-t", strlen("-t")))
|| (0 == strncmp(argv[i], "--tables", strlen("--tables")))) {
if (2 == strlen(argv[i])) {
if (argc == i+1) {
......@@ -1165,9 +1354,6 @@ static void parse_args(int argc, char *argv[], SArguments *arguments) {
exit(EXIT_FAILURE);
}
arguments->num_of_tables = atoi(argv[++i]);
} else if (strlen("--tables") == strlen(argv[i])) {
errorPrintReqArg3(argv[0], "--tables");
exit(EXIT_FAILURE);
} else if (0 == strncmp(argv[i], "--tables=", strlen("--tables="))) {
if (isStringNumber((char *)(argv[i] + strlen("--tables=")))) {
arguments->num_of_tables = atoi((char *)(argv[i]+strlen("--tables=")));
......@@ -1175,8 +1361,27 @@ static void parse_args(int argc, char *argv[], SArguments *arguments) {
errorPrintReqArg2(argv[0], "--tables");
exit(EXIT_FAILURE);
}
} else if (0 == strncmp(argv[i], "-t", strlen("-t"))) {
if (isStringNumber((char *)(argv[i] + strlen("-t")))) {
arguments->num_of_tables = atoi((char *)(argv[i]+strlen("-t")));
} else {
errorPrintReqArg2(argv[0], "-t");
exit(EXIT_FAILURE);
}
} else if (strlen("--tables") == strlen(argv[i])) {
if (argc == i+1) {
errorPrintReqArg3(argv[0], "--tables");
exit(EXIT_FAILURE);
} else if (!isStringNumber(argv[i+1])) {
errorPrintReqArg2(argv[0], "--tables");
exit(EXIT_FAILURE);
}
arguments->num_of_tables = atoi(argv[++i]);
} else {
errorUnreconized(argv[0], argv[i]);
exit(EXIT_FAILURE);
}
} else if ((strcmp(argv[i], "-n") == 0)
} else if ((0 == strncmp(argv[i], "-n", strlen("-n")))
|| (0 == strncmp(argv[i], "--records", strlen("--records")))) {
if (2 == strlen(argv[i])) {
if (argc == i+1) {
......@@ -1187,9 +1392,6 @@ static void parse_args(int argc, char *argv[], SArguments *arguments) {
exit(EXIT_FAILURE);
}
arguments->num_of_DPT = atoi(argv[++i]);
} else if (strlen("--records") == strlen(argv[i])) {
errorPrintReqArg3(argv[0], "--records");
exit(EXIT_FAILURE);
} else if (0 == strncmp(argv[i], "--records=", strlen("--records="))) {
if (isStringNumber((char *)(argv[i] + strlen("--records=")))) {
arguments->num_of_DPT = atoi((char *)(argv[i]+strlen("--records=")));
......@@ -1197,25 +1399,51 @@ static void parse_args(int argc, char *argv[], SArguments *arguments) {
errorPrintReqArg2(argv[0], "--records");
exit(EXIT_FAILURE);
}
} else if (0 == strncmp(argv[i], "-r", strlen("-r"))) {
if (isStringNumber((char *)(argv[i] + strlen("-r")))) {
arguments->num_of_DPT = atoi((char *)(argv[i]+strlen("-r")));
} else {
errorPrintReqArg2(argv[0], "-r");
exit(EXIT_FAILURE);
}
} else if (strlen("--records") == strlen(argv[i])) {
if (argc == i+1) {
errorPrintReqArg3(argv[0], "--records");
exit(EXIT_FAILURE);
} else if (!isStringNumber(argv[i+1])) {
errorPrintReqArg2(argv[0], "--records");
exit(EXIT_FAILURE);
}
arguments->num_of_DPT = atoi(argv[++i]);
} else {
errorUnreconized(argv[0], argv[i]);
exit(EXIT_FAILURE);
}
g_totalChildTables = arguments->num_of_DPT;
} else if ((strcmp(argv[i], "-d") == 0)
} else if ((0 == strncmp(argv[i], "-d", strlen("-d")))
|| (0 == strncmp(argv[i], "--database", strlen("--database")))) {
if (2 == strlen(argv[i])) {
if (argc == i+1) {
errorPrintReqArg3(argv[0], "d");
errorPrintReqArg(argv[0], "d");
exit(EXIT_FAILURE);
}
arguments->database = argv[++i];
} else if (0 == strncmp(argv[i], "--database=", strlen("--database="))) {
arguments->output_file = (char *)(argv[i] + strlen("--database="));
} else if (0 == strncmp(argv[i], "-d", strlen("-d"))) {
arguments->output_file = (char *)(argv[i] + strlen("-d"));
} else if (strlen("--database") == strlen(argv[i])) {
if (argc == i+1) {
errorPrintReqArg3(argv[0], "--database");
exit(EXIT_FAILURE);
} else if (0 == strncmp(argv[i], "--database=", strlen("--database="))) {
arguments->output_file = (char *)(argv[i] + strlen("--database="));
}
} else if ((strcmp(argv[i], "-l") == 0)
arguments->database = argv[++i];
} else {
errorUnreconized(argv[0], argv[i]);
exit(EXIT_FAILURE);
}
} else if ((0 == strncmp(argv[i], "-l", strlen("-l")))
|| (0 == strncmp(argv[i], "--columns", strlen("--columns")))) {
arguments->demo_mode = false;
if (2 == strlen(argv[i])) {
......@@ -1227,16 +1455,32 @@ static void parse_args(int argc, char *argv[], SArguments *arguments) {
exit(EXIT_FAILURE);
}
arguments->num_of_CPR = atoi(argv[++i]);
} else if (strlen("--columns")== strlen(argv[i])) {
errorPrintReqArg3(argv[0], "--columns");
exit(EXIT_FAILURE);
} else if (0 == strncmp(argv[i], "--columns=", strlen("--columns="))) {
if (isStringNumber((char *)(argv[i] + strlen("--columns=")))) {
arguments->num_of_CPR = atoi((char *)(argv[i]+strlen("--columns")));
arguments->num_of_CPR = atoi((char *)(argv[i]+strlen("--columns=")));
} else {
errorPrintReqArg2(argv[0], "--columns");
exit(EXIT_FAILURE);
}
} else if (0 == strncmp(argv[i], "-l", strlen("-l"))) {
if (isStringNumber((char *)(argv[i] + strlen("-l")))) {
arguments->num_of_CPR = atoi((char *)(argv[i]+strlen("-l")));
} else {
errorPrintReqArg2(argv[0], "-l");
exit(EXIT_FAILURE);
}
} else if (strlen("--columns")== strlen(argv[i])) {
if (argc == i+1) {
errorPrintReqArg3(argv[0], "--columns");
exit(EXIT_FAILURE);
} else if (!isStringNumber(argv[i+1])) {
errorPrintReqArg2(argv[0], "--columns");
exit(EXIT_FAILURE);
}
arguments->num_of_CPR = atoi(argv[++i]);
} else {
errorUnreconized(argv[0], argv[i]);
exit(EXIT_FAILURE);
}
if (arguments->num_of_CPR > MAX_NUM_COLUMNS) {
......@@ -1251,7 +1495,7 @@ static void parse_args(int argc, char *argv[], SArguments *arguments) {
for (int col = arguments->num_of_CPR; col < MAX_NUM_COLUMNS; col++) {
arguments->datatype[col] = NULL;
}
} else if ((strcmp(argv[i], "-b") == 0)
} else if ((0 == strncmp(argv[i], "-b", strlen("-b")))
|| (0 == strncmp(argv[i], "--data-type", strlen("--data-type")))) {
arguments->demo_mode = false;
......@@ -1262,11 +1506,19 @@ static void parse_args(int argc, char *argv[], SArguments *arguments) {
exit(EXIT_FAILURE);
}
dataType = argv[++i];
} else if (0 == strncmp(argv[i], "--data-type=", strlen("--data-type="))) {
dataType = (char *)(argv[i] + strlen("--data-type="));
} else if (0 == strncmp(argv[i], "-b", strlen("-b"))) {
dataType = (char *)(argv[i] + strlen("-b"));
} else if (strlen("--data-type") == strlen(argv[i])) {
if (argc == i+1) {
errorPrintReqArg3(argv[0], "--data-type");
exit(EXIT_FAILURE);
} else if (0 == strncmp(argv[i], "--data-type=", strlen("--data-type="))) {
dataType = (char *)(argv[i] + strlen("--data-type="));
}
dataType = argv[++i];
} else {
errorUnreconized(argv[0], argv[i]);
exit(EXIT_FAILURE);
}
if (strstr(dataType, ",") == NULL) {
......@@ -1315,7 +1567,7 @@ static void parse_args(int argc, char *argv[], SArguments *arguments) {
}
arguments->datatype[index] = NULL;
}
} else if ((strcmp(argv[i], "-w") == 0)
} else if ((0 == strncmp(argv[i], "-w", strlen("-w")))
|| (0 == strncmp(argv[i], "--binwidth", strlen("--binwidth")))) {
if (2 == strlen(argv[i])) {
if (argc == i+1) {
......@@ -1326,9 +1578,6 @@ static void parse_args(int argc, char *argv[], SArguments *arguments) {
exit(EXIT_FAILURE);
}
arguments->binwidth = atoi(argv[++i]);
} else if (strlen("--binwidth") == strlen(argv[i])) {
errorPrintReqArg3(argv[0], "--binwidth");
exit(EXIT_FAILURE);
} else if (0 == strncmp(argv[i], "--binwidth=", strlen("--binwidth="))) {
if (isStringNumber((char *)(argv[i] + strlen("--binwidth=")))) {
arguments->binwidth = atoi((char *)(argv[i]+strlen("--binwidth=")));
......@@ -1336,21 +1585,47 @@ static void parse_args(int argc, char *argv[], SArguments *arguments) {
errorPrintReqArg2(argv[0], "--binwidth");
exit(EXIT_FAILURE);
}
} else if (0 == strncmp(argv[i], "-w", strlen("-w"))) {
if (isStringNumber((char *)(argv[i] + strlen("-w")))) {
arguments->binwidth = atoi((char *)(argv[i]+strlen("-w")));
} else {
errorPrintReqArg2(argv[0], "-w");
exit(EXIT_FAILURE);
}
} else if (strlen("--binwidth") == strlen(argv[i])) {
if (argc == i+1) {
errorPrintReqArg3(argv[0], "--binwidth");
exit(EXIT_FAILURE);
} else if (!isStringNumber(argv[i+1])) {
errorPrintReqArg2(argv[0], "--binwidth");
exit(EXIT_FAILURE);
}
arguments->binwidth = atoi(argv[++i]);
} else {
errorUnreconized(argv[0], argv[i]);
exit(EXIT_FAILURE);
}
} else if ((strcmp(argv[i], "-m") == 0)
} else if ((0 == strncmp(argv[i], "-m", strlen("-m")))
|| (0 == strncmp(argv[i], "--table-prefix", strlen("--table-prefix")))) {
if (2 == strlen(argv[i])) {
if (argc == i+1) {
errorPrintReqArg3(argv[0], "m");
errorPrintReqArg(argv[0], "m");
exit(EXIT_FAILURE);
}
arguments->tb_prefix = argv[++i];
} else if (strlen("--table-prefix") == strlen(argv[i])
|| (strlen("--table-prefix=") == strlen(argv[i]))) {
errorPrintReqArg3(argv[0], "--table-prefix");
exit(EXIT_FAILURE);
} else if (0 == strncmp(argv[i], "--table-prefix=", strlen("--table-prefix="))) {
arguments->tb_prefix = (char *)(argv[i] + strlen("--table-prefix="));
} else if (0 == strncmp(argv[i], "-m", strlen("-m"))) {
arguments->tb_prefix = (char *)(argv[i] + strlen("-m"));
} else if (strlen("--table-prefix") == strlen(argv[i])) {
if (argc == i+1) {
errorPrintReqArg3(argv[0], "--table-prefix");
exit(EXIT_FAILURE);
}
arguments->tb_prefix = argv[++i];
} else {
errorUnreconized(argv[0], argv[i]);
exit(EXIT_FAILURE);
}
} else if ((strcmp(argv[i], "-N") == 0)
|| (0 == strcmp(argv[i], "--normal-table"))) {
......@@ -1369,9 +1644,7 @@ static void parse_args(int argc, char *argv[], SArguments *arguments) {
arguments->debug_print = true;
} else if (strcmp(argv[i], "-gg") == 0) {
arguments->verbose_print = true;
} else if (strcmp(argv[i], "-PP") == 0) {
arguments->performance_print = true;
} else if ((strcmp(argv[i], "-O") == 0)
} else if ((0 == strncmp(argv[i], "-O", strlen("-O")))
|| (0 == strncmp(argv[i], "--disorder", strlen("--disorder")))) {
if (2 == strlen(argv[i])) {
if (argc == i+1) {
......@@ -1382,9 +1655,6 @@ static void parse_args(int argc, char *argv[], SArguments *arguments) {
exit(EXIT_FAILURE);
}
arguments->disorderRatio = atoi(argv[++i]);
} else if (strlen("--disorder") == strlen(argv[i])) {
errorPrintReqArg3(argv[0], "--disorder");
exit(EXIT_FAILURE);
} else if (0 == strncmp(argv[i], "--disorder=", strlen("--disorder="))) {
if (isStringNumber((char *)(argv[i] + strlen("--disorder=")))) {
arguments->disorderRatio = atoi((char *)(argv[i]+strlen("--disorder=")));
......@@ -1392,6 +1662,25 @@ static void parse_args(int argc, char *argv[], SArguments *arguments) {
errorPrintReqArg2(argv[0], "--disorder");
exit(EXIT_FAILURE);
}
} else if (0 == strncmp(argv[i], "-O", strlen("-O"))) {
if (isStringNumber((char *)(argv[i] + strlen("-O")))) {
arguments->disorderRatio = atoi((char *)(argv[i]+strlen("-O")));
} else {
errorPrintReqArg2(argv[0], "-O");
exit(EXIT_FAILURE);
}
} else if (strlen("--disorder") == strlen(argv[i])) {
if (argc == i+1) {
errorPrintReqArg3(argv[0], "--disorder");
exit(EXIT_FAILURE);
} else if (!isStringNumber(argv[i+1])) {
errorPrintReqArg2(argv[0], "--disorder");
exit(EXIT_FAILURE);
}
arguments->disorderRatio = atoi(argv[++i]);
} else {
errorUnreconized(argv[0], argv[i]);
exit(EXIT_FAILURE);
}
if (arguments->disorderRatio > 50) {
......@@ -1405,7 +1694,7 @@ static void parse_args(int argc, char *argv[], SArguments *arguments) {
arguments->disorderRatio, 0);
arguments->disorderRatio = 0;
}
} else if ((strcmp(argv[i], "-R") == 0)
} else if ((0 == strncmp(argv[i], "-R", strlen("-R")))
|| (0 == strncmp(argv[i], "--disorder-range",
strlen("--disorder-range")))) {
if (2 == strlen(argv[i])) {
......@@ -1417,9 +1706,6 @@ static void parse_args(int argc, char *argv[], SArguments *arguments) {
exit(EXIT_FAILURE);
}
arguments->disorderRange = atoi(argv[++i]);
} else if (strlen("--disorder-range") == strlen(argv[i])) {
errorPrintReqArg3(argv[0], "--disorder-range");
exit(EXIT_FAILURE);
} else if (0 == strncmp(argv[i], "--disorder-range=",
strlen("--disorder-range="))) {
if (isStringNumber((char *)(argv[i] + strlen("--disorder-range=")))) {
......@@ -1429,6 +1715,13 @@ static void parse_args(int argc, char *argv[], SArguments *arguments) {
errorPrintReqArg2(argv[0], "--disorder-range");
exit(EXIT_FAILURE);
}
} else if (0 == strncmp(argv[i], "-R", strlen("-R"))) {
if (isStringNumber((char *)(argv[i] + strlen("-R")))) {
arguments->disorderRange =
atoi((char *)(argv[i]+strlen("-R")));
} else {
errorPrintReqArg2(argv[0], "-R");
exit(EXIT_FAILURE);
}
if (arguments->disorderRange < 0) {
......@@ -1436,7 +1729,20 @@ static void parse_args(int argc, char *argv[], SArguments *arguments) {
arguments->disorderRange, 1000);
arguments->disorderRange = 1000;
}
} else if ((strcmp(argv[i], "-a") == 0)
} else if (strlen("--disorder-range") == strlen(argv[i])) {
if (argc == i+1) {
errorPrintReqArg3(argv[0], "--disorder-range");
exit(EXIT_FAILURE);
} else if (!isStringNumber(argv[i+1])) {
errorPrintReqArg2(argv[0], "--disorder-range");
exit(EXIT_FAILURE);
}
arguments->disorderRange = atoi(argv[++i]);
} else {
errorUnreconized(argv[0], argv[i]);
exit(EXIT_FAILURE);
}
} else if ((0 == strncmp(argv[i], "-a", strlen("-a")))
|| (0 == strncmp(argv[i], "--replica",
strlen("--replica")))) {
if (2 == strlen(argv[i])) {
......@@ -1448,9 +1754,6 @@ static void parse_args(int argc, char *argv[], SArguments *arguments) {
exit(EXIT_FAILURE);
}
arguments->replica = atoi(argv[++i]);
} else if (strlen("--replica") == strlen(argv[i])) {
errorPrintReqArg3(argv[0], "--replica");
exit(EXIT_FAILURE);
} else if (0 == strncmp(argv[i], "--replica=",
strlen("--replica="))) {
if (isStringNumber((char *)(argv[i] + strlen("--replica=")))) {
......@@ -1460,7 +1763,28 @@ static void parse_args(int argc, char *argv[], SArguments *arguments) {
errorPrintReqArg2(argv[0], "--replica");
exit(EXIT_FAILURE);
}
} else if (0 == strncmp(argv[i], "-a", strlen("-a"))) {
if (isStringNumber((char *)(argv[i] + strlen("-a")))) {
arguments->replica =
atoi((char *)(argv[i]+strlen("-a")));
} else {
errorPrintReqArg2(argv[0], "-a");
exit(EXIT_FAILURE);
}
} else if (strlen("--replica") == strlen(argv[i])) {
if (argc == i+1) {
errorPrintReqArg3(argv[0], "--replica");
exit(EXIT_FAILURE);
} else if (!isStringNumber(argv[i+1])) {
errorPrintReqArg2(argv[0], "--replica");
exit(EXIT_FAILURE);
}
arguments->replica = atoi(argv[++i]);
} else {
errorUnreconized(argv[0], argv[i]);
exit(EXIT_FAILURE);
}
if (arguments->replica > 3 || arguments->replica < 1) {
errorPrint("Invalid replica value %d, will be set to %d\n",
arguments->replica, 1);
......@@ -1492,7 +1816,15 @@ static void parse_args(int argc, char *argv[], SArguments *arguments) {
} else {
// to simulate argp_option output
if (strlen(argv[i]) > 2) {
fprintf(stderr, "%s unrecognized options '%s'\n", argv[0], argv[i]);
if (0 == strncmp(argv[i], "--", 2)) {
fprintf(stderr, "%s: unrecognized options '%s'\n", argv[0], argv[i]);
} else if (0 == strncmp(argv[i], "-", 1)) {
char tmp[2] = {0};
tstrncpy(tmp, argv[i]+1, 2);
fprintf(stderr, "%s: invalid options -- '%s'\n", argv[0], tmp);
} else {
fprintf(stderr, "%s: Too many arguments\n", argv[0]);
}
} else {
fprintf(stderr, "%s invalid options -- '%s'\n", argv[0],
(char *)((char *)argv[i])+1);
......@@ -1527,9 +1859,9 @@ static void parse_args(int argc, char *argv[], SArguments *arguments) {
arguments->use_metric ? "true" : "false");
if (*(arguments->datatype)) {
printf("# Specified data type: ");
for (int i = 0; i < MAX_NUM_COLUMNS; i++)
if (arguments->datatype[i])
printf("%s,", arguments->datatype[i]);
for (int c = 0; c < MAX_NUM_COLUMNS; c++)
if (arguments->datatype[c])
printf("%s,", arguments->datatype[c]);
else
break;
printf("\n");
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册