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

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

[复制链接]
发表于 2008-11-14 21:54:00 | 显示全部楼层 |阅读模式
  1. // Nov 14, 2008 - by Euyis
    # Q) _' Q: F2 z

  2. ' U, u; \/ D& h: Q7 w* W! T# M/ x7 m
  3. //
    % N' o1 y- o8 U( v+ M( ]3 U+ Z! Y( }
  4. // I, the copyright holder of this work, hereby release it into the public domain. This applies worldwide.
    " h0 r! U) @" a  L- u
  5. // In case this is not legally possible,
    ! ]% E2 n5 s9 ^$ S- J2 M
  6. // I grant any entity the right to use this work for any purpose, without any conditions, unless such conditions are required by law.0 [+ U; w% d0 h
  7. //
    4 a/ D  K: O' W" m! _: f
  8. 8 i  N$ p2 R8 G; P0 L
  9. #include <iostream>
    0 W2 J5 f4 t$ L: r9 V5 K8 m- o  J
  10. #include <fstream>
    % f6 W* B+ R& w( K! F- m
  11. #include <cctype># W4 n# P  ?" y0 g0 N2 o& Y
  12. using namespace std;
    0 q* c1 u4 h5 g2 o0 o" i3 s! z

  13. , R' |1 M/ b" I) `4 H6 m! d! d
  14. // MACROS; |" N4 D  E/ i$ Q" M+ h
  15. #define SYSTEM_BLOCK_STR "[system]"( v/ t, a$ A0 _# S) |
  16. #define NICKNAME_STR "nickname = "
    1 ?' {  N1 o$ y1 b! i
  17. #define IDS_STR "strid_name = "# d* ]: E) W: c# K/ V
  18. //
    % K% x: y! j, C& I% W' n' c
  19. & E4 W6 z9 O' c, q. P1 I+ Z2 x
  20. ifstream inf;
    7 g5 D' i1 b6 f0 Q( [0 y9 v4 O
  21. char *buffer;
    3 I* ~8 x- N, O2 l1 ?7 e7 F6 R% x6 A
  22. * h1 i% N' S' j/ q5 C& e
  23. int main(int argc, char *argv[])- k  p  a  z! R3 L" A( s8 a! [
  24. {! C' ]: r- l& L% T2 B3 F  Z
  25.         int i;
    2 x* {  E/ J! Y$ g. N: d7 ^3 d
  26.        
    0 [7 s% T+ m: Q  `
  27.         if(argc!=2){ . e0 h  N$ \1 b2 V
  28.                 cout << "This program requires one and only one argument.";
    2 p" h" z6 S5 j: V. R
  29.                 return -1;9 T+ V4 z4 t1 [" ?# T' \* I. m/ @
  30.                 }
    ' t6 b& l; _+ P
  31.        
    9 J5 R- i8 T6 x  R3 p9 X
  32.         inf.open(argv[1], ios_base::in | ios_base::ate);+ B4 v5 }) G# q" N* S* v; l9 o% m
  33.         if(!inf) {
    % w# `0 ?4 l) L; @/ T3 h# X
  34.                 cout << "Error opening file.";3 C8 U) ^6 K/ u4 D' I& J
  35.                 return -1;, m* q, G' @5 Z* {; z
  36.                 }
    7 ~- a. F* z* x2 V% n8 Y2 T2 `
  37.                 7 i5 L& `- V; @+ o( U+ Z  `
  38.         int streamLength = inf.tellg();
    , A$ G4 A. j: H2 I6 Y+ O* m
  39.         if(streamLength!=-1) {) p6 o0 W' l, H" y" [
  40.                 inf.seekg(0, ios::beg);3 j6 }- a# P" l. Q* ?$ L/ ]
  41.                
    + q4 y, i; A! i% v- }
  42.                 buffer = new char [streamLength];! j* M4 [8 Z- U; S' |" O$ h
  43.                 // Read file;
    ( D$ d, E6 P8 u9 ]0 z9 w/ v
  44.                 for(i=0;i<streamLength;i++) {/ F  T/ m, A  y$ b8 d
  45.                         inf.get(buffer[i]);
    6 d% x7 b' `1 O: V- {' G' u" d
  46.                         buffer[i] = tolower(buffer[i]);
    5 g0 z, A- q9 @  b) {5 l+ v
  47.                         }5 S( y9 _+ M  F$ ~! Q! l# F
  48.                
      d$ J* u/ b2 q) N' O( s8 M0 X
  49.                 /* For testing' t" I4 r5 v6 I) n# G; v
  50.                 for(i=0;i<streamLength;i++) {
    # A8 Z0 z: U. p' n# a: a) X
  51.                         cout << buffer[i];
    $ `+ i8 y& h7 x, I; V$ M; I
  52.                 }
    0 A1 P$ A3 I, p5 P
  53.                 */4 v  j; e% ?+ E  e7 D
  54.                 }
    3 c% Z0 f. r. W! h/ |% j
  55.         else {9 K4 z7 I" B% u3 F/ F+ C
  56.         cout << "Failed to read file." << endl;
      }) t8 }6 j' X' N/ e5 {
  57.         return -1;
    . J6 _) ^( R" S6 H/ ]
  58.         }
    * h& N, K4 [2 D! G
  59.        
    5 p  l+ c. L$ y6 o3 |
  60.         string processStr (buffer);/ q) Q& U% s# w! C6 r
  61.         delete [] buffer;2 h/ [: `& u, _( T! b
  62.         ( C  M! i6 N) f; m/ u
  63.         // DUMB DUMB DUMB....
      P. n- ~0 U0 @. l
  64.         2 S( b' p! g+ e
  65.         int nextSearchPos = 0;
    3 t# m+ C! v+ p4 ]+ h/ \+ V4 r* g
  66.         int tmpSearchPos[2] = {0};
    6 a/ a# H' p  c! _. f
  67.         int entriesCount = 0;
    $ e% ~$ k$ \9 w- d/ l8 n! b
  68.         ( ?3 z! _1 `1 w; E8 |6 i: ?* D
  69.         / e! M7 @  ^% s. |' @  f+ u
  70.        
    3 B/ N# E; G1 }' m9 E
  71.         while(processStr.find(SYSTEM_BLOCK_STR, nextSearchPos)!=string::npos) {
    7 R# U7 C# C3 V
  72.                 nextSearchPos = processStr.find(SYSTEM_BLOCK_STR, nextSearchPos)+8;' Y7 j+ _# O6 d
  73.                 tmpSearchPos[0] = processStr.find(NICKNAME_STR, nextSearchPos);) M* {' s0 i: }" U$ n
  74.                 tmpSearchPos[1] = processStr.find(IDS_STR, nextSearchPos);: M3 m* l. g* U" ?5 G
  75.                
    " U# \+ ~! l9 y# g
  76.                 if(tmpSearchPos[0]!=string::npos) {
    7 Y( t# j" C/ T( k# t; s8 o3 `
  77.                         i=tmpSearchPos[0]+11;
    & t0 t/ \; H  U3 Y% S
  78.                        
    0 N; j/ U1 C. O
  79.                         while(processStr[i]!='\n' && processStr[i]!='\r') {
      @6 f4 S+ d9 Z- e
  80.                         cout << processStr[i];
    0 _+ S# K# \0 m1 k
  81.                         i++;% j' Q6 D5 y5 Q: z) {3 o
  82.                         }
    3 A5 I7 k/ h8 F: c. M
  83.                         1 W" r1 R' s; Q0 |! a5 J
  84.                         cout << endl;
    6 L5 @2 J! {+ g& o" l9 R
  85.                           J" H) a5 J, i- J/ A7 r
  86.                 }
    3 s7 f0 {' D! N8 R  Q" v. L% ?
  87.                 6 W4 x. e. z. ]
  88.                 if(tmpSearchPos[1]!=string::npos) {
    . ]: l; v6 f6 O0 s8 q
  89.                         i=tmpSearchPos[1]+13;$ [/ ^+ l$ E. g/ r- W, u0 ]4 h
  90.                        
    5 a4 P/ ~# p; n: f: T% U1 {
  91.                         while(processStr[i]!='\n' && processStr[i]!='\r') {
    7 ?5 x: u4 q8 k' C$ H$ x5 Y2 h. e3 w
  92.                         cout << processStr[i];
      M0 N8 f7 ~, U* o6 p0 N
  93.                         i++;
    & E1 A0 ?$ |* z. a; ]' J; u
  94.                         }
    ' r8 z8 z) I2 _
  95.                        
    2 o) V- k* B' Z" K5 W
  96.                         cout << endl;" w5 @: {9 ^. a& F
  97.                        
    # B% O5 K7 Z6 U! i+ u
  98.                 }8 h9 S9 t: U: {+ z+ a$ Y
  99.                
    , q" m6 h' a  U! c
  100.                 entriesCount++;
    " V& E; H) z7 O% U8 T
  101.         }
    2 l- p) b$ K9 M* W% O$ E. f) K5 b% S
  102.         ; l% w) P8 D8 t+ {2 C  t
  103.         cout<<entriesCount;3 r& d3 k2 Z( ~, o" ], f/ L
  104.         return 0;1 f. D+ m3 `1 A
  105.         ) }# d, T( E; O: p. w* }. q& ~" a
  106. }
复制代码
Update: 最后一行输出条目数.* J  `1 h; [- [5 p- `4 L: X

, N  t6 X! E  ~; {( E( a- M[ 本帖最后由 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 太空游戏站