找回密码
 注册
X系列官方授权正版
搜索
查看: 4503|回复: 3

[原创] Code... nickname->strid

[复制链接]
发表于 2008-11-14 21:54:00 | 显示全部楼层 |阅读模式
  1. // Nov 14, 2008 - by Euyis. [6 V0 Z) S. G$ F
  2. ) ]1 f. S# Q  S
  3. //. r( z' p6 d8 a$ G% C
  4. // I, the copyright holder of this work, hereby release it into the public domain. This applies worldwide.* [  P+ p3 _6 U5 [
  5. // In case this is not legally possible,7 g9 X. Z7 w6 B8 s" n4 b0 t0 d
  6. // I grant any entity the right to use this work for any purpose, without any conditions, unless such conditions are required by law.' Q6 y2 T+ `: Q8 s. @0 e$ w
  7. //7 ~3 C& k+ d: ?( E  m, j

  8. 7 N- @# m2 S0 c- N: E
  9. #include <iostream>5 e0 O5 S$ ?7 g2 n0 b1 w+ B
  10. #include <fstream>' I5 U5 G, @# c0 I+ ^2 J
  11. #include <cctype>* r: W! B  {, H- v! o) V
  12. using namespace std;  w& [7 P" v6 g0 G
  13. ' d5 D% ~# B7 `* ]+ z" y
  14. // MACROS. X1 d" h8 P9 ]( ]+ q  B8 w" p
  15. #define SYSTEM_BLOCK_STR "[system]"
    8 O" j5 o# P/ I
  16. #define NICKNAME_STR "nickname = "
    0 j3 i' _1 ?& v' e/ \# y; ?: n
  17. #define IDS_STR "strid_name = "; V; l1 Y6 j7 K7 e1 e8 `
  18. //
    9 `0 ?0 e; l8 P; S* i9 n4 K

  19. / j* J# ?7 t, v" ?: V  w/ X) _
  20. ifstream inf;6 _- ~0 P! K1 Y" H2 s0 c+ J
  21. char *buffer;# [" _3 }, d" k2 Z. v, k" S
  22. 2 e' g2 C9 e" l
  23. int main(int argc, char *argv[])
    3 C" |% z7 ~( W( P3 L7 K$ o
  24. {% e' U/ }- x; o' d& Z
  25.         int i;
    ( [. v* O" D- \) m, o
  26.         4 U4 ^' s& I$ P8 H5 N
  27.         if(argc!=2){
    ) P$ f- d8 T5 ?( Z$ c/ d& @
  28.                 cout << "This program requires one and only one argument.";* X9 Z! r: d% @8 e" M
  29.                 return -1;( C& v" T( c+ L9 o- o" U7 z  @
  30.                 }
    ' b8 D$ L6 q; |* X
  31.         # x; ~- y4 f1 R- j8 z
  32.         inf.open(argv[1], ios_base::in | ios_base::ate);
    % K6 C. f3 i' J1 G
  33.         if(!inf) {3 R7 ~2 j0 m( e6 z% Z: A  [5 Q/ C$ C
  34.                 cout << "Error opening file.";
    ; C1 T& l9 i1 g/ `
  35.                 return -1;' h) G6 M5 i; J) u) |& k9 {, E
  36.                 }
    # Z% T' H" {- @) |/ B6 v
  37.                
    % p2 w6 E3 j; [
  38.         int streamLength = inf.tellg();6 ~2 z3 y+ w. o/ ^
  39.         if(streamLength!=-1) {
    ; }  e' W$ x; e, m
  40.                 inf.seekg(0, ios::beg);
    3 i0 L3 H. p8 {
  41.                 6 O# x5 }/ u+ c$ c. g* U
  42.                 buffer = new char [streamLength];8 g! u. S7 q$ s. I6 y( x/ t, h2 {3 ^9 m/ z$ l
  43.                 // Read file;* z$ d2 l( p4 ~3 N) F
  44.                 for(i=0;i<streamLength;i++) {
    9 A8 W6 W9 W+ S7 a$ v
  45.                         inf.get(buffer[i]);
    & c# z# s. p0 _
  46.                         buffer[i] = tolower(buffer[i]);7 [0 V. @" V, G
  47.                         }
    5 b( F8 Y6 s& o3 t0 ]6 s
  48.                
    % _$ |# }" S' }% }
  49.                 /* For testing- |4 t5 b1 j5 z! g: w6 S
  50.                 for(i=0;i<streamLength;i++) {9 T7 c4 B2 z- i* d  S) D
  51.                         cout << buffer[i];. J# v7 Q! Y% Q5 I
  52.                 }
    7 J& B0 h! g/ _5 {( m% J
  53.                 */
    # E* b. g  u7 S
  54.                 }6 T" W) g& q% j2 b
  55.         else {' O; B+ c' h1 _0 F5 G# ]( h5 M
  56.         cout << "Failed to read file." << endl;
    & Y) t( `' v8 Q) O. ~+ w1 O
  57.         return -1;
    1 a' `$ |! [( W, e; L0 @
  58.         }
      I2 X) T$ f, _6 Q
  59.        
    7 q( s5 b' z9 Z6 ?: K
  60.         string processStr (buffer);
    8 b' @4 J$ R6 n* o1 n) I3 g7 V+ d2 W
  61.         delete [] buffer;
    $ }9 N  w4 u; R- b3 P* C
  62.           |8 A( o8 k  V5 b# X
  63.         // DUMB DUMB DUMB....2 J  |' t7 T; G" a! D# p: ?
  64.         4 m7 q7 L: ?, y2 i5 g; g1 r7 s
  65.         int nextSearchPos = 0;2 }, c. G  ]; \0 l
  66.         int tmpSearchPos[2] = {0};+ e# \0 Q% t: d+ m0 E2 |/ F
  67.         int entriesCount = 0;
    9 u0 Y1 Y, q& J9 U$ I- f
  68.         ; N- v7 T$ m/ m! a" W; w
  69.         # X+ k( t8 F: x: g
  70.        
    - N. j* [6 z: p& b! h
  71.         while(processStr.find(SYSTEM_BLOCK_STR, nextSearchPos)!=string::npos) {$ ^5 N3 D/ Q5 l% M  e
  72.                 nextSearchPos = processStr.find(SYSTEM_BLOCK_STR, nextSearchPos)+8;( p: C4 m  x$ l" X" x
  73.                 tmpSearchPos[0] = processStr.find(NICKNAME_STR, nextSearchPos);
    # S, c" K2 ?, q& j
  74.                 tmpSearchPos[1] = processStr.find(IDS_STR, nextSearchPos);
    2 T5 o* ?+ N7 b  Z6 v9 M) E
  75.                 + x% V9 H& R5 ^4 `
  76.                 if(tmpSearchPos[0]!=string::npos) {; E- b6 ^# I0 p0 I9 g1 K
  77.                         i=tmpSearchPos[0]+11;# r2 ]& j4 G1 M# N/ }/ E( ^. n, [
  78.                        
    $ Q1 e3 I4 w; q7 d1 Z0 @
  79.                         while(processStr[i]!='\n' && processStr[i]!='\r') {; V+ l) B* I+ T" ?9 I0 ^
  80.                         cout << processStr[i];
    0 X+ M% c- l9 i
  81.                         i++;
    & z0 K) x/ ?) p& _4 i0 Q& b: q
  82.                         }
    1 Y) d3 k& _- e& w+ m8 Y3 k
  83.                        
    ; D- @7 M/ ^) E
  84.                         cout << endl;
    8 x* R: j0 B9 f" p; |
  85.                         4 Q5 u8 J& P9 n7 L! S+ A
  86.                 }
    . b* w" w# r( C* z- J' [/ I' B' D  A
  87.                
    ' w5 a6 e# R0 e0 {! k) J) d  L
  88.                 if(tmpSearchPos[1]!=string::npos) {
    ; _6 e- K9 q$ r
  89.                         i=tmpSearchPos[1]+13;
    ' R& f% k% u( Q  V' u1 k6 d2 I  f
  90.                        
    - U/ {: _+ c1 Z! U1 {
  91.                         while(processStr[i]!='\n' && processStr[i]!='\r') {
    , d# x2 t6 ?8 q9 q
  92.                         cout << processStr[i];
    $ l4 L1 n" ?; X* m4 v; |% Z* Q1 y
  93.                         i++;# Z, T0 ?1 ]" g( G6 t9 I
  94.                         }! Q, w3 @& ~9 X7 c7 k, O' S1 y
  95.                        
    " l5 l, d1 `9 ]4 k; Z( N: u6 s$ @# J
  96.                         cout << endl;
    " x3 h* [' E% Y+ a( [: f
  97.                        
    5 i) c% E5 Q0 w5 J: @, E
  98.                 }
    6 B" k  M* p6 E* Y
  99.                 - E2 A8 K+ V1 c% X
  100.                 entriesCount++;, m/ ]- W  H0 k
  101.         }
    1 O$ R5 c/ `  B* A- j$ b4 |
  102.        
    1 S6 U8 H/ m7 E5 x& c/ ~/ }2 i4 X
  103.         cout<<entriesCount;8 w- d/ X  d" ?0 J
  104.         return 0;
    + ^4 ^( @& O: D; ~- n$ o$ E
  105.        
    - L% g, f7 `* M$ k
  106. }
复制代码
Update: 最后一行输出条目数.% r% @9 u' l7 d% k

) \; }# h) _  q[ 本帖最后由 Euyis 于 2008-11-14 22:21 编辑 ]
发表于 2008-11-14 22:04:49 | 显示全部楼层
LOL and WOW, THANKS!!
回复

使用道具 举报

发表于 2009-4-27 21:23:42 | 显示全部楼层
做什么用的啊,看不懂。。。。。楼上高手帮忙讲解一下,谢谢
回复

使用道具 举报

发表于 2009-4-27 21:44:32 | 显示全部楼层
用Nickname来查找DLL里面的Res ID
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

站长推荐上一条 /1 下一条

Archiver|手机版|小黑屋|DeepTimes.NET 太空游戏站