GrafX2 2.9.3227
The ultimate 256-color painting program
readini.c File Reference
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include "const.h"
#include "errors.h"
#include "global.h"
#include "misc.h"
#include "readini.h"
#include "setup.h"
#include "realpath.h"
#include "io.h"
#include "windows.h"
#include "gfx2log.h"
#include "gfx2mem.h"
+ Include dependency graph for readini.c:

Functions

void Load_INI_clear_string (char *str, byte keep_comments)
 Clean a line of the ini file. More...
 
int Load_INI_seek_pattern (const char *buffer, const char *pattern)
 Search for a substring in a string. More...
 
static int Load_INI_reach_group (FILE *file, char *buffer, const char *group)
 Read lines until a group is found. More...
 
static int Load_INI_get_string (FILE *file, char *buffer, const char *option_name, char *return_code, byte raw_text)
 Find the next string in the .INI file. More...
 
static int Load_INI_get_value (const char *str, int *index, int *value)
 Read a value from the string. More...
 
static int Load_INI_get_values (FILE *file, char *buffer, const char *option_name, int nb_expected_values, int *values)
 Read all values from a string. More...
 
int Load_INI (T_Config *conf)
 Load config from the gfx2.ini file. More...
 

Function Documentation

◆ Load_INI_clear_string()

void Load_INI_clear_string ( char *  str,
byte  keep_comments 
)

Clean a line of the ini file.

  • Suppress all leading and trailing spaces
  • convert the key to uppercase

Comments start with ";". The result will be in the following format : KEY=value

Parameters
[in,out]str
[in]keep_commentsif set, the comments are kept

Referenced by Load_INI_get_string(), Load_INI_get_values(), Load_INI_reach_group(), Save_INI_reach_group(), Save_INI_set_strings(), and Save_INI_set_values().

◆ Load_INI_seek_pattern()

int Load_INI_seek_pattern ( const char *  buffer,
const char *  pattern 
)

Search for a substring in a string.

Parameters
bufferthe string to search into
patternthe string to search for
Returns
0 if the pattern was not found
>0 the position (+1) where the pattern was found

Referenced by Load_INI_get_string(), Load_INI_get_value(), Load_INI_get_values(), Load_INI_reach_group(), Save_INI_reach_group(), Save_INI_set_strings(), and Save_INI_set_values().

◆ Load_INI_reach_group()

static int Load_INI_reach_group ( FILE *  file,
char *  buffer,
const char *  group 
)
static

Read lines until a group is found.

Returns
0 when the group is reached
ERROR_INI_CORRUPTED if the group is not found

References ERROR_INI_CORRUPTED, Line_number_in_INI_file, Load_INI_clear_string(), and Load_INI_seek_pattern().

Referenced by Load_INI().

◆ Load_INI_get_string()

static int Load_INI_get_string ( FILE *  file,
char *  buffer,
const char *  option_name,
char *  return_code,
byte  raw_text 
)
static

Find the next string in the .INI file.

Parameters
fileINI file currently opened
bufferCurrent text buffer, preserved from one call to the next
option_namestring to search
return_codethe found value will be copied there. (must be allocaed)
raw_textBoolean: true to return the raw value (up to end-of-line), false to strip comments.
Returns
0 when OK
ERROR_INI_CORRUPTED if the option is not found

References ERROR_INI_CORRUPTED, Line_number_in_INI_file, Load_INI_clear_string(), Load_INI_seek_pattern(), and NULL.

Referenced by Load_INI().

◆ Load_INI_get_value()

static int Load_INI_get_value ( const char *  str,
int *  index,
int *  value 
)
static

Read a value from the string.

GrafX2 is updated according to the number of characters read from the source string.

Parameters
strthe source string (option "values")
indexa pointer to the current index in the source string
valuethe read value will be put there
Returns
0
ERROR_INI_CORRUPTED

References ERROR_INI_CORRUPTED, and Load_INI_seek_pattern().

Referenced by Load_INI_get_values().

◆ Load_INI_get_values()

static int Load_INI_get_values ( FILE *  file,
char *  buffer,
const char *  option_name,
int  nb_expected_values,
int *  values 
)
static

Read all values from a string.

The values are comma separated

Parameters
filehandle to gfx2.ini
bufferCurrent text buffer, preserved from one call to the next
option_namename of the option to read
nb_expected_valuesnumber of values to read from the line
[out]valuesthe values will be put there
Returns
0 when OK
ERROR_INI_CORRUPTED if no value was found, or not enough

References ERROR_INI_CORRUPTED, Line_number_in_INI_file, Load_INI_clear_string(), Load_INI_get_value(), and Load_INI_seek_pattern().

Referenced by Load_INI().

◆ Load_INI()

int Load_INI ( T_Config conf)

Load config from the gfx2.ini file.

Parameters
[out]confthe configuration to read to
Returns
0 when OK
ERROR_INI_CORRUPTED for any error

References T_Config::Adjust_brush_pick, T_Config::Allow_multi_shortcuts, T_Config::Auto_discontinuous, T_Config::Auto_nb_used, T_Config::Auto_save, T_Config::Auto_set_res, T_Components::B, T_Config::Backup, T_Config::Bookmark_directory, T_Config::Bookmark_label, T_Config::Clear_palette, T_Config::Clear_with_stencil, Config_directory, Convert_videomode_arg(), T_Config::Coords_rel, T_Config::Cursor, Data_directory, DEFAULT_FONT_FILENAME, T_Config::Default_mode_layers, T_Config::Default_resolution, DEFAULT_SKIN_FILENAME, Default_window_height, Default_window_width, T_Config::Delay_left_click_on_slider, T_Config::Delay_right_click_on_slider, T_Config::Display_image_limits, T_Config::Double_click_speed, T_Config::Double_key_speed, ERROR_INI_CORRUPTED, ERROR_INI_MISSING, T_Config::Fast_zoom, T_Config::Fav_menu_colors, Filepath_append_to_dir(), T_Config::Find_file_fast, T_Config::Font_file, T_Config::FX_Feedback, T_Components::G, GFX2_DEBUG, GFX2_ERROR, GFX2_Log(), GFX2_malloc, GFX2_MOD_ALT, GFX2_MOD_CTRL, T_Video_mode::Height, INI_FILENAME, INIDEF_FILENAME, Line_number_in_INI_file, Load_INI_get_string(), Load_INI_get_values(), Load_INI_reach_group(), T_Config::Max_undo_pages, T_Config::Maximize_preview, Menu_bars, MENUBAR_ANIMATION, MENUBAR_LAYERS, MENUBAR_TOOLS, mode, T_Config::MOTO_gamma, T_Config::Mouse_merge_movement, T_Config::Mouse_motion_debounce, T_Config::Mouse_sensitivity_index_x, T_Config::Mouse_sensitivity_index_y, NB_BOOKMARKS, T_Config::Nb_max_vertices_per_polygon, NULL, T_Config::Opening_message, T_Config::Palette_cells_X, T_Config::Palette_cells_Y, T_Config::Palette_vertical, PIXEL_DOUBLE, PIXEL_QUAD, Pixel_ratio, PIXEL_SIMPLE, PIXEL_TALL, PIXEL_TALL2, PIXEL_TALL3, PIXEL_TRIPLE, PIXEL_WIDE, PIXEL_WIDE2, T_Components::R, T_Config::Ratio, Realpath(), T_Config::Right_click_colorpick, T_Config::Safety_colors, T_Config::Screen_size_in_GIF, T_Config::Scripts_directory, SCRIPTS_SUBDIRECTORY, T_Config::Separate_colors, T_Config::Set_resolution_according_to, T_Config::Show_hidden_directories, T_Config::Show_hidden_files, T_Config::Skin_file, T_Config::Stylus_mode, T_Config::Swap_buttons, T_Config::Sync_views, T_Config::Tilemap_allow_flipped_x, T_Config::Tilemap_allow_flipped_y, T_Config::Tilemap_show_count, T_Config::Timer_delay, T_Config::Use_virtual_keyboard, Video_mode, T_Menu_Bar::Visible, T_Video_mode::Width, T_Config::Window_pos_x, and T_Config::Window_pos_y.

Referenced by Init_program(), and Settings_load_config().