summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
author couriersud <couriersud@arcor.de>2015-01-24 15:33:06 +0100
committer couriersud <couriersud@arcor.de>2015-01-24 15:33:06 +0100
commit4e94cc61de2a5342e59ddccc2476c30c860f7859 (patch)
treeeaa75322cbf6ae8cd830d5187c193743c79feab0
parentfcdb51ef0834f42d267fb63c3d7b7d8c7ae105af (diff)
More code alignment (windows/sdl). (nw)
-rw-r--r--src/osd/sdl/netdev_pcap.c47
-rw-r--r--src/osd/sdl/netdev_pcap_osx.c33
-rw-r--r--src/osd/sdl/sdlos_win32.c42
-rw-r--r--src/osd/sdl/strconv.c91
-rw-r--r--src/osd/windows/netdev_pcap.c4
-rw-r--r--src/osd/windows/strconv.c42
-rw-r--r--src/osd/windows/winfile.c17
7 files changed, 171 insertions, 105 deletions
diff --git a/src/osd/sdl/netdev_pcap.c b/src/osd/sdl/netdev_pcap.c
index 857d8f55e8d..54d837cc9fe 100644
--- a/src/osd/sdl/netdev_pcap.c
+++ b/src/osd/sdl/netdev_pcap.c
@@ -6,6 +6,16 @@
#include "emu.h"
#include "osdnet.h"
+#define pcap_compile_dl pcap_compile
+#define pcap_findalldevs_dl pcap_findalldevs
+#define pcap_open_live_dl pcap_open_live
+#define pcap_next_ex_dl pcap_next_ex
+#define pcap_close_dl pcap_close
+#define pcap_setfilter_dl pcap_setfilter
+#define pcap_sendpacket_dl pcap_sendpacket
+#define pcap_set_datalink_dl pcap_set_datalink
+
+
class netdev_pcap : public netdev
{
public:
@@ -24,16 +34,16 @@ netdev_pcap::netdev_pcap(const char *name, class device_network_interface *ifdev
: netdev(ifdev, rate)
{
char errbuf[PCAP_ERRBUF_SIZE];
- m_p = pcap_open_live(name, 65535, 1, 1, errbuf);
+ m_p = pcap_open_live_dl(name, 65535, 1, 1, errbuf);
if(!m_p)
{
osd_printf_verbose("Unable to open %s: %s\n", name, errbuf);
return;
}
- if(pcap_set_datalink(m_p, DLT_EN10MB) == -1)
+ if(pcap_set_datalink_dl(m_p, DLT_EN10MB) == -1)
{
- osd_printf_verbose("Unable to set %s to ethernet", name);
- pcap_close(m_p);
+ osd_printf_verbose("Unable to set %s to ethernet\n", name);
+ pcap_close_dl(m_p);
m_p = NULL;
return;
}
@@ -46,26 +56,30 @@ void netdev_pcap::set_mac(const char *mac)
struct bpf_program fp;
if(!m_p) return;
sprintf(filter, "ether dst %.2X:%.2X:%.2X:%.2X:%.2X:%.2X or ether multicast or ether broadcast", (unsigned char)mac[0], (unsigned char)mac[1], (unsigned char)mac[2],(unsigned char)mac[3], (unsigned char)mac[4], (unsigned char)mac[5]);
- pcap_compile(m_p, &fp, filter, 1, 0);
- pcap_setfilter(m_p, &fp);
+ if(pcap_compile_dl(m_p, &fp, filter, 1, 0) == -1) {
+ osd_printf_verbose("Error with pcap_compile\n");
+ }
+ if(pcap_setfilter_dl(m_p, &fp) == -1) {
+ osd_printf_verbose("Error with pcap_setfilter\n");
+ }
}
int netdev_pcap::send(UINT8 *buf, int len)
{
if(!m_p) return 0;
- return (!pcap_sendpacket(m_p, buf, len))?len:0;
+ return (!pcap_sendpacket_dl(m_p, buf, len))?len:0;
}
int netdev_pcap::recv_dev(UINT8 **buf)
{
struct pcap_pkthdr *header;
if(!m_p) return 0;
- return (pcap_next_ex(m_p, &header, (const u_char **)buf) == 1)?header->len:0;
+ return (pcap_next_ex_dl(m_p, &header, (const u_char **)buf) == 1)?header->len:0;
}
netdev_pcap::~netdev_pcap()
{
- if(m_p) pcap_close(m_p);
+ if(m_p) pcap_close_dl(m_p);
}
static CREATE_NETDEV(create_pcap)
@@ -78,20 +92,17 @@ void init_pcap()
{
pcap_if_t *devs;
char errbuf[PCAP_ERRBUF_SIZE];
- if(pcap_findalldevs(&devs, errbuf) == -1)
+ if(pcap_findalldevs_dl(&devs, errbuf) == -1)
{
osd_printf_verbose("Unable to get network devices: %s\n", errbuf);
return;
}
- if (devs)
- {
- while(devs->next)
- {
- add_netdev(devs->name, devs->description, create_pcap);
- devs = devs->next;
- }
- }
+ while(devs)
+ {
+ add_netdev(devs->name, devs->description, create_pcap);
+ devs = devs->next;
+ }
}
void deinit_pcap()
diff --git a/src/osd/sdl/netdev_pcap_osx.c b/src/osd/sdl/netdev_pcap_osx.c
index f2c083940d8..9485f65775d 100644
--- a/src/osd/sdl/netdev_pcap_osx.c
+++ b/src/osd/sdl/netdev_pcap_osx.c
@@ -8,6 +8,15 @@
#include <pthread.h>
#include <libkern/OSAtomic.h>
+#define pcap_compile_dl pcap_compile
+#define pcap_findalldevs_dl pcap_findalldevs
+#define pcap_open_live_dl pcap_open_live
+#define pcap_next_ex_dl pcap_next_ex
+#define pcap_close_dl pcap_close
+#define pcap_setfilter_dl pcap_setfilter
+#define pcap_sendpacket_dl pcap_sendpacket
+#define pcap_set_datalink_dl pcap_set_datalink
+
struct netdev_pcap_context {
UINT8 *pkt;
int len;
@@ -61,16 +70,16 @@ netdev_pcap::netdev_pcap(const char *name, class device_network_interface *ifdev
: netdev(ifdev, rate)
{
char errbuf[PCAP_ERRBUF_SIZE];
- m_p = pcap_open_live(name, 65535, 1, 1, errbuf);
+ m_p = pcap_open_live_dl(name, 65535, 1, 1, errbuf);
if(!m_p)
{
osd_printf_verbose("Unable to open %s: %s\n", name, errbuf);
return;
}
- if(pcap_set_datalink(m_p, DLT_EN10MB) == -1)
+ if(pcap_set_datalink_dl(m_p, DLT_EN10MB) == -1)
{
osd_printf_verbose("Unable to set %s to ethernet\n", name);
- pcap_close(m_p);
+ pcap_close_dl(m_p);
m_p = NULL;
return;
}
@@ -88,10 +97,10 @@ void netdev_pcap::set_mac(const char *mac)
struct bpf_program fp;
if(!m_p) return;
sprintf(filter, "not ether src %.2X:%.2X:%.2X:%.2X:%.2X:%.2X and (ether dst %.2X:%.2X:%.2X:%.2X:%.2X:%.2X or ether multicast or ether broadcast or ether dst 09:00:07:ff:ff:ff)", (unsigned char)mac[0], (unsigned char)mac[1], (unsigned char)mac[2],(unsigned char)mac[3], (unsigned char)mac[4], (unsigned char)mac[5], (unsigned char)mac[0], (unsigned char)mac[1], (unsigned char)mac[2],(unsigned char)mac[3], (unsigned char)mac[4], (unsigned char)mac[5]);
- if(pcap_compile(m_p, &fp, filter, 1, 0) == -1) {
+ if(pcap_compile_dl(m_p, &fp, filter, 1, 0) == -1) {
osd_printf_verbose("Error with pcap_compile\n");
}
- if(pcap_setfilter(m_p, &fp) == -1) {
+ if(pcap_setfilter_dl(m_p, &fp) == -1) {
osd_printf_verbose("Error with pcap_setfilter\n");
}
}
@@ -99,7 +108,7 @@ void netdev_pcap::set_mac(const char *mac)
int netdev_pcap::send(UINT8 *buf, int len)
{
if(!m_p) return 0;
- return (!pcap_sendpacket(m_p, buf, len))?len:0;
+ return (!pcap_sendpacket_dl(m_p, buf, len))?len:0;
}
int netdev_pcap::recv_dev(UINT8 **buf)
@@ -121,7 +130,7 @@ int netdev_pcap::recv_dev(UINT8 **buf)
netdev_pcap::~netdev_pcap()
{
- if(m_p) pcap_close(m_p);
+ if(m_p) pcap_close_dl(m_p);
}
static CREATE_NETDEV(create_pcap)
@@ -134,12 +143,19 @@ void init_pcap()
{
pcap_if_t *devs;
char errbuf[PCAP_ERRBUF_SIZE];
- if(pcap_findalldevs(&devs, errbuf) == -1)
+ if(pcap_findalldevs_dl(&devs, errbuf) == -1)
{
osd_printf_verbose("Unable to get network devices: %s\n", errbuf);
return;
}
+#if 1
+ while(devs)
+ {
+ add_netdev(devs->name, devs->description, create_pcap);
+ devs = devs->next;
+ }
+#else
if (devs)
{
while(devs->next)
@@ -148,6 +164,7 @@ void init_pcap()
devs = devs->next;
}
}
+#endif
}
void deinit_pcap()
diff --git a/src/osd/sdl/sdlos_win32.c b/src/osd/sdl/sdlos_win32.c
index 981e3a23b0e..a5ede43df00 100644
--- a/src/osd/sdl/sdlos_win32.c
+++ b/src/osd/sdl/sdlos_win32.c
@@ -102,45 +102,3 @@ char *osd_get_clipboard_text(void)
return result;
}
-//============================================================
-// astring_from_utf8
-//============================================================
-
-CHAR *astring_from_utf8(const char *utf8string)
-{
- WCHAR *wstring;
- int char_count;
- CHAR *result;
-
- // convert MAME string (UTF-8) to UTF-16
- char_count = MultiByteToWideChar(CP_UTF8, 0, utf8string, -1, NULL, 0);
- wstring = (WCHAR *)alloca(char_count * sizeof(*wstring));
- MultiByteToWideChar(CP_UTF8, 0, utf8string, -1, wstring, char_count);
-
- // convert UTF-16 to "ANSI code page" string
- char_count = WideCharToMultiByte(CP_ACP, 0, wstring, -1, NULL, 0, NULL, NULL);
- result = (CHAR *)osd_malloc_array(char_count * sizeof(*result));
- if (result != NULL)
- WideCharToMultiByte(CP_ACP, 0, wstring, -1, result, char_count, NULL, NULL);
-
- return result;
-}
-
-//============================================================
-// wstring_from_utf8
-//============================================================
-
-WCHAR *wstring_from_utf8(const char *utf8string)
-{
- int char_count;
- WCHAR *result;
-
- // convert MAME string (UTF-8) to UTF-16
- char_count = MultiByteToWideChar(CP_UTF8, 0, utf8string, -1, NULL, 0);
- result = (WCHAR *)osd_malloc_array(char_count * sizeof(*result));
- if (result != NULL)
- MultiByteToWideChar(CP_UTF8, 0, utf8string, -1, result, char_count);
-
- return result;
-}
-
diff --git a/src/osd/sdl/strconv.c b/src/osd/sdl/strconv.c
index ffc73dc68d2..73d1f576c0a 100644
--- a/src/osd/sdl/strconv.c
+++ b/src/osd/sdl/strconv.c
@@ -1,26 +1,46 @@
+// license:BSD-3-Clause
+// copyright-holders:Aaron Giles
//============================================================
//
-// strconv.c - SDL (POSIX) string conversion
-//
-// Copyright (c) 1996-2010, Nicola Salmoria and the MAME Team.
-// Visit http://mamedev.org for licensing and usage restrictions.
-//
-// SDLMAME by Olivier Galibert and R. Belmont
+// strconv.c - Win32 string conversion
//
//============================================================
-#ifdef SDLMAME_WIN32
+#if defined(SDLMAME_WIN32) || defined(OSD_WINDOWS)
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#endif
-#include <stdlib.h>
-
// MAMEOS headers
#include "strconv.h"
#include "unicode.h"
-#ifdef SDLMAME_WIN32
+#if defined(SDLMAME_WIN32) || defined(OSD_WINDOWS)
+//============================================================
+// astring_from_utf8
+//============================================================
+
+CHAR *astring_from_utf8(const char *utf8string)
+{
+ WCHAR *wstring;
+ int char_count;
+ CHAR *result;
+
+ // convert MAME string (UTF-8) to UTF-16
+ char_count = MultiByteToWideChar(CP_UTF8, 0, utf8string, -1, NULL, 0);
+ wstring = (WCHAR *)alloca(char_count * sizeof(*wstring));
+ MultiByteToWideChar(CP_UTF8, 0, utf8string, -1, wstring, char_count);
+
+ // convert UTF-16 to "ANSI code page" string
+ char_count = WideCharToMultiByte(CP_ACP, 0, wstring, -1, NULL, 0, NULL, NULL);
+ result = (CHAR *)osd_malloc_array(char_count * sizeof(*result));
+ if (result != NULL)
+ WideCharToMultiByte(CP_ACP, 0, wstring, -1, result, char_count, NULL, NULL);
+
+ return result;
+}
+
+
//============================================================
// utf8_from_astring
//============================================================
@@ -45,6 +65,26 @@ char *utf8_from_astring(const CHAR *astring)
return result;
}
+
+//============================================================
+// wstring_from_utf8
+//============================================================
+
+WCHAR *wstring_from_utf8(const char *utf8string)
+{
+ int char_count;
+ WCHAR *result;
+
+ // convert MAME string (UTF-8) to UTF-16
+ char_count = MultiByteToWideChar(CP_UTF8, 0, utf8string, -1, NULL, 0);
+ result = (WCHAR *)osd_malloc_array(char_count * sizeof(*result));
+ if (result != NULL)
+ MultiByteToWideChar(CP_UTF8, 0, utf8string, -1, result, char_count);
+
+ return result;
+}
+
+
//============================================================
// utf8_from_wstring
//============================================================
@@ -62,21 +102,40 @@ char *utf8_from_wstring(const WCHAR *wstring)
return result;
}
-#endif
//============================================================
// osd_uchar_from_osdchar
//============================================================
-int osd_uchar_from_osdchar(unicode_char *uchar, const char *osdchar, size_t count)
+int osd_uchar_from_osdchar(UINT32 *uchar, const char *osdchar, size_t count)
{
- wchar_t wch;
+ WCHAR wch;
- count = mbstowcs(&wch, (char *)osdchar, 1);
- if (count != -1)
+ count = MIN(count, IsDBCSLeadByte(*osdchar) ? 2 : 1);
+ if (MultiByteToWideChar(CP_ACP, 0, osdchar, (DWORD)count, &wch, 1) != 0)
*uchar = wch;
else
*uchar = 0;
+ return (int) count;
+}
- return count;
+#else
+
+//============================================================
+// osd_uchar_from_osdchar
+//============================================================
+
+int osd_uchar_from_osdchar(unicode_char *uchar, const char *osdchar, size_t count)
+{
+ wchar_t wch;
+
+ count = mbstowcs(&wch, (char *)osdchar, 1);
+ if (count != -1)
+ *uchar = wch;
+ else
+ *uchar = 0;
+
+ return count;
}
+
+#endif
diff --git a/src/osd/windows/netdev_pcap.c b/src/osd/windows/netdev_pcap.c
index ea9d9902574..ce281f4feb4 100644
--- a/src/osd/windows/netdev_pcap.c
+++ b/src/osd/windows/netdev_pcap.c
@@ -112,13 +112,13 @@ void init_pcap()
catch (DWORD e)
{
FreeLibrary(handle);
- osd_printf_verbose("Unable to load winpcap: %lx\n", e);
+ osd_printf_warning("Unable to load winpcap: %lx\n", e);
return;
}
if(pcap_findalldevs_dl(&devs, errbuf) == -1)
{
FreeLibrary(handle);
- osd_printf_verbose("Unable to get network devices: %s\n", errbuf);
+ osd_printf_warning("Unable to get network devices: %s\n", errbuf);
return;
}
diff --git a/src/osd/windows/strconv.c b/src/osd/windows/strconv.c
index 3dba756a297..3eedf040127 100644
--- a/src/osd/windows/strconv.c
+++ b/src/osd/windows/strconv.c
@@ -6,15 +6,16 @@
//
//============================================================
-// standard windows headers
+#if defined(SDLMAME_WIN32) || defined(OSD_WINDOWS)
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
+#endif
// MAMEOS headers
#include "strconv.h"
#include "unicode.h"
-
+#if defined(SDLMAME_WIN32) || defined(OSD_WINDOWS)
//============================================================
// astring_from_utf8
//============================================================
@@ -101,3 +102,40 @@ char *utf8_from_wstring(const WCHAR *wstring)
return result;
}
+
+//============================================================
+// osd_uchar_from_osdchar
+//============================================================
+
+int osd_uchar_from_osdchar(UINT32 *uchar, const char *osdchar, size_t count)
+{
+ WCHAR wch;
+
+ count = MIN(count, IsDBCSLeadByte(*osdchar) ? 2 : 1);
+ if (MultiByteToWideChar(CP_ACP, 0, osdchar, (DWORD)count, &wch, 1) != 0)
+ *uchar = wch;
+ else
+ *uchar = 0;
+ return (int) count;
+}
+
+#else
+
+//============================================================
+// osd_uchar_from_osdchar
+//============================================================
+
+int osd_uchar_from_osdchar(unicode_char *uchar, const char *osdchar, size_t count)
+{
+ wchar_t wch;
+
+ count = mbstowcs(&wch, (char *)osdchar, 1);
+ if (count != -1)
+ *uchar = wch;
+ else
+ *uchar = 0;
+
+ return count;
+}
+
+#endif
diff --git a/src/osd/windows/winfile.c b/src/osd/windows/winfile.c
index af62026ecb4..9f02a547523 100644
--- a/src/osd/windows/winfile.c
+++ b/src/osd/windows/winfile.c
@@ -383,23 +383,6 @@ int osd_get_physical_drive_geometry(const char *filename, UINT32 *cylinders, UIN
//============================================================
-// osd_uchar_from_osdchar
-//============================================================
-
-int osd_uchar_from_osdchar(UINT32 *uchar, const char *osdchar, size_t count)
-{
- WCHAR wch;
-
- count = MIN(count, IsDBCSLeadByte(*osdchar) ? 2 : 1);
- if (MultiByteToWideChar(CP_ACP, 0, osdchar, (DWORD)count, &wch, 1) != 0)
- *uchar = wch;
- else
- *uchar = 0;
- return (int) count;
-}
-
-
-//============================================================
// create_path_recursive
//============================================================