// File: /workspace/github_c_makefile_star2_O2/DVaronos[P]AnLogProject1/hash.c
// Function: Readjson
LHash* Readjson(char* filename,LHash* H,LHash* Common,WHash** L){ //Diavazei to Json kai apothikei tis leksis sto leksilogio kai se ena WHash
  FILE* fp;
  if( (fp=fopen(filename,"r"))==NULL){
    perror("Fopen");
  }

  char symbols[] =  " /,\\,\n,[,],(,),*,&,^,%,$,#,@,!,:,;,<,>,`,~,+,_,-,=,{,}|,\",.," "";  //Ta simvolia ta opia tha xwrizoun tis lekseis
  (*L)=CreateWHash(200);
  char line[250];
  char* word;
  int count=0;

	while(fgets(line, sizeof(line),fp)){  //Diavazei to json grami gami

		word = strtok(line, """:");		//skip labels
		word=strtok(NULL,symbols);

		while(word!=NULL){ //Gia kathe leksi tis gramhs
			if(strlen(word)>2)
			{
				count++;
				for(int j=0; j<=strlen(word);j++){  //Metatrepei ta kefalea se peza
					if(word[j]>=65 && word[j]<=90)	word[j]=word[j]+32;
				}
				if(!LHashFind(Common,word)){  //Ean h leksh den einai mia apo tis common
					if(!WHashFind(*L,word))  H=LHashInsert(H,word); //Ean den exw isagi thn leksh allh fora sto stigekrimeno json
					*L=InsertWHash(*L,word);
				}
			}
			word=strtok(NULL,symbols);
		}
	}
	fclose(fp);
	(*L)=WHashTF(*L); //Ipoligismos twn tf gia kathe leksh tou TF
	for(int i=0 ; i<(*L)->size ; i++){
		if((*L)[i].word!=NULL){
			H=LHashIncreaseTf(H,(*L)[i].word,(*L)[i].tfidf);
		}
	}
return H;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x118, %rsp            # imm = 0x118
movq %rcx, %rbx
movq %rdx, %r15
movq %rsi, -0x30(%rbp)
leaq 0x1498(%rip), %rsi      # 0x6010
callq 0x1200
movq %rax, -0x40(%rbp)
testq %rax, %rax
je 0x4cd6
movl $0xc8, %edi
callq 0x3601
movq %rbx, -0x38(%rbp)
movq %rax, (%rbx)
leaq -0x140(%rbp), %r12
leaq 0x1777(%rip), %r14      # 0x6320
movq %r12, %rdi
movl $0xfa, %esi
movq -0x40(%rbp), %rdx
callq 0x1110
testq %rax, %rax
je 0x4c73
movq %r12, %rbx
movq %r12, %rdi
leaq 0x1745(%rip), %rsi      # 0x6315
callq 0x1220
xorl %edi, %edi
movq %r14, %rsi
callq 0x1220
testq %rax, %rax
je 0x4c6b
movq %rax, %r12
movq %rax, %rdi
callq 0x10c0
cmpq $0x3, %rax
jb 0x4bd5
xorl %r13d, %r13d
movq %r12, %rdi
callq 0x10c0
cmpq %r13, %rax
jb 0x4c20
movb (%r12,%r13), %al
leal -0x41(%rax), %ecx
cmpb $0x19, %cl
ja 0x4c1b
orb $0x20, %al
movb %al, (%r12,%r13)
incq %r13
jmp 0x4bfc
movq %r15, %rdi
movq %r12, %rsi
callq 0x4846
testl %eax, %eax
jne 0x4bd5
movq -0x38(%rbp), %rax
movq (%rax), %rdi
movq %r12, %rsi
callq 0x38db
testl %eax, %eax
jne 0x4c52
movq -0x30(%rbp), %rdi
movq %r12, %rsi
callq 0x451d
movq %rax, -0x30(%rbp)
movq -0x38(%rbp), %r13
movq (%r13), %rdi
movq %r12, %rsi
callq 0x363e
movq %rax, (%r13)
jmp 0x4bd5
movq %rbx, %r12
jmp 0x4ba9
movq -0x40(%rbp), %rdi
callq 0x10a0
movq -0x38(%rbp), %rbx
movq (%rbx), %rdi
callq 0x385f
movq %rax, (%rbx)
pushq $0x8
popq %r14
xorl %r15d, %r15d
movslq 0x14(%rax), %rcx
cmpq %rcx, %r15
jge 0x4cc0
movq (%rax,%r14), %rsi
testq %rsi, %rsi
je 0x4cb7
movsd -0x8(%rax,%r14), %xmm0
movq -0x30(%rbp), %rdi
callq 0x4acc
movq (%rbx), %rax
incq %r15
addq $0x18, %r14
jmp 0x4c92
movq -0x30(%rbp), %rax
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1346(%rip), %rdi      # 0x6023
callq 0x1210
jmp 0x4b8a
nop