Legacy/뇌자극 - WinSysProg

CommandPrmpt_Two.cpp

Foo 2015. 1. 19. 21:53
728x90

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include <stdio.h>
#include <stdlib.h>
#include <tchar.h>
#include <locale.h>
#include <Windows.h>
 
#define STR_LEN 256
#define CMD_TOKEN_NUM 10
 
TCHAR ERROR_CMD[] = _T("'%s'은(는) 실행할 수 있는 프로그램이 아닙니다. \n");
 
int CmdProcessing(void);
TCHAR * StrLower(TCHAR *);
 
int _tmain(int argc, TCHAR * argv[])
{
    _tsetlocale(LC_ALL, _T("Korean"));
 
    DWORD isExit;
    while(1)
    {
        isExit = CmdProcessing();
        if(isExit == TRUE)
        {
            _fputts(_T("명령어 처리를 종료합니다. \n"), stdout);
            break;
        }
    }
    return 0;
}
 
TCHAR cmdString[STR_LEN];
TCHAR cmdTokenList[CMD_TOKEN_NUM][STR_LEN];
TCHAR seps[] = _T(" ,\t\n");
 
int CmdProcessing(void)
{
    _fputts( _T("Best command prompt>> "), stdout);
    _getts(cmdString);
 
    TCHAR * token = _tcstok(cmdString, seps);
    int tokenNum = 0;
    while(token != NULL)
    {
        _tcscpy( cmdTokenList[tokenNum++], StrLower(token) );
        token = _tcstok(NULL, seps);
    }
 
    if( !_tcscmp(cmdTokenList[0], _T("exit")) )
    {
        return TRUE;
    }
    else if( !_tcscmp(cmdTokenList[0], _T("추가 되는 명령어 1")) )
    {
    }
    else if( !_tcscmp(cmdTokenList[0], _T("추가 되는 명령어 2")) )
    {
    }
    else
    {
        STARTUPINFO si = {0,};
        PROCESS_INFORMATION pi;
        si.cb = sizeof(si);
        BOOL isRun =
            CreateProcess ( NULL, cmdTokenList[0], NULL, NULL,
                TRUE, 0, NULL, NULL, &si, &pi);
        if(isRun == FALSE)
            _tprintf(ERROR_CMD, cmdTokenList[0]);
    }
    return 0;
}
 
TCHAR * StrLower(TCHAR *pStr)
{
    TCHAR *ret = pStr;
 
    while(*pStr)
    {
        if(_istupper(*pStr))
            *pStr = _totlower(*pStr);
        pStr++;
    }
    return ret;
}