示例#1
0
int input_parser_main(int argc, char** argv) {
    FILE*   fp;
    ot_queue   msg;
    ot_u8   msg_buffer[512];
    ot_bool usage_error = True;
    
    if (argc > 1) {
        fp = fopen(argv[1], "r");
        
        if (fp != NULL) {
            usage_error = False;
        }
        else {
             fprintf(stderr, "Error, could not open file: %s\n", argv[1]);
        }
    }
    
    if (usage_error) {
        fprintf(stderr, "Usage: tbprotocol [filename]\n");
        return 0;
    }
    
    q_init(&msg, msg_buffer, 512);
    
    while (1) {
        int test;
        int i;
        ot_u8* s;
        
        test = parse_sequence(fp, &msg);
        
        if (test < 0) break;
        
        fprintf(stdout, "Data written to ot_queue\n");
        
        for (s=(msg.putcursor-test), i=0; s<msg.putcursor; s++, i++) {
            if ((i & 3) == 0) {
                fprintf(stdout, "%04X: ", (ot_u16)s);
            }
            
            fprintf(stdout, "%02X ", *s);
            
            if ((i & 3) == 3) {
                fputc('\n', stdout);
            }
        } 
        
        if ((i & 3) != 0) {
            fputc('\n', stdout);
        }
        
        fputc('\n', stdout);
    }
    
    
    
    
    return 0;
}
示例#2
0
 static bool call(
     parser_type const& parser
   , Iterator& first, Iterator const& last
   , Context const& context, Attribute& attr, mpl::false_)
 {
     return parse_sequence(parser.left, parser.right
       , first, last, context, attr, traits::container_attribute());
 }
int parse_file(char *param_file)
{

	struct params *params;
        FILE *fd = fopen(param_file, "r");
	uint32_t file_size;
	char *buf;
	int i;	

        if(!fd)
        {
                PANEL_DEBUG("%s : Failed to open %s\n", __func__, param_file);
                return -1;
        }

	fseek(fd, 0, SEEK_END);
	file_size = ftell(fd);
	buf = (char *)malloc(file_size);
	fseek(fd, 0, SEEK_SET);
	fread(buf, file_size, 1, fd);
        fclose(fd);
	
	PANEL_DEBUG("Init sequence:\n%s\n", buf);


	parse_init(&params);
	parse_sequence(buf);

	PANEL_DEBUG("/**********  end of parse  **********/\n");	

	for(i = 0; i < params->line_nr; i++)
	{
		struct lcd_param *p;
		if(p = params->params[i])
		{
			int j;
			_PANEL_DEBUG("%d,0x%x,", p->delay, p->cmd);
			for(j = 0; j < p->data_len; j++)
				_PANEL_DEBUG("0x%x,", p->data[j]);
			_PANEL_DEBUG("\n");
		}

	}


	parse_deinit(params);


	
	return 0;
}
示例#4
0
/*
 * Parse transition
 */
static int parse_transition(snd_use_case_mgr_t *uc_mgr,
			    struct list_head *tlist,
			    snd_config_t *cfg)
{
	struct transition_sequence *tseq;
	const char *id;
	snd_config_iterator_t i, next;
	snd_config_t *n;
	int err;

	if (snd_config_get_id(cfg, &id) < 0)
		return -EINVAL;

	if (snd_config_get_type(cfg) != SND_CONFIG_TYPE_COMPOUND) {
		uc_error("compound type expected for %s", id);
		return -EINVAL;
	}

	snd_config_for_each(i, next, cfg) {
		n = snd_config_iterator_entry(i);

		if (snd_config_get_id(n, &id) < 0)
			return -EINVAL;

		tseq = calloc(1, sizeof(*tseq));
		if (tseq == NULL)
			return -ENOMEM;
		INIT_LIST_HEAD(&tseq->transition_list);

		tseq->name = strdup(id);
		if (tseq->name == NULL) {
			free(tseq);
			return -ENOMEM;
		}
	
		err = parse_sequence(uc_mgr, &tseq->transition_list, n);
		if (err < 0) {
			uc_mgr_free_transition_element(tseq);
			return err;
		}

		list_add(&tseq->list, tlist);
	}
示例#5
0
文件: rubyext.c 项目: alloy/MacRuby
static VALUE
parse_node(rb_yaml_parser_t *parser)
{
    VALUE node;
    NEXT_EVENT();

    switch (parser->event.type) {
	case YAML_DOCUMENT_END_EVENT:
	case YAML_MAPPING_END_EVENT:
	case YAML_SEQUENCE_END_EVENT:
	case YAML_STREAM_END_EVENT:
	    return Qundef;

	case YAML_MAPPING_START_EVENT:
	    node = parse_mapping(parser);
	    break;

	case YAML_SEQUENCE_START_EVENT:
	    node = parse_sequence(parser);
	    break;

	case YAML_SCALAR_EVENT:
	    node = parse_scalar(parser);
	    break;

	case YAML_ALIAS_EVENT:
	    // ignoring alias
	    node = Qundef;
	    break;

	default:
	    rb_raise(rb_eArgError, "Invalid event %d at top level",
		    (int)parser->event.type);
    }
    return node;
}