Arduino ini file library

fierland/IniFile

Use Git or checkout with SVN using the web URL.

Work fast with our official CLI. Learn more.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

README.md

IniFile is an Arduino library for parsing ini files. The format is similar to that seen in Microsoft .ini files but the implementation is completely independent. IniFile is designed to use minimal memory requirements, and the only buffer used is one supplied by the user, thus the user remains in charge of memory usage.

The ini file is separated into sections, where the section names are written inside square brackets. If you don’t wish to use sections then pass a NULL pointer for the section name. Under each section are a set of key-value pairs, separated by an equals sign ( = ). Spaces around keys and values are ignored, but extra spaces inside the key are significant. Whitespace inside the value string is preserved; if leading or trailing whitespace is important you must quote the value string inside the ini file, and you must strip out the quotes yourself. If multiple entries for the same key exist inside the selected section (if using) then only the first value is returned. If a section is defined more than once only the first is used. The .ini file can contain comments, which begin with a semicolon ( ; ) or hash ( # ). The user-supplied buffer must be large enough to accomodate the longest line in the file.

Источник

stevemarple/IniFile

Use Git or checkout with SVN using the web URL.

Work fast with our official CLI. Learn more.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

README.md

IniFile is an Arduino library for reading ini files. The format is similar to that seen in Microsoft .ini files but the implementation is completely independent. IniFile is designed to use minimal memory requirements, and the only buffer used is one supplied by the user, thus the user remains in charge of memory usage.

The ini file is separated into sections, where the section names are written inside square brackets. If you don’t wish to use sections then pass a NULL pointer for the section name. Under each section are a set of key-value pairs, separated by an equals sign ( = ). Spaces around keys and values are ignored, but extra spaces inside the key are significant. Whitespace inside the value string is preserved; if leading or trailing whitespace is important you must quote the value string inside the ini file, and you must strip out the quotes yourself. If multiple entries for the same key exist inside the selected section (if using) then only the first value is returned. If a section is defined more than once only the first is used. The .ini file can contain comments, which begin with a semicolon ( ; ) or hash ( # ). The user-supplied buffer must be large enough to accomodate the longest line in the file.

Example file format

Write support is a feature that has been requested on several occasions but as I am no longer using the IniFile library I will not add this feature. For anyone planning to add such support the information below may be useful.

One goal of the IniFile implementation was to limit the amount of memory required. For use in embedded systems malloc and new are deliberately not used. Another goal was that tasks which take a longer duration were broken down into smaller chunks of work, eg IniFile::getValue(const char* section, const char* key, char* buffer, int len, IniFileState &state) . This was because I wanted my WwwServer library, which uses IniFile , to avoid interfering with time-critical code.

I don’t think that write support can meet the time-critical goal but that doesn’t prevent its inclusion. I think the way I would choose to implement write support is to use IniFile::findKey() to find where the desired key is located in the file. I’d then copy everything up to that point to a temporary file, insert a line for the value and new key, skip the current line in the existing file (using IniFile::readline() ) and then write out the reminder of the existing file into the temporary file. I’d like to move or rename the temporary file over the existing file but the Arduino SD library doesn’t provide this functionality; I’d probably just copy the temporary file over the old one and then delete the temporary one.

The code has been written under a standard Linux environment, using a compatibility header file to mimic the SD library. This was far more convenient than doing everything on the Arduino and enabled me to use gdb to debug the code and core dumps. You’ll find arduino_compat.h inside the test directory, along with a Makefile which can be used for regression testing. Any proposed changes must pass the regression tests.

Источник

nightgryphon/WriteableIniFile

Use Git or checkout with SVN using the web URL.

Work fast with our official CLI. Learn more.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

README.md

This library allow to parse, read and write name-value pairs within .ini file. It supports sections, comments, adding and updating values, default values, printing data in INI or JSON format.

The library intends to provide convenient way to work with config files and to minimize memory usage. All data processing is performed line by line within provided buffer. The memory required is to hold one line of config file.

The only case when extra memory allocated is appending new name-value to file or updating with value longer than available free space within line (value placeholder)

Case insensitive search available using ‘lowerCaseNames’ property. When set to true all read parameter and section names converted to lower case before compare.

Typical usage can be like this:

Take a look at the examples. They shold be quite self explanary.

To start use WriteableIniFile you should provide an opened File to constructor and set the processing buffer by calling setBuffer(buf, sizeof(buf)).
The processing buffer can be shared between multiple WriteableIniFile instances but you should notice that every call to read/write parameters or sections will overwrite buffer data.

You can use any File class which support read/write/seek/size/position functions. Initially this library work with SPIFFS at ESP8266 but shold work with other platforms as well

WriteableIniFile(File * file);
Constructor. file should be the opened File.

bool setBuffer(char * buf, size_t asize, bool check_buf = true);
set processing buffer. Should be large enough to accept any single line from file

bool inLineComments;
Set to ‘false’ to disable inline comments. Default ‘true’

bool lowerCaseNames;
Set to ‘true’ to convert all names to lower case for case insensitive search. Default ‘false’

bool openSection(char * section);
Search for specified section and set it as current. NULL is the root section.

bool nextSection();
Move to the nearest next section.
Can be used to loop through sections.

void getLastName(char * &aname, size_t &name_len);
Return the pointer and length of last found name of section or parameter.
Can be used to loop through sections.

char * getLastName();
Return null terminated string pointer of last found name of section or parameter.
The data is located within processing buffer and will be destroyed by next file read.
Can be used to loop through sections.

bool getValueCopy(char * aname, char * buf, size_t asize);
Copy value to provided buffer.

char * getValue(char * aname, char * defval);
Get value by name within current section.
On success return pointer to null terminated value string within processing buffer.
On not found or error returns defval
If aname = NULL read next name-value within current section.
Can be used to loop through section values.

void resetSection();
Used to loop through section values. Restart value loop from section start.

bool setValue(char * aname, char * new_val, size_t pl_bytes = 0);
Update or create parameter within current section with new value.\ If value fits the existing space it is updated. If not than the extra space is created by moving file contents (creates temporary memory buffer while processing)

void printIni(Print & p);
print data source file to specified printable.

void printJson(Print & p);
print data as JSON string to specified printable.

size_t getJsonSize();
calculates the JSON string length. Can be used with printJson to send data as single HTTP chunk to reduce network overhead

void printJsonChunks(Print & p, bool closeStream = false);
print JSON data in HTTP chunked transport encoding to output directly to web client stream. closeStream = send final empty chunk.

error_t getLastError()
Get last error code

void resetError()
Clean errors.
Error is not reset automatically to let you check error summary after set of operations.

bool error()
was there an error?

Источник

lipoyang/minIni4Arduino

Use Git or checkout with SVN using the web URL.

Work fast with our official CLI. Learn more.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

README.md

minIni (INI file library) for Arduino

This is the minIni library ported for Arduino.

The original minIni is below.

  • 8.3 filename only (due to Arduino’s SD library)
  • Write functions are slow. (due to Arduino’s SD and File library)
  • This library uses Arduino’s String class istead of std::string.
  • For plain INI file, specify the section as «». NULL is unsupported.
  • This library is verified to work with GR-ROSE (Renesas RX65N)
  • Case insensitive matching for section / key

minIni is a portable and configurable library for reading and writing «.INI» files. At just below 900 lines of commented source code, minIni truly is a «mini» INI file parser, especially considering its features.

The library does not require the file I/O functions from the standard C/C++ library, but instead lets you configure the file I/O interface to use via macros. minIni uses limited stack space and does not use dynamic memory (malloc and friends) at all.

Some minor variations on standard INI files are supported too, notably minIni supports INI files that lack sections.

minIni is derived from an earlier INI file parser (which I wrote) for desktop systems.

In turn, that earlier parser was a re-write of the code from the article «Multiplatform .INI Files» by Joseph J. Graf in the March 1994 issue of Dr. Dobb’s Journal. In other words, minIni has its roots in the work of Joseph Graf (even though the code has been almost completely re-written).

minIni is a programmer’s library to read and write «INI» files in embedded systems. minIni takes little resources, can be configured for various kinds of file I/O libraries and provides functionality for reading, writing and deleting keys from an INI file.

Although the main feature of minIni is that it is small and minimal, it has a few other features:

  • minIni supports reading keys that are outside a section, and it thereby supports configuration files that do not use sections (but that are otherwise compatible with INI files).
  • You may use a colon to separate key and value; the colon is equivalent to the equal sign. That is, the strings «Name: Value» and «Name=Value» have the same meaning.
  • The hash character («#») is an alternative for the semicolon to start a comment. Trailing comments (i.e. behind a key/value pair on a line) are allowed.
  • Leading and trailing white space around key names and values is ignored.
  • When writing a value that contains a comment character («;» or «#»), that value will automatically be put between double quotes; when reading the value, these quotes are removed. When a double-quote itself appears in the setting, these characters are escaped.
  • Section and key enumeration are supported.
  • You can optionally set the line termination (for text files) that minIni will use. (This is a compile-time setting, not a run-time setting.)
  • Since writing speed is much lower than reading speed in Flash memory (SD/MMC cards, USB memory sticks), minIni minimizes «file writes» at the expense of double «file reads».
  • The memory footprint is deterministic. There is no dynamic memory allocation.

INI file reading paradigms

There are two approaches to reading settings from an INI file. One way is to call a function, such as GetProfileString() for every section and key that you need. This is especially convenient if there is a large INI file, but you only need a few settings from that file at any time —especially if the INI file can also change while your program runs. This is the approach that the Microsoft Windows API uses.

The above procedure is quite inefficient, however, when you need to retrieve quite a few settings in a row from the INI file —especially if the INI file is not cached in memory (which it isn’t, in minIni). A different approach to getting settings from an INI file is to call a «parsing» function and let that function call the application back with the section and key names plus the associated data. XML parsing libraries often use this approach; see for example the Expat library.

minIni supports both approaches. For reading a single setting, use functions like ini_gets(). For the callback approach, implement a callback and call ini_browse(). See the minIni manual for details.

INI file syntax

INI files are best known from Microsoft Windows, but they are also used with applications that run on other platforms (although their file extension is sometimes «.cfg» instead of «.ini»).

INI files have a simple syntax with name/value pairs in a plain text file. The name must be unique (per section) and the value must fit on a single line. INI files are commonly separated into sections —in minIni, this is optional. A section is a name between square brackets, like «[Network]» in the example below.

In the API and in this documentation, the «name» for a setting is denoted as the key for the setting. The key and the value are separated by an equal sign («=»). minIni supports the colon («:») as an alternative to the equal sign for the key/value delimiter.

Leading a trailing spaces around values or key names are removed. If you need to include leading and/or trailing spaces in a value, put the value between double quotes. The ini_gets() function (from the minIni library, see the minIni manual) strips off the double quotes from the returned value. Function ini_puts() adds double quotes if the value to write contains trailing white space (or special characters).

minIni ignores spaces around the «=» or «:» delimiters, but it does not ignore spaces between the brackets in a section name. In other words, it is best not to put spaces behind the opening bracket «[» or before the closing bracket «]» of a section name.

Comments in the INI must start with a semicolon («;») or a hash character («#»), and run to the end of the line. A comment can be a line of its own, or it may follow a key/value pair (the «#» character and trailing comments are extensions of minIni).

For more details on the format, please see http://en.wikipedia.org/wiki/INI_file.

Adapting minIni to a file system

The minIni library must be configured for a platform with the help of a so- called «glue file». This glue file contains macros (and possibly functions) that map file reading and writing functions used by the minIni library to those provided by the operating system. The glue file must be called «minGlue.h».

To get you started, the minIni distribution comes with the following example glue files:

  • a glue file that maps to the standard C/C++ library (specifically the file I/O functions from the «stdio» package),
  • a glue file for Microchip’s «Memory Disk Drive File System Library» (see http://www.microchip.com/),
  • a glue file for the FAT library provided with the CCS PIC compiler (see http://www.ccsinfo.com/)
  • a glue file for the EFS Library (EFSL, http://www.efsl.be/),
  • and a glue file for the FatFs and Petit-FatFs libraries (http://elm-chan.org/fsw/ff/00index_e.html).

The minIni library does not rely on the availability of a standard C library, because embedded operating systems may have limited support for file I/O. Even on full operating systems, separating the file I/O from the INI format parsing carries advantages, because it allows you to cache the INI file and thereby enhance performance.

The glue file must specify the type that identifies a file, whether it is a handle or a pointer. For the standard C/C++ file I/O library, this would be:

If you are not using the standard C/C++ file I/O library, chances are that you need a different handle or «structure» to identify the storage than the ubiquitous «FILE*» type. For example, the glue file for the FatFs library uses the following declaration:

The minIni functions declare variables of this INI_FILETYPE type and pass these variables to sub-functions (including the glue interface functions) by reference.

For «write support», another type that must be defined is for variables that hold the «current position» in a file. For the standard C/C++ I/O library, this is «fpos_t».

Another item that needs to be configured is the buffer size. The functions in the minIni library allocate this buffer on the stack, so the buffer size is directly related to the stack usage. In addition, the buffer size determines the maximum line length that is supported in the INI file and the maximum path name length for the temporary file. For example, minGlue.h could contain the definition:

The above macro limits the line length of the INI files supported by minIni to 512 characters.

The temporary file is only used when writing to INI files. The minIni routines copy/change the INI file to a temporary file and then rename that temporary file to the original file. This approach uses the least amount of memory. The path name of the temporary file is the same as the input file, but with the last character set to a tilde («

Below is an example of a glue file (this is the one that maps to the C/C++ «stdio» library).

As you can see, a glue file is mostly a set of macros that wraps one function definition around another.

The glue file may contain more settings, for support of rational numbers, to explicitly set the line termination character(s), or to disable write support (for example). See the manual that comes with the archive for the details.

About

A INI file library for Arduino with read/write support

Источник