Exemplo n.º 1
0
void mstore (header *hd)
{	FILE *file;
	ptyp p;
	hd=getvalue(hd); if (error) return;
	if (hd->type!=s_string)
	{	output("Expect file name.\n");
		error=1100; return;
	}
	p.udfend=udfend-ramstart;
	p.startlocal=startlocal-ramstart;
	p.endlocal=endlocal-ramstart;
	p.newram=newram-ramstart;
	file=fopen(stringof(hd),"wb");
	if (!file)
	{	output1("Could not open %s.\n",stringof(hd));
		error=1101; return;
	}
	fwrite(&p,sizeof(ptyp),1,file);
	fwrite(ramstart,1,newram-ramstart,file);
	if (ferror(file))
	{	output("Write error.\n");
		error=1102; return;
	}
	fclose(file);
}
Exemplo n.º 2
0
void mrestore (header *hd)
{	FILE *file;
	ptyp p;
	if (udfon)
	{	output("Cannot restore inside a UDF.\n");
		error=1; return;
	}
	hd=getvalue(hd); if (error) return;
	if (hd->type!=s_string)
	{	output("Expect file name.\n");
		error=1100; return;
	}
	file=fopen(stringof(hd),"rb");
	if (!file)
	{	output1("Could not open %s.\n",stringof(hd));
		error=1103; return;
	}
	fread(&p,sizeof(ptyp),1,file);
	if (ferror(file))
	{	output("Read error.\n");
		error=1104; return;
	}
	fread(ramstart,1,p.newram,file);
	if (ferror(file))
	{	output("Read error (fatal for EULER).\n");
		error=1104; return;
	}
	fclose(file);
	udfend=ramstart+p.udfend;
	startlocal=ramstart+p.startlocal;
	endlocal=ramstart+p.endlocal;
	newram=ramstart+p.newram;
	next=input_line; *next=0;
}
Exemplo n.º 3
0
void load_book (void)
/***** load_book
	interpret a notebook file.
*****/
{	header *hd;
	char name[256];
	char oldline[1024],fn[256],*oldnext;
	int oldbooktype=booktype;
	FILE *oldinfile;
	if (udfon)
	{	output("Cannot load a notebook in a function!\n");
		error=221; return;
	}
	 scan_space();
	if (*next=='(')
	{   hd=scan_value();
		if (error) return;
		if (hd->type!=s_string)
		{	output("String value expected!\n");
			error=1; return;
		}
		strcpy(name,stringof(hd));
	}
	else
	{	scan_namemax(name,256);
	}
	if (error) return;
	oldinfile=infile;
	infile=fopen(name,"r");
	if (!infile)
	{	strcpy(fn,name);
		strcat(fn,BOOKEXTENSION);
		infile=fopen(fn,"r");
		if (!infile)
		{	output1("Could not open %s!\n",stringof(name));
			error=53; infile=oldinfile; return;
		}
	}
	strcpy(oldline,input_line); oldnext=next;
	*input_line=0; next=input_line;
	booktype=1;
	while (!error && infile && !quit)
	{	startglobal=startlocal; endglobal=endlocal;
		command();
	}
	booktype=oldbooktype;
	if (infile) fclose(infile);
	infile=oldinfile;
	strcpy(input_line,oldline); next=oldnext;
}
Exemplo n.º 4
0
void do_postscript (void)
{	header *file;
	scan_space();
	file=scan_value();
	if (error || file->type!=s_string)
	{	output("Postscript needs a filename!\n");
		error=201; return;
	}
	FILE *metafile=fopen(stringof(file),"w");
	if (!metafile)
	{	output1("Could not open %s.\n",stringof(file));
	}
    dump_postscript(metafile);
    fclose(metafile);
}
Exemplo n.º 5
0
int ctest (header *hd)
/**** ctest
	test, if a matrix contains nonzero elements.
****/
{	double *m;
	LONG n,i;
	hd=getvalue(hd); if (error) return 0;
	if (hd->type==s_string) return (*stringof(hd)!=0);
	if (hd->type==s_real) return (*realof(hd)!=0.0);
	if (hd->type==s_complex) return (*realof(hd)!=0.0 &&
		*imagof(hd)!=0.0);
	if (hd->type==s_matrix)
	{	n=(LONG)(dimsof(hd)->r)*dimsof(hd)->c;
		m=matrixof(hd);
		for (i=0; i<n; i++) if (*m++==0.0) return 0;
		return 1;
	}
	if (hd->type==s_cmatrix)
	{	n=(LONG)(dimsof(hd)->r)*dimsof(hd)->c;
		m=matrixof(hd);
		for (i=0; i<n; i++) 
		{	if (*m==0.0 && *m==0.0) return 0; m+=2; }
		return 1;
	}
	return 0;
}
Exemplo n.º 6
0
void do_exec (void)
{	header *name;
	char *s;
	name=scan_value(); if (error) return;
	if (name->type!=s_string)
	{	output("Cannot execute a number or matrix!\n");
		error=130; return;
	}
	s=stringof(name);
	while (*s && !isspace(*s)) s++;
	if (*s) *s++=0;
	if (execute(stringof(name),s))
	{	output("Execution failed or program returned a failure!\n");
		error=131;
	}
}
Exemplo n.º 7
0
void do_cd (void)
{	header *hd;
	char name[256];
	char *s;
	scan_space();
	if (*next==';' || *next==',' || *next==0)
	{	s=cd("");
		output1("%s\n",s);
		return;
	}
	if (*next=='(')
	{   hd=scan_value();
		if (error) return;
		if (hd->type!=s_string)
		{	output("String value expected!\n");
			error=1; return;
		}
		strcpy(name,stringof(hd));
	}
	else
	{	scan_namemax(name,256);
	}
	if (error) return;
	s=cd(name);
	if (*next!=';') output1("%s\n",s);
	if (*next==',' || *next==';') next++;
}
Exemplo n.º 8
0
void mopen (header *hd)
{   header *st=hd,*hd1,*result;
	if (fa) fclose(fa);
	hd1=nextof(hd);
	hd=getvalue(hd); if (error) return;
	hd1=getvalue(hd1); if (error) return;
	if (hd->type!=s_string || hd1->type!=s_string) wrong_arg_in("open");
	fa=fopen(stringof(hd),stringof(hd1));
	if (!fa)
	{	error=1;
		output("Could not open the file!\n");
		return;
	}
	result=new_real((double)ferror(fa),""); if (error) return;
	moveresult(st,result);
}
Exemplo n.º 9
0
FeuThing::FeuThing(Feu *feu, TiXmlElement *ele, FeuThing *parent) {
    TiXmlAttribute *attr;
    TiXmlElement *kid;
    FeuThing *kidthing;
    std::string name,value;
    // Basic element(s)
    mFeu = feu;
    mType = ele->ValueStr();
    mName = "<unnamed>";
    // Walk Attribute list, importing as we go
    attr = ele->FirstAttribute();
    while (attr != NULL) {
        name = stringof(attr->Name());
        value = attr->ValueStr();
        info("   \"" + name + "\"  ==>  \"" + value + "\"\n");
        mAttributes[name] = value; // Store in our map
        if (name == "name") mName = value;


        attr = attr->Next();
    }

    // Walk child list, descending as we go
    kid = ele->FirstChildElement();
    while (kid != NULL) {
        kidthing = Feu::convertElement(feu,kid,this);
        if (kidthing != NULL) adopt(kidthing);
        kid = kid->NextSiblingElement();
    }
}
Exemplo n.º 10
0
void load_file (void)
/***** load_file
	interpret a file.
*****/
{	char filename[256];
	char oldline[1024],fn[256],*oldnext;
	int oldbooktype=booktype,pn;
	header *hd;
	FILE *oldinfile;
	if (udfon)
	{	output("Cannot load a file in a function!\n");
		error=221; return;
	}
	scan_space();
	if (*next=='(')
	{   hd=scan_value();
		if (error) return;
		if (hd->type!=s_string)
		{	output("String value expected!\n");
			error=1; return;
		}
		strcpy(filename,stringof(hd));
	}
	else
	{	scan_namemax(filename,256);
	}
	if (error) return;
	oldinfile=infile;
	pn=-1;
	retry :
	if (pn>=0)
	{	strcpy(fn,path[pn]);
		strcat(fn,PATH_DELIM_STR);
		strcat(fn,filename);
	}
	else strcpy(fn,filename);
	infile=fopen(fn,"r");
	if (!infile)
	{   strcat(fn,EXTENSION);
		infile=fopen(fn,"r");
		pn++;
		if (!infile)
		{	if (pn>=npath)
			{	output1("Could not open %s!\n",filename);
				error=53; infile=oldinfile; return;
			}
			else goto retry;
		}
	}
	strcpy(oldline,input_line); oldnext=next;
	*input_line=0; next=input_line;
	booktype=0;
	while (!error && infile && !quit) command();
	booktype=oldbooktype;
	if (infile) fclose(infile);
	infile=oldinfile;
	strcpy(input_line,oldline); next=oldnext;
}
Exemplo n.º 11
0
void mwrite (header *hd)
{   header *st=hd,*result;
	hd=getvalue(hd); if (error) return;
	if (hd->type!=s_string) wrong_arg_in("write");
	if (!fa) return;
	fprintf(fa,"%s",stringof(hd));
	result=new_real(ferror(fa),""); if (error) return;
	moveresult(st,result);
}
Exemplo n.º 12
0
void do_dump (void)
{	header *file;
	if (outfile)
	{	if (fclose(outfile))
		{	output("Error while closing dumpfile.\n");
		}
		outfile=0;
	}
	scan_space();
	if (*next==';' || *next==',' || *next==0)
	{	if (*next) next++; return; }
	file=scan_value();
	if (error || file->type!=s_string)
	{	output("Dump needs a filename!\n");
		error=201; return;
	}
	outfile=fopen(stringof(file),"a");
	if (!outfile)
	{	output1("Could not open %s.\n",stringof(file));
	}
}
Exemplo n.º 13
0
Arquivo: 06.c Projeto: uai/C-Quiz
main(int argc, char** argv)
{
	int a; 
	char AH[] = {0,'A',1,[3]='J','E','U',[8]='H',13,0,[6]='O','D',[0]=10};

	printf("%s", stringof(AH));
	int a = CMD2(3);
	do { 
		printf("%c", a[AH]);	
		CMD3(AH);
		CMD1	
			break;
	} while(0);

http://www.fme.vutbr.cz
	printf("%c%c", a[AH], AH[9]);
}
Exemplo n.º 14
0
void give_out (header *hd)
/***** give_out
	print a value.
*****/
{	switch(hd->type)
	{	case s_real : double_out(*realof(hd)); output("\n"); break;
		case s_complex : complex_out(*realof(hd),*imagof(hd));
			output("\n"); break;
		case s_matrix : out_matrix(hd); break;
		case s_cmatrix : out_cmatrix(hd); break;
		case s_imatrix : out_imatrix(hd); break;
		case s_string : output(stringof(hd)); output("\n"); break;
		case s_interval : interval_out(*aof(hd),*bof(hd));
			output("\n"); break;
		default : output("?\n");
	}
}
Exemplo n.º 15
0
void do_remove (void)
{	header *hd;
	char name[256];
	if (*next=='(')
	{   hd=scan_value();
		if (error) return;
		if (hd->type!=s_string)
		{	output("String value expected!\n");
			error=1; return;
		}
		strcpy(name,stringof(hd));
	}
	else
	{	scan_namemax(name,256);
	}
	if (error) return;
	remove(name);
}
Exemplo n.º 16
0
void FeuThing::setAttributeValue(std::string attr, double value) {
    double *pVal;
    // Does this exist in the fast map?
    if (NULL != (pVal = mValues[attr])) {
        *pVal = value;
        return;
    }

    // Slow path string map?
    if (0 != mAttributes.count(attr)) {
        // Got it.  Change the string backing store
        mAttributes[attr] = stringof(value);
        return;
    }

    // Not found.  Bummer.
    FeuLog::w("FeuThing:: Attempt to set value of nonexistent attribute \"" + mType + "." + attr + "\".\n");
    return;
}
Exemplo n.º 17
0
void do_dir (void)
{	header *file;
	char *s;
	scan_space();
	if (*next==';' || *next==',' || *next==0)
	{	file=new_string("*.*",5,"");
	}
	else file=scan_value();
	if (error || file->type!=s_string)
	{	output("Dir needs a string!\n");
		error=201; return;
	}
	s=dir(stringof(file));
	if (!s || !*s) return;
	output1("%s\n",s);
	while (1)
	{	s=dir(0);
		if (!s || !*s) break;
		output1("%s\n",s);
	}
	if (*next==',' || *next==';') next++;
}
Exemplo n.º 18
0
char*
writerules(char *s, int n)
{
	static uchar *text;
	char *tmp;

	free(lasterror);
	lasterror = nil;
	parsing = 1;
	if(setjmp(parsejmp) == 0){
		tmp = stringof(s, n);
		text = (uchar*)concat((char*)text, tmp);
		free(tmp);
		text = morerules(text, s==nil);
	}
	if(s == nil){
		free(text);
		text = nil;
	}
	parsing = 0;
	makeports(rules);
	return lasterror;
}
Exemplo n.º 19
0
void do_path (void)
{	header *ppath;
	char s[256],*p,*q;
	int i;
	scan_space();
	if (*next==';' || *next==',' || *next==0)
	{   out :
		for (i=0; i<npath; i++)
		{	output1("%s;",path[i]);
		}
		output("\n");
		return;
	}
	ppath=scan_value();
	if (error || ppath->type!=s_string)
	{	output("Path needs a string!\n");
		error=201; return;
	}
	p=stringof(ppath);
	for (i=0; i<npath; i++) free(path[i]);
	npath=0;
	while (*p)
	{	q=s;
		while (*p && *p!=';') *q++=*p++;
		if (q>s && *(q-1)==PATH_DELIM_CHAR) q--;
		*q=0;
		if (*p==';') p++;
		path[npath]=(char *)malloc(strlen(s)+1);
		strcpy(path[npath],s);
		npath++;
	}
	if (npath==0)
	{	path[0]=(char *)malloc(5);
		strcpy(path[0],".");
	}
	if (*next!=';') goto out;
}
Exemplo n.º 20
0
int main(int argc, char **argv)
{
    FeuCalculable  *fc;
    double fc_result;
    std::string  *expr;

    if (argc < 2) {
        FeuLog::e("Usage: feucalc <expression>\n");
        return -1;
    }

    expr = new std::string(argv[1]);
    FeuLog::i("Calculating result of expression: \""+*expr+"\"\n");

    fc = new FeuCalculable(NULL,*expr);

    fc_result = fc->proc();

    FeuLog::i("============================================================\n","Result is: \"" + stringof(fc_result) + "\"\n");
}