diff options
author | Phillip Lord <phillip.lord@russet.org.uk> | 2016-07-18 23:28:05 +0100 |
---|---|---|
committer | Phillip Lord <phillip.lord@russet.org.uk> | 2017-01-14 12:07:27 +0000 |
commit | 86a2c93b3b62a1decad326fd66ed5cc1a9e64d5f (patch) | |
tree | 2bba44a75181d40df367217f4d9f2d5ec5b05925 /src | |
parent | 9569916d94c6c448862d02919e52fc3bfb9b9c8d (diff) | |
download | emacs-feature/stdout-stderr-stream.tar.gz |
Support standard input, output and error streamsfeature/stdout-stderr-stream
* doc/lispref/streams.texi: Update doc
* lisp/simple.el (external-standard-input): New function
* src/fns.c (external-standard-input-read-char,
external-standard-input-read-line): New functions
* src/print.c: (external-standard-output,
external-standard-input): New functions
Diffstat (limited to 'src')
-rw-r--r-- | src/fns.c | 62 | ||||
-rw-r--r-- | src/print.c | 19 |
2 files changed, 81 insertions, 0 deletions
diff --git a/src/fns.c b/src/fns.c index c318608e4ce..72a7e3ab820 100644 --- a/src/fns.c +++ b/src/fns.c @@ -5082,6 +5082,65 @@ If nil, use the current buffer." */ ) return make_digest_string (digest, SHA1_DIGEST_SIZE); } +DEFUN ("external-standard-input-read-char",Fexternal_standard_input_read_char, Sexternal_standard_input_read_char, 0, 0, 0, + doc: /* Read a single character from the system standard input. + +Returns -1 if standard input is at the end.*/) + (void) +{ + int c; + Lisp_Object val; + + c = getchar(); + XSETINT(val,c); + + return val; +} + +DEFUN ("external-standard-input-read-line", Fexternal_standard_input_read_line, Sexternal_standard_input_read_line, 0, 0, 0, + doc: /* Read a line from the system standard input.*/) + (void) +{ + ptrdiff_t size, len; + char *line; + Lisp_Object val; + int c; + + val = Qnil; + size = 100; + len = 0; + line = xmalloc (size); + + while ((c = getchar ()) != '\n' && c != '\r') + { + if (c == EOF) + { + if (errno != 0) + break; + } + else + { + if (len == size) + line = xpalloc (line, &size, 1, -1, sizeof *line); + line[len++] = c; + } + } + + if (len || c == '\n' || c == '\r') + { + val = make_string (line, len); + xfree (line); + } + else + { + xfree (line); + error ("Error reading from stdin"); + } + + return val; +} + + void syms_of_fns (void) @@ -5249,4 +5308,7 @@ this variable. */); defsubr (&Ssecure_hash); defsubr (&Sbuffer_hash); defsubr (&Slocale_info); + defsubr (&Sexternal_standard_input_read_char); + defsubr (&Sexternal_standard_input_read_line); + } diff --git a/src/print.c b/src/print.c index 5531210e1b8..25f0afbf972 100644 --- a/src/print.c +++ b/src/print.c @@ -769,6 +769,22 @@ to make it write to the debugging output. */) return character; } +DEFUN ("external-standard-output", Fexternal_standard_output, Sexternal_standard_output, 1, 1, 0, + doc: /* Output character CHARACTER to system standard output. */) + (Lisp_Object character) +{ + CHECK_NUMBER (character); + printchar_to_stream (XINT(character), stdout); + return character; +} + +DEFUN ("external-standard-error", Fexternal_standard_error, Sexternal_standard_error, 1, 1, 0, + doc: /* Output character CHARACTER to system standard error. */) + (Lisp_Object character) +{ + return Fexternal_debugging_output (character); +} + /* This function is never called. Its purpose is to prevent print_output_debug_flag from being optimized away. */ @@ -2307,7 +2323,10 @@ priorities. */); defsubr (&Sprinc); defsubr (&Sprint); defsubr (&Sterpri); + defsubr (&Sexternal_standard_output); + defsubr (&Sexternal_standard_error); defsubr (&Swrite_char); + defsubr (&Sredirect_debugging_output); DEFSYM (Qprint_escape_newlines, "print-escape-newlines"); |