forked from tTh/FloatImg
82 lines
1.6 KiB
C
82 lines
1.6 KiB
C
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <stdlib.h>
|
|
#include <unistd.h>
|
|
|
|
#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<argc; foo++)
|
|
fprintf(stderr, "%3d %s\n", foo, argv[foo]);
|
|
#endif
|
|
|
|
if (4 != argc-optind) {
|
|
fprintf(stderr, "%s need some arguments...\n", argv[0]);
|
|
exit(1);
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
/* --------------------------------------------------------------------- */
|