OSDN Git Service

vbslib 5.92
[vbslib/main.git] / _src / Test / tools / scriptlib / vbslib / CheckEnglishOnly / CheckEnglishOnly_src / CheckEnglishOnly.c
1 #include  "include_c.h" \r
2 \r
3 enum { gs_PathLengthMax = 1024 };\r
4 \r
5 typedef struct _MainWorkClass  MainWorkClass;\r
6 struct _MainWorkClass {\r
7         TCHAR*  ReadingPath;\r
8         int     NotEnglishCount_InReading;\r
9         bool    IsTry_ForCRT;   /* CRT = C language runtime library */\r
10         bool    IsError_InCRT;  /* CRT = C language runtime library */\r
11         _invalid_parameter_handler  old_invalid_parameter_handler;\r
12 };\r
13 MainWorkClass  g_MainWorkClass;\r
14 \r
15 int   Main_getFilePathFromNestFind( FileT_CallByNestFindData* m );\r
16 void  Main_atExit( const wchar_t * expression, const wchar_t * function, \r
17         const wchar_t* file,  unsigned int line,  uintptr_t pReserved );\r
18 \r
19 \r
20  \r
21 /***********************************************************************\r
22   <<< [_tmain] >>> \r
23 ************************************************************************/\r
24 int  _tmain( int argc, TCHAR* argv[] )\r
25 {\r
26         errnum_t        e;\r
27         MainWorkClass*  work = &g_MainWorkClass;\r
28         FILE*           f = NULL;\r
29         StrT_Mul        paths;\r
30         TCHAR*          path;\r
31         Set2            except_names;\r
32         StrMatchKey*    except_name;\r
33         StrMatchKey*    except_name_over;\r
34         int             line_num;\r
35         bool            is_eng;\r
36         TCHAR           line[512];\r
37         TCHAR           check_folder_path[ gs_PathLengthMax ];\r
38         TCHAR           base_path[ gs_PathLengthMax ];\r
39         TCHAR           setting_path[ gs_PathLengthMax ];\r
40 \r
41         StrT_Mul_initConst( &paths );\r
42         Set2_initConst( &except_names );\r
43         work->ReadingPath = NULL;\r
44         work->IsTry_ForCRT = false;\r
45         work->IsError_InCRT = false;\r
46 \r
47         #if USE_GLOBALS\r
48                 Globals_initConst();\r
49                 e= Globals_initialize(); IF(e){goto fin;}\r
50         #endif\r
51 \r
52         SetBreakErrorID( 1 );\r
53 \r
54         _tprintf( _T(" ((( CheckEnglishOnly )))\n") );\r
55         _tprintf( _T("\83e\83L\83X\83g\83t\83@\83C\83\8b\82ª\89p\8cê\82¾\82¯\82É\82È\82Á\82Ä\82¢\82é\82©\83`\83F\83b\83N\82µ\82Ü\82·\81B\n") );\r
56 \r
57 \r
58         work->old_invalid_parameter_handler = _set_invalid_parameter_handler( Main_atExit );\r
59 \r
60 \r
61         /* Set "check_folder_path" : \89p\8cê\82¾\82¯\82©\82ð\83`\83F\83b\83N\82·\82é\83t\83H\83\8b\83_\81[\82Ì\83p\83X\81A\82Ü\82½\82Í\81A\83t\83@\83C\83\8b\82Ì\83p\83X */\r
62         _tcscpy_s( check_folder_path, _countof(check_folder_path), _T("") );  // default\r
63         e= GetCommandLineNamed( _T("Folder"), false, check_folder_path, sizeof(check_folder_path) );\r
64         if ( e != E_NOT_FOUND_SYMBOL ) { IF(e){goto fin;} }\r
65 \r
66         _tprintf( _T("\83`\83F\83b\83N\82·\82é\83t\83@\83C\83\8b\82Ü\82½\82Í\83t\83H\83\8b\83_\81[\82Ì\83p\83X: %s\n"), check_folder_path );\r
67         IF( ! FileT_isDir( check_folder_path ) ) goto err_fo;\r
68 \r
69 \r
70         /* Set "setting_path" : \90Ý\92è\83t\83@\83C\83\8b\82Ì\83p\83X */\r
71         _tcscpy_s( setting_path, _countof(setting_path), _T("") );  // default\r
72         e= GetCommandLineNamed( _T("Setting"), false, setting_path, sizeof(setting_path) );\r
73         if ( e != E_NOT_FOUND_SYMBOL ) { IF(e){goto fin;} }\r
74 \r
75         _tprintf( _T("\90Ý\92è\83t\83@\83C\83\8b\82Ì\83p\83X: %s\n"), setting_path );\r
76         IF( setting_path[0] != _T('\0')  &&  ! FileT_isFile( setting_path ) ) {goto err_st;}\r
77 \r
78         if ( setting_path[0] != _T('\0') ) {\r
79                 e= StrT_getParentFullPath( base_path,  sizeof( base_path ),  setting_path,  NULL );\r
80                         IF(e){goto fin;}\r
81         } else {\r
82                 e= StrT_getFullPath( base_path,  sizeof( base_path ),  check_folder_path,  NULL );\r
83                         IF(e){goto fin;}\r
84         }\r
85 \r
86 \r
87         /* Set "except_names" : \90Ý\92è\83t\83@\83C\83\8b\82É\8ew\92è\82µ\82½ "ExceptFile" */\r
88         e= Set2_init( &except_names, 0x20 ); IF(e){goto fin;}\r
89         if ( setting_path[0] != _T('\0') ) {\r
90                 TCHAR* right;\r
91                 TCHAR  full_path[ gs_PathLengthMax ];\r
92 \r
93                 e= FileT_openForRead( &f, setting_path ); IF(e){goto fin;}\r
94                 for (;;) {\r
95                         _fgetts( line, _countof(line), f );\r
96 \r
97                         right = IniStr_refRight( line, true );\r
98                         if ( IniStr_isLeft( line, _T("ExceptFile") ) ) {\r
99 \r
100                                 if ( right[0] == _T('*') ) {\r
101                                         e= StrT_cpy( full_path, sizeof( full_path ), right ); IF(e){goto fin;}\r
102                                 } else {\r
103                                         e= StrT_getFullPath( full_path, sizeof( full_path ),\r
104                                                 right,  base_path );\r
105                                                 IF(e){goto fin;}\r
106                                 }\r
107 \r
108                                 e= Set2_alloc( &except_names, &except_name, StrMatchKey ); IF(e){goto fin;}\r
109                                 StrMatchKey_initConst( except_name );\r
110                                 e= StrMatchKey_init( except_name, full_path ); IF(e){goto fin;}\r
111                         }\r
112                         if ( feof( f ) )  break;\r
113                 }\r
114                 fclose( f );  f = NULL;\r
115         }\r
116 \r
117 \r
118         /* Set "paths" : \83`\83F\83b\83N\82·\82é\83t\83@\83C\83\8b\82Ì\83p\83X\82Ì\8fW\8d\87\81B"path" \82Í\83t\83\8b \83p\83X */\r
119         e= StrT_Mul_init( &paths ); IF(e){goto fin;}\r
120         e= FileT_callByNestFind( check_folder_path, 0, &paths, (FuncType) Main_getFilePathFromNestFind );\r
121                 IF(e){goto fin;}\r
122         is_eng = false;\r
123         for ( StrT_Mul_forEach( &paths, &path ) ) {\r
124 \r
125                 /* "path" \82ª\81A\83`\83F\83b\83N\82ð\82µ\82È\82¢\83t\83@\83C\83\8b "except_names" \82É\8aÜ\82Ü\82ê\82é\82È\82ç\83X\83L\83b\83v\82·\82é */\r
126                 except_name_over = (StrMatchKey*) except_names.Next;\r
127                 for ( except_name = (StrMatchKey*) except_names.First;  except_name < except_name_over;  except_name++ ) {\r
128                         if ( StrMatchKey_isMatch( except_name, path ) ) { break; }\r
129                 }\r
130                 if ( except_name < except_name_over ) { continue; }\r
131 \r
132 \r
133                 /* "path" \83t\83@\83C\83\8b\82ð\8aJ\82­ */\r
134                 e= FileT_openForRead( &f, path ); IF(e){goto fin;}\r
135                 work->ReadingPath = path;\r
136                 work->NotEnglishCount_InReading = 0;\r
137                 line_num = 0;\r
138 \r
139 \r
140                 /* \83`\83F\83b\83N\82·\82é\83t\83@\83C\83\8b\82Ì\8ds\82Ì\83\8b\81[\83v */\r
141                 for (;;) {\r
142                         line[0] = _T('\0');\r
143                         work->IsTry_ForCRT = true;\r
144                         _fgetts( line, _countof(line), f );\r
145                         work->IsTry_ForCRT = false;\r
146                         IF( ferror( f ) ) goto err;\r
147                         IF( work->IsError_InCRT ) { e=E_BINARY_FILE; goto fin; }\r
148                         line_num ++;\r
149                         if ( line[0] != _T('\0') ) {\r
150                                 TCHAR*  p;\r
151                                 TCHAR   step_path[ gs_PathLengthMax ];\r
152 \r
153                                 /* 1\8ds\95ª\82Ì\83e\83L\83X\83g\82ª\81A\82·\82×\82Ä\89p\8cê\82Å\82È\82¯\82ê\82Î\81A\83G\83\89\81[\83\81\83b\83Z\81[\83W\82Æ\93à\97e\82ð\95\\8e¦\82·\82é */\r
154                                 for ( p = &line[0];  *p != _T('\0');  p++ ) {\r
155                                         if ( *p > 127 ) {\r
156                                                 work->NotEnglishCount_InReading += 1;\r
157                                                 if ( work->NotEnglishCount_InReading == 1 ) {\r
158                                                         e= StrT_getStepPath( step_path, sizeof( step_path ),\r
159                                                                 path,  base_path );\r
160                                                                 IF(e){goto fin;}\r
161 \r
162                                                         _tprintf( _T("\n<FILE path=\"%s\">\n"), step_path );\r
163                                                 }\r
164                                                 e= StrT_trim( line, sizeof(line), line ); IF(e){goto fin;}\r
165                                                 e= StrT_changeToXML_Attribute( line, sizeof(line), line ); IF(e){goto fin;}\r
166                                                 _tprintf( _T("  <LINE num=\"%d\" text=\"%s\"/>\n"), line_num, line );\r
167                                                 break;\r
168                                         }\r
169                                 }\r
170                         }\r
171                         if ( feof( f ) )  break;\r
172                 }\r
173                 if ( work->NotEnglishCount_InReading > 0 ) {\r
174                         _tprintf( _T("  <SUMMARY count=\"%d\"/>\n"), work->NotEnglishCount_InReading );\r
175                         _tprintf( _T("</FILE>\n") );\r
176                         is_eng = true;\r
177                 }\r
178                 e= FileT_closeAndNULL( &f, 0 ); IF(e){goto fin;}\r
179                 work->ReadingPath = NULL;\r
180         }\r
181         if ( is_eng ) goto err;\r
182 \r
183         e=0;\r
184 fin:\r
185         e= FileT_closeAndNULL( &f, e );\r
186         e= StrT_Mul_finish( &paths, e );\r
187 \r
188         except_name_over = (StrMatchKey*) except_names.Next;\r
189         for ( except_name = (StrMatchKey*) except_names.First;  except_name < except_name_over;  except_name++ ) {\r
190                 e= StrMatchKey_finish( except_name, e );\r
191         }\r
192         e= Set2_finish( &except_names, e );\r
193 \r
194         e= Globals_finalize( e );\r
195         Error4_showToStdErr( e );\r
196         IfErrThenBreak();\r
197         return  e;\r
198 \r
199 err:\r
200         e=1;  goto fin;\r
201 \r
202 err_fo:\r
203         Error4_printf( _T("<ERROR msg=\"\83t\83H\83\8b\83_\81[\82ª\8c©\82Â\82©\82è\82Ü\82¹\82ñ\"/>") );\r
204         e=1;  goto fin;\r
205 \r
206 err_st:\r
207         Error4_printf( _T("<ERROR msg=\"\90Ý\92è\83t\83@\83C\83\8b\82ª\8c©\82Â\82©\82è\82Ü\82¹\82ñ\"/>") );\r
208         e=1;  goto fin;\r
209 }\r
210 \r
211 \r
212  \r
213 /***********************************************************************\r
214   <<< [Main_getFilePathFromNestFind] >>> \r
215 ************************************************************************/\r
216 int  Main_getFilePathFromNestFind( FileT_CallByNestFindData* m )\r
217 {\r
218         int        e;\r
219         StrT_Mul*  paths;\r
220         TCHAR      full_path[ gs_PathLengthMax ];\r
221 \r
222         paths = (StrT_Mul*) m->CallerArgument;\r
223         e= StrT_getFullPath( full_path, sizeof(full_path), m->FullPath, NULL ); IF(e){goto fin;}\r
224         e= StrT_Mul_add( paths, full_path, NULL ); IF(e){goto fin;}\r
225 \r
226         e=0;\r
227 fin:\r
228         return  e;\r
229 }\r
230 \r
231 \r
232  \r
233 /***********************************************************************\r
234   <<< [Main_atExit] >>> \r
235 ************************************************************************/\r
236 void  Main_atExit( const wchar_t * expression, const wchar_t * function, \r
237         const wchar_t* file,  unsigned int line,  uintptr_t pReserved )\r
238 {\r
239         MainWorkClass*  work = &g_MainWorkClass;\r
240 \r
241         if ( work->IsTry_ForCRT ) {\r
242 \r
243                 if ( work->NotEnglishCount_InReading == 0 ) {\r
244                         _tprintf( _T("<FILE path=\"%s\">\n"), work->ReadingPath );\r
245                 }\r
246                 _tprintf( _T("  <LINE num=\"0\" text=\"(This is binary file)\"/>\n") );\r
247                 _tprintf( _T("</FILE>\n") );\r
248                 work->IsError_InCRT = true;\r
249         }\r
250         else {\r
251                 work->old_invalid_parameter_handler( expression, function, file, line, pReserved );\r
252         }\r
253 }\r
254 \r
255 \r
256  \r