Esempio n. 1
0
Foam::dimensionSet Foam::operator+
(
    const dimensionSet& ds1,
    const dimensionSet& ds2
)
{
    dimensionSet dimSum(ds1);

    if (dimensionSet::debug && ds1 != ds2)
    {
        FatalErrorInFunction
            << "LHS and RHS of + have different dimensions" << endl
            << "     dimensions : " << ds1 << " + " << ds2 << endl
            << abort(FatalError);
    }

    return dimSum;
}
Esempio n. 2
0
Tdim
dim(char *txt, struct Tgraph * graph)
{
	/* a linewidth mechanism were cool, i.e. automatic braking of the line */
	/* baceline should jump current y down, x should be the maximum x of all lines */
	/* a flag for linebreak should be placed, containing the y jump size */
	/* so that the draw routines know when to add to y and reset x zo 0 */
	int             i;
	int             len = strlen(txt);	/* length of text passed
						 * to parse */
	Tdim            our;	/* the dimensions of our current object */
	char           *gpos;	/* points to the tree node's text */
	char *end;
	PRSDEF          K;	/* keynumber, result from the
				 * keywordlookup */
	our.x = 0;
	our.y = 1;
	our.baseline = 0;
	graph->children = 0;	/* at the beginning the tree doesn't have
				 * children. We must first find them */
	graph->txt = (char *) malloc(len + 1);	/* allocating the same
						 * length is OK. Special
						 * characters in output
						 * are 2 chars
						 * long--shorter than in
						 * the input */
	gpos = graph->txt;	/* we setup now this pointer */
	*gpos = 0;
	if (*(end=findLineEnd(txt))!='\0')
	{
		/* the current level contains one or more line ends */
		/* the current level will become aan array of lines */
		int nlines=0;
		char * start=txt;
		char          **lines = (char **) malloc(sizeof(char *));
		Tdim            out;
		if (SYNTAX_ERR_FLAG==S_ERR)
			return out;
		*gpos = 1;		/* See parsedef.h for the keyword
				 * definitions */
		gpos++;
		*gpos = (char) ARRAY;
		gpos++;
		*gpos = 0;
		newChild(graph);
		graph->down[graph->children - 1]->options = malloc((2)*sizeof(char));
		graph->down[graph->children - 1]->options[0] = 'c'; /* default col alignment */
		graph->down[graph->children - 1]->options[1] = '\0'; /* default col alignment */
		/* count how many lines we have */
		while (1)
		{
			lines =(char **) realloc(lines,(nlines + 1) * (sizeof(char *)));
			lines[nlines] = (char *) malloc(end - start + 1);
			strncpy(lines[nlines], start, end - start);
			lines[nlines][end - start] = '\0';	/* terminate the string */
			nlines++;
			if (*end=='\0')
				break;
			start=end+1;
			end=findLineEnd(start);
		}
		/* fill the array with the lines */

#define Array (graph->down[graph->children-1])
		Array->array = malloc(sizeof(Tarray));
		Array->array->rows = nlines;
		Array->array->cols = 1;
		Array->array->rowy = (int *) calloc(nlines, sizeof(int));
		Array->array->colx = (int *) calloc(1, sizeof(int));
		for (i = 0; i < nlines; i++)
		{
			out = dim(lines[i], newChild(Array));
			if (out.x > Array->array->colx[0])
				Array->array->colx[0] = out.x;
			if (out.y > Array->array->rowy[i])
				Array->array->rowy[i] = out.y;
			free(lines[i]);
		}
		free(lines);
		Array->dim.x = 0;
		Array->dim.x += Array->array->colx[0];
		Array->dim.y = 0;
		for (i = 0; i < nlines; i++)
			Array->dim.y += Array->array->rowy[i];

		Array->dim.y += Array->array->rows - 1;
		Array->dim.x += Array->array->cols - 1;
	
		Array->dim.baseline = Array->dim.y / 2;
	
		our.x += Array->dim.x;
		if (our.baseline < Array->dim.baseline)
		{	
			our.y += Array->dim.baseline - our.baseline;
			our.baseline = Array->dim.baseline;
		}
		if (our.y < Array->dim.y)
			our.y = Array->dim.y;
#undef Array
		graph->dim = our;
		return our;
	}
	for (i = 0; i < len; i++)
	{
		if(SYNTAX_ERR_FLAG==S_ERR)
			return our;
		if ((txt[i] != '\\') && (txt[i] != '_') && (txt[i] != '^'))
		{
			our.x++;
			*gpos = txt[i];
			gpos++;
			*gpos = 0;
		} else
		{
			K = LookupKey(txt + i, Keys);
			switch (K)
			{
			case SUPER:
				i += dimSuperscript(txt + i, &gpos, &our,
						    graph);
				break;
			case SUB:
				i += dimSubscript(txt + i, &gpos, &our,
						  graph);
				break;
			case FRAC:
				i += dimFrac(txt + i, &gpos, &our, graph);
				break;
			case SQRT:
				i += dimSqrt(txt + i, &gpos, &our, graph);
				break;
			case OVERLINE:
				i += dimOverl(txt + i, &gpos, &our, graph);
				break;
			case UNDERLINE:
				i += dimUnderl(txt + i, &gpos, &our,
					       graph);
				break;
			case LIMIT:
				i += dimLimit(txt + i, &gpos, &our, graph);
				break;
			case BRACES:
				i += dimBrace(txt + i, &gpos, &our, graph);
				break;
			case ARRAY:
				i += dimArray(txt + i, &gpos, &our, graph);
				break;
			case TO:
				i += dimTo(txt + i, &gpos, &our, graph);
				break;
			case LEADSTO:
				i += dimLeadsto(txt + i, &gpos, &our,
						graph);
				break;
			case SUM:
				i += dimSum(txt + i, &gpos, &our, graph);
				break;
			case PROD:
				i += dimProd(txt + i, &gpos, &our, graph);
				break;
			case INT:
				i += dimInt(txt + i, &gpos, &our, graph);
				break;
			case OINT:
				i += dimOint(txt + i, &gpos, &our, graph);
				break;
			case INFTY:
				strcat(gpos, "oo");
				gpos += 2;
				our.x += 2;
				i += 5;
				break;
			case RCEIL:
				i += dimRceil(txt + i, &gpos, &our, graph);
				break;
			case LCEIL:
				i += dimLceil(txt + i, &gpos, &our, graph);
				break;
			case RFLOOR:
				i += dimRfloor(txt + i, &gpos, &our,
					       graph);
				break;
			case LFLOOR:
				i += dimLfloor(txt + i, &gpos, &our,
					       graph);
				break;
			case ESCAPE:
				i++;
				our.x++;
				*gpos = txt[i];
				gpos++;
				*gpos = 0;
				break;
			case ERR:
			default:
				fprintf(stderr,
					"I screwed up in dim, this should never happen!\n");
				exit(1);
				break;
			}
		}
	}
	graph->dim = our;
	return our;
}