Skip to content

Commit 11f49fb

Browse files
committed
SDL: handle DOS mode settings.txt
1 parent 021c75b commit 11f49fb

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

src/platform/sdl/settings.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@ FILE *openConfig(const char *flags, bool debug) {
7676
int nextInteger(FILE *fp, int def) {
7777
int result = 0;
7878
for (int c = fgetc(fp); c != EOF && c != ',' && c != '\n'; c = fgetc(fp)) {
79-
result = (result * 10) + (c - '0');
79+
if (c != '\r') {
80+
result = (result * 10) + (c - '0');
81+
}
8082
}
8183
if (!result) {
8284
result = def;
@@ -90,8 +92,10 @@ int nextInteger(FILE *fp, int def) {
9092
int nextHex(FILE *fp, int def) {
9193
int result = 0;
9294
for (int c = fgetc(fp); c != EOF && c != ',' && c != '\n'; c = fgetc(fp)) {
93-
int val = (c >= 'a') ? (10 + (c - 'a')) : (c - '0');
94-
result = (result * 16) + val;
95+
if (c != '\r') {
96+
int val = (c >= 'a') ? (10 + (c - 'a')) : (c - '0');
97+
result = (result * 16) + val;
98+
}
9599
}
96100
if (!result) {
97101
result = def;
@@ -106,7 +110,7 @@ int nextString(FILE *fp) {
106110
int pos = ftell(fp);
107111
int len = 0;
108112
for (int c = fgetc(fp); c != EOF; c = fgetc(fp)) {
109-
if (c == '\n') {
113+
if (c == '\n' || c == '\r') {
110114
if (len > 0) {
111115
// string terminator
112116
break;

src/ui/textedit.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
#define strcasestr StrStrI
4141
#endif
4242

43-
int g_themeId = 0;
43+
unsigned g_themeId = 0;
4444
int g_lineMarker[MAX_MARKERS] = {
4545
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1
4646
};
@@ -136,6 +136,9 @@ int compareIntegers(const void *p1, const void *p2) {
136136
// EditTheme
137137
//
138138
EditTheme::EditTheme() {
139+
if (g_themeId >= (sizeof(themes) / sizeof(themes[0]))) {
140+
g_themeId = 0;
141+
}
139142
selectTheme(themes[g_themeId]);
140143
}
141144

src/ui/textedit.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#include "common/smbas.h"
2424
#include "common/keymap.h"
2525

26-
extern int g_themeId;
26+
extern unsigned g_themeId;
2727
extern int g_user_theme[];
2828
#define THEME_COLOURS 17
2929

0 commit comments

Comments
 (0)