summaryrefslogtreecommitdiff
path: root/TAO/TAO_IDL/contrib/mcpp/cc1.cpp
blob: 3b49df70550495adf245d5e0f5246f8f6849af72 (plain)
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
/* $Id$
 * cc1.c:   dummy cc1 and cc1plus to be invoked by MinGW's GCC
 *      MinGW's GCC does not invoke shell-script named cc1.
 */

#include "stdio.h"
#include "string.h"
#include "process.h"

#define ARG_LIM 64

int exec_program( int argc, char ** argv);
// FUZZ: disable check_for_improper_main_declaration
int main( int argc, char ** argv) {
// FUZZ: enable check_for_improper_main_declaration
    int     status;

    if (argc - 1 >= ARG_LIM) {
        fprintf( stderr, "Too many arguments.\n");
        return  1;
    }
    status = exec_program( argc, argv);
                    /* MinGW does not have fork() nor wait().   */
    return  status;
}

int exec_program( int argc, char ** argv) {
    char *  buf[ ARG_LIM];
    char    temp[ FILENAME_MAX];
    char *  tp;
    int     plus = 0;
    int     n = 1;
    int     i;
    int     status;
    size_t  len;

    if (strstr( argv[ 0], "cc1plus"))
        plus = 1;                   /* C++  */
    tp = strstr( argv[ 0], "cc1");
    len = tp - argv[ 0];
    memcpy( temp, argv[ 0], len);
    temp[ len] = '\0';
    tp = temp + len;
    for (i = 1; i < argc; i++)
        if ((strcmp( argv[ i], "-fpreprocessed") == 0)
                || (strncmp( argv[ i], "-traditional", 12) == 0))
            break;                  /* Invoke cc1 or cc1plus    */
    if (i < argc) {
        strcpy( tp, plus ? "cc1plus_gnuc.exe" : "cc1_gnuc.exe");
    } else {                        /* Invoke mcpp              */
        strcpy( tp, "mcpp.exe");
        if (plus)
            buf[ n++] = "-+";       /* Insert the option        */
    }
    buf[ 0] = temp;
    for (i = 1; i < argc; i++, n++)
        buf[ n] = argv[ i];
    buf[ n] = 0;

    status = spawnv( _P_WAIT, buf[ 0], buf);
    return  status;
}