⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 expproc.cpp

📁 一个通讯管理机的源代码。比较好用。推荐
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/***************************************************************************                          expproc.cpp  -  description                             -------------------    begin                : Thu Jan 17 2002    copyright            : (C) 2002 by     email                :  ***************************************************************************//*************************************************************************** *                                                                         * *   This program is free software; you can redistribute it and/or modify  * *   it under the terms of the GNU General Public License as published by  * *   the Free Software Foundation; either version 2 of the License, or     * *   (at your option) any later version.                                   * *                                                                         * ***************************************************************************//*  $Id: expproc.cpp,v 1.6 2001/01/13 20:20:53 dbryson Exp $    Xbase project source code    Copyright (C) 1997  Startech, Gary A. Kunkel       This library is free software; you can redistribute it and/or    modify it under the terms of the GNU Lesser General Public    License as published by the Free Software Foundation; either    version 2.1 of the License, or (at your option) any later version.    This library is distributed in the hope that it will be useful,    but WITHOUT ANY WARRANTY; without even the implied warranty of    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU    Lesser General Public License for more details.    You should have received a copy of the GNU Lesser General Public    License along with this library; if not, write to the Free Software    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA    Contact:      Mail:        Technology Associates, Inc.        XBase Project        1455 Deming Way #11        Sparks, NV 89434        USA      Email:        xbase@techass.com      See our website at:        xdb.sourceforge.net    V 1.0   10/10/97   - Initial release of software    V 1.5   1/2/97     - Added memo field support    V 1.6a  4/1/98     - Added expression support    V 1.7.1 5/25/98    - Enhanced expression support*/#ifdef __WIN32__#include "xbconfigw32.h"#else#include "xbconfig.h"#endif#include "xbase.h"#ifdef XB_EXPRESSIONS#include <ctype.h>#include <math.h>#include <string.h>#include "xbexcept.h"/*! \file expproc.cpp*//*************************************************************************///! Short description/*!  \param e*/xbExpNode * xbExpn::GetFirstTreeNode( xbExpNode * e ){   xbExpNode * WorkNode;   if( !e ) return e;   WorkNode = e;   while( WorkNode->Sibling1 )      WorkNode = WorkNode->Sibling1;   return WorkNode;}/*************************************************************************///! Short description/*!  \param Operand  \param Op1  \pamam Op2*/xbShort xbExpn::ValidOperation( char * Operand, char Op1, char Op2 ){   /*  Valid operation table       operator  Field1   Field2          operator Field1   Field2        **        N        N                 =        N        N        *         N        N                 =        C        C        /         N        N                 <>,#     N        N        +         N        N                 <>,#     C        C        +         C        C                 <=       N        N        -         N        N                 <=       C        C        -         C        C                 >=       N        N        <         N        N                 >=       C        C        <         C        C                         >         N        N        >         C        C    */   if( Operand[0] == '*' && Operand[1] == '*' && Op1 == 'N' && Op2 == 'N' )      return 1;   switch( Operand[0] ) {      case '*':       case '/':         if( Op1 == 'N' && Op2 == 'N' )             return 1;          else             return 0;      case '+':      case '-':      case '<':      case '>':      case '=':      case '#':      case '$': // added 3/26/00 dtb         if(( Op1 == 'N' && Op2 == 'N' ) || ( Op1 == 'C' && Op2 == 'C' ))             return 1;         else             return 0;                   case '.' : // logical operators, added 3/26/00 dtb         if((Operand[1] == 'A' || Operand[1] == 'N' || Operand[1] == 'O')) /* &&            (Op1 == 'N' && Op2 == 'N')) */            return 1;      return 0;      default:         return 0;   }}/*************************************************************************///! Short description/*!  \param e*/xbExpNode * xbExpn::GetNextTreeNode( xbExpNode * e ){   if( !e->Node ) return NULL;   /* sibling 1 && sibling 2 exists */   if( e == e->Node->Sibling1 && e->Node->Sibling2 )      return GetFirstTreeNode( e->Node->Sibling2 );   /* sibling2 && sibling3 exists */   else if( e == e->Node->Sibling2 && e->Node->Sibling3 )      return GetFirstTreeNode( e->Node->Sibling3 );   else      return e->Node;}/*************************************************************************///! Short description/*!  \param e*/xbShort xbExpn::ProcessExpression( xbExpNode * e ){   return ProcessExpression( e, 0 );}/*************************************************************************///! Short description/*!  \param Wtree  \param RecBufSw*/xbShort xbExpn::ProcessExpression( xbExpNode * Wtree, xbShort RecBufSw ){   xbExpNode * WorkNode;   xbShort rc = 0;   if( Wtree == 0 )      Wtree = Tree;   memset(WorkBuf, 0x00, WorkBufMaxLen+1 );   /* initialize the stack - free any expnodes */   while( GetStackDepth() > 0 ) {      WorkNode = (xbExpNode *) Pop();      if( !WorkNode->InTree )         delete WorkNode;   }      if(( WorkNode = GetFirstTreeNode( Wtree )) == NULL )     xb_error(XB_NO_DATA);   while( WorkNode ) {      Push( (void *) WorkNode );      if( WorkNode->Type == 'D' && WorkNode->dbf ) {         WorkNode->dbf->GetField( WorkNode->FieldNo, WorkNode->StringResult, RecBufSw );         if( WorkNode->dbf->GetFieldType( WorkNode->FieldNo ) == 'N' ||             WorkNode->dbf->GetFieldType( WorkNode->FieldNo ) == 'F' )            WorkNode->DoubResult = WorkNode->dbf->GetDoubleField( WorkNode->FieldNo, RecBufSw );      }      else if( WorkNode->Type == 'O' ) {         if(( rc = ProcessOperator( RecBufSw )) != XB_NO_ERROR )           return rc;      }      else if( WorkNode->Type == 'F' )         if(( rc = ProcessFunction( WorkNode->NodeText )) != XB_NO_ERROR )            return rc;      WorkNode = GetNextTreeNode( WorkNode );   }   if( GetStackDepth() != 1 )    /* should only have result left in stack */     xb_error(XB_PARSE_ERROR);   return XB_NO_ERROR;}/*************************************************************************///! Short description/*!  \param e*/char xbExpn::GetOperandType( xbExpNode * e ){   /* this routine returns         L - logical         N - Numeric         C - Character         0 - error   */   char WorkType;   if( e->Type == 'd' || e->Type == 'N' || e->Type == 'i' ) return 'N';   if( e->Type == 'l' ) return 'L';   if( e->Type == 's' ) return 'C';   if( e->Type == 'C' ) {      if(e->NodeText[0]=='-' || e->NodeText[0]=='+' ||          (isdigit(e->NodeText[0]) &&     !(e->NodeText[e->DataLen] == '\'' || e->NodeText[e->DataLen] == '"'))    )        return 'N';      else        return 'C';   }   else if( e->Type == 'D' && e->dbf ) {      WorkType = e->dbf->GetFieldType( e->FieldNo );      if( WorkType == 'C' ) return 'C';      else if( WorkType == 'F' || WorkType == 'N' ) return 'N';      else if( WorkType == 'L' ) return 'L';      else return 0;   }   else      return 0;}/*************************************************************************///! Short description/*!  \param RecBufSw*/xbShort xbExpn::ProcessOperator( xbShort RecBufSw ){   xbExpNode * WorkNode;   char Operator[6 /*3*/];  // changed for logical ops 3/26/00 dtb   char t;   if( GetStackDepth() < 3 )      xb_error(XB_PARSE_ERROR);   WorkNode = (xbExpNode *) Pop();   if( WorkNode->Len > 5 /*2*/) // changed for logical ops 3/26/00 dtb{//printf("WorkNode->Len = %d\n", WorkNode->Len);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -