Skip to content

Commit

Permalink
os2: a _lot_ of coding style cleanup, sot that they match the SDL style.
Browse files Browse the repository at this point in the history
also renamed the 'debug' macro to debug_os2: the former was dangerously
a common name.

the binary (dll) output is precisely the same as before.
  • Loading branch information
sezero committed Oct 15, 2020
1 parent bdc5129 commit a90f040
Show file tree
Hide file tree
Showing 29 changed files with 3,738 additions and 4,008 deletions.
700 changes: 337 additions & 363 deletions src/audio/os2/SDL_os2audio.c

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions src/audio/os2/SDL_os2audio.h
Expand Up @@ -35,19 +35,19 @@
/* Hidden "this" pointer for the audio functions */
#define _THIS SDL_AudioDevice *this

#define NUM_BUFFERS 3
#define NUM_BUFFERS 3

typedef struct SDL_PrivateAudioData
{
USHORT usDeviceId;
BYTE _pad[2];
MCI_MIXSETUP_PARMS stMCIMixSetup;
HEV hevBuf;
ULONG ulNextBuf;
ULONG cMixBuffers;
MCI_MIX_BUFFER aMixBuffers[NUM_BUFFERS];
// ULONG ulQueuedBuf;
} SDL_PrivateAudioData, *PSDL_PrivateAudioData;
USHORT usDeviceId;
BYTE _pad[2];
MCI_MIXSETUP_PARMS stMCIMixSetup;
HEV hevBuf;
ULONG ulNextBuf;
ULONG cMixBuffers;
MCI_MIX_BUFFER aMixBuffers[NUM_BUFFERS];
/* ULONG ulQueuedBuf;*/
} SDL_PrivateAudioData;

#endif /* SDL_os2mm_h_ */

Expand Down
14 changes: 8 additions & 6 deletions src/core/os2/SDL_os2.c
Expand Up @@ -18,19 +18,21 @@
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/

#include "../../SDL_internal.h"

#if defined(__OS2__)

#include "geniconv/geniconv.h"

// SDL_OS2Quit() will be called from SDL_QuitSubSystem().

void SDL_OS2Quit()
/* SDL_OS2Quit() will be called from SDL_QuitSubSystem() */
void SDL_OS2Quit(void)
{
// Unload DLL used for iconv. We can do it at any time and use iconv again -
// dynamic library will be loaded on first call iconv_open() (see geniconv).
libiconv_clean();
/* Unload DLL used for iconv. We can do it at any time and use iconv again -
* dynamic library will be loaded on first call iconv_open() (see geniconv). */
libiconv_clean();
}

#endif

/* vi: set ts=4 sw=4 expandtab: */
18 changes: 10 additions & 8 deletions src/core/os2/SDL_os2.h
Expand Up @@ -27,24 +27,26 @@

#ifdef OS2DEBUG
#if (OS2DEBUG-0 >= 2)
# define debug(s,...) SDL_LogDebug( SDL_LOG_CATEGORY_APPLICATION, \
__func__"(): "##s, ##__VA_ARGS__ )
# define debug_os2(s,...) SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, \
__func__ "(): " ##s, ##__VA_ARGS__)
#else
# define debug(s,...) printf( __func__"(): "##s"\n", ##__VA_ARGS__ )
# define debug_os2(s,...) printf(__func__ "(): " ##s "\n", ##__VA_ARGS__)
#endif

#else
#else /* no debug */

# define debug(s,...)
# define debug_os2(s,...) do {} while (0)

#endif /* OS2DEBUG */


/* StrUTF8New() - geniconv/sys2utf8.c */
#define OS2_SysToUTF8(S) StrUTF8New( 1, S, SDL_strlen( S ) + 1 )
#define OS2_UTF8ToSys(S) StrUTF8New( 0, (char *)(S), SDL_strlen( S ) + 1 )
#define OS2_SysToUTF8(S) StrUTF8New(1, (S), SDL_strlen((S)) + 1)
#define OS2_UTF8ToSys(S) StrUTF8New(0, (char *)(S), SDL_strlen((S)) + 1)

/* SDL_OS2Quit() will be called from SDL_QuitSubSystem() */
void SDL_OS2Quit();
void SDL_OS2Quit(void);

#endif /* SDL_os2_h_ */

/* vi: set ts=4 sw=4 expandtab: */
151 changes: 72 additions & 79 deletions src/core/os2/geniconv/geniconv.c
Expand Up @@ -25,38 +25,38 @@
Andrey Vasilkin, 2016.
*/

#define INCL_DOSMODULEMGR /* Module Manager values */
#define INCL_DOSERRORS /* Error values */
#define INCL_DOSMODULEMGR /* Module Manager values */
#define INCL_DOSERRORS /* Error values */
#include <os2.h>

#include "geniconv.h"

//#define DEBUG
/*#define DEBUG*/

#ifdef DEBUG
# include <stdio.h>
# define debug(s,...) printf(__func__"(): "##s"\n" ,##__VA_ARGS__)
#else
# define debug(s,...)
# define debug(s,...) do {} while (0)
#endif

// Exports from os2iconv.c.
/* Exports from os2iconv.c */
extern iconv_t _System os2_iconv_open(const char* tocode, const char* fromcode);
extern size_t _System os2_iconv(iconv_t cd, char* * inbuf,
size_t *inbytesleft, char* * outbuf,
size_t *outbytesleft);
extern int _System os2_iconv_close(iconv_t cd);

// Functions pointers types.
/* Functions pointers types */
typedef iconv_t _System (*FNICONV_OPEN)(const char* tocode, const char* fromcode);
typedef size_t _System (*FNICONV)(iconv_t cd, char* * inbuf,
size_t *inbytesleft, char* * outbuf,
size_t *outbytesleft);
typedef int _System (*FNICONV_CLOSE)(iconv_t cd);

// Used DLL module handle.
/* Used DLL module handle */
static HMODULE hmIconv = NULLHANDLE;
// Functions pointers.
/* Functions pointers */
static FNICONV_OPEN fn_iconv_open = NULL;
static FNICONV fn_iconv = NULL;
static FNICONV_CLOSE fn_iconv_close = NULL;
Expand All @@ -65,100 +65,93 @@ static FNICONV_CLOSE fn_iconv_close = NULL;
static BOOL _loadDLL(PSZ pszName, PSZ pszIconvOpen, PSZ pszIconv,
PSZ pszIconvClose)
{
ULONG ulRC;
CHAR acError[256];
ULONG ulRC;
CHAR acError[256];

ulRC = DosLoadModule( acError, sizeof(acError), pszName, &hmIconv );
if ( ulRC != NO_ERROR )
{
debug( "DLL not loaded: %s", &acError );
return FALSE;
}

do
{
ulRC = DosQueryProcAddr( hmIconv, 0, pszIconvOpen, (PFN *)&fn_iconv_open );
if ( ulRC != NO_ERROR )
{
debug( "Error: cannot find entry %s in %s", pszIconvOpen, pszName );
break;
}

ulRC = DosQueryProcAddr( hmIconv, 0, pszIconv, (PFN *)&fn_iconv );
if ( ulRC != NO_ERROR )
{
debug( "Error: cannot find entry %s in %s", pszIconv, pszName );
break;
ulRC = DosLoadModule(acError, sizeof(acError), pszName, &hmIconv);
if (ulRC != NO_ERROR) {
debug("DLL not loaded: %s", &acError);
return FALSE;
}

ulRC = DosQueryProcAddr( hmIconv, 0, pszIconvClose, (PFN *)&fn_iconv_close );
if ( ulRC != NO_ERROR )
{
debug( "Error: cannot find entry %s in %s", pszIconvClose, pszName );
break;
}

debug( "DLL %s used", pszName );
return TRUE;
}
while( FALSE );

DosFreeModule( hmIconv );
hmIconv = NULLHANDLE;
return FALSE;
do {
ulRC = DosQueryProcAddr(hmIconv, 0, pszIconvOpen, (PFN *)&fn_iconv_open);
if (ulRC != NO_ERROR) {
debug("Error: cannot find entry %s in %s", pszIconvOpen, pszName);
break;
}

ulRC = DosQueryProcAddr(hmIconv, 0, pszIconv, (PFN *)&fn_iconv);
if (ulRC != NO_ERROR) {
debug("Error: cannot find entry %s in %s", pszIconv, pszName);
break;
}

ulRC = DosQueryProcAddr(hmIconv, 0, pszIconvClose, (PFN *)&fn_iconv_close);
if (ulRC != NO_ERROR) {
debug("Error: cannot find entry %s in %s", pszIconvClose, pszName);
break;
}

debug("DLL %s used", pszName);
return TRUE;
} while (FALSE);

DosFreeModule(hmIconv);
hmIconv = NULLHANDLE;
return FALSE;
}

static void _init()
static void _init(void)
{
if ( fn_iconv_open != NULL )
// Already was initialized.
return;

// Try to load kiconv.dll, iconv2.dll or iconv.dll.
if ( !_loadDLL( "KICONV", "_libiconv_open", "_libiconv", "_libiconv_close" )
&& !_loadDLL( "ICONV2", "_libiconv_open", "_libiconv", "_libiconv_close" )
&& !_loadDLL( "ICONV", "_iconv_open", "_iconv", "_iconv_close" ) )
{
// No one DLL was loaded - use OS/2 conversion objects API.

debug( "Uni*() API used" );
fn_iconv_open = os2_iconv_open;
fn_iconv = os2_iconv;
fn_iconv_close = os2_iconv_close;
}
if (fn_iconv_open != NULL) /* Already was initialized */
return;

/* Try to load kiconv.dll, iconv2.dll or iconv.dll */
if (!_loadDLL("KICONV", "_libiconv_open", "_libiconv", "_libiconv_close") &&
!_loadDLL("ICONV2", "_libiconv_open", "_libiconv", "_libiconv_close") &&
!_loadDLL("ICONV", "_iconv_open", "_iconv", "_iconv_close") ) {
/* No DLL was loaded - use OS/2 conversion objects API */
debug("Uni*() API used");
fn_iconv_open = os2_iconv_open;
fn_iconv = os2_iconv;
fn_iconv_close = os2_iconv_close;
}
}


// Public routines.
// ----------------
/* Public routines.
* ----------------
*/

// Non-standard function for iconv to unload the used dynamic library.
void libiconv_clean()
/* Non-standard function for iconv to unload the used dynamic library */
void libiconv_clean(void)
{
if ( hmIconv != NULLHANDLE )
{
DosFreeModule( hmIconv );
hmIconv = NULLHANDLE;
if (hmIconv != NULLHANDLE) {
DosFreeModule(hmIconv);
hmIconv = NULLHANDLE;

fn_iconv_open = NULL;
fn_iconv = NULL;
fn_iconv_close = NULL;
}
fn_iconv_open = NULL;
fn_iconv = NULL;
fn_iconv_close = NULL;
}
}

iconv_t libiconv_open(const char* tocode, const char* fromcode)
{
_init();
return fn_iconv_open( tocode, fromcode );
_init();
return fn_iconv_open(tocode, fromcode);
}

size_t libiconv(iconv_t cd, char* * inbuf, size_t *inbytesleft,
char* * outbuf, size_t *outbytesleft)
{
return fn_iconv( cd, inbuf, inbytesleft, outbuf, outbytesleft );
return fn_iconv(cd, inbuf, inbytesleft, outbuf, outbytesleft);
}

int libiconv_close(iconv_t cd)
{
return fn_iconv_close( cd );
return fn_iconv_close(cd);
}

/* vi: set ts=4 sw=4 expandtab: */
55 changes: 30 additions & 25 deletions src/core/os2/geniconv/geniconv.h
Expand Up @@ -47,34 +47,39 @@

#define iconv_clean libiconv_clean

// Non-standard function for iconv to unload the used dynamic library.
void libiconv_clean();

iconv_t libiconv_open(const char* tocode, const char* fromcode);
size_t libiconv(iconv_t cd, char* * inbuf, size_t *inbytesleft,
char* * outbuf, size_t *outbytesleft);
int libiconv_close(iconv_t cd);

// System codepage <-> UTF-8.

// StrUTF8()
// Coverts string from system cp to UTF-8 (fToUTF8 is not 0) or from UTF-8 to
// the system cp (fToUTF8 is 0). Converted ASCIIZ string will be placed at the
// buffer pcDst, up to cbDst - 1 (for sys->utf8) or 2 (for utf8->sys) bytes.
// Returns the number of bytes written into pcDst, not counting the terminating
// 0 byte(s) or -1 on error.
/* Non-standard function for iconv to unload the used dynamic library */
void libiconv_clean(void);

iconv_t libiconv_open (const char *tocode, const char *fromcode);
int libiconv_close(iconv_t cd);
size_t libiconv (iconv_t cd, char **inbuf, size_t *inbytesleft,
char **outbuf, size_t *outbytesleft);

/* System codepage <-> UTF-8
*
* StrUTF8()
* Coverts string from system cp to UTF-8 (fToUTF8 is not 0) or from UTF-8 to
* the system cp (fToUTF8 is 0). Converted ASCIIZ string will be placed at the
* buffer pcDst, up to cbDst - 1 (for sys->utf8) or 2 (for utf8->sys) bytes.
* Returns the number of bytes written into pcDst, not counting the terminating
* 0 byte(s) or -1 on error.
*/
int StrUTF8(int fToUTF8, char *pcDst, int cbDst, char *pcSrc, int cbSrc);

// StrUTF8New()
// Coverts string from system cp to UTF-8 (fToUTF8 is not 0) or from UTF-8 to
// the system cp (fToUTF8 is 0). Memory for the new string is obtained by
// using libc malloc().
// Returns converted string, terminating two bytes 0 is appended to the result.
// Returns null on error.
/* StrUTF8New()
* Coverts string from system cp to UTF-8 (fToUTF8 is not 0) or from UTF-8 to
* the system cp (fToUTF8 is 0). Memory for the new string is obtained by
* using libc malloc().
* Returns converted string, terminating two bytes 0 is appended to the result.
* Returns null on error.
*/
char *StrUTF8New(int fToUTF8, char *pcStr, int cbStr);

// StrUTF8Free()
// Deallocates the memory block located by StrUTF8New() (just libc free()).
/* StrUTF8Free()
* Deallocates the memory block located by StrUTF8New() (just libc free()).
*/
void StrUTF8Free(char *pszStr);

#endif // GENICONV_H
#endif /* GENICONV_H */

/* vi: set ts=4 sw=4 expandtab: */

0 comments on commit a90f040

Please sign in to comment.