4 * Implementation of the Microsoft Installer (msi.dll)
6 * Copyright 2003 Mike McCormack for CodeWeavers
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31 #include "wine/debug.h"
32 #include "wine/unicode.h"
37 #define YYLEX_PARAM info
38 #define YYPARSE_PARAM info
40 static int COND_error
(char *str
);
42 WINE_DEFAULT_DEBUG_CHANNEL
(msi
);
44 typedef
struct tag_yyinput
57 static LPWSTR COND_GetString
( struct cond_str
*str
);
58 static int COND_lex
( void *COND_lval
, COND_input
*info
);
59 UINT get_property
(MSIHANDLE hPackage
, const WCHAR
* prop
, WCHAR
* value
,
62 typedef INT
(*comp_int
)(INT a
, INT b
);
63 typedef INT
(*comp_str
)(LPWSTR a
, LPWSTR b
, BOOL caseless
);
64 typedef INT
(*comp_m1
)(LPWSTR a
,int b
);
65 typedef INT
(*comp_m2
)(int a
,LPWSTR b
);
67 static INT comp_lt_i
(INT a
, INT b
);
68 static INT comp_gt_i
(INT a
, INT b
);
69 static INT comp_le_i
(INT a
, INT b
);
70 static INT comp_ge_i
(INT a
, INT b
);
71 static INT comp_eq_i
(INT a
, INT b
);
72 static INT comp_ne_i
(INT a
, INT b
);
73 static INT comp_bitand
(INT a
, INT b
);
74 static INT comp_highcomp
(INT a
, INT b
);
75 static INT comp_lowcomp
(INT a
, INT b
);
77 static INT comp_eq_s
(LPWSTR a
, LPWSTR b
, BOOL casless
);
78 static INT comp_ne_s
(LPWSTR a
, LPWSTR b
, BOOL casless
);
79 static INT comp_lt_s
(LPWSTR a
, LPWSTR b
, BOOL casless
);
80 static INT comp_gt_s
(LPWSTR a
, LPWSTR b
, BOOL casless
);
81 static INT comp_le_s
(LPWSTR a
, LPWSTR b
, BOOL casless
);
82 static INT comp_ge_s
(LPWSTR a
, LPWSTR b
, BOOL casless
);
83 static INT comp_substring
(LPWSTR a
, LPWSTR b
, BOOL casless
);
84 static INT comp_start
(LPWSTR a
, LPWSTR b
, BOOL casless
);
85 static INT comp_end
(LPWSTR a
, LPWSTR b
, BOOL casless
);
87 static INT comp_eq_m1
(LPWSTR a
, INT b
);
88 static INT comp_ne_m1
(LPWSTR a
, INT b
);
89 static INT comp_lt_m1
(LPWSTR a
, INT b
);
90 static INT comp_gt_m1
(LPWSTR a
, INT b
);
91 static INT comp_le_m1
(LPWSTR a
, INT b
);
92 static INT comp_ge_m1
(LPWSTR a
, INT b
);
94 static INT comp_eq_m2
(INT a
, LPWSTR b
);
95 static INT comp_ne_m2
(INT a
, LPWSTR b
);
96 static INT comp_lt_m2
(INT a
, LPWSTR b
);
97 static INT comp_gt_m2
(INT a
, LPWSTR b
);
98 static INT comp_le_m2
(INT a
, LPWSTR b
);
99 static INT comp_ge_m2
(INT a
, LPWSTR b
);
110 comp_int fn_comp_int
;
111 comp_str fn_comp_str
;
116 %token COND_SPACE COND_EOF COND_SPACE
117 %token COND_OR COND_AND COND_NOT
118 %token COND_LT COND_GT COND_EQ
119 %token COND_LPAR COND_RPAR COND_DBLQ COND_TILDA
120 %token COND_PERCENT COND_DOLLARS COND_QUESTION COND_AMPER COND_EXCLAM
121 %token
<str
> COND_IDENT
<str
> COND_NUMBER
123 %nonassoc COND_EOF COND_ERROR
125 %type
<value
> expression boolean_term boolean_factor
126 %type
<value
> term value_i symbol_i integer
127 %type
<string> identifier value_s symbol_s literal
128 %type
<fn_comp_int
> comp_op_i
129 %type
<fn_comp_str
> comp_op_s
130 %type
<fn_comp_m1
> comp_op_m1
131 %type
<fn_comp_m2
> comp_op_m2
138 COND_input
* cond
= (COND_input
*) info
;
148 | boolean_term COND_OR expression
159 | boolean_term COND_AND boolean_factor
186 | value_i comp_op_i value_i
190 | value_s comp_op_s value_s
192 $$
= $2( $1, $3, FALSE
);
194 | value_s COND_TILDA comp_op_s value_s
196 $$
= $3( $1, $4, TRUE
);
198 | value_s comp_op_m1 value_i
202 | value_i comp_op_m2 value_s
206 | COND_LPAR expression COND_RPAR
213 /* common functions */
254 /* common functions */
295 /* common functions */
320 /*Not valid for mixed compares*/
336 /* common functions */
361 /*Not valid for mixed compares*/
399 COND_DBLQ identifier COND_DBLQ
406 COND_DOLLARS identifier
408 COND_input
* cond
= (COND_input
*) info
;
409 INSTALLSTATE install
= INSTALLSTATE_UNKNOWN
, action
= INSTALLSTATE_UNKNOWN
;
411 MsiGetComponentStateW
(cond
->hInstall
, $2, &install
, &action
);
413 HeapFree
( GetProcessHeap
(), 0, $2 );
415 | COND_QUESTION identifier
417 COND_input
* cond
= (COND_input
*) info
;
418 INSTALLSTATE install
= INSTALLSTATE_UNKNOWN
, action
= INSTALLSTATE_UNKNOWN
;
420 MsiGetComponentStateW
(cond
->hInstall
, $2, &install
, &action
);
422 HeapFree
( GetProcessHeap
(), 0, $2 );
424 | COND_AMPER identifier
426 COND_input
* cond
= (COND_input
*) info
;
427 INSTALLSTATE install
= INSTALLSTATE_UNKNOWN
, action
= INSTALLSTATE_UNKNOWN
;
429 MsiGetFeatureStateW
(cond
->hInstall
, $2, &install
, &action
);
431 HeapFree
( GetProcessHeap
(), 0, $2 );
433 | COND_EXCLAM identifier
435 COND_input
* cond
= (COND_input
*) info
;
436 INSTALLSTATE install
= INSTALLSTATE_UNKNOWN
, action
= INSTALLSTATE_UNKNOWN
;
438 MsiGetFeatureStateW
(cond
->hInstall
, $2, &install
, &action
);
440 HeapFree
( GetProcessHeap
(), 0, $2 );
448 COND_input
* cond
= (COND_input
*) info
;
449 $$
= HeapAlloc
( GetProcessHeap
(), 0, 0x100*sizeof
(WCHAR
) );
451 /* Lookup the identifier */
454 if
(MsiGetPropertyW
(cond
->hInstall
,$1,$$
,&sz
) != ERROR_SUCCESS
)
458 HeapFree
( GetProcessHeap
(), 0, $1 );
460 | COND_PERCENT identifier
462 UINT len
= GetEnvironmentVariableW
( $2, NULL
, 0 );
465 $$
= HeapAlloc
( GetProcessHeap
(), 0, len
*sizeof
(WCHAR
) );
467 GetEnvironmentVariableW
( $2, $$
, len
);
469 HeapFree
( GetProcessHeap
(), 0, $2 );
476 $$
= COND_GetString
(&$1);
485 LPWSTR szNum
= COND_GetString
(&$1);
489 HeapFree
( GetProcessHeap
(), 0, szNum
);
496 static int COND_IsAlpha
( WCHAR x
)
498 return
( ( ( x
>= 'A' ) && ( x
<= 'Z' ) ) ||
499 ( ( x
>= 'a' ) && ( x
<= 'z' ) ) ||
503 static int COND_IsNumber
( WCHAR x
)
505 return
( ( x
>= '0' ) && ( x
<= '9' ) );
509 /* the mess of comparison functions */
511 static INT comp_lt_i
(INT a
, INT b
)
513 static INT comp_gt_i
(INT a
, INT b
)
515 static INT comp_le_i
(INT a
, INT b
)
517 static INT comp_ge_i
(INT a
, INT b
)
519 static INT comp_eq_i
(INT a
, INT b
)
521 static INT comp_ne_i
(INT a
, INT b
)
523 static INT comp_bitand
(INT a
, INT b
)
525 static INT comp_highcomp
(INT a
, INT b
)
526 { return HIWORD
(a
)==b
; }
527 static INT comp_lowcomp
(INT a
, INT b
)
528 { return LOWORD
(a
)==b
; }
530 static INT comp_eq_s
(LPWSTR a
, LPWSTR b
, BOOL casless
)
531 { if
(casless
) return
!strcmpiW
(a
,b
); else return
!strcmpW
(a
,b
);}
532 static INT comp_ne_s
(LPWSTR a
, LPWSTR b
, BOOL casless
)
533 { if
(casless
) return strcmpiW
(a
,b
); else return strcmpW
(a
,b
);}
534 static INT comp_lt_s
(LPWSTR a
, LPWSTR b
, BOOL casless
)
535 { if
(casless
) return strcmpiW
(a
,b
)<0; else return strcmpW
(a
,b
)<0;}
536 static INT comp_gt_s
(LPWSTR a
, LPWSTR b
, BOOL casless
)
537 { if
(casless
) return strcmpiW
(a
,b
)>0; else return strcmpW
(a
,b
)>0;}
538 static INT comp_le_s
(LPWSTR a
, LPWSTR b
, BOOL casless
)
539 { if
(casless
) return strcmpiW
(a
,b
)<=0; else return strcmpW
(a
,b
)<=0;}
540 static INT comp_ge_s
(LPWSTR a
, LPWSTR b
, BOOL casless
)
541 { if
(casless
) return strcmpiW
(a
,b
)>=0; else return strcmpW
(a
,b
)>=0;}
542 static INT comp_substring
(LPWSTR a
, LPWSTR b
, BOOL casless
)
543 /* ERROR NOT WORKING REWRITE */
544 { if
(casless
) return strstrW
(a
,b
)!=NULL
; else return strstrW
(a
,b
)!=NULL
;}
545 static INT comp_start
(LPWSTR a
, LPWSTR b
, BOOL casless
)
546 { if
(casless
) return strncmpiW
(a
,b
,strlenW
(b
))==0;
547 else return strncmpW
(a
,b
,strlenW
(b
))==0;}
548 static INT comp_end
(LPWSTR a
, LPWSTR b
, BOOL casless
)
554 if
(casless
) return
(!strcmpiW
(&a
[i
-j
-1],b
));
555 else return
(!strcmpW
(&a
[i
-j
-1],b
));
559 static INT comp_eq_m1
(LPWSTR a
, INT b
)
560 { if
(COND_IsNumber
(a
[0])) return atoiW
(a
)==b
; else return
0;}
561 static INT comp_ne_m1
(LPWSTR a
, INT b
)
562 { if
(COND_IsNumber
(a
[0])) return atoiW
(a
)!=b
; else return
1;}
563 static INT comp_lt_m1
(LPWSTR a
, INT b
)
564 { if
(COND_IsNumber
(a
[0])) return atoiW
(a
)<b
; else return
0;}
565 static INT comp_gt_m1
(LPWSTR a
, INT b
)
566 { if
(COND_IsNumber
(a
[0])) return atoiW
(a
)>b
; else return
0;}
567 static INT comp_le_m1
(LPWSTR a
, INT b
)
568 { if
(COND_IsNumber
(a
[0])) return atoiW
(a
)<=b
; else return
0;}
569 static INT comp_ge_m1
(LPWSTR a
, INT b
)
570 { if
(COND_IsNumber
(a
[0])) return atoiW
(a
)>=b
; else return
0;}
572 static INT comp_eq_m2
(INT a
, LPWSTR b
)
573 { if
(COND_IsNumber
(b
[0])) return a
== atoiW
(b
); else return
0;}
574 static INT comp_ne_m2
(INT a
, LPWSTR b
)
575 { if
(COND_IsNumber
(b
[0])) return a
!= atoiW
(b
); else return
1;}
576 static INT comp_lt_m2
(INT a
, LPWSTR b
)
577 { if
(COND_IsNumber
(b
[0])) return a
< atoiW
(b
); else return
0;}
578 static INT comp_gt_m2
(INT a
, LPWSTR b
)
579 { if
(COND_IsNumber
(b
[0])) return a
> atoiW
(b
); else return
0;}
580 static INT comp_le_m2
(INT a
, LPWSTR b
)
581 { if
(COND_IsNumber
(b
[0])) return a
<= atoiW
(b
); else return
0;}
582 static INT comp_ge_m2
(INT a
, LPWSTR b
)
583 { if
(COND_IsNumber
(b
[0])) return a
>= atoiW
(b
); else return
0;}
587 static int COND_IsIdent
( WCHAR x
)
589 return
( COND_IsAlpha
( x
) || COND_IsNumber
( x
) ||
( x
== '_' )
590 ||
( x
== '#' ) ||
(x
== '.') );
593 static int COND_GetOne
( struct cond_str
*str
, COND_input
*cond
)
595 static const WCHAR szNot
[] = {'N','O','T',0};
596 static const WCHAR szAnd
[] = {'A','N','D',0};
597 static const WCHAR szOr
[] = {'O','R',0};
601 str
->data
= &cond
->str
[cond
->n
];
607 case
'(': rc
= COND_LPAR
; break
;
608 case
')': rc
= COND_RPAR
; break
;
609 case
'&': rc
= COND_AMPER
; break
;
610 case
'!': rc
= COND_EXCLAM
; break
;
611 case
'$': rc
= COND_DOLLARS
; break
;
612 case
'?': rc
= COND_QUESTION
; break
;
613 case
'%': rc
= COND_PERCENT
; break
;
614 case
' ': rc
= COND_SPACE
; break
;
615 case
'=': rc
= COND_EQ
; break
;
616 case
'"': rc
= COND_DBLQ
; break
;
617 case
'~': rc
= COND_TILDA
; break
;
618 case
'<': rc
= COND_LT
; break
;
619 case
'>': rc
= COND_GT
; break
;
621 if
( COND_IsAlpha
( ch
) )
623 while
( COND_IsIdent
( str
->data
[len
] ) )
629 if
( COND_IsNumber
( ch
) )
631 while
( COND_IsNumber
( str
->data
[len
] ) )
637 ERR
("Got unknown character %c(%x)\n",ch
,ch
);
642 /* keyword identifiers */
643 if
( rc
== COND_IDENT
)
645 if
( (len
==3) && (strncmpiW
(str
->data
,szNot
,len
)==0) )
647 else if
( (len
==3) && (strncmpiW
(str
->data
,szAnd
,len
)==0) )
649 else if
( (len
==2) && (strncmpiW
(str
->data
,szOr
,len
)==0) )
659 static int COND_lex
( void *COND_lval
, COND_input
*cond
)
662 struct cond_str
*str
= COND_lval
;
665 rc
= COND_GetOne
( str
, cond
);
666 } while
(rc
== COND_SPACE
);
671 static LPWSTR COND_GetString
( struct cond_str
*str
)
675 ret
= HeapAlloc
( GetProcessHeap
(), 0, (str
->len
+1) * sizeof
(WCHAR
) );
678 strncpyW
( ret
, str
->data
, str
->len
);
681 TRACE
("Got identifier %s\n",debugstr_w
(ret
));
685 static int COND_error
(char *str
)
690 MSICONDITION WINAPI MsiEvaluateConditionW
( MSIHANDLE hInstall
, LPCWSTR szCondition
)
695 cond.hInstall
= hInstall
;
696 cond.str
= szCondition
;
700 TRACE
("Evaluating %s\n",debugstr_w
(szCondition
));
702 if
( !COND_parse
( &cond
) )
705 r
= MSICONDITION_ERROR
;
707 TRACE
("Evaluates to %i\n",r
);
711 MSICONDITION WINAPI MsiEvaluateConditionA
( MSIHANDLE hInstall
, LPCSTR szCondition
)
713 LPWSTR szwCond
= NULL
;
718 UINT len
= MultiByteToWideChar
( CP_ACP
, 0, szCondition
, -1, NULL
, 0 );
719 szwCond
= HeapAlloc
( GetProcessHeap
(), 0, len
* sizeof
(WCHAR
) );
720 MultiByteToWideChar
( CP_ACP
, 0, szCondition
, -1, szwCond
, len
);
723 r
= MsiEvaluateConditionW
( hInstall
, szwCond
);
726 HeapFree
( GetProcessHeap
(), 0, szwCond
);