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

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

[复制链接]
发表于 2008-11-14 21:54:00 | 显示全部楼层 |阅读模式
  1. // Nov 14, 2008 - by Euyis
    ' K$ u0 V5 G5 M, @

  2. * B3 I8 v6 K% j: N7 z
  3. //0 d/ j: `* d, s6 u; k! T/ P
  4. // I, the copyright holder of this work, hereby release it into the public domain. This applies worldwide.
    : w5 @; E3 D) s7 h
  5. // In case this is not legally possible,0 o$ ]& G5 j- b1 }: O
  6. // I grant any entity the right to use this work for any purpose, without any conditions, unless such conditions are required by law., |! G3 h5 G; C! o) z) X
  7. //
    . ?2 T+ H3 }* x$ n8 w% O- V

  8. $ E0 O* i& r1 i- O; Y, s, a. L
  9. #include <iostream>
    ( Q( e" L" H6 _
  10. #include <fstream>
    3 |8 }! ?$ Y8 n& r/ ^
  11. #include <cctype>
    " [) }) d- l# S$ ~3 F6 ?  B
  12. using namespace std;
    ) T$ I6 j1 _0 W# w4 y

  13. " \9 |4 P$ N- X/ _: b
  14. // MACROS
    * r. l7 n4 a2 T; H! b, o5 H3 d: H  [
  15. #define SYSTEM_BLOCK_STR "[system]": {  _' E, Y) {' K$ f, C9 p
  16. #define NICKNAME_STR "nickname = "! {( |5 F# F) g6 W+ D
  17. #define IDS_STR "strid_name = "' G( ?) }5 s+ ]  v
  18. //. c/ I: q: N" y& H7 q( l( m; r
  19. $ X2 f& J/ o+ l$ m  p3 ~2 o
  20. ifstream inf;. d8 _# i- {% U
  21. char *buffer;
    - _& b. W# j% F1 C) C. V

  22. * h' b6 l( V% V8 @$ j
  23. int main(int argc, char *argv[])1 X- c$ h# H: R0 D  Q, s+ M4 I
  24. {
    / m6 N3 z, q6 V) B" G1 T7 O- h
  25.         int i;# ]) m/ r* B) h/ B# Q$ ]% A% }
  26.        
    9 x# L" X. g8 U  d& D# V7 `+ l
  27.         if(argc!=2){
    8 X! D/ R* X  P
  28.                 cout << "This program requires one and only one argument.";
    ( U. S) s% `7 Q+ D0 T- \- {1 b5 Q" x
  29.                 return -1;) d" u. r: Q/ z$ L- F+ @
  30.                 }
    : F# L; |& Y$ X' a( A, Q5 _
  31.        
    / J0 @% m. i. i# ~7 _5 D
  32.         inf.open(argv[1], ios_base::in | ios_base::ate);
    " P& q6 u( e. k
  33.         if(!inf) {+ ?6 Z, W. x, v1 k) V$ h0 W
  34.                 cout << "Error opening file.";5 E7 G- f8 w  }/ @$ ]1 l2 A4 ~
  35.                 return -1;7 d! b2 h/ k+ q- |1 ^
  36.                 }
    9 |7 \  S4 D! [% R2 k3 s0 u
  37.                
    0 e4 h/ ]. f% |5 Y( ?6 B
  38.         int streamLength = inf.tellg();
    & u& V# [& h4 Y( H  X
  39.         if(streamLength!=-1) {
    0 B+ H" s& _' q* }5 S7 [
  40.                 inf.seekg(0, ios::beg);% g* K$ t2 }# [( @3 o. O
  41.                 % n" T5 T8 {; @5 d
  42.                 buffer = new char [streamLength];% n  l3 V4 x2 q! f6 e. F
  43.                 // Read file;* T  n7 A# }0 I7 ]
  44.                 for(i=0;i<streamLength;i++) {
    " h+ g7 I8 X) [  X1 R! t$ B
  45.                         inf.get(buffer[i]);
    ) X) p& P5 H' M9 U
  46.                         buffer[i] = tolower(buffer[i]);* A6 ]0 u4 m. p4 J$ r/ a
  47.                         }
    4 d9 V, o. H+ f$ H. F
  48.                
    1 l6 p: m% v( R# |7 U" l* O
  49.                 /* For testing
    8 w8 X! K- D0 H8 J& r9 j
  50.                 for(i=0;i<streamLength;i++) {( B" R8 [# E& n0 r; u2 Z9 F
  51.                         cout << buffer[i];9 B: D4 T1 d( ~  W" q2 f4 H
  52.                 }) ~4 Y6 H5 B) d1 ^
  53.                 */
    4 v/ O: t8 \' _$ }7 z* V
  54.                 }/ V; C  p# q; Q
  55.         else {7 t5 _! R" a- Y5 I. @& p# @( B
  56.         cout << "Failed to read file." << endl;9 [4 d* o2 l9 W, c
  57.         return -1;
    # p; r2 b1 e8 u& }9 i/ U9 O1 l
  58.         }
    : X4 o7 c; A( b2 o
  59.        
    / x, b( w, L! f6 i
  60.         string processStr (buffer);
    4 g# F- f* i2 x9 x. {- J3 d2 }, Z
  61.         delete [] buffer;3 Z3 m' v) R1 }2 U: L" b& k1 q3 `
  62.        
      u! Y  f/ Z0 T. M* D  l1 O2 f
  63.         // DUMB DUMB DUMB....
    . [+ W, W  H: L  ^- ]6 s
  64.        
    6 a6 |- H/ U) o2 H" Q$ U
  65.         int nextSearchPos = 0;* ]0 [; o# u0 G2 E& z
  66.         int tmpSearchPos[2] = {0};
    * N1 x1 ~: h- |( U7 V& c
  67.         int entriesCount = 0;
    ! Q9 M, u/ O4 U+ ^) I! N. r' Z
  68.        
    . ~0 k- O3 G. S' h! H
  69.        
    0 D" n0 ^& t9 `$ p6 l8 U
  70.         3 I0 E7 w0 ]0 e" A, n; M7 p
  71.         while(processStr.find(SYSTEM_BLOCK_STR, nextSearchPos)!=string::npos) {
    : Y) Q5 v$ |  l
  72.                 nextSearchPos = processStr.find(SYSTEM_BLOCK_STR, nextSearchPos)+8;
    4 R  `" l$ A- l# \" _/ L& c
  73.                 tmpSearchPos[0] = processStr.find(NICKNAME_STR, nextSearchPos);
    . a" D2 T! D$ K6 ?. ?( P
  74.                 tmpSearchPos[1] = processStr.find(IDS_STR, nextSearchPos);, K; ~! m/ A: R8 w
  75.                
    + v8 s3 o9 z2 s
  76.                 if(tmpSearchPos[0]!=string::npos) {
    ! e# c7 e* n' \4 ~0 m7 U% r/ F
  77.                         i=tmpSearchPos[0]+11;1 ^) H9 @5 Q' V
  78.                        
    0 o' }! P- c; ^) W+ \, f3 A
  79.                         while(processStr[i]!='\n' && processStr[i]!='\r') {/ r; }0 s7 n2 E' ?5 _
  80.                         cout << processStr[i];* @5 E% K8 E# j3 T; v
  81.                         i++;
    $ \' r, K: v$ L/ ]# c4 `% `+ N+ D
  82.                         }
    7 P4 q4 v& m- b( |4 a
  83.                        
    ) v. O3 a7 L7 n7 M* o; j
  84.                         cout << endl;. D" ?% d( \2 B7 h
  85.                         % @2 f, f5 e( ]% F$ i# |. X
  86.                 }
    , ]' o: \, L4 R2 l$ g* t
  87.                
    & G* @7 o: v9 {
  88.                 if(tmpSearchPos[1]!=string::npos) {4 R/ V4 }/ [% v6 o
  89.                         i=tmpSearchPos[1]+13;2 t- [& h; B! D* g& |6 A3 {
  90.                        
    ' A! h7 A, F. t1 b1 V% d
  91.                         while(processStr[i]!='\n' && processStr[i]!='\r') {4 h; M* c$ w! ]! B6 P3 r
  92.                         cout << processStr[i];
    ; Z6 ]* T- a- l# G
  93.                         i++;
    9 @# [: ]; [# z* m- O5 z7 a
  94.                         }
    6 D1 B- E/ b& l5 V! e+ V4 a
  95.                         ( q, u9 a& c0 v. O" A+ \
  96.                         cout << endl;( g, M3 n" N2 P; Y% y$ H" N: Q
  97.                        
    8 c+ Y* x( ^; w7 M
  98.                 }5 H  {- @5 G! k" y* }+ Y
  99.                
    6 y! q) @- b0 `, K
  100.                 entriesCount++;
    2 D8 ^9 F1 D0 w, L
  101.         }9 H8 L+ B8 }+ H9 E' [6 S# E/ x$ p8 u
  102.        
    3 g# K3 }) H  m" ^2 ?% ^2 X4 s" C+ q
  103.         cout<<entriesCount;! K+ E; v8 ~9 s( R
  104.         return 0;
    ! }, m. B: b, u3 R  ]. m  U
  105.        
    + Q4 z4 `2 ]+ P' \5 @$ U/ b
  106. }
复制代码
Update: 最后一行输出条目数.
+ f7 {9 }! {: a* n# `% N* G0 C/ M0 ^- k! ]7 l7 Y- \
[ 本帖最后由 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 太空游戏站