1 /***********************************************************
2 Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
3 Amsterdam, The Netherlands.
7 Permission to use, copy, modify, and distribute this software and its
8 documentation for any purpose and without fee is hereby granted,
9 provided that the above copyright notice appear in all copies and that
10 both that copyright notice and this permission notice appear in
11 supporting documentation, and that the names of Stichting Mathematisch
12 Centrum or CWI not be used in advertising or publicity pertaining to
13 distribution of the software without specific, written prior permission.
15 STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
16 THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
17 FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
18 FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
19 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
20 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
21 OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
23 ******************************************************************/
25 /* Readline interface for tokenizer.c.
26 By default, we have a super simple my_readline function.
27 Optionally, we can use the GNU readline library (to be found in the
29 my_readline() has a different return value from GNU readline():
30 - NULL if an interrupt occurred or if an error occurred
31 - a malloc'ed empty string if EOF was read
32 - a malloc'ed string ending in \n normally
42 extern char *readline();
57 #endif /* HAVE_READLINE */
66 RETSIGTYPE (*old_inthandler
)();
69 /* Force rebind of TAB to insert-tab */
70 extern int rl_insert();
71 rl_bind_key('\t', rl_insert
);
74 old_inthandler
= signal(SIGINT
, onintr
);
76 signal(SIGINT
, old_inthandler
);
80 signal(SIGINT
, old_inthandler
);
90 if ((p
= realloc(p
, n
+2)) != NULL
) {
95 #else /* !HAVE_READLINE */
97 if ((p
= malloc(n
)) == NULL
)
100 fprintf(stderr
, "%s", prompt
);
101 if (fgets(p
, n
, stdin
) == NULL
)
108 while (n
> 0 && p
[n
-1] != '\n') {
110 p
= realloc(p
, n
+ incr
);
113 if (fgets(p
+n
, incr
, stdin
) == NULL
)
117 return realloc(p
, n
+1);
118 #endif /* !HAVE_READLINE */