KAY NEVERMIND TODAY I LEARNED MSVC HAS ABSOLUTELY NOTHING AND IS HORRIBLE IN EVERY POSSIBLE WAY IT COULD BE.
This commit is contained in:
parent
58319b43a1
commit
4fbd5b7c0a
|
@ -4,5 +4,7 @@ You can compile with the LT_NO_ICONV definition to disable iconv.
|
||||||
Compile lt.c to an object file and statically or dynamically link it with
|
Compile lt.c to an object file and statically or dynamically link it with
|
||||||
your application. That's it. Don't forget to include lt.h.
|
your application. That's it. Don't forget to include lt.h.
|
||||||
|
|
||||||
|
If you don't want to export it to a DLL/SO/whatever, define LT_NO_EXPORT.
|
||||||
|
|
||||||
Also, compiling with GDCC ( http://github.com/DavidPH/GDCC ) works.
|
Also, compiling with GDCC ( http://github.com/DavidPH/GDCC ) works.
|
||||||
It will automatically omit iconv and use some specialized functions to work.
|
It will automatically omit iconv and use some specialized functions to work.
|
||||||
|
|
|
@ -28,11 +28,13 @@ local tokenizer = {}
|
||||||
|
|
||||||
local loveToken = ffi.load("LoveToken")
|
local loveToken = ffi.load("LoveToken")
|
||||||
ffi.cdef([[
|
ffi.cdef([[
|
||||||
|
typedef int LT_BOOL;
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
bool escapeChars;
|
LT_BOOL escapeChars;
|
||||||
bool stripInvalid;
|
LT_BOOL stripInvalid;
|
||||||
bool doConvert;
|
LT_BOOL doConvert;
|
||||||
const char *fromCode;
|
const char *fromCode;
|
||||||
const char *toCode;
|
const char *toCode;
|
||||||
const char *stringChars;
|
const char *stringChars;
|
||||||
|
@ -41,33 +43,33 @@ typedef struct
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
char *token;
|
const char *token;
|
||||||
char *string;
|
char *string;
|
||||||
int pos;
|
int pos;
|
||||||
} LT_Token;
|
} LT_Token;
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
bool failure;
|
LT_BOOL failure;
|
||||||
const char *str;
|
const char *str;
|
||||||
} LT_AssertInfo;
|
} LT_AssertInfo;
|
||||||
|
|
||||||
void LT_Init(LT_Config initCfg);
|
void LT_Init(LT_Config initCfg);
|
||||||
void LT_SetConfig(LT_Config newCfg);
|
void LT_SetConfig(LT_Config newCfg);
|
||||||
void LT_Quit();
|
void LT_Quit(void);
|
||||||
|
|
||||||
bool LT_Assert(bool assertion, const char *str, ...);
|
LT_BOOL LT_Assert(LT_BOOL assertion, const char *fmt, ...);
|
||||||
LT_AssertInfo LT_CheckAssert();
|
LT_AssertInfo LT_CheckAssert(void);
|
||||||
|
|
||||||
bool LT_OpenFile(const char *filePath);
|
LT_BOOL LT_OpenFile(const char *filePath);
|
||||||
void LT_SetPos(int newPos);
|
void LT_SetPos(int newPos);
|
||||||
void LT_CloseFile();
|
void LT_CloseFile(void);
|
||||||
|
|
||||||
char *LT_ReadNumber();
|
char *LT_ReadNumber(void);
|
||||||
char *LT_ReadString(char term);
|
char *LT_ReadString(char term);
|
||||||
char *LT_Escaper(char *str, size_t pos, char escape);
|
char *LT_Escaper(char *str, size_t pos, char escape);
|
||||||
LT_Token LT_GetToken();
|
LT_Token LT_GetToken(void);
|
||||||
void LT_SkipWhite();
|
void LT_SkipWhite(void);
|
||||||
]])
|
]])
|
||||||
|
|
||||||
local pReturn
|
local pReturn
|
||||||
|
|
32
src/lt.c
32
src/lt.c
|
@ -251,7 +251,7 @@ void LT_Init(LT_Config initCfg)
|
||||||
|
|
||||||
if(cfg.stringChars != NULL)
|
if(cfg.stringChars != NULL)
|
||||||
{
|
{
|
||||||
int i;
|
unsigned i;
|
||||||
|
|
||||||
stringChars = LT_Alloc(6);
|
stringChars = LT_Alloc(6);
|
||||||
|
|
||||||
|
@ -276,7 +276,7 @@ void LT_Init(LT_Config initCfg)
|
||||||
|
|
||||||
if(cfg.charChars != NULL)
|
if(cfg.charChars != NULL)
|
||||||
{
|
{
|
||||||
int i;
|
unsigned i;
|
||||||
|
|
||||||
charChars = LT_Alloc(6);
|
charChars = LT_Alloc(6);
|
||||||
|
|
||||||
|
@ -338,7 +338,7 @@ void LT_SetConfig(LT_Config newCfg)
|
||||||
|
|
||||||
if(cfg.stringChars != NULL)
|
if(cfg.stringChars != NULL)
|
||||||
{
|
{
|
||||||
int i;
|
unsigned i;
|
||||||
|
|
||||||
stringChars = LT_Alloc(6);
|
stringChars = LT_Alloc(6);
|
||||||
|
|
||||||
|
@ -363,7 +363,7 @@ void LT_SetConfig(LT_Config newCfg)
|
||||||
|
|
||||||
if(cfg.charChars != NULL)
|
if(cfg.charChars != NULL)
|
||||||
{
|
{
|
||||||
int i;
|
unsigned i;
|
||||||
|
|
||||||
charChars = LT_Alloc(6);
|
charChars = LT_Alloc(6);
|
||||||
|
|
||||||
|
@ -430,13 +430,13 @@ LT_BOOL LT_Assert(LT_BOOL assertion, const char *fmt, ...)
|
||||||
assertError = LT_TRUE;
|
assertError = LT_TRUE;
|
||||||
assertString = malloc(512);
|
assertString = malloc(512);
|
||||||
|
|
||||||
snprintf(ftString, 16, ":%ld:", ftell(parseFile));
|
sprintf(ftString, ":%ld:", ftell(parseFile));
|
||||||
|
|
||||||
va_start(va, fmt);
|
va_start(va, fmt);
|
||||||
vsnprintf(asBuffer, 512, fmt, va);
|
vsprintf(asBuffer, fmt, va);
|
||||||
va_end(va);
|
va_end(va);
|
||||||
|
|
||||||
snprintf(assertString, 512, "%s%s", ftString, asBuffer);
|
sprintf(assertString, "%s%s", ftString, asBuffer);
|
||||||
|
|
||||||
LT_SetGarbage(assertString);
|
LT_SetGarbage(assertString);
|
||||||
}
|
}
|
||||||
|
@ -606,6 +606,8 @@ char *LT_ReadString(char term)
|
||||||
|
|
||||||
char *LT_Escaper(char *str, size_t pos, char escape)
|
char *LT_Escaper(char *str, size_t pos, char escape)
|
||||||
{
|
{
|
||||||
|
unsigned i;
|
||||||
|
|
||||||
switch(escape)
|
switch(escape)
|
||||||
{
|
{
|
||||||
case '\\': case '\'': case '"': str[pos] = escape; break;
|
case '\\': case '\'': case '"': str[pos] = escape; break;
|
||||||
|
@ -617,7 +619,7 @@ char *LT_Escaper(char *str, size_t pos, char escape)
|
||||||
case 't': str[pos] = '\t'; break;
|
case 't': str[pos] = '\t'; break;
|
||||||
case 'v': str[pos] = '\v'; break;
|
case 'v': str[pos] = '\v'; break;
|
||||||
case 'x': // [marrub] THIS ONE IS FUN
|
case 'x': // [marrub] THIS ONE IS FUN
|
||||||
for(unsigned int i = 0;;)
|
for(i = 0;;)
|
||||||
{
|
{
|
||||||
int c = fgetc(parseFile);
|
int c = fgetc(parseFile);
|
||||||
|
|
||||||
|
@ -653,9 +655,11 @@ char *LT_Escaper(char *str, size_t pos, char escape)
|
||||||
case '4': case '5': case '6': case '7':
|
case '4': case '5': case '6': case '7':
|
||||||
{
|
{
|
||||||
int c = escape;
|
int c = escape;
|
||||||
unsigned int i = 0;
|
unsigned n;
|
||||||
|
|
||||||
for(unsigned int n = 2; n != 0; n--)
|
i = 0;
|
||||||
|
|
||||||
|
for(n = 2; n != 0; n--)
|
||||||
{
|
{
|
||||||
switch(c)
|
switch(c)
|
||||||
{
|
{
|
||||||
|
@ -914,7 +918,9 @@ LT_Token LT_GetToken()
|
||||||
|
|
||||||
if(stringChars[0] != '\0')
|
if(stringChars[0] != '\0')
|
||||||
{
|
{
|
||||||
for(size_t i = 0; i < 6;)
|
unsigned i;
|
||||||
|
|
||||||
|
for(i = 0; i < 6;)
|
||||||
{
|
{
|
||||||
char cc = stringChars[i++];
|
char cc = stringChars[i++];
|
||||||
|
|
||||||
|
@ -933,7 +939,9 @@ LT_Token LT_GetToken()
|
||||||
|
|
||||||
if(charChars[0] != '\0')
|
if(charChars[0] != '\0')
|
||||||
{
|
{
|
||||||
for(size_t i = 0; i < 6;)
|
unsigned i;
|
||||||
|
|
||||||
|
for(i = 0; i < 6;)
|
||||||
{
|
{
|
||||||
char cc = charChars[i++];
|
char cc = charChars[i++];
|
||||||
|
|
||||||
|
|
56
src/lt.h
56
src/lt.h
|
@ -41,12 +41,20 @@ THE SOFTWARE.
|
||||||
// [marrub] When using in FFI, remove this from the declarations.
|
// [marrub] When using in FFI, remove this from the declarations.
|
||||||
// Also make sure to redefine this if your platform is not supported.
|
// Also make sure to redefine this if your platform is not supported.
|
||||||
// (OSX shouldn't need this at all)
|
// (OSX shouldn't need this at all)
|
||||||
#if defined(_MSC_VER)
|
#ifndef LT_NO_EXPORT
|
||||||
#define LT_EXPORT __declspec(dllexport)
|
#if defined(_MSC_VER)
|
||||||
#elseif defined(_GCC)
|
#define LT_DLLEXPORT __declspec(dllexport)
|
||||||
|
#define LT_EXPORT
|
||||||
|
#elif defined(_GCC)
|
||||||
#define LT_EXPORT __attribute__((visibility("default")))
|
#define LT_EXPORT __attribute__((visibility("default")))
|
||||||
|
#define LT_DLLEXPORT
|
||||||
|
#else
|
||||||
|
#define LT_EXPORT
|
||||||
|
#define LT_DLLEXPORT
|
||||||
|
#endif
|
||||||
#else
|
#else
|
||||||
#define LT_EXPORT
|
#define LT_EXPORT
|
||||||
|
#define LT_DLLEXPORT
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __GDCC__
|
#ifdef __GDCC__
|
||||||
|
@ -81,12 +89,14 @@ enum
|
||||||
* Types
|
* Types
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
typedef int LT_BOOL;
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
bool escapeChars;
|
LT_BOOL escapeChars;
|
||||||
bool stripInvalid;
|
LT_BOOL stripInvalid;
|
||||||
#ifndef LT_NO_ICONV
|
#ifndef LT_NO_ICONV
|
||||||
bool doConvert;
|
LT_BOOL doConvert;
|
||||||
const char *fromCode;
|
const char *fromCode;
|
||||||
const char *toCode;
|
const char *toCode;
|
||||||
#endif
|
#endif
|
||||||
|
@ -103,7 +113,7 @@ typedef struct
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
bool failure;
|
LT_BOOL failure;
|
||||||
const char *str;
|
const char *str;
|
||||||
} LT_AssertInfo;
|
} LT_AssertInfo;
|
||||||
|
|
||||||
|
@ -113,8 +123,6 @@ typedef struct LT_GarbageList_s
|
||||||
void *ptr;
|
void *ptr;
|
||||||
} LT_GarbageList; // [marrub] Don't include this into FFI declarations.
|
} LT_GarbageList; // [marrub] Don't include this into FFI declarations.
|
||||||
|
|
||||||
typedef int LT_BOOL;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Functions
|
* Functions
|
||||||
*/
|
*/
|
||||||
|
@ -123,27 +131,27 @@ typedef int LT_BOOL;
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void LT_EXPORT LT_Init(LT_Config initCfg);
|
LT_DLLEXPORT void LT_EXPORT LT_Init(LT_Config initCfg);
|
||||||
void LT_EXPORT LT_SetConfig(LT_Config newCfg);
|
LT_DLLEXPORT void LT_EXPORT LT_SetConfig(LT_Config newCfg);
|
||||||
void LT_EXPORT LT_Quit(void);
|
LT_DLLEXPORT void LT_EXPORT LT_Quit(void);
|
||||||
|
|
||||||
bool LT_EXPORT LT_Assert(bool assertion, const char *fmt, ...);
|
LT_DLLEXPORT LT_BOOL LT_EXPORT LT_Assert(LT_BOOL assertion, const char *fmt, ...);
|
||||||
void LT_EXPORT LT_Error(int type); // [marrub] C use ONLY
|
LT_DLLEXPORT void LT_EXPORT LT_Error(int type); // [marrub] C use ONLY
|
||||||
LT_AssertInfo LT_EXPORT LT_CheckAssert(void);
|
LT_DLLEXPORT LT_AssertInfo LT_EXPORT LT_CheckAssert(void);
|
||||||
|
|
||||||
#ifndef __GDCC__
|
#ifndef __GDCC__
|
||||||
bool LT_EXPORT LT_OpenFile(const char *filePath);
|
LT_DLLEXPORT LT_BOOL LT_EXPORT LT_OpenFile(const char *filePath);
|
||||||
#else
|
#else
|
||||||
bool LT_EXPORT LT_OpenFile(__str filePath);
|
LT_DLLEXPORT LT_BOOL LT_EXPORT LT_OpenFile(__str filePath);
|
||||||
#endif
|
#endif
|
||||||
void LT_EXPORT LT_SetPos(int newPos);
|
LT_DLLEXPORT void LT_EXPORT LT_SetPos(int newPos);
|
||||||
void LT_EXPORT LT_CloseFile(void);
|
LT_DLLEXPORT void LT_EXPORT LT_CloseFile(void);
|
||||||
|
|
||||||
char *LT_EXPORT LT_ReadNumber(void);
|
LT_DLLEXPORT char *LT_EXPORT LT_ReadNumber(void);
|
||||||
char *LT_EXPORT LT_ReadString(char term);
|
LT_DLLEXPORT char *LT_EXPORT LT_ReadString(char term);
|
||||||
char *LT_EXPORT LT_Escaper(char *str, size_t pos, char escape);
|
LT_DLLEXPORT char *LT_EXPORT LT_Escaper(char *str, size_t pos, char escape);
|
||||||
LT_Token LT_EXPORT LT_GetToken(void);
|
LT_DLLEXPORT LT_Token LT_EXPORT LT_GetToken(void);
|
||||||
void LT_EXPORT LT_SkipWhite(void);
|
LT_DLLEXPORT void LT_EXPORT LT_SkipWhite(void);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
Reference in New Issue
Block a user