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

📄 main.c

📁 在VC6环境下开发
💻 C
字号:
#include "eDbInit.h"


char *readline(char *zPrompt, FILE *in){
	char *zLine;
	int nLine;
	int n;
	int eol;


	if( zPrompt && *zPrompt ){
#ifdef WIN32
		printf("%s",zPrompt);
		fflush(stdout);
#else
		Uart_Printf("%s",zPrompt);
#endif
		
	}
	nLine = 100;
	zLine = eDbMalloc(nLine);
	if( zLine==0 ) return 0;
	n = 0;
	eol = 0;
	while( !eol ){
		if( n+100>nLine ){
			nLine = nLine*2 + 100;
			zLine = eDbRealloc(zLine, nLine);
			if( zLine==0 ) return 0;
		}
		if( fgets(&zLine[n], nLine - n, in)==0 ){
			if( n==0 ){
				eDbFree(zLine);
				return 0;
			}
			zLine[n] = 0;
			eol = 1;
			break;
		}
		while( zLine[n] ){ n++; }
		if( n>0 && zLine[n-1]=='\n' ){
			n--;
			zLine[n] = 0;
			eol = 1;
		}
	}
	zLine = eDbRealloc( zLine, n+1 );
	return zLine;
}

#ifdef WIN32

#include <time.h>
#include <sys/timeb.h>

FILE *fout = stdout;
FILE *fdebug = stdout;

void main(){
	eDb *db;
	int rc;
	char *Prompt = "\nPlease Input a SQL statement:";
	char *zPrompt = 0;
	char *zSql = 0;
	int bComment = 0;
	char *z = 0;
	FILE *fd = 0;

#ifdef _DEBUG
	const char *dbName= "e:\\test\\eDb.db";	
	const char *zSQLfile = "e:\\test\\sql.txt";
	const char *zOutFile = "e:\\test\\result.txt";
	const char *zDebug = "e:\\test\\debug.txt";
#else
	const char *dbName= "eDb.db";
	const char *zSQLfile = "sql.txt";
	const char *zOutFile = "result.txt";
	const char *zDebug = "debug.txt";
#endif

	struct _timeb tstart;
	struct _timeb tend;
	char *timeline;	
		
	fd = fopen(zSQLfile,"rt");
	if(fd == 0){
		fprintf(fout,"can't open file %s !\n",zSQLfile);
		fd = stdin;
		zPrompt = Prompt;
	}else{
		if(zOutFile){
			fout = fopen(zOutFile,"wt");
			if(fout == 0) fout = stdout;
		}
	}	
	if(zDebug){
		fdebug = fopen(zDebug,"wt");
		if(fout == 0) fdebug = stdout;
	}
	
	_ftime(&tstart);
	timeline = ctime(&(tstart.time));
	fprintf(fdebug,"The start time is %.19s.%hu %s\n", timeline, tstart.millitm, &timeline[20] );


#ifdef _MALLOC_H_
	mem_init();
#endif	

	eDbOpenDB(&db,dbName);

	while((z = readline(zPrompt,fd)) !=0){
		if(zSql) eDbFree(zSql);
		zSql = z;
		for(;*z && (*z== ' ' || *z== '\t' || *z== '\n');z++){}
		if(*z == '/'){
			if(*(z+1)== '/') continue;
			if(*(z+1)== '*'){
				bComment = 1;	
			}
		}
		if(bComment){
			for(;*z;z++){
				if(*z== '*' && *(z+1) == '/'){
					z +=2;
					bComment = 0;
					break;
				}
			}
			for(;*z && (*z== ' ' || *z== '\t' || *z== '\n');z++){}
			if(z == 0 || *z == 0) continue;
		}
		if(!bComment){
			rc = eDb_exec(db,z);
		}
		eDbFree(zSql);
		zSql = 0;
		fflush(fout);
		fflush(fdebug);
	}	

	fclose(fd);
	_ftime( &tend );
	timeline = ctime(&(tend.time));
	fprintf(fdebug,"\nThe end time is %.19s.%hu %s\n", timeline, tend.millitm, &timeline[20] );
	eDbGetPagerStat(db->pBt);

	eDbCloseDB(db);	

#ifdef _MALLOC_H_
	check_memory();
#endif	

	if(fout != stdout) fclose(fout);
	if(fdebug != stdout) fclose(fdebug);
}

#else	/*ucos*/

#include	"..\ucos-ii\includes.h"
FILE *fout = 0;
FILE *fdebug = 0;
void Main_Task(void *Id)
{	
	//extern void OSTimeDly(u32);
	eDb *db;
	int rc;	
	//char *z ="create table student(sname text,ssex char(2),sage int)";	
	//char *z ="create table student3(age integer)";
	//char *z1 ="insert into student3 VALUES(36)";
	//char *z ="insert into student2 VALUES('wmxing')";
	char *z = 0;
	const char *dbName= "eDb     db ";	
	
	char *zPrompt = "\nPlease Input a SQL statement:";
	char *zSql = 0;
	int bComment = 0;
	
	disp_fileInfo((char *)dbName);
	
	eDbOpenDB(&db,dbName);	
	
	while((z = readline(zPrompt,0)) !=0){
		if(zSql) eDbFree(zSql);
		zSql = z;
		for(;*z && (*z== ' ' || *z== '\t' || *z== '\n');z++){}
		if(*z == '/'){
			if(*(z+1)== '/') continue;
			if(*(z+1)== '*'){
				bComment = 1;	
			}
		}
		if(bComment){
			for(;*z;z++){
				if(*z== '*' && *(z+1) == '/'){
					z +=2;
					bComment = 0;
					break;
				}
			}
			for(;*z && (*z== ' ' || *z== '\t' || *z== '\n');z++){}
			if(z == 0 || *z == 0) continue;
		}
		if(!bComment){
			rc = eDb_exec(db,z);
		}
		eDbFree(zSql);
		zSql = 0;
	}
	
	//rc = eDb_exec(db,z);
	eDbCloseDB(db);
	
#ifdef _MALLOC_H_
	check_memory();
#endif	
	disp_fileInfo((char *)dbName);
	
}
void Main(){
	extern void ARMTargetInit(void);
	ARMTargetInit();
	mem_init();
	/* needed by uC/OS */
	OSInit();	
	initFileSys();	
	Uart_Printf("Start Runing EDB ...\n");
	Main_Task(0);
	Uart_Printf("Stop Runing EDB ...\n");
	for(;;){
	
	}
}

#endif

⌨️ 快捷键说明

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