simMain.c 1.9 KB
Newer Older
S
[TD-73]  
slguan 已提交
1 2
/*
 * Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
S
slguan 已提交
3
 *
S
[TD-73]  
slguan 已提交
4 5 6
 * 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.
S
slguan 已提交
7
 *
S
[TD-73]  
slguan 已提交
8 9 10 11 12 13 14
 * 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/>.
 */
S
slguan 已提交
15

H
Haojun Liao 已提交
16
#define _DEFAULT_SOURCE
S
slguan 已提交
17 18
#include "os.h"
#include "tglobal.h"
S
slguan 已提交
19
#include "sim.h"
S
Shengliang Guan 已提交
20
#undef TAOS_MEM_CHECK
S
slguan 已提交
21 22 23

bool simAsyncQuery = false;

H
Haojun Liao 已提交
24
void simHandleSignal(int32_t signo) {
S
slguan 已提交
25 26 27 28
  simSystemCleanUp();
  exit(1);
}

H
Haojun Liao 已提交
29
int32_t main(int32_t argc, char *argv[]) {
S
slguan 已提交
30 31
  char scriptFile[MAX_FILE_NAME_LEN] = "sim_main_test.sim";

H
Haojun Liao 已提交
32
  for (int32_t i = 1; i < argc; ++i) {
S
slguan 已提交
33
    if (strcmp(argv[i], "-c") == 0 && i < argc - 1) {
B
Bomin Zhang 已提交
34
      tstrncpy(configDir, argv[++i], MAX_FILE_NAME_LEN);
S
slguan 已提交
35 36 37 38 39 40
    } else if (strcmp(argv[i], "-f") == 0 && i < argc - 1) {
      strcpy(scriptFile, argv[++i]);
    } else if (strcmp(argv[i], "-a") == 0) {
      simAsyncQuery = true;
    } else {
      printf("usage: %s [options] \n", argv[0]);
H
Haojun Liao 已提交
41
      printf("       [-c config]: config directory, default is: %s\n", configDir);
S
slguan 已提交
42 43 44 45 46 47 48 49 50 51 52
      printf("       [-f script]: script filename\n");
      exit(0);
    }
  }

  if (!simSystemInit()) {
    simError("failed to initialize the system");
    simSystemCleanUp();
    exit(1);
  }

S
Shengliang Guan 已提交
53
  simInfo("simulator is running ...");
S
slguan 已提交
54 55 56 57 58 59 60 61 62 63 64 65 66
  signal(SIGINT, simHandleSignal);

  SScript *script = simParseScript(scriptFile);
  if (script == NULL) {
    simError("parse script file:%s failed", scriptFile);
    exit(-1);
  }

  simScriptList[++simScriptPos] = script;
  simExecuteScript(script);

  return 0;
}