From 6c54019024fd5dcbfdb3dd6692d907c22c0063bf Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Thu, 23 Feb 2017 16:57:20 -0500 Subject: [PATCH] Switched to ISC license embedded in each file --- source/bstree.h | 22 ++++++++-- source/hash.h | 22 ++++++++-- source/ini.h | 112 ++++++++++++++++++++++++++++++++++++++++++++++++ source/lex.h | 22 ++++++++-- source/list.h | 20 +++++++-- source/parse.h | 22 ++++++++-- source/slist.h | 20 +++++++-- source/strbuf.h | 20 +++++++-- source/utf8.h | 20 +++++++-- source/vec.h | 20 +++++++-- 10 files changed, 269 insertions(+), 31 deletions(-) create mode 100644 source/ini.h diff --git a/source/bstree.h b/source/bstree.h index ab53c68..43c9f7b 100644 --- a/source/bstree.h +++ b/source/bstree.h @@ -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 { diff --git a/source/hash.h b/source/hash.h index d2cb62b..953cece 100644 --- a/source/hash.h +++ b/source/hash.h @@ -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 index 0000000..b2bfdaa --- /dev/null +++ b/source/ini.h @@ -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 +#include +#include + +#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 */ diff --git a/source/lex.h b/source/lex.h index a745570..3ac148d 100644 --- a/source/lex.h +++ b/source/lex.h @@ -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 { diff --git a/source/list.h b/source/list.h index 9d63b41..fe19e48 100644 --- a/source/list.h +++ b/source/list.h @@ -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 { diff --git a/source/parse.h b/source/parse.h index a4bf058..5e0c387 100644 --- a/source/parse.h +++ b/source/parse.h @@ -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) { diff --git a/source/slist.h b/source/slist.h index 7fab57e..441f867 100644 --- a/source/slist.h +++ b/source/slist.h @@ -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 { diff --git a/source/strbuf.h b/source/strbuf.h index 3eeee9e..6a3cfaa 100644 --- a/source/strbuf.h +++ b/source/strbuf.h @@ -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 { diff --git a/source/utf8.h b/source/utf8.h index fca8fbc..d60bf54 100644 --- a/source/utf8.h +++ b/source/utf8.h @@ -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; diff --git a/source/vec.h b/source/vec.h index c7b6113..75399f7 100644 --- a/source/vec.h +++ b/source/vec.h @@ -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 -- 2.54.0