* exit my main program if file exist
@ 2002-09-22 14:07 Dominic D'Apice
2002-09-22 19:14 ` Jeffrey Carter
0 siblings, 1 reply; 2+ messages in thread
From: Dominic D'Apice @ 2002-09-22 14:07 UTC (permalink / raw)
Hi all
How can i do this ? :
------------------------------
IF file.txt exist THEN
EXIT main program ;
END IF;
------------------------------
thank
Dominic
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: exit my main program if file exist
2002-09-22 14:07 exit my main program if file exist Dominic D'Apice
@ 2002-09-22 19:14 ` Jeffrey Carter
0 siblings, 0 replies; 2+ messages in thread
From: Jeffrey Carter @ 2002-09-22 19:14 UTC (permalink / raw)
First you need to be able to know if the file exists; see the responses
to your other post for ideas about that. Once you have something like
function File_Exists (Name : String) return Boolean;
then you can start thinking about exiting the main program. This is not
as simple as it may seem. What do you mean by exit? Do you mean a normal
Ada termination, which waits for tasks to terminate and performs
finalization? Or do you mean an immediate death of the OS process, as
you get on many OSes from control-C or kill? Do you need to exit the
whole program from the environment task or from some other task?
Normal Ada termination from the environment task is fairly easy to
achieve. Declare an exception which is only handled by the main
procedure and raise it:
-- Somewhere globally visible:
Exit_Main_Program : exception;
-- In the main program or something called by it:
if File_Exists (Some_Name) then
raise Exit_Main_Program;
end if;
-- In the exception handler for the main program:
when Exit_Main_Program =>
null;
Normal Ada termination from any task may be accomplished by aborting the
environment task.
Immediate death of the process requires a call to the OS. On many
platforms, you can import the C function "exit" to accomplish this.
--
Jeff Carter
"This trial is a travesty. It's a travesty of a mockery of a
sham of a mockery of a travesty of two mockeries of a sham. ...
Do you realize there's not a single homosexual on that jury?"
Bananas
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2002-09-22 19:14 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-09-22 14:07 exit my main program if file exist Dominic D'Apice
2002-09-22 19:14 ` Jeffrey Carter
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox