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;
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) {
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)
memory handling functions
int av_expr_parse_and_eval(double *d, const char *s, const char *const *const_names, const double *const_values, const char *const *func1_names, double(*const *funcs1)(void *, double), const char *const *func2_names, double(*const *funcs2)(void *, double, double), void *opaque, int log_offset, void *log_ctx)
Parse and evaluate an expression.
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
static int getopt(int argc, char *argv[], char *opts)
int main(int argc, char **argv)
simple arithmetic expression evaluator