aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md44
-rw-r--r--any_sexp.h16
2 files changed, 54 insertions, 6 deletions
diff --git a/README.md b/README.md
index 8664ed6..d78a015 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,48 @@
# any\_libs
-single-file C libraries licensed under MIT
+single-file C libraries released under MIT license
**NOTE: Still in early stages of development! Use at your own risk**
+## [any\_log](./any_log.h)
+
+A simple log libary that supports normal and structured logging.
+
+## [any\_hash](./any_hash.h)
+
+A library that provides a simple implementation of the xxHash algorithm.
+
+## [any\_ini](./any_ini.h)
+
+A library that provides a simple ini parser.
+
+## [any\_sexp](./any_sexp.h)
+
+A library for reading, handling and printing s-expressions.
+
+## ...
+
+More libraries will be made and released as time passes.
+
+## License (MIT)
+
+Copyright (c) 2024 Federico Angelilli
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
+
diff --git a/any_sexp.h b/any_sexp.h
index c419cba..4ee401e 100644
--- a/any_sexp.h
+++ b/any_sexp.h
@@ -27,6 +27,7 @@
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
+#include <stdio.h>
typedef enum {
ANY_SEXP_TAG_ERROR = 0xf,
@@ -130,6 +131,8 @@ void any_sexp_reader_init(any_sexp_reader_t *reader, any_sexp_getchar_t getc, vo
void any_sexp_reader_string_init(any_sexp_reader_t *reader, any_sexp_reader_string_t *string, const char *source, size_t length);
+void any_sexp_reader_file_init(any_sexp_reader_t *reader, FILE *file);
+
bool any_sexp_reader_end(any_sexp_reader_t *reader);
any_sexp_t any_sexp_read(any_sexp_reader_t *reader);
@@ -138,8 +141,6 @@ any_sexp_t any_sexp_read(any_sexp_reader_t *reader);
#ifndef ANY_SEXP_NO_WRITER
-#include <stdio.h>
-
typedef struct {
any_sexp_putchar_t putc;
void *stream;
@@ -276,9 +277,9 @@ static void any_sexp_reader_skip(any_sexp_reader_t *reader)
static char any_sexp_reader_string_getc(any_sexp_reader_string_t *string)
{
- if (string->cursor >= string->length)
- return EOF;
- return string->source[string->cursor++];
+ return string->cursor < string->length
+ ? string->source[string->cursor++]
+ : EOF;
}
void any_sexp_reader_init(any_sexp_reader_t *reader, any_sexp_getchar_t getc, void *stream)
@@ -296,6 +297,11 @@ void any_sexp_reader_string_init(any_sexp_reader_t *reader, any_sexp_reader_stri
any_sexp_reader_init(reader, (any_sexp_getchar_t)any_sexp_reader_string_getc, string);
}
+void any_sexp_reader_file_init(any_sexp_reader_t *reader, FILE *file)
+{
+ any_sexp_reader_init(reader, (any_sexp_getchar_t)fgetc, file);
+}
+
bool any_sexp_reader_end(any_sexp_reader_t *reader)
{
return reader->c == EOF;