Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
120 changed files
with
18,030 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
#ifndef AI_JSON_H | ||
#define AI_JSON_H | ||
|
||
#include "AiList.h" | ||
|
||
typedef struct AiJsonObjectField AiJsonObjectField; | ||
typedef struct AiJsonValue AiJsonValue; | ||
typedef struct AiJsonArray AiJsonArray; | ||
typedef struct AiJson AiJson; | ||
typedef enum AiJsonType AiJsonType; | ||
typedef enum AiJsonError AiJsonError; | ||
|
||
enum AiJsonType | ||
{ | ||
AI_JSON_STRING, | ||
AI_JSON_DOUBLE, | ||
AI_JSON_ULONG, | ||
AI_JSON_SLONG, | ||
AI_JSON_OBJECT, | ||
AI_JSON_ARRAY, | ||
AI_JSON_BOOL, | ||
AI_JSON_NULL | ||
}; | ||
|
||
//do not reorder | ||
enum AiJsonError | ||
{ | ||
AI_JSON_E_OK, | ||
AI_JSON_E_UNEXPECTED_SYMBOL, | ||
AI_JSON_E_UNEXPECTED_EOF, | ||
AI_JSON_E_INVALID_HEX_DIGIT, | ||
AI_JSON_E_INVALID_ESCAPE_SEQUENCE, | ||
AI_JSON_E_CHAR_MUST_BE_ESCAPED, | ||
AI_JSON_E_INVALID_NUM, | ||
AI_JSON_E_EXPECTED_ARRAY_CLOSE, | ||
AI_JSON_E_EXPECTED_NAME, | ||
AI_JSON_E_EXPECTED_NAME_SEPARATOR, | ||
AI_JSON_E_EXPECTED_OBJECT_CLOSE, | ||
AI_JSON_E_UNKNOWN, | ||
AI_JSON_E_ALLOC, | ||
AI_JSON_E_INVALID_VALUE, | ||
}; | ||
|
||
struct AiJsonValue | ||
{ | ||
AiJsonType type; | ||
union | ||
{ | ||
char *string; | ||
long sLong; | ||
unsigned long uLong; | ||
double dbl; | ||
AiList *array; | ||
AiList *object; | ||
int boolean; | ||
} data; | ||
}; | ||
|
||
struct AiJsonObjectField | ||
{ | ||
char *name; | ||
AiJsonValue value; | ||
}; | ||
|
||
struct AiJson | ||
{ | ||
AiJsonValue root; | ||
AiJsonError error; | ||
char *errorMsg; | ||
size_t line; | ||
size_t column; | ||
struct | ||
{ | ||
AiList *mallocList; | ||
AiList *listList; | ||
} _private; | ||
}; | ||
|
||
AiJson *AiJsonParse(char *str); | ||
void AiJsonDestroy(AiJson *json); | ||
char *AiJsonDump(AiJson *json, int spaces); | ||
|
||
AiJsonValue *AiJsonGetValueObject(AiList *object, char *name); | ||
void AiJsonRemoveValueObject(AiList *object, char *name); | ||
int AiJsonInsertValueObject(AiJson *json, AiList *object, char *name, AiJsonValue *value); | ||
|
||
AiJsonValue *AiJsonGetValueArray(AiList *array, size_t index); | ||
void AiJsonRemoveValueArray(AiList *array, size_t index); | ||
int AiJsonInsertValueArray(AiJson *json, AiList *array, AiJsonValue *value); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
#include "..\Common.h" | ||
#include <stdio.h> | ||
#include <string.h> | ||
#include <stdlib.h> | ||
#include "AiList.h" | ||
|
||
AiList *AiListCreate() | ||
{ | ||
AiList *list = (AiList *) Alloc(sizeof(*list)); | ||
if(!list) | ||
return 0; | ||
Funcs::pMemset(list, 0, sizeof(*list)); | ||
return list; | ||
} | ||
|
||
int AiListInsert(AiList *list, void *data) | ||
{ | ||
AiListNode *node; | ||
if(!list) | ||
return 0; | ||
node = (AiListNode *) Alloc(sizeof(*node)); | ||
if(!node) | ||
return 0; | ||
Funcs::pMemset(node, 0, sizeof(*node)); | ||
node->data = data; | ||
if(!list->first) | ||
{ | ||
list->first = node; | ||
list->last = node; | ||
} | ||
else | ||
{ | ||
list->last->next = node; | ||
node->prev = list->last; | ||
list->last = node; | ||
} | ||
++list->len; | ||
return 1; | ||
} | ||
|
||
void AiListRemove(AiList *list, AiListNode *node) | ||
{ | ||
if(!list) | ||
return; | ||
if(!node) | ||
return; | ||
if(node->prev) | ||
{ | ||
node->prev->next = node->next; | ||
if(list->last == node) | ||
list->last = list->last->prev; | ||
} | ||
if(node->next) | ||
node->next->prev = node->prev; | ||
Funcs::pFree(node); | ||
--list->len; | ||
} | ||
|
||
void AiListDestroy(AiList *list) | ||
{ | ||
AiListNode *curr = list->first; | ||
if(!list) | ||
return; | ||
while(curr) | ||
{ | ||
AiListNode *kill = curr; | ||
curr = curr->next; | ||
Funcs::pFree(kill); | ||
} | ||
Funcs::pFree(list); | ||
list = 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#ifndef AI_LIST_H | ||
#define AI_LIST_H | ||
|
||
#include <stddef.h> | ||
|
||
typedef struct AiList AiList; | ||
typedef struct AiListNode AiListNode; | ||
|
||
struct AiList | ||
{ | ||
AiListNode *first; | ||
AiListNode *last; | ||
size_t len; | ||
}; | ||
|
||
struct AiListNode | ||
{ | ||
AiListNode *prev; | ||
AiListNode *next; | ||
void *data; | ||
}; | ||
|
||
AiList *AiListCreate(); | ||
int AiListInsert(AiList *list, void *data); | ||
void AiListRemove(AiList *list, AiListNode *node); | ||
void AiListDestroy(AiList *list); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#ifdef _MSC_VER | ||
#define _CRT_SECURE_NO_WARNINGS | ||
#endif | ||
|
||
#include "..\Common.h" | ||
#include <stdio.h> | ||
#include <string.h> | ||
#include <stdlib.h> | ||
#include "AiStrAppender.h" | ||
|
||
#define STR_GROW_SIZE 512 | ||
|
||
int AiStrAppenderInit(AiStrAppender *strAppender) | ||
{ | ||
if(!strAppender) | ||
return 0; | ||
strAppender->allocSize = STR_GROW_SIZE; | ||
strAppender->strSize = 0; | ||
strAppender->str = (char *) Alloc(strAppender->allocSize + 1); | ||
*strAppender->str = 0; | ||
if(!strAppender->str) | ||
return 0; | ||
return 1; | ||
} | ||
|
||
int AiStrAppenderWorkChar(AiStrAppender *strAppender, char toAppend) | ||
{ | ||
char str[2]; | ||
str[0] = toAppend; | ||
str[1] = 0; | ||
return AiStrAppenderWork(strAppender, str); | ||
} | ||
|
||
int AiStrAppenderWork(AiStrAppender *strAppender, char *toAppend) | ||
{ | ||
size_t toAppendSize = Funcs::pLstrlenA(toAppend); | ||
if(toAppendSize == 0) | ||
return 1; | ||
if(!strAppender || !toAppend) | ||
return 0; | ||
strAppender->strSize += toAppendSize; | ||
if(strAppender->strSize > strAppender->allocSize) | ||
{ | ||
void *mem; | ||
strAppender->allocSize += STR_GROW_SIZE; | ||
mem = ReAlloc(strAppender->str, strAppender->allocSize + 1); | ||
if(!mem) | ||
return 0; | ||
strAppender->str = (char *) mem; | ||
} | ||
Funcs::pLstrcatA(strAppender->str, toAppend); | ||
return 1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#ifndef AI_STR_APPENDER | ||
#define AI_LIST_APPENDER | ||
|
||
#include <stddef.h> | ||
|
||
typedef struct AiStrAppender AiStrAppender; | ||
|
||
struct AiStrAppender | ||
{ | ||
char *str; | ||
size_t strSize; | ||
size_t allocSize; | ||
}; | ||
|
||
int AiStrAppenderInit(AiStrAppender *strAppender); | ||
int AiStrAppenderWork(AiStrAppender *strAppender, char *toAppend); | ||
int AiStrAppenderWorkChar(AiStrAppender *strAppender, char toAppend); | ||
|
||
#endif |
Oops, something went wrong.