error handling + cosmetic

This commit is contained in:
tTh 2024-07-31 22:24:32 +02:00
parent 5b2320b421
commit 7e09d1b490

View File

@ -141,8 +141,7 @@ fprintf(stderr, "%s -> %s : %dx%d, rgb %d,%d,%d\n", __func__, fname, w, h,
r, g, b);
#endif
if (w < 1 || h < 1)
{
if (w < 1 || h < 1) {
fprintf(stderr, "%s : img dims %d %d ?\n", __func__, w, h);
return 666;
}
@ -168,8 +167,7 @@ Image_Desc *src;
fprintf(stderr, "timestamping '%s' to '%s' with '%s'\n", fnin, fnout, txt);
#endif
if ( (src=Image_TGA_alloc_load(fnin)) == NULL )
{
if ( (src=Image_TGA_alloc_load(fnin)) == NULL ) {
fprintf(stderr, "tga_tools, load of '%s' failed in %s\n",
fnin, __func__);
exit(5);
@ -207,15 +205,23 @@ if (must_be_verbose()) {
__func__, fnin, fnout, txt, flag);
}
if ( (src=Image_TGA_alloc_load(fnin)) == NULL )
{
if ( (src=Image_TGA_alloc_load(fnin)) == NULL ) {
fprintf(stderr, "tga_tools, load of '%s' failed in %s\n",
fnin, __func__);
exit(5);
}
foo = Image_txt1_box_0(src, txt, posx, posy, 4, &pap, &ink, 0);
Image_TGA_save(fnout, src, 0);
if (foo) {
fprintf(stderr, "err txt1_box_0 = %d\n", foo);
return foo;
}
foo = Image_TGA_save(fnout, src, 0);
if (foo) {
fprintf(stderr, "%s: err TGA save = %d\n", __func__, foo);
return foo;
}
#if DEBUG_LEVEL
fprintf(stderr, "%s : saving %s\n", __func__, fnout);
@ -234,21 +240,18 @@ if (flags) {
fprintf(stderr, "in %s, flags must be 0\n", __func__);
}
if ( (src=Image_TGA_alloc_load(filename)) == NULL )
{
if ( (src=Image_TGA_alloc_load(filename)) == NULL ) {
fprintf(stderr, "tga_tools, chargement '%s' failed\n", filename);
exit(5);
}
foo = Image_histo_RGB(src, hr, hb, hg);
if (foo)
{
if (foo) {
fprintf(stderr, "tga_tools, calcul histogramme: %d %s\n",
foo, Image_err2str(foo));
exit(5);
}
for (foo=0; foo<256; foo++)
{
for (foo=0; foo<256; foo++) {
printf("%3d %8ld %8ld %8ld\n", foo, hr[foo], hg[foo], hb[foo]);
}
@ -260,15 +263,13 @@ int print_environ(void)
{
int foo;
char *ptr;
char *noms[] =
{
char *noms[] = {
NOM_VAR_ENV_VERBOSE, NOM_VAR_ENV_TIMING, "LIBIMAGE_PATH",
"TTH_CONF_DIR", "LIBIMAGE_DEBUG", "BITMAP_FONTS",
"FIXED_SEED", ENV_DEFAULT_RGBA
};
for (foo=0; foo<(int)(sizeof(noms)/sizeof(char *)); foo++)
{
for (foo=0; foo<(int)(sizeof(noms)/sizeof(char *)); foo++) {
ptr = getenv(noms[foo]);
printf("%5d %-25s %s\n", foo, noms[foo], ptr);
}
@ -286,8 +287,7 @@ char buffer[100];
fprintf(stderr, "%s:%s %s %d\n", __FILE__, __func__, fname, value);
#endif
if ( (src=Image_TGA_alloc_load(fname)) == NULL )
{
if ( (src=Image_TGA_alloc_load(fname)) == NULL ) {
fprintf(stderr, "tga_tools, load of '%s' failed in %s\n",
fname, __func__);
exit(5);
@ -339,16 +339,14 @@ foo = set_new_seed(42);
fprintf(stderr, "!!! set new seed -> %d\n", foo);
#endif
if (1 == argc)
{
if (1 == argc) {
fprintf(stderr, "* tga_tools v 0.1.33 (%s) *\n", __DATE__);
fprintf(stderr, "usage:\n\t%s action f.tga [params]\n", argv[0]);
liste_mots_clefs(commandes, 42);
exit(0);
}
if (-1 == (idx=cherche_mot_clef(argv[1], commandes, &mode, &nbarg)) )
{
if (-1 == (idx=cherche_mot_clef(argv[1], commandes, &mode, &nbarg)) ) {
fprintf(stderr, "action '%s' inconnue.\n", argv[1]);
exit(1);
}
@ -452,7 +450,7 @@ switch(mode)
}
if (foo) {
fprintf(stderr, "*** at end of %s, foo was %d\n", __func__, foo);
/* fprintf(stderr, "*** at end of %s, foo was %d\n", __func__, foo); */
}
return 0;
}