控制台--判断参数


 1 wchar_t * matchEnd(wchar_t *text)
 2 {     
 3     while(*text != (wchar_t)' ' && *text++ != '\0');
 4     return text;
 5 }
 6 
 7 wchar_t * matchValue(wchar_t *text, wchar_t **end)
 8 {                 
 9     do    {    
10         if (*text != (wchar_t)' ')  {
11             *end = matchEnd(text);
12             return text;   
13         }
14     } while (*text++ != '\0');
15     return NULL;
16 }          
17 
18 wchar_t * matchKey(wchar_t *text)
19 {
20     wchar_t *end = NULL;
21     switch (*text)
22     {          
23     case 'd':  /* 接收消息反馈的应用程序 */
24     case 'D':{             
25             wchar_t *value = matchValue(text+1, &end);
26             if (value != NULL){
27                 memcpy(g_DeskWndName,value,end-value);
28                 g_DeskWndName[end-value + 1] = '\0';
29             }   
30         }
31          break;
32     case 'p':  /* 视频文件存放的文件夹 */
33     case 'P':{             
34             wchar_t *value = matchValue(text+1, &end); 
35             if (value != NULL){
36                 memcpy(g_RecordDirPath,value,end-value); 
37                 g_RecordDirPath[end-value + 1] = '\0';
38              }
39         }
40         break;
41     default:   
42         break;
43     }
44     return end;
45 }
46   
47 void matchSet(wchar_t *text)
48 {
49     wchar_t *ret = NULL;
50     do     {
51         if (*text == (wchar_t)'-') { 
52             ret = matchKey(text+1); 
53             if (ret != NULL)    
54                 text = ret;     
55         }
56     } while (*text++ != (wchar_t)'\0');
57 }

wchar_t g_DeskWndName[128] = _T("PrisonSyncDemo");   
wchar_t g_RecordDirPath[255] = _T("D:\\NetworkRecord");  

int main(int argc, _TCHAR* argv[])
{
    wchar_t text[] = {L" -d PrisonTalk -p d:\\\\TalkRecord"};

    matchSet(text);
}

 

posted @ 2016-04-05 17:08  joyce3800  阅读(232)  评论(0编辑  收藏  举报