Usermode - Moved UTF-8 handling into a library
authorJohn Hodge (sonata) <[email protected]>
Sun, 20 Jan 2013 06:27:39 +0000 (14:27 +0800)
committerJohn Hodge (sonata) <[email protected]>
Sun, 20 Jan 2013 06:28:27 +0000 (14:28 +0800)
Usermode/Applications/axwin3_src/WM/Makefile
Usermode/Applications/axwin3_src/WM/include/utf8.h [deleted file]
Usermode/Applications/axwin3_src/WM/main.c
Usermode/Applications/axwin3_src/WM/renderers/widget/textinput.c
Usermode/Applications/axwin3_src/WM/utf-8.c [deleted file]
Usermode/Applications/axwin3_src/WM/wm_render_text.c
Usermode/Libraries/libunicode.so_src/Makefile [new file with mode: 0644]
Usermode/Libraries/libunicode.so_src/include_exp/unicode.h [new file with mode: 0644]
Usermode/Libraries/libunicode.so_src/main.c [new file with mode: 0644]
Usermode/Libraries/libunicode.so_src/utf-8.c [new file with mode: 0644]

index 1d67450..1112ffe 100644 (file)
@@ -7,7 +7,7 @@ CFLAGS += -std=gnu99
 
 DIR := Apps/AxWin/3.0
 BIN := AxWinWM
-OBJ := main.o input.o video.o ipc.o image.o utf-8.o
+OBJ := main.o input.o video.o ipc.o image.o
 OBJ += wm.o wm_input.o wm_render.o wm_render_text.o wm_hotkeys.o
 OBJ += decorator.o
 OBJ += renderers/framebuffer.o
@@ -23,7 +23,7 @@ OBJ += renderers/widget/textinput.o
 OBJ += renderers/widget/spacer.o
 OBJ += renderers/widget/subwin.o
 
-LDFLAGS += -limage_sif -luri -lnet
+LDFLAGS += -limage_sif -luri -lnet -lunicode
 
 -include ../../Makefile.tpl
 
diff --git a/Usermode/Applications/axwin3_src/WM/include/utf8.h b/Usermode/Applications/axwin3_src/WM/include/utf8.h
deleted file mode 100644 (file)
index 3ecaeb0..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-/*
- * Acess2 GUI (AxWin) Version 3
- * - By John Hodge (thePowersGang)
- *
- * utf8.h
- * - UTF-8 Parsing header
- */
-#ifndef _UTF8_H_
-#define _UTF8_H_
-
-#include <stdint.h>
-
-extern int     ReadUTF8(const char *Input, uint32_t *Val);
-extern int     ReadUTF8Rev(const char *Base, int Offset, uint32_t *Val);
-extern int     WriteUTF8(char *buf, uint32_t Val);
-
-#endif
-
index c14cbb5..9db1c15 100644 (file)
@@ -66,10 +66,12 @@ int main(int argc, char *argv[])
        Renderer_RichText_Init();
        WM_Initialise();
 
-       // TODO: Config
+       // TODO: Move these to config
        uint32_t        keys[4];
        keys[0] = KEYSYM_LEFTGUI;       keys[1] = KEYSYM_r;
        WM_Hotkey_Register(2, keys, "Interface>Run");
+       keys[0] = KEYSYM_LEFTGUI;       keys[1] = KEYSYM_t;
+       WM_Hotkey_Register(2, keys, "Interface>Terminal");
        
        // Spawn interface root
        {
index 6d34a8e..fc7e107 100644 (file)
@@ -10,7 +10,7 @@
 #include <common.h>
 #include "./common.h"
 #include "./colours.h"
-#include <utf8.h>
+#include <unicode.h>
 #include <string.h>
 
 // TODO: Include a proper keysym header
diff --git a/Usermode/Applications/axwin3_src/WM/utf-8.c b/Usermode/Applications/axwin3_src/WM/utf-8.c
deleted file mode 100644 (file)
index 93e0318..0000000
+++ /dev/null
@@ -1,153 +0,0 @@
-/*
- * Acess2 GUI (AxWin) Version 3
- * - By John Hodge (thePowersGang)
- *
- * utf-8.c
- * - UTF-8 Parsing code
- */
-#include <stdint.h>
-#include <utf8.h>
-
-/**
- * \brief Read a UTF-8 character from a string
- * \param Input        Source UTF-8 encoded string
- * \param Val  Destination for read codepoint
- * \return Number of bytes read/used
- */
-int ReadUTF8(const char *Input, uint32_t *Val)
-{
-       const uint8_t   *str = (const uint8_t *)Input;
-       *Val = 0xFFFD;  // Assume invalid character
-       
-       // ASCII
-       if( !(*str & 0x80) ) {
-               *Val = *str;
-               return 1;
-       }
-       
-       // Middle of a sequence
-       if( (*str & 0xC0) == 0x80 ) {
-               return 1;
-       }
-       
-       // Two Byte
-       if( (*str & 0xE0) == 0xC0 ) {
-               *Val = (*str & 0x1F) << 6;      // Upper 6 Bits
-               str ++;
-               if( (*str & 0xC0) != 0x80)      return -1;      // Validity check
-               *Val |= (*str & 0x3F);  // Lower 6 Bits
-               return 2;
-       }
-       
-       // Three Byte
-       if( (*str & 0xF0) == 0xE0 ) {
-               *Val = (*str & 0x0F) << 12;     // Upper 4 Bits
-               str ++;
-               if( (*str & 0xC0) != 0x80)      return -1;      // Validity check
-               *Val |= (*str & 0x3F) << 6;     // Middle 6 Bits
-               str ++;
-               if( (*str & 0xC0) != 0x80)      return -1;      // Validity check
-               *Val |= (*str & 0x3F);  // Lower 6 Bits
-               return 3;
-       }
-       
-       // Four Byte
-       if( (*str & 0xF8) == 0xF0 ) {
-               *Val = (*str & 0x07) << 18;     // Upper 3 Bits
-               str ++;
-               if( (*str & 0xC0) != 0x80)      return -1;      // Validity check
-               *Val |= (*str & 0x3F) << 12;    // Middle-upper 6 Bits
-               str ++;
-               if( (*str & 0xC0) != 0x80)      return -1;      // Validity check
-               *Val |= (*str & 0x3F) << 6;     // Middle-lower 6 Bits
-               str ++;
-               if( (*str & 0xC0) != 0x80)      return -1;      // Validity check
-               *Val |= (*str & 0x3F);  // Lower 6 Bits
-               return 4;
-       }
-       
-       // UTF-8 Doesn't support more than four bytes
-       return 4;
-}
-
-/**
- * \brief Get the UTF-8 character before the 
- * \
- */
-int ReadUTF8Rev(const char *Base, int Offset, uint32_t *Val)
-{
-        int    len = 0;
-       
-       // Scan backwards for the beginning of the character
-       while( Offset > 0 && (Base[Offset--] & 0xC0) == 0x80 )
-               len ++;
-       // Invalid string (no beginning)
-       if(Offset == 0 && (Base[Offset] & 0xC0) == 0x80 )
-               return len;
-       
-       len ++; // First character
-       if( ReadUTF8(Base+Offset, Val) != len ) {
-               *Val = 0xFFFD;
-       }
-       return len;
-}
-
-/**
- * \brief Write a UTF-8 character sequence to a string
- * \param buf  Destination buffer (must have at least 4 bytes available)
- * \param Val  Unicode codepoint to write
- * \return Number of bytes written
- * \note Does not NULL terminate the string in \a buf
- */
-int WriteUTF8(char *buf, uint32_t Val)
-{
-       uint8_t *str = (void*)buf;
-       
-       // ASCII
-       if( Val < 128 ) {
-               if(str) {
-                       *str = Val;
-               }
-               return 1;
-       }
-       
-       // Two Byte
-       if( Val < 0x8000 ) {
-               if(str) {
-                       *str = 0xC0 | (Val >> 6);
-                       str ++;
-                       *str = 0x80 | (Val & 0x3F);
-               }
-               return 2;
-       }
-       
-       // Three Byte
-       if( Val < 0x10000 ) {
-               if(str) {
-                       *str = 0xE0 | (Val >> 12);
-                       str ++;
-                       *str = 0x80 | ((Val >> 6) & 0x3F);
-                       str ++;
-                       *str = 0x80 | (Val & 0x3F);
-               }
-               return 3;
-       }
-       
-       // Four Byte
-       if( Val < 0x110000 ) {
-               if(str) {
-                       *str = 0xF0 | (Val >> 18);
-                       str ++;
-                       *str = 0x80 | ((Val >> 12) & 0x3F);
-                       str ++;
-                       *str = 0x80 | ((Val >> 6) & 0x3F);
-                       str ++;
-                       *str = 0x80 | (Val & 0x3F);
-               }
-               return 4;
-       }
-       
-       // UTF-8 Doesn't support more than four bytes
-       return 0;
-}
-
index 6ad72be..8258531 100644 (file)
@@ -8,7 +8,7 @@
 #include <common.h>
 #include <wm_internals.h>
 #include <stdlib.h>
-#include <utf8.h>
+#include <unicode.h>
 #include <limits.h>    // INT_MAX
 
 // === TYPES ===
diff --git a/Usermode/Libraries/libunicode.so_src/Makefile b/Usermode/Libraries/libunicode.so_src/Makefile
new file mode 100644 (file)
index 0000000..d515f3d
--- /dev/null
@@ -0,0 +1,14 @@
+# Acess 2 "libunicode"
+#
+
+include ../Makefile.cfg
+
+CPPFLAGS +=
+CFLAGS   += -Wall
+LDFLAGS  += -lc -soname libunicode.so
+
+OBJ = main.o utf-8.o
+BIN = libunicode.so
+
+include ../Makefile.tpl
+
diff --git a/Usermode/Libraries/libunicode.so_src/include_exp/unicode.h b/Usermode/Libraries/libunicode.so_src/include_exp/unicode.h
new file mode 100644 (file)
index 0000000..495c8cf
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+ * Acess2 "libunicode" UTF Parser
+ * - By John Hodge (thePowersGang)
+ *
+ * unicode.h
+ * - Main header
+ */
+#ifndef _LIBUNICODE__UNICODE_H_
+#define _LIBUNICODE__UNICODE_H_
+
+#include <stdint.h>
+
+/**
+ * \breif Read a single codepoint from  a UTF-8 stream
+ * \return Number of bytes read
+ */
+extern int     ReadUTF8(const char *Input, uint32_t *Val);
+/**
+ * \brief Read backwards in the stream
+ */
+extern int     ReadUTF8Rev(const char *Base, int Offset, uint32_t *Val);
+/**
+ * \breif Write a single codepoint to a UTF-8 stream
+ */
+extern int     WriteUTF8(char *buf, uint32_t Val);
+
+#endif
+
diff --git a/Usermode/Libraries/libunicode.so_src/main.c b/Usermode/Libraries/libunicode.so_src/main.c
new file mode 100644 (file)
index 0000000..e39dc9b
--- /dev/null
@@ -0,0 +1,12 @@
+/*
+ * Acess2 "libunicode"
+ * - By John Hoge
+ *
+ * main.c
+ * - Stub main
+ */
+
+int SoMain(void)
+{
+       return 0;
+}
diff --git a/Usermode/Libraries/libunicode.so_src/utf-8.c b/Usermode/Libraries/libunicode.so_src/utf-8.c
new file mode 100644 (file)
index 0000000..3aa9d1a
--- /dev/null
@@ -0,0 +1,153 @@
+/*
+ * Acess2 "libunicode" UTF Parser
+ * - By John Hodge (thePowersGang)
+ *
+ * utf-8.c
+ * - UTF-8 Parsing code
+ */
+#include <stdint.h>
+#include <unicode.h>
+
+/**
+ * \brief Read a UTF-8 character from a string
+ * \param Input        Source UTF-8 encoded string
+ * \param Val  Destination for read codepoint
+ * \return Number of bytes read/used
+ */
+int ReadUTF8(const char *Input, uint32_t *Val)
+{
+       const uint8_t   *str = (const uint8_t *)Input;
+       *Val = 0xFFFD;  // Assume invalid character
+       
+       // ASCII
+       if( !(*str & 0x80) ) {
+               *Val = *str;
+               return 1;
+       }
+       
+       // Middle of a sequence
+       if( (*str & 0xC0) == 0x80 ) {
+               return 1;
+       }
+       
+       // Two Byte
+       if( (*str & 0xE0) == 0xC0 ) {
+               *Val = (*str & 0x1F) << 6;      // Upper 6 Bits
+               str ++;
+               if( (*str & 0xC0) != 0x80)      return -1;      // Validity check
+               *Val |= (*str & 0x3F);  // Lower 6 Bits
+               return 2;
+       }
+       
+       // Three Byte
+       if( (*str & 0xF0) == 0xE0 ) {
+               *Val = (*str & 0x0F) << 12;     // Upper 4 Bits
+               str ++;
+               if( (*str & 0xC0) != 0x80)      return -1;      // Validity check
+               *Val |= (*str & 0x3F) << 6;     // Middle 6 Bits
+               str ++;
+               if( (*str & 0xC0) != 0x80)      return -1;      // Validity check
+               *Val |= (*str & 0x3F);  // Lower 6 Bits
+               return 3;
+       }
+       
+       // Four Byte
+       if( (*str & 0xF8) == 0xF0 ) {
+               *Val = (*str & 0x07) << 18;     // Upper 3 Bits
+               str ++;
+               if( (*str & 0xC0) != 0x80)      return -1;      // Validity check
+               *Val |= (*str & 0x3F) << 12;    // Middle-upper 6 Bits
+               str ++;
+               if( (*str & 0xC0) != 0x80)      return -1;      // Validity check
+               *Val |= (*str & 0x3F) << 6;     // Middle-lower 6 Bits
+               str ++;
+               if( (*str & 0xC0) != 0x80)      return -1;      // Validity check
+               *Val |= (*str & 0x3F);  // Lower 6 Bits
+               return 4;
+       }
+       
+       // UTF-8 Doesn't support more than four bytes
+       return 4;
+}
+
+/**
+ * \brief Get the UTF-8 character before the 
+ * \
+ */
+int ReadUTF8Rev(const char *Base, int Offset, uint32_t *Val)
+{
+        int    len = 0;
+       
+       // Scan backwards for the beginning of the character
+       while( Offset > 0 && (Base[Offset--] & 0xC0) == 0x80 )
+               len ++;
+       // Invalid string (no beginning)
+       if(Offset == 0 && (Base[Offset] & 0xC0) == 0x80 )
+               return len;
+       
+       len ++; // First character
+       if( ReadUTF8(Base+Offset, Val) != len ) {
+               *Val = 0xFFFD;
+       }
+       return len;
+}
+
+/**
+ * \brief Write a UTF-8 character sequence to a string
+ * \param buf  Destination buffer (must have at least 4 bytes available)
+ * \param Val  Unicode codepoint to write
+ * \return Number of bytes written
+ * \note Does not NULL terminate the string in \a buf
+ */
+int WriteUTF8(char *buf, uint32_t Val)
+{
+       uint8_t *str = (void*)buf;
+       
+       // ASCII
+       if( Val < 128 ) {
+               if(str) {
+                       *str = Val;
+               }
+               return 1;
+       }
+       
+       // Two Byte
+       if( Val < 0x8000 ) {
+               if(str) {
+                       *str = 0xC0 | (Val >> 6);
+                       str ++;
+                       *str = 0x80 | (Val & 0x3F);
+               }
+               return 2;
+       }
+       
+       // Three Byte
+       if( Val < 0x10000 ) {
+               if(str) {
+                       *str = 0xE0 | (Val >> 12);
+                       str ++;
+                       *str = 0x80 | ((Val >> 6) & 0x3F);
+                       str ++;
+                       *str = 0x80 | (Val & 0x3F);
+               }
+               return 3;
+       }
+       
+       // Four Byte
+       if( Val < 0x110000 ) {
+               if(str) {
+                       *str = 0xF0 | (Val >> 18);
+                       str ++;
+                       *str = 0x80 | ((Val >> 12) & 0x3F);
+                       str ++;
+                       *str = 0x80 | ((Val >> 6) & 0x3F);
+                       str ++;
+                       *str = 0x80 | (Val & 0x3F);
+               }
+               return 4;
+       }
+       
+       // UTF-8 Doesn't support more than four bytes
+       return 0;
+}
+

UCC git Repository :: git.ucc.asn.au