a047e8b4cf02683e81cdad85af1a5e83cce9e463
[repair.git] / Repair / RepairCompiler / structextract / common.c
1 #include<string.h>
2 #include <sys/types.h>
3 #include <sys/stat.h>
4 #include <fcntl.h>
5 #include <stdlib.h>
6 #include "common.h"
7
8 char * copystr(const char *buf) {
9   int i;
10   if (buf==NULL)
11     return NULL;
12   for(i=0;;i++)
13     if (buf[i]==0) {
14       char *ptr=(char*)malloc(i+1);
15       memcpy(ptr,buf,i+1);
16       return ptr;
17     }
18 }
19
20
21 unsigned int hashstring(char *strptr) {
22   unsigned int hashcode=0;
23   int *intptr=(int *) strptr;
24   if(intptr==NULL)
25     return 0;
26   while(1) {
27     int copy1=*intptr;
28     if((copy1&0xFF000000)&&
29        (copy1&0xFF0000)&&
30        (copy1&0xFF00)&&
31        (copy1&0xFF)) {
32       hashcode^=*intptr;
33       intptr++;
34     } else {
35       if (!copy1&0xFF000000)
36         hashcode^=copy1&0xFF000000;
37       else if (!copy1&0xFF0000)
38         hashcode^=copy1&0xFF0000;
39       else if (!copy1&0xFF00)
40         hashcode^=copy1&0xFF00;
41       else if (!copy1&0xFF)
42         hashcode^=copy1&0xFF;
43       return hashcode;
44     }
45   }
46 }
47
48 int equivalentstrings(char *str1, char *str2) {
49   if ((str1!=NULL)&&(str2!=NULL)) {
50     if (strcmp(str1,str2)!=0)
51       return 0;
52     else
53       return 1;
54   } else if ((str1==NULL)&&(str2==NULL))
55     return 1;
56   else return 0;
57 }
58