Translates infix formulas into MathML and vice-versa.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char *translateInfix (const char *formula);
char *translateMathML (const char *xml);
int
main (int argc, char *argv[])
{
char *line;
char *result;
char *buffer = (char*)calloc( 1, sizeof(char) );
int reading = 1;
unsigned long len;
printf( "\n" );
printf( "This program translates infix formulas into MathML and\n" );
printf( "vice-versa. An 'enter' or a 'return' on an empty line\n" );
printf( "triggers translation. Ctrl-C quits\n" );
printf( "\n" );
while (reading)
{
printf( "Enter an infix formula or MathML expression (Ctrl-C to quit):\n" );
printf( "\n" );
printf( "> " );
do
{
line = trim_whitespace(get_line(stdin));
len = (unsigned int)strlen(line);
if (len > 0)
{
buffer = (char *) realloc( buffer, 1 + strlen(buffer) + len );
strncat(buffer, line, len);
strncat(buffer, "\n", 1);
}
else
{
result = (buffer[0] == '<') ?
translateMathML(buffer) : translateInfix(buffer);
printf("Result:\n\n%s\n\n\n", result);
free(result);
reading = 0;
}
}
while (len > 0);
}
free(line);
free(buffer);
return 0;
}
char *
translateInfix (const char *formula)
{
char *result;
return result;
}
char *
translateMathML (const char *xml)
{
char *result;
if (xml[0] == '<' && xml[1] != '?')
{
char *header = "<?xml version='1.0' encoding='UTF-8'?>\n";
char *content = (char *) calloc( strlen(xml) + strlen(header) + 1, sizeof(char) );
strncat(content, header, strlen(header));
strncat(content, xml, strlen(xml));
free(content);
}
else
{
}
return result;
}