File: culltrans.cpp

package info (click to toggle)
gridengine 8.1.9%2Bdfsg-10
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 56,880 kB
  • sloc: ansic: 432,689; java: 87,068; cpp: 31,958; sh: 29,429; jsp: 7,757; perl: 6,336; xml: 5,828; makefile: 4,701; csh: 3,928; ruby: 2,221; tcl: 1,676; lisp: 669; yacc: 519; python: 503; lex: 361; javascript: 200
file content (317 lines) | stat: -rw-r--r-- 9,733 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
/*___INFO__MARK_BEGIN__*/
/*************************************************************************
 * 
 *  The Contents of this file are made available subject to the terms of
 *  the Sun Industry Standards Source License Version 1.2
 * 
 *  Sun Microsystems Inc., March, 2001
 * 
 * 
 *  Sun Industry Standards Source License Version 1.2
 *  =================================================
 *  The contents of this file are subject to the Sun Industry Standards
 *  Source License Version 1.2 (the "License"); You may not use this file
 *  except in compliance with the License. You may obtain a copy of the
 *  License at http://gridengine.sunsource.net/Gridengine_SISSL_license.html
 * 
 *  Software provided under this License is provided on an "AS IS" basis,
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 *  See the License for the specific provisions governing your rights and
 *  obligations concerning the Software.
 * 
 *   The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 * 
 *   Copyright: 2001 by Sun Microsystems, Inc.
 * 
 *   All Rights Reserved.
 * 
 ************************************************************************/
/*___INFO__MARK_END__*/
// culltrans.cpp
// sgee generator initially developed for qidl, now turned into
// a multi-purpose tool that translates cull definitions into
// a metastructure, which can then be used to create anything you
// want out of it, e.g. idl files, header files, java client stubs...

#include <map>
#include <set>
#include <string>
#include <iostream>
#include <fstream>
#include "culltrans_repository.h"
#include "culltrans.h"

#include "cull.h"
#include "sge_all_listsL.h"
#include "sge_boundaries.h"

#ifdef HAVE_STD
using namespace std;
#endif

// forward declaration
#ifdef HP11
extern "C" {
#endif
int yyparse(void);
#ifdef HP11
}
#endif

// global objects to store data in
map<string, List>               lists;
map<string, List>::iterator     active;
map<int, string>                constants;
int                             last_qidl_only = CCT_LOWERBOUND;
FILE*                           disthdr = NULL;
const char*                     yyin_name;
extern FILE*                    yyin;

// string arrays to convert multitype
const char *multiType2sgeType[] = {
   "",   // lEntT undefined
   "GE_sge_float",
   "GE_sge_double",
   "GE_sge_ulong",
   "GE_sge_long",
   "GE_sge_char",
   "GE_sge_bool"
   "GE_sge_int",
   "GE_sge_string",
   "",   // lListT undefined
   "GE_sge_object",
   "GE_sge_ref",
   "GE_sge_host"
};

const char *multiType2idlType[] = {
   "",   // lEntT undefined
   "sge_float",
   "sge_double",
   "sge_ulong",
   "sge_long",
   "sge_char",
   "boolean",
   "sge_int",
   "sge_string",
   "",   // lListT undefined
   "lObjectT",
   "lRefT",
   "lHostT"
};

const char *multiType2getType[] = {
   "",   // lEntT undefined
   "Float",
   "Double",
   "Ulong",
   "Long",
   "Char",
   "Bool",
   "Int",
   "String",
   "List",
   "Object",
   "Ref",
   "Host"
};

// checkArgs
// parses command line and returns:
// ARG_ERROR: for error
// ARG_EMPTY: when no args given
// ARG_NOXXX: when not to create XXX
// or a combination of these.
enum arguments {
   ARG_EMPTY = 0,
   ARG_ERROR = 1,
   ARG_IDL = 2,
   ARG_HDR = 4,
   ARG_DISTHDR = 8,
   ARG_IMPL = 16,
   ARG_ELEMSGEES = 32
};

static int checkArgs(char**& argv) {
   int ret = ARG_EMPTY;
   argv++;
   while(*argv) {
      if(!strcmp(*argv, "-idl"))
         ret |= ARG_IDL;
      else if(!strcmp(*argv, "-hdr"))
         ret |= ARG_HDR;
      else if(!strcmp(*argv, "-disthdr"))
         ret |= ARG_DISTHDR;
      else if(!strcmp(*argv, "-impl"))
         ret |= ARG_IMPL;
      else if(!strcmp(*argv, "-elemcodes"))
         ret |= ARG_ELEMSGEES;
      else if((*argv)[0] == '-') {
         ret |= ARG_ERROR;
         break;
      }
      else
         break;
      argv++;
   }
   return ret;
}

// checkFilesAndObjects
// parses the argument list for -of and -oo switches
static void checkFilesAndObjects(char**& argv, set<string>& files,
                          set<string>& objects) {
   set<string>* cur=&files;

   for(; *argv; argv++) {
      if(!strcmp(*argv, "-of"))
         cur = &files;
      else if(!strcmp(*argv, "-oo"))
         cur = &objects;
      else
         cur->insert(*argv);
   }
}
         

// usage
// print out usage message
static void usage() {
   cerr << "Usage: culltrans [-idl] [-hdr] [-impl] [-elemcodes] [-disthdr] input-files" << endl;
   cerr << "                 [-of files] [-oo objects]" << endl;
   cerr << endl;
   cerr << "-idl:        Triggers output of IDL files." << endl;
   cerr << "-hdr:        Triggers output of _implementation.h files." << endl;
   cerr << "-impl:       Triggers output of _implementation.cpp files." << endl;
   cerr << "-elemcodes:  Triggers output of elem_codes.idl file." << endl;
   cerr << "-disthdr:    Triggers output of .h.dist files." << endl;
   cerr << "-of:         Produces output only for objects that are defined in the" <<endl;
   cerr << "             following list of files." << endl;
   cerr << "-oo:         Produces output only for the given objects." << endl;
   cerr << "input-files: List of files that contain cull list definitions." << endl;
   cerr << "files:       List of files for whose objects output will be produced." << endl;
   cerr << "objects:     List of object names for which output will be produced." <<endl;
   cerr << endl;
   cerr << "If -of or -oo are not given, culltrans produces output for all files or objects." << endl;
   cerr << "If specified, BOTH -oo and -of requirements must be met for an object." << endl;
   cerr << "That is that no output will be produced for the following command line:" << endl;
   cout << "   culltrans -idl sge_calendarL.h sge_queue.h -of sge_calendar.h -oo Queue" << endl;
   cerr << "The order of the -oo and -of switches is not important unless they occur after" << endl;
   cerr << "the input file list. It is also valid to have multiple -of and -oo switches" << endl;
   cerr << "in one command line and to specify the same file or object more than once." <<endl;
   cerr << "or to specify files that don't exist." << endl;
   cerr << "-of and -oo have no effect on dist hdr output: .h.dist files are always" << endl;
   cerr << "produced if -disthdr is specified." << endl;
}

int main(int argc, char** argv) {
   // check arguments
   int args = checkArgs(argv);
   if(args & ARG_ERROR || argc == 1) {
      usage();
      return 1;
   }
   if(!*argv)
      return 0;

   lInit(nmv);

   // Creating dummy ST_Type list ( == string sequence )
   lists.insert(map<string, List>::value_type("ST_Type", List("ST_Type", "sge_string", NULL, NULL, false)));

   // for all arguments until -of or -oo do
   for(; *argv && strcmp(*argv, "-of") && strcmp(*argv, "-oo"); argv++) {
      char* disthdrname;

      // open the file
      yyin = fopen(*argv, "r");
      disthdr = NULL;
      if(!yyin) {
         cerr << "Could not open file " << *argv << endl;
         cerr << "Aborting..." << endl;
         return 1;
      }
      yyin_name = *argv;

      if(args & ARG_DISTHDR) {
         char* slash = strrchr(*argv, '/');
         disthdrname = new char[(slash?strlen(slash+1):strlen(*argv)) + strlen(".dist") + 1];
         strcpy(disthdrname, slash?slash+1:*argv);
         strcat(disthdrname, ".dist");
         disthdr = fopen(disthdrname, "w");
         if(!disthdr) {
            cerr << "Could not open file " << disthdrname << endl;
            cerr << "Aborting..." << endl;
            delete [] disthdrname;
            fclose(yyin);
            return 1;
         }
         delete [] disthdrname;
      }

      // parse the file
      cout << "Parsing file " << *argv << "..." << flush;

      while(!feof(yyin))
         yyparse();

      cout << "done" << endl;

      // cleanup
      fclose(yyin);
      if(disthdr)
         fclose(disthdr);
   }

   // now find out which objects to write
   set<string> files, objects;
   checkFilesAndObjects(argv, files, objects);

   // write IDL files
   if(args & ARG_IDL) {
      map<string, List>::iterator it;
      for(it=lists.begin(); it != lists.end(); ++it)
         if((files.empty() || files.find(it->second.file) != files.end()) &&
            (objects.empty() || objects.find(it->second.name) != objects.end()))
            if(!writeIDL(it)) {
               cerr << "Error writing IDL file for " << it->second.name << endl;
               cerr << "Aborting..." << endl;
               return 1;
            }
   }

   // write _implementation.h files
   if(args & ARG_HDR) {
      map<string, List>::iterator it;
      for(it=lists.begin(); it != lists.end(); ++it)
         if((files.empty() || files.find(it->second.file) != files.end()) &&
            (objects.empty() || objects.find(it->second.name) != objects.end()))
            if(!writeHdr(it)) {
               cerr << "Aborting..." << endl;
               return 1;
            }
   }

   // write _implementation.cpp files
   if(args & ARG_IMPL) {
      map<string, List>::iterator it;
      for(it=lists.begin(); it != lists.end(); ++it)
         if((files.empty() || files.find(it->second.file) != files.end()) &&
            (objects.empty() || objects.find(it->second.name) != objects.end()))
            if(!writeImplementation(it)) {
               cerr << "Aborting..." << endl;
               return 1;
            }
   }

   // write enum file
   if(args & ARG_ELEMSGEES) 
      if(!writeConsts()) {
         cerr << "Aborting..." << endl;
         return 1;
      }

   return 0;
}