主要内容:嵌入式常用模板函数(用法说明函数、参数解析函数)
/*显示参数列表*/ void usage() { printf("usage: server [-p:x] [-i:IP] [-o]\n\n"); printf(" -p:x Port number to listen on\n"); printf(" -i:str Interface to listen on\n"); printf(" -o Don't echo the data back\n\n"); ExitProcess(1); } /*验证参数*/ void ValidateArgs(int argc, char **argv) { int i; for (i = 1; i < argc; i++) { if ((argv[i][0] =='-') || (argv[i][0] == '/')) { switch (tolower(argv[i][1])) { /*指定端口*/ case 'p': iPort = atoi(&argv[i][3]); break; /*指定IP*/ case 'i': bInterface = TRUE; if (strlen(argv[i]) > 3) strcpy(szAddress, &argv[i][3]); break; /*只接收消息,不回应*/ case 'o': bRecvOnly = TRUE; break; /*非法参数,显示参数列表*/ default: usage(); break; } } } }
时间: 2024-10-11 05:22:52