Merge branch 'master' of github.com:OBattler/86Box into tc1995

This commit is contained in:
TC1995
2017-05-14 16:49:47 +02:00
5 changed files with 321 additions and 3 deletions

View File

@@ -175,7 +175,7 @@ VIDOBJ = video.o \
WINOBJ = win.o \
win-d3d.o win-d3d-fs.o \
win-ddraw.o win-ddraw-fs.o win-ddraw-screenshot.o \
win-language.o win-status.o \
win-language.o win-status.o win-opendir.o \
win-video.o win-serial.o win-mouse.o \
win-joystick.o win-midi.o \
win-settings.o win-deviceconfig.o win-joystickconfig.o \

View File

@@ -90,7 +90,16 @@ network_pcap_setup(uint8_t *mac, NETRXCB func, void *arg)
char *dev;
/* Messy, but gets rid of a lot of useless info. */
strcpy(temp, pcap_lib_version());
dev = (char *)pcap_lib_version();
if (dev == NULL) {
/* Hmm, WinPcap doesn't seem to be alive.. */
pclog("PCAP: WinPcap library not found, disabling network!\n");
network_type = -1;
return(-1);
}
/* OK, good for now.. */
strcpy(temp, dev);
dev = strchr(temp, '(');
if (dev != NULL) *(dev-1) = '\0';
pclog("Initializing WinPcap, version %s\n", temp);

View File

@@ -46,7 +46,6 @@
#include "mouse.h"
#include "plat-mouse.h"
#include "network.h"
#include "net_ne2000.h"
#include "serial.h"
#include "sound/sound.h"
#include "sound/snd_cms.h"
@@ -59,6 +58,10 @@
#include "video/video.h"
#include "video/vid_voodoo.h"
#include "amstrad.h"
#ifdef WALTJE
# define UNICODE
# include "plat-dir.h"
#endif
#ifndef __unix
#define UNICODE
@@ -313,6 +316,23 @@ void initpc(int argc, wchar_t *argv[])
else if (!_wcsicmp(argv[c], L"--test"))
{
/* some (undocumented) test function here.. */
#ifdef WALTJE
DIR *dir;
struct direct *dp;
dir = opendirw(pcempath);
if (dir != NULL) {
printf("Directory '%ws':\n", pcempath);
for (;;) {
dp = readdir(dir);
if (dp == NULL) break;
printf(">> '%ws'\n", dp->d_name);
}
closedir(dir);
} else {
printf("Could not open '%ws'..\n", pcempath);
}
#endif
/* .. and then exit. */
exit(0);

76
src/plat-dir.h Normal file
View File

@@ -0,0 +1,76 @@
/*
* 86Box A hypervisor and IBM PC system emulator that specializes in
* running old operating systems and software designed for IBM
* PC systems and compatibles from 1981 through fairly recent
* system designs based on the PCI bus.
*
* This file is part of the 86Box distribution.
*
* Definitions for the platform OpenDir module.
*
* Version: @(#)plat-dir.h 1.0.1 2017/05/12
*
* Author: Fred N. van Kempen, <decwiz@yahoo.com>
* Copyright 2017 Fred N. van Kempen.
*/
#ifndef PLAT_DIR_H
# define PLAT_DIR_H
#ifdef _MAX_FNAME
# define MAXNAMLEN _MAX_FNAME
#else
# define MAXNAMLEN 15
#endif
# define MAXDIRLEN 127
struct direct {
long d_ino;
unsigned short d_reclen;
unsigned short d_off;
#ifdef UNICODE
wchar_t d_name[MAXNAMLEN + 1];
#else
char d_name[MAXNAMLEN + 1];
#endif
};
#define d_namlen d_reclen
typedef struct {
short flags; /* internal flags */
short offset; /* offset of entry into dir */
long handle; /* open handle to Win32 system */
short sts; /* last known status code */
char *dta; /* internal work data */
#ifdef UNICODE
wchar_t dir[MAXDIRLEN+1]; /* open dir */
#else
char dir[MAXDIRLEN+1]; /* open dir */
#endif
struct direct dent; /* actual directory entry */
} DIR;
/* Directory routine flags. */
#define DIR_F_LOWER 0x0001 /* force to lowercase */
#define DIR_F_SANE 0x0002 /* force this to sane path */
#define DIR_F_ISROOT 0x0010 /* this is the root directory */
/* Function prototypes. */
#ifdef UNICODE
extern DIR *opendirw(const wchar_t *);
#else
extern DIR *opendir(const char *);
#endif
extern struct direct *readdir(DIR *);
extern long telldir(DIR *);
extern void seekdir(DIR *, long);
extern int closedir(DIR *);
#define rewinddir(dirp) seekdir(dirp, 0L)
#endif /*PLAT_DIR_H*/

213
src/win-opendir.c Normal file
View File

@@ -0,0 +1,213 @@
/*
* 86Box A hypervisor and IBM PC system emulator that specializes in
* running old operating systems and software designed for IBM
* PC systems and compatibles from 1981 through fairly recent
* system designs based on the PCI bus.
*
* This file is part of the 86Box distribution.
*
* Implementation POSIX OpenDir(3) and friends for Win32 API.
*
* Based on old original code @(#)dir_win32.c 1.2.0 2007/04/19
*
* Version: @(#)win-opendir.c 1.0.1 2017/05/12
*
* Author: Fred N. van Kempen, <decwiz@yahoo.com>
* Copyright 1998-2007 MicroWalt Corporation
* Copyright 2017 Fred N. van Kempen
*/
#define UNICODE
#include <windows.h>
#include <io.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "ibm.h"
#include "plat-dir.h"
#ifdef UNICODE
# define SUFFIX L"\\*"
# define FINDATA struct _wfinddata_t
# define FINDFIRST _wfindfirst
# define FINDNEXT _wfindnext
#else
# define SUFFIX "\\*"
# define FINDATA struct _finddata_t
# define FINDFIRST _findfirst
# define FINDNEXT _findnext
#endif
/* Open a directory. */
DIR *
#ifdef UNICODE
opendirw(const wchar_t *name)
#else
opendir(const char *name)
#endif
{
DIR *p;
/* Create a new control structure. */
p = (DIR *) malloc(sizeof(DIR));
if (p == NULL)
return(NULL);
memset(p, 0x00, sizeof(DIR));
p->flags = (DIR_F_LOWER | DIR_F_SANE);
p->offset = 0;
p->sts = 0;
/* Create a work area. */
p->dta = (char *)malloc(sizeof(FINDATA));
if (p->dta == NULL) {
free(p);
return(NULL);
}
memset(p->dta, 0x00, sizeof(struct _finddata_t));
/* Add search filespec. */
#ifdef UNICODE
wcscpy(p->dir, name);
wcscat(p->dir, SUFFIX);
#else
strcpy(p->dir, name);
strcat(p->dir, SUFFIX);
#endif
/* Special case: flag if we are in the root directory. */
#ifdef UNICODE
if (wcslen(p->dir) == 3)
#else
if (strlen(p->dir) == 3)
#endif
p->flags |= DIR_F_ISROOT;
/* Start the searching by doing a FindFirst. */
p->handle = FINDFIRST(p->dir, (FINDATA *)p->dta);
if (p->handle < 0L) {
free(p->dta);
free(p);
return(NULL);
}
/* All OK. */
return(p);
}
/* Close an open directory. */
int
closedir(DIR *p)
{
if (p == NULL)
return(0);
_findclose(p->handle);
if (p->dta != NULL)
free(p->dta);
free(p);
return(0);
}
/*
* Read the next entry from a directory.
* Note that the DOS (FAT), Windows (FAT, FAT32) and Windows NTFS
* file systems do not have a root directory containing the UNIX-
* standard "." and ".." entries. Many applications do assume
* this anyway, so we simply fake these entries.
*/
struct direct *
readdir(DIR *p)
{
FINDATA *ffp;
if (p == NULL || p->sts == 1)
return(NULL);
/* Format structure with current data. */
ffp = (FINDATA *)p->dta;
p->dent.d_ino = 1L;
p->dent.d_off = p->offset++;
switch(p->offset) {
case 1: /* . */
#ifdef UNICODE
wcsncpy(p->dent.d_name, L".", MAXNAMLEN+1);
#else
strncpy(p->dent.d_name, ".", MAXNAMLEN+1);
#endif
p->dent.d_reclen = 1;
break;
case 2: /* .. */
#ifdef UNICODE
wcsncpy(p->dent.d_name, L"..", MAXNAMLEN+1);
#else
strncpy(p->dent.d_name, "..", MAXNAMLEN+1);
#endif
p->dent.d_reclen = 2;
break;
default: /* regular entry. */
#ifdef UNICODE
wcsncpy(p->dent.d_name, ffp->name, MAXNAMLEN+1);
#else
strncpy(p->dent.d_name, ffp->name, MAXNAMLEN+1);
#endif
p->dent.d_reclen = (char) wcslen(p->dent.d_name);
}
/* Read next entry. */
p->sts = 0;
/* Fake the "." and ".." entries here.. */
if ((p->flags & DIR_F_ISROOT) && (p->offset <= 2))
return(&(p->dent));
/* Get the next entry if we did not fake the above. */
if (FINDNEXT(p->handle, ffp) < 0)
p->sts = 1;
return(&(p->dent));
}
/* Report current position within the directory. */
long
telldir(DIR *p)
{
return(p->offset);
}
void
seekdir(DIR *p, long newpos)
{
short pos;
/* First off, rewind to start of directory. */
p->handle = FINDFIRST(p->dir, (FINDATA *)p->dta);
if (p->handle < 0L) {
p->sts = 1;
return;
}
p->offset = 0;
p->sts = 0;
/* If we are rewinding, that's all... */
if (newpos == 0L) return;
/* Nope.. read entries until we hit the right spot. */
pos = (short) newpos;
while (p->offset != pos) {
p->offset++;
if (FINDNEXT(p->handle, (FINDATA *)p->dta) < 0) {
p->sts = 1;
return;
}
}
}