China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-06-21 11:34
中国DOS联盟论坛 » DOS开发编程 & 发展交流 (开发室) » The Terminator of DOS Interface Development View 94,128 Replies 290
Floor 286 Posted 2018-07-14 12:10 ·  中国 广东 深圳 电信
高级用户
★★
Credits 668
Posts 295
Joined 2005-07-26 00:00
20-year member
UID 41110
Gender Male
From 广东深圳
Status Offline
// The following file is the Foxpro.h file

#ifndef _FOXPRO_20110811_H_
#define _FOXPRO_20110811_H_

// Database header
struct FOXPRO_HEAD
{
BYTE byFlags;
BYTE byYear;
BYTE byMonth;
BYTE byDay;

DWORD dwRecordCount;
WORD wRecordAddress;
WORD wRecordLength;
DWORD dwReserve1;
DWORD dwReserve2;
DWORD dwReserve3;
DWORD dwReserve4;
DWORD dwReserve5;
};

// Database "field" attributes
struct FOXPRO_FIELDS
{
BYTE strName[10];
BYTE byFill;
BYTE byStyle;
DWORD dwDataAddress;
BYTE byLength;
BYTE byDotCount;
WORD wReserve1;
BYTE byFlags;
BYTE wsReserve[11];

};

// Database "class" definition
class CFoxpro
{
private:
BOOL m_bNew;
long m_lRecordPoint;
char m_strFile[256];
FOXPRO_HEAD m_FoxproHead;
FOXPRO_FIELDS m_FoxproFields;
FILE* m_pFile;
BYTE* m_pRecordBuf;
FOXPRO_FIELDS* m_pFoxproFields;
public:
// Create a new database
BOOL CreateFoxpro(const char*pStr);
// Open an existing database
BOOL OpenFoxpro(const char*pStr);
// Close the database
BOOL CloseFoxpro();
// Add a field
BOOL AddFields(const char* strName,BYTE byStyle,int nLength,int nDot);
// Get the "field" attributes of the specified column
FOXPRO_FIELDS* GetFoxproFields(int nIndex);
public:
// Get the number of columns
int GetFieldsCount() {return(m_FoxproHead.wRecordAddress-sizeof(FOXPRO_HEAD))/sizeof(FOXPRO_FIELDS);}
// Get the total number of records
long GetRecordCount() {return(m_FoxproHead.dwRecordCount);}
// Get the record address
long GetRecordAddress() {return((DWORD)m_FoxproHead.wRecordAddress);}
// Get the last modification date of the database - "month"
int GetMonth() {return((int)m_FoxproHead.byMonth);}
// Get the last modification date of the database - "day"
int GetDay() {return((int)m_FoxproHead.byDay);}
// Get the last modification date of the database - "year"
int GetYear() {return((int)1900+(DWORD)m_FoxproHead.byYear);}
// Get the length of the record
int GetRecordLength(){return((int)(DWORD)m_FoxproHead.wRecordLength);}
// Display database debugging information
void Debug();
public:
// Trim leading spaces of the specified string
static char* TrimLeft(char *pStr);
// Trim trailing spaces of the specified string
static char* TrimRight(char *pStr);

public:
// Set the string of the string type "field"
BOOL SetFieldsString(int nIndex, const char* pStr);
// Set the numeric value of the numeric type "field"
BOOL SetFieldsNumber(int nIndex,float fValue);
// Set the date value of the date type "field"
BOOL SetFieldsDate(int nIndex,int nYear,int nMonth,int nDay);
// Set the logical value of the logical type "field"
BOOL SetFieldsLogic(int nIndex,BOOL bLogic);
// Set the memo value of the memo type "field"
BOOL SetFieldsMemo(int nIndex, const char* pStr);

// Get the string of the string type "field"
BOOL GetFieldsString(int nIndex,char* pStr);
// Get the numeric value of the numeric type "field"
float GetFieldsNumber(int nIndex);
// Get the date value of the date type "field"
BOOL GetFieldsDate(int nIndex,int* pnYear,int* pnMonth,int* pnDay);
// Get the logical value of the logical type "field"
BOOL GetFieldsLogic(int nIndex);
// Get the memo value of the memo type "field"
BOOL GetFieldsMemo(int nIndex,char* pStr);

// Locate the record
BOOL Seek(long nIndex,int nMode);
// Determine if the database is already open
BOOL IsOpen();
// Refresh the database to disk
BOOL Flush();
// Add a new record
BOOL AddNew();
// Prepare to modify the current record
BOOL Edit();
// Make the current changes effective
BOOL Update();
// Insert a record in the current record
BOOL Insert();
// Delete the current record (with delete mark)
BOOL Delete();
// Delete the current record
BOOL DeleteEx();
// Delete records with delete criteria
BOOL Zap();
public:
void CoFoxpro();// Called by the constructor
// Constructor
CFoxpro();
// Constructor (open the specified database)
CFoxpro(char* strFile);
// Destructor
~CFoxpro();
};



#endif
Floor 287 Posted 2018-07-14 12:13 ·  中国 广东 深圳 电信
高级用户
★★
Credits 668
Posts 295
Joined 2005-07-26 00:00
20-year member
UID 41110
Gender Male
From 广东深圳
Status Offline
```cpp
// The following file is the Foxpro.Cpp file
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#include <dos.h>
#include <bios.h>
#include <dir.h>
#include <conio.h>
#include <string.h>
#include <sys\\stat.h>
#include <io.h>

#include "symbol2.h"
#include "Foxpro.h"


//#include <Myframe.h>

void CFoxpro::CoFoxpro()
{
m_bNew = FALSE;
m_lRecordPoint = 0;
m_pRecordBuf = NULL;
m_pFile = NULL;
m_pFoxproFields = NULL;
_fmemset(&m_FoxproHead ,0,sizeof(FOXPRO_HEAD));
_fmemset(&m_FoxproFields,0,sizeof(FOXPRO_FIELDS));
_fmemset(&m_strFile,0,256);
}

CFoxpro::CFoxpro()
{
this->CoFoxpro();
}

CFoxpro::CFoxpro(char* strFile)
{

this->CoFoxpro();
this->OpenFoxpro(strFile);
}

CFoxpro::~CFoxpro()
{
if (m_pFile != NULL)
{
fclose(m_pFile);
}
m_pFile = NULL;

DELETE(m_pRecordBuf);
DELETE(m_pFoxproFields);

}

void CFoxpro::Debug()
{
char buf;
if(!m_pRecordBuf) return;

int nFields = this->GetFieldsCount();
printf("\n-------------------------------------------------");
for(int i=0;i<nFields;i++)
{
m_FoxproFields = *(this->GetFoxproFields(i));

printf("\n%10s--",m_FoxproFields.strName);
if(m_FoxproFields.byStyle=='C')
{
this->GetFieldsString(i,buf);
this->TrimLeft(buf);
this->TrimRight(buf);
printf("%s",buf);
}
else if(m_FoxproFields.byStyle=='L')
{
BOOL bLogic = this->GetFieldsLogic(i);
printf("%d",bLogic);
}
else if(m_FoxproFields.byStyle=='D')
{
int nYear,nMonth,nDay;
this->GetFieldsDate(i,&nYear,&nMonth,&nDay);
printf("%04d-%02d-%02d",nYear,nMonth,nDay);
}
else if(m_FoxproFields.byStyle=='N')
{
float fValue = this->GetFieldsNumber(i);
if(m_FoxproFields.byDotCount==0) printf("%.0f",fValue);
else if(m_FoxproFields.byDotCount==1) printf("%.1f",fValue);
else if(m_FoxproFields.byDotCount==2) printf("%.2f",fValue);
else if(m_FoxproFields.byDotCount==3) printf("%.3f",fValue);
else if(m_FoxproFields.byDotCount==4) printf("%.4f",fValue);
else if(m_FoxproFields.byDotCount==5) printf("%.5f",fValue);
else printf("%.6f",fValue);

}
else if(m_FoxproFields.byStyle=='M')
{
}
if(i&& !(i%24))
{
getch();
}

}
}

BOOL CFoxpro::CreateFoxpro(const char *pStr)
{
if(m_pFile) return(FALSE);

m_pFile = NULL;

CoFoxpro();

int nFields = 0;

date mDate;
::getdate(&mDate);

m_FoxproHead.byFlags = 0x03;
m_FoxproHead.byDay = (BYTE)mDate.da_day;
m_FoxproHead.byMonth = (BYTE)mDate.da_mon;
m_FoxproHead.byYear = (BYTE)(WORD)(mDate.da_year-1900);
m_FoxproHead.dwRecordCount = 0x00;
m_FoxproHead.wRecordAddress = sizeof(FOXPRO_HEAD)+1;
m_FoxproHead.wRecordLength = 0x01;
m_FoxproHead.dwReserve1 = 0x00;
m_FoxproHead.dwReserve2 = 0x00;
m_FoxproHead.dwReserve3 = 0x00;
m_FoxproHead.dwReserve4 = 0x00;
m_FoxproHead.dwReserve5 = 0x00;

_fmemset(&m_FoxproFields.strName,0,10);
m_FoxproFields.byFill = 0;
m_FoxproFields.byStyle = (BYTE)'C';
m_FoxproFields.dwDataAddress = 0;
m_FoxproFields.byLength = 0;
m_FoxproFields.byDotCount = 0;
m_FoxproFields.wReserve1 = 0;
m_FoxproFields.byFlags = 0;
_fmemset(&m_FoxproFields.wsReserve,0,11);

if(!(m_pFile=fopen(pStr,"w+b")))
{
return(FALSE);
}

fwrite(&m_FoxproHead ,sizeof(FOXPRO_HEAD) ,1,m_pFile);
fwrite(&m_FoxproFields,sizeof(FOXPRO_FIELDS),nFields,m_pFile);
fwrite("\x0D",1,1,m_pFile);
fwrite("\x1A",1,1,m_pFile);

//File Name
_fstrcpy(m_strFile,pStr);
//Malloc RecordBuf
m_pRecordBuf = new BYTE;
_fmemset(m_pRecordBuf,0,this->GetRecordLength()+1024);
//Malloc Foxpro_Fields
m_pFoxproFields = new FOXPRO_FIELDS;
_fmemset(m_pFoxproFields,0,sizeof(FOXPRO_FIELDS)*(1+this->GetFieldsCount()));
//Fill FoxproFields
::fseek(m_pFile,sizeof(FOXPRO_HEAD),SEEK_SET);
nFields = this->GetFieldsCount();
for(int i=0;i<nFields;i++)
{
::fread(&m_pFoxproFields,sizeof(FOXPRO_FIELDS),1,m_pFile);
}
return(TRUE);
}


BOOL CFoxpro::OpenFoxpro(const char* pStr)
{
if (m_pFile != NULL)
{
return(FALSE);
}

CoFoxpro();

if (!(m_pFile = fopen(pStr,"r+b")))
{
return(FALSE);
}

long lFileLength = filelength(fileno(m_pFile));
if(lFileLength<1L*sizeof(FOXPRO_HEAD)+2)
{
::fclose(m_pFile);
m_pFile=NULL;
return(FALSE);
}

rewind(m_pFile);
fread(&m_FoxproHead ,sizeof(FOXPRO_HEAD) ,1,m_pFile);
//Flags
if(m_FoxproHead.byFlags!=0x03 && m_FoxproHead.byFlags!=0xF5)
{
::fclose(m_pFile);
m_pFile=NULL;
return(FALSE);
}

BYTE nCh=0;
fseek(m_pFile,-1,SEEK_END);
fread(&nCh,1,1,m_pFile);
// End Is 0x1A?
if(nCh!=0x1A)
{
fclose(m_pFile);
m_pFile=NULL;
return(FALSE);
}
//---------------------------
//File Name
_fstrcpy(m_strFile,pStr);
//Malloc Record Buffer
m_pRecordBuf = new BYTE;
if (m_pRecordBuf == NULL)
{
fclose(m_pFile);
m_pFile=NULL;

return (FALSE);
}
_fmemset(m_pRecordBuf,0,this->GetRecordLength()+1024);
//Malloc Foxpro_Fields
m_pFoxproFields = new FOXPRO_FIELDS;
if (m_pFoxproFields == NULL)
{
delete m_pRecordBuf;
m_pRecordBuf = NULL;

fclose(m_pFile);
m_pFile=NULL;

return (FALSE);
}

_fmemset(m_pFoxproFields,0,sizeof(FOXPRO_FIELDS)*(1+this->GetFieldsCount()));
//Fill FoxproFields
::fseek(m_pFile,sizeof(FOXPRO_HEAD),SEEK_SET);
int nFields = this->GetFieldsCount();
for(int i=0;i<nFields;i++)
{
::fread(&m_pFoxproFields,sizeof(FOXPRO_FIELDS),1,m_pFile);
}
return(TRUE);
}

BOOL CFoxpro::CloseFoxpro()
{
if (NULL != m_pFile)
{
fclose(m_pFile);
}
m_pFile = NULL;

DELETE(m_pRecordBuf);
DELETE(m_pFoxproFields);

return(TRUE);
}

BOOL CFoxpro::AddFields(const char* strName,BYTE byStyle,int nLength,int nDot)
{
if(!m_pFile) return(FALSE);

if(byStyle=='C') {nDot = 0;}
else if(byStyle=='N') {}
else if(byStyle=='D') {nLength = 8;nDot = 0;}
else if(byStyle=='L') {nLength=1;nDot =0;}
else if(byStyle=='M') {nLength = 10;nDot = 0;}
else {return(0);}

_fmemset(&m_FoxproFields,0,sizeof(FOXPRO_FIELDS));
//----------------------------------------------------
if(byStyle=='M')
{
m_FoxproHead.byFlags=0xF5;
fseek(m_pFile,0,SEEK_SET);
fwrite(&m_FoxproHead ,sizeof(FOXPRO_HEAD) ,1,m_pFile);
}
//Calc Fields
int nFields=(m_FoxproHead.wRecordAddress-sizeof(FOXPRO_HEAD))/sizeof(FOXPRO_FIELDS);
//Modify Head
date mDate;
::getdate(&mDate);
m_FoxproHead.byDay = (BYTE)mDate.da_day;
m_FoxproHead.byMonth = (BYTE)mDate.da_mon;
m_FoxproHead.byYear = (BYTE)(WORD)(mDate.da_year-1900);
m_FoxproHead.wRecordAddress+= sizeof(FOXPRO_FIELDS);
m_FoxproHead.wRecordLength += (WORD)nLength;
//Write Head Again
fseek(m_pFile,0,SEEK_SET);
fwrite(&m_FoxproHead,sizeof(FOXPRO_HEAD),1,m_pFile);
//
int nFieldsAddress = 1;
fseek(m_pFile,sizeof(FOXPRO_HEAD),SEEK_SET);
for(int i=0;i<nFields;i++)
{
::fread(&m_FoxproFields,sizeof(FOXPRO_FIELDS),1,m_pFile);
nFieldsAddress+=m_FoxproFields.byLength;
}
//Fill in Field
if (::_fstrlen(strName) < 10)
{
::_fstrcpy((char*)&m_FoxproFields.strName,(char*)strName);
}
else
{
::_fmemcpy((BYTE*)&m_FoxproFields.strName, (char*)strName,
Floor 288 Posted 2018-07-14 12:15 ·  中国 广东 深圳 电信
高级用户
★★
Credits 668
Posts 295
Joined 2005-07-26 00:00
20-year member
UID 41110
Gender Male
From 广东深圳
Status Offline
// Below is the Symbol2.h file

#ifndef _SYMBOL2_H_
#define _SYMBOL2_H_

#ifndef TRUE
#define TRUE 1
#endif
#ifndef FALSE
#define FALSE 0
#endif
#ifndef NULL
#define NULL 0
#endif



#define _fmemcpy memcpy
#define _fstrcpy strcpy
#define _fstricmp stricmp
#define _fstrcmp strcmp
#define _fstrlen strlen
#define _fmemset memset

#define farmalloc malloc
#define farfree free

#define pi 3.1415926
#define CONST_SINGLE_T 3.14159f
#define CONST_DOUBLE_T 3.14159265359

typedef char* LPCTSTR;
typedef void* LPVOID;
typedef int COLOR;
typedef int HANDLE;
typedef unsigned int WORD;
typedef unsigned char BYTE;
typedef int BOOL;
typedef unsigned long DWORD;
typedef DWORD SORT;
typedef int BOOL;
typedef unsigned int BOOLEN;
typedef int HWND;
typedef DWORD WPARAM;
typedef DWORD LPARAM;
typedef long LONG;
typedef long* LPLONG;
typedef void VOID;
typedef DWORD ULONG;
typedef float FLOAT;
typedef int INT;
typedef signed short SHORT;
typedef unsigned short USHORT;
typedef unsigned short WCHAR;



#define DELETE(a) {if ((a) != NULL) delete (a); (a) = NULL;}



#define MAX(a,b) ((a>b)?a:b)
#define MIN(a,b) ((a<b)?a:b)

#define SHIFT8(a) ((a)<<8)
#define SHIFT16(a) ((a)<<16)
#define LOBYTE(a) ((BYTE)((a)&0xFF))
#define HIBYTE(a) ((((DWORD)(a))>>8)&0xFF)
#define LOWORD(a) ((WORD)((WORD)(((DWORD)(a))&0xFFFFL)))
#define HIWORD(a) ((WORD)((((DWORD)(a))>>16)&0xFFFFL))


#endif

[ Last edited by firstsail on 2018-7-14 at 12:37 ]
Floor 289 Posted 2019-05-24 11:57 ·  中国 广东 深圳 电信
高级用户
★★
Credits 668
Posts 295
Joined 2005-07-26 00:00
20-year member
UID 41110
Gender Male
From 广东深圳
Status Offline
Recently, the U.S. government has suppressed and interfered in the cooperation between Google, Qualcomm and Chinese technology companies such as Huawei and DJI. Chinese enterprises in embedded scenarios were suddenly choked by foreign enterprises and foreign governments. Only then did the Chinese people gradually realize how important and urgent it is to master the self-developed embedded system in China.

The current WinSail real-time embedded system is currently a free downloadable software system, which can be downloaded on the webpage http://www.firstsail.com.cn/Software.html. It was launched to the market in 2004 and has passed 15 years of market tests so far. It has been successfully applied to various embedded fields and has been widely downloaded and used by various industries.
Floor 290 Posted 2019-12-13 09:13 ·  中国 广东 深圳 罗湖区 电信
高级用户
★★
Credits 668
Posts 295
Joined 2005-07-26 00:00
20-year member
UID 41110
Gender Male
From 广东深圳
Status Offline
Thank goodness. After I forgot my password, I'm very grateful to forum administrator Mr. wengierwu for helping me recover the password. Old users who forget their passwords can contact wengierwu@hotmail.com to request recovery.

[ Last edited by firstsail on 2019-12-13 at 09:15 ]
Floor 291 Posted 2020-02-17 12:02 ·  中国 广东 深圳 电信
高级用户
★★
Credits 668
Posts 295
Joined 2005-07-26 00:00
20-year member
UID 41110
Gender Male
From 广东深圳
Status Offline
7 years later, the download version is updated

http://www.firstsail.com.cn/Software.html
‹ Prev 1 18 19 20
Forum Jump: