diff --git a/Paramakes.mk b/Paramakes.mk index cd3d06e..818858a 100644 --- a/Paramakes.mk +++ b/Paramakes.mk @@ -34,3 +34,7 @@ RANLIB=wc -c # modify it 'as you like' AR=ar + +# +# and valgrind is your friend +# \ No newline at end of file diff --git a/Tests/.gitignore b/Tests/.gitignore new file mode 100644 index 0000000..7dd3c91 --- /dev/null +++ b/Tests/.gitignore @@ -0,0 +1,5 @@ + +a.scratch + +*.tga + diff --git a/Tests/essai_genplot2.sh b/Tests/essai_genplot2.sh new file mode 100755 index 0000000..8220637 --- /dev/null +++ b/Tests/essai_genplot2.sh @@ -0,0 +1,15 @@ +#!/bin/bash + + +echo "------------------------------------------" +echo "GO" | ./mk_dessin.awk > a.scratch +wc a.scratch + +echo "------------------------------------------" +../Tools/genplot2 -s 640x480 +errcode=$? +echo "code retour genplot2 = " $errcode +echo "------------------------------------------" + +echo "------------------------------------------" + diff --git a/Tests/mk_dessin.awk b/Tests/mk_dessin.awk new file mode 100755 index 0000000..9792740 --- /dev/null +++ b/Tests/mk_dessin.awk @@ -0,0 +1,27 @@ +#!/usr/bin/awk -f + +# ce joli programme fabrique un fichier de donnees qui sera +# utile au bon deroulement de 'essai_genplot2.sh' + +BEGIN { nbretraits = 20000 } + +END { + for (trait=0; trait rand()) + { + posx += rand() + posy += rand() + print posx, posy, 1 + } + else + { + posx -= rand() + posy -= rand() + print posx, posy, 2 + } + } + } + +# job done + diff --git a/Tools/.gitignore b/Tools/.gitignore new file mode 100644 index 0000000..a9f7543 --- /dev/null +++ b/Tools/.gitignore @@ -0,0 +1,4 @@ + +*.tga +*.scratch + diff --git a/Tools/fonctions.c b/Tools/fonctions.c index 51ab5ab..c926663 100644 --- a/Tools/fonctions.c +++ b/Tools/fonctions.c @@ -13,12 +13,14 @@ /* non portable but useful function */ char *strdup(const char *s); +#define DEBUG_LEVEL 1 + #define IN_FONCTION #include "tga_outils.h" /*::------------------------------------------------------------------::*/ -int -cherche_mot_clef(char *mot, mot_clef *liste, int *pmode, int *pnbarg) + +int cherche_mot_clef(char *mot, mot_clef *liste, int *pmode, int *pnbarg) { int idx = 0; @@ -48,8 +50,7 @@ fprintf(stderr, "%s : %s not found\n", __func__, mot); return -1; } /*::------------------------------------------------------------------::*/ -int -liste_mots_clefs(mot_clef *liste, int flag) +int liste_mots_clefs(mot_clef *liste, int flag) { mot_clef *pmc; @@ -79,7 +80,7 @@ return 0; /*::------------------------------------------------------------------::*/ /* * INPUT str string to scan for an integer - * pval pointer to the retrun value + * pval pointer to the return value * k * not used * * * OUTPUT 1 successfuly make a conversion @@ -104,6 +105,31 @@ fprintf(stderr, "%s: %s: '%s' -> %ld -> %d\n", return 1; } +/*::------------------------------------------------------------------::*/ +/* Thu 17 Nov 2022 + * input str a string like '640x480' + * pw, ph pointers to result + * + * output 0 on ok, INVALID_PARAM on error + */ +int parse_size_param(char *str, int *pw, int *ph) +{ +int tw, th, foo; + +#if DEBUG_LEVEL +fprintf(stderr, ">>> %s ( '%s' %p %p )\n", __func__, + str, pw, ph); +#endif + +foo = sscanf(str, "%dx%d", &tw, &th); +if (2 != foo) { + fprintf(stderr, "%s: fail %d on '%s'\n", __func__, foo, str); + return INVALID_PARAM; + } +/* fprintf(stderr, " %d %d\n", tw, th); */ +*pw = tw; *ph = th; +return 0; +} /*::------------------------------------------------------------------::*/ /* input: str string to scan for four csv int prect rectangle struct who need datas @@ -149,14 +175,15 @@ while (NULL != cptr) { idx++; } +free(cptr); + return 0; } /*::------------------------------------------------------------------::*/ static Param params[NB_PARAMS]; -int -parse_parametres(int argc, char *argv[], char *types, int prem) +int parse_parametres(int argc, char *argv[], char *types, int prem) { int foo, idxt; int entier; @@ -363,11 +390,11 @@ return params[rang].p.i; } /*::------------------------------------------------------------------::*/ -int -must_be_verbose(void) +static int verboselevel; + +int must_be_verbose(void) { char *envvar; - envvar = getenv(NOM_VAR_ENV_VERBOSE); if ((envvar!=NULL) && !strcmp(envvar, "yes")) { @@ -378,9 +405,24 @@ if ((envvar!=NULL) && !strcmp(envvar, "yes")) } return 0; } + +/* new Fri 18 Nov 2022 11:48:06 PM CET */ + +int set_verbosity(int level) +{ +int tmplevel; + +tmplevel = verboselevel; +verboselevel = level; + +return tmplevel; +} +int get_verbosity(void) +{ +return verboselevel; +} /*::------------------------------------------------------------------::*/ -int -dump_command_line(int argc, char *argv[], int force) +int dump_command_line(int argc, char *argv[], int force) { char *envvar; int flag=0, foo; diff --git a/Tools/genplot2.c b/Tools/genplot2.c index f052b7c..e63667b 100644 --- a/Tools/genplot2.c +++ b/Tools/genplot2.c @@ -6,6 +6,8 @@ #include #include +#include +#include #include "tga_outils.h" @@ -63,7 +65,7 @@ RGBA rgba; int idx; #if DEBUG_LEVEL -fprintf(stderr, "\tDRAW %5d %5d to %5d %5d\n", curX, curY, x, y); +fprintf(stderr, "\tdraw %5d %5d to %5d %5d\n", curX, curY, x, y); #endif idx = color % 8; @@ -88,28 +90,60 @@ Image_TGA_save(filename, image, 0); return 0; } /*::------------------------------------------------------------------::*/ +void help_me(char *proggy) +{ +fprintf(stderr, "%s build %s %s\n", proggy, __DATE__, __TIME__); + +puts("options:"); +puts("\t-v\t\tdo some blablage"); +puts("\t-s WxH\t\tset image size"); +} +/*::------------------------------------------------------------------::*/ int main(int argc, char *argv[]) { char *filename, *image; FILE *fp; +int outw, outh; /* size of output pic */ double x, y, xmin, ymin, xmax, ymax; double fx, fy, f, X, Y; double xC, yC, XC, YC, c1, c2; +int v, nbp, opt, foo; -int v, nbp; +/* setting some default values */ + +outw = XMAX; outh = YMAX; +filename = "a.scratch"; image = "image.tga"; /*---------- processing command line arguments */ -if (argc<=1) filename = "a.scratch"; -else filename = argv[1]; +while ((opt = getopt(argc, argv, "hs:v")) != -1) { + switch (opt) { + case 'h': + help_me(argv[0]); + exit(0); + case 's': /* size of output pic */ + foo = parse_size_param(optarg, &outw, &outh); + break; + case 'v': + break; + default: + fprintf(stderr, "invalid opt %d\n", opt); + exit(1); + break; + } + } +if (argc<=optind) filename = "a.scratch"; +else filename = argv[optind]; -if (argc<=2) image = "image.tga"; -else image = argv[2]; +if (argc<=optind+1) image = "image.tga"; +else image = argv[optind+1]; +fprintf(stderr, "argc %d optind %d file '%s' image '%s'\n", + argc, optind, filename, image); /*----------- giving to the yuser some useless informations --- */ #if DEBUG_LEVEL -fprintf(stderr, "*** Genplot2 v 1.0.8 (dwtfywl) 1995,2010,2022 TontonTh \n"); -fprintf(stderr, "hardcoded picsize : %d %d\n", XMAX, YMAX); +fprintf(stderr, "*** Genplot2 v 1.0.9 (dwtfywl) 1995,2010,2022 TontonTh \n"); +fprintf(stderr, " picsize : %d %d\n", outw, outh); #endif /*----------- opening input file and getting MIN and MAX values */ @@ -137,20 +171,26 @@ if (nbp == 0) fprintf(stderr, "omg, I'v found _ZERO_ points for plotting...\n"); exit(2); } +if (nbp == 1) + { + fprintf(stderr, "omg, I can't do any job with only one point.\n"); + exit(2); + } + fprintf(stderr, "Genplot2: found %d points\n", nbp); /*---------- computing coefficients (temporary hack !-) */ -fx = (XMAX-XMIN-1)/(xmax-xmin); -fy = (YMAX-YMIN-1)/(ymax-ymin); +fx = (outw-XMIN-1)/(xmax-xmin); +fy = (outh-YMIN-1)/(ymax-ymin); #if DEBUG_LEVEL fprintf(stderr, "fc = %12f fy = %12f\n", fx, fy); #endif f = (fx