diff options
| author | Phillip Lord | 2016-07-18 23:28:05 +0100 |
|---|---|---|
| committer | Phillip Lord | 2017-01-14 12:07:27 +0000 |
| commit | 86a2c93b3b62a1decad326fd66ed5cc1a9e64d5f (patch) | |
| tree | 2bba44a75181d40df367217f4d9f2d5ec5b05925 /src | |
| parent | 9569916d94c6c448862d02919e52fc3bfb9b9c8d (diff) | |
| download | emacs-feature/stdout-stderr-stream.tar.gz emacs-feature/stdout-stderr-stream.zip | |
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
| @@ -5082,6 +5082,65 @@ If nil, use the current buffer." */ ) | |||
| 5082 | return make_digest_string (digest, SHA1_DIGEST_SIZE); | 5082 | return make_digest_string (digest, SHA1_DIGEST_SIZE); |
| 5083 | } | 5083 | } |
| 5084 | 5084 | ||
| 5085 | DEFUN ("external-standard-input-read-char",Fexternal_standard_input_read_char, Sexternal_standard_input_read_char, 0, 0, 0, | ||
| 5086 | doc: /* Read a single character from the system standard input. | ||
| 5087 | |||
| 5088 | Returns -1 if standard input is at the end.*/) | ||
| 5089 | (void) | ||
| 5090 | { | ||
| 5091 | int c; | ||
| 5092 | Lisp_Object val; | ||
| 5093 | |||
| 5094 | c = getchar(); | ||
| 5095 | XSETINT(val,c); | ||
| 5096 | |||
| 5097 | return val; | ||
| 5098 | } | ||
| 5099 | |||
| 5100 | DEFUN ("external-standard-input-read-line", Fexternal_standard_input_read_line, Sexternal_standard_input_read_line, 0, 0, 0, | ||
| 5101 | doc: /* Read a line from the system standard input.*/) | ||
| 5102 | (void) | ||
| 5103 | { | ||
| 5104 | ptrdiff_t size, len; | ||
| 5105 | char *line; | ||
| 5106 | Lisp_Object val; | ||
| 5107 | int c; | ||
| 5108 | |||
| 5109 | val = Qnil; | ||
| 5110 | size = 100; | ||
| 5111 | len = 0; | ||
| 5112 | line = xmalloc (size); | ||
| 5113 | |||
| 5114 | while ((c = getchar ()) != '\n' && c != '\r') | ||
| 5115 | { | ||
| 5116 | if (c == EOF) | ||
| 5117 | { | ||
| 5118 | if (errno != 0) | ||
| 5119 | break; | ||
| 5120 | } | ||
| 5121 | else | ||
| 5122 | { | ||
| 5123 | if (len == size) | ||
| 5124 | line = xpalloc (line, &size, 1, -1, sizeof *line); | ||
| 5125 | line[len++] = c; | ||
| 5126 | } | ||
| 5127 | } | ||
| 5128 | |||
| 5129 | if (len || c == '\n' || c == '\r') | ||
| 5130 | { | ||
| 5131 | val = make_string (line, len); | ||
| 5132 | xfree (line); | ||
| 5133 | } | ||
| 5134 | else | ||
| 5135 | { | ||
| 5136 | xfree (line); | ||
| 5137 | error ("Error reading from stdin"); | ||
| 5138 | } | ||
| 5139 | |||
| 5140 | return val; | ||
| 5141 | } | ||
| 5142 | |||
| 5143 | |||
| 5085 | 5144 | ||
| 5086 | void | 5145 | void |
| 5087 | syms_of_fns (void) | 5146 | syms_of_fns (void) |
| @@ -5249,4 +5308,7 @@ this variable. */); | |||
| 5249 | defsubr (&Ssecure_hash); | 5308 | defsubr (&Ssecure_hash); |
| 5250 | defsubr (&Sbuffer_hash); | 5309 | defsubr (&Sbuffer_hash); |
| 5251 | defsubr (&Slocale_info); | 5310 | defsubr (&Slocale_info); |
| 5311 | defsubr (&Sexternal_standard_input_read_char); | ||
| 5312 | defsubr (&Sexternal_standard_input_read_line); | ||
| 5313 | |||
| 5252 | } | 5314 | } |
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. */) | |||
| 769 | return character; | 769 | return character; |
| 770 | } | 770 | } |
| 771 | 771 | ||
| 772 | DEFUN ("external-standard-output", Fexternal_standard_output, Sexternal_standard_output, 1, 1, 0, | ||
| 773 | doc: /* Output character CHARACTER to system standard output. */) | ||
| 774 | (Lisp_Object character) | ||
| 775 | { | ||
| 776 | CHECK_NUMBER (character); | ||
| 777 | printchar_to_stream (XINT(character), stdout); | ||
| 778 | return character; | ||
| 779 | } | ||
| 780 | |||
| 781 | DEFUN ("external-standard-error", Fexternal_standard_error, Sexternal_standard_error, 1, 1, 0, | ||
| 782 | doc: /* Output character CHARACTER to system standard error. */) | ||
| 783 | (Lisp_Object character) | ||
| 784 | { | ||
| 785 | return Fexternal_debugging_output (character); | ||
| 786 | } | ||
| 787 | |||
| 772 | /* This function is never called. Its purpose is to prevent | 788 | /* This function is never called. Its purpose is to prevent |
| 773 | print_output_debug_flag from being optimized away. */ | 789 | print_output_debug_flag from being optimized away. */ |
| 774 | 790 | ||
| @@ -2307,7 +2323,10 @@ priorities. */); | |||
| 2307 | defsubr (&Sprinc); | 2323 | defsubr (&Sprinc); |
| 2308 | defsubr (&Sprint); | 2324 | defsubr (&Sprint); |
| 2309 | defsubr (&Sterpri); | 2325 | defsubr (&Sterpri); |
| 2326 | defsubr (&Sexternal_standard_output); | ||
| 2327 | defsubr (&Sexternal_standard_error); | ||
| 2310 | defsubr (&Swrite_char); | 2328 | defsubr (&Swrite_char); |
| 2329 | |||
| 2311 | defsubr (&Sredirect_debugging_output); | 2330 | defsubr (&Sredirect_debugging_output); |
| 2312 | 2331 | ||
| 2313 | DEFSYM (Qprint_escape_newlines, "print-escape-newlines"); | 2332 | DEFSYM (Qprint_escape_newlines, "print-escape-newlines"); |