summaryrefslogtreecommitdiff
path: root/usr.bin/mg/kbd.c
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>2000-09-01 14:59:10 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>2000-09-01 14:59:10 +0000
commita045bd2fd0eec255d59e94ac735e3096da56bfc7 (patch)
tree5d2398a23f5bfa85d6ea967969f36b1e419a9568 /usr.bin/mg/kbd.c
parent58c021b47d6326c960010c7261da73856d613f4b (diff)
More -Wall anmd KNF, from op2@tomahawk.SQUiSH.org
Diffstat (limited to 'usr.bin/mg/kbd.c')
-rw-r--r--usr.bin/mg/kbd.c198
1 files changed, 103 insertions, 95 deletions
diff --git a/usr.bin/mg/kbd.c b/usr.bin/mg/kbd.c
index 72be336b622..c61e575742f 100644
--- a/usr.bin/mg/kbd.c
+++ b/usr.bin/mg/kbd.c
@@ -1,22 +1,32 @@
/*
- * Terminal independent keyboard handling.
+ * Terminal independent keyboard handling.
*/
-#include "def.h"
-#include "kbd.h"
#define EXTERN
-#include "key.h"
+
+#include "def.h"
+#include "kbd.h"
+#include "key.h"
#ifndef NO_MACRO
#include "macro.h"
-#endif
+#endif /* !NO_MACRO */
-#ifdef DO_METAKEY
+#ifdef DO_METAKEY
#ifndef METABIT
#define METABIT 0x80
-#endif
+#endif /* !METABIT */
+
+#ifndef NO_DPROMPT
+#define PROMPTL 80
+char prompt[PROMPTL], *promptp;
+#endif /* !NO_DPROMPT */
-int use_metakey = TRUE;
+static int use_metakey = TRUE;
+static int pushed = FALSE;
+static int pushedc;
+
+MAP_ELEMENT *ele;
/*
* Toggle the value of use_metakey
@@ -25,7 +35,6 @@ int
do_meta(f, n)
int f, n;
{
-
if (f & FFARG)
use_metakey = n > 0;
else
@@ -33,10 +42,10 @@ do_meta(f, n)
ewprintf("Meta keys %sabled", use_metakey ? "en" : "dis");
return TRUE;
}
-#endif
+#endif /* DO_METAKEY */
-#ifdef BSMAP
-static int bs_map = BSMAP;
+#ifdef BSMAP
+static int bs_map = BSMAP;
/*
* Toggle backspace mapping
*/
@@ -44,7 +53,6 @@ int
bsmap(f, n)
int f, n;
{
-
if (f & FFARG)
bs_map = n > 0;
else
@@ -52,73 +60,66 @@ bsmap(f, n)
ewprintf("Backspace mapping %sabled", bs_map ? "en" : "dis");
return TRUE;
}
-#endif
-
-#ifndef NO_DPROMPT
-#define PROMPTL 80
-char prompt[PROMPTL], *promptp;
-#endif
-
-static int pushed = FALSE;
-static int pushedc;
+#endif /* BSMAP */
VOID
ungetkey(c)
int c;
{
-
-#ifdef DO_METAKEY
+#ifdef DO_METAKEY
if (use_metakey && pushed && c == CCHR('['))
pushedc |= METABIT;
else
-#endif
+#endif /* DO_METAKEY */
pushedc = c;
pushed = TRUE;
}
int
getkey(flag)
- int flag;
+ int flag;
{
- int c;
+ int c;
#ifndef NO_DPROMPT
if (flag && !pushed) {
if (prompt[0] != '\0' && ttwait()) {
- ewprintf("%s", prompt); /* avoid problems with % */
- update(); /* put the cursor back */
+ /* avoid problems with % */
+ ewprintf("%s", prompt);
+ /* put the cursor back */
+ update();
epresf = KPROMPT;
}
if (promptp > prompt)
*(promptp - 1) = ' ';
}
-#endif
+#endif /* !NO_DPROMPT */
if (pushed) {
c = pushedc;
pushed = FALSE;
} else
c = getkbd();
-#ifdef BSMAP
+#ifdef BSMAP
if (bs_map)
if (c == CCHR('H'))
c = CCHR('?');
else if (c == CCHR('?'))
c = CCHR('H');
-#endif
-#ifdef DO_METAKEY
+#endif /* BSMAP */
+#ifdef DO_METAKEY
if (use_metakey && (c & METABIT)) {
pushedc = c & ~METABIT;
pushed = TRUE;
c = CCHR('[');
}
-#endif
+#endif /* DO_METAKEY */
#ifndef NO_DPROMPT
if (flag && promptp < &prompt[PROMPTL - 5]) {
promptp = keyname(promptp, c);
*promptp++ = '-';
*promptp = '\0';
}
-#endif
+#endif /* !NO_DPROMPT */
return c;
}
@@ -127,20 +128,19 @@ getkey(flag)
* to the function associated with that character. Sets ele to the
* keymap element the keyboard was found in as a side effect.
*/
-
-MAP_ELEMENT *ele;
-
PF
doscan(map, c)
KEYMAP *map;
int c;
{
- MAP_ELEMENT *elec = &map->map_element[0];
- MAP_ELEMENT *last = &map->map_element[map->map_num];
+ MAP_ELEMENT *elec = &map->map_element[0];
+ MAP_ELEMENT *last = &map->map_element[map->map_num];
while (elec < last && c > elec->k_num)
elec++;
- ele = elec; /* used by prefix and binding code */
+
+ /* used by prefix and binding code */
+ ele = elec;
if (elec >= last || c < elec->k_base)
return map->map_default;
return elec->k_funcp[c - elec->k_base];
@@ -149,12 +149,12 @@ doscan(map, c)
int
doin()
{
- KEYMAP *curmap;
- PF funct;
+ KEYMAP *curmap;
+ PF funct;
#ifndef NO_DPROMPT
*(promptp = prompt) = '\0';
-#endif
+#endif /* !NO_DPROMPT */
curmap = curbp->b_modes[curbp->b_nmodes]->p_map;
key.k_count = 0;
while ((funct = doscan(curmap, (key.k_chars[key.k_count++] =
@@ -163,26 +163,27 @@ doin()
#ifndef NO_MACRO
if (macrodef && macrocount < MAXMACRO)
macro[macrocount++].m_funct = funct;
-#endif
- return (*funct) (0, 1);
+#endif /* !NO_MACRO */
+ return (*funct)(0, 1);
}
int
rescan(f, n)
- int f, n;
+ int f, n;
{
- int c;
- KEYMAP *curmap;
- int i;
- PF fp;
- int mode = curbp->b_nmodes;
+ int c;
+ KEYMAP *curmap;
+ int i;
+ PF fp = NULL;
+ int mode = curbp->b_nmodes;
for (;;) {
if (ISUPPER(key.k_chars[key.k_count - 1])) {
c = TOLOWER(key.k_chars[key.k_count - 1]);
curmap = curbp->b_modes[mode]->p_map;
for (i = 0; i < key.k_count - 1; i++) {
- if ((fp = doscan(curmap, (key.k_chars[i]))) != prefix)
+ if ((fp = doscan(curmap, (key.k_chars[i])))
+ != prefix)
break;
curmap = ele->k_prefmap;
}
@@ -190,14 +191,15 @@ rescan(f, n)
if ((fp = doscan(curmap, c)) == prefix)
while ((fp = doscan(curmap,
key.k_chars[key.k_count++] =
- getkey(TRUE))) == prefix)
+ getkey(TRUE))) == prefix)
curmap = ele->k_prefmap;
if (fp != rescan) {
#ifndef NO_MACRO
if (macrodef && macrocount <= MAXMACRO)
- macro[macrocount - 1].m_funct = fp;
-#endif
- return (*fp) (f, n);
+ macro[macrocount - 1].m_funct
+ = fp;
+#endif /* !NO_MACRO */
+ return (*fp)(f, n);
}
}
}
@@ -211,8 +213,8 @@ rescan(f, n)
curmap = ele->k_prefmap;
}
if (fp == prefix) {
- while ((fp = doscan(curmap, key.k_chars[i++] = getkey(TRUE)))
- == prefix)
+ while ((fp = doscan(curmap, key.k_chars[i++] =
+ getkey(TRUE))) == prefix)
curmap = ele->k_prefmap;
key.k_count = i;
}
@@ -220,19 +222,20 @@ rescan(f, n)
#ifndef NO_MACRO
if (macrodef && macrocount <= MAXMACRO)
macro[macrocount - 1].m_funct = fp;
-#endif
- return (*fp) (f, n);
+#endif /* !NO_MACRO */
+ return (*fp)(f, n);
}
}
}
int
universal_argument(f, n)
- int f, n;
+ int f, n;
{
- int c, nn = 4;
- KEYMAP *curmap;
- PF funct;
+ KEYMAP *curmap;
+ PF funct;
+ int c;
+ int nn = 4;
if (f & FFUNIV)
nn *= n;
@@ -256,8 +259,8 @@ universal_argument(f, n)
macro[macrocount++].m_count = nn;
macro[macrocount++].m_funct = funct;
}
-#endif
- return (*funct) (FFUNIV, nn);
+#endif /* !NO_MACRO */
+ return (*funct)(FFUNIV, nn);
}
nn <<= 2;
}
@@ -266,11 +269,11 @@ universal_argument(f, n)
/* ARGSUSED */
int
digit_argument(f, n)
- int f, n;
+ int f, n;
{
- int nn, c;
- KEYMAP *curmap;
- PF funct;
+ KEYMAP *curmap;
+ PF funct;
+ int nn, c;
nn = key.k_chars[key.k_count - 1] - '0';
for (;;) {
@@ -296,17 +299,18 @@ digit_argument(f, n)
macro[macrocount++].m_count = nn;
macro[macrocount++].m_funct = funct;
}
-#endif
- return (*funct) (FFOTHARG, nn);
+#endif /* !NO_MACRO */
+ return (*funct)(FFOTHARG, nn);
}
int
negative_argument(f, n)
- int f, n;
+ int f, n;
{
- int nn = 0, c;
- KEYMAP *curmap;
- PF funct;
+ KEYMAP *curmap;
+ PF funct;
+ int c;
+ int nn = 0;
for (;;) {
c = getkey(TRUE);
@@ -335,8 +339,8 @@ negative_argument(f, n)
macro[macrocount++].m_count = nn;
macro[macrocount++].m_funct = funct;
}
-#endif
- return (*funct) (FFNEGARG, nn);
+#endif /* !NO_MACRO */
+ return (*funct)(FFNEGARG, nn);
}
/*
@@ -345,13 +349,13 @@ negative_argument(f, n)
*/
int
selfinsert(f, n)
- int f, n;
+ int f, n;
{
- int c;
- int count;
#ifndef NO_MACRO
- LINE *lp;
-#endif
+ LINE *lp;
+#endif /* !NO_MACRO */
+ int c;
+ int count;
if (n < 0)
return FALSE;
@@ -362,8 +366,9 @@ selfinsert(f, n)
if (macrodef && macrocount < MAXMACRO) {
if (f & FFARG)
macrocount -= 2;
- if (lastflag & CFINS) { /* last command was insert -- tack on
- * end */
+
+ /* last command was insert -- tack on the end */
+ if (lastflag & CFINS) {
macrocount--;
if (maclcur->l_size < maclcur->l_used + n) {
if ((lp = lallocx(maclcur->l_used + n)) == NULL)
@@ -371,10 +376,12 @@ selfinsert(f, n)
lp->l_fp = maclcur->l_fp;
lp->l_bp = maclcur->l_bp;
lp->l_fp->l_bp = lp->l_bp->l_fp = lp;
- bcopy(maclcur->l_text, lp->l_text, maclcur->l_used);
- for (count = maclcur->l_used; count < lp->l_used; count++)
+ bcopy(maclcur->l_text, lp->l_text,
+ maclcur->l_used);
+ for (count = maclcur->l_used;
+ count < lp->l_used; count++)
lp->l_text[count] = c;
- free((char *) maclcur);
+ free((char *)maclcur);
maclcur = lp;
} else {
maclcur->l_used += n;
@@ -395,14 +402,16 @@ selfinsert(f, n)
}
thisflag |= CFINS;
}
-#endif
+#endif /* !NO_MACRO */
if (c == '\n') {
do {
count = lnewline();
} while (--n && count == TRUE);
return count;
}
- if (curbp->b_flag & BFOVERWRITE) { /* Overwrite mode */
+
+ /* overwrite mode */
+ if (curbp->b_flag & BFOVERWRITE) {
lchange(WFEDIT);
while (curwp->w_doto < llength(curwp->w_dotp) && n--)
lputc(curwp->w_dotp, curwp->w_doto++, c);
@@ -413,14 +422,13 @@ selfinsert(f, n)
}
/*
- * This could be implemented as a keymap with everthing defined
- * as self-insert.
+ * This could be implemented as a keymap with everthing defined as self-insert.
*/
int
quote(f, n)
- int f, n;
+ int f, n;
{
- int c;
+ int c;
key.k_count = 1;
if ((key.k_chars[0] = getkey(TRUE)) >= '0' && key.k_chars[0] <= '7') {