コード例 #1
0
ファイル: json.cpp プロジェクト: TorstenRobitzki/Sioux
    std::pair< bool, bool > parser::parse(const char* begin, const char* end)
    {
        assert( !state_.empty() );

        for ( ; begin != end && !state_.empty(); )
        {
            switch ( main_state( state_.top() ) )
            {
            case idle_parsing:
                begin = eat_white_space(begin, end);

                if ( begin != end )
                {
                    state_.top() = parse_idle(*begin);
                }
                break;
            case start_number_parsing:
                begin = parse_number(begin, end);
                break;
            case start_array_parsing:
                begin = parse_array(begin, end);
                break;
            case start_object_parsing:
                begin = parse_object(begin, end);
                break;
            case start_string_parsing:
                begin = parse_string(begin, end);
                break;
            case start_true_parsing:
            case start_false_parsing:
            case start_null_parsing:
                begin = parse_literal(begin, end);
                break;
            default:
                assert(!"should not happen");
            }
        }

        // consume trailing whitespaces
        if ( state_.empty() )
            begin = eat_white_space(begin, end);

        return std::make_pair( begin == end, state_.empty() );
    }
コード例 #2
0
ファイル: dahdi_cfg.c プロジェクト: Evangileon/dahdi
static int chanconfig(char *keyword, char *args)
{
	int chans[DAHDI_MAX_CHANNELS];
	int res = 0;
	int x;
	int master=0;
	int dacschan = 0;
	char *idle;
	int is_digital;
	bzero(chans, sizeof(chans));
	strtok(args, ":");
	idle = strtok(NULL, ":");
	if (!strcasecmp(keyword, "dacs") || !strcasecmp(keyword, "dacsrbs")) {
		res = parse_channel(idle, &dacschan);
	}
	if (!res)
		res = apply_channels(chans, args);
	if (res <= 0)
		return -1;
	for (x=1;x<DAHDI_MAX_CHANNELS;x++) {
		is_digital = 0;
		if (chans[x]) {
			if (slineno[x]) {
				error("Channel %d already configured as '%s' at line %d\n", x, sig[x], slineno[x]);
				continue;
			}
			if ((!strcasecmp(keyword, "dacs") || !strcasecmp(keyword, "dacsrbs")) && slineno[dacschan]) {
				error("DACS Destination channel %d already configured as '%s' at line %d\n", dacschan, sig[dacschan], slineno[dacschan]);
				continue;
			} else {
				cc[dacschan].chan = dacschan;
				cc[dacschan].master = dacschan;
				slineno[dacschan] = lineno;
			}
			cc[x].chan = x;
			cc[x].master = x;
			slineno[x] = lineno;
			if (!strcasecmp(keyword, "e&m")) {
				cc[x].sigtype = DAHDI_SIG_EM;
				sig[x] = sigtype_to_str(cc[x].sigtype);
			} else if (!strcasecmp(keyword, "e&me1")) {
				cc[x].sigtype = DAHDI_SIG_EM_E1;
				sig[x] = sigtype_to_str(cc[x].sigtype);
			} else if (!strcasecmp(keyword, "fxsls")) {
				cc[x].sigtype = DAHDI_SIG_FXSLS;
				sig[x] = sigtype_to_str(cc[x].sigtype);
			} else if (!strcasecmp(keyword, "fxsgs")) {
				cc[x].sigtype = DAHDI_SIG_FXSGS;
				sig[x] = sigtype_to_str(cc[x].sigtype);
			} else if (!strcasecmp(keyword, "fxsks")) {
				cc[x].sigtype = DAHDI_SIG_FXSKS;
				sig[x] = sigtype_to_str(cc[x].sigtype);
			} else if (!strcasecmp(keyword, "fxols")) {
				cc[x].sigtype = DAHDI_SIG_FXOLS;
				sig[x] = sigtype_to_str(cc[x].sigtype);
			} else if (!strcasecmp(keyword, "fxogs")) {
				cc[x].sigtype = DAHDI_SIG_FXOGS;
				sig[x] = sigtype_to_str(cc[x].sigtype);
			} else if (!strcasecmp(keyword, "fxoks")) {
				cc[x].sigtype = DAHDI_SIG_FXOKS;
				sig[x] = sigtype_to_str(cc[x].sigtype);
			} else if (!strcasecmp(keyword, "cas") || !strcasecmp(keyword, "user")) {
				if (parse_idle(&cc[x].idlebits, idle))
					return -1;
				cc[x].sigtype = DAHDI_SIG_CAS;
				sig[x] = sigtype_to_str(cc[x].sigtype);
				is_digital = 1;
			} else if (!strcasecmp(keyword, "dacs")) {
				/* Setup channel for monitor */
				cc[x].idlebits = dacschan;
				cc[x].sigtype = DAHDI_SIG_DACS;
				sig[x] = sigtype_to_str(cc[x].sigtype);
				/* Setup inverse */
				cc[dacschan].idlebits = x;
				cc[dacschan].sigtype = DAHDI_SIG_DACS;
				sig[x] = sigtype_to_str(cc[dacschan].sigtype);
				dacschan++;
				is_digital = 1;
			} else if (!strcasecmp(keyword, "dacsrbs")) {
				/* Setup channel for monitor */
				cc[x].idlebits = dacschan;
				cc[x].sigtype = DAHDI_SIG_DACS_RBS;
				sig[x] = sigtype_to_str(cc[x].sigtype);
				/* Setup inverse */
				cc[dacschan].idlebits = x;
				cc[dacschan].sigtype = DAHDI_SIG_DACS_RBS;
				sig[x] = sigtype_to_str(cc[dacschan].sigtype);
				is_digital = 1;
				dacschan++;
			} else if (!strcasecmp(keyword, "unused")) {
				cc[x].sigtype = 0;
				sig[x] = sigtype_to_str(cc[x].sigtype);
			} else if (!strcasecmp(keyword, "indclear") || !strcasecmp(keyword, "bchan")) {
				cc[x].sigtype = DAHDI_SIG_CLEAR;
				sig[x] = sigtype_to_str(cc[x].sigtype);
				is_digital = 1;
			} else if (!strcasecmp(keyword, "clear")) {
				sig[x] = sigtype_to_str(DAHDI_SIG_CLEAR);
				if (master) {
					cc[x].sigtype = DAHDI_SIG_SLAVE;
					cc[x].master = master;
				} else {
					cc[x].sigtype = DAHDI_SIG_CLEAR;
					master = x;
				}
				is_digital = 1;
			} else if (!strcasecmp(keyword, "rawhdlc")) {
				sig[x] = sigtype_to_str(DAHDI_SIG_HDLCRAW);
				if (master) {
					cc[x].sigtype = DAHDI_SIG_SLAVE;
					cc[x].master = master;
				} else {
					cc[x].sigtype = DAHDI_SIG_HDLCRAW;
					master = x;
				}
				is_digital = 1;
			} else if (!strcasecmp(keyword, "nethdlc")) {
				sig[x] = sigtype_to_str(DAHDI_SIG_HDLCNET);
				memset(cc[x].netdev_name, 0, sizeof(cc[x].netdev_name));
				if (master) {
					cc[x].sigtype = DAHDI_SIG_SLAVE;
					cc[x].master = master;
				} else {
					cc[x].sigtype = DAHDI_SIG_HDLCNET;
					if (idle) {
					    dahdi_copy_string(cc[x].netdev_name, idle, sizeof(cc[x].netdev_name));
					}
					master = x;
				}
				is_digital = 1;
			} else if (!strcasecmp(keyword, "fcshdlc")) {
				sig[x] = sigtype_to_str(DAHDI_SIG_HDLCFCS);
				if (master) {
					cc[x].sigtype = DAHDI_SIG_SLAVE;
					cc[x].master = master;
				} else {
					cc[x].sigtype = DAHDI_SIG_HDLCFCS;
					master = x;
				}
				is_digital = 1;
			} else if (!strcasecmp(keyword, "dchan")) {
				sig[x] = "D-channel";
				cc[x].sigtype = DAHDI_SIG_HDLCFCS;
				is_digital = 1;
			} else if (!strcasecmp(keyword, "hardhdlc")) {
				sig[x] = "Hardware assisted D-channel";
				cc[x].sigtype = DAHDI_SIG_HARDHDLC;
				is_digital = 1;
			} else if (!strcasecmp(keyword, "mtp2")) {
				sig[x] = "MTP2";
				cc[x].sigtype = DAHDI_SIG_MTP2;
				is_digital = 1;
			} else {
				fprintf(stderr, "Huh? (%s)\n", keyword);
			}
			if (is_digital)
				chan2span[x] = current_span;
			else
				current_span = 0;
		}
	}
	return 0;
}