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