📄 compile.h
字号:
{
fread(&(from.join[j]),LENGTH,1,file_opened[i].currentfp);
}
/* printf("\n*------------------------------------------------------------*\n");
fseek(file_opened[i].currentfp,128*LENGTH+2,0);
for(j=0;j<from.lines*from.fieldlenght;j++){
fread(&values[0],VALUE_LENGTH,1,file_opened[i].currentfp);
printf("%20s",values[0].fieldvalue);
if((j+1)%from.fieldlenght==0) printf("\n|------------------------------------------------------------|\n");
}
*/
lll=0;
}else
{
throwerror(13);
}
return lll;
}
////////////////////////////////////////////////////
/*
* INSERT Function 插入表元素
*/
///////////////////////////////////////////////////
int insert(char *temp)
{
int lll=1;
FILE *fp,*f;
int i=0,j=0,k=0,m=0,n;
int len=strlen(temp);
int err=0;
char token[20];
char ch;
// char *s="OPEN/d/,/w";
// openrel(s);
if(len==7){
throwerror(3);
return lll;
}
// puts(temp);
i=7;
j=0;
while(i<=len&&temp[i]!='/'){token[j]=temp[i];i++;j++;}
token[j]='\0';
// puts(token);
/////////////if file opened?
for(n=0;n<openfilenum;n++)
{
if(stricmp(token,file_opened[n].filename)==0)
{
m=1;
break;
}
}
if(m)
{
if(file_opened[n].station!=1)
{
throwerror(14);
return lll;
}
if(file_opened[n].openstyle==0)
{
throwerror(15);
return lll;
}
fp=file_opened[n].currentfp;
}else
{
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,"VALUES")==0)
{
i++;
if(i<len)
{
if(temp[i]=='(')
{
i=i+2;
for(k=0;k<from.fieldlenght-1;k++)
{
if(from.join[k].typesign==2)
{
if(temp[i]!='\''){throwerror(16);return lll;}
i=i+2;
if(temp[i]=='\'')
{
strcpy(values[k].fieldvalue,"null");
i=i+2;
}else
{
j=0;
while(i<=len&&temp[i]!='/'){token[j]=temp[i];i++;j++;}
token[j]='\0';
// puts(token);
i++;
if(temp[i]!='\''){throwerror(1);return lll;}
strcpy(values[k].fieldvalue,token);
i=i+2;
}
}else
{
if(temp[i]==','){
strcpy(values[k].fieldvalue,"null");
}
else{
j=0;
while(i<=len&&temp[i]!='/'){token[j]=temp[i];i++;j++;}
token[j]='\0';
// puts(token);
strcpy(values[k].fieldvalue,token);
i++;
}
}
if(temp[i]!=',')
{
throwerror(1);
return lll;
}
i=i+2;
}
if(from.join[from.fieldlenght-1].typesign==2)
{
if(temp[i]!='\''){throwerror(16);return lll;}
i=i+2;
if(temp[i]=='\'')
{
strcpy(values[from.fieldlenght-1].fieldvalue,"null");
i=i+2;
}
else
{
j=0;
while(i<=len&&temp[i]!='/'){token[j]=temp[i];i++;j++;}
token[j]='\0';
// puts(token);
i++;
if(temp[i]!='\''){throwerror(1);return lll;}
strcpy(values[from.fieldlenght-1].fieldvalue,token);
i=i+2;
}
}
else
{
if(temp[i]==')')
{
strcpy(values[k].fieldvalue,"null");
}
else
{
j=0;
while(i<=len&&temp[i]!='/'){token[j]=temp[i];i++;j++;}
token[j]='\0';
// puts(token);
strcpy(values[k].fieldvalue,token);
}
}
/*///////////
add file
///////////*/
}//////if(temp[i]=='(')
}//////////if(i<len)
else
{
throwerror(1);
return lll;
}
}///////////if(strcmp(token,"VALUES")==0)
else////////insert apart
{
for(j=0;j<from.fieldlenght;j++)
{
strcpy(values[j].fieldvalue,"null");
}
if(strcmp(token,"(")!=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;
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);
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++;
}
for(j=0;j<to.fieldlenght;j++)
{
for(m=0;m<from.fieldlenght;m++)
{
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){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);
if(stricmp(token,"VALUES")!=0){throwerror(1);return lll;}
i++;
if(i<len)
{
if(temp[i]=='(')
{
i=i+2;
for(k=0;k<to.fieldlenght-1;k++)
{
m=to.join[k].locate;
if(from.join[m].typesign==2)
{
if(temp[i]!='\''){throwerror(16);return lll;}
i=i+2;
if(temp[i]=='\'')
{
strcpy(values[k+from.fieldlenght].fieldvalue,"null");
i=i+2;
}else
{
j=0;
while(i<=len&&temp[i]!='/'){token[j]=temp[i];i++;j++;}
token[j]='\0';
// puts(token);
i++;
if(temp[i]!='\''){throwerror(1);return lll;}
strcpy(values[k+from.fieldlenght].fieldvalue,token);
i=i+2;
}
}else
{
if(temp[i]==','){
strcpy(values[k+from.fieldlenght].fieldvalue,"null");
}
else{
j=0;
while(i<=len&&temp[i]!='/'){token[j]=temp[i];i++;j++;}
token[j]='\0';
// puts(token);
strcpy(values[k+from.fieldlenght].fieldvalue,token);
i++;
}
}
if(temp[i]!=',')
{
break;
}
i=i+2;
}
if(from.join[to.fieldlenght-1].typesign==2)
{
if(temp[i]!='\''){throwerror(16);return lll;}
i=i+2;
if(temp[i]=='\'')
{
strcpy(values[from.fieldlenght-1+from.fieldlenght].fieldvalue,"null");
i=i+2;
}
else
{
j=0;
while(i<=len&&temp[i]!='/'){token[j]=temp[i];i++;j++;}
token[j]='\0';
// puts(token);
i++;
if(temp[i]!='\''){throwerror(1);return lll;}
strcpy(values[from.fieldlenght-1+from.fieldlenght].fieldvalue,token);
i=i+2;
}
}
else
{
if(temp[i]==')')
{
strcpy(values[k+from.fieldlenght].fieldvalue,"null");
}
else
{
j=0;
while(i<=len&&temp[i]!='/'){token[j]=temp[i];i++;j++;}
token[j]='\0';
// puts(token);
strcpy(values[k+from.fieldlenght].fieldvalue,token);
}
}
/*///////////
add file
///////////*/
}//////if(temp[i]=='(')
}//////////if(i<len)
else
{
throwerror(1);
return lll;
}
for(j=0;j<to.fieldlenght;j++)
{
k=to.join[j].locate;
strcpy(values[k].fieldvalue,values[j+from.fieldlenght].fieldvalue);
}
}
///////////////////////////write file
f=fopen("temp$","wb+");
rewind(fp);
fputc(fgetc(fp),f);
fputc(fgetc(fp)+1,f);
ch=fgetc(fp);
while(ch!=EOF)
{
fputc(ch,f);
ch=fgetc(fp);
}
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);
remove("temp$");
fclose(fp);
///////////////////////////////////////
file_opened[n].currentfp=fopen(file_opened[n].filename,"ab+");
fp=file_opened[n].currentfp;
for(i=0;i<from.fieldlenght;i++)
{
fwrite(&values[i],sizeof(struct value),1,file_opened[n].currentfp);
}
fclose(file_opened[n].currentfp);
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)throwerror(26);
return lll;
}
////////////////////////////////////////////////////
/*
* DELETE Function 删除表元祖
*/
///////////////////////////////////////////////////
int deleterel(char *temp)
{
int lll=1;
FILE *fp,*f;
int i=0,j=0,k=0,m=0,err=1;
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;
err=0;
break;
}
}
if(err){throwerror(10);return lll;}
//////////////////////////////////////////
if(len==7){
if(seeklocation1==-1)
{
throwerror(18);
return lll;
}else
{
/////////////////////
/////////////////////
f=fopen("temp$","wb+");
rewind(fp);
fputc(fgetc(fp),f);
fputc(fgetc(fp)-1,f);
for(j=0;j<128;j++)
{
fread(&(from.join[j]),LENGTH,1,fp);
fwrite(&(from.join[j]),LENGTH,1,f);
}
for(j=0;j<(seeklocation1-1)*from.fieldlenght;j++)
{
fread(&values[0],VALUE_LENGTH,1,fp);
fwrite(&values[0],VALUE_LENGTH,1,f);
}
if(seeklocation1<from.lines)
{
fseek(fp,from.fieldlenght*VALUE_LENGTH,1);
for(j=0;j<(from.lines-seeklocation1)*from.fieldlenght;j++)
{
fread(&values[0],VALUE_LENGTH,1,fp);
fwrite(&values[0],VALUE_LENGTH,1,f);
}
}
fclose(f);
fclose(fp);
fp=fopen(file_opened[i].filename,"wb+");
f=fopen("temp$","r");
ch=fgetc(f);
while(ch!=EOF)
{
fputc(ch,fp);
ch=fgetc(f);
}
fclose(f);
fclose(fp);
file_opened[i].currentfp=fopen(file_opened[i].filename,"ab+");
seeklocation=-1;
remove("temp$");
lll=0;
}
}
else
{
i=7;
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);
////////////////////
/* add if float/int */
////////////////////
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[0],VALUE_LENGTH,1,fp);
if(strcmp(token,values[0].fieldvalue)==0)
{
m=1;
seeklocation=i+1;
strcpy(temp,"DELETE/");
deleterel(temp);
from.lines--;
}else
{
i++;
}
}
if(!m){throwerror(19);return lll;}
lll=0;
}
return lll;
}
////////////////////////////////////////////////////
/*
* PROJECT Function 投影表函数
*/
///////////////////////////////////////////////////
int project(char *temp)
{
int lll=1;
FILE *fp,*f;
int i=0,j=0,k=0,m=0,err=1;
int len=strlen(temp);
char token[20];
if(len==8){
throwerror(20);
return lll;
}
//////////////////file1
i=8;
j=0;
while(i<=len&&temp[i]!='/'){token[j]=temp[i];i++;j++;}
token[j]='\0';
// puts(token);
err=1;
for(k=0;k<openfilenum;k++)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -