Move ini functions to ini.h/c

This commit is contained in:
iabdalkader 2018-07-16 21:59:51 +02:00
parent bdacce048d
commit f301c9f4c9
3 changed files with 16 additions and 15 deletions

View File

@ -4,6 +4,8 @@
*/ */
#include <stddef.h> #include <stddef.h>
#include <stdbool.h>
#include <string.h>
#include "ini.h" #include "ini.h"
/*------------------------------------------------------------------------- /*-------------------------------------------------------------------------
@ -126,6 +128,18 @@ ini_atoi(string)
return result; return result;
} }
bool ini_is_true(const char *value)
{
int i = ini_atoi(value);
if (i) return true;
if (strlen(value) != 4) return false;
if ((value[0] != 'T') && (value[0] != 't')) return false;
if ((value[1] != 'R') && (value[1] != 'r')) return false;
if ((value[2] != 'U') && (value[2] != 'u')) return false;
if ((value[3] != 'E') && (value[3] != 'e')) return false;
return true;
}
/*- /*-
* Copyright (c) 1990 The Regents of the University of California. * Copyright (c) 1990 The Regents of the University of California.
* All rights reserved. * All rights reserved.

View File

@ -16,6 +16,7 @@ https://github.com/benhoyt/inih
#define __INI_H__ #define __INI_H__
int ini_atoi(const char *string); int ini_atoi(const char *string);
bool ini_is_true(const char *value);
/* Make this header file easier to include in C++ code */ /* Make this header file easier to include in C++ code */
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -280,20 +280,6 @@ typedef struct openmv_config {
wifi_dbg_config_t wifi_dbg_config; wifi_dbg_config_t wifi_dbg_config;
} openmv_config_t; } openmv_config_t;
extern char *strncpy(char *dst, const char *src, size_t n);
static bool ini_handler_callback_is_true(const char *value)
{
int i = ini_atoi(value);
if (i) return true;
if (strlen(value) != 4) return false;
if ((value[0] != 'T') && (value[0] != 't')) return false;
if ((value[1] != 'R') && (value[1] != 'r')) return false;
if ((value[2] != 'U') && (value[2] != 'u')) return false;
if ((value[3] != 'E') && (value[3] != 'e')) return false;
return true;
}
int ini_handler_callback(void *user, const char *section, const char *name, const char *value) int ini_handler_callback(void *user, const char *section, const char *name, const char *value)
{ {
openmv_config_t *openmv_config = (openmv_config_t *) user; openmv_config_t *openmv_config = (openmv_config_t *) user;
@ -301,7 +287,7 @@ int ini_handler_callback(void *user, const char *section, const char *name, cons
#define MATCH(s, n) ((strcmp(section, (s)) == 0) && (strcmp(name, (n)) == 0)) #define MATCH(s, n) ((strcmp(section, (s)) == 0) && (strcmp(name, (n)) == 0))
if (MATCH("BootSettings", "REPLUart")) { if (MATCH("BootSettings", "REPLUart")) {
if (ini_handler_callback_is_true(value)) { if (ini_is_true(value)) {
mp_obj_t args[2] = { mp_obj_t args[2] = {
MP_OBJ_NEW_SMALL_INT(3), // UART Port MP_OBJ_NEW_SMALL_INT(3), // UART Port
MP_OBJ_NEW_SMALL_INT(115200) // Baud Rate MP_OBJ_NEW_SMALL_INT(115200) // Baud Rate