1 /*
2  *   Copyright (C) 1989-1991 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:	    main.c
42 DESCRIPTION:This file contains main control routine for the syntax
43 	    program.
44 CONTENTS:
45 DATE:	    Apr 24, 1989
46 REVISIONS:  Dec  8, 1989 - now write temp file to be moved later so
47 		that programs that follow won't run until passing
48 		syntax.
49 	    Fri Jan 25 17:57:06 PST 1991 - added debug flag to syntax.
50 ----------------------------------------------------------------- */
51 
52 #define MAIN_VARS
53 
54 #include <stdio.h>
55 #include <signal.h>
56 #include <yalecad/base.h>
57 #include <yalecad/cleanup.h>
58 #include <yalecad/file.h>
59 #include <yalecad/message.h>
60 #include <yalecad/debug.h>
61 #include "globals.h"
62 
63 #define EXPECTEDMEMORY  (1024 * 1024)  /* 1M should be enough */
64 #define VERSION         "v1.1"
65 
66 /* Forward declarations */
67 void syntax(void);
68 
main(int argc,char ** argv)69 int main(int argc, char ** argv)
70 {
71 
72   char *YinitProgram(), *Ystrclone() ;
73   char filename[LRECL] ;
74   char filename2[LRECL] ;
75   char *ptr ;
76   int  arg_count ;
77   void yaleIntro() ;
78   int  debug ;
79   FILE *fp ;
80 
81   /* start up cleanup handler */
82   YINITCLEANUP( argv[0], NULL, MAYBEDUMP ) ;
83 
84   Yinit_memsize( EXPECTEDMEMORY ) ;
85 
86   if( argc < 2 || argc > 3 ){
87     syntax() ;
88   } else {
89     debug      = FALSE ;
90     arg_count = 1 ;
91     if( *argv[1] == '-' ){
92       for( ptr = ++argv[1]; *ptr; ptr++ ){
93         switch( *ptr ){
94           case 'd':
95             debug = TRUE ;
96             break ;
97           default:
98             sprintf( YmsgG,"Unknown option:%c\n", *ptr ) ;
99             M(ERRMSG,"main",YmsgG);
100             syntax() ;
101         }
102       }
103       YdebugMemory( debug ) ;
104       cktNameG = Ystrclone( argv[++arg_count] );
105 
106       /* now tell the user what he picked */
107       M(MSG,NULL,"\n\nSyntax switches:\n" ) ;
108       if( debug ){
109         YsetDebug( TRUE ) ;
110         M(MSG,NULL,"\tdebug on\n" ) ;
111       }
112       M(MSG,NULL,"\n" ) ;
113     } else if( argc == 2 ){
114       /* order is important here */
115       YdebugMemory( FALSE ) ;
116       cktNameG = Ystrclone( argv[1] );
117 
118     } else {
119       syntax() ;
120     }
121   }
122 
123   /* remove old version of stat file */
124   sprintf( filename, "%s.stat", cktNameG ) ;
125   Yrm_files( filename ) ;
126 
127   sprintf( filename, "%s.temp", cktNameG ) ;
128   fpoG = TWOPEN( filename, "w", ABORT ) ;
129 
130   /* we can change this value in the debugger */
131   YinitProgram(SYNTAX, VERSION, yaleIntro) ;
132 
133   sprintf( filename, "%s.cel", cktNameG ) ;
134   fp = TWOPEN( filename, "r", ABORT ) ;
135   readcells( fp ) ;
136 
137   if(!(Ymessage_get_errorcount() ) ){
138     M( MSG, NULL, "No syntax errors were found\n" ) ;
139     output() ;
140   } else {
141     TWCLOSE( fp ) ;
142     TWCLOSE( fpoG ) ;
143     YexitPgm( PGMFAIL ) ;
144   }
145   TWCLOSE( fp ) ;
146   TWCLOSE( fpoG ) ;
147 
148   /* now move .temp file to .stat */
149   sprintf( filename, "%s.temp", cktNameG ) ;
150   sprintf( filename2, "%s.stat", cktNameG ) ;
151   YmoveFile( filename, filename2 ) ;
152 
153   YexitPgm( PGMOK ) ;
154 
155   return 0;
156 } /* end main */
157 
158 
159 /* give user correct syntax */
syntax()160 void syntax()
161 {
162   M(ERRMSG,NULL,"\n" ) ;
163   M(MSG,NULL,"Incorrect syntax.  Correct syntax:\n");
164   sprintf( YmsgG,
165       "\n%s circuitName\n\n", SYNTAX );
166   M(MSG,NULL,YmsgG ) ;
167   YexitPgm(PGMFAIL);
168 } /* end syntax */
169 
yaleIntro()170 void yaleIntro()
171 {
172   int i ;
173 
174   M( MSG, NULL, "\n") ;
175   M( MSG, NULL, YmsgG) ;
176   M( MSG, NULL, "\nTimberWolf System Syntax Checker\n");
177   M( MSG, NULL, "Authors: Carl Sechen, Kai-Win Lee, Bill Swartz,\n");
178   M( MSG, NULL, "         Dahe Chen, and Jimmy Lam\n");
179   M( MSG, NULL, "         Yale University\n");
180   M( MSG, NULL, "\n");
181 
182   fprintf(fpoG,"%s\n",YmsgG ) ;
183 
184 } /* end yaleIntro */
185