You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
95 lines
1.8 KiB
95 lines
1.8 KiB
#include <libse.h>
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <internal/exstring.h>
|
|
|
|
void test_exs()
|
|
{
|
|
exString *test= exs_new(NULL);
|
|
|
|
printf("New success\n");
|
|
|
|
exs_append(test, "Hello");
|
|
exs_append(test, " world.");
|
|
|
|
exs_append(test, " Test, ");
|
|
exs_append(test, "two, three. FOUR FIVE.");
|
|
|
|
exs_reduce(test, 5);
|
|
|
|
EXS(test)[strlen(EXS(test))-5] = 0;
|
|
|
|
exs_recalc(test);
|
|
|
|
exs_append(test, " Scream: ");
|
|
|
|
exs_nappendc(test, 'A', 6);
|
|
|
|
exs_appendf(test, "\nCurrent size: %d -> %d", strlen(EXS(test)), exs_realsize(test));
|
|
exs_appendf(test, "AOISDJOAIJS%s", "sokdok");
|
|
|
|
printf("%s\n", EXS(test));
|
|
|
|
printf("strlen() %d, ->currentSize %d\n", strlen(EXS(test)), exs_realsize(test));
|
|
|
|
exs_free(test);
|
|
}
|
|
|
|
void test_parse()
|
|
{
|
|
FILE* fp = fopen("test.se", "rb");
|
|
exString *buf = exs_new(NULL);
|
|
char rb[8];
|
|
int rd=0;
|
|
memset(rb,0,sizeof(rb));
|
|
|
|
while( (rd=fread(rb, 1, 8, fp))>0)
|
|
{
|
|
exs_nappend(buf, rb, rd);
|
|
}
|
|
|
|
fclose(fp);
|
|
const char* parse = EXS(buf);
|
|
//printf("%s\n", parse);
|
|
//exs_free(buf);
|
|
list_t* list = se_parse(parse, SETP_DEFAULT);
|
|
if(!list)
|
|
{
|
|
printf("Parse failed.\n");
|
|
return;
|
|
}
|
|
//printf("Parse okay.\n");
|
|
|
|
se_print(NULL, list);
|
|
printf("\n");
|
|
// printf("(car list) -> %s\n", (char*)list->ptr);
|
|
// printf("(cadr list) -> %s\n", (list->cdr?(char*)list->cdr->ptr:"nil"));
|
|
|
|
se_free(list);
|
|
exs_free(buf);
|
|
}
|
|
|
|
void test_make()
|
|
{
|
|
list_t* l = se_new("Hello", 1);
|
|
l->cdr = se_new("world", 1);
|
|
|
|
list_t* n = se_parse("(I love you)", SETP_DEFAULT | SET_NO_WRAP);
|
|
|
|
se_last((((l->cdr->cdr = n)->cdr = se_parse("((((very)) much))", SETP_DEFAULT))
|
|
->cdr = se_parse("((\\\n more parsing))", SETP_DEFAULT))
|
|
->cdr = se_parse("((AND EVEN (M (O (R (E))))) !!!)", SETP_DEFAULT))->cdr = se_parse("(test test test!)", SETP_DEFAULT);
|
|
|
|
se_print(NULL, l);
|
|
printf("\n");
|
|
se_free(l);
|
|
}
|
|
|
|
int main()
|
|
{
|
|
// test_exs();
|
|
test_parse();
|
|
test_make();
|
|
return 0;
|
|
}
|