CLI encapsulation preparing for libfirmware move

This commit is contained in:
rusefillc 2023-08-08 23:53:59 -04:00
parent 515122ea74
commit 9f4647a99f
7 changed files with 4 additions and 153 deletions

View File

@ -6,7 +6,7 @@
*/
#include "pch.h"
#include "efistringutil.h"
#include "rusefi/efistringutil.h"
#include "backup_ram.h"
#include "error_handling_led.h"

@ -1 +1 @@
Subproject commit 8800977c7803f2dbb4b4c8daa4e1acf3bd1210cf
Subproject commit 28a7376a84f131dc890f20b7eccd636a17a2feed

View File

@ -16,10 +16,10 @@
#include <rusefi/isnan.h>
#include <rusefi/math.h>
#include <rusefi/pt2001.h>
#include <rusefi/efistringutil.h>
#include "global.h"
#include "efifeatures.h"
#include "efistringutil.h"
#include "rusefi_generated.h"
#include "loggingcentral.h"
#include "error_handling.h"

View File

@ -19,7 +19,7 @@
#include <rusefi/isnan.h>
#include <rusefi/math.h>
#include "efiprintf.h"
#include "efistringutil.h"
#include "rusefi/efistringutil.h"
#include "cli_registry.h"
/* for isspace() */

View File

@ -1,127 +0,0 @@
#include <cstring>
#include <cstdint>
#include <math.h>
#include "efiprintf.h"
#include "efistringutil.h"
#include "efiprintf.h"
#include <rusefi/math.h>
uint32_t efiStrlen(const char *param) {
const char *s;
for (s = param; *s; ++s)
;
return (s - param);
}
int indexOf(const char *string, char ch) {
// a standard function for this is strnchr?
// todo: on the other hand MISRA wants us not to use standard headers
int len = efiStrlen(string);
for (int i = 0; i < len; i++) {
if (string[i] == ch) {
return i;
}
}
return -1;
}
// string to integer
int atoi(const char *string) {
int len = strlen(string);
if (len == 0) {
return -ATOI_ERROR_CODE;
}
if (string[0] == '-') {
return -atoi(string + 1);
}
int result = 0;
for (int i = 0; i < len; i++) {
char ch = string[i];
if (ch < '0' || ch > '9') {
if (i > 0) {
break;
} else {
return ATOI_ERROR_CODE;
}
}
int c = ch - '0';
result = result * 10 + c;
}
return result;
}
bool strEqualCaseInsensitive(const char *str1, const char *str2) {
int len1 = strlen(str1);
int len2 = strlen(str2);
if (len1 != len2) {
return false;
}
for (int i = 0; i < len1; i++)
if (TO_LOWER(str1[i]) != TO_LOWER(str2[i]))
return false;
return true;
}
bool strEqual(const char *str1, const char *str2) {
// todo: there must be a standard function?!
int len1 = strlen(str1);
int len2 = strlen(str2);
if (len1 != len2) {
return false;
}
for (int i = 0; i < len1; i++)
if (str1[i] != str2[i])
return false;
return true;
}
/**
* string to float. NaN input is supported
*
* @return NAN in case of invalid string
* todo: explicit value for error code? probably not, NaN is only returned in case of an error
*/
float atoff(const char *param) {
static char todofixthismesswithcopy[100];
uint32_t totallen = strlen(param);
if (totallen > sizeof(todofixthismesswithcopy) - 1)
return (float) NAN;
strcpy(todofixthismesswithcopy, param);
char *string = todofixthismesswithcopy;
if (indexOf(string, 'n') != -1 || indexOf(string, 'N') != -1) {
#if ! EFI_SIMULATOR
efiPrintf("NAN from [%s]", string);
#endif
return (float) NAN;
}
// todo: is there a standard function?
// unit-tested by 'testMisc()'
int dotIndex = indexOf(string, '.');
if (dotIndex == -1) {
// just an integer
int result = atoi(string);
if (absI(result) == ATOI_ERROR_CODE)
return (float) NAN;
return (float) result;
}
// todo: this needs to be fixed
string[dotIndex] = 0;
int integerPart = atoi(string);
if (absI(integerPart) == ATOI_ERROR_CODE)
return (float) NAN;
string += (dotIndex + 1);
int decimalLen = strlen(string);
int decimal = atoi(string);
if (absI(decimal) == ATOI_ERROR_CODE)
return (float) NAN;
float divider = 1.0;
// todo: reuse 'pow10' function which we have anyway
for (int i = 0; i < decimalLen; i++) {
divider = divider * 10.0;
}
return integerPart + decimal / divider;
}

View File

@ -1,21 +0,0 @@
#define ATOI_ERROR_CODE 311223344
#ifdef __cplusplus
extern "C"
{
#endif /* __cplusplus */
#define TO_LOWER(x) (((x)>='A' && (x)<='Z') ? (x) - 'A' + 'a' : (x))
// todo: do we even need? does 'strlen' just work like we use it in cli_registry?
uint32_t efiStrlen(const char *param);
int indexOf(const char *string, char ch);
bool strEqualCaseInsensitive(const char *str1, const char *str2);
bool strEqual(const char *str1, const char *str2);
int atoi(const char *string);
float atoff(const char *string);
#ifdef __cplusplus
}
#endif /* __cplusplus */

View File

@ -6,7 +6,6 @@ UTILSRC = \
UTILSRC_CPP = \
$(UTIL_DIR)/histogram.cpp \
$(UTIL_DIR)/efitime.cpp \
$(UTIL_DIR)/efistringutil.cpp \
$(UTIL_DIR)/containers/listener_array.cpp \
$(UTIL_DIR)/containers/local_version_holder.cpp \
$(UTIL_DIR)/math/biquad.cpp \