Skip to content
This repository has been archived by the owner on Dec 25, 2023. It is now read-only.

Commit

Permalink
DLL Projects:
Browse files Browse the repository at this point in the history
- CONFIG.DLL: Finished!
    - Fixed div.h include using a header file, DIVFIO.H, as bridge between CONFIG.CPP and minGlue-DIV.h using function pointers.
    - minIni.h: Commented all code related with C++ implementation.
    - minIni.cpp: Added new line before write section header, and added space separators to '=' assignation character.
- MATH.CPP: Style improvements.
- COMMON.CPP: Minor improvements applied.
- MAKE.BAT: Added line to copy to DIV2 DLL folder.
- Updated DLLTEST.PRG.
  • Loading branch information
José Miguel Sánchez Fernández committed May 29, 2020
1 parent 5029b52 commit ac312f4
Show file tree
Hide file tree
Showing 13 changed files with 220 additions and 143 deletions.
21 changes: 13 additions & 8 deletions DLL/COMMON.CPP
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,29 @@

void strCase(char* str, const int mode)
{
if (str == NULL || strlen(str) == 0) return;
int len = strlen(str);
if (str == NULL || len == 0) return;

for(int i = 0; i < strlen(str); i++)
for(int i = 0; i < len; i++)
{
str[i] = mode ? tolower(str[i]) : toupper(str[i]);
}
}

void strTrim(char* str)
{
if (str == NULL || strlen(str) == 0) return;
int len = strlen(str);

if (str == NULL || len == 0) return;

int s, e, i;

for (s = 0; s < strlen(str); s++)
for (s = 0; s < len; s++)
{
if (str[s] != ' ') break;
}

for (e = strlen(str) - 1; e >= 0; e--)
for (e = len - 1; e >= 0; e--)
{
if (str[e] != ' ')
{
Expand All @@ -46,10 +49,12 @@ void strTrim(char* str)

void strReplace(char * str, const char o, const char n)
{
if (str == NULL || strlen(str) == 0) return;
int len = strlen(str);

if (str == NULL || len == 0) return;

for (int i = 0; i < strlen(str); i++)
for (int i = 0; i < len; i++)
{
if (str[i] == o) str[i] = n;
}
}
}
2 changes: 1 addition & 1 deletion DLL/COMMON.H
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#ifndef __COMMON_H_
#define __COMMON_H_

#include <stdlib.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
Expand Down
Binary file added DLL/CONFIG.DLL
Binary file not shown.
35 changes: 19 additions & 16 deletions DLL/CONFIG/CONFIG.CPP
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*
* @param {string} filename - INI filename.
*/
void openFile()
void setFile()
{
filename = getStrParm();
retval(RESULT_OK);
Expand All @@ -46,7 +46,7 @@ void readBool()
{
int defValue = getparm();
char* key = getStrParm();

retval((int)ini_getbool(section, key, defValue, filename));
}

Expand All @@ -61,7 +61,7 @@ void readInt()
{
int defValue = getparm();
char* key = getStrParm();

retval((int)ini_getl(section, key, defValue, filename));
}

Expand All @@ -76,9 +76,9 @@ void readInt()
void readString()
{
char* dest = getStrParm();
int defValue = getparm();
char* defValue = getStrParm();
char* key = getStrParm();

retval(ini_gets(section, key, defValue, dest, TEMP_BUFFER, filename));
}

Expand All @@ -93,7 +93,7 @@ void writeBool()
{
int value = getparm();
char* key = getStrParm();

retval(ini_puts(section,
key,
value % 2 == 0 ?
Expand All @@ -113,7 +113,7 @@ void writeInt()
{
int value = getparm();
char* key = getStrParm();

retval(ini_putl(section, key, (long)value, filename));
}

Expand All @@ -128,20 +128,23 @@ void writeString()
{
char* value = getStrParm();
char* key = getStrParm();

retval(ini_puts(section, key, value, filename));
}

void __export divlibrary(LIBRARY_PARAMS)
{
COM_export("config_open_file", openFile, 1);
COM_export("config_set_section", setSection, 1);
COM_export("config_read_bool", readBool, 2);
COM_export("config_read_int", readInt, 2);
COM_export("config_read_string", readString, 3);
COM_export("config_write_bool", writeBool, 2);
COM_export("config_write_int", writeInt, 2);
COM_export("config_write_string", writeString, 2);
file_open = div_fopen;
file_close = div_fclose;

COM_export("config_set_file", setFile, 1);
COM_export("config_set_section", setSection, 1);
COM_export("config_read_bool", readBool, 2);
COM_export("config_read_int", readInt, 2);
COM_export("config_read_string", readString, 3);
COM_export("config_write_bool", writeBool, 2);
COM_export("config_write_int", writeInt, 2);
COM_export("config_write_string", writeString, 2);
}

void __export divmain(COMMON_PARAMS)
Expand Down
3 changes: 2 additions & 1 deletion DLL/CONFIG/CONFIG.H
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@
#define __CONFIG_H_

#include "..\common.h"
#include "divfio.h"
#include "minIni.h"

#define TEMP_BUFFER 256

char* filename;
char* section;

void openFile();
void setFile();
void setSection();

void readBool();
Expand Down
18 changes: 18 additions & 0 deletions DLL/CONFIG/DIVFIO.H
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/* FIX: For any reason, if you include div.h in any minGlue.h definition
* to replace stdio.h fopen() and fclose() by div_fopen() and div_fclose()
* this broken minIni.cpp at compiltation time.
*
* This header makes a bridge between config.cpp and minGlue-DIV.h to
* allow share div_fopen() and div_fclose() functions using pointers
* without need to include div.h.
*/

#ifndef __DIVFIO_H_
#define __DIVFIO_H_

#include <stdio.h>

FILE *(*file_open)(char*, char*);
void (*file_close)(FILE*);

#endif
2 changes: 1 addition & 1 deletion DLL/CONFIG/MAKE.BAT
Original file line number Diff line number Diff line change
@@ -1 +1 @@
wcl386 CONFIG.CPP minIni.c ..\COMMON.CPP /l=div_dll -s
wcl386 CONFIG.CPP ..\COMMON.CPP minIni.cpp /l=div_dll -s
23 changes: 10 additions & 13 deletions DLL/CONFIG/minGlue-DIV.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,22 @@
* warranties or conditions of any kind, either express or implied.
*/

/* map required file I/O types and functions to the standard C library and DIV */
#include <stdio.h>
#include "..\div.h"
#define INI_ANSIONLY
#define INI_BUFFERSIZE 256

#include "divfio.h"

#define INI_FILETYPE FILE*
#define ini_openread(filename,file) ((*(file) = div_fopen((filename),"rb")) != NULL)
#define ini_openwrite(filename,file) ((*(file) = div_fopen((filename),"wb")) != NULL)
#define ini_openrewrite(filename,file) ((*(file) = div_fopen((filename),"r+b")) != NULL)
#define ini_close(file) (div_fclose(*(file)) == 0)
#define ini_openread(filename,file) ((*(file) = (*file_open)(((char*)filename),"rb")) != NULL)
#define ini_openwrite(filename,file) ((*(file) = (*file_open)(((char*)filename),"wb")) != NULL)
#define ini_openrewrite(filename,file) ((*(file) = (*file_open)(((char*)filename),"r+b")) != NULL)
#define ini_close(file) ((*file_close)(*(file)))

#define ini_read(buffer,size,file) (fgets((buffer),(size),*(file)) != NULL)
#define ini_write(buffer,file) (fputs((buffer),*(file)) >= 0)
#define ini_rename(source,dest) (rename((source), (dest)) == 0)
#define ini_remove(filename) (remove(filename) == 0)

#define INI_FILEPOS long int
#define INI_FILEPOS int
#define ini_tell(file,pos) (*(pos) = ftell(*(file)))
#define ini_seek(file,pos) (fseek(*(file), *(pos), SEEK_SET) == 0)

/* for floating-point support, define additional types and functions */
#define INI_REAL float
#define ini_ftoa(string,value) sprintf((string),"%f",(value))
#define ini_atof(string) (INI_REAL)strtod((string),NULL)
3 changes: 3 additions & 0 deletions DLL/CONFIG/minIni.c → DLL/CONFIG/minIni.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,7 @@ static void writesection(TCHAR *LocalBuffer, const TCHAR *Section, INI_FILETYPE
{
if (Section != NULL && _tcslen(Section) > 0) {
TCHAR *p;
(void)ini_write(INI_LINETERM, fp); // Added new line before the section header.
LocalBuffer[0] = '[';
ini_strncpy(LocalBuffer + 1, Section, INI_BUFFERSIZE - 4, QUOTE_NONE); /* -1 for '[', -1 for ']', -2 for '\r\n' */
p = _tcschr(LocalBuffer, '\0');
Expand All @@ -560,7 +561,9 @@ static void writekey(TCHAR *LocalBuffer, const TCHAR *Key, const TCHAR *Value, I
ini_strncpy(LocalBuffer, Key, INI_BUFFERSIZE - 3, QUOTE_NONE); /* -1 for '=', -2 for '\r\n' */
p = _tcschr(LocalBuffer, '\0');
assert(p != NULL);
*p++ = ' '; // Added space separator.
*p++ = '=';
*p++ = ' '; // Added space separator.
ini_strncpy(p, Value, INI_BUFFERSIZE - (p - LocalBuffer) - 2, option); /* -2 for '\r\n' */
p = _tcschr(LocalBuffer, '\0');
assert(p != NULL);
Expand Down
Loading

0 comments on commit ac312f4

Please sign in to comment.