[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 4/5] Fix erroneous completer for the .close command
From: |
John Darrington |
Subject: |
[PATCH 4/5] Fix erroneous completer for the .close command |
Date: |
Fri, 21 Feb 2020 17:36:34 +0100 |
Originally all open io spaces had ids (tags) numbered from zero to N - 1.
Sometime ago this behaviour was changed, however the completer was not updated
to reflect this. Consequently the wrong completions were provided. This change
fixes the completer.
---
ChangeLog | 10 ++++++++++
src/ios.c | 27 +--------------------------
src/ios.h | 51 +++++++++++++++++++++++++++++++++++++++------------
src/pk-ios.c | 28 ++++++++--------------------
4 files changed, 58 insertions(+), 58 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 319c99b0..dce14fc8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2020-02-16 John Darrington <address@hidden>
+
+ * src/ios.h (struct ios): New structure.
+ * src/ios.h (io_list): New reference.
+ * src/ios.c (struct ios): Delete.
+ * src/ios.c (io_list): Expose scope.
+ * src/pk-ios.c (count_io_spaces) delete.
+ * src/pk-ios.c (close_completion_function): Do not assume that
+ all ids are consecutive integers from zero.
+
2020-02-16 John Darrington <address@hidden>
* src/pk-repl.c (poke_getc): Revert to poke_completion_function
diff --git a/src/ios.c b/src/ios.c
index d6b6735d..3b7a9582 100644
--- a/src/ios.c
+++ b/src/ios.c
@@ -100,38 +100,13 @@
IOS_GET_C_ERR_CHCK((charray)[8], io); \
}
-/* The following struct implements an instance of an IO space.
-
- `IS' is an unique integer identifying the IO space.
-
- HANDLER is a copy of the handler string used to open the space.
-
- DEV is the device operated by the IO space.
- DEV_IF is the interface to use when operating the device.
-
- NEXT is a pointer to the next open IO space, or NULL.
-
- XXX: add status, saved or not saved.
- */
-
-struct ios
-{
- int id;
- char *handler;
- void *dev;
- struct ios_dev_if *dev_if;
- ios_off bias;
-
- struct ios *next;
-};
-
/* Next available IOS id. */
static int ios_next_id = 0;
/* List of IO spaces, and pointer to the current one. */
-static struct ios *io_list;
+struct ios *io_list;
static struct ios *cur_io;
/* The available backends are implemented in their own files, and
diff --git a/src/ios.h b/src/ios.h
index 377510ef..c9d5f700 100644
--- a/src/ios.h
+++ b/src/ios.h
@@ -22,6 +22,45 @@
#include <config.h>
#include <stdint.h>
+/* IO spaces are bit-addressable. "Offsets" characterize positions
+ into IO spaces.
+
+ Offsets are encoded in 64-bit integers, which denote the number of
+ bits since the beginning of the space. They can be added,
+ subtracted and multiplied.
+
+ Since negative offsets are possible, the maximum size of any given
+ IO space is 2^60 bytes. */
+
+typedef int64_t ios_off;
+
+/* The following struct implements an instance of an IO space.
+
+ `IS' is an unique integer identifying the IO space.
+
+ HANDLER is a copy of the handler string used to open the space.
+
+ DEV is the device operated by the IO space.
+ DEV_IF is the interface to use when operating the device.
+
+ NEXT is a pointer to the next open IO space, or NULL.
+
+ XXX: add status, saved or not saved.
+ */
+
+struct ios
+{
+ int id;
+ char *handler;
+ void *dev;
+ struct ios_dev_if *dev_if;
+ ios_off bias;
+
+ struct ios *next;
+};
+
+extern struct ios *io_list;
+
/* The following two functions intialize and shutdown the IO poke
subsystem. */
@@ -70,18 +109,6 @@ void ios_shutdown (void);
typedef struct ios *ios;
-/* IO spaces are bit-addressable. "Offsets" characterize positions
- into IO spaces.
-
- Offsets are encoded in 64-bit integers, which denote the number of
- bits since the beginning of the space. They can be added,
- subtracted and multiplied.
-
- Since negative offsets are possible, the maximum size of any given
- IO space is 2^60 bytes. */
-
-typedef int64_t ios_off;
-
/* The following status codes are used in the several APIs defined
below in the file. */
diff --git a/src/pk-ios.c b/src/pk-ios.c
index afc7d86f..43c340a3 100644
--- a/src/pk-ios.c
+++ b/src/pk-ios.c
@@ -34,41 +34,29 @@
# include "pk-hserver.h"
#endif
-static void
-count_io_spaces (ios io, void *data)
-{
- int *i = (int *) data;
- if (i == NULL)
- return;
- (*i)++;
-}
-
static char *
close_completion_function (const char *x, int state)
{
- static int idx = 0;
- static int n_ids = 0;
+ static ios io;
if (state == 0)
{
- idx = 0;
- n_ids = 0;
- ios_map (count_io_spaces, &n_ids);
+ io = io_list;
}
else
- ++idx;
+ {
+ io = io->next;
+ }
int len = strlen (x);
- while (1)
+ while (io)
{
- if (idx >= n_ids)
- break;
char buf[16];
- snprintf (buf, 16, "#%d", idx);
+ snprintf (buf, 16, "#%d", io->id);
int match = strncmp (buf, x, len);
if (match != 0)
{
- idx++;
+ io = io->next;
continue;
}
--
2.20.1