Ejemplo n.º 1
0
void	frame_print_ext(FILE *fout, framestruc *fr, int verb, int mat, char *pref) {
	int		i;
	optionstruc	**op;
	char		pref2[50];
	
	if (!fr) {
		PROGERROR("Not printing NULL frame.");  return;
	}
	fprintf(fout,"%sFrame %p [%.18s%s%.4s], parent [%.9s], %s%d\n",pref,fr,
			FRNAME(fr)?FRNAME(fr):"",FREXTENS(fr)?" ":"",FREXTENS(fr)?FREXTENS(fr):"",
			(FRPARENT(fr)?(FRNAME(FRPARENT_XD(fr))?FRNAME(FRPARENT_XD(fr)):""):""),
			FRSONS_XD(fr)?"sons ":"",FRNUMSONS(fr));
	if (verb>0 && FRCOMMENT(fr))  fprintf(fout,"%s  - comment \"%s\"\n",pref,FRCOMMENT(fr));
	if (verb>0)  fprintf(fout,"%s  - matrix %d x %d,  number %d,  pf value %s,\n",pref,
			FRMATRIXROWS(fr),FRMATRIXCOLS(fr),FRNUMBER(fr),pfield_printvalue(25,FRVALUEEXP(fr),FRVALUESIG(fr)));
	if (FRMATRIX(fr)) if (ROWSM(FRMATRIX(fr))+COLSM(FRMATRIX(fr))>2) {
		strncpy(pref2,pref,40);  pref2[39] = 0;  strcat(pref2,"  :\t");
		if (mat>1)  ematrix_fprint_pref(fout,FRMATRIX(fr),pref2);
		else if (mat>0)  ematrix_fprint_nofr(fout,FRMATRIX(fr),pref2);
	}
	if (verb>1 && FROPTIONS(fr)) {
		fprintf(fout,"%s  - options:  ",pref);
		for (op=FROPTIONS(fr),i=0; *op; op++,i++)
			if (i<4)  fprintf(fout,"%s %.8s %.8s ; ",OPTNAME(*op),OPTPARAM(*op,0)?OPTPARAM(*op,0):"",OPTPARAM(*op,1)?OPTPARAM(*op,1):"");
		fprintf(fout,"..(%d)\n",i);
	}
	if (verb>1 && FRCOMMANDS(fr)) {
		fprintf(fout,"%s  - commands:  ",pref);
		for (op=FRCOMMANDS(fr),i=0; *op; op++,i++)
			if (i<4)  fprintf(fout,"%s %.8s %.8s ; ",OPTNAME(*op),OPTPARAM(*op,0)?OPTPARAM(*op,0):"",OPTPARAM(*op,1)?OPTPARAM(*op,1):"");
		fprintf(fout,"..(%d)\n",i);
	}
}
Ejemplo n.º 2
0
void	dispose_comoption(optionstruc *op) {
	int	i;
	
	if (OPTCONTINUED(op)<0)  {PROGERROREXIT("Disposing an option %p second time ?!",op);}
	OPTCONTINUED(op) = -1;
	if (OPTNAME(op))  FREE(OPTNAME(op));
	for (i=0; i<MAXOPTPARAMS; i++)
		if (OPTPARAM(op,i))  FREE(OPTPARAM(op,i));
	FREE(op);
	fr_aloptions--;
}
Ejemplo n.º 3
0
bool Parser::OPTION(int& pos, OptionValue& ovalue)
{
	int p{ pos };
	if (!LBRACKET(p)) return false;
	OptionName oname;
	if (!OPTNAME(p, oname)) return false;
	if (!RBRACKET(p)) return false;
	Fragment f;
	TEXT(p, f); // error check?
	ovalue.name = oname.name;
	ovalue.nameEnd = oname.nameEnd;
	ovalue.text = f.b;
	ovalue.textEnd = f.e;
	pos = p;

	char optname[256];
	int len = ovalue.nameEnd - ovalue.name;
	if (len >= 256) len = 255;
	strncpy(optname, ovalue.name, len);
	optname[len] = 0;
	char help[512];
	len = ovalue.textEnd - ovalue.text;
	if (len >= 256) len = 255;
	strncpy(help, ovalue.text, len);
	help[len] = 0;
	printf("option:\n   name=%s\n    help=%s\n", optname, help);

	return true;
}
Ejemplo n.º 4
0
void	yy_optionend(int ix, int ln) {
	optionstruc	*curo;
	
	if (ln>=0 && ln!=OPTINDEX(curoption))  {PROGERROR("Option ends with different line number ?!? %d!=%d",ln,OPTINDEX(curoption));}
	if (ix>=0 && curoptcd!=Icomproc)  DEBUG(CURDLEV+2," -  %s \"%s\" is stored (ln %d) [ %s %s .. ]\n",
			curoptcd!=Ioption?"command":"option",OPTNAME(curoption),ln,OPTPARAM(curoption,0),OPTPARAM(curoption,1));
	if (ix>=0 && curoptcd==Icomproc)  DEBUG(CURDLEV+1," -  getting procedure %s (ln %d) [ %s %s .. ]\n",
			OPTNAME(curoption),ln,OPTPARAM(curoption,0),OPTPARAM(curoption,1));
	
	curo = curoption;  curoption = NULL;
	if (curoptcd==Icommand) {
		frame_addcommand(curframe,curo,ln);
	} else if (curoptcd==Ioption) {
		frame_addoption(curframe,curo,ln);
		yy_applyoption(curo,ln);
	} else if (curoptcd==Icomproc) {
		dispose_comoption(curo);
	}
}
Ejemplo n.º 5
0
optionstruc*	option_copy(optionstruc *op) {
	optionstruc	*opn;
	int		i;
	
	opn = new_comoption_ext(OPTNAME(op),OPTCOM(op),OPTCONTINUED(op));
	OPTINDEX(opn) = OPTINDEX(op);
	OPTPARSG(opn) = OPTPARSG(op);
	OPTPAREX(opn) = OPTPAREX(op);
	for (i=0; i<MAXOPTPARAMS; i++)
		if (OPTPARAM(op,i))  option_setparam(opn,i,OPTPARAM(op,i),OPTNPARAM(op,i));
	return opn;
}
Ejemplo n.º 6
0
void	frame_addoption(framestruc *fr, optionstruc *op, int li) {
	int	i,k;
	char	*s;
	
	FROPTIONS(fr) = alist_append(FROPTIONS(fr),op);
	FRLASTOPTI(fr) = li;
	for (i=k=0; k<4 && optdescdefs[i].name; i++) {
		s = optdescdefs[i].name;
		if (k>=0 && strncmp(OPTNAME(op),s,strlen(s))==0)  k = 1;
		if (OPTISNAME(op,s))  k = 2;
		if (k>=2)  k = (optdescdefs[i].numpar<0 || OPTPARNUM(op)==optdescdefs[i].numpar)?4:-1;
	}
	if (k<=0)  {USERERROR("Unknown option \'%s\' or wrong number of option values (%d).",OPTNAME(op),OPTPARNUM(op));}
}
Ejemplo n.º 7
0
void	yy_optionval(int ix, char *val, long dv) {
	char	*s;
	int	l;
	
	if (!curoption || ix<curoptvalix)  {PROGERROREXIT("No option has started %p, or invalid index %d.",curoption,ix);}
	if (!val && dv==OPTNOPARAM)  return;
	
	if (ix-curoptvalix>=MAXOPTPARAMS) {
		s = OPTNAME(curoption);  l = OPTINDEX(curoption);
		yy_optionend(-1,-1);
		yy_optionstart(s,curoptcd,l,1);	/* a "continuing" option to accommodate all values */
		curoptvalix += MAXOPTPARAMS;
	}
	option_setparam(curoption,ix-curoptvalix,val,dv);	/* setting the value */
}
Ejemplo n.º 8
0
void	yy_applyoption(optionstruc *op, int ln) {
	int	r,x;
	ematrix	*ex;
	
	if (OPTISOPTION(op) && OPTISNAME(op,"require")) {
		if (OPTPARSG(op)<-1)  {LERROR("Undefined required value over %s at l. %d!",pfield_curname(),ln);}
		if (OPTPARNUM(op)>=2 && OPTNPARAM(op,1)<10)
			if ((OPTPARSG(op)==0)!=(OPTNPARAM(op,1)==0))
				{LERROR("Wrong required value over %s at l. %d:  %s ! %s !",
					pfield_curname(),ln,pfield_pvalue(20,OPTPAREX(op),OPTPARSG(op)),OPTNPARAM(op,1)==0?"==0":"!=0");}
		if (OPTNPARAM(op,1)<0 || (OPTNPARAM(op,1)>1 && OPTNPARAM(op,1)!=OPTNOPARAM))
				{LERROR("Expecting no value, or 0, or 1 for \"@require expr X\"!");}
		
	} else if (OPTISOPTION(op) && OPTISNAME(op,"name")) {
		if (OPTPARAM(op,0))  frame_setname(curframe,OPTPARAM(op,0));
	
	} else if (OPTISOPTION(op) && OPTISNAME(op,"comment")) {
		if (OPTPARAM(op,0))  FRCOMMENT(curframe) = MSTRDUP(OPTPARAM(op,0));
	
	} else if (OPTISOPTION(op) && OPTISNAME(op,"inputpf")) {
		x = pfield_curindex();
		r = pfield_switchto_ext(0,OPTPARAM(op,0));
		if (r<0)  {LERROR("Failed to switch input pfield to \"%s\", now in \"%s\"\n",OPTPARAM(op,0),pfield_curname());}
		else  DEBUG(CURDLEV-2,"Switched input arithmetics to a new pfield \"%s\"\n",pfield_curname());
		if (mxline>0 && r>=0)  {LERROR("Do not switch input pfield inside a matrix!");}
		else  FRPFINDEX(curframe) = pfield_curindex();
		if (r>=0 && FRPFINDEX_SAVE(curframe)<0)  FRPFINDEX_SAVE(curframe) = x;
	
	} else if (OPTISOPTION(op) && OPTISNAME(op,"transpose")) {
		if ((ex=FRMATRIX(curframe))!=NULL) {
			ematrix_transpose(ex);
			mxline = FRMATRIXCOLS(curframe);
			FRMATRIXCOLS(curframe) = FRMATRIXROWS(curframe);
			FRMATRIXROWS(curframe) = mxline;
		}
	
	//} else if (OPTISOPTION(op) && OPTISNAME(op,"")) {
		
	} else  return;
	
	DEBUG(CURDLEV+1,"Option \"%s\" applied (l. %d).\n",OPTNAME(op),ln);
	if (OPTCONTINUED(op) || curoptvalix>=MAXOPTPARAMS)
		DEBUG(CURDLEV-2,"** Warning ** - a continued option \"%s\" is not correctly processed here!\n",OPTNAME(op));
}
Ejemplo n.º 9
0
optionstruc*	new_comoption_ext(char *nm, int oc, int cont) {
	optionstruc	*op;
	int		i;
	
	if (!nm)  {PROGERROR("The option name must be given!");}
	if (oc<0 || oc>1)  {PROGERROR("Invalid option/command flag %d!",oc);}
	
	op = MMALLOC(sizeof(op[0]));		/* creates the option with its name */
	OPTNAME(op) = (nm?MSTRDUP(nm):NULL);
	OPTCOM(op) = oc;
	OPTCONTINUED(op) = (cont>0? cont:0);	/* a "continued" option flag - for continuing a long list of option values */
	OPTINDEX(op) = -1;
	OPTPARSG(op) = 0;  pfield_setzeroexp(&OPTPAREX(op));
	
	for (i=0; i<MAXOPTPARAMS; i++) {	/* nulls the option parameters (values) */
		OPTPARAM(op,i) = NULL;
		OPTNPARAM(op,i) = OPTNOPARAM;
	}
	OPTPARNUM(op) = 0;
	fr_aloptions++;
	return op;
}