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"
38 #define YYLEX_PARAM info
39 #define YYPARSE_PARAM info
41 static int COND_error(const char *str);
43 WINE_DEFAULT_DEBUG_CHANNEL(msi);
45 typedef struct tag_yyinput
58 static LPWSTR COND_GetString( struct cond_str *str );
59 static LPWSTR COND_GetLiteral( struct cond_str *str );
60 static int COND_lex( void *COND_lval, COND_input *info);
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_TILDA
120 %token COND_PERCENT COND_DOLLARS COND_QUESTION COND_AMPER COND_EXCLAM
121 %token <str> COND_IDENT <str> COND_NUMBER <str> COND_LITER
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;
143 COND_input* cond = (COND_input*) info;
144 cond->result = MSICONDITION_NONE;
153 | boolean_term COND_OR expression
164 | boolean_term COND_AND boolean_factor
189 $$ = ($1 && $1[0]) ? MSICONDITION_TRUE : MSICONDITION_FALSE;
192 | value_i comp_op_i value_i
196 | value_s comp_op_s value_s
198 $$ = $2( $1, $3, FALSE );
202 | value_s COND_TILDA comp_op_s value_s
204 $$ = $3( $1, $4, TRUE );
208 | value_s comp_op_m1 value_i
213 | value_i comp_op_m2 value_s
218 | COND_LPAR expression COND_RPAR
225 /* common functions */
266 /* common functions */
307 /* common functions */
332 /*Not valid for mixed compares*/
348 /* common functions */
373 /*Not valid for mixed compares*/
413 $$ = COND_GetLiteral(&$1);
420 COND_DOLLARS identifier
422 COND_input* cond = (COND_input*) info;
423 INSTALLSTATE install = INSTALLSTATE_UNKNOWN, action = INSTALLSTATE_UNKNOWN;
425 MSI_GetComponentStateW(cond->package, $2, &install, &action );
429 | COND_QUESTION identifier
431 COND_input* cond = (COND_input*) info;
432 INSTALLSTATE install = INSTALLSTATE_UNKNOWN, action = INSTALLSTATE_UNKNOWN;
434 MSI_GetComponentStateW(cond->package, $2, &install, &action );
438 | COND_AMPER identifier
440 COND_input* cond = (COND_input*) info;
441 INSTALLSTATE install = INSTALLSTATE_UNKNOWN, action = INSTALLSTATE_UNKNOWN;
443 MSI_GetFeatureStateW(cond->package, $2, &install, &action );
447 | COND_EXCLAM identifier
449 COND_input* cond = (COND_input*) info;
450 INSTALLSTATE install = INSTALLSTATE_UNKNOWN, action = INSTALLSTATE_UNKNOWN;
452 MSI_GetFeatureStateW(cond->package, $2, &install, &action );
462 COND_input* cond = (COND_input*) info;
465 MSI_GetPropertyW(cond->package, $1, NULL, &sz);
468 $$ = msi_alloc( sizeof(WCHAR));
474 $$ = msi_alloc( sz*sizeof (WCHAR) );
476 /* Lookup the identifier */
478 MSI_GetPropertyW(cond->package,$1,$$,&sz);
482 | COND_PERCENT identifier
484 UINT len = GetEnvironmentVariableW( $2, NULL, 0 );
487 $$ = msi_alloc( len*sizeof (WCHAR) );
489 GetEnvironmentVariableW( $2, $$, len );
498 $$ = COND_GetString(&$1);
507 LPWSTR szNum = COND_GetString(&$1);
518 static int COND_IsAlpha( WCHAR x )
520 return( ( ( x >= 'A' ) && ( x <= 'Z' ) ) ||
521 ( ( x >= 'a' ) && ( x <= 'z' ) ) ||
525 static int COND_IsNumber( WCHAR x )
527 return( (( x >= '0' ) && ( x <= '9' )) || (x =='-') || (x =='.') );
531 /* the mess of comparison functions */
533 static INT comp_lt_i(INT a, INT b)
535 static INT comp_gt_i(INT a, INT b)
537 static INT comp_le_i(INT a, INT b)
539 static INT comp_ge_i(INT a, INT b)
541 static INT comp_eq_i(INT a, INT b)
543 static INT comp_ne_i(INT a, INT b)
545 static INT comp_bitand(INT a, INT b)
547 static INT comp_highcomp(INT a, INT b)
548 { return HIWORD(a)==b; }
549 static INT comp_lowcomp(INT a, INT b)
550 { return LOWORD(a)==b; }
552 static INT comp_eq_s(LPWSTR a, LPWSTR b, BOOL casless)
553 { if (casless) return !strcmpiW(a,b); else return !strcmpW(a,b);}
554 static INT comp_ne_s(LPWSTR a, LPWSTR b, BOOL casless)
555 { if (casless) return strcmpiW(a,b); else return strcmpW(a,b);}
556 static INT comp_lt_s(LPWSTR a, LPWSTR b, BOOL casless)
557 { if (casless) return strcmpiW(a,b)<0; else return strcmpW(a,b)<0;}
558 static INT comp_gt_s(LPWSTR a, LPWSTR b, BOOL casless)
559 { if (casless) return strcmpiW(a,b)>0; else return strcmpW(a,b)>0;}
560 static INT comp_le_s(LPWSTR a, LPWSTR b, BOOL casless)
561 { if (casless) return strcmpiW(a,b)<=0; else return strcmpW(a,b)<=0;}
562 static INT comp_ge_s(LPWSTR a, LPWSTR b, BOOL casless)
563 { if (casless) return strcmpiW(a,b)>=0; else return strcmpW(a,b)>=0;}
564 static INT comp_substring(LPWSTR a, LPWSTR b, BOOL casless)
565 /* ERROR NOT WORKING REWRITE */
566 { if (casless) return strstrW(a,b)!=NULL; else return strstrW(a,b)!=NULL;}
567 static INT comp_start(LPWSTR a, LPWSTR b, BOOL casless)
568 { if (casless) return strncmpiW(a,b,strlenW(b))==0;
569 else return strncmpW(a,b,strlenW(b))==0;}
570 static INT comp_end(LPWSTR a, LPWSTR b, BOOL casless)
576 if (casless) return (!strcmpiW(&a[i-j-1],b));
577 else return (!strcmpW(&a[i-j-1],b));
581 static INT comp_eq_m1(LPWSTR a, INT b)
582 { if (COND_IsNumber(a[0])) return atoiW(a)==b; else return 0;}
583 static INT comp_ne_m1(LPWSTR a, INT b)
584 { if (COND_IsNumber(a[0])) return atoiW(a)!=b; else return 1;}
585 static INT comp_lt_m1(LPWSTR a, INT b)
586 { if (COND_IsNumber(a[0])) return atoiW(a)<b; else return 0;}
587 static INT comp_gt_m1(LPWSTR a, INT b)
588 { if (COND_IsNumber(a[0])) return atoiW(a)>b; else return 0;}
589 static INT comp_le_m1(LPWSTR a, INT b)
590 { if (COND_IsNumber(a[0])) return atoiW(a)<=b; else return 0;}
591 static INT comp_ge_m1(LPWSTR a, INT b)
592 { if (COND_IsNumber(a[0])) return atoiW(a)>=b; else return 0;}
594 static INT comp_eq_m2(INT a, LPWSTR b)
595 { if (COND_IsNumber(b[0])) return a == atoiW(b); else return 0;}
596 static INT comp_ne_m2(INT a, LPWSTR b)
597 { if (COND_IsNumber(b[0])) return a != atoiW(b); else return 1;}
598 static INT comp_lt_m2(INT a, LPWSTR b)
599 { if (COND_IsNumber(b[0])) return a < atoiW(b); else return 0;}
600 static INT comp_gt_m2(INT a, LPWSTR b)
601 { if (COND_IsNumber(b[0])) return a > atoiW(b); else return 0;}
602 static INT comp_le_m2(INT a, LPWSTR b)
603 { if (COND_IsNumber(b[0])) return a <= atoiW(b); else return 0;}
604 static INT comp_ge_m2(INT a, LPWSTR b)
605 { if (COND_IsNumber(b[0])) return a >= atoiW(b); else return 0;}
609 static int COND_IsIdent( WCHAR x )
611 return( COND_IsAlpha( x ) || COND_IsNumber( x ) || ( x == '_' )
612 || ( x == '#' ) || (x == '.') );
615 static int COND_GetOne( struct cond_str *str, COND_input *cond )
617 static const WCHAR szNot[] = {'N','O','T',0};
618 static const WCHAR szAnd[] = {'A','N','D',0};
619 static const WCHAR szOr[] = {'O','R',0};
623 str->data = &cond->str[cond->n];
629 case '(': rc = COND_LPAR; break;
630 case ')': rc = COND_RPAR; break;
631 case '&': rc = COND_AMPER; break;
632 case '!': rc = COND_EXCLAM; break;
633 case '$': rc = COND_DOLLARS; break;
634 case '?': rc = COND_QUESTION; break;
635 case '%': rc = COND_PERCENT; break;
636 case ' ': rc = COND_SPACE; break;
637 case '=': rc = COND_EQ; break;
638 case '~': rc = COND_TILDA; break;
639 case '<': rc = COND_LT; break;
640 case '>': rc = COND_GT; break;
643 const WCHAR *ch2 = str->data + 1;
646 while ( *ch2 && *ch2 != '"' )
650 len = ch2 - str->data + 1;
655 ERR("Unterminated string\n");
659 if( COND_IsAlpha( ch ) )
661 while( COND_IsIdent( str->data[len] ) )
667 if( COND_IsNumber( ch ) )
669 while( COND_IsNumber( str->data[len] ) )
675 ERR("Got unknown character %c(%x)\n",ch,ch);
680 /* keyword identifiers */
681 if( rc == COND_IDENT )
683 if( (len==3) && (strncmpiW(str->data,szNot,len)==0) )
685 else if( (len==3) && (strncmpiW(str->data,szAnd,len)==0) )
687 else if( (len==2) && (strncmpiW(str->data,szOr,len)==0) )
697 static int COND_lex( void *COND_lval, COND_input *cond )
700 struct cond_str *str = COND_lval;
703 rc = COND_GetOne( str, cond );
704 } while (rc == COND_SPACE);
709 static LPWSTR COND_GetString( struct cond_str *str )
713 ret = msi_alloc( (str->len+1) * sizeof (WCHAR) );
716 memcpy( ret, str->data, str->len * sizeof(WCHAR));
719 TRACE("Got identifier %s\n",debugstr_w(ret));
723 static LPWSTR COND_GetLiteral( struct cond_str *str )
727 ret = msi_alloc( (str->len-1) * sizeof (WCHAR) );
730 memcpy( ret, str->data+1, (str->len-2) * sizeof(WCHAR) );
733 TRACE("Got literal %s\n",debugstr_w(ret));
737 static int COND_error(const char *str)
743 MSICONDITION MSI_EvaluateConditionW( MSIPACKAGE *package, LPCWSTR szCondition )
748 if ( szCondition == NULL )
749 return MSICONDITION_NONE;
751 cond.package = package;
752 cond.str = szCondition;
754 cond.result = MSICONDITION_ERROR;
756 TRACE("Evaluating %s\n",debugstr_w(szCondition));
758 if ( !COND_parse( &cond ) )
761 r = MSICONDITION_ERROR;
763 TRACE("Evaluates to %i\n",r);
767 MSICONDITION WINAPI MsiEvaluateConditionW( MSIHANDLE hInstall, LPCWSTR szCondition )
772 package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE);
774 return MSICONDITION_ERROR;
775 ret = MSI_EvaluateConditionW( package, szCondition );
776 msiobj_release( &package->hdr );
780 MSICONDITION WINAPI MsiEvaluateConditionA( MSIHANDLE hInstall, LPCSTR szCondition )
782 LPWSTR szwCond = NULL;
785 szwCond = strdupAtoW( szCondition );
786 if( szCondition && !szwCond )
787 return MSICONDITION_ERROR;
789 r = MsiEvaluateConditionW( hInstall, szwCond );