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()