bool FQueryEvaluator::EvalNoExprMatch(FGameplayTagContainer const& Tags, bool bSkip)
{
	bool bShortCircuit = bSkip;

	// assume true until proven otherwise
	bool Result = true;

	// parse exprset
	int32 const NumExprs = GetToken();
	if (bReadError)
	{
		return false;
	}

	for (int32 Idx = 0; Idx < NumExprs; ++Idx)
	{
		bool const bExprResult = EvalExpr(Tags, bShortCircuit);
		if (bShortCircuit == false)
		{
			if (bExprResult == true)
			{
				// one match is sufficient for fail result
				Result = false;
				bShortCircuit = true;
			}
		}
	}

	return Result;
}
Example #2
0
static int resolvenametoaddr(int index, int doErrors)
{
    int offset, addr, linoffs;
    DEBUG_INFO *dbg;
    VARINFO *var;
    char buf[256];
    strcpy(buf, hdwebp[index].name);
    var = EvalExpr(&dbg, &lastScope, buf, doErrors);
    if (var)
    {
        if (var->constant)
            addr = var->ival;
        else if (var->address < 0x1000)
        {
            char data[20];
            ReadValue(var->address, &data, 4, var);
            addr = *(int*)data;
        } 
        else
            addr = var->address;
        FreeVarInfo(var);
        hdwebp[index].address = addr;
        return 1;
    }
    else
    {
        return 0;
    }
}
Example #3
0
//-------------------------------------------------------------------------
static void LoadLocals(WATCHDATA *ptr)
{
    NAMELIST *names = FindEnclosedAutos(activeScope);
    WATCHINFO *p = ptr->watchinfo_list;
    int i;
    for (i=0; i < ptr->watchinfo_count; i++)
        if (!strcmp(ptr->watchinfo_list[i].info->membername, "this"))
        {
            WATCHINFO *x = &ptr->watchinfo_list[i];
            int j;
            FreeTree(x->info, ptr);
            FreeVarInfo(x->info);
            for (j = i; j < ptr->watchinfo_count - 1; j++)

            {
                ptr->watchinfo_list[j] = ptr->watchinfo_list[j + 1];
                RenumberDeleteItems(ptr->watchinfo_list[j].info);
            }
            ptr->watchinfo_count--;
            i--;
        }
        else
        {
            p[i].marked = TRUE;
        }
    while (names)
    {
        NAMELIST *next = names->next;
        DEBUG_INFO *dbg;
        VARINFO *var = EvalExpr(&dbg, activeScope, (char*) names->data+1, FALSE);
        if (var)
        {
            AddItem(dbg, var, activeScope->address, ptr);
        }
        free(names->data);
        free(names);
        names = next;
    }
    p = ptr->watchinfo_list;
    for (i=0; i < ptr->watchinfo_count; i++)
        if (p[i].marked)
        {
            WATCHINFO *x = &ptr->watchinfo_list[i];
            int j;
            FreeTree(x->info, ptr);
            FreeVarInfo(x->info);
            for (j = i; j < ptr->watchinfo_count - 1; j++)

            {
                ptr->watchinfo_list[j] = ptr->watchinfo_list[j + 1];
                RenumberDeleteItems(ptr->watchinfo_list[j].info);
            }
            ptr->watchinfo_count--;
            i--;
        }
}
Example #4
0
/*
 * CallExpr -- get a call expression
 */
void CallExpr( address *out_val )
{
    unsigned    old;

    old = SetCurrRadix( 16 );
    _SwitchOn( SW_EXPR_IS_CALL );
    EvalExpr( 0 ); /* call expression */
    MakeMemoryAddr( TRUE, EXPR_CODE, out_val );
    SetCurrRadix( old );
}
Example #5
0
void ReqMemAddr( memory_expr def_seg, address *out_val )
{
    unsigned    old;

    old = SetCurrRadix( 16 );
    _SwitchOff( SW_EXPR_IS_CALL );
    EvalExpr( 0 );   /* memory expression */
    MakeMemoryAddr( TRUE, def_seg, out_val );
    SetCurrRadix( old );
}
Example #6
0
mad_status      DIGCLIENT MADCliMemExpr( const char *expr, unsigned radix, address *a )
{
    const char  *old_scan;
    unsigned    old_radix;

    old_radix = SetCurrRadix( radix );
    old_scan = ReScan( expr );
    EvalExpr( 0 );   /* memory expression */
    MakeMemoryAddr( TRUE, EXPR_DATA, a );
    SetCurrRadix( old_radix );
    ReScan( old_scan );
    return( MS_OK );
}
Example #7
0
void RefreshItems(int page)
{
    int i;
    char *types,  *syms;
    int offset;
    DEBUG_INFO *dbg;
    for (i = 0; i < watchinfo_count[page]; i++)
    {
        WATCHINFO *wi = &watchinfo_list[page][i];
        VARINFO *var;
        int level;
        var = EvalExpr(&wi->dbg_info, activeScope,
                               (char*)wi->info->membername, FALSE);
        if (!var)
        {
            Unscope(wi, page);
            offset = 0;
        }
        else
        {
            wi->info->outofscopereg = var->outofscopereg;
            if (var->outofscopereg)
            {
                Unscope(wi, page);
                offset = 0;
            }
            else
            {
                int ebp, level;
                Rescope(wi, i, page);
                offset = var->address;
                wi->cursoreip = activeScope->address;
                if (var->pointer)
                {
                    wi->info->derefaddress = var->derefaddress;
                }
            }
            FreeVarInfo(var);
        }
        RefreshItem(wi, offset, activeThread);
    }
    InvalidateRect(hwndTree[page], 0, 0);
}
Example #8
0
void ReloadVars(WATCHDATA *ptr)
{
    int i;
    int len = ptr->watchinfo_count;
    for (i=0; i < ptr->watchinfo_count; i++)
    {
        FreeTree(ptr->watchinfo_list[i].info, ptr);
    }
    ptr->watchinfo_count = 0;
    for (i=0; i < len; i++)
    {
        DEBUG_INFO *dbg;
        VARINFO *var = EvalExpr(&dbg, activeScope, (char*)ptr->watchinfo_list[i].info->membername , FALSE);
        if (var)
            FreeVarInfo(ptr->watchinfo_list[i].info);
        else
            var = ptr->watchinfo_list[i].info;
        AddItem(dbg, var, activeScope->address, ptr);
    }
}
Example #9
0
int main(int argc, char *argv[])
{
    EvalState c;
    uint8_t heap[512];
    char buf[100];
    VALUE value;

    InitEvalState(&c, heap, sizeof(heap));
    c.findSymbol = FindSymbol;
    c.cookie = NULL;

    for (;;) {
        printf("expr> ");
        if (!gets(buf))
            break;
        if (EvalExpr(&c, buf, &value))
            printf(" --> %g\n", value);
    }
    
    return 0;
}
bool FQueryEvaluator::Eval(FGameplayTagContainer const& Tags)
{
	CurStreamIdx = 0;

	// start parsing the set
	Version = GetToken();
	if (bReadError)
	{
		return false;
	}
	
	bool bRet = false;

	uint8 const bHasRootExpression = GetToken();
	if (!bReadError && bHasRootExpression)
	{
		bRet = EvalExpr(Tags);

	}

	ensure(CurStreamIdx == Query.QueryTokenStream.Num());
	return bRet;
}
Example #11
0
static int resolvenametoaddr(char *name, int doErrors, DWORD *size, DWORD *addr)
{
    DEBUG_INFO *dbg;
    VARINFO *var;
    var = EvalExpr(&dbg, &lastScope, name, doErrors);
    if (var)
    {
        if (var->constant)
        {
            *addr = var->ival;
            *size = 4;
        }
        else if (var->address < 0x1000)
        {
            char data[20];
            //if (!var->explicitreg)
                //ExtendedMessageBox("Address error", MB_SETFOREGROUND |
                    //MB_SYSTEMMODAL, 
                    //"Address is a register.  Using its value as the address.");
            ReadValue(var->address, &data, 4, var);
            *addr = *(int*)data;
            *size = 4;
        } 
        else
        {
            *addr = var->address;
            *size = var->size;
        }
        FreeVarInfo(var);
        return 1;
    }
    else
    {
        return 0;
    }
}
Example #12
0
int Pass1(char *fname, Table optab, Table stab)
  /* Pass1 expects a file name (fname), opcode table (optab), and
       symbol table (stab) from the caller.  It takes the fname and
       appends the file types to it so that the MACASM and ITF files
       can be opened.  Once opened, a line is read in one at a time
       and is parsed.  If there is a symbol and it is valid, it is
       placed in the symbol table.  The opcode is then checked to see
       if it is valid.  The line with its location counter and error
       code is then written to the ITF file.  The program length is
       returned.  */
{
 char MacName[45], ITFName[45];
   /* names of the MAC file and ITF file */
 FILE *mfile, *ifile;
   /* pointers to the MAC file and ITF file */
 char line[81];
   /* line read from input */
 char *label, *operation, *operand;
   /* values determined in ParseLine */
 short loc = 0;
   /* location counter */
 ITFline ITF;
   /* line to be sent to ITF */
 SymbolData *Sym;
   /* Symbol to be added to the symbol table */
 int result, good, good2;
   /* result of TInsert and flag that label is good */
 int i;
   /* loop index */
 int val;
 unsigned err;
   /* value and err from EvalExpr */
 char typ;
   /* type from EvalExpr */
 TableRecord *tptr;
   /* used for TRetrieve */
 int ok, inc; /* opcode ok  and go ahead and increment */
 
          /* append MAC and ITF to filename and open them */
 strcpy(MacName, fname);
 strcpy(ITFName, fname);
 strcat(MacName," MACASM (TEXT RECFM F LRECL 80\0");
 strcat(ITFName," ITF (BIN RECFM F LRECL 86\0");
 if ((mfile = fopen(MacName, "r")) == NULL)
   printf("Unable to open %s\n", MacName);
 else if ((ifile = fopen(ITFName, "w")) == NULL)
   printf ("Unable to open %s\n", ITFName);
 else
 {
   operation = dummystr;
   while ((!feof(mfile)) && (strcmp(operation, endstr) != 0))
    {
                 /* get line and make a copy of it */
     fread(line, 1, 81, mfile);
                 /* initialize ITFLine for comment */
     strcpy(ITF.srcline, line);
     ITF.locctr = loc;
     ITF.error = 0;
 
                    /* check line for comment */
     if (line[0] != '*')
      {
                          /* Parse Line */
       upper(line);
       ParseLine(line, &label, &operation, &operand);
 
                    /* check for valid opcode */
       ok = inc = 1;
       if (isalnum(operation[0]) || ispunct(operation[0]))
        if(TRetrieve(optab,operation)) ok = 1;
        else
         {
          ITF.error |= ILLEGAL_OPCODE;
          ok = 0;
         }
       else inc = 0;    /* no opcode so don't increment locctr */
 
       if (ok)
        {
         if ((strcmp(operation,equstr) != 0))
          {
              /* check for label and process symbol */
           good = 1;
           if (label != NULL)
            if (strcmp(operation, extstr) == 0)
             ITF.error |= UNEXPECTED_LABEL;
              /* check to see if label is valid */
            else if (isalpha(label[0]) && strlen(label) < 9)
             {
       /* valid so far, check for other problems with label */
              for (i=1; i < strlen(label); i++)
               if (!isalnum(label[i])) good = 0;
              if (good)
               {
                       /* process label */
                Sym = (SymbolData *)malloc(sizeof(SymbolData));
                strcpy(Sym->symbol, label);
                Sym->value = loc;
                Sym->type = REL;
                result = TInsert(stab, Sym->symbol, Sym);
                if (result == DUP)
                 {
                  ITF.error |= MULT_DEF_SYM;      /* duplicate symbol */
                  free(Sym);
                 }
                if (result == FULL)              /* symbol table full */
                 {
                  ITF.error |= SYM_TAB_OF;
                  free(Sym);
                 }
               } /* end if good */
              else ITF.error |= INVALID_LABEL;
             } /* end if alpha and len < 9 */
            else ITF.error |= INVALID_LABEL;
 
            /* if DX directive,  create operand symbol */
            if (strcmp(operation,dxstr) == 0)
             {
              good2 = 1;
              if(isalpha(operand[0]) && strlen(operand) < 9)
               {
                for (i=1; i < strlen(operand); i++)
                 if(!isalnum(operand[i])) good2 = 0;
               }
              else good2 = 0;
              if (good2 != 0)
               {
                Sym = (SymbolData *)malloc(sizeof(SymbolData));
                strcpy(Sym->symbol, operand);
                Sym->value = 0;
                Sym->type = DXEXT;
                result = TInsert(stab, Sym->symbol, Sym);
                if (result == DUP)
                 {
                  ITF.error |= MULT_DEF_SYM;   /* duplicate symbol */
                  free(Sym);
                 }
                if (result == FULL)         /* symbol table full */
                 {
                  ITF.error |= SYM_TAB_OF;
                  free(Sym);
                 }
               } /* end if good2 */
              else ITF.error |= BAD_SYM_DX;
             } /* end if dxstr */
 
      /* if extstr check for operand symbol and don't increment loc */
            if(strcmp(operation, extstr) == 0)
             if (tptr = TRetrieve(stab,operand))
              {
               Sym = tptr->data;
               if (Sym->type == REL)
                Sym->type = EXT;
               else ITF.error |= ILL_EXPR;
              }
             else ITF.error |= UNDEF_SYM;
                 /* increment location counter */
            else if (inc)
             if(strcmp(operation, dsstr) != 0) loc++;
             else
              {
               EvalExpr(operand,stab,&val,&typ,&err);
               if (typ == ABS && val >= 0 && !err)
                loc += val;
               else ITF.error |= err | ILL_EXPR;
              }
          }       /* end if not =  */
         else /* operation is = directive */
          {
              /* check to see if label is valid */
           good = 1;
           if ((label!=NULL) && (isalpha(label[0])) && (strlen(label)<9))
            for (i=1; i < strlen(label); i++)
             if (!isalnum(label[i])) good = 0;
             else good = good;
           else good = 0;
           if (good)
            {
             val = err = 0;
             EvalExpr(operand,stab,&val,&typ,&err);
             if (!err)
              {
               Sym = (SymbolData *)malloc(sizeof(SymbolData));
               strcpy(Sym->symbol, label);
               Sym->value = val;
               Sym->type = typ;
               result = TInsert(stab, Sym->symbol, Sym);
               if (result == DUP)
                {
                 ITF.error |= MULT_DEF_SYM;      /* duplicate symbol */
                 free(Sym);
                }
               if (result == FULL)              /* symbol table full */
                {
                 ITF.error |= SYM_TAB_OF;
                 free(Sym);
                }
              } /* end if !err */
             else ITF.error |= err;
            } /* end if good */
           else ITF.error |= INVALID_LABEL;
          }    /* end if eqstr */
        } /* end if ok */
       else ITF.error |= ILLEGAL_OPCODE;
      } /* end if not * */
 
                     /* write ITF line */
     fwrite(&ITF, sizeof(ITFline), 1, ifile);
    } /* end while */
 
                /* close files */
  fclose(mfile);
  fclose(ifile);
 }
 
 return loc - 1;
} /* end Pass1 */
Example #13
0
LRESULT CALLBACK WatchWndProc(HWND hwnd, UINT iMessage, WPARAM wParam,
    LPARAM lParam)
{
    
    static int selected;
    static POINT menupos;
    static char buf[256];
    RECT r,  *pr;
    WINDOWPOS wp;
    HD_ITEM hie;
    HD_LAYOUT hdl;
    NMHDR *h;
    DRAWITEMSTRUCT *dr;
    HBITMAP hbmp;
    HDC hMemDC;
    TCHeader tch;
    TV_ITEM item;
    TV_INSERTSTRUCT t;
    static int sizingbottom;
    int offset;
    DEBUG_INFO *dbg;
    NM_TREEVIEW *nmt;
    VARINFO *var;
    HWND win;
    int level;
    int offset1;
    int doit;
    int i;
    CHARRANGE charrange;
    switch (iMessage)
    {
        case WM_SYSCOMMAND:
            if (wParam == SC_CLOSE)
            {
                PostMessage(hwnd, WM_CLOSE, 0, 0);
                return 0;
            }
            break;
        case WM_NOTIFY:
            h = (NMHDR*)lParam;
            switch (h->code)
            {
            case TABN_SELECTED:
                {
                    LSTABNOTIFY *p = (LSTABNOTIFY *)h;
                    ShowWindow(hwndTree[selected], SW_HIDE);
                    for (i=0; i < 4; i++)
                        if (p->lParam == (LPARAM)hwndTree[i])
                            selected = i;
                    ShowWindow(hwndTree[selected], SW_SHOW);
                    break;
                }
            case NM_RCLICK:
                {
                    HMENU menu = LoadMenuGeneric(hInstance, "WATCHMENU");
                    HMENU popup = GetSubMenu(menu, 0);
                    InsertBitmapsInMenu(popup);
                    GetCursorPos(&menupos);
                    TrackPopupMenuEx(popup, TPM_BOTTOMALIGN | TPM_LEFTBUTTON,
                        menupos.x, menupos.y, hwndFrame, NULL);
                    DestroyMenu(menu);
                    SetFocus(hwndTree[selected]);
                }
                return 0;
            case TVN_ITEMEXPANDING:
                nmt = h;
                if (nmt->action)
                {
                    ExpandPointer((VARINFO*)nmt->itemNew.lParam, nmt->action, selected);
                }
                return 0;
            case TCN_EDITQUERY:
                nmt = h;
                item.mask = TVIF_PARAM;
                item.hItem = (HTREEITEM)nmt->itemNew.hItem;
                TreeView_GetItem(hwndTree[selected], &item);
                var = (VARINFO*)item.lParam;
                if (var->editable)
                {
                    WatchValue(watchinfo_list[selected][var->watchindex].dbg_info, buf,
                        var, TRUE);
                    return buf;
                }
                return 0;
            case TCN_EDITDONE:
                nmt = h;
                item.mask = TVIF_PARAM;
                item.hItem = (HTREEITEM)nmt->itemNew.hItem;
                TreeView_GetItem(hwndTree[selected], &item);
                var = (VARINFO*)item.lParam;
                ChangeData(var, nmt->itemNew.pszText, selected);
                RefreshItems(selected);
                return 0;
           }
            break;
        case WM_CREATE:
            hwndWatch = hwnd;
            GetClientRect(hwnd, &r);
            valueBitmap = LoadImage(hInstance, "ID_VALUEBMP", IMAGE_BITMAP, 0, 0, LR_LOADMAP3DCOLORS);
            itemBitmap = LoadImage(hInstance, "ID_ITEMBMP", IMAGE_BITMAP, 0, 0, LR_LOADMAP3DCOLORS);
            tch.colText1 = "Item";
            tch.colText2 = "Value";
            tch.colBmp1 = itemBitmap;
            tch.colBmp2 = valueBitmap;
            hwndTabCtrl = CreateLsTabWindow(hwnd, TABS_BOTTOM | TABS_HOTTRACK | TABS_FLAT | WS_VISIBLE);
            tabNormalFont = CreateFontIndirect(&tabFontData);
            SendMessage(hwndTabCtrl, WM_SETFONT, (WPARAM)tabNormalFont, 0);
            r.bottom -= 25;
            for (i=3; i >0 ; i--)
                hwndTree[i] = CreateextTreeWindow(hwnd, WS_DLGFRAME | TCS_LINE, &r, &tch);
            hwndTree[0] = CreateextTreeWindow(hwnd, WS_DLGFRAME | TCS_LINE | WS_VISIBLE, &r, &tch);
            for (i=3; i >=0 ; i--)
                SendMessage(hwndTabCtrl, TABM_ADD, (WPARAM)nameTags[i], (LPARAM)hwndTree[i]);
            return 0;
        case WM_ADDWATCHINDIRECT:
            win = (HWND)wParam;
            doit = FALSE;
            SendMessage(win, EM_EXGETSEL, (WPARAM)0, (LPARAM) &charrange);
            if (charrange.cpMin == charrange.cpMax)
            {
                doit = SendMessage(win, WM_WORDUNDERPOINT, (WPARAM)&rightclickPos, (LPARAM)buf);
                if (!doit)
                {
                    SendMessage(hwndFrame, IDM_ADDWATCH, 0, 0);
                    break;
                }
            }
            else
            {
                if (charrange.cpMax - charrange.cpMin < sizeof(buf))
                {
                    SendMessage(win, EM_GETSELTEXT, 0, (LPARAM)buf);
                    doit = TRUE ;
                }
            }
            if (doit)
            {
                var = EvalExpr(&dbg, activeScope, (char*) buf, TRUE);
                if (var)
                {
                    AddItem(dbg, var, activeScope->address, selected);
                    dmgrHideWindow(DID_WATCHWND, FALSE);
                    break ;
                }
            }
            ExtendedMessageBox("Error", MB_SETFOREGROUND |
                MB_SYSTEMMODAL, "Symbol does not exist in this scope");
            break;
        case WM_ADDWATCH:
            offset = wParam;
            if (!offset)
            {
                DeleteAllItems(selected);
            }
            else
            {
                var = EvalExpr(&dbg, activeScope, (char*)
                    lParam, TRUE);
                if (var)
                {
                    AddItem(dbg, var, activeScope->address, selected);
                    dmgrHideWindow(DID_WATCHWND, FALSE);
                }
            }
            break;
        case WM_COMMAND:
            switch (wParam)
            {
            case ID_SETADDRESS:
                for (i=3; i >=0; i--)
                    RefreshItems(i);
                InvalidateRect(hwndTree[selected], 0, 0);
                break;
            case IDM_DELETEWATCH:
                DeleteItem(&menupos, selected);
                break;
            case IDM_DELETEALLWATCH:
                DeleteAllItems(selected);
                break;
            }
            break;
        case WM_DESTROY:
            for (i=3; i >=0 ; i--)
                TreeView_DeleteAllItems(hwndTree[i]);
            for (i=3; i >=0 ; i--)
                DestroyWindow(hwndTree[i]);
            DeleteObject(valueBitmap);
            DeleteObject(itemBitmap);
            hwndWatch = 0;
            break;

        case WM_SIZE:
            r.left = 0;
            r.right = LOWORD(lParam);
            r.top = 0;
            r.bottom = HIWORD(lParam);
            MoveWindow(hwndTabCtrl, r.left, r.bottom - 24, r.right - r.left, 24, 1);
            for (i=3; i >=0 ; i--)
                MoveWindow(hwndTree[i], r.left, r.top, r.right - r.left, r.bottom -
                    r.top - 25, 0);
            return 0;
        case WM_CLOSE:
            break;
        case WM_ACTIVATEME:
            SendMessage(GetParent(hwnd), WM_ACTIVATEME, 0, 0);
            break;
    }
    return DefWindowProc(hwnd, iMessage, wParam, lParam);
}
	/*
	* Routine: EvalExpr(expr_t *)
	* Purpose: return the value of the expression as a string
	* Algorithm:
	* Data Structures:
	*
	* Params:
	* Returns:
	* Called By: 
	* Calls: 
	* Assumptions:
	* Side Effects:
	* TODO: None
	*/
	int 
	EvalExpr(expr_t *pExpr, Expr_Val_t *pValue, int bIsParam, int nQueryNumber)
	{
		int i,
			nDataType = 0,
			nArgCnt,
			nUseCount;
		expr_t *pArg;
		substitution_t *pSub;
		Expr_Val_t arParams[MAX_ARGS],
			*pExistingValue;

		for (i=0; i < MAX_ARGS; i++)
		{
			memset(&arParams[i], 0, sizeof(struct EXPR_VAL_T));
			arParams[i].pBuf = InitBuffer(10, 10);
		}
		
		if (pExpr->Value.pBuf == NULL)
			pExpr->Value.pBuf = InitBuffer(15, 15);
		
		/* handle the constants */
		if (pExpr->nFlags & EXPR_FL_CONST)
		{
			switch(i = pExpr->nFlags & EXPR_TYPE_MASK )
			{
			case EXPR_FL_INT|EXPR_FL_KEYWORD:
			case EXPR_FL_CHAR|EXPR_FL_KEYWORD:
				nDataType = EvalKeywordExpr(pExpr, pValue);
				break;
			case EXPR_FL_INT:
				pValue->nValue = pExpr->Value.nValue;
				nDataType = EXPR_FL_INT;
				pValue->bUseInt = 1;
				break;
			case EXPR_FL_CHAR:
				AddBuffer(pValue->pBuf, GetBuffer(pExpr->Value.pBuf));
				nDataType = EXPR_FL_CHAR;
				pValue->bUseInt = 0;
				break;
			default:
				fprintf(stderr, "INTERNAL ERROR: unknown constant type %d\n", i);
				exit(1);
			}
			
			pValue->nQueryNumber = nQueryNumber;
			return(nDataType);
		}
      /* expressions get evaluated once per query; test is done here
         to avoid a problem with constant values (e.g., LIMITB)
      */
		if (pValue->nQueryNumber == nQueryNumber)
			return(pValue->bUseInt?DT_INT:DT_STR);
		
		/* handle the parameterized expressions */
		switch(pExpr->nFlags & EXPR_FUNC_MASK)
		{
		case EXPR_FL_REPL:
			pValue->nValue = pExpr->Value.nValue;
			AddBuffer(pValue->pBuf, GetBuffer(pExpr->Value.pBuf));
			nDataType = EXPR_FL_CHAR;
			break;
		case EXPR_FL_SUBST:
			pSub = findSubstitution(pCurrentQuery, GetBuffer(pExpr->Value.pBuf), &nUseCount);
			if (pSub == NULL)
				ReportError(QERR_BAD_NAME, GetBuffer(pExpr->Value.pBuf), 1);
			if (pSub->nQueryNumber != nQueryNumber)	/* we've not set a value; do so*/
			{
				pSub->nDataType = EvalExpr(pSub->pAssignment, pSub->arValues, 0, nQueryNumber);
			}
			/*
			pExistingValue = pSub->arValues;
			pExistingValue += pSub->nSubParts * (nUseCount - 1);
			*/
			pExistingValue = &pSub->arValues[pExpr->nSubElement - 1];
			memcpy(pValue, pExistingValue, sizeof(struct EXPR_VAL_T));
			if (pExistingValue->bUseInt)
				nDataType = DT_INT;
			else
				nDataType = DT_CHR;
			pSub->nQueryNumber = nQueryNumber;
			break;
		case EXPR_FL_FUNC:
		/* walk the argument list and put them in the appropriate arXXXArgs location 
		* based on data type 
			*/
			nArgCnt = 0;
			for (pArg = (expr_t *)getHead(pExpr->ArgList); pArg; pArg = (expr_t *)getNext(pExpr->ArgList))
			{
				if (nArgCnt >= MAX_ARGS)
					ReportError(QERR_ARG_OVERFLOW, NULL, 1);
				ResetBuffer(arParams[nArgCnt].pBuf);
				if (EvalExpr(pArg, &arParams[nArgCnt], 1, nQueryNumber) == DT_INT)
					arParams[nArgCnt].bUseInt = 1;
				nArgCnt += 1;
				
			}
			
			/* invoke each function */
			switch(pExpr->Value.nValue)
			{
			case KW_TEXT:
				nDataType = EvalTextExpr(pExpr, pValue, arParams, bIsParam);
				break;
			case KW_DATE:
				nDataType = EvalDateExpr(pExpr, pValue, arParams, bIsParam);
				break;
			case KW_DISTWEIGHT:
			case KW_DISTMEMBER:
			case KW_DIST:
				nDataType = EvalDistExpr(pExpr, pValue, arParams, bIsParam);
				break;
			case KW_RANDOM:
				nDataType = EvalRandomExpr(pExpr, pValue, arParams, bIsParam);
				break;
			case OP_ADD:
			case OP_SUBTRACT:
			case OP_MULTIPLY:
			case OP_DIVIDE:
				nDataType = EvalArithmetic(pExpr, pValue, arParams);
				break;
			default:
				ReportError(QERR_BAD_NAME, KeywordText((int)pExpr->Value.nValue), 1);
				break;
			}
			break;
			default:
				fprintf(stderr, "INTERNAL ERROR: unknown expression type %x\n", pExpr->nFlags);
				exit(1);
		}
		
		pValue->nQueryNumber = nQueryNumber;
		return(nDataType);
		
}
	/*
	* Routine: void EvalKeywordExpr(expr_t *pExpr, StringBuffer_t *pBuf)
	* Purpose: set the values to be used to replace a given tag for this query generation
	* Algorithm:
	* Data Structures:
	*
	* Params:
	* Returns:
	* Called By: 
	* Calls: 
	* Assumptions:
	* Side Effects:
	* TODO: 
	*/
	int
	EvalKeywordExpr(expr_t *pExpr, Expr_Val_t *pV)
	{		
		char szMessage[1024];
		char *cp;
		substitution_t *pSub;
		
		switch (pExpr->Value.nValue)
		{
		case KW_QUERY:
			pV->nValue = g_nQueryNumber;
			pV->bUseInt = 1;
			break;
		case KW_TEMPLATE:
			AddBuffer(pV->pBuf, GetBuffer(g_sbTemplateName));
			pV->bUseInt = 0;
			break;
		case KW_STREAM:
			pV->nValue = g_nStreamNumber;
			pV->bUseInt = 1;
			break;
		case KW_SALES:
			pV->nValue = DIST_SALES;
			pV->bUseInt = 1;
			break;
		case KW_RETURNS: 
			pV->nValue = DIST_RETURNS;
			pV->bUseInt = 1;
			break;
		case KW_UNIFORM:
			pV->nValue = DIST_UNIFORM;
			pV->bUseInt = 1;
			break;
		case KW_LIMIT:
			pV->nValue = atoi(GetBuffer(pExpr->Value.pBuf));
			pV->bUseInt = 1;
         break;
		case KW_LIMITA:
		case KW_LIMITB:
		case KW_LIMITC:
			sprintf(szMessage, "__LIMIT%c", (int)pExpr->Value.nValue - KW_LIMITA + 'A');
			pSub = findSubstitution(pCurrentQuery, szMessage, 0);
         EvalExpr(pSub->pAssignment, pV, 0, g_nQueryNumber);
         if (strlen(cp = GetBuffer(pV->pBuf)))
            {
            if (strchr(cp, '%'))
               {
               pSub = findSubstitution(pCurrentQuery, "_LIMIT", 0);
               sprintf(szMessage, GetBuffer(pV->pBuf), atoi(GetBuffer(pSub->pAssignment->Value.pBuf)));
               ResetBuffer(pV->pBuf);
               AddBuffer(pV->pBuf, szMessage);
               }
            }
			break;
		default:
			ReportError(QERR_SYNTAX, NULL, 1);
			break;
		}
		
		return((pV->bUseInt)?EXPR_FL_INT:EXPR_FL_CHAR);
	}
Example #16
0
LRESULT CALLBACK WatchWndProc(HWND hwnd, UINT iMessage, WPARAM wParam,
                              LPARAM lParam)
{
    WATCHDATA *ptr;
    static POINT menupos;
    static char buf[256];
    RECT r,  *pr;
    WINDOWPOS wp;
    HD_ITEM hie;
    HD_LAYOUT hdl;
    NMHDR *h;
    DRAWITEMSTRUCT *dr;
    HBITMAP hbmp;
    HDC hMemDC;
    TCHeader tch;
    TV_ITEM item;
    TV_INSERTSTRUCT t;
    static int sizingbottom;
    int offset;
    DEBUG_INFO *dbg;
    NM_TREEVIEW *nmt;
    VARINFO *var;
    HWND win;
    int level;
    int offset1;
    int doit;
    int i;
    CHARRANGE charrange;
    switch (iMessage)
    {
    case WM_SYSCOMMAND:
        if (wParam == SC_CLOSE)
        {
            PostMessage(hwnd, WM_CLOSE, 0, 0);
            return 0;
        }
        break;
    case WM_NOTIFY:
        ptr = (WATCHDATA *)GetWindowLong(hwnd, 0);
        h = (NMHDR*)lParam;
        switch (h->code)
        {
        case NM_RCLICK:
        {
            if (ptr->DID != DID_LOCALSWND)
            {
                HMENU menu = LoadMenuGeneric(hInstance, "WATCHMENU");
                HMENU popup = GetSubMenu(menu, 0);
                TV_HITTESTINFO t;
                HTREEITEM titem;
                GetCursorPos(&t.pt);
                ScreenToClient(ptr->hwndWatchTree, &t.pt);
                titem = TreeView_HitTest(ptr->hwndWatchTree, &t);
                if (!titem || TreeView_GetParent(ptr->hwndWatchTree, titem))
                {
                    EnableMenuItem(popup, IDM_DELETEWATCH, MF_GRAYED);
                }
                InsertBitmapsInMenu(popup);
                GetCursorPos(&menupos);
                TrackPopupMenuEx(popup, TPM_BOTTOMALIGN | TPM_LEFTBUTTON,
                                 menupos.x, menupos.y, hwndFrame, NULL);
                DestroyMenu(menu);
                lastWatch = ptr->DID;
            }
            SetFocus(ptr->hwndWatchTree);
        }
        return 0;
        case TVN_ITEMEXPANDING:
            nmt = (LPNMTREEVIEW)h;
            if (nmt->action)
            {
                ExpandPointer((VARINFO*)nmt->itemNew.lParam, nmt->action, ptr);
            }
            return 0;
        case TCN_EDITQUERY:
            nmt = (LPNMTREEVIEW)h;
            item.mask = TVIF_PARAM;
            item.hItem = (HTREEITEM)nmt->itemNew.hItem;
            TreeView_GetItem(ptr->hwndWatchTree, &item);
            var = (VARINFO*)item.lParam;
            if (var->editable)
            {
                WatchValue(ptr->watchinfo_list[var->watchindex].dbg_info, buf,
                           var, TRUE);
                return buf;
            }
            return 0;
        case TCN_EDITDONE:
            nmt = (LPNMTREEVIEW)h;
            item.mask = TVIF_PARAM;
            item.hItem = (HTREEITEM)nmt->itemNew.hItem;
            TreeView_GetItem(ptr->hwndWatchTree, &item);
            var = (VARINFO*)item.lParam;
            ChangeData(var, nmt->itemNew.pszText, ptr);
            RefreshItems(ptr);
            return 0;
        }
        break;
    case WM_CREATE:
        ptr = (WATCHDATA *)calloc(sizeof(WATCHDATA),1);
        SetWindowLong(hwnd, 0, (long)ptr);
        GetClientRect(hwnd, &r);
        tch.colText1 = "Item";
        tch.colText2 = "Value";
        tch.colBmp1 = itemBitmap;
        tch.colBmp2 = valueBitmap;
        ptr->hwndWatchTree = CreateextTreeWindow(hwnd, WS_DLGFRAME | TCS_LINE | WS_VISIBLE, &r, &tch);
        return 0;
    case WM_ADDWATCHINDIRECT:
        ptr = (WATCHDATA *)GetWindowLong(hwnd, 0);
        win = (HWND)wParam;
        doit = FALSE;
        SendMessage(win, EM_EXGETSEL, (WPARAM)0, (LPARAM) &charrange);
        if (charrange.cpMin == charrange.cpMax)
        {
            doit = SendMessage(win, WM_WORDUNDERPOINT, (WPARAM)&rightclickPos, (LPARAM)buf);
            if (!doit)
            {
                PostMessage(hwndFrame, WM_COMMAND, IDM_ADDWATCH, 0);
                break;
            }
        }
        else
        {
            if (charrange.cpMax - charrange.cpMin < sizeof(buf) ||charrange.cpMin - charrange.cpMax < sizeof(buf))
            {
                SendMessage(win, EM_GETSELTEXT, 0, (LPARAM)buf);
                doit = TRUE ;
            }
        }
        if (doit)
        {
            var = EvalExpr(&dbg, activeScope, (char*) buf, TRUE);
            if (var)
            {
                AddItem(dbg, var, activeScope->address, ptr);
                SelectWindow(ptr->DID);
                break ;
            }
        }
        ExtendedMessageBox("Error", MB_SETFOREGROUND |
                           MB_SYSTEMMODAL, "Symbol does not exist in this scope");
        break;
    case WM_ADDWATCH:
        ptr = (WATCHDATA *)GetWindowLong(hwnd, 0);
        offset = wParam;
        if (!offset)
        {
            DeleteAllItems(ptr);
        }
        else
        {
            var = EvalExpr(&dbg, activeScope, (char*)
                           lParam, TRUE);
            if (var)
            {
                AddItem(dbg, var, activeScope->address, ptr);
                SelectWindow(ptr->DID);
            }
        }
        break;
    case WM_INITIALSTACK:
        ptr = (WATCHDATA *)GetWindowLong(hwnd, 0);
        ptr->refreshNeeded = TRUE;
        break;
    case WM_COMMAND:
        ptr = (WATCHDATA *)GetWindowLong(hwnd, 0);
        switch (wParam)
        {
        case ID_SETADDRESS:
            if (ptr->DID == DID_LOCALSWND)
                LoadLocals(ptr);
            if (ptr->refreshNeeded)
                ReloadVars(ptr);
            else
                RefreshItems(ptr);
            ptr->refreshNeeded = FALSE;
            InvalidateRect(ptr->hwndWatchTree, 0, 0);
            break;
        case IDM_DELETEWATCH:
            DeleteItem(&menupos, ptr);
            break;
        case IDM_DELETEALLWATCH:
            DeleteAllItems(ptr);
            break;
        }
        break;
    case WM_DESTROY:
        ptr = (WATCHDATA *)GetWindowLong(hwnd, 0);
        TreeView_DeleteAllItems(ptr->hwndWatchTree);
        DestroyWindow(ptr->hwndWatchTree);
        DeleteObject(valueBitmap);
        DeleteObject(itemBitmap);
        break;

    case WM_SIZE:
        ptr = (WATCHDATA *)GetWindowLong(hwnd, 0);
        r.left = 0;
        r.right = LOWORD(lParam);
        r.top = 0;
        r.bottom = HIWORD(lParam);
        MoveWindow(ptr->hwndWatchTree, r.left, r.top, r.right - r.left, r.bottom -
                   r.top, 0);
        return 0;
    case WM_CLOSE:
        break;
    case WM_ACTIVATEME:
        ptr = (WATCHDATA *)GetWindowLong(hwnd, 0);
        if (ptr->DID != DID_LOCALSWND)
            lastWatch = ptr->DID;
        SendMessage(GetParent(hwnd), WM_ACTIVATEME, 0, 0);
        break;
    }
    return DefWindowProc(hwnd, iMessage, wParam, lParam);
}
Example #17
0
void NormalExpr( void )
{
    EvalExpr( 1 );
}
Example #18
0
static int DoCalRem(ParsePtr p, int col)
{
    int oldLen;
    Trigger trig;
    TimeTrig tim;
    Value v;
    int r, err;
    int jul;
    CalEntry *CurCol = CalColumn[col];
    CalEntry *e;
    char const *s, *s2;
    DynamicBuffer buf, obuf, pre_buf;
    Token tok;

    int is_color, col_r, col_g, col_b;

    is_color = 0;
    DBufInit(&buf);
    DBufInit(&pre_buf);

    /* Parse the trigger date and time */
    if ( (r=ParseRem(p, &trig, &tim, 1)) ) {
	FreeTrig(&trig);
	return r;
    }

/* Don't include timed reminders in calendar if -a option supplied. */
    if (DontIssueAts && tim.ttime != NO_TIME) {
	FreeTrig(&trig);
	return OK;
    }
    if (trig.typ == NO_TYPE) {
	FreeTrig(&trig);
	return E_EOLN;
    }
    if (trig.typ == SAT_TYPE) {
	r=DoSatRemind(&trig, &tim, p);
	if (r) {
	    FreeTrig(&trig);
	    if (r == E_EXPIRED) return OK;
	    return r;
	}
	if (!LastTrigValid) {
	    FreeTrig(&trig);
	    return OK;
	}
	r=ParseToken(p, &buf);
	if (r) {
	    FreeTrig(&trig);
	    return r;
	}
	FindToken(DBufValue(&buf), &tok);
	DBufFree(&buf);
	if (tok.type == T_Empty || tok.type == T_Comment) {
	    FreeTrig(&trig);
	    return OK;
	}
	if (tok.type != T_RemType || tok.val == SAT_TYPE) {
	    FreeTrig(&trig);
	    return E_PARSE_ERR;
	}
	if (tok.val == PASSTHRU_TYPE) {
	    r=ParseToken(p, &buf);
	    if (r) return r;
	    if (!DBufLen(&buf)) {
		DBufFree(&buf);
		FreeTrig(&trig);
		return E_EOLN;
	    }
	    StrnCpy(trig.passthru, DBufValue(&buf), PASSTHRU_LEN);
	    DBufFree(&buf);
	}
	trig.typ = tok.val;
	jul = LastTriggerDate;
	if (!LastTrigValid) {
	    FreeTrig(&trig);
	    return OK;
	}
    } else {
	/* Calculate the trigger date */
	jul = ComputeTrigger(trig.scanfrom, &trig, &r, 1);
	if (r) {
	    FreeTrig(&trig);
	    return r;
	}
    }

    /* Convert PS and PSF to PASSTHRU */
    if (trig.typ == PS_TYPE) {
	strcpy(trig.passthru, "PostScript");
	trig.typ = PASSTHRU_TYPE;
    } else if (trig.typ == PSF_TYPE) {
	strcpy(trig.passthru, "PSFile");
	trig.typ = PASSTHRU_TYPE;
    }
    if (trig.typ == PASSTHRU_TYPE) {
	if (!PsCal && strcmp(trig.passthru, "COLOR") && strcmp(trig.passthru, "COLOUR")) {
	    FreeTrig(&trig);
	    return OK;
	}
	if (!strcmp(trig.passthru, "COLOR") ||
	    !strcmp(trig.passthru, "COLOUR")) {
	    is_color = 1;
	    /* Strip off the three color numbers */
	    DBufFree(&buf);
	    r=ParseToken(p, &buf);
	    DBufPuts(&pre_buf, DBufValue(&buf));
	    DBufPutc(&pre_buf, ' ');
	    DBufFree(&buf);
	    if (r) {
		FreeTrig(&trig);
		return r;
	    }
	    r=ParseToken(p, &buf);
	    DBufPuts(&pre_buf, DBufValue(&buf));
	    DBufPutc(&pre_buf, ' ');
	    DBufFree(&buf);
	    if (r) {
		FreeTrig(&trig);
		return r;
	    }
	    r=ParseToken(p, &buf);
	    DBufPuts(&pre_buf, DBufValue(&buf));
	    DBufPutc(&pre_buf, ' ');
	    DBufFree(&buf);
	    if (r) {
		FreeTrig(&trig);
		return r;
	    }
	    (void) sscanf(DBufValue(&pre_buf), "%d %d %d",
			  &col_r, &col_g, &col_b);
	    if (col_r < 0) col_r = 0;
	    else if (col_r > 255) col_r = 255;
	    if (col_g < 0) col_g = 0;
	    else if (col_g > 255) col_g = 255;
	    if (col_b < 0) col_b = 0;
	    else if (col_b > 255) col_b = 255;
	    if (!PsCal && !DoSimpleCalendar) {
		DBufFree(&pre_buf);
	    }
	}
    }

    /* If trigger date == today, add it to the current entry */
    DBufInit(&obuf);
    if ((jul == JulianToday) ||
	(DoSimpleCalDelta &&
	 ShouldTriggerReminder(&trig, &tim, jul, &err))) {
	NumTriggered++;

	if (DoSimpleCalendar || tim.ttime != NO_TIME) {
	    /* Suppress time if it's not today or if it's a non-COLOR special */
	    if (jul != JulianToday ||
		(trig.typ == PASSTHRU_TYPE &&
		 strcmp(trig.passthru, "COLOUR") &&
		 strcmp(trig.passthru, "COLOR"))) {
		if (DBufPuts(&obuf, SimpleTime(NO_TIME)) != OK) {
		    DBufFree(&obuf);
		    DBufFree(&pre_buf);
		    FreeTrig(&trig);
		    return E_NO_MEM;
		}
	    } else {
		if (DBufPuts(&obuf, CalendarTime(tim.ttime, tim.duration)) != OK) {
		    DBufFree(&obuf);
		    DBufFree(&pre_buf);
		    FreeTrig(&trig);
		    return E_NO_MEM;
		}
	    }
	}
	if (trig.typ != PASSTHRU_TYPE &&
	    UserFuncExists("calprefix")==1) {
	    char evalBuf[64];
	    sprintf(evalBuf, "calprefix(%d)", trig.priority);
	    s2 = evalBuf;
	    r = EvalExpr(&s2, &v, NULL);
	    if (!r) {
		if (!DoCoerce(STR_TYPE, &v)) {
		    if (DBufPuts(&obuf, v.v.str) != OK) {
			DestroyValue(v);
			DBufFree(&obuf);
			DBufFree(&pre_buf);
			FreeTrig(&trig);
			return E_NO_MEM;
		    }
		}
		DestroyValue(v);
	    }
	}
	oldLen = DBufLen(&obuf);

	/* In -sa mode, run in ADVANCE mode if we're triggering
	 * before the actual date */
	if (jul != JulianToday) {
	    r = DoSubst(p, &obuf, &trig, &tim, jul, ADVANCE_MODE);
	} else {
	    r = DoSubst(p, &obuf, &trig, &tim, jul, CAL_MODE);
	}
	if (r) {
	    DBufFree(&pre_buf);
	    DBufFree(&obuf);
	    FreeTrig(&trig);
	    return r;
	}
	if (DBufLen(&obuf) <= oldLen) {
	    DBufFree(&obuf);
	    DBufFree(&pre_buf);
	    FreeTrig(&trig);
	    return OK;
	}
	if (trig.typ != PASSTHRU_TYPE &&
	    UserFuncExists("calsuffix")==1) {
	    char evalBuf[64];
	    sprintf(evalBuf, "calsuffix(%d)", trig.priority);
	    s2 = evalBuf;
	    r = EvalExpr(&s2, &v, NULL);
	    if (!r) {
		if (!DoCoerce(STR_TYPE, &v)) {
		    if (DBufPuts(&obuf, v.v.str) != OK) {
			DestroyValue(v);
			DBufFree(&obuf);
			DBufFree(&pre_buf);
			FreeTrig(&trig);
			return E_NO_MEM;
		    }
		}
		DestroyValue(v);
	    }
	}
	s = DBufValue(&obuf);
	if (!DoSimpleCalendar) while (isempty(*s)) s++;
	DBufPuts(&pre_buf, s);
	s = DBufValue(&pre_buf);
	e = NEW(CalEntry);
	if (!e) {
	    DBufFree(&obuf);
	    DBufFree(&pre_buf);
	    FreeTrig(&trig);
	    return E_NO_MEM;
	}
#ifdef REM_USE_WCHAR
	e->wc_pos = NULL;
	e->wc_text = NULL;
#endif
	e->is_color = is_color;
	e->r = col_r;
	e->g = col_g;
	e->b = col_b;
	e->text = StrDup(s);
	DBufFree(&obuf);
	DBufFree(&pre_buf);
	if (!e->text) {
	    free(e);
	    FreeTrig(&trig);
	    return E_NO_MEM;
	}
	make_wchar_versions(e);
	DBufInit(&(e->tags));
	DBufPuts(&(e->tags), DBufValue(&(trig.tags)));
	if (SynthesizeTags) {
	    AppendTag(&(e->tags), SynthesizeTag());
	}

	/* Don't need tags any more */
	FreeTrig(&trig);
	e->duration = tim.duration;
	e->priority = trig.priority;
	e->filename = StrDup(FileName);
	if(!e->filename) {
	    free(e);
	    return E_NO_MEM;
	}
	e->lineno = LineNo;

	if (trig.typ == PASSTHRU_TYPE) {
	    StrnCpy(e->passthru, trig.passthru, PASSTHRU_LEN);
	} else {
	    e->passthru[0] = 0;
	}
	e->pos = e->text;
	if (jul == JulianToday) {
	    e->time = tim.ttime;
	} else {
	    e->time = NO_TIME;
	}
	e->next = CurCol;
	CalColumn[col] = e;
	SortCol(&CalColumn[col]);
    }
    return OK;
}