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

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

[复制链接]
发表于 2008-11-14 21:54:00 | 显示全部楼层 |阅读模式
  1. // Nov 14, 2008 - by Euyis7 A* V7 E9 K  g/ c9 c9 Q
  2. . [( N& y, X3 M& G4 f# L; b
  3. //
    # O. @9 G; F+ m% s# Z* L
  4. // I, the copyright holder of this work, hereby release it into the public domain. This applies worldwide.1 X: }0 x% i' p9 v3 }0 g, Q/ q' ~3 t
  5. // In case this is not legally possible,
    8 @/ X7 u7 z* k3 C7 k0 \
  6. // I grant any entity the right to use this work for any purpose, without any conditions, unless such conditions are required by law.1 {" H" c# U/ {9 K- m
  7. //
    - x0 V- G' V8 B4 q( @2 Z
  8. 7 t# \+ ^7 K) y; O1 ]2 k, q( S
  9. #include <iostream>
    7 u4 w& |! I! K" N! d* @% G
  10. #include <fstream>; ^3 s! J. Q) I( t. f+ q  ], Q
  11. #include <cctype>0 b8 w; U) L1 B/ ], y
  12. using namespace std;
    5 p7 B8 j( l% Z4 u6 B: W

  13. # h. q* x/ q- j7 O. {
  14. // MACROS
    . h" o" d+ i3 Y+ S
  15. #define SYSTEM_BLOCK_STR "[system]"- L1 }# D$ T6 }# q/ r8 c4 M
  16. #define NICKNAME_STR "nickname = "
    ; X3 @# n3 q" G1 H* o* |6 c7 H; ~
  17. #define IDS_STR "strid_name = "7 K6 O2 Z& w( Z, Y; V  r/ K
  18. //" U9 C8 Y$ L! \& g

  19. : [: E# C, }/ F8 f% s" y
  20. ifstream inf;
    : \" Q; g' y- j3 |: r( T* K
  21. char *buffer;
    ) Z6 C5 U) d1 K, O" M+ g$ d0 |& C+ V

  22. * F! G5 C( D7 ~3 [
  23. int main(int argc, char *argv[])
    ) {9 Y% x7 {+ a
  24. {, G8 N. \8 p+ L. t# x" @8 |
  25.         int i;) u, Z  {. e2 w5 _0 c% w: x2 y" @
  26.        
    ' u' b" R) G2 f9 Q7 N- ?; s  F% |
  27.         if(argc!=2){
    . c3 o0 K0 }) Z6 Q/ N' S6 {0 D' Z
  28.                 cout << "This program requires one and only one argument.";' O6 d3 O+ M: K2 [! e
  29.                 return -1;
    6 R3 O+ a7 z$ p" G7 Z# q& q  L
  30.                 }
    ) c* l+ o' V7 _0 H
  31.        
    + D% o& J) T( O, ?1 W
  32.         inf.open(argv[1], ios_base::in | ios_base::ate);
    $ ~1 q& I( Q  |" Q
  33.         if(!inf) {
    / x) Y0 B- T1 Q; j2 q6 o7 {/ W
  34.                 cout << "Error opening file.";2 o) [0 Y% B' b* Y" p  G( Q
  35.                 return -1;
    $ }4 h/ k6 Z6 h( k7 _1 B. l
  36.                 }2 {/ l  `, U; w6 C* ?! F3 |
  37.                
    # O6 n! l3 K7 B/ w* ], X) M
  38.         int streamLength = inf.tellg();
    8 p- G& f3 @; _- D  ]6 c
  39.         if(streamLength!=-1) {
    ) U0 a1 W; n8 P1 z9 H) A
  40.                 inf.seekg(0, ios::beg);7 ~: p; X( u# e8 p! }& Y
  41.                 5 r: j; h( H7 E( C" Y7 }/ H
  42.                 buffer = new char [streamLength];
    9 c( T! j# [- L) R3 M9 r
  43.                 // Read file;
    : j/ G7 b$ d3 ]" t
  44.                 for(i=0;i<streamLength;i++) {
    + E7 K1 t3 P! d* q: I6 S1 a+ J
  45.                         inf.get(buffer[i]);
    0 S# I; @' o6 \. w( E! u( Z9 Z" I6 y
  46.                         buffer[i] = tolower(buffer[i]);& k: m9 ]6 g: A5 w  c( ?! D
  47.                         }
    & v& S% ]( H% j' r2 D/ X
  48.                 7 x; A: d4 d9 C7 |
  49.                 /* For testing
    7 u8 n0 n7 x3 ]0 R6 Y$ v
  50.                 for(i=0;i<streamLength;i++) {
    $ v& I4 o  H- F% S8 s6 \
  51.                         cout << buffer[i];, Q' f( n, W2 x2 ?& ~. d: E# y
  52.                 }# S- L7 [& W% a! i6 q
  53.                 */
    % u" g4 h2 R0 \
  54.                 }' e! O( s; T7 Z* {
  55.         else {4 o4 \  z7 E$ R: |9 \4 }
  56.         cout << "Failed to read file." << endl;9 `" r( B9 K1 D! _, Z# c
  57.         return -1;
    & h1 G; u9 C# {. ~+ _
  58.         }
    7 Q4 [/ n' y9 e3 R4 d
  59.         - |- b- r6 s  Q2 r  ~
  60.         string processStr (buffer);- S# k/ M3 |1 H
  61.         delete [] buffer;+ r- K, x- W# A8 k( v. l
  62.         2 R, K  C6 m; y6 c2 s
  63.         // DUMB DUMB DUMB....
    8 @; F9 v4 J! N1 |$ W% s
  64.        
    8 i5 t: C" a2 H1 X( v5 n5 }
  65.         int nextSearchPos = 0;2 j0 w  z8 s5 y) O8 c
  66.         int tmpSearchPos[2] = {0};
    - r) C: U# I  e; @
  67.         int entriesCount = 0;2 D, A7 h" O7 K$ C9 C
  68.         0 z1 R* ?; _+ c: D9 [( Z
  69.        
    . F, C" i9 N& z0 B9 R! C5 o- M7 g
  70.        
    3 U2 e( \% d/ C  y
  71.         while(processStr.find(SYSTEM_BLOCK_STR, nextSearchPos)!=string::npos) {! r+ r- [  D$ V4 ]
  72.                 nextSearchPos = processStr.find(SYSTEM_BLOCK_STR, nextSearchPos)+8;1 r8 f2 v; @! R, {
  73.                 tmpSearchPos[0] = processStr.find(NICKNAME_STR, nextSearchPos);0 D$ x/ I  ]$ O7 T; g* F* {
  74.                 tmpSearchPos[1] = processStr.find(IDS_STR, nextSearchPos);
    3 F) e% G& ^1 W3 y$ p
  75.                
    : T4 K% K( N" z/ a. \& a
  76.                 if(tmpSearchPos[0]!=string::npos) {  @! F( O' k5 p" u. a
  77.                         i=tmpSearchPos[0]+11;6 j% n9 Q5 s" Y5 y% f6 z6 w8 I
  78.                        
    * b! s0 _! q' F
  79.                         while(processStr[i]!='\n' && processStr[i]!='\r') {; o& }& _3 j2 c. U) N
  80.                         cout << processStr[i];
    : T+ K# H. L7 s- d/ U0 V
  81.                         i++;
    . I. t& Z. C4 S2 s
  82.                         }
    & R  N$ b# T* X) V& V9 j
  83.                        
    7 P6 p7 V0 r9 W; B
  84.                         cout << endl;
    + w3 K9 J- a( X2 w9 a( c: {- c
  85.                        
    ( s7 B$ J, q6 ^1 n! W
  86.                 }( |: G% |: u5 \! `
  87.                 5 e, P; h" u+ R- A1 X
  88.                 if(tmpSearchPos[1]!=string::npos) {6 y$ z& |) t: I1 }) @
  89.                         i=tmpSearchPos[1]+13;
    ! Z. k( p. V/ G2 }# v( L
  90.                         3 E8 u3 \3 J" t5 ~- C* U
  91.                         while(processStr[i]!='\n' && processStr[i]!='\r') {
    9 |' J5 Y" |' T' F7 |
  92.                         cout << processStr[i];5 s# @, o) H! g' s+ J( O
  93.                         i++;
    ! y4 b2 x6 F# U
  94.                         }
    & d; |8 @3 F4 u. i, ^  O0 S9 O
  95.                         8 p* d' _8 R1 \+ _
  96.                         cout << endl;
    9 q8 t" n; S* Q! `, o; Z
  97.                        
    1 B- L; W3 O! h& I: M9 b
  98.                 }8 }2 ?- u; M# E! U' G9 a5 L
  99.                
    2 ~8 M1 f) e  O) A' V$ Z' _8 [$ ]
  100.                 entriesCount++;% {6 a  s2 _( k* C# w6 \1 F
  101.         }) o. b4 ~% ?# C
  102.         1 s  E: `, j4 `2 n. ^$ x
  103.         cout<<entriesCount;
    / Q; i/ W( r4 M, }& b
  104.         return 0;6 K) d; a! F6 F2 K2 ?4 \
  105.         3 E: f0 P$ E5 w+ i. t  h/ N
  106. }
复制代码
Update: 最后一行输出条目数.
  [4 ?0 ?0 ^* T; z  w( u
/ e, @9 u# X$ ?5 V7 I[ 本帖最后由 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 太空游戏站