static void AddName( char *name, FILE *link_fp ) { //==================================================== list *curr_name; list *last_name; list *new_name; char path[_MAX_PATH]; PGROUP pg1; PGROUP pg2; last_name = NULL; for( curr_name = ObjList; curr_name != NULL; curr_name = curr_name->next ) { if( stricmp( name, curr_name->filename ) == 0 ) return; last_name = curr_name; } new_name = MemAlloc( sizeof( struct list ) ); if( ObjList == NULL ) { ObjList = new_name; } else { last_name->next = new_name; } new_name->filename = strdup( name ); new_name->next = NULL; fputs( "file '", link_fp ); if( ObjName != NULL ) { // construct full name of object file from ObjName information _splitpath2( ObjName, pg1.buffer, &pg1.drive, &pg1.dir, &pg1.fname, &pg1.ext ); if( pg1.ext[0] == '\0' ) pg1.ext = OBJ_EXT; if( ( pg1.fname[0] == '\0' ) || ( ( pg1.fname[0] == '*' ) && ( pg1.fname[1] == '\0' ) ) ) { _splitpath2( name, pg2.buffer, NULL, NULL, &pg1.fname, &pg2.ext ); if( pg2.ext[0] != '\0' ) { pg1.ext = pg2.ext; } } _makepath( path, pg1.drive, pg1.dir, pg1.fname, pg1.ext ); name = path; } fputs( name, link_fp ); Fputnl( "'", link_fp ); }
static int CompLink( void ) { //================================ int rc; const char *file; bool comp_err; PGROUP pg; int i; list *currobj; list *nextobj; if( Flags.quiet ) { Fputnl( "option quiet", Fp ); } fputs( DebugOptions[ DebugFlag ], Fp ); if( Flags.link_for_sys ) { fputs( "system ", Fp ); Fputnl( SystemName, Fp ); } else { #if defined( __QNX__ ) Fputnl( "system qnx", Fp ); #elif defined( __LINUX__ ) Fputnl( "system linux", Fp ); #elif _CPU == 386 #if defined( __OS2__ ) Fputnl( "system os2v2", Fp ); #elif defined( __NT__ ) Fputnl( "system nt", Fp ); #else Fputnl( "system dos4g", Fp ); #endif #elif _CPU == 8086 if( Flags.windows ) { Fputnl( "system windows", Fp ); } else if( Flags.link_for_dos ) { Fputnl( "system dos", Fp ); } else if( Flags.link_for_os2 ) { Fputnl( "system os2", Fp ); } else { #if defined( __OS2__ ) Fputnl( "system os2", Fp ); #else Fputnl( "system dos", Fp ); #endif } #elif _CPU == _AXP Fputnl( "system ntaxp", Fp ); #else #error Unknown System #endif } comp_err = false; ObjList = NULL; for( currobj = FileList; currobj != NULL; currobj = nextobj ) { strcpy( Word, currobj->filename ); MakeName( Word, ".for" ); // if no extension, assume ".for" file = DoWildCard( Word ); while( file != NULL ) { // while more filenames: strcpy( Word, file ); #ifndef __UNIX__ strlwr( Word ); #endif _splitpath2( Word, pg.buffer, &pg.drive, &pg.dir, &pg.fname, &pg.ext ); if( strcmp( pg.ext, OBJ_EXT ) != 0 ) { // if not object, compile rc = tool_exec( TYPE_FOR, Word, CmpOpts ); if( rc != 0 ) { comp_err = true; if( ( rc == -1 ) || ( rc == 255 ) ) { rc = 1; break; } } } _makepath( Word, NULL, NULL, pg.fname, NULL ); if( ExeName[0] == '\0' ) { fputs( "name '", Fp ); fputs( Word, Fp ); Fputnl( "'", Fp ); strcpy( ExeName, Word ); } _makepath( Word, NULL, NULL, pg.fname, OBJ_EXT ); AddName( Word, Fp ); // add obj filename file = DoWildCard( NULL ); // get next filename } DoWildCardClose(); nextobj = currobj->next; free( currobj->filename ); free( currobj ); } for( currobj = LibList; currobj != NULL; currobj = nextobj ) { fputs( "library ", Fp ); Fputnl( currobj->filename, Fp ); nextobj = currobj->next; free( currobj->filename ); free( currobj ); } fclose( Fp ); // close TempFile if( comp_err ) { rc = 1; } else { rc = 0; if( ( ObjList != NULL ) && !Flags.no_link ) { rc = tool_exec( TYPE_LINK, "@" TEMPFILE, NULL ); if( rc == 0 && Flags.do_cvpack ) { rc = tool_exec( TYPE_PACK, ExeName, NULL ); } if( rc != 0 ) { rc = 2; // return 2 to show Temp_File already closed } } } for( currobj = ObjList; currobj != NULL; currobj = nextobj ) { nextobj = currobj->next; free( currobj->filename ); free( currobj ); } for( i = 0; i < TYPE_MAX; ++i ) { if( tools[i].path != NULL ) { free( tools[i].path ); tools[i].path = NULL; } } return( rc ); }
static int Parse( int argc, char **argv ) { //================================== char opt; //char *end; char *cmd; size_t len; int cmp_option; int opt_index; int cmp_opt_index; Flags.no_link = 0; Flags.link_for_sys = 0; Flags.quiet = 0; #if _CPU == 8086 Flags.windows = 0; Flags.link_for_dos = 0; Flags.link_for_os2 = 0; #else Flags.default_win = 0; #endif Flags.do_cvpack = 0; DebugFlag = 0; // Skip the first entry - it's the current program's name opt_index = 1; cmp_opt_index = 0; while( opt_index < argc ) { cmd = argv[opt_index]; opt = *cmd; if( ( opt == '-' ) || ( opt == SwitchChars[1] ) ) { cmd++; } else { opt = ' '; } len = strlen(cmd); if( len != 0 ) { if( opt == ' ' ) { // if filename, add to list strncpy( Word, cmd, len ); Word[len] = '\0'; strlwr( Word ); if( strstr( Word, ".lib" ) != NULL ) { AddFile( &LibList, Word ); } else { AddFile( &FileList, Word ); } } else { // otherwise, do option --len; strncpy( Word, cmd + 1, len ); Word[len] = '\0'; cmp_option = 1; // assume its a compiler option switch( tolower( *cmd ) ) { case 'f': // files option switch( tolower( Word[0] ) ) { case 'd': // name of linker directive file if( Word[1] == '\0' ) { LinkName = TEMPFILE; cmp_option = 0; } else if( (Word[1] == '=') || (Word[1] == '#') ) { MakeName( Word, ".lnk" ); // add extension LinkName = strdup( Word + 2 ); cmp_option = 0; } break; case 'e': // name of exe file if( ( Word[1] == '=' ) || ( Word[1] == '#' ) ) { fputs( "name ", Fp ); Fputnl( Word + 2, Fp ); strcpy( ExeName, Word + 2 ); cmp_option = 0; } break; case 'm': // name of map file if( Word[1] == '\0' ) { fputs( "option map\n", Fp ); cmp_option = 0; } else if( (Word[1] == '=') || (Word[1] == '#') ) { fputs( "option map=", Fp ); Fputnl( Word + 2, Fp ); cmp_option = 0; } break; case 'i': if( ( Word[1] == '=' ) || ( Word[1] == '#' ) ) { fputs( "@", Fp ); Fputnl( Word + 2, Fp ); cmp_option = 0; } break; case 'o': // name of object file // parse off argument, so we get right filename // in linker command file if( ( Word[1] == '=' ) || ( Word[1] == '#' ) ) { ObjName = strdup( &Word[2] ); } break; default: break; } break; case 'k': // stack size option if( ( Word[0] == '=' ) || ( Word[0] == '#' ) ) { fputs( "option stack=", Fp ); Fputnl( Word + 1, Fp ); cmp_option = 0; } break; case 'c': // compile only if( Word[0] == '\0' ) { Flags.no_link = 1; cmp_option = 0; } break; case 'y': if( Word[0] == '\0' ) { cmp_option = 0; } break; case 'p': // ignore the /p option - we now only // have a protect-mode compiler if( Word[0] == '\0' ) { cmp_option = 0; } break; case 'l': if( ( Word[0] == '=' ) || ( Word[0] == '#' ) ) { Flags.link_for_sys = 1; SystemName = strdup( &Word[1] ); cmp_option = 0; #if _CPU == 8086 } else if( stricmp( Word, "r" ) == 0 ) { Flags.link_for_dos = 1; Flags.link_for_os2 = 0; cmp_option = 0; } else if( stricmp( Word, "p" ) == 0 ) { Flags.link_for_os2 = 1; Flags.link_for_dos = 0; cmp_option = 0; #endif } break; case '"': Fputnl( &Word[0], Fp ); cmp_option = 0; break; // compiler options that affect the linker #if _CPU != 8086 case 'b': if( stricmp( Word, "w" ) ) { Flags.default_win = 1; } break; #endif case 'q': if( IsOption( cmd, len + sizeof( char ), "Quiet" ) ) { Flags.quiet = 1; } break; case 'd': if( DebugFlag == 0 ) { // not set by -h yet if( strcmp( Word, "1" ) == 0 ) { DebugFlag = 1; } else if( strcmp( Word, "2" ) == 0 ) { DebugFlag = 2; } } break; case 'h': if( strcmp( Word, "w" ) == 0 ) { DebugFlag = 3; } else if( strcmp( Word, "c" ) == 0 ) { Flags.do_cvpack = 1; DebugFlag = 4; } else if( strcmp( Word, "d" ) == 0 ) { DebugFlag = 5; } break; case 's': if( IsOption( cmd, len + sizeof( char ), "SYntax" ) ) { Flags.no_link = 1; } break; #if _CPU == 8086 case 'w': if( IsOption( cmd, len + sizeof( char ), "WIndows" ) ) { Flags.windows = 1; } break; #endif default: break; } // don't add linker-specific options to compiler command line if( cmp_option != 0 ) { CmpOpts[cmp_opt_index] = (char *)MemAlloc((3+strlen(Word))*sizeof(char)); CmpOpts[cmp_opt_index][0] = opt; CmpOpts[cmp_opt_index][1] = *cmd; CmpOpts[cmp_opt_index][2] = '\0'; strcat( CmpOpts[cmp_opt_index], Word ); CmpOpts[++cmp_opt_index] = NULL; } } } opt_index++; } return( 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 ); }
static int CompLink( void ) /***************************/ { int rc; char *p; char *file; char *path; list *itm; char errors_found; tool_type utl; int i; if( Flags.be_quiet ) { Fputnl( "option quiet", Fp ); } fputs( DebugOptions[DebugFlag], Fp ); if( StackSize != NULL ) { fputs( "option stack=", Fp ); Fputnl( StackSize, Fp ); } if( Flags.link_for_sys ) { fputs( "system ", Fp ); Fputnl( SystemName, Fp ); } else if( Flags.is32bit ) { #if defined(__OS2__) Fputnl( "system os2v2", Fp ); #elif defined(__NT__) Fputnl( "system nt", Fp ); #elif defined(__LINUX__) Fputnl( "system linux", Fp ); if( !Flags.strip_all ) Fputnl( "option exportall", Fp ); #else Fputnl( "system dos4g", Fp ); #endif } else { if( Flags.windows ) { /* 15-mar-90 */ Fputnl( "system windows", Fp ); } else if( Flags.tiny_model ) { Fputnl( "system com", Fp ); } else { #if defined(__OS2__) Fputnl( "system os2", Fp ); #else Fputnl( "system dos", Fp ); #endif } } for( itm = Directive_List; itm != NULL; itm = itm->next ) { Fputnl( itm->item, Fp ); } Word = MemAlloc( MAX_CMD ); errors_found = 0; for( itm = Files_List; itm != NULL; itm = itm->next ) { strcpy( Word, itm->item ); utl = SrcName( Word ); /* if no extension, assume .c */ file = GetName( Word ); /* get first matching filename */ path = MakePath( Word ); /* isolate path portion of filespec */ while( file != NULL ) { /* while more filenames: */ strcpy( Word, path ); strcat( Word, file ); if( !FileExtension( Word, OBJ_EXT ) && // if not .obj or .o, compile !FileExtension( Word, OBJ_EXT_SECONDARY ) ) { rc = tool_exec( utl, Word, CC_Opts ); if( rc != 0 ) { errors_found = 1; } p = strrchr( file, '.' ); if( p != NULL ) { *p = '\0'; } strcpy( Word, file ); } AddName( Word, Fp ); if( Obj_List != NULL && Flags.do_disas ) { char *sfile; char *ofile; ofile = MemAlloc( strlen( file ) + 6 ); strcpy( ofile, file ); if( Exe_Name[0] != '\0' ) { /* have "-S -o output.name" */ sfile = Exe_Name; } else { if( FileExtension( Word, OBJ_EXT ) || FileExtension( Word, OBJ_EXT_SECONDARY ) ) { p = strrchr( file, '.' ); if( p != NULL ) { *p = '\0'; } strcpy( Word, file ); } else { /* wdis needs extension */ strcat( ofile, Obj_Name ); } sfile = Word; strcat( Word, ".s" ); } memmove( sfile + 3, sfile, strlen( sfile ) + 1 ); sfile[0] = '-'; sfile[1] = 'l'; sfile[2] = '='; rc = tool_exec( TYPE_DIS, ofile, sfile ); MemFree( ofile ); } if( Exe_Name[0] == '\0' ) { #ifdef __UNIX__ strcpy( Exe_Name, OUTPUTFILE ); Flags.keep_exename = 1; #else p = strrchr( Word, '.' ); if( p != NULL ) { *p = '\0'; } strcpy( Exe_Name, Word ); #endif } #ifdef __UNIX__ MemFree( file ); #endif file = GetName( NULL ); /* get next filename */ } MemFree( path ); } if( errors_found ) { rc = 1; } else { rc = 0; BuildLinkFile(); if(( Obj_List != NULL || Flags.do_link ) && Flags.no_link == FALSE ) { rc = tool_exec( TYPE_LINK, "@" TEMPFILE, NULL ); if( rc == 0 && Flags.do_cvpack ) { rc = tool_exec( TYPE_PACK, Exe_Name, NULL ); } if( rc != 0 ) { rc = 2; /* return 2 to show Temp_File already closed */ } } } if( Word != NULL ) { MemFree( Word ); Word = NULL; } for( i = 0; i < TYPE_MAX; ++i ) { if( tools[i].path != NULL ) { MemFree( tools[i].path ); tools[i].path = NULL; } } return( rc ); }
static int CompLink( void ) /***************************/ { int rc; char *p; char *file; char *path; list *itm; char errors_found; void *tmp_env; tool_type utl; int i; if( Flags.be_quiet ) { Fputnl( "option quiet", Fp ); } fputs( DebugOptions[DebugFlag], Fp ); if( StackSize != NULL ) { fputs( "option stack=", Fp ); Fputnl( StackSize, Fp ); } if( Flags.link_for_sys ) { /* 10-jun-91 */ fputs( "system ", Fp ); Fputnl( SystemName, Fp ); } else { #if defined( WCLAXP ) Fputnl( "system ntaxp", Fp ); #elif defined( WCLPPC ) #if defined( __LINUX__ ) Fputnl( "system linuxppc", Fp ); #else Fputnl( "system ntppc", Fp ); #endif #elif defined( WCLMPS ) Fputnl( "system linuxmips", Fp ); #elif defined( WCL386 ) #if defined( __OS2__ ) Fputnl( "system os2v2", Fp ); /* 04-feb-92 */ #elif defined( __NT__ ) Fputnl( "system nt", Fp ); #elif defined( __LINUX__ ) Fputnl( "system linux", Fp ); #else Fputnl( "system dos4g", Fp ); #endif #else if( Flags.windows ) { /* 15-mar-90 */ Fputnl( "system windows", Fp ); } else if( Flags.tiny_model ) { Fputnl( "system com", Fp ); } else if( Flags.link_for_dos ) { Fputnl( "system dos", Fp ); } else if( Flags.link_for_os2 ) { Fputnl( "system os2", Fp ); } else { #if defined( __OS2__ ) Fputnl( "system os2", Fp ); #else Fputnl( "system dos", Fp ); #endif } #endif } /* pass given resources to linker */ for( itm = Res_List; itm != NULL; itm = itm->next ) { fputs( "option resource=", Fp ); FputnlQuoted( itm->item, Fp ); } /* pass given directives to linker */ for( itm = Directive_List; itm != NULL; itm = itm->next ) { Fputnl( itm->item, Fp ); } tmp_env = NULL; if( via_environment && strlen( CC_Opts ) >= 20 ) // 20 to allow wclxxxxx=y tmp_env = makeTmpEnv( CC_Opts ); errors_found = 0; for( itm = Files_List; itm != NULL; itm = itm->next ) { strcpy( Word, itm->item ); utl = SrcName( Word ); /* if no extension, assume .c */ file = GetName( Word ); /* get first matching filename */ path = MakePath( Word ); /* isolate path portion of filespec */ while( file != NULL ) { /* while more filenames: */ strcpy( Word, path ); strcat( Word, file ); if( !FileExtension( Word, OBJ_EXT ) && /* if not .obj or .o, compile */ !FileExtension( Word, OBJ_EXT_SECONDARY ) ) { rc = tool_exec( utl, Word, CC_Opts ); if( rc != 0 ) { errors_found = 1; } p = strrchr( file, '.' ); if( p != NULL ) *p = '\0'; strcpy( Word, file ); } AddName( Word, Fp ); if( Exe_Name[0] == '\0' ) { p = strrchr( Word, '.' ); if( p != NULL ) *p = '\0'; strcpy( Exe_Name, Word ); } #ifdef __UNIX__ MemFree( file ); #endif file = GetName( NULL ); /* get next filename */ } MemFree( path ); } if( tmp_env != NULL ) killTmpEnv( tmp_env ); if( errors_found ) { rc = 1; } else { rc = 0; BuildLinkFile(); if(( Obj_List != NULL || Flags.do_link ) && Flags.no_link == FALSE ) { rc = tool_exec( TYPE_LINK, "@" TEMPFILE, NULL ); if( rc == 0 && Flags.do_cvpack ) { rc = tool_exec( TYPE_PACK, Exe_Name, NULL ); } if( rc != 0 ) { rc = 2; /* return 2 to show Temp_File already closed */ } } } for( i = 0; i < TYPE_MAX; ++i ) { if( tools[i].path != NULL ) { MemFree( tools[i].path ); tools[i].path = NULL; } } return( rc ); }
static int Parse( char *cmd ) { //================================== char opt; char *end; int len; int cmp_option; char in_quotes; Flags.no_link = 0; Flags.link_for_sys = 0; Flags.quiet = 0; #if _CPU == 8086 Flags.windows = 0; Flags.link_for_dos = 0; Flags.link_for_os2 = 0; #else Flags.default_win = 0; #endif Flags.do_cvpack = 0; DebugFlag = 0; // "cmd" will always begin with at least one // non-space character if we get this far do { opt = *cmd; if( ( opt == '-' ) || ( opt == SwitchChars[1] ) ) { cmd++; } else { opt = ' '; } in_quotes = FALSE; end = cmd; for(;;) { if( *end == '\0' ) break; if( *end == '"' ) { if( in_quotes ) break; in_quotes = TRUE; } if( !in_quotes ) { if( *end == ' ' ) break; if( *end == '-' ) break; if( *end == SwitchChars[1] ) { break; } } ++end; } len = end - cmd; if( len != 0 ) { if( opt == ' ' ) { // if filename, add to list strncpy( Word, cmd, len ); Word[len] = '\0'; strlwr( Word ); if( strstr( Word, ".lib" ) != NULL ) { AddFile( &LibList, Word ); } else { AddFile( &FileList, Word ); } } else { // otherwise, do option --len; strncpy( Word, cmd + 1, len ); Word[len] = '\0'; cmp_option = 1; // assume its a compiler option switch( tolower( *cmd ) ) { case 'f': // files option end = ScanFName( end, len ); switch( tolower( Word[0] ) ) { case 'd': // name of linker directive file if( Word[1] == '\0' ) { LinkName = TEMPFILE; cmp_option = 0; } else if( (Word[1] == '=') || (Word[1] == '#') ) { MakeName( Word, ".lnk" ); // add extension LinkName = strdup( Word + 2 ); cmp_option = 0; } break; case 'e': // name of exe file if( ( Word[1] == '=' ) || ( Word[1] == '#' ) ) { fputs( "name ", Fp ); Fputnl( Word + 2, Fp ); strcpy( ExeName, Word + 2 ); cmp_option = 0; } break; case 'm': // name of map file if( Word[1] == '\0' ) { fputs( "option map\n", Fp ); cmp_option = 0; } else if( (Word[1] == '=') || (Word[1] == '#') ) { fputs( "option map=", Fp ); Fputnl( Word + 2, Fp ); cmp_option = 0; } break; case 'i': if( ( Word[1] == '=' ) || ( Word[1] == '#' ) ) { fputs( "@", Fp ); Fputnl( Word + 2, Fp ); cmp_option = 0; } break; case 'o': // name of object file // parse off argument, so we get right filename // in linker command file if( ( Word[1] == '=' ) || ( Word[1] == '#' ) ) { ObjName = strdup( &Word[2] ); } break; default: break; } break; case 'k': // stack size option if( ( Word[0] == '=' ) || ( Word[0] == '#' ) ) { fputs( "option stack=", Fp ); Fputnl( Word + 1, Fp ); cmp_option = 0; } break; case 'c': // compile only if( Word[0] == '\0' ) { Flags.no_link = 1; cmp_option = 0; } break; case 'y': if( Word[0] == '\0' ) { cmp_option = 0; } break; case 'p': // ignore the /p option - we now only // have a protect-mode compiler if( Word[0] == '\0' ) { cmp_option = 0; } break; case 'l': if( ( Word[0] == '=' ) || ( Word[0] == '#' ) ) { Flags.link_for_sys = 1; SystemName = strdup( &Word[1] ); cmp_option = 0; #if _CPU == 8086 } else if( stricmp( Word, "r" ) == 0 ) { Flags.link_for_dos = 1; Flags.link_for_os2 = 0; cmp_option = 0; } else if( stricmp( Word, "p" ) == 0 ) { Flags.link_for_os2 = 1; Flags.link_for_dos = 0; cmp_option = 0; #endif } break; case '"': Fputnl( &Word[0], Fp ); ++end; // skip over closing quote cmp_option = 0; break; // compiler options that affect the linker #if _CPU != 8086 case 'b': if( stricmp( Word, "w" ) ) { Flags.default_win = 1; } break; #endif case 'q': if( IsOption( cmd, len + sizeof(char), "Quiet" ) ) { Flags.quiet = 1; } break; case 'd': if( DebugFlag == 0 ) { // not set by -h yet if( strcmp( Word, "1" ) == 0 ) { DebugFlag = 1; } else if( strcmp( Word, "2" ) == 0 ) { DebugFlag = 2; } } break; case 'h': if( strcmp( Word, "w" ) == 0 ) { DebugFlag = 3; } else if( strcmp( Word, "c" ) == 0 ) { Flags.do_cvpack = 1; DebugFlag = 4; } else if( strcmp( Word, "d" ) == 0 ) { DebugFlag = 5; } break; case 's': if( IsOption( cmd, len + sizeof( char ), "SYntax" ) ) { Flags.no_link = 1; } break; #if _CPU == 8086 case 'w': if( IsOption( cmd, len + sizeof( char ), "WIndows" ) ) { Flags.windows = 1; } break; #endif default: break; } // don't add linker-specific options to compiler command line if( cmp_option != 0 ) { len = strlen( CmpOpts ); CmpOpts[len++] = ' '; CmpOpts[len++] = opt; CmpOpts[len++] = *cmd; // keep original case CmpOpts[len] = '\0'; strcat( CmpOpts, Word ); } } cmd = end; } cmd = SkipSpaces( cmd ); } while( *cmd != '\0' ); return( 0 ); }