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

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

[复制链接]
发表于 2008-11-14 21:54:00 | 显示全部楼层 |阅读模式
  1. // Nov 14, 2008 - by Euyis
    ) {8 W3 i& K8 P) e" `: Z9 R

  2. 9 ]! b/ M0 U- W# @3 h
  3. //* l6 k4 M9 ^5 Q, O
  4. // I, the copyright holder of this work, hereby release it into the public domain. This applies worldwide.
    3 Q) t& S2 j! G7 d% w5 v; M- o# \
  5. // In case this is not legally possible,5 b: h4 [: T$ G- R$ k0 A
  6. // I grant any entity the right to use this work for any purpose, without any conditions, unless such conditions are required by law.7 h1 B6 L. d! Q
  7. //# \, y) o. H9 z, h+ o& n. L1 [8 ^$ p

  8. ! G( _8 U& [! _9 C1 Q( X  \! H2 Y
  9. #include <iostream>; m' s; E! b+ L$ g/ Y+ b- I
  10. #include <fstream>6 X0 }& d  s0 e  Y! d
  11. #include <cctype>6 y. P; k; t' G. w3 X/ f$ G
  12. using namespace std;
    : Z1 u8 ]; d/ m% n; J9 y- w2 ~& ~
  13. 4 W# X; A+ l1 _: q
  14. // MACROS9 Q4 G6 M1 z( z* d3 R9 B
  15. #define SYSTEM_BLOCK_STR "[system]"
    2 D  R2 W6 E9 l5 p; c0 k
  16. #define NICKNAME_STR "nickname = "6 D( M! k( R! [8 K7 ~" C
  17. #define IDS_STR "strid_name = "% a- Z& R# x) c
  18. //
    : m4 Q  O8 |. u0 w4 S

  19. & a- o( p" n% P. R, M
  20. ifstream inf;
    ; @6 u2 I" D5 n$ j+ _
  21. char *buffer;. _0 J. D; d3 A2 Q8 s3 \4 P1 @. @

  22. # q5 b- Z( k" b
  23. int main(int argc, char *argv[])
    6 i6 X+ n* B! ~, o3 ], h
  24. {
    9 n% q9 Z- V) m1 n7 l& O$ Y1 r
  25.         int i;" c) X$ i5 f/ ?! l5 X* E, G0 [' k
  26.         7 [9 [% y5 e# v& V! N; C
  27.         if(argc!=2){
    " H  l4 a& _/ b7 g
  28.                 cout << "This program requires one and only one argument.";
    ( w7 O$ ]4 C0 `7 J
  29.                 return -1;$ R! o5 ?) z! z
  30.                 }8 J9 C7 X0 c$ ~
  31.           _/ t$ r9 i, O6 I8 |) A
  32.         inf.open(argv[1], ios_base::in | ios_base::ate);/ I( w9 C  f2 T1 m0 d& |/ ?
  33.         if(!inf) {0 R1 J* F2 p5 |  b0 I: ~
  34.                 cout << "Error opening file.";! W( Q9 X5 z8 q* z/ ?. i, r
  35.                 return -1;8 s# k6 _- |  O  I
  36.                 }
    # ?, e# ^9 U+ M$ `1 E
  37.                
    4 k8 C9 V  ^0 j3 m
  38.         int streamLength = inf.tellg();. J" w3 W$ w4 A( u' q5 i# `8 z
  39.         if(streamLength!=-1) {, l* C! O: v/ Y" \4 `& V3 `  t
  40.                 inf.seekg(0, ios::beg);
    2 `1 ]6 q/ z/ U  L7 O6 s
  41.                 $ C& a2 y2 @( n) t. ^0 Y
  42.                 buffer = new char [streamLength];
    % H3 l8 q, V' w$ s. d, I
  43.                 // Read file;! r% a5 X/ a1 S( C5 T) W9 X
  44.                 for(i=0;i<streamLength;i++) {
    . W' D. p: N3 w  v
  45.                         inf.get(buffer[i]);- e' s. n; Q# W& F9 I9 y* Z* `
  46.                         buffer[i] = tolower(buffer[i]);
    . {- ?7 J; R  \- b; s5 a$ Y. y
  47.                         }" M' y" D9 u3 P0 b7 ^5 L
  48.                
    ( j) W3 {" o: J5 `! a
  49.                 /* For testing( }% g9 H( ~% L; X7 b+ O  z, w% g
  50.                 for(i=0;i<streamLength;i++) {
    7 ?5 I! s) ^: h$ \
  51.                         cout << buffer[i];+ e; O# [# D9 J, ^4 |/ K
  52.                 }
    3 ]* a# {  ]7 m. t; r# N  q: H
  53.                 */
      [% ~, T# t: @, `
  54.                 }
    # d. x- Z( P  l% m
  55.         else {; J2 x/ A, w3 D6 ~
  56.         cout << "Failed to read file." << endl;8 n( `. ]: m, I8 M) `! m& _
  57.         return -1;! r7 p; ?3 l4 {+ H) r4 a) F. H
  58.         }! Z) o. A5 a6 W+ ]( D  f9 g$ H
  59.        
      s$ [) [2 X' h2 F1 r8 M. O( s% e
  60.         string processStr (buffer);: v8 E) R9 n7 U( b5 n
  61.         delete [] buffer;/ g6 X* @+ M6 {& W' [
  62.        
    % H, J, K. j* y2 Y1 C  Z: w( }
  63.         // DUMB DUMB DUMB....
    0 ]/ ~: s5 Y! P9 y
  64.        
      F+ `3 ~/ N- m# |5 T
  65.         int nextSearchPos = 0;9 P, N/ C3 f0 h# ]; G# q
  66.         int tmpSearchPos[2] = {0};6 M+ N' G2 o+ {- `$ p' p$ C0 l
  67.         int entriesCount = 0;1 |) i% u' g. \. y( y( l
  68.         & D7 g0 r$ w: }, g3 p" h
  69.        
    & i+ R0 \. Y/ `# H8 B
  70.         # q# t5 x$ k, C
  71.         while(processStr.find(SYSTEM_BLOCK_STR, nextSearchPos)!=string::npos) {" Y- a3 X! |) ~; V
  72.                 nextSearchPos = processStr.find(SYSTEM_BLOCK_STR, nextSearchPos)+8;- P7 n  c8 N+ k4 H
  73.                 tmpSearchPos[0] = processStr.find(NICKNAME_STR, nextSearchPos);
    + Q* s& L, b* s7 Z. A
  74.                 tmpSearchPos[1] = processStr.find(IDS_STR, nextSearchPos);0 v1 g% J6 }5 P3 P) N5 ^" f
  75.                
    5 g" ?4 w5 T) u! h, x5 j$ t6 v
  76.                 if(tmpSearchPos[0]!=string::npos) {
    * F- @% r1 @* i  G
  77.                         i=tmpSearchPos[0]+11;
    1 f8 U  I( P( E- e* ~
  78.                        
    1 e1 k9 O5 _! X( J. y# @  ~% }
  79.                         while(processStr[i]!='\n' && processStr[i]!='\r') {: u( X& j4 t" X
  80.                         cout << processStr[i];
    1 {* U1 s, b7 p4 |6 z+ {/ B
  81.                         i++;2 w, f9 W! ~0 E! r( w5 \: S
  82.                         }
    - q2 }$ j$ ^8 N$ v3 c$ t3 z% w
  83.                        
    ' P# V/ v  F2 \: m! V
  84.                         cout << endl;
    # G9 Q( j: k) t: s, ?. K6 P. g% ]
  85.                         * x9 {/ b( U5 {' {: ~  k8 B  e
  86.                 }: |7 \" a, `/ B* Y  K' N
  87.                
    7 @( c8 t/ Y# c8 J; n
  88.                 if(tmpSearchPos[1]!=string::npos) {
    : Z( k4 @* k& t/ W3 t0 V
  89.                         i=tmpSearchPos[1]+13;
    + K; U- ?8 ^6 g0 |! g5 W
  90.                         : b: _& S) ?6 b* Z- w, q1 @6 z
  91.                         while(processStr[i]!='\n' && processStr[i]!='\r') {
    % J, o% H2 e# _/ q8 |
  92.                         cout << processStr[i];, }4 @' E9 b! }- N- ]/ x. P2 X
  93.                         i++;
    4 o2 o5 S/ `3 v
  94.                         }: r& @3 f1 }) J9 i- i
  95.                         * J1 m1 |" V. H0 v8 A# E: y
  96.                         cout << endl;
    : ^* H! U( M8 Q6 {
  97.                        
    / o8 Z; o: d2 Y0 r
  98.                 }
    , |  B3 B# [/ G, c$ n: l
  99.                
    ' w- N& E+ H$ T; h  Q
  100.                 entriesCount++;
    * m/ [8 U; Q& q$ n$ h
  101.         }& n7 f$ h( I; Q$ m: Y
  102.         % L2 }! l6 V9 K1 C' r! W
  103.         cout<<entriesCount;$ r- b7 E$ T" ~4 F  R& m7 r
  104.         return 0;6 v' O( l" Y6 E, N3 s/ W) P
  105.         7 H; G* W) M  h( ]$ s4 s
  106. }
复制代码
Update: 最后一行输出条目数.
* t4 {% h% A- M  k- e
# R9 T6 G! b8 v- W/ U9 |9 m2 y[ 本帖最后由 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 太空游戏站