aboutsummaryrefslogtreecommitdiffstats
path: root/src/console.c
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2021-08-08 14:24:59 -0400
committerDavid Robillard <d@drobilla.net>2022-01-28 21:57:07 -0500
commit5aa146e1ce58d295b5f45446bbbbdbb30c8e557d (patch)
treec8b49564b251bf2c3ff63bbfdc932986bea8d0b6 /src/console.c
parentbaa2e4e768f542953144cfa6ebe5713ecad389fc (diff)
downloadserd-5aa146e1ce58d295b5f45446bbbbdbb30c8e557d.tar.gz
serd-5aa146e1ce58d295b5f45446bbbbdbb30c8e557d.tar.bz2
serd-5aa146e1ce58d295b5f45446bbbbdbb30c8e557d.zip
Replace serdi -b and -e options with a block size option
This is more powerful, and reduces the number of command line options that almost nobody needs to care about.
Diffstat (limited to 'src/console.c')
-rw-r--r--src/console.c37
1 files changed, 24 insertions, 13 deletions
diff --git a/src/console.c b/src/console.c
index 2cc908ef..df1bc2ff 100644
--- a/src/console.c
+++ b/src/console.c
@@ -15,7 +15,6 @@
*/
#include "console.h"
-#include "system.h"
#include "serd/serd.h"
@@ -27,6 +26,7 @@
# include <io.h>
#endif
+#include <stdint.h>
#include <string.h>
void
@@ -56,8 +56,24 @@ serd_print_version(const char* const program)
return 0;
}
+/// Wrapper for getc that is compatible with SerdReadFunc but faster than fread
+static size_t
+serd_file_read_byte(void* buf, size_t size, size_t nmemb, void* stream)
+{
+ (void)size;
+ (void)nmemb;
+
+ const int c = getc((FILE*)stream);
+ if (c == EOF) {
+ *((uint8_t*)buf) = 0;
+ return 0;
+ }
+ *((uint8_t*)buf) = (uint8_t)c;
+ return 1;
+}
+
SerdByteSource*
-serd_open_input(const char* const filename, const size_t page_size)
+serd_open_input(const char* const filename, const size_t block_size)
{
SerdByteSource* byte_source = NULL;
if (!strcmp(filename, "-")) {
@@ -65,31 +81,26 @@ serd_open_input(const char* const filename, const size_t page_size)
SerdNode* name = serd_new_string(SERD_STRING("stdin"));
- byte_source = serd_byte_source_new_function(serd_file_read_byte,
- (SerdStreamErrorFunc)ferror,
- NULL,
- stdin,
- name,
- page_size);
+ byte_source = serd_byte_source_new_function(
+ serd_file_read_byte, (SerdStreamErrorFunc)ferror, NULL, stdin, name, 1);
serd_node_free(name);
} else {
- byte_source = serd_byte_source_new_filename(filename, page_size);
+ byte_source = serd_byte_source_new_filename(filename, block_size);
}
return byte_source;
}
SerdByteSink*
-serd_open_output(const char* const filename, const size_t page_size)
+serd_open_output(const char* const filename, const size_t block_size)
{
if (!filename || !strcmp(filename, "-")) {
serd_set_stream_utf8_mode(stdout);
- return serd_byte_sink_new_function(
- (SerdWriteFunc)fwrite, stdout, page_size);
+ return serd_byte_sink_new_function((SerdWriteFunc)fwrite, stdout, 1);
}
- return serd_byte_sink_new_filename(filename, page_size);
+ return serd_byte_sink_new_filename(filename, block_size);
}
SerdStatus