Skip to content

Commit

Permalink
infra: Fix generate_skels.py for .d files
Browse files Browse the repository at this point in the history
- Set the variables `remove`, `replace_pairs`, and `end_string` for `.d`
files so they are defined when calling the `process_file()` function.
- Add check in `process_file()` if any of `pattern`, `replace`, or `remove`
are null and issue an error if so.

Fixes: open-education-hub#109

Signed-off-by: Teodor Dutu <[email protected]>
  • Loading branch information
teodutu committed Oct 21, 2024
1 parent c9d0ca0 commit 7ff15df
Show file tree
Hide file tree
Showing 11 changed files with 81 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@


def process_file(src, dst, pattern, replace, remove, replace_pairs, end_string=None):
if not pattern or not replace or not remove:
print(f"ERROR: The script behaviour is not properly specified for {src}", file=sys.stderr)
sys.exit(1)

fin = open(src, "r")
fout = open(dst, "w")
remove_lines = 0
Expand Down Expand Up @@ -127,6 +131,9 @@ def main():
elif re.match(r".*\.d$", src):
pattern = r"(.*//\s*TODO)([ 0-9]*)(:.*)"
replace = r"(.*//\s*REPLACE)( [0-9]*)"
remove = r"(.*//\s*REMOVE)( [0-9]*)"
replace_pairs = [(r"// ", "")]
end_string = None
else:
continue

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@


def process_file(src, dst, pattern, replace, remove, replace_pairs, end_string=None):
if not pattern or not replace or not remove:
print(f"ERROR: The script behaviour is not properly specified for {src}", file=sys.stderr)
sys.exit(1)

fin = open(src, "r")
fout = open(dst, "w")
remove_lines = 0
Expand Down Expand Up @@ -127,6 +131,9 @@ def main():
elif re.match(r".*\.d$", src):
pattern = r"(.*//\s*TODO)([ 0-9]*)(:.*)"
replace = r"(.*//\s*REPLACE)( [0-9]*)"
remove = r"(.*//\s*REMOVE)( [0-9]*)"
replace_pairs = [(r"// ", "")]
end_string = None
else:
continue

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@


def process_file(src, dst, pattern, replace, remove, replace_pairs, end_string=None):
if not pattern or not replace or not remove:
print(f"ERROR: The script behaviour is not properly specified for {src}", file=sys.stderr)
sys.exit(1)

fin = open(src, "r")
fout = open(dst, "w")
remove_lines = 0
Expand Down Expand Up @@ -127,6 +131,9 @@ def main():
elif re.match(r".*\.d$", src):
pattern = r"(.*//\s*TODO)([ 0-9]*)(:.*)"
replace = r"(.*//\s*REPLACE)( [0-9]*)"
remove = r"(.*//\s*REMOVE)( [0-9]*)"
replace_pairs = [(r"// ", "")]
end_string = None
else:
continue

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import std.stdio;

enum SIZE_INT = 32;

/* TODO 9: Fix the bug causing the Segmentation Fault */
// TODO 9: Fix the bug causing the Segmentation Fault
void print_bit_array(uint[SIZE_INT] the_bits)
{
int i = SIZE_INT-1;
Expand All @@ -15,16 +15,16 @@ void print_bit_array(uint[SIZE_INT] the_bits)
}
}

/* REPLACE 9 */
/* void print_bit_array(uint[SIZE_INT] the_bits) */
/* { */
/* uint i = SIZE_INT-1; */
/* while (i >= 0) */
/* { */
/* printf("%u\n", the_bits[i]); */
/* i--; */
/* } */
/* } */
// REPLACE 9
// void print_bit_array(uint[SIZE_INT] the_bits) *
// {
// uint i = SIZE_INT-1;
// while (i >= 0)
// {
// printf("%u\n", the_bits[i]);
// i--;
// }
// }

void to_bits(uint value, uint[SIZE_INT] in_bits)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@


def process_file(src, dst, pattern, replace, remove, replace_pairs, end_string=None):
if not pattern or not replace or not remove:
print(f"ERROR: The script behaviour is not properly specified for {src}", file=sys.stderr)
sys.exit(1)

fin = open(src, "r")
fout = open(dst, "w")
remove_lines = 0
Expand Down Expand Up @@ -127,6 +131,9 @@ def main():
elif re.match(r".*\.d$", src):
pattern = r"(.*//\s*TODO)([ 0-9]*)(:.*)"
replace = r"(.*//\s*REPLACE)( [0-9]*)"
remove = r"(.*//\s*REMOVE)( [0-9]*)"
replace_pairs = [(r"// ", "")]
end_string = None
else:
continue

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@


def process_file(src, dst, pattern, replace, remove, replace_pairs, end_string=None):
if not pattern or not replace or not remove:
print(f"ERROR: The script behaviour is not properly specified for {src}", file=sys.stderr)
sys.exit(1)

fin = open(src, "r")
fout = open(dst, "w")
remove_lines = 0
Expand Down Expand Up @@ -127,6 +131,9 @@ def main():
elif re.match(r".*\.d$", src):
pattern = r"(.*//\s*TODO)([ 0-9]*)(:.*)"
replace = r"(.*//\s*REPLACE)( [0-9]*)"
remove = r"(.*//\s*REMOVE)( [0-9]*)"
replace_pairs = [(r"// ", "")]
end_string = None
else:
continue

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@


def process_file(src, dst, pattern, replace, remove, replace_pairs, end_string=None):
if not pattern or not replace or not remove:
print(f"ERROR: The script behaviour is not properly specified for {src}", file=sys.stderr)
sys.exit(1)

fin = open(src, "r")
fout = open(dst, "w")
remove_lines = 0
Expand Down Expand Up @@ -127,6 +131,9 @@ def main():
elif re.match(r".*\.d$", src):
pattern = r"(.*//\s*TODO)([ 0-9]*)(:.*)"
replace = r"(.*//\s*REPLACE)( [0-9]*)"
remove = r"(.*//\s*REMOVE)( [0-9]*)"
replace_pairs = [(r"// ", "")]
end_string = None
else:
continue

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@


def process_file(src, dst, pattern, replace, remove, replace_pairs, end_string=None):
if not pattern or not replace or not remove:
print(f"ERROR: The script behaviour is not properly specified for {src}", file=sys.stderr)
sys.exit(1)

fin = open(src, "r")
fout = open(dst, "w")
remove_lines = 0
Expand Down Expand Up @@ -127,6 +131,9 @@ def main():
elif re.match(r".*\.d$", src):
pattern = r"(.*//\s*TODO)([ 0-9]*)(:.*)"
replace = r"(.*//\s*REPLACE)( [0-9]*)"
remove = r"(.*//\s*REMOVE)( [0-9]*)"
replace_pairs = [(r"// ", "")]
end_string = None
else:
continue

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@


def process_file(src, dst, pattern, replace, remove, replace_pairs, end_string=None):
if not pattern or not replace or not remove:
print(f"ERROR: The script behaviour is not properly specified for {src}", file=sys.stderr)
sys.exit(1)

fin = open(src, "r")
fout = open(dst, "w")
remove_lines = 0
Expand Down Expand Up @@ -127,6 +131,9 @@ def main():
elif re.match(r".*\.d$", src):
pattern = r"(.*//\s*TODO)([ 0-9]*)(:.*)"
replace = r"(.*//\s*REPLACE)( [0-9]*)"
remove = r"(.*//\s*REMOVE)( [0-9]*)"
replace_pairs = [(r"// ", "")]
end_string = None
else:
continue

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@


def process_file(src, dst, pattern, replace, remove, replace_pairs, end_string=None):
if not pattern or not replace or not remove:
print(f"ERROR: The script behaviour is not properly specified for {src}", file=sys.stderr)
sys.exit(1)

fin = open(src, "r")
fout = open(dst, "w")
remove_lines = 0
Expand Down Expand Up @@ -127,6 +131,9 @@ def main():
elif re.match(r".*\.d$", src):
pattern = r"(.*//\s*TODO)([ 0-9]*)(:.*)"
replace = r"(.*//\s*REPLACE)( [0-9]*)"
remove = r"(.*//\s*REMOVE)( [0-9]*)"
replace_pairs = [(r"// ", "")]
end_string = None
else:
continue

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@


def process_file(src, dst, pattern, replace, remove, replace_pairs, end_string=None):
if not pattern or not replace or not remove:
print(f"ERROR: The script behaviour is not properly specified for {src}", file=sys.stderr)
sys.exit(1)

fin = open(src, "r")
fout = open(dst, "w")
remove_lines = 0
Expand Down Expand Up @@ -127,6 +131,9 @@ def main():
elif re.match(r".*\.d$", src):
pattern = r"(.*//\s*TODO)([ 0-9]*)(:.*)"
replace = r"(.*//\s*REPLACE)( [0-9]*)"
remove = r"(.*//\s*REMOVE)( [0-9]*)"
replace_pairs = [(r"// ", "")]
end_string = None
else:
continue

Expand Down

0 comments on commit 7ff15df

Please sign in to comment.