1
0
Fork 0

Warnings and style.

Imported-from: https://svn.code.sf.net/p/dosbox/code-0/dosbox/trunk@3346
This commit is contained in:
Peter Veenstra 2009-04-16 12:28:30 +00:00
parent 92c5771c4d
commit c3af6d2420
4 changed files with 135 additions and 177 deletions

View file

@ -30,22 +30,19 @@
#include "support.h"
#include "cdrom.h"
CDROM_Interface_SDL::CDROM_Interface_SDL(void)
{
CDROM_Interface_SDL::CDROM_Interface_SDL(void) {
driveID = 0;
oldLeadOut = 0;
cd = 0;
};
}
CDROM_Interface_SDL::~CDROM_Interface_SDL(void)
{
CDROM_Interface_SDL::~CDROM_Interface_SDL(void) {
StopAudio();
SDL_CDClose(cd);
cd = 0;
};
}
bool CDROM_Interface_SDL::SetDevice (char* path, int forceCD)
{
bool CDROM_Interface_SDL::SetDevice(char* path, int forceCD) {
char buffer[512];
strcpy(buffer,path);
upcase(buffer);
@ -69,10 +66,9 @@ bool CDROM_Interface_SDL::SetDevice (char* path, int forceCD)
};
};
return false;
};
}
bool CDROM_Interface_SDL::GetAudioTracks (int& stTrack, int& end, TMSF& leadOut)
{
bool CDROM_Interface_SDL::GetAudioTracks(int& stTrack, int& end, TMSF& leadOut) {
if (CD_INDRIVE(SDL_CDStatus(cd))) {
stTrack = 1;
@ -80,19 +76,17 @@ bool CDROM_Interface_SDL::GetAudioTracks (int& stTrack, int& end, TMSF& leadOut)
FRAMES_TO_MSF(cd->track[cd->numtracks].offset,&leadOut.min,&leadOut.sec,&leadOut.fr);
}
return CD_INDRIVE(SDL_CDStatus(cd));
};
}
bool CDROM_Interface_SDL::GetAudioTrackInfo (int track, TMSF& start, unsigned char& attr)
{
bool CDROM_Interface_SDL::GetAudioTrackInfo(int track, TMSF& start, unsigned char& attr) {
if (CD_INDRIVE(SDL_CDStatus(cd))) {
FRAMES_TO_MSF(cd->track[track-1].offset,&start.min,&start.sec,&start.fr);
attr = cd->track[track-1].type<<4;//sdl uses 0 for audio and 4 for data. instead of 0x00 and 0x40
}
return CD_INDRIVE(SDL_CDStatus(cd));
};
}
bool CDROM_Interface_SDL::GetAudioSub (unsigned char& attr, unsigned char& track, unsigned char& index, TMSF& relPos, TMSF& absPos)
{
bool CDROM_Interface_SDL::GetAudioSub(unsigned char& attr, unsigned char& track, unsigned char& index, TMSF& relPos, TMSF& absPos) {
if (CD_INDRIVE(SDL_CDStatus(cd))) {
track = cd->cur_track;
index = cd->cur_track;
@ -101,19 +95,17 @@ bool CDROM_Interface_SDL::GetAudioSub (unsigned char& attr, unsigned char& track
FRAMES_TO_MSF(cd->cur_frame+cd->track[track].offset,&absPos.min,&absPos.sec,&absPos.fr);
}
return CD_INDRIVE(SDL_CDStatus(cd));
};
}
bool CDROM_Interface_SDL::GetAudioStatus (bool& playing, bool& pause)
{
bool CDROM_Interface_SDL::GetAudioStatus(bool& playing, bool& pause){
if (CD_INDRIVE(SDL_CDStatus(cd))) {
playing = (cd->status==CD_PLAYING);
pause = (cd->status==CD_PAUSED);
}
return CD_INDRIVE(SDL_CDStatus(cd));
};
}
bool CDROM_Interface_SDL::GetMediaTrayStatus (bool& mediaPresent, bool& mediaChanged, bool& trayOpen)
{
bool CDROM_Interface_SDL::GetMediaTrayStatus(bool& mediaPresent, bool& mediaChanged, bool& trayOpen) {
SDL_CDStatus(cd);
mediaPresent = (cd->status!=CD_TRAYEMPTY) && (cd->status!=CD_ERROR);
mediaChanged = (oldLeadOut!=cd->track[cd->numtracks].offset);
@ -121,45 +113,40 @@ bool CDROM_Interface_SDL::GetMediaTrayStatus (bool& mediaPresent, bool& mediaCha
oldLeadOut = cd->track[cd->numtracks].offset;
if (mediaChanged) SDL_CDStatus(cd);
return true;
};
}
bool CDROM_Interface_SDL::PlayAudioSector (unsigned long start,unsigned long len)
{
bool CDROM_Interface_SDL::PlayAudioSector(unsigned long start,unsigned long len) {
// Has to be there, otherwise wrong cd status report (dunno why, sdl bug ?)
SDL_CDClose(cd);
cd = SDL_CDOpen(driveID);
bool success = (SDL_CDPlay(cd,start+150,len)==0);
return success;
};
}
bool CDROM_Interface_SDL::PauseAudio (bool resume)
{
bool CDROM_Interface_SDL::PauseAudio(bool resume) {
bool success;
if (resume) success = (SDL_CDResume(cd)==0);
else success = (SDL_CDPause (cd)==0);
return success;
};
}
bool CDROM_Interface_SDL::StopAudio (void)
{
bool CDROM_Interface_SDL::StopAudio(void) {
// Has to be there, otherwise wrong cd status report (dunno why, sdl bug ?)
SDL_CDClose(cd);
cd = SDL_CDOpen(driveID);
bool success = (SDL_CDStop(cd)==0);
return success;
};
}
bool CDROM_Interface_SDL::LoadUnloadMedia(bool unload)
{
bool CDROM_Interface_SDL::LoadUnloadMedia(bool unload) {
bool success = (SDL_CDEject(cd)==0);
return success;
};
}
int CDROM_GetMountType(char* path, int forceCD)
int CDROM_GetMountType(char* path, int forceCD) {
// 0 - physical CDROM
// 1 - Iso file
// 2 - subdirectory
{
// 1. Smells like a real cdrom
// if ((strlen(path)<=3) && (path[2]=='\\') && (strchr(path,'\\')==strrchr(path,'\\')) && (GetDriveType(path)==DRIVE_CDROM)) return 0;
@ -187,31 +174,28 @@ int CDROM_GetMountType(char* path, int forceCD)
struct stat file_stat;
if ((stat(path, &file_stat) == 0) && S_ISREG(file_stat.st_mode)) return 1;
return 2;
};
}
// ******************************************************
// Fake CDROM
// ******************************************************
bool CDROM_Interface_Fake :: GetAudioTracks (int& stTrack, int& end, TMSF& leadOut)
{
bool CDROM_Interface_Fake :: GetAudioTracks(int& stTrack, int& end, TMSF& leadOut) {
stTrack = end = 1;
leadOut.min = 60;
leadOut.sec = leadOut.fr = 0;
return true;
};
}
bool CDROM_Interface_Fake :: GetAudioTrackInfo (int track, TMSF& start, unsigned char& attr)
{
bool CDROM_Interface_Fake :: GetAudioTrackInfo(int track, TMSF& start, unsigned char& attr) {
if (track>1) return false;
start.min = start.fr = 0;
start.sec = 2;
attr = 0x60; // data / permitted
return true;
};
}
bool CDROM_Interface_Fake :: GetAudioSub (unsigned char& attr, unsigned char& track, unsigned char& index, TMSF& relPos, TMSF& absPos)
{
bool CDROM_Interface_Fake :: GetAudioSub(unsigned char& attr, unsigned char& track, unsigned char& index, TMSF& relPos, TMSF& absPos){
attr = 0;
track = index = 1;
relPos.min = relPos.fr = 0; relPos.sec = 2;
@ -219,18 +203,16 @@ bool CDROM_Interface_Fake :: GetAudioSub (unsigned char& attr, unsigned char& tr
return true;
}
bool CDROM_Interface_Fake :: GetAudioStatus (bool& playing, bool& pause)
{
bool CDROM_Interface_Fake :: GetAudioStatus(bool& playing, bool& pause) {
playing = pause = false;
return true;
}
bool CDROM_Interface_Fake :: GetMediaTrayStatus (bool& mediaPresent, bool& mediaChanged, bool& trayOpen)
{
bool CDROM_Interface_Fake :: GetMediaTrayStatus(bool& mediaPresent, bool& mediaChanged, bool& trayOpen) {
mediaPresent = true;
mediaChanged = false;
trayOpen = false;
trayOpen = false;
return true;
};
}

View file

@ -16,7 +16,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/* $Id: dos_mscdex.cpp,v 1.58 2009-03-01 15:40:30 c2woody Exp $ */
/* $Id: dos_mscdex.cpp,v 1.59 2009-04-16 12:28:30 qbix79 Exp $ */
#include <string.h>
#include <ctype.h>
@ -54,8 +54,7 @@ int forceCD = -1;
static Bitu MSCDEX_Strategy_Handler(void);
static Bitu MSCDEX_Interrupt_Handler(void);
class DOS_DeviceHeader:public MemStruct
{
class DOS_DeviceHeader:public MemStruct {
public:
DOS_DeviceHeader(PhysPt ptr) { pt = ptr; };
@ -88,8 +87,7 @@ public:
#endif
};
class CMscdex
{
class CMscdex {
public:
CMscdex (void);
~CMscdex (void);
@ -170,7 +168,7 @@ CMscdex::CMscdex(void) {
memset(dinfo,0,sizeof(dinfo));
for (Bit32u i=0; i<MSCDEX_MAX_DRIVES; i++) cdrom[i] = 0;
};
}
CMscdex::~CMscdex(void) {
defaultBufSeg = 0;
@ -178,26 +176,26 @@ CMscdex::~CMscdex(void) {
delete (cdrom)[i];
cdrom[i] = 0;
};
};
}
void CMscdex::GetDrives(PhysPt data)
{
for (Bit16u i=0; i<GetNumDrives(); i++) mem_writeb(data+i,dinfo[i].drive);
};
}
bool CMscdex::IsValidDrive(Bit16u _drive)
{
_drive &= 0xff; //Only lowerpart (Ultimate domain)
for (Bit16u i=0; i<GetNumDrives(); i++) if (dinfo[i].drive==_drive) return true;
return false;
};
}
Bit8u CMscdex::GetSubUnit(Bit16u _drive)
{
_drive &= 0xff; //Only lowerpart (Ultimate domain)
for (Bit16u i=0; i<GetNumDrives(); i++) if (dinfo[i].drive==_drive) return (Bit8u)i;
return 0xff;
};
}
int CMscdex::RemoveDrive(Bit16u _drive)
{
@ -391,7 +389,7 @@ int CMscdex::AddDrive(Bit16u _drive, char* physicalPath, Bit8u& subUnit)
// stop audio
StopAudio(subUnit);
return result;
};
}
bool CMscdex::HasDrive(Bit16u drive) {
return (GetSubUnit(drive) != 0xff);
@ -409,7 +407,7 @@ PhysPt CMscdex::GetDefaultBuffer(void) {
defaultBufSeg = DOS_GetMemory(size);
};
return PhysMake(defaultBufSeg,2352);
};
}
PhysPt CMscdex::GetTempBuffer(void) {
if (defaultBufSeg==0) {
@ -417,7 +415,7 @@ PhysPt CMscdex::GetTempBuffer(void) {
defaultBufSeg = DOS_GetMemory(size);
};
return PhysMake(defaultBufSeg,0);
};
}
void CMscdex::GetDriverInfo (PhysPt data) {
for (Bit16u i=0; i<GetNumDrives(); i++) {
@ -425,7 +423,7 @@ void CMscdex::GetDriverInfo (PhysPt data) {
mem_writed(data+1,RealMake(rootDriverHeaderSeg,0));
data+=5;
};
};
}
bool CMscdex::GetCDInfo(Bit8u subUnit, Bit8u& tr1, Bit8u& tr2, TMSF& leadOut)
{
@ -453,7 +451,7 @@ bool CMscdex::GetTrackInfo(Bit8u subUnit, Bit8u track, Bit8u& attr, TMSF& start)
memset(&start,0,sizeof(start));
};
return dinfo[subUnit].lastResult;
};
}
bool CMscdex::PlayAudioSector(Bit8u subUnit, Bit32u sector, Bit32u length)
{
@ -472,7 +470,7 @@ bool CMscdex::PlayAudioSector(Bit8u subUnit, Bit32u sector, Bit32u length)
dinfo[subUnit].audioEnd = length;
};
return dinfo[subUnit].lastResult;
};
}
bool CMscdex::PlayAudioMSF(Bit8u subUnit, Bit32u start, Bit32u length)
{
@ -482,7 +480,7 @@ bool CMscdex::PlayAudioMSF(Bit8u subUnit, Bit32u start, Bit32u length)
Bit8u fr = (Bit8u)(start>> 0) & 0xFF;
Bit32u sector = min*60*75+sec*75+fr - 150;
return dinfo[subUnit].lastResult = PlayAudioSector(subUnit,sector,length);
};
}
bool CMscdex::GetSubChannelData(Bit8u subUnit, Bit8u& attr, Bit8u& track, Bit8u &index, TMSF& rel, TMSF& abs)
{
@ -494,7 +492,7 @@ bool CMscdex::GetSubChannelData(Bit8u subUnit, Bit8u& attr, Bit8u& track, Bit8u
memset(&abs,0,sizeof(abs));
};
return dinfo[subUnit].lastResult;
};
}
bool CMscdex::GetAudioStatus(Bit8u subUnit, bool& playing, bool& pause, TMSF& start, TMSF& end)
{
@ -519,7 +517,7 @@ bool CMscdex::GetAudioStatus(Bit8u subUnit, bool& playing, bool& pause, TMSF& st
};
return dinfo[subUnit].lastResult;
};
}
bool CMscdex::StopAudio(Bit8u subUnit)
{
@ -541,13 +539,13 @@ bool CMscdex::StopAudio(Bit8u subUnit)
dinfo[subUnit].audioPlay = false;
};
return dinfo[subUnit].lastResult;
};
}
bool CMscdex::ResumeAudio(Bit8u subUnit)
{
if (subUnit>=numDrives) return false;
return dinfo[subUnit].lastResult = PlayAudioSector(subUnit,dinfo[subUnit].audioStart,dinfo[subUnit].audioEnd);
};
}
Bit32u CMscdex::GetVolumeSize(Bit8u subUnit)
{
@ -557,7 +555,7 @@ Bit32u CMscdex::GetVolumeSize(Bit8u subUnit)
dinfo[subUnit].lastResult = GetCDInfo(subUnit,tr1,tr2,leadOut);
if (dinfo[subUnit].lastResult) return (leadOut.min*60*75)+(leadOut.sec*75)+leadOut.fr;
return 0;
};
}
bool CMscdex::ReadVTOC(Bit16u drive, Bit16u volume, PhysPt data, Bit16u& error)
{
@ -574,7 +572,7 @@ bool CMscdex::ReadVTOC(Bit16u drive, Bit16u volume, PhysPt data, Bit16u& error)
Bit8u type = mem_readb(data);
error = (type == 1) ? 1 : (type == 0xFF) ? 0xFF : 0;
return true;
};
}
bool CMscdex::GetVolumeName(Bit8u subUnit, char* data) {
if (subUnit>=numDrives) return false;
@ -591,7 +589,7 @@ bool CMscdex::GetVolumeName(Bit8u subUnit, char* data) {
};
return success;
};
}
bool CMscdex::GetCopyrightName(Bit16u drive, PhysPt data) {
Bit16u error;
@ -603,7 +601,7 @@ bool CMscdex::GetCopyrightName(Bit16u drive, PhysPt data) {
mem_writeb(data+37,0);
};
return success;
};
}
bool CMscdex::GetAbstractName(Bit16u drive, PhysPt data) {
Bit16u error;
@ -615,7 +613,7 @@ bool CMscdex::GetAbstractName(Bit16u drive, PhysPt data) {
mem_writeb(data+37,0);
};
return success;
};
}
bool CMscdex::GetDocumentationName(Bit16u drive, PhysPt data) {
Bit16u error;
@ -627,13 +625,13 @@ bool CMscdex::GetDocumentationName(Bit16u drive, PhysPt data) {
mem_writeb(data+37,0);
};
return success;
};
}
bool CMscdex::GetUPC(Bit8u subUnit, Bit8u& attr, char* upc)
{
if (subUnit>=numDrives) return false;
return dinfo[subUnit].lastResult = cdrom[subUnit]->GetUPC(attr,&upc[0]);
};
}
bool CMscdex::ReadSectors(Bit8u subUnit, bool raw, Bit32u sector, Bit16u num, PhysPt data) {
if (subUnit>=numDrives) return false;
@ -641,7 +639,7 @@ bool CMscdex::ReadSectors(Bit8u subUnit, bool raw, Bit32u sector, Bit16u num, Ph
else CPU_Cycles = 5;
dinfo[subUnit].lastResult = cdrom[subUnit]->ReadSectors(data,raw,sector,num);
return dinfo[subUnit].lastResult;
};
}
bool CMscdex::ReadSectorsMSF(Bit8u subUnit, bool raw, Bit32u start, Bit16u num, PhysPt data) {
if (subUnit>=numDrives) return false;
@ -650,12 +648,12 @@ bool CMscdex::ReadSectorsMSF(Bit8u subUnit, bool raw, Bit32u start, Bit16u num,
Bit8u fr = (Bit8u)(start>> 0) & 0xFF;
Bit32u sector = min*60*75+sec*75+fr - 150;
return ReadSectors(subUnit,raw,sector,num,data);
};
}
// Called from INT 2F
bool CMscdex::ReadSectors(Bit16u drive, Bit32u sector, Bit16u num, PhysPt data) {
return ReadSectors(GetSubUnit(drive),false,sector,num,data);
};
}
bool CMscdex::GetDirectoryEntry(Bit16u drive, bool copyFlag, PhysPt pathname, PhysPt buffer, Bit16u& error)
{
@ -766,7 +764,7 @@ bool CMscdex::GetDirectoryEntry(Bit16u drive, bool copyFlag, PhysPt pathname, Ph
};
error = 2; // file not found
return false; // not found
};
}
bool CMscdex::GetCurrentPos(Bit8u subUnit, TMSF& pos)
{
@ -776,14 +774,14 @@ bool CMscdex::GetCurrentPos(Bit8u subUnit, TMSF& pos)
dinfo[subUnit].lastResult = GetSubChannelData(subUnit, attr, track, index, rel, pos);
if (!dinfo[subUnit].lastResult) memset(&pos,0,sizeof(pos));
return dinfo[subUnit].lastResult;
};
}
bool CMscdex::GetMediaStatus(Bit8u subUnit, bool& media, bool& changed, bool& trayOpen)
{
if (subUnit>=numDrives) return false;
dinfo[subUnit].lastResult = cdrom[subUnit]->GetMediaTrayStatus(media,changed,trayOpen);
return dinfo[subUnit].lastResult;
};
}
Bit32u CMscdex::GetDeviceStatus(Bit8u subUnit)
{
@ -798,7 +796,7 @@ Bit32u CMscdex::GetDeviceStatus(Bit8u subUnit)
(1<<9) | // Red book & HSG
((!media) << 11); // Drive is empty ?
return status;
};
}
bool CMscdex::GetMediaStatus(Bit8u subUnit, Bit8u& status)
{
@ -809,14 +807,14 @@ bool CMscdex::GetMediaStatus(Bit8u subUnit, Bit8u& status)
return result; */
status = getSwapRequest() ? 0xFF : 0x01;
return true;
};
}
bool CMscdex::LoadUnloadMedia(Bit8u subUnit, bool unload)
{
if (subUnit>=numDrives) return false;
dinfo[subUnit].lastResult = cdrom[subUnit]->LoadUnloadMedia(unload);
return dinfo[subUnit].lastResult;
};
}
bool CMscdex::SendDriverRequest(Bit16u drive, PhysPt data)
{
@ -828,7 +826,7 @@ bool CMscdex::SendDriverRequest(Bit16u drive, PhysPt data)
MSCDEX_Strategy_Handler();
MSCDEX_Interrupt_Handler();
return true;
};
}
Bit16u CMscdex::GetStatusWord(Bit8u subUnit,Bit16u status)
{
@ -850,14 +848,14 @@ Bit16u CMscdex::GetStatusWord(Bit8u subUnit,Bit16u status)
}
dinfo[subUnit].lastResult = true;
return status;
};
}
void CMscdex::InitNewMedia(Bit8u subUnit) {
if (subUnit<numDrives) {
// Reopen new media
cdrom[subUnit]->InitNewMedia();
}
};
}
static CMscdex* mscdex = 0;
static PhysPt curReqheaderPtr = 0;
@ -1177,7 +1175,7 @@ static bool MSCDEX_Handler(void) {
};
LOG(LOG_MISC,LOG_ERROR)("MSCDEX: Unknwon call : %04X",reg_ax);
return true;
};
}
class device_MSCDEX : public DOS_Device {
public:
@ -1216,28 +1214,28 @@ int MSCDEX_AddDrive(char driveLetter, const char* physicalPath, Bit8u& subUnit)
{
int result = mscdex->AddDrive(driveLetter-'A',(char*)physicalPath,subUnit);
return result;
};
}
int MSCDEX_RemoveDrive(char driveLetter)
{
if(!mscdex) return 0;
return mscdex->RemoveDrive(driveLetter-'A');
};
}
bool MSCDEX_HasDrive(char driveLetter)
{
return mscdex->HasDrive(driveLetter-'A');
};
}
void MSCDEX_ReplaceDrive(CDROM_Interface* cdrom, Bit8u subUnit)
{
mscdex->ReplaceDrive(cdrom, subUnit);
};
}
bool MSCDEX_GetVolumeName(Bit8u subUnit, char* name)
{
return mscdex->GetVolumeName(subUnit,name);
};
}
bool MSCDEX_HasMediaChanged(Bit8u subUnit)
{
@ -1261,20 +1259,20 @@ bool MSCDEX_HasMediaChanged(Bit8u subUnit)
leadOut[subUnit].fr = 0;
}
return true;
};
}
void MSCDEX_SetCDInterface(int intNr, int numCD)
{
useCdromInterface = intNr;
forceCD = numCD;
};
}
void MSCDEX_ShutDown(Section* sec)
{
delete mscdex;
mscdex = 0;
curReqheaderPtr = 0;
};
}
void MSCDEX_Init(Section* sec)
{
@ -1288,4 +1286,4 @@ void MSCDEX_Init(Section* sec)
DOS_AddMultiplexHandler(MSCDEX_Handler);
/* Create MSCDEX */
mscdex = new CMscdex;
};
}

View file

@ -16,7 +16,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/* $Id: dos_programs.cpp,v 1.92 2009-03-29 09:34:18 c2woody Exp $ */
/* $Id: dos_programs.cpp,v 1.93 2009-04-16 12:28:30 qbix79 Exp $ */
#include "dosbox.h"
#include <stdlib.h>
@ -889,7 +889,7 @@ void LOADFIX::Run(void)
} else {
WriteOut(MSG_Get("PROGRAM_LOADFIX_ERROR"),kb);
}
};
}
static void LOADFIX_ProgramStart(Program * * make) {
*make=new LOADFIX;
@ -910,7 +910,7 @@ void RESCAN::Run(void)
Drives[drive]->EmptyCache();
WriteOut(MSG_Get("PROGRAM_RESCAN_SUCCESS"));
}
};
}
static void RESCAN_ProgramStart(Program * * make) {
*make=new RESCAN;
@ -1330,7 +1330,7 @@ void KEYB::Run(void) {
WriteOut(MSG_Get("PROGRAM_KEYB_INFO_LAYOUT"),dos.loaded_codepage,layout_name);
}
}
};
}
static void KEYB_ProgramStart(Program * * make) {
*make=new KEYB;

View file

@ -16,7 +16,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/* $Id: drive_cache.cpp,v 1.58 2009-03-04 21:08:22 c2woody Exp $ */
/* $Id: drive_cache.cpp,v 1.59 2009-04-16 12:28:30 qbix79 Exp $ */
#include "drives.h"
#include "dos_inc.h"
@ -41,32 +41,27 @@
int fileInfoCounter = 0;
bool SortByName(DOS_Drive_Cache::CFileInfo* const &a, DOS_Drive_Cache::CFileInfo* const &b)
{
bool SortByName(DOS_Drive_Cache::CFileInfo* const &a, DOS_Drive_Cache::CFileInfo* const &b) {
return strcmp(a->shortname,b->shortname)<0;
};
}
bool SortByNameRev(DOS_Drive_Cache::CFileInfo* const &a, DOS_Drive_Cache::CFileInfo* const &b)
{
bool SortByNameRev(DOS_Drive_Cache::CFileInfo* const &a, DOS_Drive_Cache::CFileInfo* const &b) {
return strcmp(a->shortname,b->shortname)>0;
};
}
bool SortByDirName(DOS_Drive_Cache::CFileInfo* const &a, DOS_Drive_Cache::CFileInfo* const &b)
{
bool SortByDirName(DOS_Drive_Cache::CFileInfo* const &a, DOS_Drive_Cache::CFileInfo* const &b) {
// Directories first...
if (a->isDir!=b->isDir) return (a->isDir>b->isDir);
return strcmp(a->shortname,b->shortname)<0;
};
}
bool SortByDirNameRev(DOS_Drive_Cache::CFileInfo* const &a, DOS_Drive_Cache::CFileInfo* const &b)
{
bool SortByDirNameRev(DOS_Drive_Cache::CFileInfo* const &a, DOS_Drive_Cache::CFileInfo* const &b) {
// Directories first...
if (a->isDir!=b->isDir) return (a->isDir>b->isDir);
return strcmp(a->shortname,b->shortname)>0;
};
}
DOS_Drive_Cache::DOS_Drive_Cache(void)
{
DOS_Drive_Cache::DOS_Drive_Cache(void) {
dirBase = new CFileInfo;
save_dir = 0;
srchNr = 0;
@ -75,10 +70,9 @@ DOS_Drive_Cache::DOS_Drive_Cache(void)
for (Bit32u i=0; i<MAX_OPENDIRS; i++) { dirSearch[i] = 0; free[i] = true; dirFindFirst[i] = 0; };
SetDirSort(DIRALPHABETICAL);
updatelabel = true;
};
}
DOS_Drive_Cache::DOS_Drive_Cache(const char* path)
{
DOS_Drive_Cache::DOS_Drive_Cache(const char* path) {
dirBase = new CFileInfo;
save_dir = 0;
srchNr = 0;
@ -88,23 +82,20 @@ DOS_Drive_Cache::DOS_Drive_Cache(const char* path)
SetDirSort(DIRALPHABETICAL);
SetBaseDir(path);
updatelabel = true;
};
}
DOS_Drive_Cache::~DOS_Drive_Cache(void)
{
DOS_Drive_Cache::~DOS_Drive_Cache(void) {
Clear();
for (Bit32u i=0; i<MAX_OPENDIRS; i++) { delete dirFindFirst[i]; dirFindFirst[i]=0; };
};
}
void DOS_Drive_Cache::Clear(void)
{
void DOS_Drive_Cache::Clear(void) {
delete dirBase; dirBase = 0;
nextFreeFindFirst = 0;
for (Bit32u i=0; i<MAX_OPENDIRS; i++) dirSearch[i] = 0;
};
}
void DOS_Drive_Cache::EmptyCache(void)
{
void DOS_Drive_Cache::EmptyCache(void) {
// Empty Cache and reinit
Clear();
dirBase = new CFileInfo;
@ -112,10 +103,9 @@ void DOS_Drive_Cache::EmptyCache(void)
srchNr = 0;
for (Bit32u i=0; i<MAX_OPENDIRS; i++) free[i] = true;
SetBaseDir(basePath);
};
}
void DOS_Drive_Cache::SetLabel(const char* vname,bool cdrom,bool allowupdate)
{
void DOS_Drive_Cache::SetLabel(const char* vname,bool cdrom,bool allowupdate) {
/* allowupdate defaults to true. if mount sets a label then allowupdate is
* false and will this function return at once after the first call.
* The label will be set at the first call. */
@ -124,17 +114,15 @@ void DOS_Drive_Cache::SetLabel(const char* vname,bool cdrom,bool allowupdate)
this->updatelabel = allowupdate;
Set_Label(vname,label,cdrom);
LOG(LOG_DOSMISC,LOG_NORMAL)("DIRCACHE: Set volume label to %s",label);
};
}
Bit16u DOS_Drive_Cache::GetFreeID(CFileInfo* dir)
{
Bit16u DOS_Drive_Cache::GetFreeID(CFileInfo* dir) {
for (Bit16u i=0; i<MAX_OPENDIRS; i++) if (free[i] || (dir==dirSearch[i])) return i;
LOG(LOG_FILES,LOG_NORMAL)("DIRCACHE: Too many open directories!");
return 0;
};
}
void DOS_Drive_Cache::SetBaseDir(const char* baseDir)
{
void DOS_Drive_Cache::SetBaseDir(const char* baseDir) {
Bit16u id;
strcpy(basePath,baseDir);
if (OpenDir(baseDir,id)) {
@ -165,15 +153,13 @@ void DOS_Drive_Cache::SetBaseDir(const char* baseDir)
SetLabel(labellocal,cdrom,true);
}
#endif
};
}
void DOS_Drive_Cache::ExpandName(char* path)
{
void DOS_Drive_Cache::ExpandName(char* path) {
strcpy(path,GetExpandName(path));
};
}
char* DOS_Drive_Cache::GetExpandName(const char* path)
{
char* DOS_Drive_Cache::GetExpandName(const char* path) {
static char work [CROSS_LEN] = { 0 };
char dir [CROSS_LEN];
@ -203,7 +189,7 @@ char* DOS_Drive_Cache::GetExpandName(const char* path)
}
}
return work;
};
}
void DOS_Drive_Cache::AddEntry(const char* path, bool checkExists) {
// Get Last part...
@ -237,8 +223,7 @@ void DOS_Drive_Cache::AddEntry(const char* path, bool checkExists) {
}
}
void DOS_Drive_Cache::DeleteEntry(const char* path, bool ignoreLastDir)
{
void DOS_Drive_Cache::DeleteEntry(const char* path, bool ignoreLastDir) {
CacheOut(path,ignoreLastDir);
if (dirSearch[srchNr] && (dirSearch[srchNr]->nextEntry>0)) dirSearch[srchNr]->nextEntry--;
@ -252,7 +237,7 @@ void DOS_Drive_Cache::DeleteEntry(const char* path, bool ignoreLastDir)
dirSearch[i]->nextEntry--;
}
}
};
}
void DOS_Drive_Cache::CacheOut(const char* path, bool ignoreLastDir) {
char expand[CROSS_LEN] = { 0 };
@ -285,10 +270,9 @@ void DOS_Drive_Cache::CacheOut(const char* path, bool ignoreLastDir) {
save_dir = 0;
}
bool DOS_Drive_Cache::IsCachedIn(CFileInfo* curDir)
{
bool DOS_Drive_Cache::IsCachedIn(CFileInfo* curDir) {
return (curDir->fileList.size()>0);
};
}
bool DOS_Drive_Cache::GetShortName(const char* fullname, char* shortname) {
@ -314,10 +298,9 @@ bool DOS_Drive_Cache::GetShortName(const char* fullname, char* shortname) {
};
}
return false;
};
}
int DOS_Drive_Cache::CompareShortname(const char* compareName, const char* shortName)
{
int DOS_Drive_Cache::CompareShortname(const char* compareName, const char* shortName) {
char const* cpos = strchr(shortName,'~');
if (cpos) {
/* the following code is replaced as it's not safe when char* is 64 bits */
@ -346,7 +329,7 @@ int DOS_Drive_Cache::CompareShortname(const char* compareName, const char* short
return strncmp(compareName,shortName,compareCount1);
}
return strcmp(compareName,shortName);
};
}
Bitu DOS_Drive_Cache::CreateShortNameID(CFileInfo* curDir, const char* name) {
std::vector<CFileInfo*>::size_type filelist_size = curDir->longNameList.size();
@ -373,11 +356,10 @@ Bitu DOS_Drive_Cache::CreateShortNameID(CFileInfo* curDir, const char* name) {
};
}
return foundNr+1;
};
}
bool DOS_Drive_Cache::RemoveTrailingDot(char* shortname)
bool DOS_Drive_Cache::RemoveTrailingDot(char* shortname) {
// remove trailing '.' if no extension is available (Linux compatibility)
{
size_t len = strlen(shortname);
if (len && (shortname[len-1]=='.')) {
if (len==1) return false;
@ -386,10 +368,9 @@ bool DOS_Drive_Cache::RemoveTrailingDot(char* shortname)
return true;
}
return false;
};
}
Bits DOS_Drive_Cache::GetLongName(CFileInfo* curDir, char* shortName)
{
Bits DOS_Drive_Cache::GetLongName(CFileInfo* curDir, char* shortName) {
std::vector<CFileInfo*>::size_type filelist_size = curDir->fileList.size();
if (GCC_UNLIKELY(filelist_size<=0)) return -1;
@ -411,11 +392,10 @@ Bits DOS_Drive_Cache::GetLongName(CFileInfo* curDir, char* shortName)
}
// not available
return -1;
};
}
bool DOS_Drive_Cache::RemoveSpaces(char* str)
bool DOS_Drive_Cache::RemoveSpaces(char* str) {
// Removes all spaces
{
char* curpos = str;
char* chkpos = str;
while (*chkpos!=0) {
@ -423,7 +403,7 @@ bool DOS_Drive_Cache::RemoveSpaces(char* str)
}
*curpos = 0;
return (curpos!=chkpos);
};
}
void DOS_Drive_Cache::CreateShortName(CFileInfo* curDir, CFileInfo* info) {
Bits len = 0;
@ -590,10 +570,9 @@ DOS_Drive_Cache::CFileInfo* DOS_Drive_Cache::FindDirInfo(const char* path, char*
save_dir = curDir;
return curDir;
};
}
bool DOS_Drive_Cache::OpenDir(const char* path, Bit16u& id)
{
bool DOS_Drive_Cache::OpenDir(const char* path, Bit16u& id) {
char expand[CROSS_LEN] = {0};
CFileInfo* dir = FindDirInfo(path,expand);
if (OpenDir(dir,expand,id)) {
@ -601,10 +580,9 @@ bool DOS_Drive_Cache::OpenDir(const char* path, Bit16u& id)
return true;
}
return false;
};
}
bool DOS_Drive_Cache::OpenDir(CFileInfo* dir, const char* expand, Bit16u& id)
{
bool DOS_Drive_Cache::OpenDir(CFileInfo* dir, const char* expand, Bit16u& id) {
id = GetFreeID(dir);
dirSearch[id] = dir;
char expandcopy [CROSS_LEN];
@ -625,7 +603,7 @@ bool DOS_Drive_Cache::OpenDir(CFileInfo* dir, const char* expand, Bit16u& id)
}
};
return false;
};
}
void DOS_Drive_Cache::CreateEntry(CFileInfo* dir, const char* name, bool is_directory) {
CFileInfo* info = new CFileInfo;