コマンドライン解析
#include <iostream> #include <cstring> using namespace std; void main(int argc, char *argv[]) { int i; if(argc == 1){ sprintf(szSearchDir, "Empty"); sprintf(szOutputDir, "Empty"); return; } bool bOption = false; // for(i = 1; i < argc; i++) //------- (1) start { cout << argv[i] << endl; // if( //------- (2) - オプションA (strcmp(argv[i], "-ug_step214_dwg") == 0) || (strcmp(argv[i], "-ug_iges_dwg") == 0) ) { sprintf(szOption, "%s", argv[i]); sprintf(szSearchDir, "%s", argv[i + 1]); sprintf(szOutputDir, "%s", argv[i + 2]); sprintf(szDwgOutputDir, "%s", argv[i + 3]); bOption = true; i = i + 3; } else if( //------- (2) - オプションB (strcmp(argv[i], "-dir") == 0) || (strcmp(argv[i], "-subdir") == 0) ) { sprintf(szSearchOption, argv[i]); } else if( //------- (2) - オプションC (strcmp(argv[i], "-mkdir") == 0) || (strcmp(argv[i], "-notmkdir") == 0) ) { sprintf(szMkDirOption, argv[i]); } else //------- (2) - エラー { throw szExtErrMsg("ERROR", __FILE__, __LINE__); } } //------- (1) end if(bOption == false) { throw szExtErrMsg("変換形式未指定", __FILE__, __LINE__); } return; }