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

📄 compile.h

📁 一个用c开发的小型数据库管理系统dbms
💻 H
📖 第 1 页 / 共 5 页
字号:
        while(i<=len&&temp[i]!='/'){token[j]=temp[i];i++;j++;}
        token[j]='\0';
	//	puts(token);
		tmp.join[0].length=sign(token);
		///////////////////////////////////value
		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);
		strcpy(values[0].fieldvalue,token);
		////////////////////////////////////
        i++;
		while(i<=len)
		{
			if(temp[i]!=',')break;
			i=i+2;
			////////////////////////////////////fieldname
			j=0;
            while(i<=len&&temp[i]!='/'){token[j]=temp[i];i++;j++;}
            token[j]='\0';
    //		puts(token);
    		for(k=0;k<tmp.fieldlenght;k++)
			{
				if(strcmp(token,tmp.join[k].wordname)==0)
				{
					throwerror(22);
					return lll;
				}
			}
    		strcpy(tmp.join[tmp.fieldlenght].wordname,token);
			///////////////////////////////////sign
		    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);
	     	tmp.join[tmp.fieldlenght].length=sign(token);
	    	///////////////////////////////////value
	    	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);
    		strcpy(values[tmp.fieldlenght].fieldvalue,token);
    		////////////////////////////////////
			tmp.fieldlenght++;
            i++;
		}
		////////////////////////////////
		    for(j=0;j<tmp.fieldlenght;j++)
			{
				for(m=0;m<from.fieldlenght;m++)
				{
	//				puts(tmp.join[j].wordname);
					if(strcmp(tmp.join[j].wordname,from.join[m].wordname)==0)
					{
						tmp.join[j].locate=m;
						break;
					}
				}
				if(m==from.fieldlenght){throwerror(17);return lll;}
			}
		//////////////////start output
        
			rewind(fp);
		    from.fieldlenght=fgetc(fp);
		    from.lines=fgetc(fp);
		    if(all){
				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");
			}else
			{
				for(jj=0;jj<to.fieldlenght;jj++)
				{
					printf("%20s",to.join[jj].wordname);
				}
	    	    printf("\n*");
                for(jj=0;jj<to.fieldlenght;jj++) printf("--------------------");
	    	    printf("*\n");
			}
		    for(j=0;j<from.lines;j++)
			{
				output=1;
				for(i=0;i<tmp.fieldlenght;i++)
				{
					k=tmp.join[i].locate;
					rewind(fp);
					fseek(fp,2+128*LENGTH,0);
					fseek(fp,(k+j*from.fieldlenght)*VALUE_LENGTH,1);
					fread(&values[tmp.fieldlenght],VALUE_LENGTH,1,fp);
					if(strcmp(values[tmp.fieldlenght].fieldvalue,"null")==0)
					{
						output=0;
						break;
					}
					if(from.join[k].typesign==0)
					{
						if(tmp.join[i].length==1)
						{
							if(!(atoi(values[tmp.fieldlenght].fieldvalue)>atoi(values[i].fieldvalue)))
							{
								output=0;
								break;
							}
						}
						if(tmp.join[i].length==2)
						{
							if(!(atoi(values[tmp.fieldlenght].fieldvalue)>=atoi(values[i].fieldvalue)))
							{
								output=0;
								break;
							}
						}
						if(tmp.join[i].length==3)
						{
							if(!(atoi(values[tmp.fieldlenght].fieldvalue)==atoi(values[i].fieldvalue)))
							{
								output=0;
								break;
							}
						}
						if(tmp.join[i].length==4)
						{
							if(!(atoi(values[tmp.fieldlenght].fieldvalue)<=atoi(values[i].fieldvalue)))
							{
								output=0;
								break;
							}
						}
						if(tmp.join[i].length==5)
						{
							if(!(atoi(values[tmp.fieldlenght].fieldvalue)<atoi(values[i].fieldvalue)))
							{
								output=0;
								break;
							}
						}
					}
					else if(from.join[k].typesign==1)
					{
						if(tmp.join[i].length==1)
						{
							if(!(atof(values[tmp.fieldlenght].fieldvalue)>atof(values[i].fieldvalue)))
							{
								output=0;
								break;
							}
						}
						if(tmp.join[i].length==2)
						{
							if(!(atof(values[tmp.fieldlenght].fieldvalue)>=atof(values[i].fieldvalue)))
							{
								output=0;
								break;
							}
						}
						if(tmp.join[i].length==3)
						{
							if(!(atof(values[tmp.fieldlenght].fieldvalue)==atof(values[i].fieldvalue)))
							{
								output=0;
								break;
							}
						}
						if(tmp.join[i].length==4)
						{
							if(!(atof(values[tmp.fieldlenght].fieldvalue)<=atof(values[i].fieldvalue)))
							{
								output=0;
								break;
							}
						}
						if(tmp.join[i].length==5)
						{
							if(!(atof(values[tmp.fieldlenght].fieldvalue)<atof(values[i].fieldvalue)))
							{
								output=0;
								break;
							}
						}
					}
					else
					{
						if(tmp.join[i].length==1)
						{
							if(!(strcmp(values[tmp.fieldlenght].fieldvalue,values[i].fieldvalue)>0))
							{
								output=0;
								break;
							}
						}
						if(tmp.join[i].length==2)
						{
							if(!(strcmp(values[tmp.fieldlenght].fieldvalue,values[i].fieldvalue)>=0))
							{
								output=0;
								break;
							}
						}
						if(tmp.join[i].length==3)
						{
							if(!(strcmp(values[tmp.fieldlenght].fieldvalue,values[i].fieldvalue)==0))
							{
								output=0;
								break;
							}
						}
						if(tmp.join[i].length==4)
						{
							if(!(strcmp(values[tmp.fieldlenght].fieldvalue,values[i].fieldvalue)<=0))
							{
								output=0;
								break;
							}
						}
						if(tmp.join[i].length==5)
						{
							if(!(strcmp(values[tmp.fieldlenght].fieldvalue,values[i].fieldvalue)<0))
							{
								output=0;
								break;
							}
						}
					}
				}///////for(i=0;i<tmp.fieldlenght;i++) end
		        if(output)
				{	
					if(all)
					{
						rewind(fp);
				        fseek(fp,2+128*LENGTH,0);
			        	fseek(fp,j*from.fieldlenght*VALUE_LENGTH,1);
		 	        	for(m=0;m<from.fieldlenght;m++)
						{
							fread(&values[tmp.fieldlenght],VALUE_LENGTH,1,fp);
			                printf("%20s",values[tmp.fieldlenght].fieldvalue);
						}
			        	printf("\n|");
                        for(m=0;m<from.fieldlenght;m++) printf("--------------------");
		        	    printf("|\n");   
					}
			        else
					{
						for(jj=0;jj<to.fieldlenght;jj++)
						{
							for(m=0;m<from.fieldlenght;m++)
							{
		//						puts(to.join[jj].wordname);
					            if(strcmp(to.join[jj].wordname,from.join[m].wordname)==0)
								{
									to.join[jj].locate=m;
						            break;
								}
							}
				            if(m==from.fieldlenght){throwerror(17);return lll;}
						}
			   
		    	        
				        for(jj=0;jj<to.fieldlenght;jj++)
						{
							kk=to.join[jj].locate;
					        rewind(fp);
				        	fseek(fp,2+128*LENGTH,0);
				        	fseek(fp,(kk+j*from.fieldlenght)*VALUE_LENGTH,1);
				        	fread(&values[tmp.fieldlenght],VALUE_LENGTH,1,fp);
			                printf("%20s",values[tmp.fieldlenght].fieldvalue);
			                if((jj+1)%to.fieldlenght==0) 
							{
								printf("\n|");
                                for(m=0;m<to.fieldlenght;m++) printf("--------------------");
			                    printf("|\n");
							}
						}
					} 
				}//////////////////////output end
           }//////////////for(j=0;j<from.lines;j++) end
			lll=0;
			return lll;
      }
	
	////////////////////////
	return lll;
}
////////////////////////////////////////////////////
/*
* JOIN Function 连接表函数
*/
///////////////////////////////////////////////////
int join(char *temp)
{
	int lll=1;
	FILE *fp,*f1,*f2,*f;
	int i=0,j=0,k=0,ii,jj,kk,line,fieldnum,m,l;
	int n1,n2;
	int len=strlen(temp);
    char token[20];
	char token1[20];
	char ch;
	if(len==5){
		throwerror(3);
		return lll;
	}
	////////////////////////////////////////////file1
	i=5;
    j=0;
    while(i<=len&&temp[i]!='/'){token[j]=temp[i];i++;j++;}
	token[j]='\0';
	for(n1=0;n1<openfilenum;n1++)
	{
		if(stricmp(token,file_opened[n1].filename)==0)
		{
			f1=file_opened[n1].currentfp;
			break;		
		}
	}
	if(n1==openfilenum){printf("Table %s error!",token);throwerror(13);return lll;}
    ////////////////////////////////////////////////file2
	i++;
    if(temp[i]!=','){throwerror(1);return lll;}
	i=i+2;
    if(i>=len){throwerror(3);return lll;}
    j=0;
    while(i<=len&&temp[i]!='/'){token[j]=temp[i];i++;j++;}
	token[j]='\0';
	if(stricmp(token,file_opened[n1].filename)==0){throwerror(25);return lll;}
    for(n2=0;n2<openfilenum;n2++)
	{
		if(stricmp(token,file_opened[n2].filename)==0)
		{
			f2=file_opened[n2].currentfp;
			break;		
		}
	}
	if(n2==openfilenum){printf("Table %s error!",token);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';
	if(stricmp(token,"to")==0)
	{
		////////////////////////////////////////////////file3
		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((fp=fopen(token,"r"))!=NULL)
		{
			throwerror(4);
		    fclose(fp);
	    	return lll;
		}
		rewind(f1);
		rewind(f2);
		fp=fopen(token,"wb+");
		from1.fieldlenght=fgetc(f1);
		from1.lines=fgetc(f1);
		to.fieldlenght=fgetc(f2);
		to.lines=fgetc(f2);
		fieldnum=from1.fieldlenght+to.fieldlenght;
		if(fieldnum>128){throwerror(24);return lll;}
		line=from1.lines*to.lines;
		rewind(fp);
		fputc(fieldnum,fp);
		fputc(line,fp);
		for(i=0;i<from1.fieldlenght;i++)
		{
			fread(&(from1.join[i]),LENGTH,1,f1);
			fwrite(&(from1.join[i]),LENGTH,1,fp);
		}
		for(j=0;j<to.fieldlenght;j++)
		{
			fread(&(to.join[j]),LENGTH,1,f2);
			for(k=0;k<from1.fieldlenght;k++)
			{
				if(strcmp(to.join[j].wordname,from1.join[k].wordname)==0)
				{
					strcpy(token1,to.join[j].wordname);
					strcat(to.join[j].wordname,"_1");
					break;
				}
			}	
		/////////////////2004/4/24/0:00 add
			fwrite(&(to.join[j]),LENGTH,1,fp);
			if(k!=from1.fieldlenght)strcpy(to.join[j].wordname,token1);
		}
		for(i=fieldnum;i<128;i++)
		{
			fwrite(&(to.join[i]),LENGTH,1,fp);
		}
		fseek(f1,2+128*LENGTH,0);
		fseek(f2,2+128*LENGTH,0);
		/////////////////////////////////////////add fieldname end
		/////////////////////////////////////////add data
		for(i=0;i<from1.lines;i++)
		{
			for(ii=0;ii<from1.fieldlenght;ii++)
			{
				fread(&values[ii],VALUE_LENGTH,1,f1);
			}
			fseek(f2,2+128*LENGTH,0);
			for(j=0;j<to.lines;j++)
			{
				for(ii=0;ii<from1.fieldlenght;ii++)
				{
					fwrite(&values[ii],VALUE_LENGTH,1,fp);
				}
				for(jj=0;jj<to.fieldlenght;jj++)
				{
					fread(&values[from1.fieldlenght],VALUE_LENGTH,1,f2);
					fwrite(&values[from1.fieldlenght],VALUE_LENGTH,1,fp);
				}
			}
		}
		/////////////////////////////////////////add data end
		fclose(fp);
		strcpy(temp,"OPEN/");
		strcat(temp,token);
		strcat(temp,"/,/w/");
		lll=openrel(temp);
	}
	else if(stricmp(token,"for")==0)
	{
		////////////////////////////////////////////////file3
		kk=i;
		rewind(f1);
		rewind(f2);
		fp=fopen("temp$","wb+");
		from1.fieldlenght=fgetc(f1);
		from1.lines=fgetc(f1);
		to.fieldlenght=fgetc(f2);
		to.lines=fgetc(f2);
		fieldnum=from1.fieldlenght+to.fieldlenght;
		if(fieldnum>128){throwerror(24);return lll;}
		line=from1.lines*to.lines;
		rewind(fp);
		fputc(fieldnum,fp);
		fputc(line,fp);
		for(i=0;i<from1.fieldlenght;i++)
		{
			fread(&(from1.join[i]),LENGTH,1,f1);
			fwrite(&(from1.join[i]),LENGTH,1,fp);
		}
		for(j=0;j<to.fieldlenght;j++)
		{
			fread(&(to.join[j]),LENGTH,1,f2);
			for(k=0;k<from1.fieldlenght;k++)
			{
				if(strcmp(to.join[j].wordname,from1.join[k].wordname)==0)
				{
					strcpy(token1,to.join[j].wordname);
					//strcat(to.join[j].wordname,"_1");
					break;
				}
			}	
		/////////////////2004/4/24/0:00 add
			fwrite(&(to.join[j]),LENGTH,1,fp);
			if(k!=from1.fieldlenght)strcpy(to.join[j].wordname,token1);
		}
		for(i=fieldnum;i<128;i++)
		{
			fwrite(&(to.join[i]),LENGTH,1,fp);
		}
		fseek(f1,2+128*LENGTH,0);
		fseek(f2,2+128*LENGTH,0);
		/////////////////////////////////////////add fieldname end
		/////////////////////////////////////////add data
		for(i=0;i<from1.lines;i++)
		{
			for(ii=0;ii<from1.fieldlenght;ii++)
			{
				fread(&values[ii],VALUE_LENGTH,1,f1);
			}
			fseek(f2,2+128*LENGTH,0);
			for(j=0;j<to.lines;j++)
			{
				for(ii=0;ii<from1.fieldlenght;ii++)
				{
					fwrite(&values[ii],VALUE_LENGTH,1,fp);
				}
				for(jj=0;jj<to.fieldlenght;jj++)
				{
					fread(&values[from1.fieldlenght],VALUE_LENGTH,1,f2);
					fwrite(&values[from1.fieldlenght],VALUE_LENGTH,1,fp);
				}
			}
		}
		fclose(fp);
		/////////////////////////////////////////add data end
		i=kk;
		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);
		from1.fieldlenght=1;
		strcpy(from1.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);
        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<from.fieldlenght;k++)
			{
				if(strcmp(token,from.join[k].wordname)==0)
				{
					throwerror(22);
				    return lll;
				}
			}*/
	    	strcpy(from1.join[from1.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);
			/*for(k=0;k<from.fieldlenght;k++)
			{
				if(strcmp(token,to.join[k].wordname)==0)
				{
					throwerror(22);
				    return lll;
				}
			}*/
            strcpy(to.join[from1.fieldlenght].wordname,token);
			from1.fieldlenght++;
	    	i++;
		}
		///////////////////////////////////////////
		rewind(f1);

⌨️ 快捷键说明

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