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