fst-generate.C
3.03 KB
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
/*******************************************************************/
/* */
/* FILE fst-generate.C */
/* MODULE fst-generate */
/* PROGRAM SFST */
/* AUTHOR Helmut Schmid, IMS, University of Stuttgart */
/* */
/*******************************************************************/
#include "fst.h"
using std::cerr;
bool Upper=false;
bool Lower=false;
/*******************************************************************/
/* */
/* usage */
/* */
/*******************************************************************/
void usage()
{
fprintf(stderr,"Usage: fst-generate [Options] file\n");
fprintf(stderr,"\nOptions:\n");
fprintf(stderr,"\t-s: print the surface characters only\n");
fprintf(stderr,"\t-a: print the analysis characters only\n");
fprintf(stderr,"\t-h: print usage information\n\n");
}
/*******************************************************************/
/* */
/* get_flags */
/* */
/*******************************************************************/
void get_flags( int *argc, char **argv )
{
for( int i=1; i<*argc; i++ ) {
if (strcmp(argv[i],"-s") == 0) {
Upper = true;
argv[i] = NULL;
}
else if (strcmp(argv[i],"-a") == 0) {
Lower = true;
argv[i] = NULL;
}
else if (strcmp(argv[i],"-h") == 0 ||
strcmp(argv[i],"-help") == 0 ||
strcmp(argv[i],"-?") == 0)
{
usage();
exit(0);
}
}
// remove flags from the argument list
int k;
for( int i=k=1; i<*argc; i++)
if (argv[i] != NULL)
argv[k++] = argv[i];
*argc = k;
}
/*******************************************************************/
/* */
/* main */
/* */
/*******************************************************************/
int main( int argc, char **argv )
{
FILE *file;
get_flags(&argc, argv);
if (argc == 1)
file = stdin;
else if ((file = fopen(argv[1],"rb")) == NULL) {
fprintf(stderr,"\nError: Cannot open transducer file %s\n\n", argv[1]);
exit(1);
}
try {
Transducer *a2, a(file);
fclose(file);
if (Upper)
a2 = &a.upper_level().minimise();
else if (Lower)
a2 = &a.lower_level().minimise();
else
a2 = &a;
a2->generate(stdout);
}
catch (const char *p) {
cerr << p << "\n";
return 1;
}
return 0;
}