summaryrefslogtreecommitdiff
path: root/math/eval/files/patch-ac
blob: 50dd1635f5b0e698a38ad40d3a6d177de361f360 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
--- /tmp/Eval/source/eval.c	Tue Apr 13 21:04:42 1993
+++ eval.c	Wed Sep 24 12:25:27 1997
@@ -44,6 +44,9 @@
 */
 
 #include   "eval.h"
+#include   <readline/readline.h>
+#include   <readline/history.h>
+#include   <signal.h>
 
 static char    tempname[80];
 static char    wdir[100];
@@ -122,6 +125,7 @@
 static BOOLEAN process_line(FILE *stream,int showinp,int showout,VARPTR vlist,
                             VARPTR clist,char *pinput);
 static void init_varlist(VARPTR vlist);
+static void init_sig(void);
 static void var_copy(VARPTR dest,VARPTR source);
 static int print_help(FILE *stream,int extended,int page,char *s);
 static int more(char *text,char *input,int pause);
@@ -143,6 +147,8 @@
 
 
     init_varlist(vlist);
+    initialize_readline();
+    init_sig();
     wdir[0]=EOS;
     rpath[0]=EOS;
     setobase(10);
@@ -462,6 +468,7 @@
         if (input[m0]!='?')
             {
             evaluate(&input[m0],showout,vlist,clist);
+	    init_sig(); 
             break;
             }
         if (!strcmp(&input[m0],"?"))
@@ -565,6 +572,24 @@
        vlist[i].name[0]=EOS;
    }
 
+static void ignore_fpe(void)
+{
+  printf("Floating point exception... ignore result!\n");
+  signal(SIGFPE, SIG_IGN);
+}
+
+/*
+** init_sig()
+**
+** initialize signal handler for floating point exceptions
+**
+*/
+
+static void init_sig(void)
+{
+  signal(SIGFPE, ignore_fpe);
+}
+
 /*
 ** var_copy(VARPTR dest,VARPTR source)
 **
@@ -839,24 +864,89 @@
     s[j+1]=EOS;
     }
 
+char *
+complete_consts (char *text, int state)
+{
+  static int i = 0, j = 0;
+
+  if (state == 0) {
+    i = 0;
+    j = 0;
+  }
+
+  while (i<MAXC) {
+    if (strncmp (clist[i].name, text, strlen(text)) == 0)
+      return strdup(clist[i++].name);
+    else
+      i++;
+  }
 
-static int nextline(char *s,FILE *stream)
-
+  while (j<NUMFUNCS) {
+    if (strncmp (flist[j].name, text, strlen(text)) == 0)
+      return strdup(flist[j++].name);
+    else
+      j++;
+  }
+    
+  return NULL;
+}
+    
+int initialize_readline ()
+{
+  /* Allow conditional parsing of the ~/.inputrc file. */
+  rl_readline_name = "Eval";
+  
+  rl_completion_entry_function = (Function *)complete_consts;
+}
+
+/* A static variable for holding the line. */
+static char *line_read = (char *)NULL;
+     
+/* Read a string, and return a pointer to it.  Returns NULL on EOF. */
+char *
+do_gets ()
+{
+  /* If the buffer has already been allocated, return the memory
+     to the free pool. */
+  if (line_read != (char *)NULL)
     {
-    while (1)
-
-        {
-        if (stream==stdin)
-            printf("%s",PROMPT);
-        if (fgets(s,MAXINPUT,stream)==NULL)
-            return(0);
-        fixup(s);
-        if (s[0]!=';')
-            break;
-        }
-    return(1);
+      free (line_read);
+      line_read = (char *)NULL;
     }
 
+  /* Get a line from the user. */
+  line_read = readline (PROMPT);
+  
+  /* If the line has any text in it, save it on the history. */
+  if (line_read && *line_read)
+    add_history (line_read);
+  
+  return (line_read);
+}
+
+
+static int nextline(char *s,FILE *stream)
+     
+{
+  while (1)
+    
+    {
+      if (stream==stdin) {
+	if (do_gets() == NULL)
+	  return 0;
+	else
+	  strncpy(s, line_read, MAXINPUT);
+      }
+      else
+	if (fgets(s,MAXINPUT,stream)==NULL)
+	  return(0);
+      fixup(s);
+      if (s[0]!=';')
+	break;
+    }
+  return(1);
+}
+     
 
 static void close_temp(int showout)