📄 compile.h
字号:
if(stricmp(token,file_opened[k].filename)==0)
{
fp=file_opened[k].currentfp;
strcpy(token,"USE/");
strcat(token,file_opened[k].filename);
strcat(token,"/");
use(token);
err=0;
break;
}
}
if(err){throwerror(13);return lll;}
//////////////////////////////
i++;
if(i>=len){throwerror(1);return lll;}
j=0;
while(i<=len&&temp[i]!='/'){token[j]=temp[i];i++;j++;}
token[j]='\0';
// puts(token);
if(stricmp(token,"on")!=0){throwerror(1);return lll;}
//////////////////////////////////////////////////////
i++;
if(i>=len){throwerror(1);return lll;}
j=0;
while(i<=len&&temp[i]!='/'){token[j]=temp[i];i++;j++;}
token[j]='\0';
// puts(token);
to.fieldlenght=1;
strcpy(to.join[0].wordname,token);
i++;
while(i<=len)
{
if(temp[i]!=',')break;
i=i+2;
j=0;
while(i<=len&&temp[i]!='/'){token[j]=temp[i];i++;j++;}
token[j]='\0';
// puts(token);
for(k=0;k<to.fieldlenght;k++)
{
if(strcmp(token,to.join[k].wordname)==0)
{
throwerror(22);
return lll;
}
}
strcpy(to.join[to.fieldlenght].wordname,token);
to.fieldlenght++;
i++;
}
j=0;
while(i<=len&&temp[i]!='/'){token[j]=temp[i];i++;j++;}
token[j]='\0';
// puts(token);
if(stricmp(token,"to")!=0){throwerror(1);return lll;}
i++;
if(i>=len){throwerror(20);return lll;}
////////////////////////////////////file2
j=0;
while(i<=len&&temp[i]!='/'){token[j]=temp[i];i++;j++;}
token[j]='\0';
// puts(token);
if((f=fopen(token,"r"))!=NULL)
{
throwerror(4);
fclose(f);
return lll;
}
////////////////////////////////////////
for(j=0;j<to.fieldlenght;j++)
{
for(m=0;m<from.fieldlenght;m++)
{
// puts(to.join[j].wordname);
if(strcmp(to.join[j].wordname,from.join[m].wordname)==0)
{
to.join[j].locate=m;
to.join[j].key=from.join[m].key;
to.join[j].length=from.join[m].length;
to.join[j].typesign=from.join[m].typesign;
break;
}
}
if(m==from.fieldlenght){throwerror(17);return lll;}
}
////////////////////////////////////////
/*
*
*add write file
*
*/
if((f=fopen(token,"wb+"))==NULL)
{
throwerror(4);
fclose(f);
return lll;
}
putc(to.fieldlenght,f);
putc(from.lines,f);
for(i=0;i<128;i++)
fwrite(&(to.join[i]),LENGTH,1,f);
for(i=0;i<from.lines;i++)
{
for(j=0;j<to.fieldlenght;j++)
{
k=to.join[j].locate;
rewind(fp);
fseek(fp,2+128*LENGTH,0);
fseek(fp,(k+i*from.fieldlenght)*VALUE_LENGTH,1);
fread(&values[0],VALUE_LENGTH,1,fp);
fwrite(&values[0],VALUE_LENGTH,1,f);
}
}
fclose(f);
strcpy(temp,"OPEN/");
strcat(temp,token);
strcat(temp,"/,/w/");
lll=openrel(temp);
////////////////////////////////////////
return lll;
}
////////////////////////////////////////////////////
/*
* UPDATE Function 修改表元祖函数
*/
///////////////////////////////////////////////////
int update(char *temp)
{
int lll=1;
FILE *fp,*f;
int i=0,j=0,k=0,m=0,err=1,n;
int len=strlen(temp);
char token[20];
char ch;
int seeklocation1=-1;
seeklocation1=seeklocation;
// printf("%d\n",seeklocation);
///////////////////////////////////////////if opened
for(i=0;i<openfilenum;i++)
{
if(file_opened[i].station)
{
if(!file_opened[i].openstyle){throwerror(15);return lll;}
fp=file_opened[i].currentfp;
n=i;
err=0;
break;
}
}
if(err){throwerror(10);return lll;}
//////////////////////////////////backup
rewind(fp);
f=fopen("temp$$","wb+");
ch=fgetc(fp);
while(ch!=EOF)
{
fputc(ch,f);
ch=fgetc(fp);
}
fclose(f);
//////////////////////////////////backupend
//////////////////////////////////////////if opened end
//////////////////////////////////////////update begin
i=7;
if(i>=len){throwerror(20);return lll;}
j=0;
while(i<=len&&temp[i]!='/'){token[j]=temp[i];i++;j++;}
token[j]='\0';
// puts(token);
to.fieldlenght=1;
strcpy(to.join[0].wordname,token);
i++;
if(i>=len){throwerror(1);return lll;}
if(temp[i]!='='){throwerror(1);return lll;}
i=i+2;
if(i>=len){throwerror(1);return lll;}
j=0;
while(i<=len&&temp[i]!='/'){token[j]=temp[i];i++;j++;}
token[j]='\0';
// puts(token);
/*add if(legal)*/
strcpy(values[0].fieldvalue,token);
i++;
while(i<=len)
{
if(temp[i]!=',')break;
i=i+2;
j=0;
while(i<=len&&temp[i]!='/'){token[j]=temp[i];i++;j++;}
token[j]='\0';
// puts(token);
for(k=0;k<to.fieldlenght;k++)
{
if(strcmp(token,to.join[k].wordname)==0)
{
throwerror(22);
return lll;
}
}
strcpy(to.join[to.fieldlenght].wordname,token);
i++;
if(i>=len){throwerror(1);return lll;}
if(temp[i]!='='){throwerror(1);return lll;}
i=i+2;
if(i>=len){throwerror(1);return lll;}
j=0;
while(i<=len&&temp[i]!='/'){token[j]=temp[i];i++;j++;}
token[j]='\0';
// puts(token);
strcpy(values[to.fieldlenght].fieldvalue,token);
to.fieldlenght++;
i++;
}
//////////////////////////////////////////update end
for(j=0;j<to.fieldlenght;j++)
{
for(m=0;m<from.fieldlenght;m++)
{
// puts(to.join[j].wordname);
if(strcmp(to.join[j].wordname,from.join[m].wordname)==0)
{
to.join[j].locate=m;
break;
}
}
if(m==from.fieldlenght){throwerror(17);return lll;}
}
if(i>=len)
{
if(seeklocation1==-1)
{
throwerror(18);
return lll;
}
f=fopen("temp$","wb+");
rewind(fp);
fputc(fgetc(fp),f);
fputc(fgetc(fp),f);
for(j=0;j<128;j++)
{
fread(&(from.join[j]),LENGTH,1,fp);
fwrite(&(from.join[j]),LENGTH,1,f);
}
for(i=0;i<from.lines;i++)
{
if(i==(seeklocation1-1))
{
for(j=0;j<from.fieldlenght;j++)
{
fread(&values[to.fieldlenght+j],VALUE_LENGTH,1,fp);
}
for(j=0;j<to.fieldlenght;j++)
{
k=to.join[j].locate;
strcpy(values[to.fieldlenght+k].fieldvalue,values[j].fieldvalue);
}
for(j=0;j<from.fieldlenght;j++)
{
// puts(values[to.fieldlenght+j].fieldvalue);
fwrite(&values[to.fieldlenght+j],VALUE_LENGTH,1,f);
}
}
else
{
for(j=0;j<from.fieldlenght;j++)
{
fread(&values[to.fieldlenght],VALUE_LENGTH,1,fp);
fwrite(&values[to.fieldlenght],VALUE_LENGTH,1,f);
}
}
}
fclose(f);
fclose(fp);
fp=fopen(file_opened[n].filename,"wb+");
f=fopen("temp$","r");
ch=fgetc(f);
while(ch!=EOF)
{
fputc(ch,fp);
ch=fgetc(f);
}
fclose(f);
fclose(fp);
remove("temp$");
file_opened[n].currentfp=fopen(file_opened[n].filename,"ab+");
for(i=0;i<from.fieldlenght;i++)
{
lll=condition(from.join[i].key,i,file_opened[n].currentfp);
if(lll) break;
}
if(lll)
{
fp=fopen(file_opened[n].filename,"wb+");
f=fopen("temp$$","r");
ch=fgetc(f);
while(ch!=EOF)
{
fputc(ch,fp);
ch=fgetc(f);
}
fclose(f);
fclose(fp);
remove("temp$$");
file_opened[n].currentfp=fopen(file_opened[n].filename,"ab+");
throwerror(27);
}
seeklocation=-1;
}
else
{
j=0;
while(i<=len&&temp[i]!='/'){token[j]=temp[i];i++;j++;}
token[j]='\0';
// puts(token);
if(stricmp(token,"where")!=0){throwerror(1);return lll;}
i++;
if(i>=len){throwerror(21);return lll;}
j=0;
while(i<=len&&temp[i]!='/'){token[j]=temp[i];i++;j++;}
token[j]='\0';
// puts(token);
m=0;
for(k=0;k<from.fieldlenght;k++)
{
if(strcmp(token,from.join[k].wordname)==0)
{
m=1;
break;
}
}
if(!m){throwerror(17);return lll;}
i++;
if(i>=len){throwerror(1);return lll;}
if(temp[i]!='='){ throwerror(1);return lll;}
i=i+2;
if(i>=len){throwerror(1);return lll;}
j=0;
while(i<=len&&temp[i]!='/'){token[j]=temp[i];i++;j++;}
token[j]='\0';
// puts(token);
i++;
if(i<len){throwerror(23);return lll;}
///////////////////////////////////////
m=0;
i=0;
while(i<from.lines)
{
rewind(fp);
fseek(fp,2+128*LENGTH,0);
fseek(fp,(k+i*from.fieldlenght)*VALUE_LENGTH,1);
fread(&values[to.fieldlenght],VALUE_LENGTH,1,fp);
if(strcmp(token,values[to.fieldlenght].fieldvalue)==0)
{
m=1;
seeklocation=i+1;
strcpy(temp,"UPDATE/");
strcat(temp,to.join[0].wordname);
strcat(temp,"/=/");
strcat(temp,values[0].fieldvalue);
strcat(temp,"/");
for(j=1;j<to.fieldlenght;j++)
{
strcat(temp,",/");
strcat(temp,to.join[j].wordname);
strcat(temp,"/=/");
strcat(temp,values[j].fieldvalue);
strcat(temp,"/");
}
lll=update(temp);
i++;
}else
{
i++;
}
}
if(!m){throwerror(19);return lll;}
///////////////////////////////////////
}
return lll;
}
////////////////////////////////////////////////////
/*
* SELECT Function 查找表数据函数
*/
///////////////////////////////////////////////////
int select(char *temp)
{
int lll=1;
FILE *fp;
int i=0,j=0,k=0,m=0;
int jj,kk;
int all;
int len=strlen(temp);
int err=1;
int output=0;
char token[20];
//puts(temp);
if(len==7){
throwerror(20);
return lll;
}
i=7;
j=0;
while(i<=len&&temp[i]!='/'){token[j]=temp[i];i++;j++;}
token[j]='\0';
/// puts(token);
if(strcmp(token,"*")==0)
{all=1;i++;}/////////////select all
else
{
all=0;
to.fieldlenght=1;
strcpy(to.join[0].wordname,token);
i++;
while(i<=len)
{
if(temp[i]!=',')break;
i=i+2;
j=0;
while(i<=len&&temp[i]!='/'){token[j]=temp[i];i++;j++;}
token[j]='\0';
/// puts(token);
strcpy(to.join[to.fieldlenght].wordname,token);
to.fieldlenght++;
i++;
}
}
//////////////////////////
if(i>=len){throwerror(1);return lll;}
j=0;
while(i<=len&&temp[i]!='/'){token[j]=temp[i];i++;j++;}
token[j]='\0';
if(stricmp(token,"from")!=0){throwerror(1);return lll;}
///////////////////////
i++;
if(i>=len){throwerror(3);return lll;}
j=0;
while(i<=len&&temp[i]!='/'){token[j]=temp[i];i++;j++;}
token[j]='\0';
err=1;
for(k=0;k<openfilenum;k++)
{
if(stricmp(token,file_opened[k].filename)==0)
{
fp=file_opened[k].currentfp;
strcpy(token,"USE/");
strcat(token,file_opened[k].filename);
strcat(token,"/");
use(token);
err=0;
break;
}
}
if(err){throwerror(13);return lll;}
i++;
if(i>=len)
{
if(all)
{
rewind(fp);
from.fieldlenght=fgetc(fp);
from.lines=fgetc(fp);
for(j=0;j<from.fieldlenght;j++)
{
fread(&(from.join[j]),LENGTH,1,fp);
printf("%20s",from.join[j].wordname);
}
printf("\n*");
for(j=0;j<from.fieldlenght;j++) printf("--------------------");
printf("*\n");
fseek(fp,128*LENGTH+2,0);
for(j=0;j<from.lines*from.fieldlenght;j++)
{
fread(&values[0],VALUE_LENGTH,1,fp);
printf("%20s",values[0].fieldvalue);
if((j+1)%from.fieldlenght==0)
{
printf("\n|");
for(m=0;m<from.fieldlenght;m++) printf("--------------------");
printf("|\n");
}
}
lll=0;
return lll;
}
else
{
for(j=0;j<to.fieldlenght;j++)
{
for(m=0;m<from.fieldlenght;m++)
{
// puts(to.join[j].wordname);
if(strcmp(to.join[j].wordname,from.join[m].wordname)==0)
{
to.join[j].locate=m;
break;
}
}
if(m==from.fieldlenght){throwerror(17);return lll;}
}
////////////
/*
*add output 2004/04/21/14:02
*/
for(j=0;j<to.fieldlenght;j++)
{
printf("%20s",to.join[j].wordname);
}
printf("\n*");
for(j=0;j<to.fieldlenght;j++) printf("--------------------");
printf("*\n");
for(i=0;i<from.lines;i++)
{
for(j=0;j<to.fieldlenght;j++)
{
k=to.join[j].locate;
rewind(fp);
fseek(fp,2+128*LENGTH,0);
fseek(fp,(k+i*from.fieldlenght)*VALUE_LENGTH,1);
fread(&values[0],VALUE_LENGTH,1,fp);
printf("%20s",values[0].fieldvalue);
if((j+1)%to.fieldlenght==0)
{
printf("\n|");
for(m=0;m<to.fieldlenght;m++) printf("--------------------");
printf("|\n");
}
}
}
////////////
}
}
else
{
//////////////save condition
j=0;
while(i<=len&&temp[i]!='/'){token[j]=temp[i];i++;j++;}
token[j]='\0';
// puts(token);
if(stricmp(token,"where")!=0){throwerror(1);return lll;}
///////////////////////fieldname
i++;
if(i>=len){throwerror(21);return lll;}
j=0;
while(i<=len&&temp[i]!='/'){token[j]=temp[i];i++;j++;}
token[j]='\0';
// puts(token);
tmp.fieldlenght=1;
strcpy(tmp.join[0].wordname,token);
///////////////////////////////////sign
i++;
if(i>=len){throwerror(1);return lll;}
j=0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -