diff --git a/source/tvision/tchdrdlg.cpp b/source/tvision/tchdrdlg.cpp index a3b3a44b..f14b95bf 100644 --- a/source/tvision/tchdrdlg.cpp +++ b/source/tvision/tchdrdlg.cpp @@ -88,7 +88,11 @@ void TChDirDialog::getData( void * ) { } -#define isSeparator(c) (c == '\\' || c == '/') +#ifndef _TV_UNIX + #define isSeparator(c) (c == '\\' || c == '/') +#else + #define isSeparator(c) (c == '/') +#endif static void trimEndSeparator(char *path) { @@ -114,6 +118,7 @@ void TChDirDialog::handleEvent( TEvent& event ) { TDirEntry *p = dirList->list()->at( dirList->focused ); strcpy( curDir, p->dir() ); +#ifndef _TV_UNIX if( strcmp( curDir, drivesText ) == 0 ) break; else if( driveValid( curDir[0] ) ) @@ -124,6 +129,16 @@ void TChDirDialog::handleEvent( TEvent& event ) } else return; +#else + if ( strcmp( curDir, "/" ) == 0 ) + break; + else + { + int len = strlen( curDir ); + if( !isSeparator(curDir[len - 1]) ) + strcat(curDir, "/"); + } +#endif break; } default: @@ -163,8 +178,10 @@ void TChDirDialog::setUpDialog() static int changeDir( const char *path ) { +#ifndef _TV_UNIX if( path[1] == ':' ) setdisk( toupper(path[0]) - 'A' ); +#endif return chdir( path ); } diff --git a/source/tvision/tdircoll.cpp b/source/tvision/tdircoll.cpp index 00204e86..b73a6fb2 100644 --- a/source/tvision/tdircoll.cpp +++ b/source/tvision/tdircoll.cpp @@ -76,7 +76,11 @@ Boolean isDir( const char *str ) noexcept (ff.ff_attrib & FA_DIREC) != 0 ); } -#define isSeparator(c) (c == '\\' || c == '/') +#ifndef _TV_UNIX + #define isSeparator(c) (c == '\\' || c == '/') +#else + #define isSeparator(c) (c == '/') +#endif Boolean pathValid( const char *path ) noexcept { @@ -124,6 +128,7 @@ Boolean validFileName( const char *fileName ) noexcept void getCurDir( char *dir, char drive ) noexcept { +#ifndef _TV_UNIX dir[0] = (char) ((0 <= drive && drive <= 'Z' - 'A' ? drive : getdisk()) + 'A'); dir[1] = ':'; dir[2] = '\\'; @@ -131,6 +136,10 @@ void getCurDir( char *dir, char drive ) noexcept getcurdir( dir[0] - 'A' + 1, dir+3 ); if( strlen( dir ) > 3 ) strnzcat( dir, "\\", MAXPATH ); +#else + getcwd( dir, MAXPATH ); + strnzcat( dir, "/", MAXPATH ); +#endif } Boolean isWild( const char *f ) noexcept diff --git a/source/tvision/tdirlist.cpp b/source/tvision/tdirlist.cpp index 9133d2e8..9f088caf 100644 --- a/source/tvision/tdirlist.cpp +++ b/source/tvision/tdirlist.cpp @@ -78,6 +78,7 @@ Boolean TDirListBox::isSelected( short item ) void TDirListBox::showDrives( TDirCollection *dirs ) { +#ifndef _TV_UNIX Boolean isFirst = True; char oldc[5]; strcpy( oldc, "0:\\" ); @@ -116,6 +117,7 @@ void TDirListBox::showDrives( TDirCollection *dirs ) s[ strlen(lastDir)+1 ] = EOS; dirs->insert( new TDirEntry( s, oldc ) ); } +#endif } void TDirListBox::showDirs( TDirCollection *dirs ) @@ -131,32 +133,50 @@ void TDirListBox::showDirs( TDirCollection *dirs ) strcpy( org, pathDir ); char *curDir = dir; +#ifndef _TV_UNIX char *end = dir + 3; + const char sepChar = '\\'; + char hold = *end; *end = EOS; // mark end of drive name strcpy( name, curDir ); dirs->insert( new TDirEntry( org, name ) ); *end = hold; // restore full path +#else + char *end = dir + 1; + const char sepChar = '/'; + indent = 0; +#endif curDir = end; - while( (end = strchr( curDir, '\\' )) != 0 ) + while( (end = strchr( curDir, sepChar )) != 0 ) { *end = EOS; strncpy( name, curDir, size_t(end-curDir) ); name[size_t(end-curDir)] = EOS; dirs->insert( new TDirEntry( org - indent, dir ) ); - *end = '\\'; + *end = sepChar; curDir = end+1; indent += indentSize; } cur = dirs->getCount() - 1; - end = strrchr( dir, '\\' ); + end = strrchr( dir, sepChar ); + if ( end == NULL ) + { + // no separators found so just bail. + // fixes segfault if no separators found (eg Linux path on Windows or vice versa) + return; + } char path[MAXPATH]; strncpy( path, dir, size_t(end-dir+1) ); end = path + unsigned(end-dir)+1; +#ifndef _TV_UNIX strcpy( end, "*.*" ); +#else + strcpy( end, "*" ); +#endif Boolean isFirst = True; ffblk ff; @@ -198,11 +218,16 @@ void TDirListBox::newDirectory( TStringView str ) { strnzcpy( dir, str, sizeof(dir) ); TDirCollection *dirs = new TDirCollection( 5, 5 ); +#ifndef _TV_UNIX dirs->insert( new TDirEntry( drives, drives ) ); if( str == drives ) showDrives( dirs ); else showDirs( dirs ); +#else + dirs->insert( new TDirEntry( "/", "/" ) ); + showDirs( dirs ); +#endif newList( dirs ); focusItem( cur ); }