feat: added PicoW_Sensor code template
Credits to @ext-erich.styger that provided the template
This commit is contained in:
committed by
Sylvan Arnold
parent
b2e9eab44e
commit
6cd510e749
563
TSM_PicoW_Sensor/McuLib/minIni/McuMinINI.c
Normal file
563
TSM_PicoW_Sensor/McuLib/minIni/McuMinINI.c
Normal file
@@ -0,0 +1,563 @@
|
||||
/* ###################################################################
|
||||
** This component module is generated by Processor Expert. Do not modify it.
|
||||
** Filename : McuMinINI.h
|
||||
** Project : FRDM-K64F_Generator
|
||||
** Processor : MK64FN1M0VLL12
|
||||
** Component : minIni
|
||||
** Version : Component 01.060, Driver 01.00, CPU db: 3.00.000
|
||||
** Compiler : GNU C Compiler
|
||||
** Date/Time : 2022-01-22, 12:01, # CodeGen: 775
|
||||
** Abstract :
|
||||
** minIni is a programmer<65>s library to read and write ini files in embedded systems.
|
||||
** Settings :
|
||||
** Component name : McuMinINI
|
||||
** minIni Version : 1.4
|
||||
** SDK : McuLib
|
||||
** Portable strnicmp() : yes
|
||||
** Use Real : no
|
||||
** Read Only : no
|
||||
** No Debug : yes
|
||||
** FatFS : Disabled
|
||||
** Source Folders :
|
||||
** Source Folder : minIni
|
||||
** Config Folder : minIni
|
||||
** Contents :
|
||||
** ini_getbool - int McuMinINI_ini_getbool(const mTCHAR *Section, const mTCHAR *Key, int...
|
||||
** ini_gets - int McuMinINI_ini_gets(const mTCHAR *Section, const mTCHAR *Key, const mTCHAR...
|
||||
** ini_puts - int McuMinINI_ini_puts(const mTCHAR *Section, const mTCHAR *Key, const mTCHAR...
|
||||
** ini_getl - long McuMinINI_ini_getl(const mTCHAR *Section, const mTCHAR *Key, long...
|
||||
** ini_putl - int McuMinINI_ini_putl(const mTCHAR *Section, const mTCHAR *Key, long Value,...
|
||||
** ini_hassection - int McuMinINI_ini_hassection(const mTCHAR *Section, const mTCHAR *Filename);
|
||||
** ini_getsection - int McuMinINI_ini_getsection(int idx, mTCHAR *Buffer, int BufferSize, const...
|
||||
** ini_haskey - int McuMinINI_ini_haskey(const mTCHAR *Section, const mTCHAR *Key, const...
|
||||
** ini_getkey - int McuMinINI_ini_getkey(const mTCHAR *Section, int idx, mTCHAR *Buffer, int...
|
||||
** ini_browse - int McuMinINI_ini_browse(INI_CALLBACK Callback, const void *UserData, const...
|
||||
** ParseCommand - uint8_t McuMinINI_ParseCommand(const unsigned char *cmd, bool *handled, const...
|
||||
** Deinit - void McuMinINI_Deinit(void);
|
||||
** Init - void McuMinINI_Init(void);
|
||||
**
|
||||
** (c) Copyright 2008-2021, CompuPhase;
|
||||
** http : www.compuphase.com
|
||||
** Processor Expert port: Erich Styger, 2014-2022, http://www.mcuoneclipse.com
|
||||
** License: See miniIni_LICENSE.txt and minIni_NOTICE.txt
|
||||
** Adaptions for Processor Expert: (c) Copyright 2012-2020, Erich Styger
|
||||
** ###################################################################*/
|
||||
/*!
|
||||
** @file McuMinINI.h
|
||||
** @version 01.00
|
||||
** @brief
|
||||
** minIni is a programmer<65>s library to read and write ini files in embedded systems.
|
||||
*/
|
||||
/*!
|
||||
** @addtogroup McuMinINI_module McuMinINI module documentation
|
||||
** @{
|
||||
*/
|
||||
|
||||
/* MODULE McuMinINI. */
|
||||
|
||||
#include "McuMinINI.h"
|
||||
#include "McuUtility.h" /* various utility functions */
|
||||
|
||||
|
||||
#if McuMinINI_CONFIG_PARSE_COMMAND_ENABLED
|
||||
static uint8_t PrintStatus(const McuShell_StdIOType *io) {
|
||||
uint8_t buf[16];
|
||||
|
||||
McuShell_SendStatusStr((unsigned char*)"McuMinINI", (unsigned char*)"MinINI status\r\n", io->stdOut);
|
||||
McuUtility_Num32uToStr(buf, sizeof(buf), INI_BUFFERSIZE);
|
||||
McuUtility_strcat(buf, sizeof(buf), (unsigned char*)" bytes\r\n");
|
||||
McuShell_SendStatusStr((unsigned char*)" buffer", buf, io->stdOut);
|
||||
|
||||
#if defined(INI_REAL)
|
||||
McuUtility_strcpy(buf, sizeof(buf), (unsigned char*)"supported\r\n");
|
||||
#else
|
||||
McuUtility_strcpy(buf, sizeof(buf), (unsigned char*)"not supported\r\n");
|
||||
#endif
|
||||
McuShell_SendStatusStr((unsigned char*)" real", buf, io->stdOut);
|
||||
|
||||
#if McuMinINI_CONFIG_READ_ONLY
|
||||
McuUtility_strcpy(buf, sizeof(buf), (unsigned char*)"read-only\r\n");
|
||||
#else
|
||||
McuUtility_strcpy(buf, sizeof(buf), (unsigned char*)"read-write\r\n");
|
||||
#endif
|
||||
McuShell_SendStatusStr((unsigned char*)" mode", buf, io->stdOut);
|
||||
|
||||
switch(McuMinINI_CONFIG_FS) {
|
||||
case McuMinINI_CONFIG_FS_TYPE_GENERIC:
|
||||
McuUtility_strcpy(buf, sizeof(buf), (unsigned char*)"Generic\r\n"); break;
|
||||
case McuMinINI_CONFIG_FS_TYPE_TINY_FS:
|
||||
McuUtility_strcpy(buf, sizeof(buf), (unsigned char*)"TinyFS\r\n"); break;
|
||||
case McuMinINI_CONFIG_FS_TYPE_FAT_FS:
|
||||
McuUtility_strcpy(buf, sizeof(buf), (unsigned char*)"FatFS\r\n"); break;
|
||||
case McuMinINI_CONFIG_FS_TYPE_FLASH_FS:
|
||||
McuUtility_strcpy(buf, sizeof(buf), (unsigned char*)"FLASH\r\n"); break;
|
||||
case McuMinINI_CONFIG_FS_TYPE_LITTLE_FS:
|
||||
McuUtility_strcpy(buf, sizeof(buf), (unsigned char*)"littleFS\r\n"); break;
|
||||
default:
|
||||
McuUtility_strcpy(buf, sizeof(buf), (unsigned char*)"unknown\r\n"); break;
|
||||
}
|
||||
McuShell_SendStatusStr((unsigned char*)" FS", buf, io->stdOut);
|
||||
return ERR_OK;
|
||||
}
|
||||
#endif
|
||||
/*
|
||||
** ===================================================================
|
||||
** Method : ini_getkey (component minIni)
|
||||
**
|
||||
** Description :
|
||||
** Return the key inside a section
|
||||
** Parameters :
|
||||
** NAME - DESCRIPTION
|
||||
** * Section - The name of the section to browse
|
||||
** through, or NULL to browse through the keys
|
||||
** outside any section
|
||||
** idx - The zero-based sequence number of the key
|
||||
** to return
|
||||
** * Buffer - A pointer to the buffer to copy into
|
||||
** BufferSize - The maximum number of
|
||||
** characters to copy
|
||||
** * Filename - The name and full path of the .
|
||||
** ini file to read from
|
||||
** Returns :
|
||||
** --- - The number of characters copied into the
|
||||
** supplied buffer
|
||||
** ===================================================================
|
||||
*/
|
||||
/**
|
||||
int McuMinINI_ini_getkey(const mTCHAR *Section, int idx, mTCHAR *Buffer, int BufferSize, const mTCHAR *Filename)
|
||||
{
|
||||
Implemented as macro in the header file
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
** ===================================================================
|
||||
** Method : ini_getbool (component minIni)
|
||||
**
|
||||
** Description :
|
||||
** Return a boolean key. A true boolean is found if one of the
|
||||
** following is matched:
|
||||
** - A string starting with 'y' or 'Y'
|
||||
** - A string starting with 't' or 'T'
|
||||
** - A string starting with '1'
|
||||
** A false boolean is found if one of the following is matched:
|
||||
** - A string starting with 'n' or 'N'
|
||||
** - A string starting with 'f' or 'F'
|
||||
** - A string starting with '0'
|
||||
** Parameters :
|
||||
** NAME - DESCRIPTION
|
||||
** * Section - The name of the section to search
|
||||
** for
|
||||
** * Key - The name of the entry to find the value of
|
||||
** DefValue - Default value in the event of a
|
||||
** failed read; it should be zero (0) or one
|
||||
** (1).
|
||||
** * Filename - The name and full path of the .
|
||||
** ini file to read from
|
||||
** Returns :
|
||||
** --- - The true/false flag as interpreted at Key
|
||||
** ===================================================================
|
||||
*/
|
||||
/**
|
||||
int McuMinINI_ini_getbool(const mTCHAR *Section, const mTCHAR *Key, int DefValue, const mTCHAR *Filename)
|
||||
{
|
||||
Implemented as macro in the header file
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
** ===================================================================
|
||||
** Method : ini_gets (component minIni)
|
||||
**
|
||||
** Description :
|
||||
** Return the string for a given section and key.
|
||||
** Parameters :
|
||||
** NAME - DESCRIPTION
|
||||
** * Section - The name of the section to search
|
||||
** for
|
||||
** * Key - Pointer to the name of the entry to find
|
||||
** the value of
|
||||
** * DefValue - Pointer to the default value in
|
||||
** the event of a failed read
|
||||
** * Buffer - A pointer to the buffer to copy into
|
||||
** BufferSize - The maximum number of
|
||||
** characters to copy
|
||||
** * Filename - The name and full path of the .
|
||||
** ini file to read from
|
||||
** Returns :
|
||||
** --- - The number of characters copied into the
|
||||
** supplied buffer
|
||||
** ===================================================================
|
||||
*/
|
||||
/**
|
||||
int McuMinINI_ini_gets(const mTCHAR *Section, const mTCHAR *Key, const mTCHAR *DefValue, nTCHAR *Buffer, int BufferSize, const mTCHAR *Filename)
|
||||
{
|
||||
Implemented as macro in the header file
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
** ===================================================================
|
||||
** Method : ini_getl (component minIni)
|
||||
**
|
||||
** Description :
|
||||
** Return the long integral value for a given section and key.
|
||||
** Parameters :
|
||||
** NAME - DESCRIPTION
|
||||
** * Section - The name of the section to search
|
||||
** for
|
||||
** * Key - Pointer to the name of the entry to find
|
||||
** the value of
|
||||
** DefValue - Default value in the event of a
|
||||
** failed read
|
||||
** * Filename - The name and full path of the .
|
||||
** ini file to read from
|
||||
** Returns :
|
||||
** --- - The value located at Key
|
||||
** ===================================================================
|
||||
*/
|
||||
/**
|
||||
long McuMinINI_ini_getl(const mTCHAR *Section, const mTCHAR *Key, long DefValue, const mTCHAR *Filename)
|
||||
{
|
||||
Implemented as macro in the header file
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
** ===================================================================
|
||||
** Method : ini_getsection (component minIni)
|
||||
**
|
||||
** Description :
|
||||
** Return the key inside a section
|
||||
** Parameters :
|
||||
** NAME - DESCRIPTION
|
||||
** idx - The zero-based sequence number of the
|
||||
** section to return
|
||||
** * Buffer - A pointer to the buffer to copy into
|
||||
** BufferSize - The maximum number of
|
||||
** characters to copy
|
||||
** * Filename - The name and full path of the .
|
||||
** ini file to read from
|
||||
** Returns :
|
||||
** --- - The number of characters copied into the
|
||||
** supplied buffer
|
||||
** ===================================================================
|
||||
*/
|
||||
/**
|
||||
int McuMinINI_ini_getsection(int idx, mTCHAR *Buffer, int BufferSize, const mTCHAR *Filename)
|
||||
{
|
||||
Implemented as macro in the header file
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
** ===================================================================
|
||||
** Method : ini_putl (component minIni)
|
||||
**
|
||||
** Description :
|
||||
** Writes a long integral value for a given section and key.
|
||||
** Method is only enabled if 'Read only' is set to 'no' in the
|
||||
** properties.
|
||||
** Parameters :
|
||||
** NAME - DESCRIPTION
|
||||
** * Section - The name of the section to write
|
||||
** the value in
|
||||
** * Key - The name of the entry to write
|
||||
** Value - The value to write
|
||||
** * Filename - The name and full path of the .
|
||||
** ini file to write to
|
||||
** Returns :
|
||||
** --- - 1 if successful, otherwise 0
|
||||
** ===================================================================
|
||||
*/
|
||||
/**
|
||||
int McuMinINI_ini_putl(const mTCHAR *Section, const mTCHAR *Key, long Value, const mTCHAR *Filename)
|
||||
{
|
||||
Implemented as macro in the header file
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
** ===================================================================
|
||||
** Method : ini_puts (component minIni)
|
||||
**
|
||||
** Description :
|
||||
** Writes a string value for a given section and key. Method is
|
||||
** only enabled if 'Read only' is set to 'no' in the
|
||||
** properties.
|
||||
** Parameters :
|
||||
** NAME - DESCRIPTION
|
||||
** * Section - The name of the section to write
|
||||
** the string in
|
||||
** * Key - The name of the entry to write
|
||||
** * Value - Pointer to the buffer the string, or
|
||||
** NULL to erase the key
|
||||
** * Filename - The name and full path of the .
|
||||
** ini file to write to
|
||||
** Returns :
|
||||
** --- - 1 if successful, otherwise 0
|
||||
** ===================================================================
|
||||
*/
|
||||
/**
|
||||
int McuMinINI_ini_puts(const mTCHAR *Section, const mTCHAR *Key, const mTCHAR *Value, const mTCHAR *Filename)
|
||||
{
|
||||
Implemented as macro in the header file
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
** ===================================================================
|
||||
** Method : ini_browse (component minIni)
|
||||
**
|
||||
** Description :
|
||||
** Function to browse the ini file. With this function the file
|
||||
** is opened only once.
|
||||
** Parameters :
|
||||
** NAME - DESCRIPTION
|
||||
** Callback - a pointer to a function that
|
||||
** will be called for every setting in the INI
|
||||
** file.
|
||||
** UserData - arbitrary data, which the
|
||||
** function passes on the the Callback function
|
||||
** Filename - the name and full path of the .
|
||||
** ini file to read from
|
||||
** Returns :
|
||||
** --- - 1 on success, 0 on failure (INI file not
|
||||
** found)
|
||||
** ===================================================================
|
||||
*/
|
||||
/**
|
||||
int McuMinINI_ini_browse(INI_CALLBACK Callback, const void *UserData, const TCHAR *Filename)
|
||||
{
|
||||
Implemented as macro in the header file
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
** ===================================================================
|
||||
** Method : ParseCommand (component minIni)
|
||||
**
|
||||
** Description :
|
||||
** Shell Command Line parser
|
||||
** Parameters :
|
||||
** NAME - DESCRIPTION
|
||||
** * cmd - Pointer to command line
|
||||
** * handled - Pointer to variable which tells if
|
||||
** the command has been handled or not
|
||||
** * io - Pointer to I/O structure
|
||||
** Returns :
|
||||
** --- - Error code
|
||||
** ===================================================================
|
||||
*/
|
||||
uint8_t McuMinINI_ParseCommand(const unsigned char *cmd, bool *handled, const McuShell_StdIOType *io)
|
||||
{
|
||||
const unsigned char *p;
|
||||
unsigned char section[48], key[48], value[96], fileName[64];
|
||||
size_t lenRead;
|
||||
|
||||
if (McuUtility_strcmp((char*)cmd, McuShell_CMD_HELP)==0 || McuUtility_strcmp((char*)cmd, "McuMinINI help")==0) {
|
||||
McuShell_SendHelpStr((unsigned char*)"McuMinINI", (const unsigned char*)"Group of McuMinINI commands\r\n", io->stdOut);
|
||||
McuShell_SendHelpStr((unsigned char*)" help|status", (unsigned char*)"Print help or status information\r\n", io->stdOut);
|
||||
McuShell_SendHelpStr((unsigned char*)" read <f> <s> <k>", (const unsigned char*)"Read a key from a section in a file\r\n", io->stdOut);
|
||||
#if !McuMinINI_CONFIG_READ_ONLY
|
||||
McuShell_SendHelpStr((unsigned char*)" write <f> <s> <k> <v>", (const unsigned char*)"Write a key with value to a section in a file\r\n", io->stdOut);
|
||||
McuShell_SendHelpStr((unsigned char*)" delkey <f> <s> <k>", (const unsigned char*)"Delete a key in a section of file\r\n", io->stdOut);
|
||||
McuShell_SendHelpStr((unsigned char*)" delsec <f> <s>", (const unsigned char*)"Delete a section in a file\r\n", io->stdOut);
|
||||
#endif
|
||||
*handled = TRUE;
|
||||
return ERR_OK;
|
||||
} else if ((McuUtility_strcmp((char*)cmd, McuShell_CMD_STATUS)==0) || (McuUtility_strcmp((char*)cmd, "McuMinINI status")==0)) {
|
||||
*handled = TRUE;
|
||||
return PrintStatus(io);
|
||||
} else if (McuUtility_strncmp((char*)cmd, "McuMinINI read ", sizeof("McuMinINI read ")-1)==0) {
|
||||
*handled = TRUE;
|
||||
p = cmd + sizeof("McuMinINI read ")-1;
|
||||
if (McuUtility_ReadEscapedName(p, fileName, sizeof(fileName), &lenRead, NULL, NULL)!=ERR_OK || lenRead==0) {
|
||||
return ERR_FAILED;
|
||||
}
|
||||
p += lenRead;
|
||||
McuUtility_SkipSpaces(&p);
|
||||
if (McuUtility_ReadEscapedName(p, section, sizeof(section), &lenRead, NULL, NULL)!=ERR_OK || lenRead==0) {
|
||||
return ERR_FAILED;
|
||||
}
|
||||
p += lenRead;
|
||||
McuUtility_SkipSpaces(&p);
|
||||
if (McuUtility_ReadEscapedName(p, key, sizeof(key), &lenRead, NULL, NULL)!=ERR_OK || lenRead==0) {
|
||||
return ERR_FAILED;
|
||||
}
|
||||
p += lenRead;
|
||||
if (*p != '\0') { /* still some arguments? */
|
||||
return ERR_FAILED;
|
||||
}
|
||||
if (ini_gets((const TCHAR *)section, (const TCHAR *)key, (const TCHAR *)"", (TCHAR *)value, sizeof(value), (const TCHAR *)fileName) == 0) {
|
||||
return ERR_FAILED;
|
||||
}
|
||||
McuShell_SendStr(key, io->stdOut);
|
||||
McuShell_SendStr((unsigned char*)"=", io->stdOut);
|
||||
McuShell_SendStr(value, io->stdOut);
|
||||
McuShell_SendStr((unsigned char*)"\r\n", io->stdOut);
|
||||
return ERR_OK;
|
||||
#if !McuMinINI_CONFIG_READ_ONLY
|
||||
} else if (McuUtility_strncmp((char*)cmd, "McuMinINI write ", sizeof("McuMinINI write ")-1)==0) {
|
||||
*handled = TRUE;
|
||||
p = cmd + sizeof("McuMinINI write ")-1;
|
||||
if (McuUtility_ReadEscapedName(p, fileName, sizeof(fileName), &lenRead, NULL, NULL)!=ERR_OK || lenRead==0) {
|
||||
return ERR_FAILED;
|
||||
}
|
||||
p += lenRead;
|
||||
McuUtility_SkipSpaces(&p);
|
||||
if (McuUtility_ReadEscapedName(p, section, sizeof(section), &lenRead, NULL, NULL)!=ERR_OK || lenRead==0) {
|
||||
return ERR_FAILED;
|
||||
}
|
||||
p += lenRead;
|
||||
McuUtility_SkipSpaces(&p);
|
||||
if (McuUtility_ReadEscapedName(p, key, sizeof(key), &lenRead, NULL, NULL)!=ERR_OK || lenRead==0) {
|
||||
return ERR_FAILED;
|
||||
}
|
||||
p += lenRead;
|
||||
McuUtility_SkipSpaces(&p);
|
||||
if (McuUtility_ReadEscapedName(p, value, sizeof(value), &lenRead, NULL, NULL)!=ERR_OK || lenRead==0) {
|
||||
return ERR_FAILED;
|
||||
}
|
||||
p += lenRead;
|
||||
if (*p != '\0') { /* still some arguments? */
|
||||
return ERR_FAILED;
|
||||
}
|
||||
if (ini_puts((const TCHAR *)section, (const TCHAR *)key, (const TCHAR *)value, (const TCHAR *)fileName) == 0) {
|
||||
return ERR_FAILED;
|
||||
}
|
||||
return ERR_OK;
|
||||
#endif
|
||||
#if !McuMinINI_CONFIG_READ_ONLY
|
||||
} else if (McuUtility_strncmp((char*)cmd, "McuMinINI delkey ", sizeof("McuMinINI delkey ")-1)==0) {
|
||||
*handled = TRUE;
|
||||
p = cmd + sizeof("McuMinINI delkey ")-1;
|
||||
if (McuUtility_ReadEscapedName(p, fileName, sizeof(fileName), &lenRead, NULL, NULL)!=ERR_OK || lenRead==0) {
|
||||
return ERR_FAILED;
|
||||
}
|
||||
p += lenRead;
|
||||
McuUtility_SkipSpaces(&p);
|
||||
if (McuUtility_ReadEscapedName(p, section, sizeof(section), &lenRead, NULL, NULL)!=ERR_OK || lenRead==0) {
|
||||
return ERR_FAILED;
|
||||
}
|
||||
p += lenRead;
|
||||
McuUtility_SkipSpaces(&p);
|
||||
if (McuUtility_ReadEscapedName(p, key, sizeof(key), &lenRead, NULL, NULL)!=ERR_OK || lenRead==0) {
|
||||
return ERR_FAILED;
|
||||
}
|
||||
p += lenRead;
|
||||
if (*p != '\0') { /* still some arguments? */
|
||||
return ERR_FAILED;
|
||||
}
|
||||
if (ini_puts((const TCHAR *)section, (const TCHAR *)key, NULL, (const TCHAR *)fileName) == 0) {
|
||||
return ERR_FAILED;
|
||||
}
|
||||
return ERR_OK;
|
||||
#endif
|
||||
#if !McuMinINI_CONFIG_READ_ONLY
|
||||
} else if (McuUtility_strncmp((char*)cmd, "McuMinINI delsec ", sizeof("McuMinINI delsec ")-1)==0) {
|
||||
*handled = TRUE;
|
||||
p = cmd + sizeof("McuMinINI delsec ")-1;
|
||||
if (McuUtility_ReadEscapedName(p, fileName, sizeof(fileName), &lenRead, NULL, NULL)!=ERR_OK || lenRead==0) {
|
||||
return ERR_FAILED;
|
||||
}
|
||||
p += lenRead;
|
||||
McuUtility_SkipSpaces(&p);
|
||||
if (McuUtility_ReadEscapedName(p, section, sizeof(section), &lenRead, NULL, NULL)!=ERR_OK || lenRead==0) {
|
||||
return ERR_FAILED;
|
||||
}
|
||||
p += lenRead;
|
||||
if (*p != '\0') { /* still some arguments? */
|
||||
return ERR_FAILED;
|
||||
}
|
||||
if (ini_puts((const TCHAR *)section, NULL, NULL, (const TCHAR *)fileName) == 0) {
|
||||
return ERR_FAILED;
|
||||
}
|
||||
return ERR_OK;
|
||||
#endif
|
||||
}
|
||||
return ERR_OK;
|
||||
}
|
||||
/*
|
||||
** ===================================================================
|
||||
** Method : Deinit (component minIni)
|
||||
**
|
||||
** Description :
|
||||
** Module de-initialization
|
||||
** Parameters : None
|
||||
** Returns : Nothing
|
||||
** ===================================================================
|
||||
*/
|
||||
void McuMinINI_Deinit(void)
|
||||
{
|
||||
(void)ini_deinit(); /* call low level function */
|
||||
}
|
||||
|
||||
/*
|
||||
** ===================================================================
|
||||
** Method : Init (component minIni)
|
||||
**
|
||||
** Description :
|
||||
** Module initialization
|
||||
** Parameters : None
|
||||
** Returns : Nothing
|
||||
** ===================================================================
|
||||
*/
|
||||
void McuMinINI_Init(void)
|
||||
{
|
||||
(void)ini_init(); /* call low level function */
|
||||
}
|
||||
|
||||
/*
|
||||
** ===================================================================
|
||||
** Method : ini_hassection (component minIni)
|
||||
**
|
||||
** Description :
|
||||
** Used to find out if section exists. Returns 1 if the section
|
||||
** has been found, 0 otherwise.
|
||||
** Parameters :
|
||||
** NAME - DESCRIPTION
|
||||
** * Section - The name of the section
|
||||
** * Filename - The name and full path of the .
|
||||
** ini file to read from
|
||||
** Returns :
|
||||
** --- - The number of characters copied into the
|
||||
** supplied buffer
|
||||
** ===================================================================
|
||||
*/
|
||||
/**
|
||||
int McuMinINI_ini_hassection(const mTCHAR *Section, const mTCHAR *Filename)
|
||||
{
|
||||
Implemented as macro in the header file
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
** ===================================================================
|
||||
** Method : ini_haskey (component minIni)
|
||||
**
|
||||
** Description :
|
||||
** Used to find if a key exists. Returns 1 if key has been
|
||||
** found, 0 otherwise.
|
||||
** Parameters :
|
||||
** NAME - DESCRIPTION
|
||||
** * Section - The name of the section
|
||||
** * Key - The name of the entry to find
|
||||
** * Filename - The name and full path of the .
|
||||
** ini file
|
||||
** Returns :
|
||||
** --- - 1 if successful, otherwise 0
|
||||
** ===================================================================
|
||||
*/
|
||||
/**
|
||||
int McuMinINI_ini_haskey(const mTCHAR *Section, const mTCHAR *Key, const mTCHAR *Filename)
|
||||
{
|
||||
Implemented as macro in the header file
|
||||
}
|
||||
*/
|
||||
|
||||
/* END McuMinINI. */
|
||||
|
||||
/*!
|
||||
** @}
|
||||
*/
|
||||
362
TSM_PicoW_Sensor/McuLib/minIni/McuMinINI.h
Normal file
362
TSM_PicoW_Sensor/McuLib/minIni/McuMinINI.h
Normal file
@@ -0,0 +1,362 @@
|
||||
/* ###################################################################
|
||||
** This component module is generated by Processor Expert. Do not modify it.
|
||||
** Filename : McuMinINI.h
|
||||
** Project : FRDM-K64F_Generator
|
||||
** Processor : MK64FN1M0VLL12
|
||||
** Component : minIni
|
||||
** Version : Component 01.060, Driver 01.00, CPU db: 3.00.000
|
||||
** Compiler : GNU C Compiler
|
||||
** Date/Time : 2022-01-22, 12:01, # CodeGen: 775
|
||||
** Abstract :
|
||||
** minIni is a programmer<65>s library to read and write ini files in embedded systems.
|
||||
** Settings :
|
||||
** Component name : McuMinINI
|
||||
** minIni Version : 1.4
|
||||
** SDK : McuLib
|
||||
** Portable strnicmp() : yes
|
||||
** Use Real : no
|
||||
** Read Only : no
|
||||
** No Debug : yes
|
||||
** FatFS : Disabled
|
||||
** Source Folders :
|
||||
** Source Folder : minIni
|
||||
** Config Folder : minIni
|
||||
** Contents :
|
||||
** ini_getbool - int McuMinINI_ini_getbool(const mTCHAR *Section, const mTCHAR *Key, int...
|
||||
** ini_gets - int McuMinINI_ini_gets(const mTCHAR *Section, const mTCHAR *Key, const mTCHAR...
|
||||
** ini_puts - int McuMinINI_ini_puts(const mTCHAR *Section, const mTCHAR *Key, const mTCHAR...
|
||||
** ini_getl - long McuMinINI_ini_getl(const mTCHAR *Section, const mTCHAR *Key, long...
|
||||
** ini_putl - int McuMinINI_ini_putl(const mTCHAR *Section, const mTCHAR *Key, long Value,...
|
||||
** ini_hassection - int McuMinINI_ini_hassection(const mTCHAR *Section, const mTCHAR *Filename);
|
||||
** ini_getsection - int McuMinINI_ini_getsection(int idx, mTCHAR *Buffer, int BufferSize, const...
|
||||
** ini_haskey - int McuMinINI_ini_haskey(const mTCHAR *Section, const mTCHAR *Key, const...
|
||||
** ini_getkey - int McuMinINI_ini_getkey(const mTCHAR *Section, int idx, mTCHAR *Buffer, int...
|
||||
** ini_browse - int McuMinINI_ini_browse(INI_CALLBACK Callback, const void *UserData, const...
|
||||
** ParseCommand - uint8_t McuMinINI_ParseCommand(const unsigned char *cmd, bool *handled, const...
|
||||
** Deinit - void McuMinINI_Deinit(void);
|
||||
** Init - void McuMinINI_Init(void);
|
||||
**
|
||||
** (c) Copyright 2008-2021, CompuPhase;
|
||||
** http : www.compuphase.com
|
||||
** Processor Expert port: Erich Styger, 2014-2022, http://www.mcuoneclipse.com
|
||||
** License: See miniIni_LICENSE.txt and minIni_NOTICE.txt
|
||||
** Adaptions for Processor Expert: (c) Copyright 2012-2020, Erich Styger
|
||||
** ###################################################################*/
|
||||
/*!
|
||||
** @file McuMinINI.h
|
||||
** @version 01.00
|
||||
** @brief
|
||||
** minIni is a programmer<65>s library to read and write ini files in embedded systems.
|
||||
*/
|
||||
/*!
|
||||
** @addtogroup McuMinINI_module McuMinINI module documentation
|
||||
** @{
|
||||
*/
|
||||
|
||||
#ifndef __McuMinINI_H
|
||||
#define __McuMinINI_H
|
||||
|
||||
/* MODULE McuMinINI. */
|
||||
#include "McuLib.h" /* SDK and API used */
|
||||
#include "McuMinINIconfig.h" /* configuration */
|
||||
|
||||
#if McuMinINI_CONFIG_PARSE_COMMAND_ENABLED
|
||||
#include "McuShell.h" /* Command line shell */
|
||||
#endif
|
||||
#include "minIni.h" /* minIni Header file */
|
||||
|
||||
|
||||
|
||||
|
||||
#define McuMinINI_ini_getkey(Section, idx, Buffer, BufferSize, Filename) \
|
||||
ini_getkey(Section, idx, Buffer, BufferSize, Filename)
|
||||
/*
|
||||
** ===================================================================
|
||||
** Method : ini_getkey (component minIni)
|
||||
**
|
||||
** Description :
|
||||
** Return the key inside a section
|
||||
** Parameters :
|
||||
** NAME - DESCRIPTION
|
||||
** * Section - The name of the section to browse
|
||||
** through, or NULL to browse through the keys
|
||||
** outside any section
|
||||
** idx - The zero-based sequence number of the key
|
||||
** to return
|
||||
** * Buffer - A pointer to the buffer to copy into
|
||||
** BufferSize - The maximum number of
|
||||
** characters to copy
|
||||
** * Filename - The name and full path of the .
|
||||
** ini file to read from
|
||||
** Returns :
|
||||
** --- - The number of characters copied into the
|
||||
** supplied buffer
|
||||
** ===================================================================
|
||||
*/
|
||||
|
||||
#define McuMinINI_ini_getbool(Section, Key, DefValue, Filename) \
|
||||
ini_getbool(Section, Key, DefValue, Filename)
|
||||
/*
|
||||
** ===================================================================
|
||||
** Method : ini_getbool (component minIni)
|
||||
**
|
||||
** Description :
|
||||
** Return a boolean key. A true boolean is found if one of the
|
||||
** following is matched:
|
||||
** - A string starting with 'y' or 'Y'
|
||||
** - A string starting with 't' or 'T'
|
||||
** - A string starting with '1'
|
||||
** A false boolean is found if one of the following is matched:
|
||||
** - A string starting with 'n' or 'N'
|
||||
** - A string starting with 'f' or 'F'
|
||||
** - A string starting with '0'
|
||||
** Parameters :
|
||||
** NAME - DESCRIPTION
|
||||
** * Section - The name of the section to search
|
||||
** for
|
||||
** * Key - The name of the entry to find the value of
|
||||
** DefValue - Default value in the event of a
|
||||
** failed read; it should be zero (0) or one
|
||||
** (1).
|
||||
** * Filename - The name and full path of the .
|
||||
** ini file to read from
|
||||
** Returns :
|
||||
** --- - The true/false flag as interpreted at Key
|
||||
** ===================================================================
|
||||
*/
|
||||
|
||||
#define McuMinINI_ini_gets(Section, Key, DefValue, Buffer, BufferSize, Filename) \
|
||||
ini_gets(Section, Key, DefValue, Buffer, BufferSize, Filename)
|
||||
/*
|
||||
** ===================================================================
|
||||
** Method : ini_gets (component minIni)
|
||||
**
|
||||
** Description :
|
||||
** Return the string for a given section and key.
|
||||
** Parameters :
|
||||
** NAME - DESCRIPTION
|
||||
** * Section - The name of the section to search
|
||||
** for
|
||||
** * Key - Pointer to the name of the entry to find
|
||||
** the value of
|
||||
** * DefValue - Pointer to the default value in
|
||||
** the event of a failed read
|
||||
** * Buffer - A pointer to the buffer to copy into
|
||||
** BufferSize - The maximum number of
|
||||
** characters to copy
|
||||
** * Filename - The name and full path of the .
|
||||
** ini file to read from
|
||||
** Returns :
|
||||
** --- - The number of characters copied into the
|
||||
** supplied buffer
|
||||
** ===================================================================
|
||||
*/
|
||||
|
||||
#define McuMinINI_ini_getl(Section, Key, DefValue, Filename) \
|
||||
ini_getl(Section, Key, DefValue, Filename)
|
||||
/*
|
||||
** ===================================================================
|
||||
** Method : ini_getl (component minIni)
|
||||
**
|
||||
** Description :
|
||||
** Return the long integral value for a given section and key.
|
||||
** Parameters :
|
||||
** NAME - DESCRIPTION
|
||||
** * Section - The name of the section to search
|
||||
** for
|
||||
** * Key - Pointer to the name of the entry to find
|
||||
** the value of
|
||||
** DefValue - Default value in the event of a
|
||||
** failed read
|
||||
** * Filename - The name and full path of the .
|
||||
** ini file to read from
|
||||
** Returns :
|
||||
** --- - The value located at Key
|
||||
** ===================================================================
|
||||
*/
|
||||
|
||||
#define McuMinINI_ini_getsection(idx, Buffer, BufferSize, Filename) \
|
||||
ini_getsection(idx, Buffer, BufferSize, Filename)
|
||||
/*
|
||||
** ===================================================================
|
||||
** Method : ini_getsection (component minIni)
|
||||
**
|
||||
** Description :
|
||||
** Return the key inside a section
|
||||
** Parameters :
|
||||
** NAME - DESCRIPTION
|
||||
** idx - The zero-based sequence number of the
|
||||
** section to return
|
||||
** * Buffer - A pointer to the buffer to copy into
|
||||
** BufferSize - The maximum number of
|
||||
** characters to copy
|
||||
** * Filename - The name and full path of the .
|
||||
** ini file to read from
|
||||
** Returns :
|
||||
** --- - The number of characters copied into the
|
||||
** supplied buffer
|
||||
** ===================================================================
|
||||
*/
|
||||
|
||||
#define McuMinINI_ini_putl(Section, Key, Value, Filename) \
|
||||
ini_putl(Section, Key, Value, Filename)
|
||||
/*
|
||||
** ===================================================================
|
||||
** Method : ini_putl (component minIni)
|
||||
**
|
||||
** Description :
|
||||
** Writes a long integral value for a given section and key.
|
||||
** Method is only enabled if 'Read only' is set to 'no' in the
|
||||
** properties.
|
||||
** Parameters :
|
||||
** NAME - DESCRIPTION
|
||||
** * Section - The name of the section to write
|
||||
** the value in
|
||||
** * Key - The name of the entry to write
|
||||
** Value - The value to write
|
||||
** * Filename - The name and full path of the .
|
||||
** ini file to write to
|
||||
** Returns :
|
||||
** --- - 1 if successful, otherwise 0
|
||||
** ===================================================================
|
||||
*/
|
||||
|
||||
#define McuMinINI_ini_puts(Section, Key, Value, Filename) \
|
||||
ini_puts(Section, Key, Value, Filename);
|
||||
/*
|
||||
** ===================================================================
|
||||
** Method : ini_puts (component minIni)
|
||||
**
|
||||
** Description :
|
||||
** Writes a string value for a given section and key. Method is
|
||||
** only enabled if 'Read only' is set to 'no' in the
|
||||
** properties.
|
||||
** Parameters :
|
||||
** NAME - DESCRIPTION
|
||||
** * Section - The name of the section to write
|
||||
** the string in
|
||||
** * Key - The name of the entry to write
|
||||
** * Value - Pointer to the buffer the string, or
|
||||
** NULL to erase the key
|
||||
** * Filename - The name and full path of the .
|
||||
** ini file to write to
|
||||
** Returns :
|
||||
** --- - 1 if successful, otherwise 0
|
||||
** ===================================================================
|
||||
*/
|
||||
|
||||
#define McuMinINI_ini_browse(Callback, UserData, Filename) \
|
||||
ini_browse(Callback, UserData, Filename)
|
||||
/*
|
||||
** ===================================================================
|
||||
** Method : ini_browse (component minIni)
|
||||
**
|
||||
** Description :
|
||||
** Function to browse the ini file. With this function the file
|
||||
** is opened only once.
|
||||
** Parameters :
|
||||
** NAME - DESCRIPTION
|
||||
** Callback - a pointer to a function that
|
||||
** will be called for every setting in the INI
|
||||
** file.
|
||||
** UserData - arbitrary data, which the
|
||||
** function passes on the the Callback function
|
||||
** Filename - the name and full path of the .
|
||||
** ini file to read from
|
||||
** Returns :
|
||||
** --- - 1 on success, 0 on failure (INI file not
|
||||
** found)
|
||||
** ===================================================================
|
||||
*/
|
||||
|
||||
#if McuMinINI_CONFIG_PARSE_COMMAND_ENABLED
|
||||
uint8_t McuMinINI_ParseCommand(const unsigned char *cmd, bool *handled, const McuShell_StdIOType *io);
|
||||
/*
|
||||
** ===================================================================
|
||||
** Method : ParseCommand (component minIni)
|
||||
**
|
||||
** Description :
|
||||
** Shell Command Line parser
|
||||
** Parameters :
|
||||
** NAME - DESCRIPTION
|
||||
** * cmd - Pointer to command line
|
||||
** * handled - Pointer to variable which tells if
|
||||
** the command has been handled or not
|
||||
** * io - Pointer to I/O structure
|
||||
** Returns :
|
||||
** --- - Error code
|
||||
** ===================================================================
|
||||
*/
|
||||
|
||||
#endif
|
||||
void McuMinINI_Deinit(void);
|
||||
/*
|
||||
** ===================================================================
|
||||
** Method : Deinit (component minIni)
|
||||
**
|
||||
** Description :
|
||||
** Module de-initialization
|
||||
** Parameters : None
|
||||
** Returns : Nothing
|
||||
** ===================================================================
|
||||
*/
|
||||
|
||||
void McuMinINI_Init(void);
|
||||
/*
|
||||
** ===================================================================
|
||||
** Method : Init (component minIni)
|
||||
**
|
||||
** Description :
|
||||
** Module initialization
|
||||
** Parameters : None
|
||||
** Returns : Nothing
|
||||
** ===================================================================
|
||||
*/
|
||||
|
||||
#define McuMinINI_ini_hassection(Section, Filename) \
|
||||
ini_hassection(Section, Filename)
|
||||
/*
|
||||
** ===================================================================
|
||||
** Method : ini_hassection (component minIni)
|
||||
**
|
||||
** Description :
|
||||
** Used to find out if section exists. Returns 1 if the section
|
||||
** has been found, 0 otherwise.
|
||||
** Parameters :
|
||||
** NAME - DESCRIPTION
|
||||
** * Section - The name of the section
|
||||
** * Filename - The name and full path of the .
|
||||
** ini file to read from
|
||||
** Returns :
|
||||
** --- - The number of characters copied into the
|
||||
** supplied buffer
|
||||
** ===================================================================
|
||||
*/
|
||||
|
||||
#define McuMinINI_ini_haskey(Section, Key, Filename) \
|
||||
ini_haskey(Section, Key, Filename)
|
||||
/*
|
||||
** ===================================================================
|
||||
** Method : ini_haskey (component minIni)
|
||||
**
|
||||
** Description :
|
||||
** Used to find if a key exists. Returns 1 if key has been
|
||||
** found, 0 otherwise.
|
||||
** Parameters :
|
||||
** NAME - DESCRIPTION
|
||||
** * Section - The name of the section
|
||||
** * Key - The name of the entry to find
|
||||
** * Filename - The name and full path of the .
|
||||
** ini file
|
||||
** Returns :
|
||||
** --- - 1 if successful, otherwise 0
|
||||
** ===================================================================
|
||||
*/
|
||||
|
||||
/* END McuMinINI. */
|
||||
|
||||
#endif
|
||||
/* ifndef __McuMinINI_H */
|
||||
/*!
|
||||
** @}
|
||||
*/
|
||||
80
TSM_PicoW_Sensor/McuLib/minIni/McuMinINIconfig.h
Normal file
80
TSM_PicoW_Sensor/McuLib/minIni/McuMinINIconfig.h
Normal file
@@ -0,0 +1,80 @@
|
||||
/**
|
||||
* \file
|
||||
* \brief Configuration header file for MinINI
|
||||
* Copyright (c) 2020-2021, Erich Styger
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*
|
||||
* This header file is used to configure settings of the MinINI module.
|
||||
*/
|
||||
#ifndef __McuMinINI_CONFIG_H
|
||||
#define __McuMinINI_CONFIG_H
|
||||
|
||||
#define McuMinINI_CONFIG_FS_TYPE_GENERIC (0) /* Generic File System */
|
||||
#define McuMinINI_CONFIG_FS_TYPE_FAT_FS (1) /* FatFS File System */
|
||||
#define McuMinINI_CONFIG_FS_TYPE_TINY_FS (2) /* TinyFS File System */
|
||||
#define McuMinINI_CONFIG_FS_TYPE_FLASH_FS (3) /* Flash Page System */
|
||||
#define McuMinINI_CONFIG_FS_TYPE_LITTLE_FS (4) /* LittleFS File System */
|
||||
|
||||
#ifndef McuMinINI_CONFIG_FS
|
||||
#define McuMinINI_CONFIG_FS (McuMinINI_CONFIG_FS_TYPE_GENERIC)
|
||||
/*!< File System integration used, one of McuMinINI_CONFIG_FS_TYPE_GENERIC, McuMinINI_CONFIG_FS_TYPE_FAT_FS, McuMinINI_CONFIG_FS_TYPE_TINY_FS */
|
||||
#endif
|
||||
|
||||
#define PORTABLE_STRNICMP
|
||||
|
||||
#ifndef McuMinINI_CONFIG_USE_REAL
|
||||
#define McuMinINI_CONFIG_USE_REAL (0)
|
||||
/*!< if ini file handling includes handling of floating point data types */
|
||||
#endif
|
||||
|
||||
#if McuMinINI_CONFIG_USE_REAL
|
||||
#define INI_REAL double
|
||||
#else
|
||||
//#define INI_REAL double
|
||||
#endif
|
||||
|
||||
#ifndef McuMinINI_CONFIG_READ_ONLY
|
||||
#define McuMinINI_CONFIG_READ_ONLY (0)
|
||||
#endif
|
||||
/*!< if ini file handling is read-only */
|
||||
|
||||
#ifndef McuMinINI_CONFIG_BUFFER_SIZE
|
||||
#define McuMinINI_CONFIG_BUFFER_SIZE (64)
|
||||
#endif
|
||||
/*!< maximum line length, maximum path length, buffer is allocated on the stack! */
|
||||
|
||||
#ifndef NDEBUG
|
||||
#define NDEBUG
|
||||
/*!< comment above define to turn on assertions */
|
||||
#endif
|
||||
|
||||
#if McuMinINI_CONFIG_FS==McuMinINI_CONFIG_FS_TYPE_FLASH_FS
|
||||
/* flash memory settings */
|
||||
#ifndef McuMinINI_CONFIG_FLASH_NVM_NOF_BLOCKS
|
||||
#define McuMinINI_CONFIG_FLASH_NVM_NOF_BLOCKS (1)
|
||||
/*!< number of flash blocks */
|
||||
#endif
|
||||
|
||||
#ifndef McuMinINI_CONFIG_FLASH_NVM_BLOCK_SIZE
|
||||
#define McuMinINI_CONFIG_FLASH_NVM_BLOCK_SIZE (0x800)
|
||||
/*!< must match FLASH_GetProperty(&s_flashDriver, kFLASH_PropertyPflash0SectorSize, &pflashSectorSize).
|
||||
For LPC55Sxx it is 0x200, for LPC845 it is 0x400, for K22FN/K02FN it is 0x800 */
|
||||
#endif
|
||||
|
||||
#ifndef McuMinINI_CONFIG_FLASH_NVM_ADDR_START
|
||||
#define McuMinINI_CONFIG_FLASH_NVM_ADDR_START ((0+512*1024)-(McuMinINI_CONFIG_FLASH_NVM_NOF_BLOCKS*McuMinINI_CONFIG_FLASH_NVM_BLOCK_SIZE))
|
||||
/*!< last block in FLASH, start address of data in flash */
|
||||
#endif
|
||||
|
||||
#ifndef McuMinINI_CONFIG_FLASH_NVM_MAX_DATA_SIZE
|
||||
#define McuMinINI_CONFIG_FLASH_NVM_MAX_DATA_SIZE (128)
|
||||
/*!< size for the data, less than McuMinINI_CONFIG_FLASH_NVM_BLOCK_SIZE to save memory. For LPC55Sxx it must be multiple of 0x200! */
|
||||
#endif
|
||||
#endif /* McuMinINI_CONFIG_FS_TYPE_FLASH_FS */
|
||||
|
||||
#if !defined(McuMinINI_CONFIG_PARSE_COMMAND_ENABLED)
|
||||
#define McuMinINI_CONFIG_PARSE_COMMAND_ENABLED (1)
|
||||
/*!< 1: shell support enabled, 0: otherwise */
|
||||
#endif
|
||||
|
||||
#endif /* __McuMinINI_CONFIG_H */
|
||||
37
TSM_PicoW_Sensor/McuLib/minIni/minGlue-FatFs.c
Normal file
37
TSM_PicoW_Sensor/McuLib/minIni/minGlue-FatFs.c
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.)
|
||||
*/
|
||||
|
||||
#include "McuMinINIconfig.h" /* MinIni config file */
|
||||
|
||||
#if McuMinINI_CONFIG_FS==McuMinINI_CONFIG_FS_TYPE_FAT_FS
|
||||
#include "ff.h" /* include tff.h for Tiny-FatFs */
|
||||
#include "minGlue-FatFs.h"
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
|
||||
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) ? (char*)dest : drive + 1;
|
||||
return (f_rename(source, drive) == FR_OK);
|
||||
}
|
||||
|
||||
int ini_deinit(void) {
|
||||
return 1; /* ok */
|
||||
}
|
||||
|
||||
int ini_init(void) {
|
||||
return 1; /* ok */
|
||||
}
|
||||
|
||||
#endif /* McuMinINI_CONFIG_FS==McuMinINI_CONFIG_FS_TYPE_FAT_FS */
|
||||
|
||||
67
TSM_PicoW_Sensor/McuLib/minIni/minGlue-FatFs.h
Normal file
67
TSM_PicoW_Sensor/McuLib/minIni/minGlue-FatFs.h
Normal file
@@ -0,0 +1,67 @@
|
||||
/* 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-2019
|
||||
* 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.)
|
||||
*/
|
||||
|
||||
#ifndef _MINGLUE_FATFS_H__
|
||||
#define _MINGLUE_FATFS_H__
|
||||
|
||||
#include "McuMinINIconfig.h" /* MinIni configuration file */
|
||||
|
||||
#if McuMinINI_CONFIG_FS==McuMinINI_CONFIG_FS_TYPE_FAT_FS
|
||||
|
||||
#ifdef __HIWARE__
|
||||
/* switching off some warnings */
|
||||
#pragma MESSAGE DISABLE C1420 /* Result of function call is ignored */
|
||||
#pragma MESSAGE DISABLE C5909 /* Assignment in condition */
|
||||
#endif
|
||||
|
||||
/* You must set FF_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 */
|
||||
|
||||
/* When setting FF_USE_STRFUNC to 2 (for LF to CR/LF translation), INI_LINETERM
|
||||
* should be defined to "\n" (otherwise "\r\n" will be translated by FatFS to
|
||||
* "\r\r\n").
|
||||
*/
|
||||
#if defined FF_USE_STRFUNC && FF_USE_STRFUNC == 2 && !defined INI_LINETERM
|
||||
#define INI_LINETERM "\n"
|
||||
#endif
|
||||
|
||||
#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 unsigned long//DWORD
|
||||
#define ini_tell(file,pos) (*(pos) = f_tell((file)))
|
||||
#define ini_seek(file,pos) (f_lseek((file), *(pos)) == FR_OK)
|
||||
|
||||
#define ini_assert(condition) /* empty */
|
||||
|
||||
int ini_rename(TCHAR *source, const TCHAR *dest);
|
||||
|
||||
#if defined(INI_REAL)
|
||||
#include <stdio.h> /* for sprintf() */
|
||||
|
||||
#define ini_ftoa(string,value) sprintf((string),"%f",(value))
|
||||
#define ini_atof(string) (INI_REAL)strtod((string),NULL)
|
||||
#endif /* defined INI_REAL */
|
||||
|
||||
int ini_deinit(void);
|
||||
int ini_init(void);
|
||||
|
||||
#endif /* McuMinINI_CONFIG_FS==McuMinINI_CONFIG_FS_TYPE_FAT_FS */
|
||||
|
||||
#endif /* _MINGLUE-FATFS_H__ */
|
||||
|
||||
318
TSM_PicoW_Sensor/McuLib/minIni/minGlue-Flash.c
Normal file
318
TSM_PicoW_Sensor/McuLib/minIni/minGlue-Flash.c
Normal file
@@ -0,0 +1,318 @@
|
||||
/* Glue functions for a flash (page) based storage system, without a file system.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "McuMinINIconfig.h" /* MinIni config file */
|
||||
|
||||
#if McuMinINI_CONFIG_FS==McuMinINI_CONFIG_FS_TYPE_FLASH_FS
|
||||
#include "minGlue-Flash.h"
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
#include "McuLib.h"
|
||||
#include "McuLog.h"
|
||||
#include "McuUtility.h"
|
||||
#include "McuFlash.h"
|
||||
|
||||
/* NOTE: we only support one 'file' in FLASH, and only one 'file' in RAM. The one in RAM is for the read-write and temporary one */
|
||||
/* read-only FLASH 'file' is at McuMinINI_CONFIG_FLASH_NVM_ADDR_START */
|
||||
#if !McuMinINI_CONFIG_READ_ONLY
|
||||
static unsigned char dataBuf[McuMinINI_CONFIG_FLASH_NVM_MAX_DATA_SIZE]; /* ini file for read/write */
|
||||
#endif
|
||||
|
||||
int ini_openread(const TCHAR *filename, INI_FILETYPE *file) {
|
||||
/* open file in read-only mode. This will use directly the data in FLASH */
|
||||
memset(file, 0, sizeof(INI_FILETYPE));
|
||||
file->header = (MinIniFlashFileHeader*)(McuMinINI_CONFIG_FLASH_NVM_ADDR_START);
|
||||
file->data = (unsigned char*)file->header + sizeof(MinIniFlashFileHeader);
|
||||
if (file->header->magicNumber != MININI_FLASH_MAGIC_DATA_NUMBER_ID) {
|
||||
return 0; /* failed, magic number does not match */
|
||||
}
|
||||
if (McuUtility_strcmp((char*)file->header->dataName, (char*)filename)!=0) {
|
||||
return 0; /* failed, not the file name of the storage */
|
||||
}
|
||||
file->curr = file->data;
|
||||
file->isOpen = true;
|
||||
file->isReadOnly = true;
|
||||
return 1; /* ok */
|
||||
}
|
||||
|
||||
static bool isTempFile(const TCHAR *filename) {
|
||||
size_t len;
|
||||
|
||||
len = McuUtility_strlen(filename);
|
||||
if (len==0) {
|
||||
return false; /* illegal file name */
|
||||
}
|
||||
if (filename[len-1]=='~') { /* temporary file name */
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
#if !McuMinINI_CONFIG_READ_ONLY
|
||||
int ini_openwrite(const TCHAR *filename, INI_FILETYPE *file) {
|
||||
/* create always a new file */
|
||||
memset(file, 0, sizeof(INI_FILETYPE)); /* initialize all fields in header */
|
||||
memset(dataBuf, 0, sizeof(dataBuf)); /* initialize all data */
|
||||
file->header = (MinIniFlashFileHeader*)dataBuf;
|
||||
file->data = (unsigned char*)file->header + sizeof(MinIniFlashFileHeader);
|
||||
file->header->magicNumber = MININI_FLASH_MAGIC_DATA_NUMBER_ID;
|
||||
McuUtility_strcpy(file->header->dataName, sizeof(file->header->dataName), (unsigned char*)filename);
|
||||
file->header->dataSize = 0;
|
||||
file->curr = file->data;
|
||||
file->isOpen = true;
|
||||
file->isReadOnly = false;
|
||||
return 1; /* ok */
|
||||
}
|
||||
#endif
|
||||
|
||||
int ini_close(INI_FILETYPE *file) {
|
||||
file->isOpen = false;
|
||||
if (!file->isReadOnly && !isTempFile((const char*)file->header->dataName)) { /* RAM data, and not temp file? */
|
||||
/* store data in FLASH */
|
||||
if (McuFlash_Program((void*)McuMinINI_CONFIG_FLASH_NVM_ADDR_START, file->header, McuMinINI_CONFIG_FLASH_NVM_MAX_DATA_SIZE)!=ERR_OK) {
|
||||
return 0; /* failed */
|
||||
}
|
||||
}
|
||||
return 1; /* ok */
|
||||
}
|
||||
|
||||
int ini_read(TCHAR *buffer, size_t size, INI_FILETYPE *file) {
|
||||
/* read a string until EOF or '\n' */
|
||||
unsigned char ch;
|
||||
|
||||
buffer[0] = '\0'; /* zero terminate */
|
||||
for(;;) {
|
||||
if (file->curr >= file->data+file->header->dataSize) { /* beyond boundaries? */
|
||||
file->curr = file->data+file->header->dataSize; /* point to max position possible, one byte beyond */
|
||||
return 0; /* EOF */
|
||||
}
|
||||
ch = *file->curr; /* read character */
|
||||
file->curr++; /* move pointer */
|
||||
McuUtility_chcat((unsigned char*)buffer, size, ch); /* add character to buffer */
|
||||
if (ch=='\n') { /* reached end of line */
|
||||
return 1; /* ok */
|
||||
}
|
||||
}
|
||||
return 1; /* ok */
|
||||
}
|
||||
|
||||
#if !McuMinINI_CONFIG_READ_ONLY
|
||||
int ini_write(TCHAR *buffer, INI_FILETYPE *file) {
|
||||
size_t len, remaining;
|
||||
|
||||
/* write zero terminated string to file */
|
||||
if (file->isReadOnly) {
|
||||
return 1; /* error, file is read-only */
|
||||
}
|
||||
/* data is in RAM buffer */
|
||||
len = McuUtility_strlen(buffer);
|
||||
remaining = dataBuf+sizeof(dataBuf)-file->curr;
|
||||
McuUtility_strcpy(file->curr, remaining, (const unsigned char*)buffer);
|
||||
file->curr += len;
|
||||
if (file->curr >= (unsigned char*)file->header+McuMinINI_CONFIG_FLASH_NVM_MAX_DATA_SIZE) { /* outside valid memory? */
|
||||
file->curr = (unsigned char*)file->header+McuMinINI_CONFIG_FLASH_NVM_MAX_DATA_SIZE; /* set to highest possible location */
|
||||
return 0; /* error */
|
||||
}
|
||||
if (file->curr >= file->data+file->header->dataSize) { /* moved beyond current size? file is growing */
|
||||
file->header->dataSize = file->curr - file->data; /* update size */
|
||||
return 1; /* ok */
|
||||
}
|
||||
return 1; /* ok */
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !McuMinINI_CONFIG_READ_ONLY
|
||||
int ini_remove(const TCHAR *filename) {
|
||||
MinIniFlashFileHeader *hp;
|
||||
|
||||
/* check first if we are removing the data in FLASH */
|
||||
hp = (MinIniFlashFileHeader*)McuMinINI_CONFIG_FLASH_NVM_ADDR_START;
|
||||
if ( hp->magicNumber==MININI_FLASH_MAGIC_DATA_NUMBER_ID /* valid file */
|
||||
&& McuUtility_strcmp((char*)hp->dataName, filename)==0 /* file name matches */
|
||||
)
|
||||
{
|
||||
/* flash data file */
|
||||
if (McuFlash_Erase((void*)McuMinINI_CONFIG_FLASH_NVM_ADDR_START, McuMinINI_CONFIG_FLASH_NVM_NOF_BLOCKS*McuMinINI_CONFIG_FLASH_NVM_BLOCK_SIZE)==ERR_OK) {
|
||||
return 1; /* ok */
|
||||
} else {
|
||||
return 0; /* error */
|
||||
}
|
||||
}
|
||||
/* check if we are removing the temp file */
|
||||
hp = (MinIniFlashFileHeader*)dataBuf;
|
||||
if ( hp->magicNumber==MININI_FLASH_MAGIC_DATA_NUMBER_ID /* valid file */
|
||||
&& McuUtility_strcmp((char*)hp->dataName, filename)==0 /* it the data in RAM */
|
||||
)
|
||||
{
|
||||
/* RAM data file */
|
||||
memset(dataBuf, 0, sizeof(dataBuf));
|
||||
return 1; /* ok */
|
||||
}
|
||||
return 0; /* error */
|
||||
}
|
||||
#endif
|
||||
|
||||
int ini_tell(INI_FILETYPE *file, INI_FILEPOS *pos) {
|
||||
/* return the current file pointer (offset into file) */
|
||||
*pos = file->curr - file->data;
|
||||
return 1; /* ok */
|
||||
}
|
||||
|
||||
int ini_seek(INI_FILETYPE *file, INI_FILEPOS *pos) {
|
||||
/* move the file pointer to the given position */
|
||||
file->curr = file->data + *pos; /* move current data pointer */
|
||||
if (file->curr >= (unsigned char*)file->header+McuMinINI_CONFIG_FLASH_NVM_MAX_DATA_SIZE) { /* outside limits? */
|
||||
file->curr = (unsigned char*)file->header + McuMinINI_CONFIG_FLASH_NVM_MAX_DATA_SIZE; /* back to valid range, which can be one byte beyond buffer */
|
||||
return 0; /* error, EOF */
|
||||
}
|
||||
return 1; /* ok */
|
||||
}
|
||||
|
||||
#if !McuMinINI_CONFIG_READ_ONLY
|
||||
int ini_rename(const TCHAR *source, const TCHAR *dest) {
|
||||
/* e.g. test.in~ -> test.ini: this always will do a store from RAM to FLASH! */
|
||||
MinIniFlashFileHeader *hp;
|
||||
|
||||
if (isTempFile(source)) { /* store temporary file into flash */
|
||||
hp = (MinIniFlashFileHeader*)dataBuf;
|
||||
if (McuUtility_strcmp((char*)hp->dataName, source)!=0) { /* file name in RAM does not match? */
|
||||
return 0; /* error */
|
||||
}
|
||||
McuUtility_strcpy(hp->dataName, sizeof(hp->dataName), (unsigned char*)dest); /* rename file */
|
||||
/* store in flash */
|
||||
if (McuFlash_Program((void*)McuMinINI_CONFIG_FLASH_NVM_ADDR_START, (unsigned char*)dataBuf, sizeof(dataBuf))!=ERR_OK) {
|
||||
return 0; /* failed */
|
||||
}
|
||||
memset(dataBuf, 0, sizeof(dataBuf)); /* erase RAM file content */
|
||||
}
|
||||
return 1; /* ok */
|
||||
}
|
||||
#endif
|
||||
|
||||
int ini_deinit(void) {
|
||||
/* nothing needed */
|
||||
return 0; /* ok */
|
||||
}
|
||||
|
||||
int ini_init(void) {
|
||||
#if McuLib_CONFIG_CPU_IS_LPC55xx
|
||||
if((McuMinINI_CONFIG_FLASH_NVM_MAX_DATA_SIZE%McuFlash_CONFIG_FLASH_BLOCK_SIZE)!=0) {
|
||||
#elif McuLib_CONFIG_CPU_VARIANT==McuLib_CONFIG_CPU_VARIANT_RP2040
|
||||
if((McuMinINI_CONFIG_FLASH_NVM_MAX_DATA_SIZE%McuFlash_CONFIG_FLASH_BLOCK_SIZE)!=0) {
|
||||
#else
|
||||
if( ! (McuMinINI_CONFIG_FLASH_NVM_MAX_DATA_SIZE==64
|
||||
|| McuMinINI_CONFIG_FLASH_NVM_MAX_DATA_SIZE==128
|
||||
|| McuMinINI_CONFIG_FLASH_NVM_MAX_DATA_SIZE==256
|
||||
|| McuMinINI_CONFIG_FLASH_NVM_MAX_DATA_SIZE==512
|
||||
|| McuMinINI_CONFIG_FLASH_NVM_MAX_DATA_SIZE==1024
|
||||
|| McuMinINI_CONFIG_FLASH_NVM_MAX_DATA_SIZE==2048
|
||||
|| McuMinINI_CONFIG_FLASH_NVM_MAX_DATA_SIZE==4096
|
||||
|| McuMinINI_CONFIG_FLASH_NVM_MAX_DATA_SIZE==8192)
|
||||
)
|
||||
{
|
||||
#endif
|
||||
/* data size (number of bytes) needs to be 64, 128, 256, 512, 1024 bytes for the flash programming! */
|
||||
McuLog_fatal("wrong size of data!");
|
||||
for(;;) {}
|
||||
}
|
||||
return 0; /* ok */
|
||||
}
|
||||
|
||||
static void PrintDataStatus(const McuShell_StdIOType *io, MinIniFlashFileHeader *hp, const unsigned char *dataName) {
|
||||
uint8_t buf[48];
|
||||
|
||||
if (!McuFlash_IsAccessible(hp, sizeof(MinIniFlashFileHeader))) { /* accessing erased FLASH on LPC55Sxx will cause hard fault! */
|
||||
McuUtility_strcpy(buf, sizeof(buf), (unsigned char*)"ERASED, not accessible\r\n");
|
||||
McuShell_SendStatusStr(dataName, buf, io->stdOut);
|
||||
return;
|
||||
}
|
||||
McuUtility_strcpy(buf, sizeof(buf), (unsigned char*)"magic 0x");
|
||||
McuUtility_strcatNum32Hex(buf, sizeof(buf), hp->magicNumber);
|
||||
McuUtility_strcat(buf, sizeof(buf), (unsigned char*)", ");
|
||||
if (hp->magicNumber==MININI_FLASH_MAGIC_DATA_NUMBER_ID) {
|
||||
McuUtility_strcat(buf, sizeof(buf), hp->dataName);
|
||||
McuUtility_strcat(buf, sizeof(buf), (unsigned char*)", size ");
|
||||
McuUtility_strcatNum32u(buf, sizeof(buf), hp->dataSize);
|
||||
} else {
|
||||
McuUtility_strcat(buf, sizeof(buf), (unsigned char*)"<not valid>");
|
||||
}
|
||||
McuUtility_strcat(buf, sizeof(buf), (unsigned char*)"\r\n");
|
||||
McuShell_SendStatusStr(dataName, buf, io->stdOut);
|
||||
}
|
||||
|
||||
static uint8_t PrintStatus(const McuShell_StdIOType *io) {
|
||||
uint8_t buf[48];
|
||||
|
||||
McuShell_SendStatusStr((unsigned char*)"ini", (unsigned char*)"ini flash status\r\n", io->stdOut);
|
||||
McuUtility_strcpy(buf, sizeof(buf), (unsigned char*)"start 0x");
|
||||
McuUtility_strcatNum32Hex(buf, sizeof(buf), McuMinINI_CONFIG_FLASH_NVM_ADDR_START);
|
||||
McuUtility_strcat(buf, sizeof(buf), (unsigned char*)", block 0x");
|
||||
McuUtility_strcatNum16Hex(buf, sizeof(buf), McuMinINI_CONFIG_FLASH_NVM_BLOCK_SIZE);
|
||||
McuUtility_strcat(buf, sizeof(buf), (unsigned char*)", nof ");
|
||||
McuUtility_strcatNum16u(buf, sizeof(buf), McuMinINI_CONFIG_FLASH_NVM_NOF_BLOCKS);
|
||||
McuUtility_strcat(buf, sizeof(buf), (unsigned char*)"\r\n");
|
||||
McuShell_SendStatusStr((unsigned char*)" flash", buf, io->stdOut);
|
||||
|
||||
McuUtility_Num32uToStr(buf, sizeof(buf), McuMinINI_CONFIG_FLASH_NVM_MAX_DATA_SIZE);
|
||||
McuUtility_strcat(buf, sizeof(buf), (unsigned char*)" bytes\r\n");
|
||||
McuShell_SendStatusStr((unsigned char*)" max data", buf, io->stdOut);
|
||||
|
||||
PrintDataStatus(io, (MinIniFlashFileHeader*)McuMinINI_CONFIG_FLASH_NVM_ADDR_START, (const unsigned char*)" data");
|
||||
#if !McuMinINI_CONFIG_READ_ONLY
|
||||
PrintDataStatus(io, (MinIniFlashFileHeader*)dataBuf, (const unsigned char*)" ram");
|
||||
#endif
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
static uint8_t DumpData(const McuShell_StdIOType *io) {
|
||||
MinIniFlashFileHeader *hp;
|
||||
const unsigned char *p;
|
||||
|
||||
hp = (MinIniFlashFileHeader*)McuMinINI_CONFIG_FLASH_NVM_ADDR_START;
|
||||
PrintDataStatus(io, hp, (const unsigned char*)"data");
|
||||
if (hp->magicNumber==MININI_FLASH_MAGIC_DATA_NUMBER_ID) {
|
||||
p = (const unsigned char*)hp + sizeof(MinIniFlashFileHeader);
|
||||
for(unsigned int i=0; i<hp->dataSize; i++) {
|
||||
io->stdOut(*p);
|
||||
p++;
|
||||
}
|
||||
}
|
||||
hp = (MinIniFlashFileHeader*)dataBuf;
|
||||
PrintDataStatus(io, hp, (const unsigned char*)"ram");
|
||||
if (hp->magicNumber==MININI_FLASH_MAGIC_DATA_NUMBER_ID) {
|
||||
p = (const unsigned char*)hp + sizeof(MinIniFlashFileHeader);
|
||||
for(unsigned int i=0; i<hp->dataSize; i++) {
|
||||
io->stdOut(*p);
|
||||
p++;
|
||||
}
|
||||
}
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
uint8_t ini_ParseCommand(const unsigned char *cmd, bool *handled, const McuShell_StdIOType *io) {
|
||||
if (McuUtility_strcmp((char*)cmd, McuShell_CMD_HELP)==0 || McuUtility_strcmp((char*)cmd, "ini help")==0) {
|
||||
McuShell_SendHelpStr((unsigned char*)"ini", (const unsigned char*)"Group of flash ini commands\r\n", io->stdOut);
|
||||
McuShell_SendHelpStr((unsigned char*)" help|status", (unsigned char*)"Print help or status information\r\n", io->stdOut);
|
||||
McuShell_SendHelpStr((unsigned char*)" dump", (unsigned char*)"Dump data information\r\n", io->stdOut);
|
||||
McuShell_SendHelpStr((unsigned char*)" erase", (unsigned char*)"Erase data information\r\n", io->stdOut);
|
||||
*handled = TRUE;
|
||||
return ERR_OK;
|
||||
} else if ((McuUtility_strcmp((char*)cmd, McuShell_CMD_STATUS)==0) || (McuUtility_strcmp((char*)cmd, "ini status")==0)) {
|
||||
*handled = TRUE;
|
||||
return PrintStatus(io);
|
||||
} else if (McuUtility_strcmp((char*)cmd, "ini dump")==0) {
|
||||
*handled = TRUE;
|
||||
return DumpData(io);
|
||||
} else if (McuUtility_strcmp((char*)cmd, "ini erase")==0) {
|
||||
*handled = TRUE;
|
||||
return McuFlash_Erase((void*)McuMinINI_CONFIG_FLASH_NVM_ADDR_START, McuMinINI_CONFIG_FLASH_NVM_NOF_BLOCKS*McuMinINI_CONFIG_FLASH_NVM_BLOCK_SIZE);
|
||||
}
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
#endif /* McuMinINI_CONFIG_FS==McuMinINI_CONFIG_FS_TYPE_KINETIS_FLASH_FS */
|
||||
77
TSM_PicoW_Sensor/McuLib/minIni/minGlue-Flash.h
Normal file
77
TSM_PicoW_Sensor/McuLib/minIni/minGlue-Flash.h
Normal file
@@ -0,0 +1,77 @@
|
||||
/* Glue functions for the minIni library, for a Kinetis flash page
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _MINGLUE_FLASH_H__
|
||||
#define _MINGLUE_FLASH_H__
|
||||
|
||||
#include "McuMinINIconfig.h" /* MinIni config file */
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#if McuMinINI_CONFIG_FS==McuMinINI_CONFIG_FS_TYPE_FLASH_FS
|
||||
|
||||
#define INI_BUFFERSIZE (McuMinINI_CONFIG_BUFFER_SIZE) /* maximum line length, maximum path length */
|
||||
|
||||
#define MININI_FLASH_MAGIC_DATA_NUMBER_ID (0xFEEDBABE) /* magic ID to mark valid memory */
|
||||
typedef struct MinIniFlashFileHeader {
|
||||
unsigned int magicNumber; /* magic ID: MAGIC_DATA_NUMBER_ID */
|
||||
unsigned char dataName[16]; /* file/data name, limited to 16 bytes, zero terminated */
|
||||
size_t dataSize; /* size of data, without this header */
|
||||
} MinIniFlashFileHeader;
|
||||
|
||||
typedef struct {
|
||||
MinIniFlashFileHeader *header; /* pointer to header, is at the start of the data */
|
||||
unsigned char *data; /* start of data */
|
||||
unsigned char *curr; /* current data/file pointer */
|
||||
bool isReadOnly; /* if file is for read and write or read-only */
|
||||
bool isOpen; /* if file is open or not */
|
||||
} MinIniaFlashDataFile_t;
|
||||
|
||||
|
||||
#define TCHAR char
|
||||
#define INI_FILETYPE MinIniaFlashDataFile_t
|
||||
#define INI_FILEPOS size_t
|
||||
|
||||
#define ini_assert(condition) /* empty */
|
||||
|
||||
int ini_openread(const TCHAR *filename, INI_FILETYPE *file);
|
||||
int ini_openwrite(const TCHAR *filename, INI_FILETYPE *file);
|
||||
int ini_close(INI_FILETYPE *file);
|
||||
int ini_read(TCHAR *buffer, size_t size, INI_FILETYPE *file);
|
||||
int ini_write(TCHAR *buffer, INI_FILETYPE *file);
|
||||
int ini_remove(const TCHAR *filename);
|
||||
int ini_tell(INI_FILETYPE *file, INI_FILEPOS *pos);
|
||||
int ini_seek(INI_FILETYPE *file, INI_FILEPOS *pos);
|
||||
int ini_rename(const TCHAR *source, const TCHAR *dest);
|
||||
|
||||
#if defined(INI_REAL)
|
||||
#include <stdio.h> /* for sprintf() */
|
||||
|
||||
#define ini_ftoa(string,value) sprintf((string),"%f",(value))
|
||||
#define ini_atof(string) (INI_REAL)strtod((string),NULL)
|
||||
#endif /* defined INI_REAL */
|
||||
|
||||
#include "McuShell.h"
|
||||
uint8_t ini_ParseCommand(const unsigned char *cmd, bool *handled, const McuShell_StdIOType *io);
|
||||
|
||||
/*!
|
||||
* \brief Module de-initialization
|
||||
* \return error code, 0 for no error
|
||||
*/
|
||||
int ini_deinit(void);
|
||||
|
||||
/*!
|
||||
* \brief Module initialization
|
||||
* \return error code, 0 for no error
|
||||
*/
|
||||
int ini_init(void);
|
||||
|
||||
#endif /* McuMinINI_CONFIG_FS==McuMinINI_CONFIG_FS_TYPE_FLASH_FS */
|
||||
|
||||
#endif /* _MINGLUE_FLASH_H__ */
|
||||
|
||||
64
TSM_PicoW_Sensor/McuLib/minIni/minGlue-LittleFS.c
Normal file
64
TSM_PicoW_Sensor/McuLib/minIni/minGlue-LittleFS.c
Normal file
@@ -0,0 +1,64 @@
|
||||
/* 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.)
|
||||
*/
|
||||
|
||||
#include "littleFS/lfs.h"
|
||||
#include "minGlue-LittleFS.h"
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
#include "McuUtility.h"
|
||||
|
||||
#if McuMinINI_CONFIG_FS==McuMinINI_CONFIG_FS_TYPE_LITTLE_FS
|
||||
|
||||
int ini_rename(char *source, const char *dest) {
|
||||
lfs_t *FS_lfs = McuLFS_GetFileSystem();
|
||||
/* Function f_rename() does not allow drive letters in the destination file */
|
||||
char *drive = strchr(dest, ':');
|
||||
drive = (drive == NULL) ? (char*)dest : drive + 1;
|
||||
return (lfs_rename(FS_lfs, source, dest) == 0);
|
||||
}
|
||||
|
||||
int ini_fileReadOpen(lfs_file_t *file, const char *name) {
|
||||
lfs_t *FS_lfs = McuLFS_GetFileSystem();
|
||||
return (lfs_file_open(FS_lfs, file, name, LFS_O_RDONLY)== 0);
|
||||
}
|
||||
|
||||
int ini_fileWriteOpen(lfs_file_t *file, const char *name) {
|
||||
lfs_t *FS_lfs = McuLFS_GetFileSystem();
|
||||
return (lfs_file_open(FS_lfs, file, name, LFS_O_RDWR | LFS_O_CREAT)== 0);
|
||||
}
|
||||
|
||||
int ini_fileClose(lfs_file_t *file) {
|
||||
lfs_t *FS_lfs = McuLFS_GetFileSystem();
|
||||
return (lfs_file_close(FS_lfs, file) == 0);
|
||||
}
|
||||
|
||||
int ini_fileRemove(const char *filename) {
|
||||
lfs_t *FS_lfs = McuLFS_GetFileSystem();
|
||||
return (lfs_remove(FS_lfs, filename) == 0);
|
||||
}
|
||||
|
||||
int ini_fileTell(lfs_file_t *file ,unsigned long* pos) {
|
||||
lfs_t *FS_lfs = McuLFS_GetFileSystem();
|
||||
*pos = lfs_file_tell(FS_lfs, file);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
int ini_fileSeek(lfs_file_t *file ,unsigned long* pos) {
|
||||
lfs_t *FS_lfs = McuLFS_GetFileSystem();
|
||||
lfs_file_seek(FS_lfs, file, *pos, LFS_SEEK_SET);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void ini_init(void) {}
|
||||
void ini_deinit(void) {}
|
||||
|
||||
|
||||
#endif /* McuMinINI_CONFIG_FS_TYPE_LITTLE_FS */
|
||||
72
TSM_PicoW_Sensor/McuLib/minIni/minGlue-LittleFS.h
Normal file
72
TSM_PicoW_Sensor/McuLib/minIni/minGlue-LittleFS.h
Normal file
@@ -0,0 +1,72 @@
|
||||
/* 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.)
|
||||
*/
|
||||
|
||||
#ifndef _MINGLUE_FATFS_H__
|
||||
#define _MINGLUE_FATFS_H__
|
||||
|
||||
#include "McuMinINIconfig.h"
|
||||
|
||||
#if McuMinINI_CONFIG_FS==McuMinINI_CONFIG_FS_TYPE_LITTLE_FS
|
||||
|
||||
#ifdef __HIWARE__
|
||||
/* switching off some warnings */
|
||||
#pragma MESSAGE DISABLE C1420 /* Result of function call is ignored */
|
||||
#pragma MESSAGE DISABLE C5909 /* Assignment in condition */
|
||||
#endif
|
||||
|
||||
#define INI_BUFFERSIZE (McuMinINI_CONFIG_BUFFER_SIZE) /* 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 "littleFS/lfs.h"
|
||||
#include "littleFS/McuLittleFS.h"
|
||||
|
||||
#define TCHAR char
|
||||
|
||||
int ini_fileReadOpen(lfs_file_t *file, const char *name);
|
||||
int ini_fileWriteOpen(lfs_file_t *file, const char *name);
|
||||
int ini_fileClose(lfs_file_t *file);
|
||||
int ini_fileRead( void *buffer, lfs_size_t size, lfs_file_t *file);
|
||||
int ini_fileWrite( void *buffer, lfs_file_t *file);
|
||||
int ini_fileRemove(const char *filename);
|
||||
int ini_fileTell(lfs_file_t *file ,unsigned long* pos);
|
||||
int ini_fileSeek(lfs_file_t *file ,unsigned long* pos);
|
||||
|
||||
#define INI_FILETYPE lfs_file_t
|
||||
#define ini_openread(filename,file) (ini_fileReadOpen((file), (filename)))
|
||||
#define ini_openwrite(filename,file) (ini_fileWriteOpen((file), (filename)))
|
||||
#define ini_close(file) (ini_fileClose(file))
|
||||
#define ini_read(buffer,size,file) McuLFS_gets((buffer), (size),(file))
|
||||
#define ini_write(buffer,file) McuLFS_puts((buffer), (file))
|
||||
#define ini_remove(filename) (ini_fileRemove(filename))
|
||||
|
||||
#define INI_FILEPOS unsigned long//DWORD
|
||||
#define ini_tell(file,pos) (ini_fileTell((file),(pos)))
|
||||
#define ini_seek(file,pos) (ini_fileSeek((file),(pos)))
|
||||
|
||||
#define ini_assert(condition) /* empty */
|
||||
|
||||
void ini_init(void);
|
||||
void ini_deinit(void);
|
||||
|
||||
int ini_rename(char *source, const char *dest);
|
||||
|
||||
#if defined(INI_REAL)
|
||||
#include <stdio.h> /* for sprintf() */
|
||||
|
||||
#define ini_ftoa(string,value) sprintf((string),"%f",(value))
|
||||
#define ini_atof(string) (INI_REAL)strtod((string),NULL)
|
||||
#endif /* defined INI_REAL */
|
||||
|
||||
#endif /* McuMinINI_CONFIG_FS_TYPE_LITTLE_FS */
|
||||
|
||||
#endif /* _MINGLUE-FATFS_H__ */
|
||||
49
TSM_PicoW_Sensor/McuLib/minIni/minGlue.h
Normal file
49
TSM_PicoW_Sensor/McuLib/minIni/minGlue.h
Normal file
@@ -0,0 +1,49 @@
|
||||
/* 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.
|
||||
*/
|
||||
|
||||
#include "McuLib.h" /* SDK and API used */
|
||||
#include "McuMinINIconfig.h" /* MinIni config file */
|
||||
|
||||
#if McuMinINI_CONFIG_FS==McuMinINI_CONFIG_FS_TYPE_GENERIC
|
||||
/* 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_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 fpos_t
|
||||
#define ini_tell(file,pos) (fgetpos(*(file), (pos)) == 0)
|
||||
#define ini_seek(file,pos) (fsetpos(*(file), (pos)) == 0)
|
||||
|
||||
/* for floating-point support, define additional types and functions */
|
||||
#define ini_ftoa(string,value) sprintf((string),"%f",(value))
|
||||
#define ini_atof(string) (INI_REAL)strtod((string),NULL)
|
||||
|
||||
typedef char TCHAR;
|
||||
|
||||
int ini_init(void);
|
||||
int ini_deinit(void);
|
||||
|
||||
#elif McuMinINI_CONFIG_FS==McuMinINI_CONFIG_FS_TYPE_FAT_FS
|
||||
#include "minGlue-FatFs.h"
|
||||
#elif McuMinINI_CONFIG_FS==McuMinINI_CONFIG_FS_TYPE_FLASH_FS
|
||||
#include "minGlue-Flash.h"
|
||||
#elif McuMinINI_CONFIG_FS==McuMinINI_CONFIG_FS_TYPE_LITTLE_FS
|
||||
#include "minGlue-LittleFS.h"
|
||||
#else
|
||||
#error "define the type of system"
|
||||
#endif
|
||||
|
||||
956
TSM_PicoW_Sensor/McuLib/minIni/minIni.c
Normal file
956
TSM_PicoW_Sensor/McuLib/minIni/minIni.c
Normal file
@@ -0,0 +1,956 @@
|
||||
/* minIni - Multi-Platform INI file parser, suitable for embedded systems
|
||||
*
|
||||
* These routines are in part based on the article "Multiplatform .INI Files"
|
||||
* by Joseph J. Graf in the March 1994 issue of Dr. Dobb's Journal.
|
||||
*
|
||||
* Copyright (c) CompuPhase, 2008-2021
|
||||
*
|
||||
* 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.c 53 2015-01-18 13:35:11Z thiadmer.riemersma@gmail.com $
|
||||
*/
|
||||
|
||||
#if (defined _UNICODE || defined __UNICODE__ || defined UNICODE) && !defined INI_ANSIONLY
|
||||
# if !defined UNICODE /* for Windows */
|
||||
# define UNICODE
|
||||
# endif
|
||||
# if !defined _UNICODE /* for C library */
|
||||
# define _UNICODE
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#define MININI_IMPLEMENTATION
|
||||
#include "minIni.h"
|
||||
#if defined NDEBUG
|
||||
#ifndef assert
|
||||
#define assert(e)
|
||||
#endif
|
||||
#else
|
||||
#include <assert.h>
|
||||
#endif
|
||||
|
||||
#if !defined __T || defined INI_ANSIONLY
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#define TCHAR char
|
||||
#define __T(s) s
|
||||
#define _tcscat strcat
|
||||
#define _tcschr strchr
|
||||
#define _tcscmp strcmp
|
||||
#define _tcscpy strcpy
|
||||
#define _tcsicmp stricmp
|
||||
#define _tcslen strlen
|
||||
#define _tcsncmp strncmp
|
||||
#define _tcsnicmp strnicmp
|
||||
#define _tcsrchr strrchr
|
||||
#define _tcstol strtol
|
||||
#define _tcstod strtod
|
||||
#define _totupper toupper
|
||||
#define _stprintf sprintf
|
||||
#define _tfgets fgets
|
||||
#define _tfputs fputs
|
||||
#define _tfopen fopen
|
||||
#define _tremove remove
|
||||
#define _trename rename
|
||||
#endif
|
||||
|
||||
#if defined __linux || defined __linux__
|
||||
#define __LINUX__
|
||||
#elif defined FREEBSD && !defined __FreeBSD__
|
||||
#define __FreeBSD__
|
||||
#elif defined(_MSC_VER)
|
||||
#pragma warning(disable: 4996) /* for Microsoft Visual C/C++ */
|
||||
#endif
|
||||
#if !defined strnicmp && !defined PORTABLE_STRNICMP
|
||||
#if defined __LINUX__ || defined __FreeBSD__ || defined __OpenBSD__ || defined __APPLE__ || defined __NetBSD__ || defined __DragonFly__ || defined __GNUC__
|
||||
#define strnicmp strncasecmp
|
||||
#endif
|
||||
#endif
|
||||
#if !defined _totupper
|
||||
#define _totupper toupper
|
||||
#endif
|
||||
|
||||
#if !defined INI_LINETERM
|
||||
#if defined __LINUX__ || defined __FreeBSD__ || defined __OpenBSD__ || defined __APPLE__ || defined __NetBSD__ || defined __DragonFly__
|
||||
#define INI_LINETERM __T("\n")
|
||||
#else
|
||||
#define INI_LINETERM __T("\r\n")
|
||||
#endif
|
||||
#endif
|
||||
#if !defined INI_FILETYPE
|
||||
#error Missing definition for INI_FILETYPE.
|
||||
#endif
|
||||
|
||||
#if !defined sizearray
|
||||
#define sizearray(a) (sizeof(a) / sizeof((a)[0]))
|
||||
#endif
|
||||
|
||||
enum quote_option {
|
||||
QUOTE_NONE,
|
||||
QUOTE_ENQUOTE,
|
||||
QUOTE_DEQUOTE,
|
||||
};
|
||||
|
||||
#if defined PORTABLE_STRNICMP
|
||||
int strnicmp(const TCHAR *s1, const TCHAR *s2, size_t n)
|
||||
{
|
||||
while (n-- != 0 && (*s1 || *s2)) {
|
||||
register int c1, c2;
|
||||
c1 = *s1++;
|
||||
if ('a' <= c1 && c1 <= 'z')
|
||||
c1 += ('A' - 'a');
|
||||
c2 = *s2++;
|
||||
if ('a' <= c2 && c2 <= 'z')
|
||||
c2 += ('A' - 'a');
|
||||
if (c1 != c2)
|
||||
return c1 - c2;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif /* PORTABLE_STRNICMP */
|
||||
|
||||
static TCHAR *skipleading(const TCHAR *str)
|
||||
{
|
||||
assert(str != NULL);
|
||||
while ('\0' < *str && *str <= ' ')
|
||||
str++;
|
||||
return (TCHAR *)str;
|
||||
}
|
||||
|
||||
static TCHAR *skiptrailing(const TCHAR *str, const TCHAR *base)
|
||||
{
|
||||
assert(str != NULL);
|
||||
assert(base != NULL);
|
||||
while (str > base && '\0' < *(str-1) && *(str-1) <= ' ')
|
||||
str--;
|
||||
return (TCHAR *)str;
|
||||
}
|
||||
|
||||
static TCHAR *striptrailing(TCHAR *str)
|
||||
{
|
||||
TCHAR *ptr = skiptrailing(_tcschr(str, '\0'), str);
|
||||
assert(ptr != NULL);
|
||||
*ptr = '\0';
|
||||
return str;
|
||||
}
|
||||
|
||||
static TCHAR *ini_strncpy(TCHAR *dest, const TCHAR *source, size_t maxlen, enum quote_option option)
|
||||
{
|
||||
size_t d, s;
|
||||
|
||||
assert(maxlen>0);
|
||||
assert(source != NULL && dest != NULL);
|
||||
assert((dest < source || (dest == source && option != QUOTE_ENQUOTE)) || dest > source + strlen(source));
|
||||
if (option == QUOTE_ENQUOTE && maxlen < 3)
|
||||
option = QUOTE_NONE; /* cannot store two quotes and a terminating zero in less than 3 characters */
|
||||
|
||||
switch (option) {
|
||||
case QUOTE_NONE:
|
||||
for (d = 0; d < maxlen - 1 && source[d] != '\0'; d++)
|
||||
dest[d] = source[d];
|
||||
assert(d < maxlen);
|
||||
dest[d] = '\0';
|
||||
break;
|
||||
case QUOTE_ENQUOTE:
|
||||
d = 0;
|
||||
dest[d++] = '"';
|
||||
for (s = 0; source[s] != '\0' && d < maxlen - 2; s++, d++) {
|
||||
if (source[s] == '"') {
|
||||
if (d >= maxlen - 3)
|
||||
break; /* no space to store the escape character plus the one that follows it */
|
||||
dest[d++] = '\\';
|
||||
}
|
||||
dest[d] = source[s];
|
||||
}
|
||||
dest[d++] = '"';
|
||||
dest[d] = '\0';
|
||||
break;
|
||||
case QUOTE_DEQUOTE:
|
||||
for (d = s = 0; source[s] != '\0' && d < maxlen - 1; s++, d++) {
|
||||
if ((source[s] == '"' || source[s] == '\\') && source[s + 1] == '"')
|
||||
s++;
|
||||
dest[d] = source[s];
|
||||
}
|
||||
dest[d] = '\0';
|
||||
break;
|
||||
default:
|
||||
assert(0);
|
||||
}
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
static TCHAR *cleanstring(TCHAR *string, enum quote_option *quotes)
|
||||
{
|
||||
int isstring;
|
||||
TCHAR *ep;
|
||||
|
||||
assert(string != NULL);
|
||||
assert(quotes != NULL);
|
||||
|
||||
/* Remove a trailing comment */
|
||||
isstring = 0;
|
||||
for (ep = string; *ep != '\0' && ((*ep != ';' && *ep != '#') || isstring); ep++) {
|
||||
if (*ep == '"') {
|
||||
if (*(ep + 1) == '"')
|
||||
ep++; /* skip "" (both quotes) */
|
||||
else
|
||||
isstring = !isstring; /* single quote, toggle isstring */
|
||||
} else if (*ep == '\\' && *(ep + 1) == '"') {
|
||||
ep++; /* skip \" (both quotes */
|
||||
}
|
||||
}
|
||||
assert(ep != NULL && (*ep == '\0' || *ep == ';' || *ep == '#'));
|
||||
*ep = '\0'; /* terminate at a comment */
|
||||
striptrailing(string);
|
||||
/* Remove double quotes surrounding a value */
|
||||
*quotes = QUOTE_NONE;
|
||||
if (*string == '"' && (ep = _tcschr(string, '\0')) != NULL && *(ep - 1) == '"') {
|
||||
string++;
|
||||
*--ep = '\0';
|
||||
*quotes = QUOTE_DEQUOTE; /* this is a string, so remove escaped characters */
|
||||
}
|
||||
return string;
|
||||
}
|
||||
|
||||
static int getkeystring(INI_FILETYPE *fp, const TCHAR *Section, const TCHAR *Key,
|
||||
int idxSection, int idxKey, TCHAR *Buffer, int BufferSize,
|
||||
INI_FILEPOS *mark)
|
||||
{
|
||||
TCHAR *sp, *ep;
|
||||
int len, idx;
|
||||
enum quote_option quotes;
|
||||
TCHAR LocalBuffer[INI_BUFFERSIZE];
|
||||
|
||||
assert(fp != NULL);
|
||||
/* Move through file 1 line at a time until a section is matched or EOF. If
|
||||
* parameter Section is NULL, only look at keys above the first section. If
|
||||
* idxSection is positive, copy the relevant section name.
|
||||
*/
|
||||
len = (Section != NULL) ? (int)_tcslen(Section) : 0;
|
||||
if (len > 0 || idxSection >= 0) {
|
||||
assert(idxSection >= 0 || Section != NULL);
|
||||
idx = -1;
|
||||
do {
|
||||
do {
|
||||
if (!ini_read(LocalBuffer, INI_BUFFERSIZE, fp))
|
||||
return 0;
|
||||
sp = skipleading(LocalBuffer);
|
||||
ep = _tcsrchr(sp, ']');
|
||||
} while (*sp != '[' || ep == NULL);
|
||||
/* When arrived here, a section was found; now optionally skip leading and
|
||||
* trailing whitespace.
|
||||
*/
|
||||
assert(sp != NULL && *sp == '[');
|
||||
sp = skipleading(sp + 1);
|
||||
assert(ep != NULL && *ep == ']');
|
||||
ep = skiptrailing(ep, sp);
|
||||
} while ((((int)(ep-sp) != len || Section == NULL || _tcsnicmp(sp, Section, len) != 0) && ++idx != idxSection));
|
||||
if (idxSection >= 0) {
|
||||
if (idx == idxSection) {
|
||||
assert(ep != NULL);
|
||||
*ep = '\0'; /* the end of the section name was found earlier */
|
||||
ini_strncpy(Buffer, sp, BufferSize, QUOTE_NONE);
|
||||
return 1;
|
||||
}
|
||||
return 0; /* no more section found */
|
||||
}
|
||||
}
|
||||
|
||||
/* Now that the section has been found, find the entry.
|
||||
* Stop searching upon leaving the section's area.
|
||||
*/
|
||||
assert(Key != NULL || idxKey >= 0);
|
||||
len = (Key != NULL) ? (int)_tcslen(Key) : 0;
|
||||
idx = -1;
|
||||
do {
|
||||
if (mark != NULL)
|
||||
(void)ini_tell(fp, mark); /* optionally keep the mark to the start of the line */
|
||||
if (!ini_read(LocalBuffer,INI_BUFFERSIZE,fp) || *(sp = skipleading(LocalBuffer)) == '[')
|
||||
return 0;
|
||||
sp = skipleading(LocalBuffer);
|
||||
ep = _tcschr(sp, '='); /* Parse out the equal sign */
|
||||
if (ep == NULL)
|
||||
ep = _tcschr(sp, ':');
|
||||
} while (*sp == ';' || *sp == '#' || ep == NULL
|
||||
|| ((len == 0 || (int)(skiptrailing(ep,sp)-sp) != len || _tcsnicmp(sp,Key,len) != 0) && ++idx != idxKey));
|
||||
if (idxKey >= 0) {
|
||||
if (idx == idxKey) {
|
||||
assert(ep != NULL);
|
||||
assert(*ep == '=' || *ep == ':');
|
||||
*ep = '\0';
|
||||
striptrailing(sp);
|
||||
ini_strncpy(Buffer, sp, BufferSize, QUOTE_NONE);
|
||||
return 1;
|
||||
}
|
||||
return 0; /* no more key found (in this section) */
|
||||
}
|
||||
|
||||
/* Copy up to BufferSize chars to buffer */
|
||||
assert(ep != NULL);
|
||||
assert(*ep == '=' || *ep == ':');
|
||||
sp = skipleading(ep + 1);
|
||||
sp = cleanstring(sp, "es); /* Remove a trailing comment */
|
||||
ini_strncpy(Buffer, sp, BufferSize, quotes);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/** ini_gets()
|
||||
* \param Section the name of the section to search for
|
||||
* \param Key the name of the entry to find the value of
|
||||
* \param DefValue default string in the event of a failed read
|
||||
* \param Buffer a pointer to the buffer to copy into
|
||||
* \param BufferSize the maximum number of characters to copy
|
||||
* \param Filename the name and full path of the .ini file to read from
|
||||
*
|
||||
* \return the number of characters copied into the supplied buffer
|
||||
*/
|
||||
int ini_gets(const TCHAR *Section, const TCHAR *Key, const TCHAR *DefValue,
|
||||
TCHAR *Buffer, int BufferSize, const TCHAR *Filename)
|
||||
{
|
||||
INI_FILETYPE fp;
|
||||
int ok = 0;
|
||||
|
||||
if (Buffer == NULL || BufferSize <= 0 || Key == NULL)
|
||||
return 0;
|
||||
if (ini_openread(Filename, &fp)) {
|
||||
ok = getkeystring(&fp, Section, Key, -1, -1, Buffer, BufferSize, NULL);
|
||||
(void)ini_close(&fp);
|
||||
}
|
||||
if (!ok)
|
||||
ini_strncpy(Buffer, (DefValue != NULL) ? DefValue : __T(""), BufferSize, QUOTE_NONE);
|
||||
return (int)_tcslen(Buffer);
|
||||
}
|
||||
|
||||
/** ini_getl()
|
||||
* \param Section the name of the section to search for
|
||||
* \param Key the name of the entry to find the value of
|
||||
* \param DefValue the default value in the event of a failed read
|
||||
* \param Filename the name of the .ini file to read from
|
||||
*
|
||||
* \return the value located at Key
|
||||
*/
|
||||
long ini_getl(const TCHAR *Section, const TCHAR *Key, long DefValue, const TCHAR *Filename)
|
||||
{
|
||||
TCHAR LocalBuffer[64];
|
||||
int len = ini_gets(Section, Key, __T(""), LocalBuffer, sizearray(LocalBuffer), Filename);
|
||||
return (len == 0) ? DefValue
|
||||
: ((len >= 2 && _totupper((int)LocalBuffer[1]) == 'X') ? _tcstol(LocalBuffer, NULL, 16)
|
||||
: _tcstol(LocalBuffer, NULL, 10));
|
||||
}
|
||||
|
||||
#if defined INI_REAL
|
||||
/** ini_getf()
|
||||
* \param Section the name of the section to search for
|
||||
* \param Key the name of the entry to find the value of
|
||||
* \param DefValue the default value in the event of a failed read
|
||||
* \param Filename the name of the .ini file to read from
|
||||
*
|
||||
* \return the value located at Key
|
||||
*/
|
||||
INI_REAL ini_getf(const TCHAR *Section, const TCHAR *Key, INI_REAL DefValue, const TCHAR *Filename)
|
||||
{
|
||||
TCHAR LocalBuffer[64];
|
||||
int len = ini_gets(Section, Key, __T(""), LocalBuffer, sizearray(LocalBuffer), Filename);
|
||||
return (len == 0) ? DefValue : ini_atof(LocalBuffer);
|
||||
}
|
||||
#endif
|
||||
|
||||
/** ini_getbool()
|
||||
* \param Section the name of the section to search for
|
||||
* \param Key the name of the entry to find the value of
|
||||
* \param DefValue default value in the event of a failed read; it should
|
||||
* zero (0) or one (1).
|
||||
* \param Filename the name and full path of the .ini file to read from
|
||||
*
|
||||
* A true boolean is found if one of the following is matched:
|
||||
* - A string starting with 'y' or 'Y'
|
||||
* - A string starting with 't' or 'T'
|
||||
* - A string starting with '1'
|
||||
*
|
||||
* A false boolean is found if one of the following is matched:
|
||||
* - A string starting with 'n' or 'N'
|
||||
* - A string starting with 'f' or 'F'
|
||||
* - A string starting with '0'
|
||||
*
|
||||
* \return the true/false flag as interpreted at Key
|
||||
*/
|
||||
int ini_getbool(const TCHAR *Section, const TCHAR *Key, int DefValue, const TCHAR *Filename)
|
||||
{
|
||||
TCHAR LocalBuffer[2] = __T("");
|
||||
int ret;
|
||||
|
||||
ini_gets(Section, Key, __T(""), LocalBuffer, sizearray(LocalBuffer), Filename);
|
||||
LocalBuffer[0] = (TCHAR)_totupper((int)LocalBuffer[0]);
|
||||
if (LocalBuffer[0] == 'Y' || LocalBuffer[0] == '1' || LocalBuffer[0] == 'T')
|
||||
ret = 1;
|
||||
else if (LocalBuffer[0] == 'N' || LocalBuffer[0] == '0' || LocalBuffer[0] == 'F')
|
||||
ret = 0;
|
||||
else
|
||||
ret = DefValue;
|
||||
|
||||
return(ret);
|
||||
}
|
||||
|
||||
/** ini_getsection()
|
||||
* \param idx the zero-based sequence number of the section to return
|
||||
* \param Buffer a pointer to the buffer to copy into
|
||||
* \param BufferSize the maximum number of characters to copy
|
||||
* \param Filename the name and full path of the .ini file to read from
|
||||
*
|
||||
* \return the number of characters copied into the supplied buffer
|
||||
*/
|
||||
int ini_getsection(int idx, TCHAR *Buffer, int BufferSize, const TCHAR *Filename)
|
||||
{
|
||||
INI_FILETYPE fp;
|
||||
int ok = 0;
|
||||
|
||||
if (Buffer == NULL || BufferSize <= 0 || idx < 0)
|
||||
return 0;
|
||||
if (ini_openread(Filename, &fp)) {
|
||||
ok = getkeystring(&fp, NULL, NULL, idx, -1, Buffer, BufferSize, NULL);
|
||||
(void)ini_close(&fp);
|
||||
}
|
||||
if (!ok)
|
||||
*Buffer = '\0';
|
||||
return (int)_tcslen(Buffer);
|
||||
}
|
||||
|
||||
/** ini_getkey()
|
||||
* \param Section the name of the section to browse through, or NULL to
|
||||
* browse through the keys outside any section
|
||||
* \param idx the zero-based sequence number of the key to return
|
||||
* \param Buffer a pointer to the buffer to copy into
|
||||
* \param BufferSize the maximum number of characters to copy
|
||||
* \param Filename the name and full path of the .ini file to read from
|
||||
*
|
||||
* \return the number of characters copied into the supplied buffer
|
||||
*/
|
||||
int ini_getkey(const TCHAR *Section, int idx, TCHAR *Buffer, int BufferSize, const TCHAR *Filename)
|
||||
{
|
||||
INI_FILETYPE fp;
|
||||
int ok = 0;
|
||||
|
||||
if (Buffer == NULL || BufferSize <= 0 || idx < 0)
|
||||
return 0;
|
||||
if (ini_openread(Filename, &fp)) {
|
||||
ok = getkeystring(&fp, Section, NULL, -1, idx, Buffer, BufferSize, NULL);
|
||||
(void)ini_close(&fp);
|
||||
}
|
||||
if (!ok)
|
||||
*Buffer = '\0';
|
||||
return (int)_tcslen(Buffer);
|
||||
}
|
||||
|
||||
/** ini_hassection()
|
||||
* \param Section the name of the section to search for
|
||||
* \param Filename the name of the .ini file to read from
|
||||
*
|
||||
* \return 1 if the section is found, 0 if not found
|
||||
*/
|
||||
int ini_hassection(const mTCHAR *Section, const mTCHAR *Filename)
|
||||
{
|
||||
TCHAR LocalBuffer[32]; /* dummy buffer */
|
||||
INI_FILETYPE fp;
|
||||
int ok = 0;
|
||||
|
||||
if (ini_openread(Filename, &fp)) {
|
||||
ok = getkeystring(&fp, Section, NULL, -1, 0, LocalBuffer, sizearray(LocalBuffer), NULL);
|
||||
(void)ini_close(&fp);
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
|
||||
/** ini_haskey()
|
||||
* \param Section the name of the section to search for
|
||||
* \param Key the name of the entry to find the value of
|
||||
* \param Filename the name of the .ini file to read from
|
||||
*
|
||||
* \return 1 if the key is found, 0 if not found
|
||||
*/
|
||||
int ini_haskey(const mTCHAR *Section, const mTCHAR *Key, const mTCHAR *Filename)
|
||||
{
|
||||
TCHAR LocalBuffer[32]; /* dummy buffer */
|
||||
INI_FILETYPE fp;
|
||||
int ok = 0;
|
||||
|
||||
if (ini_openread(Filename, &fp)) {
|
||||
ok = getkeystring(&fp, Section, Key, -1, -1, LocalBuffer, sizearray(LocalBuffer), NULL);
|
||||
(void)ini_close(&fp);
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
|
||||
|
||||
#if !defined INI_NOBROWSE
|
||||
/** ini_browse()
|
||||
* \param Callback a pointer to a function that will be called for every
|
||||
* setting in the INI file.
|
||||
* \param UserData arbitrary data, which the function passes on the
|
||||
* \c Callback function
|
||||
* \param Filename the name and full path of the .ini file to read from
|
||||
*
|
||||
* \return 1 on success, 0 on failure (INI file not found)
|
||||
*
|
||||
* \note The \c Callback function must return 1 to continue
|
||||
* browsing through the INI file, or 0 to stop. Even when the
|
||||
* callback stops the browsing, this function will return 1
|
||||
* (for success).
|
||||
*/
|
||||
int ini_browse(INI_CALLBACK Callback, void *UserData, const TCHAR *Filename)
|
||||
{
|
||||
TCHAR LocalBuffer[INI_BUFFERSIZE];
|
||||
int lenSec, lenKey;
|
||||
enum quote_option quotes;
|
||||
INI_FILETYPE fp;
|
||||
|
||||
if (Callback == NULL)
|
||||
return 0;
|
||||
if (!ini_openread(Filename, &fp))
|
||||
return 0;
|
||||
|
||||
LocalBuffer[0] = '\0'; /* copy an empty section in the buffer */
|
||||
lenSec = (int)_tcslen(LocalBuffer) + 1;
|
||||
for ( ;; ) {
|
||||
TCHAR *sp, *ep;
|
||||
if (!ini_read(LocalBuffer + lenSec, INI_BUFFERSIZE - lenSec, &fp))
|
||||
break;
|
||||
sp = skipleading(LocalBuffer + lenSec);
|
||||
/* ignore empty strings and comments */
|
||||
if (*sp == '\0' || *sp == ';' || *sp == '#')
|
||||
continue;
|
||||
/* see whether we reached a new section */
|
||||
ep = _tcsrchr(sp, ']');
|
||||
if (*sp == '[' && ep != NULL) {
|
||||
sp = skipleading(sp + 1);
|
||||
ep = skiptrailing(ep, sp);
|
||||
*ep = '\0';
|
||||
ini_strncpy(LocalBuffer, sp, INI_BUFFERSIZE, QUOTE_NONE);
|
||||
lenSec = (int)_tcslen(LocalBuffer) + 1;
|
||||
continue;
|
||||
}
|
||||
/* not a new section, test for a key/value pair */
|
||||
ep = _tcschr(sp, '='); /* test for the equal sign or colon */
|
||||
if (ep == NULL)
|
||||
ep = _tcschr(sp, ':');
|
||||
if (ep == NULL)
|
||||
continue; /* invalid line, ignore */
|
||||
*ep++ = '\0'; /* split the key from the value */
|
||||
striptrailing(sp);
|
||||
ini_strncpy(LocalBuffer + lenSec, sp, INI_BUFFERSIZE - lenSec, QUOTE_NONE);
|
||||
lenKey = (int)_tcslen(LocalBuffer + lenSec) + 1;
|
||||
/* clean up the value */
|
||||
sp = skipleading(ep);
|
||||
sp = cleanstring(sp, "es); /* Remove a trailing comment */
|
||||
ini_strncpy(LocalBuffer + lenSec + lenKey, sp, INI_BUFFERSIZE - lenSec - lenKey, quotes);
|
||||
/* call the callback */
|
||||
if (!Callback(LocalBuffer, LocalBuffer + lenSec, LocalBuffer + lenSec + lenKey, UserData))
|
||||
break;
|
||||
}
|
||||
|
||||
(void)ini_close(&fp);
|
||||
return 1;
|
||||
}
|
||||
#endif /* INI_NOBROWSE */
|
||||
|
||||
#if !McuMinINI_CONFIG_READ_ONLY
|
||||
static void ini_tempname(TCHAR *dest, const TCHAR *source, int maxlength)
|
||||
{
|
||||
TCHAR *p;
|
||||
|
||||
ini_strncpy(dest, source, maxlength, QUOTE_NONE);
|
||||
p = _tcschr(dest, '\0');
|
||||
assert(p != NULL);
|
||||
*(p - 1) = '~';
|
||||
}
|
||||
|
||||
static enum quote_option check_enquote(const TCHAR *Value)
|
||||
{
|
||||
const TCHAR *p;
|
||||
|
||||
/* run through the value, if it has trailing spaces, or '"', ';' or '#'
|
||||
* characters, enquote it
|
||||
*/
|
||||
assert(Value != NULL);
|
||||
for (p = Value; *p != '\0' && *p != '"' && *p != ';' && *p != '#'; p++)
|
||||
/* nothing */;
|
||||
return (*p != '\0' || (p > Value && *(p - 1) == ' ')) ? QUOTE_ENQUOTE : QUOTE_NONE;
|
||||
}
|
||||
|
||||
static void writesection(TCHAR *LocalBuffer, const TCHAR *Section, INI_FILETYPE *fp)
|
||||
{
|
||||
if (Section != NULL && _tcslen(Section) > 0) {
|
||||
TCHAR *p;
|
||||
LocalBuffer[0] = '[';
|
||||
ini_strncpy(LocalBuffer + 1, Section, INI_BUFFERSIZE - 4, QUOTE_NONE); /* -1 for '[', -1 for ']', -2 for '\r\n' */
|
||||
p = _tcschr(LocalBuffer, '\0');
|
||||
assert(p != NULL);
|
||||
*p++ = ']';
|
||||
_tcscpy(p, INI_LINETERM); /* copy line terminator (typically "\n") */
|
||||
if (fp != NULL)
|
||||
(void)ini_write(LocalBuffer, fp);
|
||||
}
|
||||
}
|
||||
|
||||
static void writekey(TCHAR *LocalBuffer, const TCHAR *Key, const TCHAR *Value, INI_FILETYPE *fp)
|
||||
{
|
||||
TCHAR *p;
|
||||
enum quote_option option = check_enquote(Value);
|
||||
ini_strncpy(LocalBuffer, Key, INI_BUFFERSIZE - 3, QUOTE_NONE); /* -1 for '=', -2 for '\r\n' */
|
||||
p = _tcschr(LocalBuffer, '\0');
|
||||
assert(p != NULL);
|
||||
*p++ = '=';
|
||||
ini_strncpy(p, Value, INI_BUFFERSIZE - (p - LocalBuffer) - 2, option); /* -2 for '\r\n' */
|
||||
p = _tcschr(LocalBuffer, '\0');
|
||||
assert(p != NULL);
|
||||
_tcscpy(p, INI_LINETERM); /* copy line terminator (typically "\n") */
|
||||
if (fp != NULL)
|
||||
(void)ini_write(LocalBuffer, fp);
|
||||
}
|
||||
|
||||
static int cache_accum(const TCHAR *string, int *size, int max)
|
||||
{
|
||||
int len = (int)_tcslen(string);
|
||||
if (*size + len >= max)
|
||||
return 0;
|
||||
*size += len;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int cache_flush(TCHAR *buffer, int *size,
|
||||
INI_FILETYPE *rfp, INI_FILETYPE *wfp, INI_FILEPOS *mark)
|
||||
{
|
||||
int terminator_len = (int)_tcslen(INI_LINETERM);
|
||||
int pos = 0, pos_prev = -1;
|
||||
|
||||
(void)ini_seek(rfp, mark);
|
||||
assert(buffer != NULL);
|
||||
buffer[0] = '\0';
|
||||
assert(size != NULL);
|
||||
assert(*size <= INI_BUFFERSIZE);
|
||||
while (pos < *size && pos != pos_prev) {
|
||||
pos_prev = pos; /* to guard against zero bytes in the INI file */
|
||||
(void)ini_read(buffer + pos, INI_BUFFERSIZE - pos, rfp);
|
||||
while (pos < *size && buffer[pos] != '\0')
|
||||
pos++; /* cannot use _tcslen() because buffer may not be zero-terminated */
|
||||
}
|
||||
if (buffer[0] != '\0') {
|
||||
assert(pos > 0 && pos <= INI_BUFFERSIZE);
|
||||
if (pos == INI_BUFFERSIZE)
|
||||
pos--;
|
||||
buffer[pos] = '\0'; /* force zero-termination (may be left unterminated in the above while loop) */
|
||||
(void)ini_write(buffer, wfp);
|
||||
}
|
||||
(void)ini_tell(rfp, mark); /* update mark */
|
||||
*size = 0;
|
||||
/* return whether the buffer ended with a line termination */
|
||||
return (pos > terminator_len) && (_tcscmp(buffer + pos - terminator_len, INI_LINETERM) == 0);
|
||||
}
|
||||
|
||||
static int close_rename(INI_FILETYPE *rfp, INI_FILETYPE *wfp, const TCHAR *filename, TCHAR *buffer)
|
||||
{
|
||||
(void)ini_close(rfp);
|
||||
(void)ini_close(wfp);
|
||||
(void)ini_tempname(buffer, filename, INI_BUFFERSIZE);
|
||||
#if defined ini_remove || defined INI_REMOVE
|
||||
(void)ini_remove(filename);
|
||||
#endif
|
||||
(void)ini_rename(buffer, filename);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/** ini_puts()
|
||||
* \param Section the name of the section to write the string in
|
||||
* \param Key the name of the entry to write, or NULL to erase all keys in the section
|
||||
* \param Value a pointer to the buffer the string, or NULL to erase the key
|
||||
* \param Filename the name and full path of the .ini file to write to
|
||||
*
|
||||
* \return 1 if successful, otherwise 0
|
||||
*/
|
||||
int ini_puts(const TCHAR *Section, const TCHAR *Key, const TCHAR *Value, const TCHAR *Filename)
|
||||
{
|
||||
INI_FILETYPE rfp;
|
||||
INI_FILETYPE wfp;
|
||||
INI_FILEPOS mark;
|
||||
INI_FILEPOS head;
|
||||
TCHAR *sp, *ep;
|
||||
TCHAR LocalBuffer[INI_BUFFERSIZE];
|
||||
int len, match, flag, cachelen;
|
||||
|
||||
assert(Filename != NULL);
|
||||
if (!ini_openread(Filename, &rfp)) {
|
||||
/* If the .ini file doesn't exist, make a new file */
|
||||
if (Key != NULL && Value != NULL) {
|
||||
if (!ini_openwrite(Filename, &wfp))
|
||||
return 0;
|
||||
writesection(LocalBuffer, Section, &wfp);
|
||||
writekey(LocalBuffer, Key, Value, &wfp);
|
||||
(void)ini_close(&wfp);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* If parameters Key and Value are valid (so this is not an "erase" request)
|
||||
* and the setting already exists, there are two short-cuts to avoid rewriting
|
||||
* the INI file.
|
||||
*/
|
||||
if (Key != NULL && Value != NULL) {
|
||||
match = getkeystring(&rfp, Section, Key, -1, -1, LocalBuffer, sizearray(LocalBuffer), &head);
|
||||
if (match) {
|
||||
/* if the current setting is identical to the one to write, there is
|
||||
* nothing to do.
|
||||
*/
|
||||
if (_tcscmp(LocalBuffer,Value) == 0) {
|
||||
(void)ini_close(&rfp);
|
||||
return 1;
|
||||
}
|
||||
/* if the new setting has the same length as the current setting, and the
|
||||
* glue file permits file read/write access, we can modify in place.
|
||||
*/
|
||||
#if defined ini_openrewrite || defined INI_OPENREWRITE
|
||||
INI_FILEPOS tail;
|
||||
/* we already have the start of the (raw) line, get the end too */
|
||||
(void)ini_tell(&rfp, &tail);
|
||||
/* create new buffer (without writing it to file) */
|
||||
writekey(LocalBuffer, Key, Value, NULL);
|
||||
if (_tcslen(LocalBuffer) == (size_t)(tail - head)) {
|
||||
/* length matches, close the file & re-open for read/write, then
|
||||
* write at the correct position
|
||||
*/
|
||||
(void)ini_close(&rfp);
|
||||
if (!ini_openrewrite(Filename, &wfp))
|
||||
return 0;
|
||||
(void)ini_seek(&wfp, &head);
|
||||
(void)ini_write(LocalBuffer, &wfp);
|
||||
(void)ini_close(&wfp);
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
/* key not found, or different value & length -> proceed */
|
||||
} else if (Key != NULL && Value == NULL) {
|
||||
/* Conversely, for a request to delete a setting; if that setting isn't
|
||||
present, just return */
|
||||
match = getkeystring(&rfp, Section, Key, -1, -1, LocalBuffer, sizearray(LocalBuffer), NULL);
|
||||
if (!match) {
|
||||
(void)ini_close(&rfp);
|
||||
return 1;
|
||||
}
|
||||
/* key found -> proceed to delete it */
|
||||
}
|
||||
|
||||
/* Get a temporary file name to copy to. Use the existing name, but with
|
||||
* the last character set to a '~'.
|
||||
*/
|
||||
(void)ini_close(&rfp);
|
||||
ini_tempname(LocalBuffer, Filename, INI_BUFFERSIZE);
|
||||
if (!ini_openwrite(LocalBuffer, &wfp))
|
||||
return 0;
|
||||
/* In the case of (advisory) file locks, ini_openwrite() may have been blocked
|
||||
* on the open, and after the block is lifted, the original file may have been
|
||||
* renamed, which is why the original file was closed and is now reopened */
|
||||
if (!ini_openread(Filename, &rfp)) {
|
||||
/* If the .ini file doesn't exist any more, make a new file */
|
||||
assert(Key != NULL && Value != NULL);
|
||||
writesection(LocalBuffer, Section, &wfp);
|
||||
writekey(LocalBuffer, Key, Value, &wfp);
|
||||
(void)ini_close(&wfp);
|
||||
return 1;
|
||||
}
|
||||
|
||||
(void)ini_tell(&rfp, &mark);
|
||||
cachelen = 0;
|
||||
|
||||
/* Move through the file one line at a time until a section is
|
||||
* matched or until EOF. Copy to temp file as it is read.
|
||||
*/
|
||||
len = (Section != NULL) ? (int)_tcslen(Section) : 0;
|
||||
if (len > 0) {
|
||||
do {
|
||||
if (!ini_read(LocalBuffer, INI_BUFFERSIZE, &rfp)) {
|
||||
/* Failed to find section, so add one to the end */
|
||||
flag = cache_flush(LocalBuffer, &cachelen, &rfp, &wfp, &mark);
|
||||
if (Key!=NULL && Value!=NULL) {
|
||||
if (!flag)
|
||||
(void)ini_write(INI_LINETERM, &wfp); /* force a new line behind the last line of the INI file */
|
||||
writesection(LocalBuffer, Section, &wfp);
|
||||
writekey(LocalBuffer, Key, Value, &wfp);
|
||||
}
|
||||
return close_rename(&rfp, &wfp, Filename, LocalBuffer); /* clean up and rename */
|
||||
}
|
||||
/* Check whether this line is a section */
|
||||
sp = skipleading(LocalBuffer);
|
||||
ep = _tcsrchr(sp, ']');
|
||||
match = (*sp == '[' && ep != NULL);
|
||||
if (match) {
|
||||
/* A section was found, skip leading and trailing whitespace */
|
||||
assert(sp != NULL && *sp == '[');
|
||||
sp = skipleading(sp + 1);
|
||||
assert(ep != NULL && *ep == ']');
|
||||
ep = skiptrailing(ep, sp);
|
||||
match = ((int)(ep-sp) == len && _tcsnicmp(sp, Section, len) == 0);
|
||||
}
|
||||
/* Copy the line from source to dest, but not if this is the section that
|
||||
* we are looking for and this section must be removed
|
||||
*/
|
||||
if (!match || Key != NULL) {
|
||||
if (!cache_accum(LocalBuffer, &cachelen, INI_BUFFERSIZE)) {
|
||||
cache_flush(LocalBuffer, &cachelen, &rfp, &wfp, &mark);
|
||||
(void)ini_read(LocalBuffer, INI_BUFFERSIZE, &rfp);
|
||||
cache_accum(LocalBuffer, &cachelen, INI_BUFFERSIZE);
|
||||
}
|
||||
}
|
||||
} while (!match);
|
||||
}
|
||||
cache_flush(LocalBuffer, &cachelen, &rfp, &wfp, &mark);
|
||||
/* when deleting a section, the section head that was just found has not been
|
||||
* copied to the output file, but because this line was not "accumulated" in
|
||||
* the cache, the position in the input file was reset to the point just
|
||||
* before the section; this must now be skipped (again)
|
||||
*/
|
||||
if (Key == NULL) {
|
||||
(void)ini_read(LocalBuffer, INI_BUFFERSIZE, &rfp);
|
||||
(void)ini_tell(&rfp, &mark);
|
||||
}
|
||||
|
||||
/* Now that the section has been found, find the entry. Stop searching
|
||||
* upon leaving the section's area. Copy the file as it is read
|
||||
* and create an entry if one is not found.
|
||||
*/
|
||||
len = (Key != NULL) ? (int)_tcslen(Key) : 0;
|
||||
for( ;; ) {
|
||||
if (!ini_read(LocalBuffer, INI_BUFFERSIZE, &rfp)) {
|
||||
/* EOF without an entry so make one */
|
||||
flag = cache_flush(LocalBuffer, &cachelen, &rfp, &wfp, &mark);
|
||||
if (Key!=NULL && Value!=NULL) {
|
||||
if (!flag)
|
||||
(void)ini_write(INI_LINETERM, &wfp); /* force a new line behind the last line of the INI file */
|
||||
writekey(LocalBuffer, Key, Value, &wfp);
|
||||
}
|
||||
return close_rename(&rfp, &wfp, Filename, LocalBuffer); /* clean up and rename */
|
||||
}
|
||||
sp = skipleading(LocalBuffer);
|
||||
ep = _tcschr(sp, '='); /* Parse out the equal sign */
|
||||
if (ep == NULL)
|
||||
ep = _tcschr(sp, ':');
|
||||
match = (ep != NULL && len > 0 && (int)(skiptrailing(ep,sp)-sp) == len && _tcsnicmp(sp,Key,len) == 0);
|
||||
if ((Key != NULL && match) || *sp == '[')
|
||||
break; /* found the key, or found a new section */
|
||||
/* copy other keys in the section */
|
||||
if (Key == NULL) {
|
||||
(void)ini_tell(&rfp, &mark); /* we are deleting the entire section, so update the read position */
|
||||
} else {
|
||||
if (!cache_accum(LocalBuffer, &cachelen, INI_BUFFERSIZE)) {
|
||||
cache_flush(LocalBuffer, &cachelen, &rfp, &wfp, &mark);
|
||||
(void)ini_read(LocalBuffer, INI_BUFFERSIZE, &rfp);
|
||||
cache_accum(LocalBuffer, &cachelen, INI_BUFFERSIZE);
|
||||
}
|
||||
}
|
||||
}
|
||||
/* the key was found, or we just dropped on the next section (meaning that it
|
||||
* wasn't found); in both cases we need to write the key, but in the latter
|
||||
* case, we also need to write the line starting the new section after writing
|
||||
* the key
|
||||
*/
|
||||
flag = (*sp == '[');
|
||||
cache_flush(LocalBuffer, &cachelen, &rfp, &wfp, &mark);
|
||||
if (Key != NULL && Value != NULL)
|
||||
writekey(LocalBuffer, Key, Value, &wfp);
|
||||
/* cache_flush() reset the "read pointer" to the start of the line with the
|
||||
* previous key or the new section; read it again (because writekey() destroyed
|
||||
* the buffer)
|
||||
*/
|
||||
(void)ini_read(LocalBuffer, INI_BUFFERSIZE, &rfp);
|
||||
if (flag) {
|
||||
/* the new section heading needs to be copied to the output file */
|
||||
cache_accum(LocalBuffer, &cachelen, INI_BUFFERSIZE);
|
||||
} else {
|
||||
/* forget the old key line */
|
||||
(void)ini_tell(&rfp, &mark);
|
||||
}
|
||||
/* Copy the rest of the INI file */
|
||||
while (ini_read(LocalBuffer, INI_BUFFERSIZE, &rfp)) {
|
||||
if (!cache_accum(LocalBuffer, &cachelen, INI_BUFFERSIZE)) {
|
||||
cache_flush(LocalBuffer, &cachelen, &rfp, &wfp, &mark);
|
||||
(void)ini_read(LocalBuffer, INI_BUFFERSIZE, &rfp);
|
||||
cache_accum(LocalBuffer, &cachelen, INI_BUFFERSIZE);
|
||||
}
|
||||
}
|
||||
cache_flush(LocalBuffer, &cachelen, &rfp, &wfp, &mark);
|
||||
return close_rename(&rfp, &wfp, Filename, LocalBuffer); /* clean up and rename */
|
||||
}
|
||||
|
||||
/* Ansi C "itoa" based on Kernighan & Ritchie's "Ansi C" book. */
|
||||
#define ABS(v) ((v) < 0 ? -(v) : (v))
|
||||
|
||||
static void strreverse(TCHAR *str)
|
||||
{
|
||||
int i, j;
|
||||
for (i = 0, j = (int)_tcslen(str) - 1; i < j; i++, j--) {
|
||||
TCHAR t = str[i];
|
||||
str[i] = str[j];
|
||||
str[j] = t;
|
||||
}
|
||||
}
|
||||
|
||||
static void long2str(long value, TCHAR *str)
|
||||
{
|
||||
int i = 0;
|
||||
long sign = value;
|
||||
|
||||
/* generate digits in reverse order */
|
||||
do {
|
||||
int n = (int)(value % 10); /* get next lowest digit */
|
||||
str[i++] = (TCHAR)(ABS(n) + '0'); /* handle case of negative digit */
|
||||
} while (value /= 10); /* delete the lowest digit */
|
||||
if (sign < 0)
|
||||
str[i++] = '-';
|
||||
str[i] = '\0';
|
||||
|
||||
strreverse(str);
|
||||
}
|
||||
|
||||
/** ini_putl()
|
||||
* \param Section the name of the section to write the value in
|
||||
* \param Key the name of the entry to write
|
||||
* \param Value the value to write
|
||||
* \param Filename the name and full path of the .ini file to write to
|
||||
*
|
||||
* \return 1 if successful, otherwise 0
|
||||
*/
|
||||
int ini_putl(const TCHAR *Section, const TCHAR *Key, long Value, const TCHAR *Filename)
|
||||
{
|
||||
TCHAR LocalBuffer[32];
|
||||
long2str(Value, LocalBuffer);
|
||||
return ini_puts(Section, Key, LocalBuffer, Filename);
|
||||
}
|
||||
|
||||
#if defined INI_REAL
|
||||
/** ini_putf()
|
||||
* \param Section the name of the section to write the value in
|
||||
* \param Key the name of the entry to write
|
||||
* \param Value the value to write
|
||||
* \param Filename the name and full path of the .ini file to write to
|
||||
*
|
||||
* \return 1 if successful, otherwise 0
|
||||
*/
|
||||
int ini_putf(const TCHAR *Section, const TCHAR *Key, INI_REAL Value, const TCHAR *Filename)
|
||||
{
|
||||
TCHAR LocalBuffer[64];
|
||||
ini_ftoa(LocalBuffer, Value);
|
||||
return ini_puts(Section, Key, LocalBuffer, Filename);
|
||||
}
|
||||
#endif /* INI_REAL */
|
||||
#endif /* !INI_READONLY */
|
||||
|
||||
173
TSM_PicoW_Sensor/McuLib/minIni/minIni.h
Normal file
173
TSM_PicoW_Sensor/McuLib/minIni/minIni.h
Normal file
@@ -0,0 +1,173 @@
|
||||
/* minIni - Multi-Platform INI file parser, suitable for embedded systems
|
||||
*
|
||||
* Copyright (c) CompuPhase, 2008-2021
|
||||
*
|
||||
* 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 "McuMinINIconfig.h" /* MinIni config file */
|
||||
#include "minGlue.h"
|
||||
#include <stddef.h> /* for size_t */
|
||||
|
||||
#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 McuMinINI_CONFIG_BUFFER_SIZE
|
||||
#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);
|
||||
|
||||
int ini_hassection(const mTCHAR *Section, const mTCHAR *Filename);
|
||||
int ini_haskey(const mTCHAR *Section, const mTCHAR *Key, 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 !McuMinINI_CONFIG_READ_ONLY
|
||||
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);
|
||||
#if defined INI_REAL
|
||||
int ini_putf(const mTCHAR *Section, const mTCHAR *Key, INI_REAL Value, const mTCHAR *Filename);
|
||||
#endif
|
||||
#endif /* !McuMinINI_CONFIG_READ_ONLY */
|
||||
|
||||
#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 PORTABLE_STRNICMP
|
||||
int strnicmp(const TCHAR *s1, const TCHAR *s2, size_t n);
|
||||
#endif /* PORTABLE_STRNICMP */
|
||||
|
||||
#if defined __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#if defined __cplusplus
|
||||
|
||||
#if defined __WXWINDOWS__
|
||||
#include "wxMinIni.h"
|
||||
#else
|
||||
#include <string>
|
||||
|
||||
/* The C++ class in minIni.h was contributed by Steven Van Ingelgem. */
|
||||
class minIni
|
||||
{
|
||||
public:
|
||||
minIni(const std::string& filename) : iniFilename(filename)
|
||||
{ }
|
||||
|
||||
bool getbool(const std::string& Section, const std::string& Key, bool DefValue=false) const
|
||||
{ return ini_getbool(Section.c_str(), Key.c_str(), int(DefValue), iniFilename.c_str()) != 0; }
|
||||
|
||||
long getl(const std::string& Section, const std::string& Key, long DefValue=0) const
|
||||
{ return ini_getl(Section.c_str(), Key.c_str(), DefValue, iniFilename.c_str()); }
|
||||
|
||||
int geti(const std::string& Section, const std::string& Key, int DefValue=0) const
|
||||
{ return static_cast<int>(this->getl(Section, Key, long(DefValue))); }
|
||||
|
||||
std::string gets(const std::string& Section, const std::string& Key, const std::string& DefValue="") const
|
||||
{
|
||||
char buffer[INI_BUFFERSIZE];
|
||||
ini_gets(Section.c_str(), Key.c_str(), DefValue.c_str(), buffer, INI_BUFFERSIZE, iniFilename.c_str());
|
||||
return buffer;
|
||||
}
|
||||
|
||||
std::string getsection(int idx) const
|
||||
{
|
||||
char buffer[INI_BUFFERSIZE];
|
||||
ini_getsection(idx, buffer, INI_BUFFERSIZE, iniFilename.c_str());
|
||||
return buffer;
|
||||
}
|
||||
|
||||
std::string getkey(const std::string& Section, int idx) const
|
||||
{
|
||||
char buffer[INI_BUFFERSIZE];
|
||||
ini_getkey(Section.c_str(), idx, buffer, INI_BUFFERSIZE, iniFilename.c_str());
|
||||
return buffer;
|
||||
}
|
||||
|
||||
bool hassection(const std::string& Section) const
|
||||
{ return ini_hassection(Section.c_str(), iniFilename.c_str()) != 0; }
|
||||
|
||||
bool haskey(const std::string& Section, const std::string& Key) const
|
||||
{ return ini_haskey(Section.c_str(), Key.c_str(), iniFilename.c_str()) != 0; }
|
||||
|
||||
#if defined INI_REAL
|
||||
INI_REAL getf(const std::string& Section, const std::string& Key, INI_REAL DefValue=0) const
|
||||
{ return ini_getf(Section.c_str(), Key.c_str(), DefValue, iniFilename.c_str()); }
|
||||
#endif
|
||||
|
||||
#if !McuMinINI_CONFIG_READ_ONLY
|
||||
bool put(const std::string& Section, const std::string& Key, long Value) const
|
||||
{ return ini_putl(Section.c_str(), Key.c_str(), Value, iniFilename.c_str()) != 0; }
|
||||
|
||||
bool put(const std::string& Section, const std::string& Key, int Value)
|
||||
{ return ini_putl(Section.c_str(), Key.c_str(), (long)Value, iniFilename.c_str()) != 0; }
|
||||
|
||||
bool put(const std::string& Section, const std::string& Key, bool Value)
|
||||
{ return ini_putl(Section.c_str(), Key.c_str(), (long)Value, iniFilename.c_str()) != 0; }
|
||||
|
||||
bool put(const std::string& Section, const std::string& Key, const std::string& Value)
|
||||
{ return ini_puts(Section.c_str(), Key.c_str(), Value.c_str(), iniFilename.c_str()) != 0; }
|
||||
|
||||
bool put(const std::string& Section, const std::string& Key, const char* Value)
|
||||
{ return ini_puts(Section.c_str(), Key.c_str(), Value, iniFilename.c_str()) != 0; }
|
||||
|
||||
#if defined INI_REAL
|
||||
bool put(const std::string& Section, const std::string& Key, INI_REAL Value)
|
||||
{ return ini_putf(Section.c_str(), Key.c_str(), Value, iniFilename.c_str()) != 0; }
|
||||
#endif
|
||||
|
||||
bool del(const std::string& Section, const std::string& Key)
|
||||
{ return ini_puts(Section.c_str(), Key.c_str(), 0, iniFilename.c_str()) != 0; }
|
||||
|
||||
bool del(const std::string& Section)
|
||||
{ return ini_puts(Section.c_str(), 0, 0, iniFilename.c_str()) != 0; }
|
||||
#endif
|
||||
|
||||
#if !defined INI_NOBROWSE
|
||||
bool browse(INI_CALLBACK Callback, void *UserData) const
|
||||
{ return ini_browse(Callback, UserData, iniFilename.c_str()) != 0; }
|
||||
#endif
|
||||
|
||||
private:
|
||||
std::string iniFilename;
|
||||
};
|
||||
|
||||
#endif /* __WXWINDOWS__ */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* MININI_H */
|
||||
|
||||
191
TSM_PicoW_Sensor/McuLib/minIni/minIni_LICENSE.txt
Normal file
191
TSM_PicoW_Sensor/McuLib/minIni/minIni_LICENSE.txt
Normal file
@@ -0,0 +1,191 @@
|
||||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
|
||||
EXCEPTION TO THE APACHE 2.0 LICENSE
|
||||
|
||||
As a special exception to the Apache License 2.0 (and referring to the
|
||||
definitions in Section 1 of this license), you may link, statically or
|
||||
dynamically, the "Work" to other modules to produce an executable file
|
||||
containing portions of the "Work", and distribute that executable file
|
||||
in "Object" form under the terms of your choice, without any of the
|
||||
additional requirements listed in Section 4 of the Apache License 2.0.
|
||||
This exception applies only to redistributions in "Object" form (not
|
||||
"Source" form) and only if no modifications have been made to the "Work".
|
||||
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
|
||||
|
||||
13
TSM_PicoW_Sensor/McuLib/minIni/minIni_NOTICE.txt
Normal file
13
TSM_PicoW_Sensor/McuLib/minIni/minIni_NOTICE.txt
Normal file
@@ -0,0 +1,13 @@
|
||||
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.
|
||||
|
||||
Reference in New Issue
Block a user