Skip to content

Commit

Permalink
Use C89 to make it compile with older toolsets.
Browse files Browse the repository at this point in the history
  • Loading branch information
KrossX committed Nov 21, 2017
1 parent edf36f1 commit bd0f3bb
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 22 deletions.
6 changes: 4 additions & 2 deletions durazno/custom_func.c
Expand Up @@ -8,8 +8,9 @@ static
DWORD cheap_find_last_of(char *string, char c)
{
DWORD charpos = 0;
char *strpos;

for (char *strpos = string; *strpos; strpos++)
for (strpos = string; *strpos; strpos++)
{
if (*strpos == c)
charpos = (DWORD)(strpos - string);
Expand All @@ -34,8 +35,9 @@ int cheap_atoi_n(char *str, int n)
{
// no negative
int num = 0;
char *p;

for (char *p = str; *p && n; p++, n--)
for (p = str; *p && n; p++, n--)
{
if (*p >= '0' && *p <= '9')
num = num * 10 + (*p - '0');
Expand Down
28 changes: 19 additions & 9 deletions durazno/durazno.c
Expand Up @@ -27,15 +27,20 @@ static
BOOL load_xinput_dll(HINSTANCE instance)
{
char sysdir[MAX_PATH];
UINT sysdir_len = GetSystemDirectoryA(sysdir, MAX_PATH);
if (sysdir_len == 0 || sysdir_len >= MAX_PATH) return FALSE;

char modname[MAX_PATH];
DWORD modname_len = GetModuleFileNameA(instance, modname, MAX_PATH);
UINT sysdir_len;
DWORD modname_len;
DWORD namepos;
char *dllpath;

sysdir_len = GetSystemDirectoryA(sysdir, MAX_PATH);
if (sysdir_len == 0 || sysdir_len >= MAX_PATH) return FALSE;

modname_len = GetModuleFileNameA(instance, modname, MAX_PATH);
if (!modname_len) return FALSE;

DWORD namepos = cheap_find_last_of(modname, '\\');
char *dllpath = lstrcatA(sysdir, &modname[namepos]);
namepos = cheap_find_last_of(modname, '\\');
dllpath = lstrcatA(sysdir, &modname[namepos]);
if (!dllpath) return FALSE;

XInput.dll = LoadLibraryA(dllpath);
Expand Down Expand Up @@ -80,12 +85,14 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)

DWORD WINAPI XInputGetState(DWORD dwUserIndex, XINPUT_STATE* pState)
{
DWORD retval;

struct settings *set = &settings[dwUserIndex];

if(set->disabled)
return ERROR_DEVICE_NOT_CONNECTED;

DWORD retval = XInput.GetState(set->index, pState);
retval = XInput.GetState(set->index, pState);

if (retval == ERROR_SUCCESS)
{
Expand Down Expand Up @@ -169,12 +176,14 @@ DWORD WINAPI XInputGetAudioDeviceIds(DWORD dwUserIndex, LPWSTR pRenderDeviceId,

DWORD WINAPI XInputGetStateEx(DWORD dwUserIndex, XINPUT_STATE *pState)
{
DWORD retval;

struct settings *set = &settings[dwUserIndex];

if (set->disabled)
return ERROR_DEVICE_NOT_CONNECTED;

DWORD retval = XInput.GetStateEx(set->index, pState);
retval = XInput.GetStateEx(set->index, pState);

if (retval == ERROR_SUCCESS)
{
Expand Down Expand Up @@ -246,8 +255,9 @@ DWORD WINAPI DuraznoGetStateEx(DWORD dwUserIndex, XINPUT_STATE* pState)
DWORD WINAPI GetControllerInput(DWORD port)
{
XINPUT_STATE state;
int i;

for (int i = 0; i < 100; i++)
for (i = 0; i < 100; i++)
{
if (DuraznoGetState(port, &state) != ERROR_SUCCESS)
return (DWORD)-1;
Expand Down
27 changes: 19 additions & 8 deletions durazno/file_io.c
Expand Up @@ -18,7 +18,9 @@ void load_remap(char *secbuf, struct remap *remap)

if (length != 71)
{
for (int i = 0; i < 24; i++)
int i;

for (i = 0; i < 24; i++)
{
remap[i].control = i;

Expand All @@ -29,7 +31,9 @@ void load_remap(char *secbuf, struct remap *remap)
}
else
{
for (int i = 0; i < 24; i++, secdata += 3)
int i;

for (i = 0; i < 24; i++, secdata += 3)
{
int control = remap[i].control = cheap_atoi_n(secdata, 2);

Expand Down Expand Up @@ -58,10 +62,12 @@ void load_remap(char *secbuf, struct remap *remap)
static
void save_remap(char *secbuf, struct remap *remap)
{
int i;

wsprintfA(secbuf, "Remap=");
secbuf = next_str(secbuf) - 1;

for (int i = 0; i < 24; i++, secbuf += 3)
for (i = 0; i < 24; i++, secbuf += 3)
{
wsprintfA(secbuf, "%02d ", remap[i].control);
}
Expand Down Expand Up @@ -109,6 +115,8 @@ void toggle_inverted(struct settings *set)
static
void ini_load(void)
{
int port;

if (GetPrivateProfileIntA("General", "INIVersion", 0, INI_FILENAME) != INI_VERSION)
{
// clear the file or something
Expand All @@ -117,7 +125,7 @@ void ini_load(void)

GetPrivateProfileStringA("General", "LoadDLL", "", custom_dll, MAX_PATH, INI_FILENAME);

for (int port = 0; port < 4; port++)
for (port = 0; port < 4; port++)
{
struct settings *set = &settings[port];
wsprintfA(fileiobuf, "Controller%d", port);
Expand Down Expand Up @@ -164,6 +172,7 @@ void ini_load(void)
static
void ini_save(void)
{
int port;
char *secbuf = fileiobuf;

wsprintfA(secbuf, "INIversion=%d", INI_VERSION); secbuf = next_str(secbuf);
Expand All @@ -172,13 +181,15 @@ void ini_save(void)

WritePrivateProfileSectionA("General", fileiobuf, INI_FILENAME);

for (int port = 0; port < 4; port++)
for (port = 0; port < 4; port++)
{
struct settings *set = &settings[port];
char *section;
char *secdata;

char *section = fileiobuf;
section = fileiobuf;
wsprintfA(section, "Controller%d", port);
char *secdata = next_str(section);
secdata = next_str(section);

secbuf = secdata;
wsprintfA(secbuf, "Port=%d", set->index); secbuf = next_str(secbuf);
Expand Down
6 changes: 3 additions & 3 deletions makefile
@@ -1,7 +1,7 @@
#NMAKE

CC_FLAGS = /c /O2 /GL /D _USING_V110_SDK71_ /D _WINDLL /D _MBCS /MD /GS- /nologo
LINKER_FLAGS = /NODEFAULTLIB /MANIFEST:NO /SUBSYSTEM:WINDOWS /OPT:REF /OPT:ICF /LTCG /ENTRY:"DllMain" /DYNAMICBASE:NO /NXCOMPAT /SAFESEH:NO /DLL /NOLOGO
CC_FLAGS = /c /O1 /Oi /fp:fast /GS- /GR- /MT /nologo /Wall
LINKER_FLAGS = /DLL /SUBSYSTEM:WINDOWS /MANIFEST:NO /NOLOGO

SOURCE = durazno\durazno.c

Expand All @@ -14,7 +14,7 @@ all: $(TARGETS)
@del build\*.lib

durazno.obj:
@cl $(CC_FLAGS) $(SOURCE) -Fo:durazno.obj
@cl $(CC_FLAGS) $(SOURCE) /Fodurazno.obj

$(TARGETS): durazno.obj
@link durazno.obj kernel32.lib user32.lib $(LINKER_FLAGS) /DEF:durazno\$(@).def /OUT:build\$(@).dll
Expand Down

0 comments on commit bd0f3bb

Please sign in to comment.