示例#1
0
NodeBase* NodeSetAssociateData::run(base_script_t* param) {
    if (NULL == param) {
        IVR_WARN("base_script_t pointer should not be null");
        return NULL;
    }

    IVR_TRACE("%s", enter(param->name_var_map).c_str());

    const char* exit = EXIT_FAIL;
    string key_data;
    string value_data;
    const map<string, variable_t>& vars = param->name_var_map;

    if (!parse_all(_key_data, vars, key_data) || key_data.empty() ||
            !parse_all(_value_data, vars, value_data)) {
        IVR_WARN("get key or key failed!, key %s, value %s", _key_data.c_str(), _value_data.c_str());
        return _find_exit_node(param, exit);
    }

    if (IVR_SUCCESS == ims_mgr_t::get_instance()->set_associatedata(
                param->imsno, param->imssid, key_data, value_data)) {
        IVR_TRACE("set associate data success!");
        exit = EXIT_SUCC;
    } else {
        IVR_WARN("set associate data failed!");
    }

    return _find_exit_node(param, exit);
}
示例#2
0
t_list				*parse_data(t_list **raw_data)
{
	char		*line;
	int			((*parser[3])(char *));
	t_list		*data;
	int			ok;
	int			i;

	i = 0;
	ok = 1;
	data = NULL;
	*raw_data = NULL;
	parser[0] = &is_antnumber;
	parser[1] = &is_room;
	parser[2] = &is_link;
	while (ok && (get_next_line(0, &line) > 0) && *line)
	{
		*raw_data = list_add(raw_data, line, ft_strlen(line) + 1);
		if (!parse_hash(line, &data, &ok))
			ok = parse_all(line, &data, parser, &i);
		free(line);
	}
	if (i != 2)
		ft_error();
	return (data);
}
示例#3
0
int
parse_columns(columns_t columns, add_column_cb ac, map_name_cb cn,
		const char str[], void *arg)
{
	column_info_t *list;
	size_t list_len;
	if((list = parse_all(cn, str, &list_len, arg)) != NULL)
	{
		add_all(columns, ac, list, list_len);
		free(list);
		return 0;
	}
	return 1;
}
示例#4
0
int
fuse_opt_parse(struct fuse_args *args, void *data,
		const struct fuse_opt *opts, fuse_opt_proc_t proc)
{
	struct fuse_args outargs = FUSE_ARGS_INIT(0, NULL);
	int rv;

	if (!args || !args->argv || !args->argc)
		return 0;

	rv = parse_all(args, &outargs, data, opts, proc);
	if (rv != -1) {
		/* Succeeded. Swap the outargs and args. */
		struct fuse_args tmp = *args;
		*args = outargs;
		outargs = tmp;
	}

	fuse_opt_free_args(&outargs);
	return rv;
}
示例#5
0
NodeBase* NodeGetAssociateData::run(base_script_t* param) {
    if (NULL == param) {
        IVR_WARN("base_script_t pointer should not be null");
        return NULL;
    }

    IVR_TRACE("%s", enter(param->name_var_map).c_str());

    const char* exit = EXIT_FAIL;

    string data_key, data_value;
    const map<string, variable_t>& vars = param->name_var_map;

    if (vars.find(_value_data) == vars.end()) {
        IVR_WARN("δÕÒµ½ÐèÒª¸³ÖµµÄ±äÁ¿ %s", _value_data.c_str());
        return _find_exit_node(param, exit);
    }

    if (parse_all(_key_data, vars, data_key) && !data_key.empty()) {
        int32_t recode = ims_mgr_t::get_instance()->get_associatedata(param->imsno, param->imssid, data_key,
                         data_value);

        if (IVR_SUCCESS == recode) {
            variable_t& var = param->name_var_map[_value_data];

            if (var.type == STRING && NULL != var.pvalue) {
                *((string*)(var.pvalue)) = data_value;
                exit = EXIT_SUCC;
            } else {
                IVR_WARN("get associate data set result failed");
            }
        } else {
            IVR_WARN("get associate data failed");
        }
    } else {
        IVR_WARN("½âÎökey×Ö·û´®Ê§°Ü %s", _key_data.c_str());
    }

    return _find_exit_node(param, exit);
}
示例#6
0
int main(int argc, char *argv[])
{
  FILE *fp, *fp2;
  char buf[100000][100];	/*命令 読み込み用バッファ */
  char fpt[FPT_MAX_COUNT][20] = { 0 };
  char ofname[1000] = "result";
  int i = 0, j, k;
  //メモリ上の浮動小数点テーブルの位置
  int fpmemoffset = 0;
  int result;
  bool doprintregs = false, doprintmem = false;
  program *answer;
  program2 *answer2;
  double t2, t1;
  int ll = 0;

  while ((result = getopt(argc, argv, "rmo:")) != -1) {
    switch (result) {

      /* 値をとらないオプション */
    case 'r':
      /* getoptの返り値は見付けたオプションである. */
      doprintregs = true;
      break;
    case 'm':
      doprintmem = true;
      break;

    case 'o':
      /* 値を取る引数の場合は外部変数optargにその値を格納する. */
      strcpy(ofname, optarg);
      break;
    }
  }
  argc -= optind;
  argv += optind;


  /*assembler-file open and read */
  fp = fopen(argv[0], "r");
  if (fp == NULL) {
    printf("%sが開けませんaa\n", argv[0]);
    return 1;
  }

  if (argc > 1) {
    fp2 = fopen(argv[1], "r");
    if (fp2 == NULL) {
      printf("%sが開けません\n", argv[1]);
      return 1;
    }
    for (i = 0; i < FPT_MAX_COUNT; ++i) {
      if (fgets(fpt[i], 20, fp2) == NULL) {	/* 1行読み込み */
	break;		/* 末尾まで完了したか、エラー発生で終了 */
      }
    }

    for (j = 0; j < i; ++j) {
      //エラーが起こっても関係ない
      //printf("%s\n", fpt[j]);
      memory[j + fpmemoffset].i = (int) strtoll(fpt[j], NULL, 16);
    }
    //print_memory();
  }

  i = 0;
  while (1) {
    if (fgets(buf[i], 81, fp) == NULL) {	/* 1行読み込み */
      break;		/* 末尾まで完了したか、エラー発生で終了 */
    }
    i++;
  }

  out_fp = fopen(ofname, "w");

  answer = parse_all(buf, i);
  answer2 = parse_all2(parse_all(buf, i));
  
  //print_program(answer);

  t1 = gettimeofday_sec();
  do_assemble2(answer, answer2);
  t2 = gettimeofday_sec();
  
  printf("%lf\n", t2 - t1);
  printf("%lld\n", cnt);

  if (doprintregs)
    print_register();
  if (doprintmem)
    print_memory();

  fclose(fp);
  fclose(fp2);
  fclose(out_fp);
    
  return 0;
}
示例#7
0
xml_configuration::xml_configuration(std::list<std::string> files) : _files { std::move(files) }
{
    parse_all();
}
示例#8
0
NodeBase* NodeJsonGet::run(base_script_t* param) {
    IVR_TRACE("%s", enter(param->name_var_map).c_str());

    const char* exit = EXIT_FAIL;
    std::string value = "";
    std::string input = "";
    std::string key = "";
    variable_t var_value;
    variable_t var_reason;
    std::string reason_type_error = "reason type error";
    var_value.pvalue = &reason_type_error;
    var_reason.pvalue = &reason_type_error;

    if (param->name_var_map.find(_value) == param->name_var_map.end()) {
        IVR_WARN("not found variable %s", _value.c_str());
        goto LEAVE;
    }

    if (param->name_var_map.find(_reason) == param->name_var_map.end()) {
        IVR_WARN("not found variable %s", _reason.c_str());
        goto LEAVE;
    }


    var_value = param->name_var_map[_value];
    var_reason = param->name_var_map[_reason];

    if (var_reason.type != INT32) {
        IVR_WARN("变量%s 的类型错误", _reason.c_str());
        //(*(std::string*)var_reason.pvalue).assign("5");
        goto LEAVE;
    }

    (*(std::string*)var_reason.pvalue).assign("0");

    if (parse_all(_input, param->name_var_map, input) && parse_all(_key, param->name_var_map, key)) {
        IVR_TRACE("INPUT: %s; key: %s", input.c_str(), key.c_str());
        //获取json串
        json_object* obj = json_tokener_parse(input.c_str());

        if (is_error(obj) || NULL == obj) {
            IVR_TRACE("未找到需要赋值的变量");
            (*(std::string*)var_reason.pvalue).assign("1");
            goto LEAVE;
        }

        const char* tmp = json_object_get_string(obj);

        if (tmp[0] >= '0' && tmp[0] <= '9') {
            IVR_TRACE("未找到需要赋值的变量");
            (*(std::string*)var_reason.pvalue).assign("1");
            json_object_put(obj);
            goto LEAVE;
        }

        //查找key
        json_object* obj_value = json_object_object_get(obj, key.c_str());

        if (is_error(obj_value) || NULL == obj_value) {
            IVR_TRACE("未找到key值");
            (*(std::string*)var_reason.pvalue).assign("2");
            json_object_put(obj);
            goto LEAVE;
        }

        //根据需要转化
        if (0 == strcasecmp(_valuetype.c_str(), PARAMITEM_TYPE_STRING)) {
            const char* cstr_value = json_object_get_string(obj_value);

            if (NULL == cstr_value) {
                IVR_TRACE("转换key值错误");
                (*(std::string*)var_reason.pvalue).assign("3");
                json_object_put(obj);
                //json_object_put(obj_value);
                goto LEAVE;
            }

            if (var_value.type != STRING) {
                IVR_TRACE("赋值变量类型错误");
                (*(std::string*)var_reason.pvalue).assign("4");
                json_object_put(obj);
                //json_object_put(obj_value);
                goto LEAVE;
            }

            value.assign(cstr_value);
            *(string*)var_value.pvalue = value;
            exit = EXIT_SUCC;
            json_object_put(obj);
            goto LEAVE;
        } else if (0 == strcasecmp(_valuetype.c_str(), PARAMITEM_TYPE_INT32)) {
            int32_t int32_value = json_object_get_int(obj_value);

            if (var_value.type != INT32) {
                IVR_TRACE("赋值变量类型错误");
                (*(std::string*)var_reason.pvalue).assign("4");
                json_object_put(obj);
                //json_object_put(obj_value);
                goto LEAVE;
            }

            std::stringstream ss;
            ss << int32_value;
            ss >> value;
            *(string*)var_value.pvalue = value;
            exit = EXIT_SUCC;
            json_object_put(obj);
            goto LEAVE;
        } else if (0 == strcasecmp(_valuetype.c_str(), PARAMITEM_TYPE_BOOL)) {
示例#9
0
文件: simoo.c 项目: pandora2000/aiueo
int main(int argc, char *argv[])
{
  FILE *fp, *fp2;
  char buf[100000][100];	/*命令 読み込み用バッファ */
  char fpt[FPT_MAX_COUNT][20] = { 0 };
  char ofname[1000] = "result";
  int i = 0, j, k;
  //メモリ上の浮動小数点テーブルの位置
  int fpmemoffset = 0;
  int result;
  bool doprintregs = false, doprintmem = false;
  program *answer;
  program2 *answer2;
  double t2, t1;
  int ll = 0;

  while ((result = getopt(argc, argv, "rmo:")) != -1) {
    switch (result) {

      /* 値をとらないオプション */
    case 'r':
      /* getoptの返り値は見付けたオプションである. */
      doprintregs = true;
      break;
    case 'm':
      doprintmem = true;
      break;

    case 'o':
      /* 値を取る引数の場合は外部変数optargにその値を格納する. */
      strcpy(ofname, optarg);
      break;

      /* 以下二つのcaseは意味がないようだ.
	 getoptが直接エラーを出力してくれるから.
	 プログラムを終了するなら意味があるかも知れない */
    case ':':
      /* 値を取る引数に値がなかった場合:を返す. */
      fprintf(stdout, "%c needs value\n", result);
      break;

      /* getoptの引数で指定されなかったオプションを受け取ると?を返す. */
    case '?':
      fprintf(stdout, "unknown\n");
      break;
    }
  }
  argc -= optind;
  argv += optind;
    

  /*
    if (argc < 3) {
    fprintf(stderr, "<Useage>:%s assembler-file fp-table-file\n",
    argv[0]);
    return 1;
    }
  */


  /*assembler-file open and read */
  fp = fopen(argv[0], "r");
  if (fp == NULL) {
    printf("%sが開けませんaa\n", argv[0]);
    return 1;
  }

  if (argc > 1) {
    fp2 = fopen(argv[1], "r");
    if (fp2 == NULL) {
      printf("%sが開けません\n", argv[1]);
      return 1;
    }
    for (i = 0; i < FPT_MAX_COUNT; ++i) {
      if (fgets(fpt[i], 20, fp2) == NULL) {	/* 1行読み込み */
	break;		/* 末尾まで完了したか、エラー発生で終了 */
      }
    }

    for (j = 0; j < i; ++j) {
      //エラーが起こっても関係ない
      //printf("%s\n", fpt[j]);
      memory[j + fpmemoffset].i = (int) strtoll(fpt[j], NULL, 16);
    }
    //print_memory();
  }

  i = 0;
  while (1) {
    if (fgets(buf[i], 81, fp) == NULL) {	/* 1行読み込み */
      break;		/* 末尾まで完了したか、エラー発生で終了 */
    }
    i++;
  }

  out_fp = fopen(ofname, "w");

  answer = parse_all(buf, i);

  answer2 = parse_all2(answer);
  //print_program(answer);

  t1 = gettimeofday_sec();
  //do_assemble(answer);
  do_assemble2(answer, answer2);
  t2 = gettimeofday_sec();
  printf("%lf\n", t2 - t1);

  if (doprintregs)
    print_register();
  if (doprintmem)
    print_memory();

  fclose(fp);
  fclose(fp2);
  fclose(out_fp);

  printf("%f\n", ppp);
  printf("%f\n", nnn);
  /*
    fprintf(fp, "P3\n%d %d %d\n", memory[8193].i, memory[8194].i,
    memory[8195].i);
    for (i = 8196; i < memory[8192].i; i = i + 3) {
    fprintf(fp, "%d %d %d\n", (int) memory[i].d,
    (int) memory[i + 1].d, (int) memory[i + 2].d);
    }
  */

    
  return 0;
}
示例#10
0
NodeBase* NodeJsonGetArray::run(base_script_t* param) {
    IVR_TRACE("%s", enter(param->name_var_map).c_str());

    const char* exit = EXIT_FAIL;
    std::string value = "";
    std::string valueindex = "";
    std::string input = "";
    std::string key = "";

    variable_t var_value;
    variable_t var_reason;
    std::string reason_type_error = "reason type error";
    var_value.pvalue = &reason_type_error;
    var_reason.pvalue = &reason_type_error;

    if (param->name_var_map.find(_value) == param->name_var_map.end()) {
        IVR_WARN("not found variable %s", _value.c_str());
        goto LEAVE;
    }

    if (param->name_var_map.find(_reason) == param->name_var_map.end()) {
        IVR_WARN("not found variable %s", _reason.c_str());
        goto LEAVE;
    }

    var_value = param->name_var_map[_value];
    var_reason = param->name_var_map[_reason];

    if (var_reason.type != INT32) {
        IVR_WARN("变量%s 的类型错误", _reason.c_str());
        //(*(std::string*)var_reason.pvalue).assign("5");
        goto LEAVE;
    }

    (*(std::string*)var_reason.pvalue).assign("0");

    if (parse_all(_input, param->name_var_map, input)
            && parse_all(_key, param->name_var_map, key)
            && parse_expression(_valueindex, param->name_var_map, valueindex)) {
        IVR_TRACE("INPUT: %s; key: %s", input.c_str(), key.c_str());
        //获取json串
        json_object* obj = json_tokener_parse(input.c_str());

        if (is_error(obj) || NULL == obj) {
            IVR_TRACE("未找到需要赋值的变量");
            (*(std::string*)var_reason.pvalue).assign("1");
            goto LEAVE;
        }

        const char* tmp = json_object_get_string(obj);

        if (tmp[0] >= '0' && tmp[0] <= '9') {
            IVR_TRACE("未找到需要赋值的变量");
            (*(std::string*)var_reason.pvalue).assign("1");
            json_object_put(obj);
            goto LEAVE;
        }

        //查找key
        json_object* obj_value = json_object_object_get(obj, key.c_str());

        if (is_error(obj_value) || NULL == obj_value) {
            IVR_TRACE("未找到key值");
            (*(std::string*)var_reason.pvalue).assign("2");
            json_object_put(obj);
            goto LEAVE;
        }


        //检查是否为array
        if (! json_object_is_type(obj_value, json_type_array)) {
            IVR_WARN("jsonget array 中出现非array值");
            //TODO: assign what?
            (*(std::string*)var_reason.pvalue).assign("10");
            json_object_put(obj);
            //json_object_put(obj_value);
            goto LEAVE;
        }

        if (!ivr_tools_t::is_nonnegative_integer(valueindex)) {
            IVR_WARN("下标需为非负整数值: %s", valueindex.c_str());
            //TODO: assign what?
            (*(std::string*)var_reason.pvalue).assign("11");
            json_object_put(obj);
            //json_object_put(obj_value);
            goto LEAVE;
        }

        int32_t tmp_value_index = atoi(valueindex.c_str());

        int32_t array_len = json_object_array_length(obj_value);

        if (tmp_value_index < 0 || tmp_value_index >= array_len) {
            IVR_WARN("jsonget array 中下标值越界");
            //TODO: assign what?
            (*(std::string*)var_reason.pvalue).assign("12");
            json_object_put(obj);
            //json_object_put(obj_value);
            goto LEAVE;
        }

        json_object* obj_sub = json_object_array_get_idx(obj_value, tmp_value_index);

        if (is_error(obj_sub) || NULL == obj_sub) {
            IVR_TRACE("未找到key中下标为%d的值", tmp_value_index);
            //TODO: assign what?
            (*(std::string*)var_reason.pvalue).assign("13");
            json_object_put(obj);
            //json_object_put(obj_value);
            goto LEAVE;
        }

        //根据需要转化
        if (0 == strcasecmp(_valuetype.c_str(), PARAMITEM_TYPE_STRING)) {
            const char* cstr_value = json_object_get_string(obj_sub);

            if (NULL == cstr_value) {
                IVR_TRACE("转换key值错误");
                (*(std::string*)var_reason.pvalue).assign("3");
                json_object_put(obj);
                //json_object_put(obj_value);
                //json_object_put(obj_sub);
                goto LEAVE;
            }

            if (var_value.type != STRING) {
                IVR_TRACE("赋值变量类型错误");
                (*(std::string*)var_reason.pvalue).assign("4");
                json_object_put(obj);
                //json_object_put(obj_value);
                //json_object_put(obj_sub);
                goto LEAVE;
            }

            value.assign(cstr_value);
            *(string*)var_value.pvalue = value;
            exit = EXIT_SUCC;
            json_object_put(obj);
            goto LEAVE;
        } else if (0 == strcasecmp(_valuetype.c_str(), PARAMITEM_TYPE_INT32)) {
            int32_t int32_value = json_object_get_int(obj_sub);

            if (var_value.type != INT32) {
                IVR_TRACE("赋值变量类型错误");
                (*(std::string*)var_reason.pvalue).assign("4");
                json_object_put(obj);
                //json_object_put(obj_value);
                //json_object_put(obj_sub);
                goto LEAVE;
            }

            std::stringstream ss;
            ss << int32_value;
            ss >> value;
            *(string*)var_value.pvalue = value;
            exit = EXIT_SUCC;
            json_object_put(obj);
            goto LEAVE;
        } else if (0 == strcasecmp(_valuetype.c_str(), PARAMITEM_TYPE_BOOL)) {