]> git.mdlowis.com Git - projs/alib.git/commitdiff
Switched to ISC license embedded in each file
authorMichael D. Lowis <mike@mdlowis.com>
Thu, 23 Feb 2017 21:57:20 +0000 (16:57 -0500)
committerMichael D. Lowis <mike@mdlowis.com>
Thu, 23 Feb 2017 21:57:20 +0000 (16:57 -0500)
source/bstree.h
source/hash.h
source/ini.h [new file with mode: 0644]
source/lex.h
source/list.h
source/parse.h
source/slist.h
source/strbuf.h
source/utf8.h
source/vec.h

index ab53c68d2747c73518bb4e3e10b1c2152e317c03..43c9f7b22a6232b68e8b3e899ce115ad2c4988ca 100644 (file)
@@ -1,7 +1,21 @@
-/**
-  @brief Simple binary search tree implementation.
-  @author Michael D. Lowis
-  @license BSD 2-clause License
+/*
+    Simple binary search tree implementation.
+    
+    Copyright 2017, Michael D. Lowis
+    
+    Permission to use, copy, modify, and/or distribute this software
+    for any purpose with or without fee is hereby granted, provided
+    that the above copyright notice and this permission notice appear
+    in all copies.
+    
+    THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
+    WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
+    WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
+    AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+    DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA
+    OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+    TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+    PERFORMANCE OF THIS SOFTWARE.
 */
 
 typedef struct bstree_node_t {
index d2cb62b69efb6a8fbca6d649ca67c271809df31f..953cece1e45a0347655c0cefbab7d916f9bb8c73 100644 (file)
@@ -1,7 +1,21 @@
-/**
-  @brief Simple generic hash table implementation.
-  @author Michael D. Lowis
-  @license BSD 2-clause License
+/*
+    Simple generic hash table implementation.
+    
+    Copyright 2017, Michael D. Lowis
+    
+    Permission to use, copy, modify, and/or distribute this software
+    for any purpose with or without fee is hereby granted, provided
+    that the above copyright notice and this permission notice appear
+    in all copies.
+    
+    THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
+    WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
+    WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
+    AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+    DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA
+    OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+    TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+    PERFORMANCE OF THIS SOFTWARE.
 */
 
 typedef struct hash_entry_t {
diff --git a/source/ini.h b/source/ini.h
new file mode 100644 (file)
index 0000000..b2bfdaa
--- /dev/null
@@ -0,0 +1,112 @@
+/*
+    A simple and minimal INI-file parser.
+    
+    Copyright 2017, Michael D. Lowis
+    
+    Permission to use, copy, modify, and/or distribute this software
+    for any purpose with or without fee is hereby granted, provided
+    that the above copyright notice and this permission notice appear
+    in all copies.
+    
+    THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
+    WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
+    WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
+    AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+    DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA
+    OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+    TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+    PERFORMANCE OF THIS SOFTWARE.
+*/
+#ifndef INI_H
+#define INI_H
+
+#include <stdio.h>
+#include <stdbool.h>
+#include <string.h>
+
+#ifndef INI_SECT_MAX
+#define INI_SECT_MAX (256u)
+#endif
+
+#ifndef INI_LINE_MAX
+#define INI_LINE_MAX (256u)
+#endif
+
+#ifndef INI_COMMENT_CHAR
+#define INI_COMMENT_CHAR ';'
+#endif
+
+typedef struct {
+    FILE* file;
+    char section[INI_SECT_MAX];
+    char line[INI_LINE_MAX];
+} inifile_t;
+
+typedef struct {
+    const char* section;
+    const char* name;
+    const char* value;
+} inientry_t;
+
+static char* ininows(char* str)
+{
+    /* Skip leading whitespace */
+    while (*str && isspace(*str))
+        str++;
+    /* Trim trailing whitespace */
+    char* end = str + strlen(str);
+    while (end > str && isspace(*(--end)))
+        *end = '\0';
+    return str;
+}
+
+static bool iniparse(inifile_t* inifile, inientry_t* entry)
+{
+    /* If no file was opened then stop parsing here. */
+    if (inifile->file == NULL) return false;
+    /* First things first, clear the entry */
+    memset(entry, 0, sizeof(inientry_t));
+    /* Otherwise, there must be something we can do */
+    while (!feof(inifile->file)) {
+        inifile->line[0] = '\0'; // Reset the line
+        fgets(inifile->line, INI_LINE_MAX, inifile->file);
+        char* start = ininows(inifile->line);
+        if (*start == '[') {
+            char* section = inifile->section;
+            start++;
+            while (*start && *start != ']' &&
+                   ((section - inifile->section) <= INI_SECT_MAX)) {
+                *(section++) = *(start++);
+                *(section)   = '\0';
+            }
+        } else if (*start != '\0' && *start != INI_COMMENT_CHAR) {
+            /* Figure out the maximum end of the name field */
+            char* end = (inifile->line + (INI_LINE_MAX-2));
+            /* Store off the section and name since we have those now */
+            entry->section = inifile->section;
+            entry->name    = start;
+            /* Mark the end of the name field with a null char */
+            while (*start && start < end && !isspace(*start))
+                start++;
+            *(start++) = '\0';
+            /* Skip everything up to and including the = */
+            while (*start && start < end && *start != '=')
+                start++;
+            /* Skip whitespace after the = */
+            entry->value = ininows(start+1);
+            /* Mark the end of the value field */
+            while (*start && *start != INI_COMMENT_CHAR)
+                start++;
+            *start = '\0';
+            /* Strip whitespace on both sides and return the entry */
+            entry->value = ininows((char*)(entry->value));
+            return true;
+        }
+    }
+    /* If we got here, the file is done being parsed so close it and wrap up */
+    fclose(inifile->file);
+    inifile->file = NULL;
+    return false;
+}
+
+#endif /* INI_H */
index a7455701586424117e3e255ef7cd55c4567ccdd6..3ac148df50f0bea70dd83cab15be6af7914426eb 100644 (file)
@@ -1,7 +1,21 @@
-/**
-  @brief Helper utilities for writing a handwritten lexer.
-  @author Michael D. Lowis
-  @license BSD 2-clause License
+/*
+    Helper utilities for writing a handwritten lexer.
+    
+    Copyright 2017, Michael D. Lowis
+    
+    Permission to use, copy, modify, and/or distribute this software
+    for any purpose with or without fee is hereby granted, provided
+    that the above copyright notice and this permission notice appear
+    in all copies.
+    
+    THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
+    WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
+    WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
+    AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+    DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA
+    OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+    TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+    PERFORMANCE OF THIS SOFTWARE.
 */
 
 typedef struct lex_ctx_t {
index 9d63b412b5109a4b281024620db0227112912880..fe19e48e67bf0490e95cfacc72e8b36ae37e3f86 100644 (file)
@@ -1,7 +1,21 @@
 /**
-  @brief Intrusive doubly-linked list implementation.
-  @author Michael D. Lowis
-  @license BSD 2-clause License
+    Intrusive doubly-linked list implementation.
+    
+    Copyright 2017, Michael D. Lowis
+    
+    Permission to use, copy, modify, and/or distribute this software
+    for any purpose with or without fee is hereby granted, provided
+    that the above copyright notice and this permission notice appear
+    in all copies.
+    
+    THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
+    WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
+    WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
+    AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+    DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA
+    OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+    TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+    PERFORMANCE OF THIS SOFTWARE.
 */
 
 typedef struct list_node_t {
index a4bf05835d2e8dbd7e0fafd3c9cbb7a26308b3f3..5e0c387d433a994b1cff1fe52670231569043103 100644 (file)
@@ -1,7 +1,21 @@
 /**
-  @brief Infinite lookahead and backtracking parser implementation.
-  @author Michael D. Lowis
-  @license BSD 2-clause License
+    Infinite lookahead and backtracking parser implementation.
+    
+    Copyright 2017, Michael D. Lowis
+    
+    Permission to use, copy, modify, and/or distribute this software
+    for any purpose with or without fee is hereby granted, provided
+    that the above copyright notice and this permission notice appear
+    in all copies.
+    
+    THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
+    WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
+    WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
+    AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+    DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA
+    OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+    TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+    PERFORMANCE OF THIS SOFTWARE.
 */
 
 /*
@@ -119,7 +133,7 @@ static void expect(parser_t* ctx, int toktype) {
     if (peektype(ctx,1) == toktype)
         consume(ctx);
     else
-        error(ctx, "Unexpected token. Expected %d, received %d\n", peektype(ctx,1), toktype);
+        parse_error(ctx, "Unexpected token. Expected %d, received %d\n", peektype(ctx,1), toktype);
 }
 
 static size_t mark(parser_t* ctx) {
index 7fab57e1d4daa6e49704b47a346ff70b5b576f98..441f86764fd574cf812526cffb16b20cd0cd2c19 100644 (file)
@@ -1,7 +1,21 @@
 /**
-  @brief Intrusive singly-linked list implementation.
-  @author Michael D. Lowis
-  @license BSD 2-clause License
+    Intrusive singly-linked list implementation.
+    
+    Copyright 2017, Michael D. Lowis
+    
+    Permission to use, copy, modify, and/or distribute this software
+    for any purpose with or without fee is hereby granted, provided
+    that the above copyright notice and this permission notice appear
+    in all copies.
+    
+    THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
+    WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
+    WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
+    AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+    DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA
+    OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+    TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+    PERFORMANCE OF THIS SOFTWARE.
 */
 
 typedef struct slist_node_t {
index 3eeee9e11891a0efb7141988880730a0b930ca31..6a3cfaafa299e36662c605b8104a22891e7c65bc 100644 (file)
@@ -1,7 +1,21 @@
 /**
-  @brief Simple implementation of string buffers in c.
-  @author Michael D. Lowis
-  @license BSD 2-clause License
+    Simple implementation of string buffers in c.
+    
+    Copyright 2017, Michael D. Lowis
+    
+    Permission to use, copy, modify, and/or distribute this software
+    for any purpose with or without fee is hereby granted, provided
+    that the above copyright notice and this permission notice appear
+    in all copies.
+    
+    THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
+    WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
+    WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
+    AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+    DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA
+    OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+    TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+    PERFORMANCE OF THIS SOFTWARE.
 */
 
 typedef struct {
index fca8fbc139b1b8b568d93bf2cb2397c1898fe3f1..d60bf54b9fbb53b4eed48727b3443e37476c0f25 100644 (file)
@@ -1,7 +1,21 @@
 /**
-  @brief Simple UTF-8 encoding and decoding routines.
-  @author Michael D. Lowis
-  @license BSD 2-clause License
+    Simple UTF-8 encoding and decoding routines.
+
+    Copyright 2017, Michael D. Lowis
+    
+    Permission to use, copy, modify, and/or distribute this software
+    for any purpose with or without fee is hereby granted, provided
+    that the above copyright notice and this permission notice appear
+    in all copies.
+    
+    THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
+    WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
+    WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
+    AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+    DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA
+    OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+    TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+    PERFORMANCE OF THIS SOFTWARE.
 */
 
 typedef uint32_t Rune;
index c7b61138b7fe181c8d03f7a6692265d0e6770d79..75399f73bfc6c2a344a9c671dfd38e0f66c82574 100644 (file)
@@ -1,7 +1,21 @@
 /**
-  @brief Generic vector implementation.
-  @author Michael D. Lowis
-  @license BSD 2-clause License
+    Generic vector implementation.
+    
+    Copyright 2017, Michael D. Lowis
+    
+    Permission to use, copy, modify, and/or distribute this software
+    for any purpose with or without fee is hereby granted, provided
+    that the above copyright notice and this permission notice appear
+    in all copies.
+    
+    THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
+    WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
+    WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
+    AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+    DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA
+    OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+    TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+    PERFORMANCE OF THIS SOFTWARE.
 */
 #ifndef VEC_H
 #define VEC_H