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

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

[复制链接]
发表于 2008-11-14 21:54:00 | 显示全部楼层 |阅读模式
  1. // Nov 14, 2008 - by Euyis7 V" C- Q  Y! v9 G- Z
  2. 2 W& R8 |+ i) X$ B( K2 B3 [
  3. //
    0 l1 }' Q  ~9 Y
  4. // I, the copyright holder of this work, hereby release it into the public domain. This applies worldwide.
    ' A9 S9 w* O3 i# E( j
  5. // In case this is not legally possible,9 g5 D2 |- }5 E9 @1 j/ y4 |; ^( g
  6. // I grant any entity the right to use this work for any purpose, without any conditions, unless such conditions are required by law.4 [# i. r3 j6 v. B, e. P9 \7 B
  7. //
    ) I7 r- r7 o4 U* Y) \

  8. $ e3 @' b0 c" Z
  9. #include <iostream>% u& X: U. z) C* O% `% i; P4 I
  10. #include <fstream>
    : V$ r- M0 n3 s* Y! u+ ?
  11. #include <cctype>
    # D4 e$ K1 a, S* K" W
  12. using namespace std;
    + v: X1 n" i/ [; s% x3 N# t! I

  13. # I& [* |1 W8 [0 e
  14. // MACROS
    ) o; U# ^* O8 d4 F  u
  15. #define SYSTEM_BLOCK_STR "[system]"8 J) o: b9 O7 E& j5 h
  16. #define NICKNAME_STR "nickname = "
    " y  J$ _7 S) ^2 S  j
  17. #define IDS_STR "strid_name = "" J( u) V4 z2 G' ]+ M$ J
  18. //  ~% x5 V, {4 t0 s( E6 L

  19. 4 ~$ j5 z# Q( }8 O4 e3 A2 I/ V
  20. ifstream inf;9 `$ {2 j* [. U$ F5 d3 K
  21. char *buffer;# l7 |* b0 [. Q- ^3 m

  22. ( O. [& ]8 W/ B6 V
  23. int main(int argc, char *argv[])
    $ @; X5 U1 A' [* S  I# ^, |0 s, }1 h
  24. {
    , q5 x* ~0 J" P* j
  25.         int i;" X3 h. A1 q( ?( K/ ?8 X! B" Z0 }
  26.         3 o4 H0 @* S6 M; {; D) S1 m
  27.         if(argc!=2){ % z" C9 F2 R5 S% p* H2 L1 D
  28.                 cout << "This program requires one and only one argument.";
    ; A- a* O) g& K3 @3 S$ j% s
  29.                 return -1;# M) C5 I* x( s& \
  30.                 }! V, ?$ v! M0 k, D# c3 V
  31.         4 v  v) h$ ]1 ~8 J  E7 P8 c
  32.         inf.open(argv[1], ios_base::in | ios_base::ate);* X6 q) u! |$ T3 ^  V! i2 V4 @& U
  33.         if(!inf) {1 b) i% s* P3 ~- Y3 v' h$ ]
  34.                 cout << "Error opening file.";* `0 D7 T: E' w  l* b
  35.                 return -1;
    ( j, e9 x. `9 @5 D+ m1 C$ \
  36.                 }
    : w% [& p4 _# r- V! Z$ R( ]
  37.                 9 A. |* Z* \! R
  38.         int streamLength = inf.tellg();
    $ K5 o+ Q" E8 B3 z, f
  39.         if(streamLength!=-1) {8 k) w; h' U% `3 `
  40.                 inf.seekg(0, ios::beg);' ^" E3 U% J/ N9 G3 L- q, P2 ^
  41.                 $ ]- C5 v  ~1 @5 y3 I
  42.                 buffer = new char [streamLength];2 Y+ u1 A% [# }5 N, Q
  43.                 // Read file;7 {* x( v+ X' ~) |' R1 k; Y" \
  44.                 for(i=0;i<streamLength;i++) {
    ' R* {6 A9 |" `6 b7 _
  45.                         inf.get(buffer[i]);
    0 Y& E0 n2 J# `4 S! l
  46.                         buffer[i] = tolower(buffer[i]);
    5 r% v8 X- F: W! u% S: A8 \
  47.                         }8 k1 p( g3 Z& n1 C2 E/ Y4 q
  48.                
    9 s  B$ X( S! X& A. U
  49.                 /* For testing" O" z# M6 }+ T% c% i
  50.                 for(i=0;i<streamLength;i++) {6 `5 D+ ?) q* o3 I" E# p+ D$ h
  51.                         cout << buffer[i];
    3 q2 N* u" ]3 X6 E1 I
  52.                 }
    $ ^$ O, [: e" g  Q2 j4 i9 b7 z1 B0 c
  53.                 */
    . {9 R: ?) `3 l. A
  54.                 }' R6 I" X3 @7 F- }9 c: \
  55.         else {& Z( s& H) s  f* P6 K
  56.         cout << "Failed to read file." << endl;1 h, D" q7 z6 Y' l: V7 H
  57.         return -1;
    , b$ U/ y+ g- x: c6 v
  58.         }- X# E7 u  ^( c9 L/ h  I" n; t) T' F
  59.        
    9 Y/ E' U8 @# N1 g: i+ A+ |) g
  60.         string processStr (buffer);2 s' ?" e- g" ^3 V4 @
  61.         delete [] buffer;' E# a. j' F2 G! ^, |; H* F
  62.        
    8 H/ v7 ]0 s9 `5 i4 M& [
  63.         // DUMB DUMB DUMB....( T5 g: ^  r# t5 l' B- B! p
  64.        
    4 B6 G: S5 N5 b  u
  65.         int nextSearchPos = 0;. O7 b6 ^! P& V% [  ^2 n3 l
  66.         int tmpSearchPos[2] = {0};
    8 S* l+ P$ j5 _) o  [' `% Y  @0 l  J
  67.         int entriesCount = 0;
    $ X& r& _% {5 [+ k
  68.         6 i# Y+ Y' B- T. C5 ^
  69.         $ c2 p' i9 m* [1 w1 _0 z) b/ A
  70.        
    % _2 E- c  }( h; p
  71.         while(processStr.find(SYSTEM_BLOCK_STR, nextSearchPos)!=string::npos) {; r+ p7 @% s. s+ _1 y
  72.                 nextSearchPos = processStr.find(SYSTEM_BLOCK_STR, nextSearchPos)+8;8 v1 q5 b. g9 Y) F2 W# k
  73.                 tmpSearchPos[0] = processStr.find(NICKNAME_STR, nextSearchPos);/ W( `! P. U; ~; s
  74.                 tmpSearchPos[1] = processStr.find(IDS_STR, nextSearchPos);% O5 G& {6 d" x, Q# k" C/ P
  75.                 : Y" G+ ?5 E; B2 ?8 s
  76.                 if(tmpSearchPos[0]!=string::npos) {4 ], H% F# l. |7 l% l" \+ A
  77.                         i=tmpSearchPos[0]+11;
    0 l7 l) F8 N! m4 w8 v2 ^* n
  78.                        
    . f8 R* B* V% q* P
  79.                         while(processStr[i]!='\n' && processStr[i]!='\r') {; _, v7 ]9 h- @
  80.                         cout << processStr[i];
    * w$ y7 C% ?* K& i# T
  81.                         i++;8 \: W$ ?; x: O3 [- P" L' H
  82.                         }
    ) ^/ @3 m; K& b0 s
  83.                        
    & p& b/ I/ T& ?3 |
  84.                         cout << endl;
    . O6 |! B% `5 a0 G$ H" c
  85.                         ' ^* D5 A" V1 e- K( M2 U1 m
  86.                 }
    , X, K5 u( l. K+ R5 u
  87.                 ! J; q; Z9 Y& n6 S0 |
  88.                 if(tmpSearchPos[1]!=string::npos) {. S2 _+ A0 d/ u4 P8 w
  89.                         i=tmpSearchPos[1]+13;2 n: R0 t! V/ [6 v4 s1 B5 U4 P
  90.                         ! v  O% l$ P, _; l$ `
  91.                         while(processStr[i]!='\n' && processStr[i]!='\r') {5 E( m( z9 ?8 l/ Q, P2 h/ o1 g; F
  92.                         cout << processStr[i];: E1 I3 @& D  \- l. I
  93.                         i++;
    * ~2 c9 U% N# G9 ?5 o* Q3 ]
  94.                         }4 ~, _7 Y- b) E( b3 E- V/ h- A
  95.                        
    : W  L3 e% T2 r* }8 M7 {
  96.                         cout << endl;+ a$ r$ v7 |. ?0 u" q  g
  97.                         2 D, z9 ?9 J; j9 C. \3 e
  98.                 }1 Y& B- {+ w% V/ h
  99.                 7 d* ?8 Z3 C! R$ d
  100.                 entriesCount++;) l" k" a; Z$ j# o/ \
  101.         }; S9 F, D) f4 p9 g5 X0 y3 \9 `
  102.         8 u1 q4 W9 n0 t9 x. F* D: i+ G* F, F# t
  103.         cout<<entriesCount;
    & ~# S$ v# r/ j9 v
  104.         return 0;/ r! N5 \# F; ?. S7 |
  105.         + j/ j, S% ~0 @- f: P
  106. }
复制代码
Update: 最后一行输出条目数.  Q4 t. M* V5 x- j. N& h1 _8 T

% M: U* x4 H2 X  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 太空游戏站