[Coco] error trapping
Willard Goosey
goosey at virgo.sdc.org
Tue Dec 1 17:18:18 EST 2009
On Tue, Dec 01, 2009 at 01:58:31AM -0800, Wayne Campbell wrote:
> I need to know how to trap an error generated by the makdir command
> when it's being executed with a SHELL statement in a Basic09
> subroutine.
SHELL "makdir foo >> /nil" should work, as long as nil and VRN are in
the kernel. (All REAL operating systems have a null device! :-)
Otherwise, you can do some magic to check to see if the dir exists
first...
Here is my attempt at that magic, based on the C system call access()
But it has not been extensively tested. (In particular I'm not sure
name will get the full size if passed
"/dd/extra/long/path/thats/longer/than/basic09/default/string/length"
) On the other hand, it's not a fatal error if the file can't be
opened.
PROCEDURE access
PARAM name:STRING; perm:BYTE; result:BOOLEAN
(* access checks to see if file <name> can be opened with
(* permissions <perm> and returns the result in <result>
(*requires syscall
(*Willard Goosey
TYPE registers=cc,a,b,dp:BYTE; x,y,u:INTEGER
DIM path:BYTE
DIM regs:registers
DIM callcode:BYTE
DIM newname:STRING[100]
(*make sure filename ends in <cr>
newname:=name+CHR$($0D)
(*clear random garbage from regs struct
regs.cc:=0
regs.b:=0
(* PRINT "before syscall"; regs.cc
(* open #path,name:perm
(* can't actually do that :-(
(* open refuses to let its perms be in a variable.
callcode:=$84
regs.a:=perm
regs.x:=ADDR(newname)
RUN syscall(callcode,regs)
path:=regs.a
IF regs.b=0 THEN
result:=TRUE
(* CLOSE #path
(* have to do this the hard way too
callcode:=$8F
regs.a:=path
RUN syscall(callcode,regs)
ELSE
result:=FALSE
(*PRINT "regs.cc was"; regs.cc
(*PRINT "regs.b was "; regs.b
ENDIF
END
Willard
--
Willard Goosey goosey at sdc.org
Socorro, New Mexico, USA
I search my heart and find Cimmeria, land of Darkness and the Night.
-- R.E. Howard
More information about the Coco
mailing list