File: revert_linenoise-ng.patch

package info (click to toggle)
vice 3.9%2Bdfsg-1
  • links: PTS
  • area: contrib
  • in suites: forky, sid, trixie
  • size: 54,736 kB
  • sloc: ansic: 453,239; cpp: 35,725; sh: 9,629; makefile: 7,326; perl: 1,821; yacc: 1,262; lex: 632; sed: 184; objc: 115; xml: 36; awk: 6
file content (272 lines) | stat: -rw-r--r-- 7,608 bytes parent folder | download
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
Description: revert usage of buggy and non-free linenoise-ng
 Revert linenoise-ng usage to readline.
Author: Laszlo Boszormenyi (GCS) <gcs@debian.org>
Forwarded: not-needed
Last-Update: 2024-10-19

---

--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -629,7 +629,7 @@ resid_libs = @RESID_LIBS@
 resid_dtv_libs = @RESID_DTV_LIBS@
 
 # external libraries required for all emulators
-emu_extlibs = @UI_LIBS@ @SDL_EXTRA_LIBS@ @SOUND_LIBS@ @JOY_LIBS@ @GFXOUTPUT_LIBS@ @ZLIB_LIBS@ @DYNLIB_LIBS@ @ARCH_LIBS@ $(archdep_lib) $(linenoise_ng_lib)
+emu_extlibs = @UI_LIBS@ @SDL_EXTRA_LIBS@ @SOUND_LIBS@ @JOY_LIBS@ @GFXOUTPUT_LIBS@ @ZLIB_LIBS@ @DYNLIB_LIBS@ @ARCH_LIBS@ $(archdep_lib)
 
 driver_libs = $(joyport_lib) $(samplerdrv_lib) $(sounddrv_lib) $(mididrv_lib) $(socketdrv_lib) $(hwsiddrv_lib) $(gfxoutputdrv_lib) $(printerdrv_lib) $(rs232drv_lib) $(diskimage_lib) $(fsdevice_lib) $(tape_lib) $(fileio_lib) $(serial_lib) $(core_lib)
 
@@ -1230,7 +1230,6 @@ c1541_libs = \
 	$(tape_lib) \
 	$(serial_lib) \
 	$(socketdrv_lib) \
-	$(linenoise_ng_lib) \
 	$(archdep_lib)
 
 c1541_LDADD = \
--- a/src/Makefile.in
+++ b/src/Makefile.in
@@ -1217,7 +1217,7 @@ resid_libs = @RESID_LIBS@
 resid_dtv_libs = @RESID_DTV_LIBS@
 
 # external libraries required for all emulators
-emu_extlibs = @UI_LIBS@ @SDL_EXTRA_LIBS@ @SOUND_LIBS@ @JOY_LIBS@ @GFXOUTPUT_LIBS@ @ZLIB_LIBS@ @DYNLIB_LIBS@ @ARCH_LIBS@ $(archdep_lib) $(linenoise_ng_lib)
+emu_extlibs = @UI_LIBS@ @SDL_EXTRA_LIBS@ @SOUND_LIBS@ @JOY_LIBS@ @GFXOUTPUT_LIBS@ @ZLIB_LIBS@ @DYNLIB_LIBS@ @ARCH_LIBS@ $(archdep_lib)
 driver_libs = $(joyport_lib) $(samplerdrv_lib) $(sounddrv_lib) $(mididrv_lib) $(socketdrv_lib) $(hwsiddrv_lib) $(gfxoutputdrv_lib) $(printerdrv_lib) $(rs232drv_lib) $(diskimage_lib) $(fsdevice_lib) $(tape_lib) $(fileio_lib) $(serial_lib) $(core_lib)
 @SUPPORT_X64_FALSE@x64_bin = 
 @SUPPORT_X64_TRUE@x64_bin = x64
@@ -1678,7 +1678,6 @@ c1541_libs = \
 	$(tape_lib) \
 	$(serial_lib) \
 	$(socketdrv_lib) \
-	$(linenoise_ng_lib) \
 	$(archdep_lib)
 
 c1541_LDADD = \
--- a/src/arch/shared/console_unix.c
+++ b/src/arch/shared/console_unix.c
@@ -44,8 +44,21 @@
 #include "log.h"
 #include "charset.h"
 
-#include "lib/linenoise-ng/linenoise.h"
+#if !defined(HAVE_READLINE) || !defined(HAVE_READLINE_READLINE_H)
+static FILE *mon_input;
+static FILE *mon_output;
+#endif
 
+#ifdef HAVE_READLINE
+#define _FUNCTION_DEF
+#define USE_VARARGS
+#define PREFER_STDARG
+#include <readline/readline.h>
+#include <readline/history.h>
+#undef _FUNCTION_DEF
+#undef USE_VARARGS
+#undef PREFER_STDARG
+#endif
 
 typedef struct console_private_s {
     FILE *input;
@@ -81,7 +94,10 @@ console_t *native_console_open(const cha
         printf("\033]2;VICE monitor console (%d)\007", (int)getpid());
     }
 
-    linenoiseHistorySetMaxLen(100);
+#if !defined(HAVE_READLINE) || !defined(HAVE_READLINE_READLINE_H)
+    mon_input = conpriv->input = stdin;
+    mon_output = conpriv->output = stdout;
+#endif
 
 #ifdef HAVE_SYS_IOCTL_H
     if (ioctl(fileno(stdin), TIOCGWINSZ, &w)) {
@@ -108,9 +124,7 @@ exitnull:
 
 int native_console_close(console_t *log)
 {
-    lib_free(log->private);
     lib_free(log);
-    linenoiseHistoryFree();
     return 0;
 }
 
@@ -164,23 +178,54 @@ int native_console_petscii_out(console_t
     return 0;
 }
 
+#ifndef HAVE_READLINE
+char *readline(const char *prompt)
+{
+    char *p = lib_malloc(1024);
+    size_t len;
+
+    native_console_out(NULL, "%s", prompt);
+
+    fflush(mon_output);
+    if (fgets(p, 1024, mon_input) == NULL) {
+        lib_free(p);
+        return NULL;
+    }
+
+    /* Remove trailing newlines.  */
+    for (len = strlen(p);
+            len > 0 && (p[len - 1] == '\r' || p[len - 1] == '\n');
+            len--) {
+        p[len - 1] = '\0';
+    }
+    return p;
+}
+#endif
+
 char *native_console_in(console_t *log, const char *prompt)
 {
-    char *p;
-    char *ret_string;
+    char *p, *ret_string;
 
-    p = linenoise(prompt);
-    if (p != NULL && *p != '\0') {
-        linenoiseHistoryAdd(p);
+    p = readline(prompt);
+#ifdef HAVE_READLINE
+    if (p && *p) {
+        add_history(p);
     }
+#endif
     ret_string = lib_strdup(p);
+#if 0
+    /* Don't free this, add_history() seems to take ownership */
     free(p);
+#endif
 
     return ret_string;
 }
 
 int native_console_init(void)
 {
+#if defined(HAVE_READLINE) && defined(HAVE_RLNAME)
+    rl_readline_name = "VICE";
+#endif
     return 0;
 }
 
--- a/src/c1541.c
+++ b/src/c1541.c
@@ -101,9 +101,6 @@
 #include "p64.h"
 #include "fileio/p00.h"
 
-/* we want the NG header, not the old one in arch/gtk3: */
-#include "lib/linenoise-ng/linenoise.h"
-
 #ifdef UNIX_COMPILE
 #include <unistd.h>
 #endif
@@ -537,6 +534,52 @@ const command_t command_list[] = {
 
 /* ------------------------------------------------------------------------- */
 
+#if defined(HAVE_READLINE) && defined(HAVE_READLINE_READLINE_H)
+#include <readline/readline.h>
+#include <readline/history.h>
+
+/** \brief  Read a line of input from stdin
+ *
+ * \param[in]   prompt  prompt to display to the user
+ *
+ * \return  line read from stdin
+ */
+static char *read_line(const char *prompt)
+{
+    static char *line = NULL;
+
+    if (line != NULL) {
+        free(line);
+    }
+    line = readline(prompt);
+    if (line != NULL && *line != 0) {
+        add_history(line);
+    }
+    return line;
+}
+
+#else
+
+/** \brief  Read a line of input from stdin
+ *
+ * \param[in]   prompt  prompt to display to the user
+ *
+ * \return  line read from stdin
+ */
+static char *read_line(const char *prompt)
+{
+    static char line[1024];
+
+    /* Make sure there is a 0 at the end of the string */
+    line[sizeof(line) - 1] = 0;
+
+    fputs(prompt, stdout);
+    fflush(stdout);
+    return fgets(line, sizeof(line) - 1, stdin);
+}
+
+#endif
+
 
 /** \brief  Split \a line into a list of arguments
  *
@@ -3642,7 +3685,9 @@ static int quit_cmd(int nargs, char **ar
     if (interactive_mode) {
         archdep_shutdown();
         log_close_all();    /* do we need this? */
-        linenoiseHistoryFree();
+#ifdef HAVE_READLINE_READLINE_H
+        clear_history();
+#endif
     }
     exit(0);
     return 0;   /* OSF1 cc complains */
@@ -5644,10 +5689,11 @@ int main(int argc, char **argv)
 
         /* Interactive mode.  */
         interactive_mode = 1;
-        /* init linenoise-ng */
-        linenoiseHistorySetMaxLen(100);
 
-        /* TODO: Add completions on Windows, somehow, or perhaps not */
+        /* properly init GNU readline, if available */
+#ifdef HAVE_READLINE_READLINE_H
+        using_history();
+#endif
 
         version_cmd(0, NULL);
         printf("Copyright 1995-" VICEDATE_YEAR_STR " The VICE Development Team.\n"
@@ -5664,7 +5710,7 @@ int main(int argc, char **argv)
             lib_free(buf);
             buf = lib_msprintf("c1541 #%d> ", drive_index | 8);
 
-            line = linenoise(buf);
+            line = read_line(buf);
 
             if (line == NULL) {
                 putchar('\n');
@@ -5698,7 +5744,6 @@ int main(int argc, char **argv)
                     lookup_and_execute_command(nargs, args);
                }
             }
-            linenoiseHistoryAdd(line);
         }
         lib_free(buf);
         /* free memory used by the argument 'parser' */
@@ -5708,7 +5753,9 @@ int main(int argc, char **argv)
             }
         }
         /* properly clean up GNU readline's history, if used */
-        linenoiseHistoryFree();
+#ifdef HAVE_READLINE_READLINE_H
+        clear_history();
+#endif
     } else {
         while (i < argc) {
             int match = 0, minargs = 0/*, maxargs = 0*/;