1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
|
/* Format an interpretation in various ways
*/
#include "../ladr/top_input.h"
#include "../ladr/interp.h"
#define PROGRAM_NAME "modelformat"
#include "../VERSION_DATE.h"
static char Help_string[] =
"\nThis program reads a stream containing interpretations in portable format\n"
"(from stdin) and takes a command-line argument saying how to print them:\n\n"
" portable : one line per operation\n"
" portable2 : portable, with binary operations in a square\n"
" tabular : as nice tables\n"
" raw : similar to portable, but without punctuation\n"
" cooked : as terms, e.g., f(0,1)=2\n"
" tex : formatted for LaTeX\n"
" xml : XML\n\n";
enum {PORTABLE, PORTABLE2, TABULAR, RAW, COOKED, TEX, XML};
/*************
*
* circ()
*
*************/
static
BOOL circ(char *b, int n, int j, char *str)
{
int i;
for (i = 0; i < n; i++, j++) {
if (b[j % n] != str[i])
return FALSE;
}
return TRUE;
} /* circ */
/*************
*
* read_to_string()
*
*************/
/* DOCUMENTATION
*/
/* PUBLIC */
int read_to_string(FILE *fp, char *str)
{
int n = strlen(str);
char *b = calloc(n, 1);
BOOL found = FALSE;
int i = 0;
int c;
c = getc(fp);
while (c != EOF && !found) {
b[i % n] = c;
i++;
found = circ(b, n, i, str);
if (!found)
c = getc(fp);
}
free(b);
return c;
} /* read_to_string */
int main(int argc, char **argv)
{
int type, rc;
if (string_member("help", argv, argc) ||
string_member("-help", argv, argc)) {
printf("\n%s, version %s, %s\n",PROGRAM_NAME,PROGRAM_VERSION,PROGRAM_DATE);
printf("%s", Help_string);
exit(1);
}
else if (string_member("portable", argv, argc))
type = PORTABLE;
else if (string_member("portable2", argv, argc))
type = PORTABLE2;
else if (string_member("tabular", argv, argc))
type = TABULAR;
else if (string_member("raw", argv, argc))
type = RAW;
else if (string_member("cooked", argv, argc))
type = COOKED;
else if (string_member("tex", argv, argc))
type = TEX;
else if (string_member("xml", argv, argc))
type = XML;
else {
printf("%s", Help_string);
exit(1);
}
init_standard_ladr();
if (type == XML) {
printf("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n");
printf("\n<!DOCTYPE interps SYSTEM \"interp.dtd\">\n");
printf("\n<?xml-stylesheet type=\"text/xsl\" href=\"interp.xsl\"?>\n");
printf("\n<interps>\n");
}
rc = read_to_string(stdin, "interpretation(");
while (rc != EOF) {
/* ok, we have an interpretation */
Term t, interp;
Interp a;
int n;
rc = scanf("%d", &n); /* get domain size */
rc = read_to_string(stdin, ","); /* get past comma */
ungetc('(', stdin); /* so that we can read a complete term */
t = read_term(stdin, stderr);
interp = build_binary_term(str_to_sn("interpretation", 2),
nat_to_term(n),
t);
a = compile_interp(interp, TRUE);
if (type == PORTABLE)
fprint_interp(stdout, a);
else if (type == PORTABLE2)
fprint_interp_2(stdout, a);
else if (type == TABULAR)
fprint_interp_tabular(stdout, a);
else if (type == COOKED)
fprint_interp_cooked(stdout, a);
else if (type == RAW)
fprint_interp_raw(stdout, a);
else if (type == TEX)
fprint_interp_tex(stdout, a);
else if (type == XML)
fprint_interp_xml(stdout, a);
zap_interp(a);
zap_term(interp);
rc = read_to_string(stdin, "interpretation(");
}
if (type == XML) {
printf("\n</interps>\n");
}
exit(0);
} /* main */
|