summaryrefslogtreecommitdiffstats
path: root/linenoise/linenoise.h
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2018-05-18 06:24:22 -0700
committerKaz Kylheku <kaz@kylheku.com>2018-05-18 06:24:22 -0700
commitb13a869dddb06218151f00a0abec077fff9cdd4a (patch)
tree36bc99e1331499e91bed8a9a4a9898b896c95c06 /linenoise/linenoise.h
parenta7916fbac400497b6ac35da8a689a3c2cb68141d (diff)
downloadtxr-b13a869dddb06218151f00a0abec077fff9cdd4a.tar.gz
txr-b13a869dddb06218151f00a0abec077fff9cdd4a.tar.bz2
txr-b13a869dddb06218151f00a0abec077fff9cdd4a.zip
listener: Cygwin fix.
We cannot pass raw C wide literals to static_str; this breaks on platforms where wchar_t is two bytes and strings are aligned to only two byte boundaries. That's why TXR has the wli() macro. We don't want to introduce the wli() macro into linenoise, so the two choices are: duplicate the incoming mode strings into dynamic storage with string(), or pass some enum to specify file mode and locally convert to static mode string. Let's go with the latter. * linenoise.c (edit_in_editor, lino_hist_save): Use enum constant for file mode instead of mode string. * linenoise.h (enum lino_file_mode, line_file_mode_t): New enum. (struct lino_os): File opening functions use lino_file_mode_t instead of mode string. * parser.c (lino_mode_str): New static array. (lino_open, lino_open8, lino_fdopen): Take enum mode instead of string. Convert to literal through lino_mode_str table, and pass that literal to static_str.
Diffstat (limited to 'linenoise/linenoise.h')
-rw-r--r--linenoise/linenoise.h11
1 files changed, 8 insertions, 3 deletions
diff --git a/linenoise/linenoise.h b/linenoise/linenoise.h
index 8cc0a234..3c887a33 100644
--- a/linenoise/linenoise.h
+++ b/linenoise/linenoise.h
@@ -54,6 +54,11 @@ typedef unsigned char mem_t;
#define MEM_T_DEFINED
#endif
+typedef enum lino_file_mode {
+ lino_read,
+ lino_overwrite,
+} lino_file_mode_t;
+
typedef struct lino_os {
mem_t *(*alloc_fn)(size_t n);
mem_t *(*realloc_fn)(mem_t *old, size_t size);
@@ -67,9 +72,9 @@ typedef struct lino_os {
wchar_t *(*getl_fn)(mem_t *stream, wchar_t *buf, size_t nchar);
wchar_t *(*gets_fn)(mem_t *stream, wchar_t *buf, size_t nchar);
int (*eof_fn)(mem_t *stream);
- mem_t *(*open_fn)(const wchar_t *name, const wchar_t *mode);
- mem_t *(*open8_fn)(const char *name, const wchar_t *mode);
- mem_t *(*fdopen_fn)(int fd, const wchar_t *mode);
+ mem_t *(*open_fn)(const wchar_t *name, lino_file_mode_t mode);
+ mem_t *(*open8_fn)(const char *name, lino_file_mode_t mode);
+ mem_t *(*fdopen_fn)(int fd, lino_file_mode_t mode);
void (*close_fn)(mem_t *stream);
int (*wide_display_fn)(wchar_t);
} lino_os_t;