40 printf(
"Simple expression evalutor, please *don't* turn me to a feature-complete language interpreter\n");
41 printf(
"usage: ffeval [OPTIONS]\n");
44 "-e echo each input line on output\n"
45 "-h print this help\n"
46 "-i INFILE set INFILE as input file, stdin if omitted\n"
47 "-o OUTFILE set OUTFILE as output file, stdout if omitted\n"
48 "-p PROMPT set output prompt\n");
51 int main(
int argc,
char **argv)
55 const char *outfilename = NULL, *infilename = NULL;
56 FILE *
outfile = NULL, *infile = NULL;
57 const char *prompt =
"=> ";
58 int count = 0, echo = 0;
61 #define GROW_ARRAY() \
63 if (!av_dynarray2_add((void **)&buf, &buf_size, 1, NULL)) { \
64 av_log(NULL, AV_LOG_ERROR, \
65 "Memory allocation problem occurred\n"); \
71 while ((c =
getopt(argc, argv,
"ehi:o:p:")) != -1) {
93 if (!infilename || !strcmp(infilename,
"-")) {
97 infile = fopen(infilename,
"r");
100 fprintf(stderr,
"Impossible to open input file '%s': %s\n", infilename, strerror(errno));
104 if (!outfilename || !strcmp(outfilename,
"-")) {
105 outfilename =
"stdout";
108 outfile = fopen(outfilename,
"w");
111 fprintf(stderr,
"Impossible to open output file '%s': %s\n", outfilename, strerror(errno));
115 while ((c = fgetc(infile)) != EOF) {
123 NULL, NULL, NULL, NULL, NULL, 0, NULL);
125 fprintf(outfile,
"%s ", buf);
126 if (ret >= 0) fprintf(outfile,
"%s%f\n", prompt, d);
127 else fprintf(outfile,
"%s%f (%s)\n", prompt, d,
av_err2str(ret));
131 if (count >= buf_size-1)