📄 arwrbase.c
字号:
/*
Copyright (c) 2003, Dan Kranz and Arnold Rom
All rights reserved.
Redistribution and use in source and binary forms, with or
without modification, are permitted provided that the following
conditions are met:
* Redistributions of source code must retain the above
copyright notice, this list of conditions and the following
disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials
provided with the distribution.
* The names of its contributors may not be used to endorse or
promote products derived from this software without specific
prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdlib.h>
#include <stdio.h>
#include <io.h>
#include <string.h>
#include <roots.h>
/* ################################################################## */
/* write data base # */
/* # */
/* output: write base = 0 if data base was written # */
/* = error code otherwise # */
/* # */
/* input: pointer to DataBaseStructure # */
/* ################################################################## */
BYTE WriteBase(DataBase* db)
/* ---------------------------------------------------------------------------- */
{ /* WriteBase START */
/* ---------------------------------------------------------------------------- */
BYTE *stream;
char fspec[MAX_PATH];
static char tempBase[]="$temp",tempArx[]="$temp.arx";
long cpl,i,outputSize,k;
/* ---------------------------------------------------------------------------- */
/* delete old data base if nline==0 */
/* ---------------------------------------------------------------------------- */
if(!db->base.nline)
{
unlink(db->name);
unlink(strcat(strcpy(fspec,db->name),".bas"));
return 0;
}
/* ---------------------------------------------------------------------------- */
/* build and write the data base file */
/* ---------------------------------------------------------------------------- */
ExpandGeneric(BYTE,stream,(db->base.nline*db->base.cpl+5));
/* first 5 bytes contain: rflag(10101010) cpl nline */
stream[0]=0xaa;
stream[1]=(BYTE)(db->base.cpl%0x100);
stream[2]=(BYTE)(db->base.cpl/0x100);
stream[3]=(BYTE)(db->base.nline%0x100);
stream[4]=(BYTE)(db->base.nline/0x100);
/* append the actual data base */
memcpy(&stream[5],db->base.block,db->base.cpl*db->base.nline);
cpl=db->base.nline*db->base.cpl+5;
if(WriteBinFile(&stream,&cpl,tempBase))return 1;
free(stream);
/* ---------------------------------------------------------------------------- */
/* write the tables file */
/* ---------------------------------------------------------------------------- */
/* calulcate required outputSize */
outputSize=3; /* signature and nbtabs */
for(i=0;i<db->nbtabs;i++)
outputSize+=(5+db->arx[i].cpl*db->arx[i].nline);
ExpandGeneric(BYTE,stream,outputSize);
/* move arx file to stream */
stream[0]=0x55;
stream[1]=(BYTE)(db->nbtabs%0x100);
stream[2]=(BYTE)(db->nbtabs/0x100);
k=3;
for(i=0; i<db->nbtabs; i++)
{
stream[k++]=0xaa;
stream[k++]=(BYTE)(db->arx[i].cpl%0x100);
stream[k++]=(BYTE)(db->arx[i].cpl/0x100);
stream[k++]=(BYTE)(db->arx[i].nline%0x100);
stream[k++]=(BYTE)(db->arx[i].nline/0x100);
if(db->arx[i].cpl==0 || db->arx[i].nline == 0) continue;
memcpy(&stream[k],db->arx[i].block,db->arx[i].cpl*db->arx[i].nline);
k+=db->arx[i].cpl*db->arx[i].nline;
}
if(WriteBinFile(&stream,&outputSize,tempArx))return 1;
free(stream);
/* delete old base and replace with new one */
unlink(db->name);
unlink(strcat(strcpy(fspec,db->name),".bas"));
rename(tempBase,strcat(strcpy(fspec,db->name),".bas"));
rename(tempArx ,db->name);
return 0;
/* ---------------------------------------------------------------------------- */
} /* WriteBase END */
/* ---------------------------------------------------------------------------- */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -