水無瀬の部屋 > Programming > sample > exe2ico > cmdline.cpp |
---|
1: //*********************************************************
2: // プロジェクト: exe2ico
3: // ファイル名: cmdline.cpp
4: //*********************************************************
5: #include "cmdline.h"
6:
7:
8: //---------------------------------------------------------
9: // テスト関数 の 宣言
10: //---------------------------------------------------------
11: DECLARE_TESTPROC( test_cmdline );
12:
13:
14: //---------------------------------------------------------
15: // マクロ の 定義
16: //---------------------------------------------------------
17: #define PARAM_NOICO "/ico:0"
18: #define PARAM_NOCUR "/cur:0"
19: #define PARAM_NOBMP "/bmp:0"
20: #define PARAM_NOAVI "/avi:0"
21: #define PARAM_NOWAV "/wav:0"
22: #define PARAM_NOANI "/ani:0"
23:
24:
25: //---------------------------------------------------------
26: // ファイルスコープ変数 の 定義
27: //---------------------------------------------------------
28: static const struct
29: {
30: DWORD flag;
31: const char *param;
32: }
33: g_opt[] =
34: {
35: { FLAG_NOICO, PARAM_NOICO },
36: { FLAG_NOCUR, PARAM_NOCUR },
37: { FLAG_NOBMP, PARAM_NOBMP },
38: { FLAG_NOAVI, PARAM_NOAVI },
39: { FLAG_NOWAV, PARAM_NOWAV },
40: { FLAG_NOANI, PARAM_NOANI },
41: };
42:
43:
44: //*********************************************************
45: // make_cmdline
46: //*********************************************************
47: size_t
48: make_cmdline
49: (
50: char *buffer,
51: size_t bufsize,
52: DWORD flags
53: )
54: {
55: CALLONCE_TESTPROC( test_cmdline ); // [テスト]
56:
57: // パラメタの仮定
58: ASSERT( 0 < bufsize );
59: ASSERT( IsValidStringBufferPtr( buffer, bufsize ) );
60: DESTROY_TEXT_BUFFER( buffer, bufsize ); // [破壊]
61:
62: //
63: char path[ MAX_PATH_BUF ];
64: HINSTANCE hInstance = GetModuleHandle( null );
65: VERIFY( GetModuleFileName( hInstance, path, numof( path ) ) );
66:
67: //
68: size_t count = 0;
69:
70: //
71: count += strputs( buffer, bufsize, count, "\"" );
72: count += strputs( buffer, bufsize, count, path );
73: count += strputs( buffer, bufsize, count, "\"" );
74:
75: //
76: {for( int i = 0; i < numof( g_opt ); ++i )
77: {
78: if ( g_opt[ i ].flag == (flags & g_opt[ i ].flag) )
79: {
80: count += strputs( buffer, bufsize, count, " " );
81: count += strputs( buffer, bufsize, count, g_opt[ i ].param );
82: }
83: }}
84:
85: //
86: count += strputs( buffer, bufsize, count, " " );
87: count += strputs( buffer, bufsize, count, "\"" );
88: count += strputs( buffer, bufsize, count, "%1" );
89: count += strputs( buffer, bufsize, count, "\"" );
90:
91: //
92: if ( buffer && (count < bufsize) ) { buffer[ count ] = '\0'; }
93: if ( !buffer || (count < bufsize) ) { ++count; }
94:
95: ASSERT( IsValidStringPtr( buffer ) );
96: ASSERT( strlen( buffer ) < bufsize );
97:
98: return count;
99: }//make_cmdline
100:
101: //*********************************************************
102: // get_cmdline_option
103: //*********************************************************
104: DWORD
105: get_cmdline_option
106: (
107: int argc,
108: char **argv
109: )
110: {
111: DWORD flags = 0;
112: {for( int i = 1; i < argc; ++i )
113: {
114: {for( int j = 0; j < numof(g_opt); ++j )
115: {
116: if ( streqli( argv[ i ], g_opt[ j ].param ) )
117: {
118: flags |= g_opt[ j ].flag;
119: }
120: }}
121: }}
122:
123: return flags;
124: }//get_cmdline_option
125:
126:
127: //******************************************************************************************************************
128: // TEST
129: //******************************************************************************************************************
130:
131:
132: #ifdef _DEBUG // デバッグ時のみ
133:
134:
135: //*********************************************************
136: // test_cmdline
137: //*********************************************************
138: DEFINE_TESTPROC( test_cmdline )
139: {
140: //---------------------------------------------------------
141: // 定数 の テスト
142: //---------------------------------------------------------
143:
144: //---------------------------------------------------------
145: // ファイルスコープ関数 の テスト
146: //---------------------------------------------------------
147:
148: //---------------------------------------------------------
149: // 公開関数 の テスト
150: //---------------------------------------------------------
151: // make_cmdline(), get_cmdline_option()
152: {
153: const struct
154: {
155: DWORD flags;
156: }
157: testcase[] =
158: {
159: #define MAKE_TESTCASE( flags ) { flags }
160: MAKE_TESTCASE( 0 ),
161: MAKE_TESTCASE( FLAG_NOICO ),
162: MAKE_TESTCASE( FLAG_NOCUR ),
163: MAKE_TESTCASE( FLAG_NOBMP ),
164: MAKE_TESTCASE( FLAG_NOAVI ),
165: MAKE_TESTCASE( FLAG_NOWAV ),
166: MAKE_TESTCASE( FLAG_NOANI ),
167: #undef MAKE_TESTCASE
168: };
169: {for( int i = 0; i < numof( testcase ); ++i )
170: {
171: char cmdline[ MAX_PATH_BUF ];
172: make_cmdline( cmdline, numof(cmdline), testcase[i].flags );
173: ASSERT( IsValidStringPtr( cmdline ) );
174:
175: int argc;
176: char **argv = argcargv( &argc, cmdline, FLG_ARGCARGV_MSDEFAULT );
177: ASSERT( IsValidArgcArgv( argc, argv ) );
178:
179: /* ASSERT( IsPathFile( argv[0] ) );
180: ASSERT( (!testcase[i].argv1 && (argc < 2))
181: || ( testcase[i].argv1 && streql( argv[1], testcase[i].argv1 )) );
182: ASSERT( (!testcase[i].argv2 && (argc < 3))
183: || ( testcase[i].argv2 && streql( argv[2], testcase[i].argv2 )) ); */
184:
185: const DWORD result = get_cmdline_option( argc, argv );
186: ASSERT( result == testcase[i].flags );
187:
188: free_argcargv( argc, argv );
189: }}
190: }
191:
192: }//test_cmdline
193:
194:
195: #endif // #ifdef _DEBUG
196:
197:
198: //** end **
参照:
水無瀬の部屋 > sample > exe2ico > cmdline.cpp |
---|
このページは cpp2web が出力しました。
水無瀬 優 postmaster@katsura-kotonoha.sakura.ne.jp
http://katsura-kotonoha.sakura.ne.jp/prog/code/exe2ico/cmdline_cpp.shtml