/*获取文件的长度*/ int getflen(){ long i; file *p; if (ismulti() == 1){ if (file_head == NULL){ getflap(); } p = file_head; while (p != NULL){ file_size += p->len; p = p -> next; } }else { if (findkey("6:length",&i) == i) { i = i + strlen("6:length"); i++; //跳过i while(torrent_content[i] != 'e'){ file_size = file_size * 10 + torrent_content[i] - '0'; i++; } } } #ifdef DEBUG printf("file length:%lld\n",file_size); #endif return 0; }
/*对于多文件,获取文件的长度和名字*/ int getflap(){ long i; int count,length; file *node = NULL,*p = NULL; if (ismulti() != 1){ return 0; } for (i=0; i<torrent_length - 8; i++){ if (memcmp(&torrent_content[i],"6:length",8) == 0){ i = i + 8; i++; length = 0; while (torrent_content[i] != 'e'){ length = length * 10 + (torrent_content[i] - '0'); i++; } node = (file *)malloc(sizeof(file)); node -> len = length; node -> next = NULL; if (file_head == NULL){ file_head = node; }else{ p = file_head; while (p->next != NULL){ p = p->next; } p->next = node; } } if (memcmp(&torrent_content[i],"4:path",6) == 0){ i = i + 6; i++; count = 0; while (torrent_content[i] != ':'){ count = count * 10 + (torrent_content[i] - '0'); i++; } i++; p = file_head; while (p->next != NULL){ p = p->next; } memcpy(p->path,&torrent_content[i],count); *(p->path + count) = '\0'; } } return 0; }
VimMByte::ChClass VimMByte::chclass(wchar_t c) { if (!ismulti(c)) { if (iswblank(c) || c == L'\n') { return VimMByte::BLANK_LF; } if (iswalnum(c) || c == L'_') { return VimMByte::ASCII_WORD; } return VimMByte::OTHER; } if (c == L'、' || c == L'。' || c == L',' || c == L'.') { return VimMByte::PUNCT; } // TODO: Support JA_KANJI etc. return VimMByte::OTHER; }
int rtorrent(char *torrent){ int ret; ret = readtorr(torrent); if (ret < 0) { printf("%s:%d wrong:",__FILE__,__LINE__); return -1; } ret = getann(); if (ret < 0) { printf("%s:%d wrong:",__FILE__,__LINE__); return -1; } ret = ismulti(); if (ret < 0) { printf("%s:%d wrong:",__FILE__,__LINE__); return -1; } ret = getpilen(); if (ret < 0) { printf("%s:%d wrong:",__FILE__,__LINE__); return -1; } ret = getpihash(); if (ret < 0) { printf("%s:%d wrong:",__FILE__,__LINE__); return -1; } ret = getfname(); if (ret < 0) { printf("%s:%d wrong:",__FILE__,__LINE__); return -1; } ret = getflap(); if (ret < 0){ printf("%s:%d wrong:",__FILE__,__LINE__); return -1; } ret = getflen(); if (ret < 0){ printf("%s:%d wrong:",__FILE__,__LINE__); return -1; } ret = getinhash(); if (ret < 0){ printf("%s:%d wrong:",__FILE__,__LINE__); return -1; } ret = getpeid(); if (ret < 0){ printf("%s:%d wrong:",__FILE__,__LINE__); return -1; } return 0; }