3djc/add f gets (#3998)

* Introduce f_gets()

* Comment out debug TRACE

* Windows editing protection

* Store strlen result + uncrustify

* Uncrustify was probably too harsh !

* Cosmetics
This commit is contained in:
3djc
2016-11-11 22:23:05 +01:00
committed by Bertrand Songis
parent 7b2d8b1f0a
commit dccfb03b67
2 changed files with 24 additions and 19 deletions
+10 -17
View File
@@ -229,26 +229,19 @@ class ModelsList
bool readNextLine(char * line, int maxlen)
{
char c;
unsigned int read;
int len=0;
while (1) {
FRESULT result = f_read(&file, (uint8_t *)&c, 1, &read);
if (result != FR_OK || read != 1) {
line[len] = '\0';
return false;
}
if (c == '\n') {
if (len > 0) {
// we skip empty lines
line[len] = '\0';
return true;
if (f_gets(line, maxlen, &file) != NULL) {
int curlen = strlen(line) - 1;
if (line[curlen] == '\n') { // remove unwanted chars if file was edited using windows
if (line[curlen - 1] == '\r') {
line[curlen - 1] = 0;
}
else {
line[curlen] = 0;
}
}
else if (c != '\r' && len < maxlen) {
line[len++] = c;
}
return true;
}
return false;
}
ModelsCategory * createCategory()
+14 -2
View File
@@ -155,7 +155,7 @@ void simuInit()
void simuSetKey(uint8_t key, bool state)
{
// if (state) TRACE("simuSetKey(%d, %d)", key, state);
switch (key) {
#if !defined(PCBHORUS)
KEY_CASE(KEY_MENU, KEYS_GPIO_REG_MENU, KEYS_GPIO_PIN_MENU)
@@ -219,7 +219,7 @@ void simuSetTrim(uint8_t trim, bool state)
void simuSetSwitch(uint8_t swtch, int8_t state)
{
// TRACE("simuSetSwitch(%d, %d)", swtch, state);
switch (swtch) {
#if defined(PCBFLAMENCO)
// SWITCH_3_CASE(0, SWITCHES_GPIO_REG_A_L, SWITCHES_GPIO_REG_A_H, SWITCHES_GPIO_PIN_A_L, SWITCHES_GPIO_PIN_A_H)
@@ -694,6 +694,18 @@ FRESULT f_write (FIL* fil, const void* data, UINT size, UINT* written)
return FR_OK;
}
TCHAR * f_gets (TCHAR* buff, int len, FIL* fil)
{
if (fil && fil->obj.fs) {
buff = fgets(buff, len, (FILE*)fil->obj.fs);
if (buff != NULL) {
fil->fptr = *buff;
}
// TRACE("fgets(%p) %u, %s", fil->obj.fs, len, buff);
}
return buff;
}
FRESULT f_lseek (FIL* fil, DWORD offset)
{
if (fil && fil->obj.fs) fseek((FILE*)fil->obj.fs, offset, SEEK_SET);