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

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

[复制链接]
发表于 2008-11-14 21:54:00 | 显示全部楼层 |阅读模式
  1. // Nov 14, 2008 - by Euyis
    : X& B+ P! T. }* p" ]0 p
  2. : K$ P& F5 ]: N
  3. //4 O  X) x. a/ b+ u/ L
  4. // I, the copyright holder of this work, hereby release it into the public domain. This applies worldwide.
    2 K9 @0 I" _- L, S  r% y
  5. // In case this is not legally possible,' m' _3 `' ]& v
  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 d( s6 y3 |  x. w, s; b
  7. //
    1 A" ^; R7 j; _& r* P
  8. 7 n# O! {. n0 x+ p
  9. #include <iostream>
    ' \8 H' V' y) y- o- g; R
  10. #include <fstream>
    % M* x9 m0 A! ~6 y8 n
  11. #include <cctype>5 c9 N3 g* l" l4 b  N' Z2 T/ q& h
  12. using namespace std;
    : t/ U; x, C# j! `; h' T) Z

  13. ) K6 d+ X) H% o2 x
  14. // MACROS
    " P* j- {$ M: d8 G& ]1 T0 u% a5 D
  15. #define SYSTEM_BLOCK_STR "[system]"; O, H- p4 y4 _4 j$ }4 X! k
  16. #define NICKNAME_STR "nickname = "
    $ T3 a6 s1 m. C* z7 J7 I$ x
  17. #define IDS_STR "strid_name = ": P) ]  ?" \3 h8 ^6 P9 B
  18. //* s/ X  R# ?; f+ U7 A1 Y" X3 P2 b
  19. % S3 s8 x3 l9 w, U+ K- \
  20. ifstream inf;3 A1 S6 j, [; W( `3 M6 n
  21. char *buffer;
    8 @, ~7 D& b5 `2 e  D$ x! n  ]% S

  22.   e0 v# G1 y; D
  23. int main(int argc, char *argv[])
    & X0 P5 S0 L  Y* _. J
  24. {3 [8 @  k5 R2 C" a/ G
  25.         int i;7 o8 _# R. z1 p6 E' u+ b
  26.         % m) @8 @- l0 Y. X( h3 x/ J* L* [( l
  27.         if(argc!=2){
    % K1 }4 d7 P+ t* j
  28.                 cout << "This program requires one and only one argument.";
    4 X! v& j& W* o! H
  29.                 return -1;
    9 R/ i9 \4 {. k9 ?- M4 o
  30.                 }: X5 c& h; ]( u5 V
  31.         9 r6 Q* s, v0 Q* \! `$ w% K5 l
  32.         inf.open(argv[1], ios_base::in | ios_base::ate);
    ; e; K/ N$ l# u2 j- L* j
  33.         if(!inf) {1 B' T# P! g! E# S) ^0 ?
  34.                 cout << "Error opening file.";+ k5 N% D/ Z2 e" W4 V
  35.                 return -1;7 p# {8 _9 O3 h- H# b3 A4 g
  36.                 }9 X; j1 `! a6 V5 y. c& g
  37.                
    , Z! E) A0 ]2 k# V
  38.         int streamLength = inf.tellg();  _7 v+ |* w- l5 b! W/ n6 q
  39.         if(streamLength!=-1) {/ I, F8 \6 f+ A1 s9 @7 g& P
  40.                 inf.seekg(0, ios::beg);
    ! o" J. i' l. V3 ~: h" q3 \
  41.                
    ; K. b9 {) D6 Q1 J& A5 s
  42.                 buffer = new char [streamLength];: J) t* }( B: j4 U* P2 h6 O( M$ H
  43.                 // Read file;$ }" J/ C# ~  h' ]
  44.                 for(i=0;i<streamLength;i++) {- \7 B8 n4 I& b+ u7 y
  45.                         inf.get(buffer[i]);
    $ U# _( Y. n3 ?# P, ]
  46.                         buffer[i] = tolower(buffer[i]);
    3 g6 W1 b$ s) D, ]) Z2 o
  47.                         }
    $ F- @2 j, I; b4 }* T* C+ V
  48.                
    3 X1 k3 E+ A+ ]% l6 K! n! w
  49.                 /* For testing% [5 @- o9 x2 X1 R5 |' O
  50.                 for(i=0;i<streamLength;i++) {# j' R! l' A9 R# v0 Q! a. E  K
  51.                         cout << buffer[i];) D5 N6 H& Z; V
  52.                 }/ j" k7 e. W" C$ i0 u& ?' T
  53.                 */5 j4 D5 |# K& a8 e2 \( O1 K- o9 `
  54.                 }$ M. q/ M+ `0 G" z
  55.         else {" P+ \  P! n: Y5 o
  56.         cout << "Failed to read file." << endl;
    3 e0 Y% L. X7 r: _, x8 k
  57.         return -1;
    $ b2 m9 M$ ~* A% C# x
  58.         }
    - |8 |- _, ~( t4 _: q
  59.        
    ) ~2 T( t# d9 {" V- c
  60.         string processStr (buffer);" Q1 u6 P1 j. `$ I& S
  61.         delete [] buffer;1 C% u7 Z4 X6 R7 }
  62.         2 M1 }/ p) q/ a* X3 m
  63.         // DUMB DUMB DUMB....8 U2 y" j& Q& {9 H
  64.         7 R0 [& x# p4 D1 F0 R- V0 Z! I" F
  65.         int nextSearchPos = 0;4 i4 [* u1 q+ H6 k- t
  66.         int tmpSearchPos[2] = {0};
    + H% H+ a1 |& a  a+ G2 I2 S1 ^
  67.         int entriesCount = 0;
    2 R8 m6 h3 f/ @9 p3 c0 q
  68.        
      @8 `: m, ~& t
  69.        
    , v9 U9 W' u  @. S
  70.         + g1 ]; b& `, g' d
  71.         while(processStr.find(SYSTEM_BLOCK_STR, nextSearchPos)!=string::npos) {
    $ V! e9 {: f2 |9 l( L: n
  72.                 nextSearchPos = processStr.find(SYSTEM_BLOCK_STR, nextSearchPos)+8;
    4 h0 [7 A3 e% Z1 q* F1 Y
  73.                 tmpSearchPos[0] = processStr.find(NICKNAME_STR, nextSearchPos);4 O2 r# `) p: E, ]- I2 i; Z
  74.                 tmpSearchPos[1] = processStr.find(IDS_STR, nextSearchPos);2 l7 s% U* \/ S" n, S# ~- ?' _
  75.                
      X0 T5 R7 a/ s- q, W
  76.                 if(tmpSearchPos[0]!=string::npos) {% d: C/ \5 I2 J* C' q
  77.                         i=tmpSearchPos[0]+11;8 U9 Y* T# v% o5 f5 R9 M9 h( e
  78.                        
    0 t8 d& Q3 `* |
  79.                         while(processStr[i]!='\n' && processStr[i]!='\r') {
    - e) a4 N4 `* ?% N+ y; B3 \- {
  80.                         cout << processStr[i];( A1 X# h3 G! r1 L' b5 }' h3 f& w
  81.                         i++;# }' Y( U( m3 C# d, H: T
  82.                         }
    / s6 p2 X) V- Z0 s
  83.                        
    1 c! i$ \* t! r1 H
  84.                         cout << endl;
    5 }# i! y# `) j: z
  85.                        
    % a* \- D/ a; E; w: G# k
  86.                 }2 I& F: {$ q. w* M7 ]( G; K1 y
  87.                 6 Z# Q! r9 g8 e( `3 S% a, I* y  _
  88.                 if(tmpSearchPos[1]!=string::npos) {6 `+ }6 I1 q4 \
  89.                         i=tmpSearchPos[1]+13;1 A9 Q' R1 N7 V* r% p
  90.                        
    1 o) c) l( t& E' T/ Y
  91.                         while(processStr[i]!='\n' && processStr[i]!='\r') {2 ]  @' _  B8 K
  92.                         cout << processStr[i];; g2 q0 q& ~; b" i
  93.                         i++;* I$ U2 [7 u  y  r: C
  94.                         }0 g1 p' z& b" P8 U1 R9 ^, ?/ S( O
  95.                         % d$ A4 }) ^! b- Y0 ~' v6 G, h
  96.                         cout << endl;
    * i  f. w, _/ ]  _' W
  97.                         5 V3 O+ |. w" z
  98.                 }
    & N5 S% J  J2 N
  99.                 * G* p; G* L* Q6 L- M4 {9 y, j
  100.                 entriesCount++;  N: _& f# E- J; |
  101.         }
    & c$ w/ F  N8 k( g" b
  102.         0 r3 P1 Z8 t0 m# e: i8 c% ~+ w
  103.         cout<<entriesCount;
    3 E& Z' o: M& q- }  [. _
  104.         return 0;
    : d  X3 [- p, C) w) `" d
  105.         : m8 q6 u% P3 [9 @7 s" L% a6 Z
  106. }
复制代码
Update: 最后一行输出条目数.
  j+ l. |2 y# m+ V( Q2 Z) V- J5 A; C/ k
[ 本帖最后由 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 太空游戏站