diff --git a/errors.h b/errors.h index 5fc671ce..4ff652ad 100644 --- a/errors.h +++ b/errors.h @@ -42,3 +42,13 @@ void Error_function(int error_code, const char *filename, int line_number, const /// - If the error code is 0, just do a red screen flash and resume. /// - If the error code is non-zero, abort the program. #define Error(n) Error_function(n, __FILE__,__LINE__,__func__) + +/// Helper function used by the macro ::Warning +void Warning_function(const char *message, const char *filename, int line_number, const char *function_name); + +/// +/// Report a run-time abnormal condition : It will print to standard output +/// some information about the calling function, and then resume silently. +/// This is most useful in debugger so you can put a breakpoint on +/// ::Warning_function and examine the stack trace. +#define Warning(msg) Warning_function(msg, __FILE__,__LINE__,__func__) \ No newline at end of file diff --git a/factory.c b/factory.c index 1ea41986..f17c3b87 100644 --- a/factory.c +++ b/factory.c @@ -488,9 +488,6 @@ int L_GetTransColor(lua_State* L) return 1; } - - - int L_InputBox(lua_State* L) { const int max_settings = 9; @@ -574,7 +571,6 @@ int L_InputBox(lua_State* L) if (max_label_length>25) max_label_length=25; - Hide_cursor(); Open_window(115+max_label_length*8,44+nb_settings*17,window_caption); // OK @@ -603,7 +599,7 @@ int L_InputBox(lua_State* L) // Numeric input field Window_set_input_button(12+max_label_length*8+21, 20+setting*17,7); // Print editable value - Dec2str(current_value[setting],str,decimal_places[setting]); + Sprint_double(str,current_value[setting],decimal_places[setting],7); Print_in_window_limited(12+max_label_length*8+23, 22+setting*17, str, 7,MC_Black,MC_Light); // control[Window_nb_buttons] = CONTROL_INPUT | setting; @@ -636,7 +632,8 @@ int L_InputBox(lua_State* L) break; case CONTROL_INPUT: - Dec2str(current_value[setting],str,decimal_places[setting]); + + Sprint_double(str,current_value[setting],decimal_places[setting],0); Readline_ex(12+max_label_length*8+23, 22+setting*17,str,7,40,3,decimal_places[setting]); current_value[setting]=atof(str); @@ -644,9 +641,8 @@ int L_InputBox(lua_State* L) current_value[setting] = min_value[setting]; else if (current_value[setting] > max_value[setting]) current_value[setting] = max_value[setting]; - Hide_cursor(); // Print editable value - Dec2str(current_value[setting],str,decimal_places[setting]); + Sprint_double(str,current_value[setting],decimal_places[setting],7); Print_in_window_limited(12+max_label_length*8+23, 22+setting*17, str, 7,MC_Black,MC_Light); // Display_cursor(); @@ -662,7 +658,7 @@ int L_InputBox(lua_State* L) Hide_cursor(); // Print editable value - Dec2str(current_value[setting],str,decimal_places[setting]); + Sprint_double(str,current_value[setting],decimal_places[setting],7); Print_in_window_limited(12+max_label_length*8+23, 22+setting*17, str, 7,MC_Black,MC_Light); // Display_cursor(); @@ -678,7 +674,7 @@ int L_InputBox(lua_State* L) Hide_cursor(); // Print editable value - Dec2str(current_value[setting],str,decimal_places[setting]); + Sprint_double(str,current_value[setting],decimal_places[setting],7); Print_in_window_limited(12+max_label_length*8+23, 22+setting*17, str, 7,MC_Black,MC_Light); // Display_cursor(); @@ -695,7 +691,6 @@ int L_InputBox(lua_State* L) } } - Hide_cursor(); Close_window(); Cursor_shape=CURSOR_SHAPE_HOURGLASS; Display_cursor(); diff --git a/main.c b/main.c index 6f5a12df..aea6c6b4 100644 --- a/main.c +++ b/main.c @@ -110,6 +110,12 @@ void Display_syntax(void) } } +// ---------------------------- Sortie impromptue ---------------------------- +void Warning_function(const char *message, const char *filename, int line_number, const char *function_name) +{ + printf("Warning in file %s, line %d, function %s : %s\n", filename, line_number, function_name, message); +} + // ---------------------------- Sortie impromptue ---------------------------- void Error_function(int error_code, const char *filename, int line_number, const char *function_name) diff --git a/readline.c b/readline.c index 0c9c0759..936549e0 100644 --- a/readline.c +++ b/readline.c @@ -152,7 +152,10 @@ byte Readline_ex(word x_pos,word y_pos,char * str,byte visible_size,byte max_siz else if (input_type==1) snprintf(str,10,"%d",atoi(str)); // On tasse la chaine à gauche else if (input_type==3) - sprintf(str,"%.*f",decimal_places, atof(str)); // On tasse la chaine à gauche + { + // Nothing. The caller should have used Sprint_double, with min_positions + // at zero, so there's no spaces on the left and no useless 0s on the right. + } Wait_end_of_click(); Keyboard_click_allowed = 0; @@ -169,7 +172,7 @@ byte Readline_ex(word x_pos,word y_pos,char * str,byte visible_size,byte max_siz size=strlen(str); position=(sizevisible_size) + if (position-offset>=visible_size) offset=position-visible_size+1; // Formatage d'une partie de la chaine (si trop longue pour tenir) strncpy(display_string, str + offset, visible_size); @@ -247,7 +250,7 @@ byte Readline_ex(word x_pos,word y_pos,char * str,byte visible_size,byte max_siz if ((positionvisible_size) + if (position-offset>=visible_size) offset=position-visible_size+1; goto affichage; } @@ -359,35 +362,9 @@ affichage: else if (input_type==3) { double value; - int i; - unsigned int str_length; - - value = atof(str); - - // Remove extraneous decimal places: - // From number - value = Fround(value, decimal_places); - - // From display - sprintf(str,"%.*f",decimal_places, atof(str)); - // Remove extraneous zeroes - /* - for (i=0; i= 0 && decimals[j]=='0'; j--) + { + decimals[j] = '\0'; + } + // If all decimals were removed, remove the dot too + if (str[i+1]=='\0') + str[i]='\0'; + + // Update string length + length=strlen(str); + + // Ends the parent loop + break; + } + } + + // Now try add spaces at beginning + if (length