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

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

[复制链接]
发表于 2008-11-14 21:54:00 | 显示全部楼层 |阅读模式
  1. // Nov 14, 2008 - by Euyis
    , G& r& L8 v# c! U. x1 S

  2. 0 R7 q5 ]7 J$ r) w" t* V
  3. //
    ) l/ Y9 _; B$ T: Q1 ]
  4. // I, the copyright holder of this work, hereby release it into the public domain. This applies worldwide.
    7 {; }) R, {+ J' Z9 h5 P
  5. // In case this is not legally possible,
    0 C( v7 t" x7 {$ L. g) Z
  6. // I grant any entity the right to use this work for any purpose, without any conditions, unless such conditions are required by law.9 |7 u* r7 B0 r# a2 f9 Q3 _
  7. //
    # _9 l. k* N' U/ n0 ^/ o

  8. % t( U0 P5 w; {1 Z
  9. #include <iostream>
    ( w7 I& P# [# h
  10. #include <fstream>
    2 b; }5 G( t4 O. i* U0 T7 F
  11. #include <cctype>
    6 ]  @1 X( |4 U5 _* q& U
  12. using namespace std;
    ' f3 H; m: x4 e8 F: E

  13. 5 y6 s9 n+ b" |' _' s
  14. // MACROS  s' v' |9 Z+ u) j0 w
  15. #define SYSTEM_BLOCK_STR "[system]"! m! S& P. l) N+ p" V4 c
  16. #define NICKNAME_STR "nickname = "" B& ~) I- k; p& U
  17. #define IDS_STR "strid_name = "
    9 e4 L( v! l0 Y( @3 I7 c. K+ o
  18. //6 Z/ I7 r( [" B4 z  t
  19. 3 ^7 G- z, o4 D* F
  20. ifstream inf;
    : z( ]; K) I9 [" w. e
  21. char *buffer;
    ; [8 p7 \9 a; V( s+ c, ^7 A; Z  J2 d
  22. * l. c7 I. ?5 J0 o  I# v
  23. int main(int argc, char *argv[]), u/ B. u% c6 U  o3 @) @6 C  |% M! n! k7 w+ F
  24. {
    ' x, Y3 l5 Q: i0 M3 G' }* w2 c
  25.         int i;: }+ m  A- l; @! k% r
  26.        
    . W0 a) U* s& S8 E9 R& o. j$ `/ u
  27.         if(argc!=2){ ' F/ b: L: U# Q. d4 O1 |# d
  28.                 cout << "This program requires one and only one argument.";$ Q3 c" u0 p7 Y2 ?! A
  29.                 return -1;3 h6 j4 [, t( D" t
  30.                 }
      r' o% i7 H- y% v
  31.         / f7 r, F8 N3 p* S) d. i9 a% n: h
  32.         inf.open(argv[1], ios_base::in | ios_base::ate);
    + h  r5 \: i1 z
  33.         if(!inf) {* k! ]4 ]3 w* p4 a/ H2 Z4 x2 P
  34.                 cout << "Error opening file.";/ q$ A) q) Y; c" V+ X* ]  Y5 B  g
  35.                 return -1;' K" R. E( B& |" T2 j  _
  36.                 }
    4 g  l4 U/ D- x6 k- |/ l/ c" h
  37.                   `, I# V$ p" P/ |0 t2 \, e
  38.         int streamLength = inf.tellg();5 A; q1 r3 f/ @/ Z3 R- u; J
  39.         if(streamLength!=-1) {
    8 d  W4 _4 A7 p+ e4 ?' j" w9 f/ k
  40.                 inf.seekg(0, ios::beg);  G! ]" j2 `  R! U$ m1 d
  41.                
    7 Q/ x2 ~. c' P" \
  42.                 buffer = new char [streamLength];6 W" P; @1 N: i7 ^9 M
  43.                 // Read file;" u5 h0 m4 u/ v5 b: Y
  44.                 for(i=0;i<streamLength;i++) {$ g7 H+ n: w& S& t3 l) T
  45.                         inf.get(buffer[i]);$ \- }4 [/ a7 ^8 W: K$ v) _
  46.                         buffer[i] = tolower(buffer[i]);
    % A" ]* \' ^6 A+ ?" X
  47.                         }& y" v+ L( y8 V5 c
  48.                
    - Z+ w4 B% ]5 ?/ n# b7 Q+ I$ C/ O
  49.                 /* For testing. Z% I/ K# T- b0 S! }7 n% o
  50.                 for(i=0;i<streamLength;i++) {
    6 V/ I* v! C- R, c- w
  51.                         cout << buffer[i];
    0 P+ I( W7 a- s8 k# Q- ~& p6 `
  52.                 }; O; g) S/ G# F; F
  53.                 */6 }7 O% q8 x* O" o2 L( o
  54.                 }
    % d* w- T8 ~5 [8 D* c( k# B* }
  55.         else {2 k3 @7 _' w, ?/ H
  56.         cout << "Failed to read file." << endl;6 b; O! {- ~# g( \# h; E* h( q
  57.         return -1;
    # ^' I' Q% L$ b# F7 ]4 N% R
  58.         }
    1 j. {/ F; b  A$ H2 i2 j
  59.        
    2 t& F: w/ G9 t5 X+ B
  60.         string processStr (buffer);$ h2 B8 h+ t0 k. E9 D' u# @$ O6 `' |
  61.         delete [] buffer;- g3 ^) j: N9 ~  G2 R+ v! ~
  62.         7 X. W) N  P9 B) w) \. g
  63.         // DUMB DUMB DUMB....
    1 Y& @# X  i( C6 w+ I
  64.         8 T) l) Z! C6 l4 N8 P% X5 J
  65.         int nextSearchPos = 0;$ a! F/ k4 v$ u+ p: A: ?8 v
  66.         int tmpSearchPos[2] = {0};
    9 V0 h0 Q: G! }; B8 e; }* x
  67.         int entriesCount = 0;
    1 f) Y! M7 d) x$ Z; ^0 S0 K
  68.        
    & ]8 d$ |. n9 c. Q2 E6 }
  69.        
    4 F( s; i/ Z! y) U- @$ x
  70.        
      ~2 d, i& r: f" c
  71.         while(processStr.find(SYSTEM_BLOCK_STR, nextSearchPos)!=string::npos) {, z/ s% M6 y2 R" c5 Y" d- W# E2 A
  72.                 nextSearchPos = processStr.find(SYSTEM_BLOCK_STR, nextSearchPos)+8;* P' z! {9 @: V$ X4 n9 f" G
  73.                 tmpSearchPos[0] = processStr.find(NICKNAME_STR, nextSearchPos);: x& J; n* Q" G4 l! P  E, i7 D  t5 ]
  74.                 tmpSearchPos[1] = processStr.find(IDS_STR, nextSearchPos);) X8 M; O* U* v* H: f! x. u
  75.                 4 P  ?- |/ |5 e* i7 u
  76.                 if(tmpSearchPos[0]!=string::npos) {
    " R  ?. B9 v3 j! L
  77.                         i=tmpSearchPos[0]+11;
    2 |7 U( w$ }, z2 ~
  78.                        
    * M0 M( a3 W. G% U9 s& ]0 b
  79.                         while(processStr[i]!='\n' && processStr[i]!='\r') {
    & _3 @, T) V. ~6 Q9 J) ?* Z
  80.                         cout << processStr[i];
    0 m9 j/ B) r* o8 Q( O! U& Y+ N
  81.                         i++;+ `& E; k5 a% F( B: ]+ z' O
  82.                         }+ w; y1 M' i+ i1 c
  83.                        
    $ J- u0 P7 j2 x* U! X$ N
  84.                         cout << endl;$ F& J/ k# T- w6 U
  85.                         - s% e+ g- V* b3 j/ P. Q/ C0 x8 ~( ~" g
  86.                 }  G$ Q; |1 b$ b; u$ J) O' s
  87.                 " C: D# Y3 d+ A4 X; W7 o6 e8 \
  88.                 if(tmpSearchPos[1]!=string::npos) {
    . O' ?2 i- b- r& W! J5 O
  89.                         i=tmpSearchPos[1]+13;
    # ^" X/ H) @! q+ s5 X) _  a
  90.                        
    3 M, ?: V* u* u1 h
  91.                         while(processStr[i]!='\n' && processStr[i]!='\r') {( q& Z( A( o$ }+ p' @, D
  92.                         cout << processStr[i];# x% x3 w- N) x
  93.                         i++;& ^. d4 j8 D7 g: H1 I7 ]
  94.                         }2 @' t' y* ]) q) |
  95.                        
    % M  I) z9 m) F) w8 r, B
  96.                         cout << endl;- {: ]5 Y) s2 a! Y0 Q0 a9 O
  97.                        
    8 h( A% {, n) y0 }) f/ v. U
  98.                 }
    # G6 u9 h) k; p7 Z; F; F5 Q: X1 T
  99.                
    2 D# L2 i) z  y! Q. I) Y# Z( V
  100.                 entriesCount++;9 \$ c( q, T3 V) @* ]' \2 I# W
  101.         }
    7 m) V5 @  Q( S6 Q9 F* M# ?* ]
  102.         8 w( \1 |3 ]! j" {1 A
  103.         cout<<entriesCount;/ g1 C" n$ h" j* V) F  k
  104.         return 0;
    / J: g- c9 z2 W& ~6 u' O- l
  105.         % P% Q1 T* W- j
  106. }
复制代码
Update: 最后一行输出条目数.
2 z1 i1 k, e: c: C% N* ~8 l
  W& S9 L; a' H* Y* @7 A[ 本帖最后由 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 太空游戏站