Working argument parser
This commit is contained in:
parent
3ee47e2a77
commit
322cf64183
71
src/main.adb
71
src/main.adb
|
@ -10,19 +10,19 @@ with Ada.Strings.Unbounded;
|
||||||
-- @return
|
-- @return
|
||||||
-- @description Main Function call
|
-- @description Main Function call
|
||||||
procedure Main is
|
procedure Main is
|
||||||
type InstructionList is array(1..65536) of String(1..64);
|
type InstructionList is array (1 .. 65_536) of String (1 .. 64);
|
||||||
type ArgumentParserState is
|
type ArgumentParserState is
|
||||||
(PSInit, PSFilename, PSLanguage, PSRecycle, PSFinish, PSError);
|
(PSInit, PSFilename, PSLanguage, PSRecycle, PSFinish, PSError);
|
||||||
type FileList is array(1..128) of Unbounded.Unbounded_String;
|
type FileList is array (1 .. 128) of Ada.Strings.Unbounded.Unbounded_String;
|
||||||
ParserState : ArgumentParserState := Init;
|
ParserState : ArgumentParserState := PSInit;
|
||||||
Filename : Unbounded.Unbounded_String :=
|
Filename : Ada.Strings.Unbounded.Unbounded_String :=
|
||||||
Unbounded.To_Unbounded_String ("bin.out");
|
Ada.Strings.Unbounded.To_Unbounded_String ("bin.out");
|
||||||
Language : Unbounded.Unbounded_String :=
|
Language : Ada.Strings.Unbounded.Unbounded_String :=
|
||||||
Unbounded.To_Unbounded_String ("VHDL");
|
Ada.Strings.Unbounded.To_Unbounded_String ("VHDL");
|
||||||
Recycle : Boolean := False;
|
Recycle : Boolean := False;
|
||||||
InputFileList : FileList;
|
InputFileList : FileList;
|
||||||
InputFileListIndex : Integer := 1;
|
InputFileListIndex : Integer := 1;
|
||||||
Argument : String;
|
Argument : Ada.Strings.Unbounded.Unbounded_String;
|
||||||
|
|
||||||
Argumenterror : exception;
|
Argumenterror : exception;
|
||||||
Languageoptionerror : exception;
|
Languageoptionerror : exception;
|
||||||
|
@ -30,51 +30,56 @@ begin
|
||||||
|
|
||||||
-- Check input file limit for arguments and lowest argument
|
-- Check input file limit for arguments and lowest argument
|
||||||
if Ada.Command_Line.Argument_Count > 128 then
|
if Ada.Command_Line.Argument_Count > 128 then
|
||||||
Text_IO.Put_Line ("To many arguments!");
|
Ada.Text_IO.Put_Line ("To many arguments!");
|
||||||
elsif Ada.Command_Line.Argument_Count < 2 then
|
elsif Ada.Command_Line.Argument_Count < 2 then
|
||||||
Text_IO.Put_Line ("Not enough arguments!");
|
Ada.Text_IO.Put_Line ("Not enough arguments!");
|
||||||
end if;
|
end if;
|
||||||
|
|
||||||
for Index in 1 .. Ada.Command_Line.Argument_Count loop
|
for Index in 1 .. Ada.Command_Line.Argument_Count loop
|
||||||
Argument := Command_Line.Argument(Index);
|
Argument :=
|
||||||
|
Ada.Strings.Unbounded.To_Unbounded_String
|
||||||
|
(Ada.Command_Line.Argument (Index));
|
||||||
case ParserState is
|
case ParserState is
|
||||||
when Init =>
|
when PSInit =>
|
||||||
if Argument = "-o" then
|
if Ada.Strings.Unbounded.To_String (Argument) = "-o" then
|
||||||
ParserState := PSFilename;
|
ParserState := PSFilename;
|
||||||
elsif Argument = "-x" then
|
elsif Ada.Strings.Unbounded.To_String (Argument) = "-x" then
|
||||||
ParserState := PSLanguage;
|
ParserState := PSLanguage;
|
||||||
elsif Argument = "-r" then
|
elsif Ada.Strings.Unbounded.To_String (Argument) = "-r" then
|
||||||
ParserState := PSRecycle;
|
ParserState := PSRecycle;
|
||||||
else
|
else
|
||||||
ParserState := PSError;
|
ParserState := PSError;
|
||||||
end if;
|
end if;
|
||||||
when Filename =>
|
when PSFilename =>
|
||||||
ParserState := PSInit;
|
ParserState := PSInit;
|
||||||
Filename := Unbounded.To_Unbounded_String (Argument);
|
Filename := Argument;
|
||||||
when Language =>
|
when PSLanguage =>
|
||||||
ParserState := PSInit;
|
ParserState := PSInit;
|
||||||
Language := PSUnbounded.To_Unbounded_String (Argument);
|
Language := Argument;
|
||||||
when Recycle =>
|
when PSRecycle =>
|
||||||
ParserState := PSInit;
|
ParserState := PSInit;
|
||||||
Recycle := True;
|
Recycle := True;
|
||||||
when PSError =>
|
when PSError =>
|
||||||
ParserState := PSError;
|
ParserState := PSError;
|
||||||
raise Argumenterror;
|
raise Argumenterror;
|
||||||
when PSFinish =>
|
when PSFinish =>
|
||||||
ParserState := PSFinish;
|
ParserState := PSFinish;
|
||||||
InputFileListIndex := InputFileListIndex + 1;
|
InputFileListIndex := InputFileListIndex + 1;
|
||||||
InputFileList(InputFileListIndex) := Argument;
|
InputFileList (InputFileListIndex) := Argument;
|
||||||
when others =>
|
when others =>
|
||||||
ParserState := PSFinish;
|
ParserState := PSFinish;
|
||||||
InputFileListIndex := 1;
|
InputFileListIndex := 1;
|
||||||
InputFileList(InputFileListIndex) := Argument;
|
InputFileList (InputFileListIndex) := Argument;
|
||||||
end case;
|
end case;
|
||||||
end loop;
|
end loop;
|
||||||
|
|
||||||
-- Check the language for correct values
|
-- Check the language for correct values
|
||||||
if not (Language = "VHDL" or Language = "C") then
|
if not
|
||||||
Text_Io.Put_Line
|
(Ada.Strings.Unbounded.To_String (Language) = "VHDL" or
|
||||||
("ERROR: The language " & Unbounded.To_String (Language) &
|
Ada.Strings.Unbounded.To_String (Language) = "C")
|
||||||
|
then
|
||||||
|
Ada.Text_IO.Put_Line
|
||||||
|
("ERROR: The language " & Ada.Strings.Unbounded.To_String (Language) &
|
||||||
" is not available!");
|
" is not available!");
|
||||||
raise Languageoptionerror;
|
raise Languageoptionerror;
|
||||||
end if;
|
end if;
|
||||||
|
|
Loading…
Reference in New Issue