~strahinja/adash

d013bfd20abe2b6d1e2dc29a9352cc1e6330b67d — Страхиња Радић 2 months ago 3eca602
More error handling; new command: pwd

Signed-off-by: Страхиња Радић <contact@strahinja.org>
3 files changed, 28 insertions(+), 4 deletions(-)

M adash_cmd.adb
M adash_cmd.ads
M adash_parse.adb
M adash_cmd.adb => adash_cmd.adb +23 -4
@@ 1,9 1,13 @@
-- See the file LICENSE for copyright and license details. --
with Ada.Characters.Latin_1, Ada.Exceptions, Ada.Text_IO,
with Ada.Characters.Latin_1, Ada.Exceptions, Ada.IO_Exceptions, Ada.Text_IO,
	GNAT.Directory_Operations, Adash_Const;
use Ada.Characters.Latin_1, Ada.Exceptions, Ada.Text_IO,
	GNAT.Directory_Operations, Adash_Const;
package body Adash_Cmd is
	package AEX renames Ada.Exceptions;
	package AIE renames Ada.IO_Exceptions;
	package ATI renames Ada.Text_IO;

	procedure Cat_File(filename: String) is
		input: File_Type;
		line: String(1..File_Buf_Max);


@@ 19,15 23,19 @@ package body Adash_Cmd is
	exception
		when E: Name_Error =>
			Put_Line(Exception_Message(E));
			Close(input);
		when E: AIE.Device_Error =>
			Put_Line("cat:" & filename & ": Device error (file "
				& "is a directory?)");
			Close(input);
	end Cat_File;

	procedure Change_Directory(dir: String) is
	begin
		Put_Line("Change_Directory(" & dir & ")");
		Change_Dir(dir);
	exception
		when E: Directory_Error =>
			Put_Line(Exception_Message(E));
			Put_Line("cd: Directory error (not a directory?)");
	end Change_Directory;

	procedure Less_File(filename: String) is


@@ 57,6 65,11 @@ package body Adash_Cmd is
	exception
		when E: Name_Error =>
			Put_Line(Exception_Message(E));
			Close(input);
		when E: AIE.Device_Error =>
			Put_Line("less:" & filename & ": Device error (file "
				& "is a directory?)");
			Close(input);
	end Less_File;

	procedure List_Files(pattern: String := "") is


@@ 81,9 94,15 @@ package body Adash_Cmd is
		Close(dir);
	end List_Files;

	procedure Print_Working_Directory is
	begin
		Put_Line(Get_Current_Dir);
	end Print_Working_Directory;

	procedure Show_Commands is
	begin
		Put_Line("Commands: cat cd copying exit help less ls version");
		Put_Line("Commands: cat cd copying exit help less ls pwd "
			& "version");
	end Show_Commands;

	procedure Show_Copying is

M adash_cmd.ads => adash_cmd.ads +1 -0
@@ 4,6 4,7 @@ package Adash_Cmd is
	procedure Change_Directory(dir: String);
	procedure Less_File(filename: String);
	procedure List_Files(pattern: String := "");
	procedure Print_Working_Directory;
	procedure Show_Commands;
	procedure Show_Copying;
	procedure Show_Version;

M adash_parse.adb => adash_parse.adb +4 -0
@@ 12,6 12,7 @@ package body Adash_Parse is
		Command_Copying,
		Command_Exit,
		Command_Help,
		Command_Pwd,
		Command_Less,
		Command_Ls,
		Command_Version);


@@ 23,6 24,7 @@ package body Adash_Parse is
		To_Unbounded_String("copying"),
		To_Unbounded_String("exit"),
		To_Unbounded_String("help"),
		To_Unbounded_String("pwd"),
		To_Unbounded_String("less"),
		To_Unbounded_String("ls"),
		To_Unbounded_String("version")


@@ 123,6 125,8 @@ package body Adash_Parse is
					Put_Line("Usage: less [file]");
				when Command_Ls =>
					List_Files;
				when Command_Pwd =>
					Print_Working_Directory;
				when Command_Version =>
					Show_Version;
				when others => Null;