From 5b6095f0bc0c7fe76793ff1e96127341e225b62f Mon Sep 17 00:00:00 2001 From: Adrien Destugues Date: Sat, 6 May 2017 15:13:50 +0200 Subject: [PATCH] Fix all warnings and enable -Werror mostly unused variables and broken indentation. --- src/Makefile | 2 +- src/brush.c | 27 +++++---------------------- src/buttons_effects.c | 10 ---------- src/factory.c | 8 +++----- src/fileformats.c | 7 +++---- src/libraw2crtc.c | 5 ----- src/loadsave.c | 20 ++++++++++++++++++++ src/miscfileformats.c | 22 +++------------------- src/mountlist.c | 2 ++ src/operatio.c | 32 +++++++++++++------------------- src/pages.c | 3 --- src/readini.c | 4 +++- src/realpath.c | 3 +++ src/windows.c | 6 ------ 14 files changed, 56 insertions(+), 95 deletions(-) diff --git a/src/Makefile b/src/Makefile index a035e103..6e531b9d 100644 --- a/src/Makefile +++ b/src/Makefile @@ -382,7 +382,7 @@ endif # Compiles a regular linux executable for the native platform BIN = ../bin/grafx2 - COPT = -W -Wall -Wdeclaration-after-statement -std=c99 -c -g $(shell sdl-config --cflags) $(TTFCOPT) $(LUACOPT) $(JOYCOPT) -O$(OPTIM) + COPT = -W -Wall -Wdeclaration-after-statement -Werror -std=c99 -c -g $(shell sdl-config --cflags) $(TTFCOPT) $(LUACOPT) $(JOYCOPT) -O$(OPTIM) COPT += $(shell pkg-config --cflags libpng) ifneq ($(PLATFORM), FreeBSD) diff --git a/src/brush.c b/src/brush.c index 4acd5284..cc270640 100644 --- a/src/brush.c +++ b/src/brush.c @@ -115,10 +115,6 @@ void Display_paintbrush(short x,short y,byte color) // de laquelle on affiche la brosse/pinceau short start_y_counter; // Position Y (dans la brosse/pinceau) à partir // de laquelle on affiche la brosse/pinceau - short end_counter_x; // Position X ou s'arrête l'affichade de la - // brosse/pinceau - short end_counter_y; // Position Y ou s'arrête l'affichade de la - // brosse/pinceau byte * temp; if (Mouse_K) // pas de curseur si on est en preview et @@ -156,8 +152,6 @@ void Display_paintbrush(short x,short y,byte color) break; start_x_counter=start_x-(x-Brush_offset_X); start_y_counter=start_y-(y-Brush_offset_Y); - end_counter_x=start_x_counter+width; - end_counter_y=start_y_counter+height; if (Paintbrush_shape==PAINTBRUSH_SHAPE_COLOR_BRUSH) Display_brush_color( start_x-Main_offset_X, @@ -220,8 +214,6 @@ void Display_paintbrush(short x,short y,byte color) Compute_clipped_dimensions(&start_x,&start_y,&width,&height); start_x_counter=start_x-(x-Paintbrush_offset_X); start_y_counter=start_y-(y-Paintbrush_offset_Y); - end_counter_x=start_x_counter+width; - end_counter_y=start_y_counter+height; temp=Brush; Brush=Paintbrush_sprite; @@ -430,6 +422,7 @@ void Draw_paintbrush(short x,short y,byte color) counter_y < end_counter_y; y_pos++, counter_y++ ) + { for (x_pos = start_x, counter_x = start_x_counter; counter_x < end_counter_x; x_pos++, counter_x++ @@ -445,8 +438,9 @@ void Draw_paintbrush(short x,short y,byte color) Display_pixel(x_pos,y_pos,Smear_brush[position]); Smear_brush[position]=temp_color; } + } - Update_part_of_screen(start_x,start_y,width,height); + Update_part_of_screen(start_x,start_y,width,height); } Smear_min_X=start_x_counter; @@ -580,7 +574,7 @@ void Draw_paintbrush(short x,short y,byte color) Display_pixel(x_pos,y_pos,Smear_brush[position]); Smear_brush[position]=temp_color; } - Update_part_of_screen(start_x, start_y, width, height); + Update_part_of_screen(start_x, start_y, width, height); } @@ -711,8 +705,6 @@ void Hide_paintbrush(short x,short y) //short counter_x; // Position X (dans la brosse/pinceau) en cours //d'affichage //short counter_y; // Position Y (dans la brosse/pinceau) en cours d'affichage - short end_counter_x; // Position X ou s'arrête l'affichage de la brosse/pinceau - short end_counter_y; // Position Y ou s'arrête l'affichage de la brosse/pinceau byte * temp; if (Mouse_K == 0) @@ -737,8 +729,6 @@ void Hide_paintbrush(short x,short y) Compute_clipped_dimensions(&start_x,&start_y,&width,&height); start_x_counter=start_x-(x-Brush_offset_X); start_y_counter=start_y-(y-Brush_offset_Y); - end_counter_x=start_x_counter+width; - end_counter_y=start_y_counter+height; if ( (width>0) && (height>0) ) Clear_brush(start_x-Main_offset_X, @@ -778,8 +768,6 @@ void Hide_paintbrush(short x,short y) Compute_clipped_dimensions(&start_x,&start_y,&width,&height); start_x_counter=start_x-(x-Paintbrush_offset_X); start_y_counter=start_y-(y-Paintbrush_offset_Y); - end_counter_x=start_x_counter+width; - end_counter_y=start_y_counter+height; temp=Brush; Brush=Paintbrush_sprite; @@ -1318,19 +1306,16 @@ void Stretch_brush(short x1, short y1, short x2, short y2) byte * new_brush; int new_brush_width; // Width de la nouvelle brosse int new_brush_height; // Height de la nouvelle brosse - int x_flipped, y_flipped; // Compute new brush dimensions if ((new_brush_width=x1-x2)<0) { - x_flipped=1; new_brush_width=-new_brush_width; } new_brush_width++; if ((new_brush_height=y1-y2)<0) { - y_flipped=1; new_brush_height=-new_brush_height; } new_brush_height++; @@ -2023,15 +2008,13 @@ void Draw_quad_texture_preview(byte *texture, int texture_width, int x3,int y3,int xt3,int yt3, int x4,int y4,int xt4,int yt4) { - int x_min,x_max,y_min,y_max; + int y_min,y_max; int x,y,xt,yt; int y_,y_min_; int start_x,end_x,width,height; float temp; byte color; - x_min=Min(Min(x1,x2),Min(x3,x4)); - x_max=Max(Max(x1,x2),Max(x3,x4)); y_min=Min(Min(y1,y2),Min(y3,y4)); y_max=Max(Max(y1,y2),Max(y3,y4)); height=1+y_max-y_min; diff --git a/src/buttons_effects.c b/src/buttons_effects.c index 4beffb07..b9d6fab4 100644 --- a/src/buttons_effects.c +++ b/src/buttons_effects.c @@ -1036,21 +1036,11 @@ void Button_Sieve_menu(void) short old_sieve_width=Sieve_width; short old_sieve_height=Sieve_height; byte old_sieve[16][16]; - short preview_x_start; // | Données précalculées - short preview_y_start; // |_ pour la preview - short preview_x_end; // | => plus grande - short preview_y_end; // | rapidité. - memcpy(old_sieve,Sieve,256); Open_window(290,179,"Sieve"); - preview_x_start=Window_pos_X+(Menu_factor_X*230); - preview_y_start=Window_pos_Y+(Menu_factor_Y*78); - preview_x_end=preview_x_start+(Menu_factor_X*51); - preview_y_end=preview_y_start+(Menu_factor_Y*71); - Window_display_frame ( 7, 65,130,43); Window_display_frame ( 7,110,130,43); Window_display_frame_in(142, 68, 82,82); diff --git a/src/factory.c b/src/factory.c index 2f52c1f0..f3aea685 100644 --- a/src/factory.c +++ b/src/factory.c @@ -1723,7 +1723,6 @@ int L_WindowReadline(lua_State* L) int L_WindowPrint(lua_State* L) { int x, y, fg=0, bg=2; - int len; int colors[4] = {MC_Black, MC_Dark, MC_Light, MC_White}; const char *text=""; int nb_args = lua_gettop(L); @@ -1749,7 +1748,7 @@ int L_WindowPrint(lua_State* L) Hide_cursor(); Cursor_is_visible=0; } - len=strlen(text); + Print_in_window_limited(x, y, text, (Window_width-x)/8,colors[fg], colors[bg]); Window_needs_update=1; @@ -1760,7 +1759,6 @@ int L_WindowSlider(lua_State* L) { word x, y, height, nb_elements, nb_elements_visible, initial_position; int horizontal; - T_Scroller_button *button; int nb_args = lua_gettop(L); LUA_ARG_LIMIT (7, "windowslider"); @@ -1790,9 +1788,9 @@ int L_WindowSlider(lua_State* L) Cursor_is_visible=0; } if (horizontal) - button = Window_set_horizontal_scroller_button(x, y, height+24, nb_elements, nb_elements_visible, initial_position); + Window_set_horizontal_scroller_button(x, y, height+24, nb_elements, nb_elements_visible, initial_position); else - button = Window_set_scroller_button(x, y, height+24, nb_elements, nb_elements_visible, initial_position); + Window_set_scroller_button(x, y, height+24, nb_elements, nb_elements_visible, initial_position); Window_needs_update=1; diff --git a/src/fileformats.c b/src/fileformats.c index 6b104e64..410dc4e0 100644 --- a/src/fileformats.c +++ b/src/fileformats.c @@ -105,7 +105,6 @@ void Load_IMG(T_IO_Context * context) byte * buffer; FILE *file; word x_pos,y_pos; - long width_read; long file_size; T_IMG_Header IMG_header; @@ -133,7 +132,6 @@ void Load_IMG(T_IO_Context * context) context->Width=IMG_header.Width; context->Height=IMG_header.Height; - width_read=IMG_header.Width; for (y_pos=0;(y_posHeight) && (!File_error);y_pos++) { @@ -589,7 +587,6 @@ void Load_IFF(T_IO_Context * context) byte color; long file_size; dword dummy; - byte is_anim=0; int iff_format; int plane; @@ -608,7 +605,6 @@ void Load_IFF(T_IO_Context * context) Read_bytes(IFF_file,format,4); if (!memcmp(format,"ANIM",4)) { - is_anim=1; // Skip a bit, brother Read_bytes(IFF_file,section,4); Read_dword_be(IFF_file,&dummy); @@ -4227,6 +4223,9 @@ void Load_PNG(T_IO_Context * context) png_read_image(png_ptr, Row_pointers); break; + case CONTEXT_PALETTE: + // No pixels to draw in a palette! + break; } } } diff --git a/src/libraw2crtc.c b/src/libraw2crtc.c index 42de562b..eb8f697f 100644 --- a/src/libraw2crtc.c +++ b/src/libraw2crtc.c @@ -66,7 +66,6 @@ unsigned char *raw2crtc(T_IO_Context *context, unsigned char mode, unsigned char unsigned char minAddrIsDefined = 0; unsigned short maxAddr = 0; - unsigned char nbPixPerByte; int y,x; unsigned char r6; unsigned short i; @@ -85,28 +84,24 @@ unsigned char *raw2crtc(T_IO_Context *context, unsigned char mode, unsigned char case 0: { *r1 = (width+3)/4; - nbPixPerByte = 2; ptrMode = mode0interlace; break; } case 1: { *r1 = (width+7)/8; - nbPixPerByte = 4; ptrMode = mode1interlace; break; } case 2: { *r1 = (width+15)/16; - nbPixPerByte = 8; ptrMode = mode2interlace; break; } case 3: { *r1 = (width+3)/4; - nbPixPerByte = 2; ptrMode = mode3interlace; break; } diff --git a/src/loadsave.c b/src/loadsave.c index 8cb98820..cfba817b 100644 --- a/src/loadsave.c +++ b/src/loadsave.c @@ -322,6 +322,10 @@ void Set_pixel_24b(T_IO_Context *context, short x_pos, short y_pos, byte r, byte context->Preview_bitmap[x_pos/context->Preview_factor_X + (y_pos/context->Preview_factor_Y)*PREVIEW_WIDTH*Menu_factor_X]=color; } break; + + case CONTEXT_PALETTE: + // In a palette, there are no pixels! + break; } } @@ -514,6 +518,10 @@ void Pre_load(T_IO_Context *context, short width, short height, long file_size, //context->Pitch = context->Surface->pitch; //context->Target_address = context->Surface->pixels; break; + + case CONTEXT_PALETTE: + // In a palette, there are no pixels! + break; } if (File_error) @@ -546,6 +554,10 @@ void Pre_load(T_IO_Context *context, short width, short height, long file_size, // Load palette Set_palette_fake_24b(context->Palette); break; + + case CONTEXT_PALETTE: + // In a palette, there are no pixels! + break; } } } @@ -695,6 +707,10 @@ void Load_image(T_IO_Context *context) File_error=1; break; + + case CONTEXT_PALETTE: + // In a palette, there are no pixels! + break; } } free(context->Buffer_image_24b); @@ -1031,6 +1047,10 @@ void Save_image(T_IO_Context *context) case CONTEXT_SURFACE: break; + + case CONTEXT_PALETTE: + // In a palette, there are no pixels! + break; } format = Get_fileformat(context->Format); diff --git a/src/miscfileformats.c b/src/miscfileformats.c index 8a32c11b..5a0d123b 100644 --- a/src/miscfileformats.c +++ b/src/miscfileformats.c @@ -143,7 +143,6 @@ void Load_GPL(T_IO_Context * context) { FILE *file; char filename[MAX_PATH_CHARACTERS]; // full filename - long file_size; long pos; Get_full_filename(filename, context->File_name, context->File_directory); @@ -153,7 +152,6 @@ void Load_GPL(T_IO_Context * context) if ((file=fopen(filename, "rb"))) { fread(filename, 1, 13, file); - file_size = File_length_file(file); if (strncmp(filename,"GIMP Palette\n",13) == 0) { int i, j, r, g, b, columns, chars_read; @@ -2923,15 +2921,11 @@ int Save_C64_multi(T_IO_Context *context, char *filename, byte saveWhat, byte lo // the stack has a rather small size... byte bitmap[8000],screen_ram[1000],color_ram[1000]; - word numcolors,count; + word numcolors; dword cusage[256]; byte i,background=0; FILE *file; - numcolors=Count_used_colors(cusage); - - count=0; - // Detect the ackground color the image should be using. It's the one that's // used on all tiles having 4 colors. for(y=0;y<200;y=y+8) @@ -3151,19 +3145,9 @@ void Save_C64(T_IO_Context * context) { char filename[MAX_PATH_CHARACTERS]; static byte saveWhat=0, loadAddr=0; - dword numcolors,cusage[256]; - numcolors=Count_used_colors(cusage); Get_full_filename(filename, context->File_name, context->File_directory); - /* - if (numcolors>16) - { - Warning_message("Error: Max 16 colors"); - File_error = 1; - return; - } - */ if (((context->Width!=320) && (context->Width!=160)) || context->Height!=200) { Warning_message("must be 320x200 or 160x200"); @@ -3176,7 +3160,6 @@ void Save_C64(T_IO_Context * context) File_error = 1; return; } - //printf("saveWhat=%d, loadAddr=%d\n",saveWhat,loadAddr); if (strcasecmp(filename + strlen(filename) - 4, ".fli") == 0) { @@ -3558,7 +3541,7 @@ void Save_CM5(T_IO_Context* context) void Test_PPH(T_IO_Context * context) { FILE *file; - unsigned char buffer[MAX_PATH_CHARACTERS]; + char buffer[MAX_PATH_CHARACTERS]; long file_size; int w; int expected; @@ -3908,6 +3891,7 @@ void Load_PPH(T_IO_Context* context) void Save_PPH(T_IO_Context* context) { + (void)context; // unused // TODO // Detect mode diff --git a/src/mountlist.c b/src/mountlist.c index 9bc405aa..d1f8abdf 100644 --- a/src/mountlist.c +++ b/src/mountlist.c @@ -47,7 +47,9 @@ #define MOUNTED_GETMNTENT1 #endif +#ifndef _XOPEN_SOURCE #define _XOPEN_SOURCE 500 +#endif // --- END GRAFX2 CUSTOM CONFIG --- #include "mountlist.h" diff --git a/src/operatio.c b/src/operatio.c index f986bcff..992ed6e2 100644 --- a/src/operatio.c +++ b/src/operatio.c @@ -2892,19 +2892,18 @@ void Scroll_0_5(void) Operation_pop(¢er_x); if (side == RIGHT_SIDE) - { - // All layers at once - if (x_pos>=center_x) - x_offset=(x_pos-center_x)%Main_image_width; - else - x_offset=Main_image_width-((center_x-x_pos)%Main_image_width); - - if (y_pos>=center_y) - y_offset=(y_pos-center_y)%Main_image_height; - else - y_offset=Main_image_height-((center_y-y_pos)%Main_image_height); - - + { + // All layers at once + if (x_pos>=center_x) + x_offset=(x_pos-center_x)%Main_image_width; + else + x_offset=Main_image_width-((center_x-x_pos)%Main_image_width); + + if (y_pos>=center_y) + y_offset=(y_pos-center_y)%Main_image_height; + else + y_offset=Main_image_height-((center_y-y_pos)%Main_image_height); + // Do the actual scroll operation on all layers. for (i=0; iPages->Nb_layers; i++) //if ((1< Main_image_width // Rectangle at right of picture || start_y > Main_image_height // Rectangle below picture diff --git a/src/pages.c b/src/pages.c index e8104bd2..ba24f9ff 100644 --- a/src/pages.c +++ b/src/pages.c @@ -1445,11 +1445,8 @@ byte Add_layer(T_List_of_pages *list, int layer) /// Delete a layer from the latest page of a list. Returns 0 on success. byte Delete_layer(T_List_of_pages *list, int layer) { - T_Page * page; int i; - page = list->Pages; - // Keep the position reasonable if (layer >= list->Pages->Nb_layers) layer = list->Pages->Nb_layers - 1; diff --git a/src/readini.c b/src/readini.c index f5db50cc..8a6ba2cf 100644 --- a/src/readini.c +++ b/src/readini.c @@ -21,7 +21,9 @@ You should have received a copy of the GNU General Public License along with Grafx2; if not, see */ -#define _XOPEN_SOURCE 500 +#ifndef _XOPEN_SOURCE + #define _XOPEN_SOURCE 500 +#endif #include #include diff --git a/src/realpath.c b/src/realpath.c index 88c6e690..b5138f93 100644 --- a/src/realpath.c +++ b/src/realpath.c @@ -1,6 +1,9 @@ /* vim:expandtab:ts=2 sw=2: */ +#ifndef _XOPEN_SOURCE #define _XOPEN_SOURCE 500 +#endif + #include #include #include diff --git a/src/windows.c b/src/windows.c index d8535585..eebc15e5 100644 --- a/src/windows.c +++ b/src/windows.c @@ -1391,8 +1391,6 @@ void Display_menu_palette_avoiding_window(byte * table) word height; word corner_x=Window_pos_X+Window_width*Menu_factor_X; // |_ Coin bas-droit word corner_y=Window_pos_Y+Window_height*Menu_factor_Y; // | de la fenêtre +1 - int transparent = -1; - if (Config.Separate_colors) { @@ -1405,10 +1403,6 @@ void Display_menu_palette_avoiding_window(byte * table) height=Menu_factor_Y*((Menu_height-11)/Menu_cells_Y); } - if (Main_backups->Pages->Image_mode == 0 && Main_backups->Pages->Nb_layers > 1) - transparent = Main_backups->Pages->Transparent_color; - - for (color=0,real_color=First_color_in_palette;color