Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/lib/libcurses Re-arrange some code to approach our regular s...
details: https://anonhg.NetBSD.org/src/rev/862dded21a3d
branches: trunk
changeset: 473545:862dded21a3d
user: pk <pk%NetBSD.org@localhost>
date: Sun Jun 06 21:05:03 1999 +0000
description:
Re-arrange some code to approach our regular style.
diffstat:
lib/libcurses/getch.c | 276 +++++++++++++++++++++++++------------------------
1 files changed, 139 insertions(+), 137 deletions(-)
diffs (truncated from 429 to 300 lines):
diff -r b80daeb3ba23 -r 862dded21a3d lib/libcurses/getch.c
--- a/lib/libcurses/getch.c Sun Jun 06 20:45:21 1999 +0000
+++ b/lib/libcurses/getch.c Sun Jun 06 21:05:03 1999 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: getch.c,v 1.11 1999/06/06 20:43:00 pk Exp $ */
+/* $NetBSD: getch.c,v 1.12 1999/06/06 21:05:03 pk Exp $ */
/*
* Copyright (c) 1981, 1993, 1994
@@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)getch.c 8.2 (Berkeley) 5/4/94";
#else
-__RCSID("$NetBSD: getch.c,v 1.11 1999/06/06 20:43:00 pk Exp $");
+__RCSID("$NetBSD: getch.c,v 1.12 1999/06/06 21:05:03 pk Exp $");
#endif
#endif /* not lint */
@@ -71,7 +71,7 @@
union {
keymap_t *next; /* next keymap is key is multi-key sequence */
int symbol; /* key symbol if key is a leaf entry */
- } value;
+ } value;
};
/* Types of key structures we can have */
#define KEYMAP_MULTI 1 /* part of a multi char sequence */
@@ -83,8 +83,8 @@
#define MAX_CHAR 256
struct keymap {
- int count; /* count of number of key structs allocated */
- short mapping[MAX_CHAR]; /* mapping of key to allocated structs */
+ int count; /* count of number of key structs allocated */
+ short mapping[MAX_CHAR]; /* mapping of key to allocated structs */
key_entry_t **key; /* dynamic array of keys */};
@@ -94,22 +94,22 @@
char inbuf[INBUF_SZ];
int start, end, working; /* pointers for manipulating inbuf data */
-#define INC_POINTER(ptr) do { \
- (ptr)++; \
- ptr %= INBUF_SZ; \
+#define INC_POINTER(ptr) do { \
+ (ptr)++; \
+ ptr %= INBUF_SZ; \
} while(/*CONSTCOND*/0)
-short state; /* state of the inkey function */
+short state; /* state of the inkey function */
-#define INKEY_NORM 0 /* no key backlog to process */
+#define INKEY_NORM 0 /* no key backlog to process */
#define INKEY_ASSEMBLING 1 /* assembling a multi-key sequence */
-#define INKEY_BACKOUT 2 /* recovering from an unrecognised key */
-#define INKEY_TIMEOUT 3 /* multi-key sequence timeout */
+#define INKEY_BACKOUT 2 /* recovering from an unrecognised key */
+#define INKEY_TIMEOUT 3 /* multi-key sequence timeout */
/* The termcap data we are interested in and the symbols they map to */
struct tcdata {
- char *name; /* name of termcap entry */
- int symbol; /* the symbol associated with it */
+ char *name; /* name of termcap entry */
+ int symbol; /* the symbol associated with it */
};
const struct tcdata tc[] = {
@@ -158,14 +158,9 @@
keymap_t *base_keymap;
/* prototypes for private functions */
-keymap_t *
-new_keymap(void); /* create a new keymap */
-
-key_entry_t *
-new_key(void); /* create a new key entry */
-
-unsigned
-inkey(int, int);
+keymap_t *new_keymap(void); /* create a new keymap */
+key_entry_t *new_key(void); /* create a new key entry */
+unsigned inkey(int, int);
/*
* Init_getch - initialise all the pointers & structures needed to make
@@ -176,10 +171,10 @@
__init_getch(sp)
char *sp;
{
- int i, j, length;
+static char termcap[1024];
+ char entry[1024], termname[1024], *p;
+ int i, j, length;
keymap_t *current;
-static char termcap[1024];
- char entry[1024], termname[1024], *p;
key_entry_t *the_key;
/* init the inkey state variable */
@@ -195,69 +190,70 @@
strncpy(termname, sp, 1022);
termname[1023] = 0;
- if (tgetent(termcap, termname) > 0) {
- for (i = 0; i < num_tcs; i++) {
- p = entry;
- if (tgetstr(tc[i].name, &p) != NULL) {
- current = base_keymap; /* always start with
- * base keymap. */
- length = strlen(entry);
+ if (tgetent(termcap, termname) <= 0)
+ return;
+
+ for (i = 0; i < num_tcs; i++) {
+
+ p = entry;
+ if (tgetstr(tc[i].name, &p) == NULL)
+ continue;
- for (j = 0; j < length - 1; j++) {
- if (current->mapping[(unsigned) entry[j]] < 0) {
- /* first time for this char */
- current->mapping[(unsigned) entry[j]] = current->count; /* map new entry */
- the_key = new_key();
- /* multikey coz we are here */
- the_key->type = KEYMAP_MULTI;
+ current = base_keymap; /* always start with base keymap. */
+ length = strlen(entry);
- /* need for next key */
- the_key->value.next
- = new_keymap();
-
- /* put into key array */
- if ((current->key = realloc(current->key, (current->count + 1) * sizeof(key_entry_t *))) == NULL) {
- fprintf(stderr,
- "Could not malloc for key entry\n");
- exit(1);
- }
-
- current->key[current->count++]
- = the_key;
+ for (j = 0; j < length - 1; j++) {
+ if (current->mapping[(unsigned) entry[j]] < 0) {
+ /* first time for this char */
+ current->mapping[(unsigned) entry[j]] = current->count; /* map new entry */
+ the_key = new_key();
+ /* multikey coz we are here */
+ the_key->type = KEYMAP_MULTI;
- }
- /* next key uses this map... */
- current = current->key[current->mapping[(unsigned) entry[j]]]->value.next;
+ /* need for next key */
+ the_key->value.next = new_keymap();
+
+ /* put into key array */
+ if ((current->key = realloc(current->key, (current->count + 1) * sizeof(key_entry_t *))) == NULL) {
+ fprintf(stderr,
+ "Could not malloc for key entry\n");
+ exit(1);
}
+
+ current->key[current->count++] = the_key;
+
+ }
+ /* next key uses this map... */
+ current = current->key[current->mapping[(unsigned) entry[j]]]->value.next;
+ }
- /* this is the last key in the sequence (it
- * may have been the only one but that does
- * not matter) this means it is a leaf key and
- * should have a symbol associated with it */
- if (current->count > 0) {
- /* if there were other keys then
- we need to extend the mapping
- array */
- if ((current->key =
- realloc(current->key,
- (current->count + 1) *
- sizeof(key_entry_t *)))
- == NULL) {
- fprintf(stderr,
- "Could not malloc for key entry\n");
- exit(1);
- }
- }
- current->mapping[(unsigned) entry[length - 1]]
- = current->count;
- the_key = new_key();
- the_key->type = KEYMAP_LEAF; /* leaf key */
+ /*
+ * This is the last key in the sequence (it may have been
+ * the only one but that does not matter) this means it is
+ * a leaf key and should have a symbol associated with it.
+ */
+ if (current->count > 0) {
+ /*
+ * If there were other keys then we need to
+ * extend the mapping array.
+ */
+ if ((current->key =
+ realloc(current->key,
+ (current->count + 1) *
+ sizeof(key_entry_t *))) == NULL) {
- /* the associated symbol */
- the_key->value.symbol = tc[i].symbol;
- current->key[current->count++] = the_key;
+ fprintf(stderr,
+ "Could not malloc for key entry\n");
+ exit(1);
}
}
+ current->mapping[(unsigned) entry[length - 1]] = current->count;
+ the_key = new_key();
+ the_key->type = KEYMAP_LEAF; /* leaf key */
+
+ /* the associated symbol */
+ the_key->value.symbol = tc[i].symbol;
+ current->key[current->count++] = the_key;
}
}
@@ -277,19 +273,20 @@
perror("Inkey: Cannot allocate new keymap");
exit(2);
}
- /* initialise the new map */
+
+ /* Initialise the new map */
new_map->count = 0;
for (i = 0; i < MAX_CHAR; i++) {
new_map->mapping[i] = -1; /* no mapping for char */
}
- /* one does assume there will be at least one key mapped.... */
+ /* one does assume there will be at least one key mapped.... */
if ((new_map->key = malloc(sizeof(key_entry_t *))) == NULL) {
perror("Could not malloc first key ent");
exit(1);
}
- return new_map;
+ return (new_map);
}
/*
@@ -309,7 +306,7 @@
new_one->type = 0;
new_one->value.next = NULL;
- return new_one;
+ return (new_one);
}
/*
@@ -349,60 +346,58 @@
end = working;
state = INKEY_ASSEMBLING; /* go to the assembling
* state now */
- } else
- if (state == INKEY_BACKOUT) {
- k = inbuf[working];
- INC_POINTER(working);
- if (working == end) { /* see if we have run
- * out of keys in the
- * backlog */
+ } else if (state == INKEY_BACKOUT) {
+ k = inbuf[working];
+ INC_POINTER(working);
+ if (working == end) { /* see if we have run
+ * out of keys in the
+ * backlog */
- /* if we have then switch to
- assembling */
- state = INKEY_ASSEMBLING;
- }
- } else if (state == INKEY_ASSEMBLING) {
- /* assembling a key sequence */
- if (delay)
- {
- if (__timeout(to ? DEFAULT_DELAY : delay) == ERR)
+ /* if we have then switch to
+ assembling */
+ state = INKEY_ASSEMBLING;
+ }
+ } else if (state == INKEY_ASSEMBLING) {
+ /* assembling a key sequence */
+ if (delay) {
+ if (__timeout(to ? DEFAULT_DELAY : delay) == ERR)
return ERR;
- } else {
- if (to && (__timeout(DEFAULT_DELAY) == ERR))
- return ERR;
Home |
Main Index |
Thread Index |
Old Index