home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 8 / FreshFishVol8-CD1.bin / new / util / edit / jade / src / commandline.c < prev    next >
C/C++ Source or Header  |  1994-07-03  |  2KB  |  69 lines

  1. /* commandline.c -- Braindead prompt
  2.    Copyright (C) 1993, 1994 John Harper <jsh@ukc.ac.uk>
  3.  
  4.    This file is part of Jade.
  5.  
  6.    Jade is free software; you can redistribute it and/or modify it
  7.    under the terms of the GNU General Public License as published by
  8.    the Free Software Foundation; either version 2, or (at your option)
  9.    any later version.
  10.  
  11.    Jade is distributed in the hope that it will be useful, but
  12.    WITHOUT ANY WARRANTY; without even the implied warranty of
  13.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.    GNU General Public License for more details.
  15.  
  16.    You should have received a copy of the GNU General Public License
  17.    along with Jade; see the file COPYING.  If not, write to
  18.    the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20. #include "jade.h"
  21. #include "jade_protos.h"
  22.  
  23. #include <string.h>
  24.  
  25. _PR void commandline_init(void);
  26. _PR void commandline_kill(void);
  27. _PR u_char *last_prompted;      /* one line history */
  28. u_char *last_prompted;
  29.  
  30. _PR VALUE cmd_prompt(VALUE prompt, VALUE string);
  31. DEFUN("prompt", cmd_prompt, subr_prompt, (VALUE prompt, VALUE string), V_Subr2, DOC_prompt) /*
  32. ::doc:prompt::
  33. prompt PROMPT [STRING]
  34.  
  35. Displays PROMPT and waits for the user to enter a string, which is
  36. then returned. If STRING is provided it is used as the starting value
  37. of the string.
  38. ::end:: */
  39. {
  40.     u_char *str = NULL;
  41.     VALUE res;
  42.     DECLARE1(prompt, STRINGP);
  43.     if(STRINGP(string))
  44.     str = VSTR(string);
  45.     str = sys_prompt(curr_vw, VSTR(prompt), str);
  46.     if(str)
  47.     {
  48.     res = string_dup(str);
  49.     str_free(str);
  50.     return(res);
  51.     }
  52.     return(sym_nil);
  53. }
  54.  
  55. void
  56. commandline_init(void)
  57. {
  58.     ADD_SUBR(subr_prompt);
  59. }
  60. void
  61. commandline_kill(void)
  62. {
  63.     if(last_prompted)
  64.     {
  65.     str_free(last_prompted);
  66.     last_prompted = NULL;
  67.     }
  68. }
  69.