forked from compuphase/minIni
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c6e2072
commit d68edbe
Showing
17 changed files
with
1,675 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
minIni is a programmer's library to read and write "INI" files in embedded | ||
systems. The library takes little resources and can be configured for various | ||
kinds of file I/O libraries. | ||
|
||
The method for portable INI file management in minIni is, in part based, on the | ||
article "Multiplatform .INI Files" by Joseph J. Graf in the March 1994 issue of | ||
Dr. Dobb's Journal. | ||
|
||
The C++ class in minIni.h was contributed by Steven Van Ingelgem. | ||
|
||
The option to compile minIni as a read-only library was contributed by Luca | ||
Bassanello. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* Glue functions for the minIni library, based on the FatFs and Petit-FatFs | ||
* libraries, see http://elm-chan.org/fsw/ff/00index_e.html | ||
* | ||
* By CompuPhase, 2008-2012 | ||
* This "glue file" is in the public domain. It is distributed without | ||
* warranties or conditions of any kind, either express or implied. | ||
* | ||
* (The FatFs and Petit-FatFs libraries are copyright by ChaN and licensed at | ||
* its own terms.) | ||
*/ | ||
|
||
#define INI_BUFFERSIZE 256 /* maximum line length, maximum path length */ | ||
|
||
/* You must set _USE_STRFUNC to 1 or 2 in the include file ff.h (or tff.h) | ||
* to enable the "string functions" fgets() and fputs(). | ||
*/ | ||
#include "ff.h" /* include tff.h for Tiny-FatFs */ | ||
|
||
#define INI_FILETYPE FIL | ||
#define ini_openread(filename,file) (f_open((file), (filename), FA_READ+FA_OPEN_EXISTING) == FR_OK) | ||
#define ini_openwrite(filename,file) (f_open((file), (filename), FA_WRITE+FA_CREATE_ALWAYS) == FR_OK) | ||
#define ini_close(file) (f_close(file) == FR_OK) | ||
#define ini_read(buffer,size,file) f_gets((buffer), (size),(file)) | ||
#define ini_write(buffer,file) f_puts((buffer), (file)) | ||
#define ini_remove(filename) (f_unlink(filename) == FR_OK) | ||
|
||
#define INI_FILEPOS DWORD | ||
#define ini_tell(file,pos) (*(pos) = f_tell((file))) | ||
#define ini_seek(file,pos) (f_lseek((file), *(pos)) == FR_OK) | ||
|
||
static int ini_rename(TCHAR *source, const TCHAR *dest) | ||
{ | ||
/* Function f_rename() does not allow drive letters in the destination file */ | ||
char *drive = strchr(dest, ':'); | ||
drive = (drive == NULL) ? dest : drive + 1; | ||
return (f_rename(source, drive) == FR_OK); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* minIni glue functions for FAT library by CCS, Inc. (as provided with their | ||
* PIC MCU compiler) | ||
* | ||
* By CompuPhase, 2011-2012 | ||
* This "glue file" is in the public domain. It is distributed without | ||
* warranties or conditions of any kind, either express or implied. | ||
* | ||
* (The FAT library is copyright (c) 2007 Custom Computer Services, and | ||
* licensed at its own terms.) | ||
*/ | ||
|
||
#define INI_BUFFERSIZE 256 /* maximum line length, maximum path length */ | ||
|
||
#ifndef FAT_PIC_C | ||
#error FAT library must be included before this module | ||
#endif | ||
#define const /* keyword not supported by CCS */ | ||
|
||
#define INI_FILETYPE FILE | ||
#define ini_openread(filename,file) (fatopen((filename), "r", (file)) == GOODEC) | ||
#define ini_openwrite(filename,file) (fatopen((filename), "w", (file)) == GOODEC) | ||
#define ini_close(file) (fatclose((file)) == 0) | ||
#define ini_read(buffer,size,file) (fatgets((buffer), (size), (file)) != NULL) | ||
#define ini_write(buffer,file) (fatputs((buffer), (file)) == GOODEC) | ||
#define ini_remove(filename) (rm_file((filename)) == 0) | ||
|
||
#define INI_FILEPOS fatpos_t | ||
#define ini_tell(file,pos) (fatgetpos((file), (pos)) == 0) | ||
#define ini_seek(file,pos) (fatsetpos((file), (pos)) == 0) | ||
|
||
#ifndef INI_READONLY | ||
/* CCS FAT library lacks a rename function, so instead we copy the file to the | ||
* new name and delete the old file | ||
*/ | ||
static int ini_rename(char *source, char *dest) | ||
{ | ||
FILE fr, fw; | ||
int n; | ||
|
||
if (fatopen(source, "r", &fr) != GOODEC) | ||
return 0; | ||
if (rm_file(dest) != 0) | ||
return 0; | ||
if (fatopen(dest, "w", &fw) != GOODEC) | ||
return 0; | ||
|
||
/* With some "insider knowledge", we can save some memory: the "source" | ||
* parameter holds a filename that was built from the "dest" parameter. It | ||
* was built in a local buffer with the size INI_BUFFERSIZE. We can reuse | ||
* this buffer for copying the file. | ||
*/ | ||
while (n=fatread(source, 1, INI_BUFFERSIZE, &fr)) | ||
fatwrite(source, 1, n, &fw); | ||
|
||
fatclose(&fr); | ||
fatclose(&fw); | ||
|
||
/* Now we need to delete the source file. However, we have garbled the buffer | ||
* that held the filename of the source. So we need to build it again. | ||
*/ | ||
ini_tempname(source, dest, INI_BUFFERSIZE); | ||
return rm_file(source) == 0; | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* Glue functions for the minIni library, based on the EFS Library, see | ||
* http://www.efsl.be/ | ||
* | ||
* By CompuPhase, 2008-2012 | ||
* This "glue file" is in the public domain. It is distributed without | ||
* warranties or conditions of any kind, either express or implied. | ||
* | ||
* (EFSL is copyright 2005-2006 Lennart Ysboodt and Michael De Nil, and | ||
* licensed under the GPL with an exception clause for static linking.) | ||
*/ | ||
|
||
#define INI_BUFFERSIZE 256 /* maximum line length, maximum path length */ | ||
#define INI_LINETERM "\r\n" /* set line termination explicitly */ | ||
|
||
#include "efs.h" | ||
extern EmbeddedFileSystem g_efs; | ||
|
||
#define INI_FILETYPE EmbeddedFile | ||
#define ini_openread(filename,file) (file_fopen((file), &g_efs.myFs, (char*)(filename), 'r') == 0) | ||
#define ini_openwrite(filename,file) (file_fopen((file), &g_efs.myFs, (char*)(filename), 'w') == 0) | ||
#define ini_close(file) file_fclose(file) | ||
#define ini_read(buffer,size,file) (file_read((file), (size), (buffer)) > 0) | ||
#define ini_write(buffer,file) (file_write((file), strlen(buffer), (char*)(buffer)) > 0) | ||
#define ini_remove(filename) rmfile(&g_efs.myFs, (char*)(filename)) | ||
|
||
#define INI_FILEPOS euint32 | ||
#define ini_tell(file,pos) (*(pos) = (file)->FilePtr)) | ||
#define ini_seek(file,pos) file_setpos((file), (*pos)) | ||
|
||
#if ! defined INI_READONLY | ||
/* EFSL lacks a rename function, so instead we copy the file to the new name | ||
* and delete the old file | ||
*/ | ||
static int ini_rename(char *source, const char *dest) | ||
{ | ||
EmbeddedFile fr, fw; | ||
int n; | ||
|
||
if (file_fopen(&fr, &g_efs.myFs, source, 'r') != 0) | ||
return 0; | ||
if (rmfile(&g_efs.myFs, (char*)dest) != 0) | ||
return 0; | ||
if (file_fopen(&fw, &g_efs.myFs, (char*)dest, 'w') != 0) | ||
return 0; | ||
|
||
/* With some "insider knowledge", we can save some memory: the "source" | ||
* parameter holds a filename that was built from the "dest" parameter. It | ||
* was built in buffer and this buffer has the size INI_BUFFERSIZE. We can | ||
* reuse this buffer for copying the file. | ||
*/ | ||
while (n=file_read(&fr, INI_BUFFERSIZE, source)) | ||
file_write(&fw, n, source); | ||
|
||
file_fclose(&fr); | ||
file_fclose(&fw); | ||
|
||
/* Now we need to delete the source file. However, we have garbled the buffer | ||
* that held the filename of the source. So we need to build it again. | ||
*/ | ||
ini_tempname(source, dest, INI_BUFFERSIZE); | ||
return rmfile(&g_efs.myFs, source) == 0; | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* Glue functions for the minIni library, based on the "FAT Filing System" | ||
* library by embedded-code.com | ||
* | ||
* By CompuPhase, 2008-2012 | ||
* This "glue file" is in the public domain. It is distributed without | ||
* warranties or conditions of any kind, either express or implied. | ||
* | ||
* (The "FAT Filing System" library itself is copyright embedded-code.com, and | ||
* licensed at its own terms.) | ||
*/ | ||
|
||
#define INI_BUFFERSIZE 256 /* maximum line length, maximum path length */ | ||
#include <mem-ffs.h> | ||
|
||
#define INI_FILETYPE FFS_FILE* | ||
#define ini_openread(filename,file) ((*(file) = ffs_fopen((filename),"r")) != NULL) | ||
#define ini_openwrite(filename,file) ((*(file) = ffs_fopen((filename),"w")) != NULL) | ||
#define ini_close(file) (ffs_fclose(*(file)) == 0) | ||
#define ini_read(buffer,size,file) (ffs_fgets((buffer),(size),*(file)) != NULL) | ||
#define ini_write(buffer,file) (ffs_fputs((buffer),*(file)) >= 0) | ||
#define ini_rename(source,dest) (ffs_rename((source), (dest)) == 0) | ||
#define ini_remove(filename) (ffs_remove(filename) == 0) | ||
|
||
#define INI_FILEPOS long | ||
#define ini_tell(file,pos) (ffs_fgetpos(*(file), (pos)) == 0) | ||
#define ini_seek(file,pos) (ffs_fsetpos(*(file), (pos)) == 0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* minIni glue functions for Microchip's "Memory Disk Drive" file system | ||
* library, as presented in Microchip application note AN1045. | ||
* | ||
* By CompuPhase, 2011-2014 | ||
* This "glue file" is in the public domain. It is distributed without | ||
* warranties or conditions of any kind, either express or implied. | ||
* | ||
* (The "Microchip Memory Disk Drive File System" is copyright (c) Microchip | ||
* Technology Incorporated, and licensed at its own terms.) | ||
*/ | ||
|
||
#define INI_BUFFERSIZE 256 /* maximum line length, maximum path length */ | ||
|
||
#include "MDD File System\fsio.h" | ||
#include <string.h> | ||
|
||
#define INI_FILETYPE FSFILE* | ||
#define ini_openread(filename,file) ((*(file) = FSfopen((filename),FS_READ)) != NULL) | ||
#define ini_openwrite(filename,file) ((*(file) = FSfopen((filename),FS_WRITE)) != NULL) | ||
#define ini_openrewrite(filename,file) ((*(file) = fopen((filename),FS_READPLUS)) != NULL) | ||
#define ini_close(file) (FSfclose(*(file)) == 0) | ||
#define ini_write(buffer,file) (FSfwrite((buffer), 1, strlen(buffer), (*file)) > 0) | ||
#define ini_remove(filename) (FSremove((filename)) == 0) | ||
|
||
#define INI_FILEPOS long int | ||
#define ini_tell(file,pos) (*(pos) = FSftell(*(file))) | ||
#define ini_seek(file,pos) (FSfseek(*(file), *(pos), SEEK_SET) == 0) | ||
|
||
/* Since the Memory Disk Drive file system library reads only blocks of files, | ||
* the function to read a text line does so by "over-reading" a block of the | ||
* of the maximum size and truncating it behind the end-of-line. | ||
*/ | ||
static int ini_read(char *buffer, int size, INI_FILETYPE *file) | ||
{ | ||
size_t numread = size; | ||
char *eol; | ||
|
||
if ((numread = FSfread(buffer, 1, size, *file)) == 0) | ||
return 0; /* at EOF */ | ||
if ((eol = strchr(buffer, '\n')) == NULL) | ||
eol = strchr(buffer, '\r'); | ||
if (eol != NULL) { | ||
/* terminate the buffer */ | ||
*++eol = '\0'; | ||
/* "unread" the data that was read too much */ | ||
FSfseek(*file, - (int)(numread - (size_t)(eol - buffer)), SEEK_CUR); | ||
} /* if */ | ||
return 1; | ||
} | ||
|
||
#ifndef INI_READONLY | ||
static int ini_rename(const char *source, const char *dest) | ||
{ | ||
FSFILE* ftmp = FSfopen((source), FS_READ); | ||
FSrename((dest), ftmp); | ||
return FSfclose(ftmp) == 0; | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* Glue functions for the minIni library, based on the C/C++ stdio library | ||
* | ||
* Or better said: this file contains macros that maps the function interface | ||
* used by minIni to the standard C/C++ file I/O functions. | ||
* | ||
* By CompuPhase, 2008-2014 | ||
* This "glue file" is in the public domain. It is distributed without | ||
* warranties or conditions of any kind, either express or implied. | ||
*/ | ||
|
||
/* map required file I/O types and functions to the standard C library */ | ||
#include <stdio.h> | ||
|
||
#define INI_FILETYPE FILE* | ||
#define ini_openread(filename,file) ((*(file) = fopen((filename),"rb")) != NULL) | ||
#define ini_openwrite(filename,file) ((*(file) = fopen((filename),"wb")) != NULL) | ||
#define ini_openrewrite(filename,file) ((*(file) = fopen((filename),"r+b")) != NULL) | ||
#define ini_close(file) (fclose(*(file)) == 0) | ||
#define ini_read(buffer,size,file) (fgets((buffer),(size),*(file)) != NULL) | ||
#define ini_write(buffer,file) (fputs((buffer),*(file)) >= 0) | ||
#define ini_rename(source,dest) (rename((source), (dest)) == 0) | ||
#define ini_remove(filename) (remove(filename) == 0) | ||
|
||
#define INI_FILEPOS long int | ||
#define ini_tell(file,pos) (*(pos) = ftell(*(file))) | ||
#define ini_seek(file,pos) (fseek(*(file), *(pos), SEEK_SET) == 0) | ||
|
||
/* for floating-point support, define additional types and functions */ | ||
#define INI_REAL float | ||
#define ini_ftoa(string,value) sprintf((string),"%f",(value)) | ||
#define ini_atof(string) (INI_REAL)strtod((string),NULL) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* Glue functions for the minIni library, based on the C/C++ stdio library | ||
* | ||
* Or better said: this file contains macros that maps the function interface | ||
* used by minIni to the standard C/C++ file I/O functions. | ||
* | ||
* By CompuPhase, 2008-2014 | ||
* This "glue file" is in the public domain. It is distributed without | ||
* warranties or conditions of any kind, either express or implied. | ||
*/ | ||
|
||
/* map required file I/O types and functions to the standard C library */ | ||
#include <stdio.h> | ||
|
||
#define INI_FILETYPE FILE* | ||
#define ini_openread(filename,file) ((*(file) = fopen((filename),"rb")) != NULL) | ||
#define ini_openwrite(filename,file) ((*(file) = fopen((filename),"wb")) != NULL) | ||
#define ini_openrewrite(filename,file) ((*(file) = fopen((filename),"r+b")) != NULL) | ||
#define ini_close(file) (fclose(*(file)) == 0) | ||
#define ini_read(buffer,size,file) (fgets((buffer),(size),*(file)) != NULL) | ||
#define ini_write(buffer,file) (fputs((buffer),*(file)) >= 0) | ||
#define ini_rename(source,dest) (rename((source), (dest)) == 0) | ||
#define ini_remove(filename) (remove(filename) == 0) | ||
|
||
#define INI_FILEPOS long int | ||
#define ini_tell(file,pos) (*(pos) = ftell(*(file))) | ||
#define ini_seek(file,pos) (fseek(*(file), *(pos), SEEK_SET) == 0) | ||
|
||
/* for floating-point support, define additional types and functions */ | ||
#define INI_REAL float | ||
#define ini_ftoa(string,value) sprintf((string),"%f",(value)) | ||
#define ini_atof(string) (INI_REAL)strtod((string),NULL) |
Oops, something went wrong.