revert runtime file.
[repair.git] / Repair / RepairInterpreter / common.cc
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 #include "classlist.h"
8
9 char * copystr(const char *buf) {
10   int i;
11   if (buf==NULL)
12     return NULL;
13   for(i=0;;i++)
14     if (buf[i]==0) {
15       char *ptr=new char[i+1];
16       memcpy(ptr,buf,i+1);
17       return ptr;
18     }
19 }
20
21
22 unsigned int hashstring(char *strptr) {
23   unsigned int hashcode=0;
24   int *intptr=(int *) strptr;
25   if(intptr==NULL)
26     return 0;
27   while(1) {
28     int copy1=*intptr;
29     if((copy1&0xFF000000)&&
30        (copy1&0xFF0000)&&
31        (copy1&0xFF00)&&
32        (copy1&0xFF)) {
33       hashcode^=*intptr;
34       intptr++;
35     } else {
36       if (!copy1&0xFF000000)
37         hashcode^=copy1&0xFF000000;
38       else if (!copy1&0xFF0000)
39         hashcode^=copy1&0xFF0000;
40       else if (!copy1&0xFF00)
41         hashcode^=copy1&0xFF00;
42       else if (!copy1&0xFF)
43         hashcode^=copy1&0xFF;
44       return hashcode;
45     }
46   }
47 }
48
49 int equivalentstrings(char *str1, char *str2) {
50   if ((str1!=NULL)&&(str2!=NULL)) {
51     if (strcmp(str1,str2)!=0)
52       return 0;
53     else
54       return 1;
55   } else if ((str1==NULL)&&(str2==NULL))
56     return 1;
57   else return 0;
58 }
59