1 /* ______ ___ ___ 2 * /\ _ \ /\_ \ /\_ \ 3 * \ \ \L\ \\//\ \ \//\ \ __ __ _ __ ___ 4 * \ \ __ \ \ \ \ \ \ \ /'__`\ /'_ `\/\`'__\/ __`\ 5 * \ \ \/\ \ \_\ \_ \_\ \_/\ __//\ \L\ \ \ \//\ \L\ \ 6 * \ \_\ \_\/\____\/\____\ \____\ \____ \ \_\\ \____/ 7 * \/_/\/_/\/____/\/____/\/____/\/___L\ \/_/ \/___/ 8 * /\____/ 9 * \_/__/ 10 * 11 * Unicode support routines. 12 * 13 * By Shawn Hargreaves. 14 * 15 * See readme.txt for copyright information. 16 */ 17 18 19 #ifndef ALLEGRO_UNICODE__H 20 #define ALLEGRO_UNICODE__H 21 22 #include "base.h" 23 24 #ifdef __cplusplus 25 extern "C" { 26 #endif 27 28 #define U_ASCII AL_ID('A','S','C','8') 29 #define U_ASCII_CP AL_ID('A','S','C','P') 30 #define U_UNICODE AL_ID('U','N','I','C') 31 #define U_UTF8 AL_ID('U','T','F','8') 32 #define U_CURRENT AL_ID('c','u','r','.') 33 34 AL_FUNC(void, set_uformat, (int type)); 35 AL_FUNC(int, get_uformat, (void)); 36 AL_FUNC(void, register_uformat, (int type, AL_METHOD(int, u_getc, (AL_CONST char *s)), AL_METHOD(int, u_getx, (char **s)), AL_METHOD(int, u_setc, (char *s, int c)), AL_METHOD(int, u_width, (AL_CONST char *s)), AL_METHOD(int, u_cwidth, (int c)), AL_METHOD(int, u_isok, (int c)), int u_width_max)); 37 AL_FUNC(void, set_ucodepage, (AL_CONST unsigned short *table, AL_CONST unsigned short *extras)); 38 39 AL_FUNC(int, need_uconvert, (AL_CONST char *s, int type, int newtype)); 40 AL_FUNC(int, uconvert_size, (AL_CONST char *s, int type, int newtype)); 41 AL_FUNC(void, do_uconvert, (AL_CONST char *s, int type, char *buf, int newtype, int size)); 42 AL_FUNC(char *, uconvert, (AL_CONST char *s, int type, char *buf, int newtype, int size)); 43 AL_FUNC(int, uwidth_max, (int type)); 44 45 #define uconvert_ascii(s, buf) uconvert(s, U_ASCII, buf, U_CURRENT, sizeof(buf)) 46 #define uconvert_toascii(s, buf) uconvert(s, U_CURRENT, buf, U_ASCII, sizeof(buf)) 47 48 #define EMPTY_STRING "\0\0\0" 49 50 AL_ARRAY(char, empty_string); 51 52 AL_FUNCPTR(int, ugetc, (AL_CONST char *s)); 53 AL_FUNCPTR(int, ugetx, (char **s)); 54 AL_FUNCPTR(int, ugetxc, (AL_CONST char **s)); 55 AL_FUNCPTR(int, usetc, (char *s, int c)); 56 AL_FUNCPTR(int, uwidth, (AL_CONST char *s)); 57 AL_FUNCPTR(int, ucwidth, (int c)); 58 AL_FUNCPTR(int, uisok, (int c)); 59 AL_FUNC(int, uoffset, (AL_CONST char *s, int idx)); 60 AL_FUNC(int, ugetat, (AL_CONST char *s, int idx)); 61 AL_FUNC(int, usetat, (char *s, int idx, int c)); 62 AL_FUNC(int, uinsert, (char *s, int idx, int c)); 63 AL_FUNC(int, uremove, (char *s, int idx)); 64 AL_FUNC(int, utolower, (int c)); 65 AL_FUNC(int, utoupper, (int c)); 66 AL_FUNC(int, uisspace, (int c)); 67 AL_FUNC(int, uisdigit, (int c)); 68 AL_FUNC(int, ustrsize, (AL_CONST char *s)); 69 AL_FUNC(int, ustrsizez, (AL_CONST char *s)); 70 AL_FUNC(char *, _ustrdup, (AL_CONST char *src, AL_METHOD(void *, malloc_func, (size_t)))); 71 AL_FUNC(char *, ustrzcpy, (char *dest, int size, AL_CONST char *src)); 72 AL_FUNC(char *, ustrzcat, (char *dest, int size, AL_CONST char *src)); 73 AL_FUNC(int, ustrlen, (AL_CONST char *s)); 74 AL_FUNC(int, ustrcmp, (AL_CONST char *s1, AL_CONST char *s2)); 75 AL_FUNC(char *, ustrzncpy, (char *dest, int size, AL_CONST char *src, int n)); 76 AL_FUNC(char *, ustrzncat, (char *dest, int size, AL_CONST char *src, int n)); 77 AL_FUNC(int, ustrncmp, (AL_CONST char *s1, AL_CONST char *s2, int n)); 78 AL_FUNC(int, ustricmp, (AL_CONST char *s1, AL_CONST char *s2)); 79 AL_FUNC(int, ustrnicmp, (AL_CONST char *s1, AL_CONST char *s2, int n)); 80 AL_FUNC(char *, ustrlwr, (char *s)); 81 AL_FUNC(char *, ustrupr, (char *s)); 82 AL_FUNC(char *, ustrchr, (AL_CONST char *s, int c)); 83 AL_FUNC(char *, ustrrchr, (AL_CONST char *s, int c)); 84 AL_FUNC(char *, ustrstr, (AL_CONST char *s1, AL_CONST char *s2)); 85 AL_FUNC(char *, ustrpbrk, (AL_CONST char *s, AL_CONST char *set)); 86 AL_FUNC(char *, ustrtok, (char *s, AL_CONST char *set)); 87 AL_FUNC(char *, ustrtok_r, (char *s, AL_CONST char *set, char **last)); 88 AL_FUNC(double, uatof, (AL_CONST char *s)); 89 AL_FUNC(long, ustrtol, (AL_CONST char *s, char **endp, int base)); 90 AL_FUNC(double, ustrtod, (AL_CONST char *s, char **endp)); 91 AL_FUNC(AL_CONST char *, ustrerror, (int err)); 92 AL_PRINTFUNC(int, uszprintf, (char *buf, int size, AL_CONST char *format, ...), 3, 4); 93 AL_FUNC(int, uvszprintf, (char *buf, int size, AL_CONST char *format, va_list args)); 94 AL_PRINTFUNC(int, usprintf, (char *buf, AL_CONST char *format, ...), 2, 3); 95 96 #ifndef ustrdup 97 #ifdef FORTIFY 98 #define ustrdup(src) _ustrdup(src, Fortify_malloc) 99 #else 100 #define ustrdup(src) _ustrdup(src, malloc) 101 #endif 102 #endif 103 104 #define ustrcpy(dest, src) ustrzcpy(dest, INT_MAX, src) 105 #define ustrcat(dest, src) ustrzcat(dest, INT_MAX, src) 106 #define ustrncpy(dest, src, n) ustrzncpy(dest, INT_MAX, src, n) 107 #define ustrncat(dest, src, n) ustrzncat(dest, INT_MAX, src, n) 108 #define uvsprintf(buf, format, args) uvszprintf(buf, INT_MAX, format, args) 109 110 #ifdef __cplusplus 111 } 112 #endif 113 114 #endif /* ifndef ALLEGRO_UNICODE__H */ 115 116 117