From 521ce5dd0bfe45d8dd52a74f753c2eae9900d651 Mon Sep 17 00:00:00 2001 From: xolatile Date: Mon, 13 May 2024 06:41:21 -0400 Subject: [PATCH] The worst Ada code I have ever wrote... --- source/main.adb | 2 +- source/ui.adb | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 75 insertions(+), 6 deletions(-) diff --git a/source/main.adb b/source/main.adb index cfb78a6..f4de683 100644 --- a/source/main.adb +++ b/source/main.adb @@ -209,7 +209,7 @@ begin -- exit when signal_mode = signal_space or cursor_mode = 2; -- - main_menu; + --~main_menu; -- --~ui.write (to_string (xxx.text), 0, 0, size => 11, code => true); ui.write_ada_code (xxx, 0, 0); diff --git a/source/ui.adb b/source/ui.adb index a963c5e..2f3e01a 100644 --- a/source/ui.adb +++ b/source/ui.adb @@ -583,27 +583,96 @@ package body ui is ------------------------------------------------------------------------------------------ procedure write_ada_code (text : in core.string_box_data; x, y : in integer) is + word : unbounded_string := to_unbounded_string (""); + -- buffer : character := ' '; width : constant integer := 13; height : constant integer := 11; length : natural := 1; offset : core.vector := (x, y); + subset : natural := 0; begin loop buffer := ada.strings.unbounded.element (text.text, length); + offset.x := offset.x + width; -- exit when buffer = character'val (0); - --~exit when buffer = ';'; -- case buffer is when character'val (9) => offset.x := offset.x + 2 * width; when character'val (10) => offset.y := offset.y + 1 * height; offset.x := x; - when ':' => ui.write (buffer & "", offset.x, offset.y, ( 0, 255, 255, 255), height, code => true); - when others => ui.write (buffer & "", offset.x, offset.y, (255, 255, 255, 255), height, code => true); + when ':' | ';' | '+' | '*' | '/' | '.' | ',' | '(' | ')' | ''' | '=' | '<' | '>' => + ui.write (buffer & "", offset.x, offset.y, ( 0, 255, 255, 255), height, code => true); + when '"' => + ui.write (buffer & "", offset.x, offset.y, (255, 127, 255, 255), height, code => true); + offset.x := offset.x + width; + loop + core.increment (length); + buffer := ada.strings.unbounded.element (text.text, length); + ui.write (buffer & "", offset.x, offset.y, (255, 127, 255, 255), height, code => true); + offset.x := offset.x + width; + exit when buffer = '"'; + end loop; + when '-' => + if ada.strings.unbounded.element (text.text, length + 1) = '-' then + ui.write (buffer & "", offset.x, offset.y, (127, 127, 127, 255), height, code => true); + offset.x := offset.x + width; + loop + core.increment (length); + buffer := ada.strings.unbounded.element (text.text, length); + ui.write (buffer & "", offset.x, offset.y, (127, 127, 127, 255), height, code => true); + offset.x := offset.x + width; + exit when buffer = character'val (10); + end loop; + core.decrement (length); + else + ui.write (buffer & "", offset.x, offset.y, ( 0, 255, 255, 255), height, code => true); + end if; + when '0' .. '9' => + loop + ui.write (buffer & "", offset.x, offset.y, (0, 0, 255, 255), height, code => true); + core.increment (length); + buffer := ada.strings.unbounded.element (text.text, length); + exit when buffer = ' ' or buffer = ';' or buffer = ')' or buffer = ','; + offset.x := offset.x + width; + end loop; + core.decrement (length); + when 'a' .. 'z' | 'A' .. 'Z' => + word := to_unbounded_string (buffer & ""); + subset := 1; + loop + buffer := ada.strings.unbounded.element (text.text, length + subset); + exit when buffer = ' ' or buffer = '.' or buffer = '(' or buffer = ')' or buffer = ',' or buffer = ';' + or buffer = character'val (9) or buffer = character'val (10); + word := word & to_unbounded_string (buffer & ""); + core.increment (subset); + end loop; + if word = "type" or word = "begin" or word = "end" or word = "when" or word = "others" or word = "procedure" or word = "function" + or word = "package" or word = "body" or word = "if" or word = "then" or word = "else" or word = "elsif" or word = "case" or word = "is" + or word = "and" or word = "or" or word = "xor" or word = "exit" or word = "constant" or word = "access" or word = "range" + or word = "subtype" or word = "array" or word = "in" or word = "out" or word = "return" or word = "for" + or word = "loop" or word = "while" or word = "of" or word = "null" or word = "record" or word = "use" or word = "mod" or word = "new" + --~or word = "" + --~or word = "" + --~or word = "" + --~or word = "" + --~or word = "" + --~or word = "" + --~or word = "" + --~or word = "" + --~or word = "" + or word = "aliased" then + ui.write (to_string (word), offset.x, offset.y, (255, 255, 0, 255), height, code => true); + else + ui.write (to_string (word), offset.x, offset.y, (255, 255, 255, 255), height, code => true); + end if; + offset.x := offset.x + (subset - 1) * width; + length := length + subset - 1; + when others => + ui.write (buffer & "", offset.x, offset.y, (255, 255, 255, 255), height, code => true); end case; -- - offset.x := offset.x + width; - length := length + 1; + core.increment (length); end loop; end write_ada_code;