windows-pr 1.0.8 → 1.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGES +9 -0
- data/README +114 -118
- data/Rakefile +65 -50
- data/lib/windows/com/accessibility.rb +13 -13
- data/lib/windows/limits.rb +26 -18
- data/lib/windows/msvcrt/string.rb +159 -159
- data/lib/windows/service.rb +1 -0
- data/lib/windows/unicode.rb +153 -142
- data/test/tc_handle.rb +1 -1
- data/test/tc_mailslot.rb +2 -2
- data/test/tc_msvcrt_string.rb +69 -68
- data/test/tc_network_management.rb +1 -1
- data/test/tc_unicode.rb +83 -82
- data/windows-pr.gemspec +27 -29
- metadata +3 -3
@@ -1,159 +1,159 @@
|
|
1
|
-
require 'windows/api'
|
2
|
-
|
3
|
-
module Windows
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
end
|
1
|
+
require 'windows/api'
|
2
|
+
|
3
|
+
module Windows
|
4
|
+
module MSVCRT
|
5
|
+
module String
|
6
|
+
API.auto_constant = false # We want multiple versions
|
7
|
+
API.auto_method = false # We need to handle 0 & nil explicitly
|
8
|
+
API.auto_unicode = false
|
9
|
+
|
10
|
+
Strchr = API.new('strchr', 'PI', 'P', MSVCRT_DLL)
|
11
|
+
Strcmp = API.new('strcmp', 'PP', 'I', MSVCRT_DLL)
|
12
|
+
Strcpy = API.new('strcpy', 'PL', 'L', MSVCRT_DLL)
|
13
|
+
Strcspn = API.new('strcspn', 'PP', 'L', MSVCRT_DLL)
|
14
|
+
Strlen = API.new('strlen', 'P', 'L', MSVCRT_DLL)
|
15
|
+
Strncpy = API.new('strncpy', 'PPL', 'P', MSVCRT_DLL)
|
16
|
+
Strpbrk = API.new('strpbrk', 'PP', 'P', MSVCRT_DLL)
|
17
|
+
Strrchr = API.new('strrchr', 'PI', 'P', MSVCRT_DLL)
|
18
|
+
Strrev = API.new('_strrev', 'P', 'P', MSVCRT_DLL)
|
19
|
+
Strspn = API.new('strspn', 'PP', 'L', MSVCRT_DLL)
|
20
|
+
Strstr = API.new('strstr', 'PP', 'P', MSVCRT_DLL)
|
21
|
+
Strtok = API.new('strtok', 'PP', 'P', MSVCRT_DLL)
|
22
|
+
|
23
|
+
Mbscmp = API.new('_mbscmp', 'PP', 'I', 'msvcrt')
|
24
|
+
Mbscpy = API.new('_mbscpy', 'PL', 'L', 'msvcrt')
|
25
|
+
Mbslen = API.new('_mbslen', 'P', 'L', 'msvcrt')
|
26
|
+
Mbsrev = API.new('_mbsrev', 'P', 'P', 'msvcrt')
|
27
|
+
|
28
|
+
Wcscmp = API.new('wcscmp', 'PP', 'I', MSVCRT_DLL)
|
29
|
+
Wcscpy = API.new('wcscpy', 'PL', 'L', MSVCRT_DLL)
|
30
|
+
Wcslen = API.new('wcslen', 'P', 'L', MSVCRT_DLL)
|
31
|
+
Wcsncpy = API.new('wcsncpy', 'PPL', 'P', MSVCRT_DLL)
|
32
|
+
Wcsrev = API.new('_wcsrev', 'P', 'P', MSVCRT_DLL)
|
33
|
+
|
34
|
+
begin
|
35
|
+
Strtok_s = API.new('strtok_s', 'PPI', 'P', MSVCRT_DLL)
|
36
|
+
rescue Win32::API::LoadLibraryError
|
37
|
+
# Do nothing. Not supported on your system.
|
38
|
+
end
|
39
|
+
|
40
|
+
def strchr(string, char)
|
41
|
+
return nil if string == 0 || char == 0
|
42
|
+
Strchr.call(string, char)
|
43
|
+
end
|
44
|
+
|
45
|
+
def strcmp(str1, str2)
|
46
|
+
if str1 == 0 || str2 == 0
|
47
|
+
return nil
|
48
|
+
end
|
49
|
+
Strcmp.call(str1, str2)
|
50
|
+
end
|
51
|
+
|
52
|
+
def strcpy(dest, src)
|
53
|
+
return nil if src == 0
|
54
|
+
Strcpy.call(dest, src)
|
55
|
+
end
|
56
|
+
|
57
|
+
def strlen(string)
|
58
|
+
return nil if string == 0
|
59
|
+
Strlen.call(string)
|
60
|
+
end
|
61
|
+
|
62
|
+
def strcspn(string, charset)
|
63
|
+
return nil if string == 0
|
64
|
+
Strcspn.call(string, charset)
|
65
|
+
end
|
66
|
+
|
67
|
+
def strncpy(dest, source, count)
|
68
|
+
return nil if source == 0
|
69
|
+
Strncpy.call(dest, source, count)
|
70
|
+
end
|
71
|
+
|
72
|
+
def strpbrk(string, charset)
|
73
|
+
return nil if string == 0 || charset == 0
|
74
|
+
Strpbrk.call(string, charset)
|
75
|
+
end
|
76
|
+
|
77
|
+
def strrchr(string, int)
|
78
|
+
return nil if string == 0
|
79
|
+
Strrchr.call(string, int)
|
80
|
+
end
|
81
|
+
|
82
|
+
def strrev(str)
|
83
|
+
return nil if str == 0
|
84
|
+
Strrev.call(str)
|
85
|
+
end
|
86
|
+
|
87
|
+
def strspn(string, charset)
|
88
|
+
return nil if string == 0 || charset == 0
|
89
|
+
Strspn.call(string, charset)
|
90
|
+
end
|
91
|
+
|
92
|
+
def strstr(string, search)
|
93
|
+
return nil if string == 0 || search == 0
|
94
|
+
Strstr.call(string, search)
|
95
|
+
end
|
96
|
+
|
97
|
+
def strtok(token, delimeter)
|
98
|
+
return nil if token == 0 || delimeter == 0
|
99
|
+
Strtok.call(token, delimeter)
|
100
|
+
end
|
101
|
+
|
102
|
+
if defined? Strtok_s
|
103
|
+
def strtok_s(token, delimeter, context)
|
104
|
+
return nil if [token, delimter, context].include?(0)
|
105
|
+
Strtok_s.call(token, delimeter, context)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
def mbscmp(str1, str2)
|
110
|
+
if str1 == 0 || str2 == 0
|
111
|
+
return nil
|
112
|
+
end
|
113
|
+
Mbscmp.call(str1, str2)
|
114
|
+
end
|
115
|
+
|
116
|
+
def mbscpy(dest, src)
|
117
|
+
return nil if src == 0
|
118
|
+
Mbscpy.call(dest, src)
|
119
|
+
end
|
120
|
+
|
121
|
+
def mbslen(string)
|
122
|
+
return nil if string == 0
|
123
|
+
Mbslen.call(string)
|
124
|
+
end
|
125
|
+
|
126
|
+
def mbsrev(str)
|
127
|
+
return nil if str == 0
|
128
|
+
Mbsrev.call(str)
|
129
|
+
end
|
130
|
+
|
131
|
+
def wcscmp(str1, str2)
|
132
|
+
if str1 == 0 || str2 == 0
|
133
|
+
return nil
|
134
|
+
end
|
135
|
+
Wcscmp.call(str1, str2)
|
136
|
+
end
|
137
|
+
|
138
|
+
def wcscpy(dest, src)
|
139
|
+
return nil if src == 0
|
140
|
+
Wcscpy.call(dest, src)
|
141
|
+
end
|
142
|
+
|
143
|
+
def wcslen(string)
|
144
|
+
return nil if string == 0
|
145
|
+
Wcslen.call(string)
|
146
|
+
end
|
147
|
+
|
148
|
+
def wcsncpy(dest, source, count)
|
149
|
+
return nil if source == 0
|
150
|
+
Wcsncpy.call(dest, source, count)
|
151
|
+
end
|
152
|
+
|
153
|
+
def wcsrev(str)
|
154
|
+
return nil if str == 0
|
155
|
+
Wcsrev.call(str)
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
data/lib/windows/service.rb
CHANGED
data/lib/windows/unicode.rb
CHANGED
@@ -1,142 +1,153 @@
|
|
1
|
-
|
2
|
-
require 'windows/
|
3
|
-
require 'windows/
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
1
|
+
# encoding: ascii-8bit
|
2
|
+
require 'windows/api'
|
3
|
+
require 'windows/msvcrt/string'
|
4
|
+
require 'windows/error'
|
5
|
+
|
6
|
+
module Windows
|
7
|
+
module Unicode
|
8
|
+
include Windows::MSVCRT::String
|
9
|
+
include Windows::Error
|
10
|
+
|
11
|
+
API.auto_namespace = 'Windows::Unicode'
|
12
|
+
API.auto_constant = true
|
13
|
+
API.auto_method = true
|
14
|
+
API.auto_unicode = false
|
15
|
+
|
16
|
+
CP_ACP = 0
|
17
|
+
CP_OEMCP = 1
|
18
|
+
CP_MACCP = 2
|
19
|
+
CP_THREAD_ACP = 3
|
20
|
+
CP_SYMBOL = 42
|
21
|
+
CP_UTF7 = 65000
|
22
|
+
CP_UTF8 = 65001
|
23
|
+
|
24
|
+
MB_PRECOMPOSED = 0x00000001
|
25
|
+
MB_COMPOSITE = 0x00000002
|
26
|
+
MB_USEGLYPHCHARS = 0x00000004
|
27
|
+
MB_ERR_INVALID_CHARS = 0x00000008
|
28
|
+
|
29
|
+
WC_COMPOSITECHECK = 0x00000200
|
30
|
+
WC_DISCARDNS = 0x00000010
|
31
|
+
WC_SEPCHARS = 0x00000020
|
32
|
+
WC_DEFAULTCHAR = 0x00000040
|
33
|
+
WC_NO_BEST_FIT_CHARS = 0x00000400
|
34
|
+
|
35
|
+
ANSI_CHARSET = 0
|
36
|
+
DEFAULT_CHARSET = 1
|
37
|
+
SYMBOL_CHARSET = 2
|
38
|
+
SHIFTJIS_CHARSET = 128
|
39
|
+
HANGEUL_CHARSET = 129
|
40
|
+
HANGUL_CHARSET = 129
|
41
|
+
GB2312_CHARSET = 134
|
42
|
+
CHINESEBIG5_CHARSET = 136
|
43
|
+
OEM_CHARSET = 255
|
44
|
+
JOHAB_CHARSET = 130
|
45
|
+
HEBREW_CHARSET = 177
|
46
|
+
ARABIC_CHARSET = 178
|
47
|
+
GREEK_CHARSET = 161
|
48
|
+
TURKISH_CHARSET = 162
|
49
|
+
VIETNAMESE_CHARSET = 163
|
50
|
+
THAI_CHARSET = 222
|
51
|
+
EASTEUROPE_CHARSET = 238
|
52
|
+
RUSSIAN_CHARSET = 204
|
53
|
+
|
54
|
+
IS_TEXT_UNICODE_ASCII16 = 0x0001
|
55
|
+
IS_TEXT_UNICODE_REVERSE_ASCII16 = 0x0010
|
56
|
+
IS_TEXT_UNICODE_STATISTICS = 0x0002
|
57
|
+
IS_TEXT_UNICODE_REVERSE_STATISTICS = 0x0020
|
58
|
+
IS_TEXT_UNICODE_CONTROLS = 0x0004
|
59
|
+
IS_TEXT_UNICODE_REVERSE_CONTROLS = 0x0040
|
60
|
+
IS_TEXT_UNICODE_SIGNATURE = 0x0008
|
61
|
+
IS_TEXT_UNICODE_REVERSE_SIGNATURE = 0x0080
|
62
|
+
IS_TEXT_UNICODE_ILLEGAL_CHARS = 0x0100
|
63
|
+
IS_TEXT_UNICODE_ODD_LENGTH = 0x0200
|
64
|
+
IS_TEXT_UNICODE_DBCS_LEADBYTE = 0x0400
|
65
|
+
IS_TEXT_UNICODE_NULL_BYTES = 0x1000
|
66
|
+
IS_TEXT_UNICODE_UNICODE_MASK = 0x000F
|
67
|
+
IS_TEXT_UNICODE_REVERSE_MASK = 0x00F0
|
68
|
+
IS_TEXT_UNICODE_NOT_UNICODE_MASK = 0x0F00
|
69
|
+
IS_TEXT_UNICODE_NOT_ASCII_MASK = 0xF000
|
70
|
+
|
71
|
+
TCI_SRCCHARSET = 1
|
72
|
+
TCI_SRCCODEPAGE = 2
|
73
|
+
TCI_SRCFONTSIG = 3
|
74
|
+
TCI_SRCLOCALE = 0x100
|
75
|
+
|
76
|
+
API.new('GetTextCharset', 'L', 'I', 'gdi32')
|
77
|
+
API.new('GetTextCharsetInfo', 'LPL', 'I', 'gdi32')
|
78
|
+
API.new('IsDBCSLeadByte', 'P', 'B')
|
79
|
+
API.new('IsDBCSLeadByteEx', 'IP', 'B')
|
80
|
+
API.new('IsTextUnicode', 'SIP', 'B', 'advapi32')
|
81
|
+
API.new('MultiByteToWideChar', 'ILSIPI', 'I')
|
82
|
+
API.new('TranslateCharsetInfo', 'PPL', 'B', 'gdi32')
|
83
|
+
API.new('WideCharToMultiByte', 'ILSIPIPP', 'I')
|
84
|
+
|
85
|
+
# Convenient wrapper methods
|
86
|
+
|
87
|
+
# Maps a wide character string to a new character string using the
|
88
|
+
# specified +encoding+. If no encoding is specified, then CP_UTF8
|
89
|
+
# is used if $KCODE (or the encoding name in Ruby 1.9.x) is set to UTF8.
|
90
|
+
# Otherwise, CP_ACP is used.
|
91
|
+
#
|
92
|
+
# If the function fails it simply returns the string as-is.
|
93
|
+
#
|
94
|
+
def multi_to_wide(string, encoding=nil)
|
95
|
+
return nil unless string
|
96
|
+
raise TypeError unless string.is_a?(String)
|
97
|
+
return string if IsTextUnicode(string, string.size, nil)
|
98
|
+
|
99
|
+
unless encoding
|
100
|
+
if RUBY_VERSION.to_f >= 1.9
|
101
|
+
encoding = (string.encoding.name == 'UTF-8') ? CP_UTF8 : CP_ACP
|
102
|
+
else
|
103
|
+
encoding = ($KCODE == 'UTF8') ? CP_UTF8 : CP_ACP
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
int = MultiByteToWideChar(encoding, 0, string, -1, nil, 0)
|
108
|
+
|
109
|
+
# Trailing nulls are retained
|
110
|
+
if int > 0
|
111
|
+
buf = ' ' * int * 2
|
112
|
+
MultiByteToWideChar(encoding, 0, string, -1, buf, int)
|
113
|
+
buf
|
114
|
+
else
|
115
|
+
raise ArgumentError, get_last_error
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
# Maps a wide character string to a new character string using the
|
120
|
+
# specified +encoding+. If no encoding is specified, then CP_UTF8
|
121
|
+
# is used if $KCODE (or the encoding name in Ruby 1.9.x) is set to UTF8.
|
122
|
+
# Otherwise, CP_ACP is used.
|
123
|
+
#
|
124
|
+
# If the function fails it simply returns the string as-is.
|
125
|
+
#
|
126
|
+
def wide_to_multi(wstring, encoding=nil)
|
127
|
+
return nil unless wstring
|
128
|
+
raise TypeError unless wstring.is_a?(String)
|
129
|
+
|
130
|
+
unless encoding
|
131
|
+
if RUBY_VERSION.to_f >= 1.9
|
132
|
+
encoding = (wstring.encoding.name == 'UTF-8') ? CP_UTF8 : CP_ACP
|
133
|
+
else
|
134
|
+
encoding = ($KCODE == 'UTF8') ? CP_UTF8 : CP_ACP
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
# Add a trailing double null if necessary
|
139
|
+
wstring << "\000\000" if wstring[-1].chr != "\000"
|
140
|
+
|
141
|
+
int = WideCharToMultiByte(encoding, 0, wstring, -1, 0, 0, nil, nil)
|
142
|
+
|
143
|
+
# Trailing nulls are stripped
|
144
|
+
if int > 0
|
145
|
+
buf = ' ' * int
|
146
|
+
WideCharToMultiByte(encoding, 0, wstring, -1, buf, strlen(buf), nil, nil)
|
147
|
+
buf[ /^[^\0]*/ ]
|
148
|
+
else
|
149
|
+
raise ArgumentError, get_last_error
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|