39 printf(
"Simple expression evalutor, please *don't* turn me to a feature-complete language interpreter\n");
40 printf(
"usage: ffeval [OPTIONS]\n");
43 "-e echo each input line on output\n"
44 "-h print this help\n"
45 "-i INFILE set INFILE as input file, stdin if omitted\n"
46 "-o OUTFILE set OUTFILE as output file, stdout if omitted\n"
47 "-p PROMPT set output prompt\n");
50 #define MAX_BLOCK_SIZE SIZE_MAX
52 int main(
int argc,
char **argv)
54 size_t buf_size = 256;
56 const char *outfilename =
NULL, *infilename =
NULL;
58 const char *prompt =
"=> ";
59 int count = 0, echo = 0;
64 while ((c =
getopt(argc, argv,
"ehi:o:p:")) != -1) {
86 if (!infilename || !strcmp(infilename,
"-")) {
90 infile = fopen(infilename,
"r");
93 fprintf(stderr,
"Impossible to open input file '%s': %s\n", infilename, strerror(errno));
97 if (!outfilename || !strcmp(outfilename,
"-")) {
98 outfilename =
"stdout";
101 outfile = fopen(outfilename,
"w");
104 fprintf(stderr,
"Impossible to open output file '%s': %s\n", outfilename, strerror(errno));
108 while ((c = fgetc(infile)) != EOF) {
118 fprintf(outfile,
"%s ", buf);
119 fprintf(outfile,
"%s%f\n", prompt, d);
123 if (count >= buf_size-1) {