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

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

[复制链接]
发表于 2008-11-14 21:54:00 | 显示全部楼层 |阅读模式
  1. // Nov 14, 2008 - by Euyis0 B6 B2 }9 ^( E' s1 a$ ]5 V) H4 h
  2. % ^* j- Q1 P: v) a! [
  3. //
    ' W& {1 C$ A; d
  4. // I, the copyright holder of this work, hereby release it into the public domain. This applies worldwide.
    5 G: i5 Z' O. s6 u* ^0 d1 c
  5. // In case this is not legally possible,
    0 N% ^: R4 J5 R+ z
  6. // I grant any entity the right to use this work for any purpose, without any conditions, unless such conditions are required by law.. G' W1 x+ ~0 \) Z
  7. //
    4 p  }! ^/ l3 U' g: ^' p0 Z/ n' V& `
  8. , C( t: ^6 c5 o: v
  9. #include <iostream>
    0 K2 c- y; K& A
  10. #include <fstream>8 q! t# _& S" o( ~3 a
  11. #include <cctype>
    , y% ]" [- J! x6 L" @9 M+ W
  12. using namespace std;) r0 R* y$ r) J+ K3 |- _

  13. " z0 J/ p. b. e' G9 c
  14. // MACROS: y& s# y# _) }  }% C  |0 Z! C! F: W* P
  15. #define SYSTEM_BLOCK_STR "[system]"
    5 R$ e, V" R; x: \8 x- {$ c
  16. #define NICKNAME_STR "nickname = "
    & M1 U8 O: c+ B: U  u
  17. #define IDS_STR "strid_name = "
    , ]7 t4 U' I8 |9 }: m2 T6 P
  18. //) `/ G  L- D3 [0 U1 L/ j5 c; j
  19. 0 U5 x  D3 Z* Y% ^. D3 Y# M9 y
  20. ifstream inf;
      R' e' W: j; x  F$ f, C
  21. char *buffer;
    : s3 b6 p. d$ f! c: G- @
  22. + D# U+ h- s+ Q! i" f1 c8 o
  23. int main(int argc, char *argv[])
    & l! }, R. E$ w% c  E
  24. {. Z4 j, w  `) a# e0 |
  25.         int i;! t  E! x* C7 O  F# r" @$ ~+ Z
  26.        
    ) b- o4 v4 q8 ^% S  V
  27.         if(argc!=2){ & {  C7 g, u. I& U3 R) t6 k( x( N2 n
  28.                 cout << "This program requires one and only one argument.";
    ( C- W! p8 w7 Y6 P6 }
  29.                 return -1;/ ~$ r" R: e  q- x1 Q6 f
  30.                 }
    5 K! L9 j: D1 L4 d
  31.         7 A# Y" y& R# ]: c9 f1 s. v/ Y
  32.         inf.open(argv[1], ios_base::in | ios_base::ate);$ J) L( h  J/ G: P/ Y4 {
  33.         if(!inf) {
      Q) M& w# U1 w" |9 q' O8 b
  34.                 cout << "Error opening file.";
    9 G3 |5 Q3 T0 z5 o% Z, N! h/ m
  35.                 return -1;
    ( p/ i5 g( a- f: W, z$ k  V, Y
  36.                 }
      p' X! o3 X5 N" p! {. d" q
  37.                
    8 H# P6 e7 k+ i1 m
  38.         int streamLength = inf.tellg();
      e& c- ~& u! {) i' I
  39.         if(streamLength!=-1) {
    ' o% t; q/ J$ |
  40.                 inf.seekg(0, ios::beg);
    # c+ t9 O: @6 x( l  K" M
  41.                 * q( T" c* n+ a5 [
  42.                 buffer = new char [streamLength];
    8 _. V) M( B2 u, }
  43.                 // Read file;
    + V& `2 t+ z* [9 W4 H
  44.                 for(i=0;i<streamLength;i++) {
    ' E9 ]3 e% ^3 e
  45.                         inf.get(buffer[i]);
    & V8 p. Z6 E, x5 k! |% z4 s
  46.                         buffer[i] = tolower(buffer[i]);2 z1 W) S& I, f9 u/ H# ?! D; `2 v8 b
  47.                         }
    : w" U# ^' _; ]* |& W$ J
  48.                
    & g& F" k/ |3 G+ p1 ^( O
  49.                 /* For testing6 C# F9 s2 e# g6 N9 X; z9 r0 Q
  50.                 for(i=0;i<streamLength;i++) {3 O0 h3 t. p1 ^. ~; }1 U4 k  w
  51.                         cout << buffer[i];/ z/ Z3 \3 B2 I6 I( [# C4 i
  52.                 }
    ( h: c9 w) k( Z' c4 P/ K6 ]' @& G
  53.                 */
    5 Q# K3 T. h( E  U
  54.                 }9 A" Q- m" z- k" `7 K; V
  55.         else {
    ( v( _9 G- r6 D: V0 ]: U1 o8 x3 B. `
  56.         cout << "Failed to read file." << endl;9 n- k' Q  H: r8 C
  57.         return -1;
    $ K% [3 z4 P8 v0 ^  H
  58.         }
    ! h8 z/ Y0 Y: _, j6 h1 _
  59.        
    & k( w4 o* L9 i9 O; r* M
  60.         string processStr (buffer);. g8 f, l, ]4 A5 g9 c4 t! T% B
  61.         delete [] buffer;& C3 H& T3 @3 o. l) n, K
  62.        
    - I5 T+ ]$ H0 Y$ F3 h4 c
  63.         // DUMB DUMB DUMB....
    % f, W; S# W2 d0 J7 P/ a2 e  E" r
  64.        
    % v) u) B  j1 h1 Z
  65.         int nextSearchPos = 0;& ~6 {$ z" j  [3 K
  66.         int tmpSearchPos[2] = {0};
    % r+ A& ]- f) `: m: ^+ ^
  67.         int entriesCount = 0;' E; v1 Z7 L7 I0 Q4 E+ `8 |
  68.        
    ; i- F5 J2 {  J6 J! G( a, S: s
  69.        
    * t! T" `8 [5 r: }
  70.         8 ^+ _8 Q& \. d4 Y# X# U$ H  R7 _
  71.         while(processStr.find(SYSTEM_BLOCK_STR, nextSearchPos)!=string::npos) {
    , F1 o- K$ \. F4 ]! P7 G  |
  72.                 nextSearchPos = processStr.find(SYSTEM_BLOCK_STR, nextSearchPos)+8;
    * g8 y9 c8 g% g6 I( i  O2 ]8 }
  73.                 tmpSearchPos[0] = processStr.find(NICKNAME_STR, nextSearchPos);
    2 Q, w/ q( k9 [2 w. r. \
  74.                 tmpSearchPos[1] = processStr.find(IDS_STR, nextSearchPos);0 R  e+ }' b: {) I: P6 K. r
  75.                
    7 D4 X: r8 f: i
  76.                 if(tmpSearchPos[0]!=string::npos) {
    % _- _/ C) J' T' u9 _7 y/ l6 L
  77.                         i=tmpSearchPos[0]+11;+ S: N: K  v3 W* u6 z1 d3 `5 i; h
  78.                         0 }8 R1 C$ u: M' I/ ~" v( |% I
  79.                         while(processStr[i]!='\n' && processStr[i]!='\r') {8 [7 T" _6 ?) z& w
  80.                         cout << processStr[i];5 g+ t/ ^* ]) [% g
  81.                         i++;6 d: h% I% n/ [! n* Q
  82.                         }" i# y" D3 I9 ]4 I8 N; }
  83.                        
    ( E6 V7 W! i* q" _! l
  84.                         cout << endl;
    + H" h# {9 b! h' D- {
  85.                         + \; {" [$ }% Q* }% c1 ?9 x
  86.                 }" G' T2 J9 m: l: t! N
  87.                
    ! u1 e+ x( |" m' u3 f9 c
  88.                 if(tmpSearchPos[1]!=string::npos) {/ R" r' w) u: u
  89.                         i=tmpSearchPos[1]+13;
    $ q7 f+ t9 }/ B- C1 v- N& w( W+ s
  90.                         ! r7 j! x$ ]/ {
  91.                         while(processStr[i]!='\n' && processStr[i]!='\r') {
    1 m- M$ Y/ N* u6 U! P) x
  92.                         cout << processStr[i];
    1 q, v6 n% p; u3 [6 b+ Q* u
  93.                         i++;
    " p' K5 k$ F) x
  94.                         }7 h7 {; n4 t, K6 G% B. r; P/ f
  95.                         ; o7 V/ ]: T/ u/ L& s: [1 ~3 o
  96.                         cout << endl;
    8 n* J, B8 e  [# h4 H& n
  97.                         $ c% C- k1 [/ i* i: Q1 m1 q5 {
  98.                 }
    0 J$ F5 e! p- z
  99.                
    0 d* [# a) M+ t5 }# I
  100.                 entriesCount++;. o: x  g( F( o% m: S
  101.         }
    7 L+ M$ A1 R1 o9 }- a' U) {
  102.        
    0 R2 ^# B' A/ b) p
  103.         cout<<entriesCount;. |/ C0 q* u+ }$ q2 T/ W# u
  104.         return 0;
    ' B$ |* A& o( K# G$ p7 s
  105.         $ ]0 \0 o3 T1 Q  K& Y# e) I
  106. }
复制代码
Update: 最后一行输出条目数.7 D8 ]/ ^5 \( |+ W
/ R3 ?! P7 }( V6 q% r/ x" ^
[ 本帖最后由 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 太空游戏站