Archived
1
0

did some polishing work. fun!

This commit is contained in:
Marrub 2015-07-26 05:36:36 -04:00
parent a3d95d57bd
commit dce1f1b534
4 changed files with 28 additions and 22 deletions

View File

@ -1,6 +1,8 @@
Compiling LoveToken is near trivial since it only needs C99 (and optionally iconv). Compiling LoveToken is trivial since it only needs C99, and optionally iconv.
Build an object file from lt.c (and link it with iconv if you want conversion) into a dll/so/etc. You can compile with the LT_NO_ICONV definition to disable iconv.
You can compile with the NO_ICONV definition to skip iconv requirements.
Also, compiling with GDCC ( http://github.com/DavidPH/GDCC ) is now allowed. 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.
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.

View File

@ -1,4 +1,4 @@
LoveToken is a tokenizer made for usage with LOVE2D's (LuaJIT) FFI. LoveToken is a tokenizer made for usage with LOVE2D's (LuaJIT) FFI.
It also works just as well in C or C++, or really anything that can load C functions. It also works just as well in C or C++, or really anything that can load external C symbols.
See COMPILING.txt for info on compiling. See COMPILING.txt for info on compiling.
Supported platforms (known): Microsoft Windows, Linux, ZDoom, Mac OS X Supported platforms (known): Microsoft Windows, Linux, ZDoom, Mac OS X

View File

@ -33,12 +33,15 @@ THE SOFTWARE.
#ifdef __GDCC__ #ifdef __GDCC__
#include <ACS_Zandronum.h> #include <ACS_Zandronum.h>
#else #else
#ifndef NO_ICONV #ifndef LT_NO_ICONV
#include <iconv.h> #include <iconv.h>
#endif #endif
#endif #endif
#ifdef __GDCC__ #ifdef __GDCC__
// TODO: replace these with GDCC's new file function tables or whatever they're called
#define fopen LT_FOpen #define fopen LT_FOpen
#define ftell LT_FTell #define ftell LT_FTell
#define fgetc LT_FGetC #define fgetc LT_FGetC
@ -63,7 +66,7 @@ static LT_GarbageList *gbHead, *gbRover;
static FILE *parseFile; static FILE *parseFile;
static LT_Config cfg; static LT_Config cfg;
#ifndef NO_ICONV #ifndef LT_NO_ICONV
static iconv_t icDesc; static iconv_t icDesc;
#endif #endif
@ -95,7 +98,7 @@ const char *LT_TkNames[] = {
* Functions * Functions
*/ */
#ifndef NO_ICONV #ifndef LT_NO_ICONV
static void LT_DoConvert(char **str) static void LT_DoConvert(char **str)
{ {
size_t i = strlen(*str); size_t i = strlen(*str);
@ -152,11 +155,11 @@ static void *LT_SetGarbage(void *p)
#ifdef __GDCC__ #ifdef __GDCC__
#define StrParam(...) \ #define StrParam(...) \
( \ ( \
ACS_BeginStrParam(), \ ACS_BeginStrParam(), \
__nprintf(__VA_ARGS__), \ __nprintf(__VA_ARGS__), \
ACS_EndStrParam() \ ACS_EndStrParam() \
) )
#define StrParamL(...) (StrParam("%LS", StrParam(__VA_ARGS__))) #define StrParamL(...) (StrParam("%LS", StrParam(__VA_ARGS__)))
LT_File *LT_FOpen(__str languageId, const char *mode) LT_File *LT_FOpen(__str languageId, const char *mode)
@ -215,6 +218,7 @@ int LT_FClose(LT_File *file)
void LT_Init(LT_Config initCfg) void LT_Init(LT_Config initCfg)
{ {
#ifndef __GDCC__ #ifndef __GDCC__
// [marrub] we don't need a garbage collector in GDCC
gbHead = LT_Alloc(sizeof(LT_GarbageList)); gbHead = LT_Alloc(sizeof(LT_GarbageList));
gbHead->next = NULL; gbHead->next = NULL;
gbHead->ptr = NULL; gbHead->ptr = NULL;
@ -224,7 +228,7 @@ void LT_Init(LT_Config initCfg)
cfg = initCfg; cfg = initCfg;
#ifndef NO_ICONV #ifndef LT_NO_ICONV
if(cfg.doConvert && cfg.fromCode != NULL && cfg.toCode != NULL) if(cfg.doConvert && cfg.fromCode != NULL && cfg.toCode != NULL)
{ {
icDesc = iconv_open(cfg.toCode, cfg.fromCode); icDesc = iconv_open(cfg.toCode, cfg.fromCode);
@ -300,7 +304,7 @@ void LT_SetConfig(LT_Config newCfg)
{ {
cfg = newCfg; cfg = newCfg;
#ifndef NO_ICONV #ifndef LT_NO_ICONV
if(cfg.doConvert && cfg.fromCode != NULL && cfg.toCode != NULL) if(cfg.doConvert && cfg.fromCode != NULL && cfg.toCode != NULL)
{ {
if(icDesc != NULL) if(icDesc != NULL)
@ -385,7 +389,7 @@ void LT_SetConfig(LT_Config newCfg)
void LT_Quit() void LT_Quit()
{ {
#ifndef NO_ICONV #ifndef LT_NO_ICONV
if(cfg.doConvert) if(cfg.doConvert)
{ {
iconv_close(icDesc); iconv_close(icDesc);
@ -434,7 +438,7 @@ bool LT_Assert(bool assertion, const char *fmt, ...)
snprintf(assertString, 512, "%s%s", ftString, asBuffer); snprintf(assertString, 512, "%s%s", ftString, asBuffer);
LT_SetGarbage(LT_ReAlloc(assertString, strlen(assertString) + 1)); LT_SetGarbage(assertString = LT_ReAlloc(assertString, strlen(assertString) + 1));
} }
return assertion; return assertion;
@ -522,7 +526,7 @@ char *LT_ReadNumber()
str[i++] = '\0'; str[i++] = '\0';
#ifndef NO_ICONV #ifndef LT_NO_ICONV
if(cfg.doConvert) if(cfg.doConvert)
{ {
LT_DoConvert(&str); LT_DoConvert(&str);
@ -590,7 +594,7 @@ char *LT_ReadString(char term)
str[i++] = '\0'; str[i++] = '\0';
#ifndef NO_ICONV #ifndef LT_NO_ICONV
if(cfg.doConvert) if(cfg.doConvert)
{ {
LT_DoConvert(&str); LT_DoConvert(&str);
@ -974,7 +978,7 @@ LT_Token LT_GetToken()
str[i++] = '\0'; // [marrub] Completely forgot this line earlier. Really screwed up everything. str[i++] = '\0'; // [marrub] Completely forgot this line earlier. Really screwed up everything.
#ifndef NO_ICONV #ifndef LT_NO_ICONV
if(cfg.doConvert) if(cfg.doConvert)
{ {
LT_DoConvert(&str); LT_DoConvert(&str);

View File

@ -51,7 +51,7 @@ THE SOFTWARE.
#endif #endif
#ifdef __GDCC__ #ifdef __GDCC__
#define NO_ICONV #define LT_NO_ICONV
#endif #endif
enum enum
@ -83,7 +83,7 @@ typedef struct
{ {
bool escapeChars; bool escapeChars;
bool stripInvalid; bool stripInvalid;
#ifndef NO_ICONV #ifndef LT_NO_ICONV
bool doConvert; bool doConvert;
const char *fromCode; const char *fromCode;
const char *toCode; const char *toCode;