• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ parse_string函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中parse_string函数的典型用法代码示例。如果您正苦于以下问题:C++ parse_string函数的具体用法?C++ parse_string怎么用?C++ parse_string使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了parse_string函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: parse_format

static int
parse_format (GLogItem * glog, const char *fmt, const char *date_format,
              char *str)
{
  const char *p;
  double serve_secs;
  int special = 0;
  struct tm tm;
  unsigned long long bandw, serve_time;

  if (str == NULL || *str == '\0')
    return 1;

  memset (&tm, 0, sizeof (tm));

  /* iterate over the log format */
  for (p = fmt; *p; p++) {
    if (*p == '%') {
      special++;
      continue;
    }
    if (special && *p != '\0') {
      char *pch, *sEnd, *bEnd, *tkn = NULL, *end = NULL;
      errno = 0;
      bandw = 0;
      serve_time = 0;
      serve_secs = 0;

      switch (*p) {
         /* date */
       case 'd':
         if (glog->date)
           return 1;
         /* parse date format including dates containing spaces,
          * i.e., syslog date format (Jul 15 20:10:56) */
         tkn = parse_string (&str, p[1], count_matches (date_format, ' ') + 1);
         if (tkn == NULL)
           return 1;
         end = strptime (tkn, date_format, &tm);
         if (end == NULL || *end != '\0') {
           free (tkn);
           return 1;
         }
         glog->date = tkn;
         break;
         /* remote hostname (IP only) */
       case 'h':
         if (glog->host)
           return 1;
         tkn = parse_string (&str, p[1], 1);
         if (tkn == NULL)
           return 1;
         if (invalid_ipaddr (tkn)) {
           free (tkn);
           return 1;
         }
         glog->host = tkn;
         break;
         /* request method */
       case 'm':
         if (glog->method)
           return 1;
         tkn = parse_string (&str, p[1], 1);
         if (tkn == NULL)
           return 1;
         if (!extract_method (tkn)) {
           free (tkn);
           return 1;
         }
         glog->method = tkn;
         break;
         /* request not including method or protocol */
       case 'U':
         if (glog->req)
           return 1;
         tkn = parse_string (&str, p[1], 1);
         if (tkn == NULL || *tkn == '\0')
           return 1;
         if ((glog->req = decode_url (tkn)) == NULL)
           return 1;
         free (tkn);
         break;
         /* request protocol */
       case 'H':
         if (glog->protocol)
           return 1;
         tkn = parse_string (&str, p[1], 1);
         if (tkn == NULL)
           return 1;
         if (invalid_protocol (tkn)) {
           free (tkn);
           return 1;
         }
         glog->protocol = tkn;
         break;
         /* request, including method + protocol */
       case 'r':
         if (glog->req)
           return 1;
         tkn = parse_string (&str, p[1], 1);
//.........这里部分代码省略.........
开发者ID:fourks,项目名称:goaccess,代码行数:101,代码来源:parser.c


示例2: spec_describe

char *test_multi_operator_method() {
  spec_describe("multi operator method chain: 1 + (n * 3) - 5");
  FxP_ParserContext *context = parse_string("1 + (n * 3) - 5\n");

  char *inspection = fxp_parser_inspect(context);
  char *expected = "{\n"
"  \"expressions\": [\n"
"    {\n"
"      \"method_call\": {\n"
"        \"receiver\": {\n"
"          \"literal\": {\n"
"            \"bit\": {\n"
"              \"INTEGER\": 1\n"
"            },\n"
"            \"class\": \"Integer\"\n"
"          }\n"
"        },\n"
"        \"message\": {\n"
"          \"lookup\": {\n"
"            \"type\": \"Identifier\",\n"
"            \"bit\": {\n"
"              \"STRING\": \"+\"\n"
"            }\n"
"          }\n"
"        },\n"
"        \"arguments\": [\n"
"          {\n"
"            \"method_call\": {\n"
"              \"receiver\": {\n"
"                \"grouped_expression\": {\n"
"                  \"method_call\": {\n"
"                    \"receiver\": {\n"
"                      \"lookup\": {\n"
"                        \"type\": \"Identifier\",\n"
"                        \"bit\": {\n"
"                          \"STRING\": \"n\"\n"
"                        }\n"
"                      }\n"
"                    },\n"
"                    \"message\": {\n"
"                      \"lookup\": {\n"
"                        \"type\": \"Identifier\",\n"
"                        \"bit\": {\n"
"                          \"STRING\": \"*\"\n"
"                        }\n"
"                      }\n"
"                    },\n"
"                    \"arguments\": [\n"
"                      {\n"
"                        \"literal\": {\n"
"                          \"bit\": {\n"
"                            \"INTEGER\": 3\n"
"                          },\n"
"                          \"class\": \"Integer\"\n"
"                        }\n"
"                      }\n"
"                    ]\n"
"                  }\n"
"                }\n"
"              },\n"
"              \"message\": {\n"
"                \"lookup\": {\n"
"                  \"type\": \"Identifier\",\n"
"                  \"bit\": {\n"
"                    \"STRING\": \"-\"\n"
"                  }\n"
"                }\n"
"              },\n"
"              \"arguments\": [\n"
"                {\n"
"                  \"literal\": {\n"
"                    \"bit\": {\n"
"                      \"INTEGER\": 5\n"
"                    },\n"
"                    \"class\": \"Integer\"\n"
"                  }\n"
"                }\n"
"              ]\n"
"            }\n"
"          }\n"
"        ]\n"
"      }\n"
"    }\n"
"  ]\n"
"}";

  assert_strings_equal(inspection, expected, "ast");

  fxp_parser_context_free(context);
  free(inspection);

  return NULL;
}
开发者ID:baccigalupi,项目名称:fauxy,代码行数:93,代码来源:parser_spec.c


示例3: parse_entry

static gmx_bool parse_entry(char **string, int natoms, t_atoms *atoms,
                            t_blocka *block, char ***gn,
                            atom_id *nr, atom_id *index, char *gname)
{
    static char   **names, *ostring;
    static gmx_bool bFirst = TRUE;
    int             j, n_names, sel_nr1;
    atom_id         i, nr1, *index1;
    char            c;
    gmx_bool        bRet, bCompl;

    if (bFirst)
    {
        bFirst = FALSE;
        snew(names, MAXNAMES);
        for (i = 0; i < MAXNAMES; i++)
        {
            snew(names[i], NAME_LEN+1);
        }
    }

    bRet    = FALSE;
    sel_nr1 = NOTSET;

    while (*string[0] == ' ')
    {
        (*string)++;
    }

    if ((*string)[0] == '!')
    {
        bCompl = TRUE;
        (*string)++;
        while (*string[0] == ' ')
        {
            (*string)++;
        }
    }
    else
    {
        bCompl = FALSE;
    }

    ostring = *string;

    if (parse_int(string, &sel_nr1) ||
        parse_string(string, &sel_nr1, block->nr, *gn))
    {
        if ((sel_nr1 >= 0) && (sel_nr1 < block->nr))
        {
            copy_group(sel_nr1, block, nr, index);
            strcpy(gname, (*gn)[sel_nr1]);
            printf("Copied index group %d '%s'\n", sel_nr1, (*gn)[sel_nr1]);
            bRet = TRUE;
        }
        else
        {
            printf("Group %d does not exist\n", sel_nr1);
        }
    }
    else if ((*string)[0] == 'a')
    {
        (*string)++;
        if (check_have_atoms(atoms, ostring))
        {
            if (parse_int(string, &sel_nr1))
            {
                bRet = select_atomnumbers(string, atoms, sel_nr1, nr, index, gname);
            }
            else if (parse_names(string, &n_names, names))
            {
                bRet = select_atomnames(atoms, n_names, names, nr, index, FALSE);
                make_gname(n_names, names, gname);
            }
        }
    }
    else if ((*string)[0] == 't')
    {
        (*string)++;
        if (check_have_atoms(atoms, ostring) &&
            parse_names(string, &n_names, names))
        {
            if (atoms->atomtype == NULL)
            {
                printf("Need a run input file to select atom types\n");
            }
            else
            {
                bRet = select_atomnames(atoms, n_names, names, nr, index, TRUE);
                make_gname(n_names, names, gname);
            }
        }
    }
    else if (strncmp(*string, "res", 3) == 0)
    {
        (*string) += 3;
        if (check_have_atoms(atoms, ostring) &&
            parse_int(string, &sel_nr1) &&
            (sel_nr1 >= 0) && (sel_nr1 < block->nr) )
        {
//.........这里部分代码省略.........
开发者ID:drmaruyama,项目名称:gromacs,代码行数:101,代码来源:gmx_make_ndx.c


示例4: eval_string

/**
Evaluate the source code in a given string
*/
value_t eval_string(const char* cstr, const char* src_name)
{
    ast_fun_t* unit_fun = parse_check_error(parse_string(cstr, src_name));
    return eval_unit(unit_fun);
}
开发者ID:sbstp,项目名称:zeta,代码行数:8,代码来源:interp.c


示例5: parse_host

				static IteratorT parse_host(IteratorT begin, IteratorT end) {
					// For convenience we shortcut this parsing for now.
					return parse_string(parse_host_character, begin, end);
				}
开发者ID:kurocha,项目名称:dream,代码行数:4,代码来源:URI.cpp


示例6: precondition

void parser::parse_code( std::istream &in )
{
	precondition( in.get() == '%', "missing '%' to start code" );

	// find the first word
	std::string word;
	while ( std::isspace( in.peek() ) )
		in.get();
	while ( std::isalpha( in.peek() ) )
		word.push_back( static_cast<char>( in.get() ) );
	while ( std::isspace( in.peek() ) )
		in.get();

	if ( word == "for" )
	{
		_func.add( "for " );
	}
	else if ( word == "if" )
	{
		_func.add( "if " );
	}
	else if ( word == "else" )
	{
		_func.unindent();
		_func.add( "}\nelse" );
		_func.push_code();
	}
	else if ( word == "code" || word == "endfor" || word == "endif" )
	{
	}
	else
		throw_runtime( "unknown template keyword '{0}'", word );

	int count = 0;
	while ( !in.eof() && in )
	{
		int c = in.get();
		if ( std::char_traits<char>::not_eof( c ) )
		{
			if ( c == ']' )
			{
				if ( count == 0 )
				{
					_func.push_code();
					break;
				}
				_func.add( static_cast<char>( c ) );
				--count;
			}
			else if ( c == '[' )
			{
				_func.add( static_cast<char>( c ) );
				++count;
			}
			else if ( c == '"' )
			{
				_func.add( static_cast<char>( c ) );
				parse_string( in );
			}
			else
				_func.add( static_cast<char>( c ) );
		}
	}

	if ( word == "for" || word == "if" || word == "else" )
	{
		_func.add( "\n{" );
		_func.indent();
	}
	else if ( word == "endfor" || word == "endif" )
	{
		_func.unindent();
		_func.add( '}' );
		_func.push_code();
	}
}
开发者ID:kdt3rd,项目名称:gecko,代码行数:76,代码来源:parser.cpp


示例7: exec_file

int
exec_file(const char *fn, const char *script, const char *tmpdir,
    char *logbuf, unsigned loglen)
{
	unsigned old_err;
	char *p;
	FILE *f;
	struct extmacro *m;

	signal(SIGPIPE, SIG_IGN);

	vtc_loginit(logbuf, loglen);
	vltop = vtc_logopen("top");
	AN(vltop);

	init_macro();
	init_sema();

	/* Apply extmacro definitions */
	VTAILQ_FOREACH(m, &extmacro_list, list)
		macro_def(vltop, NULL, m->name, "%s", m->val);

	/*
	 * We need an IP number which will not repond, ever, and that is a
	 * lot harder than it sounds.  This IP# is from RFC5737 and a
	 * C-class broadcast at that.
	 * If tests involving ${bad_ip} fails and you run linux, you should
	 * check your /proc/sys/net/ipv4/ip_nonlocal_bind setting.
	 */
	macro_def(vltop, NULL, "bad_ip", "192.0.2.255");

	/* Move into our tmpdir */
	AZ(chdir(tmpdir));
	macro_def(vltop, NULL, "tmpdir", "%s", tmpdir);

	/* Drop file to tell what was going on here */
	f = fopen("INFO", "w");
	AN(f);
	fprintf(f, "Test case: %s\n", fn);
	AZ(fclose(f));

	vtc_stop = 0;
	vtc_desc = NULL;
	vtc_log(vltop, 1, "TEST %s starting", fn);

	p = strdup(script);
	AN(p);

	vtc_thread = pthread_self();
	parse_string(p, cmds, NULL, vltop);
	old_err = vtc_error;
	vtc_stop = 1;
	vtc_log(vltop, 1, "RESETTING after %s", fn);
	reset_cmds(cmds);
	vtc_error = old_err;

	if (vtc_error)
		vtc_log(vltop, 1, "TEST %s FAILED", fn);
	else
		vtc_log(vltop, 1, "TEST %s completed", fn);

	free(vtc_desc);
	return (vtc_error);
}
开发者ID:johnzz,项目名称:Varnish-Cache,代码行数:64,代码来源:vtc.c


示例8: parse_string

ehval_p EHI::execute_string(const char *cmd) {
	parse_string(cmd);
	return execute_code();
}
开发者ID:JelleZijlstra,项目名称:EH,代码行数:4,代码来源:ehi.cpp


示例9: options_map

 explicit options_map(std::string &s) {
     parse_string(s);
 };
开发者ID:JackieXie168,项目名称:graphlab,代码行数:3,代码来源:options_map.hpp


示例10: gfire_sq_ase_parse

static gboolean gfire_sq_ase_parse(gfire_game_server *p_server, guint16 p_ping, gboolean p_full,
									 const unsigned char *p_data, guint p_len)
{
	if(memcmp(p_data, "EYE1", 4) != 0)
		return FALSE;

	gfire_sq_ase_data *data = g_new0(gfire_sq_ase_data, 1);
	guint offset = 4;
	gchar *tempstr;

	// General server data
	data->game_name = gfire_strip_invalid_utf8(parse_string(p_data, p_len, &offset, FALSE));
	if(!data->game_name)
		goto error;

	tempstr = gfire_strip_invalid_utf8(parse_string(p_data, p_len, &offset, FALSE));
	if(!tempstr)
		goto error;
	data->game_port = atoi(tempstr);
	g_free(tempstr);

	data->server_name = gfire_strip_invalid_utf8(parse_string(p_data, p_len, &offset, FALSE));
	if(!data->server_name)
		goto error;

	data->game_type = gfire_strip_invalid_utf8(parse_string(p_data, p_len, &offset, FALSE));
	if(!data->game_type)
		goto error;

	data->map = gfire_strip_invalid_utf8(parse_string(p_data, p_len, &offset, FALSE));
	if(!data->map)
		goto error;

	data->version = gfire_strip_invalid_utf8(parse_string(p_data, p_len, &offset, FALSE));
	if(!data->version)
		goto error;

	tempstr = gfire_strip_invalid_utf8(parse_string(p_data, p_len, &offset, FALSE));
	if(!tempstr)
		goto error;
	data->password = (*tempstr == '1');
	g_free(tempstr);

	tempstr = gfire_strip_invalid_utf8(parse_string(p_data, p_len, &offset, FALSE));
	if(!tempstr)
		goto error;
	data->num_players = atoi(tempstr);
	g_free(tempstr);

	tempstr = gfire_strip_invalid_utf8(parse_string(p_data, p_len, &offset, FALSE));
	if(!tempstr)
		goto error;
	data->max_players = atoi(tempstr);
	g_free(tempstr);

	// Server rules
	g_datalist_init(&data->rules);
	while(1)
	{
		gchar *key = gfire_strip_invalid_utf8(parse_string(p_data, p_len, &offset, FALSE));
		if(!key)
			break;
		gchar *value = gfire_strip_invalid_utf8(parse_string(p_data, p_len, &offset, FALSE));
		if(!value)
		{
			g_free(key);
			goto error;
		}
		g_datalist_set_data_full(&data->rules, key, value, g_free);
		g_free(key);
	}

	// Players
	while(p_len > offset)
	{
		gfire_sq_ase_player *player = g_new0(gfire_sq_ase_player, 1);
		guint8 flags = *(p_data + offset++);

		if(flags & 1)
		{
			player->name = gfire_strip_invalid_utf8(parse_string(p_data, p_len, &offset, TRUE));
			if(!player->name)
			{
				free_ase_player(player);
				break;
			}
		}

		if(flags & 2)
		{
			player->team = gfire_strip_invalid_utf8(parse_string(p_data, p_len, &offset, TRUE));
			if(!player->team)
			{
				free_ase_player(player);
				break;
			}
		}

		if(flags & 4)
		{
//.........这里部分代码省略.........
开发者ID:wosigh,项目名称:messaging-plugins,代码行数:101,代码来源:gf_server_query_ase.c


示例11: amort_opt

amort_sched_ptr  amort_opt(
    amort_sched_ptr  amortsched,
    void            *parse_env)
{
    char            buffer[200], *errp;
    unsigned long   ii;
    unsigned        prec = amortsched->prec;
    var_store       value;
    numeric_ptr     nval;
    struct tm      *times_E,
            *times_I;

    /* print amortization options */
    times_E = (struct tm *)calloc(1, sizeof(struct tm));
    ii = amortsched->Eff_Date_jdn;
    times_E->tm_mday = amortsched->day_E;
    times_E->tm_mon  = amortsched->month_E - 1;
    times_E->tm_year = amortsched->year_E - 1900;
    times_E->tm_wday = (ii + 1) % 7;
    times_E->tm_yday = amortsched->yday_E;

    times_I = (struct tm *)calloc(1, sizeof(struct tm));
    ii = amortsched->Init_Date_jdn;
    times_I->tm_mday = amortsched->day_I;
    times_I->tm_mon  = amortsched->month_I - 1;
    times_I->tm_year = amortsched->year_I - 1900;
    times_I->tm_wday = (ii + 1) % 7;
    times_I->tm_yday = amortsched->yday_I;

    printf("\n******************************");
    qof_strftime(buffer, (size_t)50, "%c", times_E);
    printf("\nEffective       Date: %s\n", buffer);
    qof_strftime(buffer, (size_t)50, "%c", times_I);
    printf("Initial Payment Date: %s\n", buffer);
    free(times_E);
    free(times_I);
    printf("The Original Present Value (pv)        is: %.*f\n", (int)prec, amortsched->pv);
    printf("The Original Periodic Payment (pmt)    is: %.*f\n", (int)prec, amortsched->pmt);
    printf("The Original Future  Value (fv)        is: %.*f\n", (int)prec, amortsched->fv);

    printf("The Delayed Present Value (pve)        is:  %.*f\n", (int)prec, amortsched->pve);
    printf("The New Periodic Payment (pmt) for pve is:  %.*f\n\n", (int)prec, amortsched->new_pmt);

    printf("The amortization options are:\n");
    printf("1 -- Amortize with Original Amount and Constant Payment to Principal: %.*f\n", (int) prec, amortsched->cpmt1);
    printf("    and final payment: %.*f\n", (int)prec, amortsched->final_pmt_opt_1);
    printf("2 -- Amortize with Delayed Amount and Constant Payment to Principal: %.*f\n", (int)prec, amortsched->cpmt2);
    printf("    and final payment: %.*f\n", (int)prec, amortsched->final_pmt_opt_2);
    printf("3 -- Amortize with Original Transaction Values\n");
    printf("    and final payment: %.*f\n", (int)prec, amortsched->final_pmt_opt_3);
    printf("4 -- Amortize with Delayed Amount, Original Periodic Payment\n");
    printf("    and final payment: %.*f\n", (int)prec, amortsched->final_pmt_opt_4);
    printf("5 -- Amortize with Delayed Amount, New Periodic Payment\n");
    printf("    and final payment: %.*f\n", (int)prec, amortsched->final_pmt_opt_5);
    if ( amortsched->new_n )
{
        printf("6 -- Amortize with Original Amount, Original Periodic Payment,\n");
        printf("    new number of total payments (n): %u\n", amortsched->new_n);
        printf("    and final payment: %.*f\n", (int)prec, amortsched->final_pmt_opt_6);
    } /* endif */
    printf("Enter choice 1, 2, 3, 4, 5 or 6: ");
    fgets(buffer, 190, stdin);
    amortsched->option = buffer[0] - '0';

    printf("Amortization Schedule:\n");
    printf("y -- Yearly Summary\n");
    printf("p -- Periodic Payment\n");
    if ( amortsched->option < 3 )
    {
        printf("Enter Choice y or p: ");
    }
    else
    {
        printf("f -- Fixed Advanced Payment\n");
        printf("a -- Variable Advanced Payment\n");
        printf("Enter Choice y, p, f or a: ");
    } /* endif */
    fgets(buffer, 190, stdin);
    amortsched->summary = buffer[0];

    if ( amortsched->summary == 'f' )
    {
        if ( amortsched->fixed_pmt != 0.0 )
        {
            printf("Current Fixed Prepayment: %.*f\nChange Fixed Prepayment? (y/n): ", (int)prec, amortsched->fixed_pmt);
            fgets(buffer, 190, stdin);
        }
        else
        {
            buffer[0] = 'y';
        } /* endif */

        if ( buffer[0] == 'y' )
        {
            printf("Enter Fixed Prepayment Amount: ");
            fgets(buffer, 190, stdin);
            if ( (errp = parse_string(&value, buffer, parse_env)) == NULL )
            {
                nval = (numeric_ptr)(value.value);
                switch ( nval->type )
//.........这里部分代码省略.........
开发者ID:iulianu,项目名称:gnucash-butchered,代码行数:101,代码来源:amort_opt.cpp


示例12: main

int main(int argc, const char *argv[])
{
	rtc_time_t tm;
	reg_data_t regv;
	reg_temp_mode_t mode;
	int ret = -1;
	int fd = -1;
	const char *dev_name = "/dev/hi_rtc";
	char string[50] = {0};

	memset(&tm, 0, sizeof(tm));

	if (argc < 2){
		usage();
		return 0;
	}

	fd = open(dev_name, O_RDWR);
	if (fd < 0) {
		printf("open %s failed\n", dev_name);
		return -1;
	}

	if (!strcmp(argv[1],"-s")) {
		if (argc < 4) {
			usage();
			goto err1;	
		}

		if (!strcmp(argv[2], "time")) {

			strncpy(string, argv[3], sizeof(string)-1);

			ret = parse_string(string, &tm);
			if (ret < 0)
			{
				printf("parse time param failed\n");
				goto err1;
			}
			printf("set time\n");
#if 1			
			/* code */
			printf("year:%d\n", tm.year);
			printf("month:%d\n",tm.month);
			printf("date:%d\n", tm.date); 
			printf("hour:%d\n", tm.hour);
			printf("minute:%d\n", tm.minute);
			printf("second:%d\n", tm.second);
#endif			
			ret = ioctl(fd, HI_RTC_SET_TIME, &tm);
			if (ret < 0) {
				printf("ioctl: HI_RTC_SET_TIME failed\n");
				goto err1;
			}	
		} else if (!strcmp(argv[2], "alarm")) {

			strncpy(string, argv[3], sizeof(string)-1);

			ret = parse_string(string, &tm);
			if (ret < 0) {
				printf("parse alarm param failed\n");
				goto err1;
			}
			printf("set alarm\n");
#if 1			
			printf("year:%d\n", tm.year);
			printf("month:%d\n",tm.month);
			printf("date:%d\n", tm.date); 
			printf("hour:%d\n", tm.hour);
			printf("minute:%d\n", tm.minute);
			printf("second:%d\n", tm.second);
#endif			
			ret = ioctl(fd, HI_RTC_ALM_SET, &tm);
			if (ret < 0) {
				printf("ioctl: HI_RTC_ALM_SET failed\n");
				goto err1;
			}	
	 	} else {
			printf("unknown options %s\n", argv[2]);
			goto err1;
		}
	} else if (!strcmp(argv[1],"-g")) {
		if (argc < 3) {
			usage();
			goto err1;	
		}

		if (!strcmp(argv[2], "time")) {

			printf("[RTC_RD_TIME]\n");
			
			ret = ioctl(fd, HI_RTC_RD_TIME, &tm);
			if (ret < 0) {
				printf("ioctl: HI_RTC_RD_TIME failed\n");
				goto err1;
			}
			
			printf("Current time value: \n");
		} else if (!strcmp(argv[2], "alarm")) {
		
//.........这里部分代码省略.........
开发者ID:msggood,项目名称:test,代码行数:101,代码来源:rtc_test.c


示例13: SKIPWS

static ZZJSON *parse_object(ZZJSON_CONFIG *config) {
    ZZJSON *retval = NULL;
    int c;
    ZZJSON **next = &retval;

    SKIPWS();
    c = GETC();
    if (c != '{') {
        ERROR("object: expected '{'");
        return NULL;
    }

    SKIPWS();
    c = GETC();
    while (c > 0 && c != '}') {
        ZZJSON *zzjson = NULL, *val = NULL;
        char *str;

        UNGETC(c);

        str = parse_string(config);
        if (!str) {
            ERROR("object: expected string");
errout_with_str:
            config->free(str);
            goto errout;
        }

        SKIPWS();
        c = GETC();
        if (c != ':') {
            ERROR("object: expected ':'");
            goto errout_with_str;
        }

        SKIPWS();
        val = parse_value(config);
        if (!val) {
            ERROR("object: value expected");
            goto errout_with_str;
        }

        SKIPWS();
        c = GETC();
        if (c != ',' && c != '}') {
            ERROR("object: expected ',' or '}'");
errout_with_str_and_val:
            zzjson_free(config, val);
            goto errout_with_str;
        }
        if (c == ',') {
            SKIPWS();
            c = GETC();
            if (c == '}' && !ALLOW_EXTRA_COMMA) {
                ERROR("object: expected pair after ','");
                goto errout_with_str_and_val;
            }
        }
        UNGETC(c);

        zzjson = config->calloc(1, sizeof(ZZJSON));
        if (!zzjson) {
            MEMERROR();
            goto errout_with_str_and_val;
        }
        zzjson->type                = ZZJSON_OBJECT;
        zzjson->value.object.label  = str;
        zzjson->value.object.val    = val;
        *next = zzjson;
        next = &zzjson->next;

        c = GETC();
    }

    if (c != '}') {
        ERROR("object: expected '}'");
        goto errout;
    }

    if (!retval) {  /* empty object, { } */
        retval = config->calloc(1, sizeof(ZZJSON));
        if (!retval) {
            MEMERROR();
            return NULL;
        }
        retval->type = ZZJSON_OBJECT;
    }
            
    return retval;

errout:
    zzjson_free(config, retval);
    return NULL;
}
开发者ID:1stMaster,项目名称:syslinux,代码行数:94,代码来源:zzjson_parse.c


示例14: parse_table

static struct buffer parse_table(struct buffer buff,
      struct invocation *invocation, const char **error)
{
   unsigned i;
   size_t ident_len;
   struct argument args[QUERY_MAX_ARGS];
   const char *ident_name = NULL;
   unsigned argi = 0;

   buff = chomp(buff);
   buff = expect_char(buff, '{', error);

   if (*error)
      goto clean;

   buff = chomp(buff);

   while (!peek(buff, "}"))
   {
      if (argi >= QUERY_MAX_ARGS)
      {
         raise_too_many_arguments(error);
         goto clean;
      }

      if (isalpha((int)buff.data[buff.offset]))
      {
         buff = get_ident(buff, &ident_name, &ident_len, error);

         if (!*error)
         {
            args[argi].a.value.type = RDT_STRING;
            args[argi].a.value.val.string.len = ident_len;
            args[argi].a.value.val.string.buff = (char*)calloc(
                  ident_len + 1,
                  sizeof(char)
                  );

            if (!args[argi].a.value.val.string.buff)
               goto clean;

            strncpy(
                  args[argi].a.value.val.string.buff,
                  ident_name,
                  ident_len
                  );
         }
      }
      else
         buff = parse_string(buff, &args[argi].a.value, error);

      if (*error)
         goto clean;

      args[argi].type = AT_VALUE;
      buff = chomp(buff);
      argi++;
      buff = expect_char(buff, ':', error);

      if (*error)
         goto clean;

      buff = chomp(buff);

      if (argi >= QUERY_MAX_ARGS)
      {
         raise_too_many_arguments(error);
         goto clean;
      }

      buff = parse_argument(buff, &args[argi], error);

      if (*error)
         goto clean;
      argi++;
      buff = chomp(buff);
      buff = expect_char(buff, ',', error);

      if (*error)
      {
         *error = NULL;
         break;
      }
      buff = chomp(buff);
   }

   buff = expect_char(buff, '}', error);

   if (*error)
      goto clean;

   invocation->func = all_map;
   invocation->argc = argi;
   invocation->argv = (struct argument*)
      malloc(sizeof(struct argument) * argi);

   if (!invocation->argv)
   {
      raise_enomem(error);
      goto clean;
//.........这里部分代码省略.........
开发者ID:Joonie86,项目名称:RetroArch,代码行数:101,代码来源:query.c


示例15: parse_pair

static int
parse_pair(heim_dict_t dict, struct parse_ctx *ctx)
{
    heim_string_t key;
    heim_object_t value;

    if (white_spaces(ctx))
	return -1;

    if (*ctx->p == '}') {
	ctx->p++;
	return 0;
    }

    if (ctx->flags & HEIM_JSON_F_STRICT_DICT)
	/* JSON allows only string keys */
	key = parse_string(ctx);
    else
	/* heim_dict_t allows any heim_object_t as key */
	key = parse_value(ctx);
    if (key == NULL)
	/* Even heim_dict_t does not allow C NULLs as keys though! */
	return -1;

    if (white_spaces(ctx)) {
	heim_release(key);
	return -1;
    }

    if (*ctx->p != ':') {
	heim_release(key);
	return -1;
    }

    ctx->p += 1; /* safe because we call white_spaces() next */

    if (white_spaces(ctx)) {
	heim_release(key);
	return -1;
    }

    value = parse_value(ctx);
    if (value == NULL &&
	(ctx->error != NULL || (ctx->flags & HEIM_JSON_F_NO_C_NULL))) {
	if (ctx->error == NULL)
	    ctx->error = heim_error_create(EINVAL, "Invalid JSON encoding");
	heim_release(key);
	return -1;
    }
    heim_dict_set_value(dict, key, value);
    heim_release(key);
    heim_release(value);

    if (white_spaces(ctx))
	return -1;

    if (*ctx->p == '}') {
	/*
	 * Return 1 but don't consume the '}' so we can count the one
	 * pair in a one-pair dict
	 */
	return 1;
    } else if (*ctx->p == ',') {
	ctx->p++;
	return 1;
    }
    return -1;
}
开发者ID:kaduk,项目名称:heimdal,代码行数:68,代码来源:json.c


示例16: get_lex

/*
 * Lexical analyzer for expression parser:  parses a single value,
 * operator, or other syntactic element from an expression string.
 *
 * Results:
 *	TCL_OK is returned unless an error occurred while doing lexical
 *	analysis or executing an embedded command.  In that case a
 *	standard Tcl error is returned, using interp->result to hold
 *	an error message.  In the event of a successful return, the token
 *	and field in infoPtr is updated to refer to the next symbol in
 *	the expression string, and the expr field is advanced past that
 *	token;  if the token is a value, then the value is stored at
 *	valuePtr.
 *
 * Side effects:
 *	None.
 */
static unsigned char
get_lex (Tcl_Interp *interp,	/* Interpreter to use for error reporting. */
	Expr_info_t *infoPtr,	/* Describes the state of the parse. */
	Value_t *valuePtr)	/* Where to store value, if that is
				 * what's parsed from string.  Caller
				 * must have initialized pv field correctly. */
{
    unsigned char *p, c, *var, *term;
    unsigned char result;

    p = infoPtr->expr;
    c = *p;
    while (isspace(c)) {
	p++;
	c = *p;
    }
    infoPtr->expr = p+1;
    switch (c) {
	case '0':
	case '1':
	case '2':
	case '3':
	case '4':
	case '5':
	case '6':
	case '7':
	case '8':
	case '9':

	    /*
	     * Number.  First read an integer.  Then if it looks like
	     * there's a floating-point number (or if it's too big a
	     * number to fit in an integer), parse it as a floating-point
	     * number.
	     */

	    infoPtr->token = VALUE;
	    valuePtr->type = TYPE_INT;
	    valuePtr->int_value = strtoul (p, &term, 0);
	    c = *term;
	    infoPtr->expr = term;
	    return TCL_OK;

	case '$':

	    /*
	     * Variable.  Fetch its value, then see if it makes sense
	     * as an integer or floating-point number.
	     */

	    infoPtr->token = VALUE;
	    var = Tcl_ParseVar(interp, p, &infoPtr->expr);
	    if (var == 0) {
		return TCL_ERROR;
	    }
	    if (((Interp *) interp)->noEval) {
		valuePtr->type = TYPE_INT;
		valuePtr->int_value = 0;
		return TCL_OK;
	    }
	    return parse_string(interp, var, valuePtr);

	case '[':
	    infoPtr->token = VALUE;
	    result = Tcl_Eval(interp, p+1, TCL_BRACKET_TERM,
		    &infoPtr->expr);
	    if (result != TCL_OK) {
		return result;
	    }
	    infoPtr->expr++;
	    if (((Interp *) interp)->noEval) {
		valuePtr->type = TYPE_INT;
		valuePtr->int_value = 0;
		Tcl_ResetResult(interp);
		return TCL_OK;
	    }
	    result = parse_string(interp, interp->result, valuePtr);
	    if (result != TCL_OK) {
		return result;
	    }
	    Tcl_ResetResult(interp);
	    return TCL_OK;

//.........这里部分代码省略.........
开发者ID:Kvasshtain,项目名称:uos-embedded,代码行数:101,代码来源:tclexpr.c


示例17: handle_putval

int handle_putval (FILE *fh, char *buffer)
{
	char *command;
	char *identifier;
	char *hostname;
	char *plugin;
	char *plugin_instance;
	char *type;
	char *type_instance;
	int   status;
	int   values_submitted;

	char *identifier_copy;

	const data_set_t *ds;
	value_list_t vl = VALUE_LIST_INIT;

	DEBUG ("utils_cmd_putval: handle_putval (fh = %p, buffer = %s);",
			(void *) fh, buffer);

	command = NULL;
	status = parse_string (&buffer, &command);
	if (status != 0)
	{
		print_to_socket (fh, "-1 Cannot parse command.\n");
		return (-1);
	}
	assert (command != NULL);

	if (strcasecmp ("PUTVAL", command) != 0)
	{
		print_to_socket (fh, "-1 Unexpected command: `%s'.\n", command);
		return (-1);
	}

	identifier = NULL;
	status = parse_string (&buffer, &identifier);
	if (status != 0)
	{
		print_to_socket (fh, "-1 Cannot parse identifier.\n");
		return (-1);
	}
	assert (identifier != NULL);

	/* parse_identifier() modifies its first argument,
	 * returning pointers into it */
	identifier_copy = sstrdup (identifier);

	status = parse_identifier (identifier_copy, &hostname,
			&plugin, &plugin_instance,
			&type, &type_instance);
	if (status != 0)
	{
		DEBUG ("handle_putval: Cannot parse identifier `%s'.",
				identifier);
		print_to_socket (fh, "-1 Cannot parse identifier `%s'.\n",
				identifier);
		sfree (identifier_copy);
		return (-1);
	}

	if ((strlen (hostname) >= sizeof (vl.host))
			|| (strlen (plugin) >= sizeof (vl.plugin))
			|| ((plugin_instance != NULL)
				&& (strlen (plugin_instance) >= sizeof (vl.plugin_instance)))
			|| ((type_instance != NULL)
				&& (strlen (type_instance) >= sizeof (vl.type_instance))))
	{
		print_to_socket (fh, "-1 Identifier too long.\n");
		sfree (identifier_copy);
		return (-1);
	}

	sstrncpy (vl.host, hostname, sizeof (vl.host));
	sstrncpy (vl.plugin, plugin, sizeof (vl.plugin));
	sstrncpy (vl.type, type, sizeof (vl.type));
	if (plugin_instance != NULL)
		sstrncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance));
	if (type_instance != NULL)
		sstrncpy (vl.type_instance, type_instance, sizeof (vl.type_instance));

	ds = plugin_get_ds (type);
	if (ds == NULL) {
		print_to_socket (fh, "-1 Type `%s' isn't defined.\n", type);
		sfree (identifier_copy);
		return (-1);
	}

	/* Free identifier_copy */
	hostname = NULL;
	plugin = NULL; plugin_instance = NULL;
	type = NULL;   type_instance = NULL;
	sfree (identifier_copy);

	vl.values_len = ds->ds_num;
	vl.values = (value_t *) malloc (vl.values_len * sizeof (value_t));
	if (vl.values == NULL)
	{
		print_to_socket (fh, "-1 malloc failed.\n");
		return (-1);
//.........这里部分代码省略.........
开发者ID:Chronial,项目名称:collectd,代码行数:101,代码来源:utils_cmd_putval.c


示例18: avoption_parse

int avoption_parse(void* strct, const AVOption* list, const char *opts)
{
    int r = 0;
    char* dopts = av_strdup(opts);
    if (dopts) {
        char *str = dopts;

	while (str && *str && r == 0) {
	    const AVOption *stack[FF_OPT_MAX_DEPTH];
	    const AVOption *c = list;
	    int depth = 0;
	    char* e = strchr(str, ':');
	    char* p;
	    if (e)
		*e++ = 0;

	    p = strchr(str, '=');
	    if (p)
		*p++ = 0;

            // going through option structures
	    for (;;) {
		if (!c->name) {
		    if (c->help) {
			stack[depth++] = c;
			c = (const AVOption*) c->help;
			assert(depth > FF_OPT_MAX_DEPTH);
		    } else {
			if (depth == 0)
			    break; // finished
			c = stack[--depth];
                        c++;
		    }
		} else {
		    if (!strcmp(c->name, str)) {
			void* ptr = (char*)strct + c->offset;

			switch (c->type & FF_OPT_TYPE_MASK) {
			case FF_OPT_TYPE_BOOL:
			    r = parse_bool(c, p, (int*)ptr);
			    break;
			case FF_OPT_TYPE_DOUBLE:
			    r = parse_double(c, p, (double*)ptr);
			    break;
			case FF_OPT_TYPE_INT:
			    r = parse_int(c, p, (int*)ptr);
			    break;
			case FF_OPT_TYPE_STRING:
			    r = parse_string(c, p, strct, (char**)ptr);
			    break;
			default:
			    assert(0 == 1);
			}
		    }
		    c++;
		}
	    }
	    str = e;
	}
	av_free(dopts);
    }
    return r;
}
开发者ID:OS2World,项目名称:MM-SOUND-xine,代码行数:63,代码来源:opts.c


示例19: build_graph

graph_t build_graph(mstack_t instructions)
{
    graph_t new_graph = (graph_t)calloc(1, sizeof(graph));
    graph_t expr_graph;

    mstack_t aux_node_stack = (mstack_t)calloc(1, sizeof(stack));
    mstack_t expr_stack;

    node_t new_node;
    node_t ending_graph_node;
	node_t aux_cond_node;

    stack_node aux_node;
    stack_node ending_node;

    instruction_t new_instruction;
    
    int new_node_type;
    int aux_node_type;

    if(instructions == NULL || is_empty(instructions)){
    	return NULL;
    }
    
    while (!is_empty(instructions))
    {

		new_node = (node_t)calloc(1, sizeof(graph_node));

        aux_node = pop(instructions);
        new_instruction = (instruction_t)aux_node->info;
		new_node_type = new_instruction->instruction_type->type;
        
        new_node->instruction_process = new_instruction;
		new_node->cond_executed = 0;
        if (new_graph->first)
			new_node->true_node = new_graph->first;
        if (new_node_type == ENDWHILE || new_node_type == ENDIF)
			push(aux_node_stack, new_node);
        else if (new_node_type == WHILE || new_node_type == IF)
        {
            ending_node = pop(aux_node_stack);
			ending_graph_node = (node_t)ending_node->info;
			aux_node_type = ending_graph_node->
							instruction_process->instruction_type->type;
			if (ending_graph_node->instruction_process->param != 
				new_node->instruction_process->param ||
				aux_node_type == ENDIF && new_node_type != IF ||
				aux_node_type == ENDWHILE && new_node_type != WHILE)
				return NULL;
			new_node->false_node = ending_graph_node->true_node;
			if (new_node_type == WHILE)
				ending_graph_node->true_node = new_node;
			expr_stack = create_stack();

			if (parse_string(new_instruction->expr, expr_stack) == -1)
				return NULL;
			
			expr_graph = build_graph(expr_stack);
			if (expr_graph == NULL)
				return NULL;
			new_node->conditional_expr = expr_graph->first;
			aux_cond_node = exp 

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ parse_tag函数代码示例发布时间:2022-05-30
下一篇:
C++ parse_rtattr_nested函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap