Skip to content

Commit 5d6450c

Browse files
author
Spacehuhn
committed
Allow infinite loops
1 parent 270824e commit 5d6450c

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

src/attack/attack.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,11 @@ namespace attack {
8787
if (duckparser::loopBegin()) {
8888
start_pos = msc::getPosition();
8989
loops = duckparser::getLoops();
90-
} else if (duckparser::loopEnd() && (loops > 1)) {
90+
} else if (duckparser::loopEnd() && ((loops > 1) || (loops <= 0))) {
91+
// If loops > 1: decrement each time until it reaches 1 and exit then
92+
// If loops == 0 or loops < 0: treat as infinite loop and do not decrement
93+
if (loops > 1) --loops;
9194
msc::gotoPosition(start_pos);
92-
--loops;
9395
}
9496

9597
// For IMPORT

src/duckparser/duckparser.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,10 @@ namespace duckparser {
2424
bool loop_begin = false;
2525
bool loop_end = false;
2626

27-
int default_delay = 5;
28-
int repeat_num = 0;
29-
int loop_num = 0;
27+
unsigned int default_delay = 5;
28+
unsigned int repeat_num = 0;
29+
30+
int loop_num = 0; // <= 0 for infinite loops
3031

3132
std::string import_path = "";
3233

@@ -296,7 +297,7 @@ namespace duckparser {
296297
}
297298
// LOOP_BEGIN
298299
else if (compare(cmd->str, cmd->len, "LOOP_BEGIN", CASE_SENSETIVE)) {
299-
loop_num = to_uint(line_str, line_str_len);
300+
loop_num = to_int(line_str, line_str_len);
300301
loop_begin = true;
301302
ignore_delay = true;
302303
}

0 commit comments

Comments
 (0)