I've been tinkering around with turing for quite a while now, and I decided that for my first major projects I would make a shell. So far its been going great. I've had a few issues with things like manually setting colours, and clearscreen. I just thought I'd post it so I could get some feedback on it, tips tricks, suggestions... please, no bad feedback or unconstructive critisism, I am just learning to code.
Turing: | %Var declarations
var changedir, menuchoice, delpathname, rmdirpath, copysourcefile, copydestfile, renamefilepath, newname : string
var colortype, newcolor : int
procedure pwdcommand %This command prints out the working directory of the program
put Dir.Current
end pwdcommand
procedure colorcommand %currently not working
get newcolor
colortype := newcolor
end colorcommand
procedure clscommand %again, currently not working
cls
end clscommand
procedure delcommand %deletes a file
get delpathname
File.Delete (delpathname )
if Error.Last = eNoError then
put skip, delpathname, " deleted"
else
put skip, "Did not delete ", delpathname
put "Error: ", Error.LastMsg
end if
end delcommand
procedure helpcommand %displays a list of commands and how to use them
color (10)
put "Name Description/instructions (if available)"
color (36)
put "CD Changes the working directory [cd (newname)]"
put "COPY Copies a file [copy (sourcefile) {destfile}]"
put "DEL Delete the file specified [del (targetdile)]"
put "LS Lists all of the files/folders in the working directory"
put "HELP Displays this help page"
put "PWD Prints the working directory"
put "RMDIR Deletes the folder specified [rmdir (targerdir)]"
put "SCAR Renames a file (scar [targetfile] {newname}]"
color (7)
end helpcommand
procedure renamecommand %renames a file
get renamefilepath, newname
File.Rename (renamefilepath, newname )
if Error.Last = eNoError then
put "File renamed"
else
put "Did not rename the file."
put "Error: ", Error.LastMsg
end if
end renamecommand
procedure copycommand %copies a file
get copysourcefile, copydestfile
File.Copy (copysourcefile, copydestfile )
if Error.Last = eNoError then
put "File copied", skip
else
put "Did not copy the file."
put "Error: ", Error.LastMsg, skip
end if
end copycommand
procedure passme
put "passed through"
end passme
procedure lscommand %lists all files and directories
setscreen ("text")
var streamNumber : int
var fileName : string
streamNumber := Dir.Open (".")
assert streamNumber > 0
loop
fileName := Dir.Get (streamNumber )
exit when fileName = ""
put fileName
end loop
Dir.Close (streamNumber )
passme
end lscommand
procedure rmdircommand
get rmdirpath
Dir.Delete (rmdirpath )
if Error.Last = eNoError then
put "Directory delete"
else
put "Did not delete the directory."
put "Error: ", Error.LastMsg
end if
end rmdircommand
procedure cdcommand %a procedure to change the working directory of a program
get changedir
Dir.Change (changedir )
end cdcommand
/* This is an if statment that takes a single command (no args, I don't know how to do
those yet), and then processes the string that was entered. If it is any of the commands
in the shell, it points the program to the correct procedure and then returns to the
start of the menu.
*/
procedure menu
put Dir.Current ,": "..
get menuchoice
if menuchoice = "help" then
helpcommand
menu
elsif menuchoice = "pwd" then
pwdcommand
menu
elsif menuchoice = "cd" then
cdcommand
menu
elsif menuchoice = "cls" then
menu
elsif menuchoice = "color" then
colorcommand
menu
elsif menuchoice = "colors" then
menu
elsif menuchoice = "ls" then
lscommand
menu
elsif menuchoice = "del" then
delcommand
menu
elsif menuchoice = "rmdir" then
rmdircommand
menu
elsif menuchoice = "copy" then
copycommand
menu
elsif menuchoice = "scar" then
renamecommand
menu
else
put "command not understood, returning to menu"
menu
end if
end menu
put "Welcome to Darwin"
colortype := 7
setscreen ("graphics")
menu
|
I have alot to add to this, I just thought I would post it up for some criticism. |