comp.lang.ada
 help / color / mirror / Atom feed
From: Jeffrey Carter <jrcarter@acm.org>
Subject: Re: exit my main program if file exist
Date: Sun, 22 Sep 2002 19:14:19 GMT
Date: 2002-09-22T19:14:19+00:00	[thread overview]
Message-ID: <3D8E1672.8080103@acm.org> (raw)
In-Reply-To: mailman.1032703682.11663.comp.lang.ada@ada.eu.org

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




      reply	other threads:[~2002-09-22 19:14 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-09-22 14:07 exit my main program if file exist Dominic D'Apice
2002-09-22 19:14 ` Jeffrey Carter [this message]
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox