Skip to content

Commit

Permalink
STRING splitting if too long
Browse files Browse the repository at this point in the history
  • Loading branch information
dekuNukem committed Nov 30, 2023
1 parent 5ce12a1 commit af889b8
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 13 deletions.
73 changes: 62 additions & 11 deletions pc_software/ds3_preprocessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -763,9 +763,27 @@ def expand_mousemove(xtotal, ytotal):

return result_listing

STRING_MAX_SIZE = 240

def split_string(input_string, max_length=STRING_MAX_SIZE):
if len(input_string) <= max_length:
return [input_string]
return [input_string[i:i+max_length] for i in range(0, len(input_string), max_length)]

def split_str_cmd(cmd_type, this_line):
str_content = this_line.split(cmd_type + " ", 1)[-1]
if len(str_content) <= STRING_MAX_SIZE:
return [this_line]
cmd_list = []
for item in split_string(str_content):
cmd_list.append(cmd_STRING + " " + item)
if cmd_type == cmd_STRINGLN:
cmd_list[-1] = cmd_list[-1].replace(cmd_STRING, cmd_STRINGLN, 1)
return cmd_list

def run_all(program_listing):
# ----------- expand MOUSE_MOVE ----------
new_program_listing = []

for index, this_line in enumerate(program_listing):
if ds_syntax_check.is_mouse_move(this_line) is False:
new_program_listing.append(this_line)
Expand All @@ -783,18 +801,59 @@ def run_all(program_listing):

program_listing = new_program_listing

# ----------- remove cmd_INJECT_MOD ----------

for index, this_line in enumerate(program_listing):
first_word = this_line.split(" ")[0]
if first_word == cmd_INJECT_MOD:
program_listing[index] = this_line.replace(cmd_INJECT_MOD, "", 1)

# ----------- Do a pass ---------------

rdict = run_once(program_listing)
if rdict['is_success'] is False:
return rdict

print("\n---------First Pass OK!---------\n")

# ----------- making condensed version ----------
# ----------- expand STRING_BLOCK and STRINGLN_BLOCK, split STRING and STRINGLN ----------

new_program_listing = []
for line_number_starting_from_1, this_line in enumerate(program_listing):
line_number_starting_from_1 += 1

if is_within_strlen_block(line_number_starting_from_1, rdict['strlen_block_table']):
this_line = "STRINGLN " + this_line
elif is_within_str_block(line_number_starting_from_1, rdict['str_block_table']):
this_line = "STRING " + this_line
else:
this_line = this_line.lstrip(' \t')
if len(this_line) == 0:
continue

first_word = this_line.split(" ")[0]
first_word, this_line = replace_delay_statements(this_line)

if first_word in [cmd_STRINGLN_BLOCK, cmd_END_STRINGLN, cmd_STRING_BLOCK, cmd_END_STRING]:
continue

if first_word in [cmd_STRINGLN, cmd_STRING]:
for item in split_str_cmd(first_word, this_line):
new_program_listing.append(item)
else:
new_program_listing.append(this_line)

program_listing = new_program_listing

# ----------- Do another pass ---------------

rdict = run_once(program_listing)
if rdict['is_success'] is False:
return rdict

print("\n---------STR expansion OK!---------\n")

# ----------- make condensed version ----------

def_dict = rdict['define_dict']
second_pass_program_listing = []
Expand All @@ -817,20 +876,12 @@ def run_all(program_listing):

for line_number_starting_from_1, this_line in enumerate(program_listing):
line_number_starting_from_1 += 1
if is_within_strlen_block(line_number_starting_from_1, rdict['strlen_block_table']):
this_line = "STRINGLN " + this_line
elif is_within_str_block(line_number_starting_from_1, rdict['str_block_table']):
this_line = "STRING " + this_line
else:
this_line = this_line.lstrip(' \t')
this_line = this_line.lstrip(' \t')
if len(this_line) == 0:
continue
first_word = this_line.split(" ")[0]
first_word, this_line = replace_delay_statements(this_line)
if is_within_rem_block(line_number_starting_from_1, rdict['rem_block_table']):
continue
if first_word in [cmd_STRINGLN_BLOCK, cmd_END_STRINGLN, cmd_STRING_BLOCK, cmd_END_STRING]:
continue
if needs_rstrip(first_word):
this_line = this_line.rstrip(" \t")
if first_word == cmd_REM or this_line.startswith(cmd_C_COMMENT):
Expand Down
7 changes: 5 additions & 2 deletions pc_software/duckypad_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,15 @@
automatically expands MOUSE_MOVE is value is more than 127
checks if duckypad is busy before trying to connect
1.6.2 2023 11 11
increased max profile to 64
1.6.3 2023 11 30
automatically splits STRING/STRINGLN commands if too long
"""

THIS_VERSION_NUMBER = '1.6.2'
THIS_VERSION_NUMBER = '1.6.3'
MIN_DUCKYPAD_FIRMWARE_VERSION = "1.1.2"
MAX_DUCKYPAD_FIRMWARE_VERSION = "1.10.10"

Expand Down
Binary file modified pc_software/duckypad_config_latest_source.zip
Binary file not shown.
11 changes: 11 additions & 0 deletions pc_software/sample_script.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
DEFINE TEN 10
VAR $spam = TEN*7+3

DEFAULTDELAY 30

STRINGLN_BLOCK

I'd just like to interject for a moment. What you're refering to as Linux, is in fact, GNU/Linux, or as I've recently taken to calling it, GNU plus Linux. Linux is not an operating system unto itself, but rather another free component of a fully functioning GNU system made useful by the GNU corelibs, shell utilities and vital system components comprising a full OS as defined by POSIX. Many computer users run a modified version of the GNU system every day, without realizing it. Through a peculiar turn of events, the version of GNU which is widely used today is often called Linux, and many of its users are not aware that it is basically the GNU system, developed by the GNU Project. There really is a Linux, and these people are using it, but it is just a part of the system they use. Linux is the kernel: the program in the system that allocates the machine's resources to the other programs that you run. The kernel is an essential part of an operating system, but useless by itself; it can only function in the context of a complete operating system. Linux is normally used in combination with the GNU operating system: the whole system is basically GNU with Linux added, or GNU/Linux. All the so-called Linux distributions are really distributions of GNU/Linux!

hello world!

END_STRINGLN

DELAY $spam

0 comments on commit af889b8

Please sign in to comment.