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

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

[复制链接]
发表于 2008-11-14 21:54:00 | 显示全部楼层 |阅读模式
  1. // Nov 14, 2008 - by Euyis
    8 F  ]2 Y  P  b! Y0 N- y
  2. ; f( d( e9 _8 v% B+ W2 g( N1 D& P
  3. //4 m6 y3 y+ f" J/ w) o! p1 L/ ^* @
  4. // I, the copyright holder of this work, hereby release it into the public domain. This applies worldwide.
    0 K! V7 H2 W) s( Z; {
  5. // In case this is not legally possible,
    0 s8 h& ?3 W) Z% b! {! j
  6. // I grant any entity the right to use this work for any purpose, without any conditions, unless such conditions are required by law.5 J8 A/ {; ]4 D' r7 u
  7. //  T; x; F7 z1 g1 S

  8. : s8 q8 j5 x+ ^* \1 I1 d1 c, {4 r
  9. #include <iostream>
    ) s) o5 v0 I" s: ]! ^" i* _- c9 U
  10. #include <fstream>- |: m+ Q! a0 i; T0 [' r
  11. #include <cctype>1 P. h2 f/ _3 }5 {
  12. using namespace std;, l: h6 t+ `% P( p9 X/ }$ q

  13. + P) {6 c. Q3 E' Y9 v8 k3 h: o
  14. // MACROS3 K2 E) Y9 H& y" ^' w6 o
  15. #define SYSTEM_BLOCK_STR "[system]"8 S! {$ A; J3 B/ T% F3 [
  16. #define NICKNAME_STR "nickname = "
    - \; z& k6 I( d& Z' O3 T
  17. #define IDS_STR "strid_name = "/ f. w/ F( ^9 c2 L
  18. //
    7 @7 H# s7 \8 H4 }

  19. ' d; V0 n6 [. r; e6 b; T, q
  20. ifstream inf;
    ; m9 T9 \4 Z6 ^8 k- r$ I
  21. char *buffer;
    * ^' M8 J/ a) s5 [- n! u) S

  22. 0 F1 F- T7 ?4 }
  23. int main(int argc, char *argv[])
    0 H5 s  q5 B0 U7 |/ X/ R' S
  24. {: n9 q! j. L3 k8 s" R' Z, B) S5 l
  25.         int i;
    % ~7 a. {6 q% C
  26.         0 P$ K) n* z0 u  l9 `0 K9 r. D
  27.         if(argc!=2){
    , s" E- i; }6 \: ]& i; R' t
  28.                 cout << "This program requires one and only one argument.";
    ; h1 z: S$ k- L4 `6 z0 _
  29.                 return -1;5 ~% d8 C  ~  x9 V# R
  30.                 }: ^7 L* @6 F3 n1 {4 O4 Y
  31.         ; q" A, b' {3 J7 p- f; w( h( g
  32.         inf.open(argv[1], ios_base::in | ios_base::ate);
    4 P4 P. M  G8 X0 @8 h
  33.         if(!inf) {
    0 j( }! [- ]- `& Y
  34.                 cout << "Error opening file.";& U8 m" ?5 y" F4 J; N' L  H  W
  35.                 return -1;- v, x  T$ L+ ~  O2 L
  36.                 }) n  a' m# G1 w8 }/ j
  37.                 ) }3 |4 o  O7 R; Q
  38.         int streamLength = inf.tellg();( v) L/ l5 N: K$ O1 g" b
  39.         if(streamLength!=-1) {
    2 x) y; E1 O$ I, D
  40.                 inf.seekg(0, ios::beg);
    + `% @" U3 {3 e+ f# w* j
  41.                
    , E3 q* e# Y6 J) j% s7 s* \
  42.                 buffer = new char [streamLength];* L; m) y  t. Z: |/ P$ C. F, l
  43.                 // Read file;
    ' }* T: J7 n: z3 A+ u1 j7 b
  44.                 for(i=0;i<streamLength;i++) {! ~1 P' L6 H3 A. m. Z
  45.                         inf.get(buffer[i]);
    " |8 c, i0 w$ q, g
  46.                         buffer[i] = tolower(buffer[i]);
    3 {* B$ A5 P% s$ h) J5 C. c
  47.                         }
    ! v4 P  L$ x( q, {
  48.                 2 K: E! U7 v4 g/ a
  49.                 /* For testing- R3 k) s4 P$ R5 y1 i
  50.                 for(i=0;i<streamLength;i++) {& p# D/ u# k% H/ C, c5 ^% ]
  51.                         cout << buffer[i];& r2 @0 p2 C( e+ c
  52.                 }
    / u" D9 P9 J/ {! n
  53.                 */' r5 h0 v- ]6 d) C# _9 U
  54.                 }0 ]- f1 o# F: L
  55.         else {" I* m, L3 E" Y
  56.         cout << "Failed to read file." << endl;( t; Q4 ?$ e& F4 t8 S/ Z
  57.         return -1;
    2 t( @2 R4 m" M1 t: C* o, }
  58.         }$ P" _- S$ P9 h. r' u
  59.         - D0 X+ `: E6 d# U+ l
  60.         string processStr (buffer);, K" p5 e+ x" b9 M# G) d4 B- b
  61.         delete [] buffer;. g. i" G) s; [8 ~, I! o* p
  62.        
    ; q! t/ M* \( i1 X* E/ `- p
  63.         // DUMB DUMB DUMB....
    / B: ?8 e, x( _4 K  P
  64.        
      a) J7 l( b$ }# H- X" x& s. N
  65.         int nextSearchPos = 0;( f" I! Z. s% L: `4 {& e
  66.         int tmpSearchPos[2] = {0};3 c+ w* i5 U) y% N3 [2 y0 [
  67.         int entriesCount = 0;( T5 T3 l6 ]/ @+ U
  68.         ( Y9 o  P8 n! e& J. T
  69.        
    * F& e8 L2 P( q( w/ m
  70.         & H2 G- E/ v( W/ a3 k0 ^# k3 p# e! Q5 p
  71.         while(processStr.find(SYSTEM_BLOCK_STR, nextSearchPos)!=string::npos) {
    ( f* ~0 ~% x$ O, |
  72.                 nextSearchPos = processStr.find(SYSTEM_BLOCK_STR, nextSearchPos)+8;( {# r) }9 c# [. H( d
  73.                 tmpSearchPos[0] = processStr.find(NICKNAME_STR, nextSearchPos);# m, H# m5 m$ I9 r! a$ A
  74.                 tmpSearchPos[1] = processStr.find(IDS_STR, nextSearchPos);
    1 `, M' K( F2 V, [+ ~
  75.                   e4 {) R8 w' v; M
  76.                 if(tmpSearchPos[0]!=string::npos) {' N9 u; n9 @) c- s
  77.                         i=tmpSearchPos[0]+11;
    4 w' I$ ~* u4 n; d4 o
  78.                        
    * k' R& X" b$ j% c
  79.                         while(processStr[i]!='\n' && processStr[i]!='\r') {
    . E$ b: ^2 N8 z- p
  80.                         cout << processStr[i];$ m. L8 c- l; ~* F7 V
  81.                         i++;" q7 \: D" w2 N4 N2 S5 B, D* h
  82.                         }
    * U, v* m# o' p1 G% c; N
  83.                         " |& N2 B9 F4 E: L! i) y* a
  84.                         cout << endl;
    " f# v, ?. _  A- I$ A# L
  85.                        
    ( B& T$ e) w/ j1 ?0 `$ ^# z2 ?
  86.                 }
    ) c1 l; H, O5 V4 a/ t# Z
  87.                
    4 ]. D7 C/ {$ d* m* x
  88.                 if(tmpSearchPos[1]!=string::npos) {4 Q7 _) }- Z3 g6 v% J
  89.                         i=tmpSearchPos[1]+13;9 P* Y+ g. l) ^
  90.                         ; s: x4 g% r" |
  91.                         while(processStr[i]!='\n' && processStr[i]!='\r') {  I* g& U% C6 y/ v- d; X! v
  92.                         cout << processStr[i];. [3 a9 n! \, F0 l# s. c# g
  93.                         i++;5 E7 |8 z* Q9 m  U  {' q; p2 b
  94.                         }# ?2 D; G- ]! j, m* }/ e4 s* W
  95.                         6 I$ u2 O1 y" B$ m$ H( a# k
  96.                         cout << endl;
    & q4 F6 Y2 P* v: o% ^! l
  97.                         - \; L! o5 S1 i0 p; X
  98.                 }
    , N4 k, S6 v/ W7 H) N  d- G
  99.                 ) i; p5 G( ^5 V& |! g( Z
  100.                 entriesCount++;1 C% u2 n) r! J
  101.         }
    $ f" x0 m  g; f' @
  102.         + N2 l" x  ]1 s( Q' ?
  103.         cout<<entriesCount;. @6 \/ [% \! J5 ^: b" i
  104.         return 0;
    2 s3 a4 Z0 }3 f4 q: S; o! w
  105.        
      [/ x$ X4 u& M) w0 m
  106. }
复制代码
Update: 最后一行输出条目数.
0 x: H4 T2 \/ q5 a2 @9 L% @8 Y: c6 j
[ 本帖最后由 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 太空游戏站