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

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

[复制链接]
发表于 2008-11-14 21:54:00 | 显示全部楼层 |阅读模式
  1. // Nov 14, 2008 - by Euyis
    0 V; I9 d3 t1 J# t/ v0 F* k
  2. " u2 I; u, U6 w2 }' w1 k& A
  3. //. V% a6 s, {6 p1 n# O
  4. // I, the copyright holder of this work, hereby release it into the public domain. This applies worldwide.. T0 ]$ f) ?: h1 K- Q+ b2 _9 U
  5. // In case this is not legally possible,' R8 W% p  o% n2 a) B
  6. // I grant any entity the right to use this work for any purpose, without any conditions, unless such conditions are required by law.
    9 E( }. Z1 b9 _
  7. //
    $ H2 B) Z( c5 [
  8. 6 z8 x4 e+ z; q! B. E
  9. #include <iostream>5 Y2 d: O* m5 T4 ~4 b& ]
  10. #include <fstream>) U. F; s% _0 q& T
  11. #include <cctype>( K0 c. P1 i' J- Z5 z6 O
  12. using namespace std;6 f& @1 z: ^! t( y* V1 ]" c" x6 ^5 m

  13. 7 y; Y7 q6 o( ]
  14. // MACROS6 D( p3 d  p8 L3 b
  15. #define SYSTEM_BLOCK_STR "[system]"
    ' r& P8 V8 n; \1 A
  16. #define NICKNAME_STR "nickname = "  Y0 N( \& V" i& j% W  h
  17. #define IDS_STR "strid_name = "
    $ u1 s1 s$ [( [
  18. //
    9 c8 h( c  M( p, t4 N6 T  X

  19. 4 ?, k+ N" x* r% N$ q9 @/ ^0 H
  20. ifstream inf;
    2 _. v# L6 @2 [( O
  21. char *buffer;
    # q5 J0 Q' c) k
  22. ) G6 Q% n4 T. ?* E# {
  23. int main(int argc, char *argv[])
    2 y: ]9 J) a1 Z% k8 l0 c6 Z
  24. {7 o: t) d1 @; w
  25.         int i;
    * C3 Q0 G# v0 O# q; |
  26.         ; }0 L5 `1 w6 h  v% {- E5 o( a' g
  27.         if(argc!=2){ - T( C8 X. t! b" r2 n. O4 p
  28.                 cout << "This program requires one and only one argument.";
    ) f$ N3 ~! T6 |( N9 v
  29.                 return -1;
    - i1 C; z2 ?  o: p
  30.                 }
    1 ?6 `9 K) M- U; Y* {$ ]
  31.        
    % q$ O8 `2 _7 G0 k4 r! E5 v# g+ ?3 K
  32.         inf.open(argv[1], ios_base::in | ios_base::ate);4 @' F6 U; F5 M# ]
  33.         if(!inf) {
    ; O  K1 ~- r5 ?" s: P9 G
  34.                 cout << "Error opening file.";
    7 X+ }: O* K  d5 @9 g& v
  35.                 return -1;0 C" N3 U) V: [$ c
  36.                 }+ q8 O. P5 O# A) Q8 ~4 Y  {, q
  37.                 + m3 Z6 ]9 A0 k* I6 h! \; s
  38.         int streamLength = inf.tellg();
    / Y! Z$ }7 v0 W; V
  39.         if(streamLength!=-1) {
    # W) {0 f! {  M9 `$ W" _
  40.                 inf.seekg(0, ios::beg);: _/ |& p% ^+ m
  41.                 & f. l' ~) {" m# P3 J
  42.                 buffer = new char [streamLength];% S* Y: q+ l$ q8 Z" Y  A) ^7 A' ~
  43.                 // Read file;+ t( P, ?$ D0 q
  44.                 for(i=0;i<streamLength;i++) {; D% V' [, I: s. s
  45.                         inf.get(buffer[i]);, U8 D6 ]4 F# N. W. |
  46.                         buffer[i] = tolower(buffer[i]);7 r* l% P* L2 d" y) O! G9 N
  47.                         }) x: }8 Z; A4 @6 z& `4 b
  48.                
    9 |9 m: b( C! |1 M9 j4 T# [7 p
  49.                 /* For testing
    9 h0 D4 z0 ^  B# J+ `* b
  50.                 for(i=0;i<streamLength;i++) {
    " F: {  u0 n$ o4 ]
  51.                         cout << buffer[i];- d1 p; I3 y0 Z3 J
  52.                 }
    7 U' e. v" y3 Y  f3 \; A9 o
  53.                 */: `, b7 v/ }' F7 K2 v3 W
  54.                 }
    7 C% C# f: h5 @
  55.         else {) t/ ~+ s  \( O! r# J5 u3 a& i
  56.         cout << "Failed to read file." << endl;0 G+ X7 H- U4 P$ d+ T6 W% X$ ~
  57.         return -1;3 J8 g* v8 e% H! J) `3 K) a
  58.         }
    5 c1 a% ?6 I; Y3 g3 ~( i
  59.        
    ) B5 F% b1 T3 P1 U
  60.         string processStr (buffer);1 w+ B& i1 o4 k3 K& H! S3 K
  61.         delete [] buffer;# E8 }4 y1 @: z+ o& C' g
  62.         / `) s: U6 v6 e2 q: E' Q! X
  63.         // DUMB DUMB DUMB....; X) H. O/ F/ j% y: M$ a+ ?3 @4 W% |! s0 e
  64.        
    % V! w/ w* e/ k) ~& o; l
  65.         int nextSearchPos = 0;+ w2 O- G9 y3 _) Y, }; E
  66.         int tmpSearchPos[2] = {0};
    2 x$ [2 F0 P- K! I0 [7 W+ N
  67.         int entriesCount = 0;
    3 w+ A! m( z0 Z1 [' o$ j
  68.        
    - |$ y9 C0 n( W8 F  O
  69.        
    & p  i* M" r( y! f* X2 \
  70.         0 i  x' p7 ?! E, @
  71.         while(processStr.find(SYSTEM_BLOCK_STR, nextSearchPos)!=string::npos) {& z" l$ P# b9 s" U
  72.                 nextSearchPos = processStr.find(SYSTEM_BLOCK_STR, nextSearchPos)+8;  G# R: _; d: e! ]4 B
  73.                 tmpSearchPos[0] = processStr.find(NICKNAME_STR, nextSearchPos);
    $ ?( }$ I+ e1 L7 [
  74.                 tmpSearchPos[1] = processStr.find(IDS_STR, nextSearchPos);6 U' f% y: }- Q4 a
  75.                
    + Z, G9 h/ i4 z& E6 b
  76.                 if(tmpSearchPos[0]!=string::npos) {
    5 o& n5 p5 T0 K7 g$ U
  77.                         i=tmpSearchPos[0]+11;
    ) e3 i6 m1 {9 F2 _9 M  s
  78.                         : B1 S- r4 B- G7 j, G8 u  f. v
  79.                         while(processStr[i]!='\n' && processStr[i]!='\r') {# f$ ]' f' `. n; D
  80.                         cout << processStr[i];
    9 a) N# B' G9 C) g& `+ Y
  81.                         i++;4 w0 g% H; Q) x& ~' J( V; d- G2 ?
  82.                         }( q6 p. |, c4 T+ ?% c' h
  83.                         $ |7 }# [, j4 t* |& q; b  w% H8 N
  84.                         cout << endl;
    ! a/ M* d5 _; G8 W8 B1 E( ]2 L; y- b: w
  85.                         + G- W6 F5 z! a  ?! @
  86.                 }
    & g1 G  J' d* l2 a  K7 o% [
  87.                
    " B' _5 h7 _* g3 }' C+ o
  88.                 if(tmpSearchPos[1]!=string::npos) {9 S( f( V( m7 R9 K; t
  89.                         i=tmpSearchPos[1]+13;2 X- u0 K5 a% e. X4 V
  90.                         ) I/ z- q& o' |& I+ {
  91.                         while(processStr[i]!='\n' && processStr[i]!='\r') {
    9 y8 B. l9 I# \& _$ K3 ^
  92.                         cout << processStr[i];- p! t/ R# @" ~
  93.                         i++;, z2 J% Q0 t; u8 z! r; U5 q* c
  94.                         }
    4 P! O3 I6 |: T" I, I+ ?
  95.                        
    " e9 F- j" T6 |# f
  96.                         cout << endl;
    $ O. I3 z- s( X
  97.                        
    3 B' c2 [+ X8 r2 ^) v3 k/ S
  98.                 }
    ( j6 f! _/ U) D" `! U% h
  99.                
    * Y: j  J$ b9 N+ {3 `- G
  100.                 entriesCount++;
    1 \+ k+ x% n" T; W
  101.         }; u! [4 M7 X, Z2 X, I
  102.         * I4 Q" r1 d0 k
  103.         cout<<entriesCount;
    1 O6 u8 T8 P- b+ ^+ g
  104.         return 0;
    : ~4 H2 _/ y3 V0 b$ k
  105.        
    ! ~9 T' W. `; V1 j4 P; |7 V
  106. }
复制代码
Update: 最后一行输出条目数.
! i' D% h, q/ f9 S4 W4 [
( N7 j- Z5 z5 _6 y4 `9 i4 l[ 本帖最后由 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 太空游戏站