1 /*
2  *   Copyright (C) 1990 Yale University
3  *
4  *   This work is distributed in the hope that it will be useful; you can
5  *   redistribute it and/or modify it under the terms of the
6  *   GNU General Public License as published by the Free Software Foundation;
7  *   either version 2 of the License,
8  *   or any later version, on the following conditions:
9  *
10  *   (a) YALE MAKES NO, AND EXPRESSLY DISCLAIMS
11  *   ALL, REPRESENTATIONS OR WARRANTIES THAT THE MANUFACTURE, USE, PRACTICE,
12  *   SALE OR
13  *   OTHER DISPOSAL OF THE SOFTWARE DOES NOT OR WILL NOT INFRINGE UPON ANY
14  *   PATENT OR
15  *   OTHER RIGHTS NOT VESTED IN YALE.
16  *
17  *   (b) YALE MAKES NO, AND EXPRESSLY DISCLAIMS ALL, REPRESENTATIONS AND
18  *   WARRANTIES
19  *   WHATSOEVER WITH RESPECT TO THE SOFTWARE, EITHER EXPRESS OR IMPLIED,
20  *   INCLUDING,
21  *   BUT NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A
22  *   PARTICULAR
23  *   PURPOSE.
24  *
25  *   (c) LICENSEE SHALL MAKE NO STATEMENTS, REPRESENTATION OR WARRANTIES
26  *   WHATSOEVER TO
27  *   ANY THIRD PARTIES THAT ARE INCONSISTENT WITH THE DISCLAIMERS BY YALE IN
28  *   ARTICLE
29  *   (a) AND (b) above.
30  *
31  *   (d) IN NO EVENT SHALL YALE, OR ITS TRUSTEES, DIRECTORS, OFFICERS,
32  *   EMPLOYEES AND
33  *   AFFILIATES BE LIABLE FOR DAMAGES OF ANY KIND, INCLUDING ECONOMIC DAMAGE OR
34  *   INJURY TO PROPERTY AND LOST PROFITS, REGARDLESS OF WHETHER YALE SHALL BE
35  *   ADVISED, SHALL HAVE OTHER REASON TO KNOW, OR IN FACT SHALL KNOW OF THE
36  *   POSSIBILITY OF THE FOREGOING.
37  *
38  */
39 
40 /* -----------------------------------------------------------------
41 FILE:	    system.c
42 DESCRIPTION:system routines
43 DATE:	    Apr 26, 1990
44 REVISIONS:  May 12, 1990 - added move file and getenv.
45 ----------------------------------------------------------------- */
46 
47 #include <yalecad/file.h>
48 #include <yalecad/message.h>
49 #include <yalecad/program.h>
50 
Ysystem(program,abortFlag,exec_statement,abort_func)51 INT Ysystem( program, abortFlag, exec_statement, abort_func )
52 char *program ;
53 BOOL abortFlag ;
54 char *exec_statement ;
55 INT  (*abort_func)() ;
56 {
57     INT status ;        /* return status from program */
58 
59     if( status = system( exec_statement ) ){
60 	/* get status from exit routine */
61 	status = (status & 0x0000FF00) >> 8 ;/* return code in 2nd byte */
62 	/* now determine the program */
63 
64 	sprintf( YmsgG, "Program %s returned with exit code:%d\n",program,
65 	    status );
66 	M( ERRMSG, NULL, YmsgG ) ;
67 	if( abort_func ){
68 	    (*abort_func)() ;
69 	}
70 	if( abortFlag ){
71 	    YexitPgm( PGMFAIL ) ; /* exit the program */
72 	}
73 	return( status ) ;
74     }
75     return( 0 ) ;
76 } /* end Ysystem */
77 
YcopyFile(sourcefile,destfile)78 void YcopyFile( sourcefile, destfile )
79 char *sourcefile, *destfile ;
80 {
81     sprintf( YmsgG, "/bin/cp %s %s", sourcefile, destfile ) ;
82     Ysystem( "Ylib/YcopyFile", ABORT, YmsgG, NULL ) ;
83 } /* end Ycopyfile */
84 
YmoveFile(sourcefile,destfile)85 void YmoveFile( sourcefile, destfile )
86 char *sourcefile, *destfile ;
87 {
88     sprintf( YmsgG, "/bin/mv %s %s", sourcefile, destfile ) ;
89     Ysystem( "Ylib/YmoveFile", ABORT, YmsgG, NULL ) ;
90 } /* end Ycopyfile */
91 
Yrm_files(files)92 void Yrm_files( files )
93 char *files ;
94 {
95     sprintf( YmsgG, "/bin/rm -rf %s", files ) ;
96     Ysystem( "Ylib/Yrm_files", NOABORT, YmsgG, NULL ) ;
97 } /* end Ycopyfile */
98 
Ygetenv(env_var)99 char *Ygetenv( env_var )
100 char *env_var ;
101 {
102     char *getenv() ;
103 
104     return( (char *) getenv( env_var ) ) ;
105 
106 } /* end Ygetenv */
107