/** * Formats the given ASTNode as a rational number and appends the result to * the given StringBuffer. For SBML L1 this amounts to: * * "(numerator/denominator)" */ void FormulaFormatter_formatRational (StringBuffer_t *sb, const ASTNode_t *node) { StringBuffer_appendChar( sb, '('); StringBuffer_appendInt ( sb, ASTNode_getNumerator(node) ); StringBuffer_appendChar( sb, '/'); StringBuffer_appendInt ( sb, ASTNode_getDenominator(node) ); StringBuffer_appendChar( sb, ')'); }
/** * Formats the given ASTNode as a rational number and appends the result to * the given StringBuffer. For SBML L1 this amounts to: * * "(numerator/denominator)" */ void L3FormulaFormatter_formatRational (StringBuffer_t *sb, const ASTNode_t *node, const L3ParserSettings_t *settings) { StringBuffer_appendChar( sb, '('); StringBuffer_appendInt ( sb, ASTNode_getNumerator(node) ); StringBuffer_appendChar( sb, '/'); StringBuffer_appendInt ( sb, ASTNode_getDenominator(node) ); StringBuffer_appendChar( sb, ')'); if (L3ParserSettings_getParseUnits(settings)) { if (ASTNode_hasUnits(node)) { StringBuffer_appendChar( sb, ' '); StringBuffer_append( sb, ASTNode_getUnits(node)); } } }
/** * Formats the given ASTNode as a rational number and returns the result as * a string. This amounts to: * * "(numerator/denominator)" */ char * FormulaGraphvizFormatter_formatRational (const ASTNode_t *node) { char *s; StringBuffer_t *p = StringBuffer_create(128); StringBuffer_appendChar( p, '('); StringBuffer_appendInt ( p, ASTNode_getNumerator(node) ); StringBuffer_appendChar( p, '/'); StringBuffer_appendInt ( p, ASTNode_getDenominator(node) ); StringBuffer_appendChar( p, ')'); s = StringBuffer_toString(p); free(p); return s; }
/** * Since graphviz will interpret identical names as referring to * the same node presentation-wise it is better if each function node * has a unique name. * * Returns the name of the operator with the name of the first child * prepended * * THIS COULD BE DONE BETTER */ char * FormulaGraphvizFormatter_OperatorGetUniqueName (const ASTNode_t *node) { char *s; char number[10]; StringBuffer_t *p = StringBuffer_create(128); ASTNodeType_t type = ASTNode_getType(node); if (FormulaGraphvizFormatter_isFunction(ASTNode_getChild(node,0)) || ASTNode_isOperator(ASTNode_getChild(node,0))) { StringBuffer_append(p, "func"); } else { if (ASTNode_isInteger(ASTNode_getChild(node, 0))) { sprintf(number, "%d", (int)ASTNode_getInteger(ASTNode_getChild(node, 0))); StringBuffer_append(p, number); } else if (ASTNode_isReal(ASTNode_getChild(node, 0))) { sprintf(number, "%ld", ASTNode_getNumerator(ASTNode_getChild(node, 0))); StringBuffer_append(p, number); } else { StringBuffer_append(p, ASTNode_getName(ASTNode_getChild(node,0))); } } switch (type) { case AST_TIMES: StringBuffer_append(p, "times"); break; case AST_DIVIDE: StringBuffer_append(p, "divide"); break; case AST_PLUS: StringBuffer_append(p, "plus"); break; case AST_MINUS: StringBuffer_append(p, "minus"); break; case AST_POWER: StringBuffer_append(p, "power"); break; default: StringBuffer_appendChar(p, ASTNode_getCharacter(node)); break; } s = StringBuffer_toString(p); free(p); return s; }