Example #1
0
void
initvar(void)
{
	const struct varinit *ip;
	struct var *vp;
	struct var **vpp;

	for (ip = varinit ; (vp = ip->var) != NULL ; ip++) {
		if (find_var(ip->text, &vpp, &vp->name_len) != NULL)
			continue;
		vp->next = *vpp;
		*vpp = vp;
		vp->text = strdup(ip->text);
		vp->flags = ip->flags;
		vp->func = ip->func;
	}
	/*
	 * PS1 depends on uid
	 */
	if (find_var("PS1", &vpp, &vps1.name_len) == NULL) {
		vps1.next = *vpp;
		*vpp = &vps1;
		vps1.text = strdup(geteuid() ? "PS1=$ " : "PS1=# ");
		vps1.flags = VSTRFIXED|VTEXTFIXED;
	}
}
Example #2
0
void CodeGen::back_patch(){
	break_program();

	for (int i = 0; i < code_ptr; i++){
		if(std::regex_match(bytes[i], std::regex("T[0-9]*"))){

			int offset = find_var(bytes[i] + bytes[i + 1]).offset;
			char *val_star = new char[2];
	 		std::sprintf(val_star, "%02X", code_ptr + offset);

	 		bytes[i++] = val_star;
	 		bytes[i] = "00";
		}
		else if(std::regex_match(bytes[i], std::regex("I[0-9]*"))){
			int offset = find_var(bytes[i] + bytes[i + 1]).offset;
			char *val_star = new char[2];
	 		std::sprintf(val_star, "%02X", code_ptr + offset);

	 		bytes[i++] = val_star;
	 		bytes[i] = "00";
		}
		else if(std::regex_match(bytes[i], std::regex("J[0-9]*"))){
			int offset = find_jump(bytes[i]) -> second;
			char *val_star = new char[2];
	 		std::sprintf(val_star, "%02X", offset);

	 		// std::cout << bytes[i] << ": " << offset << std::endl;
	 		bytes[i++] = val_star;
		}
	}
}
Example #3
0
void atom(int &value)
{
	int i;
	char temp[MAX_ID_LEN + 1];

	switch (token_type) {
	case IDENTIFIER:
		i = internal_func(token);
		if (i != -1) {
			// Call "standard library" function. 
			value = (*intern_func[i].p)();
		}
		else if (find_func(token)) {
			// Call programmer-created function. 
			call();
			value = ret_value;
		}
		else {
			value = find_var(token); // get var's value 
			strcpy(temp, token); // save variable name 

								 // Check for ++ or --. 
			get_token();
			if (*token == INC || *token == DEC) {
				if (*token == INC)
					assign_var(temp, find_var(temp) + 1);
				else
					assign_var(temp, find_var(temp) - 1);
			}
			else putback();
		}

		get_token();
		return;
	case NUMBER: // is numeric constant 
		value = atoi(token);
		get_token();

		return;
	case DELIMITER: // see if character constant 
		if (*token == '\'') {
			value = *prog;
			prog++;
			if (*prog != '\'')
				throw InterpExc(QUOTE_EXPECTED);

			prog++;
			get_token();

			return;
		}
		if (*token == ')') return; // process empty expression 
		else throw InterpExc(SYNTAX);  // otherwise, syntax error 
	default:
		throw InterpExc(SYNTAX); // syntax error 
	}
}
Example #4
0
void assign_val(char *destName, char *srcName)
{
	pgxc_ctl_var *dest = find_var(destName);
	pgxc_ctl_var *src = find_var(srcName);
	int ii;

	reset_value(dest);
	for (ii = 0; ii < src->val_used; ii++)
		add_val(dest, src->val[ii]);
}
void testcase(void) {
	assert(find_var("result1"));
	printf("result1      OK\n");

	assert(find_var("result2"));
	printf("result2      OK\n");

	assert(find_var("result3"));
	printf("result3      OK\n");
}
Example #6
0
/*
 * Removes datanode slave from pgxc_ctl configuration.
 */
static void emptyDatanodeSlaves()
{
	int ii;

	reset_var_val(VAR_datanodeSlave, "n");
	reset_var(VAR_datanodeSlaveServers);
	reset_var(VAR_datanodeSlaveDirs);
	reset_var(VAR_datanodeArchLogDirs);
	for (ii = 0; ii < arraySizeName(VAR_datanodeSlaveServers); ii++)
	{
		add_val(find_var(VAR_datanodeSlaveServers), "none");
		add_val(find_var(VAR_coordSlaveDirs), "none");
		add_val(find_var(VAR_coordArchLogDirs), "none");
	}
}
Example #7
0
void assign_sval(char *destName, char *val)
{
	pgxc_ctl_var *dest = find_var(destName);

	reset_value(dest);
	add_val(dest, val);
}
Example #8
0
char *sval(char *name)
{
	pgxc_ctl_var *var = find_var(name);
	if (!var)
		return NULL;
	return var->val[0];
}
Example #9
0
/*
 * Get all the servers --> VAR_allServers
 */
static void
addServer(char **name)
{
	int ii, jj;
	int flag;

	confirm_var(VAR_allServers);
	
	for (ii = 0; name[ii]; ii++)
	{
		flag = TRUE;
		for (jj = 0; aval(VAR_allServers)[jj]; jj++)
		{
			if (strcmp(name[ii], aval(VAR_allServers)[jj]) != 0)
				continue;
			else
			{
				flag = FALSE;
				break;
			}
		}
		if (flag)
			add_val(find_var(VAR_allServers), name[ii]);
	}
}
Example #10
0
int
rrd_parse_vdef(char *line, unsigned int *eaten, graph_desc_t *gdp, image_desc_t *im) {
    char tmpstr[MAX_VNAME_LEN+1];	/* vname\0 */
    int i=0;

    dprintf("- parsing '%s'\n",&line[*eaten]);
    if (rrd_parse_vname(line,eaten,gdp,im)) return 1;

    sscanf(&line[*eaten], DEF_NAM_FMT ",%n", tmpstr,&i);
    if (!i) {
	rrd_set_error("Cannot parse line '%s'",line);
	return 1;
    }
    if ((gdp->vidx=find_var(im,tmpstr))<0) {
	rrd_set_error("Not a valid vname: %s in line %s",tmpstr,line);
	return 1;
    }
    if (   im->gdes[gdp->vidx].gf != GF_DEF
	&& im->gdes[gdp->vidx].gf != GF_CDEF) {
	rrd_set_error("variable '%s' not DEF nor "
			"CDEF in VDEF '%s'", tmpstr,gdp->vname);
	return 1;
    }
    dprintf("- found vname: '%s' vidx %li\n",tmpstr,gdp->vidx);
    (*eaten)+=i;

    dprintf("- calling vdef_parse with param '%s'\n",&line[*eaten]);
    vdef_parse(gdp,&line[*eaten]);
    while (line[*eaten]!='\0'&&line[*eaten]!=':')
	(*eaten)++;

    return 0;
}
Example #11
0
int
rrd_parse_xport(char *line, unsigned int *eaten, graph_desc_t *gdp, image_desc_t *im) {
	char	*l = strdup(line + *eaten), *p;
	int	rc = 1;

	p = strchr(l, ':');
	if (p != NULL)
		*p++ = '\0';
	else
		p = "";
	
	if ((gdp->vidx=find_var(im, l))==-1){
		rrd_set_error("unknown variable '%s'",l);
		goto out;
	}
	
	if (strlen(p) >= FMT_LEG_LEN)
		*(p + FMT_LEG_LEN) = '\0';
	
	strcpy(gdp->legend, p);
	*eaten = strlen(line);
	rc = 0;
	
 out:
	free(l);
	return rc;
}
Example #12
0
var_t interpretexp(char** line)
{
    var_t exp;
    while (isspace(**line) != 0) ++(*line);
    if (**line == '"') 
    {
        ++(*line);
        exp.any.s = readtoken(line, isqmark, 1);
        exp.tag = STRING;
    }
    else if (isdigit(**line))
    {
        char* str = readtoken(line, isdigit, 0);
        exp.any.i = atoi(str);
        exp.tag = INT;
        free(str);
    }
    else if (isalpha(**line))
    {
        char* id = readtoken(line, isalpha, 0);
        exp = *find_var(id);
        free(id);
    }
    else
    {
        printf("Error at:\n %s ", *line);
        exit(EXIT_FAILURE);
    }
    while (isspace(**line) != 0) ++(*line);
    /*if + return add_var(exp, interpretexp(line))
    else if - return sub_var(exp, interpretexp(line))*/
    return exp;
}
Example #13
0
pgxc_ctl_var *confirm_var(char *name)
{
	pgxc_ctl_var *rc;
	if ((rc = find_var(name)))
		return rc;
	return new_var(name);
}
Example #14
0
void print_var(char *vname)
{
	pgxc_ctl_var *var;
	char outBuf[MAXLINE + 1];

	outBuf[0] = 0;
	if ((var = find_var(vname)) == NULL)
	{
		elog(ERROR, "ERROR: Variable %s not found.\n", vname);
		return;
	}
	else
	{
		char **curv;
		char editbuf[MAXPATH];

		snprintf(editbuf, MAXPATH, "%s (", vname);
		strncat(outBuf, editbuf, MAXLINE);
		for (curv=var->val; *curv; curv++)
		{
			snprintf(editbuf, MAXPATH, " \"%s\" ", *curv);
			strncat(outBuf, editbuf, MAXLINE);
		}
		strncat(outBuf, ")", MAXLINE);
		elog(NOTICE, "%s\n", outBuf);
	}
	
}
Example #15
0
File: var.c Project: dezelin/kBuild
int
unsetvar(shinstance *psh, const char *s, int unexport)
{
    struct var **vpp;
    struct var *vp;

    vp = find_var(psh, s, &vpp, NULL);
    if (vp == NULL)
        return 1;

    if (vp->flags & VREADONLY)
        return (1);

    INTOFF;
    if (unexport) {
        vp->flags &= ~VEXPORT;
    } else {
        if (vp->text[vp->name_len + 1] != '\0')
            setvar(psh, s, nullstr, 0);
        vp->flags &= ~VEXPORT;
        vp->flags |= VUNSET;
        if ((vp->flags & VSTRFIXED) == 0) {
            if ((vp->flags & VTEXTFIXED) == 0)
                ckfree(psh, vp->text);
            *vpp = vp->next;
            ckfree(psh, vp);
        }
    }
    INTON;
    return 0;
}
Example #16
0
File: var.c Project: dezelin/kBuild
int
exportcmd(shinstance *psh, int argc, char **argv)
{
    struct var *vp;
    char *name;
    const char *p;
    int flag = argv[0][0] == 'r'? VREADONLY : VEXPORT;
    int pflag;

    pflag = nextopt(psh, "p") == 'p' ? 3 : 0;
    if (argc <= 1 || pflag) {
        showvars(psh, pflag ? argv[0] : 0, flag, pflag );
        return 0;
    }

    while ((name = *psh->argptr++) != NULL) {
        if ((p = strchr(name, '=')) != NULL) {
            p++;
        } else {
            vp = find_var(psh, name, NULL, NULL);
            if (vp != NULL) {
                vp->flags |= flag;
                continue;
            }
        }
        setvar(psh, name, p, flag);
    }
    return 0;
}
Example #17
0
File: expr.c Project: FK2469/F-NEMU
uint32_t eval(int p, int q, bool *success) {
	if(p > q) {
		printf("Bad expression!\n");
		*success = false;
		return 0;
	} else if(p == q) {
		uint32_t val;
		if(tokens[p].type == DINT) sscanf(tokens[p].str, "%d", &val);
		else if(tokens[p].type == HINT) sscanf(tokens[p].str, "%x", &val);
		else if(tokens[p].type == REG) val = get_register(tokens[p].str);
		else if(tokens[p].type == VAR) {
			Exp_flag = 1;
			val = find_var(tokens[p].str);
			if(val == -1) {
			printf("No var matched!\n");
			*success = false;
			return 0;
			}
		} 
		else {
			printf("No number matched!\n");
			*success = false;
			return 0;
		}
		return val;
	} else if(check_parentheses(p, q, success) == true) {
		return eval(p + 1, q - 1, success);
	} else if(*success == true) {
		int op = find_dominant_operator(p, q);
		//printf("%d\n", op);
		int op_type = tokens[op].type;
		uint32_t val1, val2;
		if(op_type == NOT || op_type == DEREF) {
			val1 = eval(op+1, q, success);
			val2 = eval(op+1, q, success);
		} else {
			val1 = eval(p, op-1, success);
			val2 = eval(op+1, q, success);
		}

		switch(op_type) {
			case '+': return val1 + val2;
			case '-': return val1 - val2;
			case '*': return val1 * val2;
			case '/': return val1 / val2;
			case EQ: return val1 == val2;
			case UEQ: return val1 != val2;
			case AND: return val1 && val2;
			case OR: return val1 || val2;
			case NOT: return !val2;
			case DEREF: return swaddr_read(val2, 4,R_DS);
			default: 
				*success = false;
				printf("Cannot evaluate expression!\n");
				return 0;
		}
	} else {
		return 0;
	}
}
Example #18
0
static void push_fnc(struct context *context, struct byte_array *program)
{
    uint32_t num_closures = serial_decode_int(program);
    struct map *closures = NULL;

    for (int i=0; i<num_closures; i++) {
        struct byte_array *name = serial_decode_string(program);
        if (context->runtime) {
            if (!closures)
                closures = map_new();
            struct variable *c = find_var(context, name);
            c = variable_copy(context, c);
            map_insert(closures, name, c);
        }
    }

    struct byte_array *body = serial_decode_string(program);

    DEBUGPRINT("FNC %u,%u\n", num_closures, body->length);
    //display_code(context, body);

    if (context->runtime) {
        struct variable *f = variable_new_fnc(context, body, closures);
        variable_push(context, f);
    }
}
Example #19
0
/* Find value of number, variable or function. */
void atom(int *value)
{
  int i;
  switch(token_type) {
  case IDENTIFIER:
    i = internal_func(token);
    if(i!= -1) {  /* call "standard library" function */
      *value = (*intern_func[i].p)();
    }
    else
    if(find_func(token)){  /* call user-defined function */
      call();
      *value = ret_value;
    }
    else  *value = find_var(token);  /* get var's value */
    get_token();
    return;
  case NUMBER: /* is numeric constant */
    *value = atoi(token);
    get_token();
    return;
  case DELIMITER: /* see if character constant */
    if(*token=='\'') {
      *value = *prog;
      prog++;
      if(*prog!='\'') sntx_err(QUOTE_EXPECTED);
      prog++;
      get_token();
    }
    return;
  default:
    if(*token==')') return; /* process empty expression */
    else sntx_err(SYNTAX); /* syntax error */
  }
}
Example #20
0
void primitive(double *hold)
{
	switch (token_type)
	{
	case VARIABLE:
		*hold = find_var(token);
		get_token();
		return;
	case NUMBER:
    //
		*hold = atof((token));
    //if (sscanf(token, "%lf", hold) != 1)
	*hold = convert(token);
	if (convert_error == ERROR)
      serror( ERR_BADNUMER);
		get_token();
		return;
	case FUNCTION:
		calc_function( hold);
		if (*token != ')')
			serror(ERR_NOBRACKET);
		get_token();
		return;
	default:	// error
		return;
	}
}
Example #21
0
File: expr.c Project: thewhoo/ifj15
int its_function()
{
	int answer;
	htab_item *item;

	answer = not_function;
	token = get_token();
	switch (token->type) {
		case TOKEN_IDENTIFIER:
			item = htab_lookup(G.g_globalTab, token->data);
			if (item == NULL) {
				find_var(token, 0);
			} else {
				answer = external_function;
			}
			break;
		case TOKEN_LENGTH:
		case TOKEN_SUBSTR:
		case TOKEN_CONCAT:
		case TOKEN_FIND:
		case TOKEN_SORT:
			answer = internal_function;
	}
	unget_token(token);

	return answer;
}
Example #22
0
/*create a structure and add it into the struct list
 *structure defined by structspecifier node in syntax tree*/
struct struct_descriptor*
create_structure(struct tree_node* structspecifier_node){

	assert(structspecifier_node -> unit_code == StructSpecifier);
	struct tree_node* opttag_node = structspecifier_node -> child -> sibling;
	char* struct_name;
	if(structspecifier_node -> child -> sibling -> child != NULL){	//OptTag !-> empty
		struct_name = opttag_node -> child -> unit_value; //ID node has a value
		/*check struct name repeat*/
		if((find_struct(struct_table_head, struct_name) != NULL) ||
			(find_var(var_table_head, struct_name) != NULL)){
			printf("Error type 16 at line %d: Struct name redefine\n", structspecifier_node -> lineno);
			semantic_error_flag = true;
			return NULL;
		}
	}
	else
		struct_name = "";	//empty struct name
	
	struct tree_node* deflist_node = opttag_node -> sibling -> sibling;
		
	struct struct_descriptor* new_struct_descriptor = create_struct_descriptor(struct_name);
	new_struct_descriptor -> member_num = init_member_list(new_struct_descriptor -> member_list_head, deflist_node);
	add_struct(struct_table_head, new_struct_descriptor);
	return new_struct_descriptor;
}
Example #23
0
/*
 * Test each node and build target server list
 */
void makeServerList(void)
{
	/* Initialize */
	reset_var(VAR_allServers);
	/* GTM Master */
	addServer(aval(VAR_gtmMasterServer));
	/* GTM Slave */
	if (isVarYes(VAR_gtmSlave))
		addServer(aval(VAR_gtmSlaveServer));
	/* GTM_Proxy */
	if (isVarYes(VAR_gtmProxy))
		addServer(aval(VAR_gtmProxyServers));
	/* Coordinator Master */
	if (find_var(VAR_coordMasterServers))
		addServer(aval(VAR_coordMasterServers));
	/* Coordinator Slave */
	if (isVarYes(VAR_coordSlave))
		addServer(aval(VAR_coordSlaveServers));
	/* Datanode Master */
	addServer(aval(VAR_datanodeMasterServers));
	/* Datanode Slave */
	if (isVarYes(VAR_datanodeSlave))
		addServer(aval(VAR_datanodeSlaveServers));
	/* Should add secondary slaves */
}
Example #24
0
pgxc_ctl_var *new_var(char *name)
{
	pgxc_ctl_var *newv;

	if (find_var(name))
	{
		elog(ERROR, "ERROR: Variable %s already defined. Check your configuration.\n", name);
		return NULL;
	}

	newv = (pgxc_ctl_var *)Malloc(sizeof(pgxc_ctl_var));
	if (var_head == NULL)
	{
		var_head = var_tail = newv;
		newv->prev = NULL;
	}
	else
	{
		newv->prev = var_tail;
		var_tail->next = newv;
		var_tail = newv;
	}
	newv->next = NULL;
	newv->varname = Strdup(name);
	newv->val_size = 1;
	newv->val_used = 0;
	newv->val = (char **)Malloc(sizeof(char *));
	newv->val[0] = NULL;
	add_var_hash(newv);
	return(newv);
}
Example #25
0
static void checkIfVarIsConfigured(char *name)
{
	if (!find_var(name) || !sval(name))
	{
		anyConfigErrors = TRUE;
		reportMissingVar(name);
	}
}
Example #26
0
int
interp_var(struct cli_env *env, const char *var, char *buf, int buflen){

    const struct Var *v = find_var(env, var);
    if( !v ) return -1;

    return interp_varref(env, v, buf, buflen);
}
Example #27
0
void add_val_name(char *name, char *val)
{
	pgxc_ctl_var *var;
	if (!(var = find_var(name)))
		return;
	add_val(var, name);
	return;
}
Example #28
0
/* Try to find a var. If the given module is NULL, then search through both the
   current and builtin modules. For everything else, just search through the
   module given. */
lily_var *lily_find_var(lily_symtab *symtab, lily_module_entry *module,
        const char *name)
{
    uint64_t shorthash = shorthash_for_name(name);
    lily_var *result;

    if (module == NULL) {
        result = find_var(symtab->builtin_module->var_chain, name,
                    shorthash);
        if (result == NULL)
            result = find_var(symtab->active_module->var_chain, name, shorthash);
    }
    else
        result = find_var(module->var_chain, name, shorthash);

    return result;
}
Example #29
0
int arraySizeName(char *name)
{
	pgxc_ctl_var *var;

	if ((var = find_var(name)) == NULL)
		return -1;
	return(arraySize(var));
}
Example #30
0
/* Try to find a var. If the given import is NULL, then search through both the
   current and builtin imports. For everything else, just search through the
   import given. */
lily_var *lily_find_var(lily_symtab *symtab, lily_import_entry *import,
        const char *name)
{
    uint64_t shorthash = shorthash_for_name(name);
    lily_var *result;

    if (import == NULL) {
        result = find_var(symtab->builtin_import->var_chain, name,
                    shorthash);
        if (result == NULL)
            result = find_var(symtab->active_import->var_chain, name, shorthash);
    }
    else
        result = find_var(import->var_chain, name, shorthash);

    return result;
}