marrub
/
LoveToken
Archived
1
0
Fork 0

fixed linux make, added some features

master
Marrub 2015-06-07 03:46:36 -04:00
parent 0c758e3f63
commit 1cb7804fe1
3 changed files with 120 additions and 24 deletions

View File

@ -17,7 +17,7 @@ else
CC+=gcc CC+=gcc
MKDIR+=mkdir -p MKDIR+=mkdir -p
PCFLAGS+=-fPIC PCFLAGS+=-fPIC
LIBNAME+=$(OUTDIR)/lovetoken.so LIBNAME+=$(OUTDIR)/LoveToken.so
endif endif
endif endif

131
src/lt.c
View File

@ -36,7 +36,7 @@ THE SOFTWARE.
static LT_GarbageList *gbHead, *gbRover; static LT_GarbageList *gbHead, *gbRover;
static FILE *parseFile; static FILE *parseFile;
static LT_InitInfo info; static LT_Config cfg;
static iconv_t icDesc; static iconv_t icDesc;
static bool assertError = false; static bool assertError = false;
static char *assertString; static char *assertString;
@ -115,7 +115,7 @@ static void *LT_SetGarbage(void *p)
return gbRover->ptr; return gbRover->ptr;
} }
void LT_Init(LT_InitInfo initInfo) void LT_Init(LT_Config initCfg)
{ {
gbHead = LT_Alloc(sizeof(LT_GarbageList)); gbHead = LT_Alloc(sizeof(LT_GarbageList));
gbHead->next = NULL; gbHead->next = NULL;
@ -123,11 +123,11 @@ void LT_Init(LT_InitInfo initInfo)
gbRover = gbHead; gbRover = gbHead;
info = initInfo; cfg = initCfg;
if(info.doConvert && info.fromCode != NULL && info.toCode != NULL) if(cfg.doConvert && cfg.fromCode != NULL && cfg.toCode != NULL)
{ {
icDesc = iconv_open(info.toCode, info.fromCode); icDesc = iconv_open(cfg.toCode, cfg.fromCode);
if(icDesc == (iconv_t) -1) if(icDesc == (iconv_t) -1)
{ {
@ -136,15 +136,15 @@ void LT_Init(LT_InitInfo initInfo)
} }
else else
{ {
info.doConvert = false; cfg.doConvert = false;
} }
if(info.stripInvalid && info.doConvert) if(cfg.stripInvalid && cfg.doConvert)
{ {
info.stripInvalid = false; cfg.stripInvalid = false;
} }
if(info.stringChars != NULL) if(cfg.stringChars != NULL)
{ {
int i; int i;
@ -152,7 +152,7 @@ void LT_Init(LT_InitInfo initInfo)
for(i = 0; i < 6; i++) for(i = 0; i < 6; i++)
{ {
int c = info.stringChars[i]; int c = cfg.stringChars[i];
if(c != '\0') if(c != '\0')
{ {
@ -169,7 +169,7 @@ void LT_Init(LT_InitInfo initInfo)
LT_SetGarbage(stringChars); LT_SetGarbage(stringChars);
} }
if(info.charChars != NULL) if(cfg.charChars != NULL)
{ {
int i; int i;
@ -177,7 +177,92 @@ void LT_Init(LT_InitInfo initInfo)
for(i = 0; i < 6; i++) for(i = 0; i < 6; i++)
{ {
int c = info.charChars[i]; int c = cfg.charChars[i];
if(c != '\0')
{
charChars[i] = c;
}
else
{
break;
}
}
charChars[i] = '\0';
LT_SetGarbage(charChars);
}
}
void LT_SetConfig(LT_Config newCfg)
{
cfg = newCfg;
if(cfg.doConvert && cfg.fromCode != NULL && cfg.toCode != NULL)
{
if(icDesc != NULL)
{
iconv_close(icDesc);
}
icDesc = iconv_open(cfg.toCode, cfg.fromCode);
if(icDesc == (iconv_t) -1)
{
LT_Assert(true, "LT_Init: Failure opening iconv");
}
}
else
{
if(icDesc != NULL)
{
iconv_close(icDesc);
icDesc = NULL;
}
cfg.doConvert = false;
}
if(cfg.stripInvalid && cfg.doConvert)
{
cfg.stripInvalid = false;
}
if(cfg.stringChars != NULL)
{
int i;
stringChars = LT_Alloc(6);
for(i = 0; i < 6; i++)
{
int c = cfg.stringChars[i];
if(c != '\0')
{
stringChars[i] = c;
}
else
{
break;
}
}
stringChars[i] = '\0';
LT_SetGarbage(stringChars);
}
if(cfg.charChars != NULL)
{
int i;
charChars = LT_Alloc(6);
for(i = 0; i < 6; i++)
{
int c = cfg.charChars[i];
if(c != '\0') if(c != '\0')
{ {
@ -197,7 +282,7 @@ void LT_Init(LT_InitInfo initInfo)
void LT_Quit() void LT_Quit()
{ {
if(info.doConvert) if(cfg.doConvert)
{ {
iconv_close(icDesc); iconv_close(icDesc);
} }
@ -269,6 +354,14 @@ bool LT_OpenFile(const char *filePath)
return true; return true;
} }
void LT_SetPos(int newPos)
{
if(fseek(parseFile, newPos, SEEK_SET) != 0)
{
LT_Assert(ferror(parseFile), "LT_SetPos: Failed to set position");
}
}
void LT_CloseFile() void LT_CloseFile()
{ {
if(parseFile != NULL) if(parseFile != NULL)
@ -300,7 +393,7 @@ char *LT_ReadNumber()
str[i++] = c; str[i++] = c;
if(info.stripInvalid) if(cfg.stripInvalid)
{ {
str[i++] = (isspace(c) || isprint(c)) ? c : ' '; str[i++] = (isspace(c) || isprint(c)) ? c : ' ';
} }
@ -308,7 +401,7 @@ char *LT_ReadNumber()
str[i++] = '\0'; str[i++] = '\0';
if(info.doConvert) if(cfg.doConvert)
{ {
LT_DoConvert(&str); LT_DoConvert(&str);
} }
@ -339,7 +432,7 @@ char *LT_ReadString(char term)
return LT_SetGarbage(emptyString); return LT_SetGarbage(emptyString);
} }
if(c == '\\' && info.escapeChars) if(c == '\\' && cfg.escapeChars)
{ {
c = fgetc(parseFile); c = fgetc(parseFile);
@ -365,7 +458,7 @@ char *LT_ReadString(char term)
str[i++] = c; str[i++] = c;
if(info.stripInvalid) if(cfg.stripInvalid)
{ {
str[i++] = (isspace(c) || isprint(c)) ? c : ' '; str[i++] = (isspace(c) || isprint(c)) ? c : ' ';
} }
@ -374,7 +467,7 @@ char *LT_ReadString(char term)
str[i++] = '\0'; str[i++] = '\0';
if(info.doConvert) if(cfg.doConvert)
{ {
LT_DoConvert(&str); LT_DoConvert(&str);
} }
@ -755,7 +848,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.
if(info.doConvert) if(cfg.doConvert)
{ {
LT_DoConvert(&str); LT_DoConvert(&str);
} }

View File

@ -37,7 +37,7 @@ THE SOFTWARE.
// [marrub] This can be changed if you have either a lot of very // [marrub] This can be changed if you have either a lot of very
// long strings, or a lot of very small strings, for optimization. // long strings, or a lot of very small strings, for optimization.
#define TOKEN_STR_BLOCK_LENGTH 512 #define TOKEN_STR_BLOCK_LENGTH 128
// [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.
@ -84,7 +84,7 @@ typedef struct
const char *toCode; const char *toCode;
const char *stringChars; const char *stringChars;
const char *charChars; const char *charChars;
} LT_InitInfo; } LT_Config;
typedef struct typedef struct
{ {
@ -109,13 +109,16 @@ typedef struct LT_GarbageList_s
* Functions * Functions
*/ */
void LT_EXPORT LT_Init(LT_InitInfo initInfo); void LT_EXPORT LT_Init(LT_Config initCfg);
void LT_EXPORT LT_SetConfig(LT_Config newCfg);
void LT_EXPORT LT_Quit(); void LT_EXPORT LT_Quit();
bool LT_EXPORT LT_Assert(bool assertion, const char *str); bool LT_EXPORT LT_Assert(bool assertion, const char *str);
LT_AssertInfo LT_EXPORT LT_CheckAssert();
void LT_EXPORT LT_Error(int type); // [marrub] C use ONLY void LT_EXPORT LT_Error(int type); // [marrub] C use ONLY
LT_AssertInfo LT_EXPORT LT_CheckAssert();
bool LT_EXPORT LT_OpenFile(const char *filePath); bool LT_EXPORT LT_OpenFile(const char *filePath);
void LT_EXPORT LT_SetPos(int newPos);
void LT_EXPORT LT_CloseFile(); void LT_EXPORT LT_CloseFile();
char *LT_EXPORT LT_ReadNumber(); char *LT_EXPORT LT_ReadNumber();