char * nls_str_toext(char *dst, const char *src) { char *p = dst; size_t inlen, outlen; if (!iconv_loaded) return strcpy(dst, src); if (nls_toext == (iconv_t)0) return strcpy(dst, src); inlen = outlen = strlen(src); my_iconv(nls_toext, NULL, NULL, &p, &outlen); while (my_iconv(nls_toext, &src, &inlen, &p, &outlen) == -1) { *p++ = *src++; inlen--; outlen--; } *p = 0; return dst; }
void * nls_mem_toext(void *dst, const void *src, int size) { char *p = dst; const char *s = src; size_t inlen, outlen; if (size == 0) return NULL; if (!iconv_loaded || nls_toext == (iconv_t)0) return memcpy(dst, src, size); inlen = outlen = size; my_iconv(nls_toext, NULL, NULL, &p, &outlen); while (my_iconv(nls_toext, &s, &inlen, &p, &outlen) == -1) { *p++ = *s++; inlen--; outlen--; } return dst; }
int main(int c, char **v) { if (c != 3){ perror("usage..."); return -1; } char buf[256]; char tmpbuf[256]; char *rptr, *tmp, *p; int i = 0, ret, n; FILE *rp = fopen(v[1], "r"); if (rp == NULL){ perror("fopen..."); return -1; } //sprintf(buf, "%s.new", v[1]); FILE *wp = fopen("tmp", "w+"); if (wp == NULL){ perror("fopen..."); return -1; } while (1) { i = 0; memset(buf, 0, sizeof(buf)); rptr = NULL; rptr = fgets(buf, 256, rp); if (rptr == 0){ if (feof(rp)) break; } if (buf[strlen(buf) - 1] == '\n') buf[strlen(buf) - 1] = '\0'; // char str[] = "新园乡 932 枋寮乡 940"; #if 1 ret = my_iconv((char*)"utf8", (char*)"gbk", tmpbuf, sizeof(tmpbuf), buf, 256); if (ret == 1){ return -1; } //printf("%s\n", tmpbuf); #endif char *ch = strtok(tmpbuf, v[2]); while(ch != NULL) { i++; if (i%2){ tmp = ch; } else{ //printf("%s %s\n", tmp, ch); //ret = atoi(ch); // if (ret) fprintf(wp, "%s,%s\n", tmp, ch); // else //fprintf(wp, "%s,%s,%s\n", tmp, ch,"000000"); //else //break; } // printf("%s\n", ch); ch = strtok(NULL, v[2]); } } fclose(rp); fclose(wp); return 0; }
int load_po(FILE *f) { unsigned char buf[1024]; unsigned char msgid[1024]; unsigned char msgstr[1024]; unsigned char bf[8192]; struct charmap *po_map = locale_map; int preload_flag = 0; msgid[0] = 0; msgstr[0] = 0; while (preload_flag || fgets((char *)buf,sizeof(buf)-1,f)) { unsigned char *p; preload_flag = 0; p = buf; parse_ws(&p, '#'); if (!parse_field(&p, "msgid")) { int ofst = 0; int len; msgid[0] = 0; parse_ws(&p, '#'); while ((len = parse_string(&p, msgid + ofst, sizeof(msgid)-ofst)) >= 0) { preload_flag = 0; ofst += len; parse_ws(&p, '#'); if (!*p) { if (fgets((char *)buf,sizeof(buf) - 1,f)) { p = buf; preload_flag = 1; parse_ws(&p, '#'); } else { goto bye; } } } } else if (!parse_field(&p, "msgstr")) { int ofst = 0; int len; msgstr[0] = 0; parse_ws(&p, '#'); while ((len = parse_string(&p, msgstr + ofst, sizeof(msgstr)-ofst)) >= 0) { preload_flag = 0; ofst += len; parse_ws(&p, '#'); if (!*p) { if (fgets((char *)buf,sizeof(buf) - 1,f)) { p = buf; preload_flag = 1; parse_ws(&p, '#'); } else { break; } } } if (msgid[0] && msgstr[0]) { /* Convert to locale character map */ my_iconv(bf,locale_map,msgstr,po_map); /* Add to hash table */ htadd(gettext_ht, strdup(msgid), strdup(bf)); } else if (!msgid[0] && msgstr[0]) { unsigned char *p = (unsigned char *)strstr((char *)msgstr, "charset="); if (p) { /* Copy character set name up to next delimiter */ int x; p += sizeof("charset=") - 1; while (*p == ' ' || *p == '\t') ++p; for (x = 0; p[x] && p[x] !='\n' && p[x] != '\r' && p[x] != ' ' && p[x] != '\t' && p[x] != ';' && p[x] != ','; ++x) msgid[x] = p[x]; msgid[x] = 0; po_map = find_charmap(msgid); if (!po_map) po_map = locale_map; } } } } bye: fclose(f); return 0; }
static int load_po(FILE *f) { char buf[1024]; char msgid[1024]; char msgstr[1024]; char bf[8192]; struct charmap *po_map = locale_map; int preload_flag = 0; msgid[0] = 0; msgstr[0] = 0; while (preload_flag || fgets(buf,SIZEOF(buf)-1,f)) { const char *p; preload_flag = 0; p = buf; parse_ws(&p, '#'); if (!parse_field(&p, "msgid")) { ptrdiff_t ofst = 0; ptrdiff_t len; msgid[0] = 0; parse_ws(&p, '#'); while ((len = parse_string(&p, msgid + ofst, SIZEOF(msgid)-ofst)) >= 0) { preload_flag = 0; ofst += len; parse_ws(&p, '#'); if (!*p) { if (fgets(buf,SIZEOF(buf) - 1,f)) { p = buf; preload_flag = 1; parse_ws(&p, '#'); } else { goto bye; } } } } else if (!parse_field(&p, "msgstr")) { ptrdiff_t ofst = 0; ptrdiff_t len; msgstr[0] = 0; parse_ws(&p, '#'); while ((len = parse_string(&p, msgstr + ofst, SIZEOF(msgstr)-ofst)) >= 0) { preload_flag = 0; ofst += len; parse_ws(&p, '#'); if (!*p) { if (fgets(buf,SIZEOF(buf) - 1,f)) { p = buf; preload_flag = 1; parse_ws(&p, '#'); } else { break; } } } if (msgid[0] && msgstr[0]) { /* Convert to locale character map */ my_iconv(bf, SIZEOF(bf), locale_map,msgstr,po_map); /* Add to hash table */ htadd(gettext_ht, zdup(msgid), zdup(bf)); } else if (!msgid[0] && msgstr[0]) { char *tp = zstr(msgstr, "charset="); if (tp) { /* Copy character set name up to next delimiter */ int x; tp += SIZEOF("charset=") - 1; while (*tp == ' ' || *tp == '\t') ++tp; for (x = 0; tp[x] && tp[x] !='\n' && tp[x] != '\r' && tp[x] != ' ' && tp[x] != '\t' && tp[x] != ';' && tp[x] != ','; ++x) msgid[x] = tp[x]; msgid[x] = 0; po_map = find_charmap(msgid); if (!po_map) po_map = locale_map; } } } } bye: fclose(f); return 0; }
/* static */char *stagen(char *stalin, BW *bw, const char *s, char fill) { char buf[80]; int x; int field; W *w = bw->parent; time_t n=time(NULL); struct tm *cas; cas=localtime(&n); stalin = vstrunc(stalin, 0); while (*s) { if (*s == '%' && s[1]) { field = 0; ++s; while (*s >= '0' && *s <= '9' && s[1]) { field = field * 10 + *s - '0'; ++s; } switch (*s) { case 'v': /* Version of JOE */ { joe_snprintf_1(buf, SIZEOF(buf), "%s", VERSION); stalin = vsncpy(sv(stalin), sz(buf)); } break; case 'x': /* Context (but only if autoindent is enabled) */ { if ( bw->o.autoindent) { char *ts = get_context(bw); /* We need to translate between file's character set to locale */ my_iconv(stdbuf, SIZEOF(stdbuf), locale_map,ts,bw->o.charmap); stalin = vsncpy(sv(stalin), sz(stdbuf)); } } break; case 'y': { if (bw->o.syntax) { joe_snprintf_1(buf, SIZEOF(buf), "(%s)", bw->o.syntax->name); stalin = vsncpy(sv(stalin), sz(buf)); } } break; case 't': { time_t curtime = time(NULL); int l; char *d = ctime(&curtime); l = (d[11] - '0') * 10 + d[12] - '0'; if (l > 12) l -= 12; joe_snprintf_1(buf, SIZEOF(buf), "%2.2d", l); if (buf[0] == '0') buf[0] = fill; stalin = vsncpy(sv(stalin), buf, 2); stalin = vsncpy(sv(stalin), d + 13, 3); } break; case 'd': { if (s[1]) switch (*++s) { case 'd' : joe_snprintf_1(buf, SIZEOF(buf), "%02d",cas->tm_mday); break; case 'm' : joe_snprintf_1(buf, SIZEOF(buf), "%02d",cas->tm_mon + 1); break; case 'y' : joe_snprintf_1(buf, SIZEOF(buf), "%02d",cas->tm_year % 100); break; case 'Y' : joe_snprintf_1(buf, SIZEOF(buf), "%04d",cas->tm_year + 1900); break; case 'w' : joe_snprintf_1(buf, SIZEOF(buf), "%d",cas->tm_wday); break; case 'D' : joe_snprintf_1(buf, SIZEOF(buf), "%03d",cas->tm_yday); break; default : buf[0]='d'; buf[1]=*s; buf[2]=0; } else { buf[0]='d'; buf[1]=0; } stalin=vsncpy(sv(stalin),sz(buf)); } break; case 'E': { char *ch; int l; buf[0]=0; for(l=0;s[l+1] && s[l+1] != '%'; l++) buf[l]=s[l+1]; if (s[l+1]=='%' && buf[0]) { buf[l]=0; s+=l+1; ch=getenv(buf); if (ch) stalin=vsncpy(sv(stalin),sz(ch)); } } break; case 'Z': { const char *ch; int l; buf[0]=0; for(l=0;s[l+1] && s[l+1] != '%'; l++) buf[l]=s[l+1]; if (s[l+1]=='%' && buf[0]) { buf[l]=0; s+=l+1; ch=get_status(bw, buf); if (ch) stalin=vsncpy(sv(stalin),sz(ch)); } } break; case 'u': { time_t curtime = time(NULL); char *d = ctime(&curtime); stalin = vsncpy(sv(stalin), d + 11, 5); } break; case 'T': if (bw->o.overtype) stalin = vsadd(stalin, 'O'); else stalin = vsadd(stalin, 'I'); break; case 'W': if (bw->o.wordwrap) stalin = vsadd(stalin, 'W'); else stalin = vsadd(stalin, fill); break; case 'I': if (bw->o.autoindent) stalin = vsadd(stalin, 'A'); else stalin = vsadd(stalin, fill); break; case 'X': if (square) stalin = vsadd(stalin, 'X'); else stalin = vsadd(stalin, fill); break; case 'n': { if (bw->b->name) { char *tmp = simplify_prefix(bw->b->name); char *tmp1 = duplicate_backslashes(sv(tmp)); vsrm(tmp); stalin = vsncpy(sv(stalin), sv(tmp1)); vsrm(tmp1); } else { stalin = vsncpy(sv(stalin), sz(joe_gettext(_("Unnamed")))); } } break; case 'm': if (bw->b->changed) stalin = vsncpy(sv(stalin), sz(joe_gettext(_("(Modified)")))); break; case 'R': if (bw->b->rdonly) stalin = vsncpy(sv(stalin), sz(joe_gettext(_("(Read only)")))); break; case '*': if (bw->b->changed) stalin = vsadd(stalin, '*'); else stalin = vsadd(stalin, fill); break; case 'r': if (field) #ifdef HAVE_LONG_LONG joe_snprintf_1(buf, SIZEOF(buf), "%-4lld", (long long)(bw->cursor->line + 1)); #else joe_snprintf_1(buf, SIZEOF(buf), "%-4ld", (long)(bw->cursor->line + 1)); #endif else #ifdef HAVE_LONG_LONG joe_snprintf_1(buf, SIZEOF(buf), "%lld", (long long)(bw->cursor->line + 1)); #else joe_snprintf_1(buf, SIZEOF(buf), "%ld", (long)(bw->cursor->line + 1)); #endif for (x = 0; buf[x]; ++x) if (buf[x] == ' ') buf[x] = fill; stalin = vsncpy(sv(stalin), sz(buf)); break; case 'o': if (field) #ifdef HAVE_LONG_LONG joe_snprintf_1(buf, SIZEOF(buf), "%-4lld", (long long)bw->cursor->byte); #else joe_snprintf_1(buf, SIZEOF(buf), "%-4ld", (long)bw->cursor->byte); #endif else #ifdef HAVE_LONG_LONG joe_snprintf_1(buf, SIZEOF(buf), "%lld", (long long)bw->cursor->byte); #else joe_snprintf_1(buf, SIZEOF(buf), "%ld", (long)bw->cursor->byte); #endif for (x = 0; buf[x]; ++x) if (buf[x] == ' ') buf[x] = fill; stalin = vsncpy(sv(stalin), sz(buf)); break; case 'O': if (field) #ifdef HAVE_LONG_LONG joe_snprintf_1(buf, SIZEOF(buf), "%-4llX", (unsigned long long)bw->cursor->byte); #else joe_snprintf_1(buf, SIZEOF(buf), "%-4lX", (unsigned long)bw->cursor->byte); #endif else
void getipaddr(char *start, char **countrybuf, char **areabuf) { char *pos, *p_country = NULL, *p_area = NULL, buf[2][128]; memset(buf, 0, sizeof(buf)); unsigned int offset; int len[2]; offset = getlong3(start); pos = p_share + offset + 4; char *byte = pos; // 标志字节 pos++; switch (*byte) { case 1:{ // 标志字节为1,表示国家和区域信息都被同时重定向 int countryOffset = getlong3(pos); // 重定向地址 pos+=3; pos=p_share+countryOffset; byte = pos; // 标志字节 pos++; switch (*byte) { case 2: // 标志字节为2,表示国家信息又被重定向 { p_country=p_share+getlong3(pos); pos=p_share+countryOffset+4; p_area = getarea(pos); } break; default: // 否则,表示国家信息没有被重定向 { p_country=byte; p_area = getarea(p_country+strlen(p_country)+1); } break; } } break; case 2: // 标志字节为2,表示国家信息被重定向 { p_country=p_share+getlong3(pos);// 重定向地址 pos = p_share + offset + 8; p_area = getarea(pos); } break; default:{ // 否则,表示国家信息没有被重定向 p_country=byte; p_area=getarea(p_country+strlen(p_country)+1); } break; } if (codetype == GBK_t){ my_iconv("utf8", "gbk", buf[0], sizeof(buf[0]), p_country, strlen(p_country)); my_iconv("utf8", "gbk", buf[1], sizeof(buf[1]), p_area, strlen(p_area)); //printf("buf:%s %s, %d %d\n", buf[0], buf[1], strlen(buf[0]), strlen(buf[1])); len[0] = strlen(buf[0]), len[1] = strlen(buf[1]); if (len[0]){ *countrybuf = (char *)malloc(len[0] + 1); if (!(*countrybuf)){ perror("malloc"); exit(1); } memcpy(*countrybuf, buf[0], len[0]+1); }else { *countrybuf = NULL; } if (len[1]){ *areabuf = (char *)malloc(len[1] + 1); if (!(*areabuf)){ perror("malloc"); exit(1); } memcpy(*areabuf, buf[1], len[1]+1); }else { *areabuf = NULL; } }else if (codetype == UTF_t){ len[0] = strlen(p_country), len[1] = strlen(p_area); if (len[0]){ *countrybuf = (char *)malloc(len[0] + 1); if (!(*countrybuf)){ perror("malloc"); exit(1); } memcpy(*countrybuf, p_country, len[0]+1); }else { *countrybuf = NULL; } if (len[1]){ *areabuf = (char *)malloc(len[1] + 1); if (!(*areabuf)){ perror("malloc"); exit(1); } memcpy(*areabuf, p_area, len[1]+1); }else { *areabuf = NULL; } } //printf("areabuf:%s %s\n", *countrybuf, *areabuf); }
void create_view(void) { // Window win, ewin; Evas *evas; Ecore_Evas * ee; int x, y, w, h, res; int maxcol; int engine; char *fontdir; int font_cache, image_cache; char buf[4096]; char *s; E_DB_INT_GET(shell->rcfile, "/main_win/win_x", x, res); ENGY_ASSERT(res); E_DB_INT_GET(shell->rcfile, "/main_win/win_y", y, res); ENGY_ASSERT(res); E_DB_INT_GET(shell->rcfile, "/main_win/win_w", w, res); ENGY_ASSERT(res); E_DB_INT_GET(shell->rcfile, "/main_win/win_h", h, res); ENGY_ASSERT(res); E_DB_STR_GET(shell->rcfile, "/aliases", (shell->aliases), res); ENGY_ASSERT(res); E_DB_INT_GET(shell->rcfile, "/maxcolors", maxcol, res); ENGY_ASSERT(res); E_DB_INT_GET(shell->rcfile, "/rendermethod", engine, res); ENGY_ASSERT(res); if (render_method != -1) engine = render_method; E_DB_INT_GET(shell->rcfile, "/maximagecache", image_cache, res); ENGY_ASSERT(res); E_DB_INT_GET(shell->rcfile, "/maxfontcache", font_cache, res); ENGY_ASSERT(res); E_DB_STR_GET(shell->rcfile, "/fontdir", s, res); ENGY_ASSERT(res); if (s[0] != '/') { snprintf(buf, 4000,"%s/%s", shell->home, s); imlib_add_path_to_font_path(buf); fontdir = DUP(buf); } else { imlib_add_path_to_font_path(s); fontdir = DUP(s); } FREE(s); /* win = ecore_window_new(0, x, y, w, h); ecore_window_set_events(win, XEV_CONFIGURE | XEV_KEY); evas = evas_new_all(ecore_display_get(), win, 0, 0, w, h, engine, maxcol, font_cache, image_cache, fontdir); ENGY_ASSERTS(evas, "evas_new"); FREE(fontdir); evas_set_output_viewport(evas, 0, 0, w, h); ewin = evas_get_window(evas); ecore_window_set_events(ewin, XEV_EXPOSE | XEV_BUTTON | XEV_MOUSE_MOVE); */ if (!ecore_x_init(NULL)) exit(-1); //LOG_AND_RETURN (ERR_EFL); if (!ecore_evas_init()) exit(-1); //LOG_AND_RETURN (ERR_EFL); ee = ecore_evas_software_x11_new(NULL, 0, 0, 0, 640, 480); if (!ee) exit(-1); //LOG_AND_RETURN (ERR_EFL); evas = ecore_evas_get(ee); evas_font_path_prepend(evas, fontdir); FREE(fontdir); ecore_evas_callback_delete_request_set(ee, engy_delete_request); ecore_evas_callback_pre_render_set(ee, engy_pre_rend); ecore_evas_callback_post_render_set(ee, engy_post_rend); ecore_evas_callback_resize_set(ee, engy_resize); ecore_evas_name_class_set(ee, "engy", "main"); ecore_evas_show(ee); _get_title_dcd(); shell->title = my_iconv(shell->title_dcd, TITLE); ecore_evas_title_set(ee, shell->title); shell->evas = evas; shell->win = ecore_evas_software_x11_window_get(ee); shell->ee = ee; shell->w = w; shell->h = h; // GLS // ecore_set_blank_pointer(win); // ecore_window_set_title(win, shell->title); // my_evas_init(); _shell_bg_create(); menu_init(); // GLS engy_cl_init(); cl_configure(w, h); log_init(); info_init(); info_sync(); panel_init(); pointer_init(); serv_init(); logo_init(); alias_init(); // evas_render(shell->evas); }