Differences From Artifact [97a142a9264ab72a]:
- File
src/util.d
- 2011-02-23 12:53:16 - part of checkin [c2b7a98c21] on branch trunk - Initial import (user: kinaba) [annotate]
To Artifact [9a6609551ad86e62]:
- File
src/util.d
- 2015-04-21 10:46:55 - part of checkin [4e2933c620] on branch trunk - Rebased to the latest verson dmd 2.067. Not yet verified the outcome. (user: kinaba) [annotate]
> 1 private import win32.windows;
1 private import std.string; | 2 private import std.string;
2 private import std.file; 3 private import std.file;
3 private import win32.ansi.windows; <
4 4
5 char lastChar( char[] s ) | 5 char lastChar( string s )
6 { return *CharPrev(s, cast(char*)s+s.length); } | 6 { return *CharPrevA(cast(char*)s.ptr, cast(char*)s.ptr+s.length); }
7 7
8 //---------------------------------------------------------------- 8 //----------------------------------------------------------------
9 // int do_opApply!(E, C)( collection, delegate ); 9 // int do_opApply!(E, C)( collection, delegate );
10 // int do_opApply!(E) ( array, delegate ); 10 // int do_opApply!(E) ( array, delegate );
11 // forwarding the opApply call to another collection 11 // forwarding the opApply call to another collection
12 //---------------------------------------------------------------- 12 //----------------------------------------------------------------
13 13
................................................................................................................................................................................
67 foreach( int t ; x ) assert( t==2 ); 67 foreach( int t ; x ) assert( t==2 );
68 } 68 }
69 69
70 //---------------------------------------------------------------- 70 //----------------------------------------------------------------
71 // コマンドライン解析 71 // コマンドライン解析
72 //---------------------------------------------------------------- 72 //----------------------------------------------------------------
73 73
74 char[][] cmd_parse( char[] str, bool in_resp=false ) | 74 string[] cmd_parse( string str, bool in_resp=false )
75 { 75 {
76 char[][] ans; | 76 string[] ans;
77 char resp_char = '@'; 77 char resp_char = '@';
78 78
79 for(int i=0; i!=str.length; ) 79 for(int i=0; i!=str.length; )
80 { 80 {
81 // 空白スキップ 81 // 空白スキップ
82 while( i!=str.length && 0<=str[i] && str[i]<=' ' ) 82 while( i!=str.length && 0<=str[i] && str[i]<=' ' )
83 ++i; 83 ++i;
84 if( i == str.length ) 84 if( i == str.length )
85 break; 85 break;
86 86
87 // ""を考慮して一個パラメタ切り出し 87 // ""を考慮して一個パラメタ切り出し
88 char[] param; | 88 string param;
89 if( str[i] == '"' ) 89 if( str[i] == '"' )
90 { 90 {
91 int j = ++i; 91 int j = ++i;
92 while( j!=str.length ) 92 while( j!=str.length )
93 { 93 {
94 if( str[j]=='"' && 94 if( str[j]=='"' &&
95 (j+1==str.length || 0<=str[j+1] && str[j+1] 95 (j+1==str.length || 0<=str[j+1] && str[j+1]
................................................................................................................................................................................
108 i = j; 108 i = j;
109 } 109 }
110 110
111 // レスポンスファイル関連の処理 111 // レスポンスファイル関連の処理
112 if( !in_resp && param[0]==resp_char ) 112 if( !in_resp && param[0]==resp_char )
113 { 113 {
114 try { 114 try {
115 char[] rsp = cast(char[]) std.file.read( param[1 | 115 string rsp = cast(string) std.file.read( param[1
116 ans ~= cmd_parse(rsp,true); 116 ans ~= cmd_parse(rsp,true);
117 } catch( FileException e ) {} 117 } catch( FileException e ) {}
118 } 118 }
119 else if( param.length>=2 && param[0..2]=="--" ) 119 else if( param.length>=2 && param[0..2]=="--" )
120 { 120 {
121 resp_char = (param.length==2 ? '\0' : param[2]); 121 resp_char = (param.length==2 ? '\0' : param[2]);
122 } 122 }
................................................................................................................................................................................
128 return ans; 128 return ans;
129 } 129 }
130 130
131 //---------------------------------------------------------------- 131 //----------------------------------------------------------------
132 // DOS形式でファイル音更新時刻を書き換え 132 // DOS形式でファイル音更新時刻を書き換え
133 //---------------------------------------------------------------- 133 //----------------------------------------------------------------
134 134
135 void dosSetFTime( char[] fname, ushort date, ushort time ) | 135 void dosSetFTime( string fname, ushort date, ushort time )
136 { 136 {
137 FILETIME ft,lc; 137 FILETIME ft,lc;
138 if( DosDateTimeToFileTime( date, time, &lc ) ) 138 if( DosDateTimeToFileTime( date, time, &lc ) )
139 if( LocalFileTimeToFileTime( &lc, &ft ) ) 139 if( LocalFileTimeToFileTime( &lc, &ft ) )
140 { 140 {
141 HANDLE han = CreateFile( toStringz(fname), | 141 HANDLE han = CreateFileA( toStringz(fname),
142 GENERIC | 142 GENERI
143 FILE_SH | 143 FILE_S
144 OPEN_EX | 144 OPEN_E
145 FILE_AT | 145 FILE_A
146 NULL ); | 146 null )
147 if( han==INVALID_HANDLE_VALUE ) 147 if( han==INVALID_HANDLE_VALUE )
148 return; 148 return;
149 149
150 SetFileTime( han,&ft,NULL,&ft ); | 150 SetFileTime( han,&ft,null,&ft );
151 CloseHandle( han ); 151 CloseHandle( han );
152 } 152 }
153 } 153 }
154 154
155 //---------------------------------------------------------------- 155 //----------------------------------------------------------------
156 // 指定時刻(DOS形式)より新しいファイルか? 156 // 指定時刻(DOS形式)より新しいファイルか?
157 //---------------------------------------------------------------- 157 //----------------------------------------------------------------
158 158
159 bool newer_than( ushort d1, ushort t1, char[] fname ) | 159 bool newer_than( ushort d1, ushort t1, string fname )
160 { 160 {
161 HANDLE han = CreateFile( toStringz(fname), | 161 HANDLE han = CreateFileA( toStringz(fname),
162 GENERIC_READ | GENERIC_ | 162 GENERIC_READ | GENERIC
163 FILE_SHARE_READ,NULL, | 163 FILE_SHARE_READ,null,
164 OPEN_EXISTING, | 164 OPEN_EXISTING,
165 FILE_ATTRIBUTE_NORMAL, | 165 FILE_ATTRIBUTE_NORMAL,
166 NULL ); | 166 null );
167 if( han==INVALID_HANDLE_VALUE ) 167 if( han==INVALID_HANDLE_VALUE )
168 return false; 168 return false;
169 FILETIME ft; 169 FILETIME ft;
170 GetFileTime( han, null, null, &ft ); 170 GetFileTime( han, null, null, &ft );
171 CloseHandle( han ); 171 CloseHandle( han );
172 172
173 FILETIME lc; 173 FILETIME lc;