Moved char related macro to ascii.h.
authorDaniel Carl <danielcarl@gmx.de>
Tue, 3 Jun 2014 13:45:36 +0000 (15:45 +0200)
committerDaniel Carl <danielcarl@gmx.de>
Tue, 3 Jun 2014 13:45:36 +0000 (15:45 +0200)
src/ascii.h
src/ex.c
src/input.c
src/main.h
src/map.c
src/mode.c
src/pass.c

index 9180a80..928e128 100644 (file)
 #define SC VB_SPACE|VB_CTRL
 #define PI VB_PUNKT|VB_IDENT
 static const unsigned char chartable[256] = {
-    C,  C,  C,  C,  C,  C,  C,  C,  C, SC, SC,  C, SC, SC,  C,  C,
-    C,  C,  C,  C,  C,  C,  C,  C,  C,  C,  C,  C,  C,  C,  C,  C,
-    S,  P,  P,  P,  P,  P,  P,  P,  P,  P,  P,  P,  P,  P,  P,  P,
-    D,  D,  D,  D,  D,  D,  D,  D,  D,  D,  P,  P,  P,  P,  P,  P,
-   PI, UI, UI, UI, UI, UI, UI, UI, UI, UI, UI, UI, UI, UI, UI, UI,
-   UI, UI, UI, UI, UI, UI, UI, UI, UI, UI, UI,  P,  P,  P,  P, PI,
-    P, LI, LI, LI, LI, LI, LI, LI, LI, LI, LI, LI, LI, LI, LI, LI,
-   LI, LI, LI, LI, LI, LI, LI, LI, LI, LI, LI,  P,  P,  P,  P,  C,
-    P,  P,  P,  P,  P,  P,  P,  P,  P,  P,  P,  P,  P,  P,  P,  P,
-    P,  P,  P,  P,  P,  P,  P,  P,  P,  P,  P,  P,  P,  P,  P,  P,
-    P,  P,  P,  P,  P,  P,  P,  P,  P,  P,  P,  P,  P,  P,  P,  P,
-    P,  P,  P,  P,  P,  P,  P,  P,  P,  P,  P,  P,  P,  P,  P,  P,
-    P,  P,  P,  P,  P,  P,  P,  P,  P,  P,  P,  P,  P,  P,  P,  P,
-    P,  P,  P,  P,  P,  P,  P,  P,  P,  P,  P,  P,  P,  P,  P,  P,
-    P,  P,  P,  P,  P,  P,  P,  P,  P,  P,  P,  P,  P,  P,  P,  P,
-    P,  P,  P,  P,  P,  P,  P,  P,  P,  P,  P,  P,  P,  P,  P,  P
+/* 0x00-0x0f */  C,  C,  C,  C,  C,  C,  C,  C,  C, SC, SC,  C, SC, SC,  C,  C,
+/* 0x10-0x1f */  C,  C,  C,  C,  C,  C,  C,  C,  C,  C,  C,  C,  C,  C,  C,  C,
+/* 0x20-0x2f */  S,  P,  P,  P,  P,  P,  P,  P,  P,  P,  P,  P,  P,  P,  P,  P,
+/* 0x30-0x3f */  D,  D,  D,  D,  D,  D,  D,  D,  D,  D,  P,  P,  P,  P,  P,  P,
+/* 0x40-0x4f */ PI, UI, UI, UI, UI, UI, UI, UI, UI, UI, UI, UI, UI, UI, UI, UI,
+/* 0x50-0x5f */ UI, UI, UI, UI, UI, UI, UI, UI, UI, UI, UI,  P,  P,  P,  P, PI,
+/* 0x60-0x6f */  P, LI, LI, LI, LI, LI, LI, LI, LI, LI, LI, LI, LI, LI, LI, LI,
+/* 0x70-0x7f */ LI, LI, LI, LI, LI, LI, LI, LI, LI, LI, LI,  P,  P,  P,  P,  C,
+/* 0x80-0x8f */  P,  P,  P,  P,  P,  P,  P,  P,  P,  P,  P,  P,  P,  P,  P,  P,
+/* 0x90-0x9f */  P,  P,  P,  P,  P,  P,  P,  P,  P,  P,  P,  P,  P,  P,  P,  P,
+/* 0xa0-0xaf */  P,  P,  P,  P,  P,  P,  P,  P,  P,  P,  P,  P,  P,  P,  P,  P,
+/* 0xb0-0xbf */  P,  P,  P,  P,  P,  P,  P,  P,  P,  P,  P,  P,  P,  P,  P,  P,
+/* 0xc0-0xcf */  P,  P,  P,  P,  P,  P,  P,  P,  P,  P,  P,  P,  P,  P,  P,  P,
+/* 0xd0-0xdf */  P,  P,  P,  P,  P,  P,  P,  P,  P,  P,  P,  P,  P,  P,  P,  P,
+/* 0xe0-0xef */  P,  P,  P,  P,  P,  P,  P,  P,  P,  P,  P,  P,  P,  P,  P,  P,
+/* 0xf0-0xff */  P,  P,  P,  P,  P,  P,  P,  P,  P,  P,  P,  P,  P,  P,  P,  P
 };
 #undef U
 #undef L
@@ -85,6 +85,10 @@ static const unsigned char chartable[256] = {
 #define CSI         0x80
 #define CSI_STR     "\x80"
 
+/* check if the char c is a char with CTRL like ^C */
+#define IS_CTRL(c)  (((unsigned char)c) <= 0x1f)
+#define CTRL(c)     ((c) ^ 0x40)
+
 #define IS_SPECIAL(c)       (c < 0)
 
 #define TERMCAP2KEY(a, b)   (-((a) + ((int)(b) << 8)))
index 0dd3fc4..a4fa0f1 100644 (file)
--- a/src/ex.c
+++ b/src/ex.c
@@ -21,8 +21,8 @@
  * This file contains function to handle input editing, parsing of called ex
  * commands from inputbox and the ex commands.
  */
-#include <sys/wait.h>
 #include "config.h"
+#include <sys/wait.h>
 #include "main.h"
 #include "ex.h"
 #include "ascii.h"
index 9ae2a52..56f135c 100644 (file)
@@ -24,6 +24,7 @@
 #include "input.h"
 #include "dom.h"
 #include "util.h"
+#include "ascii.h"
 
 typedef struct {
     char    *file;
index 553f23a..d9d061c 100644 (file)
 
 #define LENGTH(x) (sizeof x / sizeof x[0])
 
-#define CTRL(x)      ((x) ^ 0x40)
-/* check if the char x is a char with CTRL like ^C */
-#define IS_CTRL(x)   (((guchar)x) <= 0x1f)
-
 #define FLOCK(fd, cmd) { \
     struct flock lock = {.l_type=cmd,.l_start=0,.l_whence=SEEK_SET,.l_len=0}; \
     fcntl(fd, F_SETLK, lock); \
index 5f538a0..f04cceb 100644 (file)
--- a/src/map.c
+++ b/src/map.c
@@ -507,13 +507,11 @@ static char *convert_keys(char *in, int inlen, int *len)
             if (symlen == 5 && p[2] == '-') {
                 /* is it a <C-X> */
                 if (p[1] == 'C') {
-                    /* TODO add macro to check if the char is a upper or lower
-                     * with these ranges */
-                    if (p[3] >= 0x41 && p[3] <= 0x5d) {
+                    if (VB_IS_UPPER(p[3])) {
                         ch[0]  = p[3] - 0x40;
                         raw    = ch;
                         rawlen = 1;
-                    } else if (p[3] >= 0x61 && p[3] <= 0x7a) {
+                    } else if (VB_IS_LOWER(p[3])) {
                         ch[0]  = p[3] - 0x60;
                         raw    = ch;
                         rawlen = 1;
index b33d933..7d6d074 100644 (file)
@@ -21,6 +21,7 @@
 #include "main.h"
 #include "mode.h"
 #include "normal.h"
+#include "ascii.h"
 
 static GHashTable *modes = NULL;
 extern VbCore vb;
index 8e06b92..4fb62ec 100644 (file)
@@ -22,6 +22,7 @@
 #include "pass.h"
 #include "mode.h"
 #include "dom.h"
+#include "ascii.h"
 
 extern VbCore vb;