From 9f42b813e77d6ee086291f11eb2b50c5ec2db2be Mon Sep 17 00:00:00 2001 From: tth Date: Wed, 11 Sep 2019 07:43:08 +0200 Subject: [PATCH] adding a new tool : fimgops --- .gitignore | 1 + tools/Makefile | 5 ++- tools/fimgops.c | 81 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 86 insertions(+), 1 deletion(-) create mode 100644 tools/fimgops.c diff --git a/.gitignore b/.gitignore index ee64b42..62cfed1 100644 --- a/.gitignore +++ b/.gitignore @@ -36,3 +36,4 @@ tools/png2fimg tools/addtga2fimg tools/addpnm2fimg tools/cumulfimgs +tools/fimgops diff --git a/tools/Makefile b/tools/Makefile index f82872a..9b624e7 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -9,7 +9,7 @@ DEPS = ../floatimg.h ../libfloatimg.a Makefile # ---------- all: fimg2pnm mkfimg png2fimg fimgstats fimg2png \ - addpnm2fimg cumulfimgs + addpnm2fimg cumulfimgs fimgops fimgstats: fimgstats.c $(DEPS) gcc $(COPT) $< ../libfloatimg.a -o $@ @@ -20,6 +20,9 @@ cumulfimgs: cumulfimgs.c $(DEPS) mkfimg: mkfimg.c $(DEPS) gcc $(COPT) $< ../libfloatimg.a -o $@ +fimgops: fimgops.c $(DEPS) + gcc $(COPT) $< ../libfloatimg.a -o $@ + fimg2pnm: fimg2pnm.c $(DEPS) gcc $(COPT) $< ../libfloatimg.a -o $@ diff --git a/tools/fimgops.c b/tools/fimgops.c new file mode 100644 index 0000000..bab7786 --- /dev/null +++ b/tools/fimgops.c @@ -0,0 +1,81 @@ +#include +#include +#include +#include + +#include "../floatimg.h" + +int verbosity; + +/* --------------------------------------------------------------------- */ +#define OP_ADD 1 +#define OP_MUL 2 +typedef struct { + int code; + char *op; + } Opcode; + +Opcode opcodes[] = { + { OP_ADD, "add" }, + { OP_MUL, "mul" }, + { 0, NULL } + }; +static void pr_opcodes(void) +{ +Opcode *optr; +puts("operators:"); +for (optr = opcodes; optr->code; optr++) { + printf("\t%-20s %d\n", optr->op, optr->code); + } +} +static int look_opcodes(char *txt) +{ +Opcode *optr; + +for (optr = opcodes; optr->code; optr++) { + if (!strcmp(txt, optr->op)) { + printf("found %s as %d\n", optr->op, optr->code); + return optr->code; + } + } +return -1; +} +/* --------------------------------------------------------------------- */ +static void help(int lj) +{ + +puts("usage:\n\tfimgops [options] A.fimg B.fimg operator D.fimg"); +pr_opcodes(); +if (verbosity) fimg_print_version(1); +exit(0); +} +/* --------------------------------------------------------------------- */ +int main(int argc, char *argv[]) +{ +int foo, opt; +float fvalue; + +FloatImg fimg; + +while ((opt = getopt(argc, argv, "hk:v")) != -1) { + switch(opt) { + case 'h': help(0); break; + case 'k': fvalue = atof(optarg); break; + case 'v': verbosity++; break; + } + } + +#if DEBUG_LEVEL +fprintf(stderr, "argc %d optind %d\n", argc, optind); +for (foo=0; foo