Пример #1
0
void SetFunction( TypeInfo *ret, char *fname ) {
/***********************************************/

    if( inSubPgm ) {
        return;
    }

    assert( fname );
    assert( ret );

    copyTypeInfo( &( SRU.curr.sp.ret_type ), ret );
    SRU.curr.sp.name = MemStrDup( fname );
    SRU.curr.sp.typ = ST_FUNCTION;
    SRU.curr_typ = SRU_SUBPROG;
    SRU.curr.sp.typ_id = isTypeKnown( ret ); /* we must first set sp info */
    if( !SRU.curr.sp.typ_id ) {
        /* issue warning if unknown type is found and set fake bit */
        /* only issue a warning for forward definitions so we don't issue
         * the same warning twice */
        if( SRU.sections->data.sec.primary == ST_FORWARD ) {
            Warning( UNKNOWN_TYPE, ret->name, fname );
        }
        SRU.curr.sp.fake = TRUE;
    }
}
Пример #2
0
void InitSru( void ) {
/********************/

    long        x;

    memset( &SRU, 0, sizeof( sru_file ) );
    inSubPgm = FALSE;
    setHeader = FALSE;
    SRU.type_prots = NewHashTable( PROTO_PRIME );
    SRU.name = MemStrDup( NONAME_FILE );
    SetDefaultAccess( ST_PUBLIC );
    SetBaseName( SRU.name );
    if( Options & OPT_GEN_C_CODE ) {
        SRU.flags |= CONSTRUCTOR_DEFINED;
        SRU.flags |= DESTRUCTOR_DEFINED;
    }
    mkConsDesNames();

    /* loads types into hash table */
    SRU.typ_tab = NewHashTable( HASH_PRIME );
    x = 0;
    while( DataTypes[x].key != NULL ) {
        InsertHashValue( SRU.typ_tab, DataTypes[x].key,
                        strlen( DataTypes[x].key ), &DataTypes[x] );
        x++;
    }
}
Пример #3
0
static void copyTypeInfo( TypeInfo *dst, TypeInfo *src ) {
/*********************************************************/
    if( src->name == NULL ) {
        dst->name = NULL;
    } else {
        dst->name = MemStrDup( src->name );
    }
    dst->isref = src->isref;
}
Пример #4
0
static int ProcMemInit( void )
{
    Map_Name = NULL;
    Obj_Name = MemStrDup( ".o" );
    Link_Name = NULL;
    SystemName = NULL;
    StackSize = NULL;
    Directive_List = NULL;
    Files_List = NULL;
    Obj_List = NULL;
    Libs_List = NULL;
    return( 0 );
}
Пример #5
0
void SetSubroutine( char *sname ) {
/*********************************/

    if( inSubPgm ) {
        return;
    }
    assert( sname );

    SRU.curr.sp.ret_type.name = NULL;
    SRU.curr.sp.ret_type.isref = FALSE;
    SRU.curr.sp.name = MemStrDup( sname );
    SRU.curr.sp.typ = ST_SUBROUTINE;
    SRU.curr.sp.subroutine = TRUE;
    SRU.curr_typ = SRU_SUBPROG;
}
Пример #6
0
void SetHeader( char *name, char *ext ) {
/***************************************/

    unsigned            headerlen;

    ext = ext;
    headerlen = strlen( SRU_HEADER );
    if( inSubPgm || setHeader || strnicmp(name, SRU_HEADER, headerlen ) ) {
        return;
    }
    assert( name );
    assert( ext );

    setHeader = TRUE;

    if( SRU.name ) {
        MemFree( SRU.name );
    }
    SRU.name = MemStrDup( name );
    strcpy( SRU.name, name + headerlen );
    SetBaseName( SRU.name );
    mkConsDesNames();
}
Пример #7
0
void AddParm( TypeInfo *typ, char *tname, ArrayInfo *array ) {
/*************************************************************/

/* add parameter to current function's list */

    var_rec     *ptmp;

    if( inSubPgm ) {
         return;
    }

    assert( tname );
    assert( typ );

    ptmp = MemMalloc( sizeof( var_rec ) );
    memset( ptmp, 0, sizeof( var_rec ) );
    if( SRU.curr.sp.last_parm ) {
        SRU.curr.sp.last_parm->next = ptmp;
    } else {
        SRU.curr.sp.parm_list = ptmp;
    }
    SRU.curr.sp.last_parm = ptmp;
    copyTypeInfo( &ptmp->type, typ );
    ptmp->typ_id = isTypeKnown( typ );
    if( !ptmp->typ_id ) {
        ptmp->fake = TRUE;
    }
    ptmp->next = NULL;
    ptmp->name = MemStrDup( tname );
    if( array == NULL ) {
        ptmp->array = NULL;
    } else {
        ptmp->array = MemMalloc( sizeof( ArrayInfo ) );
        memcpy( ptmp->array, array, sizeof( ArrayInfo ) );
    }
}
Пример #8
0
static statement *insertTypePrototype( statement *func, statement *locale ) {
/***************************************************************************/

/* insert a prototype of the external function into the types protoype section*/

    char        *line;
    char        *name;
    char        *libname;
    char        *sp;
    char        *ret;
    var_rec     *finger;
    statement   *rc;
    long        size;
    TypeInfo    *typ;
    char        typbuf[64];
    TypeInfo    tmptype;

    assert( func );
    assert( locale );

    name =  func->data.sp.name;

    /* determine return type */
    if( !func->data.sp.subroutine ) {
        typ = &func->data.sp.ret_type;
        sp = FUNCTION;
        if( _IsRefType( func->data.sp.typ_id ) ) {
            strcpy( typbuf, REF_MODIFIER );
            strcat( typbuf, typ->name );
            ret = typbuf;
            if( !func->data.sp.typ_id ) {
                func->data.sp.fake = TRUE;
            }
        } else {
            ret = typ->name;
        }
    } else {
        ret = "";
        sp = SUBROUTINE;
    }

    /* calculate size of statement */
    libname = GetLibName();
    size = strlen( name ) + strlen( sp ) + strlen( ret ) + strlen( libname );
    size += sizeof( DECL_THIS_VAR ) + sizeof( LIBRARY  ) + sizeof( LEFT_PAREN )
          + sizeof( RIGHT_PAREN ) + sizeof( DLL_SUFFIX ) + sizeof( DQUOTE )
          + sizeof( DQUOTE ) + OVERHEAD;

    finger = func->data.sp.parm_list;
    while( finger ) {
        size += sizeof( COMMA_DELIM ) + strlen( finger->name ) + 3;
        if( _IsRefType( finger->typ_id ) ) {
            size += sizeof( REF_MODIFIER );
        }
        size += strlen( finger->type.name );
        finger = finger->next;
    }


    /* build the statement */
    line = alloca( size );
    finger = func->data.sp.parm_list;
    if( Options & OPT_GEN_C_CODE ) {
        sprintf( line, "%s %s %s %s ", sp, ret, name, LEFT_PAREN );
    } else {
        sprintf( line, "%s %s %s %s %s", sp, ret, name, LEFT_PAREN,
                                        DECL_THIS_VAR );
        if( finger ) {
            strcat( line, COMMA_DELIM );
        }
    }
    while( finger ) {
        if( _IsRefType( finger->typ_id ) ) {
            strcat( line, REF_MODIFIER );
        }
        strcat( line, finger->type.name );
        strcat( line, " " );
        strcat( line, finger->name );
        if( finger->next ) {
            strcat( line, COMMA_DELIM );
        }
        finger = finger->next;
    }
    strcat( line, RIGHT_PAREN );
    strcat( line, " " );
    strcat( line, LIBRARY );
    strcat( line, DQUOTE );
    strcat( line, libname );
    strcat( line, DLL_SUFFIX );
    strcat( line, DQUOTE );
    strcat( line, "\n" );

    /* insert statement into our statement linked list */
    rc = insertStatement( locale, line );

    // beware - when pointers get added to the sp_header structure they
    //          must be explicitly copied here or else things will get freed
    //          twice.  This code should be rewritten. DRW
    memcpy( &(rc->data), &(func->data), sizeof( spec ) );
    rc->data.sp.name = MemStrDup( name );
    copyTypeInfo( &rc->data.sp.ret_type, &func->data.sp.ret_type );
    finger = func->data.sp.parm_list;
    SRU.curr.sp.parm_list = NULL;
    SRU.curr.sp.last_parm = NULL;
    tmptype.name = THIS_TYPE;
    tmptype.isref = FALSE;
    AddParm( &tmptype, THIS_VARIABLE, NULL );
    while( finger ) {
        AddParm( &finger->type, finger->name, finger->array );
        finger = finger->next;
    }
    rc->data.sp.parm_list = SRU.curr.sp.parm_list;
    rc->data.sp.last_parm = SRU.curr.sp.last_parm;
    rc->typ = SRU_SUBPROG;
    return( rc );
}
Пример #9
0
static  int  ParseArgs( int argc, char **argv )
/*********************************************/
{
    char        *p;
    int         wcc_option;
    int         c;
    int         i;
    list        *new_item;

    initialize_Flags();
    DebugFlag          = 1;
    StackSize = NULL;
    Conventions[0]     = 'r';
    Conventions[1]     = '\0';
    preprocess_only    = 0;
    cpp_want_lines     = 1; /* NB: wcc and wcl default to 0 here */
    cpp_keep_comments  = 0;
    cpp_encrypt_names  = 0;
    cpp_linewrap       = NULL;
    O_Name             = NULL;

    AltOptChar = '-'; /* Suppress '/' as option herald */
    while( (c = GetOpt( &argc, argv,
#if 0
                        "b:Cc::D:Ef:g::"
                        "HI:i::k:L:l:M::m:"
                        "O::o:P::QSs::U:vW::wx:yz::",
#else
                        "b:CcD:Ef:g::"
                        "HI:i::k:L:l:M::m:"
                        "O::o:P::QSs::U:vW::wx::yz::",
#endif
                        EnglishHelp )) != -1 ) {

        char    *Word = "";
        int     found_mapping = FALSE;

        for( i = 0; i < sizeof( mappings ) / sizeof( mappings[0] ); i++ ) {
            option_mapping  *m    = mappings + i;
            char            *tail = strchr( m->LongName, ':' );

            if( c != m->LongName[0] )
                continue;
            if( OptArg == NULL ) {
                if( m->LongName[1] == '\0' ) {
                    strcat( CC_Opts, " -" );
                    strcat( CC_Opts, m->WatcomName );
                    found_mapping = TRUE;
                    break;
                }
                /* non-existant argument can't match other cases */
                continue;
            }
            if( tail != NULL ) {
                if( !strncmp( OptArg, m->LongName + 1,
                              tail - m->LongName - 1 ) ) {
                    strcat( CC_Opts, " -" );
                    strcat( CC_Opts, m->WatcomName );
                    strcat( CC_Opts, OptArg + ( tail - m->LongName - 1) );
                    found_mapping = TRUE;
                    break;
                }
            } else if( !strcmp( OptArg, m->LongName + 1 ) ) {
                strcat( CC_Opts, " -" );
                strcat( CC_Opts, m->WatcomName );
                found_mapping = TRUE;
                break;
            }
        }
        if( found_mapping )
            continue;

        if( OptArg != NULL ) {
            Word = MemAlloc( strlen( OptArg ) + 6 );
            strcpy( Word, OptArg );
        }

        wcc_option = 1;

        switch( c ) {
        case 'f':
            if( !strcmp( Word, "syntax-only" ) ) {
                c = 'z';
                strcpy( Word, "s" );
                Flags.no_link = 1;
                break;
            }
            if( !strncmp( Word, "cpp-wrap=", 9 ) ) {
                MemFree( cpp_linewrap );
                Word[7] = 'w';
                cpp_linewrap = MemStrDup( Word + 7 );
                wcc_option = 0;
                break;
            }
            if( !strcmp( Word, "mangle-cpp" ) ) {
                cpp_encrypt_names = 1;
                wcc_option = 0;
                break;
            }
            switch( Word[0] ) {
            case 'd':           /* name of linker directive file */
                if( Word[1] == '='  ||  Word[1] == '#' ) {
                    MakeName( Word, ".lnk" );    /* add extension */
                    MemFree( Link_Name );
                    Link_Name = strfdup( Word + 2 );
                } else {
                    MemFree( Link_Name );
                    Link_Name = MemStrDup( TEMPFILE );
                }
                wcc_option = 0;
                break;
            case 'm':           /* name of map file */
                Flags.map_wanted = TRUE;
                if( Word[1] == '='  ||  Word[1] == '#' ) {
                    MemFree( Map_Name );
                    Map_Name = strfdup( 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;
                }
                MemFree( Obj_Name );
                Obj_Name = strfdup( p );        /* 08-mar-90 */
                break;
            case 'r':           /* name of error report file */
                Flags.want_errfile = TRUE;
                break;
            }
            /* avoid passing on unknown options */
            wcc_option = 0;
            break;

        case 'k':               /* stack size option */
            if( Word[0] != '\0' ) {
                MemFree( StackSize );
                StackSize = MemStrDup( Word );
            }
            wcc_option = 0;
            break;

        /* compiler options that affect the linker */
        case 'c':           /* compile only */
            Flags.no_link = TRUE;
            wcc_option = 0;
            break;
        case 'x':           /* change source language */
            if( strcmp( Word, "c" ) == 0 ) {
                Flags.force_c = TRUE;
            } else if( strcmp( Word, "c++" ) == 0 ) {
                Flags.force_c_plus = TRUE;
            } else {
                Flags.no_link = TRUE;
            }
            wcc_option = 0;
            break;

        case 'm':
            if( ( !strncmp( "cmodel=", Word, 7 ) )
                && ( Word[8] == '\0' ) ) {
                if( Word[7] == 't' ) {      /* tiny model */
                    Word[0] = 's';              /* change to small */
                    Flags.tiny_model = TRUE;
                } else {
                    Word[0] = Word[7];
                }
                Word[1] = '\0';
                break;
            }
            if( !strncmp( "regparm=", Word, 8 ) ) {
                if( !strcmp( Word + 8, "0" ) ) {
                    Conventions[0] =  's';
                } else {
                    Conventions[0] = 'r';
                }
                wcc_option = 0;
                break;
            }
            if( !strncmp( "tune=i", Word, 6 ) ) {
                switch( Word[6] ) {
                case '0':
                case '1':
                case '2':
                    CPU_Class = Word[6];
                    Conventions[0] = '\0';
                    break;
                case '3':
                case '4':
                case '5':
                case '6':
                    CPU_Class = Word[6];
                    break;
                default:
                    /* Unknown CPU type --- disable generation of this
                     * option */
                    CPU_Class = '\0';
                }
                wcc_option = 0;
                break;
            }
            wcc_option = 0;     /* dont' pass on unknown options */
            break;

        case 'z':                   /* 12-jan-89 */
            switch( tolower( Word[0] ) ) {
            case 's':
                Flags.no_link = TRUE;
                break;
            case 'q':
                Flags.be_quiet = TRUE;
                break;
            case 'w':
                Flags.windows = TRUE;
            }
            break;
        case 'E':
            preprocess_only = 1;
            wcc_option = 0;
            break;
        case 'P':
            cpp_want_lines = 0;
            wcc_option = 0;
            break;
        case 'C':
            cpp_keep_comments = 1;
            wcc_option = 0;
            break;
        case 'o':
            MemFree( O_Name );
            O_Name = strfdup( OptArg );
            wcc_option = 0;
            break;
        case 'g':
            if( OptArg == NULL ) {
                Word = "2";
            } else if( !isdigit( OptArg[0] ) ) {
                c = 'h';
                if( strcmp( Word, "w" ) == 0 ) {
                    DebugFlag = 3;
                } else if( strcmp( Word, "c" ) == 0 ) { /* 02-mar-91 */
                    Flags.do_cvpack = 1;
                    DebugFlag = 4;
                } else if( strcmp( Word, "d" ) == 0 ) {
                    DebugFlag = 5;
                }
                break;
            }
            c = '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 'S':
            Flags.do_disas = TRUE;
            Flags.no_link = TRUE;
            if( DebugFlag == 0 ) {
                c = 'd';
                Word = "1";
                goto parse_d;
            }
            wcc_option = 0;
            break;
        case 's':
            if( OptArg != NULL ) {
                /* leave -shared to mapping table */
                wcc_option = 0;
                break;
            }
            Flags.strip_all = 1;
            DebugFlag = 0;
            wcc_option = 0;
            break;
        case 'v':
            Flags.be_quiet = 0;
            wcc_option = 0;
            break;
        case 'W':
            if( OptArg != NULL && strncmp( OptArg, "l,", 2 ) == 0 ) {
                AddDirective( OptArg + 2 );
                wcc_option = 0;
            }
            /* other cases handled by table */
            break;
        case 'I':
            xlate_fname( Word );
            break;
        case 'b':
            Flags.link_for_sys = TRUE;
            MemFree( SystemName );
            SystemName = MemStrDup( Word );
            /* if Word found in specs.owc, add options from there: */
            if( ConsultSpecsFile( Word ) ) {
                /* all set */
                wcc_option = 0;
            } else {
                /* not found --- default to bt=<system> */
                strcpy( Word, "t=" );
                strcat( Word, SystemName );
            }
            break;
        case 'l':
            new_item = MemAlloc( sizeof( list ) );
            new_item->next = NULL;
            p = MemAlloc( strlen( OptArg ) + 2 + 1 );
            strcpy( p, OptArg );
            strcat( p, ".a" );
            new_item->item = strfdup( p );
            MemFree( p );
            ListAppend( &Libs_List, new_item );
            wcc_option = 0;
            break;
        case 'L':
            xlate_fname( Word );
            fputs( "libpath ", Fp );
            Fputnl( Word, Fp );
            wcc_option = 0;
            break;
        case 'i':       /* -include <file> --> -fi=<file> */
            if( OptArg == NULL ) {
                wcc_option = 0;
                break;
            }
            if( !strcmp( OptArg, "nclude" ) ) {
                c = 'f';
                Word = MemReAlloc( Word, strlen( argv[OptInd] ) + 6 );
                if( OptInd >= argc - 1 ) {
                    MemFree( cpp_linewrap );
                    PrintMsg( "Argument of -include missing\n", OptArg );
                    return( 1 );
                }
                strcpy( Word, "i=" );
                strfcat( Word, argv[OptInd] );
                argv[OptInd++][0] = '\0';
                break;
            }
            /* avoid passing un unknown options */
            wcc_option = 0;
            break;

        case 'M':               /* autodepend information for Unix makes */
            if( OptArg == NULL ) {
                wcc_option = 0;
                break;
            }
            c = 'a';
            if( !strcmp( OptArg, "D" ) ||
                !strcmp( OptArg, "MD" ) ) {
                /* NB: only -MMD really matches OW's behaviour, but
                 * for now, let's accept -MD to mean the same */
                /* translate to -adt=.o */
                strcpy( Word, "dt=.o" );
            } else if( !strcmp( OptArg, "F" ) ) {
                Word = MemReAlloc( Word, strlen( argv[OptInd] ) + 6 );
                if( OptInd >= argc - 1 ) {
                    MemFree( cpp_linewrap );
                    PrintMsg( "Argument of -MF missing\n", OptArg );
                    return( 1 );
                }
                strcpy( Word, "d=" );
                strfcat( Word, argv[OptInd] );
                argv[OptInd++][0] = '\0';
            } else if( !strcmp( OptArg, "T") ) {
                Word = MemReAlloc( Word, strlen( argv[OptInd] ) + 6 );
                if( OptInd >= argc - 1 ) {
                    MemFree( cpp_linewrap );
                    PrintMsg( "Argument of -M%s missing\n", OptArg );
                    return( 1 );
                }
                strcpy( Word, "dt=" );
                strcat( Word, argv[OptInd] );
                argv[OptInd++][0] = '\0';
            } else {
                /* avoid passing on incompatible options */
                wcc_option = 0;
            }
            break;
        }

        /* don't add linker-specific options */
        /* to compiler command line:     */
        if( wcc_option ) {
            addccopt( c, Word );
        }
        if( OptArg != NULL ) {
            MemFree( Word );
            Word = NULL;
        }
    }

    if( preprocess_only ) {
        Flags.no_link = TRUE;
        if( O_Name == NULL ) {
            MemFree( Obj_Name );           /* preprocess to stdout by default */
            Obj_Name = NULL;
        }
        strcat( CC_Opts, " -p" );
        if( cpp_encrypt_names )
            strcat( CC_Opts, "e" );
        if( cpp_want_lines )
            strcat( CC_Opts, "l" );
        if( cpp_keep_comments )
            strcat( CC_Opts, "c" );
        if( cpp_linewrap != NULL ) {
            strcat( CC_Opts, cpp_linewrap );
        }
    }
    if( CPU_Class )
        addccopt( CPU_Class, Conventions );
    if( Flags.be_quiet )
        addccopt( 'z', "q" );
    if( O_Name != NULL ) {
        if( Flags.no_link && !Flags.do_disas ) {
            MemFree( Obj_Name );
            Obj_Name = O_Name;
        } else {
            strcpy( Exe_Name, O_Name );
            Flags.keep_exename = 1;
            MemFree( O_Name );
        }
        O_Name = NULL;
    }
    if( Obj_Name != NULL ) {
        strcat( CC_Opts, " -fo=" );
        strcat( CC_Opts, Obj_Name );
    }
    if( !Flags.want_errfile ) {
        strcat( CC_Opts, " -fr" );
    }
    for( i = 1; i < argc ; i++ ) {
        Word = argv[i];
        if( Word == NULL || Word[0] == '\0' )
            /* HBB 20060217: argument was used up */
            continue;
        new_item = MemAlloc( sizeof( list ) );
        new_item->next = NULL;
        new_item->item = strfdup( Word );
        if( FileExtension( Word, ".lib" ) || FileExtension( Word, ".a" ) ) {
            ListAppend( &Libs_List, new_item );
        } else {
            ListAppend( &Files_List, new_item );
        }
    }
    MemFree( cpp_linewrap );
    return( 0 );
}
Пример #10
0
static char *strfdup( const char *source )
{
    return( xlate_fname( MemStrDup( source ) ) );
}
Пример #11
0
/*
 * doInitializeEditor - do just that
 */
static void doInitializeEditor( int argc, char *argv[] )
{
    int         i, arg, cnt, ocnt, startcnt = 0;
    srcline     sline;
    int         k, j;
    char        tmp[FILENAME_MAX], c[1];
    char        buff[MAX_STR], file[MAX_STR], **list;
    char        cmd[MAX_STR * 2];
    char        *parm;
    char        *startup[MAX_STARTUP];
    char        *startup_parms[MAX_STARTUP];
    vi_rc       rc;
    vi_rc       rc1;

    /*
     * Make sure WATCOM is setup and if it is not, make a best guess.
     */
    watcom_setup_env();

    /*
     * If EDPATH is not set, use system default %WATCOM%\EDDAT.
     */
    if( getenv( "EDPATH" ) == NULL ) {
        char *watcom;

        watcom = getenv( "WATCOM" );
        if( watcom != NULL ) {
            char edpath[FILENAME_MAX];

            sprintf( edpath, "%s%c%s", watcom, FILE_SEP, "eddat" );

            if( setenv( "EDPATH", edpath, 0 ) != 0 ) {
                /*
                 * Bail out silently on error, as we will get error message later on.
                 */
            }
        }
    }

    /*
     * misc. set up
     */
    MaxMemFree = MemSize();
    StaticStart();
    FTSInit();
    BoundDataInit();
    EditFlags.Starting = true;
    InitCommandLine();
    ChkExtendedKbd();
    SSInitBeforeConfig();

    GetCWD1( &HomeDirectory );
    GetCWD1( &CurrentDirectory );
    SetCWD( HomeDirectory );
    if( cfgFN == NULL ){
        cfgFN = DupString( CFG_NAME );
    }

    checkFlags( &argc, argv, startup, startup_parms, &startcnt );
    ScreenInit();
    SetWindowSizes();
    EditFlags.ClockActive = false;
    SetInterrupts();
#ifdef __WIN__
    InitClrPick();
    InitFtPick();
    SubclassGenericInit();
    CursorOp( COP_INIT );
#else
    InitColors();
#endif
    InitSavebufs();
    InitKeyMaps();

    /*
     * initial configuration
     */
    EditVars.Majick = MemStrDup( "()~@" );
    EditVars.FileEndString = MemStrDup( "[END_OF_FILE]" );
    MatchInit();
    SetGadgetString( NULL );
    WorkLine = MemAlloc( sizeof( line ) + EditVars.MaxLine + 2 );
    WorkLine->len = -1;

    sline = 0;
    if( cfgFN[0] != 0 ) {
        c[0] = 0;
        rc = Source( cfgFN, c, &sline );
        if( rc == ERR_FILE_NOT_FOUND ) {
#ifdef __WIN__
            CloseStartupDialog();
            MessageBox( (HWND)NULLHANDLE, "Could not locate configuration information; please make sure your EDPATH environment variable is set correctly",
                        EditorName, MB_OK );
            ExitEditor( -1 );
#else
            rc = ERR_NO_ERR;
#endif
        }
    } else {
        rc = ERR_NO_ERR;
    }
    if( wantNoReadEntireFile ) {
        EditFlags.ReadEntireFile = false;
    }
    VerifyTmpDir();
    while( LostFileCheck() );
    HookScriptCheck();

    if( EditFlags.Quiet ) {
        EditFlags.Spinning = false;
        EditFlags.Clock = false;
    }
    ExtendedMemoryInit();

    /*
     * more misc. setup
     */
    if( EditVars.WordDefn == NULL ) {
        EditVars.WordDefn = DupString( &WordDefnDefault[6] );
        InitWordSearch( EditVars.WordDefn );
    }
    if( EditVars.WordAltDefn == NULL ) {
        EditVars.WordAltDefn = DupString( WordDefnDefault );
    }
    if( EditVars.TagFileName == NULL ) {
        EditVars.TagFileName = DupString( "tags" );
    }
    DotBuffer = MemAlloc( (maxdotbuffer + 2) * sizeof( vi_key ) );
    AltDotBuffer = MemAlloc( (maxdotbuffer + 2) * sizeof( vi_key ) );
    DotCmd = MemAlloc( (maxdotbuffer + 2) * sizeof( vi_key ) );
    SwapBlockInit( EditVars.MaxSwapBlocks );
    ReadBuffer = MemAlloc( MAX_IO_BUFFER + 6 );
    WriteBuffer = MemAlloc( MAX_IO_BUFFER + 6 );
    FindHistInit( EditVars.FindHist.max );
    FilterHistInit( EditVars.FilterHist.max );
    CLHistInit( EditVars.CLHist.max );
    LastFilesHistInit( EditVars.LastFilesHist.max );
    GetClockStart();
    GetSpinStart();
    SelRgnInit();
    SSInitAfterConfig();
#if defined( VI_RCS )
    ViRCSInit();
#endif

    /*
     * create windows
     */
    StartWindows();
    InitMouse();
    rc1 = NewMessageWindow();
    if( rc1 != ERR_NO_ERR ) {
        FatalError( rc1 );
    }
    DoVersion();
    rc1 = InitMenu();
    if( rc1 != ERR_NO_ERR ) {
        FatalError( rc1 );
    }
    EditFlags.SpinningOurWheels = true;
    EditFlags.ClockActive = true;
    EditFlags.DisplayHold = true;
    rc1 = NewStatusWindow();
    if( rc1 != ERR_NO_ERR ) {
        FatalError( rc1 );
    }
    EditFlags.DisplayHold = false;

    MaxMemFreeAfterInit = MemSize();

    /*
     * look for a tag: if there is one, set it up as the file to start
     */
    EditFlags.WatchForBreak = true;
    if( cTag != NULL && !EditFlags.NoInitialFileLoad ) {
#if defined( __NT__ ) && !defined( __WIN__ )
        {
            if( !EditFlags.Quiet ) {
                SetConsoleActiveScreenBuffer( OutputHandle );
            }
        }
#endif
        rc1 = LocateTag( cTag, file, buff );
        cFN = file;
        if( rc1 != ERR_NO_ERR ) {
            if( rc1 == ERR_TAG_NOT_FOUND ) {
                Error( GetErrorMsg( rc1 ), cTag );
                ExitEditor( 0 );
            }
            FatalError( rc1 );
        }
    }

    /*
     * start specified file(s)
     */
    cmd[0] = 'e';
    cmd[1] = 0;

    arg = argc - 1;
    k = 1;
    while( !EditFlags.NoInitialFileLoad ) {

        if( cFN == nullFN && !EditFlags.UseNoName ) {
            break;
        }

#ifdef __NT__
        {
            int     k2;
            int     arg2;
            char    path[_MAX_PATH];
            int     found;
            int     fd;
            size_t  len;
            size_t  len1;
            char    *p;

            /*
             * check for the existence of a file name containing spaces, and open it if
             * there is one
             */
            len = _MAX_PATH - 1;
            found = 0;
            p = path;
            arg2 = arg;
            for( k2 = k; argv[k2] != NULL; ) {
                len1 = strlen( argv[k2] );
                if( len1 > len )
                    break;
                memcpy( p, argv[k2], len1 );
                p += len1;
                *p = '\0';
                len -= len1;
                --arg2;
                ++k2;
                fd = open( path, O_RDONLY );
                if( fd != -1 ) {
                    close( fd );
                    k = k2;
                    arg = arg2;
                    found = 1;
                    break;
                }
                *p++ = ' ';
            }
            if( found ) {
#ifndef __UNIX__
                len1 = strlen( path );
                if( path[len1 - 1] == '.' )
                    path[len1 - 1] = '\0';
#endif
                rc1 = NewFile( path, false );
                if( rc1 != ERR_NO_ERR ) {
                    FatalError( rc1 );
                }
                cFN = argv[k];
                if( arg < 1 ) {
                    break;
                }
                continue;
            }
        }
#endif

        strcat( cmd, SingleBlank );
        strcat( cmd, cFN );
        ocnt = cnt = ExpandFileNames( cFN, &list );
        if( cnt == 0 ) {
            cnt = 1;
        } else {
            cFN = list[0];
        }

        for( j = 0; j < cnt; j++ ) {
            rc1 = NewFile( cFN, false );
            if( rc1 != ERR_NO_ERR && rc1 != NEW_FILE ) {
                FatalError( rc1 );
            }
            if( EditFlags.BreakPressed ) {
                break;
            }
            if( cnt > 0 && j < cnt - 1 ) {
                cFN = list[j + 1];
            }
        }
        if( ocnt > 0 ) {
            MemFreeList( ocnt, list );
        }
        if( EditFlags.BreakPressed ) {
            ClearBreak();
            break;
        }
        k++;
        arg--;
        if( cTag != NULL || arg < 1 ) {
            break;
        }
        cFN = argv[k];
    }
    if( EditFlags.StdIOMode ) {
        rc1 = NewFile( "stdio", false );
        if( rc1 != ERR_NO_ERR ) {
            FatalError( rc1 );
        }
    }
    EditFlags.WatchForBreak = false;
    EditFlags.Starting = false;

    /*
     * if there was a tag, do the appropriate search
     */
    if( cTag != NULL && !EditFlags.NoInitialFileLoad ) {
        if( buff[0] != '/' ) {
            i = atoi( buff );
            rc1 = GoToLineNoRelCurs( i );
        } else {
            rc1 = FindTag( buff );
        }
        if( rc1 > 0 ) {
            Error( GetErrorMsg( rc1 ) );
        }
    }

    /*
     * try to run startup file
     */
    if( EditFlags.RecoverLostFiles ) {
        startcnt = 0;
    }
    for( i = 0; i < startcnt; i++ ) {
        GetFromEnv( startup[i], tmp );
        ReplaceString( &cfgFN, tmp );
        if( cfgFN[0] != 0 ) {
            if( startup_parms[i] != NULL ) {
                parm = startup_parms[i];
            } else {
                c[0] = 0;
                parm = c;
            }
#if defined( __NT__ ) && !defined( __WIN__ )
            {
                if( !EditFlags.Quiet ) {
                    SetConsoleActiveScreenBuffer( OutputHandle );
                }
            }
#endif
            sline = 0;
            rc = Source( cfgFN, parm, &sline );
        }
    }
    if( rc > ERR_NO_ERR ) {
        Error( "%s on line %u of \"%s\"", GetErrorMsg( rc ), sline, cfgFN );
    }
    if( argc == 1 ) {
        LoadHistory( NULL );
    } else {
        LoadHistory( cmd );
    }
    if( EditVars.GrepDefault == NULL ) {
        EditVars.GrepDefault = DupString( "*.(c|h)" );
    }
    if( goCmd[0] != 0 ) {
        KeyAddString( goCmd );
    }
    if( keysToPush != NULL ) {
        KeyAddString( keysToPush );
    }
#ifdef __WIN__
    if( lineToGoTo != 0 ) {
        SetCurrentLine( lineToGoTo );
        NewCursor( CurrentWindow, EditVars.NormalCursorType );
    }
#endif
    AutoSaveInit();
    HalfPageLines = WindowAuxInfo( CurrentWindow, WIND_INFO_TEXT_LINES ) / 2 - 1;
#if defined( _M_X64 )
    VarAddGlobalStr( "OSX64", "1" );
#elif defined( _M_IX86 ) && !defined( _M_I86 )
    VarAddGlobalStr( "OS386", "1" );
#endif
    if( EditVars.StatusString == NULL ) {
        EditVars.StatusString = DupString( "L:$6L$nC:$6C" );
    }
    UpdateStatusWindow();
#ifdef __WIN__
    if( CurrentInfo == NULL ) {
        // no file loaded - screen is disconcertenly empty - reassure
        DisplayFileStatus();
    }
#endif
    NewCursor( CurrentWindow, EditVars.NormalCursorType );
#if defined( __NT__ ) && !defined( __WIN__ )
    {
        SetConsoleActiveScreenBuffer( OutputHandle );
    }
#endif

} /* doInitializeEditor */
Пример #12
0
static int Parse( char *Cmd )
/***************************/
{
    char        opt;
    char        *end;
    FILE        *atfp;
    char        buffer[_MAX_PATH];
    char        unquoted[_MAX_PATH];
    size_t      len;
    char        *p;
    int         wcc_option;
    list        *new_item;

    /* Cmd will always begin with at least one */
    /* non-space character if we get this far  */

    for( ;; ) {
        Cmd = SkipSpaces( Cmd );
        if( *Cmd == '\0' )
            break;
        opt = *Cmd;
        if( opt == '-'  ||  opt == Switch_Chars[1] ) {
            Cmd++;
        } else if( opt != '@' ) {
            opt = ' ';
        }

        end = Cmd;
        if( *Cmd == '"' ) {
            end = FindNextWS( end );
        } else {
            end = FindNextWSOrOpt( end, opt, Switch_Chars );
        }
        len = end - Cmd;
        if( len != 0 ) {
            if( opt == ' ' ) {          /* if filename, add to list */
                strncpy( Word, Cmd, len );
                Word[len] = '\0';
                end = ScanFName( end, len );
                UnquoteFName( unquoted, sizeof( unquoted ), Word );
                new_item = MemAlloc( sizeof( list ) );
                new_item->next = NULL;
                new_item->item = MemStrDup( unquoted );
                if( FileExtension( Word, ".lib" ) ) {
                    ListAppend( &Libs_List, new_item );
                } else if( FileExtension( Word, ".res" ) ) {
                    ListAppend( &Res_List, new_item );
                } else {
                    ListAppend( &Files_List, new_item );
                }
            } else {                    /* otherwise, do option */
                --len;
                strncpy( Word, Cmd + 1, len );
                Word[len] = '\0';
                wcc_option = 1;         /* assume it's a wcc option */

                switch( tolower( *Cmd ) ) {
                case 'b':               /* possibly -bcl */
                    if( strnicmp( Word, "cl=", 3 ) == 0 ) {
                        strcat( CC_Opts, " -bt=" );
                        strcat( CC_Opts, Word+3 );
                        Flags.link_for_sys = TRUE;
                        MemFree( SystemName );
                        SystemName = MemStrDup( Word+3 );
                        wcc_option = 0;
                    }
                    break;

                case 'f':               /* files option */
                    p = ScanFName( end, len );
                    switch( tolower( Word[0] ) ) {
                    case 'd':           /* name of linker directive file */
                        if( Word[1] == '='  ||  Word[1] == '#' ) {
                            end = p;
                            /* remove quotes from target linker control filename */
                            UnquoteFName( unquoted, sizeof( unquoted ), Word + 2 );

                            MakeName( unquoted, ".lnk" );    /* add extension */

                            MemFree( Link_Name );
                            Link_Name = MemStrDup( unquoted );
                        } else {
                            MemFree( Link_Name );
                            Link_Name = MemStrDup( TEMPFILE );
                        }
                        wcc_option = 0;
                        break;
                    case 'e':           /* name of exe file */
                        if( Word[1] == '='  ||  Word[1] == '#' ) {
                            end = p;
                            /* remove quotes from target executable filename */
                            UnquoteFName( unquoted, sizeof( unquoted ), Word + 2 );
                            strcpy( Exe_Name, unquoted );
                        }
                        wcc_option = 0;
                        break;
                    case 'i':           /* name of forced include file */
                        end = p;
                        break;
                    case 'm':           /* name of map file */
                        Flags.map_wanted = TRUE;
                        if( Word[1] == '='  ||  Word[1] == '#' ) {
                            end = p;
                            /* remove quotes from target map filename */
                            UnquoteFName( unquoted, sizeof( unquoted ), Word + 2 );

                            MemFree( Map_Name );
                            Map_Name = MemStrDup( unquoted );
                        }
                        wcc_option = 0;
                        break;
                    case 'o':           /* name of object file */
                        end = p;
                        /* parse off argument, so we get right filename
                            in linker command file */
                        p = &Word[1];
                        if( Word[1] == '='  ||  Word[1] == '#' )
                            ++p;

                        /* remove quotes from object name */
                        UnquoteFName( unquoted, sizeof( unquoted ), p );

                        MemFree( Obj_Name );
                        Obj_Name = MemStrDup( unquoted );
                        break;
#if defined( WCLI86 ) || defined( WCL386 )
                    case 'p':           /* floating-point option */
                        end = p;
                        if( tolower( Word[1] ) == 'c' ) {
                            Flags.math_8087 = 0;
                        }
                        break;
#endif
                    default:
                        end = p;
                        break;
                    }
                    break;
                case 'k':               /* stack size option */
                    if( Word[0] != '\0' ) {
                        MemFree( StackSize );
                        StackSize = MemStrDup( Word );
                    }
                    wcc_option = 0;
                    break;
                case 'l':               /* link target option */
                    switch( (Word[1] << 8) | tolower( Word[0] ) ) {
                    case 'p':
                        Flags.link_for_dos = 0;
                        Flags.link_for_os2 = TRUE;
                        break;
                    case 'r':
                        Flags.link_for_dos = TRUE;
                        Flags.link_for_os2 = 0;
                        break;
                    default:                    /* 10-jun-91 */
                        Flags.link_for_sys = TRUE;
                        p = &Word[0];
                        if( Word[0] == '='  ||  Word[0] == '#' )
                            ++p;
                        MemFree( SystemName );
                        SystemName = MemStrDup( p );
                        break;
                    }
                    wcc_option = 0;
                    break;
                case 'x':
                    if( Word[0] == '\0' ) {
                        Flags.two_case = TRUE;
                        wcc_option = 0;
                    }
                    break;
                case '@':
                    if( Word[0] != '\0' ) {
                        char const * const      env = getenv( Word );

                        if( env != NULL ) {
                            if( handle_environment_variable( env ) ) {
                                return( 1 );          // Recursive call failed
                            }
                            via_environment = TRUE;
                            Cmd = end;
                            continue;
                        }

                        end = ScanFName( end, len );

                        /* remove quotes from additional linker options file */
                        UnquoteFName( unquoted, sizeof( unquoted ), Word );
                        strcpy( Word, unquoted );

                        MakeName( Word, ".lnk" );
                        errno = 0;
                        if( (atfp = fopen( Word, "r" )) == NULL ) {
                            PrintMsg( WclMsgs[UNABLE_TO_OPEN_DIRECTIVE_FILE], Word, strerror(  errno ) );
                            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 != NULL )
                                    *p = '\0';
                                AddName( &buffer[5], Fp );
                                Flags.do_link = TRUE;
                            } else {
                                fputs( buffer, Fp );
                            }
                        }
                        fclose( atfp );
                    }
                    wcc_option = 0;
                    break;

                /* compiler options that affect the linker */
#ifdef WCL386
                case '3':
                case '4':
                case '5':                           /* 22-sep-92 */
                    Conventions = tolower( Word[0] );
                    break;
#endif
                case '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':
                    if( strcmp( Word, "w" ) == 0 ) {
                        DebugFlag = 3;
                    } else if( strcmp( Word, "c" ) == 0 ) { /* 02-mar-91 */
                        Flags.do_cvpack = 1;
                        DebugFlag = 4;
                    } else if( strcmp( Word, "d" ) == 0 ) {
                        DebugFlag = 5;
                    }
                    break;
                case 'i':           /* include file path */
                    end = ScanFName( end, len );
                    break;
                case 'c':           /* compile only */
                    if( stricmp( Word, "c" ) == 0 ) {
                        Flags.force_c = TRUE;
                    } else if( stricmp( Word, "c++" ) == 0 ) {
                        Flags.force_c_plus = TRUE;
                    } else {
                        Flags.no_link = TRUE;
                    }
                    wcc_option = 0;
                    break;
                case 'y':
                    if( stricmp( Word, "x" ) == 0 ) {
                        strcat( CC_Opts, " -x" );
                        wcc_option = 0;
                    } else if( Word[0] == '\0' ) {
                        wcc_option = 0;
                    }
                    break;
#if defined( WCLI86 ) || defined( WCL386 )
                case 'm':           /* memory model */
                    if( Cmd[1] == 't' || Cmd[1] == 'T' ) { /* tiny model*/
                        Word[0] = 's';              /* change to small */
                        Flags.tiny_model = TRUE;
                    }
                    break;
#endif
                case 'p':
                    Flags.no_link = TRUE;
                    break;      /* this is a preprocessor option */
                case 'q':
                    Flags.be_quiet = TRUE;
                    break;
                case 'z':                   /* 12-jan-89 */
                    switch( tolower( Cmd[1] ) ) {
                    case 's':
                        Flags.no_link = TRUE;
                        break;
                    case 'q':
                        Flags.be_quiet = TRUE;
                        break;
#ifdef WCLI86
                    case 'w':
                        Flags.windows = TRUE;
#endif
                    }
                    break;
                case '"':                           /* 17-dec-91 */
                    /* As parameter passing to linker is a special case, we need to pass
                     * whole command instead of first character removed. This allows us
                     * to parse also string literals in AddDirective.
                     */
                    wcc_option = 0;
                    strncpy( Word, Cmd, ++len );
                    Word[len] = '\0';
                    AddDirective( len );
                    break;
                }

                /* don't add linker-specific options */
                /* to compiler command line:     */

                if( wcc_option ) {
                    len = strlen( CC_Opts );
                    CC_Opts[len++] = ' ';
                    CC_Opts[len++] = opt;
                    CC_Opts[len++] = *Cmd;    /* keep original case */
                    CC_Opts[len] = '\0';
                    strcat( CC_Opts, Word );
                }
            }
            Cmd = end;
        }
    }

    return( 0 );
}
Пример #13
0
PVOID dbgStrDup(PSZ pszFile, ULONG line, PSZ pszCall, PSZ psz)
  {
  PVOID p = MemStrDup(psz);
  logfunction(pszFile, line, pszCall, "strdup", p, 0);
  return p;
  }