aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGerd Moellmann1999-11-03 12:41:38 +0000
committerGerd Moellmann1999-11-03 12:41:38 +0000
commitedfef199576ef058b75a2c7740bea125bb5308b0 (patch)
tree31cadd43bb2ed78795edb2bed859d204d7927285 /src
parent82a700f3f25a2a108c3e3bb65bdbf8aaa6640a2e (diff)
downloademacs-edfef199576ef058b75a2c7740bea125bb5308b0.tar.gz
emacs-edfef199576ef058b75a2c7740bea125bb5308b0.zip
(string_to_object): New.
(read_minibuf_noninteractive): New. (read_minibuf): Call read_minibuf_noninteractive if noninteractive. Use string_to_object.
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog5
-rw-r--r--src/minibuf.c136
2 files changed, 117 insertions, 24 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index a0c6d860c13..af8631a3b22 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,5 +1,10 @@
11999-11-03 Gerd Moellmann <gerd@gnu.org> 11999-11-03 Gerd Moellmann <gerd@gnu.org>
2 2
3 * minibuf.c (string_to_object): New.
4 (read_minibuf_noninteractive): New.
5 (read_minibuf): Call read_minibuf_noninteractive if
6 noninteractive. Use string_to_object.
7
3 * doc.c (Fdocumentation_property): Fix bug bypassing UNGCPRO. 8 * doc.c (Fdocumentation_property): Fix bug bypassing UNGCPRO.
4 9
51999-11-02 Dave Love <fx@gnu.org> 101999-11-02 Dave Love <fx@gnu.org>
diff --git a/src/minibuf.c b/src/minibuf.c
index 2cd3dc5aec7..28e576939f2 100644
--- a/src/minibuf.c
+++ b/src/minibuf.c
@@ -210,6 +210,112 @@ static Lisp_Object read_minibuf P_ ((Lisp_Object, Lisp_Object,
210 int, Lisp_Object, 210 int, Lisp_Object,
211 Lisp_Object, Lisp_Object, 211 Lisp_Object, Lisp_Object,
212 int, int)); 212 int, int));
213static Lisp_Object read_minibuf_noninteractive P_ ((Lisp_Object, Lisp_Object,
214 Lisp_Object, Lisp_Object,
215 int, Lisp_Object,
216 Lisp_Object, Lisp_Object,
217 int, int));
218static Lisp_Object string_to_object P_ ((Lisp_Object, Lisp_Object));
219
220
221/* Read a Lisp object from VAL and return it. If VAL is an empty
222 string, and DEFALT is a string, read from DEFALT instead of VAL. */
223
224static Lisp_Object
225string_to_object (val, defalt)
226 Lisp_Object val, defalt;
227{
228 struct gcpro gcpro1, gcpro2;
229 Lisp_Object expr_and_pos;
230 int pos;
231
232 GCPRO2 (val, defalt);
233
234 if (STRINGP (val) && XSTRING (val)->size == 0
235 && STRINGP (defalt))
236 val = defalt;
237
238 expr_and_pos = Fread_from_string (val, Qnil, Qnil);
239 pos = XINT (Fcdr (expr_and_pos));
240 if (pos != XSTRING (val)->size)
241 {
242 /* Ignore trailing whitespace; any other trailing junk
243 is an error. */
244 int i;
245 pos = string_char_to_byte (val, pos);
246 for (i = pos; i < STRING_BYTES (XSTRING (val)); i++)
247 {
248 int c = XSTRING (val)->data[i];
249 if (c != ' ' && c != '\t' && c != '\n')
250 error ("Trailing garbage following expression");
251 }
252 }
253
254 val = Fcar (expr_and_pos);
255 RETURN_UNGCPRO (val);
256}
257
258
259/* Like read_minibuf but reading from stdin. This function is called
260 from read_minibuf to do the job if noninteractive. */
261
262static Lisp_Object
263read_minibuf_noninteractive (map, initial, prompt, backup_n, expflag,
264 histvar, histpos, defalt, allow_props,
265 inherit_input_method)
266 Lisp_Object map;
267 Lisp_Object initial;
268 Lisp_Object prompt;
269 Lisp_Object backup_n;
270 int expflag;
271 Lisp_Object histvar;
272 Lisp_Object histpos;
273 Lisp_Object defalt;
274 int allow_props;
275 int inherit_input_method;
276{
277 int size, len;
278 char *line, *s;
279 struct gcpro gcpro1, gcpro2;
280 Lisp_Object val;
281
282 fprintf (stdout, "%s", XSTRING (prompt)->data);
283 fflush (stdout);
284
285 size = 100;
286 len = 0;
287 line = (char *) xmalloc (size * sizeof *line);
288 while ((s = fgets (line + len, size - len, stdin)) != NULL
289 && (len = strlen (line),
290 len == size - 1 && line[len - 1] != '\n'))
291 {
292 size *= 2;
293 line = (char *) xrealloc (line, size);
294 }
295
296 if (s)
297 {
298 len = strlen (line);
299
300 if (len > 0 && line[len - 1] == '\n')
301 line[--len] = '\0';
302
303 val = build_string (line);
304 xfree (line);
305 }
306 else
307 {
308 xfree (line);
309 error ("Error reading from stdin");
310 }
311
312 /* If Lisp form desired instead of string, parse it. */
313 if (expflag)
314 val = string_to_object (val, defalt);
315
316 return val;
317}
318
213 319
214/* Read from the minibuffer using keymap MAP, initial contents INITIAL 320/* Read from the minibuffer using keymap MAP, initial contents INITIAL
215 (a string), putting point minus BACKUP_N bytes from the end of INITIAL, 321 (a string), putting point minus BACKUP_N bytes from the end of INITIAL,
@@ -279,6 +385,11 @@ read_minibuf (map, initial, prompt, backup_n, expflag,
279 build_string ("Command attempted to use minibuffer while in minibuffer")); 385 build_string ("Command attempted to use minibuffer while in minibuffer"));
280 } 386 }
281 387
388 if (noninteractive)
389 return read_minibuf_noninteractive (map, initial, prompt, backup_n,
390 expflag, histvar, histpos, defalt,
391 allow_props, inherit_input_method);
392
282 /* Choose the minibuffer window and frame, and take action on them. */ 393 /* Choose the minibuffer window and frame, and take action on them. */
283 394
284 choose_minibuf_frame (); 395 choose_minibuf_frame ();
@@ -506,30 +617,7 @@ read_minibuf (map, initial, prompt, backup_n, expflag,
506 617
507 /* If Lisp form desired instead of string, parse it. */ 618 /* If Lisp form desired instead of string, parse it. */
508 if (expflag) 619 if (expflag)
509 { 620 val = string_to_object (val, defalt);
510 Lisp_Object expr_and_pos;
511 int pos;
512
513 if (STRINGP (val) && XSTRING (val)->size == 0
514 && STRINGP (defalt))
515 val = defalt;
516
517 expr_and_pos = Fread_from_string (val, Qnil, Qnil);
518 pos = XINT (Fcdr (expr_and_pos));
519 if (pos != XSTRING (val)->size)
520 {
521 /* Ignore trailing whitespace; any other trailing junk is an error. */
522 int i;
523 pos = string_char_to_byte (val, pos);
524 for (i = pos; i < STRING_BYTES (XSTRING (val)); i++)
525 {
526 int c = XSTRING (val)->data[i];
527 if (c != ' ' && c != '\t' && c != '\n')
528 error ("Trailing garbage following expression");
529 }
530 }
531 val = Fcar (expr_and_pos);
532 }
533 621
534 /* The appropriate frame will get selected 622 /* The appropriate frame will get selected
535 in set-window-configuration. */ 623 in set-window-configuration. */