Changeset 13331 for lang/c/gtkwassr

Show
Ignore:
Timestamp:
06/06/08 21:25:20 (5 years ago)
Author:
mattn
Message:

* 絵文字対応(暫定: コード範囲適当)
* TODO機能実装しかけ

Location:
lang/c/gtkwassr/trunk
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • lang/c/gtkwassr/trunk/Makefile.w32

    r6230 r13331  
     1#CFLAGS=/MT 
    12CFLAGS=/MT 
    23 
  • lang/c/gtkwassr/trunk/gtkwassr.c

    r6326 r13331  
    1616#endif 
    1717 
     18#define IS_EMOJI(x) (0xE001 <= code && code <= 0xF0FC) 
     19 
     20/* 
     21        ((0xE001 <= code && code <= 0xE05A) || \ 
     22         (0xE101 <= code && code <= 0xE15A) || \ 
     23         (0xE201 <= code && code <= 0xE253) || \ 
     24         (0xE255 <= code && code <= 0xE257) || \ 
     25         (0xE301 <= code && code <= 0xE34D) || \ 
     26         (0xE401 <= code && code <= 0xE44C) || \ 
     27         (0xE501 <= code && code <= 0xE537)) // for softbank 
     28*/ 
     29 
    1830#ifdef _WIN32 
    1931# define DATA_DIR "data" 
     
    2941#define APP_URL                    "http://www.ac.cyberhome.ne.jp/~mattn/gtkwassr.xml" 
    3042#define SERVICE_NAME               "wassr" 
    31 #define SERVICE_UPDATE_URL         "http://api.wassr.jp/statuses/update.json" 
     43#define SERVICE_UPDATE_STATUS_URL  "http://api.wassr.jp/statuses/update.json" 
     44#define SERVICE_TODO_LIST_URL      "http://api.wassr.jp/todo/list.json" 
     45#define SERVICE_TODO_ADD_URL       "http://api.wassr.jp/todo/add.json" 
    3246#define SERVICE_SELF_STATUS_URL    "http://api.wassr.jp/statuses/friends_timeline.rss" 
    3347#define SERVICE_FRIENDS_STATUS_URL "http://api.wassr.jp/statuses/friends_timeline.rss?id=%s" 
     
    4256#define XML_CONTENT(x) (x->children ? (char*)x->children->content : NULL) 
    4357 
     58static char utf8len_tab[256] = 
     59{ 
     60    1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 
     61    1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 
     62    1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 
     63    1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 
     64    1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, /*bogus*/ 
     65    1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, /*bogus*/ 
     66    2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, 
     67    3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,6,6,1,1, 
     68}; 
     69 
    4470static GdkCursor* hand_cursor = NULL; 
    4571static GdkCursor* regular_cursor = NULL; 
     
    94120        response_data = NULL; 
    95121        response_size = 0; 
     122} 
     123 
     124static int utf_ptr2char(unsigned char* p) { 
     125        int                len; 
     126 
     127        if (p[0] < 0x80)        /* be quick for ASCII */ 
     128                return p[0]; 
     129 
     130        len = utf8len_tab[p[0]]; 
     131        if ((p[1] & 0xc0) == 0x80) 
     132        { 
     133                if (len == 2) 
     134                        return ((p[0] & 0x1f) << 6) + (p[1] & 0x3f); 
     135                if ((p[2] & 0xc0) == 0x80) 
     136                { 
     137                        if (len == 3) 
     138                                return ((p[0] & 0x0f) << 12) + ((p[1] & 0x3f) << 6) 
     139                                        + (p[2] & 0x3f); 
     140                        if ((p[3] & 0xc0) == 0x80) 
     141                        { 
     142                                if (len == 4) 
     143                                        return ((p[0] & 0x07) << 18) + ((p[1] & 0x3f) << 12) 
     144                                                + ((p[2] & 0x3f) << 6) + (p[3] & 0x3f); 
     145                                if ((p[4] & 0xc0) == 0x80) 
     146                                { 
     147                                        if (len == 5) 
     148                                                return ((p[0] & 0x03) << 24) + ((p[1] & 0x3f) << 18) 
     149                                                        + ((p[2] & 0x3f) << 12) + ((p[3] & 0x3f) << 6) 
     150                                                        + (p[4] & 0x3f); 
     151                                        if ((p[5] & 0xc0) == 0x80 && len == 6) 
     152                                                return ((p[0] & 0x01) << 30) + ((p[1] & 0x3f) << 24) 
     153                                                        + ((p[2] & 0x3f) << 18) + ((p[3] & 0x3f) << 12) 
     154                                                        + ((p[4] & 0x3f) << 6) + (p[5] & 0x3f); 
     155                                } 
     156                        } 
     157                } 
     158        } 
     159        /* Illegal value, just return the first byte */ 
     160        return p[0]; 
    96161} 
    97162 
     
    545610        if (!status) return; 
    546611        while(*ptr) { 
     612                int code = utf_ptr2char(ptr); 
    547613                if (!strncmp(ptr, "http://", 7) || !strncmp(ptr, "ftp://", 6)) { 
    548614                        GtkTextTag *tag; 
     
    614680                                ptr = tmp; 
    615681                } else 
     682                if (IS_EMOJI(code)) { 
     683                        char* emoji; 
     684                        GdkPixbuf* pixbuf; 
     685                        if (last != ptr) 
     686                                gtk_text_buffer_insert(buffer, iter, last, ptr-last); 
     687 
     688                        emoji = g_strdup_printf("http://wassr.jp/img/pictogram/%X.gif", code); 
     689                        pixbuf = url2pixbuf(emoji, NULL); 
     690                        if (pixbuf) gtk_text_buffer_insert_pixbuf(buffer, iter, pixbuf); 
     691                        g_free(emoji); 
     692                        ptr += utf8len_tab[(unsigned char)*ptr]; 
     693                        last = ptr; 
     694                } else 
    616695#ifdef USE_REPLAY_ACCESS 
    617696                if (!strncmp(ptr, ">>", 2)) { 
     
    649728                } else 
    650729#endif 
    651                         ptr++; 
     730                        ptr += utf8len_tab[(unsigned char)*ptr]; 
    652731        } 
    653732        if (last != ptr) 
     
    835914                while(status) { 
    836915                        if (!strcmp("modified", (char*)status->name)) date = (char*)status->children->content; 
    837                         if (!strcmp("description", (char*)status->name)) { 
    838                                 if (status->children) text = (char*)status->children->content; 
     916                        if (!strcmp("title", (char*)status->name)) { 
     917                                if (status->children) { 
     918                                        char *ptr; 
     919                                        text = (char*)status->children->content; 
     920                                        ptr = strstr(text, " : "); 
     921                                        if (ptr) text = ptr + 3; 
     922                                } 
    839923                        } 
    840924                        if (!strcmp("author", (char*)status->name)) { 
     
    862946                                } 
    863947                        } 
    864                         if (!strcmp("description", (char*)status->name)) desc = XML_CONTENT(status); 
     948                        if (!strcmp("title", (char*)status->name)) { 
     949                                char *ptr; 
     950                                desc = XML_CONTENT(status); 
     951                                ptr = strstr(desc, " : "); 
     952                                if (ptr) desc = ptr + 3; 
     953                        } 
    865954                        status = status->next; 
    866955                } 
     
    10171106        /* making authenticate info */ 
    10181107        memset(url, 0, sizeof(url)); 
    1019         strncpy(url, SERVICE_UPDATE_URL, sizeof(url)-1); 
    10201108        sanitized_message = sanitize_message_alloc(message); 
    10211109        if (!message) return NULL; 
    1022         message = sanitized_message; 
    1023         message = url_encode_alloc(message); 
    1024         free(sanitized_message); 
    1025         if (message) { 
    1026                 strncat(url, "?status=", sizeof(url)-1);; 
    1027                 strncat(url, message, sizeof(url)-1); 
    1028                 free(message); 
    1029                 strncat(url, "&source=", sizeof(url)-1); 
    1030                 strncat(url, APP_NAME, sizeof(url)-1); 
     1110 
     1111/* 
     1112        if (!strnicmp(message, "todo:", 5)) { 
     1113                if (strlen(message + 5) == 0) { 
     1114                        strncpy(url, SERVICE_TODO_LIST_URL, sizeof(url)-1); 
     1115                } else { 
     1116                        strncpy(url, SERVICE_TODO_ADD_URL, sizeof(url)-1); 
     1117                } 
     1118                message = sanitized_message + 5; 
     1119                message = url_encode_alloc(message); 
     1120                free(sanitized_message); 
     1121                if (message) { 
     1122                        strncat(url, "?body=", sizeof(url)-1);; 
     1123                        strncat(url, message, sizeof(url)-1); 
     1124                        strncat(url, "&source=", sizeof(url)-1); 
     1125                        strncat(url, APP_NAME, sizeof(url)-1); 
     1126                        free(message); 
     1127                } 
     1128        } else 
     1129*/ 
     1130        { 
     1131                message = sanitized_message; 
     1132                message = url_encode_alloc(message); 
     1133                free(sanitized_message); 
     1134                if (message) { 
     1135                        strncpy(url, SERVICE_UPDATE_STATUS_URL, sizeof(url)-1); 
     1136                        strncat(url, "?status=", sizeof(url)-1);; 
     1137                        strncat(url, message, sizeof(url)-1); 
     1138                        strncat(url, "&source=", sizeof(url)-1); 
     1139                        strncat(url, APP_NAME, sizeof(url)-1); 
     1140                        free(message); 
     1141                } 
    10311142        } 
    10321143        memset(auth, 0, sizeof(auth));