├── .gitignore ├── build.txt ├── cloud ├── build.txt ├── cloud.c ├── cloud.h ├── local.c ├── local.h ├── pinyin.c ├── pinyin.h └── system.c ├── common ├── aes.c ├── aes.h ├── app.c ├── async.c ├── bihua.c ├── bihua.h ├── book.c ├── common.c ├── common.h ├── dict.c ├── english.c ├── english.h ├── history.c ├── im.c ├── im.h ├── keyboard.c ├── keyboard.xml.c ├── keydesc.c ├── keytool.c ├── keytool.h ├── layout.c ├── layout.h ├── main.c ├── mapfile.c ├── mapfile.h ├── menu.c ├── nl.c ├── pinyin.c ├── pinyin.h ├── replace.c ├── s2t.c ├── s2t.h ├── s2t_char.c ├── s2t_phrase.c ├── select.c ├── select.h ├── speed.c ├── t2s_char.c ├── t2s_phrase.c ├── translate.c ├── translate.h ├── trie.c ├── trie.h ├── version.h ├── ybus.c └── ybus.h ├── config ├── XPStyle.manifest ├── XPStyle64.manifest ├── aes.c ├── aes.h ├── build.txt ├── config_gtk.c ├── config_main.c ├── config_ui.c ├── config_ui.h ├── custom.c ├── custom_sync.c ├── custom_update.c ├── gz.c ├── lpng.c ├── lpng.h ├── session.c ├── session.h ├── session_curl.c ├── sync.c ├── sync.h ├── update.c ├── update.h └── yong-config.rc ├── data ├── README.txt ├── bihua.bin ├── entry │ ├── cloud.ini │ ├── erbi.ini │ ├── gbk.ini │ ├── pinyin.ini │ ├── wbpy.ini │ ├── wubi.ini │ ├── yong.ini │ ├── zhangma.ini │ └── zhengma.ini ├── mb │ ├── english.txt │ ├── erbi.txt │ ├── pinyin.ini │ ├── pinyin.txt │ ├── pypre.bin │ ├── sp.ini │ ├── wbpy.ini │ ├── wbx.txt │ ├── yong.txt │ ├── zhangma.txt │ └── zhengma.txt ├── normal.txt └── yong.chm ├── gbk ├── build.txt └── gbk.c ├── im ├── IMdkit │ ├── FrameMgr.c │ ├── FrameMgr.h │ ├── IMConn.c │ ├── IMMethod.c │ ├── IMValues.c │ ├── IMdkit.h │ ├── Xi18n.h │ ├── Xi18nTr.h │ ├── Xi18nX.h │ ├── XimFunc.h │ ├── XimProto.h │ ├── Xtrans.h │ ├── build.txt │ ├── i18nAttr.c │ ├── i18nClbk.c │ ├── i18nIMProto.c │ ├── i18nIc.c │ ├── i18nMethod.c │ ├── i18nOffsetCache.c │ ├── i18nPtHdr.c │ ├── i18nUtil.c │ └── i18nX.c ├── build.txt ├── fbterm.c ├── fbterm.h ├── fbterm │ ├── immessage.h │ ├── keycode.c │ ├── keycode.h │ └── keymap.c ├── gtk-im │ ├── build.txt │ ├── gtkimcontextyong.c │ ├── gtkimcontextyong.h │ ├── imyong.c │ └── zh_CN.po ├── gtk4-im │ ├── build.txt │ ├── imyong.c │ ├── yongimcontext.c │ └── yongimcontext.h ├── lcall.c ├── lcall.h ├── qt5-im │ ├── build.txt │ ├── main.cpp │ ├── main.h │ ├── qyongplatforminputcontext.cpp │ ├── qyongplatforminputcontext.h │ └── yong.json ├── skin │ ├── 1 │ │ ├── keyboard1.png │ │ └── menu1.png │ ├── 1.25 │ │ ├── keyboard1.png │ │ └── menu1.png │ ├── ban1.svg │ ├── cn1.svg │ ├── cn_biaodian1.svg │ ├── en1.svg │ ├── en_biaodian1.svg │ ├── fan1.svg │ ├── input.png │ ├── input1.png │ ├── input2.png │ ├── jian1.svg │ ├── keyboard1.png │ ├── logo.svg │ ├── main.png │ ├── menu1.png │ ├── skin.ini │ ├── skin0.ini │ ├── skin1.ini │ ├── skin1.png │ ├── skin2.ini │ ├── tray1.ico │ ├── tray1.png │ ├── tray2.ico │ └── tray2.png ├── ui-common.c ├── ui-draw.c ├── ui-draw.h ├── ui-timer.c ├── ui.c ├── wayland │ ├── input-method-client-protocol-v1.h │ ├── input-method-client-protocol-v2.h │ ├── input-method-protocol-v1.c │ ├── input-method-protocol-v2.c │ ├── libwayland-glib-source.c │ ├── virtual-keyboard-v1.c │ ├── virtual-keyboard-v1.h │ └── ybus-wayland.c ├── ybus-ibus.c ├── ybus-ibus.h ├── ybus-lcall.c ├── ybus-xim.c ├── ybutton.c ├── ybutton.h ├── yong-tool.sh ├── yong.ini └── yong.xml ├── include ├── gbk.h ├── ui.h ├── xim.h └── yong.h ├── install └── build.txt ├── llib ├── build.txt ├── larray.c ├── larray.h ├── lbase64.c ├── lbase64.h ├── lbits.h ├── lconfig.h ├── lconv.c ├── lconv.h ├── lcoroutine.c ├── lcoroutine.h ├── ldlfcn.h ├── lenv.c ├── lenv.h ├── lescape.c ├── lescape.h ├── lexpr.c ├── lexpr.h ├── lfile.c ├── lfile.h ├── lfuncs.c ├── lfuncs.h ├── lgb.c ├── lgb.h ├── lhashtable.c ├── lhashtable.h ├── lkeyfile.c ├── lkeyfile.h ├── llib.h ├── llist.c ├── llist.h ├── lmacros.h ├── lmem.h ├── lqsort.c ├── lqsort.h ├── lqueue.c ├── lqueue.h ├── lsearch.c ├── lsearch.h ├── lslice.c ├── lslist.c ├── lslist.h ├── lstring.c ├── lstring.h ├── lthreads.h ├── ltime.h ├── ltricky.h ├── ltypes.h ├── lunicode.c ├── lunicode.h ├── lxml.c ├── lxml.h ├── lzip.c ├── lzlib.c ├── lzlib.h ├── md5.c └── md5.h ├── mb ├── assoc.c ├── assoc.h ├── build.txt ├── cset.c ├── cset.h ├── face.c ├── fuzzy.c ├── fuzzy.h ├── learn.c ├── learn.h ├── mb.c ├── mb.h ├── pyzip.c ├── pyzip.h ├── sentence.c ├── sentence.h └── tools.c ├── rules.txt └── vim ├── build.txt └── vim.c /.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | *.so 3 | l64/ 4 | l32-*/ 5 | l64-*/ 6 | install/yong/ 7 | -------------------------------------------------------------------------------- /build.txt: -------------------------------------------------------------------------------- 1 | var DIRS=[ 2 | 'llib', 3 | 'gbk', 4 | 'cloud', 5 | 'config', 6 | 'im', 7 | 8 | 'mb', 9 | 'vim' 10 | ]; 11 | 12 | 13 | build(DIRS,undefined,target); 14 | -------------------------------------------------------------------------------- /cloud/build.txt: -------------------------------------------------------------------------------- 1 | var SRCS=['pinyin.c','cloud.c','local.c','trie.c','system.c']; 2 | var DIRS=['l32','l64', 3 | 4 | ]; 5 | 6 | env("VPATH+=$(TOPDIR)/cloud"); 7 | env("CFLAGS+=$(PICFLAGS) $(LLIB_CFLAGS)"); 8 | env("LDFLAGS+=-shared $(LLIB_LDFLAGS)"); 9 | env("LIBS+=$(LLIB_LDADD)"); 10 | 11 | function run(target){ 12 | cd(target); 13 | include("../../rules.txt"); 14 | if(target=="w32" || target=="w64") 15 | env("LIBS+=-lws2_32"); 16 | var OBJS=wildcard(SRCS,function(input){ 17 | return input.replace(/.c$/,'.o'); 18 | }); 19 | begin(); 20 | cc(SRCS,OBJS); 21 | end(function(){ 22 | ld(OBJS,'$(DESTDIR)/libcloud.so'); 23 | }); 24 | } 25 | 26 | if(target=="clean"){ 27 | rmdir(DIRS,'*'); 28 | } else if(!target || target=="all"){ 29 | build(undefined,undefined,DIRS); 30 | } else { 31 | run(target); 32 | } 33 | -------------------------------------------------------------------------------- /cloud/cloud.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "llib.h" 4 | 5 | #define SG_CACHE_SIZE 13771 6 | 7 | typedef struct{ 8 | char *s; 9 | int l; 10 | }sg_cand_t; 11 | 12 | typedef struct{ 13 | void *n; 14 | char *q; 15 | sg_cand_t *cs; 16 | unsigned short l; 17 | unsigned short c; 18 | }sg_res_t; 19 | 20 | typedef struct{ 21 | void *n; 22 | char *name; 23 | char *value; 24 | }sg_cookie_t; 25 | 26 | typedef struct{ 27 | sg_res_t *t[SG_CACHE_SIZE]; 28 | sg_res_t *l,*l_old; 29 | int c; 30 | int abort; 31 | int ready; 32 | char req[128]; 33 | 34 | char *format; 35 | char *proxy; 36 | char *proxy_auth; 37 | char *key; 38 | char *option; 39 | 40 | LSList *cookie; 41 | }sg_cache_t; 42 | 43 | extern sg_cache_t *l_cache; 44 | 45 | struct cloud_api{ 46 | const char *name; 47 | const char *method; 48 | const char *host; 49 | const char *query_key; 50 | const char *query_res; 51 | const char *post_res; 52 | char* (*key_parse)(sg_cache_t *C,char *s); 53 | sg_res_t* (*res_parse)(sg_cache_t *c,char *s); 54 | }; 55 | extern struct cloud_api sg_apis[]; 56 | extern struct cloud_api *sg_cur_api; 57 | 58 | void sg_cookie_free(sg_cookie_t *cookie); 59 | void sg_recc(sg_cache_t *c,int rec); 60 | void sg_cache_add(sg_cache_t *c,sg_res_t *r); 61 | sg_res_t *sg_cache_get(sg_cache_t *c,char *s,int l); 62 | sg_res_t *sg_local(sg_res_t *r,const char *p,bool strict); 63 | sg_res_t *sg_parse(sg_cache_t *c,char *s); 64 | 65 | void CloudInit(void); 66 | void CloudCleanup(void); 67 | void CloudWaitReady(void); 68 | void CloudSetSignal(void); 69 | void CloudLock(void); 70 | void CloudUnlock(void); 71 | -------------------------------------------------------------------------------- /cloud/local.h: -------------------------------------------------------------------------------- 1 | #ifndef _LOCAL_H_ 2 | #define _LOCAL_H_ 3 | 4 | void local_load_pinyin(const char *fn); 5 | void local_load_assist(const char *fn,int pos); 6 | void local_free_all(void); 7 | bool local_assist_match(const char *p,int c); 8 | bool local_is_assist_key(int key); 9 | const char *local_pinyin_get(const char *pinyin); 10 | 11 | void local_load_user(const char *fn); 12 | const void *local_phrase_set(const char *pinyin); 13 | int local_phrase_count(const void *phrase); 14 | int local_phrase_get(const void *phrase,int at,int num, 15 | char cand[][MAX_CAND_LEN+1]); 16 | #endif/*_LOCAL_H_*/ 17 | -------------------------------------------------------------------------------- /cloud/pinyin.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dgod/yong/22b4e983260b53cbcd6a6602d38d7c00081b87a5/cloud/pinyin.c -------------------------------------------------------------------------------- /cloud/pinyin.h: -------------------------------------------------------------------------------- 1 | #ifndef _PINYIN_H_ 2 | #define _PINYIN_H_ 3 | 4 | #define PY_MAX_TOKEN 128 5 | 6 | struct py_item; 7 | typedef struct py_item *py_item_t; 8 | 9 | void py_init(int split,char *sp); 10 | 11 | int py_parse_string(const char *input,py_item_t *token,int caret); 12 | int py_build_string(char *out,py_item_t *token,int count); 13 | int py_build_sp_string(char *out,py_item_t *token,int count); 14 | int py_prepare_string(char *to,const char *from,int *caret); 15 | int py_parse_sp_simple(const char *input,py_item_t *token); 16 | int py_caret_to_pos(py_item_t *token,int count,int caret); 17 | int py_string_step(char *input,int caret,uint8_t step[],int max); 18 | int py_conv_from_sp(const char *in,char *out,int size,int split); 19 | int py_conv_to_sp(const char *s,const char *zi,char *out); 20 | int py_is_valid_input(int sp,int c,int pos); 21 | int py_is_valid_code(const char *in); 22 | int py_is_valid_quanpin(const char *input); 23 | int py_is_valid_sp(const char *input); 24 | int py_remove_split(py_item_t *token,int count); 25 | int py_pos_of_sp(const char *in,int pos); 26 | int py_pos_of_qp(py_item_t *in,int pos); 27 | int py_sp_has_semi(void); 28 | int py_get_space_pos(py_item_t *token,int count,int space); 29 | 30 | #endif/*_PINYIN_H_*/ 31 | -------------------------------------------------------------------------------- /cloud/system.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dgod/yong/22b4e983260b53cbcd6a6602d38d7c00081b87a5/cloud/system.c -------------------------------------------------------------------------------- /common/aes.h: -------------------------------------------------------------------------------- 1 | #ifndef AES_H_ 2 | #define AES_H_ 3 | 4 | #include 5 | 6 | void aes_set_key(const uint8_t *cipher_key, int key_len); 7 | int aes_encrypt(const uint8_t *plain_text, uint8_t *cipher_text); //加密 8 | int aes_decrypt(const uint8_t *cipher_text, uint8_t *plain_text); //解密 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /common/bihua.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dgod/yong/22b4e983260b53cbcd6a6602d38d7c00081b87a5/common/bihua.c -------------------------------------------------------------------------------- /common/bihua.h: -------------------------------------------------------------------------------- 1 | /*! 2 | * \author dgod 3 | */ 4 | #ifndef _BIHUA_H_ 5 | #define _BIHUA_H_ 6 | 7 | /* note that we don't support gbk and above at ->name */ 8 | typedef struct{ 9 | char *name; 10 | char *code; 11 | }Y_BIHUA_INFO; 12 | 13 | #define Y_BIHUA_KEY "abcdefghijklmnopqrstuvwxyz;',./" 14 | 15 | extern Y_BIHUA_INFO y_bihua_info[]; 16 | 17 | int y_bihua_load(const char *fn); 18 | void y_bihua_free(void); 19 | int y_bihua_set(char *s); 20 | char *y_bihua_get(int at,int num); 21 | void *y_bihua_eim(void); 22 | int y_bihua_good(void); 23 | 24 | #endif/*_BIHUA_H_*/ 25 | -------------------------------------------------------------------------------- /common/book.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dgod/yong/22b4e983260b53cbcd6a6602d38d7c00081b87a5/common/book.c -------------------------------------------------------------------------------- /common/common.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dgod/yong/22b4e983260b53cbcd6a6602d38d7c00081b87a5/common/common.c -------------------------------------------------------------------------------- /common/dict.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dgod/yong/22b4e983260b53cbcd6a6602d38d7c00081b87a5/common/dict.c -------------------------------------------------------------------------------- /common/english.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dgod/yong/22b4e983260b53cbcd6a6602d38d7c00081b87a5/common/english.c -------------------------------------------------------------------------------- /common/english.h: -------------------------------------------------------------------------------- 1 | #ifndef _ENGLISH_H_ 2 | #define _ENGLISH_H_ 3 | 4 | #include "yong.h" 5 | #include "ltypes.h" 6 | 7 | typedef struct{ 8 | int (*Set)(const char *s); 9 | int (*Get)(char cand[][MAX_CAND_LEN+1],int pos,int count); 10 | void (*Reset)(void); 11 | int Count; 12 | int64_t Priv1; 13 | uintptr_t Priv2; 14 | }ENGLISH_IM; 15 | 16 | void y_english_init(void); 17 | void y_english_destroy(void); 18 | void *y_english_eim(void); 19 | void y_english_key_desc(const char *code,char *res); 20 | 21 | #endif/*_ENGLISH_H_*/ 22 | -------------------------------------------------------------------------------- /common/im.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dgod/yong/22b4e983260b53cbcd6a6602d38d7c00081b87a5/common/im.c -------------------------------------------------------------------------------- /common/im.h: -------------------------------------------------------------------------------- 1 | #ifndef _IM_H_ 2 | #define _IM_H_ 3 | 4 | #include "yong.h" 5 | #include "bihua.h" 6 | #include "english.h" 7 | #include "s2t.h" 8 | #include "layout.h" 9 | 10 | #ifdef _WIN32 11 | #include 12 | #endif 13 | 14 | typedef struct{ 15 | void *handle; 16 | EXTRA_IM *eim; 17 | 18 | int Index; 19 | int IndexPrev; 20 | int CandWord; 21 | int Preedit; 22 | int Biaodian; 23 | int Trad; 24 | int TradDef; 25 | int Bing; 26 | int AssocLen; 27 | int AssocLoop; 28 | int InAssoc; 29 | int Beep; 30 | int BingSkip[2]; 31 | int Hint; // 编码提示 32 | 33 | #if defined(_WIN32) || defined(CFG_XIM_ANDROID) 34 | uint16_t StringGet[MAX_CAND_LEN+1]; 35 | uint16_t CodeInput[MAX_CODE_LEN*2+1]; 36 | #else 37 | char StringGet[(MAX_CAND_LEN+1)*3/2]; 38 | char CodeInput[(MAX_CODE_LEN+1)*3]; 39 | #endif 40 | int CodeLen; 41 | int CaretPos; 42 | char CandTable[10][(MAX_CAND_LEN+1)*2]; 43 | char CodeTips[10][(MAX_TIPS_LEN+1)*2]; 44 | char AssistCode[4]; 45 | 46 | char StringGetEngine[MAX_CAND_LEN+2]; 47 | char CodeInputEngine[MAX_CODE_LEN+2]; 48 | char CandTableEngine[10][MAX_CAND_LEN+1]; 49 | char CodeTipsEngine[10][MAX_TIPS_LEN+1]; 50 | 51 | int cursor_h; 52 | double CandPosX[33]; 53 | double CandPosY[33]; 54 | uint16_t CandWidth[10]; 55 | uint16_t CandHeight[10]; 56 | int BihuaMode; 57 | int EnglishMode; 58 | int ChinglishMode; 59 | int SelectMode; 60 | int StopInput; 61 | #if defined(_WIN32) || defined(CFG_XIM_ANDROID) 62 | uint16_t Page[32]; 63 | #else 64 | char Page[32]; 65 | #endif 66 | double PageLen[3]; 67 | double PagePosX; 68 | double PagePosY; 69 | double CodePos[4]; 70 | 71 | Y_LAYOUT *layout; 72 | }IM; 73 | 74 | /* this one defined at main.c */ 75 | extern IM im; 76 | 77 | int InitExtraIM(IM *im,EXTRA_IM *eim,const char *arg); 78 | int LoadExtraIM(IM *im,const char *fn); 79 | const char *YongFullChar(int key); 80 | const char *YongGetPunc(int key,int bd,int peek); 81 | EXTRA_IM *YongCurrentIM(void); 82 | 83 | #define CURRENT_EIM YongCurrentIM 84 | 85 | #endif/*_FCITX_H_*/ 86 | -------------------------------------------------------------------------------- /common/keytool.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "common.h" 4 | 5 | #ifndef CFG_NO_KEYTOOL 6 | 7 | Y_KEY_TOOL *y_key_tools_load(void) 8 | { 9 | Y_KEY_TOOL *h=NULL; 10 | for(int i=0;i<64;i++) 11 | { 12 | char key[32]; 13 | sprintf(key,"tools[%d]",i); 14 | const char *item=y_im_get_config_data("key",key); 15 | if(!item) 16 | break; 17 | const char *p=strchr(item,' '); 18 | if(!p) 19 | continue; 20 | int keyval=y_im_str_to_key(item,NULL); 21 | if(keyval==0) 22 | continue; 23 | int len=strlen(p); 24 | Y_KEY_TOOL *kt=l_alloc(sizeof(Y_KEY_TOOL)+len); 25 | kt->key=keyval; 26 | strcpy(kt->exec,p+1); 27 | h=l_slist_prepend(h,kt); 28 | } 29 | 30 | return h; 31 | } 32 | 33 | void y_key_tools_free(Y_KEY_TOOL *kt) 34 | { 35 | l_slist_free(kt,l_free); 36 | } 37 | 38 | int y_key_tools_run(Y_KEY_TOOL *kt,int key) 39 | { 40 | Y_KEY_TOOL *p; 41 | for(p=kt;p!=NULL;p=p->next) 42 | { 43 | if(p->key==key) 44 | { 45 | if(p->exec[0]=='$') 46 | y_xim_send_string(p->exec); 47 | else 48 | y_xim_explore_url(p->exec); 49 | return 1; 50 | } 51 | } 52 | return 0; 53 | } 54 | 55 | #endif //CFG_NO_KEYTOOL 56 | -------------------------------------------------------------------------------- /common/keytool.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | typedef struct{ 4 | void *next; 5 | int key; 6 | char exec[]; 7 | }Y_KEY_TOOL; 8 | 9 | Y_KEY_TOOL *y_key_tools_load(void); 10 | void y_key_tools_free(Y_KEY_TOOL *kt); 11 | int y_key_tools_run(Y_KEY_TOOL *kt,int key); 12 | -------------------------------------------------------------------------------- /common/layout.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dgod/yong/22b4e983260b53cbcd6a6602d38d7c00081b87a5/common/layout.h -------------------------------------------------------------------------------- /common/main.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dgod/yong/22b4e983260b53cbcd6a6602d38d7c00081b87a5/common/main.c -------------------------------------------------------------------------------- /common/mapfile.c: -------------------------------------------------------------------------------- 1 | #ifdef _WIN32 2 | #include 3 | #else 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #endif 10 | #include "llib.h" 11 | 12 | struct y_mmap{ 13 | void *addr; 14 | int size; 15 | }; 16 | 17 | #if defined(CFG_XIM_ANDROID) || defined(CFG_XIM_WEBIM) 18 | 19 | #include 20 | 21 | void *y_mmap_new(const char *fn) 22 | { 23 | struct y_mmap *p; 24 | size_t len; 25 | p=calloc(1,sizeof(struct y_mmap)); 26 | p->addr=l_file_get_contents(fn,&len,NULL); 27 | if(!p->addr) 28 | { 29 | free(p); 30 | return NULL; 31 | } 32 | p->size=(int)len; 33 | return p; 34 | } 35 | 36 | void y_mmap_free(void *map) 37 | { 38 | struct y_mmap *p=map; 39 | if(!p) return; 40 | l_free(p->addr); 41 | free(p); 42 | } 43 | 44 | #else 45 | 46 | void *y_mmap_new(const char *fn) 47 | { 48 | struct y_mmap *p; 49 | p=calloc(1,sizeof(struct y_mmap)); 50 | #ifdef _WIN32 51 | { 52 | HANDLE fd; 53 | HANDLE map; 54 | fd=CreateFileA(fn,GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL); 55 | if(fd==INVALID_HANDLE_VALUE) 56 | { 57 | free(p); 58 | return NULL; 59 | } 60 | p->size=(int)GetFileSize(fd,NULL); 61 | map=CreateFileMapping(fd,NULL,PAGE_READONLY,0,0,NULL); 62 | CloseHandle(fd); 63 | if(!map) 64 | { 65 | free(p); 66 | return NULL; 67 | } 68 | p->addr=MapViewOfFile(map,FILE_MAP_READ,0,0,0); 69 | if(!p->addr) 70 | { 71 | CloseHandle(map); 72 | free(p); 73 | return NULL; 74 | } 75 | CloseHandle(map); 76 | } 77 | #else 78 | { 79 | int fd; 80 | //struct stat st; 81 | fd=open(fn,O_RDONLY); 82 | if(fd==-1) 83 | { 84 | free(p); 85 | return NULL; 86 | } 87 | //fstat(fd,&st); 88 | //p->size=st.st_size; 89 | //if(st.st_size<=0) 90 | //{ 91 | // close(fd); 92 | // free(p); 93 | // return NULL; 94 | //} 95 | p->size=l_file_size(fn); 96 | p->addr=mmap(NULL,p->size,PROT_READ,MAP_PRIVATE,fd,0); 97 | close(fd); 98 | if(!p->addr) 99 | { 100 | free(p); 101 | return NULL; 102 | } 103 | } 104 | #endif 105 | return p; 106 | } 107 | 108 | void y_mmap_free(void *map) 109 | { 110 | struct y_mmap *p=map; 111 | if(!p) return; 112 | #ifdef _WIN32 113 | UnmapViewOfFile(p->addr); 114 | #else 115 | munmap(p->addr,p->size); 116 | #endif 117 | free(p); 118 | } 119 | 120 | #endif 121 | 122 | int y_mmap_length(void *map) 123 | { 124 | struct y_mmap *p=map; 125 | return p->size; 126 | } 127 | 128 | void *y_mmap_addr(void *map) 129 | { 130 | struct y_mmap *p=map; 131 | return p->addr; 132 | } 133 | 134 | -------------------------------------------------------------------------------- /common/mapfile.h: -------------------------------------------------------------------------------- 1 | #ifndef _MAPFILE_H_ 2 | #define _MAPFILE_H_ 3 | 4 | void *y_mmap_new(const char *fn); 5 | void y_mmap_free(void *map); 6 | int y_mmap_length(void *map); 7 | void *y_mmap_addr(void *map); 8 | 9 | 10 | #endif/*_MAPFILE_H_*/ 11 | 12 | -------------------------------------------------------------------------------- /common/menu.c: -------------------------------------------------------------------------------- 1 | const char *ui_menu_default= 2 | 3 | "[root]\n" 4 | "child=config tools im output help - exit\n" 5 | 6 | "[config]\n" 7 | "name=设置\n" 8 | "exec=$CONFIG\n" 9 | 10 | "[tools]\n" 11 | "name=工具\n" 12 | "child=stat sys update keymap mbo mbm mbe\n" 13 | 14 | "[stat]\n" 15 | "name=输入统计\n" 16 | "exec=$STAT\n" 17 | 18 | "[sys]\n" 19 | "name=系统信息\n" 20 | "exec=$SYSINFO\n" 21 | 22 | "[update]\n" 23 | "name=软件更新\n" 24 | "exec=$GO(yong-config --update)\n" 25 | 26 | "[keymap]\n" 27 | "exec=$KEYMAP\n" 28 | 29 | "[mbo]\n" 30 | "name=码表优化\n" 31 | "exec=$MBO\n" 32 | 33 | "[mbm]\n" 34 | "name=合并用户码表\n" 35 | "exec=$MBM\n" 36 | 37 | "[mbe]\n" 38 | "name=编辑码表\n" 39 | "exec=$MBEDIT\n" 40 | 41 | "[im]\n" 42 | "name=输入法\n" 43 | "exec=$IMLIST\n" 44 | 45 | "[output]\n" 46 | "name=输出方式\n" 47 | "exec=$OUTPUT\n" 48 | 49 | "[help]\n" 50 | "name=帮助\n" 51 | "child=help0 help1 about\n" 52 | 53 | "[help0]\n" 54 | "exec=$HELP(main)\n" 55 | 56 | "[help1]\n" 57 | "exec=$HELP(?)\n" 58 | 59 | "[about]\n" 60 | "name=关于\n" 61 | "exec=$ABOUT\n" 62 | 63 | "[exit]\n" 64 | "name=退出\n" 65 | "exec=$EXIT\n" 66 | ; 67 | -------------------------------------------------------------------------------- /common/nl.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dgod/yong/22b4e983260b53cbcd6a6602d38d7c00081b87a5/common/nl.c -------------------------------------------------------------------------------- /common/pinyin.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dgod/yong/22b4e983260b53cbcd6a6602d38d7c00081b87a5/common/pinyin.c -------------------------------------------------------------------------------- /common/pinyin.h: -------------------------------------------------------------------------------- 1 | #ifndef _PINYIN_H_ 2 | #define _PINYIN_H_ 3 | 4 | #define PY_MAX_TOKEN 128 5 | 6 | struct py_item; 7 | typedef struct py_item *py_item_t; 8 | 9 | void py_init(int split,char *sp); 10 | 11 | int py_parse_string(const char *input,py_item_t *token,int caret,int (*check)(int,const char*,void *),void *arg); 12 | int py_build_string(char *out,py_item_t *token,int count); 13 | int py_build_string_no_split(char *out,const py_item_t *token,int count); 14 | int py_build_sp_string(char *out,py_item_t *token,int count); 15 | int py_build_jp_string(char *out,const py_item_t *token,int count); 16 | int py_build_zrm_string(char *out,const py_item_t *token,int count); 17 | int py_prepare_string(char *to,const char *from,int *caret); 18 | int py_parse_sp_jp(const char *input,py_item_t *token); 19 | int py_caret_to_pos(py_item_t *token,int count,int caret); 20 | int py_caret_next_item(py_item_t *token,int count,int caret); 21 | int py_string_step(char *input,int caret,uint8_t step[],int max); 22 | int py_conv_from_sp(const char *in,char *out,int size,int split); 23 | int py_conv_to_sp(const char *s,const char *zi,char *out); 24 | int py_conv_to_sp2(const char *s,const char *zi,char *out,int (*first_code)(uint32_t,char*,void*),void *arg); 25 | int py_conv_to_sp3(const char *s,char *out); 26 | int py_is_valid_input(int sp,int c,int pos); 27 | int py_is_valid_code(const char *in); 28 | int py_is_valid_quanpin(const char *input); 29 | int py_is_valid_sp(const char *input); 30 | int py_remove_split(py_item_t *token,int count); 31 | int py_pos_of_sp(const char *in,int pos); 32 | int py_pos_of_qp(py_item_t *in,int pos); 33 | int py_sp_has_semi(void); 34 | int py_get_space_pos(py_item_t *token,int count,int space); 35 | const char *py_sp_get_chshzh(void); 36 | int py_sp_unlikely_jp(const char *in); 37 | int py_quanpin_maybe_jp(const py_item_t *token,int count); 38 | int py_first_zrm_shen(const char *s); 39 | int py_jp_from_qp(const char *s,const char *zi,char *out); 40 | int py_item_len(py_item_t it); 41 | int py_get_jp_code(const py_item_t token); 42 | 43 | #endif/*_PINYIN_H_*/ 44 | -------------------------------------------------------------------------------- /common/replace.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dgod/yong/22b4e983260b53cbcd6a6602d38d7c00081b87a5/common/replace.c -------------------------------------------------------------------------------- /common/s2t.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dgod/yong/22b4e983260b53cbcd6a6602d38d7c00081b87a5/common/s2t.c -------------------------------------------------------------------------------- /common/s2t.h: -------------------------------------------------------------------------------- 1 | #ifndef _S2T_H_ 2 | #define _S2T_H_ 3 | 4 | void s2t_enable(int b); 5 | int s2t_is_enable(void); 6 | void s2t_biaodian(int b); 7 | const char *s2t_conv(const char *s); 8 | int s2t_select(const char *s); 9 | void s2t_multiple(int b); 10 | 11 | #endif/*_S2T_H_*/ 12 | -------------------------------------------------------------------------------- /common/select.c: -------------------------------------------------------------------------------- 1 | #include "im.h" 2 | #include "yong.h" 3 | 4 | #include 5 | #include 6 | #include "llib.h" 7 | #include "common.h" 8 | 9 | static int SelInit(const char *arg); 10 | static void SelReset(void); 11 | static char *SelGetCandWord(int index); 12 | static int SelGetCandWords(int mode); 13 | static int SelDestroy(void); 14 | static int SelDoInput(int key); 15 | 16 | static EXTRA_IM EIM={ 17 | "select", 18 | .Reset = SelReset, 19 | .DoInput = SelDoInput, 20 | .GetCandWords = SelGetCandWords, 21 | .GetCandWord = SelGetCandWord, 22 | .Init = SelInit, 23 | .Destroy = SelDestroy, 24 | }; 25 | 26 | static LPtrArray *cands; 27 | 28 | static int SelInit(const char *arg) 29 | { 30 | return 0; 31 | } 32 | 33 | static void SelReset(void) 34 | { 35 | EIM.CodeInput[0]=0; 36 | EIM.StringGet[0]=0; 37 | EIM.CodeLen=0; 38 | EIM.CurCandPage=EIM.CandPageCount=EIM.CandWordCount=0; 39 | EIM.SelectIndex=0; 40 | im.SelectMode=0; 41 | if(cands) 42 | { 43 | l_ptr_array_free(cands,l_free); 44 | cands=NULL; 45 | } 46 | } 47 | 48 | static char *SelGetCandWord(int index) 49 | { 50 | char *ret; 51 | if(index==-1) index=EIM.SelectIndex; 52 | if(index>=EIM.CandWordCount) return 0; 53 | ret=&EIM.CandTable[index][0]; 54 | strcpy(EIM.StringGet,ret); 55 | return ret; 56 | } 57 | 58 | static int SelGetCandWords(int mode) 59 | { 60 | if(cands) 61 | { 62 | if(mode==PAGE_ASSOC) 63 | return IMR_PASS; 64 | if(mode==PAGE_FIRST) 65 | EIM.CurCandPage=0; 66 | else if(mode==PAGE_NEXT && EIM.CurCandPage+10) 69 | EIM.CurCandPage--; 70 | if(EIM.CurCandPagekey); 16 | l_free(p->val); 17 | l_free(p->val_utf8); 18 | l_free(p); 19 | } 20 | 21 | static LHashTable *l_strings; 22 | 23 | void y_translate_init(const char *config) 24 | { 25 | FILE *fp; 26 | char key[256],val[256]; 27 | int len; 28 | fp=l_file_open(config,"rb",y_im_get_path("HOME"),y_im_get_path("DATA"),NULL); 29 | if(!fp) 30 | { 31 | return; 32 | } 33 | l_strings=L_HASH_TABLE_STRING(struct item,key,251); 34 | while(1) 35 | { 36 | struct item *it; 37 | len=l_get_line(key,sizeof(val),fp); 38 | if(len<0) break; 39 | if(len==0) continue; 40 | len=l_get_line(val,sizeof(val),fp); 41 | if(len<0) break; 42 | if(len==0) continue; 43 | it=l_new(struct item); 44 | it->key=l_strdup(key); 45 | it->val=l_strdup(val); 46 | it->val_utf8=NULL; 47 | it=l_hash_table_replace(l_strings,it); 48 | item_free(it); 49 | } 50 | 51 | fclose(fp); 52 | } 53 | 54 | const char *y_translate_get(const char *s) 55 | { 56 | if(!l_strings || !s) 57 | return s; 58 | struct item *it=l_hash_table_lookup(l_strings,s); 59 | if(!it) 60 | return s; 61 | return it->val; 62 | } 63 | 64 | const char *y_translate_get_utf8(const char *s) 65 | { 66 | if(!l_strings || !s) 67 | return s; 68 | char temp[8192]; 69 | l_utf8_to_gb(s,temp,sizeof(temp)); 70 | struct item *it=l_hash_table_lookup(l_strings,temp); 71 | if(!it) 72 | return s; 73 | if(!it->val_utf8) 74 | { 75 | l_gb_to_utf8(it->val,temp,sizeof(temp)); 76 | it->val_utf8=l_strdup(temp); 77 | } 78 | return it->val_utf8; 79 | } 80 | 81 | int y_translate_is_enable(void) 82 | { 83 | return l_strings?1:0; 84 | } 85 | -------------------------------------------------------------------------------- /common/translate.h: -------------------------------------------------------------------------------- 1 | #ifndef _TRANSLATE_H_ 2 | #define _TRANSLATE_H_ 3 | 4 | void y_translate_init(const char *config); 5 | const char *y_translate_get(const char *s); 6 | const char *y_translate_get_utf8(const char *s); 7 | int y_translate_is_enable(void); 8 | 9 | #define YT(s) ((char*)y_translate_get(s)) 10 | #define YT8(s) ((char*)y_translate_get_utf8(s)) 11 | 12 | #endif/*_TRANSLATE_H_*/ 13 | -------------------------------------------------------------------------------- /common/trie.h: -------------------------------------------------------------------------------- 1 | #ifndef _TRIE_H_ 2 | #define _TRIE_H_ 3 | 4 | struct trie_tree; 5 | typedef struct trie_tree trie_tree_t ; 6 | struct trie_node; 7 | typedef struct trie_node trie_node_t; 8 | 9 | struct trie_node{ 10 | union{ 11 | struct{ 12 | uint64_t node:1; 13 | uint64_t leaf:1; 14 | uint64_t self:8; 15 | uint64_t brother:27; 16 | uint64_t child:27; 17 | }; 18 | void *data; 19 | }; 20 | }; 21 | 22 | struct trie_tree{ 23 | trie_node_t *page[256]; 24 | int count; 25 | }; 26 | 27 | typedef struct trie_iter{ 28 | trie_tree_t *tree; 29 | trie_node_t *root; 30 | int max; 31 | int depth; 32 | int skip; 33 | int path[64]; 34 | }trie_iter_t; 35 | 36 | #define TRIE_DATA(n) ((trie_node_t*)(n)->data) 37 | 38 | trie_tree_t *trie_tree_new(void); 39 | void trie_tree_free(trie_tree_t *t); 40 | trie_node_t *trie_tree_root(trie_tree_t *t); 41 | trie_node_t *trie_tree_get_path(trie_tree_t *t,const char *s,int len); 42 | trie_node_t *trie_tree_get_leaf(trie_tree_t *t,const char *s,int len); 43 | trie_node_t *trie_tree_add(trie_tree_t *t,const char *s,int len); 44 | int trie_tree_del(trie_tree_t *t,const char *s,int len); 45 | int trie_tree_is_leaf(trie_tree_t *t,const char *s,int len); 46 | 47 | trie_node_t *trie_node_get_child(trie_tree_t *t,trie_node_t *n); 48 | trie_node_t *trie_node_get_brother(trie_tree_t *t,trie_node_t *n); 49 | trie_node_t *trie_node_get_leaf(trie_tree_t *t,trie_node_t *n); 50 | 51 | trie_node_t *trie_iter_leaf_first(trie_iter_t *iter,trie_tree_t *t,trie_node_t *n,int depth); 52 | trie_node_t *trie_iter_leaf_next(trie_iter_t *iter); 53 | trie_node_t *trie_iter_path_first(trie_iter_t *iter,trie_tree_t *t,trie_node_t *n,int depth); 54 | trie_node_t *trie_iter_path_next(trie_iter_t *iter); 55 | #define trie_iter_path_skip(iter) ((iter)->skip=1) 56 | int trie_iter_get_path(trie_iter_t *iter,char *s); 57 | 58 | typedef union{ 59 | struct{ 60 | uint32_t child:9; 61 | uint32_t brother:9; 62 | uint32_t item:9; 63 | uint32_t self:5; 64 | }; 65 | uint32_t data; 66 | }py_node_t; 67 | 68 | typedef struct{ 69 | uint32_t node[512]; 70 | int count; 71 | }py_tree_t; 72 | 73 | void py_tree_init(py_tree_t *tree); 74 | void py_tree_add(py_tree_t *tree,const char *s,int len,int item); 75 | int py_tree_get(py_tree_t *tree,const char *s,int *out); 76 | 77 | #endif/*_TRIE_H_*/ 78 | -------------------------------------------------------------------------------- /common/version.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #define YONG_VERSION "2024-12-21 15:14" 3 | -------------------------------------------------------------------------------- /common/ybus.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dgod/yong/22b4e983260b53cbcd6a6602d38d7c00081b87a5/common/ybus.c -------------------------------------------------------------------------------- /common/ybus.h: -------------------------------------------------------------------------------- 1 | #ifndef _YBUS_H_ 2 | #define _YBUS_H_ 3 | 4 | typedef uintptr_t CLIENT_ID; 5 | typedef uintptr_t CONN_ID; 6 | 7 | typedef struct{ 8 | void *next; 9 | CLIENT_ID id; 10 | int x,y; 11 | int track; 12 | int key; 13 | int state; 14 | int rel; 15 | uint8_t priv[]; 16 | }YBUS_CLIENT; 17 | 18 | typedef struct{ 19 | void *next; 20 | 21 | const char *name; 22 | 23 | int (*init)(void); 24 | 25 | int (*getpid)(CONN_ID id); 26 | const char *(*get_appid)(CONN_ID id); 27 | CLIENT_ID (*copy_client_id)(CLIENT_ID id); 28 | void (*free_client_id)(CLIENT_ID id); 29 | int (*match_client)(CLIENT_ID,CLIENT_ID); 30 | 31 | CONN_ID (*copy_connect_id)(CONN_ID id); 32 | void (*free_connect_id)(CONN_ID id); 33 | int (*match_connect)(CONN_ID,CONN_ID); 34 | 35 | int (*config)(CONN_ID,CLIENT_ID,const char*,...); 36 | void (*open_im)(CONN_ID,CLIENT_ID); 37 | void (*close_im)(CONN_ID,CLIENT_ID); 38 | void (*preedit_clear)(CONN_ID,CLIENT_ID); 39 | int (*preedit_draw)(CONN_ID,CLIENT_ID,const char*); 40 | void (*send_string)(CONN_ID,CLIENT_ID,const char*,int flags); 41 | void (*send_key)(CONN_ID,CLIENT_ID,int key,int repeat); 42 | void (*send_keys)(CONN_ID,CLIENT_ID,const int *keys,int count); 43 | 44 | void (*wm_state)(CONN_ID,int); 45 | void (*wm_make_above)(CONN_ID,const char *); 46 | void (*wm_move)(CONN_ID,const char *,int,int,int); 47 | void (*wm_icon)(CONN_ID,const char *,const char*); 48 | }YBUS_PLUGIN; 49 | 50 | typedef struct{ 51 | void *next; 52 | int pid; 53 | CONN_ID id; 54 | YBUS_CLIENT *client; 55 | YBUS_PLUGIN *plugin; 56 | YBUS_CLIENT *active; 57 | int64_t alive; 58 | 59 | LKeyFile *app; 60 | 61 | unsigned int state:1; 62 | unsigned int lang:1; 63 | unsigned int corner:1; 64 | unsigned int focus:1; 65 | unsigned int biaodian:1; 66 | unsigned int trad:1; 67 | unsigned int onspot:2; 68 | }YBUS_CONNECT; 69 | 70 | enum{ 71 | YBUS_TOOL_NONE=0, 72 | YBUS_TOOL_SET_LANG, 73 | YBUS_TOOL_GET_LANG, 74 | YBUS_TOOL_SET_WM, 75 | YBUS_TOOL_TRIGGER, 76 | YBUS_TOOL_CONFIG, 77 | YBUS_TOOL_WM_FOCUS, 78 | YBUS_TOOL_RELOAD_ALL, 79 | YBUS_TOOL_KEYBOARD, 80 | YBUS_TOOL_EXIT, 81 | YBUS_TOOL_STATUS_POS, 82 | YBUS_TOOL_IMKEY, 83 | }; 84 | 85 | int ybus_init(void); 86 | void ybus_destroy(void); 87 | void ybus_add_plugin(YBUS_PLUGIN *plugin); 88 | int ybus_init_plugins(void); 89 | int64_t ybus_now(void); 90 | 91 | int ybus_on_key(YBUS_PLUGIN *plugin,CONN_ID conn_id,CLIENT_ID client_id,int key); 92 | int ybus_on_focus_in(YBUS_PLUGIN *plugin,CONN_ID conn_id,CLIENT_ID client_id); 93 | int ybus_on_focus_out(YBUS_PLUGIN *plugin,CONN_ID conn_id,CLIENT_ID client_id); 94 | int ybus_on_open(YBUS_PLUGIN *plugin,CONN_ID conn_id,CLIENT_ID client_id); 95 | int ybus_on_close(YBUS_PLUGIN *plugin,CONN_ID conn_id,CLIENT_ID client_id); 96 | int ybus_on_tool(YBUS_PLUGIN *plugin,CONN_ID conn_id,int type,int param); 97 | int ybus_on_cursor(YBUS_PLUGIN *plugin,CONN_ID conn_id,CLIENT_ID client_id,int x,int y,int rel); 98 | 99 | YBUS_CONNECT *ybus_find_connect(YBUS_PLUGIN *plugin,CONN_ID conn_id); 100 | YBUS_CONNECT *ybus_add_connect(YBUS_PLUGIN *plugin,CONN_ID conn_id); 101 | void ybus_free_connect(YBUS_CONNECT *conn); 102 | YBUS_CLIENT *ybus_find_client(YBUS_CONNECT *conn,CLIENT_ID client_id); 103 | YBUS_CLIENT *ybus_add_client(YBUS_CONNECT *conn,CLIENT_ID client_id,size_t child); 104 | void ybus_free_client(YBUS_CONNECT *conn,YBUS_CLIENT *client); 105 | int ybus_get_active(YBUS_CONNECT **conn,YBUS_CLIENT **client); 106 | void *ybus_get_priv(YBUS_PLUGIN *plugin,CONN_ID conn_id,CLIENT_ID client_id); 107 | 108 | int xim_ybus_init(void); 109 | void xim_ybus_destroy(void); 110 | void xim_ybus_enable(int enable); 111 | int xim_ybus_trigger_key(int key); 112 | CONNECT_ID *xim_ybus_get_connect(void); 113 | void xim_ybus_put_connect(CONNECT_ID *id); 114 | void xim_ybus_forward_key(int key,int repeat); 115 | void xim_ybus_send_string(const char *s,int flags); 116 | int xim_ybus_preedit_clear(void); 117 | int xim_ybus_preedit_draw(const char *s,int len); 118 | 119 | YBUS_CONNECT *ybus_wm_ready(void); 120 | void ybus_wm_icon(const char *icon1,const char *icon2); 121 | 122 | #endif/*_YBUS_H_*/ 123 | -------------------------------------------------------------------------------- /config/XPStyle.manifest: -------------------------------------------------------------------------------- 1 | 2 | 3 | 9 | yong-config 10 | 11 | 12 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | true 46 | PerMonitorV2 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /config/XPStyle64.manifest: -------------------------------------------------------------------------------- 1 | 2 | 3 | 9 | yong-config 10 | 11 | 12 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | true 46 | PerMonitorV2 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /config/aes.h: -------------------------------------------------------------------------------- 1 | #ifndef AES_H_ 2 | #define AES_H_ 3 | 4 | #include 5 | 6 | void aes_set_key(const uint8_t *cipher_key, int key_len); 7 | int aes_encrypt(const uint8_t *plain_text, uint8_t *cipher_text); //加密 8 | int aes_decrypt(const uint8_t *cipher_text, uint8_t *plain_text); //解密 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /config/build.txt: -------------------------------------------------------------------------------- 1 | var SRCS=['config_ui.c','config_main.c','translate.c', 2 | 'sync.c','aes.c','update.c']; 3 | var SRCS_WIN=['config_win.c','lpng.c','session_win.c']; 4 | var SRCS_LIN=['config_gtk.c','session_curl.c']; 5 | var DIRS=['l32-gtk3','l64-gtk3','l32-gtk4','l64-gtk4', 6 | 7 | ]; 8 | 9 | env("VPATH+=$(TOPDIR)/config"); 10 | env("CFLAGS+=$(LLIB_CFLAGS)"); 11 | env("LDFLAGS+=$(LLIB_LDFLAGS)"); 12 | env("LIBS+=$(LLIB_LDADD)"); 13 | 14 | function run(target){ 15 | cd(target); 16 | include("../../rules.txt"); 17 | if(target=="w32" || target=="w64"){ 18 | var srcs=SRCS.concat(SRCS_WIN); 19 | } else { 20 | var srcs=SRCS.concat(SRCS_LIN); 21 | var ARCH=target.split('-')[0]; 22 | var GTK=target.split('-')[1]; 23 | if(GTK=='gtk3') 24 | env("CFLAGS+=`pkg-config --cflags gtk+-3.0` -Wno-deprecated-declarations"); 25 | else 26 | env("CFLAGS+=`pkg-config --cflags gtk4` -Wno-deprecated-declarations"); 27 | if(ARCH=="l32") 28 | process.env.PKG_CONFIG_PATH="/usr/lib/pkgconfig"; 29 | else 30 | process.env.PKG_CONFIG_PATH="/usr/lib64/pkgconfig"; 31 | } 32 | var OBJS=wildcard(srcs,function(input){ 33 | return input.replace(/\.c$/,'.o'); 34 | }); 35 | begin(); 36 | cc(srcs,OBJS); 37 | if(target=="w32" || target=="w64"){ 38 | cr('yong-config.rc','yong-config.res','$(WINDRES) -i $^ -o $@ -O coff'); 39 | OBJS.push("yong-config.res"); 40 | env("LDFLAGS+=-mwindows"); 41 | env("LIBS+=-lgdi32 -lcomctl32 -lcomdlg32 -lws2_32 -lole32 -luuid -lwinhttp"); 42 | } else { 43 | env("LDFLAGS+=-Wl,-rpath,'$ORIGIN'"); 44 | if(GTK=="gtk3") 45 | env("LIBS+=`pkg-config --libs gtk+-3.0`"); 46 | else 47 | env("LIBS+=`pkg-config --libs gtk4`"); 48 | env("LIBS+=-lcurl -ldl"); 49 | } 50 | end(function(){ 51 | ld(OBJS,'$(DESTDIR)/yong-config$(EXE)'); 52 | }); 53 | } 54 | 55 | function xml_transform(buf){ 56 | var temp=buf.toString().replaceAll(/[\t\r\n]+/g, ''); 57 | return Buffer.from(temp); 58 | } 59 | 60 | if(target=="clean"){ 61 | rmdir(DIRS,'*'); 62 | } else if(!target || target=="all"){ 63 | build(undefined,undefined,DIRS); 64 | } else if(target=="xml") { 65 | bin2c("custom.xml","custom.c",{ 66 | static:true,zero:true,readonly:true,name:"config_custom",transform:xml_transform 67 | }); 68 | bin2c("sync.xml","custom_sync.c",{ 69 | static:true,zero:true,readonly:true,name:"config_sync",transform:xml_transform 70 | }); 71 | bin2c("update.xml","custom_update.c",{ 72 | static:true,zero:true,readonly:true,name:"config_update",transform:xml_transform 73 | }); 74 | } else if(target=="l32"){ 75 | build(undefined,undefined,["l32-gtk3","l32-gtk4"]); 76 | } else if(target=="l64"){ 77 | build(undefined,undefined,["l64-gtk3","l64-gtk4"]); 78 | } else if(target=="test"){ 79 | cp('l64-gtk3/yong-config','../install/yong/l64/yong-config-gtk3'); 80 | } else { 81 | run(target); 82 | } 83 | -------------------------------------------------------------------------------- /config/config_ui.h: -------------------------------------------------------------------------------- 1 | #ifndef _CONFIG_UI_H_ 2 | #define _CONFIG_UI_H_ 3 | 4 | #include "llib.h" 5 | 6 | extern LKeyFile *config; 7 | extern LXml *custom; 8 | 9 | enum{ 10 | CU_WINDOW=0, 11 | CU_LABEL, 12 | CU_EDIT, 13 | CU_LIST, 14 | CU_COMBO, 15 | CU_CHECK, 16 | CU_BUTTON, 17 | CU_TREE, 18 | CU_ITEM, 19 | CU_GROUP, 20 | CU_PAGE, 21 | CU_FONT, 22 | CU_IMAGE, 23 | CU_SEPARATOR, 24 | CU_LINK, 25 | }; 26 | 27 | typedef struct{ 28 | int x,y,w,h; 29 | }CURect; 30 | 31 | typedef struct _CUAction *CUAction; 32 | typedef struct _CUCtrl *CUCtrl; 33 | typedef struct _CUMenu *CUMenu; 34 | typedef struct _CUMenuEntry *CUMenuEntry; 35 | typedef struct _CULoopArg CULoopArg; 36 | 37 | struct _CUAction{ 38 | CUAction next; 39 | int (*action)(CUCtrl,int,char **); 40 | int arc; 41 | char **arg; 42 | }; 43 | 44 | struct _CUCtrl{ 45 | char *group; 46 | int type; 47 | void *self; 48 | CUCtrl parent; 49 | CUCtrl next; 50 | CUCtrl child; 51 | CUCtrl tlist; 52 | CURect pos; 53 | char *text; 54 | 55 | char *cgroup; 56 | char *ckey; 57 | int cpos; 58 | 59 | char **data; 60 | char **view; 61 | 62 | CUAction action; 63 | CUAction init; 64 | CUAction save; 65 | 66 | CUMenu menu; 67 | 68 | int init_done; 69 | int visible; 70 | 71 | const LXmlNode *node; 72 | int realized; 73 | void *priv; 74 | }; 75 | 76 | struct _CUMenuEntry{ 77 | char *text; 78 | void (*cb)(void *,void*); 79 | void *arg; 80 | LFreeFunc free; 81 | }; 82 | 83 | struct _CUMenu{ 84 | void *self; 85 | int count; 86 | int x,y; 87 | struct _CUMenuEntry entries[]; 88 | }; 89 | 90 | struct _CULoopArg{ 91 | LXml *custom; 92 | const char *app_id; 93 | CUCtrl win; 94 | void *priv; 95 | }; 96 | 97 | const char *y_im_get_path(const char *type); 98 | LKeyFile *y_im_load_config(char *fn); 99 | int y_im_set_default(int index); 100 | void cu_reload(); 101 | void cu_notify_reload(); 102 | 103 | int cfg_install(const char *name); 104 | int cfg_uninstall(const char *name); 105 | extern int cu_reload_ui; 106 | extern int cu_quit_ui; 107 | 108 | int cu_ctrl_init_self(CUCtrl p); 109 | int cu_ctrl_init_done(CUCtrl p); 110 | void cu_ctrl_destroy_self(CUCtrl p); 111 | int cu_ctrl_show_self(CUCtrl p,int b); 112 | int cu_ctrl_set_self(CUCtrl p,const char *s); 113 | int cu_ctrl_set_prop(CUCtrl p,const char *prop); 114 | char *cu_ctrl_get_self(CUCtrl p); 115 | 116 | void cu_config_save(void); 117 | int cu_config_init_default(CUCtrl p); 118 | int cu_config_save_default(CUCtrl p); 119 | int cu_config_set(const char *group,const char *key,int pos,const char *value); 120 | char *cu_config_get(const char *group,const char *key,int pos); 121 | 122 | CUCtrl cu_ctrl_new(CUCtrl parent,const LXmlNode *node); 123 | void cu_ctrl_free(CUCtrl p); 124 | CUCtrl cu_ctrl_list_from_type(int type); 125 | CUCtrl cu_ctrl_from_group(CUCtrl root,const char *group); 126 | CUCtrl cu_ctrl_get_root(CUCtrl p); 127 | void cu_ctrl_foreach(CUCtrl root,void (*cb)(CUCtrl,void*),void*user); 128 | 129 | int cu_ctrl_action_run(CUCtrl ctrl,CUAction action); 130 | void cu_ctrl_action_free(CUCtrl ctrl,CUAction action); 131 | 132 | int cu_confirm(CUCtrl p,const char *message); 133 | 134 | void cu_menu_popup(CUCtrl p,CUMenu m); 135 | void cu_menu_init_self(CUMenu m); 136 | void cu_menu_destroy_self(CUMenu m); 137 | CUMenu cu_menu_new(int count); 138 | void cu_menu_free(CUMenu m); 139 | int cu_menu_append(CUMenu m,char *text,void (*cb)(void*,void*),void *arg,LFreeFunc arg_free); 140 | CUMenu cu_menu_install(void); 141 | 142 | char *cu_translate(const char *s); 143 | 144 | int cu_init(void); 145 | int cu_loop(void (*activate)(CULoopArg *),CULoopArg*); 146 | int cu_quit(void); 147 | int cu_step(void); 148 | int cu_call(void (*cb)(void*),void *arg); 149 | 150 | void cu_show_page(const char *name); 151 | 152 | int cu_screen_dpi(void); 153 | 154 | void cu_init_all(CUCtrl ctrl,void *user); 155 | 156 | extern double CU_SCALE; 157 | 158 | #endif/*_CONFIG_UI_H_*/ 159 | -------------------------------------------------------------------------------- /config/custom_sync.c: -------------------------------------------------------------------------------- 1 | static const unsigned char config_sync[330]={ 2 | 0x3c,0x77,0x69,0x6e,0x64,0x6f,0x77,0x20,0x70,0x6f,0x73,0x3d,0x22,0x34,0x32,0x30, 3 | 0x2c,0x39,0x30,0x22,0x20,0x74,0x65,0x78,0x74,0x3d,0x22,0xe5,0x90,0x8c,0xe6,0xad, 4 | 0xa5,0x22,0x20,0x76,0x69,0x73,0x69,0x62,0x6c,0x65,0x3d,0x22,0x30,0x22,0x3e,0x3c, 5 | 0x62,0x75,0x74,0x74,0x6f,0x6e,0x20,0x70,0x6f,0x73,0x3d,0x22,0x31,0x30,0x2c,0x31, 6 | 0x30,0x2c,0x38,0x30,0x2c,0x33,0x30,0x22,0x20,0x74,0x65,0x78,0x74,0x3d,0x22,0xe4, 7 | 0xb8,0x8a,0xe4,0xbc,0xa0,0x22,0x20,0x61,0x63,0x74,0x69,0x6f,0x6e,0x3d,0x22,0x53, 8 | 0x79,0x6e,0x63,0x55,0x70,0x6c,0x6f,0x61,0x64,0x28,0x29,0x3b,0x22,0x2f,0x3e,0x3c, 9 | 0x62,0x75,0x74,0x74,0x6f,0x6e,0x20,0x70,0x6f,0x73,0x3d,0x22,0x31,0x30,0x30,0x2c, 10 | 0x31,0x30,0x2c,0x38,0x30,0x2c,0x33,0x30,0x22,0x20,0x74,0x65,0x78,0x74,0x3d,0x22, 11 | 0xe4,0xb8,0x8b,0xe8,0xbd,0xbd,0x22,0x20,0x61,0x63,0x74,0x69,0x6f,0x6e,0x3d,0x22, 12 | 0x53,0x79,0x6e,0x63,0x44,0x6f,0x77,0x6e,0x6c,0x6f,0x61,0x64,0x28,0x29,0x3b,0x22, 13 | 0x2f,0x3e,0x3c,0x6c,0x61,0x62,0x65,0x6c,0x20,0x70,0x6f,0x73,0x3d,0x22,0x32,0x30, 14 | 0x30,0x2c,0x31,0x30,0x2c,0x35,0x30,0x2c,0x33,0x30,0x22,0x20,0x74,0x65,0x78,0x74, 15 | 0x3d,0x22,0xe5,0xaf,0x86,0xe7,0xa0,0x81,0xef,0xbc,0x9a,0x22,0x3e,0x3c,0x2f,0x6c, 16 | 0x61,0x62,0x65,0x6c,0x3e,0x3c,0x65,0x64,0x69,0x74,0x20,0x69,0x64,0x3d,0x22,0x70, 17 | 0x61,0x73,0x73,0x77,0x64,0x22,0x20,0x70,0x6f,0x73,0x3d,0x22,0x32,0x35,0x30,0x2c, 18 | 0x31,0x30,0x2c,0x31,0x33,0x35,0x2c,0x33,0x30,0x22,0x3e,0x3c,0x2f,0x65,0x64,0x69, 19 | 0x74,0x3e,0x3c,0x6c,0x61,0x62,0x65,0x6c,0x20,0x69,0x64,0x3d,0x22,0x73,0x74,0x61, 20 | 0x74,0x75,0x73,0x22,0x20,0x70,0x6f,0x73,0x3d,0x22,0x31,0x30,0x2c,0x35,0x30,0x2c, 21 | 0x33,0x38,0x30,0x2c,0x34,0x30,0x22,0x3e,0x3c,0x2f,0x6c,0x61,0x62,0x65,0x6c,0x3e, 22 | 0x3c,0x2f,0x77,0x69,0x6e,0x64,0x6f,0x77,0x3e 23 | }; 24 | -------------------------------------------------------------------------------- /config/custom_update.c: -------------------------------------------------------------------------------- 1 | static const unsigned char config_update[178]={ 2 | 0x3c,0x77,0x69,0x6e,0x64,0x6f,0x77,0x20,0x70,0x6f,0x73,0x3d,0x22,0x34,0x32,0x30, 3 | 0x2c,0x39,0x30,0x22,0x20,0x74,0x65,0x78,0x74,0x3d,0x22,0xe6,0x9b,0xb4,0xe6,0x96, 4 | 0xb0,0x22,0x20,0x76,0x69,0x73,0x69,0x62,0x6c,0x65,0x3d,0x22,0x30,0x22,0x3e,0x3c, 5 | 0x62,0x75,0x74,0x74,0x6f,0x6e,0x20,0x70,0x6f,0x73,0x3d,0x22,0x31,0x30,0x2c,0x31, 6 | 0x30,0x2c,0x31,0x30,0x30,0x2c,0x33,0x30,0x22,0x20,0x74,0x65,0x78,0x74,0x3d,0x22, 7 | 0xe7,0xab,0x8b,0xe5,0x88,0xbb,0xe6,0x9b,0xb4,0xe6,0x96,0xb0,0x22,0x20,0x61,0x63, 8 | 0x74,0x69,0x6f,0x6e,0x3d,0x22,0x55,0x70,0x64,0x61,0x74,0x65,0x44,0x6f,0x77,0x6e, 9 | 0x6c,0x6f,0x61,0x64,0x28,0x29,0x3b,0x22,0x2f,0x3e,0x3c,0x6c,0x61,0x62,0x65,0x6c, 10 | 0x20,0x69,0x64,0x3d,0x22,0x73,0x74,0x61,0x74,0x75,0x73,0x22,0x20,0x70,0x6f,0x73, 11 | 0x3d,0x22,0x31,0x30,0x2c,0x35,0x30,0x2c,0x33,0x38,0x30,0x2c,0x34,0x30,0x22,0x3e, 12 | 0x3c,0x2f,0x6c,0x61,0x62,0x65,0x6c,0x3e,0x3c,0x2f,0x77,0x69,0x6e,0x64,0x6f,0x77, 13 | 0x3e 14 | }; 15 | -------------------------------------------------------------------------------- /config/gz.c: -------------------------------------------------------------------------------- 1 | //http://www.gzip.org/zlib/rfc-gzip.html 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include "ltricky.h" 8 | #include "lzlib.h" 9 | 10 | #define GZ_ID1 0x1F 11 | #define GZ_ID2 0x8B 12 | 13 | #define GZ_CM_DEFLATE 0x08 14 | 15 | #define FTEXT 0x01 16 | #define FHCRC 0x02 17 | #define FEXTRA 0x04 18 | #define FNAME 0x08 19 | #define FCOMMENT 0x10 20 | 21 | typedef struct{ 22 | uint8_t ID1; 23 | uint8_t ID2; 24 | uint8_t CM; 25 | uint8_t FLG; 26 | uint32_t MTIME; 27 | uint8_t XFL; 28 | uint8_t OS; 29 | }GZ_HDR; 30 | #define GZ_HDR_LEN 10 31 | 32 | void *gz_extract(const void *input,int len,int *olen) 33 | { 34 | const GZ_HDR *h; 35 | const uint8_t *p; 36 | if(lenID1!=GZ_ID1 || h->ID2!=GZ_ID2 || h->CM!=GZ_CM_DEFLATE) 42 | { 43 | return NULL; 44 | } 45 | p=(uint8_t*)h+GZ_HDR_LEN;len-=GZ_HDR_LEN; 46 | if((h->FLG&FEXTRA)!=0) 47 | { 48 | if(len<2) 49 | { 50 | return NULL; 51 | } 52 | int xlen=p[0]|(p[1]<<8); 53 | p+=2;len-=2; 54 | if(lenFLG&FNAME)!=0) 61 | { 62 | for(;len>0&&p[0];len--,p++); 63 | if(len==0) 64 | { 65 | return NULL; 66 | } 67 | len--;p++; 68 | } 69 | if((h->FLG&FCOMMENT)!=0) 70 | { 71 | for(;len>0&&p[0];len--,p++); 72 | if(len==0) 73 | { 74 | return NULL; 75 | } 76 | len--;p++; 77 | } 78 | if((h->FLG&FHCRC)!=0) 79 | { 80 | len-=2;p+=2; 81 | } 82 | if(len<8) 83 | { 84 | return NULL; 85 | } 86 | const void *zdata=p; 87 | int zlen=len-8; 88 | p+=zlen;len=zlen; 89 | // CRC32 90 | p+=4;len-=4; 91 | // ISIZE 92 | int isize=(int)(p[0]|(p[1]<<8)|(p[2]<<16)|(p[3]<<24)); 93 | uint8_t *res=malloc(isize+1); 94 | if(olen) *olen=isize; 95 | if(isize!=l_zlib_decode(res,isize,zdata,zlen,0)) 96 | { 97 | free(res); 98 | return NULL; 99 | } 100 | res[isize]=0; 101 | return res; 102 | } 103 | 104 | #if 0 105 | 106 | #include 107 | #include 108 | void *read_file(const char *path,int *len) 109 | { 110 | FILE *fp; 111 | struct stat st; 112 | uint8_t *res; 113 | fp=fopen(path,"rb"); 114 | if(!fp) return NULL; 115 | fstat(fileno(fp),&st); 116 | res=malloc(st.st_size); 117 | if(len) *len=(int)st.st_size; 118 | fread(res,1,st.st_size,fp); 119 | fclose(fp); 120 | return res; 121 | } 122 | 123 | void write_file(const char *path,const void *data,int len) 124 | { 125 | FILE *fp; 126 | fp=fopen(path,"wb"); 127 | if(!fp) return; 128 | fwrite(data,1,len,fp); 129 | fclose(fp); 130 | } 131 | 132 | int main(void) 133 | { 134 | void *data,*odata; 135 | int len,olen; 136 | data=read_file("test.gz",&len); 137 | if(!data) 138 | return -1; 139 | odata=gz_extract(data,len,&olen); 140 | free(data); 141 | if(!odata) 142 | { 143 | printf("gz_extract fail\n"); 144 | return -1; 145 | } 146 | write_file("test.zlib",odata,olen); 147 | free(odata); 148 | return 0; 149 | } 150 | #endif 151 | -------------------------------------------------------------------------------- /config/lpng.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | typedef struct{ 4 | uint32_t img_x; 5 | uint32_t img_y; 6 | uint8_t *out; 7 | }L_PNG; 8 | 9 | L_PNG *l_png_load(const char *file,va_list ap); 10 | void l_png_free(L_PNG *); 11 | -------------------------------------------------------------------------------- /config/session.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | struct _HttpSession; 4 | typedef struct _HttpSession HttpSession; 5 | 6 | enum{ 7 | HTTP_AUTH_NONE=0, 8 | HTTP_AUTH_BASIC, 9 | HTTP_AUTH_DIGEST, 10 | }; 11 | 12 | HttpSession *http_session_new(void); 13 | void http_session_free(HttpSession *ss); 14 | int http_session_clear(HttpSession *ss); 15 | int http_session_abort(HttpSession *ss); 16 | int http_session_set_abort(HttpSession *ss,int *abort); 17 | int http_session_is_abort(HttpSession *ss); 18 | int http_session_set_host(HttpSession *ss,const char *host,int port); 19 | const char *http_session_get_host(HttpSession *ss); 20 | int http_session_set_header(HttpSession *ss,const char *header); 21 | char *http_session_get(HttpSession *ss,const char *path,int *len,const char *post,int post_len); 22 | char *http_session_put(HttpSession *ss,const char *url,int *len,const char *data,int data_len); 23 | char *http_session_post_form(HttpSession *ss,const char *path,int *len,const char *name,const char *val,...); 24 | int http_session_download(HttpSession *ss,const char *remote,const char *local); 25 | int http_session_set_auth(HttpSession *ss,const char *user,const char *pass); 26 | int http_session_set_auth_type(HttpSession *ss,int type); 27 | int http_session_get_auth(HttpSession *ss,char **user,char **pass); 28 | int http_session_set_cookie(HttpSession *ss,const char *cookie); 29 | const char *http_session_get_cookie(HttpSession *ss); 30 | int http_session_set_proxy(HttpSession *ss,const char *proxy); 31 | 32 | int http_session_test(HttpSession *ss); 33 | int http_session_sockc_connect(HttpSession *ss,const char *host,int port); 34 | int http_session_sockc_send(HttpSession *ss,const void *buf,size_t size); 35 | int http_session_sockc_sendn(HttpSession *ss,const void *buf,size_t size); 36 | int http_session_sockc_recv(HttpSession *ss,void *buf,size_t size); 37 | int http_session_sockc_recvn(HttpSession *ss,void *buf,size_t size); 38 | void http_session_sockc_close(HttpSession *ss); 39 | 40 | void http_session_base64_encode(char *out, const void *in, int inlen); 41 | 42 | int encodeURIComponent(const char *in,char *out,int size); 43 | 44 | -------------------------------------------------------------------------------- /config/session_curl.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "llib.h" 4 | #include "session.h" 5 | 6 | struct _HttpSession{ 7 | int port; 8 | char host[68]; 9 | int timeout; 10 | volatile int abort; 11 | LString str; 12 | CURLM *curlm; 13 | }; 14 | 15 | HttpSession *http_session_new(void) 16 | { 17 | HttpSession *ss=l_new0(HttpSession); 18 | ss->timeout=30000; 19 | ss->curlm=curl_multi_init(); 20 | return ss; 21 | } 22 | 23 | void http_session_free(HttpSession *ss) 24 | { 25 | if(!ss) 26 | return; 27 | curl_multi_cleanup(ss->curlm); 28 | free(ss->str.str); 29 | l_free(ss); 30 | } 31 | 32 | int http_session_set_host(HttpSession *ss,const char *host,int port) 33 | { 34 | if(!ss) 35 | return -1; 36 | if(port<=0 || port>=65536) 37 | return -1; 38 | snprintf(ss->host,sizeof(ss->host),"%s",host); 39 | ss->port=port; 40 | return 0; 41 | } 42 | 43 | static size_t write_callback(char *ptr, size_t size, size_t nmemb, HttpSession *ss) 44 | { 45 | // printf("write %d\n",nmemb); 46 | #ifndef CURL_WRITEFUNC_ERROR 47 | if(ss->abort) 48 | return 0; 49 | #else 50 | if(ss->abort) 51 | return CURL_WRITEFUNC_ERROR; 52 | #endif 53 | l_string_append(&ss->str,ptr,nmemb); 54 | return nmemb; 55 | } 56 | 57 | char *http_session_get(HttpSession *ss,const char *path,int *len,const char *post,int post_len) 58 | { 59 | char url[256]; 60 | const char *proto=ss->port==443?"https":"http"; 61 | snprintf(url,sizeof(url),"%s://%s:%d%s",proto,ss->host,ss->port,path); 62 | CURL *curl=curl_easy_init(); 63 | curl_multi_add_handle(ss->curlm,curl); 64 | curl_easy_setopt(curl,CURLOPT_URL,url); 65 | if(post && post_len>0) 66 | { 67 | curl_easy_setopt(curl,CURLOPT_POSTFIELDS,post); 68 | curl_easy_setopt(curl,CURLOPT_POSTFIELDSIZE,post_len); 69 | } 70 | curl_easy_setopt(curl,CURLOPT_TIMEOUT_MS,ss->timeout); 71 | curl_easy_setopt(curl,CURLOPT_ACCEPTTIMEOUT_MS,1000); 72 | curl_easy_setopt(curl,CURLOPT_CONNECTTIMEOUT_MS,1000); 73 | l_string_init(&ss->str,16); 74 | if(!strcmp(proto,"https")) 75 | { 76 | curl_easy_setopt(curl,CURLOPT_SSL_VERIFYPEER,0); 77 | curl_easy_setopt(curl,CURLOPT_SSL_VERIFYHOST,0); 78 | } 79 | curl_easy_setopt(curl,CURLOPT_WRITEFUNCTION,(void*)write_callback); 80 | curl_easy_setopt(curl,CURLOPT_WRITEDATA,ss); 81 | struct curl_slist *header = NULL; 82 | header = curl_slist_append(header, "Cache-Control: no-cache"); 83 | header = curl_slist_append(header, "Content-Type: text/plain"); 84 | curl_easy_setopt(curl,CURLOPT_HTTPHEADER,header); 85 | CURLMcode mcode; 86 | int still_running; 87 | do{ 88 | mcode=curl_multi_perform(ss->curlm,&still_running); 89 | }while(mcode==CURLM_OK && still_running); 90 | curl_slist_free_all(header); 91 | curl_multi_remove_handle(ss->curlm,curl); 92 | curl_easy_cleanup(curl); 93 | if(mcode!=CURLM_OK || still_running || ss->abort) 94 | { 95 | l_string_clear(&ss->str); 96 | // printf("curl result code=%d still_running=%d abort=%d\n",mcode,still_running,ss->abort); 97 | // printf("\turl=%s\n",url); 98 | return NULL; 99 | } 100 | if(len) 101 | *len=ss->str.len; 102 | return l_string_steal(&ss->str); 103 | } 104 | 105 | int http_session_abort(HttpSession *ss) 106 | { 107 | if(!ss) 108 | return -1; 109 | ss->abort=1; 110 | #if LIBCURL_VERSION_NUM>0x074400 111 | curl_multi_wakeup(ss->curlm); 112 | #endif 113 | return 0; 114 | } 115 | 116 | -------------------------------------------------------------------------------- /config/sync.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | int SyncUpload(CUCtrl p,int arc,char **arg); 4 | int SyncDownload(CUCtrl p,int arc,char **arg); 5 | int SyncMain(int argc,char **argv); 6 | -------------------------------------------------------------------------------- /config/update.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | int UpdateDownload(CUCtrl p,int arc,char **arg); 4 | int UpdateMain(void); 5 | -------------------------------------------------------------------------------- /config/yong-config.rc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #ifdef _WIN64 4 | CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST "XPStyle64.manifest" 5 | #else 6 | CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST "XPStyle.manifest" 7 | #endif 8 | 9 | -------------------------------------------------------------------------------- /data/README.txt: -------------------------------------------------------------------------------- 1 | ========================================================================== 2 | 3 | 软件作者 dgod 4 | 对本软件的重新发布必须包含本声明 5 | 论坛 http://yong.dgod.net 6 | 软件希望能对用户有用,但软件及作者不对用户的任何使用后果负任何责任 7 | 8 | 帮助文件yong.chm 制作者是网友春意盎然,在此感谢 9 | 10 | 永码,拼音 作者就是本人 11 | 12 | 五笔 名称:五笔86极爽词库6.0标准版 13 | 作者:窝子(wozy.in@gmail.com) 14 | 15 | 张码 作者:张建平先生 16 | 网址:http://zmsrf.5d6d.com/ 17 | 有商业用途,请事先联系 18 | 19 | 其他码表 来自网络 20 | 21 | 22 | ========================================================================== 23 | -------------------------------------------------------------------------------- /data/bihua.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dgod/yong/22b4e983260b53cbcd6a6602d38d7c00081b87a5/data/bihua.bin -------------------------------------------------------------------------------- /data/entry/cloud.ini: -------------------------------------------------------------------------------- 1 | [cloud] 2 | name=云端 3 | engine=libcloud.so 4 | arg= -------------------------------------------------------------------------------- /data/entry/erbi.ini: -------------------------------------------------------------------------------- 1 | [erbi] 2 | name=二笔 3 | engine=libmb.so 4 | arg=mb/erbi.txt -------------------------------------------------------------------------------- /data/entry/gbk.ini: -------------------------------------------------------------------------------- 1 | [gbk] 2 | name=内码 3 | engine=libgbk.so -------------------------------------------------------------------------------- /data/entry/pinyin.ini: -------------------------------------------------------------------------------- 1 | [pinyin] 2 | name=拼音 3 | engine=libmb.so 4 | arg=mb/pinyin.txt 5 | overlay=mb/pinyin.ini -------------------------------------------------------------------------------- /data/entry/wbpy.ini: -------------------------------------------------------------------------------- 1 | [wbpy] 2 | name=笔拼 3 | engine=libmb.so 4 | arg=mb/wbx.txt 5 | overlay=mb/wbpy.ini 6 | -------------------------------------------------------------------------------- /data/entry/wubi.ini: -------------------------------------------------------------------------------- 1 | [wubi] 2 | name=五笔 3 | engine=libmb.so 4 | arg=mb/wbx.txt 5 | overlay=mb/wbx.ini -------------------------------------------------------------------------------- /data/entry/yong.ini: -------------------------------------------------------------------------------- 1 | [yong] 2 | name=永码 3 | engine=libmb.so 4 | arg=mb/yong.txt -------------------------------------------------------------------------------- /data/entry/zhangma.ini: -------------------------------------------------------------------------------- 1 | [zhangma] 2 | name=张码 3 | engine=libmb.so 4 | arg=mb/zhangma.txt 5 | -------------------------------------------------------------------------------- /data/entry/zhengma.ini: -------------------------------------------------------------------------------- 1 | [zhengma] 2 | name=郑码 3 | engine=libmb.so 4 | arg=mb/zhengma.txt -------------------------------------------------------------------------------- /data/mb/english.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dgod/yong/22b4e983260b53cbcd6a6602d38d7c00081b87a5/data/mb/english.txt -------------------------------------------------------------------------------- /data/mb/erbi.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dgod/yong/22b4e983260b53cbcd6a6602d38d7c00081b87a5/data/mb/erbi.txt -------------------------------------------------------------------------------- /data/mb/pinyin.ini: -------------------------------------------------------------------------------- 1 | [key] 2 | tEN=v 3 | bihua=u 4 | 5 | [pinyin] 6 | predict=mb/pypre.bin 7 | simple=1 8 | -------------------------------------------------------------------------------- /data/mb/pinyin.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dgod/yong/22b4e983260b53cbcd6a6602d38d7c00081b87a5/data/mb/pinyin.txt -------------------------------------------------------------------------------- /data/mb/pypre.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dgod/yong/22b4e983260b53cbcd6a6602d38d7c00081b87a5/data/mb/pypre.bin -------------------------------------------------------------------------------- /data/mb/sp.ini: -------------------------------------------------------------------------------- 1 | [pinyin] 2 | predict=mb/pypre.bin 3 | simple=1 4 | -------------------------------------------------------------------------------- /data/mb/wbpy.ini: -------------------------------------------------------------------------------- 1 | [table] 2 | adict=1 3 | wildcard=] 4 | -------------------------------------------------------------------------------- /data/mb/wbx.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dgod/yong/22b4e983260b53cbcd6a6602d38d7c00081b87a5/data/mb/wbx.txt -------------------------------------------------------------------------------- /data/mb/yong.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dgod/yong/22b4e983260b53cbcd6a6602d38d7c00081b87a5/data/mb/yong.txt -------------------------------------------------------------------------------- /data/mb/zhangma.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dgod/yong/22b4e983260b53cbcd6a6602d38d7c00081b87a5/data/mb/zhangma.txt -------------------------------------------------------------------------------- /data/mb/zhengma.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dgod/yong/22b4e983260b53cbcd6a6602d38d7c00081b87a5/data/mb/zhengma.txt -------------------------------------------------------------------------------- /data/normal.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dgod/yong/22b4e983260b53cbcd6a6602d38d7c00081b87a5/data/normal.txt -------------------------------------------------------------------------------- /data/yong.chm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dgod/yong/22b4e983260b53cbcd6a6602d38d7c00081b87a5/data/yong.chm -------------------------------------------------------------------------------- /gbk/build.txt: -------------------------------------------------------------------------------- 1 | var SRCS=dir('.','*.c'); 2 | var DIRS=['l32','l64', 3 | 4 | ]; 5 | 6 | env("VPATH+=$(TOPDIR)/gbk"); 7 | env("CFLAGS+=$(PICFLAGS) $(LLIB_CFLAGS)"); 8 | env("LDFLAGS+=-shared $(LLIB_LDFLAGS)"); 9 | env("LIBS+=$(LLIB_LDADD)"); 10 | 11 | // env("CFLAGS+=-fanalyzer"); 12 | 13 | function run(target){ 14 | if(target=="js") 15 | env("LIBS-=$(LLIB_LDADD)"); 16 | cd(target); 17 | include("../../rules.txt"); 18 | var OBJS=wildcard(SRCS,function(input){ 19 | return input.replace(/\.c$/,'.o'); 20 | }); 21 | cc(SRCS,OBJS); 22 | ld(OBJS,'$(DESTDIR)/libgbk.so'); 23 | } 24 | 25 | if(target=="clean"){ 26 | rmdir(DIRS,'*'); 27 | } else if(!target || target=="all"){ 28 | build(undefined,undefined,DIRS); 29 | } else { 30 | run(target); 31 | } 32 | -------------------------------------------------------------------------------- /gbk/gbk.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dgod/yong/22b4e983260b53cbcd6a6602d38d7c00081b87a5/gbk/gbk.c -------------------------------------------------------------------------------- /im/IMdkit/IMMethod.c: -------------------------------------------------------------------------------- 1 | /****************************************************************** 2 | 3 | Copyright 1994, 1995 by Sun Microsystems, Inc. 4 | Copyright 1993, 1994 by Hewlett-Packard Company 5 | 6 | Permission to use, copy, modify, distribute, and sell this software 7 | and its documentation for any purpose is hereby granted without fee, 8 | provided that the above copyright notice appear in all copies and 9 | that both that copyright notice and this permission notice appear 10 | in supporting documentation, and that the name of Sun Microsystems, Inc. 11 | and Hewlett-Packard not be used in advertising or publicity pertaining to 12 | distribution of the software without specific, written prior permission. 13 | Sun Microsystems, Inc. and Hewlett-Packard make no representations about 14 | the suitability of this software for any purpose. It is provided "as is" 15 | without express or implied warranty. 16 | 17 | SUN MICROSYSTEMS INC. AND HEWLETT-PACKARD COMPANY DISCLAIMS ALL 18 | WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL 20 | SUN MICROSYSTEMS, INC. AND HEWLETT-PACKARD COMPANY BE LIABLE FOR ANY 21 | SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER 22 | RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF 23 | CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR 24 | IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 25 | 26 | Author: Hidetoshi Tajima(tajima@Eng.Sun.COM) Sun Microsystems, Inc. 27 | 28 | This version tidied and debugged by Steve Underwood May 1999 29 | 30 | ******************************************************************/ 31 | 32 | #include 33 | #include "IMdkit.h" 34 | 35 | /* Public Function */ 36 | void IMForwardEvent (XIMS ims, XPointer call_data) 37 | { 38 | (ims->methods->forwardEvent) (ims, call_data); 39 | } 40 | 41 | void IMCommitString (XIMS ims, XPointer call_data) 42 | { 43 | (ims->methods->commitString) (ims, call_data); 44 | } 45 | 46 | int IMCallCallback (XIMS ims, XPointer call_data) 47 | { 48 | return (ims->methods->callCallback) (ims, call_data); 49 | } 50 | 51 | int IMPreeditStart (XIMS ims, XPointer call_data) 52 | { 53 | return (ims->methods->preeditStart) (ims, call_data); 54 | } 55 | 56 | int IMPreeditEnd (XIMS ims, XPointer call_data) 57 | { 58 | return (ims->methods->preeditEnd) (ims, call_data); 59 | } 60 | 61 | int IMSyncXlib(XIMS ims, XPointer call_data) 62 | { 63 | ims->sync = True; 64 | return (ims->methods->syncXlib) (ims, call_data); 65 | } 66 | -------------------------------------------------------------------------------- /im/IMdkit/IMValues.c: -------------------------------------------------------------------------------- 1 | /****************************************************************** 2 | 3 | Copyright 1994, 1995 by Sun Microsystems, Inc. 4 | Copyright 1993, 1994 by Hewlett-Packard Company 5 | 6 | Permission to use, copy, modify, distribute, and sell this software 7 | and its documentation for any purpose is hereby granted without fee, 8 | provided that the above copyright notice appear in all copies and 9 | that both that copyright notice and this permission notice appear 10 | in supporting documentation, and that the name of Sun Microsystems, Inc. 11 | and Hewlett-Packard not be used in advertising or publicity pertaining to 12 | distribution of the software without specific, written prior permission. 13 | Sun Microsystems, Inc. and Hewlett-Packard make no representations about 14 | the suitability of this software for any purpose. It is provided "as is" 15 | without express or implied warranty. 16 | 17 | SUN MICROSYSTEMS INC. AND HEWLETT-PACKARD COMPANY DISCLAIMS ALL 18 | WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL 20 | SUN MICROSYSTEMS, INC. AND HEWLETT-PACKARD COMPANY BE LIABLE FOR ANY 21 | SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER 22 | RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF 23 | CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR 24 | IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 25 | 26 | Author: Hidetoshi Tajima(tajima@Eng.Sun.COM) Sun Microsystems, Inc. 27 | 28 | This version tidied and debugged by Steve Underwood May 1999 29 | 30 | ******************************************************************/ 31 | 32 | #include 33 | #include 34 | #include "IMdkit.h" 35 | #include 36 | 37 | #define Va_start(a,b) va_start(a,b) 38 | 39 | static void _IMCountVaList (va_list var, int *total_count) 40 | { 41 | char *attr; 42 | 43 | *total_count = 0; 44 | 45 | for (attr = va_arg (var, char *); attr; attr = va_arg (var, char *)) 46 | { 47 | (void)va_arg (var, XIMArg *); 48 | ++(*total_count); 49 | } 50 | /*endfor*/ 51 | } 52 | 53 | static void _IMVaToNestedList (va_list var, int max_count, XIMArg **args_return) 54 | { 55 | XIMArg *args; 56 | char *attr; 57 | 58 | if (max_count <= 0) 59 | { 60 | *args_return = (XIMArg *) NULL; 61 | return; 62 | } 63 | /*endif*/ 64 | 65 | args = (XIMArg *) malloc ((unsigned) (max_count + 1)*sizeof (XIMArg)); 66 | *args_return = args; 67 | if (!args) 68 | return; 69 | /*endif*/ 70 | for (attr = va_arg (var, char *); attr; attr = va_arg (var, char *)) 71 | { 72 | args->name = attr; 73 | args->value = va_arg (var, XPointer); 74 | args++; 75 | } 76 | /*endfor*/ 77 | args->name = (char *) NULL; 78 | } 79 | 80 | char *IMGetIMValues (XIMS ims, ...) 81 | { 82 | va_list var; 83 | int total_count; 84 | XIMArg *args; 85 | char *ret; 86 | 87 | Va_start (var, ims); 88 | _IMCountVaList (var, &total_count); 89 | va_end (var); 90 | 91 | Va_start (var, ims); 92 | _IMVaToNestedList (var, total_count, &args); 93 | va_end (var); 94 | 95 | ret = (*ims->methods->getIMValues) (ims, args); 96 | 97 | if (args) 98 | XFree ((char *) args); 99 | /*endif*/ 100 | return ret; 101 | } 102 | 103 | char *IMSetIMValues (XIMS ims, ...) 104 | { 105 | va_list var; 106 | int total_count; 107 | XIMArg *args; 108 | char *ret; 109 | 110 | Va_start (var, ims); 111 | _IMCountVaList (var, &total_count); 112 | va_end (var); 113 | 114 | Va_start (var, ims); 115 | _IMVaToNestedList (var, total_count, &args); 116 | va_end (var); 117 | 118 | ret = (*ims->methods->setIMValues) (ims, args); 119 | 120 | if (args) 121 | XFree ((char *) args); 122 | /*endif*/ 123 | return ret; 124 | } 125 | -------------------------------------------------------------------------------- /im/IMdkit/Xi18nTr.h: -------------------------------------------------------------------------------- 1 | /****************************************************************** 2 | 3 | Copyright 1994, 1995 by Sun Microsystems, Inc. 4 | Copyright 1993, 1994 by Hewlett-Packard Company 5 | 6 | Permission to use, copy, modify, distribute, and sell this software 7 | and its documentation for any purpose is hereby granted without fee, 8 | provided that the above copyright notice appear in all copies and 9 | that both that copyright notice and this permission notice appear 10 | in supporting documentation, and that the name of Sun Microsystems, Inc. 11 | and Hewlett-Packard not be used in advertising or publicity pertaining to 12 | distribution of the software without specific, written prior permission. 13 | Sun Microsystems, Inc. and Hewlett-Packard make no representations about 14 | the suitability of this software for any purpose. It is provided "as is" 15 | without express or implied warranty. 16 | 17 | SUN MICROSYSTEMS INC. AND HEWLETT-PACKARD COMPANY DISCLAIMS ALL 18 | WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL 20 | SUN MICROSYSTEMS, INC. AND HEWLETT-PACKARD COMPANY BE LIABLE FOR ANY 21 | SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER 22 | RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF 23 | CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR 24 | IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 25 | 26 | Author: Hidetoshi Tajima(tajima@Eng.Sun.COM) Sun Microsystems, Inc. 27 | 28 | This version tidied and debugged by Steve Underwood May 1999 29 | 30 | ******************************************************************/ 31 | 32 | #ifndef _Xi18nTrTrans_h 33 | #define _Xi18nTrTrans_h 34 | 35 | typedef struct _TransClient 36 | { 37 | int accept_fd; 38 | struct _XtransConnInfo *accept_conn; 39 | } TransClient; 40 | 41 | typedef struct 42 | { 43 | struct _XtransConnInfo *trans_conn; /* transport connection object */ 44 | char *port; 45 | } TransSpecRec; 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /im/IMdkit/Xi18nX.h: -------------------------------------------------------------------------------- 1 | /****************************************************************** 2 | 3 | Copyright 1994, 1995 by Sun Microsystems, Inc. 4 | Copyright 1993, 1994 by Hewlett-Packard Company 5 | 6 | Permission to use, copy, modify, distribute, and sell this software 7 | and its documentation for any purpose is hereby granted without fee, 8 | provided that the above copyright notice appear in all copies and 9 | that both that copyright notice and this permission notice appear 10 | in supporting documentation, and that the name of Sun Microsystems, Inc. 11 | and Hewlett-Packard not be used in advertising or publicity pertaining to 12 | distribution of the software without specific, written prior permission. 13 | Sun Microsystems, Inc. and Hewlett-Packard make no representations about 14 | the suitability of this software for any purpose. It is provided "as is" 15 | without express or implied warranty. 16 | 17 | SUN MICROSYSTEMS INC. AND HEWLETT-PACKARD COMPANY DISCLAIMS ALL 18 | WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL 20 | SUN MICROSYSTEMS, INC. AND HEWLETT-PACKARD COMPANY BE LIABLE FOR ANY 21 | SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER 22 | RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF 23 | CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR 24 | IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 25 | 26 | Author: Hidetoshi Tajima(tajima@Eng.Sun.COM) Sun Microsystems, Inc. 27 | 28 | This version tidied and debugged by Steve Underwood May 1999 29 | 30 | ******************************************************************/ 31 | 32 | #ifndef _Xi18nTrX_h 33 | #define _Xi18nTrX_h 34 | 35 | #define _XIM_PROTOCOL "_XIM_PROTOCOL" 36 | #define _XIM_XCONNECT "_XIM_XCONNECT" 37 | 38 | #define XCM_DATA_LIMIT 20 39 | 40 | typedef struct _XClient 41 | { 42 | Window client_win; /* client window */ 43 | Window accept_win; /* accept window */ 44 | } XClient; 45 | 46 | typedef struct 47 | { 48 | Atom xim_request; 49 | Atom connect_request; 50 | } XSpecRec; 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /im/IMdkit/XimFunc.h: -------------------------------------------------------------------------------- 1 | /****************************************************************** 2 | 3 | Copyright 1994, 1995 by Sun Microsystems, Inc. 4 | Copyright 1993, 1994 by Hewlett-Packard Company 5 | 6 | Permission to use, copy, modify, distribute, and sell this software 7 | and its documentation for any purpose is hereby granted without fee, 8 | provided that the above copyright notice appear in all copies and 9 | that both that copyright notice and this permission notice appear 10 | in supporting documentation, and that the name of Sun Microsystems, Inc. 11 | and Hewlett-Packard not be used in advertising or publicity pertaining to 12 | distribution of the software without specific, written prior permission. 13 | Sun Microsystems, Inc. and Hewlett-Packard make no representations about 14 | the suitability of this software for any purpose. It is provided "as is" 15 | without express or implied warranty. 16 | 17 | SUN MICROSYSTEMS INC. AND HEWLETT-PACKARD COMPANY DISCLAIMS ALL 18 | WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL 20 | SUN MICROSYSTEMS, INC. AND HEWLETT-PACKARD COMPANY BE LIABLE FOR ANY 21 | SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER 22 | RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF 23 | CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR 24 | IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 25 | 26 | Author: Hidetoshi Tajima(tajima@Eng.Sun.COM) Sun Microsystems, Inc. 27 | 28 | This version tidied and debugged by Steve Underwood May 1999 29 | 30 | ******************************************************************/ 31 | 32 | #ifndef _XimFunc_h 33 | #define _XimFunc_h 34 | 35 | /* i18nAttr.c */ 36 | void _Xi18nInitAttrList (Xi18n i18n_core); 37 | void _Xi18nInitExtension(Xi18n i18n_core); 38 | 39 | /* i18nClbk.c */ 40 | int _Xi18nGeometryCallback (XIMS ims, IMProtocol *call_data); 41 | int _Xi18nPreeditStartCallback (XIMS ims, IMProtocol *call_data); 42 | int _Xi18nPreeditDrawCallback (XIMS ims, IMProtocol *call_data); 43 | int _Xi18nPreeditCaretCallback (XIMS ims, IMProtocol *call_data); 44 | int _Xi18nPreeditDoneCallback (XIMS ims, IMProtocol *call_data); 45 | int _Xi18nStatusStartCallback (XIMS ims, IMProtocol *call_data); 46 | int _Xi18nStatusDrawCallback (XIMS ims, IMProtocol *call_data); 47 | int _Xi18nStatusDoneCallback (XIMS ims, IMProtocol *call_data); 48 | int _Xi18nStringConversionCallback (XIMS ims, IMProtocol *call_data); 49 | 50 | /* i18nIc.c */ 51 | void _Xi18nChangeIC (XIMS ims, IMProtocol *call_data, unsigned char *p, 52 | int create_flag); 53 | void _Xi18nGetIC (XIMS ims, IMProtocol *call_data, unsigned char *p); 54 | 55 | /* i18nUtil.c */ 56 | int _Xi18nNeedSwap (Xi18n i18n_core, CARD16 connect_id); 57 | Xi18nClient *_Xi18nNewClient(Xi18n i18n_core); 58 | Xi18nClient *_Xi18nFindClient (Xi18n i18n_core, CARD16 connect_id); 59 | void _Xi18nDeleteClient (Xi18n i18n_core, CARD16 connect_id); 60 | void _Xi18nSendMessage (XIMS ims, CARD16 connect_id, CARD8 major_opcode, 61 | CARD8 minor_opcode, unsigned char *data, long length); 62 | void _Xi18nSendTriggerKey (XIMS ims, CARD16 connect_id); 63 | void _Xi18nSetEventMask (XIMS ims, CARD16 connect_id, CARD16 im_id, 64 | CARD16 ic_id, CARD32 forward_mask, CARD32 sync_mask); 65 | 66 | /* Xlib internal */ 67 | void _XRegisterFilterByType(Display*, Window, int, int, 68 | Bool (*filter)(Display*, Window, XEvent*, XPointer), XPointer); 69 | void _XUnregisterFilter(Display*, Window, 70 | Bool (*filter)(Display*, Window, XEvent*, XPointer), XPointer); 71 | 72 | #endif 73 | -------------------------------------------------------------------------------- /im/IMdkit/build.txt: -------------------------------------------------------------------------------- 1 | var SRCS = ['FrameMgr.c', 'i18nAttr.c', 'i18nClbk.c', 'i18nIc.c', 2 | 'i18nIMProto.c', 'i18nMethod.c', 'i18nPtHdr.c', 'i18nUtil.c', 'i18nX.c', 3 | 'IMConn.c', 'IMMethod.c', 'IMValues.c', 'i18nOffsetCache.c']; 4 | 5 | var OBJS=wildcard(SRCS,function(input){ 6 | return input.replace(/\.c$/,'.o'); 7 | }); 8 | 9 | var DIRS=['l32','l64']; 10 | 11 | env("VPATH+=$(TOPDIR)/im/IMdkit"); 12 | env("CFLAGS+=$(LLIB_CFLAGS)"); 13 | 14 | if("X11_CFLAGS" in process.env) 15 | env("CFLAGS","+=",process.env.X11_CFLAGS); 16 | 17 | if("X11_LDFLAGS" in process.env) 18 | env("LDFLAGS","+=",process.env.X11_LDFLAGS); 19 | 20 | function run(target){ 21 | cd(target); 22 | include("../../../rules.txt"); 23 | begin(); 24 | cc(SRCS,OBJS); 25 | end(function(){ 26 | cr(OBJS,'libXimd.a',"$(AR) $@ $^"); 27 | }); 28 | } 29 | 30 | if(target=="clean"){ 31 | rmdir(DIRS,'*'); 32 | }else if(!target || target=="all"){ 33 | build(undefined,undefined,DIRS); 34 | }else{ 35 | run(target); 36 | } 37 | -------------------------------------------------------------------------------- /im/IMdkit/i18nOffsetCache.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Peng Huang 3 | * Copyright (C) 2014 Red Hat, Inc. 4 | * 5 | * Permission to use, copy, modify, distribute, and sell this 6 | * software and its documentation for any purpose is hereby granted 7 | * without fee, provided that the above copyright notice appear in 8 | * all copies and that both that copyright notice and this permission 9 | * notice appear in supporting documentation, and that the name of 10 | * the copyright holders not be used in advertising or publicity 11 | * pertaining to distribution of the software without specific, 12 | * written prior permission. The copyright holders make no 13 | * representations about the suitability of this software for any 14 | * purpose. It is provided "as is" without express or implied 15 | * warranty. 16 | * 17 | * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS 18 | * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND 19 | * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY 20 | * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 21 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN 22 | * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, 23 | * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF 24 | * THIS SOFTWARE. 25 | * 26 | * Author: Klemens Baum 27 | */ 28 | 29 | #include 30 | #include 31 | #include "IMdkit.h" 32 | #include "Xi18n.h" 33 | 34 | #include "ltricky.h" 35 | 36 | /* 37 | * The XIM specification does not limit the number of window properties 38 | * that can be used to transfer data, but Xlib uses the atom strings 39 | * _client0 through _client20. 40 | * 41 | * So use that as a sensible initial size for the offset cache. 42 | */ 43 | #define INITIAL_OFFSET_CACHE_CAPACITY 21 44 | #define OFFSET_CACHE_GROWTH_FACTOR 2 45 | 46 | void _Xi18nInitOffsetCache (Xi18nOffsetCache *offset_cache) 47 | { 48 | offset_cache->size = 0; 49 | offset_cache->capacity = INITIAL_OFFSET_CACHE_CAPACITY; 50 | offset_cache->data = (Xi18nAtomOffsetPair *) malloc ( 51 | INITIAL_OFFSET_CACHE_CAPACITY * sizeof (Xi18nAtomOffsetPair)); 52 | } 53 | 54 | unsigned long _Xi18nLookupPropertyOffset (Xi18nOffsetCache *offset_cache, 55 | Atom key) 56 | { 57 | Xi18nAtomOffsetPair *data = offset_cache->data; 58 | size_t i; 59 | 60 | for (i = 0; i < offset_cache->size; ++i) { 61 | if (data[i].key == key) { 62 | return data[i].offset; 63 | } 64 | } 65 | 66 | return 0; 67 | } 68 | 69 | void _Xi18nSetPropertyOffset (Xi18nOffsetCache *offset_cache, Atom key, 70 | unsigned long offset) 71 | { 72 | Xi18nAtomOffsetPair *data = offset_cache->data; 73 | size_t i; 74 | 75 | for (i = 0; i < offset_cache->size; ++i) { 76 | if (data[i].key == key) { 77 | data[i].offset = offset; 78 | return; 79 | } 80 | } 81 | 82 | if (++offset_cache->size > offset_cache->capacity) { 83 | offset_cache->capacity *= OFFSET_CACHE_GROWTH_FACTOR; 84 | offset_cache->data = data = (Xi18nAtomOffsetPair *) realloc (data, 85 | offset_cache->capacity * sizeof (Xi18nAtomOffsetPair)); 86 | } 87 | 88 | data[i].key = key; 89 | data[i].offset = offset; 90 | } 91 | 92 | -------------------------------------------------------------------------------- /im/build.txt: -------------------------------------------------------------------------------- 1 | var SRCS=['main.c','im.c','bihua.c','common.c','s2t.c','nl.c', 2 | 'english.c','dict.c','keyboard.c','mapfile.c', 3 | 'aes.c','book.c','keytool.c', 4 | 'keydesc.c','ui.c','fbterm.c','keycode.c','select.c','layout.c','translate.c', 5 | 'ybus.c','ybus-xim.c','ybus-lcall.c','lcall.c','ybus-ibus.c', 6 | 'menu.c','history.c','replace.c','ybus-wayland.c', 7 | 'app.c','async.c','ui-draw.c','speed.c']; 8 | 9 | var DIRS=['l32-gtk3','l64-gtk3']; 10 | 11 | feature(['x11','ibus']); 12 | 13 | env("VPATH+=$(TOPDIR)/im"); 14 | env("VPATH+=$(TOPDIR)/im/fbterm"); 15 | env("VPATH+=$(TOPDIR)/im/wayland"); 16 | 17 | env("CFLAGS+=$(LLIB_CFLAGS)"); 18 | env("LDFLAGS+=$(LLIB_LDFLAGS)"); 19 | env("LIBS+=$(LLIB_LDADD)"); 20 | 21 | env("CFLAGS+=-I$(TOPDIR)/im"); 22 | env("CFLAGS+=-DCFG_XIM_YBUS"); 23 | env("CFLAGS+=-DCFG_XIM_IBUS `pkg-config --cflags ibus-1.0`"); 24 | env("CFLAGS+=-DCFG_XIM_FBTERM -I$(TOPDIR)/im/fbterm"); 25 | env("CFLAGS+=-DL_CALL_GLIB_SERVER -DL_CALL_GLIB_CLIENT"); 26 | env("CFLAGS+=-Wno-deprecated-declarations"); 27 | if(support("x11")) 28 | env("CFLAGS+=-I$(TOPDIR)/im/IMdkit"); 29 | 30 | env("LDFLAGS+=-Wl,-rpath,'$ORIGIN'"); 31 | env("LIBS+=-ll -ldl -lm -lxkbcommon"); 32 | 33 | function run(target){ 34 | cd(target); 35 | include("../../rules.txt"); 36 | var ARCH=target.split('-')[0]; 37 | var GTK=target.split('-')[1]; 38 | if("GTK_CFLAGS" in process.env) 39 | env("CFLAGS","+=",process.env.GTK_CFLAGS); 40 | else if(GTK=="gtk4") 41 | env("CFLAGS+=`pkg-config --cflags gtk+-4.0` -Wno-unused-const-variable"); 42 | else 43 | env("CFLAGS+=`pkg-config --cflags gtk+-3.0` -Wno-unused-const-variable"); 44 | var OBJS=wildcard(SRCS,function(input){ 45 | return input.replace(/\.c$/,'.o'); 46 | }); 47 | begin(); 48 | cc(SRCS,OBJS); 49 | end(function(){ 50 | env("LDFLAGS+=-L$(TOPDIR)/im/IMdkit/$(BUILD)"); 51 | if("GTK_LDFLAGS" in process.env) 52 | env("LDFLAGS","+=",process.env.GTK_LDFLAGS); 53 | if(support('x11')) 54 | env('LIBS+=-lX11 -lXimd'); 55 | if(GTK=="gtk4") 56 | env("LIBS+=`pkg-config --libs gtk+-4.0`"); 57 | else 58 | env("LIBS+=`pkg-config --libs gtk+-3.0`"); 59 | ld(OBJS,'$(DESTDIR)/yong'); 60 | }); 61 | } 62 | 63 | function bihua(){ 64 | var SRCS=['bihua.c','mapfile.c']; 65 | env("BUILD?=l64"); 66 | include("../rules.txt"); 67 | env("CFLAGS=-I$(TOPDIR)/include $(LLIB_CFLAGS) -Wall -DTOOLS_BIHUA"); 68 | cr(SRCS,'bihua','$(CC) $(CFLAGS) $(LDFLAGS) $^ -o $@'); 69 | } 70 | 71 | if(target=="clean"){ 72 | rmdir(DIRS,'*'); 73 | build(["IMdkit","gtk-im","qt5-im"],undefined,'clean'); 74 | } else if(!target || target=="all"){ 75 | build(["IMdkit","gtk-im","qt5-im"]); 76 | build(undefined,undefined,DIRS); 77 | } else if(target=="bihua") { 78 | bihua(); 79 | } else if(target=="l32") { 80 | if(support('x11')) 81 | build("IMdkit",undefined,"l32"); 82 | build("gtk-im",undefined,['l32-gtk2','l32-gtk3']); 83 | build("gtk4-im",undefined,['l32-gtk4']); 84 | build("qt5-im",undefined,['l32-qt5','l32-qt6']); 85 | build(undefined,undefined,['l32-gtk3']); 86 | } else if(target=="l64") { 87 | if(support('x11')) 88 | build("IMdkit",undefined,"l64"); 89 | build("gtk-im",undefined,['l64-gtk2','l64-gtk3']); 90 | build("gtk4-im",undefined,['l64-gtk4']); 91 | build("qt5-im",undefined,['l64-qt5','l64-qt6']); 92 | build(undefined,undefined,['l64-gtk3']); 93 | } else if(target=="test"){ 94 | exec("install l64-gtk3/yong ../install/yong/l64/yong-gtk3"); 95 | } else if(target=='xml'){ 96 | bin2c("../data/keyboard.xml","../common/keyboard.xml.c",{ 97 | static:true, 98 | zero:true, 99 | readonly:true, 100 | name:"keyboard_xml", 101 | transform(buf){ 102 | var temp=buf.toString().replaceAll(/[\t\r\n]+/g, ''); 103 | return Buffer.from(temp); 104 | } 105 | }); 106 | } else { 107 | run(target); 108 | } 109 | 110 | -------------------------------------------------------------------------------- /im/fbterm.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dgod/yong/22b4e983260b53cbcd6a6602d38d7c00081b87a5/im/fbterm.c -------------------------------------------------------------------------------- /im/fbterm.h: -------------------------------------------------------------------------------- 1 | #ifndef _FBTERM_H_ 2 | #define _FBTERM_H_ 3 | 4 | int xim_fbterm_init(void); 5 | void xim_fbterm_destroy(void); 6 | void xim_fbterm_enable(int enable); 7 | void xim_fbterm_forward_key(int key,int repeat); 8 | int xim_fbterm_last_key(void); 9 | int xim_fbterm_trigger_key(int key); 10 | void xim_fbterm_send_string(const char *s); 11 | int xim_fbterm_preedit_clear(void); 12 | int xim_fbterm_preedit_draw(const char *s,int len); 13 | CONNECT_ID *xim_fbterm_get_connect(void); 14 | 15 | #endif/*_FBTERM_H_*/ 16 | -------------------------------------------------------------------------------- /im/fbterm/keycode.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2008-2009 dragchan 3 | * This file is part of FbTerm. 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License 7 | * as published by the Free Software Foundation; either version 2 8 | * of the License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 18 | * 19 | */ 20 | 21 | #ifndef KEYCODE_H 22 | #define KEYCODE_H 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | void init_keycode_state(); 29 | 30 | void update_term_mode(char crlf, char appkey, char curo); 31 | 32 | unsigned short keycode_to_keysym(unsigned short keycode, char down); 33 | 34 | unsigned short keypad_keysym_redirect(unsigned short keysym); 35 | 36 | char *keysym_to_term_string(unsigned short keysym, char down); 37 | 38 | #ifdef __cplusplus 39 | } 40 | #endif 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /im/gtk-im/build.txt: -------------------------------------------------------------------------------- 1 | var SRCS=['lcall.c','imyong.c','gtkimcontextyong.c']; 2 | var DIRS=['l32-gtk2','l32-gtk3','l64-gtk2','l64-gtk3']; 3 | 4 | env("VPATH+=$(TOPDIR)/im/gtk-im $(TOPDIR)/im"); 5 | env("CFLAGS+=$(PICFLAGS) $(LLIB_CFLAGS)"); 6 | env("CFLAGS+=-DL_CALL_GLIB_CLIENT -fvisibility=hidden -I$(TOPDIR)/im"); 7 | env("LDFLAGS+=-shared"); 8 | 9 | function run(target){ 10 | cd(target); 11 | include("../../../rules.txt"); 12 | var ARCH=target.split('-')[0]; 13 | var GTK=target.split('-')[1]; 14 | if("GTK_CFLAGS" in process.env) 15 | env("CFLAGS","+=",process.env.GTK_CFLAGS); 16 | else if(GTK=="gtk2") 17 | env("CFLAGS+=`pkg-config --cflags gtk+-2.0`"); 18 | else if(GTK=="gtk3") 19 | env("CFLAGS+=`pkg-config --cflags gtk+-3.0`"); 20 | env("CFLAGS+=-Wno-deprecated-declarations"); 21 | var OBJS=wildcard(SRCS,function(input){ 22 | return input.replace(/\.c$/,'.o'); 23 | }); 24 | begin(); 25 | cc(SRCS,OBJS); 26 | end(function(){ 27 | if("GTK_LDFLAGS" in process.env) 28 | env("LDFLAGS","+=",process.env.GTK_LDFLAGS); 29 | if(GTK=="gtk2") 30 | env("LIBS+=-lglib-2.0 -lgobject-2.0 -lcairo -lX11 -lpango-1.0 -lpangocairo-1.0 -lgdk_pixbuf-2.0 -lgdk-x11-2.0 -lgtk-x11-2.0"); 31 | else if(GTK=="gtk3") 32 | env("LIBS+=-lX11 `pkg-config --libs gtk+-3.0`"); 33 | ld(OBJS,'$(DESTDIR)/im-yong.so'); 34 | }); 35 | } 36 | 37 | if(target=="clean"){ 38 | rmdir(DIRS,'*'); 39 | } else if(!target || target=="all"){ 40 | build(undefined,undefined,DIRS); 41 | } else { 42 | run(target); 43 | } 44 | -------------------------------------------------------------------------------- /im/gtk-im/gtkimcontextyong.h: -------------------------------------------------------------------------------- 1 | #ifndef _GTKIMCONTEXTYONG_H_ 2 | #define _GTKIMCONTEXTYONG_H_ 3 | 4 | #include 5 | 6 | extern GType gtk_type_im_context_yong; 7 | 8 | #define GTK_TYPE_IM_CONTEXT_YONG gtk_type_im_context_yong 9 | #define GTK_IM_CONTEXT_YONG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_IM_CONTEXT_YONG, GtkIMContextYong)) 10 | #define GTK_IM_CONTEXT_YONG_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), GTK_TYPE_IM_CONTEXT_YONG, GtkIMContextYongClass)) 11 | #define GTK_IS_IM_CONTEXT_YONG(obj) (GTK_CHECK_TYPE ((obj), GTK_TYPE_IM_CONTEXT_YONG)) 12 | #define GTK_IS_IM_CONTEXT_YONG_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), GTK_TYPE_IM_CONTEXT_YONG)) 13 | #define GTK_IM_CONTEXT_YONG_GET_CLASS(obj) (GTK_CHECK_GET_CLASS ((obj), GTK_TYPE_IM_CONTEXT_YONG, GtkIMContextYongClass)) 14 | 15 | 16 | typedef struct _GtkIMContextYong GtkIMContextYong; 17 | typedef struct _GtkIMContextYongClass GtkIMContextYongClass; 18 | 19 | struct _GtkIMContextYongClass 20 | { 21 | GtkIMContextClass parent_class; 22 | }; 23 | 24 | void gtk_im_context_yong_register_type (GTypeModule *type_module); 25 | GtkIMContext *gtk_im_context_yong_new (void); 26 | 27 | void gtk_im_context_yong_shutdown (void); 28 | 29 | #endif/*_GTKIMCONTEXTYONG_H_*/ 30 | -------------------------------------------------------------------------------- /im/gtk-im/imyong.c: -------------------------------------------------------------------------------- 1 | #include "gtk/gtkimmodule.h" 2 | #include "gtkimcontextyong.h" 3 | 4 | #undef G_MODULE_EXPORT 5 | #define G_MODULE_EXPORT __attribute__((visibility("default"))) 6 | 7 | #include 8 | #include 9 | 10 | static GtkIMContextInfo yong_info = { 11 | "yong", 12 | "Yong Input Method", 13 | "yong", 14 | "/usr/share/locale", 15 | "*" 16 | }; 17 | 18 | static const GtkIMContextInfo *info_list[] = { 19 | &yong_info 20 | }; 21 | 22 | G_MODULE_EXPORT void im_module_init (GTypeModule *type_module) 23 | { 24 | gtk_im_context_yong_register_type(type_module); 25 | } 26 | 27 | G_MODULE_EXPORT void im_module_exit (void) 28 | { 29 | gtk_im_context_yong_shutdown(); 30 | } 31 | 32 | G_MODULE_EXPORT void im_module_list (const GtkIMContextInfo ***contexts,int *n_contexts) 33 | { 34 | #if 0 35 | char *lang=getenv("LANG"); 36 | if(lang && !strncmp(lang,"zh_CN.",6)) 37 | yong_info.context_name="Yong输入法"; 38 | else if(lang && !strncmp(lang,"zh_",3)) 39 | yong_info.context_name="Yong輸入法"; 40 | #endif 41 | *contexts = info_list; 42 | *n_contexts = G_N_ELEMENTS (info_list); 43 | } 44 | 45 | G_MODULE_EXPORT GtkIMContext * im_module_create (const gchar *context_id) 46 | { 47 | if (strcmp (context_id, "yong") == 0) 48 | return gtk_im_context_yong_new (); 49 | else 50 | return NULL; 51 | } 52 | -------------------------------------------------------------------------------- /im/gtk-im/zh_CN.po: -------------------------------------------------------------------------------- 1 | msgid "" 2 | msgstr "" 3 | "Project-Id-Version: yong 1.0\n" 4 | "PO-Revision-Date: 2012-07-31 09:00+0000\n" 5 | "Last-Translator: dgod \n" 6 | "Language-Team: dgod\n" 7 | "Language: zh_CN\n" 8 | "MIME-Version: 1.0\n" 9 | "Content-Type: text/plain; charset=UTF-8\n" 10 | "Content-Transfer-Encoding: 8bit\n" 11 | 12 | msgid "Yong Input Method" 13 | msgstr "Yong输入法" 14 | 15 | -------------------------------------------------------------------------------- /im/gtk4-im/build.txt: -------------------------------------------------------------------------------- 1 | var SRCS=['lcall.c','imyong.c','yongimcontext.c']; 2 | var DIRS=['l32-gtk4','l64-gtk4']; 3 | 4 | env("VPATH+=$(TOPDIR)/im/gtk4-im $(TOPDIR)/im"); 5 | env("CFLAGS+=$(PICFLAGS) $(LLIB_CFLAGS)"); 6 | env("CFLAGS+=-DL_CALL_GLIB_CLIENT -fvisibility=hidden -I$(TOPDIR)/im"); 7 | env("LDFLAGS+=-shared"); 8 | 9 | function run(target){ 10 | cd(target); 11 | include("../../../rules.txt"); 12 | var ARCH=target.split('-')[0]; 13 | var GTK=target.split('-')[1]; 14 | if("GTK_CFLAGS" in process.env) 15 | env("CFLAGS","+=",process.env.GTK_CFLAGS); 16 | else 17 | env("CFLAGS+=`pkg-config --cflags gtk4`"); 18 | env("CFLAGS+=-Wno-deprecated-declarations"); 19 | var OBJS=wildcard(SRCS,function(input){ 20 | return input.replace(/\.c$/,'.o'); 21 | }); 22 | begin(); 23 | cc(SRCS,OBJS); 24 | end(function(){ 25 | if("GTK_LDFLAGS" in process.env) 26 | env("LDFLAGS","+=",process.env.GTK_LDFLAGS); 27 | else 28 | env("LIBS+=-lX11 `pkg-config --libs gtk4`"); 29 | ld(OBJS,'$(DESTDIR)/libimyong.so'); 30 | }); 31 | } 32 | 33 | if(target=="clean"){ 34 | rmdir(DIRS,'*'); 35 | } else if(!target || target=="all"){ 36 | build(undefined,undefined,DIRS); 37 | } else if(target=='l32'){ 38 | build(undefined,undefined,['l32-gtk4']); 39 | } else if(target=='l64'){ 40 | build(undefined,undefined,['l64-gtk4']); 41 | }else { 42 | run(target); 43 | } 44 | -------------------------------------------------------------------------------- /im/gtk4-im/imyong.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "yongimcontext.h" 4 | 5 | G_MODULE_EXPORT void g_io_module_load(GIOModule *module) 6 | { 7 | g_type_module_use(G_TYPE_MODULE(module)); 8 | yong_im_context_register_type(G_TYPE_MODULE(module)); 9 | 10 | g_io_extension_point_implement(GTK_IM_MODULE_EXTENSION_POINT_NAME, 11 | YONG_TYPE_IM_CONTEXT, "yong", 10); 12 | } 13 | 14 | G_MODULE_EXPORT void g_io_module_unload(GIOModule *module) 15 | { 16 | } 17 | 18 | G_MODULE_EXPORT char **g_io_module_query(void) 19 | { 20 | return g_strsplit(GTK_IM_MODULE_EXTENSION_POINT_NAME," ",-1); 21 | } 22 | -------------------------------------------------------------------------------- /im/gtk4-im/yongimcontext.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dgod/yong/22b4e983260b53cbcd6a6602d38d7c00081b87a5/im/gtk4-im/yongimcontext.c -------------------------------------------------------------------------------- /im/gtk4-im/yongimcontext.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #define YONG_TYPE_IM_CONTEXT (yong_im_context_get_type()) 6 | #define YONG_IM_CONTEXT(obj) \ 7 | (G_TYPE_CHECK_INSTANCE_CAST((obj), YONG_TYPE_IM_CONTEXT, YongIMContext)) 8 | #define YONG_IM_CONTEXT_CLASS(klass) \ 9 | (G_TYPE_CHECK_CLASS_CAST((klass), YONG_TYPE_IM_CONTEXT, \ 10 | YongIMContextClass)) 11 | #define YONG_IS_IM_CONTEXT(obj) \ 12 | (G_TYPE_CHECK_INSTANCE_TYPE((obj), YONG_TYPE_IM_CONTEXT)) 13 | #define YONG_IS_IM_CONTEXT_CLASS(klass) \ 14 | (G_TYPE_CHECK_CLASS_TYPE((klass), YONG_TYPE_IM_CONTEXT)) 15 | #define YONG_IM_CONTEXT_GET_CLASS(obj) \ 16 | (G_TYPE_CHECK_GET_CLASS((obj), YONG_TYPE_IM_CONTEXT, YongIMContextClass)) 17 | 18 | typedef struct _YongIMContext YongIMContext; 19 | typedef struct _YongIMContextClass YongIMContextClass; 20 | 21 | GType yong_im_context_get_type(void); 22 | YongIMContext *yong_im_context_new(void); 23 | void yong_im_context_register_type(GTypeModule *type_module); 24 | -------------------------------------------------------------------------------- /im/lcall.h: -------------------------------------------------------------------------------- 1 | #ifndef _LCALL_H_ 2 | #define _LCALL_H_ 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include 9 | #include 10 | 11 | #define L_CALL_BUF_SIZE 1024 12 | #define L_CALL_MAGIC 0x4321 13 | 14 | #define L_CALL_FLAG_SYNC (1<<0) 15 | 16 | typedef struct{ 17 | uint16_t size; 18 | uint16_t pos; 19 | union{ 20 | uint8_t data[L_CALL_BUF_SIZE]; 21 | struct{ 22 | uint16_t magic; 23 | uint16_t seq; 24 | uint16_t len; 25 | uint16_t flag; 26 | }; 27 | }; 28 | }LCallBuf; 29 | 30 | int l_call_buf_reset(LCallBuf *buf); 31 | int l_call_buf_start(LCallBuf *buf,uint16_t seq,const char *name); 32 | int l_call_buf_stop(LCallBuf *buf); 33 | int l_call_buf_ready(LCallBuf *buf); 34 | int l_call_buf_next(LCallBuf *buf); 35 | const char *l_call_buf_name(LCallBuf *buf); 36 | int l_call_buf_write(LCallBuf *buf,const void *data,size_t size); 37 | 38 | int l_call_buf_put_data(LCallBuf *buf,const void *data,size_t size,int align); 39 | int l_call_buf_get_data(LCallBuf *buf,void *data,size_t size,int align); 40 | int l_call_buf_get_string(LCallBuf *buf,char *data,size_t size); 41 | int l_call_buf_put_string(LCallBuf *buf,const char *s); 42 | 43 | #define l_call_buf_put_val(buf,type,val) \ 44 | do { \ 45 | type _t=(type)val; \ 46 | l_call_buf_put_data((buf),&(_t),sizeof(_t),sizeof(_t)); \ 47 | }while(0) 48 | 49 | #define l_call_buf_get_val(buf,val) \ 50 | l_call_buf_get_data((buf),&(val),sizeof(val),sizeof(val)) 51 | 52 | #define l_call_buf_get_ptr(buf,ptr) \ 53 | l_call_buf_get_data(buf,ptr,sizeof(*ptr),sizeof(*ptr)) 54 | 55 | #if defined(L_CALL_GLIB_SERVER) || defined(L_CALL_GLIB_CLIENT) 56 | #include 57 | 58 | struct _LCallConn; 59 | typedef struct _LCallConn LCallConn; 60 | struct _LCallServ; 61 | typedef struct _LCallServ LCallServ; 62 | struct _LCallUser; 63 | typedef struct _LCallUser LCallUser; 64 | 65 | struct _LCallConn{ 66 | LCallServ *serv; 67 | LCallUser *user; 68 | GIOChannel *ch; 69 | LCallBuf buf; 70 | uint16_t seq; 71 | uint16_t rseq; 72 | gboolean res; 73 | guint id; 74 | void *arg; 75 | int ref; 76 | }; 77 | 78 | struct _LCallServ{ 79 | GIOChannel *ch; 80 | guint id; 81 | GSList *conn; 82 | void *arg; 83 | LCallUser *user; 84 | }; 85 | 86 | struct _LCallUser{ 87 | void (*init)(LCallConn *); 88 | void (*free)(LCallConn *); 89 | int (*dispatch)(LCallConn *,const char *,LCallBuf *); 90 | }; 91 | 92 | LCallConn *l_call_conn_new(GIOChannel *channel,LCallUser *user); 93 | int l_call_conn_return(LCallConn *conn,uint16_t seq,int res); 94 | int l_call_conn_call(LCallConn *conn,const char *name,int *res,const char *param,...); 95 | int l_call_conn_vcall(LCallConn *conn,const char *name,int *res,const char *param,va_list ap); 96 | void l_call_conn_free(LCallConn *conn); 97 | int l_call_conn_peer_pid(LCallConn *conn); 98 | 99 | #endif 100 | 101 | #ifdef L_CALL_GLIB_SERVER 102 | 103 | GIOChannel *l_call_server_new(void); 104 | LCallServ *l_call_serv_new(void *arg,LCallUser *user); 105 | void l_call_serv_free(LCallServ *serv); 106 | 107 | #endif 108 | 109 | #ifdef L_CALL_GLIB_CLIENT 110 | GIOChannel *l_call_client_new(void); 111 | void l_call_client_connect(void); 112 | void l_call_client_disconnect(void); 113 | void l_call_client_dispatch(int (*_dispatch)(const char *,LCallBuf *)); 114 | void l_call_client_set_connect(void (*cb)(void)); 115 | int l_call_client_call(const char *name,int *res,const char *param,...); 116 | #endif 117 | 118 | #ifdef __cplusplus 119 | } 120 | #endif 121 | 122 | #endif/*_LCALL_H_*/ 123 | -------------------------------------------------------------------------------- /im/qt5-im/main.cpp: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | QStringList QYongPlatformInputContextPlugin::keys() const 4 | { 5 | return QStringList(QStringLiteral("yong")); 6 | } 7 | 8 | QYongPlatformInputContext *QYongPlatformInputContextPlugin::create(const QString& system, const QStringList& paramList) 9 | { 10 | Q_UNUSED(paramList); 11 | if (system.compare(system, QStringLiteral("yong"), Qt::CaseInsensitive) == 0) 12 | return new QYongPlatformInputContext(); 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /im/qt5-im/main.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "qyongplatforminputcontext.h" 6 | 7 | class QYongPlatformInputContextPlugin : public QPlatformInputContextPlugin{ 8 | Q_OBJECT 9 | public: 10 | Q_PLUGIN_METADATA(IID QPlatformInputContextFactoryInterface_iid FILE "yong.json") 11 | QStringList keys() const; 12 | QYongPlatformInputContext *create(const QString& system, const QStringList& paramList); 13 | }; 14 | -------------------------------------------------------------------------------- /im/qt5-im/qyongplatforminputcontext.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | class QYongPlatformInputContext : public QPlatformInputContext{ 8 | Q_OBJECT; 9 | public: 10 | QYongPlatformInputContext(); 11 | virtual ~QYongPlatformInputContext(); 12 | 13 | virtual bool isValid() const; 14 | #ifdef FIX_WPS_QT 15 | virtual void reset(bool bCancel); 16 | #else 17 | virtual void reset(); 18 | #endif 19 | virtual void commit(); 20 | virtual void update(Qt::InputMethodQueries quries ); 21 | virtual void invokeAction(QInputMethod::Action , int cursorPosition); 22 | virtual bool filterEvent(const QEvent* event); 23 | virtual void setFocusObject(QObject* object); 24 | #if 0 25 | virtual void updateEnable(QWindow *pWindow){}; 26 | virtual void updateFocusEnable(){}; 27 | virtual void closeCandidateWindow(){}; 28 | #endif 29 | 30 | QKeyEvent* createKeyEvent(uint keyval, int type); 31 | void update_preedit(); 32 | 33 | guint id; 34 | QObject *client_window; 35 | int has_focus:1; 36 | int use_preedit:1; 37 | int skip_cursor:1; 38 | int is_wayland:1; 39 | int update_cursor:1; 40 | int key_ignore; 41 | int app_type; 42 | QRect cursor_area; 43 | char *preedit_string; 44 | 45 | public Q_SLOTS: 46 | void cursorRectChanged(); 47 | }; 48 | -------------------------------------------------------------------------------- /im/qt5-im/yong.json: -------------------------------------------------------------------------------- 1 | { 2 | "Keys": [ "yong" ] 3 | } 4 | -------------------------------------------------------------------------------- /im/skin/1.25/keyboard1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dgod/yong/22b4e983260b53cbcd6a6602d38d7c00081b87a5/im/skin/1.25/keyboard1.png -------------------------------------------------------------------------------- /im/skin/1.25/menu1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dgod/yong/22b4e983260b53cbcd6a6602d38d7c00081b87a5/im/skin/1.25/menu1.png -------------------------------------------------------------------------------- /im/skin/1/keyboard1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dgod/yong/22b4e983260b53cbcd6a6602d38d7c00081b87a5/im/skin/1/keyboard1.png -------------------------------------------------------------------------------- /im/skin/1/menu1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dgod/yong/22b4e983260b53cbcd6a6602d38d7c00081b87a5/im/skin/1/menu1.png -------------------------------------------------------------------------------- /im/skin/ban1.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | " 4 | -------------------------------------------------------------------------------- /im/skin/cn1.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | " 4 | -------------------------------------------------------------------------------- /im/skin/cn_biaodian1.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | " 4 | " 5 | -------------------------------------------------------------------------------- /im/skin/en1.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | " 4 | -------------------------------------------------------------------------------- /im/skin/en_biaodian1.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | " 4 | " 5 | -------------------------------------------------------------------------------- /im/skin/fan1.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | " 4 | -------------------------------------------------------------------------------- /im/skin/input.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dgod/yong/22b4e983260b53cbcd6a6602d38d7c00081b87a5/im/skin/input.png -------------------------------------------------------------------------------- /im/skin/input1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dgod/yong/22b4e983260b53cbcd6a6602d38d7c00081b87a5/im/skin/input1.png -------------------------------------------------------------------------------- /im/skin/input2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dgod/yong/22b4e983260b53cbcd6a6602d38d7c00081b87a5/im/skin/input2.png -------------------------------------------------------------------------------- /im/skin/jian1.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | " 4 | -------------------------------------------------------------------------------- /im/skin/keyboard1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dgod/yong/22b4e983260b53cbcd6a6602d38d7c00081b87a5/im/skin/keyboard1.png -------------------------------------------------------------------------------- /im/skin/logo.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | " 4 | -------------------------------------------------------------------------------- /im/skin/main.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dgod/yong/22b4e983260b53cbcd6a6602d38d7c00081b87a5/im/skin/main.png -------------------------------------------------------------------------------- /im/skin/menu1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dgod/yong/22b4e983260b53cbcd6a6602d38d7c00081b87a5/im/skin/menu1.png -------------------------------------------------------------------------------- /im/skin/skin.ini: -------------------------------------------------------------------------------- 1 | [about] 2 | name=默认 3 | preview=main.png,input.png 4 | 5 | [tray] 6 | icon=tray1.png tray2.png 7 | 8 | [main] 9 | line_width=1.2 10 | size=152,30 11 | border=#59b6e7 12 | move=2,3,10,24 13 | lang=14,3,20,24 14 | lang_cn=cn1.svg 15 | lang_en=en1.svg 16 | corner=34,3,20,24 17 | corner_half=ban1.svg 18 | corner_full=quan1.svg 19 | biaodian=54,3,20,24 20 | biaodian_cn=cn_biaodian1.svg 21 | biaodian_en=en_biaodian1.svg 22 | s2t=74,3,20,24 23 | s2t_s=jian1.svg 24 | s2t_t=fan1.svg 25 | keyboard=98,3,24,24 26 | keyboard_img=keyboard1.png 27 | menu=126,3,20,24 28 | menu_img=menu1.png 29 | 30 | [main-dark] 31 | bg=#353535 32 | border=#424242 33 | lang_cn=cn1_dark.svg 34 | lang_en=en1_dark.svg 35 | corner_half=ban1_dark.svg 36 | corner_full=quan1_dark.svg 37 | biaodian_cn=cn_biaodian1_dark.svg 38 | biaodian_en=en_biaodian1_dark.svg 39 | s2t_s=jian1_dark.svg 40 | s2t_t=fan1_dark.svg 41 | 42 | [input] 43 | line_width=1.2 44 | size=192,54 45 | msize=120,54 46 | bg=#FFFFFF 47 | border=#59b6e7 48 | stretch=3,3 49 | code=10,4 50 | cand=10,32 51 | no=0 52 | space=10 53 | font=Monospace 12 54 | #default,first,tip,caret,page,code,buffer 55 | color=#0182e5,#000000,#f68080,#0182e5,#0182e5 56 | line=0 57 | caret=1 58 | page=1 59 | 60 | [input-dark] 61 | bg=#353535 62 | border=#424242 63 | color=#f2f2f2,#f8db3c,#f68080,#f2f2f2,#f2f2f2 64 | -------------------------------------------------------------------------------- /im/skin/skin0.ini: -------------------------------------------------------------------------------- 1 | [about] 2 | name=默认 3 | preview=main.png,input.png 4 | 5 | [tray] 6 | icon=tray1.png tray2.png 7 | 8 | [main] 9 | line_width=1.2 10 | size=152,30 11 | border=#59b6e7 12 | move=2,3,10,24 13 | lang=14,3,20,24 14 | lang_cn=cn1.svg 15 | lang_en=en1.svg 16 | corner=34,3,20,24 17 | corner_half=ban1.svg 18 | corner_full=quan1.svg 19 | biaodian=54,3,20,24 20 | biaodian_cn=cn_biaodian1.svg 21 | biaodian_en=en_biaodian1.svg 22 | s2t=74,3,20,24 23 | s2t_s=jian1.svg 24 | s2t_t=fan1.svg 25 | keyboard=98,3,24,24 26 | keyboard_img=keyboard1.png 27 | menu=126,3,20,24 28 | menu_img=menu1.png 29 | 30 | [main-dark] 31 | bg=#353535 32 | border=#424242 33 | lang_cn=cn1_dark.svg 34 | lang_en=en1_dark.svg 35 | corner_half=ban1_dark.svg 36 | corner_full=quan1_dark.svg 37 | biaodian_cn=cn_biaodian1_dark.svg 38 | biaodian_en=en_biaodian1_dark.svg 39 | s2t_s=jian1_dark.svg 40 | s2t_t=fan1_dark.svg 41 | 42 | [input] 43 | line_width=1.2 44 | size=192,54 45 | msize=120,54 46 | bg=#FFFFFF 47 | border=#59b6e7 48 | stretch=3,3 49 | code=10,4 50 | cand=10,32 51 | no=0 52 | space=10 53 | font=Monospace 12 54 | #default,first,tip,caret,page,code,buffer 55 | color=#0182e5,#000000,#f68080,#0182e5,#0182e5 56 | line=0 57 | caret=1 58 | page=1 59 | 60 | [input-dark] 61 | bg=#353535 62 | border=#424242 63 | color=#f2f2f2,#f8db3c,#f68080,#f2f2f2,#f2f2f2 64 | -------------------------------------------------------------------------------- /im/skin/skin1.ini: -------------------------------------------------------------------------------- 1 | [about] 2 | name=单行 3 | preview=main.png,input1.png 4 | 5 | [tray] 6 | icon=tray1.png tray2.png 7 | 8 | [main] 9 | line_width=1.2 10 | size=152,30 11 | border=#59b6e7 12 | move=2,3,10,24 13 | lang=14,3,20,24 14 | lang_cn=cn1.svg 15 | lang_en=en1.svg 16 | corner=34,3,20,24 17 | corner_half=ban1.svg 18 | corner_full=quan1.svg 19 | biaodian=54,3,20,24 20 | biaodian_cn=cn_biaodian1.svg 21 | biaodian_en=en_biaodian1.svg 22 | s2t=74,3,20,24 23 | s2t_s=jian1.svg 24 | s2t_t=fan1.svg 25 | keyboard=98,3,24,24 26 | keyboard_img=keyboard1.png 27 | menu=126,3,20,24 28 | menu_img=menu1.png 29 | 30 | [main-dark] 31 | bg=#353535 32 | border=#424242 33 | lang_cn=cn1_dark.svg 34 | lang_en=en1_dark.svg 35 | corner_half=ban1_dark.svg 36 | corner_full=quan1_dark.svg 37 | biaodian_cn=cn_biaodian1_dark.svg 38 | biaodian_en=en_biaodian1_dark.svg 39 | s2t_s=jian1_dark.svg 40 | s2t_t=fan1_dark.svg 41 | 42 | [input] 43 | line_width=1.2 44 | #bg=skin1.svg 45 | size=192,27 46 | msize=120,27 47 | bg=#FFFFFF 48 | border=#59b6e7 49 | stretch=3,3 50 | code=10,5 51 | cand=10,6 52 | no=0 53 | space=10 54 | font=Monospace 12 55 | #default,first,tip,caret,page 56 | color=#0182e5,#000000,#f68080,#0182e5,#0182e5 57 | line=1 58 | caret=0 59 | page=0 60 | 61 | [input-dark] 62 | bg=#353535 63 | border=#424242 64 | color=#f2f2f2,#f8db3c,#f68080,#f2f2f2,#f2f2f2 65 | -------------------------------------------------------------------------------- /im/skin/skin1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dgod/yong/22b4e983260b53cbcd6a6602d38d7c00081b87a5/im/skin/skin1.png -------------------------------------------------------------------------------- /im/skin/skin2.ini: -------------------------------------------------------------------------------- 1 | [about] 2 | name=多行 3 | preview=main.png,input2.png 4 | 5 | [tray] 6 | icon=tray1.png tray2.png 7 | 8 | [main] 9 | line_width=1.2 10 | size=152,30 11 | border=#59b6e7 12 | move=2,3,10,24 13 | lang=14,3,20,24 14 | lang_cn=cn1.svg 15 | lang_en=en1.svg 16 | corner=34,3,20,24 17 | corner_half=ban1.svg 18 | corner_full=quan1.svg 19 | biaodian=54,3,20,24 20 | biaodian_cn=cn_biaodian1.svg 21 | biaodian_en=en_biaodian1.svg 22 | s2t=74,3,20,24 23 | s2t_s=jian1.svg 24 | s2t_t=fan1.svg 25 | keyboard=98,3,24,24 26 | keyboard_img=keyboard1.png 27 | menu=126,3,20,24 28 | menu_img=menu1.png 29 | 30 | [main-dark] 31 | bg=#353535 32 | border=#424242 33 | lang_cn=cn1_dark.svg 34 | lang_en=en1_dark.svg 35 | corner_half=ban1_dark.svg 36 | corner_full=quan1_dark.svg 37 | biaodian_cn=cn_biaodian1_dark.svg 38 | biaodian_en=en_biaodian1_dark.svg 39 | s2t_s=jian1_dark.svg 40 | s2t_t=fan1_dark.svg 41 | 42 | [input] 43 | line_width=1.2 44 | size=192,54 45 | msize=120,54 46 | bg=#FFFFFF 47 | border=#59b6e7 48 | stretch=3,3 49 | code=10,4 50 | cand=10,32 51 | no=0 52 | space=3 53 | font=Monospace 12 54 | #default,first,tip,caret,page 55 | color=#0182e5,#000000,#f68080,#0182e5,#0182e5 56 | line=2 57 | caret=1 58 | page=1 59 | 60 | [input-dark] 61 | bg=#353535 62 | border=#424242 63 | color=#f2f2f2,#f8db3c,#f68080,#f2f2f2,#f2f2f2 64 | -------------------------------------------------------------------------------- /im/skin/tray1.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dgod/yong/22b4e983260b53cbcd6a6602d38d7c00081b87a5/im/skin/tray1.ico -------------------------------------------------------------------------------- /im/skin/tray1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dgod/yong/22b4e983260b53cbcd6a6602d38d7c00081b87a5/im/skin/tray1.png -------------------------------------------------------------------------------- /im/skin/tray2.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dgod/yong/22b4e983260b53cbcd6a6602d38d7c00081b87a5/im/skin/tray2.ico -------------------------------------------------------------------------------- /im/skin/tray2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dgod/yong/22b4e983260b53cbcd6a6602d38d7c00081b87a5/im/skin/tray2.png -------------------------------------------------------------------------------- /im/ui-draw.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #ifdef _WIN32 7 | 8 | #include 9 | 10 | typedef struct{ 11 | int x,y; 12 | int width,height; 13 | union{ 14 | uint8_t *bits; 15 | uint32_t *pixels; 16 | }; 17 | UI_COLOR pen; 18 | double line_width; 19 | HWND win; 20 | HDC dc; 21 | bool text; 22 | }DRAW_CONTEXT1; 23 | 24 | typedef HBITMAP UI_IMAGE; 25 | typedef HICON UI_ICON; 26 | typedef struct{ 27 | HFONT gdi; 28 | void *dw; 29 | int lineGap; 30 | }*UI_FONT; 31 | 32 | typedef HDC UI_DC; 33 | typedef HWND UI_WINDOW; 34 | 35 | #else 36 | 37 | #include 38 | #include 39 | 40 | typedef GdkPixbuf *UI_IMAGE; 41 | typedef GtkWidget *UI_WINDOW; 42 | typedef cairo_t *UI_DC; 43 | typedef GdkPixbuf *UI_ICON; 44 | 45 | typedef struct{ 46 | PangoLayout *pango; 47 | uint8_t extraSpaceAbove; 48 | uint8_t extraSpaceBelow; 49 | }*UI_FONT; 50 | 51 | typedef struct{ 52 | int x,y; 53 | GtkWidget *win; 54 | cairo_t *dc; 55 | }DRAW_CONTEXT1; 56 | 57 | #endif 58 | 59 | #define IMAGE_SKIN 1 60 | #define IMAGE_SKIN_DEF 2 61 | #define IMAGE_ROOT 4 62 | #define IMAGE_ALL 0xff 63 | 64 | void ui_draw_init(void); 65 | void ui_draw_begin(DRAW_CONTEXT1 *ctx,void *win,void *dc); 66 | void ui_draw_end(DRAW_CONTEXT1 *ctx); 67 | void ui_draw_line(DRAW_CONTEXT1 *ctx,int x0,int y0,int x1,int y1,UI_COLOR color,double line_width); 68 | void ui_draw_rect(DRAW_CONTEXT1 *ctx,int x,int y,int w,int h,UI_COLOR color,double line_width); 69 | void ui_fill_rect(DRAW_CONTEXT1 *ctx,int x,int y,int w,int h,UI_COLOR color); 70 | void ui_draw_round_rect(DRAW_CONTEXT1 *ctx,int x,int y,int w,int h,int r,UI_COLOR stroke,UI_COLOR fill,double line_width); 71 | void ui_draw_text_begin(DRAW_CONTEXT1 *ctx); 72 | int ui_draw_text_end(DRAW_CONTEXT1 *ctx); 73 | void ui_draw_text(DRAW_CONTEXT1 *ctx,UI_FONT font,int x,int y,const void *text,UI_COLOR color); 74 | void ui_draw_image(DRAW_CONTEXT1 *ctx,UI_IMAGE image,int x,int y); 75 | void ui_stretch_image(DRAW_CONTEXT1 *ctx,UI_IMAGE image,int x,int y,int w,int h); 76 | void ui_draw_image_full(DRAW_CONTEXT1 *ctx,UI_IMAGE image,int dx,int dy,int dw,int dh,int x,int y,int w,int h); 77 | UI_FONT ui_font_parse(void *win,const char *s,double scale); 78 | void ui_font_free(UI_FONT font); 79 | int ui_text_size(void *dc,UI_FONT font,const void*text,int *w,int *h); 80 | bool ui_image_path(const char *file,char path[],int where); 81 | UI_IMAGE ui_image_load(const char *file,int where); 82 | void ui_image_free(UI_IMAGE img); 83 | UI_IMAGE ui_image_load_at_size(const char *file,int width,int height,int where); 84 | UI_IMAGE ui_image_load_scale(const char *file,double scale,int width,int height,int where); 85 | UI_ICON ui_icon_load(const char *file); 86 | void ui_icon_free(UI_ICON icon); 87 | 88 | -------------------------------------------------------------------------------- /im/ui.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dgod/yong/22b4e983260b53cbcd6a6602d38d7c00081b87a5/im/ui.c -------------------------------------------------------------------------------- /im/wayland/libwayland-glib-source.c: -------------------------------------------------------------------------------- 1 | typedef struct _GWaylandSource GWaylandSource; 2 | struct _GWaylandSource { 3 | GSource source; 4 | gboolean display_owned; 5 | struct wl_display *display; 6 | GPollFD fd; 7 | }; 8 | 9 | static gboolean _g_wayland_source_prepare(GSource *source, gint *timeout) 10 | { 11 | GWaylandSource *self = (GWaylandSource *)source; 12 | p_wl_display_flush(self->display); 13 | *timeout = -1; 14 | return FALSE; 15 | } 16 | 17 | static gboolean _g_wayland_source_check(GSource *source) 18 | { 19 | GWaylandSource *self = (GWaylandSource *)source; 20 | 21 | return ( self->fd.revents & G_IO_IN ); 22 | } 23 | 24 | static gboolean _g_wayland_source_dispatch(GSource *source, GSourceFunc callback, gpointer user_data) 25 | { 26 | GWaylandSource *self = (GWaylandSource *)source; 27 | gint r; 28 | 29 | r = p_wl_display_dispatch(self->display); 30 | //printf("dispatch %p %d\n",self->display,r); 31 | if ( r < 0 ) 32 | { 33 | printf("wayland error %d\n",p_wl_display_get_error(self->display)); 34 | exit(-1); 35 | /*if ( callback != NULL ) 36 | return callback(user_data); 37 | return FALSE;*/ 38 | } 39 | 40 | return TRUE; 41 | } 42 | 43 | static void _g_wayland_source_finalize(GSource *source) 44 | { 45 | GWaylandSource *self = (GWaylandSource *)source; 46 | 47 | if ( self->display_owned ) 48 | p_wl_display_disconnect(self->display); 49 | } 50 | 51 | static GSourceFuncs _g_wayland_source_funcs = { 52 | _g_wayland_source_prepare, 53 | _g_wayland_source_check, 54 | _g_wayland_source_dispatch, 55 | _g_wayland_source_finalize 56 | }; 57 | 58 | static GWaylandSource *g_wayland_source_new_for_display(GMainContext *context, struct wl_display *display) 59 | { 60 | GWaylandSource *source; 61 | 62 | source = (GWaylandSource *)g_source_new(&_g_wayland_source_funcs, sizeof(GWaylandSource)); 63 | 64 | source->display = display; 65 | 66 | source->fd.fd = p_wl_display_get_fd(display); 67 | source->fd.events = G_IO_IN; 68 | 69 | g_source_add_poll((GSource *)source, &source->fd); 70 | g_source_attach((GSource *)source, context); 71 | 72 | return source; 73 | } 74 | 75 | static GWaylandSource *g_wayland_source_new(GMainContext *context, const gchar *name) 76 | { 77 | struct wl_display *display; 78 | GWaylandSource *source; 79 | 80 | GdkDisplay *gd=gdk_display_get_default(); 81 | if(gd!=NULL && !l_str_has_prefix(gdk_display_get_name(gd),":")) 82 | { 83 | display=p_gdk_wayland_display_get_wl_display(gd); 84 | source = (GWaylandSource *)g_source_new(&_g_wayland_source_funcs, sizeof(GWaylandSource)); 85 | source->fd.fd = p_wl_display_get_fd(display); 86 | source->fd.events=0; 87 | source->display = display; 88 | return source; 89 | } 90 | 91 | display = p_wl_display_connect(name); 92 | if ( display == NULL ) 93 | { 94 | return NULL; 95 | } 96 | 97 | source = g_wayland_source_new_for_display(context, display); 98 | source->display_owned = TRUE; 99 | return source; 100 | } 101 | 102 | #ifdef WAYLAND_STANDALONE 103 | static void g_wayland_source_set_error_callback(GWaylandSource *self, GSourceFunc callback, gpointer user_data, GDestroyNotify destroy_notify) 104 | { 105 | g_return_if_fail(self != NULL); 106 | 107 | g_source_set_callback((GSource *)self, callback, user_data, destroy_notify); 108 | } 109 | #endif 110 | 111 | static struct wl_display *g_wayland_source_get_display(GWaylandSource *self) 112 | { 113 | g_return_val_if_fail(self != NULL, NULL); 114 | 115 | return self->display; 116 | } 117 | -------------------------------------------------------------------------------- /im/wayland/virtual-keyboard-v1.c: -------------------------------------------------------------------------------- 1 | /* Generated by wayland-scanner 1.22.0 */ 2 | 3 | /* 4 | * Copyright © 2008-2011 Kristian Høgsberg 5 | * Copyright © 2010-2013 Intel Corporation 6 | * Copyright © 2012-2013 Collabora, Ltd. 7 | * Copyright © 2018 Purism SPC 8 | * 9 | * Permission is hereby granted, free of charge, to any person obtaining a 10 | * copy of this software and associated documentation files (the "Software"), 11 | * to deal in the Software without restriction, including without limitation 12 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 13 | * and/or sell copies of the Software, and to permit persons to whom the 14 | * Software is furnished to do so, subject to the following conditions: 15 | * 16 | * The above copyright notice and this permission notice (including the next 17 | * paragraph) shall be included in all copies or substantial portions of the 18 | * Software. 19 | * 20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 21 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 23 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 24 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 25 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 26 | * DEALINGS IN THE SOFTWARE. 27 | */ 28 | 29 | #include 30 | #include 31 | #include "wayland-util.h" 32 | 33 | #ifndef __has_attribute 34 | # define __has_attribute(x) 0 /* Compatibility with non-clang compilers. */ 35 | #endif 36 | 37 | #if (__has_attribute(visibility) || defined(__GNUC__) && __GNUC__ >= 4) 38 | #define WL_PRIVATE __attribute__ ((visibility("hidden"))) 39 | #else 40 | #define WL_PRIVATE 41 | #endif 42 | 43 | extern const struct wl_interface wl_seat_interface; 44 | extern const struct wl_interface zwp_virtual_keyboard_v1_interface; 45 | 46 | static const struct wl_interface *virtual_keyboard_unstable_v1_types[] = { 47 | NULL, 48 | NULL, 49 | NULL, 50 | NULL, 51 | NULL,//p_wl_seat_interface 52 | &zwp_virtual_keyboard_v1_interface, 53 | }; 54 | 55 | static const struct wl_message zwp_virtual_keyboard_v1_requests[] = { 56 | { "keymap", "uhu", virtual_keyboard_unstable_v1_types + 0 }, 57 | { "key", "uuu", virtual_keyboard_unstable_v1_types + 0 }, 58 | { "modifiers", "uuuu", virtual_keyboard_unstable_v1_types + 0 }, 59 | { "destroy", "", virtual_keyboard_unstable_v1_types + 0 }, 60 | }; 61 | 62 | WL_PRIVATE const struct wl_interface zwp_virtual_keyboard_v1_interface = { 63 | "zwp_virtual_keyboard_v1", 1, 64 | 4, zwp_virtual_keyboard_v1_requests, 65 | 0, NULL, 66 | }; 67 | 68 | static const struct wl_message zwp_virtual_keyboard_manager_v1_requests[] = { 69 | { "create_virtual_keyboard", "on", virtual_keyboard_unstable_v1_types + 4 }, 70 | }; 71 | 72 | WL_PRIVATE const struct wl_interface zwp_virtual_keyboard_manager_v1_interface = { 73 | "zwp_virtual_keyboard_manager_v1", 1, 74 | 1, zwp_virtual_keyboard_manager_v1_requests, 75 | 0, NULL, 76 | }; 77 | 78 | -------------------------------------------------------------------------------- /im/ybus-ibus.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | int ybus_ibus_input_hide(void); 4 | int ybus_ibus_input_draw(int line); 5 | 6 | -------------------------------------------------------------------------------- /im/ybutton.h: -------------------------------------------------------------------------------- 1 | #ifndef __GTK_YBUTTON_H__ 2 | #define __GTK_YBUTTON_H__ 3 | 4 | #include 5 | #include 6 | 7 | G_BEGIN_DECLS 8 | 9 | #define GTK_TYPE_YBUTTON (gtk_ybutton_get_type ()) 10 | #define GTK_YBUTTON(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_YBUTTON, GtkYButton)) 11 | #define GTK_YBUTTON_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_YBUTTON, GtkYButtonClass)) 12 | #define GTK_IS_YBUTTON(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_YBUTTON)) 13 | #define GTK_IS_YBUTTON_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_YBUTTON)) 14 | #define GTK_YBUTTON_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_YBUTTON, GtkYButtonClass)) 15 | 16 | typedef struct _GtkYButton GtkYButton; 17 | typedef struct _GtkYButtonClass GtkYButtonClass; 18 | 19 | struct _GtkYButton 20 | { 21 | GtkWidget widget; 22 | 23 | GdkWindow *event_window; 24 | 25 | PangoLayout *layout; 26 | GdkPixbuf *bg[3]; 27 | 28 | guint activate_timeout; 29 | 30 | guint in_button : 1; 31 | guint button_down : 1; 32 | guint depressed : 1; 33 | guint depress_on_activate : 1; 34 | }; 35 | 36 | struct _GtkYButtonClass 37 | { 38 | GtkWidgetClass parent_class; 39 | void (* pressed) (GtkYButton *button); 40 | void (* released) (GtkYButton *button); 41 | void (* clicked) (GtkYButton *button); 42 | void (* enter) (GtkYButton *button); 43 | void (* leave) (GtkYButton *button); 44 | void (* activate) (GtkYButton *button); 45 | }; 46 | 47 | enum{ 48 | YBUTTON_NORMAL=0, 49 | YBUTTON_OVER, 50 | YBUTTON_DOWN, 51 | }; 52 | 53 | GType gtk_ybutton_get_type(void) G_GNUC_CONST; 54 | 55 | GtkWidget *gtk_ybutton_new(void); 56 | void gtk_ybutton_pressed(GtkYButton *button); 57 | void gtk_ybutton_released(GtkYButton *button); 58 | void gtk_ybutton_clicked(GtkYButton *button); 59 | void gtk_ybutton_enter(GtkYButton *button); 60 | void gtk_ybutton_leave(GtkYButton *button); 61 | void gtk_ybutton_text(GtkYButton *button,char *text); 62 | void gtk_ybutton_bg(GtkYButton *button,int state,GdkPixbuf *pixbuf); 63 | 64 | G_END_DECLS 65 | 66 | #endif /* __GTK_YBUTTON_H__ */ 67 | 68 | -------------------------------------------------------------------------------- /im/yong.ini: -------------------------------------------------------------------------------- 1 | #!/usr/bin/yong-config 2 | #Yong输入法配置文件 3 | 4 | [DESC] 5 | #配置文件版本 6 | version=2 7 | 8 | [IM] 9 | default=0 10 | 0=yong 11 | 1=wubi 12 | 2=zhengma 13 | 3=erbi 14 | 4=gbk 15 | 5=pinyin 16 | 17 | #候选字个数 18 | cand=5 19 | #简繁转换 20 | s2t=0 21 | #简繁一对多转换 22 | s2t_m=0 23 | #汉字过滤 0:不过滤 1:常用汉字 24 | filter=0 25 | #默认启动 26 | enable=0 27 | #皮肤 28 | skin=skin 29 | #回车键行为 clear:清编码 commit:上屏首选 30 | #enter=clear 31 | #数字键行为 32 | #num=push 33 | #半角出全角空格 34 | #space=full 35 | #预编辑模式 0:禁用 1:启用 36 | onspot=0 37 | #预编辑类型 0:候选 1:编码 38 | preedit=0 39 | #自动调频 40 | auto_move=0 41 | #历史记录 42 | #history=history.txt 43 | #小键盘 0:默认 1:不作为编码键 2:出数字 44 | keypad=0 45 | 46 | [main] 47 | #用户的配置文件编辑器 48 | edit= 49 | #显示托盘图标 50 | tray=1 51 | #不显示主窗口 52 | noshow=0 53 | #状态栏半透明 54 | tran=0 55 | #主窗口位置 0:右下 1:顶部居中 2:左下 56 | pos=0 57 | 58 | [input] 59 | #编码提示 60 | hint=1 61 | #不使用光标跟随 62 | root=0 63 | #不显示输入窗口 64 | noshow=0 65 | #候选显示长度 66 | strip=9 67 | 68 | [key] 69 | #打开输入法 70 | trigger=CTRL_SPACE 71 | #二三重码选择 72 | select=LSHIFT RSHIFT 73 | #中英文切换 74 | CNen=LCTRL 75 | #临时英语模式 76 | tEN=NONE 77 | #切换输入法 78 | switch=CTRL_LSHIFT 79 | #翻页 80 | page=- = 81 | #以词定字 82 | w2c=[ ] 83 | #汉字过滤 84 | filter=\\ 85 | #调词频 86 | move=CTRL_UP CTRL_DOWN 87 | #显示输入条 88 | ishow=` 89 | #一键切换到输入法 90 | switch_default=CTRL_` 91 | #笔画引导 92 | bihua=` 93 | 94 | [yong] 95 | name=永码 96 | engine=libmb.so 97 | arg=mb/yong.txt 98 | 99 | [wubi] 100 | name=五笔 101 | engine=libmb.so 102 | arg=mb/wbx.txt 103 | 104 | [zhengma] 105 | name=郑码 106 | engine=libmb.so 107 | arg=mb/zhengma.txt 108 | 109 | [erbi] 110 | name=二笔 111 | engine=libmb.so 112 | arg=mb/erbi.txt 113 | 114 | [gbk] 115 | name=内码 116 | engine=libgbk.so 117 | 118 | [pinyin] 119 | name=拼音 120 | engine=libmb.so 121 | arg=mb/pinyin.txt 122 | overlay=mb/pinyin.ini 123 | 124 | -------------------------------------------------------------------------------- /im/yong.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | org.freedesktop.IBus.Yong 5 | Yong Component 6 | /usr/bin/yong --ibus 7 | 2.7.0 8 | dgod 9 | http://yong.dgod.net 10 | yong 11 | 12 | 13 | yong 14 | zh_CN 15 | dgod 16 | /usr/share/yong/skin/tray1.png 17 | us 18 | Yong 19 | Yong Input Method 20 | /usr/bin/yong --config 21 | 22 | Yong 23 | Yong输入法 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /include/xim.h: -------------------------------------------------------------------------------- 1 | #ifndef _XIM_H_ 2 | #define _XIM_H_ 3 | 4 | #include "yong.h" 5 | #include 6 | 7 | #define POSITION_ORIG 0xffff 8 | 9 | #define LANG_CN 0 10 | #define LANG_EN 1 11 | #define CORNER_HALF 0 12 | #define CORNER_FULL 1 13 | 14 | typedef struct _CONNECT_ID{ 15 | struct _CONNECT_ID *next; 16 | unsigned int connect_id; 17 | unsigned int dummy:1; 18 | unsigned int state:1; 19 | unsigned int lang:1; 20 | unsigned int corner:1; 21 | unsigned int biaodian:1; 22 | unsigned int trad:1; 23 | unsigned int track:1; 24 | unsigned int focus:1; 25 | unsigned int lock:1; 26 | unsigned int onspot:2; 27 | int x,y; 28 | time_t last_active; 29 | }CONNECT_ID; 30 | 31 | typedef struct{ 32 | char *name; 33 | CONNECT_ID *(*get_connect)(void); 34 | void (*put_connect)(CONNECT_ID *); 35 | int (*init)(void); 36 | void (*destroy)(void); 37 | void (*enable)(int enable); 38 | void (*forward_key)(int key,int repeat); 39 | int (*trigger_key)(int key); 40 | void (*send_string)(const char *s,int flags); 41 | int (*preedit_clear)(void); 42 | int (*preedit_draw)(const char *s,int len); 43 | int (*input_key)(int key); 44 | void (*update_config)(void); 45 | void (*explore_url)(const char *s); 46 | int (*send_keys)(const int *keys,int count); 47 | int (*get_onspot)(void); 48 | }Y_XIM; 49 | 50 | CONNECT_ID *YongGetConnect(void); 51 | void YongMoveInput(int x,int y); 52 | void YongShowInput(int show); 53 | void YongShowMain(int show); 54 | int YongHotKey(int key); 55 | int YongKeyInput(int key,int mod); 56 | void YongForwardKey(int key,int repeat); 57 | void YongSendString(const char *s,int flags); 58 | int YongInitXIM(void); 59 | void YongDestroyXIM(void); 60 | void YongResetIM(void); 61 | void YongSetLang(int lang); 62 | void YongSetBiaodian(int biaodian); 63 | void YongSetCorner(int corner); 64 | void YongSetTrad(int trad); 65 | void YongUpdateMain(CONNECT_ID *id); 66 | void YongReloadAll(void); 67 | void YongReloadAllTip(void); 68 | void YongDestroyIM(void); 69 | int YongSwitchIM(int id); 70 | void YongDoDebug(void); 71 | void YongRecycleConnect(int force); 72 | void YongEnableIM(int enable); 73 | int YongTriggerKey(int key); 74 | int YongOutputSet(int type); 75 | int YongPreeditClear(void); 76 | int YongPreeditDraw(const char *s,int len); 77 | void YongSendFile(const char *fn); 78 | void YongSendClipboard(const char *s); 79 | int YongInputKey(int key); 80 | const void *YongGetSelectNumber(int n); 81 | void YongLogWrite(const char *fmt,...); 82 | void YongUpdateInputDesc(EXTRA_IM *eim); 83 | 84 | #endif/*_XIM_H_*/ 85 | -------------------------------------------------------------------------------- /llib/build.txt: -------------------------------------------------------------------------------- 1 | var SRCS=dir('.','*.c'); 2 | var DIRS=['l32','l64', 3 | 4 | ]; 5 | 6 | function run(target){ 7 | if(target=='w32') { 8 | env('CROSS_COMPILE=i686-w64-mingw32-'); 9 | env('DLL=.dll'); 10 | env('CFLAGS=-D_UNICODE -DUNICODE -DUSE_SYSTEM_ICONV'); 11 | env('LDFLAGS=-static-libgcc'); 12 | // env('LDFLAGS+=-Wl,--out-implib=w32/libl.a'); 13 | }else if(target=='w64'){ 14 | env('CROSS_COMPILE=x86_64-w64-mingw32-'); 15 | env('DLL=.dll'); 16 | env('CFLAGS=-D_UNICODE -DUNICODE -DUSE_SYSTEM_ICONV'); 17 | env('LDFLAGS=-static-libgcc'); 18 | // env('LDFLAGS+=-Wl,--out-implib=w64/libl.a'); 19 | }else if(target=='l32'){ 20 | env('CC=clang -m32'); 21 | env('LDFLAGS=-Wl,--hash-style=sysv'); 22 | env('DLL=.so'); 23 | env('CFLAGS=-m32 -fpic'); 24 | if(os.platform()=='linux') 25 | env('CFLAGS+=-D_GNU_SOURCE'); 26 | env('LIBS=-lm'); 27 | }else if(target=='l64'){ 28 | env('CC=clang'); 29 | env('LDFLAGS=-Wl,--hash-style=sysv'); 30 | env('DLL=.so'); 31 | env('CFLAGS=-fpic'); 32 | if(os.platform()=='linux') 33 | env('CFLAGS+=-D_GNU_SOURCE'); 34 | env('LIBS=-lm'); 35 | }else if(target=='js'){ 36 | env('LDFLAGS=-m32'); 37 | env('CFLAGS=-m32'); 38 | env('DLL=.so'); 39 | env('CROSS_COMPILE=/home/dgod/git/emsdk/upstream/emscripten/'); 40 | env('CC:=$(CROSS_COMPILE)emcc'); 41 | env('AR:=$(CROSS_COMPILE)ar'); 42 | env('LDFLAGS+=-shared -Wno-emcc'); 43 | env('CFLAGS+=-Wno-invalid-source-encoding'); 44 | env('CFLAGS+=-sSUPPORT_LONGJMP=wasm'); 45 | env('LDFLAGS+=-sSUPPORT_LONGJMP=wasm'); 46 | } else { 47 | return; 48 | } 49 | env("CFLAGS+=-Wall -pipe -g -O2 -fno-plt -flto=auto -ffast-math -fms-extensions -Wno-microsoft-anon-tag"); 50 | //env("CFLAGS+=-fanalyzer -Wno-analyzer-possible-null-dereference -Wno-analyzer-possible-null-argument -Wanalyzer-malloc-leak"); 51 | if(target!='js'){ 52 | if(!$('CC')) 53 | env('CC:=$(CROSS_COMPILE)gcc'); 54 | env('AR:=$(CROSS_COMPILE)ar'); 55 | env('STRIP:=$(CROSS_COMPILE)strip'); 56 | env('DLLTOOL:=$(CROSS_COMPILE)dlltool'); 57 | env('LDFLAGS+=-shared'); 58 | } 59 | if($('CC').includes('clang')){ 60 | env('CFLAGS+=-Wno-invalid-source-encoding'); 61 | } 62 | var OBJS=wildcard(SRCS,function(input){ 63 | return target+'/'+input.replace(/\.c$/,'.o'); 64 | }); 65 | begin(); 66 | cc(SRCS,OBJS); 67 | end(function(){ 68 | ld(OBJS,target+'/'+'libl$(DLL)'); 69 | }); 70 | } 71 | 72 | function clean(targets){ 73 | if(!targets){ 74 | rmdir(DIRS,'*'); 75 | return; 76 | } 77 | targets.forEach(e=>{ 78 | if(!DIRS.includes(e)){ 79 | console.log("invalid clean target"); 80 | exit(-1); 81 | } 82 | rmdir(e,'*'); 83 | }); 84 | } 85 | 86 | if(target=="clean"){ 87 | clean(target.targets); 88 | } else if(!target || target=="all"){ 89 | build(undefined,undefined,DIRS); 90 | } else { 91 | run(target); 92 | } 93 | -------------------------------------------------------------------------------- /llib/larray.c: -------------------------------------------------------------------------------- 1 | #include "ltypes.h" 2 | #include "lmem.h" 3 | #include "larray.h" 4 | #include "lsearch.h" 5 | #include "ltricky.h" 6 | #include "lqsort.h" 7 | 8 | #include 9 | #include 10 | 11 | LArray *l_array_new(int count,int size) 12 | { 13 | LArray *array; 14 | array=l_new(LArray); 15 | array->count=count; 16 | array->size=size; 17 | array->len=0; 18 | if(size>0) 19 | { 20 | array->data=l_alloc(array->count*array->size); 21 | } 22 | else 23 | { 24 | array->data=NULL; 25 | } 26 | return array; 27 | } 28 | 29 | void l_array_free(LArray *array,LFreeFunc func) 30 | { 31 | int i; 32 | if(!array) return; 33 | if(func && array->data) for(i=0;ilen;i++) 34 | { 35 | func(array->data+i*array->size); 36 | } 37 | l_free(array->data); 38 | l_free(array); 39 | } 40 | 41 | static void l_array_expand(LArray *array) 42 | { 43 | int v1,v2; 44 | if(array->count-array->len>=1) 45 | return; 46 | v1=array->len+4; 47 | v2=array->count*5/4; 48 | array->count=v1>v2?v1:v2; 49 | array->data=l_realloc(array->data,array->size*array->count); 50 | } 51 | 52 | void l_array_append(LArray *array,const void *val) 53 | { 54 | l_array_expand(array); 55 | memcpy(array->data+array->len*array->size,val,array->size); 56 | array->len++; 57 | } 58 | 59 | void l_array_insert(LArray *array,int n,const void *val) 60 | { 61 | char *orig; 62 | l_array_expand(array); 63 | orig=array->data+array->size*n; 64 | memmove(orig+array->size,orig,(array->len-n)*array->size); 65 | memcpy(orig,val,array->size); 66 | array->len++; 67 | } 68 | 69 | int l_array_remove(LArray *array,int n) 70 | { 71 | char *orig; 72 | if(n<0 || n>=array->len) 73 | return -1; 74 | orig=array->data+array->size*n; 75 | memmove(orig,orig+array->size,(array->len-n-1)*array->size); 76 | array->len--; 77 | return 0; 78 | } 79 | 80 | int l_array_insert_sorted(LArray *array,const void *val,LCmpFunc cmpar) 81 | { 82 | int pos; 83 | pos=l_bsearch_right(val,array->data,array->len,array->size,cmpar); 84 | if(pos==array->len) 85 | l_array_append(array,val); 86 | else 87 | l_array_insert(array,pos,val); 88 | return pos; 89 | } 90 | 91 | void l_array_clear(LArray *array,LFreeFunc func) 92 | { 93 | if(!array) return; 94 | if(func && array->data) 95 | { 96 | int i; 97 | for(i=0;ilen;i++) 98 | { 99 | func(array->data+i*array->size); 100 | } 101 | } 102 | array->len=0; 103 | } 104 | 105 | void l_array_sort(LArray *array,LCmpFunc cmp) 106 | { 107 | l_qsort(array->data,array->len,array->size,cmp); 108 | } 109 | 110 | void l_array_sort_r(LArray *array,LCmpDataFunc cmp,void *arg) 111 | { 112 | l_qsort_r(array->data,array->len,array->size,cmp,arg); 113 | } 114 | 115 | void l_ptr_array_append(LArray *array,const void *val) 116 | { 117 | l_array_expand(array); 118 | array->ptr[array->len++]=(void*)val; 119 | } 120 | 121 | void l_ptr_array_insert(LArray *array,int n,const void *val) 122 | { 123 | l_array_insert(array,n,&val); 124 | } 125 | 126 | void l_ptr_array_free(LArray *array,LFreeFunc func) 127 | { 128 | int i; 129 | if(!array) return; 130 | if(array->data) 131 | { 132 | if(func) for(i=0;ilen;i++) 133 | { 134 | func(array->ptr[i]); 135 | } 136 | l_free(array->data); 137 | } 138 | l_free(array); 139 | } 140 | 141 | void l_ptr_array_clear(LArray *array,LFreeFunc func) 142 | { 143 | if(!array) return; 144 | if(func) 145 | { 146 | int i; 147 | for(i=0;ilen;i++) 148 | { 149 | func(array->ptr[i]); 150 | } 151 | } 152 | array->len=0; 153 | } 154 | 155 | static int _ptr_array_cmp_r(void **p1,void **p2,void *arr[2]) 156 | { 157 | return ((LCmpDataFunc)arr[0])(*p1,*p2,arr[1]); 158 | } 159 | 160 | static int _ptr_array_cmp(void **p1,void **p2,LCmpFunc cmp) 161 | { 162 | return cmp(*p1,*p2); 163 | } 164 | 165 | void l_ptr_array_sort(LArray *array,LCmpFunc cmp) 166 | { 167 | l_qsort_r(array->data,array->len,sizeof(void*),(LCmpDataFunc)_ptr_array_cmp,cmp); 168 | } 169 | 170 | void l_ptr_array_sort_r(LArray *array,LCmpDataFunc cmp,void *arg) 171 | { 172 | void *arr[2]={cmp,arg}; 173 | l_qsort_r(array->data,array->len,sizeof(void*),(LCmpDataFunc)_ptr_array_cmp_r,arr); 174 | } 175 | 176 | -------------------------------------------------------------------------------- /llib/larray.h: -------------------------------------------------------------------------------- 1 | #ifndef _LARRAY_H_ 2 | #define _LARRAY_H_ 3 | 4 | typedef struct{ 5 | union{ 6 | char *data; 7 | void **ptr; 8 | }; 9 | int len; 10 | int count; 11 | int size; 12 | }LArray; 13 | 14 | LArray *l_array_new(int count,int size); 15 | void l_array_free(LArray *array,LFreeFunc func); 16 | void l_array_append(LArray *array,const void *val); 17 | #define l_array_nth(array,n) ((void*)(array->data+(n)*array->size)) 18 | void l_array_insert(LArray *array,int n,const void *val); 19 | int l_array_insert_sorted(LArray *array,const void *val,LCmpFunc cmpar); 20 | int l_array_remove(LArray *array,int n); 21 | #define l_array_length(array) ((array)->len) 22 | void l_array_clear(LArray *array,LFreeFunc func); 23 | void l_array_sort(LArray *array,LCmpFunc cmp); 24 | void l_array_sort_r(LArray *array,LCmpDataFunc cmp,void *arg); 25 | 26 | #define l_array_bsearch_left(array,key,cmp) l_bsearch_left((key),(array)->data,(array)->len,(array)->size,cmp) 27 | 28 | #define L_ARRAY_INIT(size) (LArray){.size=(size)} 29 | 30 | typedef LArray LPtrArray; 31 | #define l_ptr_array_new(count) l_array_new((count),sizeof(void*)) 32 | void l_ptr_array_append(LArray *array,const void *val); 33 | void l_ptr_array_insert(LArray *array,int n,const void *val); 34 | #define l_ptr_array_remove(array,n) l_array_remove(array,n) 35 | void l_ptr_array_free(LArray *array,LFreeFunc func); 36 | #define l_ptr_array_nth(array,n) (((LArray*)array)->ptr[n]) 37 | #define l_ptr_array_length(array) l_array_length(array) 38 | void l_ptr_array_clear(LArray *array,LFreeFunc func); 39 | void l_ptr_array_sort(LArray *array,LCmpFunc cmp); 40 | void l_ptr_array_sort_r(LArray *array,LCmpDataFunc cmp,void *arg); 41 | 42 | #define L_PTR_ARRAY_INIT (LPtrArray){.size=sizeof(void*)} 43 | 44 | #endif/*_LARRAY_H_*/ 45 | -------------------------------------------------------------------------------- /llib/lbase64.c: -------------------------------------------------------------------------------- 1 | #include "lmem.h" 2 | #include "ltypes.h" 3 | 4 | static const char b64_list[] = 5 | "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; 6 | 7 | void l_base64_encode(char *out, const uint8_t *in, int inlen) 8 | { 9 | for (; inlen >= 3; inlen -= 3) 10 | { 11 | *out++ = b64_list[in[0] >> 2]; 12 | *out++ = b64_list[((in[0] << 4) & 0x30) | (in[1] >> 4)]; 13 | *out++ = b64_list[((in[1] << 2) & 0x3c) | (in[2] >> 6)]; 14 | *out++ = b64_list[in[2] & 0x3f]; 15 | in += 3; 16 | } 17 | if (inlen > 0) 18 | { 19 | uint8_t fragment; 20 | *out++ = b64_list[in[0] >> 2]; 21 | fragment = (in[0] << 4) & 0x30; 22 | if (inlen > 1) 23 | fragment |= in[1] >> 4; 24 | *out++ = b64_list[fragment]; 25 | *out++ = (inlen < 2) ? '=' : b64_list[(in[1] << 2) & 0x3c]; 26 | *out++ = '='; 27 | } 28 | *out = '\0'; 29 | } 30 | 31 | #define XX 99 32 | static const uint8_t b64_index[128] = { 33 | XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX, 34 | XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX, 35 | XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,62, XX,XX,XX,63, 36 | 52,53,54,55, 56,57,58,59, 60,61,XX,XX, XX,XX,XX,XX, 37 | XX, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10, 11,12,13,14, 38 | 15,16,17,18, 19,20,21,22, 23,24,25,XX, XX,XX,XX,XX, 39 | XX,26,27,28, 29,30,31,32, 33,34,35,36, 37,38,39,40, 40 | 41,42,43,44, 45,46,47,48, 49,50,51,XX, XX,XX,XX,XX, 41 | }; 42 | 43 | #define DEC(c) (((c)>0 && (c)<128)?b64_index[c]:XX) 44 | int l_base64_decode(uint8_t *out, const char *in) 45 | { 46 | int len = 0; 47 | register uint8_t d1, d2, d3, d4; 48 | do { 49 | d1 = in[0]; 50 | if(DEC(d1) == XX) return -1; 51 | d2 = in[1]; 52 | if(DEC(d2) == XX) return -1; 53 | d3 = in[2]; 54 | if (d3 != '=' && DEC(d3) == XX) return -1; 55 | d4 = in[3]; 56 | if (d4 != '=' && DEC(d4) == XX) return -1; 57 | in += 4; 58 | if(out!=NULL) *out++ = (DEC(d1) << 2) | (DEC(d2) >> 4); 59 | ++len; 60 | if (d3 != '=') 61 | { 62 | if(out!=NULL) *out++ = ((DEC(d2) << 4) & 0xf0) | (DEC(d3) >> 2); 63 | ++len; 64 | if (d4 != '=') 65 | { 66 | if(out!=NULL) *out++ = ((DEC(d3) << 6) & 0xc0) | DEC(d4); 67 | ++len; 68 | } 69 | } 70 | }while (*in && d4 != '='); 71 | return len; 72 | } 73 | -------------------------------------------------------------------------------- /llib/lbase64.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | void l_base64_encode(char *out, const uint8_t *in, int inlen); 4 | int l_base64_decode(uint8_t *out, const char *in); 5 | -------------------------------------------------------------------------------- /llib/lbits.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "ltypes.h" 4 | 5 | #define l_read_u8(p) *(uint8_t*)(p) 6 | #define l_write_u8(p,v) (*(uint8_t*)(p)=(v)) 7 | 8 | #if L_ALIGNED_ACCESS 9 | static inline uint16_t l_read_u16(const void *p) 10 | { 11 | #if L_BYTE_ORDER==L_LITTLE_ENDIAN 12 | return ((uint8_t*)p)[0]|(((uint8_t*)p)[1]<<8); 13 | #else 14 | return ((uint8_t*)p)[1]|(((uint8_t*)p)[0]<<8); 15 | #endif 16 | } 17 | static inline uint32_t l_read_u32(const void *p) 18 | { 19 | #if L_BYTE_ORDER==L_LITTLE_ENDIAN 20 | return ((uint8_t*)p)[0]|(((uint8_t*)p)[1]<<8)| 21 | (((uint8_t*)p)[2]<<16)|(((uint8_t*)p)[3]<<24); 22 | #else 23 | return ((uint8_t*)p)[4]|(((uint8_t*)p)[2]<<8)| 24 | (((uint8_t*)p)[1]<<16)|(((uint8_t*)p)[0]<<24); 25 | #endif 26 | } 27 | static inline void l_write_u16(void *p,uint16_t v) 28 | { 29 | #if L_BYTE_ORDER==L_LITTLE_ENDIAN 30 | ((uint8_t*)p)[0]=v; 31 | ((uint8_t*)p)[1]=v>>8; 32 | #else 33 | ((uint8_t*)p)[0]=v>>8; 34 | ((uint8_t*)p)[1]=v; 35 | #endif 36 | } 37 | 38 | static inline void l_write_u32(void *p,uint32_t v) 39 | { 40 | #if L_BYTE_ORDER==L_LITTLE_ENDIAN 41 | ((uint8_t*)p)[0]=v; 42 | ((uint8_t*)p)[1]=v>>8; 43 | ((uint8_t*)p)[2]=v>>8; 44 | ((uint8_t*)p)[3]=v>>8; 45 | #else 46 | ((uint8_t*)p)[0]=v>>24; 47 | ((uint8_t*)p)[1]=v>>16; 48 | ((uint8_t*)p)[1]=v>>8; 49 | ((uint8_t*)p)[1]=v; 50 | #endif 51 | } 52 | 53 | #else 54 | #define l_read_u16(p) *(uint16_t*)(p) 55 | #define l_read_u32(p) *(uint32_t*)(p) 56 | #define l_write_u16(p,v) (*(uint16_t*)(p)=(v)) 57 | #define l_write_u32(p,v) (*(uint32_t*)(p)=(v)) 58 | #endif 59 | 60 | #if L_BYTE_ORDER==L_LITTLE_ENDIAN 61 | 62 | #define l_read_u16le(p) l_read_u16(p) 63 | #define l_read_u32le(p) l_read_u32(p) 64 | #define l_write_u16le(p,v) l_write_u16(p,v) 65 | #define l_write_u32le(p,v) l_write_u32(p,v) 66 | 67 | static inline uint16_t l_read_u16be(const void *p) 68 | { 69 | return (((uint8_t*)p)[0]<<8)|((uint8_t*)p)[1]; 70 | } 71 | static inline uint32_t l_read_u32be(const void *p) 72 | { 73 | return (((uint8_t*)p)[0]<<24)|(((uint8_t*)p)[1]<<16)| 74 | (((uint8_t*)p)[2]<<8)|((uint8_t*)p)[3]; 75 | } 76 | 77 | static inline void l_write_u16be(void *p,uint16_t v) 78 | { 79 | ((uint8_t*)p)[0]=v>>8; 80 | ((uint8_t*)p)[1]=v; 81 | } 82 | 83 | static inline void l_write_u32be(void *p,uint32_t v) 84 | { 85 | ((uint8_t*)p)[0]=v>>24; 86 | ((uint8_t*)p)[1]=v>>16; 87 | ((uint8_t*)p)[2]=v>>8; 88 | ((uint8_t*)p)[3]=v; 89 | } 90 | 91 | #else 92 | 93 | #define l_read_u16be(p) l_read_u16(p) 94 | #define l_read_u32be(p) l_read_u32(p) 95 | #define l_write_u16be(p) l_write_u16(p) 96 | #define l_write_u32be(p) l_write_u32(p) 97 | 98 | static inline uint16_t l_read_u16le(const void *p) 99 | { 100 | return (((uint8_t*)p)[0]<<8)|((uint8_t*)p)[1]; 101 | } 102 | static inline uint32_t l_read_u32le(const void *p) 103 | { 104 | return ((uint8_t*)p)[0]|(((uint8_t*)p)[1]<<8)| 105 | (((uint8_t*)p)[2]<<16)|(((uint8_t*)p)[3]<<24); 106 | } 107 | 108 | static inline void l_write_u16le(void *p,uint16_t v) 109 | { 110 | ((uint8_t*)p)[0]=v; 111 | ((uint8_t*)p)[1]=v>>8; 112 | } 113 | 114 | static inline void l_write_u32le(void *p,uint16_t v) 115 | { 116 | ((uint8_t*)p)[0]=v; 117 | ((uint8_t*)p)[1]=v>>8; 118 | ((uint8_t*)p)[2]=v>>16; 119 | ((uint8_t*)p)[3]=v>>24; 120 | } 121 | 122 | #endif 123 | 124 | #define l_flip_bits(v,mask) ((v)^(mask)) 125 | #define l_flip_bit(v,n) ((v)^(1<<(n))) 126 | 127 | #define l_bswap16(v) __builtin_bswap16(v) 128 | #define l_bswap32(v) __builtin_bswap32(v) 129 | #define l_bswap64(v) __builtin_bswap64(v) 130 | 131 | -------------------------------------------------------------------------------- /llib/lconfig.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // #define L_USE_COROUTINE 0 4 | // #define L_USE_XML_DUMP 1 5 | 6 | #if !defined(L_USE_COROUTINE) 7 | #if defined(__EMSCRIPTEN__) 8 | #define L_USE_COROUTINE 0 9 | #elif defined(__ANDROID__) 10 | #define L_USE_COROUTINE 0 11 | #elif !defined(_WIN32) 12 | #define L_USE_COROUTINE 1 13 | #endif 14 | #endif 15 | 16 | -------------------------------------------------------------------------------- /llib/lconv.c: -------------------------------------------------------------------------------- 1 | #include "ltypes.h" 2 | #include "lconv.h" 3 | #include "lmem.h" 4 | 5 | #ifdef USE_SYSTEM_ICONV 6 | 7 | #ifdef _WIN32 8 | #include 9 | 10 | static int gb_codepage; 11 | 12 | static void detect_codepage(void) 13 | { 14 | if(MultiByteToWideChar(54936,0," ",-1,0,0)>0) 15 | gb_codepage=54936; 16 | else 17 | gb_codepage=936; 18 | } 19 | 20 | void *l_gb_to_utf16(const char *s,void *out,int size) 21 | { 22 | if(!gb_codepage) detect_codepage(); 23 | MultiByteToWideChar(gb_codepage,0,s,-1,out,size/sizeof(WCHAR)); 24 | return out; 25 | } 26 | 27 | char *l_gb_to_utf8(const char *s,char *out,int size) 28 | { 29 | int len=MultiByteToWideChar(gb_codepage,0,s,-1,NULL,0); 30 | WCHAR temp[len+1]; 31 | l_gb_to_utf16(s,temp,sizeof(temp)); 32 | l_utf16_to_utf8(temp,out,size); 33 | return out; 34 | } 35 | 36 | char *l_utf8_to_gb(const char *s,char *out,int size) 37 | { 38 | int len=MultiByteToWideChar(CP_UTF8,0,s,-1,NULL,0); 39 | WCHAR temp[len+1]; 40 | l_utf8_to_utf16(s,temp,sizeof(temp)); 41 | l_utf16_to_gb(temp,out,size); 42 | return out; 43 | } 44 | 45 | char *l_utf16_to_gb(const void *s,char *out,int size) 46 | { 47 | if(!gb_codepage) detect_codepage(); 48 | WideCharToMultiByte(gb_codepage,0,s,-1,out,size,NULL,FALSE); 49 | return out; 50 | } 51 | 52 | #else 53 | #include 54 | 55 | static iconv_t gb_utf8=(iconv_t)-1; 56 | static iconv_t gb_utf16=(iconv_t)-1; 57 | static iconv_t utf16_gb=(iconv_t)-1; 58 | static iconv_t utf8_gb=(iconv_t)-1; 59 | 60 | char *l_gb_to_utf8(const char *s,char *out,int size) 61 | { 62 | size_t l1=strlen(s),l2=size-1; 63 | char *inbuf=(char*)s,*outbuf=(char*)out; 64 | 65 | if(gb_utf8==(iconv_t)-1) 66 | { 67 | gb_utf8=iconv_open("UTF8","GB18030"); 68 | if(gb_utf8==(iconv_t)-1) 69 | { 70 | gb_utf8=iconv_open("UTF8","GBK"); 71 | if(gb_utf8==(iconv_t)-1) 72 | return 0; 73 | } 74 | } 75 | 76 | iconv(gb_utf8,&inbuf,&l1,&outbuf,&l2); 77 | outbuf[0]=0; 78 | 79 | return out; 80 | } 81 | 82 | void *l_gb_to_utf16(const char *s,void *out,int size) 83 | { 84 | size_t l1=strlen(s),l2=size-2; 85 | char *inbuf=(char*)s,*outbuf=(char*)out; 86 | 87 | if(gb_utf16==(iconv_t)-1) 88 | { 89 | gb_utf16=iconv_open("UTF16","GB18030"); 90 | if(gb_utf16==(iconv_t)-1) 91 | { 92 | gb_utf16=iconv_open("UTF16","GBK"); 93 | if(gb_utf16==(iconv_t)-1) 94 | return 0; 95 | } 96 | } 97 | iconv(gb_utf16,&inbuf,&l1,&outbuf,&l2); 98 | outbuf[0]=outbuf[1]=0; 99 | 100 | return out; 101 | } 102 | 103 | char *l_utf8_to_gb(const char *s,char *out,int size) 104 | { 105 | size_t l1=strlen(s),l2=size-1; 106 | char *inbuf=(char*)s,*outbuf=(char*)out; 107 | 108 | if(utf8_gb==(iconv_t)-1) 109 | { 110 | utf8_gb=iconv_open("GB18030","UTF8"); 111 | if(utf8_gb==(iconv_t)-1) 112 | { 113 | utf8_gb=iconv_open("GBK","UTF8"); 114 | if(utf8_gb==(iconv_t)-1) 115 | return 0; 116 | } 117 | } 118 | iconv(utf8_gb,&inbuf,&l1,&outbuf,&l2); 119 | outbuf[0]=0; 120 | return out; 121 | } 122 | 123 | static int utf16_size(const void *s) 124 | { 125 | const uint16_t *p=s; 126 | int i; 127 | for(i=0;p[i]!=0;i++); 128 | return i<<1; 129 | } 130 | 131 | char *l_utf16_to_gb(const void *s,char *out,int size) 132 | { 133 | size_t l1=utf16_size(s),l2=size-1; 134 | char *inbuf=(char*)s,*outbuf=(char*)out; 135 | if(utf16_gb==(iconv_t)-1) 136 | { 137 | utf16_gb=iconv_open("GB18030","UTF16"); 138 | if(utf16_gb==(iconv_t)-1) 139 | { 140 | utf16_gb=iconv_open("GBK","UTF16"); 141 | if(utf16_gb==(iconv_t)-1) 142 | return 0; 143 | } 144 | } 145 | iconv(utf16_gb,&inbuf,&l1,&outbuf,&l2); 146 | outbuf[0]=0; 147 | return out; 148 | } 149 | 150 | #endif 151 | 152 | #endif 153 | -------------------------------------------------------------------------------- /llib/lconv.h: -------------------------------------------------------------------------------- 1 | #ifndef _LCONV_H_ 2 | #define _LCONV_H_ 3 | 4 | char *l_gb_to_utf8(const char *s,char *out,int size); 5 | void *l_gb_to_utf16(const char *s,void *out,int size); 6 | char *l_utf8_to_gb(const char *s,char *out,int size); 7 | void *l_utf8_to_utf16(const char *s,void *out,int size); 8 | char *l_utf16_to_utf8(const void *s,char *out,int size); 9 | char *l_utf16_to_gb(const void *s,char *out,int size); 10 | 11 | #endif/*_LCONV_H_*/ 12 | 13 | -------------------------------------------------------------------------------- /llib/lcoroutine.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | typedef struct { 4 | int (*sleep)(unsigned ms,void (*cb)(void*),void *arg); 5 | }L_CO_EVENTS; 6 | 7 | typedef struct { 8 | int stack_size; 9 | L_CO_EVENTS events; 10 | }L_CO_INIT; 11 | 12 | int l_co_init(L_CO_INIT *init); 13 | int l_co_exit(void); 14 | void l_co_sched(void); 15 | int l_co_create(void (*routine)(void*),void *arg); 16 | int l_co_sleep(int ms); 17 | int l_co_yield(void); 18 | int l_co_self(void); 19 | 20 | -------------------------------------------------------------------------------- /llib/ldlfcn.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifdef _WIN32 4 | 5 | #include 6 | 7 | #define l_dlopen(x) LoadLibraryA(x) 8 | #define l_dlsym(x,y) (void*)GetProcAddress(x, y) 9 | #define l_dlclose(x) FreeLibrary(x) 10 | #define l_defsym(x,y) (void*)GetProcAddress(GetModuleHandlA(x), y) 11 | 12 | #else 13 | 14 | #include 15 | 16 | #define l_dlopen(x) dlopen(x,RTLD_LAZY) 17 | #define l_dlsym(x,y) dlsym(x,y) 18 | #define l_dlclose(x) dlclose(x) 19 | #define l_defsym(x) dlsym(RTLD_DEFAULT,x) 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /llib/lenv.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | char *l_getenv(const char *name,char *buf,int size); 4 | char *l_getenv_gb(const char *name,char *buf,int size); 5 | #ifdef _WIN32 6 | int l_setenv(const char *name,const char *value,int overwrite); 7 | #else 8 | #define l_setenv(name,value,overwrite) setenv(name,value,overwrite) 9 | #endif 10 | 11 | #define L_PSEUDO_ENV_NONE 0x00 12 | #define L_PSEUDO_ENV_STRING 0x01 13 | #define L_PSEUDO_ENV_FUNC 0x02 14 | #define L_PSEUDO_ENV_UTF8 0x80 15 | int l_setenv_pseudo(const char *name,int flags,...); 16 | -------------------------------------------------------------------------------- /llib/lescape.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define L_ESCAPE_NEXT 0x01 4 | #define L_ESCAPE_GB 0x02 5 | #define L_ESCAPE_LAST 0x04 6 | #define L_ESCAPE_HEX ((char)-1) 7 | 8 | typedef struct{ 9 | char from; 10 | char to; 11 | }L_ESCAPE_ITEM; 12 | 13 | typedef struct lescapeconfig{ 14 | char lead; 15 | uint8_t flags; 16 | uint8_t count; 17 | char sep; 18 | char env[4]; 19 | char surround[2]; 20 | L_ESCAPE_ITEM map[]; 21 | }L_ESCAPE_CONFIG; 22 | 23 | void *l_unescape(const void *in, char *out, int size, const L_ESCAPE_CONFIG *config); 24 | char **l_unescape_array(const void *in, const L_ESCAPE_CONFIG *config); 25 | int l_escape(const void *in, char *out, int size, const L_ESCAPE_CONFIG *config); 26 | 27 | int encodeURIComponent(const char *in,char *out,int size); 28 | 29 | -------------------------------------------------------------------------------- /llib/lexpr.h: -------------------------------------------------------------------------------- 1 | #ifndef _LEXPR_H_ 2 | #define _LEXPR_H_ 3 | 4 | LVariant l_expr_calc(const char *s); 5 | 6 | #endif/*_LEXPR_H_*/ 7 | 8 | -------------------------------------------------------------------------------- /llib/lfile.h: -------------------------------------------------------------------------------- 1 | #ifndef _LFILE_H_ 2 | #define _LFILE_H_ 3 | 4 | #include 5 | 6 | FILE *l_file_vopen(const char *file,const char *mode,va_list ap,size_t *size); 7 | FILE *l_file_open(const char *file,const char *mode,...); 8 | char *l_file_vget_contents(const char *file,size_t *length,va_list ap); 9 | char *l_file_get_contents(const char *file,size_t *length,...); 10 | int l_file_set_contents(const char *file,const void *contents,size_t length,...); 11 | 12 | struct _ldir; 13 | typedef struct _ldir LDir; 14 | 15 | LDir *l_dir_open(const char *path); 16 | void l_dir_close(LDir *dir); 17 | const char *l_dir_read_name(LDir *dir); 18 | int l_mkdir(const char *name,int mode); 19 | int l_rmdir(const char *name); 20 | char **l_readdir(const char *path); 21 | int l_remove(const char *name); 22 | 23 | bool l_file_is_dir(const char *path); 24 | bool l_file_exists(const char *path); 25 | time_t l_file_mtime(const char *path); 26 | ssize_t l_file_size(const char *path); 27 | ssize_t l_filep_size(FILE *fp); 28 | 29 | int l_file_copy(const char *dst,const char *src,...); 30 | 31 | int l_get_line(char *line, size_t n, FILE *fp); 32 | 33 | char *l_fullpath(char *abs,const char *rel,size_t size); 34 | char *l_getcwd(void); 35 | char *l_path_resolve(const char *path); 36 | 37 | #endif/*_LFILE_H_*/ 38 | -------------------------------------------------------------------------------- /llib/lfuncs.c: -------------------------------------------------------------------------------- 1 | #include "llib.h" 2 | 3 | void l_noop(void) 4 | { 5 | } 6 | 7 | #if !L_USE_C11_THREADS 8 | 9 | #include "lthreads.h" 10 | 11 | #ifdef _WIN32 12 | 13 | DWORD WINAPI l_winthread_wrapper(void *param) 14 | { 15 | void **arr=(void**)param; 16 | l_thrd_start_t func = (l_thrd_start_t)arr[0]; 17 | void *arg = ((void**)arr)[1]; 18 | l_free(param); 19 | return (DWORD)func(arg); 20 | } 21 | 22 | #else 23 | 24 | void *l_pthread_wrapper(void *param) 25 | { 26 | void **arr=(void**)param; 27 | l_thrd_start_t func = (l_thrd_start_t)arr[0]; 28 | void *arg = ((void**)arr)[1]; 29 | l_free(param); 30 | return (void*)(size_t)func(arg); 31 | } 32 | 33 | #endif 34 | #endif 35 | 36 | int l_int_equal(const void *p1,const void *p2) 37 | { 38 | int v1=*(const int*)p1; 39 | int v2=*(const int*)p2; 40 | if(v1>v2) 41 | return 1; 42 | else if(v1==v2) 43 | return 0; 44 | else 45 | return -1; 46 | } 47 | 48 | int l_int_equal_r(const void *p1,const void *p2) 49 | { 50 | int v1=*(const int*)p1; 51 | int v2=*(const int*)p2; 52 | if(v2>v1) 53 | return 1; 54 | else if(v1==v2) 55 | return 0; 56 | else 57 | return -1; 58 | } 59 | 60 | int l_uint64_equal(const void *p1,const void *p2) 61 | { 62 | uint64_t v1=*(const uint64_t*)p1; 63 | uint64_t v2=*(const uint64_t*)p2; 64 | if(v1>v2) 65 | return 1; 66 | else if(v1==v2) 67 | return 0; 68 | else 69 | return -1; 70 | } 71 | 72 | 73 | 74 | -------------------------------------------------------------------------------- /llib/lfuncs.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | void l_noop(void); 4 | 5 | #ifdef _WIN32 6 | #include 7 | DWORD WINAPI l_winthread_wrapper(void *param); 8 | #else 9 | void *l_pthread_wrapper(void *param); 10 | #endif 11 | 12 | int l_int_equal(const void *v1,const void *v2); 13 | int l_int_equal_r(const void *v1,const void *v2); 14 | int l_uint64_equal(const void *v1,const void *v2); 15 | -------------------------------------------------------------------------------- /llib/lgb.h: -------------------------------------------------------------------------------- 1 | #ifndef _LGB_H_ 2 | #define _LGB_H_ 3 | 4 | int l_unichar_to_gb(uint32_t c,uint8_t *outbuf); 5 | uint32_t l_gb_to_unichar(const uint8_t *s); 6 | void *l_gb_next_char(const void *p); 7 | int l_gb_strlen(const void *p,int size); 8 | void *l_gb_offset(const void *p,int offset); 9 | uint32_t l_gb_to_char(const void *p); 10 | uint32_t l_gb_last_char(const void *p); 11 | int l_char_to_gb(uint32_t c,void *outbuf); 12 | const void *l_gb_strchr(const void *p,uint32_t c); 13 | 14 | #endif/*_LGB_H_*/ 15 | 16 | -------------------------------------------------------------------------------- /llib/lhashtable.h: -------------------------------------------------------------------------------- 1 | #ifndef _LHASHTABLE_H_ 2 | #define _LHASHTABLE_H_ 3 | 4 | struct _lhashtable; 5 | typedef struct _lhashtable LHashTable; 6 | 7 | typedef struct{ 8 | LHashTable *h; 9 | int index; 10 | void *next; 11 | }LHashIter; 12 | 13 | LHashTable *l_hash_table_new(LHashFunc hash,LCmpFunc cmp,int size,int offset); 14 | void l_hash_table_free(LHashTable *h,LFreeFunc func); 15 | void l_hash_table_clear(LHashTable *h,LFreeFunc func); 16 | void *l_hash_table_find(LHashTable *h,const void *item); 17 | void *l_hash_table_lookup(LHashTable *h,const void *key); 18 | bool l_hash_table_insert(LHashTable *h,void *item); 19 | void *l_hash_table_replace(LHashTable *h,void *item); 20 | void *l_hash_table_remove(LHashTable *h,void *item); 21 | void *l_hash_table_del(LHashTable *h,const void *key); 22 | int l_hash_table_size(LHashTable *h); 23 | 24 | void l_hash_iter_init(LHashIter *iter,LHashTable *h); 25 | void *l_hash_iter_next(LHashIter *iter); 26 | 27 | unsigned l_str_hash (const void *v); 28 | unsigned l_int_hash(const void *v); 29 | 30 | #define _L_HASH_DEREF_STRING(t,k) ( \ 31 | _Generic(&(((t*)NULL)->k), \ 32 | signed char **:-1, \ 33 | const signed char **:-1, \ 34 | unsigned char**:-1, \ 35 | const unsigned char **:-1, \ 36 | char **:-1, \ 37 | const char **:-1, \ 38 | void **:-1, \ 39 | const void **:-1, \ 40 | default:1)) 41 | #define L_HASH_TYPE_STRING(t,k) (_L_HASH_DEREF_STRING(t,k) * (int)offsetof(t,k)) 42 | #define L_HASH_TABLE_STRING(t,k,s) l_hash_table_new(l_str_hash,(LEqualFunc)strcmp,(s),L_HASH_TYPE_STRING(t,k)) 43 | #define L_HASH_TABLE_INT(t,k,s) l_hash_table_new(l_int_hash,l_int_equal,(s),(int)offsetof(t,k)) 44 | 45 | #ifdef __GNUC__ 46 | #define L_HASH_TABLE_LOOKUP_INT(t,i) \ 47 | (__extension__ \ 48 | ({ \ 49 | typeof(i) __i=i; \ 50 | l_hash_table_lookup(t,&__i); \ 51 | }) \ 52 | ) 53 | #endif 54 | 55 | static inline LHashTable *l_string_set_new(int size) 56 | { 57 | return l_hash_table_new(l_str_hash,(LEqualFunc)strcmp,size,sizeof(void*)); 58 | } 59 | 60 | static inline int l_string_set_add(LHashTable *h,const char *s) 61 | { 62 | if(l_hash_table_lookup(h,s)) 63 | return 1; 64 | size_t len=strlen(s)+1; 65 | char *item=l_alloc(sizeof(void*)+len); 66 | memcpy(item+sizeof(void*),s,len); 67 | l_hash_table_insert(h,item); 68 | return 0; 69 | } 70 | 71 | static inline bool l_string_set_has(LHashTable *h,const char *s) 72 | { 73 | return l_hash_table_lookup(h,s)?true:false; 74 | } 75 | 76 | static inline void l_string_set_del(LHashTable *h,const char *s) 77 | { 78 | void *item=l_hash_table_del(h,s); 79 | l_free(item); 80 | } 81 | 82 | static inline void l_string_set_free(LHashTable *h) 83 | { 84 | l_hash_table_free(h,l_free); 85 | } 86 | 87 | #endif/*_LHASHTABLE_H_*/ 88 | 89 | -------------------------------------------------------------------------------- /llib/lkeyfile.h: -------------------------------------------------------------------------------- 1 | #ifndef _LKEYFILE_H_ 2 | #define _LKEYFILE_H_ 3 | 4 | struct _lkeyfile; 5 | typedef struct _lkeyfile LKeyFile; 6 | 7 | LKeyFile *l_key_file_open(const char *file,int create,...); 8 | LKeyFile *l_key_file_load(const char *data,ssize_t length); 9 | int l_key_file_save(LKeyFile *key_file,const char *path); 10 | void l_key_file_free(LKeyFile *key_file); 11 | const char *l_key_file_get_data(LKeyFile *key_file,const char *group,const char *key); 12 | char *l_key_file_get_string(LKeyFile *key_file,const char *group,const char *key); 13 | char *l_key_file_get_string_gb(LKeyFile *key_file,const char *group,const char *key); 14 | int l_key_file_get_int(LKeyFile *key_file,const char *group,const char *key); 15 | int l_key_file_set_data(LKeyFile *key_file,const char *group,const char *key,const char *value); 16 | int l_key_file_set_string(LKeyFile *key_file,const char *group,const char *key,const char *value); 17 | int l_key_file_set_int(LKeyFile *key_file,const char *group,const char *key,int value); 18 | void l_key_file_set_dirty(LKeyFile *key_file); 19 | const char *l_key_file_get_start_group(LKeyFile *key_file); 20 | bool l_key_file_has_group(LKeyFile *key_file,const char *group); 21 | char **l_key_file_get_groups(LKeyFile *key_file); 22 | char **l_key_file_get_keys(LKeyFile *key_file,const char *group); 23 | void l_key_file_set_inherit(LKeyFile *key_file,char delimiter); 24 | void l_key_file_set_overlay(LKeyFile *key_file,LKeyFile *overly); 25 | 26 | #define l_key_file_remove_group(key_file,group) \ 27 | l_key_file_set_data((key_file),(group),NULL,NULL) 28 | 29 | #define l_key_file_remove_key(key_file,group,key) \ 30 | l_key_file_set_data((key_file),(group),(key),NULL) 31 | 32 | #endif/*_LKEYFILE_H_*/ 33 | -------------------------------------------------------------------------------- /llib/llib.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #if defined(__linux__) && !defined(_GNU_SOURCE) 4 | #define _GNU_SOURCE 5 | #endif 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | #include 18 | 19 | #include "lconfig.h" 20 | #include "ltypes.h" 21 | #include "lmacros.h" 22 | #include "lmem.h" 23 | #include "lslist.h" 24 | #include "llist.h" 25 | #include "lkeyfile.h" 26 | #include "lhashtable.h" 27 | #include "lstring.h" 28 | #include "larray.h" 29 | #include "lconv.h" 30 | #include "lunicode.h" 31 | #include "lgb.h" 32 | #include "lfile.h" 33 | #include "lexpr.h" 34 | #include "lqueue.h" 35 | #include "lsearch.h" 36 | #include "lqsort.h" 37 | #include "lbase64.h" 38 | #include "lxml.h" 39 | #include "lzlib.h" 40 | #include "lbits.h" 41 | #include "lenv.h" 42 | #include "lescape.h" 43 | #include "ltime.h" 44 | #include "lfuncs.h" 45 | #include "lthreads.h" 46 | #include "lcoroutine.h" 47 | #include "ldlfcn.h" 48 | #include "ltricky.h" 49 | -------------------------------------------------------------------------------- /llib/llist.c: -------------------------------------------------------------------------------- 1 | #include "ltypes.h" 2 | #include "lmem.h" 3 | 4 | struct _llist; 5 | typedef struct _llist LList; 6 | struct _llist{ 7 | LList *next; 8 | LList *prev; 9 | }; 10 | 11 | void *l_list_append(LList *h,LList *item) 12 | { 13 | LList *p; 14 | if(!h) 15 | { 16 | item->prev=item->next=NULL; 17 | return item; 18 | } 19 | for(p=h;p->next!=0;p=p->next); 20 | p->next=item;item->next=NULL;item->prev=p; 21 | return h; 22 | } 23 | 24 | void *l_list_prepend(LList *h,LList *item) 25 | { 26 | item->prev=NULL; 27 | item->next=h; 28 | if(h) h->prev=item; 29 | return item; 30 | } 31 | 32 | void *l_list_remove(LList *h,LList *item) 33 | { 34 | if(h==item) 35 | { 36 | h=item->next; 37 | if(h) h->prev=NULL; 38 | } 39 | else 40 | { 41 | LList *n=item->next,*p=item->prev; 42 | p->next=n; 43 | if(n) n->prev=p; 44 | } 45 | item->prev=item->next=NULL; 46 | return h; 47 | } 48 | -------------------------------------------------------------------------------- /llib/llist.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | typedef struct _llist{ 4 | struct _llist *next; 5 | struct _llist *prev; 6 | }LList; 7 | 8 | void *l_list_append(void *h,void *item); 9 | void *l_list_prepend(void *h,void *item); 10 | void *l_list_remove(void *h,void *item); 11 | #define l_list_free(h,func) l_slist_free((h),(func)) 12 | #define l_list_find(h,item,cmp) l_slist_find((h),(item),(cmp)) 13 | #define l_list_length(h) l_slist_length(h) 14 | #define l_list_nth(h,n) l_slist_nth((h),(n)) 15 | -------------------------------------------------------------------------------- /llib/lmacros.h: -------------------------------------------------------------------------------- 1 | #ifndef _LMACROS_H_ 2 | #define _LMACROS_H_ 3 | 4 | #ifndef likely 5 | #ifdef __GNUC__ 6 | #define likely(x) __builtin_expect(!!(x), 1) 7 | #define unlikely(x) __builtin_expect(!!(x),0) 8 | #else 9 | #define likely(x) (x) 10 | #define unlikely(x) (x) 11 | #endif 12 | #endif 13 | 14 | #ifdef _WIN32 15 | #define L_EXPORT(x) __declspec(dllexport) extern x;x 16 | #elif __GNUC__ >= 4 17 | #define L_EXPORT(x) extern x __attribute__((visibility("default")));x 18 | #else 19 | #define L_EXPORT(x) x 20 | #endif 21 | 22 | #if __STDC_VERSION>=201112L 23 | #define L_ALIGN(x,a) alignas(a) x 24 | #elif __GNUC__ >= 4 25 | #define L_ALIGN(x,a) x __attribute__((aligned(a))) 26 | #else 27 | #define L_ALIGN(x,a) x 28 | #endif 29 | 30 | #ifndef FALSE 31 | #define FALSE (0) 32 | #endif 33 | 34 | #ifndef TRUE 35 | #define TRUE (!FALSE) 36 | #endif 37 | 38 | #define L_VA_NUM_ARGS(...) L_VA_NUM_ARGS_IMPL(__VA_ARGS__, 9,8,7,6,5,4,3,2,1) 39 | #define L_VA_NUM_ARGS_IMPL(_1,_2,_3,_4,_5,_6,_7,_8,_9,N,...) N 40 | 41 | #define L_CAT(a,b) L_CAT_IMPL(a,b) 42 | #define L_CAT_IMPL(a,b) a##b 43 | 44 | #define L_TO_STR_IMPL(s) #s 45 | #define L_TO_STR(s) L_TO_STR_IMPL(s) 46 | 47 | #ifndef MIN 48 | #define MIN(a,b) ((a)<(b)?(a):(b)) 49 | #endif 50 | 51 | #ifndef MAX 52 | #define MAX(a,b) ((a)>(b)?(a):(b)) 53 | #endif 54 | 55 | #ifndef EQUAL 56 | #define EQUAL(a,b) _Generic( \ 57 | (a), \ 58 | const char*: \ 59 | !strcmp( \ 60 | (void*)(uintptr_t)(a), \ 61 | (void*)(uintptr_t)(b)), \ 62 | char*: \ 63 | !strcmp( \ 64 | (void*)(uintptr_t)(a), \ 65 | (void*)(uintptr_t)(b)), \ 66 | default:(a)==(b)) 67 | #endif 68 | 69 | #ifdef __GNUC__ 70 | #define array_index(a,c,v) \ 71 | (__extension__ \ 72 | ({ \ 73 | typeof((a)[0]) *__a=(void*)(a); \ 74 | int __c=(int)(c); \ 75 | typeof(v) __v=(v); \ 76 | int __r=-1; \ 77 | for(int __i=0;__i<__c;__i++) \ 78 | { \ 79 | if(EQUAL(__v,__a[__i])) \ 80 | { \ 81 | __r=__i; \ 82 | break; \ 83 | } \ 84 | } \ 85 | __r; \ 86 | }) \ 87 | ) 88 | #define array_includes(a,c,v) (array_index((a),(c),(v))>=0) 89 | #endif 90 | 91 | #define SWAP(a,i,j) \ 92 | do{ \ 93 | int _i=(int)(i); \ 94 | int _j=(int)(j); \ 95 | typeof(a[0]) t=a[_i]; \ 96 | a[_i]=a[_j]; \ 97 | a[_j]=t; \ 98 | }while(0) 99 | 100 | #ifdef __clang__ 101 | 102 | #else 103 | 104 | #define LAMDA(body) \ 105 | (__extension__ \ 106 | ({ \ 107 | int l_lamda_func body \ 108 | (void*)l_lamda_func; \ 109 | }) \ 110 | ) 111 | 112 | #endif 113 | 114 | #endif/*_LMACROS_H_*/ 115 | -------------------------------------------------------------------------------- /llib/lmem.h: -------------------------------------------------------------------------------- 1 | #ifndef _LMEM_H_ 2 | #define _LMEM_H_ 3 | 4 | #include "lmacros.h" 5 | #include 6 | #include 7 | #ifdef _WIN32 8 | #include 9 | #else 10 | #include 11 | #endif 12 | 13 | #define l_alloc(s) malloc(s) 14 | #define l_calloc(n,s) malloc((n)*(s)) 15 | #define l_alloc0(s) calloc(1,(s)) 16 | #define l_calloc0(n,s) calloc((n),(s)) 17 | #define l_realloc(p,s) realloc((p),(s)) 18 | #define l_recalloc(p,n,s) realloc((p),(n)*(s)) 19 | #define L_ALLOC(p) malloc(sizeof(*p)) 20 | #define L_ALLOC0(p) calloc(1,sizeof(*p)) 21 | #define l_new(t) ((t*)malloc(sizeof(t))) 22 | #define l_cnew(n,t) ((t*)malloc((n)*sizeof(t))) 23 | #define l_new0(t) ((t*)calloc(1,sizeof(t))) 24 | #define l_cnew0(n,t) ((t*)calloc(n,sizeof(t))) 25 | #define l_renew(p,n,t) ((t*)realloc((p),(n)*sizeof(t))) 26 | #define l_memdup(p,s) memcpy(malloc(s),p,s) 27 | #define l_strdup(p) strdup(p) 28 | #define l_free free 29 | #define l_zfree(p) do{l_free(p);p=NULL;}while(0) 30 | 31 | static inline void *l_memcpy0(void *dest,const void *src,size_t n) 32 | { 33 | memcpy(dest,src,n); 34 | ((char*)dest)[n]=0; 35 | return dest; 36 | } 37 | 38 | static inline void *l_memdup0(const void *p,size_t s) 39 | { 40 | char *r=malloc(s+1); 41 | memcpy(r,p,s); 42 | r[s]=0; 43 | return r; 44 | } 45 | 46 | #if defined(__ANDROID__) || defined(__EMSCRIPTEN__) 47 | #define l_strndup(p,n) strndup(p,n) 48 | #define l_alloca(s) alloca(s) 49 | #define l_strdupa(s) ((s)?strcpy(l_alloca(strlen(s)+1),(s)):NULL) 50 | #define l_strndupa(s,n) l_strncpy(l_alloca(n+1),(s),(n)) 51 | #elif !defined(_WIN32) 52 | #define l_strndup(p,n) strndup(p,n) 53 | #define l_alloca(s) alloca(s) 54 | #define l_strdupa(s) ((s)?strdupa(s):NULL) 55 | #ifdef strndupa 56 | #define l_strndupa(s,n) strndupa(s,n) 57 | #else 58 | #define l_strndupa(s,n) l_strncpy(l_alloca(n+1),(s),(n)) 59 | #endif 60 | #else 61 | #define l_strndup(s,n) l_strncpy(l_alloc(n+1),(s),(n)) 62 | #define l_alloca(s) _alloca(s) 63 | #define l_strdupa(s) ((s)?strcpy(l_alloca(strlen(s)+1),(s)):NULL) 64 | #define l_strndupa(s,n) l_strncpy(l_alloca(n+1),(s),(n)) 65 | #endif 66 | 67 | #define l_alloca0(s) memset(l_alloc(s),0,(s)) 68 | #define l_newa(t) ((t*)l_alloc(sizeof(t))) 69 | #define l_newa0(t) ((t*)l_alloca0(sizeof(t))) 70 | #define l_memdupa(p,s) memcpy(l_alloca(s),p,s) 71 | 72 | #ifdef __GNUC__ 73 | #define l_memdupa0(p,s) \ 74 | (__extension__ \ 75 | ({ \ 76 | int __s=(int)(s); \ 77 | char *__r=l_alloca(__s+1); \ 78 | memcpy(__r,(p),__s); \ 79 | __r[__s]=0; \ 80 | __r; \ 81 | }) \ 82 | ) 83 | #endif 84 | 85 | typedef struct _lslices LSlices; 86 | LSlices *l_slices_new(int n,...); 87 | void l_slices_free(LSlices *r); 88 | void *l_slice_alloc(LSlices *r,int size); 89 | #define l_slice_new(r,t) l_slice_alloc(r,sizeof(t)) 90 | void l_slice_free(LSlices *r,void *p,int size); 91 | 92 | #ifdef __GNUC__ 93 | #define L_AUTO_FREE_X(p) __attribute__((cleanup(p)) 94 | #define L_AUTO_FREE L_AUTO_FREE_X(l_free) 95 | #endif 96 | 97 | #endif/*_LMEM_H_*/ 98 | 99 | -------------------------------------------------------------------------------- /llib/lqsort.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "lsearch.h" 5 | #include "lqsort.h" 6 | 7 | #ifndef _GNU_SOURCE 8 | 9 | // we do not need to be thread safe 10 | #if 0 11 | static __thread void *_arg; 12 | static __thread LCmpDataFunc _compar_data; 13 | #else 14 | static void *_arg; 15 | static LCmpDataFunc _compar_data; 16 | #endif 17 | static int _compar(const void *p1,const void *p2) 18 | { 19 | return _compar_data(p1,p2,_arg); 20 | } 21 | void l_qsort_r(void *base,size_t nmemb,size_t size,LCmpDataFunc compar,void *arg) 22 | { 23 | _arg=arg; 24 | _compar_data=compar; 25 | qsort(base,nmemb,size,_compar); 26 | _arg=NULL; 27 | _compar_data=NULL; 28 | } 29 | #endif 30 | 31 | void l_isort_r(void *base,size_t nmemb,size_t size,LCmpDataFunc compar,void *arg) 32 | { 33 | if(nmemb<=1) 34 | return; 35 | int p=0; 36 | for(int i=1;ip) 52 | { 53 | p+=l_bsearch_right_r(cur,(char*)base+p*size,i-p,size,compar,arg); 54 | } 55 | } 56 | if(p!=i) 57 | { 58 | if(size==4) 59 | { 60 | int32_t temp=*(int32_t*)cur; 61 | char *orig=base+size*p; 62 | memmove(orig+4,orig,(i-p)*4); 63 | *(int32_t*)orig=temp; 64 | } 65 | else 66 | { 67 | char temp[size]; 68 | memcpy(temp,cur,size); 69 | char *orig=base+size*p; 70 | memmove(orig+size,orig,(i-p)*size); 71 | memcpy(orig,temp,size); 72 | } 73 | } 74 | } 75 | } 76 | 77 | -------------------------------------------------------------------------------- /llib/lqsort.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "ltypes.h" 4 | #include "lmacros.h" 5 | 6 | #define l_qsort(base,nmemb,size,compar) qsort((base),(nmemb),(size),(compar)) 7 | 8 | #if defined(_GNU_SOURCE) && !defined(__ANDROID__) 9 | #define l_qsort_r(base,nmemb,size,compar,arg) qsort_r((base),(nmemb),(size),(compar),(arg)) 10 | #else 11 | void l_qsort_r(void *base,size_t nmemb,size_t size,LCmpDataFunc compar,void *arg); 12 | #endif 13 | 14 | void l_isort_r(void *base,size_t nmemb,size_t size,LCmpDataFunc compar,void *arg); 15 | 16 | -------------------------------------------------------------------------------- /llib/lqueue.c: -------------------------------------------------------------------------------- 1 | #include "ltypes.h" 2 | #include "lqueue.h" 3 | #include "lslist.h" 4 | #include "llist.h" 5 | #include "lmem.h" 6 | 7 | #include 8 | #include 9 | 10 | LQueue *l_queue_new(LFreeFunc free) 11 | { 12 | LQueue *res=l_new(LQueue); 13 | res->head=res->tail=NULL; 14 | res->length=0; 15 | res->free=free; 16 | return res; 17 | } 18 | 19 | void l_queue_free(LQueue *q) 20 | { 21 | if(!q) return; 22 | l_list_free(q->head,q->free); 23 | l_free(q); 24 | } 25 | 26 | void l_queue_push_head(LQueue *q,void *data) 27 | { 28 | LList *head=q->head; 29 | q->head=l_list_prepend(head,data); 30 | if(!head) q->tail=data; 31 | q->length++; 32 | } 33 | 34 | void l_queue_push_tail(LQueue *q,void *data) 35 | { 36 | LList *tail=q->tail,*p=data; 37 | if(!tail) 38 | { 39 | q->head=q->tail=p; 40 | p->prev=p->next=NULL; 41 | } 42 | else 43 | { 44 | tail->next=p; 45 | p->prev=tail; 46 | p->next=NULL; 47 | q->tail=p; 48 | } 49 | q->length++; 50 | } 51 | 52 | void *l_queue_pop_head(LQueue *q) 53 | { 54 | void *res=q->head; 55 | if(!res) return NULL; 56 | q->head=l_list_remove(q->head,q->head); 57 | q->length--; 58 | if(!q->head) q->tail=NULL; 59 | return res; 60 | } 61 | 62 | void *l_queue_peek_head(LQueue *q) 63 | { 64 | return q->head; 65 | } 66 | 67 | int l_queue_length(LQueue *q) 68 | { 69 | return q->length; 70 | } 71 | 72 | void l_queue_remove(LQueue *q,void *data) 73 | { 74 | if(data==q->tail) 75 | q->tail=((LList*)data)->prev; 76 | q->head=l_list_remove(q->head,data); 77 | q->length--; 78 | } 79 | -------------------------------------------------------------------------------- /llib/lqueue.h: -------------------------------------------------------------------------------- 1 | #ifndef _LQUEUE_H_ 2 | #define _LQUEUE_H_ 3 | 4 | typedef struct { 5 | void *head; 6 | void *tail; 7 | int length; 8 | LFreeFunc free; 9 | }LQueue; 10 | 11 | LQueue *l_queue_new(LFreeFunc free); 12 | void l_queue_free(LQueue *q); 13 | void l_queue_push_head(LQueue *q,void *data); 14 | void l_queue_push_tail(LQueue *q,void *data); 15 | void *l_queue_pop_head(LQueue *q); 16 | void *l_queue_peek_head(LQueue *q); 17 | int l_queue_length(LQueue *q); 18 | void l_queue_remove(LQueue *q,void *data); 19 | #define l_queue_is_empty(q) (((q)->head)?0:1) 20 | #define l_queue_find(q,item,cmp) l_list_find((q)->head,(item),(cmp)) 21 | 22 | #endif/*_LQUEUE_H_*/ 23 | -------------------------------------------------------------------------------- /llib/lsearch.c: -------------------------------------------------------------------------------- 1 | #include "lsearch.h" 2 | 3 | int l_bsearch_r(const void *key,const void *base,size_t nmemb,size_t size,LCmpDataFunc compar,void *arg) 4 | { 5 | int b=0,e=nmemb,h,r; 6 | while(b0) 11 | { 12 | b=h+1; 13 | } 14 | else if(r<0) 15 | { 16 | e=h; 17 | } 18 | else 19 | { 20 | b=h; 21 | break; 22 | } 23 | } 24 | return b; 25 | } 26 | 27 | int l_bsearch_left(const void *key,const void *base,size_t nmemb,size_t size,LCmpFunc compar) 28 | { 29 | int b=0,e=nmemb,h,r; 30 | while(b0) 35 | { 36 | b=h+1; 37 | } 38 | else 39 | { 40 | e=h; 41 | } 42 | } 43 | return b; 44 | } 45 | 46 | int l_bsearch_left_r(const void *key,const void *base,size_t nmemb,size_t size,LCmpDataFunc compar,void *arg) 47 | { 48 | int b=0,e=nmemb,h,r; 49 | while(b0) 54 | { 55 | b=h+1; 56 | } 57 | else 58 | { 59 | e=h; 60 | } 61 | } 62 | return b; 63 | } 64 | 65 | 66 | int l_bsearch_right(const void *key,const void *base,size_t nmemb,size_t size,LCmpFunc compar) 67 | { 68 | int b=0,e=nmemb,h,r; 69 | while(b=0) 74 | { 75 | b=h+1; 76 | } 77 | else 78 | { 79 | e=h; 80 | } 81 | } 82 | return e; 83 | } 84 | 85 | int l_bsearch_right_r(const void *key,const void *base,size_t nmemb,size_t size,LCmpDataFunc compar,void *arg) 86 | { 87 | int b=0,e=nmemb,h,r; 88 | while(b=0) 93 | { 94 | b=h+1; 95 | } 96 | else 97 | { 98 | e=h; 99 | } 100 | } 101 | return e; 102 | } 103 | 104 | -------------------------------------------------------------------------------- /llib/lsearch.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "ltypes.h" 4 | 5 | #define l_bsearch(key,base,nmemb,size,compar) bsearch((key),(base),(nmemb),(size),(compar)) 6 | int l_bsearch_left(const void *key,const void *base,size_t nmemb,size_t size,LCmpFunc compar); 7 | int l_bsearch_right(const void *key,const void *base,size_t nmemb,size_t size,LCmpFunc compar); 8 | int l_bsearch_r(const void *key,const void *base,size_t nmemb,size_t size,LCmpDataFunc compar,void *arg); 9 | int l_bsearch_left_r(const void *key,const void *base,size_t nmemb,size_t size,LCmpDataFunc compar,void *arg); 10 | int l_bsearch_right_r(const void *key,const void *base,size_t nmemb,size_t size,LCmpDataFunc compar,void *arg); 11 | 12 | -------------------------------------------------------------------------------- /llib/lslice.c: -------------------------------------------------------------------------------- 1 | #include "llib.h" 2 | 3 | #define SLICE_DEBUG 0 4 | 5 | #if SLICE_DEBUG || defined(EMSCRIPTEN) 6 | 7 | #define SLICE_PAGE_SIZE (16*1024) 8 | static inline void *alloc_page(void) 9 | { 10 | return malloc(SLICE_PAGE_SIZE); 11 | } 12 | static inline void free_page(void *p) 13 | { 14 | free(p); 15 | } 16 | #elif defined(_WIN32) 17 | #include 18 | #define SLICE_PAGE_SIZE (16*1024) 19 | static inline void *alloc_page(void) 20 | { 21 | return VirtualAlloc(NULL,SLICE_PAGE_SIZE,MEM_COMMIT|MEM_RESERVE,PAGE_READWRITE); 22 | } 23 | static inline void free_page(void *p) 24 | { 25 | VirtualFree(p,0,MEM_RELEASE); 26 | } 27 | #else 28 | #include 29 | #include 30 | static int SLICE_PAGE_SIZE=0; 31 | static inline void *alloc_page(void) 32 | { 33 | return mmap(NULL,SLICE_PAGE_SIZE,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_ANONYMOUS,-1,0); 34 | } 35 | 36 | static inline void free_page(void *p) 37 | { 38 | munmap(p,SLICE_PAGE_SIZE); 39 | } 40 | 41 | #endif 42 | 43 | typedef struct _slice SLICE; 44 | typedef struct _page PAGE; 45 | 46 | struct _slice{ 47 | PAGE *page; 48 | LSList *idle; 49 | int pos; 50 | int block; 51 | }; 52 | 53 | typedef struct _lslices{ 54 | int count; 55 | SLICE slice[]; 56 | }LSlices; 57 | 58 | struct _page{ 59 | PAGE *next; 60 | uint8_t data[]; 61 | }; 62 | 63 | LSlices *l_slices_new(int n,...) 64 | { 65 | int size[n]; 66 | int count=0; 67 | va_list ap; 68 | #ifndef SLICE_PAGE_SIZE 69 | if(!SLICE_PAGE_SIZE) 70 | { 71 | SLICE_PAGE_SIZE=(int)sysconf(_SC_PAGESIZE); 72 | if(SLICE_PAGE_SIZE<16*1024) 73 | SLICE_PAGE_SIZE=16*1024; 74 | } 75 | #endif 76 | va_start(ap,n); 77 | for(int i=0;i=0) 83 | continue; 84 | assert(temp<64); 85 | size[count++]=temp; 86 | } 87 | va_end(ap); 88 | qsort(size,count,sizeof(int),l_int_equal); 89 | LSlices *r=l_alloc(sizeof(LSlices)+sizeof(SLICE)*count); 90 | r->count=count; 91 | for(int i=0;islice+i; 94 | s->page=NULL; 95 | s->idle=NULL; 96 | s->pos=SLICE_PAGE_SIZE; 97 | s->block=size[i]; 98 | } 99 | return r; 100 | } 101 | 102 | void l_slices_free(LSlices *r) 103 | { 104 | if(!r) 105 | return; 106 | 107 | for(int i=0;icount;i++) 108 | { 109 | SLICE *s=r->slice+i; 110 | PAGE *page=s->page; 111 | while(page) 112 | { 113 | PAGE *next=page->next; 114 | free_page(page); 115 | page=next; 116 | } 117 | } 118 | l_free(r); 119 | } 120 | 121 | #if SLICE_DEBUG 122 | static bool slice_includes(const SLICE *s,const void *mem) 123 | { 124 | const PAGE *page=s->page; 125 | const uint8_t *p=mem; 126 | while(page!=NULL) 127 | { 128 | if(p>=page->data && pdata+SLICE_PAGE_SIZE-sizeof(PAGE)) 129 | return true; 130 | page=page->next; 131 | } 132 | return false; 133 | } 134 | #endif 135 | 136 | void *l_slice_alloc(LSlices *r,int size) 137 | { 138 | for(int i=0;icount;i++) 139 | { 140 | SLICE *s=r->slice+i; 141 | if(s->blockidle; 144 | if(ret!=NULL) 145 | { 146 | s->idle=ret->next; 147 | return ret; 148 | } 149 | if(s->pos+s->block>SLICE_PAGE_SIZE-sizeof(PAGE)) 150 | { 151 | PAGE *page=alloc_page(); 152 | page->next=s->page; 153 | s->page=page; 154 | s->pos=s->block; 155 | return page->data; 156 | } 157 | else 158 | { 159 | ret=(void*)(s->page->data+s->pos); 160 | s->pos+=s->block; 161 | return ret; 162 | } 163 | } 164 | return l_alloc(size); 165 | } 166 | 167 | void l_slice_free(LSlices *r,void *p,int size) 168 | { 169 | if(!p) 170 | return; 171 | for(int i=0;icount;i++) 172 | { 173 | SLICE *s=r->slice+i; 174 | if(s->blockidle=l_slist_prepend(s->idle,p); 180 | return; 181 | } 182 | free(p); 183 | } 184 | 185 | -------------------------------------------------------------------------------- /llib/lslist.c: -------------------------------------------------------------------------------- 1 | #include "ltypes.h" 2 | #include "lmem.h" 3 | 4 | #include 5 | 6 | struct _lslist; 7 | typedef struct _lslist LSList; 8 | struct _lslist{ 9 | LSList *next; 10 | }; 11 | 12 | LSList *l_slist_append(LSList *h,LSList *n) 13 | { 14 | LSList *p; 15 | n->next=0; 16 | if(!h) return n; 17 | for(p=h;p->next!=0;p=p->next); 18 | p->next=n; 19 | return h; 20 | } 21 | 22 | void *l_slist_insert_before(LSList *h,LSList *sibling,LSList *data) 23 | { 24 | data->next=sibling; 25 | if(h==sibling) 26 | return data; 27 | LSList *p=h; 28 | while(1) 29 | { 30 | if(p->next==sibling) 31 | { 32 | p->next=data; 33 | return h; 34 | } 35 | p=p->next; 36 | assert(p!=NULL); 37 | } 38 | } 39 | 40 | void l_slist_free(LSList *h,void (*func)(void*)) 41 | { 42 | LSList *p,*n; 43 | for(p=h;p!=0;p=n) 44 | { 45 | n=p->next; 46 | func(p); 47 | } 48 | } 49 | 50 | LSList *l_slist_remove(LSList *h,void *data) 51 | { 52 | LSList *p; 53 | if(!h) return 0; 54 | if(h==data) 55 | { 56 | p=h->next; 57 | return p; 58 | } 59 | for(p=h;p->next!=0;p=p->next) 60 | { 61 | if(p->next==data) 62 | { 63 | p->next=p->next->next; 64 | break; 65 | } 66 | } 67 | return h; 68 | } 69 | 70 | void *l_slist_find(void *h,const void *item,LCmpFunc cmp) 71 | { 72 | LSList *p=h; 73 | for(;p!=0;p=p->next) 74 | { 75 | if(0==cmp(p,item)) 76 | return p; 77 | } 78 | return NULL; 79 | } 80 | 81 | void *l_slist_find_r(void *h,const void *item,LCmpDataFunc cmp,void *arg) 82 | { 83 | LSList *p=h; 84 | for(;p!=0;p=p->next) 85 | { 86 | if(0==cmp(p,item,arg)) 87 | return p; 88 | } 89 | return NULL; 90 | } 91 | 92 | int l_slist_length(void *h) 93 | { 94 | LSList *p=h; 95 | int i; 96 | for(i=0;p!=NULL;p=p->next,i++); 97 | return i; 98 | } 99 | 100 | void *l_slist_nth(void *h,int n) 101 | { 102 | LSList *p=h; 103 | int i; 104 | for(i=0;inext; 106 | return p; 107 | } 108 | 109 | void *l_slist_last(void *h) 110 | { 111 | LSList *p=h; 112 | if(!p) 113 | return NULL; 114 | for(;p->next!=NULL;p=p->next); 115 | return p; 116 | } 117 | 118 | -------------------------------------------------------------------------------- /llib/lslist.h: -------------------------------------------------------------------------------- 1 | #ifndef _LSLIST_H_ 2 | #define _LSLIST_H_ 3 | 4 | typedef struct _lslist{ 5 | struct _lslist *next; 6 | }LSList; 7 | 8 | void *l_slist_append(void *h,void *item); 9 | static inline void *l_slist_prepend(void *h,void *item) 10 | { 11 | ((LSList*)item)->next=h; 12 | return item; 13 | } 14 | void *l_slist_insert_before(void *h,void *sibling,void *item); 15 | static inline void *l_slist_insert_after(void *h,void *sibling,void *item) 16 | { 17 | ((LSList*)item)->next=((LSList*)sibling)->next; 18 | ((LSList*)sibling)->next=item; 19 | return h; 20 | } 21 | void *l_slist_remove(void *h,void *item); 22 | void l_slist_free(void *h,LFreeFunc func); 23 | void *l_slist_find(void *h,const void *item,LCmpFunc cmp); 24 | void *l_slist_find_r(void *h,const void *item,LCmpDataFunc cmp,void *arg); 25 | int l_slist_length(void *h); 26 | void *l_slist_nth(void *h,int n); 27 | void *l_slist_last(void *h); 28 | 29 | #define l_slist_find_by(h,k,cmp,v) \ 30 | (__extension__ \ 31 | ({ \ 32 | typeof(h) p; \ 33 | for(p=h;p!=NULL;p=(void*)p->next) \ 34 | { \ 35 | if(!cmp(p->k,v)) \ 36 | break; \ 37 | } \ 38 | p; \ 39 | }) \ 40 | ) 41 | 42 | #endif/*_LSLIST_H_*/ 43 | -------------------------------------------------------------------------------- /llib/lstring.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dgod/yong/22b4e983260b53cbcd6a6602d38d7c00081b87a5/llib/lstring.c -------------------------------------------------------------------------------- /llib/lstring.h: -------------------------------------------------------------------------------- 1 | #ifndef _LSTRING_H_ 2 | #define _LSTRING_H_ 3 | 4 | char *l_sprintf(const char *fmt,...); 5 | char **l_strsplit(const char *str,int delimiter); 6 | char *l_strjoinv(const char *sep,char **list); 7 | void l_strfreev(char **list); 8 | int l_strv_length(char **list); 9 | bool l_str_has_prefix(const char *str,const char *prefix); 10 | bool l_str_has_suffix(const char *str,const char *suffix); 11 | #define l_str_has_surround(str,prefix,suffix) (l_str_has_prefix((str),(prefix)) && l_str_has_suffix((str),(suffix))) 12 | char *l_str_trim_left(char *str); 13 | char *l_str_trim_right(char *str); 14 | char *l_str_trim(char *str); 15 | int l_str_replace(char *s,int from,int to); 16 | 17 | typedef struct{ 18 | char *str; 19 | int len; 20 | int size; 21 | }LString; 22 | 23 | #define L_STRING_INIT (LString){.size=0} 24 | 25 | LString *l_string_new(int size); 26 | void l_string_init(LString *string,int size); 27 | void l_string_free(LString *string); 28 | void l_string_expand(LString *string,int len); 29 | void l_string_append(LString *string,const char *val,int len); 30 | void l_string_append_c(LString *string,int c); 31 | char *l_string_steal(LString *string); 32 | void l_string_clear(LString *string); 33 | 34 | void l_strup(char *s); 35 | void l_strdown(char *s); 36 | 37 | int l_vsscanf(const char * buf, const char * fmt, va_list args); 38 | int l_sscanf(const char * buf, const char * fmt, ...); 39 | 40 | int l_strcpy(char *dest,int dest_size,const char *src); 41 | void *l_strncpy(char *restrict dest,const char *restrict src,size_t n); 42 | 43 | #if defined(_WIN32) || !defined(__GLIBC__) 44 | char *l_stpcpy(char *dest,const char *src); 45 | #else 46 | #define l_stpcpy(dest,src) stpcpy((dest),(src)) 47 | #endif 48 | 49 | void *l_memmem(const void *haystack,int haystacklen,const void *needle,int needlelen); 50 | int l_mempos(const void *haystack,int haystacklen,const void *needle,int needlelen); 51 | int l_strpos(const char *haystack,const char *needle); 52 | int l_chrpos(const char *s,int c); 53 | 54 | #define L_INT2STR_HZ 0x01 55 | #define L_INT2STR_UTF8 0x03 56 | #define L_INT2STR_ZERO0 0x04 57 | #define L_INT2STR_BIG 0x08 58 | #define L_INT2STR_INDIRECT 0x11 59 | #define L_INT2STR_TRAD 0x20 60 | #define L_INT2STR_KEEP10 0x40 61 | #define L_INT2STR_MINSEC 0x80 62 | #define L_INT2STR_NEST 0x100 63 | int l_int_to_str(int64_t n,const char *format,int flags,char *out); 64 | 65 | int l_strtok(const char *str,int delim,const char *res[],int limit); 66 | int l_strtok0(char *str,int delim,char *res[],int limit); 67 | 68 | #endif/*_LSTRING_H_*/ 69 | 70 | -------------------------------------------------------------------------------- /llib/ltime.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "ltypes.h" 5 | 6 | #ifdef _WIN32 7 | #include 8 | static inline uint64_t l_ticks(void) 9 | { 10 | #ifdef _WIN64 11 | return GetTickCount64(); 12 | #else 13 | return GetTickCount(); 14 | #endif 15 | } 16 | #else 17 | static inline uint64_t l_ticks(void) 18 | { 19 | struct timespec t; 20 | clock_gettime(CLOCK_MONOTONIC,&t); 21 | return t.tv_sec*1000+t.tv_nsec/1000000; 22 | } 23 | #endif 24 | 25 | 26 | #if L_WORD_SIZE==64 || !defined(_WIN32) 27 | #define l_time() (int64_t)time(NULL) 28 | #define l_localtime(timep) localtime((const time_t*)(timep)) 29 | #define l_mktime(tm) (int64_t)mktime(tm) 30 | #else 31 | #define l_time() (int64_t)_time64(NULL) 32 | #define l_localtime(timep) _localtime64((const __time64_t*)(timep)) 33 | #define l_mktime(tm) (int64_t)_mktime64(tm) 34 | #endif 35 | 36 | -------------------------------------------------------------------------------- /llib/ltricky.h: -------------------------------------------------------------------------------- 1 | #ifndef _LTRICKY_H_ 2 | #define _LTRICKY_H_ 3 | 4 | #if defined(__GLIBC__) && (defined(__i386__) || defined(__x86_64__)) 5 | 6 | #include "ltypes.h" 7 | 8 | #if L_WORD_SIZE==32 9 | __asm__(".symver __isoc99_sscanf,sscanf@GLIBC_2.0"); 10 | __asm__(".symver __isoc23_sscanf,sscanf@GLIBC_2.0"); 11 | __asm__(".symver __isoc99_vsscanf,vsscanf@GLIBC_2.0"); 12 | __asm__(".symver __isoc23_vsscanf,vsscanf@GLIBC_2.0"); 13 | __asm__(".symver __isoc23_strtol,strtol@GLIBC_2.0"); 14 | __asm__(".symver __isoc23_strtoul,strtoul@GLIBC_2.0"); 15 | __asm__(".symver __isoc23_strtoll,strtoll@GLIBC_2.0"); 16 | #else 17 | __asm__(".symver __isoc99_sscanf,sscanf@GLIBC_2.2.5"); 18 | __asm__(".symver __isoc23_sscanf,sscanf@GLIBC_2.2.5"); 19 | __asm__(".symver __isoc99_vsscanf,vsscanf@GLIBC_2.2.5"); 20 | __asm__(".symver __isoc23_vsscanf,vsscanf@GLIBC_2.2.5"); 21 | __asm__(".symver memcpy,memcpy@GLIBC_2.2.5"); 22 | __asm__(".symver __isoc23_strtol,strtol@GLIBC_2.2.5"); 23 | __asm__(".symver __isoc23_strtoul,strtoul@GLIBC_2.2.5"); 24 | __asm__(".symver __isoc23_strtoll,strtoll@GLIBC_2.2.5"); 25 | #endif 26 | 27 | #endif/*__GLIBC__*/ 28 | 29 | #endif/*_LTRICKY_H_*/ 30 | -------------------------------------------------------------------------------- /llib/ltypes.h: -------------------------------------------------------------------------------- 1 | #ifndef _LTYPES_H_ 2 | #define _LTYPES_H_ 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #define extends(s) \ 9 | union{ \ 10 | s s;\ 11 | s; \ 12 | }; 13 | 14 | #ifndef offsetof 15 | #ifdef __GNUC__ 16 | #define offsetof(type,field) __builtin_offsetof (type, field) 17 | #else 18 | #define offsetof(type,field) ((size_t)&((type*)0)->field) 19 | #endif 20 | #endif 21 | 22 | #ifndef container_of 23 | #define container_of(ptr,type,field) ((type*)((char*)ptr-offsetof(type,field))) 24 | #endif 25 | 26 | #ifndef lengthof 27 | #define lengthof(arr) (sizeof (arr) / sizeof ((arr)[0])) 28 | #endif 29 | 30 | #define L_ARRAY_SIZE(arr) lengthof(arr) 31 | 32 | typedef void (*LEnumFunc)(void *data,void *user); 33 | typedef void (*LFreeFunc)(void *data); 34 | typedef int (*LCmpFunc)(const void *p1,const void *p2); 35 | typedef int (*LCmpDataFunc)(const void *p1,const void *p2,void *user); 36 | typedef unsigned (*LHashFunc)(const void *key); 37 | typedef LCmpFunc LEqualFunc; 38 | 39 | enum{ 40 | L_TYPE_VOID=0, 41 | L_TYPE_CHAR, 42 | L_TYPE_INT, 43 | L_TYPE_FLOAT, 44 | L_TYPE_POINTER, 45 | L_TYPE_OP, 46 | }; 47 | 48 | typedef struct{ 49 | int type; 50 | union{ 51 | int v_char; 52 | long v_int; 53 | double v_float; 54 | void *v_pointer; 55 | int v_op; 56 | }; 57 | }LVariant; 58 | 59 | #ifndef MAX 60 | #define MAX(a,b) ((a)>(b)?(a):(b)) 61 | #endif 62 | 63 | #ifndef MIN 64 | #define MIN(a,b) ((a)<(b)?(a):(b)) 65 | #endif 66 | 67 | #define LPTR_TO_INT(p) ((int)(size_t)(p)) 68 | #define LINT_TO_PTR(i) ((void*)(size_t)(i)) 69 | 70 | #define L_LITTLE_ENDIAN 1234 71 | #define L_BIG_ENDIAN 4321 72 | 73 | #define L_BYTE_ORDER L_LITTLE_ENDIAN 74 | 75 | #if defined(_WIN64) || defined(__x86_64__) || defined(__aarch64__) || defined(__loongarch64) 76 | #define L_WORD_SIZE 64 77 | #else 78 | #define L_WORD_SIZE 32 79 | #endif 80 | 81 | #ifndef L_ALIGNED_ACCESS 82 | #define L_ALIGNED_ACCESS 0 83 | #endif 84 | 85 | #endif/*_LTYPES_H_*/ 86 | 87 | -------------------------------------------------------------------------------- /llib/lunicode.h: -------------------------------------------------------------------------------- 1 | #ifndef _LUNICODE_H_ 2 | #define _LUNICODE_H_ 3 | 4 | int l_unichar_to_utf8 (uint32_t c,uint8_t *outbuf); 5 | uint32_t l_utf8_to_unichar(const uint8_t *s); 6 | uint8_t *l_utf8_strncpy(uint8_t *dst,const uint8_t *src,size_t n); 7 | int l_utf8_strlen(const void *p,int size); 8 | const uint8_t *l_utf8_offset(const uint8_t *s,int offset); 9 | int l_unichar_to_utf16 (uint32_t c,uint16_t *outbuf); 10 | uint32_t l_utf16_to_unichar(const uint16_t *s); 11 | const uint8_t *l_utf8_next_char(const uint8_t *s); 12 | const uint16_t *l_utf16_next_char(const uint16_t *s); 13 | int l_utf16_strlen(const void *p,int size); 14 | const void *l_utf16_offset(const void *p,int offset); 15 | 16 | #endif/*_LUNICODE_H_*/ 17 | -------------------------------------------------------------------------------- /llib/lxml.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | struct _lxmlprop; 4 | typedef struct _lxmlprop LXmlProp; 5 | struct _lxmlnode; 6 | typedef struct _lxmlnode LXmlNode; 7 | 8 | struct _lxmlprop{ 9 | LXmlProp *next; 10 | char *name; 11 | char *value; 12 | }; 13 | 14 | struct _lxmlnode{ 15 | LXmlNode *next; 16 | LXmlNode *parent; 17 | LXmlNode *child; 18 | LXmlProp *prop; 19 | char *name; 20 | char *data; 21 | }; 22 | 23 | typedef struct{ 24 | LXmlNode root; 25 | LXmlNode *cur; 26 | const char *data; 27 | int deep; 28 | int status; 29 | int intag; 30 | }LXml; 31 | 32 | LXml *l_xml_load(const char *data); 33 | void l_xml_free(LXml *x); 34 | LXmlNode *l_xml_get_child(const LXmlNode *node,const char *name); 35 | const char *l_xml_get_prop(const LXmlNode *node,const char *name); 36 | -------------------------------------------------------------------------------- /llib/lzlib.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | 4 | int l_zlib_decode(void *obuffer, int olen, const void *ibuffer, int ilen, int header); 5 | void *l_zlib_decode_alloc(const void *buffer, int len, int *outlen, int header); 6 | -------------------------------------------------------------------------------- /llib/md5.h: -------------------------------------------------------------------------------- 1 | #ifndef _MD5_H_ 2 | #define _MD5_H_ 3 | 4 | #include 5 | 6 | typedef struct{ 7 | uint32_t i[2]; 8 | uint32_t buf[4]; 9 | uint8_t in[64]; 10 | uint8_t digest[16]; 11 | }MD5_CTX; 12 | 13 | void l_md5_init(MD5_CTX *); 14 | void l_md5_update(MD5_CTX *,const uint8_t *,unsigned); 15 | void l_md5_final(MD5_CTX *ctx); 16 | 17 | #endif /*_MD5_H_*/ 18 | -------------------------------------------------------------------------------- /mb/assoc.h: -------------------------------------------------------------------------------- 1 | #ifndef _ASSOC_H_ 2 | #define _ASSOC_H_ 3 | 4 | int y_assoc_get(void *handle,const char *src,int slen, 5 | int dlen,char calc[][MAX_CAND_LEN+1],int max); 6 | void y_assoc_move(void *handle,const char *phrase); 7 | void y_assoc_free(void *handle); 8 | void *y_assoc_new(const char *file,int save); 9 | 10 | #endif/*_ASSOC_H_*/ 11 | -------------------------------------------------------------------------------- /mb/build.txt: -------------------------------------------------------------------------------- 1 | var SRCS=['mb.c','face.c','pinyin.c','learn.c','assoc.c','pyzip.c', 2 | 'trie.c','fuzzy.c','cset.c','sentence.c','tools.c']; 3 | var DIRS=['l32','l64', 4 | 5 | ]; 6 | 7 | env("VPATH+=$(TOPDIR)/mb"); 8 | env("CFLAGS+=$(PICFLAGS) $(LLIB_CFLAGS)"); 9 | env("LDFLAGS+=$(LLIB_LDFLAGS)"); 10 | env("LIBS+=$(LLIB_LDADD)"); 11 | 12 | // env("CFLAGS+=-fanalyzer -Wno-analyzer-possible-null-dereference -Wno-analyzer-possible-null-argument -Wno-analyzer-malloc-leak"); 13 | 14 | function run(target){ 15 | cd(target); 16 | include("../../rules.txt"); 17 | if(target=="l32" || target=="l64"){ 18 | env("CFLAGS+=-fvisibility=hidden"); 19 | env("LIBS=-ldl -ll -lpthread"); 20 | } 21 | var OBJS=wildcard(SRCS,function(input){ 22 | return input.replace(/\.c$/,'.o'); 23 | }); 24 | begin(); 25 | cc(SRCS,OBJS); 26 | end(function(){ 27 | push(); 28 | env("LDFLAGS+=-shared"); 29 | ld(OBJS,'$(DESTDIR)/libmb.so'); 30 | pop(); 31 | 32 | }); 33 | } 34 | 35 | if(target=="clean"){ 36 | rmdir(DIRS,'*'); 37 | } else if(!target || target=="all"){ 38 | build(undefined,undefined,DIRS); 39 | } else if(target=="test"){ 40 | exec("install l64/libmb.so ../install/yong/l64/"); 41 | } else { 42 | run(target); 43 | } 44 | -------------------------------------------------------------------------------- /mb/cset.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "yong.h" 4 | #include "mb.h" 5 | 6 | enum{ 7 | CSET_TYPE_NONE=0, 8 | CSET_TYPE_CALC, 9 | CSET_TYPE_ARRAY, 10 | CSET_TYPE_PREDICT, 11 | CSET_TYPE_MB, 12 | CSET_TYPE_EXTRA_ZI, 13 | CSET_TYPE_SENTENCE, 14 | CSET_TYPE_UNKNOWN, 15 | }; 16 | #define CSET_TYPE_ALL CSET_TYPE_NONE 17 | 18 | typedef struct _cset_group{ 19 | struct _cset_group *next; 20 | int type; 21 | int count; 22 | int offset; 23 | int (*get)(struct _cset_group *g,int at,int num,char cand[][MAX_CAND_LEN+1],char tip[][MAX_TIPS_LEN+1]); 24 | void (*free)(struct _cset_group *g); 25 | }CSET_GROUP; 26 | 27 | typedef struct _cset_group_calc{ 28 | CSET_GROUP; 29 | int size; 30 | char (*phrase)[MAX_CAND_LEN+1]; 31 | }CSET_GROUP_CALC; 32 | 33 | typedef struct _cset_group_predict{ 34 | CSET_GROUP; 35 | int ptype; 36 | char phrase[MAX_CAND_LEN+1]; 37 | char codetip[MAX_CODE_LEN+1]; 38 | }CSET_GROUP_PREDICT; 39 | 40 | typedef struct _cset_group_mb{ 41 | CSET_GROUP; 42 | struct y_mb *mb; 43 | }CSET_GROUP_MB; 44 | 45 | typedef struct{ 46 | char *cand; 47 | char *codetip; 48 | int index; 49 | }CSET_GROUP_ARRAY_ITEM; 50 | 51 | typedef struct _cset_group_array{ 52 | CSET_GROUP; 53 | LArray *array; 54 | }CSET_GROUP_ARRAY; 55 | 56 | typedef struct _cset{ 57 | CSET_GROUP *list; 58 | 59 | CSET_GROUP_CALC calc; 60 | CSET_GROUP_PREDICT predict; 61 | CSET_GROUP_MB mb; 62 | CSET_GROUP_ARRAY array; 63 | 64 | LHashTable *assoc; 65 | short assoc_adjust; 66 | short assoc_adjust_add; 67 | }CSET; 68 | 69 | void cset_init(CSET *cs); 70 | void cset_reset(CSET *cs); 71 | void cset_destroy(CSET *cs); 72 | void cset_append(CSET *cs,CSET_GROUP *g); 73 | void cset_prepend(CSET *cs,CSET_GROUP *g); 74 | void cset_remove(CSET *cs,CSET_GROUP *g); 75 | int cset_count(CSET *cs); 76 | int cset_output(CSET *cs,int at,int num,char cand[][MAX_CAND_LEN+1],char tip[][MAX_TIPS_LEN+1]); 77 | void *cset_get_group_by_type(CSET *cs,int type); 78 | void cset_clear(CSET *cs,int type); 79 | 80 | void cset_group_free(CSET_GROUP *g); 81 | int cset_group_offset(CSET_GROUP *g,int offset); 82 | void cset_group_dump(CSET_GROUP *g,FILE *fp); 83 | 84 | CSET_GROUP_PREDICT *cset_predict_group_new(CSET *cs); 85 | int cset_predict_group_count(CSET *cs); 86 | 87 | CSET_GROUP_CALC *cset_calc_group_new(CSET *cs); 88 | int cset_calc_group_append(CSET_GROUP_CALC *g,const char *s); 89 | int cset_calc_group_count(CSET *cs); 90 | 91 | CSET_GROUP_MB *cset_mb_group_new(CSET *cs,struct y_mb *mb,int count); 92 | void cset_mb_group_set(CSET *cs,struct y_mb *mb,int count); 93 | 94 | CSET_GROUP_ARRAY *cset_array_group_new(CSET *cs); 95 | int cset_array_group_append(CSET_GROUP_ARRAY *g,const char *cand,const char *codetip); 96 | 97 | void cset_set_assoc(CSET *cs,char CalcPhrase[][MAX_CAND_LEN+1],int count); 98 | int cset_has_assoc(CSET *cs,const char *code); 99 | void cset_apply_assoc(CSET *cs); 100 | 101 | -------------------------------------------------------------------------------- /mb/face.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dgod/yong/22b4e983260b53cbcd6a6602d38d7c00081b87a5/mb/face.c -------------------------------------------------------------------------------- /mb/fuzzy.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dgod/yong/22b4e983260b53cbcd6a6602d38d7c00081b87a5/mb/fuzzy.c -------------------------------------------------------------------------------- /mb/fuzzy.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dgod/yong/22b4e983260b53cbcd6a6602d38d7c00081b87a5/mb/fuzzy.h -------------------------------------------------------------------------------- /mb/learn.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dgod/yong/22b4e983260b53cbcd6a6602d38d7c00081b87a5/mb/learn.c -------------------------------------------------------------------------------- /mb/learn.h: -------------------------------------------------------------------------------- 1 | #ifndef _LEARN_H_ 2 | #define _LEARN_H_ 3 | 4 | #include "cset.h" 5 | 6 | #define PREDICT_SENTENCE 0 7 | #define PREDICT_ASSIST 1 8 | #define PREDICT_JP 2 9 | 10 | struct learn_data; 11 | typedef struct learn_data LEARN_DATA; 12 | 13 | LEARN_DATA *y_mb_learn_load(struct y_mb *mb,const char *in); 14 | void y_mb_learn_free(LEARN_DATA *data); 15 | int y_mb_predict_by_learn(struct y_mb *mb,char *s,int caret,CSET_GROUP_PREDICT *g,int begin); 16 | const char *y_mb_predict_nth(const char *s,int n); 17 | 18 | extern int l_predict_simple; 19 | extern int l_predict_sp; 20 | extern int l_predict_simple_mode; 21 | 22 | #endif/*_LEARN_H_*/ 23 | -------------------------------------------------------------------------------- /mb/mb.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dgod/yong/22b4e983260b53cbcd6a6602d38d7c00081b87a5/mb/mb.c -------------------------------------------------------------------------------- /mb/pyzip.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dgod/yong/22b4e983260b53cbcd6a6602d38d7c00081b87a5/mb/pyzip.c -------------------------------------------------------------------------------- /mb/pyzip.h: -------------------------------------------------------------------------------- 1 | #ifndef _PYZIP_H_ 2 | #define _PYZIP_H_ 3 | 4 | int cp_zip(const char *in,char *out); 5 | int cp_unzip(const char *in,char *out,int size); 6 | int cp_unzip_size(const char *in,int size); 7 | int cp_unzip_py(const char *in,char *out,int size); 8 | int cp_unzip_jp(const char *in,char *out,int size); 9 | 10 | int cz_zip(const char *in,char *out); 11 | int cz_unzip(const char *in,char *out,int size); 12 | int cz_gblen(const char *in,int size); 13 | 14 | #endif/*_PYZIP_H_*/ 15 | -------------------------------------------------------------------------------- /mb/sentence.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | int sentence_init(void); 4 | void sentence_save(void); 5 | void sentence_destroy(void); 6 | CSET_GROUP *sentence_get(const char *code,struct y_mb *mb,char super); 7 | int sentence_add(const char *code,const char *cand); 8 | int sentence_del(const char *cand); 9 | 10 | -------------------------------------------------------------------------------- /rules.txt: -------------------------------------------------------------------------------- 1 | env("TOPDIR","=",path.dirname($("BUILD_FILE"))); 2 | 3 | env("BUILD","?=",path.basename(process.cwd()).split('-')[0]); 4 | var BUILD=$("BUILD"); 5 | 6 | if(BUILD=="w32"){ 7 | env("CROSS_COMPILE=i686-w64-mingw32-"); 8 | env("CFLAGS+=-D_UNICODE -DUNICODE -march=i686"); 9 | env("LDFLAGS+=-static-libgcc"); 10 | env("EXE=.exe"); 11 | env("DESTDIR=$(TOPDIR)/winim/yong"); 12 | env("CC=$(CROSS_COMPILE)gcc"); 13 | env("CXX=$(CROSS_COMPILE)g++"); 14 | }else if(BUILD=="l32"){ 15 | env("LDFLAGS+=-Wl,--hash-style=sysv -m32"); 16 | env("EXE="); 17 | env("DESTDIR=."); 18 | //env("CC=$(CROSS_COMPILE)gcc -m32 -march=i686"); 19 | //env("CXX=$(CROSS_COMPILE)g++ -m32"); 20 | env("CC=clang -m32"); 21 | env("CXX=clang++ -m32"); 22 | env("PICFLAGS=-fPIC"); 23 | if(os.platform()=='linux') 24 | env("CFLAGS+=-D_GNU_SOURCE"); 25 | process.env.PKG_CONFIG_PATH="/usr/lib/pkgconfig"; 26 | }else if(BUILD=="w64"){ 27 | env("CROSS_COMPILE=x86_64-w64-mingw32-"); 28 | env("CFLAGS+=-D_UNICODE -DUNICODE -Wno-return-local-addr"); 29 | env("LDFLAGS+=-static-libgcc"); 30 | env("EXE=.exe"); 31 | env("DESTDIR=$(TOPDIR)/winim/yong/w64"); 32 | env("CC=$(CROSS_COMPILE)gcc"); 33 | env("CXX=$(CROSS_COMPILE)g++"); 34 | }else if(BUILD=="l64"){ 35 | env("LDFLAGS+=-Wl,--hash-style=sysv"); 36 | env("EXE="); 37 | env("DESTDIR=."); 38 | //env("CC=$(CROSS_COMPILE)gcc"); 39 | //env("CXX=$(CROSS_COMPILE)g++"); 40 | env("CC=clang -m64"); 41 | env("CXX=clang++ -m64"); 42 | env("PICFLAGS=-fPIC"); 43 | if(os.platform()=='linux') 44 | env("CFLAGS+=-D_GNU_SOURCE"); 45 | process.env.PKG_CONFIG_PATH="/usr/lib64/pkgconfig"; 46 | }else if(BUILD=="js"){ 47 | env("LDFLAGS+=-m32"); 48 | env("EXE=.bin"); 49 | env("DESTDIR=."); 50 | env("CROSS_COMPILE=/home/dgod/git/emsdk/upstream/emscripten/"); 51 | env("LDFLAGS+=-Wno-emcc"); 52 | env("CC:=$(CROSS_COMPILE)emcc"); 53 | env("CFLAGS+=-Wno-invalid-source-encoding"); 54 | env('CFLAGS+=-sSUPPORT_LONGJMP=wasm'); 55 | env('LDFLAGS+=-sSUPPORT_LONGJMP=wasm'); 56 | }else if(BUILD=="loongson"){ 57 | env("CFLAGS+=-march=mips64r2 -mabi=64"); 58 | env("EXE="); 59 | env("DESTDIR=."); 60 | env('CROSS_COMPILE=mips64el-unknown-linux-gnu-'); 61 | env("CC=$(CROSS_COMPILE)gcc"); 62 | env("AR=ar cr"); 63 | } 64 | 65 | env("VPATH+=$(TOPDIR)/common"); 66 | env("AR?=$(CROSS_COMPILE)ar cr"); 67 | env("RANLIB:=$(CROSS_COMPILE)ranlib"); 68 | env("WINDRES:=$(CROSS_COMPILE)windres"); 69 | env("STRIP=$(CROSS_COMPILE)strip"); 70 | env("DLLTOOL:=$(CROSS_COMPILE)dlltool"); 71 | 72 | env("CFLAGS+=-Wall -g -O2 -fno-plt -fno-strict-aliasing -Wno-format-truncation -fms-extensions -pipe -ffast-math -I$(TOPDIR)/include -I$(TOPDIR)/common"); 73 | if($('CC').includes('clang')){ 74 | env('CFLAGS+=-Wno-invalid-source-encoding'); 75 | env('CFLAGS+= -Wno-microsoft-anon-tag'); 76 | } 77 | if(BUILD=='js') 78 | env("CFLAGS+=-Wno-microsoft-anon-tag"); 79 | 80 | env("LLIB_PATH:=$(TOPDIR)/llib"); 81 | env("LLIB_CFLAGS:=-I$(LLIB_PATH)"); 82 | env("LLIB_LDFLAGS:=-L$(LLIB_PATH)/$(BUILD)"); 83 | env("LLIB_LDADD:=-ll"); 84 | -------------------------------------------------------------------------------- /vim/build.txt: -------------------------------------------------------------------------------- 1 | var SRCS=['vim.c']; 2 | var OBJS=wildcard(SRCS,function(input){ 3 | return input.replace(/\.c$/,'.o'); 4 | }); 5 | var DIRS=['l32','l64', 6 | 7 | ]; 8 | 9 | env('VPATH+=$(TOPDIR)/vim'); 10 | 11 | function run(target){ 12 | cd(target); 13 | include("../../rules.txt"); 14 | if(target=="w32" || target=="w64") 15 | env("LDFLAGS+=-mwindows"); 16 | cc(SRCS,OBJS); 17 | ld(OBJS,'$(DESTDIR)/yong-vim$(EXE)'); 18 | } 19 | 20 | if(target=='clean'){ 21 | rmdir(DIRS,'*'); 22 | } else if(!target || target=='all'){ 23 | build(undefined,undefined,DIRS); 24 | } else { 25 | run(target); 26 | } 27 | -------------------------------------------------------------------------------- /vim/vim.c: -------------------------------------------------------------------------------- 1 | #ifdef _WIN32 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | #include 10 | 11 | #define WM_USER_TOOL (WM_USER+116) 12 | #define WM_RELOAD_ALL (WM_USER+200) 13 | 14 | void tools_reload_all(void) 15 | { 16 | HWND hWnd=FindWindow(_T("yong_main"),_T("main")); 17 | if(!hWnd) 18 | return; 19 | PostMessage(hWnd,WM_RELOAD_ALL,0,0); 20 | } 21 | 22 | int main(int arc,char *arg[]) 23 | { 24 | int i; 25 | int wait_result=0; 26 | int cmd=0; 27 | int tool=1; 28 | HWND hWnd; 29 | int res=0; 30 | 31 | for(i=1;i 61 | #include 62 | #include 63 | #include 64 | #include 65 | 66 | #include 67 | #include 68 | #include 69 | #include 70 | 71 | typedef struct{ 72 | uint16_t magic; 73 | uint16_t seq; 74 | uint16_t len; 75 | uint16_t flag; 76 | char method[8]; 77 | uint32_t data[2]; 78 | }LCallMsg; 79 | 80 | static void l_call_build_path(char *path) 81 | { 82 | char *p; 83 | p=getenv("DISPLAY"); 84 | sprintf(path,"/tmp/yong-%s",p); 85 | p=strchr(path,'.'); 86 | if(p) *p=0; 87 | } 88 | 89 | int l_call_connect(void) 90 | { 91 | struct sockaddr_un sa; 92 | int s; 93 | struct timeval timeo; 94 | 95 | timeo.tv_sec=0; 96 | timeo.tv_usec=500*1000; 97 | 98 | s=socket(AF_UNIX,SOCK_STREAM,0); 99 | memset(&sa,0,sizeof(sa)); 100 | sa.sun_family=AF_UNIX; 101 | l_call_build_path(sa.sun_path); 102 | 103 | if(0!=connect(s,(struct sockaddr*)&sa,sizeof(sa))) 104 | { 105 | perror("connect"); 106 | close(s); 107 | return -1; 108 | } 109 | setsockopt(s,SOL_SOCKET,SO_RCVTIMEO,&timeo,sizeof(timeo)); 110 | setsockopt(s,SOL_SOCKET,SO_SNDTIMEO,&timeo,sizeof(timeo)); 111 | 112 | return s; 113 | } 114 | 115 | static LCallMsg tool_buf={ 116 | 0x4321,0,sizeof(LCallMsg),0,"tool",{1,0} 117 | }; 118 | 119 | int main(int arc,char *arg[]) 120 | { 121 | int s; 122 | int ret; 123 | int i; 124 | int res=0; 125 | 126 | for(i=1;i=sizeof(tool_buf)-4) 157 | { 158 | res=tool_buf.data[0]; 159 | } 160 | else 161 | { 162 | } 163 | } 164 | printf("%d\n",res); 165 | close(s); 166 | return 0; 167 | } 168 | #endif 169 | --------------------------------------------------------------------------------