I am working on a school project with the Ada programming language. The professor wants us to use a language that we are not familiar with to write. I need to use Ada doubly linked list to write a text editor program. The program will take a single optional command-line argument when called that will specify the default file name. If that file already exists, its contents should be loaded into the text buffer. Upon saving the file, the contents of the buffer will be dumped into a file with the specified name, overwriting any existing file.
for example, if I enter
a -- command for appended
hello
world
.
the file will have
hello
world
appended to the end of the document
if I type
3 a
hello
world
.
then the same line gets appended after line 3 of the document.
Here is the code I wrote so far, but I can't figure out how to use string as my case statement's condition too.
Can someone help me with this project?
with Ada.Containers.Doubly_Linked_Lists;
with Ada.Text_Io; use Ada.Text_Io;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
procedure main is
package String_List is new Ada.Containers.Doubly_Linked_Lists(Unbounded_String);
use String_List;
--Userinput : String(1 .. 10) := (others => ' '); --This string length is 10
Last: Integer; --This is use to count input string length
currentAddress: Integer := 0;
text : List; -- List is from Doubly_Linked_Lists
type Userinput is (a, c, p, e);
--size: Integer; --This is use to count input string length
procedure Print(Position : Cursor) is -- this subprogram print all string from list
begin
Put_Line(To_String(Element(Position)));
--Put_Line("K");
end Print;
begin
loop
Put( Integer'Image (currentAddress) & " >> " );
Get_Line(Userinput);
case Userinput is
when a =>
Put( Integer'Image (currentAddress) & " >> " );
Get_Line(Userinput);
text.Append(To_Unbounded_String(Userinput)); -- if letter is a add it to the doubly link list
when c =>
--text.Insert(Before => text.Find(To_Unbounded_String(Userinput)), New_Item => To_Unbounded_String( ? ));
when p =>
text.Iterate(Print'access);
when e =>
Put_Line("Program Exit");
exit;
when others =>
Put_Line ("No command found ");
end case;
end loop;
end main;