📄 compile.h
字号:
tmp.fieldlenght=fgetc(f1);
tmp.lines=fgetc(f1);
for(j=0;j<tmp.fieldlenght;j++)
{
fread(&(tmp.join[j]),LENGTH,1,f1);
}
for(j=0;j<from1.fieldlenght;j++)
{
for(m=0;m<tmp.fieldlenght;m++)
{
// puts(to.join[j].wordname);
if(strcmp(from1.join[j].wordname,tmp.join[m].wordname)==0)
{
from1.join[j].locate=m;
break;
}
}
if(m==tmp.fieldlenght){throwerror(17);return lll;}
}
rewind(f2);
l=tmp.fieldlenght;
tmp.fieldlenght=fgetc(f2);
tmp.lines=fgetc(f2);
for(j=0;j<tmp.fieldlenght;j++)
{
fread(&(tmp.join[j]),LENGTH,1,f2);
}
for(j=0;j<from1.fieldlenght;j++)
{
for(m=0;m<tmp.fieldlenght;m++)
{
// puts(to.join[j].wordname);
if(strcmp(to.join[j].wordname,tmp.join[m].wordname)==0)
{
to.join[j].locate=m+l;
break;
}
}
if(m==tmp.fieldlenght){throwerror(17);return lll;}
}
///////////////////////////////////////////
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,"to")!=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);
if((fp=fopen(token,"r"))!=NULL)
{
throwerror(4);
fclose(fp);
return lll;
}
f=fopen("temp$","r");
fp=fopen(token,"wb+");
ch=fgetc(f);
while(ch!=EOF)
{
fputc(ch,fp);
ch=fgetc(f);
}
fclose(f);
remove("temp$");
fclose(fp);
/////////////////////////////////////////////
strcpy(temp,"OPEN/");
strcat(temp,token);
strcat(temp,"/,/w/");
openrel(temp);
fclose(fp);
fp=fopen(token,"ab+");
rewind(fp);
tmp.fieldlenght=fgetc(fp);
tmp.lines=fgetc(fp);
for(i=0;i<tmp.fieldlenght;i++)
{
fread(&tmp.join[i],LENGTH,1,fp);
}
i=0;
while(i<tmp.lines)
{
for(j=0;j<from1.fieldlenght;j++)
{
///////////////////////////////////data1
k=from1.join[j].locate;
rewind(fp);
fseek(fp,2+128*LENGTH,0);
fseek(fp,(k+i*tmp.fieldlenght)*VALUE_LENGTH,1);
fread(&values[0],VALUE_LENGTH,1,fp);
///////////////////////////////////data2
k=to.join[j].locate;
rewind(fp);
fseek(fp,2+128*LENGTH,0);
fseek(fp,(k+i*tmp.fieldlenght)*VALUE_LENGTH,1);
fread(&values[1],VALUE_LENGTH,1,fp);
///////////////////////////////////
m=0;
if(strcmp(values[0].fieldvalue,values[1].fieldvalue)!=0)
{
seeklocation=i+1;
strcpy(temp,"DELETE/");
deleterel(temp);
m=1;
tmp.lines--;
break;
}
}
if(!m) i++;
}
///////////////////////////////////
fclose(fp);
fclose(f);
f=fopen("temp$","wb+");
fp=fopen(token,"r");
rewind(fp);
fieldnum=fgetc(fp);
line=fgetc(fp);
from.fieldlenght=fieldnum;
from.lines=line;
for(i=0;i<from.fieldlenght-1;i++)
{
for(j=i+1;j<from.fieldlenght;j++)
{
if(strcmp(from.join[i].wordname,from.join[j].wordname)==0)
{
from.join[j].locate=-1;
fieldnum--;
}
}
}
fputc(fieldnum,f);
fputc(line,f);
for(i=0;i<from.fieldlenght;i++)
{
if(from.join[i].locate!=-1)
{
fwrite(&(from.join[i]),LENGTH,1,f);
}
}
for(i=fieldnum;i<128;i++)
{
fwrite(&(from.join[i]),LENGTH,1,f);
}
rewind(fp);
fseek(fp,2+128*LENGTH,0);
for(i=0;i<from.lines;i++)
{
for(j=0;j<from.fieldlenght;j++)
{
fread(&values[0],VALUE_LENGTH,1,fp);
if(from.join[j].locate!=-1)
{
fwrite(&values[0],VALUE_LENGTH,1,f);
}
}
}
fclose(f);
fclose(fp);
remove(token);
rename("temp$",token);
fp=fopen(token,"ab+");
rewind(fp);
from.fieldlenght=fgetc(fp);
from.lines=fgetc(fp);
for(i=0;i<from.fieldlenght;i++)
{
fread(&from.join[i],LENGTH,1,fp);
}
file_opened[openfilenum-1].currentfp=fp;
///////////////////////////////////
lll=0;
}
else
{
throwerror(1);
return lll;
}
///////////////////////////////////////////////file end
///////////////////////////////////////////////////////
return lll;
}
////////////////////////////////////////////////////
/*
* ALTER Function 添加字段函数
*/
///////////////////////////////////////////////////
int alter(char *temp)
{
int lll=1;
FILE *fp,*f;
int i=0,j=0,k=0,m=0,l,line,fieldnum,n;
int len=strlen(temp);
int err=0;
char token[20];
char ch;
if(len==6){
throwerror(3);
return lll;
}
// puts(temp);
i=6;
j=0;
while(i<=len&&temp[i]!='/'){token[j]=temp[i];i++;j++;}
token[j]='\0';
// puts(token);
err=1;
for(n=0;n<openfilenum;n++)
{
if(stricmp(token,file_opened[n].filename)==0)
{
if(file_opened[n].station)
{
if(!file_opened[n].openstyle){throwerror(15);return lll;}
fp=file_opened[n].currentfp;
err=0;
break;
}else
{
throwerror(14);
return lll;
}
}
}
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,"add")!=0){throwerror(1);return lll;}
i++;
if(temp[i]!='('){throwerror(1);return lll;}
i=i+2;
j=0;
rewind(fp);
fieldnum=fgetc(fp);
line=fgetc(fp);
for(k=0;k<fieldnum;k++) fread(&rel[k],LENGTH,1,fp);
while(i<=len)
{
j=0;
l=i;
while(l<=len&&temp[l]!='/'){
token[j]=temp[l];
j++;
l++;
}
token[j]='\0';
for(m=0;m<k;m++)
{
if(strcmp(token,rel[m].wordname)==0)
{
throwerror(5);
return lll;
}
}
strcpy(rel[k].wordname,token);
rel[k].key=0;
// puts(rel[k].wordname);
///////////////////////////
l++;
j=0;
while(l<=len&&temp[l]!='/'){
token[j]=temp[l];
j++;
l++;
}
token[j]='\0';
strlwr(token);
// puts(token);
if(strcmp(token,"int")==0)
{
rel[k].typesign=0;
rel[k].length=16;
l++;
}else if(strcmp(token,"float")==0){
rel[k].typesign=1;
rel[k].length=16;
l++;
}else if(strcmp(token,"char")==0){
rel[k].typesign=2;
l++;
if(temp[l]!='('){throwerror(1);return lll;}
else
{
l++;
l++;
j=0;
while(l<=len&&temp[l]!='/'){
token[j]=temp[l];
j++;
l++;
}
token[j]='\0';
rel[k].length=atoi(token);
// printf("%d\n",rel[k].length);
l++;
}
if(temp[l]!=')'){throwerror(1);return lll;}
else{l++;l++;}
}else{throwerror(1);return lll;}
if(temp[l]=='P'||temp[l]=='N'||temp[l]=='U'){
j=0;
while(l<=len&&temp[l]!='/'){
token[j]=temp[l];
j++;
l++;
}
token[j]='\0';
strlwr(token);
// puts(token);
if(strcmp(token,"primarykey")==0)
{
rel[k].key=1;
l++;
}
if(strcmp(token,"notnull")==0)
{
rel[k].key=2;
l++;
}
if(strcmp(token,"unique")==0)
{
rel[k].key=3;
l++;
}
if(strcmp(token,"notnullunique")==0)
{
rel[k].key=4;
l++;
}
}
if(temp[l]==')')
{
l++;
l++;
k++;
i=l;
break;
}else if(temp[l]==',')
{
k++;
i=l;
i++;
i++;
continue;
}else{
throwerror(1);return lll;
}
///////////////////////////
}
if((f=fopen("temp$","wb+"))!=NULL)
{
fputc(k,f);
from.fieldlenght=k;
fputc(line,f);
fseek(fp,2+128*LENGTH,0);
for(j=0;j<k;j++)
{
strcpy(from.join[j].wordname,rel[j].wordname);
rel[j].locate=j+1;
}
for(j=0;j<128;j++)
fwrite(&rel[j],LENGTH,1,f);
for(i=0;i<line;i++)
{
for(j=0;j<k-1;j++)
{
fread(&values[0],VALUE_LENGTH,1,fp);
fwrite(&values[0],VALUE_LENGTH,1,f);
}
strcpy(values[0].fieldvalue,"null");
fwrite(&values[0],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);
remove("temp$");
fclose(fp);
file_opened[n].currentfp=fopen(file_opened[n].filename,"ab+");
lll=0;
}else
{
throwerror(2);
}
///////////////////////////////////////////
return lll;
}
////////////////////////////////////////////////////
/*
* SEEK Function 按行号查找数据函数
*/
///////////////////////////////////////////////////
int seek(char *temp)
{
int lll=1;
FILE *fp;
int i=0,j=0,m=0,err=1;
int len=strlen(temp);
char token[20];
int seeklocation1;
seeklocation=-1;
if(len==5){
throwerror(1);
return lll;
}
puts(temp);
i=5;
j=0;
while(i<=len&&temp[i]!='/'){token[j]=temp[i];i++;j++;}
token[j]='\0';
// puts(token);
for(i=0;i<j;i++)
{
if(!isNum(token[i]))
{
throwerror(1);
return lll;
}
}
m=atoi(token);
for(i=0;i<openfilenum;i++)
{
if(file_opened[i].station)
{
fp=file_opened[i].currentfp;
err=0;
break;
}
}
if(err){throwerror(10);return lll;}
if(m>from.lines)
{
m=from.lines;
printf("\nExceeded to limit!\n");
}
if(m<1)
{
m=1;
printf("\nExceeded to limit!\n");
}
for(i=0;i<from.fieldlenght;i++)
{
printf("%20s",from.join[i].wordname);
}
printf("\n*");
for(j=0;j<from.fieldlenght;j++) printf("--------------------");
printf("*\n");
seeklocation1=128*LENGTH+2+from.fieldlenght*(m-1)*VALUE_LENGTH;
seeklocation=m;
fseek(fp,seeklocation1,0);
for(i=0;i<from.fieldlenght;i++){
fread(&values[0],VALUE_LENGTH,1,fp);
printf("%20s",values[0].fieldvalue);
}
printf("\n|");
for(j=0;j<from.fieldlenght;j++) printf("--------------------");
printf("|\n");
fseek(fp,seeklocation1,0);
lll=0;
return lll;
}
////////////////////////////////////////////////////
/*
* Condition Function 根据表属性判断实体完整性函数
*/
///////////////////////////////////////////////////
int condition(int con,int id,FILE *f)
{
int lll=0;
int i,j,k,line,num;
char *temp="DELETE/";
rewind(f);
num=fgetc(f);
line=fgetc(f);
if(con==1)
{
k=0;
i=0;
while(i<line-1)
{
rewind(f);
fseek(f,2+128*LENGTH,0);
fseek(f,(id+i*num)*VALUE_LENGTH,1);
fread(&values[0],VALUE_LENGTH,1,f);
j=i+1;
while(j<line)
{
rewind(f);
fseek(f,2+128*LENGTH,0);
fseek(f,(id+j*num)*VALUE_LENGTH,1);
fread(&values[1],VALUE_LENGTH,1,f);
if(strcmp(values[0].fieldvalue,values[1].fieldvalue)==0)
{
seeklocation=j+1;
deleterel(temp);
line--;
printf("\n%s is key,not allow duplicate!\n",from.join[id].wordname);
k=1;
}
else
{
j++;
}
}
i++;
}
i=0;
while(i<line)
{
rewind(f);
fseek(f,2+128*LENGTH,0);
fseek(f,(id+i*num)*VALUE_LENGTH,1);
fread(&values[0],VALUE_LENGTH,1,f);
if(strcmp(values[0].fieldvalue,"null")==0)
{
seeklocation=i+1;
deleterel(temp);
line--;
printf("\n%s is key,not allow null!\n",from.join[id].wordname);
k=1;
}
else
{
i++;
}
}
if(k)
{
lll=1;
}
}
else if(con==2)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -