static void set_some_kinda_name( char token, char *name ) /*******************************************************/ /* set: code class / data seg. / module name / text seg */ { int len; char **tmp; len = strlen( name ) + 1; switch( token ) { case 'c': tmp = &Options.code_class; break; case 'd': tmp = &Options.data_seg; break; case 'm': tmp = &Options.module_name; break; case 't': tmp = &Options.text_seg; break; default: return; } if( *tmp != NULL ) { AsmFree(*tmp); } *tmp = AsmAlloc( len ); strcpy( *tmp, name ); }
static char *ReadIndirectFile( void ) /***********************************/ { char *env; char *str; int handle; int len; char ch; env = NULL; handle = open( ParamBuf, O_RDONLY | O_BINARY ); if( handle != -1 ) { len = filelength( handle ); env = AsmAlloc( len + 1 ); read( handle, env, len ); env[len] = '\0'; close( handle ); // zip through characters changing \r, \n etc into ' ' str = env; while( *str ) { ch = *str; if( ch == '\r' || ch == '\n' ) { *str = ' '; } #if !defined(__UNIX__) if( ch == 0x1A ) { // if end of file *str = '\0'; // - mark end of str break; } #endif ++str; } } return( env ); }
static char * MakeAnonymousLabel( void ) /**************************************/ { char *p = AsmAlloc( LABELSIZE ); sprintf( p, "@C%04X", ModuleInfo.hll_label ); ModuleInfo.hll_label++; return ( p ); }
static void SetCPUPMC( void ) /***************************/ { char *tmp; for( tmp=OptParm; tmp < OptScanPtr; tmp++ ) { if( *tmp == 'p' ) { if( SWData.cpu >= 2 ) { // set protected mode SWData.protect_mode = TRUE; } else { MsgPrintf1( MSG_CPU_OPTION_INVALID, CopyOfParm() ); } } else if( *tmp == 'r' ) { if( SWData.cpu >= 3 ) { // set register based calling convention Options.watcom_parms_passed_by_regs = TRUE; } else { MsgPrintf1( MSG_CPU_OPTION_INVALID, CopyOfParm() ); } } else if( *tmp == 's' ) { if( SWData.cpu >= 3 ) { // set stack based calling convention Options.watcom_parms_passed_by_regs = FALSE; } else { MsgPrintf1( MSG_CPU_OPTION_INVALID, CopyOfParm() ); } } else if( *tmp == '"' ) { // set default mangler char *dest; tmp++; dest = strchr(tmp, '"'); if( Options.default_name_mangler != NULL ) { AsmFree( Options.default_name_mangler ); } Options.default_name_mangler = AsmAlloc( dest - tmp + 1 ); dest = Options.default_name_mangler; for( ; *tmp != '"'; dest++, tmp++ ) { *dest = *tmp; } *dest = NULLC; } else { MsgPrintf1( MSG_UNKNOWN_OPTION, CopyOfParm() ); exit( 1 ); } } if( SWData.cpu < 3 ) { Options.watcom_parms_passed_by_regs = TRUE; if( SWData.cpu < 2 ) { SWData.protect_mode = FALSE; } } }
static void SetTargName( char *name, size_t len ) /***********************************************/ { char *p; if( Options.build_target != NULL ) { AsmFree( Options.build_target ); Options.build_target = NULL; } if( name == NULL || len == 0 ) return; Options.build_target = AsmAlloc( len + 1 ); p = Options.build_target; for( ; len != 0; --len ) { *p++ = (char)toupper( *name++ ); } *p++ = '\0'; }
static void SetTargName( char *name, unsigned len ) /*************************************************/ { char *p; if( Options.build_target != NULL ) { AsmFree( Options.build_target ); Options.build_target = NULL; } if( name == NULL || len == 0 ) return; Options.build_target = AsmAlloc( len + 1 ); p = Options.build_target; while( len != 0 ) { *p++ = toupper( *name++ ); --len; } *p++ = '\0'; }
static ret_code WriteExprSrc( hll_list * hll, char * buffer ) /***********************************************************/ { int size; char *p; size = strlen( buffer ) + 1; if ( hll->condlines ) { size += strlen( hll->condlines ) + 1; } p = AsmAlloc( size ); if ( hll->condlines ) { strcpy( p, hll->condlines ); strcat( p, "\n" ); strcat( p, buffer ); } else strcpy( p, buffer ); AsmFree( hll->condlines ); hll->condlines = p; return( NOT_ERROR ); }
static int ProcOptions( char *str, int *level ) /*********************************************/ { char *save[MAX_NESTING]; char *buffers[MAX_NESTING]; if( str != NULL ) { for( ;; ) { while( *str == ' ' || *str == '\t' ) ++str; if( *str == '@' && *level < MAX_NESTING ) { save[(*level)++] = CollectEnvOrFileName( str + 1 ); buffers[*level] = NULL; str = getenv( ParamBuf ); if( str == NULL ) { str = ReadIndirectFile(); buffers[*level] = str; } if( str != NULL ) continue; str = save[--(*level)]; } if( *str == '\0' ) { if( *level == 0 ) break; if( buffers[*level] != NULL ) { AsmFree( buffers[*level] ); buffers[*level] = NULL; } str = save[--(*level)]; continue; } if( *str == '-' || *str == SwitchChar ) { str = ProcessOption(str+1, str); } else { /* collect file name */ char *beg, *p; int len; beg = str; if( *str == '"' ) { for( ;; ) { ++str; if( *str == '"' ) { ++str; break; } if( *str == '\0' ) break; if( *str == '\\' ) { ++str; } } } else { for( ;; ) { if( *str == '\0' ) break; if( *str == ' ' ) break; if( *str == '\t' ) break; #if !defined(__UNIX__) if( *str == SwitchChar ) break; #endif ++str; } } len = str-beg; p = (char *) AsmAlloc( len + 1 ); memcpy( p, beg, len ); p[ len ] = '\0'; StripQuotes( p ); get_fname( p, ASM ); AsmFree(p); } } } return( 0 ); }
static void get_fname( char *token, int type ) /********************************************/ /* * figure out the source file name & store it in AsmFiles * fill in default object file name if it is null */ { char name [ _MAX_PATH ]; char msgbuf[80]; PGROUP pg; PGROUP def; /* get filename for source file */ if( type == ASM ) { if( token == NULL ) { MsgGet( SOURCE_FILE, msgbuf ); Fatal( MSG_CANNOT_OPEN_FILE, msgbuf ); } if( AsmFiles.fname[ASM] != NULL ) { Fatal( MSG_TOO_MANY_FILES ); } _splitpath2( token, pg.buffer, &pg.drive, &pg.dir, &pg.fname, &pg.ext ); if( *pg.ext == '\0' ) { pg.ext = ASM_EXT; } _makepath( name, pg.drive, pg.dir, pg.fname, pg.ext ); AsmFiles.fname[ASM] = AsmAlloc( strlen( name ) + 1 ); strcpy( AsmFiles.fname[ASM], name ); _makepath( name, pg.drive, pg.dir, NULL, NULL ); /* add the source path to the include path */ AddStringToIncludePath( name ); if( AsmFiles.fname[OBJ] == NULL ) { /* set up default object and error filename */ pg.ext = OBJ_EXT; _makepath( name, NULL, NULL, pg.fname, pg.ext ); } else { _splitpath2( AsmFiles.fname[OBJ], def.buffer, &def.drive, &def.dir, &def.fname, &def.ext ); if( *def.fname == NULLC ) def.fname = pg.fname; if( *def.ext == NULLC ) def.ext = OBJ_EXT; _makepath( name, def.drive, def.dir, def.fname, def.ext ); AsmFree( AsmFiles.fname[OBJ] ); } AsmFiles.fname[OBJ] = AsmAlloc( strlen( name ) + 1 ); strcpy( AsmFiles.fname[OBJ], name ); if( AsmFiles.fname[ERR] == NULL ) { pg.ext = ERR_EXT; _makepath( name, NULL, NULL, pg.fname, pg.ext ); } else { _splitpath2( AsmFiles.fname[ERR], def.buffer, &def.drive, &def.dir, &def.fname, &def.ext ); if( *def.fname == NULLC ) def.fname = pg.fname; if( *def.ext == NULLC ) def.ext = ERR_EXT; _makepath( name, def.drive, def.dir, def.fname, def.ext ); AsmFree( AsmFiles.fname[ERR] ); } AsmFiles.fname[ERR] = AsmAlloc( strlen( name ) + 1 ); strcpy( AsmFiles.fname[ERR], name ); if( AsmFiles.fname[LST] == NULL ) { pg.ext = LST_EXT; _makepath( name, NULL, NULL, pg.fname, pg.ext ); } else { _splitpath2( AsmFiles.fname[LST], def.buffer, &def.drive, &def.dir, &def.fname, &def.ext ); if( *def.fname == NULLC ) def.fname = pg.fname; if( *def.ext == NULLC ) def.ext = LST_EXT; _makepath( name, def.drive, def.dir, def.fname, def.ext ); AsmFree( AsmFiles.fname[LST] ); } AsmFiles.fname[LST] = AsmAlloc( strlen( name ) + 1 ); strcpy( AsmFiles.fname[LST], name ); } else { /* get filename for object, error, or listing file */ _splitpath2( token, pg.buffer, &pg.drive, &pg.dir, &pg.fname, &pg.ext ); if( AsmFiles.fname[ASM] != NULL ) { _splitpath2( AsmFiles.fname[ASM], def.buffer, &def.drive, &def.dir, &def.fname, &def.ext ); if( *pg.fname == NULLC ) { pg.fname = def.fname; } } if( *pg.ext == NULLC ) { switch( type ) { case ERR: pg.ext = ERR_EXT; break; case LST: pg.ext = LST_EXT; break; case OBJ: pg.ext = OBJ_EXT; break; } } _makepath( name, pg.drive, pg.dir, pg.fname, pg.ext ); if( AsmFiles.fname[type] != NULL ) { AsmFree( AsmFiles.fname[type] ); } AsmFiles.fname[type] = AsmAlloc( strlen( name ) + 1 ); strcpy( AsmFiles.fname[type], name ); } }
ret_code HllStartDef( int i ) /***************************/ { struct hll_list *hll; int cmd = AsmBuffer[i]->value; char buffer[MAX_ID_LEN+1+64]; DebugMsg(("HllStartDef(%u [=%s]) enter\n", i, AsmBuffer[i]->string_ptr )); #if FASTPASS /* make sure the directive is stored */ if ( StoreState == FALSE && Parse_Pass == PASS_1 ) { SaveState(); } #endif switch (cmd) { case T_DOT_REPEAT: if ( AsmBuffer[i+1]->token != T_FINAL ) { DebugMsg(("HllStartDef: unexpected tokens behind .REPEAT\n" )); AsmError( SYNTAX_ERROR ); return( ERROR ); } break; case T_DOT_IF: case T_DOT_WHILE: #if 0 /* Masm allows a missing expression! */ if ( AsmBuffer[i+1]->token == T_FINAL ) { AsmError( SYNTAX_ERROR ); return( ERROR ); } #endif break; } hll = AsmAlloc( sizeof(hll_list) ); hll->cmd = HLL_UNDEF; /* create labels which are always needed */ /* for .IF -.ENDIF without .ELSE no symexit label is needed. */ hll->symfirst = NULL; hll->symexit = NULL; hll->symtest = MakeAnonymousLabel(); hll->condlines = NULL; // structure for .IF .ELSE .ENDIF // cond jump to symtest // ... // jmp symexit // symtest: // ... // symexit: // structure for .IF .ELSEIF // cond jump to symtest // ... // jmp symexit // symtest: // cond jump to (new) symtest // ... // jmp symexit // symtest: // ... // structure for .WHILE and .REPEAT: // jmp symtest (for .WHILE only) // symfirst: // ... // symtest: (jumped to by .continue) // test end condition, cond jump to symfirst // symexit: (jumped to by .break) PushLineQueue(); switch (cmd) { case T_DOT_IF: hll->cmd = HLL_IF; /* get the C-style expression, convert to ASM code lines */ i++; if ( ERROR == EvaluateHllExpression( hll, &i, LABELTEST, FALSE ) ) { return( ERROR ); } HllPushTestLines( hll ); #if 1 /* if no lines have been created, the symtest label isn't needed */ if ( line_queue == NULL ) { AsmFree( hll->symtest ); hll->symtest = NULL; } #endif break; case T_DOT_WHILE: case T_DOT_REPEAT: /* create the label to loop start */ hll->symfirst = MakeAnonymousLabel(); hll->symexit = MakeAnonymousLabel(); if ( cmd == T_DOT_WHILE ) { i++; hll->cmd = HLL_WHILE; if ( AsmBuffer[i]->token != T_FINAL ) { if ( ERROR == EvaluateHllExpression( hll, &i, LABELFIRST, TRUE ) ) { return( ERROR ); } } else hll->condlines = ""; /* create a jump to second label */ /* optimisation: if second label is just a jump, dont jump! */ if ( hll->condlines && _memicmp(hll->condlines, "jmp", 3) ) { sprintf( buffer, " jmp %s", hll->symtest ); AddLineQueue( buffer ); } else { AsmFree( hll->symtest ); hll->symtest = NULL; } } else { i++; hll->cmd = HLL_REPEAT; } MakeLabel( buffer, hll->symfirst ); AddLineQueue( buffer ); break; } if ( AsmBuffer[i]->token != T_FINAL ) { DebugMsg(("HllStartDef: unexpected token %u [%s]\n", AsmBuffer[i]->token, AsmBuffer[i]->string_ptr )); AsmErr( SYNTAX_ERROR_EX, AsmBuffer[i]->string_ptr ); return( ERROR ); } hll->next = HllStack; HllStack = hll; if ( ModuleInfo.list ) LstWrite( LSTTYPE_DIRECTIVE, GetCurrOffset(), NULL ); if ( line_queue ) /* might be NULL! (".if 1") */ RunLineQueue(); return( NOT_ERROR ); }