

#include<stdio.h>
#include<unistd.h>
#include<sys/wait.h>
#include<netinet/in.h>
#include<string.h>
#include<stdlib.h>
#include<pthread.h>

#include"sitar.h"
#include"sitar_com.h"
#include<almemsys/almemsys.h>
#include"jpreturn.h"
#include<file_comp/file_comp.h>




int my_chmem(char * data1, char * data2)
{
int ret, count, count1, count2, count3;
char * cp_data1;
char * cp_data2;
int data1_size;
int data2_size;

data1_size = (int)strlen(data1);
data2_size = (int)strlen(data2);

if((cp_data1 = (char *)calloc((data1_size + 15), sizeof(char)))==NULL){ exit(1);}
if((cp_data2 = (char *)calloc((data2_size + 15), sizeof(char)))==NULL){ exit(1);}

ret = 0;

// cp_data に data1 をコピー
count1 = 0;
for(count = 0; data1_size > count; count++){
 if(data1[count] != '\n' && data1[count] != ' ' && data1[count] != ';' && data1[count] != (char)0x05 &&
      data1[count] != (char)0x01 && data1[count] != (char)0x0a){
      cp_data1[count1] = data1[count];
      #ifdef MYCHMEM_DEBUG
      printf("MYCHMEM: my_chmem(): data1 %c", data1[count]);
      #endif
      }
   else{
      count1--;
      }
   count1++;
   }

// cp_data2 に data2 をコピー
count1 = 0;
for(count = 0; data2_size > count; count++){
   if(data2[count] != '\n' && data2[count] != ' ' && data1[count] != ';' && data1[count] != (char)0x05 &&
      data2[count] != (char)0x01 && data2[count] != (char)0x0a){
      cp_data2[count1] = data2[count];
      #ifdef MYCHMEM_DEBUG
      printf("MYCHMEM: my_chmem(): data2 <%c>", data2[count]);
      #endif
      }
   else{
      count1--;
      }
   count1++;
   }

count2 = (int)strlen(cp_data1);
count3 = (int)strlen(cp_data2);

if(count2 == count3 && count2 > 1){
   for(count = 0; count < count2; count++){
      if(cp_data1[count] != cp_data2[count]){
         ret = -1;
         }
      #ifdef MYCHMEM_DEBUG
      printf("MYCHMEM: my_chmem(): A=%c, B=%c, STAT=%d\n", cp_data1[count], cp_data2[count], ret);
      #endif
      } 
   }
else{
   ret = -1;
   #ifdef MYCHMEM_DEBUG
   printf("MYCHMEM: my_chmem(): count2 != count3 RET=%d\n", ret);
   #endif
   }

#ifdef MYCHMEM_DEBUG
printf("MYCHMEM: my_chmem(): <%s>\n\n <%s> <%d>\n", cp_data1, cp_data2, ret);
#endif

#ifdef FREE_BUG
printf("FREE: single my_chmem(1): cp_data %s\n", cp_data1);
printf("FREE: single my_chmem(1): cp_data2 %s\n", cp_data2);
#endif
free(cp_data1);
free(cp_data2);

return(ret);
}




