Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

A simple and easy-to-use ini-style files reader and writer

License

NotificationsYou must be signed in to change notification settings

raysan5/rini

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

48 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rini is a simple and easy-to-use ini-style files reader and writer

rini is provided as a self-contained portable single-file header-only library with no external dependencies.Its only dependency, the standard C library, can also be replaced with a custom implementation if required.

Multiple configuration options are available through#define values.




features

  • Init/Config files reading and writing
  • Supported value types: int, string
  • Support comment lines and empty lines
  • Support custom line comment delimiter
  • Support custom value delimiters
  • Support value description comments
  • Support custom description custom delimiter
  • Support multi-word text values w/o quote delimiters
  • Minimal C standard lib dependency (optional)
  • Customizable maximum values capacity

configuration

#define RINI_IMPLEMENTATION

Generates the implementation of the library into the included file.If not defined, the library is in header only mode and can be included in other headersor source files without problems. But only ONE file should hold the implementation.

#define RINI_MAX_VALUE_CAPACITY

Define the maximum capacity of key-value data structure, customizable by user.Default value: 32 entries support

#define RINI_LINE_COMMENT_DELIMITER

Define character used to comment lines, placed at beginning of lineMost .ini files use semicolon ';' but '#' is also usedDefault value: '#'

#define RINI_LINE_SECTION_DELIMITER

Defines section lines start characterSections loading is not supported, lines are just skipped for now

#define RINI_VALUE_COMMENTS_DELIMITER

Defines a property line-end comment delimiterThis implementation allows adding inline comments after the value.Default value: '#'

#define RINI_VALUE_DELIMITER

Defines a key value delimiter, in case it is defined.Most .ini files use '=' as value delimiter but ':' is also used or just whitespaceDefault value: ' '

#define RINI_VALUE_QUOTATION_MARKS

Defines quotation marks to be used around text valuesText values are determined checking text with atoi(), only for integer values,in case of float values they are always considered as textDefault value: '"'

#define RINI_DESCRIPTION_DELIMITER

Defines a property line-end comment delimiterThis implementation allows adding inline comments after the value.Default value: '#'

basic functions

// Load/unload config from file (*.ini) or create a new config object (pass NULL)rini_datarini_load(constchar*file_name);voidrini_unload(rini_data*config);// Save config to file, with custom header (if provided)// NOTE: Only full config file rewrite supported, no partial updatesvoidrini_save(rini_dataconfig,constchar*file_name);// Get config value int/text/description for provided key, returns NULL if not foundintrini_get_value(rini_dataconfig,constchar*key);constchar*rini_get_value_text(rini_dataconfig,constchar*key);constchar*rini_get_value_description(rini_dataconfig,constchar*key);// Set config value int/text and description for existing key or create a new entry// NOTE: When setting a text value, if id does not exist, a new entry is automatically createdintrini_set_value(rini_data*config,constchar*key,intvalue,constchar*desc);intrini_set_value_text(rini_data*config,constchar*key,constchar*text,constchar*desc);// Set config value description for existing key// WARNING: Key must exist to add description, if a description exists, it is updatedintrini_set_value_description(rini_data*config,constchar*key,constchar*desc);

limitations

  • [sections] not supported
  • Saving file requires complete rewrite

usage example

Load an existing file

#defineRINI_IMPLEMENTATION#include"rini.h"intmain(){rini_dataconfig=rini_load("config.ini");intshow_window_sponsors_value=rini_get_value(config,"SHOW_WINDOW_SPONSORS");intshow_window_info_value=rini_get_value(config,"SHOW_WINDOW_INFO");intshow_window_edit_value=rini_get_value(config,"SHOW_WINDOW_EDIT");intimage_scale_filter_value=rini_get_value(config,"IMAGE_SCALE_FILTER");intimage_background_value=rini_get_value(config,"IMAGE_BACKGROUND");intvisual_style_value=rini_get_value(config,"VISUAL_STYLE");intclean_window_mode_value=rini_get_value(config,"CLEAN_WINDOW_MODE");rini_unload(&config);return0;}

Save a custom file:

#defineRINI_IMPLEMENTATION#include"rini.h"intmain(){// Create empty file with 32 entries (RINI_MAX_VALUES_CAPACITY)rini_dataconfig=rini_load(NULL);// Define header comment linesrini_set_comment_line(&config,NULL);// Empty comment line, but including comment prefix delimiterrini_set_comment_line(&config,"rTexViewer initialization configuration options");rini_set_comment_line(&config,NULL);rini_set_comment_line(&config,"NOTE: This file is loaded at application startup,");rini_set_comment_line(&config,"if file is not found, default values are applied");rini_set_comment_line(&config,NULL);// Define valuesrini_set_value(&config,"SHOW_WINDOW_SPONSORS",1,"Show sponsors window at initialization");rini_set_value(&config,"SHOW_WINDOW_INFO",0,"Show image info window");rini_set_value(&config,"SHOW_WINDOW_EDIT",0,"Show image edit window");rini_set_value(&config,"IMAGE_SCALE_FILTER",1,"Image scale filter enabled: 0-Point, 1-Bilinear");rini_set_value(&config,"IMAGE_BACKGROUND",0,"Image background style: 0-None, 1-Checked, 2-Black, 3-Magenta");rini_set_value(&config,"VISUAL_STYLE",2,"UI visual style selected: 0-9");rini_set_value(&config,"CLEAN_WINDOW_MODE",0,"Clean window mode enabled");rini_save(config,"config.ini",ini_header);rini_unload(&config);return0;}

license

rini is licensed under an unmodified zlib/libpng license, which is an OSI-certified, BSD-like license that allows static linking with closed source software. CheckLICENSE for further details.

About

A simple and easy-to-use ini-style files reader and writer

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

  •  

Contributors4

  •  
  •  
  •  
  •  

Languages


[8]ページ先頭

©2009-2025 Movatter.jp