Skip to content

Commit 89cf75e

Browse files
committed
fix: correctly check for empty lines
1 parent 9a61677 commit 89cf75e

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

src/mConfigFromFile.axs

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ DEFINE_DEVICE
5151
(***********************************************************)
5252
DEFINE_CONSTANT
5353

54-
constant integer MAX_FILE_SIZE = 2048
54+
constant integer MAX_LINES = 500
55+
constant integer MAX_LINE_LENGTH = 255
5556

5657
constant char EOF[] = '[END_OF_FILE]'
5758

@@ -85,8 +86,9 @@ DEFINE_MUTUALLY_EXCLUSIVE
8586
(* EXAMPLE: DEFINE_CALL '<NAME>' (<PARAMETERS>) *)
8687

8788
define_function GetConfig(char path[]) {
88-
stack_var char data[MAX_FILE_SIZE]
89-
stack_var char lines[1][255]
89+
stack_var char data[MAX_LINES * MAX_LINE_LENGTH]
90+
stack_var char lines[MAX_LINES][MAX_LINE_LENGTH]
91+
stack_var integer count
9092
stack_var slong result
9193
stack_var long total
9294
stack_var integer x
@@ -105,26 +107,35 @@ define_function GetConfig(char path[]) {
105107

106108
NAVLog("'mConfigFromFile => Total Bytes Read: ', itoa(total)")
107109

108-
NAVSplitString(data, "NAV_LF", lines)
110+
count = NAVSplitString(data, "NAV_LF", lines)
109111

110-
for (x = 1; x <= length_array(lines); x++) {
111-
NAVLog("'mConfigFromFile => Line: ', lines[x]")
112+
if (count <= 0) {
113+
return
114+
}
112115

116+
for (x = 1; x <= count; x++) {
113117
if (NAVContains(lines[x], EOF)) {
114-
NAVLog("'mConfigFromFile => EOF Found'")
115118
break
116119
}
117120

118121
{
122+
stack_var char line[MAX_LINE_LENGTH]
119123
stack_var char value[255]
120124

121-
value = NAVGetStringBetween(lines[x], '////', '////')
125+
line = NAVTrimString(lines[x])
126+
value = NAVGetStringBetween(line, '////', '////')
127+
128+
if (!length_array(value) && !NAVContains(line, '////////')) {
129+
continue
130+
}
131+
132+
NAVLog("'mConfigFromFile => Line ', itoa(x), ': ', line")
122133

123-
if (!length_array(value) || !NAVContains(lines[x], '////////')) {
134+
if (!length_array(value)) {
124135
continue
125136
}
126137

127-
NAVLog("'mConfigFromFile => Line Value: ', value")
138+
NAVLog("'mConfigFromFile => Line ', itoa(x), ' Value: ', value")
128139

129140
send_string vdvObject, "'LINE-', itoa(x), ',', value"
130141
}

0 commit comments

Comments
 (0)