Exemple #1
0
int DoUnset (Parser *p)
{
    int r;

    DynamicBuffer buf;
    DBufInit(&buf);

    r = ParseToken(p, &buf);
    if (r) return r;
    if (!DBufLen(&buf)) {
	DBufFree(&buf);
	return E_EOLN;
    }

    (void) DeleteVar(DBufValue(&buf));  /* Ignore error - nosuchvar */

/* Keep going... */
    while(1) {
	r = ParseToken(p, &buf);
	if (r) return r;
	if (!DBufLen(&buf)) {
	    DBufFree(&buf);
	    return OK;
	}
	(void) DeleteVar(DBufValue(&buf));
    }
}
Exemple #2
0
	void unsetenv (

/*  SYNOPSIS */
	const char *name)

/*  FUNCTION
	 deletes a variable from the environment.

    INPUTS
	name  --  Name of the environment variable to delete.

    RESULT
       Returns zero on success, or -1 if the variable was not found.

    NOTES
    
    EXAMPLE

    BUGS

    SEE ALSO

    INTERNALS

******************************************************************************/
{
    DeleteVar(name, GVF_LOCAL_ONLY);
} /* unsetenv */
Exemple #3
0
int 
SetStatusString (statusfile_t *sf, char *section, char *variable, char *value)
{
hash_item_t *p_hi;
int ret = 0;

if (sf->filename == NULL) return (0);

if (!pthread_mutex_lock(&(sf->mutex_lock))) {
   /* Do we delete the value? */
   if (value == NULL) {
      DeleteVar(sf, section, variable);
      ret = 1;
      }
   /* See if its already in there.  If it is, then replace the current val */
   else if ((p_hi = LookupVar(sf, section, variable)) != NULL) {
      if ((p_hi->value != NULL) && strcmp(p_hi->value, value)) {
         free(p_hi->value);
	 p_hi->value = strdup(value);
	 }
      ret = 1;
      }
   /* If its not, add a new value */
   else {
      p_hi = irrd_malloc(sizeof(hash_item_t));
      p_hi->key = strdup(variable);
      p_hi->value = strdup(value);
      if (InsertVar(sf, section, p_hi)) ret = 1;
      }

   ret = WriteStatusFile(sf, NULL);

   pthread_mutex_unlock(&(sf->mutex_lock));
   }

return (ret);
}
Exemple #4
0
// USER
int emulator::setUpEmulator()
{
    DEBUG(3) dprintf("emulator::setUpEmulator() called. this=%p\n", this);

    int retc;

    // Internal module
    int_module = new internal_module();
    if(!int_module)
        return ENOMEM;

    retc = int_module->init();
    if(retc)
        return retc;

    // Exec module
    exec_module = new exec::main();
    if(!exec_module)
        return ENOMEM;

    retc = exec_module->init();
    if(retc)
        return retc;

    // Dos module
    dos_module = new dos::main();
    if(!dos_module)
        return ENOMEM;

    retc = dos_module->init();
    if(retc)
        return retc;

    // Bootstrap
    bootstrap_mapping = new rom_mapping(sizeof(bootstrap_data), bootstrap_data);
    if(!bootstrap_mapping)
        return ENOMEM;

    if(v_space.add_mapping(bootstrap_mapping) == 0xFFFFFFFF)
        return ENOMEM;

    // Spawn emulation process
    char this_hex[17];
    sprintf(this_hex, "%p", this);

    // Set environment variable with "this" pointer.
    // It is inherited by the new process
    if(!SetVar("EMUMIGA_CREATOR", this_hex, -1, GVF_LOCAL_ONLY))
        return ENOMEM;

    creatorProc = (struct Process *)FindTask(0);
    creatorSigNo = AllocSignal(-1);

    if(creatorSigNo == -1)
        return ENOMEM;

    SetSignal(0, 1 << creatorSigNo);

    struct TagItem tags[] = {
        { NP_Entry, (IPTR)processEntry },
        { TAG_DONE, 0 }
    };

    struct Process *new_proc = CreateNewProcTagList(tags);

    if(!new_proc) {
        FreeSignal(creatorSigNo);
        return ENOMEM;
    }

    Wait(1 << creatorSigNo);

    FreeSignal(creatorSigNo);

    DeleteVar("EMUMIGA_CREATOR", GVF_LOCAL_ONLY);

    return 0;
}
Exemple #5
0
//-----------------------------------------------------------------------------
void mglParser::DeleteVar(const char *name)
{
	MGL_TO_WCS(name,DeleteVar(wcs));
}
Exemple #6
0
//-----------------------------------------------------------------------------
// return values: 0 - OK, 1 - wrong arguments, 2 - wrong command, 3 - string too long, 4 -- unclosed string
int mglParser::Parse(mglGraph *gr, std::wstring str, long pos)
{
	if(Stop || gr->NeedStop())	return 0;
	curGr = gr->Self();
	std::wstring arg[1024];
	str=mgl_trim_ws(str);
	long n,k=0,m=0,mm=0,res;
	// try parse ':' -- several commands in line
	for(n=0;n<long(str.length());n++)
	{
		if(str[n]=='\'' && (n==0 || str[n-1]!='\\'))	k++;
		if(k%2)	continue;
		if(str[n]=='(')	m++;	if(str[n]==')')	m--;
		if(str[n]=='{')	mm++;	if(str[n]=='}')	mm--;
		if(str[n]=='#')	break;
		if((str[n]==':' || str[n]=='\n') && k%2==0 && m==0 && mm==0)
		{
			res=Parse(gr,str.substr(0,n),pos);
			if(!res)	res=Parse(gr,str.substr(n+1),pos);
			return res;
		}
	}
	if(k%2 || m || mm)	return 4;	// strings is not closed
	// define parameters or start cycle
	res = ParseDef(str);	if(res)	return res-1;
	// parse arguments (parameters $1, ..., $9)
	PutArg(str,false);	str=mgl_trim_ws(str);

	std::wstring opt;
	for(k=0;k<1024;k++)	// parse string to substrings (by spaces)
	{
		n = mglFindArg(str);
		if(n<1)	// this is option
		{
			if(str[-n]==';')	opt = str.substr(-n+1);
			if(n<0)	str = str.substr(0,-n);
			break;
		}
		arg[k] = str.substr(0,n);
		str = mgl_trim_ws(str.substr(n+1));
	}
	// try to find last argument
	if(str[0]!=0 && str[0]!='#' && str[0]!=';')	{	arg[k] = str;	k++;	}
	if(k<1) n =0;
	else
	{
		// fill arguments by its values
		mglArg *a = new mglArg[k];
		FillArg(gr, k, arg, a);
		// execute first special (program-flow-control) commands
		if(!skip() && !arg[0].compare(L"stop"))
		{	Stop = true;	delete []a;	return 0;	}
		if(!arg[0].compare(L"func"))
		{	Stop = true;	delete []a;	return 0;	}
		n = FlowExec(gr, arg[0].c_str(),k-1,a);
		if(n)		{	delete []a;	return n-1;	}
		if(skip())	{	delete []a;	return 0;	}
		if(!arg[0].compare(L"load"))
		{
			int n = a[0].type==1?0:1;
			a[0].s.assign(a[0].w.begin(),a[0].w.end());
			if(!n)	mgl_parser_load(this,a[0].s.c_str());
			delete []a;	return n;
		}
		if(!arg[0].compare(L"define"))
		{
			if(k==3)
			{
				DeleteVar(arg[1].c_str());	// force to delete variable with the same name
				mglNum *v=AddNum(arg[1].c_str());
				if(arg[2][0]=='!')	// complex number is added
				{	HADT dd = mglFormulaCalcC(arg[2].substr(1),this, DataList);
					v->d=NAN;	v->c = dd->a[0];	delete dd;	}
				else
				{	HMDT dd = mglFormulaCalc(arg[2],this, DataList);
					v->c = v->d = dd->a[0];	delete dd;	}
			}
			delete []a;	return k==3?0:1;
		}
		if(!arg[0].compare(L"rkstep"))
		{
			int res=1;
			if(k>2 && a[0].type==1 && a[1].type==1)
			{
				std::wstring a1 = arg[1], a2=arg[2];	res = 0;
				if(a1[0]=='\'')	a1 = a1.substr(1,a1.length()-2);
				if(a2[0]=='\'')	a2 = a2.substr(1,a2.length()-2);
				mgl_rk_step_w(this, a1.c_str(), a2.c_str(), (k>=3 && a[2].type==2)?a[2].v:1);
			}
			delete []a;	return res;
		}
		if(!arg[0].compare(L"call"))
		{
			n = 1;
			if(a[0].type==1)
			{
				int na=0;
				a[0].s.assign(a[0].w.begin(),a[0].w.end());
				n=-IsFunc(a[0].w.c_str(),&na);
				if(n && k!=na+2)
				{
					char buf[64];
					snprintf(buf,64,"Bad arguments for %ls: %ld instead of %d\n", a[0].w.c_str(),k-2,na);
					buf[63]=0;	gr->SetWarn(-1,buf);	n = 1;
				}
				else if(n)
				{
					mglFnStack fn;			fn.pos = pos;
					for(int i=0;i<10;i++)	{	fn.par[i] = par[i];	par[i]=L"";	}
					for(int i=1;i<k-1;i++)	AddParam(i,arg[i+1].c_str());
					fn_stack.push_back(fn);	n--;
				}
				else if(AllowFileIO)	// disable external scripts if AllowFileIO=false
				{
					FILE *fp = fopen(a[0].s.c_str(),"rt");
					if(fp)
					{
						register int i;
						mglParser *prs = new mglParser(AllowSetSize);
						prs->DataList.swap(DataList);	prs->NumList.swap(NumList);	prs->Cmd=Cmd;
						for(i=10;i<30;i++)	prs->AddParam(i,par[i].c_str());
						prs->Execute(gr,fp);
						for(i=10;i<30;i++)	AddParam(i,prs->par[i].c_str());
						DataList.swap(prs->DataList);	NumList.swap(prs->NumList);
						prs->Cmd=0;	delete prs;	fclose(fp);
					}
					else	n=1;
				}
			}
			delete []a;	return n;
		}
		if(!arg[0].compare(L"for"))
		{
			n = 1;
			char ch = arg[1][0];
			int r = ch-'0';
			if(ch>='a' && ch<='z')	r = 10+ch-'a';
//			int r = int(a[0].v);
			if(arg[1][1]==0 && (r>=0 && r<40))
			{
				if(a[1].type==0)
				{
					n=0;		fval[r] = *(a[1].d);
					fval[r].nx *= fval[r].ny*fval[r].nz;
				}
				else if(a[1].type==2 && a[2].type==2 && a[2].v>a[1].v)
				{
					mreal step = a[3].type==2?a[3].v:1;
					mm = int(step>0 ? (a[2].v-a[1].v)/step : 0);
					if(mm>0)
					{
						n=0;	fval[r].Create(mm+1);
						for(int ii=0;ii<mm+1;ii++)
							fval[r].a[ii] = a[1].v + step*ii;
					}
				}
				if(n==0)
				{
					for(int i=39;i>0;i--)
					{	for_stack[i]=for_stack[i-1];	if_for[i]=if_for[i-1];	}
					for_stack[0] = r+1;		fval[r].nz = pos;	if_for[0]=if_pos;
					wchar_t buf[32];		mglprintf(buf,32,L"%g",fval[r].a[0]);
					AddParam(r, buf);	fval[r].ny = 1;
				}
			}
			delete []a;	return n;
		}
		// alocate new arrays and execute the command itself
		n = PreExec(gr, k, arg, a);
		if(n>0)	n--;
		else if(!arg[0].compare(L"setsize") && !AllowSetSize)	n = 2;
		else	n = Exec(gr, arg[0].c_str(),k-1,a, arg[1].c_str(), opt.c_str());
		delete []a;
	}
	// delete temporary data arrays
	for(size_t i=0;i<DataList.size();i++)	if(DataList[i] && DataList[i]->temp)
	{	mglDataA *u=DataList[i];	DataList[i]=0;	delete u;	}
	return n;
}
Exemple #7
0
//-----------------------------------------------------------------------------
// return values: 0 - not found, 1 - OK, 2 - wrong arguments, 3 - wrong command, 4 - string too long
int mglParser::PreExec(mglGraph *, long k, std::wstring *arg, mglArg *a)
{
	long n=0;
	if(!arg[0].compare(L"delete") && k==2)	// parse command "delete"
	{	DeleteVar(arg[1].c_str());	n=1;	}
	else if(!arg[0].compare(L"list"))	// parse command "list"
	{
		if(k<3 || CheckForName(arg[1]))	return 2;
		long nx=0, ny=1,j=0,i,t=0;
		for(i=2;i<k;i++)
		{
			char ch = arg[i][0];
			if(a[i-1].type==1)	return 2;
			if(a[i-1].type==0)
			{
				if(t==1)	return 2;
				t=2;	nx++;
			}
			if(a[i-1].type==2)
			{
				if(t==2)	return 2;
				j++;	t=1;
			}
			if(ch=='|' && t==1)		{	nx = j>nx ? j:nx;	j=0;	ny++;	}
		}
		mglDataA *vv = AddVar(arg[1].c_str());
		mglData *v = dynamic_cast<mglData*>(vv);
		mglDataC *vc = dynamic_cast<mglDataC*>(vv);
		if(v)
		{
			if(t==1)	nx = j>nx ? j:nx;
			if(t==1)	// list of numeric values
			{
				v->Create(nx,ny);
				j=t=0;
				for(i=2;i<k;i++)
				{
					if(arg[i][0]=='|')	{	t++;	j=0;	}
					else
					{	v->a[j+nx*t] = a[i-1].v;	j++;	}
				}
			}
			if(t==2)	// list of data
			{
				v->Set(a[1].d);
				for(long i=2;i<k;i++)	v->Join(*(a[i].d));
			}
			n=1;
		}
		if(vc)
		{
			if(t==1)	nx = j>nx ? j:nx;
			if(t==1)	// list of numeric values
			{
				vc->Create(nx,ny);
				j=t=0;
				for(i=2;i<k;i++)
				{
					if(arg[i][0]=='|')	{	t++;	j=0;	}
					else
					{	vc->a[j+nx*t] = a[i-1].c;	j++;	}
				}
			}
			if(t==2)	// list of data
			{
				vc->Set(a[1].d);
				for(long i=2;i<k;i++)	vc->Join(*(a[i].d));
			}
			n=1;
		}
	}
	return n;
}