Lines 1-20
Link Here
|
1 |
--- cider/common/src/bin/main.c.orig Sat Mar 12 08:20:59 1994 |
1 |
--- cider/common/src/bin/main.c.orig Sat Mar 12 08:20:59 1994 |
2 |
+++ cider/common/src/bin/main.c Wed Sep 19 11:07:47 2001 |
2 |
+++ cider/common/src/bin/main.c Fri Oct 17 22:19:55 2003 |
3 |
@@ -25,6 +25,13 @@ |
3 |
@@ -36,6 +36,11 @@ |
4 |
#include <pwd.h> |
|
|
5 |
#endif |
6 |
|
7 |
+#ifdef HAS_GNUREADLINE |
8 |
+/* Added GNU Readline Support 11/3/97 -- Andrew Veliath <veliaa@rpi.edu> */ |
9 |
+#include <readline/readline.h> |
10 |
+#include <readline/history.h> |
11 |
+#include "fteinput.h" |
12 |
+#endif |
13 |
+ |
14 |
#ifdef HAS_UNIX_SIGS |
15 |
#include <signal.h> |
16 |
#endif |
17 |
@@ -36,6 +43,11 @@ |
18 |
#endif |
4 |
#endif |
19 |
|
5 |
|
20 |
#include "patchlev.h" |
6 |
#include "patchlev.h" |
Lines 26-197
Link Here
|
26 |
#include "suffix.h" |
12 |
#include "suffix.h" |
27 |
|
13 |
|
28 |
/* (Virtual) Machine architecture parameters */ |
14 |
/* (Virtual) Machine architecture parameters */ |
29 |
@@ -53,6 +65,11 @@ |
15 |
@@ -214,6 +219,10 @@ |
30 |
bool ft_intrpt = false; /* Set by the (void) signal handlers. */ |
16 |
FILE *fp; |
31 |
bool ft_setflag = false; /* Don't abort after an interrupt. */ |
17 |
FILE *circuit_file; |
32 |
|
18 |
|
33 |
+#ifdef HAS_GNUREADLINE |
|
|
34 |
+char gnu_history_file[512]; |
35 |
+static char *application_name; |
36 |
+#endif |
19 |
+#endif |
37 |
+ |
20 |
+ |
38 |
struct variable *(*if_getparam)( ); |
|
|
39 |
|
40 |
#ifdef BATCH |
41 |
@@ -185,6 +202,95 @@ |
42 |
|
43 |
#endif |
44 |
|
45 |
+#ifdef HAS_GNUREADLINE |
46 |
+/* Adapted ../lib/cp/lexical.c:prompt() for GNU Readline -- Andrew Veliath <veliaa@rpi.edu> */ |
47 |
+static char * |
48 |
+prompt() |
49 |
+{ |
50 |
+ static char pbuf[128]; |
51 |
+ int n = sizeof(pbuf); |
52 |
+ char *p = pbuf, *s; |
53 |
+ |
54 |
+ if (cp_interactive == false) |
55 |
+ return; |
56 |
+ if (cp_promptstring == NULL) |
57 |
+ s = "-> "; |
58 |
+ else |
59 |
+ s = cp_promptstring; |
60 |
+ if (cp_altprompt) |
61 |
+ s = cp_altprompt; |
62 |
+ while (*s && (n > 1)) { |
63 |
+ int w; |
64 |
+ switch (strip(*s)) { |
65 |
+ case '!': |
66 |
+ w = snprintf(p, n, "%d", where_history() + 1); |
67 |
+ w = (w >= n) ? n - 1 : w; |
68 |
+ p += w; |
69 |
+ n -= w; |
70 |
+ break; |
71 |
+ case '\\': |
72 |
+ if (*(s + 1)) ++s; |
73 |
+ default: |
74 |
+ *p = strip(*s); ++p; |
75 |
+ --n; |
76 |
+ break; |
77 |
+ } |
78 |
+ s++; |
79 |
+ } |
80 |
+ *p = 0; |
81 |
+ return pbuf; |
82 |
+} |
83 |
+ |
84 |
+/* Process device events in Readline's hook since there is no where |
85 |
+ else to do it now - AV */ |
86 |
+int rl_event_func() |
87 |
+{ |
88 |
+ static REQUEST reqst = { checkup_option, 0 }; |
89 |
+ Input(&reqst, NULL); |
90 |
+ return 0; |
91 |
+} |
92 |
+ |
93 |
+/* Added GNU Readline Support -- Andrew Veliath <veliaa@rpi.edu> */ |
94 |
+void app_rl_readlines() |
95 |
+{ |
96 |
+ char *line, *expanded_line; |
97 |
+ |
98 |
+ strcpy(gnu_history_file, getenv("HOME")); |
99 |
+ strcat(gnu_history_file, "/."); |
100 |
+ strcat(gnu_history_file, application_name); |
101 |
+ strcat(gnu_history_file, "_history"); |
102 |
+ |
103 |
+ using_history(); |
104 |
+ read_history(gnu_history_file); |
105 |
+ |
106 |
+ rl_readline_name = application_name; |
107 |
+ rl_instream = cp_in; |
108 |
+ rl_outstream = cp_out; |
109 |
+ rl_event_hook = rl_event_func; |
110 |
+ |
111 |
+ while (1) { |
112 |
+ history_set_pos(history_length); |
113 |
+ line = readline(prompt()); |
114 |
+ if (line && *line) { |
115 |
+ int s = history_expand(line, &expanded_line); |
116 |
+ |
117 |
+ if (s == 2) { |
118 |
+ fprintf(stderr, "-> %s\n", expanded_line); |
119 |
+ } else if (s == -1) { |
120 |
+ fprintf(stderr, "readline: %s\n", expanded_line); |
121 |
+ } else { |
122 |
+ cp_evloop(expanded_line); |
123 |
+ add_history(expanded_line); |
124 |
+ } |
125 |
+ free(expanded_line); |
126 |
+ } |
127 |
+ if (line) free(line); |
128 |
+ else if (line == NULL) cp_evloop("quit"); |
129 |
+ } |
130 |
+ /* History gets written in ../fte/misccoms.c com_quit */ |
131 |
+} |
132 |
+#endif /* HAS_GNUREADLINE */ |
133 |
+ |
134 |
char *hlp_filelist[] = { "spice", "cider", 0 }; |
135 |
|
136 |
void |
137 |
@@ -216,6 +322,10 @@ |
138 |
|
139 |
#endif |
140 |
|
141 |
+#ifdef __FreeBSD__ |
21 |
+#ifdef __FreeBSD__ |
142 |
+ fpsetmask(fpgetmask() & ~FP_X_INV & ~FP_X_DZ & ~FP_X_OFL); |
22 |
+ fpsetmask(fpgetmask() & ~FP_X_INV & ~FP_X_DZ & ~FP_X_OFL); |
143 |
+#endif |
|
|
144 |
+ |
145 |
/* MFB tends to jump to 0 on errors. This tends to catch it. */ |
146 |
if (started) { |
147 |
fprintf(cp_err, "main: Internal Error: jump to zero\n"); |
148 |
@@ -236,6 +346,13 @@ |
149 |
ARCHsize = 1; |
150 |
#endif /* PARALLEL_ARCH */ |
151 |
|
152 |
+#ifdef HAS_GNUREADLINE |
153 |
+ if (!(application_name = strrchr(av[0],'/'))) |
154 |
+ application_name = av[0]; |
155 |
+ else |
156 |
+ ++application_name; |
157 |
+#endif |
158 |
+ |
159 |
#ifdef HAS_MAC_ARGCARGV |
160 |
ac = initmac(&av); |
161 |
#endif |
162 |
@@ -472,7 +589,11 @@ |
163 |
# ifdef HAS_UNIX_SIGS |
164 |
/* Set up (void) signal handling */ |
165 |
if (!ft_batchmode) { |
166 |
+# ifdef HAS_GNUREADLINE |
167 |
+ (void) signal(SIGINT, SIG_IGN); |
168 |
+# else |
169 |
(void) signal(SIGINT, ft_sigintr); |
170 |
+# endif |
171 |
(void) signal(SIGFPE, sigfloat); |
172 |
# ifdef SIGTSTP |
173 |
(void) signal(SIGTSTP, sigstop); |
174 |
@@ -668,7 +789,11 @@ |
175 |
} else { |
176 |
(void) setjmp(jbuf); |
177 |
cp_interactive = true; |
178 |
+#ifdef HAS_GNUREADLINE |
179 |
+ app_rl_readlines(); |
180 |
+#else |
181 |
while (cp_evloop((char *) NULL) == 1) ; |
182 |
+#endif /* ifelse HAS_GNUREADLINE */ |
183 |
} |
184 |
|
185 |
# else /* if BATCH */ |
186 |
@@ -708,7 +833,11 @@ |
187 |
/* Nutmeg "main" */ |
188 |
(void) setjmp(jbuf); |
189 |
cp_interactive = true; |
190 |
+#ifdef HAS_GNUREADLINE |
191 |
+ app_rl_readlines(); |
192 |
+#else |
193 |
while (cp_evloop((char *) NULL) == 1) ; |
194 |
+#endif /* ifelse HAS_GNUREADLINE */ |
195 |
|
196 |
#endif |
23 |
#endif |
197 |
|
24 |
|
|
|
25 |
/* MFB tends to jump to 0 on errors. This tends to catch it. */ |