데블스캠프2011/넷째날/Git/권순의 (rev. 1.5)
myCmdBase ¶
// myCmdBase.cpp : 콘솔 응용 프로그램에 대한 진입점을 정의합니다.
//
#include "stdafx.h"
#include <iostream>
using namespace std;
#include <string.h>
#include "cmdTest.h"
#include "rei.h"
typedef char (*ARGV)[ARG_SIZE];
typedef int (*PF)(int, ARGV);
struct Cmds{
char cmdName[256];
PF cmd;
} cmds[] = {{"rei", rei}};
int parseCommand(char* str, ARGV argv);
PF getCommander(ARGV argv);
int _tmain(int argc, _TCHAR* argv[])
{
char input[256];
char inputArgv[ARG_NUM][ARG_SIZE] = {0,};
cout<<"input your command : ";
cin>>input;
// 사용자 입력을 띄어쓰기 단위로 나누고 몇개로
int inputArgc = parseCommand(input, inputArgv);
// 커맨드를 비교하여 적절한 커맨드 함수를 받는다.
PF pf = getCommander(inputArgv);
// 커맨드 함수 호출
pf(inputArgc, inputArgv);
return 0;
}
// 문자열을 띄어쓰기 단위로 나눈다.
int parseCommand(char* str, ARGV argv){
if( strlen(str) <= 0 )
return 0; // no command
char* ptr = strtok( str, " ");
strcpy( argv[0], ptr);
int i;
for( i=1; ptr = strtok( NULL, " "); i++)
strcpy(argv[i], ptr);
return i;
}
// 가장 앞 문자열을 이용하여 일치하는 커맨드를 가져온다.
PF getCommander(ARGV argv){
for( int i=0; i<sizeof(cmds)/sizeof(Cmds); i++)
if( strcmp(argv[0], cmds[i].cmdName ) == 0 )
return cmds[i].cmd;
return testCmd;
}
rei.cpp ¶
#include "rei.h"
#include <fstream>
int rei(int argc, char (*argv)[ARG_SIZE]){
ifstream f("rei.txt");
if(!f) {
cout << "Fail to Load File" << endl;
exit(0);
}
char ch;
while(!f.eof()){
f.get(ch);
cout << ch;
}
return 0;
}
rei.txt ¶
Lovely Ayanami Rei ASCII Image.......................
.....................................................
.....................................................
..................:;rriisr:;r,rr:;...................
..............:rssSSiiisi5SG3hhX525r:................
............;rSSisrrrrrrrsi2AirrrrsSSir..............
.........:rSSisrrrrrrrrrrrrr3s;r;rriiS22r............
........;SSsrrrsiiiriiiisrr;iXrS995srrsiXX;..........
......;S2srrrsr:...SS :i;rrsi&h5iSr;;rsi2s:........
.....i5Ss;;r: .. :;ssrr;r;::;;;;;r;rrS3Xr.......
...:2iir;;r; Hr.:r2X5sr;rrr;;;;r;;rrr;;;riAMA;.....
..:2rSr;;;i...2@s2Sirr;;srrrrsrrrrrrrrr;ri;srG@@i....
..5sir;;;;S:rS2rr;r;;r53SrrrrS;rrrrrr;rrrs ;r2M#....
..Sir;;;;r5Sir;;;rri&@h;;rr;2rrrrrrsrsrrrsr .2;iM:...
..S5;;;;ri;;r;;sSh#@#s:is;rGS;rrrrrrSis;riX: . rS:...
..:rSr;;r5s;SM##BX5225r;h#sr2GX;9rr;23irrrrX:Xl ;i;..
...sS;;ii;;3#Bh22i; :r2i;rXSG2;Hir;92Si;rrSA&.;r.:..
...rr;is:r2isS:. .r2:.;s.:srirHir;HrS5rrrr2 .3hr ..
...sr;;;i2s:.s. S#2G#B52; i:srXh3;s#;22rri;9s9si@...
...Sr;;;s;2i.5; 5@@ i2r .r..irMiXrisr22rS5:2@3;;@X .
...sr;sr;ir#rrH rr . riMrS3. :XSG;9i;;A5:.BG .
...is;A3r5r5#;2i :3A:S@&.:5G2h;Bs;sX2: H9 .
...;i;M#3;H:XBi:. .sr s@9.GhhSM;2Arrr2i. @r .
....rsA@MrH&:2B5 . .. ;#. 39i#i;&sS:;h; ;i ..
.....rs@#&X@Xs22r .. .. :sA@ArA;s..XS ::...
.... . ;B@&rB:::.. ... .:sr ;A#MHSr.. ..r.:s;....
...... r##r;r .;:. ;G@@M#X; ..............
....... 2###G29r .:iA@@@#Ms#, ...............
........ :rh#@@@X ;rX@@@@@@GrA.55 ................
......;. A@@@BM@HAM5rri5. r.r& .................
.....:: @2 s@@i::: ; :. . ..::.............
....;r .iAS G@ .&@ B@32#h. ::...........
...2@ . .: ..;s.;@@@@&XSi: .9@@@r .:..........
- 인터넷 찾아보시면 이미지를 텍스트로 바꾸어 주는 사이트 있습니다. 뻘짓하지 마세요