summaryrefslogtreecommitdiffstats
path: root/stream.h
diff options
context:
space:
mode:
Diffstat (limited to 'stream.h')
-rw-r--r--stream.h85
1 files changed, 62 insertions, 23 deletions
diff --git a/stream.h b/stream.h
index 2d7688c6..d4300154 100644
--- a/stream.h
+++ b/stream.h
@@ -1,4 +1,4 @@
-/* Copyright 2009-2020
+/* Copyright 2009-2024
* Kaz Kylheku <kaz@kylheku.com>
* Vancouver, Canada
* All rights reserved.
@@ -6,23 +6,24 @@
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
- * 1. Redistributions of source code must retain the above copyright notice, this
- * list of conditions and the following disclaimer.
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
*/
enum strm_whence {
@@ -55,6 +56,7 @@ struct strm_base {
unsigned force_break;
cnum max_length;
cnum max_depth;
+ val close_result;
struct strm_ctx *ctx;
};
@@ -69,8 +71,8 @@ struct strm_ops {
val (*get_byte)(val);
val (*unget_char)(val, val);
val (*unget_byte)(val, int);
- val (*put_buf)(val, val, cnum);
- val (*fill_buf)(val, val, cnum);
+ ucnum (*put_buf)(val, mem_t *, ucnum len, ucnum pos);
+ ucnum (*fill_buf)(val, mem_t *, ucnum len, ucnum pos);
val (*close)(val, val);
val (*flush)(val);
val (*seek)(val, val, enum strm_whence);
@@ -109,26 +111,38 @@ struct stdio_mode {
unsigned append : 1;
unsigned binary : 1;
unsigned notrunc : 1;
+ unsigned excl : 1;
+ unsigned nonblock : 1;
unsigned interactive : 1;
unsigned unbuf : 1;
unsigned linebuf : 1;
+ unsigned gzip : 1;
+ unsigned gzlevel : 4;
+ unsigned tmpfile : 1;
int buforder : 5;
int redir[STDIO_MODE_NREDIRS][2];
};
-#define stdio_mode_init_blank { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1 }
-#define stdio_mode_init_r { 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, -1 }
-#define stdio_mode_init_rpb { 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, -1 }
+#define stdio_mode_init_blank { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, { { 0 } } }
+#define stdio_mode_init_r { 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, { { 0 } } }
+#define stdio_mode_init_rpb { 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, { { 0 } } }
#define std_input (deref(lookup_var_l(nil, stdin_s)))
#define std_output (deref(lookup_var_l(nil, stdout_s)))
#define std_debug (deref(lookup_var_l(nil, stddebug_s)))
#define std_error (deref(lookup_var_l(nil, stderr_s)))
#define std_null (deref(lookup_var_l(nil, stdnull_s)))
+
+enum json_fmt {
+ json_fmt_default,
+ json_fmt_standard
+};
+
loc lookup_var_l(val env, val sym);
extern val from_start_k, from_current_k, from_end_k;
extern val real_time_k, name_k, addr_k, fd_k, byte_oriented_k;
+extern val standard_k;
extern val format_s;
extern val stdio_stream_s;
@@ -142,12 +156,18 @@ extern val get_error_s, get_error_str_s, clear_error_s, get_fd_s;
extern val print_flo_precision_s, print_flo_digits_s, print_flo_format_s;
extern val pprint_flo_format_s, print_base_s, print_circle_s;
+extern val print_json_format_s;
#if HAVE_SOCKETS
extern val socket_error_s;
#endif
extern const wchli_t *path_sep_chars;
+extern wchar_t path_var_sep_char;
+
+extern val top_stderr;
+
+extern struct cobj_class *stream_cls, *stdio_stream_cls;
void strm_base_init(struct strm_base *s);
void strm_base_cleanup(struct strm_base *s);
@@ -156,16 +176,20 @@ void fill_stream_ops(struct strm_ops *ops);
void stream_print_op(val stream, val out, val pretty, struct strm_ctx *);
void stream_mark_op(val stream);
void stream_destroy_op(val stream);
-struct stdio_mode parse_mode(val mode_str, struct stdio_mode m_dfl);
-val normalize_mode(struct stdio_mode *m, val mode_str, struct stdio_mode m_dfl);
-val normalize_mode_no_bin(struct stdio_mode *m, val mode_str, struct stdio_mode m_dfl);
+int w_open_mode(const wchar_t *wname, const struct stdio_mode m);
+struct stdio_mode parse_mode(val mode_str, struct stdio_mode m_dfl, val self);
+val normalize_mode(struct stdio_mode *m, val mode_str,
+ struct stdio_mode m_dfl, val self);
+val normalize_mode_no_bin(struct stdio_mode *m, val mode_str,
+ struct stdio_mode m_dfl, val self);
val set_mode_props(const struct stdio_mode m, val stream);
val generic_get_line(val stream);
val errno_to_string(val err);
val make_null_stream(void);
val make_stdio_stream(FILE *, val descr);
val make_tail_stream(FILE *, val descr);
-val make_pipe_stream(FILE *, val descr);
+val pipe_close_status_helper(val stream, val throw_on_error,
+ int status, val self);
val stream_fd(val stream);
#if HAVE_SOCKETS
val make_sock_stream(FILE *f, val family, val type);
@@ -193,11 +217,13 @@ val clear_error(val stream);
val get_line(val);
val get_char(val);
val get_byte(val);
+val get_bytes(val self, val, mem_t *ptr, ucnum len);
val unget_char(val ch, val stream);
val unget_byte(val byte, val stream);
val put_buf(val buf, val pos, val stream);
val fill_buf(val buf, val pos, val stream);
val fill_buf_adjust(val buf, val pos, val stream);
+val get_line_as_buf(val stream);
val vformat(val stream, val string, va_list);
val vformat_to_string(val string, va_list);
val format(val stream, val string, ...);
@@ -219,6 +245,7 @@ val set_indent_mode(val stream, val mode);
val get_indent(val stream);
val set_indent(val stream, val indent);
val inc_indent(val stream, val delta);
+val inc_indent_abs(val stream, val delta);
val width_check(val stream, val alt);
val force_break(val stream);
val set_max_length(val stream, val length);
@@ -228,9 +255,10 @@ struct strm_ctx *get_ctx(val stream);
val get_string(val stream, val nchars, val close_after_p);
val open_directory(val path);
val open_file(val path, val mode_str);
-val open_fileno(val fd, val mode_str);
+val open_fileno(val fd, val mode_str, val pid_opt);
val open_tail(val path, val mode_str, val seek_end_p);
val open_command(val path, val mode_str);
+val path_search(val name, val path_in);
val open_process(val path, val mode_str, val args);
val make_catenated_stream(val stream_list);
val make_catenated_stream_v(struct args *streams);
@@ -238,13 +266,24 @@ val catenated_stream_p(val obj);
val catenated_stream_push(val new_stream, val cat_stream);
val remove_path(val path, val throw_on_error);
val rename_path(val from, val to);
+val portable_abs_path_p(val path);
val abs_path_p(val path);
val pure_rel_path_p(val path);
val base_name(val path, val suff);
val dir_name(val path);
+val short_suffix(val name, val alt_in);
+val long_suffix(val name, val alt_in);
+val trim_short_suffix(val name);
+val trim_long_suffix(val name);
+val trim_path_seps(val name);
val path_cat(val dir_name, val base_name);
+val add_suffix(val name, val suffix);
val make_byte_input_stream(val obj);
val iobuf_get(void);
void iobuf_put(val buf);
void iobuf_list_empty(void);
+val tmpfile_wrap(void);
+val mkdtemp_wrap(val prefix);
+val mkstemp_wrap(val prefix, val suffix);
void stream_init(void);
+void stream_compat_fixup(int compat_ver);