00778 :
00779
00780 This routine compares a Dbcs name and an expression and tells
the caller
00781
if the name
is in
the language defined by
the expression. The input name
00782 cannot contain wildcards,
while the expression may contain wildcards.
00783
00784 Expression wild cards are evaluated as shown in
the nondeterministic
00785 finite automatons below. Note that ~* and ~? are DOS_STAR and DOS_QM.
00786
00787
00788 ~*
is DOS_STAR, ~?
is DOS_QM, and ~.
is DOS_DOT
00789
00790
00791 S
00792 <-----<
00793 X | | e Y
00794 X * Y == (0)----->-(1)->-----(2)-----(3)
00795
00796
00797 S-.
00798 <-----<
00799 X | | e Y
00800 X ~* Y == (0)----->-(1)->-----(2)-----(3)
00801
00802
00803
00804 X S S Y
00805 X ?? Y == (0)---(1)---(2)---(3)---(4)
00806
00807
00808
00809 X . . Y
00810 X ~.~. Y == (0)---(1)----(2)------(3)---(4)
00811 | |________|
00812 | ^ |
00813 |_______________|
00814 ^EOF or .^
00815
00816
00817 X S-. S-. Y
00818 X ~?~? Y == (0)---(1)-----(2)-----(3)---(4)
00819 | |________|
00820 | ^ |
00821 |_______________|
00822 ^EOF or .^
00823
00824
00825
00826 where S
is any single character
00827
00828 S-.
is any single character except
the final .
00829
00830 e
is a null character transition
00831
00832 EOF
is the end of
the name string
00833
00834 In words:
00835
00836 * matches 0 or more characters.
00837
00838 ? matches exactly 1 character.
00839
00840 DOS_STAR matches 0 or more characters until encountering and
matching
00841
the final . in
the name.
00842
00843 DOS_QM matches any single character, or upon encountering a period or
00844 end of name string, advances
the expression to
the end of
the
00845 set of contiguous DOS_QMs.
00846
00847 DOS_DOT matches either a . or zero characters beyond name string.
00848
00849 Arguments:
00850
00851 Expression - Supplies
the input expression to check against
00852
00853
Name - Supplies
the input name to check
for.
00854
00855 Return Value:
00856
00857 BOOLEAN -
TRUE if Name is an element in
the set of strings denoted
00858 by
the input Expression and
FALSE otherwise.
00859
00860 --*/
00861
00862 {
00863
USHORT NameOffset;
00864
USHORT ExprOffset;
00865
USHORT Length;
00866
00867 ULONG SrcCount;
00868 ULONG DestCount;
00869 ULONG PreviousDestCount;
00870 ULONG MatchesCount;
00871
00872 WCHAR NameChar, ExprChar;
00873
00874
USHORT LocalBuffer[
MATCHES_ARRAY_SIZE * 2];
00875
00876
USHORT *AuxBuffer =
NULL;
00877
USHORT *PreviousMatches;
00878
USHORT *CurrentMatches;
00879
00880
USHORT MaxState;
00881
USHORT CurrentState;
00882
00883 BOOLEAN NameFinished =
FALSE;
00884
00885
00886
00887
00888
00889
00890
00891
00892
00893
PAGED_CODE();
00894
00895
DebugTrace(+1, Dbg,
"FsRtlIsDbcsInExpression\n", 0);
00896
DebugTrace( 0, Dbg,
" Expression = %Z\n", Expression );
00897
DebugTrace( 0, Dbg,
" Name = %Z\n", Name );
00898
00899
ASSERT(
Name->Length != 0 );
00900
ASSERT( Expression->Length != 0 );
00901
00902
00903
00904
00905
00906
if ( (
Name->Length == 0) || (Expression->Length == 0) ) {
00907
00908
return (BOOLEAN)(!(
Name->Length + Expression->Length));
00909 }
00910
00911
00912
00913
00914
00915
if ((Expression->Length == 1) && (Expression->Buffer[0] ==
'*')) {
00916
00917
return TRUE;
00918 }
00919
00920
ASSERT(
FsRtlDoesDbcsContainWildCards( Expression ) );
00921
00922
00923
00924
00925
00926
00927
if (Expression->Buffer[0] ==
'*') {
00928
00929 ANSI_STRING LocalExpression;
00930
00931 LocalExpression = *Expression;
00932
00933 LocalExpression.Buffer += 1;
00934 LocalExpression.Length -= 1;
00935
00936
00937
00938
00939
00940
if ( !
FsRtlDoesDbcsContainWildCards( &LocalExpression ) ) {
00941
00942 ULONG StartingNameOffset;
00943
00944
if (
Name->Length < (
USHORT)(Expression->Length - 1)) {
00945
00946
return FALSE;
00947 }
00948
00949 StartingNameOffset =
Name->Length - LocalExpression.Length;
00950
00951
00952
00953
00954
00955
00956
00957
if (
NlsMbOemCodePageTag) {
00958
00959 ULONG i = 0;
00960
00961
while ( i < StartingNameOffset ) {
00962
00963 i +=
FsRtlIsLeadDbcsCharacter(
Name->Buffer[i] ) ? 2 : 1;
00964 }
00965
00966
if ( i > StartingNameOffset ) {
00967
00968
return FALSE;
00969 }
00970 }
00971
00972
00973
00974
00975
00976
00977
return (BOOLEAN) RtlEqualMemory( LocalExpression.Buffer,
00978
Name->Buffer + StartingNameOffset,
00979 LocalExpression.Length );
00980 }
00981 }
00982
00983
00984
00985
00986
00987
00988
00989
00990
00991
00992
00993
00994
00995
00996
00997
00998
00999
01000
01001
01002
01003
01004
01005
01006
01007
01008
01009
01010
01011
01012
01013
01014
01015
01016
01017
01018
01019
01020
01021
01022
01023
01024
01025
01026
01027
01028
01029
01030
01031
01032 PreviousMatches = &LocalBuffer[0];
01033 CurrentMatches = &LocalBuffer[
MATCHES_ARRAY_SIZE];
01034
01035 PreviousMatches[0] = 0;
01036 MatchesCount = 1;
01037
01038 NameOffset = 0;
01039
01040 MaxState = (
USHORT)(Expression->Length * 2);
01041
01042
while ( !NameFinished ) {
01043
01044
if ( NameOffset <
Name->Length ) {
01045
01046
GetDbcs(
Name->Buffer, NameOffset, &NameChar, &Length );
01047 NameOffset += Length;
01048
01049 }
else {
01050
01051 NameFinished =
TRUE;
01052
01053
01054
01055
01056
01057
01058
if ( PreviousMatches[MatchesCount-1] == MaxState ) {
01059
01060
break;
01061 }
01062 }
01063
01064
01065
01066
01067
01068
01069
01070 SrcCount = 0;
01071 DestCount = 0;
01072 PreviousDestCount = 0;
01073
01074
while ( SrcCount < MatchesCount ) {
01075
01076
01077
01078
01079
01080
01081
01082
01083
01084
01085 ExprOffset = (
USHORT)((PreviousMatches[SrcCount++] + 1) / 2);
01086
01087 Length = 0;
01088
01089
01090
while (
TRUE ) {
01091
01092
if ( ExprOffset == Expression->Length ) {
01093
01094
break;
01095 }
01096
01097
01098
01099
01100
01101
01102 ExprOffset += Length;
01103
01104 CurrentState = (
USHORT)(ExprOffset * 2);
01105
01106
if ( ExprOffset == Expression->Length ) {
01107
01108 CurrentMatches[DestCount++] = MaxState;
01109
break;
01110 }
01111
01112
GetDbcs(Expression->Buffer, ExprOffset, &ExprChar, &Length);
01113
01114
ASSERT( !((ExprChar >=
'a') && (ExprChar <=
'z')) );
01115
01116
01117
01118
01119
01120
01121
01122
01123
if ( (DestCount >=
MATCHES_ARRAY_SIZE - 2) &&
01124 (AuxBuffer ==
NULL) ) {
01125
01126 AuxBuffer =
FsRtlpAllocatePool( PagedPool,
01127 (Expression->Length+1) *
01128
sizeof(USHORT)*2*2 );
01129
01130 RtlCopyMemory( AuxBuffer,
01131 CurrentMatches,
01132 MATCHES_ARRAY_SIZE *
sizeof(USHORT) );
01133
01134 CurrentMatches = AuxBuffer;
01135
01136 RtlCopyMemory( AuxBuffer + (Expression->Length+1)*2,
01137 PreviousMatches,
01138 MATCHES_ARRAY_SIZE *
sizeof(USHORT) );
01139
01140 PreviousMatches = AuxBuffer + (Expression->Length+1)*2;
01141
01142 }
01143
01144
01145
01146
01147
01148
if (ExprChar ==
'*') {
01149
01150 CurrentMatches[DestCount++] = CurrentState;
01151 CurrentMatches[DestCount++] = CurrentState + 1;
01152
continue;
01153 }
01154
01155
01156
01157
01158
01159
if (ExprChar == ANSI_DOS_STAR) {
01160
01161 BOOLEAN ICanEatADot =
FALSE;
01162
01163
01164
01165
01166
01167
01168
if ( !NameFinished && (NameChar ==
'.') ) {
01169
01170 WCHAR NameChar;
01171
USHORT Offset;
01172
USHORT Length;
01173
01174
for (
Offset = NameOffset;
01175
Offset <
Name->Length;
01176
Offset += Length ) {
01177
01178
GetDbcs(
Name->Buffer, Offset, &NameChar, &Length );
01179
01180
if (NameChar ==
'.') {
01181
01182 ICanEatADot =
TRUE;
01183
break;
01184 }
01185 }
01186 }
01187
01188
if (NameFinished || (NameChar !=
'.') || ICanEatADot) {
01189
01190 CurrentMatches[DestCount++] = CurrentState;
01191 CurrentMatches[DestCount++] = CurrentState + 1;
01192
continue;
01193
01194 }
else {
01195
01196
01197
01198
01199
01200
01201 CurrentMatches[DestCount++] = CurrentState + 1;
01202
continue;
01203 }
01204 }
01205
01206
01207
01208
01209
01210
01211
01212 CurrentState += (
USHORT)(Length * 2);
01213
01214
01215
01216
01217
01218
01219
01220
01221
if ( ExprChar == ANSI_DOS_QM ) {
01222
01223
if ( NameFinished || (NameChar ==
'.') ) {
01224
01225
continue;
01226 }
01227
01228 CurrentMatches[DestCount++] = CurrentState;
01229
break;
01230 }
01231
01232
01233
01234
01235
01236
01237
if (ExprChar == DOS_DOT) {
01238
01239
if ( NameFinished ) {
01240
01241
continue;
01242 }
01243
01244
if (NameChar ==
'.') {
01245
01246 CurrentMatches[DestCount++] = CurrentState;
01247
break;
01248 }
01249 }
01250
01251
01252
01253
01254
01255
01256
if ( NameFinished ) {
01257
01258
break;
01259 }
01260
01261
01262
01263
01264
01265
if (ExprChar ==
'?') {
01266
01267 CurrentMatches[DestCount++] = CurrentState;
01268
break;
01269 }
01270
01271
01272
01273
01274
01275
if (ExprChar == NameChar) {
01276
01277 CurrentMatches[DestCount++] = CurrentState;
01278
break;
01279 }
01280
01281
01282
01283
01284
01285
01286
break;
01287 }
01288
01289
01290
01291
01292
01293
01294
01295
01296
01297
01298
01299
if ((SrcCount < MatchesCount) &&
01300 (PreviousDestCount < DestCount) ) {
01301
01302
while (PreviousDestCount < DestCount) {
01303
01304
while ( PreviousMatches[SrcCount] <
01305 CurrentMatches[PreviousDestCount] ) {
01306
01307
01308 SrcCount += 1;
01309 }
01310
01311 PreviousDestCount += 1;
01312 }
01313 }
01314 }
01315
01316
01317
01318
01319
01320
01321
if ( DestCount == 0 ) {
01322
01323
01324
if (AuxBuffer !=
NULL) {
ExFreePool( AuxBuffer ); }
01325
01326
return FALSE;
01327 }
01328
01329
01330
01331
01332
01333 {
01334
USHORT *Tmp;
01335
01336 Tmp = PreviousMatches;
01337
01338 PreviousMatches = CurrentMatches;
01339
01340 CurrentMatches = Tmp;
01341 }
01342
01343 MatchesCount = DestCount;
01344 }
01345
01346
01347 CurrentState = PreviousMatches[MatchesCount-1];
01348
01349
if (AuxBuffer !=
NULL) {
ExFreePool( AuxBuffer ); }
01350
01351
01352
return (BOOLEAN)(CurrentState == MaxState);
01353 }
}