]> git.mdlowis.com Git - proto/gir.git/commitdiff
Removed external dependencies
authorMike D. Lowis <mike.lowis@gentex.com>
Fri, 21 Aug 2015 20:27:11 +0000 (16:27 -0400)
committerMike D. Lowis <mike.lowis@gentex.com>
Fri, 21 Aug 2015 20:27:11 +0000 (16:27 -0400)
source/main.c
source/parser.c
source/slist.c [new file with mode: 0644]
source/slist.h [new file with mode: 0644]

index 62d3413c86e68d3d63d839e286d9e722b94d8576..37ed4254da06aa7ae839af87ccb44cc654da3f22 100644 (file)
@@ -1,13 +1,13 @@
-#include <libc.h>
-
+#include <stdio.h>
 /* 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;
 }
 
index 68bc24d6e2b6c3c3bb8c6c6abbd1dd0e00cd6493..afbca1d09714390b7c32b5bcc877fa8360638f25 100644 (file)
@@ -2,9 +2,12 @@
   @file parser.c
 */
 //#include "parser.h"
-
-#include <libc.h>
-#include <data/slist.h>
+#include "slist.h"
+#include <stdlib.h>
+#include <stdio.h>
+#include <ctype.h>
+#include <string.h>
+#include <stdint.h>
 
 #define UNKNOWN     0
 #define SYMBOL      1
 #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 (file)
index 0000000..e4308e7
--- /dev/null
@@ -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 (file)
index 0000000..cae7ba3
--- /dev/null
@@ -0,0 +1,43 @@
+/**
+  @file slist.h
+*/
+#ifndef SLIST_H
+#define SLIST_H
+
+#include <stdbool.h>
+#include <stddef.h>
+
+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 */