/* * Hack -- read a string */ static void rd_string(char *str, int max) { int i; /* Read the string */ for (i = 0; TRUE; i++) { byte tmp8u; /* Read a byte */ rd_byte(&tmp8u); /* Collect string while legal */ if (i < max) str[i] = tmp8u; /* End of string */ if (!tmp8u) break; } /* Terminate */ str[max-1] = '\0'; #ifdef JP /* Convert Kanji code */ switch (kanji_code) { #ifdef SJIS case 2: /* EUC to SJIS */ euc2sjis(str); break; #endif #ifdef EUC case 3: /* SJIS to EUC */ sjis2euc(str); break; #endif case 0: { /* 不明の漢字コードからシステムの漢字コードに変換 */ byte code = codeconv(str); /* 漢字コードが判明したら、それを記録 */ if (code) kanji_code = code; break; } default: /* No conversion needed */ break; } #endif }
char * any2sjis( const char *p ) { char *q; q = utf2sjis( p ); if ( !q ) { // p の charset は UTF-8 ではない if ( strstr( p, "\033$@" ) || strstr( p, "\033$B" ) ) q = jis2sjis( p ); else { q = euc2sjis( p ); if ( !q ) q = (char *)p; // すでに Shift_JIS 変換済み(とみなす) } } return ( q ); }
char * any2utf( const char *p ) { char *q; q = utf2sjis( p ); if ( q ) q = (char *)p; // すでに UTF-8 変換済み else { // p の charset は UTF-8 ではない if ( strstr( p, "\033$@" ) || strstr( p, "\033$B" ) ) q = jis2utf( p ); else { q = euc2sjis( p ); if ( q ) q = euc2utf( p ); if ( !q ) q = sjis2utf( p ); if ( !q && p ) { /* 以下、Vox 対策 */ char *r = (char *)malloc( strlen(p) * 12 + 1 ); if ( r ) { char *s; strcpy( r, p ); s = utf2sjisEx( r ); /* (主として) ç 対策 */ if ( s ) q = sjis2utf( s ); free( r ); } } if ( !q ) q = (char *)p; } } return ( q ); }
int getBlogIDsRakuten( const char *userName, // (I) ユーザ名 const char *password, // (I) パスワード int *numberOfBlogs, // (I) 取得する/取得した blog 情報の数 BLOGINF *blogInfo ) // (O) 取得した blog 情報 { char cookie[MAX_COOKIE_LEN]; char url[MAX_URLLENGTH]; int numOfBlogs = 0; cookie[0] = NUL; url[0] = NUL; loginRakuten( userName, password, cookie, url ); if ( url[0] ) { size_t sz = MAX_CONTENT_SIZE; char *response; strcpy( blogInfo[0].url, url ); blogInfo[0].blogName[0] = NUL; blogInfo[0].blogID[0] = NUL; response = (char *)malloc( sz ); if ( response ) { setUpReceiveBuffer( response, sz ); http_get( url, response ); if ( *response ) { char target[BUFSIZ]; const char *p, *q; target[0] = NUL; p = strstr( response, "<td class=\"title_text\" id=\"title\">" ); if ( p ) { p += 34; while ( (*p == ' ') || (*p == '\t') || (*p == '\r') || (*p == '\n') ) p++; q = strstr( p, "</td>" ); if ( q ) { while ( (q > p) && ( (*(q - 1) == ' ') || (*(q - 1) == '\t') || (*(q - 1) == '\r') || (*(q - 1) == '\n') ) ) q--; strncpy( target, p, q - p ); target[q - p] = NUL; } } else { p = strstr( response, "<title>" ); if ( p ) { p += 7; q = strstr( p, sjis2euc(" - 楽天") ); if ( q ) { strncpy( target, p, q - p ); target[q - p] = NUL; } } else { p = strstr( response, " id=\"counter\">" ); if ( p ) { p += 14; p = strstr( p, "<font color=\"" ); if ( p ) { p = strchr( p + 13, '>' ); if ( p ) { p++; q = strstr( p, sjis2euc(" 楽天") ); if ( q ) { strncpy( target, p, q - p ); target[q - p] = NUL; } } } } } } if ( target[0] ) { p = euc2sjis( target ); strcpy( blogInfo[0].blogName, p ? p : target ); } } free( response ); } numOfBlogs = 1; } *numberOfBlogs = numOfBlogs; return ( numOfBlogs ); }
BOOL getTagsFrom1470net( const char *url, /* (I) 当該WebページのURL */ char **tags, /* (O) タグ候補 */ char **hatenaTags,/* (I/O) はてブから取得したタグ候補 */ int *curNum, /* (I/O) 今までに取得済みのタグ候補の数 */ int numOfTags, /* (I) 取得しようとしているタグ候補の数 */ char *response, /* (O) 受信バッファ */ size_t sz /* (I) 受信バッファのサイズ */ ) { BOOL stat1470net = TRUE; BOOL recover = FALSE; char *p, *q; char *targetURL; int num = *curNum; p = encodeURL( url ); targetURL = (char *)malloc( strlen( p ) + 128 ); if ( !targetURL ) return ( stat1470net ); // http://1470.net/api/mmutil.php?cmd=getwords;url=[URL] を GET sprintf( targetURL, "http://1470.net/api/mmutil.php?cmd=getwords&url=%s", p ); setUpReceiveBuffer( response, sz ); http_get( targetURL, response ); if ( response[0] && (strncmp( response, "<a ", 3 ) != 0) && !strstr( response, "<li>Not Found</li>" ) ) { /* 注意: http://1470.net/api/mmutil.php がサービス停止中の場合は */ /* <a href="http://tdiary.ishinao.net/">blog</a>. のような */ /* 内容の response が返ってくる */ /* --- 2007年4月25日現在、<li>Not Found</li> を含む応答が返っ */ /* てくる (サービス停止中?) */ p = euc2sjis( response ); if ( !p ) { p = response; recover = TRUE; } while ( *p ) { q = tags[num]; while ( *p && (*p != '\t') && (*p != '\r') && (*p != '\n') ) *q++ = *p++; *q = NUL; if ( recover ) { q = euc2sjis( tags[num] ); if ( q ) strcpy( tags[num], q ); else goto next; } normalizeTag( tags[num] ); if ( strlen( tags[num] ) <= 2 ) goto next; if ( hatenaTags && *hatenaTags ) { // 重複チェック int i; for ( i = 0; i < num; i++ ) { if ( !strcmp( tags[i], tags[num] ) ) goto next; } } num++; if ( num >= numOfTags ) break; if ( (*p == '\t') || (*p == '\r') || (*p == '\n') ) { next: while ( *p && ((*p == '\t') || (*p == '\r') || (*p == '\n')) ) p++; if ( *p ) continue; } break; } *curNum = num; } else stat1470net = FALSE; free( targetURL ); return ( stat1470net ); }
void getHatenaKeywordLink( const char *body, /* (I) 解析対象 */ char **tags, /* (O) タグ候補 */ int *curNum, /* (I/O) 今までに取得済みのタグ候補の数 */ int numOfTags, /* (I) 取得しようとしているタグ候補の数 */ BOOL striped /* (I) すでに stripTags 済みか否か */ ) { /* キーワードリンク埋め込み */ char *p, *result; size_t sz = ((body && *body) ? strlen( body ) : MAX_CONTENT_SIZE) * 32; result = (char *)malloc( sz ); if ( result ) { const char *q = body; if ( !striped ) { p = any2utf( body ); q = stripTags( p ? p : body ); } memset( result, 0x00, sz ); p = setKeywordLink( q, result, sz, 0, CNAME_GENERAL, "_blank", "hatena" ); if ( p && *p && strcmp( p, "(null)" ) ) { if ( !strncmp( p, ";lt=;lt=", 8 ) ) { /* 文字化け検出 */ free( result ); return; } else utf2sjisEx( p ); } else { #if 0 /* はてなダイアリーキーワード自動リンクAPIが */ /* 機能していない場合 */ char *q; size_t len = 0; memset( result, 0x00, sz ); p = changeHatenaKeyword( body, result, MODE_HTML ); q = euc2sjis( p ); if ( !q ) q = any2sjis( p ); if ( q && *q ) len = strlen( q ); if ( len >= sz - 1 ) { strncpy( result, q, sz - 1 ); result[sz - 1] = NUL; } else if ( len > 0 ) strcpy( result, q ); #else /* http://d.hatena.ne.jp/images/keyword/keywordlist のフォー */ /* マットが変更されているため、changeHatenaKeyword() がうまく */ /* 機能しなくなっている (変更時期不明) */ *result = NUL; /* 暫定対処 */ #endif } if ( *result ) { /* キーワードを抜き出す */ BOOL found; char *q; int i; int num = *curNum; p = any2sjis( result ); p = strstr( p ? p : result, "<a class=\"hatena\" " ); while ( p ) { p += 18; q = strchr( p, '>' ); if ( !q ) break; p = q + 1; q = strstr( p, "</a>" ); if ( !q ) break; strncpy( tags[num], p, q - p ); tags[num][q - p] = NUL; normalizeTag( tags[num] ); found = FALSE; for ( i = 0; i < num; i++ ) { if ( !strcmp( tags[i], tags[num] ) ) { found = TRUE; break; } } if ( found == FALSE ) { num++; if ( num >= numOfTags ) break; } q += 4; p = strstr( q, "<a class=\"hatena\" " ); } *curNum = num; } free( result ); } }
void orcqrencode(char *ctx) { int version; int level; int hint; int size; int margin; int i; int doEncodeStructured; char buf[MAX_DATA_SIZE]; char buf2[MAX_DATA_SIZE]; char qrfile[SIZE_QRFILE]; char qrfile_suffix[SIZE_QRFILE + 10]; char *p; QRcode *code; QRcode_List *head, *entry; OPENLOG; if((p = strchr(CTX(ctx, OFFSET_INFILE), ' ')) != NULL) *p = '\0'; if((p = strchr(CTX(ctx, OFFSET_QRFILE), ' ')) != NULL) *p = '\0'; memset(CTX(ctx, OFFSET_RET_CODE), QRENCODE_OK, SIZE_RET_CODE); if(euc2sjis(CTX(ctx, OFFSET_INFILE), buf) != 0){ memset(CTX(ctx, OFFSET_RET_CODE), CHAR_CONV_ERROR, SIZE_RET_CODE); return; } hint = ctx_string2int(ctx, OFFSET_HINT, SIZE_HINT); if (hint < 2) { if(parse_csv(buf, buf2) !=0){ memset(CTX(ctx, OFFSET_RET_CODE), KANA_CONV_ERROR, SIZE_RET_CODE); return; } } else { lf2crlf(buf,buf2); } snprintf(qrfile, SIZE_QRFILE, "%s", CTX(ctx, OFFSET_QRFILE)); version = ctx_string2int(ctx, OFFSET_VERSION, SIZE_VERSION); if(version <= 0 || version > 40){ memset(CTX(ctx, OFFSET_RET_CODE), PARAM_ERROR, SIZE_RET_CODE); return; } switch(*CTX(ctx, OFFSET_LEVEL)){ case 'L': level = QR_ECLEVEL_L; break; case 'M': level = QR_ECLEVEL_M; break; case 'Q': level = QR_ECLEVEL_Q; break; case 'H': level = QR_ECLEVEL_H; break; default: level = QR_ECLEVEL_L; } p = strrchr(qrfile, '.'); if(p != NULL)*p = '\0'; doEncodeStructured = ctx_string2int(ctx, OFFSET_STRUCTURED, SIZE_STRUCTURED); hint = (hint % 2) == 0 ? QR_MODE_KANJI : QR_MODE_8; size = ctx_string2int(ctx, OFFSET_PIXEL, SIZE_PIXEL); margin = ctx_string2int(ctx, OFFSET_MARGIN, SIZE_MARGIN); code = QRcode_encodeString(buf2, version, level, hint, 1); if (code != NULL) { if (code->version <= version) { snprintf(qrfile_suffix, sizeof(qrfile_suffix), "%s_%02d.png", qrfile, 1); if(writePNG(code, qrfile_suffix, size, margin) != 0){ memset(CTX(ctx, OFFSET_RET_CODE), WRITE_PNG_ERROR, SIZE_RET_CODE); QRcode_free(code); return; } SYSLOG("write single image"); sprintf(buf, "%02d" , code->version); memcpy(CTX(ctx, OFFSET_RET_VERSION), buf, SIZE_RET_VERSION); sprintf(buf, "%02d" , 1); memcpy(CTX(ctx, OFFSET_RET_SYMBOLS), "01", SIZE_RET_SYMBOLS); QRcode_free(code); return; } QRcode_free(code); } if (doEncodeStructured) { head = QRcode_encodeStringStructured(buf2, version, level, hint ,1); if(head) { entry = head; i = 0; while(entry != NULL) { code = entry->code; snprintf(qrfile_suffix, sizeof(qrfile_suffix), "%s_%02d.png", qrfile, i + 1); if(writePNG(code, qrfile_suffix, size, margin) != 0){ memset(CTX(ctx, OFFSET_RET_CODE), WRITE_PNG_ERROR, SIZE_RET_CODE); break; } entry = entry->next; i++; } SYSLOG("write multi images"); QRcode_List_free(entry); } else { memset(CTX(ctx, OFFSET_RET_CODE), QRENCODE_ERROR, SIZE_RET_CODE); return; } sprintf(buf, "%02d" , head->code->version); memcpy(CTX(ctx, OFFSET_RET_VERSION), buf, SIZE_RET_VERSION); sprintf(buf, "%02d" , i); memcpy(CTX(ctx, OFFSET_RET_SYMBOLS), buf, SIZE_RET_SYMBOLS); QRcode_List_free(head); } #if 1 print_ctx(ctx); #endif SYSLOG("end"); return; }
static bool flush_ringbuf_client(void) { char buf[1024]; /* 書くデータなし */ if (fresh_queue.next == fresh_queue.tail) return (FALSE); /* まだ書くべき時でない */ if (fresh_queue.time[fresh_queue.next] > get_current_time() - epoch_time) return (FALSE); /* 時間情報(区切り)が得られるまで書く */ while (get_nextbuf(buf)) { char id; int x, y, len, col; int i; unsigned char tmp1, tmp2, tmp3, tmp4; char *mesg; sscanf(buf, "%c%c%c%c%c", &id, &tmp1, &tmp2, &tmp3, &tmp4); x = tmp1-1; y = tmp2-1; len = tmp3; col = tmp4; if (id == 's') { col = tmp3; mesg = &buf[4]; } else mesg = &buf[5]; #ifndef WINDOWS win2unix(col, mesg); #endif switch (id) { case 't': /* 通常 */ #ifdef SJIS euc2sjis(mesg); #endif update_term_size(x, y, len); (void)((*angband_term[0]->text_hook)(x, y, len, (byte)col, mesg)); strncpy(&Term->scr->c[y][x], mesg, len); for (i = x; i < x+len; i++) { Term->scr->a[y][i] = col; } break; case 'n': /* 繰り返し */ for (i = 1; i < len; i++) { mesg[i] = mesg[0]; } mesg[i] = '\0'; update_term_size(x, y, len); (void)((*angband_term[0]->text_hook)(x, y, len, (byte)col, mesg)); strncpy(&Term->scr->c[y][x], mesg, len); for (i = x; i < x+len; i++) { Term->scr->a[y][i] = col; } break; case 's': /* 一文字 */ update_term_size(x, y, 1); (void)((*angband_term[0]->text_hook)(x, y, 1, (byte)col, mesg)); strncpy(&Term->scr->c[y][x], mesg, 1); Term->scr->a[y][x] = col; break; case 'w': update_term_size(x, y, len); (void)((*angband_term[0]->wipe_hook)(x, y, len)); break; case 'x': if (x == TERM_XTRA_CLEAR) Term_clear(); (void)((*angband_term[0]->xtra_hook)(x, 0)); break; case 'c': update_term_size(x, y, 1); (void)((*angband_term[0]->curs_hook)(x, y)); break; case 'C': update_term_size(x, y, 1); (void)((*angband_term[0]->bigcurs_hook)(x, y)); break; } } fresh_queue.next++; if (fresh_queue.next == FRESH_QUEUE_SIZE) fresh_queue.next = 0; return (TRUE); }