Esempio n. 1
0
static void parse_method(fb_parser_t *P, fb_member_t *fld)
{
    fb_token_t *t;
    if (!(t = match(P, LEX_TOK_ID, "method expected identifier"))) {
        goto fail;
    }
    fld->symbol.ident = t;
    if (!match(P, '(', "method expected '(' after identifier")) {
        goto fail;
    }
    parse_type(P, &fld->req_type);
    if (!match(P, ')', "method expected ')' after request type")) {
        goto fail;
    }
    if (!match(P, ':', "method expected ':' before mandatory response type")) {
        goto fail;
    }
    parse_type(P, &fld->type);
    if ((t = optional(P, '='))) {
        error_tok(P, t, "method does not accept an initializer");
        goto fail;
    }
    fld->metadata = parse_metadata(P);
    advance(P, ';', "method must be terminated with ';'", 0);
    return;
fail:
    recover2(P, ';', 1, '}', 0);
}
Esempio n. 2
0
void				sessions_init(char *types)
{
  char				*comma;
  struct session		*elt;

  bonus_time = 0;
  sessions_track_types = TYPE_NONE;
  while (NULL != (comma = strchr(types, ','))) {
    *comma = '\0';
    sessions_track_types |= parse_type(types);
    types = comma + 1;
  }
  sessions_track_types |= parse_type(types);
  while (sessions_count) {
    elt = first_session;
    first_session = first_session->next;
    --sessions_count;
    dumper_close(elt->dumper);
    free(elt);
  }
# ifdef HAVE_LIBOOH323C
  ooH323EpInitialize(OO_CALLMODE_AUDIOCALL, "/dev/null");
  ooH323EpDisableAutoAnswer();
# endif
  track_sessions = 1;
}
Esempio n. 3
0
size_t smbresult_tocsv(smbresult data, char **buf, char *ace) {
	if(data.statuscode < 0) {
		return 0;
	}

	//parsehidden returns 0 or 1, so we need a quick if statement
	char hidden = ' ';
	if(parse_hidden(data.mode))
		hidden = 'X';

	//We need to parse the access entry, here are the variables we'll use to hold them
	char * principal = "";
	unsigned int atype = 0;
	unsigned int aflags = 0;
	unsigned int amask = 0;

	//Parse the entry, if we can't then just quit because we got bad data.
	if(ace != NULL) {
		if(parse_acl(ace, &principal, &atype, &aflags, &amask) == 0) {
			return 0;
		}
	}

	//We need to determine the length of our new string
	size_t size = snprintf(NULL, 0, "\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%c\"", 
		data.host, 
		data.share, 
		data.object, 
		parse_type(data.type),
		principal,
		parse_accessmask(amask),
		hidden
	);

	//Otherwise, just a simple sprintf to the buffer the user gave us.
	char *buffer = malloc(size+1);
	snprintf(buffer, size+1, "\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%c\"", 
		data.host, 
		data.share, 
		data.object, 
		parse_type(data.type),
		principal,
		parse_accessmask(amask),
		hidden
	);

	*buf = strdup(buffer);

	free(buffer);

	return size+1;
}
static void parse_types(const char *arg, uint16_t *mask)
{
    const char *comma;

    while ((comma = strchr(arg, ',')) != NULL) {
        if (comma == arg || !parse_type(arg, comma-arg, mask))
            xtables_error(PARAMETER_PROBLEM,
                          "addrtype: bad type `%s'", arg);
        arg = comma + 1;
    }

    if (strlen(arg) == 0 || !parse_type(arg, strlen(arg), mask))
        xtables_error(PARAMETER_PROBLEM, "addrtype: bad type \"%s\"", arg);
}
Esempio n. 5
0
/* returns the value as a ctype, pushes the user value onto the stack */
void check_ctype(lua_State* L, int idx, struct ctype* ct)
{
    if (lua_isstring(L, idx)) {
        struct parser P;
        P.line = 1;
        P.prev = P.next = lua_tostring(L, idx);
        P.align_mask = DEFAULT_ALIGN_MASK;
        parse_type(L, &P, ct);
        parse_argument(L, &P, -1, ct, NULL, NULL);
        lua_remove(L, -2); /* remove the user value from parse_type */

    } else if (lua_getmetatable(L, idx)) {
        if (!equals_upval(L, -1, &ctype_mt_key)
                && !equals_upval(L, -1, &cdata_mt_key)) {
            goto err;
        }

        lua_pop(L, 1); /* pop the metatable */
        *ct = *(struct ctype*) lua_touserdata(L, idx);
        lua_getuservalue(L, idx);

    } else {
        goto err;
    }

    return;

err:
    luaL_error(L, "expected cdata, ctype or string for arg #%d", idx);
}
Esempio n. 6
0
void handle_userdata_field(struct userdata *data) {
  trace(TRACE_USERDATA, "Adding a userdata field");

  // find the field name
  char * field_name = next_token();
  if (field_name == NULL) {
    error(ERROR_USERDATA, "Missing a field name for userdata %s", data->name);
  }
  
  struct userdata_field * field = data->fields;
  while (field != NULL && strcmp(field->name, field_name)) {
    field = field-> next;
  }
  if (field != NULL) {
    error(ERROR_USERDATA, "Field %s already exsists in userdata %s (declared on %d)", field_name, data->name, field->line);
  }

  trace(TRACE_USERDATA, "Adding field %s", field_name);
  field = (struct userdata_field *)allocate(sizeof(struct userdata_field));
  field->next = data->fields;
  data->fields = field;
  field->line = state.line_num;
  string_copy(&(field->name), field_name);

  parse_type(&(field->type), TYPE_REQUIRED, RANGE_CHECK_NONE);
  field->access_flags = parse_access_flags(&(field->type));
}
Esempio n. 7
0
static int parse_entries(const scconf_context * config, const scconf_block * block, scconf_entry * entry, int depth)
{
	int r, i, idx;
	scconf_entry *e;
	scconf_block **blocks = NULL;

	if (config->debug) {
		fprintf(stderr, "parse_entries called, depth %d\n", depth);
	}
	for (idx = 0; entry[idx].name; idx++) {
		e = &entry[idx];
		blocks = getblocks(config, block, e);
		if (!blocks) {
			if (!(e->flags & SCCONF_MANDATORY)) {
				if (config->debug)
					fprintf(stderr, "optional configuration entry '%s' not present\n",
						e->name);
				continue;
			}
			fprintf(stderr, "mandatory configuration entry '%s' not found\n", e->name);
			return 1;
		}
		for (i = 0; blocks[i]; i++) {
			r = parse_type(config, blocks[i], e, depth);
			if (r) {
				free(blocks);
				return r;
			}
			if (!(e->flags & SCCONF_ALL_BLOCKS))
				break;
		}
		free(blocks);
	}
	return 0;
}
int argdata_seq_iterate(const argdata_t *ad, argdata_seq_iterator_t *it_) {
  struct cloudabi_argdata_seq_iterator *it =
      (struct cloudabi_argdata_seq_iterator *)it_;
  switch (ad->type) {
    case AD_BUFFER: {
      const uint8_t *buf = ad->buffer;
      size_t len = ad->length;
      it->container = ad;
      it->error = parse_type(ADT_SEQ, &buf, &len);
      it->offset = buf - ad->buffer;
      break;
    }
    case AD_SEQ:
      it->container = ad;
      it->error = 0;
      it->offset = 0;
      break;
    default:
      it->error = EINVAL;
      break;
  }
  if (it->error != 0) {
    // If the iterator is invalid, fall back to using an empty buffer,
    // so that calls to argdata_seq_next() act as if iterating an empty
    // sequence.
    it->container = &argdata_null;
    it->offset = 0;
  }
  return it->error;
}
Esempio n. 9
0
static void parse_field(fb_parser_t *P, fb_member_t *fld)
{
    fb_token_t *t;
    if (!(t = match(P, LEX_TOK_ID, "field expected identifier"))) {
        goto fail;
    }
    fld->symbol.ident = t;
    if (!match(P, ':', "field expected ':' before mandatory type")) {
        goto fail;
    }
    parse_type(P, &fld->type);
    if (optional(P, '=')) {
        /*
         * Because types can be named references, we do not check the
         * default assignment before the schema is fully parsed.
         * We allow the initializer to be a name in case it is an enum
         * name.
         */
        parse_value(P, &fld->value, allow_id_value, "initializer must be of scalar type");
    }
    fld->metadata = parse_metadata(P);
    advance(P, ';', "field must be terminated with ';'", 0);
    return;
fail:
    recover2(P, ';', 1, '}', 0);
}
Esempio n. 10
0
static errr parse_specs(struct parser_hook *h, char *fmt) {
	char *name ;
	char *stype = NULL;
	int type;
	struct parser_spec *s;

	assert(h);
	assert(fmt);

	name = strtok(fmt, " ");
	if (!name)
		return -EINVAL;
	h->dir = string_make(name);
	h->fhead = NULL;
	h->ftail = NULL;
	while (name) {
		/* Lack of a type is legal; that means we're at the end of the line. */
		stype = strtok(NULL, " ");
		if (!stype)
			break;

		/* Lack of a name, on the other hand... */
		name = strtok(NULL, " ");
		if (!name) {
			clean_specs(h);
			return -EINVAL;
		}

		/* Grab a type, check to see if we have a mandatory type
		 * following an optional type. */
		type = parse_type(stype);
		if (type == PARSE_T_NONE) {
			clean_specs(h);
			return -EINVAL;
		}
		if (!(type & PARSE_T_OPT) && h->ftail &&
			(h->ftail->type & PARSE_T_OPT)) {
			clean_specs(h);
			return -EINVAL;
		}
		if (h->ftail && ((h->ftail->type & ~PARSE_T_OPT) == PARSE_T_STR)) {
			clean_specs(h);
			return -EINVAL;
		}

		/* Save this spec. */
		s = mem_alloc(sizeof *s);
		s->type = type;
		s->name = string_make(name);
		s->next = NULL;
		if (h->fhead)
			h->ftail->next = s;
		else
			h->fhead = s;
		h->ftail = s;
	}

	return 0;
}
Esempio n. 11
0
static xmms_magic_entry_t *
parse_entry (const gchar *s)
{
	xmms_magic_entry_t *entry;
	gchar *end = NULL;

	entry = g_new0 (xmms_magic_entry_t, 1);
	entry->endian = G_BYTE_ORDER;
	entry->oper = XMMS_MAGIC_ENTRY_OPERATOR_EQUAL;
	entry->offset = strtoul (s, &end, 0);

	end++;

	entry->type = parse_type (&end, &entry->endian);
	if (entry->type == XMMS_MAGIC_ENTRY_TYPE_UNKNOWN) {
		g_free (entry);
		return NULL;
	}

	if (!parse_pre_test_and_op (entry, &end)) {
		g_free (entry);
		return NULL;
	}

	/* @todo Implement string operators */
	switch (entry->type) {
		case XMMS_MAGIC_ENTRY_TYPE_STRING:
		case XMMS_MAGIC_ENTRY_TYPE_STRINGC:
			break;
		default:
			entry->oper = parse_oper (&end);
			break;
	}

	switch (entry->type) {
		case XMMS_MAGIC_ENTRY_TYPE_BYTE:
			entry->value.i8 = strtoul (end, &end, 0);
			entry->len = 1;
			break;
		case XMMS_MAGIC_ENTRY_TYPE_INT16:
			entry->value.i16 = strtoul (end, &end, 0);
			entry->len = 2;
			break;
		case XMMS_MAGIC_ENTRY_TYPE_INT32:
			entry->value.i32 = strtoul (end, &end, 0);
			entry->len = 4;
			break;
		case XMMS_MAGIC_ENTRY_TYPE_STRING:
		case XMMS_MAGIC_ENTRY_TYPE_STRINGC:
			g_strlcpy (entry->value.s, end, sizeof (entry->value.s));
			entry->len = strlen (entry->value.s);
			break;
		default:
			break; /* won't get here, handled above */
	}

	return entry;
}
Esempio n. 12
0
/* `enum` must already be matched. */
static void parse_enum_decl(fb_parser_t *P, fb_compound_type_t *ct)
{
    fb_token_t *t, *t0;
    fb_member_t *member;

    if (!(ct->symbol.ident = match(P, LEX_TOK_ID, "enum declaration expected identifier"))) {
        goto fail;
    }
    if (optional(P, ':')) {
        parse_type(P, &ct->type);
        if (ct->type.type != vt_scalar_type) {
            error_tok(P, ct->type.t, "integral type expected");
        } else {
            switch (ct->type.t->id) {
            case tok_kw_float:
            case tok_kw_double:
                error_tok(P, ct->type.t, "integral type expected");
            default:
                break;
            }
        }
    }
    ct->metadata = parse_metadata(P);
    if (!((t0 = match(P, '{', "enum declaration expected '{'")))) {
        goto fail;
    }
    for (;;) {
        if (!(t = match(P, LEX_TOK_ID,
                "member identifier expected"))) {
            goto fail;
        }
        if (P->failed >= FLATCC_MAX_ERRORS) {
            goto fail;
        }
        member = fb_add_member(P, &ct->members);
        member->symbol.ident = t;
        if (optional(P, '=')) {
            t = P->token;
            parse_value(P, &member->value, 0, "integral constant expected");
            /* Leave detailed type (e.g. no floats) and range checking to a later stage. */
        }
        /*
         * Trailing comma is optional in flatc but not in grammar, we
         * follow flatc.
         */
        if (!optional(P, ',') || P->token->id == '}') {
            break;
        }
        P->doc = 0;
    }
    if (t0) {
        advance(P, '}', "enum missing closing '}' to match", t0);
    }
    revert_symbols(&ct->members);
    return;
fail:
    recover(P, '}', 1);
}
Esempio n. 13
0
void parse_varDef() {
    expression_t expr;
    size_t addr;
    switch(next_token.type) {
        case TT_TYPE_DOUBLE:
        case TT_TYPE_INT:
        case TT_TYPE_STRING:
            var_init();
            parse_type();
            var_set_type(curr_token.type);
            match(TT_IDENTIFICATOR);
            var_set_name(curr_token.str);
            addr = generate_push();
            var_set_addr(addr);
            symbol_t* var = var_finish();
            var_table_add(var);
            parse_varDefFollow(var_table_find(var->name));
            break;
        case TT_TYPE_AUTO:
            var_init();
            match(TT_TYPE_AUTO);
            match(TT_IDENTIFICATOR);
            var_set_name(curr_token.str);
            match_deduction(TT_OP_ASSIGNMENT);
            var_set_initialized();
            addr = generate_push();
            var_set_addr(addr);
            expr = parse_expr();
            switch (expr.type) {
                case DOUBLE_DT:
                case INT_DT:
                case STRING_DT:
                    var_set_type(expr.type);
                    generate_mov(addr, expr.addr);
                    break;
                case DOUBLE_LIT_DT:
                    var_set_type(DOUBLE_DT);
                    generate_mov_double(addr, expr.double_val);
                    break;
                case INT_LIT_DT:
                    var_set_type(INT_DT);
                    generate_mov_int(addr, expr.int_val);
                    break;
                case STRING_LIT_DT:
                    var_set_type(STRING_DT);
                    generate_mov_string(addr, expr.str_val);
                    break;
                default:
                    ;
            }
            var_table_add(var_finish());
            break;
        default:
            error("Syntactic error: Failed to parse the program", ERROR_SYN);
    }
}
static struct arg_type_info *
parse_lens(struct protolib *plib, struct locus *loc,
	   char **str, struct param **extra_param,
	   size_t param_num, int *ownp, int *forwardp)
{
	int own_lens;
	struct lens *lens = name2lens(str, &own_lens);
	int has_args = 1;
	struct arg_type_info *info;
	if (lens != NULL) {
		eat_spaces(str);

		/* Octal lens gets special treatment, because of
		 * backward compatibility.  */
		if (lens == &octal_lens && **str != '(') {
			has_args = 0;
			info = type_get_simple(ARGTYPE_INT);
			*ownp = 0;
		} else if (parse_char(loc, str, '(') < 0) {
			report_error(loc->filename, loc->line_no,
				     "expected type argument after the lens");
			return NULL;
		}
	}

	if (has_args) {
		eat_spaces(str);
		info = parse_type(plib, loc, str, extra_param, param_num,
				  ownp, forwardp);
		if (info == NULL) {
		fail:
			if (own_lens && lens != NULL)
				lens_destroy(lens);
			return NULL;
		}
	}

	if (lens != NULL && has_args) {
		eat_spaces(str);
		parse_char(loc, str, ')');
	}

	/* We can't modify shared types.  Make a copy if we have a
	 * lens.  */
	if (lens != NULL && unshare_type_info(loc, &info, ownp) < 0)
		goto fail;

	if (lens != NULL) {
		info->lens = lens;
		info->own_lens = own_lens;
	}

	return info;
}
Esempio n. 15
0
static int32_t
snmp_import_top(struct snmp_toolinfo *snmptoolctx, enum tok *tok)
{
	enum snmp_tc tc;
	struct enum_type *t;

	if (*tok == '(')
		return (snmp_import_tree(snmptoolctx, tok));

	if (*tok == TOK_TYPEDEF) {
		if ((*tok = gettoken(snmptoolctx)) != TOK_STR) {
			warnx("type name expected after typedef - %s",
			    input->fname);
			return (-1);
		}

		t = snmp_enumtc_init(nexttok);

		*tok = gettoken(snmptoolctx);
		t->is_enum = (*tok == TOK_ENUM);
		t->is_bits = (*tok == TOK_BITS);
		t->syntax = parse_type(snmptoolctx, tok, &tc, &(t->snmp_enum));
		snmp_enumtc_insert(snmptoolctx, t);

		return (1);
	}

	if (*tok == TOK_INCLUDE) {
		int i;

		*tok = gettoken(snmptoolctx);
		if (*tok != TOK_FILENAME) {
			warnx("filename expected in include directive - %s",
			    nexttok);
			return (-1);
		}

		if (( i = add_filename(snmptoolctx, nexttok, NULL, 1)) == 0) {
			*tok = gettoken(snmptoolctx);
			return (1);
		}

		if (i == -1)
			return (-1);

		input_fopen(nexttok);
		*tok = gettoken(snmptoolctx);
		return (1);
	}

	warnx("'(' or 'typedef' expected - %s", nexttok);
	return (-1);
}
Esempio n. 16
0
/*
 * Read everything after the syntax type that is certainly a leaf OID info.
 */
static int
snmp_import_leaf(struct snmp_toolinfo *tool, enum tok *tok, struct snmp_oid2str *oid2str)
{
	int32_t i, syntax;

	if ((syntax = parse_type(tool, tok, &(oid2str->tc), &(oid2str->snmp_enum))) < 0)
		return(-1);

	oid2str->syntax = syntax;
	/*
	 * That is the name of the function, corresponding to the entry
	 * It is used by bsnmpd, but is not interesting for us.
	 */
	if (*tok == TOK_STR)
		*tok = gettoken(tool);

	/*
	 * Avoid looping forever here -
	 * while (tok == TOK_ACCESS)
	 */
	for (i = 0; i < SNMP_ACCESS_GETSET && *tok == TOK_ACCESS; i++) {
		oid2str->access |=  (u_int)val;
		*tok = gettoken(tool);
	}

	if (*tok != ')') {
		warnx("')' expected at end of line %d", input->lno);
		return (-1);
	}

	oid2str->table_idx = snmp_import_update_table(ENTRY_DATA,
			(struct snmp_index_entry *) NULL);

	if ((i = snmp_leaf_insert(tool, oid2str)) < 0) {
		warnx("Error adding leaf %s to list", oid2str->string);
		return (-1);
	}

	/*
	 * Same entry is already present in the mapping lists and
	 * the new one was not inserted.
	 */
	if (i == 0)  {
		free(oid2str->string);
		free(oid2str);
	}

	(void) snmp_import_update_table(ENTRY_NONE,
			(struct snmp_index_entry *) NULL);

	return (1);
}
Esempio n. 17
0
void handle_method(enum trace_level traceType, char *parent_name, struct method **methods) {
  trace(traceType, "Adding a method");

  // find the field name
  char * name = next_token();
  if (name == NULL) {
    error(ERROR_USERDATA, "Missing method name for %s", parent_name);
  }
  
  struct method * method = *methods;
  while (method != NULL && strcmp(method->name, name)) {
    method = method-> next;
  }
  if (method != NULL) {
    error(ERROR_USERDATA, "Method %s already exsists for %s (declared on %d)", name, parent_name, method->line);
  }

  trace(traceType, "Adding method %s", name);
  method = allocate(sizeof(struct method));
  method->next = *methods;
  *methods = method;
  string_copy(&(method->name), name);
  method->line = state.line_num;

  parse_type(&(method->return_type), TYPE_REQUIRED, RANGE_CHECK_NONE);

  // iterate the arguments
  struct type arg_type = {};
  while (parse_type(&arg_type, TYPE_OPTIONAL, RANGE_CHECK_MANDATORY)) {
    if (arg_type.type == TYPE_NONE) {
      error(ERROR_USERDATA, "Can't pass an empty argument to a method");
    }
    struct argument * arg = allocate(sizeof(struct argument));
    memcpy(&(arg->type), &arg_type, sizeof(struct type));
    arg->next = method->arguments;
    method->arguments = arg;
  }
}
Esempio n. 18
0
int main(void) {
	char input_buffer[MAX_STRING];
	char type[MAX_SUBSTRING];
	char declarator[MAX_SUBSTRING];
	char identifier[MAX_SUBSTRING];

	while (get_string(input_buffer)) {
		type[0] = identifier[0] = declarator[0] = '\0';
		parse_type(type, input_buffer);
		parse_declarator(identifier, declarator, input_buffer);
		printf("Declare %s as %s %s\n", identifier, declarator, type);
	}

	return 0;
}
Esempio n. 19
0
	void stuff_first(SCP_string &firstFont)
	{
		try
		{
			font_parse_setup("fonts.tbl");

			FontType type;
			parse_type(type, firstFont);
		}
		catch (const parse::ParseException& e)
		{
			Error(LOCATION, "Failed to setup font parsing. This may be caused by an empty fonts.tbl file.\nError message: %s", e.what());
			firstFont = "";
		}
	}
Esempio n. 20
0
int parse_desc_file(FILE* f, DESC* desc)
{
    int c = 0;
    char* value;
    char line[256], buffer[256];

    while (fgets(line, sizeof(line), f) != 0 && c < 4) {

    	if (sscanf(line, "%s", buffer) != 1)
    		return PARSE_ERROR;

    	value = strchr(buffer, '=');
    	if (!(value && strlen(value) > 1))
    		return PARSE_ERROR;
    	value++;

    	switch (c) {
	    	case 0:
	    		if (!parse_name(value, desc->name))
    				return PARSE_ERROR;
	    		break;

	    	case 1:
    			if (!parse_type(value, &(desc->type)))
    				return PARSE_ERROR;
	    		break;

	    	case 2:
		    	if (!parse_opcode(value, &(desc->opcode)))
	    			return PARSE_ERROR;
		    		break;

		    case 3:
		    	if (desc->type == 'R') {
		    		if (!parse_function(value, &(desc->function)))
	    				return PARSE_ERROR;
		    	}	
		    	else {
		    		desc->function = -1;
		    	}	
		    	break;	
    	}
    	c++;
    }
    return PARSE_SUCCESS;
}
Esempio n. 21
0
void parse_paramSpecFollow() {
    switch(next_token.type) {
        case TT_COMMA:
            match(TT_COMMA);
            var_init();
            parse_type();
            var_set_type(curr_token.type);
            match(TT_IDENTIFICATOR);
            var_set_name(curr_token.str);
            var_set_addr(++param_count);
            var_set_initialized();
            func_add_param(var_finish());
            parse_paramSpecFollow();
            break;
        default:
            return;
    }
}
Esempio n. 22
0
/* parses a line of the file
 * tries to set the corresponding row in the matrix
 * returns false on error
 */
bool parse_row(char* s, int row, LinearProgram* lp) {
    assert(lp_is_valid(lp));
    assert(row >= 0);
    assert(row < get_rows(lp));

    char* end_ptr;
    int cols = get_cols(lp);

    int i;
    for (i = 0; i < cols; i++) {
        num_t num = parse_num(s, &end_ptr);

        if (!is_num_valid(num, s, end_ptr)) {
            return false;
        }

        set_coef(lp, row, i, num);
        s = end_ptr;
    }


    s = parse_type(s, row, lp);

    if (NULL == s) {
        return false;
    }

    num_t num = parse_num(s, &end_ptr);
    if (!is_num_valid(num, s, end_ptr)) {
        return false;
    }
    s = end_ptr;

    s = skip_spaces(s);

    if ('\0' != *s) {
        return false;
    }

    set_rhs(lp, row, num);

    assert(lp_is_valid(lp));
    return true;
}
Esempio n. 23
0
/* parses a line of the file
 * tries to set the corresponding row in the matrix
 * returns false on error
 */
bool parse_row(char* s, int row, LinearProgram* lp) {
    assert(lp_is_valid(lp));
    assert(row >= 0);
    assert(row < lp->rows);

    int i;
    char* end_ptr;
    for (i = 0; i < lp->cols; i++) {
        num_t num = parse_num(s, &end_ptr);

        if (!is_num_valid(num, s, end_ptr)) {
            return false;
        }

        lp->matrix[row][i] = num;
        s = end_ptr;
    }


    s = parse_type(s, row, lp);

    if (NULL == s) {
        return false;
    }

    num_t num = parse_num(s, &end_ptr);
    if (!is_num_valid(num, s, end_ptr)) {
        return false;
    }
    s = end_ptr;

    s = skip_spaces(s);

    if ('\0' != *s) {
        return false;
    }

    lp->vector[row] = num;

    assert(lp_is_valid(lp));
    return true;
}
Esempio n. 24
0
File: parser.c Progetto: mabm/lem-in
t_map		*parse_lemin()
{
  t_map		*map;
  char		*buffer;
  int		step;
  t_info	info;

  init_map(&map);
  step = 0;
  info.command = 0;
  while ((buffer = get_next_line(0)) != NULL)
    {
      info.type = get_line_type(buffer);
      info.command = parse_type(info, buffer, &step, map);
      info.command = get_command(info.command, step, map);
      free(buffer);
    }
  is_valid_map(map);
  return (map);
}
Esempio n. 25
0
int argdata_get_binary(const argdata_t *ad, const void **value,
                       size_t *valuelen) {
  switch (ad->type) {
    case AD_BUFFER: {
      const uint8_t *buf = ad->buffer;
      size_t len = ad->length;
      int error = parse_type(ADT_BINARY, &buf, &len);
      if (error != 0)
        return error;

      *value = buf;
      *valuelen = len;
      return 0;
    }
    case AD_BINARY:
      *value = ad->binary;
      *valuelen = ad->length - 1;
      return 0;
    default:
      return EINVAL;
  }
}
Esempio n. 26
0
int cloudabi_argdata_get_int_u(const argdata_t *ad, uintmax_t *value,
                               uintmax_t max) {
  switch (ad->type) {
    case AD_BUFFER: {
      const uint8_t *buf = ad->buffer;
      size_t len = ad->length;
      int error = parse_type(ADT_INT, &buf, &len);
      if (error != 0)
        return error;

      // Parse unsigned number.
      uintmax_t res = 0;
      if (len > 0) {
        if ((buf[0] & 0x80) != 0) {
          // Number is negative.
          return ERANGE;
        }
        if (len > sizeof(res) && (len != sizeof(res) + 1 || buf[0] != 0)) {
          // Number is too large.
          return ERANGE;
        }

        // Add digits.
        do {
          res = res << 8 | *buf++;
        } while (--len > 0);
        if (res > max)
          return ERANGE;
      }
      *value = res;
      return 0;
    }
    default:
      return EINVAL;
  }
}
Esempio n. 27
0
inline bool parse_addr_type(char*& s, int& addr_t)
{ return parse_type(s,addr_t,addr_type_lookup,"address type"); }
Esempio n. 28
0
inline bool parse_net_type(char*& s, int& network)
{ return parse_type(s,network,net_type_lookup,"net type"); }
Esempio n. 29
0
inline bool parse_transport_prot(char*& s, int& tp)
{ return parse_type(s,tp,transport_prot_lookup,"transport protocol"); }
Esempio n. 30
0
static int read_line(char *linebuf, DEFINITION_FILE_STATE state)
{
  int 	retval = OK;

  switch (state) 
    {
    case START:
      /* Non-whitespace line in START state */
      printf("Can't parse line: %s\n");
      retval = PARSE_ERROR;
      break;
    case NAME:
      if (lc_name)			/* may be 2nd time through */
	break;
      lc_name = (char *)malloc(strlen(linebuf) + 1);
      if (lc_name == NULL) {
	retval = SYSTEM_ERROR;
	break;
      }
      downcase_string_no_blanks(lc_name, linebuf);
      form_plural_name(lc_name);
      break;
    case TABLES:
      retval = parse_and_append_table(&tables, linebuf);
      break;
    case STATIC_TABLES:   
      retval = parse_and_append_table(&static_tables, linebuf);
      break;
    case KEYS:
      if (tables) {
	if (fields == NULL) parse_table_files(tables, &fields);
	retval = mark_key(linebuf, fields, tables);
      }
      break;
    case CONDITIONAL_KEYS:
      if (tables) {
	if (fields == NULL) parse_table_files(tables, &fields);
	retval = mark_conditional_key(linebuf, fields, tables);
      }
      break;
    case KEY_STRINGS:
      retval = cache_key_string(linebuf);
      break;
    case IS_ACTIVE_STRINGS:
      retval = cache_is_active_string(linebuf);
      break;
    case CONDITIONAL_STRINGS:
      retval = cache_conditional_string(linebuf);
      break;
    case DISCONNECT_REASON_NAME:
      retval = cache_disconnect_reason_name(linebuf);
      break;
    case NEW_FIELDS:
      retval = cache_new_fields(linebuf);
      break;
    case IS_ACTIVE_FIELDS:
      if (tables) {
	if (fields == NULL) parse_table_files(tables, &fields);
	retval = add_is_active_field(linebuf);
      }
      break;
    case STATIC_KEYS:
      if (static_tables) {
	if (static_fields == NULL) 
	  parse_table_files(static_tables, &static_fields);
	retval = mark_key(linebuf, static_fields, static_tables);
      }
      else {
	printf("Sorry: current implementation requires that STATIC_TABLES appear ahead of STATIC_KEYS.\n");
	retval = FORMAT_ERROR;
      }
      break;
    case JOINS:
      if (tables) {
	if (fields == NULL) parse_table_files(tables, &fields);
	retval = add_join(linebuf);
      }
      break;
    case CONDITIONAL_JOINS:
      if (tables) {
	if (fields == NULL) parse_table_files(tables, &fields);
	retval = add_conditional_join(linebuf);
	has_conditionals = TRUE;
      }
      break;
    case CONDITIONAL_TABLES:
      if (tables) {
	if (fields == NULL) parse_table_files(tables, &fields);
	retval = mark_table_as_conditional(linebuf);
	has_conditionals = TRUE;
      }
      break;
    case STATIC_JOINS:
      if (tables && (fields == NULL))
	parse_table_files(tables, &fields);
      if (static_tables && (static_fields == NULL))
	parse_table_files(static_tables, &static_fields);
      if (fields && static_fields)
	retval = add_static_join(linebuf);
      break;
    case NULL_KEY_VALUES:
      if (has_keys) 
	retval = add_null_key_value(linebuf);
      else {
	/* Might get this on the second pass. */
	fprintf(stderr, "WARNING: Null-key list seen with no keys parsed.\n");
	retval = OK;
      }
      break;
    case EXCLUDES:
      if (has_includes) {
	printf("Cannot have both include and exclude fields.\n");
	retval = FORMAT_ERROR;
	break;
      }
      if (tables) {
	if (fields == NULL) parse_table_files(tables, &fields);
	if (!has_excludes) {
	  has_excludes = TRUE;
	  mark_fields_include(fields);
	}
	retval = exclude_field(linebuf);
      }
      break;
    case INCLUDES:
      if (has_excludes) {
	printf("Cannot have both include and exclude fields.\n");
	retval = FORMAT_ERROR;
	break;
      }
      if (tables) {
	if (fields == NULL) parse_table_files(tables, &fields);
	if (!has_includes) {
	  has_includes = TRUE;
	  mark_fields_exclude(fields);
	}
	retval = include_field(linebuf);
      }
      break;
    case READ_ONLIES:
      if (tables) {
	if (fields == NULL) parse_table_files(tables, &fields);
	retval = mark_read_only(linebuf);
      }
      break;
    case CHILDREN:
      retval = add_child(linebuf);
      break;
    case GRANDCHILDREN:
      retval = add_grandchild(linebuf);
      break;
    case ALIASES:
      retval = add_alias(linebuf);
      break;
    case TYPE:
      retval = parse_type(linebuf);
      break;
    case SORTING_FEATURES:
      retval = OK;
      has_sorting_features = TRUE;
      /* Add the line into the buffer */
      {
	strcat(sorting_alias, linebuf);
	strcat(sorting_alias, "\n");
      }
      break;
    case SPECIFY_EFFECTIVE_DATE:
      retval = OK;
      break;
    case NO_SELECT:
      retval = OK;
      break;
    case NO_LIST:
      retval = OK;
      break;
    case NO_NEW_DEL_UNSET:
      retval = OK;
      break;
    default:
      printf("Can't parse line: %s\n", linebuf);
      retval = PARSE_ERROR;
      break;
    }
  return retval;
}