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

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

[复制链接]
发表于 2008-11-14 21:54:00 | 显示全部楼层 |阅读模式
  1. // Nov 14, 2008 - by Euyis
    2 q# n" U+ }9 z5 ?/ C

  2. + W5 c. F. }6 g' G  v* Q2 O
  3. //
    , p/ W5 y# V  ?. `
  4. // I, the copyright holder of this work, hereby release it into the public domain. This applies worldwide.
    ; a( S' _9 ~  B
  5. // In case this is not legally possible,
    7 `6 y4 k+ y. p8 H" w# H
  6. // I grant any entity the right to use this work for any purpose, without any conditions, unless such conditions are required by law." S7 y& s+ i1 b4 @
  7. //
    - P6 ?) s" S% \! B+ v( y2 U' t" w% ]

  8. 1 w( ~$ k  Y6 |2 l
  9. #include <iostream>% o6 a5 |0 c, s) B% F& K" |
  10. #include <fstream>3 I( {( E1 e9 w/ t; Q7 Z
  11. #include <cctype>
    " @# U2 N, a* }4 I
  12. using namespace std;! L% y) V5 ?1 G3 D; \

  13. 0 `6 H  V# d; ~' L7 Z9 b
  14. // MACROS7 ^+ H4 f4 m& j5 X  w; o
  15. #define SYSTEM_BLOCK_STR "[system]"
    % j: }! C. E4 p6 \6 [' L1 O
  16. #define NICKNAME_STR "nickname = "
    4 A1 ]5 T6 n8 C7 P
  17. #define IDS_STR "strid_name = "
    % J9 O3 N- I: z$ u, U2 }/ V- j
  18. //
    7 E4 S1 O: w1 w" z3 b
  19. 1 J( I2 I) l7 [$ a3 k
  20. ifstream inf;
    ; r8 p; M$ d- M$ r3 t7 N+ H# z
  21. char *buffer;
    0 ]; U  V/ e: X/ Y8 d$ O
  22. / t( s, _' N/ |! e1 R& r
  23. int main(int argc, char *argv[])
    5 T) x9 ^; @3 f- M1 Z& m
  24. {. M/ Z+ N1 C  G0 ^  s
  25.         int i;
    6 ~2 a: N' |2 O$ N1 T
  26.         ! }1 U! E0 S# g- k
  27.         if(argc!=2){
    : }% E6 g+ a. M6 I: K: S
  28.                 cout << "This program requires one and only one argument.";
    ( E3 E1 Y3 j" z: ^
  29.                 return -1;- x& i& Q2 l# `& W* {! e5 T& F
  30.                 }
    ! V5 \/ N- q) g! x
  31.         " K1 }4 F% m2 w9 s9 o; f
  32.         inf.open(argv[1], ios_base::in | ios_base::ate);
    5 s9 h1 k3 a# I' P7 ]
  33.         if(!inf) {
    - A# C( n; F0 p# D3 `) x7 p
  34.                 cout << "Error opening file.";
    + S8 u' D5 h. K3 g& h& O
  35.                 return -1;
    , N- x- M' u9 O7 Z1 m) a/ I2 b
  36.                 }1 o4 j( y6 n$ G2 E
  37.                 ' ~, x1 D0 d9 }" s) G$ K% z2 N
  38.         int streamLength = inf.tellg();; i+ U6 B; i2 X" b
  39.         if(streamLength!=-1) {4 \( n8 n2 W9 A) b) B3 [, a
  40.                 inf.seekg(0, ios::beg);
    ) U4 J+ y$ H2 F: v- [/ f$ f) ?3 j, v
  41.                
    & ^& d9 ^: {& r" T
  42.                 buffer = new char [streamLength];
    ' S' u$ ?  Y5 @  Z8 n+ h# S
  43.                 // Read file;
    - K8 [$ n2 M# L) ~
  44.                 for(i=0;i<streamLength;i++) {
    . U! R# g/ g6 u& _5 E/ u1 {* F
  45.                         inf.get(buffer[i]);0 Z! v" N, A- r4 }
  46.                         buffer[i] = tolower(buffer[i]);: |$ g2 i* Z  e4 o* m" a
  47.                         }
    & J+ R2 R8 y2 n& N2 g
  48.                 : Y/ Z1 `+ h/ e3 D. o! Z8 ~7 ]
  49.                 /* For testing. k" N6 f5 M8 r
  50.                 for(i=0;i<streamLength;i++) {
    6 L6 L5 V( W! A8 k5 J
  51.                         cout << buffer[i];
    * X* O  i2 r$ h  ]$ j! H2 A
  52.                 }0 t3 v& r2 @9 k
  53.                 */' Y. t  F( S1 e9 \! C6 L! a
  54.                 }. f& u* n2 Q9 E5 m1 F8 P. V2 r
  55.         else {
    1 V3 R  f4 c6 r1 V
  56.         cout << "Failed to read file." << endl;
    7 {6 [  Z) v! U' u. [2 T  ~
  57.         return -1;- W& l3 r7 t% n( Y" K+ U+ ]
  58.         }5 ^: {7 Y1 h0 b7 {6 J+ o
  59.        
    5 [& L2 Y5 ^, X. h6 D# a
  60.         string processStr (buffer);
    4 p5 [! D0 t, b% E0 z8 V3 A7 \; P4 R
  61.         delete [] buffer;
    $ w, t' A5 f7 y0 m5 U
  62.        
    . Q/ J& h+ \/ ~7 D8 b
  63.         // DUMB DUMB DUMB....+ P8 l0 p. H5 }0 \4 U6 ~! {: t
  64.         7 z2 P$ c% \* O! S& h$ x
  65.         int nextSearchPos = 0;
      B# r% y" P! _3 {( e! Y, O3 h
  66.         int tmpSearchPos[2] = {0};0 S$ y6 A' r: F9 g' B$ U
  67.         int entriesCount = 0;
    4 C# F' c2 `3 t: S9 n( [( T2 W) t
  68.        
    5 U8 p, N. w( |9 r8 e- Q. W& @
  69.         ; v; o+ [% I+ _7 }% d3 l7 C
  70.        
    ' `8 [8 Z* C2 n( J5 ]
  71.         while(processStr.find(SYSTEM_BLOCK_STR, nextSearchPos)!=string::npos) {
    . C4 v6 {3 l/ t- i3 R- {/ `# \% L
  72.                 nextSearchPos = processStr.find(SYSTEM_BLOCK_STR, nextSearchPos)+8;
    $ h! F3 \; H3 l. Q. H5 R) w8 M
  73.                 tmpSearchPos[0] = processStr.find(NICKNAME_STR, nextSearchPos);1 t& J& W7 C3 a. U6 N
  74.                 tmpSearchPos[1] = processStr.find(IDS_STR, nextSearchPos);# b5 u4 s' X. O, G) m5 H4 B" V5 O
  75.                 % P! o1 U) V/ P9 A9 i
  76.                 if(tmpSearchPos[0]!=string::npos) {. P* W0 j: m2 T1 ?
  77.                         i=tmpSearchPos[0]+11;
    : n% ~- \  [  T& a
  78.                         $ y$ a6 K% j: q6 P% B. d2 s
  79.                         while(processStr[i]!='\n' && processStr[i]!='\r') {
    : M" }; Z$ S+ v: I
  80.                         cout << processStr[i];
      P: t" W: Y2 L) u% j! p& `
  81.                         i++;
    0 F* x' M. C: c4 l& F) S4 u
  82.                         }+ ^3 O( v& y/ w
  83.                        
    6 U/ e$ I8 a: |/ l
  84.                         cout << endl;5 x/ U9 _  T3 h
  85.                        
    0 A. k# d# c; L* z
  86.                 }' w1 y% C7 D8 N) b0 Z: g- z
  87.                 - A* ]" R; c3 k* o* U
  88.                 if(tmpSearchPos[1]!=string::npos) {
    / ]( F8 L+ o9 y, M" t7 i
  89.                         i=tmpSearchPos[1]+13;
    # m; U( i+ h7 z3 k' M4 Y( J
  90.                         : |/ i$ c6 F9 I8 C& K: h, M7 y
  91.                         while(processStr[i]!='\n' && processStr[i]!='\r') {* j; n% P# {% W7 e) N. z0 L7 P+ {2 M
  92.                         cout << processStr[i];
    6 ~: @9 R5 p% z% U3 g; H) q& k
  93.                         i++;" a3 O  A& K  g
  94.                         }6 _$ }2 S4 O6 M3 W( ]; [
  95.                         3 ^. l1 s* j- Y, N  c
  96.                         cout << endl;; l+ n2 R) {% `- R; W% N4 G" F
  97.                         + Y$ f; ~& l3 R' {; j$ s# i) p2 D- C
  98.                 }/ @' D( p5 W* `* E. ^- f1 \: p
  99.                 ( H& C2 u" Q& F
  100.                 entriesCount++;3 m# B( S& {7 P/ r# v. Z
  101.         }
    + t$ X& g/ G1 H" x
  102.        
    # `  e- L. q/ P; `# V
  103.         cout<<entriesCount;/ h. t$ U" _: ]7 j. h* b
  104.         return 0;: y& g9 H9 N7 e3 v  t. L
  105.        
    2 d/ U8 v7 \- M+ H* l7 `
  106. }
复制代码
Update: 最后一行输出条目数.  z  i# ?  R/ k$ U* b

& C& x) g! m2 ~) R0 j9 o[ 本帖最后由 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 太空游戏站