marrub
/
LoveToken
Archived
1
0
Fork 0

everything is broken aaa

master
Marrub 2015-06-06 09:28:04 -04:00
parent c9f001c238
commit 214a3a7517
3 changed files with 95 additions and 23 deletions

View File

@ -35,6 +35,8 @@ typedef struct
bool doConvert;
const char *fromCode;
const char *toCode;
const char *stringChars;
const char *charChars; // [marrub] heh
} LT_InitInfo;
typedef struct

114
src/lt.c
View File

@ -40,6 +40,12 @@ static LT_InitInfo info;
static iconv_t icDesc;
static bool assertError = false;
static const char *assertString;
static char *stringChars, *charChars;
static const char *errors[] = {
"LT_Error: Syntax error",
"LT_Error: Unknown operation"
};
char *LT_TkNames[] = {
// [marrub] So, this was an interesting bug. This was completely misordered from the enum.
@ -53,11 +59,6 @@ char *LT_TkNames[] = {
"TOK_Identi", "TOK_EOF", "TOK_ChrSeq"
};
static const char *errors[] = {
"LT_Error: Syntax error",
"LT_Error: Unknown operation"
};
/*
* Functions
*/
@ -83,16 +84,6 @@ void LT_Init(LT_InitInfo initInfo)
if(info.doConvert && info.fromCode != NULL && info.toCode != NULL)
{
if(strcmp(info.fromCode, "UTF8"))
{
info.fromCode = "UTF-8";
}
if(strcmp(info.toCode, "UTF8"))
{
info.toCode = "UTF-8";
}
icDesc = iconv_open(info.toCode, info.fromCode);
if(icDesc == (iconv_t) -1)
@ -110,6 +101,62 @@ void LT_Init(LT_InitInfo initInfo)
info.stripInvalid = false;
}
if(info.stringChars != NULL)
{
int i;
stringChars = malloc(6);
for(i = 0; i < 6; i++)
{
char c = info.stringChars[i];
if(c != '\0')
{
stringChars[i] = c;
}
else
{
break;
}
}
stringChars[i] = '\0';
info.stringChars = NULL; // [marrub] don't use this after init
}
else
{
stringChars = "\"";
}
if(info.charChars != NULL)
{
int i;
charChars = malloc(6);
for(i = 0; i < 6; i++)
{
char c = info.charChars[i];
if(c != '\0')
{
charChars[i] = c;
}
else
{
break;
}
}
charChars[i] = '\0';
info.charChars = NULL; // [marrub] don't use this after init
}
else
{
charChars = "'";
}
gbHead = malloc(sizeof(LT_GarbageList));
gbHead->next = NULL;
gbHead->ptr = NULL;
@ -124,6 +171,8 @@ void LT_Quit()
iconv_close(icDesc);
}
free(stringChars);
gbRover = gbHead;
while(gbRover != NULL)
@ -538,19 +587,38 @@ LT_Token LT_GetToken()
}
return tk;
case '"': case '\'':
tk.string = LT_ReadString(c);
}
for(size_t i = 0; i < 6;)
{
char cc = stringChars[i++];
if(c == '"')
if(cc == '\0')
{
break;
}
else if(c == cc)
{
tk.string = LT_ReadString(c);
tk.token = LT_TkNames[TOK_String];
return tk;
}
else
{
tk.token = LT_TkNames[TOK_Charac];
}
}
for(size_t i = 0; i < 6;)
{
char cc = charChars[i++];
return tk;
if(cc == '\0')
{
break;
}
else if(c == cc)
{
tk.string = LT_ReadString(c);
tk.token = LT_TkNames[TOK_Charac];
return tk;
}
}
if(isdigit(c))

View File

@ -72,6 +72,8 @@ typedef struct
bool doConvert;
const char *fromCode;
const char *toCode;
const char *stringChars;
const char *charChars; // [marrub] heh
} LT_InitInfo;
typedef struct