⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 owcc.c

📁 Open Watcom 的 C 编译器源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/****************************************************************************
*
*                            Open Watcom Project
*
*    Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
*  ========================================================================
*
*    This file contains Original Code and/or Modifications of Original
*    Code as defined in and that are subject to the Sybase Open Watcom
*    Public License version 1.0 (the 'License'). You may not use this file
*    except in compliance with the License. BY USING THIS FILE YOU AGREE TO
*    ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
*    provided with the Original Code and Modifications, and is also
*    available at www.sybase.com/developer/opensource.
*
*    The Original Code and all software distributed under the License are
*    distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
*    EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
*    ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
*    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
*    NON-INFRINGEMENT. Please see the License for the specific language
*    governing rights and limitations under the License.
*
*  ========================================================================
*
* Description:  UNIX style compile command
*
****************************************************************************/


#include <sys/types.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <unistd.h>
#include "getopt.h"
#include <process.h>
#include <malloc.h>
#include <conio.h>

#include "clcommon.h"
#include "banner.h"
#undef  _BANEXTRA
#define _BANEXTRA _BANEXSHORT

#if defined(__UNIX__)
#define strfcmp strcmp
#else
#define strfcmp stricmp
#endif

#define DIS         "wdis"
#define CC          "wcc386"          /* Open Watcom C compiler          */
#define CCXX        "wpp386"          /* Open Watcom C++ compiler        */
#define STACKSIZE   "8192"            /* default stack size              */
#define _NAME_      "C/C++32 "

#ifdef __UNIX__
#define PATH_SEP_STR "/"
#else
#define PATH_SEP_STR "/\\"
#endif
#define OUTPUTFILE  "a.out"
#define LINK        "wlink"             /* Open Watcom linker              */
#define TEMPFILE    "@__WCL__.LNK"      /* temporary linker directive file */

char *OptEnvVar = "OWCC";

static  char    *Cmd;               /* command line parameters            */
static  char    *Word;              /* one parameter                      */
static  char    *SystemName;        /* system to link for                 */
static  char    Files[MAX_CMD];     /* list of filenames from Cmd         */
        char    Libs[MAX_CMD];      /* list of libraires from Cmd         */
static  char    CC_Opts[MAX_CMD];   /* list of compiler options from Cmd  */
static  char    CC_Path[_MAX_PATH]; /* path name for wcc.exe              */
static  char    PathBuffer[_MAX_PATH];/* buffer for path name of tool     */
        FILE    *Fp;                /* file pointer for Temp_Link         */
static  char    *Link_Name;         /* name for Temp_Link if /fd specified*/
static  char    *Temp_Link;         /* temporary linker directive file    */
        struct  list *Obj_List;     /* linked list of object filenames    */
static  struct directives *Directive_List; /* linked list of directives   */
        char    Exe_Name[_MAX_PATH];/* name of executable                 */
        char    *Map_Name;          /* name of map file                   */
        char    *Obj_Name;          /* object file name pattern           */
static  char    *O_Name;            /* name of -o option                  */
static  char    *StackSize;         /* size of stack                      */
static  char    DebugFlag;          /* debug info wanted                  */
static  char    Conventions;        /* 'r' for -3r or 's' for -3s         */

        struct flags Flags;

/*
 *  Static function prototypes
 */

int     Parse( int argc, char **argv );
int     CompLink( void );
char    *SkipSpaces( char * );
void    Fputnl( char *, FILE * );
void    *MemAlloc( int );
void    MakeName( char *, char * );
void    Usage( void );
#ifdef __UNIX__
  #define EXE_EXT ""
#else
  #define EXE_EXT ".exe"
#endif


char *EnglishMsgs[] = {
#undef pick
#undef E
#undef J
#define E(msg)  msg
#define J(msg)
#define pick(code,english)      english
#include "wclmsg.h"
};

char *JapaneseMsgs[] = {
#undef pick
#undef E
#undef J
#define E(msg)
#define J(msg)  msg
#define pick(code,japanese)     japanese
#include "wclmsg.h"
};

char    **WclMsgs = EnglishMsgs;

static const char *usage[] = {"",NULL};

void print_banner( void )
{
    static int done;

    if( done ) return;
    puts( banner1w( _NAME_ "Compiler Driver Program",_WCL_VERSION_) );
    puts( banner2( "1988" ) );
    puts( banner3 );
    puts( banner3a );
    done = 1;
}

void addccopt( int option , char *opt )
{
    char op[4];
    op[0] = ' ';
    op[1] = '-';
    op[2] = option;
    op[3] = '\0';
    strcat(CC_Opts, op);
    if ( opt )
        strcat(CC_Opts, opt);
}

int   main( int argc, char **argv )
{
    int rc;

    Temp_Link = TEMPFILE;
    if( ( Fp = fopen( &Temp_Link[ 1 ], "w" ) ) == NULL ) {
        PrintMsg( WclMsgs[ UNABLE_TO_OPEN_TEMPORARY_FILE ] );
        exit( 1 );
    }
    Map_Name = NULL;
    Obj_Name = NULL;
    Directive_List = NULL;

    rc = Parse( argc, argv );
    if( rc == 0 ) {
        if( ! Flags.be_quiet ) {
            print_banner();
        }
        rc = CompLink();
    }
    if( rc == 1 )  fclose( Fp );
    if( Link_Name != NULL ) {
        if( strfcmp( Link_Name, &Temp_Link[ 1 ] ) != 0 ) {
            remove( Link_Name );
            rename( &Temp_Link[ 1 ], Link_Name );
        }
    } else {
        remove( &Temp_Link[ 1 ] );
    }
    return( rc == 0 ? 0 : 1 );
}

static int FileExtension( char *p, char *ext )
{
    char        *dot;

    dot = NULL;
    while( *p != '\0' ) {
        if( *p == '.' )  dot = p;
        ++p;
    }
    if( dot != NULL ) {
        if( strfcmp( dot, ext ) == 0 ) {
            return( 1 );                // indicate file extension matches
        }
    }
    return( 0 );                        // indicate no match
}

static void AddDirective( char *directive )
/*********************************/
{
    struct directives *p;
    struct directives *p2;

    p = MemAlloc( sizeof(struct directives) );
    p->next = NULL;
    p->directive = MemAlloc( strlen( directive ) + 1 );
    strcpy( p->directive, Word );
    if( Directive_List == NULL ) {
        Directive_List = p;
    } else {
        p2 = Directive_List;
        while( p2->next != NULL )  p2 = p2->next;
        p2->next = p;
    }
}

static  int  Parse( int argc, char **argv )
/************************/
{
    FILE        *atfp;
    char        buffer[_MAX_PATH];
    char        *p;
    int         wcc_option;
    int         c;
    int         i;

    Flags.map_wanted   = 0;
    Flags.two_case     = 0;
    Flags.tiny_model   = 0;
    Flags.be_quiet     = 1;
    Flags.no_link      = 0;
    Flags.do_link      = 0;
    Flags.do_cvpack    = 0;
    Flags.link_for_dos = 0;
    Flags.link_for_os2 = 0;
    Flags.windows      = 0;
    Flags.is32bit      = 1;
    Flags.math_8087    = 1;
    DebugFlag          = 1;
    StackSize = NULL;
    Conventions = 'r';

    AltOptChar = '-';
    while ((c = GetOpt( &argc, argv,
                        "0123::456a::b:c::D:d:Ee:f:Gg::h:I:i:jk:L:l:Mm:N:n:"
                        "O::o:P::p::Qr::Sst:U:vW:w:Xx::yz:",
                        usage)) != -1) {

        char *Word = "";
        if (OptArg) {
            Word = malloc(strlen(OptArg) + 6);
            strcpy(Word, OptArg);
        }

        wcc_option = 1;

        switch (c) {

        case 'f':               /* files option */
            switch( Word[0] ) {
            case 'd':           /* name of linker directive file */
                Link_Name = "__WCL__.LNK";
                if( Word[1] == '='  ||  Word[1] == '#' ) {
                    MakeName( Word, ".lnk" );    /* add extension */
                    Link_Name = strdup( Word + 2 );
                }
                wcc_option = 0;
                break;
            case 'e':           /* name of exe file */
                if( Word[1] == '='  ||  Word[1] == '#' ) {
                    strcpy( Exe_Name, Word + 2 );
                }
                wcc_option = 0;
                break;
            case 'm':           /* name of map file */
                Flags.map_wanted = TRUE;
                if( Word[1] == '='  ||  Word[1] == '#' ) {
                    Map_Name = strdup( Word + 2 );
                }
                wcc_option = 0;
                break;
            case 'o':           /* name of object file */
                /* parse off argument, so we get right filename
                   in linker command file */
                p = &Word[1];
                if( Word[1] == '='  ||  Word[1] == '#' ) ++p;
                Obj_Name = strdup( p );         /* 08-mar-90 */
                break;
            case 'p':           /* floating-point option */
                if( Word[1] == 'c' ) {
                    Flags.math_8087 = 0;
                }
                break;
            default:
                break;
            }
            break;
        case 'k':               /* stack size option */
            if( Word[0] != '\0' ) {
                StackSize = strdup( Word );
            }
            wcc_option = 0;
            break;
        case 'x':
            if( Word[0] == '\0' ) {
                Flags.two_case = TRUE;
                wcc_option = 0;
            }
            break;
        case '@':
            if( Word[0] != '\0' ) {
                MakeName( Word, ".lnk" );
                if( ( atfp = fopen( Word, "r" ) ) == NULL ) {
                    PrintMsg( WclMsgs[UNABLE_TO_OPEN_DIRECTIVE_FILE], Word );
                    return( 1 );
                }
                while( fgets( buffer, sizeof(buffer), atfp ) != NULL ) {
                    if( strnicmp( buffer, "file ", 5 ) == 0 ) {

                        /* look for names separated by ','s */

                        p = strchr( buffer, '\n' );
                        if( p )  *p = NULLCHAR;
                        AddName( &buffer[5], Fp );
                        Flags.do_link = TRUE;
                    } else {
                        fputs( buffer, Fp );
                    }
                }
                fclose( atfp );
            }
            wcc_option = 0;
            break;

            /* compiler options that affect the linker */
        case '3':
        case '4':
        case '5':                           /* 22-sep-92 */
            Conventions = tolower( Word[0] );
            break;
        case 'd':
        parse_d:
            if( DebugFlag == 0 ){ /* not set by -h yet */
                if( strcmp( Word, "1" ) == 0 ) {
                    DebugFlag = 1;
                } else if( strcmp( Word, "1+" ) == 0 ) { /* 02-mar-91 */
                    DebugFlag = 2;
                } else if( strcmp( Word, "2" ) == 0 ) {
                    DebugFlag = 2;
                } else if( strcmp( Word, "2i" ) == 0 ) {
                    DebugFlag = 2;
                } else if( strcmp( Word, "2s" ) == 0 ) {
                    DebugFlag = 2;
                } else if( strcmp( Word, "3" ) == 0 ) {
                    DebugFlag = 2;
                } else if( strcmp( Word, "3i" ) == 0 ) {
                    DebugFlag = 2;
                } else if( strcmp( Word, "3s" ) == 0 ) {
                    DebugFlag = 2;
                }
            }
            break;
        case 'h':
        parse_h:
            if( strcmp( Word, "w" ) == 0 ) {
                DebugFlag = 3;
            } else if( strcmp( Word, "c" ) == 0 ) { /* 02-mar-91 */
                Flags.do_cvpack = 1;
                DebugFlag = 4;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -