~ubuntu-branches/ubuntu/breezy/ace/breezy

« back to all changes in this revision

Viewing changes to TAO/orbsvcs/IFR_Service/drv_preproc_ifr.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad, Benjamin Montgomery, Adam Conrad
  • Date: 2005-09-18 22:51:38 UTC
  • mfrom: (1.2.1 upstream) (2.1.1 sarge) (0.1.2 woody)
  • Revision ID: james.westby@ubuntu.com-20050918225138-seav22q6fyylb536
Tags: 5.4.7-3ubuntu1
[ Benjamin Montgomery ]
* Added a patch for amd64 and powerpc that disables the compiler
  option -fvisibility-inlines-hidden

[ Adam Conrad ]
* Added DPATCH_OPTION_CPP=1 to debian/patches/00options to make
  Benjamin's above changes work correctly with dpatch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// drv_preproc_ifr.cpp,v 1.15 2003/11/04 05:21:30 dhinton Exp
2
 
 
3
 
/*
4
 
 
5
 
COPYRIGHT
6
 
 
7
 
Copyright 1992, 1993, 1994 Sun Microsystems, Inc.  Printed in the United
8
 
States of America.  All Rights Reserved.
9
 
 
10
 
This product is protected by copyright and distributed under the following
11
 
license restricting its use.
12
 
 
13
 
The Interface Definition Language Compiler Front End (CFE) is made
14
 
available for your use provided that you include this license and copyright
15
 
notice on all media and documentation and the software program in which
16
 
this product is incorporated in whole or part. You may copy and extend
17
 
functionality (but may not remove functionality) of the Interface
18
 
Definition Language CFE without charge, but you are not authorized to
19
 
license or distribute it to anyone else except as part of a product or
20
 
program developed by you or with the express written consent of Sun
21
 
Microsystems, Inc. ("Sun").
22
 
 
23
 
The names of Sun Microsystems, Inc. and any of its subsidiaries or
24
 
affiliates may not be used in advertising or publicity pertaining to
25
 
distribution of Interface Definition Language CFE as permitted herein.
26
 
 
27
 
This license is effective until terminated by Sun for failure to comply
28
 
with this license.  Upon termination, you shall destroy or return all code
29
 
and documentation for the Interface Definition Language CFE.
30
 
 
31
 
INTERFACE DEFINITION LANGUAGE CFE IS PROVIDED AS IS WITH NO WARRANTIES OF
32
 
ANY KIND INCLUDING THE WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS
33
 
FOR A PARTICULAR PURPOSE, NONINFRINGEMENT, OR ARISING FROM A COURSE OF
34
 
DEALING, USAGE OR TRADE PRACTICE.
35
 
 
36
 
INTERFACE DEFINITION LANGUAGE CFE IS PROVIDED WITH NO SUPPORT AND WITHOUT
37
 
ANY OBLIGATION ON THE PART OF Sun OR ANY OF ITS SUBSIDIARIES OR AFFILIATES
38
 
TO ASSIST IN ITS USE, CORRECTION, MODIFICATION OR ENHANCEMENT.
39
 
 
40
 
SUN OR ANY OF ITS SUBSIDIARIES OR AFFILIATES SHALL HAVE NO LIABILITY WITH
41
 
RESPECT TO THE INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY
42
 
INTERFACE DEFINITION LANGUAGE CFE OR ANY PART THEREOF.
43
 
 
44
 
IN NO EVENT WILL SUN OR ANY OF ITS SUBSIDIARIES OR AFFILIATES BE LIABLE FOR
45
 
ANY LOST REVENUE OR PROFITS OR OTHER SPECIAL, INDIRECT AND CONSEQUENTIAL
46
 
DAMAGES, EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
47
 
 
48
 
Use, duplication, or disclosure by the government is subject to
49
 
restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
50
 
Technical Data and Computer Software clause at DFARS 252.227-7013 and FAR
51
 
52.227-19.
52
 
 
53
 
Sun, Sun Microsystems and the Sun logo are trademarks or registered
54
 
trademarks of Sun Microsystems, Inc.
55
 
 
56
 
SunSoft, Inc.
57
 
2550 Garcia Avenue
58
 
Mountain View, California  94043
59
 
 
60
 
NOTE:
61
 
 
62
 
SunOS, SunSoft, Sun, Solaris, Sun Microsystems or the Sun logo are
63
 
trademarks or registered trademarks of Sun Microsystems, Inc.
64
 
 
65
 
*/
66
 
 
67
 
// Pass an IDL file through the C preprocessor
68
 
 
69
 
#include "drv_extern_ifr.h"
70
 
#include "be_global.h"
71
 
#include "be_extern.h"
72
 
 
73
 
#include "idl_bool.h"
74
 
#include "idl_defines.h"
75
 
#include "global_extern.h"
76
 
#include "fe_extern.h"
77
 
#include "utl_string.h"
78
 
#include "ace/Process_Manager.h"
79
 
#include "ace/SString.h"
80
 
#include "ace/Env_Value_T.h"
81
 
#include "ace/ARGV.h"
82
 
#include "ace/streams.h"
83
 
#include "ace/OS_NS_stdio.h"
84
 
 
85
 
ACE_RCSID (IFR_Service, 
86
 
           drv_preproc_ifr, 
87
 
           "drv_preproc_ifr.cpp,v 1.15 2003/11/04 05:21:30 dhinton Exp")
88
 
 
89
 
static long argcount = 0;
90
 
static long max_argcount = 128;
91
 
static const char *arglist[128];
92
 
static const char *output_arg_format = 0;
93
 
static long output_arg_index = 0;
94
 
 
95
 
// Push the new CPP location if we got a -Yp argument
96
 
void
97
 
DRV_cpp_new_location (const char *new_loc)
98
 
{
99
 
  arglist[0] = new_loc;
100
 
}
101
 
 
102
 
// Push an argument into the arglist
103
 
void
104
 
DRV_cpp_putarg (const char *str)
105
 
{
106
 
  if (argcount >= max_argcount) 
107
 
    {
108
 
      ACE_ERROR ((LM_ERROR,
109
 
                  "%s%s %d %s\n",
110
 
                  idl_global->prog_name (),
111
 
                  ACE_TEXT (": More than"),
112
 
                  max_argcount,
113
 
                  ACE_TEXT ("arguments to preprocessor")));
114
 
 
115
 
      ACE_OS::exit (99);
116
 
    }
117
 
 
118
 
  arglist[argcount++] = ACE::strnew (str);
119
 
}
120
 
 
121
 
// Expand the output argument with the given filename.
122
 
void
123
 
DRV_cpp_expand_output_arg (const char *filename)
124
 
{
125
 
  if (output_arg_format != 0)
126
 
    {
127
 
      delete [] ACE_const_cast (char *, arglist[output_arg_index]);
128
 
      arglist[output_arg_index] = 0; 
129
 
 
130
 
      char *output_arg = 0;
131
 
      ACE_NEW (output_arg,
132
 
               char [ACE_OS::strlen (output_arg_format)
133
 
                     + ACE_OS::strlen (filename)
134
 
                     + 1]);
135
 
 
136
 
      ACE_OS::sprintf (output_arg,
137
 
                       output_arg_format,
138
 
                       filename);
139
 
 
140
 
      arglist[output_arg_index] = output_arg;
141
 
    }
142
 
}
143
 
 
144
 
// Initialize the cpp argument list.
145
 
void
146
 
DRV_cpp_init (void)
147
 
{
148
 
  // @@ There are two "one time" memory leaks in this function.
149
 
  //    They will not blow off the program but should be fixed at some point.
150
 
  const char *cpp_loc; 
151
 
  const char *cpp_args;
152
 
 
153
 
  // See if TAO_IDL_PREPROCESSOR is defined.
154
 
 
155
 
  ACE_Env_Value<char*> preprocessor ("TAO_IDL_PREPROCESSOR", (char *) 0);
156
 
 
157
 
  // Set cpp_loc to the built in location, unless it has been overriden by
158
 
  // environment variables.
159
 
 
160
 
  if (preprocessor != 0)
161
 
    {
162
 
      cpp_loc = preprocessor;
163
 
    }
164
 
  else
165
 
    {
166
 
      // Check for the deprecated CPP_LOCATION environment variable
167
 
      ACE_Env_Value<char*> cpp_path ("CPP_LOCATION", (char *) 0);
168
 
      if (cpp_path != 0)
169
 
        {
170
 
          ACE_ERROR ((LM_ERROR,
171
 
                      ACE_TEXT ("Warning: The environment variable ")
172
 
                      ACE_TEXT ("CPP_LOCATION has been deprecated.\n")
173
 
                      ACE_TEXT ("         Please use TAO_IDL_PREPROCESSOR ")
174
 
                      ACE_TEXT ("instead.\n")));
175
 
 
176
 
          cpp_loc = cpp_path;
177
 
        }
178
 
      else
179
 
        {
180
 
          cpp_loc = idl_global->cpp_location ();
181
 
        }
182
 
    }
183
 
 
184
 
  DRV_cpp_putarg (cpp_loc);
185
 
  DRV_cpp_putarg ("-I.");
186
 
 
187
 
  // Added some customizable preprocessor options
188
 
 
189
 
  ACE_Env_Value<char*> args1 ("TAO_IDL_PREPROCESSOR_ARGS", (char *) 0);
190
 
 
191
 
  if (args1 != 0)
192
 
    {
193
 
      cpp_args = args1;
194
 
    }
195
 
  else
196
 
    {
197
 
      // Check for the deprecated TAO_IDL_DEFAULT_CPP_FLAGS environment variable
198
 
      ACE_Env_Value<char*> args2 ("TAO_IDL_DEFAULT_CPP_FLAGS", (char *) 0);
199
 
      if (args2 != 0)
200
 
        {
201
 
          ACE_ERROR ((LM_ERROR,
202
 
                      "%s%s%s%s%s",
203
 
                      ACE_TEXT ("Warning: The environment variable "),
204
 
                      ACE_TEXT ("TAO_IDL_DEFAULT_CPP_FLAGS has been "),
205
 
                      ACE_TEXT ("deprecated.\n"),
206
 
                      ACE_TEXT ("         Please use "),
207
 
                      ACE_TEXT ("TAO_IDL_PREPROCESSOR_ARGS instead.\n")));
208
 
 
209
 
          cpp_args = args2;
210
 
        }
211
 
      else
212
 
        {
213
 
          // If no cpp flag was defined by the user, we define some
214
 
          // platform specific flags here.
215
 
          char option[BUFSIZ];
216
 
 
217
 
#if defined (TAO_IDL_PREPROCESSOR_ARGS)
218
 
          cpp_args = TAO_IDL_PREPROCESSOR_ARGS;
219
 
#elif defined (ACE_CC_PREPROCESSOR_ARGS)
220
 
          cpp_args = ACE_CC_PREPROCESSOR_ARGS;
221
 
#else
222
 
          cpp_args = "-E";
223
 
#endif /* TAO_IDL_PREPROCESSOR_ARGS */
224
 
 
225
 
          // So we can find OMG IDL files, such as `orb.idl'.
226
 
          ACE_OS::strcpy (option, "-I");
227
 
 
228
 
#if defined (TAO_IDL_INCLUDE_DIR)
229
 
          // TAO_IDL_INCLUDE_DIR should be in quotes,
230
 
          // e.g. "/usr/local/include/tao"
231
 
 
232
 
          ACE_OS::strcat (option, TAO_IDL_INCLUDE_DIR);
233
 
#else
234
 
          const char* TAO_ROOT = ACE_OS::getenv ("TAO_ROOT");
235
 
          
236
 
          if (TAO_ROOT != 0)
237
 
            {
238
 
              ACE_OS::strcat (option, TAO_ROOT);
239
 
              ACE_OS::strcat (option, "/tao");
240
 
            }
241
 
          else
242
 
            {
243
 
              const char* ACE_ROOT = ACE_OS::getenv ("ACE_ROOT");
244
 
 
245
 
              if (ACE_ROOT != 0)
246
 
                {
247
 
                  ACE_OS::strcat (option, ACE_ROOT);
248
 
                  ACE_OS::strcat (option, "/TAO/tao");
249
 
                }
250
 
              else
251
 
                {
252
 
                  ACE_ERROR ((
253
 
                      LM_ERROR,
254
 
                      "%s%s%s%s",
255
 
                      ACE_TEXT ("Note: The environment variables "),
256
 
                      ACE_TEXT ("TAO_ROOT and ACE_ROOT are not defined.\n"),
257
 
                      ACE_TEXT ("      TAO_IDL may not be able to "),
258
 
                      ACE_TEXT ("locate orb.idl\n")
259
 
                    ));
260
 
 
261
 
                  ACE_OS::strcat (option, ".");
262
 
                }
263
 
            }
264
 
#endif  /* TAO_IDL_INCLUDE_DIR */
265
 
 
266
 
          DRV_cpp_putarg (option);
267
 
      }
268
 
  }
269
 
 
270
 
  // Add any flags in cpp_args to cpp's arglist.
271
 
  ACE_ARGV arglist (cpp_args);
272
 
 
273
 
  for (size_t arg_cnt = 0; arg_cnt < (size_t)arglist.argc (); ++arg_cnt)
274
 
    {
275
 
      // Check for an argument that specifies the preprocessor's output file.
276
 
      if (ACE_OS::strstr (arglist[arg_cnt], "%s") != 0 
277
 
          && output_arg_format == 0)
278
 
        {
279
 
          output_arg_format = ACE::strnew (arglist[arg_cnt]);
280
 
          output_arg_index = argcount;
281
 
          DRV_cpp_putarg (0);
282
 
        }
283
 
      else
284
 
        {
285
 
          DRV_cpp_putarg (arglist[arg_cnt]);
286
 
        }
287
 
    }
288
 
}
289
 
 
290
 
// Lines can be 1024 chars long.
291
 
#define LINEBUF_SIZE    1024
292
 
static  char    drv_line[LINEBUF_SIZE + 1];
293
 
 
294
 
// Get a line from stdin
295
 
static long
296
 
DRV_get_line (FILE *f)
297
 
{
298
 
    char *l = fgets (drv_line, 
299
 
                     LINEBUF_SIZE, 
300
 
                     f);
301
 
    size_t i = 0;
302
 
 
303
 
    if (l == NULL)
304
 
      {
305
 
        return I_FALSE;
306
 
      }
307
 
 
308
 
    if (*l == '\0' && feof (f))
309
 
      {
310
 
        return I_FALSE;
311
 
      }
312
 
 
313
 
    if (*l == '\0')
314
 
      {
315
 
        return I_TRUE;
316
 
      }
317
 
 
318
 
    i = strlen(l) - 1;
319
 
 
320
 
    if (l[i] == '\n')
321
 
      {
322
 
        l[i] = '\0';
323
 
      }
324
 
 
325
 
    return I_TRUE;
326
 
}
327
 
 
328
 
// Copy from stdin to a file
329
 
static void
330
 
DRV_copy_input (FILE *fin, 
331
 
                char *fn, 
332
 
                const char *orig_filename)
333
 
{
334
 
  FILE  *f = ACE_OS::fopen (fn, "w");
335
 
 
336
 
  if (f == NULL) 
337
 
    {
338
 
      ACE_ERROR ((LM_ERROR,
339
 
                  "%s%s%s%s",
340
 
                  idl_global->prog_name (),
341
 
                  ACE_TEXT (": cannot open temp file "),
342
 
                  fn,
343
 
                  ACE_TEXT (" for writing\n")));
344
 
 
345
 
      ACE_OS::exit (99);
346
 
    }
347
 
 
348
 
  if (fin == NULL) 
349
 
    {
350
 
      ACE_ERROR ((LM_ERROR,
351
 
                  "%s%s",
352
 
                  idl_global->prog_name (),
353
 
                  ACE_TEXT (": cannot open input file\n")));
354
 
 
355
 
      ACE_OS::exit (99);
356
 
    }
357
 
 
358
 
#if !defined (ACE_WIN32)
359
 
  fprintf (f, 
360
 
           "#line 1 \"%s\"\n", 
361
 
           orig_filename);
362
 
#else
363
 
  // Convert single \ into double \ otherwise MSVC++ pre-processor
364
 
  // gets awfully confused.
365
 
  char buf[2*MAXPATHLEN];
366
 
  char *d = buf;
367
 
 
368
 
  for (const char *s = orig_filename; *s != 0; ++s)
369
 
    {
370
 
      if (*s == '\\')
371
 
        {
372
 
          *d = '\\';
373
 
          d++;
374
 
        }
375
 
 
376
 
      *d = *s;
377
 
      d++;
378
 
    }
379
 
 
380
 
  *d = 0;
381
 
  ACE_OS::fprintf (f, 
382
 
                   "#line 1 \"%s\"\n", 
383
 
                   buf);
384
 
#endif /* ! ACE_WIN32 */
385
 
 
386
 
  while (DRV_get_line (fin))
387
 
    {
388
 
      // We really need to know whether this line is a "#include
389
 
      // ...". If so, we would like to separate the "file name" and
390
 
      // keep that in the idl_global. We need them to produce
391
 
      // "#include's in the stubs and skeletons.
392
 
      DRV_check_for_include (drv_line);
393
 
 
394
 
      // Print the line to the temp file.
395
 
      ACE_OS::fprintf (f, 
396
 
                       "%s\n", 
397
 
                       drv_line);
398
 
    }
399
 
 
400
 
  // Close the temp file.
401
 
  ACE_OS::fclose (f);
402
 
}
403
 
 
404
 
// Strip down a name to the last component, 
405
 
// i.e. everything after the last '/' or '\' character
406
 
static char *
407
 
DRV_stripped_name (char *fn)
408
 
{
409
 
    char        *n = fn;
410
 
    size_t      l;
411
 
 
412
 
    if (n == NULL)
413
 
      {
414
 
        return NULL;
415
 
      }
416
 
 
417
 
    l = strlen (n);
418
 
    int slash_found = 0;
419
 
 
420
 
    for (n += l - 1; n >= fn && !slash_found; n--)
421
 
      {
422
 
        slash_found = (*n == '/' || *n == '\\');
423
 
      }
424
 
 
425
 
    n += 1;
426
 
 
427
 
    if (slash_found) 
428
 
      {
429
 
        n += 1;
430
 
      }
431
 
 
432
 
    return n;
433
 
}
434
 
 
435
 
// File names
436
 
static char     tmp_file[128];
437
 
static char     tmp_ifile[128];
438
 
 
439
 
// Pass input through preprocessor
440
 
void
441
 
DRV_pre_proc (const char *myfile)
442
 
{
443
 
  long  readfromstdin = I_FALSE;
444
 
 
445
 
  // Macro to avoid "warning: unused parameter" type warning.
446
 
  ACE_UNUSED_ARG (readfromstdin);
447
 
 
448
 
  const char* tmpdir = idl_global->temp_dir ();
449
 
 
450
 
  ACE_OS::strcpy (tmp_file, tmpdir);
451
 
  ACE_OS::strcpy (tmp_ifile, tmpdir);
452
 
 
453
 
  ACE_OS::strcat (tmp_file, "idlf_XXXXXX");
454
 
  ACE_OS::strcat (tmp_ifile, "idli_XXXXXX");
455
 
 
456
 
  (void) ACE_OS::mktemp (tmp_file); ACE_OS::strcat (tmp_file, ".cc");
457
 
  (void) ACE_OS::mktemp (tmp_ifile); ACE_OS::strcat (tmp_ifile, ".cc");
458
 
 
459
 
  UTL_String *tmp = 0;
460
 
 
461
 
  be_global->filename (ACE_const_cast (char *, myfile));
462
 
 
463
 
  if (strcmp (myfile, "standard input") == 0)
464
 
    {
465
 
      ACE_NEW (tmp,
466
 
               UTL_String (tmp_ifile));
467
 
      idl_global->set_filename (tmp);
468
 
 
469
 
      ACE_NEW (tmp,
470
 
               UTL_String (tmp_ifile));
471
 
      idl_global->set_main_filename (tmp);
472
 
 
473
 
      ACE_NEW (tmp,
474
 
               UTL_String (DRV_stripped_name (tmp_ifile)));
475
 
      idl_global->set_stripped_filename (tmp);
476
 
 
477
 
      ACE_NEW (tmp,
478
 
               UTL_String (tmp_ifile));
479
 
      idl_global->set_real_filename (tmp);
480
 
 
481
 
      DRV_copy_input (stdin, 
482
 
                      tmp_ifile, 
483
 
                      "standard input");
484
 
 
485
 
      idl_global->set_read_from_stdin (I_TRUE);
486
 
    }
487
 
  else
488
 
    {
489
 
      FILE *fd = fopen (myfile, "r");
490
 
      DRV_copy_input (fd, 
491
 
                      tmp_ifile, 
492
 
                      myfile);
493
 
      fclose (fd);
494
 
 
495
 
      idl_global->set_read_from_stdin (I_FALSE);
496
 
 
497
 
      ACE_NEW (tmp,
498
 
               UTL_String (myfile));
499
 
      idl_global->set_filename (tmp);
500
 
 
501
 
      ACE_NEW (tmp,
502
 
               UTL_String (myfile));
503
 
      idl_global->set_main_filename (tmp);
504
 
 
505
 
      ACE_Auto_String_Free safety (ACE_OS::strdup (myfile));
506
 
      ACE_NEW (tmp,
507
 
               UTL_String (DRV_stripped_name (safety.get ())));
508
 
      idl_global->set_stripped_filename (tmp);
509
 
 
510
 
      ACE_NEW (tmp,
511
 
               UTL_String (tmp_ifile));
512
 
      idl_global->set_real_filename (tmp);
513
 
    }
514
 
 
515
 
  // We use ACE instead of the (low level) fork facilities, this also
516
 
  // works on NT.
517
 
  ACE_Process process;
518
 
 
519
 
  // For complex builds, the default command line buffer size of 1024
520
 
  // is sometimes not enough. We use 4096 here.
521
 
  ACE_Process_Options cpp_options (1,       // Inherit environment.
522
 
                                   TAO_IDL_COMMAND_LINE_BUFFER_SIZE);
523
 
 
524
 
  DRV_cpp_expand_output_arg (tmp_file);
525
 
  DRV_cpp_putarg (tmp_ifile);
526
 
  DRV_cpp_putarg (0); // Null terminate the arglist.
527
 
 
528
 
  cpp_options.command_line (arglist);
529
 
  
530
 
  /// Remove any existing output file.
531
 
  (void) ACE_OS::unlink (tmp_file);
532
 
 
533
 
  ACE_HANDLE fd = ACE_INVALID_HANDLE;
534
 
 
535
 
  if (output_arg_format == 0)
536
 
    {
537
 
      // If the following open() fails, then we're either being hit with a
538
 
      // symbolic link attack, or another process opened the file before
539
 
      // us.
540
 
      fd = ACE_OS::open (tmp_file,
541
 
                         O_WRONLY | O_CREAT | O_EXCL,
542
 
                         ACE_DEFAULT_FILE_PERMS);
543
 
 
544
 
      if (fd == ACE_INVALID_HANDLE)
545
 
        {
546
 
          ACE_ERROR ((LM_ERROR,
547
 
                      "%s%s%s%s",
548
 
                      idl_global->prog_name (),
549
 
                      ACE_TEXT (": cannot open temp file "),
550
 
                      tmp_file,
551
 
                      ACE_TEXT (" for writing\n")));
552
 
 
553
 
          return;
554
 
        }
555
 
 
556
 
      cpp_options.set_handles (ACE_INVALID_HANDLE, fd);
557
 
    }
558
 
 
559
 
  if (process.spawn (cpp_options) == ACE_INVALID_PID)
560
 
    {
561
 
      ACE_ERROR ((LM_ERROR,
562
 
                  "%s%s%s%s",
563
 
                  idl_global->prog_name (),
564
 
                  ACE_TEXT (": spawn of "),
565
 
                  arglist[0],
566
 
                  ACE_TEXT (" failed\n")));
567
 
 
568
 
      return;
569
 
    }
570
 
 
571
 
  if (fd != ACE_INVALID_HANDLE)
572
 
    {
573
 
      // Close the output file on the parent process.
574
 
      if (ACE_OS::close (fd) == -1)
575
 
        {
576
 
          ACE_ERROR ((LM_ERROR,
577
 
                      "%s%s%s%s",
578
 
                      idl_global->prog_name (),
579
 
                      ACE_TEXT (": cannot close temp file"),
580
 
                      tmp_file,
581
 
                      ACE_TEXT (" on parent\n")));
582
 
 
583
 
          return;
584
 
        }
585
 
    }
586
 
 
587
 
  // Remove the null termination and the input file from the arglist,
588
 
  // the next file will the previous args.
589
 
  argcount -= 2;
590
 
 
591
 
  ACE_exitcode status = 0;
592
 
  if (process.wait (&status) == ACE_INVALID_PID)
593
 
    {
594
 
      ACE_ERROR ((LM_ERROR,
595
 
                  "%s%s",
596
 
                  idl_global->prog_name (),
597
 
                  ACE_TEXT (": wait for child process failed\n")));
598
 
 
599
 
      return;
600
 
    }
601
 
 
602
 
  if (WIFEXITED ((status)))
603
 
    {
604
 
      // child terminated normally?
605
 
      if (WEXITSTATUS ((status)) != 0)
606
 
        {
607
 
          errno = WEXITSTATUS ((status));
608
 
 
609
 
          ACE_ERROR ((LM_ERROR,
610
 
                      "%s%s%s%s",
611
 
                      idl_global->prog_name (),
612
 
                      ACE_TEXT (": preprocessor "),
613
 
                      arglist[0],
614
 
                      ACE_TEXT (" returned with an error\n")));
615
 
 
616
 
          ACE_OS::exit (1);
617
 
        }
618
 
    }
619
 
  else
620
 
    {
621
 
      // child didn't call exit(); perhaps it received a signal?
622
 
      errno = EINTR;
623
 
 
624
 
      ACE_ERROR ((LM_ERROR,
625
 
                  "%s%s%s%s",
626
 
                  idl_global->prog_name (),
627
 
                  ACE_TEXT (": preprocessor "),
628
 
                  arglist[0],
629
 
                  ACE_TEXT (" appears to have been interrupted\n")));
630
 
 
631
 
      ACE_OS::exit (1);
632
 
    }
633
 
  // TODO: Manage problems in the pre-processor, in the previous
634
 
  // version the current process would exit if the pre-processor
635
 
  // returned with error.
636
 
 
637
 
  FILE *yyin = ACE_OS::fopen (tmp_file, "r");
638
 
 
639
 
  if (yyin == NULL) 
640
 
    {
641
 
      ACE_ERROR ((LM_ERROR,
642
 
                  "%s%s %s\n",
643
 
                  idl_global->prog_name (),
644
 
                  ACE_TEXT (": Could not open cpp output file"),
645
 
                  tmp_file));
646
 
 
647
 
      ACE_OS::exit (99);
648
 
    }
649
 
 
650
 
  FE_set_yyin (ACE_reinterpret_cast (File *, yyin));
651
 
 
652
 
  if (idl_global->compile_flags() & IDL_CF_ONLY_PREPROC) 
653
 
    {
654
 
      FILE *preproc = ACE_OS::fopen (tmp_file, "r");
655
 
      char buffer[ACE_MAXLOGMSGLEN];
656
 
      size_t bytes;
657
 
 
658
 
      if (preproc == NULL)
659
 
        {
660
 
          ACE_ERROR ((LM_ERROR,
661
 
                      "%s: Could not open cpp output file: %s\n",
662
 
                      idl_global->prog_name (),
663
 
                      tmp_file));
664
 
 
665
 
          ACE_OS::exit (99);
666
 
        }
667
 
 
668
 
      // ACE_DEBUG sends to stderr - we want stdout for this dump
669
 
      // of the preprocessor output. So we modify the singleton that
670
 
      // was created in this process. Since IDL_CF_ONLY_PREPROC causes
671
 
      // an (almost) immediate exit below, we don't have to restore
672
 
      // the singleton's default parameters.
673
 
      ACE_Log_Msg *out = ACE_Log_Msg::instance ();
674
 
      out->msg_ostream (&cout);
675
 
      out->clr_flags (ACE_Log_Msg::STDERR);
676
 
      out->set_flags (ACE_Log_Msg::OSTREAM);
677
 
 
678
 
      while ((bytes = ACE_OS::fread (buffer, 
679
 
                                     sizeof (char), 
680
 
                                     ACE_MAXLOGMSGLEN - 1, 
681
 
                                     preproc)) 
682
 
          != 0)
683
 
        {
684
 
          buffer[bytes] = 0;
685
 
 
686
 
          ACE_DEBUG ((LM_DEBUG, 
687
 
                      buffer));
688
 
        }
689
 
 
690
 
      ACE_OS::fclose (preproc);
691
 
  }
692
 
 
693
 
  if (ACE_OS::unlink (tmp_ifile) == -1) 
694
 
    {
695
 
      ACE_ERROR ((LM_ERROR,
696
 
                  "%s%s %s\n",
697
 
                  idl_global->prog_name (),
698
 
                  ACE_TEXT (": Could not remove cpp input file"),
699
 
                  tmp_ifile));
700
 
 
701
 
      ACE_OS::exit (99);
702
 
    }
703
 
 
704
 
#if !defined (ACE_WIN32) || defined (ACE_HAS_WINNT4) && (ACE_HAS_WINNT4 != 0)
705
 
  if (ACE_OS::unlink (tmp_file) == -1) 
706
 
    {
707
 
      ACE_ERROR ((LM_ERROR,
708
 
                  "%s%s %s\n",
709
 
                  idl_global->prog_name (),
710
 
                  ACE_TEXT (": Could not remove cpp output file"),
711
 
                  tmp_file));
712
 
 
713
 
      ACE_OS::exit (99);
714
 
    }
715
 
#endif /* ACE_HAS_WINNT4 && ACE_HAS_WINNT4 != 0 */
716
 
 
717
 
  if (idl_global->compile_flags() & IDL_CF_ONLY_PREPROC)
718
 
    {
719
 
      ACE_OS::exit (0);
720
 
    }
721
 
}
722
 
 
723
 
// We really need to know whether this line is a "#include ...". If
724
 
// so, we would like to separate the "file name" and keep that in the
725
 
// idl_global. We need them to produce "#include's in the stubs and
726
 
// skeletons.
727
 
void
728
 
DRV_check_for_include (const char* buf)
729
 
{
730
 
  const char* r = buf;
731
 
  const char* h;
732
 
 
733
 
  // Skip initial '#'.
734
 
  if (*r != '#')
735
 
    {
736
 
      return;
737
 
    }
738
 
  else
739
 
    {
740
 
      r++;
741
 
    }
742
 
 
743
 
  // Skip the tabs and spaces.
744
 
  while (*r == ' ' || *r == '\t')
745
 
    {
746
 
      r++;
747
 
    }
748
 
 
749
 
  // Probably we are at the word `include`. If not return.
750
 
  if (*r != 'i')
751
 
    {
752
 
      return;
753
 
    }
754
 
 
755
 
  // Check whether this word is `include` or no.
756
 
  const char* include_str = "include";
757
 
 
758
 
  for (size_t ii = 0; 
759
 
       ii < strlen ("include") && *r != '\0' && *r != ' ' && *r != '\t'; 
760
 
       r++, ii++)
761
 
    {
762
 
      // Return if it doesn't match.
763
 
      if (include_str [ii] != *r)
764
 
        {
765
 
          return;
766
 
        }
767
 
    }
768
 
 
769
 
  // Next thing is finding the file that has been `#include'd. Skip
770
 
  // all the blanks and tabs and reach the startng " or < character.
771
 
  for (; (*r != '"') && (*r != '<'); r++)
772
 
    {
773
 
      if (*r == '\n' || *r == '\0')
774
 
        {
775
 
          return;
776
 
        }
777
 
    }
778
 
 
779
 
  // Decide on the end char.
780
 
  char end_char = '"';
781
 
 
782
 
  if (*r == '<')
783
 
    {
784
 
      end_char = '>';
785
 
    }
786
 
 
787
 
  // Skip this " or <.
788
 
  r++;
789
 
 
790
 
  // Store this position.
791
 
  h = r;
792
 
 
793
 
  // Found this in idl.ll. Decides the file to be standard input.
794
 
  if (*h == '\0')
795
 
    {
796
 
      return;
797
 
    }
798
 
 
799
 
  // Find the closing " or < character.
800
 
  for (; *r != end_char; r++)
801
 
    {
802
 
      continue;
803
 
    }
804
 
 
805
 
  // Make a new string for this file name.
806
 
  char* file_name = 0;
807
 
  ACE_NEW (file_name,
808
 
           char [r - h + 1]);
809
 
 
810
 
  // Copy the char's.
811
 
  size_t fi = 0;
812
 
 
813
 
  for (; h != r; fi++, h++)
814
 
    {
815
 
      file_name [fi] = *h;
816
 
    }
817
 
 
818
 
  // Terminate the string.
819
 
  file_name [fi] = '\0';
820
 
 
821
 
  // Put Microsoft-style pathnames into a canonical form.
822
 
  size_t i = 0;
823
 
 
824
 
  for (size_t j = 0; file_name [j] != '\0'; i++, j++)
825
 
    {
826
 
      if (file_name [j] == '\\' && file_name [j + 1] == '\\')
827
 
        {
828
 
          j++;
829
 
        }
830
 
 
831
 
      file_name [i] = file_name [j];
832
 
    }
833
 
 
834
 
  // Terminate this string.
835
 
  file_name [i] = '\0';
836
 
 
837
 
  // Store in the idl_global, unless it's "orb.idl" -
838
 
  // we don't want to generate header includes for that.
839
 
  if (ACE_OS::strcmp (file_name, "orb.idl"))
840
 
    {
841
 
      idl_global->add_to_included_idl_files (file_name);
842
 
    }
843
 
}
844
 
 
845
 
#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION)
846
 
  template class ACE_Env_Value<char*>;
847
 
#elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA)
848
 
# pragma instantiate  ACE_Env_Value<char*>
849
 
#endif