TeX/src/platform/cli.c

113 lines
2.2 KiB
C

//---
// CLI interface: for parsing and computation tests on computer
//---
#ifdef TEX_PLATFORM_CLI
#include <TeX/TeX.h>
#include <TeX/structure.h>
#include <TeX/parser.h>
#include <stdio.h>
#include <string.h>
//---
// Interface functions
//---
/* dpixel() - Set a single pixel */
void dpixel(int x, int y, int color)
{
}
/* dline() - Draw a line */
void dline(int x1, int y1, int x2, int y2, int color)
{
}
/* dsize() - Get the dimensions of a string */
void dsize(char const *str, int *width, int *height)
{
/* Use fx9860g size standards */
*width = 6 * strlen(str) - 1;
*height = 7;
}
/* dtext() - Draw variable-width text */
void dtext(char const *str, int x, int y, int color)
{
}
void test_auto(void)
{
/* printf("\e[36m<><><>\e[0m \e[1mLexing\e[0m\n\n");
debug_lex("\\frac{1}{2}vt^2 = \\int_a^{b} f(x) dx");
printf("\n");
debug_lex("\\left(\\frac{1}{2}\\right)^{\\frac{n(n+1)}{2}}");
printf("\n");
printf("\e[36m<><><>\e[0m \e[1mParsing\e[0m\n\n"); */
struct TeX_Flow *flow = NULL;
/* flow = TeX_parse("\\frac{1}{2}vt^2 = \\int_a^{b} f(x) dx");
if(!flow) puts("parsing error!");
else TeX_debug_flow(flow, 0);
TeX_free(flow);
printf("\n");
flow = TeX_parse("\\left(\\frac{1}{2}\\right)^{\\frac{n(n+1)}{2}}");
if(!flow) puts("parsing error!");
else TeX_debug_flow(flow, 0);
TeX_free(flow);
printf("\n"); */
flow = TeX_parse("\\frac{1}{\\left(\\frac{12}{27}\\right)^2}");
if(!flow) puts("parsing error!");
else
{
size_flow(flow);
TeX_debug_flow(flow, 0);
}
TeX_free(flow);
printf("\n");
}
int main(void)
{
/* Set interface functions */
TeX_intf_pixel(dpixel);
TeX_intf_line(dline);
TeX_intf_size(dsize);
TeX_intf_text(dtext);
char formula[80];
printf("Input a string, or leave empty for auto tests:\n> ");
fgets(formula, 80, stdin);
/* Get out the NL */
formula[strlen(formula) - 1] = 0;
if(!formula[0])
{
test_auto();
return 0;
}
printf("\n\e[36m<><><>\e[0m \e[1mLexing\e[0m\n\n");
TeX_debug_lex(formula);
printf("\n\e[36m<><><>\e[0m \e[1mParsing\e[0m\n\n");
struct TeX_Flow *flow = TeX_parse(formula);
if(!flow) puts("parsing error!");
else TeX_debug_flow(flow, 0);
TeX_free(flow);
printf("\n");
return 0;
}
#endif /* TEX_PLATFORM_CLI */