rewrite everything
This commit is contained in:
37
Source/sys-clk/sysmodule/lib/minIni/dev/minGlue-FatFs.h
Normal file
37
Source/sys-clk/sysmodule/lib/minIni/dev/minGlue-FatFs.h
Normal file
@@ -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);
|
||||
}
|
||||
64
Source/sys-clk/sysmodule/lib/minIni/dev/minGlue-ccs.h
Normal file
64
Source/sys-clk/sysmodule/lib/minIni/dev/minGlue-ccs.h
Normal file
@@ -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
|
||||
63
Source/sys-clk/sysmodule/lib/minIni/dev/minGlue-efsl.h
Normal file
63
Source/sys-clk/sysmodule/lib/minIni/dev/minGlue-efsl.h
Normal file
@@ -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
|
||||
26
Source/sys-clk/sysmodule/lib/minIni/dev/minGlue-ffs.h
Normal file
26
Source/sys-clk/sysmodule/lib/minIni/dev/minGlue-ffs.h
Normal file
@@ -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)
|
||||
58
Source/sys-clk/sysmodule/lib/minIni/dev/minGlue-mdd.h
Normal file
58
Source/sys-clk/sysmodule/lib/minIni/dev/minGlue-mdd.h
Normal file
@@ -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
|
||||
31
Source/sys-clk/sysmodule/lib/minIni/dev/minGlue-stdio.h
Normal file
31
Source/sys-clk/sysmodule/lib/minIni/dev/minGlue-stdio.h
Normal file
@@ -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)
|
||||
35
Source/sys-clk/sysmodule/lib/minIni/dev/minGlue.h
Normal file
35
Source/sys-clk/sysmodule/lib/minIni/dev/minGlue.h
Normal file
@@ -0,0 +1,35 @@
|
||||
/* 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)
|
||||
|
||||
#define INI_ANSIONLY
|
||||
#define INI_LINETERM "\n"
|
||||
#define PORTABLE_STRNICMP
|
||||
1009
Source/sys-clk/sysmodule/lib/minIni/dev/minIni.c
Normal file
1009
Source/sys-clk/sysmodule/lib/minIni/dev/minIni.c
Normal file
File diff suppressed because it is too large
Load Diff
68
Source/sys-clk/sysmodule/lib/minIni/dev/minIni.h
Normal file
68
Source/sys-clk/sysmodule/lib/minIni/dev/minIni.h
Normal file
@@ -0,0 +1,68 @@
|
||||
/* minIni - Multi-Platform INI file parser, suitable for embedded systems
|
||||
*
|
||||
* Copyright (c) CompuPhase, 2008-2017
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy
|
||||
* of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
* Version: $Id: minIni.h 53 2015-01-18 13:35:11Z thiadmer.riemersma@gmail.com $
|
||||
*/
|
||||
#ifndef MININI_H
|
||||
#define MININI_H
|
||||
|
||||
#include "minGlue.h"
|
||||
|
||||
#if (defined _UNICODE || defined __UNICODE__ || defined UNICODE) && !defined INI_ANSIONLY
|
||||
#include <tchar.h>
|
||||
#define mTCHAR TCHAR
|
||||
#else
|
||||
/* force TCHAR to be "char", but only for minIni */
|
||||
#define mTCHAR char
|
||||
#endif
|
||||
|
||||
#if !defined INI_BUFFERSIZE
|
||||
#define INI_BUFFERSIZE 512
|
||||
#endif
|
||||
|
||||
#if defined __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int ini_getbool(const mTCHAR *Section, const mTCHAR *Key, int DefValue, const mTCHAR *Filename);
|
||||
long ini_getl(const mTCHAR *Section, const mTCHAR *Key, long DefValue, const mTCHAR *Filename);
|
||||
int ini_gets(const mTCHAR *Section, const mTCHAR *Key, const mTCHAR *DefValue, mTCHAR *Buffer, int BufferSize, const mTCHAR *Filename);
|
||||
int ini_getsection(int idx, mTCHAR *Buffer, int BufferSize, const mTCHAR *Filename);
|
||||
int ini_getkey(const mTCHAR *Section, int idx, mTCHAR *Buffer, int BufferSize, const mTCHAR *Filename);
|
||||
|
||||
#if defined INI_REAL
|
||||
INI_REAL ini_getf(const mTCHAR *Section, const mTCHAR *Key, INI_REAL DefValue, const mTCHAR *Filename);
|
||||
#endif
|
||||
|
||||
#if !defined INI_READONLY
|
||||
int ini_putl(const mTCHAR *Section, const mTCHAR *Key, long Value, const mTCHAR *Filename);
|
||||
int ini_puts(const mTCHAR *Section, const mTCHAR *Key, const mTCHAR *Value, const mTCHAR *Filename);
|
||||
int ini_putsection(const mTCHAR *Section, const mTCHAR **Keys, const mTCHAR **Values, const mTCHAR *Filename);
|
||||
#if defined INI_REAL
|
||||
int ini_putf(const mTCHAR *Section, const mTCHAR *Key, INI_REAL Value, const mTCHAR *Filename);
|
||||
#endif
|
||||
#endif /* INI_READONLY */
|
||||
|
||||
#if !defined INI_NOBROWSE
|
||||
typedef int (*INI_CALLBACK)(const mTCHAR *Section, const mTCHAR *Key, const mTCHAR *Value, void *UserData);
|
||||
int ini_browse(INI_CALLBACK Callback, void *UserData, const mTCHAR *Filename);
|
||||
#endif /* INI_NOBROWSE */
|
||||
|
||||
#if defined __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* MININI_H */
|
||||
117
Source/sys-clk/sysmodule/lib/minIni/dev/test.c
Normal file
117
Source/sys-clk/sysmodule/lib/minIni/dev/test.c
Normal file
@@ -0,0 +1,117 @@
|
||||
/* Simple test program
|
||||
*
|
||||
* gcc -o test test.c minIni.c
|
||||
*/
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "minIni.h"
|
||||
|
||||
#define sizearray(a) (sizeof(a) / sizeof((a)[0]))
|
||||
|
||||
const char inifile[] = "test.ini";
|
||||
const char inifile2[] = "testplain.ini";
|
||||
|
||||
int Callback(const char *section, const char *key, const char *value, void *userdata)
|
||||
{
|
||||
(void)userdata; /* this parameter is not used in this example */
|
||||
printf(" [%s]\t%s=%s\n", section, key, value);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
char str[100];
|
||||
long n;
|
||||
int s, k;
|
||||
char section[50];
|
||||
|
||||
/* string reading */
|
||||
n = ini_gets("first", "string", "dummy", str, sizearray(str), inifile);
|
||||
assert(n==4 && strcmp(str,"noot")==0);
|
||||
n = ini_gets("second", "string", "dummy", str, sizearray(str), inifile);
|
||||
assert(n==4 && strcmp(str,"mies")==0);
|
||||
n = ini_gets("first", "undefined", "dummy", str, sizearray(str), inifile);
|
||||
assert(n==5 && strcmp(str,"dummy")==0);
|
||||
/* ----- */
|
||||
n = ini_gets("", "string", "dummy", str, sizearray(str), inifile2);
|
||||
assert(n==4 && strcmp(str,"noot")==0);
|
||||
n = ini_gets(NULL, "string", "dummy", str, sizearray(str), inifile2);
|
||||
assert(n==4 && strcmp(str,"noot")==0);
|
||||
/* ----- */
|
||||
printf("1. String reading tests passed\n");
|
||||
|
||||
/* value reading */
|
||||
n = ini_getl("first", "val", -1, inifile);
|
||||
assert(n==1);
|
||||
n = ini_getl("second", "val", -1, inifile);
|
||||
assert(n==2);
|
||||
n = ini_getl("first", "undefined", -1, inifile);
|
||||
assert(n==-1);
|
||||
/* ----- */
|
||||
n = ini_getl(NULL, "val", -1, inifile2);
|
||||
assert(n==1);
|
||||
/* ----- */
|
||||
printf("2. Value reading tests passed\n");
|
||||
|
||||
/* string writing */
|
||||
n = ini_puts("first", "alt", "flagged as \"correct\"", inifile);
|
||||
assert(n==1);
|
||||
n = ini_gets("first", "alt", "dummy", str, sizearray(str), inifile);
|
||||
assert(n==20 && strcmp(str,"flagged as \"correct\"")==0);
|
||||
/* ----- */
|
||||
n = ini_puts("second", "alt", "correct", inifile);
|
||||
assert(n==1);
|
||||
n = ini_gets("second", "alt", "dummy", str, sizearray(str), inifile);
|
||||
assert(n==7 && strcmp(str,"correct")==0);
|
||||
/* ----- */
|
||||
n = ini_puts("third", "test", "correct", inifile);
|
||||
assert(n==1);
|
||||
n = ini_gets("third", "test", "dummy", str, sizearray(str), inifile);
|
||||
assert(n==7 && strcmp(str,"correct")==0);
|
||||
/* ----- */
|
||||
n = ini_puts("second", "alt", "overwrite", inifile);
|
||||
assert(n==1);
|
||||
n = ini_gets("second", "alt", "dummy", str, sizearray(str), inifile);
|
||||
assert(n==9 && strcmp(str,"overwrite")==0);
|
||||
/* ----- */
|
||||
n = ini_puts("second", "alt", "123456789", inifile);
|
||||
assert(n==1);
|
||||
n = ini_gets("second", "alt", "dummy", str, sizearray(str), inifile);
|
||||
assert(n==9 && strcmp(str,"123456789")==0);
|
||||
/* ----- */
|
||||
n = ini_puts(NULL, "alt", "correct", inifile2);
|
||||
assert(n==1);
|
||||
n = ini_gets(NULL, "alt", "dummy", str, sizearray(str), inifile2);
|
||||
assert(n==7 && strcmp(str,"correct")==0);
|
||||
/* ----- */
|
||||
printf("3. String writing tests passed\n");
|
||||
|
||||
/* section/key enumeration */
|
||||
printf("4. Section/key enumeration, file structure follows\n");
|
||||
for (s = 0; ini_getsection(s, section, sizearray(section), inifile) > 0; s++) {
|
||||
printf(" [%s]\n", section);
|
||||
for (k = 0; ini_getkey(section, k, str, sizearray(str), inifile) > 0; k++) {
|
||||
printf("\t%s\n", str);
|
||||
} /* for */
|
||||
} /* for */
|
||||
|
||||
/* browsing through the file */
|
||||
printf("5. browse through all settings, file field list follows\n");
|
||||
ini_browse(Callback, NULL, inifile);
|
||||
|
||||
/* string deletion */
|
||||
n = ini_puts("first", "alt", NULL, inifile);
|
||||
assert(n==1);
|
||||
n = ini_puts("second", "alt", NULL, inifile);
|
||||
assert(n==1);
|
||||
n = ini_puts("third", NULL, NULL, inifile);
|
||||
assert(n==1);
|
||||
/* ----- */
|
||||
n = ini_puts(NULL, "alt", NULL, inifile2);
|
||||
assert(n==1);
|
||||
printf("6. String deletion tests passed\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
8
Source/sys-clk/sysmodule/lib/minIni/dev/test.ini
Normal file
8
Source/sys-clk/sysmodule/lib/minIni/dev/test.ini
Normal file
@@ -0,0 +1,8 @@
|
||||
[First]
|
||||
String=noot # trailing commment
|
||||
Val=1
|
||||
|
||||
[Second]
|
||||
Val = 2
|
||||
#comment=3
|
||||
String = mies
|
||||
80
Source/sys-clk/sysmodule/lib/minIni/dev/test2.cc
Normal file
80
Source/sys-clk/sysmodule/lib/minIni/dev/test2.cc
Normal file
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
gcc -o minIni.o -c minIni.c
|
||||
g++ -o test2.o -c test2.cc
|
||||
g++ -o test2 test2.o minIni.o
|
||||
./test2
|
||||
*/
|
||||
|
||||
|
||||
#include <assert>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
using namespace std ;
|
||||
|
||||
#include "minIni.h"
|
||||
|
||||
int main(void)
|
||||
{
|
||||
minIni ini("test.ini");
|
||||
string s;
|
||||
|
||||
/* string reading */
|
||||
s = ini.gets( "first", "string" , "aap" );
|
||||
assert(s == "noot");
|
||||
s = ini.gets( "second", "string" , "aap" );
|
||||
assert(s == "mies");
|
||||
s = ini.gets( "first", "dummy" , "aap" );
|
||||
assert(s == "aap");
|
||||
cout << "1. String reading tests passed" << endl ;
|
||||
|
||||
|
||||
/* value reading */
|
||||
long n;
|
||||
n = ini.getl("first", "val", -1 );
|
||||
assert(n==1);
|
||||
n = ini.getl("second", "val", -1);
|
||||
assert(n==2);
|
||||
n = ini.getl("first", "dummy", -1);
|
||||
assert(n==-1);
|
||||
cout << "2. Value reading tests passed" << endl ;
|
||||
|
||||
|
||||
/* string writing */
|
||||
bool b;
|
||||
b = ini.put("first", "alt", "flagged as \"correct\"");
|
||||
assert(b);
|
||||
s = ini.gets("first", "alt", "aap");
|
||||
assert(s=="flagged as \"correct\"");
|
||||
|
||||
b = ini.put("second", "alt", "correct");
|
||||
assert(b);
|
||||
s = ini.gets("second", "alt", "aap");
|
||||
assert(s=="correct");
|
||||
|
||||
b = ini.put("third", "alt", "correct");
|
||||
assert(b);
|
||||
s = ini.gets("third", "alt", "aap" );
|
||||
assert(s=="correct");
|
||||
cout << "3. String writing tests passed" << endl;
|
||||
|
||||
/* section/key enumeration */
|
||||
cout << "4. section/key enumeration; file contents follows" << endl;
|
||||
string section;
|
||||
for (int is = 0; section = ini.getsection(is), section.length() > 0; is++) {
|
||||
cout << " [" << section.c_str() << "]" << endl;
|
||||
for (int ik = 0; s = ini.getkey(section, ik), s.length() > 0; ik++) {
|
||||
cout << "\t" << s.c_str() << endl;
|
||||
}
|
||||
}
|
||||
|
||||
/* string deletion */
|
||||
b = ini.del("first", "alt");
|
||||
assert(b);
|
||||
b = ini.del("second", "alt");
|
||||
assert(b);
|
||||
b = ini.del("third");
|
||||
assert(b);
|
||||
cout << "5. string deletion passed " << endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
3
Source/sys-clk/sysmodule/lib/minIni/dev/testplain.ini
Normal file
3
Source/sys-clk/sysmodule/lib/minIni/dev/testplain.ini
Normal file
@@ -0,0 +1,3 @@
|
||||
String=noot # trailing commment
|
||||
#comment=3
|
||||
Val=1
|
||||
101
Source/sys-clk/sysmodule/lib/minIni/dev/wxMinIni.h
Normal file
101
Source/sys-clk/sysmodule/lib/minIni/dev/wxMinIni.h
Normal file
@@ -0,0 +1,101 @@
|
||||
/* minIni - Multi-Platform INI file parser, wxWidgets interface
|
||||
*
|
||||
* Copyright (c) CompuPhase, 2008-2012
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy
|
||||
* of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
* Version: $Id: wxMinIni.h 44 2012-01-04 15:52:56Z thiadmer.riemersma@gmail.com $
|
||||
*/
|
||||
#ifndef WXMININI_H
|
||||
#define WXMININI_H
|
||||
|
||||
#include <wx/wx.h>
|
||||
#include "minIni.h"
|
||||
|
||||
class minIni
|
||||
{
|
||||
public:
|
||||
minIni(const wxString& filename) : iniFilename(filename)
|
||||
{ }
|
||||
|
||||
bool getbool(const wxString& Section, const wxString& Key, bool DefValue=false) const
|
||||
{ return ini_getbool(Section.utf8_str(), Key.utf8_str(), int(DefValue), iniFilename.utf8_str()) != 0; }
|
||||
|
||||
long getl(const wxString& Section, const wxString& Key, long DefValue=0) const
|
||||
{ return ini_getl(Section.utf8_str(), Key.utf8_str(), DefValue, iniFilename.utf8_str()); }
|
||||
|
||||
int geti(const wxString& Section, const wxString& Key, int DefValue=0) const
|
||||
{ return static_cast<int>(ini_getl(Section.utf8_str(), Key.utf8_str(), (long)DefValue, iniFilename.utf8_str())); }
|
||||
|
||||
wxString gets(const wxString& Section, const wxString& Key, const wxString& DefValue=wxT("")) const
|
||||
{
|
||||
char buffer[INI_BUFFERSIZE];
|
||||
ini_gets(Section.utf8_str(), Key.utf8_str(), DefValue.utf8_str(), buffer, INI_BUFFERSIZE, iniFilename.utf8_str());
|
||||
wxString result = wxString::FromUTF8(buffer);
|
||||
return result;
|
||||
}
|
||||
|
||||
wxString getsection(int idx) const
|
||||
{
|
||||
char buffer[INI_BUFFERSIZE];
|
||||
ini_getsection(idx, buffer, INI_BUFFERSIZE, iniFilename.utf8_str());
|
||||
wxString result = wxString::FromUTF8(buffer);
|
||||
return result;
|
||||
}
|
||||
|
||||
wxString getkey(const wxString& Section, int idx) const
|
||||
{
|
||||
char buffer[INI_BUFFERSIZE];
|
||||
ini_getkey(Section.utf8_str(), idx, buffer, INI_BUFFERSIZE, iniFilename.utf8_str());
|
||||
wxString result = wxString::FromUTF8(buffer);
|
||||
return result;
|
||||
}
|
||||
|
||||
#if defined INI_REAL
|
||||
INI_REAL getf(const wxString& Section, wxString& Key, INI_REAL DefValue=0) const
|
||||
{ return ini_getf(Section.utf8_str(), Key.utf8_str(), DefValue, iniFilename.utf8_str()); }
|
||||
#endif
|
||||
|
||||
#if ! defined INI_READONLY
|
||||
bool put(const wxString& Section, const wxString& Key, long Value) const
|
||||
{ return ini_putl(Section.utf8_str(), Key.utf8_str(), Value, iniFilename.utf8_str()) != 0; }
|
||||
|
||||
bool put(const wxString& Section, const wxString& Key, int Value) const
|
||||
{ return ini_putl(Section.utf8_str(), Key.utf8_str(), (long)Value, iniFilename.utf8_str()) != 0; }
|
||||
|
||||
bool put(const wxString& Section, const wxString& Key, bool Value) const
|
||||
{ return ini_putl(Section.utf8_str(), Key.utf8_str(), (long)Value, iniFilename.utf8_str()) != 0; }
|
||||
|
||||
bool put(const wxString& Section, const wxString& Key, const wxString& Value) const
|
||||
{ return ini_puts(Section.utf8_str(), Key.utf8_str(), Value.utf8_str(), iniFilename.utf8_str()) != 0; }
|
||||
|
||||
bool put(const wxString& Section, const wxString& Key, const char* Value) const
|
||||
{ return ini_puts(Section.utf8_str(), Key.utf8_str(), Value, iniFilename.utf8_str()) != 0; }
|
||||
|
||||
#if defined INI_REAL
|
||||
bool put(const wxString& Section, const wxString& Key, INI_REAL Value) const
|
||||
{ return ini_putf(Section.utf8_str(), Key.utf8_str(), Value, iniFilename.utf8_str()) != 0; }
|
||||
#endif
|
||||
|
||||
bool del(const wxString& Section, const wxString& Key) const
|
||||
{ return ini_puts(Section.utf8_str(), Key.utf8_str(), 0, iniFilename.utf8_str()) != 0; }
|
||||
|
||||
bool del(const wxString& Section) const
|
||||
{ return ini_puts(Section.utf8_str(), 0, 0, iniFilename.utf8_str()) != 0; }
|
||||
#endif
|
||||
|
||||
private:
|
||||
wxString iniFilename;
|
||||
};
|
||||
|
||||
#endif /* WXMININI_H */
|
||||
Reference in New Issue
Block a user