update dev300-m57
[ooovba.git] / dmake / quit.c
blobc3b3d57bf768336db10a601e3330c99b2fa53d8a
1 /* $RCSfile: quit.c,v $
2 -- $Revision: 1.8 $
3 -- last change: $Author: kz $ $Date: 2008-03-05 18:29:56 $
4 --
5 -- SYNOPSIS
6 -- End the dmake session.
7 --
8 -- DESCRIPTION
9 -- Handles dmake termination.
11 -- AUTHOR
12 -- Dennis Vadura, dvadura@dmake.wticorp.com
14 -- WWW
15 -- http://dmake.wticorp.com/
17 -- COPYRIGHT
18 -- Copyright (c) 1996,1997 by WTI Corp. All rights reserved.
19 --
20 -- This program is NOT free software; you can redistribute it and/or
21 -- modify it under the terms of the Software License Agreement Provided
22 -- in the file <distribution-root>/readme/license.txt.
24 -- LOG
25 -- Use cvs log to obtain detailed change logs.
28 #include "extern.h"
30 static void _handle_quit ANSI((char*));
31 static int _quitting = 0; /* Set to 1 once Quit() is called for the
32 * first time. */
35 PUBLIC void
36 Quit( sig )/*
37 ======== Error or quit */
38 int sig;
40 if( sig == SIGINT )
41 fprintf(stderr, "Caught SIGINT. Trying to quit ...\n");
42 else
43 #ifdef SIGQUIT
44 /* MinGW, maybe others also, does not have SIGQUIT. */
45 if( sig == SIGQUIT )
46 fprintf(stderr, "Caught SIGQUIT. Trying to quit ...\n");
47 else
48 #endif
49 if( sig == 0 )
50 /* Don't be verbose during regular program termination. */
52 else
53 fprintf(stderr, "Caught signal %d. Trying to quit ...\n", sig);
55 if( _quitting ) return; /* Guard to only quit once. */
56 _quitting = 1;
58 while( Closefile() != NIL( FILE ) );
60 /* CTRL-c sends SIGINT and CTRL-\ sends SIGQUIT to the parent and to all
61 * children. No need to kill them. */
62 if( sig != SIGINT
63 #ifdef SIGQUIT
64 /* MinGW, maybe others also, does not have SIGQUIT. */
65 && sig != SIGQUIT
66 #endif
68 /* This should be called Kill_all_processes(). */
69 Clean_up_processes();
71 /* Wait until all Processes are done. */
72 while( Wait_for_child(TRUE, -1) != -1 )
75 if( Current_target != NIL(CELL) )
76 Unlink_temp_files(Current_target);
78 if( _quitting == 0 ) _handle_quit( ".ERROR" );
80 Set_dir( Makedir ); /* No Error message if we can't do it */
81 Epilog( ERROR_EXIT_VALUE );
85 PUBLIC const int
86 in_quit( void )/*
87 =================
88 Called to check if we are already quitting.
89 (Only used in unix/runargv.c.) */
91 return _quitting;
94 static void
95 _handle_quit( err_target )/*
96 ============================
97 Called by Quit() to handle the execution of termination code
98 from within make */
99 char *err_target;
101 HASHPTR hp;
102 CELLPTR cp;
104 if( (hp = Get_name(err_target, Defs, FALSE)) != NIL(HASH) ) {
105 cp = hp->CP_OWNR;
106 Glob_attr |= A_IGNORE;
108 cp->ce_flag |= F_TARGET;
109 Make( cp, NIL(CELL) );
111 /* Beware! If the ".ERROR" target doesn't finish the following
112 * wait will never return!!! */
113 while( Wait_for_child(FALSE, -1) != -1 );