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

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

[复制链接]
发表于 2008-11-14 21:54:00 | 显示全部楼层 |阅读模式
  1. // Nov 14, 2008 - by Euyis
    # B' `/ f. F: ~6 c+ o  f/ D
  2. 6 ^4 R: x* |0 r7 h3 Y9 p; n! f
  3. //8 d, @0 W- U/ O
  4. // I, the copyright holder of this work, hereby release it into the public domain. This applies worldwide.2 w% c, \8 `+ S! g2 t+ z9 E
  5. // In case this is not legally possible,
    2 o8 [3 U/ B- ]  I, ]
  6. // I grant any entity the right to use this work for any purpose, without any conditions, unless such conditions are required by law.
    . S7 e+ x; @9 i: H/ L
  7. //4 r" [5 v/ |  T$ |
  8. ! Q( F0 U$ m) |
  9. #include <iostream>
    ! u& V9 C9 j% ~) h( z4 t5 K6 o$ h
  10. #include <fstream>
    ( c  o2 ~  u3 H$ H
  11. #include <cctype>( Q5 D# M; }, N( o3 n# B
  12. using namespace std;
      C% M# ]! b. T4 R  `. W- M* q9 Y
  13. ' g) Y# J1 G* N& h( y' G6 X
  14. // MACROS
    ; H1 F4 N) s* R" A
  15. #define SYSTEM_BLOCK_STR "[system]"$ W3 }3 B  w; F
  16. #define NICKNAME_STR "nickname = "  V& \6 Z4 Z) w% w" E2 V
  17. #define IDS_STR "strid_name = "
    : G1 r: y7 z3 y3 y
  18. //- c7 Z6 l3 H6 S; @3 A
  19. - N+ U' O7 P, ~6 P
  20. ifstream inf;
    ( Z! w2 ~/ y) p7 f1 X
  21. char *buffer;/ W) R8 c' d+ l: E) {! u

  22. + z. C5 F+ S4 x% @. `) q
  23. int main(int argc, char *argv[])# l& P0 O& ~; ^9 k
  24. {
    $ J% D1 C9 ^- q9 i. D0 X/ @; p
  25.         int i;
    - q$ i* G$ I4 }" O! B& K
  26.           D, J3 q5 `" p3 Z: V
  27.         if(argc!=2){
    & _/ |5 m0 k' T6 E; Z- ]% ~  c$ w9 m
  28.                 cout << "This program requires one and only one argument.";, q" y; X* w% }3 B4 E: E# X
  29.                 return -1;
    3 a* i( ]& s5 N0 M$ V3 O" I5 m0 i
  30.                 }
    2 C! r' L. x! Z
  31.        
    + Y4 j2 w* e5 y" ?
  32.         inf.open(argv[1], ios_base::in | ios_base::ate);% i3 a/ j$ |4 @8 u
  33.         if(!inf) {& J3 x. ^- ~* Z. X& b- ~. y8 o
  34.                 cout << "Error opening file.";
    # Y! ^: J" V3 S! r1 q9 ]- E' U7 f5 S
  35.                 return -1;; E3 v  K# k0 r' t
  36.                 }
    ; g- Q+ K6 V# |. K; _
  37.                
    ' a; B; N4 x$ N1 x/ d) @5 i( ?
  38.         int streamLength = inf.tellg();
    2 C. a7 D6 o; Z: s' n3 Q
  39.         if(streamLength!=-1) {( y; \; J" u! _. V# {
  40.                 inf.seekg(0, ios::beg);1 U+ h' J' X- \. b* F* V" l
  41.                 , a7 {8 m$ c. {' ~( V
  42.                 buffer = new char [streamLength];
    4 n2 v- q( M: J- o
  43.                 // Read file;. S! m. J5 @2 l
  44.                 for(i=0;i<streamLength;i++) {
    7 D8 {0 X+ |$ q
  45.                         inf.get(buffer[i]);5 @0 N  d: E* F9 o* z
  46.                         buffer[i] = tolower(buffer[i]);& S! l2 `+ @5 N5 O! C& q
  47.                         }
    " _/ I9 d1 l6 V+ o
  48.                 2 ^( S6 Y1 E. ]
  49.                 /* For testing
    7 g* p: p% q+ y# p
  50.                 for(i=0;i<streamLength;i++) {3 N$ q1 ^5 n( G5 v4 A* O
  51.                         cout << buffer[i];
    3 S+ t5 V3 B" s5 T# ~2 [4 k
  52.                 }
    8 ^; j- C: _. x( t1 D+ h" `9 ~
  53.                 */' M9 w  }; R  `) W
  54.                 }0 i% t: N4 T) `8 L  j, {9 A7 ]
  55.         else {6 M. @5 B* |0 |, j( E% M
  56.         cout << "Failed to read file." << endl;
    - d" K; F; o: L$ s- o4 n; L2 d
  57.         return -1;
    ' w  ?) _0 h4 k# }- E5 a2 d+ E
  58.         }
    ) v/ {/ {0 Y/ w2 @5 E1 X6 P  @
  59.         ! }  L1 f+ l+ F/ @
  60.         string processStr (buffer);
    ! c* n4 n+ {  _+ s
  61.         delete [] buffer;
    % d4 [5 y5 v6 c" p3 |) E0 E; ~
  62.        
    + c) K% ^8 O' k; j/ U
  63.         // DUMB DUMB DUMB....
      [: I* [$ A+ {" v- m( r$ ^
  64.        
      j, u; h0 I  C; d9 i$ o% ?
  65.         int nextSearchPos = 0;2 Z5 Y4 s& L1 S+ H
  66.         int tmpSearchPos[2] = {0};
    / c% [3 W; j% `! g( d
  67.         int entriesCount = 0;
    1 Y# M4 D. I7 ~1 I2 s; _5 {
  68.        
    / H0 X/ y; z( d
  69.         ( A+ d: r. R+ i3 z- O7 ?: W
  70.         1 Q) d$ y* C3 a& E( f, N# S+ W
  71.         while(processStr.find(SYSTEM_BLOCK_STR, nextSearchPos)!=string::npos) {
    1 M2 T. _; J% V
  72.                 nextSearchPos = processStr.find(SYSTEM_BLOCK_STR, nextSearchPos)+8;
    - V' U6 M0 |7 j; l9 K
  73.                 tmpSearchPos[0] = processStr.find(NICKNAME_STR, nextSearchPos);, b8 u# A( L5 [5 _4 }% t2 _
  74.                 tmpSearchPos[1] = processStr.find(IDS_STR, nextSearchPos);
    # Q2 d. F$ @2 X, T/ K& r
  75.                 9 ?% m% ~5 Y0 \+ l: k
  76.                 if(tmpSearchPos[0]!=string::npos) {
    * _" A% B/ J, L( v! A
  77.                         i=tmpSearchPos[0]+11;+ |2 J% I8 d5 W9 ^3 G
  78.                         ' R$ E2 ^% h, F; x# Q# ^
  79.                         while(processStr[i]!='\n' && processStr[i]!='\r') {
    2 E0 X5 c; `1 T! R7 i3 h
  80.                         cout << processStr[i];
    * L6 y* j0 k5 G( N" b
  81.                         i++;
    ( A# Q* c$ b% u, g9 v8 [6 h: S
  82.                         }
    + F6 L' i2 }: k* w+ h" d% K' S
  83.                        
    ' U, H7 G% b9 M1 ]
  84.                         cout << endl;
    ; B$ G( V4 W' e2 u/ ?1 i' t# X
  85.                        
    & ^  s& E  w" C' S
  86.                 }" Z# Y# ^- B% W# _: E7 J3 V8 E
  87.                
    ( v& k% P8 I3 o" Y9 ]
  88.                 if(tmpSearchPos[1]!=string::npos) {! G; h/ j" x+ z! `8 `4 _0 U
  89.                         i=tmpSearchPos[1]+13;
    & s+ S" X- x- X& P7 f2 M1 }
  90.                         ( s2 ?7 U0 X2 O% O. R! r
  91.                         while(processStr[i]!='\n' && processStr[i]!='\r') {9 D$ f) B' ?) E& l
  92.                         cout << processStr[i];
    ) |7 z" S! y6 d" j7 q
  93.                         i++;
    ! Z. S8 h4 Z$ ~, k& b. a3 y( Z3 m
  94.                         }. V, P$ }# \! a
  95.                         ; w7 z& Y% ?2 f, T2 w  c. e4 M
  96.                         cout << endl;
    . ~) X4 i1 m! Z8 J0 C
  97.                         3 Y- H+ `$ |/ R) D
  98.                 }+ E( |0 j3 N6 d3 b0 d
  99.                 # Y5 w7 D( F$ t6 O# W
  100.                 entriesCount++;5 S$ ~$ b# A+ E$ S; G% d
  101.         }
    / _+ [* s7 @: X) A
  102.         2 k* [& _- [  J  b
  103.         cout<<entriesCount;
    + K$ F$ m: y8 P7 C; l
  104.         return 0;
    $ N# Q* g' ~, M/ Y' t
  105.         , t4 z0 r0 }  L2 u9 p. e
  106. }
复制代码
Update: 最后一行输出条目数.% k' F4 F, t- B5 z
" D1 R, c# _' B5 \- 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 太空游戏站