Archived
1
0

informative git log

This commit is contained in:
Marrub 2015-06-05 11:14:35 -04:00
parent e28a3f89ce
commit 119cadadc4
5 changed files with 108 additions and 16 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
src/*iconv*
bin/*
test/*
test

View File

@ -3,6 +3,8 @@
all:
mkdir -p bin
mingw32-gcc --std=c99 -g -ggdb -c -o bin/lt.o lt.c
mingw32-gcc -shared -g -ggdb -o bin/LoveToken.dll bin/lt.o -Wl,--out-implib,bin/libLoveToken.a
# cp bin/LoveToken.dll test/LoveToken.dll
mingw32-gcc --std=c99 -g -ggdb -liconv -c -o bin/lt.o src/lt.c -liconv
mingw32-gcc -shared -g -ggdb -liconv -o bin/LoveToken.dll bin/lt.o -Wl,--out-implib,bin/libLoveToken.a -liconv
#mingw32-gcc --std=c99 -g -ggdb -c -o bin/lt.o -DI_FUCKING_HATE_WINDOWS src/lt.c
#mingw32-gcc -shared -g -ggdb -o bin/LoveToken.dll bin/iconv.o bin/lt.o -Wl,--out-implib,bin/libLoveToken.a
#cp bin/LoveToken.dll test/LoveToken.dll

View File

@ -21,17 +21,15 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include <stdbool.h>
#include "lt.h"
FILE *LT_ParseFile;
bool LT_AssertError = false;
LT_GarbageList *gbHead, *gbRover;
static FILE *LT_ParseFile;
static LT_InitInfo info;
static iconv_t icDesc;
static bool LT_AssertError = false;
static const char *LT_AssertString;
static char *tokenTypes[] = {
// [marrub] So, this was an interesting bug. This was completely misordered from the enum.
@ -45,10 +43,35 @@ static char *tokenTypes[] = {
"TOK_Identi", "TOK_EOF", "TOK_ChrSeq"
};
static void LT_DoConvert(char **str)
{
size_t i = strlen(*str);
char *strbuf = calloc((i * 6) + 1, 1);
char *strbufOrig = strbuf, *strOrig = *str;
size_t in = i, out = i * 6;
iconv(icDesc, str, &in, &strbuf, &out);
*str = strOrig, strbuf = strbufOrig;
free(*str);
*str = strbuf;
}
void LT_Init(LT_InitInfo initInfo)
{
info = initInfo;
if(info.doConvert)
{
icDesc = iconv_open(info.toCode, info.fromCode);
if(icDesc == (iconv_t) -1)
{
LT_Assert(true, "failure opening iconv");
}
}
gbHead = malloc(sizeof(LT_GarbageList));
gbHead->next = NULL;
gbHead->ptr = NULL;
@ -58,6 +81,11 @@ void LT_Init(LT_InitInfo initInfo)
void LT_Quit()
{
if(info.doConvert)
{
iconv_close(icDesc);
}
gbRover = gbHead;
while(gbRover != NULL)
@ -84,12 +112,21 @@ bool LT_Assert(bool assertion, const char *str)
if(assertion)
{
LT_AssertError = true;
LT_AssertString = str;
fprintf(stderr, "LT_Assert: %s", str);
}
return assertion;
}
LT_AssertInfo LT_CheckAssert()
{
LT_AssertInfo ltAssertion;
ltAssertion.failure = LT_AssertError;
ltAssertion.str = LT_AssertString;
return ltAssertion;
}
bool LT_OpenFile(const char *filePath)
{
LT_ParseFile = fopen(filePath, "r");
@ -131,11 +168,21 @@ char *LT_ReadNumber()
realloc(str, TOKEN_STR_BLOCK_LENGTH * str_blocks++);
}
str[i++] = ((info.stripInvalid && (isspace(c) || isprint(c))) || !info.stripInvalid) ? c : ' ';
str[i++] = c;
if(info.stripInvalid)
{
str[i++] = (isspace(c) || isprint(c)) ? c : ' ';
}
}
str[i++] = '\0';
if(info.doConvert)
{
LT_DoConvert(&str);
}
gbRover->next = malloc(sizeof(LT_GarbageList));
gbRover = gbRover->next;
gbRover->ptr = realloc(str, i);
@ -188,12 +235,22 @@ char *LT_ReadString(char term)
realloc(str, TOKEN_STR_BLOCK_LENGTH * str_blocks++);
}
str[i++] = ((info.stripInvalid && (isspace(c) || isprint(c))) || !info.stripInvalid) ? c : ' ';
str[i++] = c;
if(info.stripInvalid)
{
str[i++] = (isspace(c) || isprint(c)) ? c : ' ';
}
}
}
str[i++] = '\0';
if(info.doConvert)
{
LT_DoConvert(&str);
}
gbRover->next = malloc(sizeof(LT_GarbageList));
gbRover = gbRover->next;
gbRover->ptr = realloc(str, i);
@ -465,12 +522,23 @@ LT_Token LT_GetToken()
realloc(str, TOKEN_STR_BLOCK_LENGTH * str_blocks++);
}
str[i++] = ((info.stripInvalid && (isspace(c) || isprint(c))) || !info.stripInvalid) ? c : ' ';
str[i++] = c;
if(info.stripInvalid)
{
str[i++] = (isspace(c) || isprint(c)) ? c : ' ';
}
fread(&c, 1, 1, LT_ParseFile);
}
str[i++] = '\0'; // [marrub] Completely forgot this line earlier. Really screwed up everything.
if(info.doConvert)
{
LT_DoConvert(&str);
}
gbRover->next = malloc(sizeof(LT_GarbageList));
gbRover = gbRover->next;
gbRover->ptr = realloc(str, i);
@ -483,6 +551,17 @@ LT_Token LT_GetToken()
return tk;
}
tk.string = malloc(2);
tk.string[0] = c;
tk.string[1] = '\0';
gbRover->next = malloc(sizeof(LT_GarbageList));
gbRover = gbRover->next;
gbRover->ptr = tk.string;
gbRover->next = NULL;
tk.token = tokenTypes[TOK_ChrSeq];
return tk;
}

View File

@ -25,8 +25,12 @@ THE SOFTWARE.
#define LOVETOKEN_LT_H
#include <stdio.h>
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <iconv.h>
#define TOKEN_STR_BLOCK_LENGTH 512
@ -38,6 +42,9 @@ typedef struct
{
bool escapeChars;
bool stripInvalid;
bool doConvert;
const char *fromCode;
const char *toCode;
} LT_InitInfo;
typedef struct
@ -47,11 +54,16 @@ typedef struct
int pos;
} LT_Token;
extern bool LT_EXPORT LT_AssertError;
typedef struct
{
bool failure;
const char *str;
} LT_AssertInfo;
void LT_EXPORT LT_Init(LT_InitInfo initInfo);
void LT_EXPORT LT_Quit();
bool LT_EXPORT LT_Assert(bool assertion, const char *str);
LT_AssertInfo LT_EXPORT LT_CheckAssert();
bool LT_EXPORT LT_OpenFile(const char *filePath);
void LT_EXPORT LT_CloseFile();
@ -69,8 +81,6 @@ typedef struct LT_GarbageList_s
void *ptr;
} LT_GarbageList;
extern FILE *LT_ParseFile;
enum
{
TOK_Colon,