From 4d017d6e7fa87ffb11f535c6af9c67263e7465a9 Mon Sep 17 00:00:00 2001 From: Adrian Castravete Date: Mon, 12 Feb 2018 17:34:47 +0200 Subject: [PATCH] Use vasprintf for formatted messages --- src/windows.c | 162 +++++++++++++++++++++++++------------------------- 1 file changed, 80 insertions(+), 82 deletions(-) diff --git a/src/windows.c b/src/windows.c index c1cce9f9..5d1934b0 100644 --- a/src/windows.c +++ b/src/windows.c @@ -43,7 +43,7 @@ #include "palette.h" T_Toolbar_button Buttons_Pool[NB_BUTTONS]; -T_Menu_Bar Menu_bars[MENUBAR_COUNT] = +T_Menu_Bar Menu_bars[MENUBAR_COUNT] = {{MENU_WIDTH, 9, 1, 45, {NULL,NULL,NULL}, 20, BUTTON_HIDE }, // Status {MENU_WIDTH, 14, 1, 35, {NULL,NULL,NULL}, 236, BUTTON_ANIM_PLAY }, // Animation {MENU_WIDTH, 10, 1, 35, {NULL,NULL,NULL}, 144, BUTTON_LAYER_SELECT }, // Layers @@ -79,7 +79,7 @@ void Pixel_in_menu(word bar, word x, word y, byte color) void Pixel_in_menu_and_skin(word bar, word x, word y, byte color) { Pixel_in_menu(bar, x, y, color); - Menu_bars[bar].Skin[2][y*Menu_bars[bar].Skin_width + x] = color; + Menu_bars[bar].Skin[2][y*Menu_bars[bar].Skin_width + x] = color; } // Affichage d'un pixel dans la fenêtre (la fenêtre doit être visible) @@ -208,7 +208,7 @@ word Palette_cell_Y(byte index) void Set_fore_color(byte color) { byte old_fore_color = Fore_color; - + Fore_color=color; Reposition_palette(); Display_foreback(); @@ -219,7 +219,7 @@ void Set_fore_color(byte color) void Set_back_color(byte color) { byte old_back_color = Back_color; - + Back_color=color; Display_foreback(); Frame_menu_color(old_back_color); @@ -236,7 +236,7 @@ void Frame_menu_color(byte id) word index; word cell_height=Menu_bars[MENUBAR_TOOLS].Height/Menu_cells_Y; byte color; - + if (! Menu_bars[MENUBAR_TOOLS].Visible) return; @@ -399,7 +399,7 @@ void Reposition_palette(void) cells=Menu_cells_X; else cells=Menu_cells_Y; - + if (Fore_color 16) // can be different from MAX_NB_LAYERS button_number = 16; - + // Enlarge the buttons themselves if there's enough room while (button_number*(button_width+2) < horiz_space && repeats < 20) { repeats+=1; button_width+=2; } - + x_off=Menu_bars[MENUBAR_LAYERS].Skin_width; for (current_button=0; current_button0; i--) { Pixel_in_menu(MENUBAR_LAYERS, x_pos + x_off, y_pos, Gfx->Layer_sprite[sprite_index][current_button][y_pos][source_x]); @@ -564,25 +564,25 @@ void Display_layerbar(void) } // Next line x_pos=0; - } + } // Next button x_off+=button_width; } // Texture any remaining space to the right. // This overwrites any junk like deleted buttons. Draw_bar_remainder(MENUBAR_LAYERS, x_off); - + // Update the active area of the layers pseudo-button Buttons_Pool[BUTTON_LAYER_SELECT].Width = button_number * button_width; - + // Required to determine which layer button is clicked Layer_button_width = button_width; - + // A screen refresh required by some callers Update_rect( - Menu_bars[MENUBAR_LAYERS].Skin_width, - Menu_Y+Menu_bars[MENUBAR_LAYERS].Top*Menu_factor_Y, - horiz_space*Menu_factor_X, + Menu_bars[MENUBAR_LAYERS].Skin_width, + Menu_Y+Menu_bars[MENUBAR_LAYERS].Top*Menu_factor_Y, + horiz_space*Menu_factor_X, Menu_bars[MENUBAR_LAYERS].Height*Menu_factor_Y); } if (Menu_bars[MENUBAR_ANIMATION].Visible) @@ -598,7 +598,7 @@ void Display_layerbar(void) Update_rect( (59)*Menu_factor_X, (Menu_bars[MENUBAR_ANIMATION].Top+3)*Menu_factor_Y+Menu_Y, - 7*8*Menu_factor_X, + 7*8*Menu_factor_X, 8*Menu_factor_Y); } } @@ -636,7 +636,7 @@ void Display_menu(void) // the last two columns Draw_bar_remainder(current_menu, Menu_bars[current_menu].Skin_width); } - + // Next bar } } @@ -714,7 +714,7 @@ void Print_char_in_window(short x_pos,short y_pos,const unsigned char c,byte tex byte *pixel; // Premier pixel du caractère pixel=Menu_font + (c<<6); - + for (y=0;y<8;y++) for (x=0;x<8;x++) Pixel_in_window(x_pos+x, y_pos+y, @@ -799,7 +799,7 @@ void Print_filename(void) // Determine maximum size, in characters max_size = 12 + (Screen_width / Menu_factor_X - 320) / 8; - + // Partial copy of the name { #ifdef ENABLE_FILENAMES_ICONV @@ -1071,7 +1071,7 @@ byte Confirmation_box(char * message) { char * next_eol; char display_string[36+1]; - + next_eol = strchr(c, '\n'); if (next_eol==NULL) // last line current_length = strlen(c); @@ -1086,7 +1086,7 @@ byte Confirmation_box(char * message) display_string[current_length]='\0'; Print_in_window((window_width>>1)-(current_length<<2), 20+(current_line<<3), display_string, MC_Black, MC_Light); - + c += current_length; if (*c == '\n') c++; @@ -1190,18 +1190,16 @@ void Warning_with_format(const char *template, ...) { va_list arg_ptr; char *message; - message = malloc(sizeof(char) * 1024); // a maximum of 1 KiB of complete message. - if (message) { - va_start(arg_ptr, template); - vsprintf(message, template, arg_ptr); - //Warning_message(message); - Verbose_message("Warning", message); - va_end(arg_ptr); - free(message); - } else { + va_start(arg_ptr, template); + if (vasprintf(&message, template, arg_ptr) == -1) { //Warning_message(template); Verbose_message("Warning", template); + } else { + //Warning_message(message); + Verbose_message("Warning", message); + free(message); } + va_end(arg_ptr); } /// Window that shows a big message (up to 35x13), and waits for a click on OK. @@ -1216,9 +1214,9 @@ void Verbose_message(const char *caption, const char * message ) char buffer[36]; byte original_cursor_shape = Cursor_shape; - + Open_window(300,160,caption); - + // Word-wrap the message for (line=0; line < 13 && *message!='\0'; line++) { @@ -1240,10 +1238,10 @@ void Verbose_message(const char *caption, const char * message ) if (message[nb_char]=='\0' || last_space == -1) last_space = nb_char; buffer[last_space]='\0'; - + // Print Print_in_window(10,20+line*8,buffer,MC_Black,MC_Light); - + // Next line message=message+last_space; // Strip at most one carriage return and any leading spaces @@ -1325,7 +1323,7 @@ void Display_paintbrush_in_window(word x,word y,int number) width=Min(Paintbrush[number].Width,PAINTBRUSH_WIDTH); height=Min(Paintbrush[number].Height,PAINTBRUSH_WIDTH); - + origin_x = (x + 8)*Menu_factor_X - (width/2)*x_size+Window_pos_X; origin_y = (y + 8)*Menu_factor_Y - (height/2)*y_size+Window_pos_Y; @@ -1587,7 +1585,7 @@ void Compute_paintbrush_coordinates(void) Paintbrush_X=(((Paintbrush_X+(Snap_width>>1)-Snap_offset_X)/Snap_width)*Snap_width)+Snap_offset_X; Paintbrush_Y=(((Paintbrush_Y+(Snap_height>>1)-Snap_offset_Y)/Snap_height)*Snap_height)+Snap_offset_Y; } - + // Handling the snap axis mode, when shift is pressed. switch (Current_operation) { @@ -1604,7 +1602,7 @@ void Compute_paintbrush_coordinates(void) Snap_axis=1; Snap_axis_origin_X=Paintbrush_X; Snap_axis_origin_Y=Paintbrush_Y; - } + } } if (Snap_axis==1) @@ -1741,8 +1739,8 @@ void Position_screen_according_to_position(int target_x, int target_y) Main.offset_X=0; else if (Main.image_width=0; i--) { - + if (Round_palette_component(palette[i].R)/tolerence==cpc_colors[3].R/tolerence && Round_palette_component(palette[i].G)/tolerence==cpc_colors[3].G/tolerence && Round_palette_component(palette[i].B)/tolerence==cpc_colors[3].B/tolerence) @@ -3183,7 +3181,7 @@ void Compute_optimal_menu_colors(T_Components * palette) } } } - + // Third method: // Compute luminance for whole palette @@ -3222,7 +3220,7 @@ void Compute_optimal_menu_colors(T_Components * palette) else if (l[i]<64) s[i]=s[i]*l[i]/64; } - + // Find color nearest to min+2(max-min)/3 // but at the same time we try to minimize the saturation so that the menu @@ -3237,7 +3235,7 @@ void Compute_optimal_menu_colors(T_Components * palette) MC_Light = i; } } - + // Target "Dark color" is 2/3 between Light and Black low_l = ((int)l[MC_Light]*2+l[MC_Black])/3; for (i = 0; i < 256; i++) @@ -3248,15 +3246,15 @@ void Compute_optimal_menu_colors(T_Components * palette) MC_Dark = i; } } - - + + //if (l[MC_Light]Layer_sprite[l][k][j][i]); - + // Status bar for (k=0; k<3; k++) for (j=0; jHelp_font_t4[k][i][j]); - + // Drives and other misc. 8x8 icons for (k=0; k