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

📄 param.c

📁 开放源码的编译器open watcom 1.6.0版的源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
/****************************************************************************
*
*                            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:  WRC command line parameter parsing.
*
****************************************************************************/

#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <unistd.h>
#include "errors.h"
#include "global.h"
#include "param.h"
#include "rctypes.h"
#include "rcmem.h"
#include "swchar.h"
#include "dbtable.h"
#ifdef __OSI__
 #include "ostype.h"
#endif
#include "leadbyte.h"
#include "swchar.h"

#if defined(__UNIX__)
# define PATH_SPLIT_S       ":"     /* path seperator in string form        */
#else
# define PATH_SPLIT_S       ";"     /* path seperator in string form        */
#endif

/* forward declaration */
static bool scanEnvVar( const char *varname, int *nofilenames );

extern void RcAddCPPArg( char * newarg )
/***************************************/
{
    int     numargs;        /* number of args in list at end of this function */
    char ** arg;
    char ** cppargs;

    cppargs = CmdLineParms.CPPArgs;

    if (CmdLineParms.CPPArgs == NULL) {
        /* 3 is 1 for the command, 1 for newarg, 1 for NULL */
        numargs = 3;
        cppargs = RcMemMalloc( numargs * sizeof(char *) );
        /* cppargs[0] is reserved for the name of the command so set it */
        /* to the null string for now */
        cppargs[0] = "";
    } else {
        arg = CmdLineParms.CPPArgs;
        while( *arg != NULL ) {
            arg++;
        }
        /* + 2 for the NULL arg and the new arg */
        numargs = arg - CmdLineParms.CPPArgs + 2;
        cppargs = RcMemRealloc( cppargs, numargs * sizeof(char *) );
    }

    cppargs[ numargs - 2 ] = newarg;
    cppargs[ numargs - 1 ] = NULL;

    CmdLineParms.CPPArgs = cppargs;
} /* RcAddCPPArg */


/*
 * SetDBRange - set the CharSet array up to recognize double byte character
 *              sequences
 */
void SetDBRange( unsigned from, unsigned to ) {
/***********************************************/
    unsigned    i;

    for( i=from; i <= to; i++ ) {
        CharSet[i] = DB_CHAR;
    }
}

static void SetDBChars( const uint_8 *bytes ) {
/**********************************************/
    unsigned    i;

    for( i=0; i < 256; i++ ) {
        if( bytes[i] == 0 ) {
            CharSet[i] = 0;
        } else {
            CharSet[i] = DB_CHAR;
        }
    }
}

#if(0)
static char *fixNewDirs( char *arg ) {
/************************************/
    char        *ret;
    char        *src;
    char        *dst;

    src = arg;
    ret = RcMemMalloc( strlen( src ) + 1 );
    dst = ret;
    while( *src != '\0' ) {
        if( !isspace( *src ) ) {
            *dst = *src;
            dst++;
        }
        src++;
    }
    *dst = '\0';
    RcMemFree( arg );
    return( ret );
}
#endif

static bool scanString( char *buf, const char *str, unsigned len )
/*****************************************************************/
{
    bool        have_quote;

    have_quote = FALSE;
    while( isspace( *str ) ) str++;
    while( *str != '\0' && len > 0 ) {
        if( *str == '\"' ) {
            have_quote = !have_quote;
        } else {
            *buf = *str;
            buf++;
            len--;
        }
        str++;
    }
    *buf = '\0';
    return( have_quote );
}

extern void AddNewIncludeDirs( const char * arg )
/***********************************************/
{
    int     len;
    int     oldlen;

    len = strlen( arg );
    if (len == 0) {
        return;
    }

    if (NewIncludeDirs == NULL) {
        /* + 1 for the '\0' */
        NewIncludeDirs = RcMemMalloc( len + 1 );
        NewIncludeDirs[ 0 ] = '\0';
        oldlen = 0;
    } else {
        /* + 2 for the '\0' and the ';' */
        oldlen = strlen( NewIncludeDirs );
        NewIncludeDirs = RcMemRealloc( NewIncludeDirs, oldlen + len + 2 );
        strcat( NewIncludeDirs + oldlen , PATH_SPLIT_S );
        oldlen ++; //for the semicolon
    }
    if( scanString( NewIncludeDirs + oldlen, arg, len + 1 ) ) {
        RcError( ERR_UNMATCHED_QUOTE_ON_CMD_LINE );
    }
//    NewIncludeDirs = fixNewDirs( NewIncludeDirs );
} /* AddNewIncludeDirs */

static bool ScanMultiOptArg( const char * arg )
/*********************************************/
{
    bool    contok;

    contok = true;

    for( ; *arg != '\0' && contok; arg++ ) {
        switch( tolower( *arg ) ) {
        case 'e':
            CmdLineParms.GlobalMemEMS = TRUE;
            break;
        case 'k':
            CmdLineParms.SegmentSorting = SEG_SORT_NONE;
            break;
        case 'l':
            CmdLineParms.EMSDirect = TRUE;
            break;
        case 'm':
            CmdLineParms.EMSInstance = TRUE;
            break;
#if 0
        case 'n':
            CmdLineParms.NoProtectCC = TRUE;
            break;
#endif
        case 'p':
            CmdLineParms.PrivateDLL = TRUE;
            break;
        case 'q':
            CmdLineParms.Quiet = TRUE;
            break;
        case 'r':
            CmdLineParms.Pass1Only = TRUE;
            break;
        case 't':
            CmdLineParms.ProtModeOnly = TRUE;
            break;
        case '?':
            CmdLineParms.PrintHelp = TRUE;
            contok = FALSE;
            break;
        default:
            RcError( ERR_UNKNOWN_OPTION, *arg );
            contok = FALSE;
            break;
        }
    }
    return( contok );
} /* ScanMultiOptArg */

static bool ScanOptionsArg( const char * arg )
/********************************************/
{
    bool        contok;
    ExtraRes    *resfile;
    FRStrings   *frStrings;
    char        *temp=NULL;
    char        *p;
    char        *delims = ",";
    int         findlen = 0;
    int         replen = 0;

    contok = true;

    switch( tolower( *arg ) ) {
    case '\0':
        RcError( ERR_NO_OPT_SPECIFIED );
        contok = false;
        break;
    case 'a':
        arg++;
        if( tolower( *arg ) == 'd' ) {
            CmdLineParms.GenAutoDep = TRUE;
        } else if( tolower( *arg ) == 'p' ) {
            arg++;
            if( *arg == '=' ) arg++;
            strncpy( CmdLineParms.PrependString, arg, _MAX_PATH );
            if( scanString( CmdLineParms.PrependString, arg, _MAX_PATH  ) ) {
                RcError( ERR_UNMATCHED_QUOTE_ON_CMD_LINE );
            }
            CmdLineParms.Prepend = TRUE;
            break;
        } else {
            RcError( ERR_UNKNOWN_MULT_OPTION, arg - 1 );
            contok = FALSE;
        }
        break;
    case '3':
        arg++;
        switch( tolower( *arg ) ) {
        case '0':
            CmdLineParms.VersionStamp = VERSION_30_STAMP;
            break;
        case '1':
            CmdLineParms.VersionStamp = VERSION_31_STAMP;
            break;
        default:
            RcError( ERR_UNKNOWN_MULT_OPTION, arg - 1 );
            contok = FALSE;
            break;
        }
        break;
    case 'b':
        arg++;
        if( tolower( *arg ) == 't' ) {
            arg++;
            if( *arg == '=' ) arg++;
            if( stricmp( arg, "windows" ) == 0 || stricmp( arg, "win" ) == 0 ) {
                CmdLineParms.TargetOS = RC_TARGET_OS_WIN16;
            } else if( stricmp( arg, "nt" ) == 0 ) {
                CmdLineParms.TargetOS = RC_TARGET_OS_WIN32;
            } else if( stricmp( arg, "os2" ) == 0 ) {
                CmdLineParms.TargetOS = RC_TARGET_OS_OS2;
            } else {
                RcError( ERR_UNKNOWN_TARGET_OS, arg );
                contok = FALSE;
            }
        } else {
            RcError( ERR_UNKNOWN_MULT_OPTION, arg - 1 );
            contok = FALSE;
        }
        break;
    case 'c':
        arg++;
        if( *arg == '=' ) arg++;
        strcpy( CmdLineParms.CodePageFile, arg );
        if( scanString( CmdLineParms.CodePageFile, arg, _MAX_PATH  ) ) {
            RcError( ERR_UNMATCHED_QUOTE_ON_CMD_LINE );
        }
        break;
    case 'd':
        /* temporary until preprocessing done inline */
        /* -1 to get the '-' or '/' as well */
        /* the cast is so the argument won't be const */
        RcAddCPPArg( (char *) arg - 1 );
        break;
    case 'f':
        arg++;
        switch( tolower( *arg ) ) {
        case 'o':
            arg++;
            if( *arg == '=' ) arg++;
            strncpy( CmdLineParms.OutResFileName, arg, _MAX_PATH );
            if( scanString( CmdLineParms.OutResFileName, arg, _MAX_PATH  ) ) {
                RcError( ERR_UNMATCHED_QUOTE_ON_CMD_LINE );
            }
            break;
        case 'r':
            arg++;

⌨️ 快捷键说明

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