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

📄 convert.cpp

📁 空战游戏flacon源码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	DescHeadKeep   = (char *)Deschead;
	ttlentity      += ( 2*sizeof(short) );
	ttldesctxt     = 0;

	token = trdata;
	token = strtok( NULL, backn );
	/* While there are tokens in "string" */
	while ( token ) {
		if (strncmp( token,"END_TEXT",8 )) {
			/* Not End Text yet, Copy token & Get next token */
			DescTxtptr = new TextString;
			DescPtrKeep[curdesidx] = (char *)DescTxtptr;
			ttlentity  += ( sizeof(short) );

			len = strlen( token );
			if ( len == 1 ) len++;
			DescTxtptr->length = len;
			DescChildTxt       = new char[len];
			DescChildKeep[curdesidx] = DescChildTxt;
			tptr = DescChildTxt;
			for ( i=0;i < len-1;i++ ) {
				*tptr = token[i];
				tptr++;
			}
			*tptr      = '\0';
			ttlentity  += len;
			ttldesctxt += len+sizeof(short);
			curdesidx++;

			token = strtok( NULL, backn );
			if ( token ) newlnptr = token;
		}
		else { // End of Text block found
			// Get some values here
			trdata      = token+strlen(token)+1;
			trdata      = GetALine( trdata,backn );	// ZoomAdjust
			lZoomAdjust = Text2Short( trdata );
			Entityptr->ZoomAdjust = lZoomAdjust;

			trdata    = nextdata;
			trdata    = GetALine( trdata,backn );	// Vert Offset
			lVertical = Text2Short( trdata );
			Entityptr->VerticalOffset = lVertical;

			trdata = nextdata;
			trdata = GetALine( trdata,backn );	// Horiz Offset
			lHoriz = Text2Short( trdata );
			Entityptr->HorizontalOffset = lHoriz;

			trdata   = nextdata;
			trdata   = GetALine( trdata,backn );	// MissileFlag
			lMissile = Text2Short( trdata );
			Entityptr->MissileFlag = lMissile;

			ttlentity += ( 4*sizeof(short) );
			trdata    = nextdata;
			trdata    = GetALine( trdata,backn );	// Photo fname
			len       = strlen( trdata );
			tptr      = (char *)&Entityptr->PhotoFile[0];
			for ( i=0;i < len-1;i++ ) {
				*tptr = trdata[i];
				tptr++;
			}
			*tptr          = '\0';
			ttlentity      += 32;	// fix length
			Deschead->size = ttldesctxt;
			break;
		}
	}
}

// Process End Text token
void DoEndText()
{
	where = _ENDTEXT_;
	Stringhead->size = ttltxt;
	if ( Stringhead ) delete Stringhead; Stringhead = NULL;
	if ( Txtptr )     delete Txtptr; Txtptr = NULL;
}

// Process Begin Rwr token
void DoBegRwr()
{
	short lSearchSymbol,lLockSymbol;
	short len,i;
	long  lSearchTone,lLockTone;
	char  *tptr;

	where   = _RWR_DATA_;
	Rwrhead = new Header;
	RwrHeadKeep[currwridx] = (char *)Rwrhead;
	Rwrptr  = new RWR_Data;
	RwrPtrKeep[currwridx]  = (char *)Rwrptr;

	Rwrhead->type = tokmap[toktype];
	trdata = nextdata;
	trdata = GetALine( trdata,backn );	// RWRNAME
	len    = strlen( trdata );
	tptr   = (char *)&Rwrptr->Name[0];
	for ( i=0;i < len-1;i++ ) {
		*tptr = trdata[i];
		tptr++;
	}
	*tptr     = '\0';
	ttlentity += 32;	// fix length
	ttlrwr    += 32;

	trdata = nextdata;
	trdata = GetALine( trdata,backn );	// SearchSymbol
	lSearchSymbol       = Text2Short( trdata );
	Rwrptr->SearchState = lSearchSymbol;
	ttlentity += (sizeof(short));
	ttlrwr    += (sizeof(short));

	trdata = nextdata;
	trdata = GetALine( trdata,backn );	// SearchTone
	lSearchTone        = Text2Long( trdata );
	Rwrptr->SearchTone = lSearchTone;
	ttlentity += (sizeof(long));
	ttlrwr    += (sizeof(long));

	trdata = nextdata;
	trdata = GetALine( trdata,backn );	// LockSymbol
	lLockSymbol       = Text2Short( trdata );
	Rwrptr->LockState = lLockSymbol;
	ttlentity += (sizeof(short));
	ttlrwr    += (sizeof(short));

	trdata = nextdata;
	trdata = GetALine( trdata,backn );	// LockTone
	lLockTone        = Text2Long( trdata );
	Rwrptr->LockTone = lLockTone;
	ttlentity += (sizeof(long));
	ttlrwr    += (sizeof(long));
}

// Process End Rwr token
void DoEndRwr()
{
	where  = _ENDRWR_;
	Rwrhead->size = ttlrwr;
	currwridx++;	// ready 4 next memory
	ttlrwr = 0;	// current RWR total size
}

// Parse the tacref database file
void DoParse()
{
	char Prsdone;

	Prsdone = 0;
	while ( !Prsdone ) {
		trdata  = GetALine( trdata,backn );
		toktype = CheckToken( trdata );
		if ( toktype != -1 ) {
			(tokfunc[toktype])();
		}
		trdata = nextdata;
		if ( trdata >= endingdata ) {
			Prsdone = 1;
		}
	}
}

void InitVar()
{
	long i;

	ttlentity  = ttlstat = ttlcat = ttltxt = ttlrwr = 0;
	Enthead    = NULL;
	Entityptr  = NULL;
	Stathead   = NULL;
	Cathead    = NULL;
	Catptr     = NULL;
	Stringhead = NULL;
	Txtptr     = NULL;
	Rwrhead    = NULL;
	Rwrptr     = NULL;

	currwridx     = 0;
	InitRwrKeep ();
	curdesidx     = 0;
	DescHeadKeep  = NULL;
	InitDescKeep();
	curcatidx     = 0;
	ttlcatstrhead = 0;
	curintxtidx   = 0;
	InitCatKeep ();
	InitCatInTxtKeep();

	for (i = 0; i< MAXCATKEEPTXT; i++) {
		CatKeeptxt[i] = NULL;
	}
}

void InitRwrKeep()
{
	short i;

	for ( i = 0; i < MAXRWRKEEP; i++ ) {
		RwrHeadKeep[i] = NULL;
		RwrPtrKeep[i]  = NULL;
	}
}

void InitDescKeep()
{
	short i;

	for ( i = 0; i < MAXDESCKEEP; i++ ) {
		DescPtrKeep[i]   = NULL;
		DescChildKeep[i] = NULL;
	}
}

void InitCatKeep()
{
	short i;

	for ( i = 0; i < MAXCATKEEP; i++ ) {
		CatHeadKeep[i]     = NULL;
		CatPtrKeep[i]      = NULL;
		CatStrKeep[i]      = NULL;
		catintxtidxkeep[i] = 0;
	}
}

void InitCatInTxtKeep()
{
	short i,j;

	for ( j = 0; j < MAXCATKEEP; j++ ) {
		for ( i = 0; i < MAXINTXTKEEP; i++ ) {
			CatInTxtKeep[j][i]   = NULL;
			CatInChildKeep[j][i] = NULL;
		}
	}
}

// Write out An Entity chunk
void CreateBin()
{
	long  numwr;
	long  lnum;
	short snum,i,j,qty,k;
	char  *tcptr;
	char  tbuff[80];

// Entity Record
	numwr = 0;
	snum  = Enthead->type;
	numwr += _write( ofh, &snum, sizeof(short) );
	snum  = Enthead->size;
	numwr += _write( ofh, &snum, sizeof(short) );
	lnum  = Entityptr->GroupID;
	numwr += _write( ofh, &lnum, sizeof(long) );
	lnum  = Entityptr->SubGroupID;
	numwr += _write( ofh, &lnum, sizeof(long) );
	lnum  = Entityptr->EntityID;
	numwr += _write( ofh, &lnum, sizeof(long) );
	snum  = Entityptr->ModelID;
	numwr += _write( ofh, &snum, sizeof(short) );

	snum  = Entityptr->ZoomAdjust;
	numwr += _write( ofh, &snum, sizeof(short) );
	snum  = Entityptr->VerticalOffset;
	numwr += _write( ofh, &snum, sizeof(short) );
	snum  = Entityptr->HorizontalOffset;
	numwr += _write( ofh, &snum, sizeof(short) );
	snum  = Entityptr->MissileFlag;
	numwr += _write( ofh, &snum, sizeof(short) );

	for ( k = 0; k < 80; k++ ) tbuff[k] = '\0';
	tcptr = Entityptr->Name;
	strcpy( tbuff, tcptr );
	tcptr = tbuff;
	numwr += _write( ofh, tcptr,32 );	// fix length
	tcptr = Entityptr->PhotoFile;
	for ( k = 0; k < 80; k++ ) tbuff[k] = '\0';
	strcpy( tbuff, tcptr );
	tcptr = tbuff;
	numwr += _write( ofh, tcptr, 32 );	// fix length

// Statistics Record (only a header)
	snum  = ((struct Header *)Stathead)->type;
	numwr += _write( ofh, &snum, sizeof(short) );
	snum  = ((struct Header *)Stathead)->size;
	numwr += _write( ofh, &snum, sizeof(short) );
//
	// Category Record
	for ( i = 0; i < curcatidx; i++ ) {
		snum  = ((struct Header *)CatHeadKeep[i])->type;
		numwr += _write( ofh, &snum, sizeof(short) );
		snum  = ((struct Header *)CatHeadKeep[i])->size;
		numwr += _write( ofh, &snum, sizeof(short) );
		numwr = 0;
		tcptr = ((struct Category *)CatPtrKeep[i])->Name;
		for ( k = 0; k < 80; k++ ) tbuff[k] = '\0';
		strcpy( tbuff, tcptr );
		tcptr = tbuff;
		numwr += _write( ofh, tcptr, 40 );	// fix length

		// Category text
		snum  = ((struct Header *)CatStrKeep[i])->type;
		numwr += _write( ofh, &snum, sizeof(short) );
		snum  = ((struct Header *)CatStrKeep[i])->size;
		numwr += _write( ofh, &snum, sizeof(short) );
		qty   = (short) catintxtidxkeep[i];
		for ( j = 0; j < qty ; j++ ) {
			lnum  = ((struct Text4CatString *)CatInTxtKeep[i][j])->GroupID;
			numwr += _write( ofh, &lnum, sizeof(long) );
			lnum  = ((struct Text4CatString *)CatInTxtKeep[i][j])->SubGroupID;
			numwr += _write( ofh, &lnum, sizeof(long) );
			lnum  = ((struct Text4CatString *)CatInTxtKeep[i][j])->EntityID;
			numwr += _write( ofh, &lnum, sizeof(long) );


			snum  = ((struct Text4CatString *)CatInTxtKeep[i][j])->length;
			numwr += _write( ofh, &snum, sizeof(short) );
			tcptr = CatInChildKeep[i][j];
			if ( *tcptr == 0x0d ) {
				*tcptr = 0x0;
				numwr  += _write( ofh, tcptr, 2 );
			}
			else {
				numwr  += _write( ofh, tcptr, strlen(tcptr)+1 );
			}

		}
		if ( numwr != ((struct Header *)CatHeadKeep[i])->size)
		{	// just checking
			numwr += 10;
			numwr -= 10;
		}
	}

// Description Record (header... no data)
	snum  = ((struct Header *)DescHeadKeep)->type;
	numwr += _write( ofh, &snum, sizeof(short) );
	snum  = ((struct Header *)DescHeadKeep)->size;
	numwr += _write( ofh, &snum, sizeof(short) );

	// Description text
	for ( i = 0; i < curdesidx; i++ ) {
		// Description text
		snum  = ((struct TextString *)DescPtrKeep[i])->length;
		numwr += _write( ofh, &snum, sizeof(short) );
		tcptr = DescChildKeep[i];
		if ( *tcptr == 0x0d ) {
			*tcptr  = 0x0;
			numwr   += _write( ofh, tcptr, 2 );
		}
		else {
			numwr   += _write( ofh, tcptr, strlen(tcptr)+1 );
		}
	}
//
		snum  =_RWR_DATA_;
		numwr += _write( ofh, &snum, sizeof(short) );
		snum  = currwridx * sizeof(struct RWR_Data);	// can be 0 if no RWR data
		numwr += _write( ofh, &snum, sizeof(short) );
	// RWR Record
	for ( i = 0; i < currwridx; i++ ) {
		snum  = ((struct RWR_Data *)RwrPtrKeep[i])->SearchState;
		numwr += _write( ofh, &snum, sizeof(short) );
		snum  = ((struct RWR_Data *)RwrPtrKeep[i])->LockState;
		numwr += _write( ofh, &snum, sizeof(short) );
		lnum  = ((struct RWR_Data *)RwrPtrKeep[i])->SearchTone;
		numwr += _write( ofh, &lnum, sizeof(long) );
		lnum  = ((struct RWR_Data *)RwrPtrKeep[i])->LockTone;
		numwr += _write( ofh, &lnum, sizeof(long) );

		tcptr = ((struct RWR_Data *)RwrPtrKeep[i])->Name;
		for ( k = 0; k < 80; k++ ) tbuff[k] = '\0';
		strcpy( tbuff, tcptr );
		tcptr = tbuff;
		numwr += _write( ofh, tcptr, 32 );	// fix length
	}

	numwr = numwr;	// just checking
}

//void Conv2Bin()
void Conv2Bin(char *ifname,char *ofname)
{
//	char *ifname = "D:\\falcon4\\TOOLS\\tacref\\tacrefdb.txt";
//	char *ofname = "D:\\falcon4\\TOOLS\\tacref\\tacrefdb.bin";
	long bytesread;

	ifh = _open( ifname, _O_BINARY|_O_RDONLY );
	if( ifh == -1 ) {
		printf("Error: can't open input file (%s)\n",ifname);
		return;	// Error
	}
	//DrawText( gblhdc, "File Opened for Reading!", -1, &gblrect, DT_SINGLELINE);

	ofh = _open( ofname, _O_TRUNC|_O_CREAT|_O_BINARY|_O_WRONLY, _S_IREAD|_S_IWRITE );
	if( ofh == -1 ) {
		if ( ifh ) _close ( ifh );
		printf("Can't create output file (%s)\n",ofname);
		return;
	}

	// Get file length
	flen = _filelength( ifh );
	/* Allocate space for dumping database file  */
	trdata = NULL;
	trdata = (char *) malloc( flen );
	if( !trdata ) {
		// Error, printf( "Insufficient memory !\n" );
		if ( ifh ) _close ( ifh );
		if ( ofh ) _close ( ofh );
		return;
	}

	// reads in the database file
	if (( bytesread = (long) _read( ifh, trdata, flen )) <= 0 ) {
		// Error, perror( "Problem reading file" );
		if ( ifh )    _close ( ifh );
		if ( ofh )    _close ( ofh );
		if ( trdata ) { free( trdata ); trdata = NULL; }
		return;
	}

	startdata   = trdata;
	endingdata  = startdata+flen;

	trdata      = SkipJunk( trdata );
	startentity = trdata;
	InitVar();
	// Conversion
	DoParse();

	_close( ifh );
    _close( ofh );
	DrawText( gblhdc, "Both files are Closed !            ", -1, &gblrect, DT_SINGLELINE);

    free( startdata );
}

int WINAPI WinMain (HINSTANCE hInst, HINSTANCE hPrev, PSTR szCmdLine, int iCmdShow)
{
/*
	static     char szAppName[] = "convert";
	HWND       hwnd;
	MSG        msg;
	WNDCLASSEX wndclass;

	wndclass.cbSize        = sizeof(wndclass);
	wndclass.style         = CS_HREDRAW | CS_VREDRAW;
	wndclass.lpfnWndProc   = WinProc;
	wndclass.cbClsExtra    = 0;
	wndclass.cbWndExtra    = 0;
	wndclass.hInstance     = hInst;
	wndclass.hIcon         = LoadIcon (NULL,IDI_APPLICATION);
	wndclass.hCursor       = LoadCursor(NULL,IDC_ARROW);
	wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
	wndclass.lpszMenuName  = NULL;
	wndclass.lpszClassName = szAppName;
	wndclass.hIconSm       = LoadIcon(NULL,IDI_APPLICATION);

	RegisterClassEx(&wndclass);

	hwnd = CreateWindow(szAppName,
					   "Convert",
					   WS_OVERLAPPEDWINDOW,
					   CW_USEDEFAULT,
					   CW_USEDEFAULT,
					   CW_USEDEFAULT,
					   CW_USEDEFAULT,
					   NULL,
					   NULL,
					   hInst,
					   NULL);

	ShowWindow(hwnd,iCmdShow);
	UpdateWindow(hwnd);

// Reads in tac ref database file
*/
	char infile[MAX_PATH],outfile[MAX_PATH];
	char *token;
	long Error=0;
	
	token=strtok(szCmdLine," ");
	if(token)
	{
		strcpy(infile,token);
		token=strtok(NULL," ");
		if(token)
			strcpy(outfile,token);
		else
			Error=1;
	}
	else
		Error=1;

	printf("TACREF Database converter to binary tool - by Billy Sutyono\n");
	if(Error)
	{
		printf("Usage:  txt2bin   <input>  <output>\n\n");
		exit(0);
	}
//	Conv2Bin();
	Conv2Bin(infile,outfile);
/*
	while(GetMessage(&msg,NULL,0,0))
	{
		TranslateMessage(&msg);
		DispatchMessage(&msg);
	}
	return(msg.lParam);
*/
	return(0);
}
/*
LRESULT CALLBACK WinProc (HWND hwnd, UINT message,WPARAM wParam,LPARAM lParam)
{
	HDC         hdc;
	PAINTSTRUCT ps;
	RECT        rect;
	LRESULT     retval=1;

	switch(message)
	{
		case WM_CREATE:
			 return(0);
		case WM_SYSKEYDOWN:
		case WM_CHAR:
			 return(0);

		case WM_PAINT:
			 hdc=BeginPaint(hwnd,&ps);
			 GetClientRect(hwnd,&rect);

			 gblhdc  = hdc;
			 gblhwnd = hwnd;
			 gblrect = rect;

			 DrawText(hdc, "Begin reading file", -1, &rect, DT_SINGLELINE);
  
			 EndPaint(hwnd,&ps);
			 return(0);
		case WM_LBUTTONUP:

			 return(0);

		case WM_DESTROY:
			 PostQuitMessage(0);
			 return(0);
	}
	return(DefWindowProc(hwnd,message,wParam,lParam));
}
*/

⌨️ 快捷键说明

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