Skip to content

Commit d68edbe

Browse files
committed
Port form Google Code.
1 parent c6e2072 commit d68edbe

17 files changed

+1675
-28
lines changed

LICENSE

Lines changed: 15 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,21 @@
1-
Apache License
1+
2+
Apache License
23
Version 2.0, January 2004
34
http://www.apache.org/licenses/
45

6+
7+
EXCEPTION TO THE APACHE 2.0 LICENSE
8+
9+
As a special exception to the Apache License 2.0 (and referring to the
10+
definitions in Section 1 of this license), you may link, statically or
11+
dynamically, the "Work" to other modules to produce an executable file
12+
containing portions of the "Work", and distribute that executable file
13+
in "Object" form under the terms of your choice, without any of the
14+
additional requirements listed in Section 4 of the Apache License 2.0.
15+
This exception applies only to redistributions in "Object" form (not
16+
"Source" form) and only if no modifications have been made to the "Work".
17+
18+
519
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
620

721
1. Definitions.
@@ -173,30 +187,3 @@ Apache License
173187
incurred by, or claims asserted against, such Contributor by reason
174188
of your accepting any such warranty or additional liability.
175189

176-
END OF TERMS AND CONDITIONS
177-
178-
APPENDIX: How to apply the Apache License to your work.
179-
180-
To apply the Apache License to your work, attach the following
181-
boilerplate notice, with the fields enclosed by brackets "{}"
182-
replaced with your own identifying information. (Don't include
183-
the brackets!) The text should be enclosed in the appropriate
184-
comment syntax for the file format. We also recommend that a
185-
file or class name and description of purpose be included on the
186-
same "printed page" as the copyright notice for easier
187-
identification within third-party archives.
188-
189-
Copyright {yyyy} {name of copyright owner}
190-
191-
Licensed under the Apache License, Version 2.0 (the "License");
192-
you may not use this file except in compliance with the License.
193-
You may obtain a copy of the License at
194-
195-
http://www.apache.org/licenses/LICENSE-2.0
196-
197-
Unless required by applicable law or agreed to in writing, software
198-
distributed under the License is distributed on an "AS IS" BASIS,
199-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200-
See the License for the specific language governing permissions and
201-
limitations under the License.
202-

NOTICE

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
minIni is a programmer's library to read and write "INI" files in embedded
2+
systems. The library takes little resources and can be configured for various
3+
kinds of file I/O libraries.
4+
5+
The method for portable INI file management in minIni is, in part based, on the
6+
article "Multiplatform .INI Files" by Joseph J. Graf in the March 1994 issue of
7+
Dr. Dobb's Journal.
8+
9+
The C++ class in minIni.h was contributed by Steven Van Ingelgem.
10+
11+
The option to compile minIni as a read-only library was contributed by Luca
12+
Bassanello.

dev/minGlue-FatFs.h

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/* Glue functions for the minIni library, based on the FatFs and Petit-FatFs
2+
* libraries, see http://elm-chan.org/fsw/ff/00index_e.html
3+
*
4+
* By CompuPhase, 2008-2012
5+
* This "glue file" is in the public domain. It is distributed without
6+
* warranties or conditions of any kind, either express or implied.
7+
*
8+
* (The FatFs and Petit-FatFs libraries are copyright by ChaN and licensed at
9+
* its own terms.)
10+
*/
11+
12+
#define INI_BUFFERSIZE 256 /* maximum line length, maximum path length */
13+
14+
/* You must set _USE_STRFUNC to 1 or 2 in the include file ff.h (or tff.h)
15+
* to enable the "string functions" fgets() and fputs().
16+
*/
17+
#include "ff.h" /* include tff.h for Tiny-FatFs */
18+
19+
#define INI_FILETYPE FIL
20+
#define ini_openread(filename,file) (f_open((file), (filename), FA_READ+FA_OPEN_EXISTING) == FR_OK)
21+
#define ini_openwrite(filename,file) (f_open((file), (filename), FA_WRITE+FA_CREATE_ALWAYS) == FR_OK)
22+
#define ini_close(file) (f_close(file) == FR_OK)
23+
#define ini_read(buffer,size,file) f_gets((buffer), (size),(file))
24+
#define ini_write(buffer,file) f_puts((buffer), (file))
25+
#define ini_remove(filename) (f_unlink(filename) == FR_OK)
26+
27+
#define INI_FILEPOS DWORD
28+
#define ini_tell(file,pos) (*(pos) = f_tell((file)))
29+
#define ini_seek(file,pos) (f_lseek((file), *(pos)) == FR_OK)
30+
31+
static int ini_rename(TCHAR *source, const TCHAR *dest)
32+
{
33+
/* Function f_rename() does not allow drive letters in the destination file */
34+
char *drive = strchr(dest, ':');
35+
drive = (drive == NULL) ? dest : drive + 1;
36+
return (f_rename(source, drive) == FR_OK);
37+
}

dev/minGlue-ccs.h

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/* minIni glue functions for FAT library by CCS, Inc. (as provided with their
2+
* PIC MCU compiler)
3+
*
4+
* By CompuPhase, 2011-2012
5+
* This "glue file" is in the public domain. It is distributed without
6+
* warranties or conditions of any kind, either express or implied.
7+
*
8+
* (The FAT library is copyright (c) 2007 Custom Computer Services, and
9+
* licensed at its own terms.)
10+
*/
11+
12+
#define INI_BUFFERSIZE 256 /* maximum line length, maximum path length */
13+
14+
#ifndef FAT_PIC_C
15+
#error FAT library must be included before this module
16+
#endif
17+
#define const /* keyword not supported by CCS */
18+
19+
#define INI_FILETYPE FILE
20+
#define ini_openread(filename,file) (fatopen((filename), "r", (file)) == GOODEC)
21+
#define ini_openwrite(filename,file) (fatopen((filename), "w", (file)) == GOODEC)
22+
#define ini_close(file) (fatclose((file)) == 0)
23+
#define ini_read(buffer,size,file) (fatgets((buffer), (size), (file)) != NULL)
24+
#define ini_write(buffer,file) (fatputs((buffer), (file)) == GOODEC)
25+
#define ini_remove(filename) (rm_file((filename)) == 0)
26+
27+
#define INI_FILEPOS fatpos_t
28+
#define ini_tell(file,pos) (fatgetpos((file), (pos)) == 0)
29+
#define ini_seek(file,pos) (fatsetpos((file), (pos)) == 0)
30+
31+
#ifndef INI_READONLY
32+
/* CCS FAT library lacks a rename function, so instead we copy the file to the
33+
* new name and delete the old file
34+
*/
35+
static int ini_rename(char *source, char *dest)
36+
{
37+
FILE fr, fw;
38+
int n;
39+
40+
if (fatopen(source, "r", &fr) != GOODEC)
41+
return 0;
42+
if (rm_file(dest) != 0)
43+
return 0;
44+
if (fatopen(dest, "w", &fw) != GOODEC)
45+
return 0;
46+
47+
/* With some "insider knowledge", we can save some memory: the "source"
48+
* parameter holds a filename that was built from the "dest" parameter. It
49+
* was built in a local buffer with the size INI_BUFFERSIZE. We can reuse
50+
* this buffer for copying the file.
51+
*/
52+
while (n=fatread(source, 1, INI_BUFFERSIZE, &fr))
53+
fatwrite(source, 1, n, &fw);
54+
55+
fatclose(&fr);
56+
fatclose(&fw);
57+
58+
/* Now we need to delete the source file. However, we have garbled the buffer
59+
* that held the filename of the source. So we need to build it again.
60+
*/
61+
ini_tempname(source, dest, INI_BUFFERSIZE);
62+
return rm_file(source) == 0;
63+
}
64+
#endif

dev/minGlue-efsl.h

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/* Glue functions for the minIni library, based on the EFS Library, see
2+
* http://www.efsl.be/
3+
*
4+
* By CompuPhase, 2008-2012
5+
* This "glue file" is in the public domain. It is distributed without
6+
* warranties or conditions of any kind, either express or implied.
7+
*
8+
* (EFSL is copyright 2005-2006 Lennart Ysboodt and Michael De Nil, and
9+
* licensed under the GPL with an exception clause for static linking.)
10+
*/
11+
12+
#define INI_BUFFERSIZE 256 /* maximum line length, maximum path length */
13+
#define INI_LINETERM "\r\n" /* set line termination explicitly */
14+
15+
#include "efs.h"
16+
extern EmbeddedFileSystem g_efs;
17+
18+
#define INI_FILETYPE EmbeddedFile
19+
#define ini_openread(filename,file) (file_fopen((file), &g_efs.myFs, (char*)(filename), 'r') == 0)
20+
#define ini_openwrite(filename,file) (file_fopen((file), &g_efs.myFs, (char*)(filename), 'w') == 0)
21+
#define ini_close(file) file_fclose(file)
22+
#define ini_read(buffer,size,file) (file_read((file), (size), (buffer)) > 0)
23+
#define ini_write(buffer,file) (file_write((file), strlen(buffer), (char*)(buffer)) > 0)
24+
#define ini_remove(filename) rmfile(&g_efs.myFs, (char*)(filename))
25+
26+
#define INI_FILEPOS euint32
27+
#define ini_tell(file,pos) (*(pos) = (file)->FilePtr))
28+
#define ini_seek(file,pos) file_setpos((file), (*pos))
29+
30+
#if ! defined INI_READONLY
31+
/* EFSL lacks a rename function, so instead we copy the file to the new name
32+
* and delete the old file
33+
*/
34+
static int ini_rename(char *source, const char *dest)
35+
{
36+
EmbeddedFile fr, fw;
37+
int n;
38+
39+
if (file_fopen(&fr, &g_efs.myFs, source, 'r') != 0)
40+
return 0;
41+
if (rmfile(&g_efs.myFs, (char*)dest) != 0)
42+
return 0;
43+
if (file_fopen(&fw, &g_efs.myFs, (char*)dest, 'w') != 0)
44+
return 0;
45+
46+
/* With some "insider knowledge", we can save some memory: the "source"
47+
* parameter holds a filename that was built from the "dest" parameter. It
48+
* was built in buffer and this buffer has the size INI_BUFFERSIZE. We can
49+
* reuse this buffer for copying the file.
50+
*/
51+
while (n=file_read(&fr, INI_BUFFERSIZE, source))
52+
file_write(&fw, n, source);
53+
54+
file_fclose(&fr);
55+
file_fclose(&fw);
56+
57+
/* Now we need to delete the source file. However, we have garbled the buffer
58+
* that held the filename of the source. So we need to build it again.
59+
*/
60+
ini_tempname(source, dest, INI_BUFFERSIZE);
61+
return rmfile(&g_efs.myFs, source) == 0;
62+
}
63+
#endif

dev/minGlue-ffs.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/* Glue functions for the minIni library, based on the "FAT Filing System"
2+
* library by embedded-code.com
3+
*
4+
* By CompuPhase, 2008-2012
5+
* This "glue file" is in the public domain. It is distributed without
6+
* warranties or conditions of any kind, either express or implied.
7+
*
8+
* (The "FAT Filing System" library itself is copyright embedded-code.com, and
9+
* licensed at its own terms.)
10+
*/
11+
12+
#define INI_BUFFERSIZE 256 /* maximum line length, maximum path length */
13+
#include <mem-ffs.h>
14+
15+
#define INI_FILETYPE FFS_FILE*
16+
#define ini_openread(filename,file) ((*(file) = ffs_fopen((filename),"r")) != NULL)
17+
#define ini_openwrite(filename,file) ((*(file) = ffs_fopen((filename),"w")) != NULL)
18+
#define ini_close(file) (ffs_fclose(*(file)) == 0)
19+
#define ini_read(buffer,size,file) (ffs_fgets((buffer),(size),*(file)) != NULL)
20+
#define ini_write(buffer,file) (ffs_fputs((buffer),*(file)) >= 0)
21+
#define ini_rename(source,dest) (ffs_rename((source), (dest)) == 0)
22+
#define ini_remove(filename) (ffs_remove(filename) == 0)
23+
24+
#define INI_FILEPOS long
25+
#define ini_tell(file,pos) (ffs_fgetpos(*(file), (pos)) == 0)
26+
#define ini_seek(file,pos) (ffs_fsetpos(*(file), (pos)) == 0)

dev/minGlue-mdd.h

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/* minIni glue functions for Microchip's "Memory Disk Drive" file system
2+
* library, as presented in Microchip application note AN1045.
3+
*
4+
* By CompuPhase, 2011-2014
5+
* This "glue file" is in the public domain. It is distributed without
6+
* warranties or conditions of any kind, either express or implied.
7+
*
8+
* (The "Microchip Memory Disk Drive File System" is copyright (c) Microchip
9+
* Technology Incorporated, and licensed at its own terms.)
10+
*/
11+
12+
#define INI_BUFFERSIZE 256 /* maximum line length, maximum path length */
13+
14+
#include "MDD File System\fsio.h"
15+
#include <string.h>
16+
17+
#define INI_FILETYPE FSFILE*
18+
#define ini_openread(filename,file) ((*(file) = FSfopen((filename),FS_READ)) != NULL)
19+
#define ini_openwrite(filename,file) ((*(file) = FSfopen((filename),FS_WRITE)) != NULL)
20+
#define ini_openrewrite(filename,file) ((*(file) = fopen((filename),FS_READPLUS)) != NULL)
21+
#define ini_close(file) (FSfclose(*(file)) == 0)
22+
#define ini_write(buffer,file) (FSfwrite((buffer), 1, strlen(buffer), (*file)) > 0)
23+
#define ini_remove(filename) (FSremove((filename)) == 0)
24+
25+
#define INI_FILEPOS long int
26+
#define ini_tell(file,pos) (*(pos) = FSftell(*(file)))
27+
#define ini_seek(file,pos) (FSfseek(*(file), *(pos), SEEK_SET) == 0)
28+
29+
/* Since the Memory Disk Drive file system library reads only blocks of files,
30+
* the function to read a text line does so by "over-reading" a block of the
31+
* of the maximum size and truncating it behind the end-of-line.
32+
*/
33+
static int ini_read(char *buffer, int size, INI_FILETYPE *file)
34+
{
35+
size_t numread = size;
36+
char *eol;
37+
38+
if ((numread = FSfread(buffer, 1, size, *file)) == 0)
39+
return 0; /* at EOF */
40+
if ((eol = strchr(buffer, '\n')) == NULL)
41+
eol = strchr(buffer, '\r');
42+
if (eol != NULL) {
43+
/* terminate the buffer */
44+
*++eol = '\0';
45+
/* "unread" the data that was read too much */
46+
FSfseek(*file, - (int)(numread - (size_t)(eol - buffer)), SEEK_CUR);
47+
} /* if */
48+
return 1;
49+
}
50+
51+
#ifndef INI_READONLY
52+
static int ini_rename(const char *source, const char *dest)
53+
{
54+
FSFILE* ftmp = FSfopen((source), FS_READ);
55+
FSrename((dest), ftmp);
56+
return FSfclose(ftmp) == 0;
57+
}
58+
#endif

dev/minGlue-stdio.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/* Glue functions for the minIni library, based on the C/C++ stdio library
2+
*
3+
* Or better said: this file contains macros that maps the function interface
4+
* used by minIni to the standard C/C++ file I/O functions.
5+
*
6+
* By CompuPhase, 2008-2014
7+
* This "glue file" is in the public domain. It is distributed without
8+
* warranties or conditions of any kind, either express or implied.
9+
*/
10+
11+
/* map required file I/O types and functions to the standard C library */
12+
#include <stdio.h>
13+
14+
#define INI_FILETYPE FILE*
15+
#define ini_openread(filename,file) ((*(file) = fopen((filename),"rb")) != NULL)
16+
#define ini_openwrite(filename,file) ((*(file) = fopen((filename),"wb")) != NULL)
17+
#define ini_openrewrite(filename,file) ((*(file) = fopen((filename),"r+b")) != NULL)
18+
#define ini_close(file) (fclose(*(file)) == 0)
19+
#define ini_read(buffer,size,file) (fgets((buffer),(size),*(file)) != NULL)
20+
#define ini_write(buffer,file) (fputs((buffer),*(file)) >= 0)
21+
#define ini_rename(source,dest) (rename((source), (dest)) == 0)
22+
#define ini_remove(filename) (remove(filename) == 0)
23+
24+
#define INI_FILEPOS long int
25+
#define ini_tell(file,pos) (*(pos) = ftell(*(file)))
26+
#define ini_seek(file,pos) (fseek(*(file), *(pos), SEEK_SET) == 0)
27+
28+
/* for floating-point support, define additional types and functions */
29+
#define INI_REAL float
30+
#define ini_ftoa(string,value) sprintf((string),"%f",(value))
31+
#define ini_atof(string) (INI_REAL)strtod((string),NULL)

dev/minGlue.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/* Glue functions for the minIni library, based on the C/C++ stdio library
2+
*
3+
* Or better said: this file contains macros that maps the function interface
4+
* used by minIni to the standard C/C++ file I/O functions.
5+
*
6+
* By CompuPhase, 2008-2014
7+
* This "glue file" is in the public domain. It is distributed without
8+
* warranties or conditions of any kind, either express or implied.
9+
*/
10+
11+
/* map required file I/O types and functions to the standard C library */
12+
#include <stdio.h>
13+
14+
#define INI_FILETYPE FILE*
15+
#define ini_openread(filename,file) ((*(file) = fopen((filename),"rb")) != NULL)
16+
#define ini_openwrite(filename,file) ((*(file) = fopen((filename),"wb")) != NULL)
17+
#define ini_openrewrite(filename,file) ((*(file) = fopen((filename),"r+b")) != NULL)
18+
#define ini_close(file) (fclose(*(file)) == 0)
19+
#define ini_read(buffer,size,file) (fgets((buffer),(size),*(file)) != NULL)
20+
#define ini_write(buffer,file) (fputs((buffer),*(file)) >= 0)
21+
#define ini_rename(source,dest) (rename((source), (dest)) == 0)
22+
#define ini_remove(filename) (remove(filename) == 0)
23+
24+
#define INI_FILEPOS long int
25+
#define ini_tell(file,pos) (*(pos) = ftell(*(file)))
26+
#define ini_seek(file,pos) (fseek(*(file), *(pos), SEEK_SET) == 0)
27+
28+
/* for floating-point support, define additional types and functions */
29+
#define INI_REAL float
30+
#define ini_ftoa(string,value) sprintf((string),"%f",(value))
31+
#define ini_atof(string) (INI_REAL)strtod((string),NULL)

0 commit comments

Comments
 (0)