Synchronet now requires the libarchive development package (e.g. libarchive-dev on Debian-based Linux distros, libarchive.org for more info) to build successfully.

Commit 1066ae7e authored by deuce's avatar deuce

Many many more nixin-fixin.

parent f942cf9a
......@@ -52,7 +52,7 @@ LD := ld
#
# Compiler command-line flags.
#
CFLAGS += -O2
CFLAGS += -O2 -g
# /MTd /Zi - for debug
#
#------------------------------------------------------------------------------
......
......@@ -117,14 +117,14 @@ ODAPIDEF void ODCALL ODConfigInit(void)
if((pfConfigFile = fopen(od_control.od_config_filename, "rt")) == NULL)
{
if(strchr(od_control.od_config_filename, '\\') != NULL
if(strchr(od_control.od_config_filename, DIRSEP) != NULL
|| strchr(od_control.od_config_filename, ':') != NULL)
{
wCurrent = strlen(od_control.od_config_filename);
pchConfigText = (char *)od_control.od_config_filename + (wCurrent - 1);
while(wCurrent > 0)
{
if(*pchConfigText == '\\' || *pchConfigText == ':')
if(*pchConfigText == DIRSEP || *pchConfigText == ':')
{
strcpy(szConfigLine, (char *)pchConfigText + 1);
pfConfigFile = fopen(szConfigLine, "rt");
......@@ -236,7 +236,7 @@ ODAPIDEF void ODCALL ODConfigInit(void)
break;
case 2:
if(pchConfigText[strlen(pchConfigText) - 1] == '\\'
if(pchConfigText[strlen(pchConfigText) - 1] == DIRSEP
&& pchConfigText[strlen(pchConfigText) - 2] != ':'
&& strlen(pchConfigText) > 1)
{
......
......@@ -51,6 +51,9 @@
#include <ctype.h>
#include "OpenDoor.h"
#ifdef ODPLAT_NIX
#define stricmp strcasecmp
#endif
#include "ODPlat.h"
#include "ODCore.h"
#include "ODInEx.h"
......
......@@ -1024,7 +1024,7 @@ static BOOL ODEditIsCharValidForPos(char chEntered, INT nPosition)
/* Filename separators. */
case ':':
case '.':
case '\\':
case DIRSEP:
/* Wildcard characters. */
case '?':
......@@ -1073,7 +1073,7 @@ static BOOL ODEditIsCharValidForPos(char chEntered, INT nPosition)
case 'w':
if(chEntered >= 'A' && chEntered <= 'Z') break;
if(chEntered >= 'a' && chEntered <= 'z') break;
if(chEntered == ':' || chEntered == '.' || chEntered == '\\'
if(chEntered == ':' || chEntered == '.' || chEntered == DIRSEP
|| chEntered == '*' || chEntered == '?')
{
break;
......
......@@ -60,7 +60,7 @@
#endif /* ODPLAT_WIN32 */
/* Text mode specific definitions. */
#ifdef ODPLAT_DOS
#if defined(ODPLAT_DOS) || defined(ODPLAT_NIX)
#define OD_TEXTMODE
#endif /* ODPLAT_DOS */
......
......@@ -86,6 +86,9 @@
#include <time.h>
#include "OpenDoor.h"
#ifdef ODPLAT_NIX
#define strnicmp strncasecmp
#endif
#include "ODCore.h"
#include "ODGen.h"
#include "ODScrn.h"
......
......@@ -842,9 +842,9 @@ INT ODSearchForDropFile(char **papszFileNames, INT nNumFileNames,
/* Next, look for the drop file(s) in the current directory. */
if((nResult = ODSearchInDir(papszFileNames, nNumFileNames, pszFound,
".\\")) != -1)
"."DIRSEP_STR)) != -1)
{
if(pszDirectory != NULL) strcpy(pszDirectory, ".\\");
if(pszDirectory != NULL) strcpy(pszDirectory, "."DIRSEP_STR);
return(nResult);
}
......
......@@ -119,18 +119,18 @@ ODAPIDEF BOOL ODCALL od_list_files(char *pszFileSpec)
if(pszFileSpec == NULL)
{
strcpy(szODWorkString, ".");
strcpy(szDirectory, ".\\");
strcpy(szDirectory, "."DIRSEP_STR);
}
else if(*pszFileSpec == '\0')
{
strcpy(szODWorkString, ".");
strcpy(szDirectory, ".\\");
strcpy(szDirectory, "."DIRSEP_STR);
}
else
{
strcpy(szODWorkString, pszFileSpec);
strcpy(szDirectory, pszFileSpec);
if(szODWorkString[strlen(szODWorkString) - 1] == '\\')
if(szODWorkString[strlen(szODWorkString) - 1] == DIRSEP)
{
szODWorkString[strlen(szODWorkString) - 1] = '\0';
}
......@@ -441,7 +441,7 @@ static INT ODListFilenameSplit(const char *pszEntirePath, char *pszDrive,
nToReturn |= DRIVE;
}
if((pchCurrentPos = strrchr(pchStart, '\\'))==NULL)
if((pchCurrentPos = strrchr(pchStart, DIRSEP))==NULL)
{
pszDir[0] = '\0';
}
......
......@@ -57,6 +57,12 @@
#include <string.h>
#include "OpenDoor.h"
#ifdef ODPLAT_NIX
#include <sys/time.h>
#include <glob.h>
#include <sys/types.h>
#include <sys/stat.h>
#endif
#include "ODGen.h"
#include "ODCore.h"
#include "ODPlat.h"
......@@ -549,6 +555,9 @@ void ODProcessExit(INT nExitCode)
*/
void ODTimerStart(tODTimer *pTimer, tODMilliSec Duration)
{
#ifdef ODPLAT_NIX
struct timeval tv;
#endif
ASSERT(pTimer != NULL);
ASSERT(Duration >= 0);
......@@ -566,6 +575,13 @@ void ODTimerStart(tODTimer *pTimer, tODMilliSec Duration)
pTimer->Start = GetCurrentTime();
pTimer->Duration = Duration;
#endif /* ODPLAT_WIN32 */
#ifdef ODPLAT_NIX
gettimeofday(&tv,NULL);
pTimer->Start.tv_sec=tv.tv_sec;
pTimer->Start.tv_usec=tv.tv_usec;
pTimer->Duration = Duration;
#endif
}
......@@ -581,6 +597,10 @@ void ODTimerStart(tODTimer *pTimer, tODMilliSec Duration)
*/
BOOL ODTimerElapsed(tODTimer *pTimer)
{
#ifdef ODPLAT_NIX
struct timeval tv;
struct timeval end;
#endif
ASSERT(pTimer != NULL);
#ifdef ODPLAT_DOS
......@@ -592,6 +612,13 @@ BOOL ODTimerElapsed(tODTimer *pTimer)
return(GetCurrentTime() > pTimer->Start + pTimer->Duration
|| GetCurrentTime() < pTimer->Start);
#endif /* ODPLAT_WIN32 */
#ifdef ODPLAT_NIX
gettimeofday(&tv,NULL);
end.tv_sec=pTimer->Start.tv_sec+(pTimer->Duration / 1000);
end.tv_usec=(pTimer->Start.tv_usec+(pTimer->Duration*1000))%1000000;
return(end.tv_sec >= tv.tv_sec && end.tv_usec >= tv.tv_usec);
#endif
}
......@@ -607,6 +634,9 @@ BOOL ODTimerElapsed(tODTimer *pTimer)
*/
void ODTimerWaitForElapse(tODTimer *pTimer)
{
#ifdef ODPLAT_NIX
struct timeval tv;
#endif
ASSERT(pTimer != NULL);
#ifdef ODPLAT_DOS
......@@ -623,6 +653,17 @@ void ODTimerWaitForElapse(tODTimer *pTimer)
od_sleep(0);
}
#elif defined(ODPLAT_NIX)
gettimeofday(&tv,NULL);
tv.tv_sec -= pTimer->Start.tv_sec;
tv.tv_usec -= pTimer->Start.tv_usec;
if(tv.tv_usec < 0) {
tv.tv_sec--;
tv.tv_usec += 1000000;
}
if(tv.tv_sec<0 || tv.tv_usec<0)
return;
select(0,NULL,NULL,NULL,&tv);
#else /* !ODPLAT_DOS */
{
/* Under other platforms, timer resolution is high enough that we can */
......@@ -663,6 +704,9 @@ void ODTimerWaitForElapse(tODTimer *pTimer)
*/
tODMilliSec ODTimerLeft(tODTimer *pTimer)
{
#ifdef ODPLAT_NIX
struct timeval tv;
#endif
ASSERT(pTimer != NULL);
#ifdef ODPLAT_DOS
......@@ -681,6 +725,15 @@ tODMilliSec ODTimerLeft(tODTimer *pTimer)
return(ODDWordMultiply(Left, MILLISEC_PER_TICK));
}
#elif defined(ODPLAT_NIX)
gettimeofday(&tv,NULL);
tv.tv_sec -= pTimer->Start.tv_sec;
tv.tv_usec -= pTimer->Start.tv_usec;
if(tv.tv_usec < 0) {
tv.tv_sec--;
tv.tv_usec += 1000000;
}
return((tv.tv_usec/1000)+(tv.tv_sec*1000));
#else /* !ODPLAT_DOS */
{
tODMilliSec Now;
......@@ -718,6 +771,9 @@ tODMilliSec ODTimerLeft(tODTimer *pTimer)
*/
ODAPIDEF void ODCALL od_sleep(tODMilliSec Milliseconds)
{
#ifdef ODPLAT_NIX
struct timeval tv;
#endif
/* Log function entry if running in trace mode. */
TRACE(TRACE_API, "od_sleep()");
......@@ -747,6 +803,12 @@ ODAPIDEF void ODCALL od_sleep(tODMilliSec Milliseconds)
Sleep(Milliseconds);
#endif /* ODPLAT_WIN32 */
#ifdef ODPLAT_NIX
tv.tv_sec=Milliseconds/1000;
tv.tv_usec=(Milliseconds%1000)*1000;
select(0,NULL,NULL,NULL,tv);
#endif
OD_API_EXIT();
}
......@@ -781,6 +843,11 @@ typedef struct
WIN32_FIND_DATA WindowsDirEntry;
int wAttributes;
#endif /* ODPLAT_WIN32 */
#ifdef ODPLAT_NIX
glob_t g;
int pos;
int wAttributes;
#endif
} tODDirInfo;
......@@ -877,6 +944,17 @@ tODResult ODDirOpen(CONST char *pszPath, WORD wAttributes, tODDirHandle *phDir)
}
#endif /* ODPLAT_WIN32 */
#ifdef ODPLAT_NIX
if(glob(pszPath,GLOB_NOSORT,NULL,&(pDirInfo->g)))
return(kODRCNoMatch);
if(pDirInfo->g.gl_matchc==0) {
globfree(&(pDirInfo->g));
return(kODRCNoMatch);
}
pDirInfo->pos=0;
pDirInfo->wAttributes = wAttributes;
#endif
/* Now that open operation is complete, give the caller a directory */
/* handle. */
*phDir = ODPTR2HANDLE(pDirInfo, tODDirInfo);
......@@ -909,6 +987,9 @@ tODResult ODDirRead(tODDirHandle hDir, tODDirEntry *pDirEntry)
WORD wDOSDate;
WORD wDOSTime;
#endif /* ODPLAT_WIN32 */
#ifdef ODPLAT_NIX
struct stat st;
#endif
ASSERT(pDirEntry != NULL);
ASSERT(pDirInfo != NULL);
......@@ -1000,6 +1081,30 @@ tODResult ODDirRead(tODDirHandle hDir, tODDirEntry *pDirEntry)
} while(!ODDirWinMatchesAttributes(pDirInfo));
#endif /* ODPLAT_WIN32 */
#ifdef ODPLAT_NIX
while(!pDirInfo->bEOF) {
if(strrchr(pDirInfo->g.gl_pathv[pDirInfo->pos],DIRSEP)==NULL)
strcpy(pDirEntry->szFileName,pDirInfo->g.gl_pathv[pDirInfo->pos]);
else
strcpy(pDirEntry->szFileName,strrchr(pDirInfo->g.gl_pathv[pDirInfo->pos],DIRSEP));
stat(pDirInfo->g.gl_pathv[pDirInfo->pos],&st);
pDirEntry->wAttributes=DIR_ATTRIB_NORMAL;
if(st.st_mode & S_IFDIR)
pDirEntry->wAttributes |= DIR_ATTRIB_DIREC;
if(!st.st_mode & S_IWUSR)
pDirEntry->wAttributes |= DIR_ATTRIB_RDONLY;
if(!st.st_mode & S_IRUSR)
pDirEntry->wAttributes |= DIR_ATTRIB_SYSTEM;
pDirInfo->pos++;
if(pDirInfo->pos==pDirInfo->g.gl_matchc)
pDirInfo->bEOF=TRUE;
if(pDirEntry->wAttributes==pDirInfo->wAttributes)
return(kODRCSuccess);
if(pDirInfo->bEOF==TRUE)
return(kODRCEndOfFile);
}
#endif
/* Return with success. */
return(kODRCSuccess);
}
......@@ -1026,6 +1131,10 @@ void ODDirClose(tODDirHandle hDir)
FindClose(pDirInfo->hWindowsDir);
#endif /* ODPLAT_WIN32 */
#ifdef ODPLAT_NIX
globfree(&(pDirInfo->g));
#endif
/* Free the directory information structure. */
free(pDirInfo);
}
......@@ -1243,6 +1352,10 @@ void ODDirChangeCurrent(char *pszPath)
#ifdef ODPLAT_WIN32
SetCurrentDirectory(pszPath);
#endif /* ODPLAT_WIN32 */
#ifdef ODPLAT_NIX
chdir(pszPath);
#endif
}
......@@ -1276,6 +1389,10 @@ void ODDirGetCurrent(char *pszPath, INT nMaxPathChars)
GetCurrentDirectory(nMaxPathChars, pszPath);
#endif /* ODPLAT_WIN32 */
#ifdef ODPLAT_NIX
getcwd(pszPath,nMaxPathChars);
#endif
ASSERT((INT)strlen(pszPath) + 1 <= nMaxPathChars);
}
......@@ -1324,6 +1441,10 @@ Done:
#ifdef ODPLAT_WIN32
return(DeleteFile(pszPath) ? kODRCSuccess : kODRCGeneralFailure);
#endif /* ODPLAT_WIN32 */
#ifdef ODPLAT_NIX
return(unlink(pszPath));
#endif
}
......@@ -1352,8 +1473,8 @@ BOOL ODFileAccessMode(char *pszFilename, int nAccessMode)
BYTE nLength;
/* If we are looking for the root directory. */
nLength = strlen(pszFilename);
if((nLength == 3 && pszFilename[1] == ':' && pszFilename[2] == '\\') ||
(nLength == 1 && pszFilename[0] == '\\'))
if((nLength == 3 && pszFilename[1] == ':' && pszFilename[2] == DIRSEP) ||
(nLength == 1 && pszFilename[0] == DIRSEP))
{
if(nAccessMode == 0)
{
......
......@@ -67,6 +67,9 @@ typedef struct
#ifdef ODPLAT_DOS
clock_t Start;
clock_t Duration;
#elif defined(ODPLAT_NIX)
struct timeval Start;
tODMilliSec Duration;
#else /* !ODPLAT_DOS */
tODMilliSec Start;
tODMilliSec Duration;
......@@ -161,7 +164,7 @@ extern tODMultitasker ODMultitasker;
typedef tODHandle tODDirHandle;
/* Directory entry structure. */
#define DIR_FILENAME_SIZE 13
#define DIR_FILENAME_SIZE 1024
#define DIR_ATTRIB_NORMAL 0x00
#define DIR_ATTRIB_RDONLY 0x01
......
......@@ -43,6 +43,9 @@
#include <stdio.h>
#include "OpenDoor.h"
#ifdef ODPLAT_NIX
#define stricmp strcasecmp
#endif
#include "ODUtil.h"
#include "ODGen.h"
......@@ -226,10 +229,14 @@ tODResult ODMakeFilename(char *pszOut, CONST char *pszPath,
}
/* Ensure there is a trailing backslash, if path was not empty. */
if(pszOut[strlen(pszOut) - 1] != '\\' && strlen(pszOut) > 0)
#ifdef ODPLAT_NIX
#else
if(pszOut[strlen(pszOut) - 1] != DIRSEP && strlen(pszOut) > 0)
{
strcat(pszOut, "\\");
strcat(pszOut, DIRSEP_STR);
}
#endif
/* Append base filename. */
strcat(pszOut, pszFilename);
......
......@@ -82,6 +82,9 @@
/* OpenDoors API version number. */
#define OD_VERSION 0x621
#define DIRSEP '\\'
#define DIRSEP_STR "\\"
/* OpenDoors target platform. */
#if defined(WIN32) || defined(__WIN32__) || defined(_WIN32)
#define ODPLAT_WIN32
......@@ -96,6 +99,10 @@
#if defined(__unix__) || defined(__NetBSD__)
#define ODPLAT_NIX
#undef ODPLAT_DOS
#undef DIRSEP
#define DIRSEP '/'
#undef DIRSEP_STR
#define DIRSEP_STR "/"
#else
#define ODPLAT_DOS
#undef ODPLAT_WIN32
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment