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

📄 xbase.cpp

📁 一个通讯管理机的源代码。比较好用。推荐
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/***************************************************************************                          xbase.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: xbase.cpp,v 1.8 2000/11/10 19:04:17 dbryson Exp $    Xbase project source code    This file contains logic for the basic Xbase class.    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.6b  4/8/98     - Numeric index keys    V 1.7.1 5/25/98    - Big Endian support*/#ifdef __GNUG__  #pragma implementation "xbase.h"#endif#ifdef __WIN32__#include "xbconfigw32.h"#else#include "xbconfig.h"#endif#include "xbase.h"#include <ctype.h>#include <string>using namespace std;#include "xbexcept.h"/*! \file xbase.cpp*//*************************************************************************///! Constructor./*!*/xbXBase::xbXBase( void ){   xbShort e = 1;   EndianType = *(char *) &e;   if( EndianType )      EndianType = 'L';   else      EndianType = 'B';   DbfList = NULL;   FreeDbfList = NULL;}/*************************************************************************///! Get pointer to named dbf./*!  Looks up an open DBF file by Name.    \param Name  \returns A pointer to the xbDbf class instance if found or NULL if    not found.*/xbDbf *xbXBase::GetDbfPtr(const char *Name) {  xbDbList *t;  t = DbfList;  xbShort len = strlen(Name);  /* check for -> embedded in the name */  for( xbShort i = 0; i < (len-1); i++ )    if( Name[i] == '-' && Name[i+1] == '>' )      len = i-1;  while (t) {    if (strncmp(Name, t->DbfName, len) == 0 )      return t->dbf;    t = t->NextDbf;  }  return NULL;}/*************************************************************************///! Destructor./*!*/xbXBase::~xbXBase(){   xbDbList *i = FreeDbfList;   while (i) {      xbDbList *t = i->NextDbf;      if (i->DbfName) {         free(i->DbfName);      }      free(i);      i = t;   }}/*************************************************************************///! Add dbf to dbf list./*!  Adds an xbDbf class instance to the list of dbf's.    \param d the xbDbf instance to be added  \param DatabaseName name of the database    \returns One of the following return codes:    \htmlonly      <p>      <table border=2><tr><th>Return Code</th><th>Description</th></tr>        <tr><td>XB_NO_ERROR</td><td>No error</td></tr>        <tr><td>XB_NO_MEMORY</td><td>Out of memory</td></tr>      </table>    \endhtmlonly    \latexonly      \\      \\      \begin{tabular}{|l|l|} \hline        \textbf{Return Code} & \textbf{Description} \\ \hline \hline        XB\_NO\_ERROR & No Error \\ \hline        XB\_NO\_MEMORY & Out of memory \\ \hline      \end{tabular}    \endlatexonly*/xbShort xbXBase::AddDbfToDbfList(xbDbf *d, const char *DatabaseName) {   xbDbList *i, *s, *t;   if(!FreeDbfList) {      if((i = (xbDbList *)malloc(sizeof(xbDbList))) == NULL) {         xb_memory_error;      }   } else {      i = FreeDbfList;      FreeDbfList = i->NextDbf;   }   memset(i, 0x00, sizeof(xbDbList));   i->DbfName  = strdup(DatabaseName);   i->dbf      = d;   s = NULL;   t = DbfList;   while(t && strcmp(t->DbfName, DatabaseName) < 0) {      s = t;      t = t->NextDbf;   }   i->NextDbf = t;   if (s == NULL)      DbfList = i;   else      s->NextDbf = i;         return 0;}/***********************************************************************///!  Remove dbf from dbf list./*!  Removes the specified xbDbf class instance from the list of dbf's.    \param d xbDbf to be removed    \returns One of the following return codes:    \htmlonly      <p>      <table border=2><tr><th>Return Code</th><th>Description</th></tr>        <tr><td>XB_NO_ERROR</td><td>No error</td></tr>      </table>    \endhtmlonly    \latexonly      \\      \\      \begin{tabular}{|l|l|} \hline        \textbf{Return Code} & \textbf{Description} \\ \hline \hline        XB\_NO\_ERROR & No Error \\ \hline      \end{tabular}    \endlatexonly*/xbShort xbXBase::RemoveDbfFromDbfList(xbDbf *d) {   xbDbList *i, *s;   i = DbfList;   s = NULL;   while (i) {      if(i->dbf == d) {         /* remove it from current chain */         if(s)            s->NextDbf = i->NextDbf;         else            DbfList = i->NextDbf;         /* add i to the current free chain */         i->NextDbf = FreeDbfList;         FreeDbfList = i;         free(FreeDbfList->DbfName);         FreeDbfList->DbfName = NULL;         FreeDbfList->NextDbf = NULL;          break;      } else {         s = i;         i = i->NextDbf;      }   }   return XB_NO_ERROR;} // FIXME: byte reverse methods are awful, compared to bitwise shifts  -- willy/************************************************************************///! Get a portable short value./*!  Converts a short (16 bit integer) value stored at p from a portable   format to the machine format.    \param p pointer to memory containing the portable short value    \returns the short value.*//* This routine returns a short value from a 2 byte character stream */xbShort xbXBase::GetShort(const char *p) {   xbShort s, i;   const char *sp;   char *tp;   s = 0;   tp = (char *) &s;   sp = p;   if( EndianType == 'L' )      for( i = 0; i < 2; i++ ) *tp++ = *sp++;   else   {      sp++;      for( i = 0; i < 2; i++ ) *tp++ = *sp--;   }     return s;}//! Get a portable long value./*!  Converts a long (32 bit integer) value stored at p from a portable   format to the machine format.    \param p pointer to memory containing the portable long value    \returns the long value.*//* This routine returns a long value from a 4 byte character stream */xbLong xbXBase::GetLong( const char *p ){   xbLong l;   const char *sp;   char *tp;   xbShort i;   tp = (char *) &l;   sp = p;   if( EndianType == 'L' )      for( i = 0; i < 4; i++ ) *tp++ = *sp++;   else   {      sp+=3;      for( i = 0; i < 4; i++ )  *tp++ = *sp--;   }     return l;}//! Get a portable unsigned long value./*!  Converts an unsigned long (32 bit integer) value stored at p from a portable   format to the machine format.    \param p pointer to memory containing the portable unsigned long value    \returns the unsigned long value.*//* This routine returns a long value from a 4 byte character stream */xbULong xbXBase::GetULong( const char *p ){  xbULong l;  char *tp;  xbShort i;    tp = (char *) &l;  if( EndianType == 'L' )    for( i = 0; i < 4; i++ ) *tp++ = *p++;  else{

⌨️ 快捷键说明

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