shellDarwin.c 18.0 KB
Newer Older
S
slguan 已提交
1
/*
2
 * Copyright (c) 2022 TAOS Data, Inc. <jhtao@taosdata.com>
S
slguan 已提交
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
 *
 * This program is free software: you can use, redistribute, and/or modify
 * it under the terms of the GNU Affero General Public License, version 3
 * or later ("AGPL"), as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */

#define __USE_XOPEN

#include "os.h"

#include "shell.h"
#include "shellCommand.h"
#include "tkey.h"

F
eok  
freemine 已提交
24
#include "tscLog.h"
A
Alex Duan 已提交
25
#include "shellAuto.h"
F
eok  
freemine 已提交
26

S
slguan 已提交
27 28 29 30 31 32 33 34 35 36 37
#define OPT_ABORT 1 /* �Cabort */

int indicator = 1;
struct termios oldtio;

extern int wcwidth(wchar_t c);
void insertChar(Command *cmd, char *c, int size);


void printHelp() {
  char indent[10] = "        ";
38
  printf("TDengine Command Line is used to test the TDengine database\n");
S
slguan 已提交
39 40

  printf("%s%s\n", indent, "-h");
41
  printf("%s%s%s\n", indent, indent, "TDengine server IP address to connect. The default host is localhost.");
S
slguan 已提交
42 43 44 45 46
  printf("%s%s\n", indent, "-p");
  printf("%s%s%s\n", indent, indent, "The password to use when connecting to the server.");
  printf("%s%s\n", indent, "-P");
  printf("%s%s%s\n", indent, indent, "The TCP/IP port number to use for the connection");
  printf("%s%s\n", indent, "-u");
47
  printf("%s%s%s\n", indent, indent, "The user name to use when connecting to the server.");
S
slguan 已提交
48 49 50 51 52 53 54 55 56 57
  printf("%s%s\n", indent, "-c");
  printf("%s%s%s\n", indent, indent, "Configuration directory.");
  printf("%s%s\n", indent, "-s");
  printf("%s%s%s\n", indent, indent, "Commands to run without enter the shell.");
  printf("%s%s\n", indent, "-r");
  printf("%s%s%s\n", indent, indent, "Output time as unsigned long..");
  printf("%s%s\n", indent, "-f");
  printf("%s%s%s\n", indent, indent, "Script to run without enter the shell.");
  printf("%s%s\n", indent, "-d");
  printf("%s%s%s\n", indent, indent, "Database to use when connecting to the server.");
58
  printf("%s%s\n", indent, "-z");
S
slguan 已提交
59 60 61 62 63
  printf("%s%s%s\n", indent, indent, "Time zone of the shell, default is local.");
  printf("%s%s\n", indent, "-D");
  printf("%s%s%s\n", indent, indent, "Use multi-thread to import all SQL files in the directory separately.");
  printf("%s%s\n", indent, "-T");
  printf("%s%s%s\n", indent, indent, "Number of threads when using multi-thread to import data.");
64 65
  printf("%s%s\n", indent, "-R");
  printf("%s%s%s\n", indent, indent, "Connect and interact with TDengine use restful.");
66 67
  printf("%s%s\n", indent, "-E");
  printf("%s%s%s\n", indent, indent, "The DSN to use when connecting TDengine's cloud services.");
S
slguan 已提交
68 69 70
  exit(EXIT_SUCCESS);
}

A
Alex Duan 已提交
71
char      DARWINCLIENT_VERSION[] = "Welcome to the TDengine Command Line Interface from %s, Client Version:%s\n"
72
                             "Copyright (c) 2022 by TAOS Data, Inc. All rights reserved.\n\n";
73
char g_password[SHELL_MAX_PASSWORD_LEN];
74

S
TD-1057  
Shengliang Guan 已提交
75
void shellParseArgument(int argc, char *argv[], SShellArguments *arguments) {
S
slguan 已提交
76 77 78 79
  wordexp_t full_path;
  for (int i = 1; i < argc; i++) {
    // for host
    if (strcmp(argv[i], "-h") == 0) {
80 81 82 83 84 85 86
        if (i < argc - 1) {
            arguments->cloud = false;
            arguments->host = argv[++i];
        } else {
            fprintf(stderr, "option -h requires an argument\n");
            exit(EXIT_FAILURE);
        }
S
slguan 已提交
87 88
    }
      // for password
89 90
    else if ((strncmp(argv[i], "-p", 2) == 0)
            || (strncmp(argv[i], "--password", 10) == 0)) {
91 92
        strcpy(tsOsName, "Darwin");
        printf(DARWINCLIENT_VERSION, tsOsName, taos_get_client_info());
93 94
        if ((strlen(argv[i]) == 2)
                  || (strncmp(argv[i], "--password", 10) == 0)) {
95
            printf("Enter password: ");
96
            taosSetConsoleEcho(false);
97
            if (scanf("%s", g_password) > 1) {
98 99
                fprintf(stderr, "password read error\n");
            }
100
            taosSetConsoleEcho(true);
101 102
            getchar();
        } else {
103
            tstrncpy(g_password, (char *)(argv[i] + 2), SHELL_MAX_PASSWORD_LEN);
104 105
        }
        arguments->password = g_password;
106
        arguments->is_use_passwd = true;
107 108
        strcpy(argv[i], "");
        argc -= 1;
S
slguan 已提交
109
    }
110
    // for management port
S
slguan 已提交
111 112
    else if (strcmp(argv[i], "-P") == 0) {
      if (i < argc - 1) {
113
        arguments->cloud = false;
S
#1811  
slguan 已提交
114
        arguments->port = atoi(argv[++i]);
S
slguan 已提交
115 116 117 118 119 120 121 122 123 124 125 126 127 128
      } else {
        fprintf(stderr, "option -P requires an argument\n");
        exit(EXIT_FAILURE);
      }
    }
      // for user
    else if (strcmp(argv[i], "-u") == 0) {
      if (i < argc - 1) {
        arguments->user = argv[++i];
      } else {
        fprintf(stderr, "option -u requires an argument\n");
        exit(EXIT_FAILURE);
      }
    } else if (strcmp(argv[i], "-c") == 0) {
129
      if (i < argc - 1) {
130
        arguments->cloud = false;
B
Bomin Zhang 已提交
131
        if (strlen(argv[++i]) >= TSDB_FILENAME_LEN) {
H
Hui Li 已提交
132 133 134 135
          fprintf(stderr, "config file path: %s overflow max len %d\n", argv[i], TSDB_FILENAME_LEN - 1);
          exit(EXIT_FAILURE);
        }
        strcpy(configDir, argv[i]);
S
slguan 已提交
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
      } else {
        fprintf(stderr, "Option -c requires an argument\n");
        exit(EXIT_FAILURE);
      }
    } else if (strcmp(argv[i], "-s") == 0) {
      if (i < argc - 1) {
        arguments->commands = argv[++i];
      } else {
        fprintf(stderr, "option -s requires an argument\n");
        exit(EXIT_FAILURE);
      }
    } else if (strcmp(argv[i], "-r") == 0) {
      arguments->is_raw_time = true;
    }
      // For temperory batch commands to run TODO
    else if (strcmp(argv[i], "-f") == 0) {
      if (i < argc - 1) {
        strcpy(arguments->file, argv[++i]);
      } else {
        fprintf(stderr, "option -f requires an argument\n");
        exit(EXIT_FAILURE);
      }
    }
      // for default database
    else if (strcmp(argv[i], "-d") == 0) {
      if (i < argc - 1) {
        arguments->database = argv[++i];
      } else {
        fprintf(stderr, "option -d requires an argument\n");
        exit(EXIT_FAILURE);
      }
    }
      // For time zone
169
    else if (strcmp(argv[i], "-z") == 0) {
S
slguan 已提交
170 171 172
      if (i < argc - 1) {
        arguments->timezone = argv[++i];
      } else {
173
        fprintf(stderr, "option -z requires an argument\n");
S
slguan 已提交
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
        exit(EXIT_FAILURE);
      }
    }
      // For import directory
    else if (strcmp(argv[i], "-D") == 0) {
      if (i < argc - 1) {
        if (wordexp(argv[++i], &full_path, 0) != 0) {
          fprintf(stderr, "Invalid path %s\n", argv[i]);
          exit(EXIT_FAILURE);
        }
        strcpy(arguments->dir, full_path.we_wordv[0]);
        wordfree(&full_path);
      } else {
        fprintf(stderr, "option -D requires an argument\n");
        exit(EXIT_FAILURE);
      }
    }
      // For time zone
    else if (strcmp(argv[i], "-T") == 0) {
      if (i < argc - 1) {
S
slguan 已提交
194
        arguments->threadNum = atoi(argv[++i]);
S
slguan 已提交
195 196 197 198 199
      } else {
        fprintf(stderr, "option -T requires an argument\n");
        exit(EXIT_FAILURE);
      }
    }
200 201

    else if (strcmp(argv[i], "-R") == 0) {
202
        arguments->cloud = false;
203 204 205
        arguments->restful = true;
    }

206
    else if (strcmp(argv[i], "-E") == 0) {
207
        if (i < argc - 1) {
208
            arguments->cloudDsn = argv[++i];
209
        } else {
210
            fprintf(stderr, "options -E requires an argument\n");
211 212 213 214
            exit(EXIT_FAILURE);
        }
    }

S
slguan 已提交
215 216 217 218 219 220 221 222 223 224
      // For temperory command TODO
    else if (strcmp(argv[i], "--help") == 0) {
      printHelp();
      exit(EXIT_FAILURE);
    } else {
      fprintf(stderr, "wrong options\n");
      printHelp();
      exit(EXIT_FAILURE);
    }
  }
225 226 227 228 229 230 231 232 233 234
  if (args.cloudDsn == NULL) {
      if (args.cloud) {
          args.cloudDsn = getenv("TDENGINE_CLOUD_DSN");
          if (args.cloudDsn == NULL) {
              args.cloud = false;
          }
      }
  } else {
      args.cloud = true;
  }
S
slguan 已提交
235 236
}

D
fix bug  
dapan1121 已提交
237
int32_t shellReadCommand(TAOS *con, char *command) {
S
slguan 已提交
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258
  unsigned hist_counter = history.hend;
  char utf8_array[10] = "\0";
  Command cmd;
  memset(&cmd, 0, sizeof(cmd));
  cmd.buffer = (char *)calloc(1, MAX_COMMAND_SIZE);
  cmd.command = (char *)calloc(1, MAX_COMMAND_SIZE);
  showOnScreen(&cmd);

  // Read input.
  char c;
  while (1) {
    c = getchar();

    if (c < 0) {  // For UTF-8
      int count = countPrefixOnes(c);
      utf8_array[0] = c;
      for (int k = 1; k < count; k++) {
        c = getchar();
        utf8_array[k] = c;
      }
      insertChar(&cmd, utf8_array, count);
A
Alex Duan 已提交
259 260 261 262
      pressOtherKey(c);
    } else if (c == TAB_KEY) {
      // press TAB key
      pressTabKey(con, &cmd);
S
slguan 已提交
263
    } else if (c < '\033') {
A
Alex Duan 已提交
264
      pressOtherKey(c);
S
slguan 已提交
265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292
      // Ctrl keys.  TODO: Implement ctrl combinations
      switch (c) {
        case 1:  // ctrl A
          positionCursorHome(&cmd);
          break;
        case 3:
          printf("\n");
          resetCommand(&cmd, "");
          kill(0, SIGINT);
          break;
        case 4:  // EOF or Ctrl+D
          printf("\n");
          taos_close(con);
          // write the history
          write_history();
          exitShell();
          break;
        case 5:  // ctrl E
          positionCursorEnd(&cmd);
          break;
        case 8:
          backspaceChar(&cmd);
          break;
        case '\n':
        case '\r':
          printf("\n");
          if (isReadyGo(&cmd)) {
            sprintf(command, "%s%s", cmd.buffer, cmd.command);
S
TD-1848  
Shengliang Guan 已提交
293 294
            tfree(cmd.buffer);
            tfree(cmd.command);
D
fix bug  
dapan1121 已提交
295
            return 0;
S
slguan 已提交
296 297 298 299
          } else {
            updateBuffer(&cmd);
          }
          break;
300 301 302
        case 11:  // Ctrl + K;
          clearLineAfter(&cmd);
          break;
S
slguan 已提交
303 304 305 306
        case 12:  // Ctrl + L;
          system("clear");
          showOnScreen(&cmd);
          break;
307 308 309
        case 21:  // Ctrl + U
          clearLineBefore(&cmd);
          break;
310 311 312
        case 23:  // Ctrl + W;
          positionCursorMiddle(&cmd);
          break;
S
slguan 已提交
313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388
      }
    } else if (c == '\033') {
      c = getchar();
      switch (c) {
        case '[':
          c = getchar();
          switch (c) {
            case 'A':  // Up arrow
              if (hist_counter != history.hstart) {
                hist_counter = (hist_counter + MAX_HISTORY_SIZE - 1) % MAX_HISTORY_SIZE;
                resetCommand(&cmd, (history.hist[hist_counter] == NULL) ? "" : history.hist[hist_counter]);
              }
              break;
            case 'B':  // Down arrow
              if (hist_counter != history.hend) {
                int next_hist = (hist_counter + 1) % MAX_HISTORY_SIZE;

                if (next_hist != history.hend) {
                  resetCommand(&cmd, (history.hist[next_hist] == NULL) ? "" : history.hist[next_hist]);
                } else {
                  resetCommand(&cmd, "");
                }
                hist_counter = next_hist;
              }
              break;
            case 'C':  // Right arrow
              moveCursorRight(&cmd);
              break;
            case 'D':  // Left arrow
              moveCursorLeft(&cmd);
              break;
            case '1':
              if ((c = getchar()) == '~') {
                // Home key
                positionCursorHome(&cmd);
              }
              break;
            case '2':
              if ((c = getchar()) == '~') {
                // Insert key
              }
              break;
            case '3':
              if ((c = getchar()) == '~') {
                // Delete key
                deleteChar(&cmd);
              }
              break;
            case '4':
              if ((c = getchar()) == '~') {
                // End key
                positionCursorEnd(&cmd);
              }
              break;
            case '5':
              if ((c = getchar()) == '~') {
                // Page up key
              }
              break;
            case '6':
              if ((c = getchar()) == '~') {
                // Page down key
              }
              break;
            case 72:
              // Home key
              positionCursorHome(&cmd);
              break;
            case 70:
              // End key
              positionCursorEnd(&cmd);
              break;
          }
          break;
      }
    } else if (c == 0x7f) {
A
Alex Duan 已提交
389
      pressOtherKey(c);
S
slguan 已提交
390 391 392
      // press delete key
      backspaceChar(&cmd);
    } else {
A
Alex Duan 已提交
393
      pressOtherKey(c);
S
slguan 已提交
394 395 396
      insertChar(&cmd, &c, 1);
    }
  }
D
fix bug  
dapan1121 已提交
397 398

  return 0;
S
slguan 已提交
399 400 401 402 403 404 405 406 407 408
}

void *shellLoopQuery(void *arg) {
  if (indicator) {
    get_old_terminal_mode(&oldtio);
    indicator = 0;
  }

  TAOS *con = (TAOS *)arg;

409 410
  setThreadName("shellLoopQuery");

S
slguan 已提交
411 412 413 414 415 416 417 418
  pthread_cleanup_push(cleanup_handler, NULL);

    char *command = malloc(MAX_COMMAND_SIZE);
    if (command == NULL){
      tscError("failed to malloc command");
      return NULL;
    }

D
fix bug  
dapan1121 已提交
419 420
    int32_t err = 0;

421 422
    do {
      // Read command from shell.
S
slguan 已提交
423 424
      memset(command, 0, MAX_COMMAND_SIZE);
      set_terminal_mode();
D
fix bug  
dapan1121 已提交
425 426 427 428
      err = shellReadCommand(con, command);
      if (err) {
        break;
      }
S
slguan 已提交
429
      reset_terminal_mode();
430
    } while (shellRunCommand(con, command) == 0);
S
slguan 已提交
431

432 433 434
  tfree(command);
  exitShell();

S
slguan 已提交
435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493
  pthread_cleanup_pop(1);

  return NULL;
}

int get_old_terminal_mode(struct termios *tio) {
  /* Make sure stdin is a terminal. */
  if (!isatty(STDIN_FILENO)) {
    return -1;
  }

  // Get the parameter of current terminal
  if (tcgetattr(0, &oldtio) != 0) {
    return -1;
  }

  return 1;
}

void reset_terminal_mode() {
  if (tcsetattr(0, TCSANOW, &oldtio) != 0) {
    fprintf(stderr, "Fail to reset the terminal properties!\n");
    exit(EXIT_FAILURE);
  }
}

void set_terminal_mode() {
  struct termios newtio;

  /* if (atexit(reset_terminal_mode) != 0) { */
  /*     fprintf(stderr, "Error register exit function!\n"); */
  /*     exit(EXIT_FAILURE); */
  /* } */

  memcpy(&newtio, &oldtio, sizeof(oldtio));

  // Set new terminal attributes.
  newtio.c_iflag &= ~(IXON | IXOFF | ICRNL | INLCR | IGNCR | IMAXBEL | ISTRIP);
  newtio.c_iflag |= IGNBRK;

  // newtio.c_oflag &= ~(OPOST|ONLCR|OCRNL|ONLRET);
  newtio.c_oflag |= OPOST;
  newtio.c_oflag |= ONLCR;
  newtio.c_oflag &= ~(OCRNL | ONLRET);

  newtio.c_lflag &= ~(IEXTEN | ICANON | ECHO | ECHOE | ECHONL | ECHOCTL | ECHOPRT | ECHOKE | ISIG);
  newtio.c_cc[VMIN] = 1;
  newtio.c_cc[VTIME] = 0;

  if (tcsetattr(0, TCSANOW, &newtio) != 0) {
    fprintf(stderr, "Fail to set terminal properties!\n");
    exit(EXIT_FAILURE);
  }
}

void get_history_path(char *history) { sprintf(history, "%s/%s", getpwuid(getuid())->pw_dir, HISTORY_FILE); }

void clearScreen(int ecmd_pos, int cursor_pos) {
  struct winsize w;
494 495 496 497 498
  if (ioctl(0, TIOCGWINSZ, &w) < 0 || w.ws_col == 0 || w.ws_row == 0) {
    //fprintf(stderr, "No stream device, and use default value(col 120, row 30)\n");
    w.ws_col = 120;
    w.ws_row = 30;
  }
S
slguan 已提交
499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515

  int cursor_x = cursor_pos / w.ws_col;
  int cursor_y = cursor_pos % w.ws_col;
  int command_x = ecmd_pos / w.ws_col;
  positionCursor(cursor_y, LEFT);
  positionCursor(command_x - cursor_x, DOWN);
  fprintf(stdout, "\033[2K");
  for (int i = 0; i < command_x; i++) {
    positionCursor(1, UP);
    fprintf(stdout, "\033[2K");
  }
  fflush(stdout);
}

void showOnScreen(Command *cmd) {
  struct winsize w;
  if (ioctl(0, TIOCGWINSZ, &w) < 0 || w.ws_col == 0 || w.ws_row == 0) {
516 517 518
    //fprintf(stderr, "No stream device\n");
    w.ws_col = 120;
    w.ws_row = 30;
S
slguan 已提交
519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541
  }

  wchar_t wc;
  int size = 0;

  // Print out the command.
  char *total_string = malloc(MAX_COMMAND_SIZE);
  memset(total_string, '\0', MAX_COMMAND_SIZE);
  if (strcmp(cmd->buffer, "") == 0) {
    sprintf(total_string, "%s%s", PROMPT_HEADER, cmd->command);
  } else {
    sprintf(total_string, "%s%s", CONTINUE_PROMPT, cmd->command);
  }

  int remain_column = w.ws_col;
  /* size = cmd->commandSize + prompt_size; */
  for (char *str = total_string; size < cmd->commandSize + prompt_size;) {
    int ret = mbtowc(&wc, str, MB_CUR_MAX);
    if (ret < 0) break;
    size += ret;
    /* assert(size >= 0); */
    int width = wcwidth(wc);
    if (remain_column > width) {
542
      printf("%lc", wc);
S
slguan 已提交
543 544 545
      remain_column -= width;
    } else {
      if (remain_column == width) {
546
        printf("%lc\n\r", wc);
S
slguan 已提交
547 548
        remain_column = w.ws_col;
      } else {
549
        printf("\n\r%lc", wc);
S
slguan 已提交
550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591
        remain_column = w.ws_col - width;
      }
    }

    str = total_string + size;
  }

  free(total_string);
  /* for (int i = 0; i < size; i++){ */
  /*     char c = total_string[i]; */
  /*     if (k % w.ws_col == 0) { */
  /*         printf("%c\n\r", c); */
  /*     } */
  /*     else { */
  /*         printf("%c", c); */
  /*     } */
  /*     k += 1; */
  /* } */

  // Position the cursor
  int cursor_pos = cmd->screenOffset + prompt_size;
  int ecmd_pos = cmd->endOffset + prompt_size;

  int cursor_x = cursor_pos / w.ws_col;
  int cursor_y = cursor_pos % w.ws_col;
  // int cursor_y = cursor % w.ws_col;
  int command_x = ecmd_pos / w.ws_col;
  int command_y = ecmd_pos % w.ws_col;
  // int command_y = (command.size() + prompt_size) % w.ws_col;
  positionCursor(command_y, LEFT);
  positionCursor(command_x, UP);
  positionCursor(cursor_x, DOWN);
  positionCursor(cursor_y, RIGHT);
  fflush(stdout);
}

void cleanup_handler(void *arg) { tcsetattr(0, TCSANOW, &oldtio); }

void exitShell() {
  tcsetattr(0, TCSANOW, &oldtio);
  exit(EXIT_SUCCESS);
}
592

593
int tcpConnect(char* host, int port) {
594
    struct sockaddr_in serv_addr;
595 596
    if (port == 0) {
        port = 6041;
597 598
        args.port = 6041;
    }
599 600
    if (NULL == host) {
        host = "localhost";
601 602 603
        args.host = "localhost";
    }

604
    struct hostent *server = gethostbyname(host);
605
    if ((server == NULL) || (server->h_addr == NULL)) {
606
        fprintf(stderr, "no such host: %s\n", host);
607 608 609 610
        return -1;
    }
    memset(&serv_addr, 0, sizeof(struct sockaddr_in));
    serv_addr.sin_family = AF_INET;
611
    serv_addr.sin_port = htons(port);
612 613 614 615 616 617 618 619 620 621 622 623 624 625
    memcpy(&(serv_addr.sin_addr.s_addr), server->h_addr, server->h_length);
    args.socket = socket(AF_INET, SOCK_STREAM, 0);
    if (args.socket < 0) {
        fprintf(stderr, "failed to create socket\n");
        return -1;
    }
    int retConn = connect(args.socket, (struct sockaddr *)&serv_addr, sizeof(struct sockaddr));
    if (retConn < 0) {
        fprintf(stderr, "failed to connect\n");
        close(args.socket);
        return -1;
    }
    return 0;
}