aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile5
-rw-r--r--common.h1
-rw-r--r--libcmap.h50
-rw-r--r--libcmap_dprint_range.c12
-rw-r--r--libcmap_fprint_range.c12
-rw-r--r--libcmap_print_range.c9
6 files changed, 85 insertions, 4 deletions
diff --git a/Makefile b/Makefile
index 4966165..f5e26c8 100644
--- a/Makefile
+++ b/Makefile
@@ -27,7 +27,10 @@ OBJ =\
libcmap_find_block.o\
libcmap_find_script.o\
libcmap_sprint_range.o\
- libcmap_snprint_range.o
+ libcmap_snprint_range.o\
+ libcmap_fprint_range.o\
+ libcmap_print_range.o\
+ libcmap_dprint_range.o
HDR =\
libcmap.h\
diff --git a/common.h b/common.h
index c5fc285..0007af2 100644
--- a/common.h
+++ b/common.h
@@ -1,7 +1,6 @@
/* See LICENSE file for copyright and license details. */
#include "libcmap.h"
#include <limits.h>
-#include <stdio.h>
#define SINGLETON_RANGE_FMT "U+%04lX"
diff --git a/libcmap.h b/libcmap.h
index 324f790..a04b38e 100644
--- a/libcmap.h
+++ b/libcmap.h
@@ -4,6 +4,8 @@
#include <stddef.h>
#include <stdint.h>
+#include <stdio.h>
+
#if defined(__GNUC__)
# define LIBCMAP_PURE_ __attribute__((__pure__))
@@ -224,6 +226,7 @@ const struct libcmap_block *libcmap_find_block(uint32_t codepoint, size_t *offse
*/
const struct libcmap_script *libcmap_find_script(uint32_t codepoint, size_t *offset_out, size_t *subrange_out);
+
/**
* Print a string representing a Unicode codepoint range
*
@@ -233,7 +236,9 @@ const struct libcmap_script *libcmap_find_script(uint32_t codepoint, size_t *off
* @param endash Desired delimiter between the first and the last
* codepoint, or `NULL` for the default (not ASCII)
* @return The number of bytes in the string, excluding the
- * terminating NUL byte
+ * terminating NUL byte, -1 on failure
+ *
+ * @throws Any error specified for sprintf(3)
*
* A NUL byte will added to the end of the string, but this byte
* will not be counted in the return value
@@ -250,7 +255,9 @@ int libcmap_sprint_range(char *buf, const struct libcmap_range *range, const cha
* @param endash Desired delimiter between the first and the last
* codepoint, or `NULL` for the default (not ASCII)
* @return The number of bytes in the string, excluding the
- * terminating NUL byte
+ * terminating NUL byte, -1 on failure
+ *
+ * @throws Any error specified for snprintf(3)
*
* A NUL byte will added to the end of the string, but this byte
* will not be counted in the return value
@@ -268,6 +275,45 @@ int libcmap_sprint_range(char *buf, const struct libcmap_range *range, const cha
*/
int libcmap_snprint_range(char *buf, size_t bufsize, const struct libcmap_range *range, const char *endash);
+/**
+ * Print a string representing a Unicode codepoint range
+ *
+ * @param fp The file to write to
+ * @param range The range to print a representation of
+ * @param endash Desired delimiter between the first and the last
+ * codepoint, or `NULL` for the default (not ASCII)
+ * @return The number of bytes in the string, -1 on failure
+ *
+ * @throws Any error specified for fprintf(3)
+ */
+int libcmap_fprint_range(FILE *fp, const struct libcmap_range *range, const char *endash);
+
+/**
+ * Print, to standard output, a string representing a
+ * Unicode codepoint range
+ *
+ * @param range The range to print a representation of
+ * @param endash Desired delimiter between the first and the last
+ * codepoint, or `NULL` for the default (not ASCII)
+ * @return The number of bytes in the string, -1 on failure
+ *
+ * @throws Any error specified for fprintf(3)
+ */
+int libcmap_print_range(const struct libcmap_range *range, const char *endash);
+
+/**
+ * Print a string representing a Unicode codepoint range
+ *
+ * @param fd The file descriptor
+ * @param range The range to print a representation of
+ * @param endash Desired delimiter between the first and the last
+ * codepoint, or `NULL` for the default (not ASCII)
+ * @return The number of bytes in the string, -1 on failure
+ *
+ * @throws Any error specified for dprintf(3)
+ */
+int libcmap_dprint_range(int fd, const struct libcmap_range *range, const char *endash);
+
#undef LIBCMAP_PURE_
#undef LIBCMAP_CONST_
diff --git a/libcmap_dprint_range.c b/libcmap_dprint_range.c
new file mode 100644
index 0000000..7047871
--- /dev/null
+++ b/libcmap_dprint_range.c
@@ -0,0 +1,12 @@
+/* See LICENSE file for copyright and license details. */
+#include "common.h"
+
+
+int
+libcmap_dprint_range(int fd, const struct libcmap_range *range, const char *endash)
+{
+ if (range->first == range->last)
+ return dprintf(fd, SINGLETON_RANGE_FMT, SINGLETON_RANGE_ARGS(range));
+ else
+ return dprintf(fd, RANGE_FMT, RANGE_ARGS(range, endash));
+}
diff --git a/libcmap_fprint_range.c b/libcmap_fprint_range.c
new file mode 100644
index 0000000..35c68c5
--- /dev/null
+++ b/libcmap_fprint_range.c
@@ -0,0 +1,12 @@
+/* See LICENSE file for copyright and license details. */
+#include "common.h"
+
+
+int
+libcmap_fprint_range(FILE *fp, const struct libcmap_range *range, const char *endash)
+{
+ if (range->first == range->last)
+ return fprintf(fp, SINGLETON_RANGE_FMT, SINGLETON_RANGE_ARGS(range));
+ else
+ return fprintf(fp, RANGE_FMT, RANGE_ARGS(range, endash));
+}
diff --git a/libcmap_print_range.c b/libcmap_print_range.c
new file mode 100644
index 0000000..868549e
--- /dev/null
+++ b/libcmap_print_range.c
@@ -0,0 +1,9 @@
+/* See LICENSE file for copyright and license details. */
+#include "common.h"
+
+
+int
+libcmap_print_range(const struct libcmap_range *range, const char *endash)
+{
+ return libcmap_fprint_range(stdout, range, endash);
+}