From a83b25f286a0ba1c0bf63c5977b7f1a34945caf8 Mon Sep 17 00:00:00 2001 From: "Mike D. Lowis" Date: Fri, 21 Aug 2015 16:27:11 -0400 Subject: [PATCH] Removed external dependencies --- source/main.c | 6 ++-- source/parser.c | 20 ++++++------ source/slist.c | 85 +++++++++++++++++++++++++++++++++++++++++++++++++ source/slist.h | 43 +++++++++++++++++++++++++ 4 files changed, 142 insertions(+), 12 deletions(-) create mode 100644 source/slist.c create mode 100644 source/slist.h diff --git a/source/main.c b/source/main.c index 62d3413..37ed425 100644 --- a/source/main.c +++ b/source/main.c @@ -1,13 +1,13 @@ -#include - +#include /* Main *****************************************************************************/ -void main(int argc, char** argv) { +int main(int argc, char** argv) { extern void world_init(void); extern void exec_file(FILE* file, const char* prompt); world_init(); exec_file(stdin, ":> "); (void)argc; (void)argv; + return 0; } diff --git a/source/parser.c b/source/parser.c index 68bc24d..afbca1d 100644 --- a/source/parser.c +++ b/source/parser.c @@ -2,9 +2,12 @@ @file parser.c */ //#include "parser.h" - -#include -#include +#include "slist.h" +#include +#include +#include +#include +#include #define UNKNOWN 0 #define SYMBOL 1 @@ -38,6 +41,11 @@ #define KEYWORD_MSG 107 #define SELECTOR 108 +#ifndef container_of +#define container_of(obj, type, member) \ + (type*)((uintptr_t)obj - offsetof(type, member)) +#endif + /* Table of Contents *****************************************************************************/ // Types @@ -523,12 +531,6 @@ static void strbuf_putc(strbuf_t* buf, int ch) buf->string[buf->index] = '\0'; } -//static void strbuf_print(strbuf_t* buf, const char* str) -//{ -// while(*str) -// strbuf_putc(buf, *str++); -//} - static char* strbuf_string(strbuf_t* buf) { char* str = buf->string; diff --git a/source/slist.c b/source/slist.c new file mode 100644 index 0000000..e4308e7 --- /dev/null +++ b/source/slist.c @@ -0,0 +1,85 @@ +#include "slist.h" + +void slist_init(slist_t* list) +{ + list->head = NULL; +} + +bool slist_empty(slist_t* list) +{ + return (list->head == NULL); +} + +size_t slist_size(slist_t* list) +{ + size_t sz = 0; + slist_node_t* node = list->head; + while (node != NULL) { + sz++; + node = node->next; + } + return sz; +} + +slist_node_t* slist_front(slist_t* list) +{ + return list->head; +} + +void slist_push_front(slist_t* list, slist_node_t* node) +{ + node->next = list->head; + list->head = node; +} + +slist_node_t* slist_pop_front(slist_t* list) +{ + slist_node_t* node = list->head; + list->head = node->next; + node->next = NULL; + return node; +} + +slist_node_t* slist_back(slist_t* list) +{ + slist_node_t* node = list->head; + while (node && node->next != NULL) + node = node->next; + return (node) ? node : NULL; +} + +void slist_push_back(slist_t* list, slist_node_t* node) +{ + slist_node_t* back = slist_back(list); + if (NULL != back) + back->next = node; + else + list->head = node; + node->next = NULL; +} + +slist_node_t* slist_pop_back(slist_t* list) +{ + slist_node_t* prev = NULL; + slist_node_t* curr = list->head; + while (curr && curr->next != NULL) { + prev = curr; + curr = curr->next; + } + if (prev != NULL) + prev->next = NULL; + if (list->head == curr) + list->head = NULL; + return curr; +} + +bool slist_node_has_next(slist_node_t* node) +{ + return (node->next != NULL); +} + +slist_node_t* slist_node_next(slist_node_t* node) +{ + return node->next; +} + diff --git a/source/slist.h b/source/slist.h new file mode 100644 index 0000000..cae7ba3 --- /dev/null +++ b/source/slist.h @@ -0,0 +1,43 @@ +/** + @file slist.h +*/ +#ifndef SLIST_H +#define SLIST_H + +#include +#include + +typedef struct slist_node_t { + struct slist_node_t* next; +} slist_node_t; + +typedef struct { + slist_node_t* head; +} slist_t; + +void slist_init(slist_t* list); + +bool slist_empty(slist_t* list); + +size_t slist_size(slist_t* list); + +slist_node_t* slist_front(slist_t* list); + +void slist_push_front(slist_t* list, slist_node_t* node); + +slist_node_t* slist_pop_front(slist_t* list); + +slist_node_t* slist_back(slist_t* list); + +void slist_push_back(slist_t* list, slist_node_t* node); + +slist_node_t* slist_pop_back(slist_t* list); + +bool slist_node_has_next(slist_node_t* node); + +slist_node_t* slist_node_next(slist_node_t* node); + +#define slist_foreach(elem, list) \ + for(slist_node_t* elem = slist_front(list); elem != NULL; elem = elem->next) + +#endif /* SLIST_H */ -- 2.52.0