The worst Ada code I have ever wrote...

This commit is contained in:
Ognjen Milan Robovic 2024-05-13 06:41:21 -04:00
parent 725296802c
commit 521ce5dd0b
2 changed files with 75 additions and 6 deletions

View File

@ -209,7 +209,7 @@ begin
-- --
exit when signal_mode = signal_space or cursor_mode = 2; 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 (to_string (xxx.text), 0, 0, size => 11, code => true);
ui.write_ada_code (xxx, 0, 0); ui.write_ada_code (xxx, 0, 0);

View File

@ -583,27 +583,96 @@ package body ui is
------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------
procedure write_ada_code (text : in core.string_box_data; x, y : in integer) is procedure write_ada_code (text : in core.string_box_data; x, y : in integer) is
word : unbounded_string := to_unbounded_string ("");
--
buffer : character := ' '; buffer : character := ' ';
width : constant integer := 13; width : constant integer := 13;
height : constant integer := 11; height : constant integer := 11;
length : natural := 1; length : natural := 1;
offset : core.vector := (x, y); offset : core.vector := (x, y);
subset : natural := 0;
begin begin
loop loop
buffer := ada.strings.unbounded.element (text.text, length); buffer := ada.strings.unbounded.element (text.text, length);
offset.x := offset.x + width;
-- --
exit when buffer = character'val (0); exit when buffer = character'val (0);
--~exit when buffer = ';';
-- --
case buffer is case buffer is
when character'val (9) => offset.x := offset.x + 2 * width; when character'val (9) => offset.x := offset.x + 2 * width;
when character'val (10) => offset.y := offset.y + 1 * height; offset.x := x; 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 ':' | ';' | '+' | '*' | '/' | '.' | ',' | '(' | ')' | ''' | '=' | '<' | '>' =>
when others => ui.write (buffer & "", offset.x, offset.y, (255, 255, 255, 255), height, code => true); 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; end case;
-- --
offset.x := offset.x + width; core.increment (length);
length := length + 1;
end loop; end loop;
end write_ada_code; end write_ada_code;