// File: /workspace/github_cpp_makefile_star2_O2/pawan231[P]MiniDataBase/include/display.h
// Function: display()
void display(){
	char *tab;
	tab=(char*)malloc(sizeof(char)*MAX_PATH);
	cout<<"enter table name to display\n";
	cin>>tab;
	int ret=search_table(tab);
	if(ret==0) {
		printf("%s doesn't exist\n\n",tab);
		return ;
	}
	else if(ret==1){
		//table exists

		table *temp;
		int count;
		int tot=0;
		temp=(table*)malloc(sizeof(table));
		printf("\n-----------------------------------------------\n");
		FILE *fp=open_file(tab,const_cast<char*>("r"));
		if(fp){
			fread(temp,1,sizeof(table),fp);
			count=temp->count;
			void *data2[MAX_ATTR];
			for(int i=0;i<count;i++){
				cout<<temp->col[i].col_name<<setw(20);
				if(temp->col[i].type==INT)
				{
					data2[i] =(int*) malloc(sizeof(int));
					if(data2[i]==NULL)
					{
						cout<<"NULL";
						return;
					}
					tot+=sizeof(int);
				}
				else if(temp->col[i].type==VARCHAR)
				{
					data2[i] = malloc(sizeof(char) * (MAX_NAME + 1));
					if(data2[i]==NULL)
					{
						cout<<"NULL";
						return;
					}
					tot+=(sizeof(char) * (MAX_NAME + 1));
				}
			}
			fclose(fp);
			cout<<"\n";
			printf("-----------------------------------------------\n");

			int c;
			char d[MAX_NAME];
			//cout<<"C........"<<c<<endl;
			for(int i=0;i<temp->rec_count;i++){
				FILE *fpr;
				char *str;
				str=(char*)malloc(sizeof(char)*MAX_PATH);
				sprintf(str,"table/%s/file%d.dat",tab,i);
				//cout<<str<<endl;
				fpr=fopen(str,"r");
				//cout<<*(int *)data1[0]<<" ";
				//fread(data2,temp->count,tot,fpr);
				//fread(data2,1,tot,fpr);
				for(int j=0;j<temp->count;j++){
					if(temp->col[j].type==INT){
						fread(&c,1,sizeof(int),fpr);
						cout<<c<<setw(20);
					}
					else if(temp->col[j].type==VARCHAR){
						fread(d,1,sizeof(char)*MAX_NAME,fpr);
						cout<<d<<setw(20);
					}
				}
				cout<<"\n\n";

				free(str);
				fclose(fpr);
			}
			printf("-----------------------------------------------\n");
					//fclose(fp);
		}
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movl $0x3e8, %edi            # imm = 0x3E8
callq 0x2240
movq %rax, %r15
movq 0x68ff(%rip), %rdi      # 0x9fd0
leaq 0x2b59(%rip), %rsi      # 0x6231
callq 0x2180
movq 0x68fc(%rip), %rdi      # 0x9fe0
movq %r15, %rsi
callq 0x459a
movq %r15, %rdi
callq 0x315d
testl %eax, %eax
je 0x38e0
movl $0x420, %edi            # imm = 0x420
callq 0x2240
movq %rax, %r14
leaq 0x3406(%rip), %rdi      # 0x6b16
callq 0x22c0
leaq 0x3165(%rip), %rsi      # 0x6881
movq %r15, %rdi
callq 0x2c0a
testq %rax, %rax
je 0x38d1
movq %rax, %rbx
movq %r15, 0x10(%rsp)
pushq $0x1
popq %rsi
movl $0x420, %edx            # imm = 0x420
movq %r14, %rdi
movq %rax, %rcx
callq 0x22a0
movl 0x3e0(%r14), %eax
leaq 0x7c(%r14), %r15
xorl %r13d, %r13d
testl %eax, %eax
cmovgl %eax, %r13d
movq 0x686d(%rip), %r12      # 0x9fd0
subq $0x1, %r13
jb 0x378a
movq %r12, %rdi
movq %r15, %rsi
callq 0x2180
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
movq $0x14, 0x10(%rax,%rcx)
addq $0x1c, %r15
jmp 0x3763
movq %rbx, %rdi
callq 0x2190
movq 0x6837(%rip), %rdi      # 0x9fd0
leaq 0x2b82(%rip), %rsi      # 0x6322
callq 0x2180
leaq 0x336b(%rip), %rdi      # 0x6b17
callq 0x22c0
movq %r14, %rax
addq $0x90, %rax
movq %rax, 0x8(%rsp)
leaq 0x20(%rsp), %rbp
pushq $0x1
popq %r12
xorl %ebx, %ebx
cmpl 0x418(%r14), %ebx
jge 0x38c5
movl $0x3e8, %edi            # imm = 0x3E8
callq 0x2240
movq %rax, %r15
movq %rax, %rdi
leaq 0x2960(%rip), %rsi      # 0x614e
movq 0x10(%rsp), %rdx
movl %ebx, (%rsp)
movl %ebx, %ecx
xorl %eax, %eax
callq 0x2040
movq %r15, 0x18(%rsp)
movq %r15, %rdi
leaq 0x3073(%rip), %rsi      # 0x6881
callq 0x21f0
movq %rax, %rbx
movq 0x8(%rsp), %r13
xorl %r15d, %r15d
movslq 0x3e0(%r14), %rax
cmpq %rax, %r15
jge 0x3896
movl (%r13), %eax
cmpl $0x2, %eax
je 0x385d
cmpl $0x1, %eax
jne 0x388d
leaq 0x4(%rsp), %rdi
movq %r12, %rsi
pushq $0x4
popq %rdx
movq %rbx, %rcx
callq 0x22a0
movl 0x4(%rsp), %esi
movq 0x677a(%rip), %rdi      # 0x9fd0
callq 0x2310
jmp 0x387d
movq %rbp, %rdi
movq %r12, %rsi
pushq $0x32
popq %rdx
movq %rbx, %rcx
callq 0x22a0
movq 0x675b(%rip), %rdi      # 0x9fd0
movq %rbp, %rsi
callq 0x2180
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
movq $0x14, 0x10(%rax,%rcx)
incq %r15
addq $0x1c, %r13
jmp 0x381e
movq 0x6733(%rip), %rdi      # 0x9fd0
leaq 0x2a7d(%rip), %rsi      # 0x6321
callq 0x2180
movq 0x18(%rsp), %rdi
callq 0x2200
movq %rbx, %rdi
callq 0x2190
movl (%rsp), %ebx
incl %ebx
jmp 0x37ca
leaq 0x324b(%rip), %rdi      # 0x6b17
callq 0x22c0
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x2acf(%rip), %rdi      # 0x63b6
movq %r15, %rsi
xorl %eax, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2030