extern void WndTmpFileInspect( const char *file ) { void *viewhndl; viewhndl = FOpenSource( file, NO_MOD, 0 ); DoWndFileOpen( file, viewhndl, NULL, false, true, WND_TMPFILE ); }
extern void WndFileInspect( const char *file, bool binary ) { handle filehndl; void *viewhndl; mod_handle mod; DIPHDL( cue, ch ); viewhndl = NULL; if( binary ) { filehndl = FileOpen( file, OP_READ ); if( filehndl == NIL_HANDLE ) Error( ERR_NONE, LIT_ENG( ERR_FILE_NOT_OPEN ), file ); DoWndBinOpen( file, filehndl ); } else { mod = LookupModName( NO_MOD, file, strlen( file ) ); if( mod == NO_MOD ) { mod = FindFileMod( file ); } if( FindFirstCue( mod, ch ) ) { viewhndl = OpenSrcFile( ch ); } else { viewhndl = FOpenSource( file, NO_MOD, 0 ); ch = NULL; } if( viewhndl == NULL ) Error( ERR_NONE, LIT_ENG( ERR_FILE_NOT_OPEN ), file ); DoWndFileOpen( file, viewhndl, ch, false, false, WND_FILE ); } }
extern wp_srcfile * WPSourceOpen( sio_data * curr_sio, bint quiet ) /*****************************************************************/ { file_info * curr_file; rtn_info * curr_rtn; wp_srcfile * wpsrc_file; void * src_file; mod_info * curr_mod; cue_handle * ch; location_list ll; int line; curr_mod = curr_sio->curr_mod; curr_file = curr_sio->curr_file; curr_rtn = curr_sio->curr_rtn; if( curr_file->unknown_file ) { src_file = NULL; } else { src_file = FOpenSource( curr_file->name, curr_mod->mh, curr_file->fid ); } if( src_file == NULL ) { curr_sio->src_file = NULL; if( !quiet ) { if( curr_file->unknown_file ) { ErrorMsg( LIT( Src_File_Not_Known ) ); } else { ErrorMsg( LIT( Src_File_Not_Found ), curr_file->name ); } } return( NULL ); } wpsrc_file = ProfCAlloc( sizeof( wp_srcfile ) ); wpsrc_file->src_file = src_file; curr_sio->src_file = wpsrc_file; if( SymLocation( curr_rtn->sh, NULL, &ll ) == DS_OK ) { ch = alloca( DIPHandleSize( HK_CUE ) ); AddrCue( curr_mod->mh, ll.e[0].u.addr, ch ); wpsrc_file->rtn_line = CueLine( ch ); } setSrcLineData( wpsrc_file, curr_sio, curr_mod, curr_file, curr_rtn ); line = 1; for( ;; ) { WPSourceGetLine( curr_sio->sample_window, line ); if( wpsrc_file->src_eof ) break; line++; } wpsrc_file->src_rows = line - 1; return( wpsrc_file ); }
int main( void ) { char buff[256]; struct browser *fp; int len; int i; int got; fp = FOpenSource( "testsrcm.c", 0, 0 ); if( fp != NULL ) { for( i = 1; FReadLine( fp, i, 0, buff, 256 ) != FREADLINE_ERROR; ++i ) { } for( --i; i >= 1; --i ) { buff[FReadLine( fp, i, 0, buff, 256 )] = '\0'; printf( "%s\n", buff ); } FDoneSource( fp ); } }
void *OpenSrcFile( cue_handle *ch ) { void *hndl; char_ring *path; char *p; char *d; char *rem_name; bool used_star; unsigned len; char *buff; len = CueFile( ch, NULL, 0 ) + 1; _AllocA( buff, len ); CueFile( ch, buff, len ); hndl = FOpenSource( buff, CueMod( ch ), CueFileId( ch ) ); if( hndl != NULL ) return( hndl ); for( path = SrcSpec; path != NULL; path = path->next ) { used_star = FALSE; d = TxtBuff; for( p = path->name; *p != '\0'; ++p ) { if( *p == '*' ) { used_star = TRUE; d += ModName( CueMod( ch ), d, TXT_LEN ); } else { *d++ = *p; } } *d = NULLCHAR; if( !used_star ) { #if 0 /* John can't remember why he put this code in, and it screws up when the user sets a source path of ".". If we find some case where it's required, we'll have to think harder about things. */ if( *ExtPointer( TxtBuff, 0 ) != '\0' ) { *SkipPathInfo( TxtBuff, 0 ) = '\0'; } #endif d = AppendPathDelim( TxtBuff, 0 ); if( !IsAbsolutePath( buff ) ) { StrCopy( buff, d ); hndl = FOpenSource( TxtBuff, CueMod( ch ), CueFileId( ch ) ); if( hndl != NULL ) return( hndl ); } /* We have a small problem here. We want to strip off the path information for the source file name, but we don't know if the file was compiled on the local system or the remote one. We'll kludge things by doing a local skip and then a remote one and seeing who takes off the most stuff. Don't even think about the case where the file has been compiled on a third, different type of file system. */ p = SkipPathInfo( buff, OP_LOCAL ); rem_name = SkipPathInfo( buff, OP_REMOTE ); if( rem_name > p ) p = rem_name; d = StrCopy( p, d ); *d = NULLCHAR; } hndl = FOpenSource( TxtBuff, CueMod( ch ), CueFileId( ch ) ); if( hndl != NULL ) return( hndl ); } return( NULL ); }
wp_asmfile *WPAsmOpen( sio_data * curr_sio, int src_row, bool quiet ) /*******************************************************************/ { wp_asmfile * wpasm_file; cue_handle * ch; cue_handle * ch2; mod_info * curr_mod; file_info * curr_file; massgd_sample_addr * samp_data; wp_asmline * asm_line; mod_handle mh; file_handle fh; address addr; cue_fileid fid; search_result cue_find; int rows; int asm_group; int asm_row; int file_index; int addr_cmp; clicks_t addr_tick_index; quiet=quiet; ch = alloca( DIPHandleSize( HK_CUE ) ); ch2 = alloca( DIPHandleSize( HK_CUE ) ); curr_file = curr_sio->curr_file; curr_mod = curr_sio->curr_mod; if( curr_file->fid == 0 || LineCue( curr_mod->mh, curr_sio->curr_file->fid, src_row, 0, ch2 ) == SR_NONE ) { ch2 = NULL; } fh = ExeOpen( curr_sio->curr_image->name ); if( fh == -1 ) { ErrorMsg( LIT( Exe_Not_Found ), curr_sio->curr_image->name ); return( NULL ); } wpasm_file = ProfCAlloc( sizeof(wp_asmfile) ); curr_sio->asm_file = wpasm_file; wpasm_file->asm_buff = ProfAlloc( MAX_ASM_BUFF_LEN ); wpasm_file->asm_buff_len = MAX_ASM_BUFF_LEN; SetNumBytes( 0 ); SetExeFile( fh, false ); wpasm_file->fh = fh; addr = ModAddr( curr_mod->mh ); SetExeOffset( addr ); wpasm_file->max_time = 0; addr_tick_index = curr_mod->first_tick_index - 1; samp_data = WPGetMassgdSampData( curr_sio, addr_tick_index++ ); wpasm_file->asm_data = ProfAlloc( sizeof(wp_asm_groups) ); wpasm_file->asm_data[0].asm_lines = ProfAlloc( MAX_ASM_LINE_SIZE ); wpasm_file->asm_groups = 0; rows = 0; for( ;; ) { mh = curr_mod->mh; if( EndOfSegment() || AddrMod( addr, &mh ) == SR_NONE || mh != curr_mod->mh ) break; cue_find = (AddrCue( curr_mod->mh, addr, ch ) == SR_EXACT); if( ch2 != NULL && CueCmp( ch, ch2 ) == 0 ) { wpasm_file->entry_line = rows; ch2 = NULL; } asm_line = WPGetAsmLoc( wpasm_file, rows, &asm_group, &asm_row ); if( cue_find ) { asm_line->source_line = true; asm_line->u.src.line = CueLine( ch ); asm_line->u.src.src_file = NULL; if( !curr_file->unknown_file ) { fid = CueFileId( ch ); file_index = 0; while( file_index < curr_mod->file_count ) { curr_file = curr_mod->mod_file[file_index]; if( curr_file->fid == fid ) { asm_line->u.src.src_file = FOpenSource( curr_file->name, mh, fid ); break; } file_index++; } } rows++; asm_line = WPGetAsmLoc( wpasm_file, rows, &asm_group, &asm_row ); } asm_line = &wpasm_file->asm_data[asm_group].asm_lines[asm_row]; asm_line->source_line = false; asm_line->u.asm_line.addr = addr; asm_line->u.asm_line.tick_count = 0; for( ;; ) { if( samp_data == NULL ) break; addr_cmp = AddrCmp( &addr, samp_data->raw ); if( addr_cmp < 0 ) break; if( addr_cmp == 0 ) { asm_line->u.asm_line.tick_count = samp_data->hits; if( asm_line->u.asm_line.tick_count > wpasm_file->max_time ) { wpasm_file->max_time = asm_line->u.asm_line.tick_count; } } samp_data = WPGetMassgdSampData( curr_sio, addr_tick_index++ ); } rows++; CodeAdvance( &addr ); } WPGetAsmLoc( wpasm_file, rows, &asm_group, &asm_row ); wpasm_file->asm_data[asm_group].asm_lines = ProfRealloc( wpasm_file->asm_data[asm_group].asm_lines, sizeof(wp_asmline)*(asm_row+1) ); wpasm_file->asm_rows = rows; return( wpasm_file ); }