Subversion Repositories wimsdev

Rev

Rev 3835 | Rev 8100 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3835 Rev 8082
Line 71... Line 71...
71
    int i;
71
    int i;
72
    for(i=0;!isspace(*p) && *p!=0 && i<MAX_LINELEN; p++,i++);
72
    for(i=0;!isspace(*p) && *p!=0 && i<MAX_LINELEN; p++,i++);
73
    return p;
73
    return p;
74
}
74
}
75
 
75
 
76
        /* searches a list. Returns index if found, -1 if nomatch.
76
/* searches a list. Returns index if found, (-1-index of insertion) if nomatch.
77
         * Uses binary search, list must be sorted. */
77
 * Uses binary search, list must be sorted. */
-
 
78
 
78
int search_list(void *list, int items, size_t item_size, const char *str)
79
int search_list(void *list, int items, size_t item_size, const char *str)
79
{
80
{
80
    int i1,i2,j,k;
81
 int i = 0;
81
    char **p;
82
 while (items > 0)
82
    char c;
-
 
83
   
83
   {
84
    if(items<=0) return -1;
84
     int m = items / 2, j = i + m;
85
    j=0; c=*str;
-
 
86
    p=list;
-
 
87
    k=**p-c; if(k==0) k=strcmp(*p,str);
-
 
88
    if(k==0) return k; if(k>0) return -1;
-
 
89
    p=list+(items-1)*item_size;
-
 
90
    k=**p-c; if(k==0) k=strcmp(*p,str);
85
     int k = strcmp(*(char **)(list + j * item_size), str);
91
    if(k==0) return items-1; if(k<0) return -1;
-
 
92
    for(i1=0,i2=items-1;i2>i1+1;) {
-
 
93
        j=i1+(i2-i1)/2;
-
 
94
        p=list+(j*item_size);
-
 
95
        k=**p-c; if(k==0) k=strcmp(*p,str);
-
 
96
        if(k==0) return j;
86
     if (k == 0) return j;
97
        if(k>0) {i2=j; continue;}
87
     if (k > 0) items = m; else {i = j + 1; items -= (m + 1);}
98
        if(k<0) {i1=j; continue;}      
-
 
99
    }
88
   }
100
    return -1;
89
 return ~i;
101
}
90
}
102
 
91
 
103
        /* get the content of a file, and store in buf. */
92
        /* get the content of a file, and store in buf. */
104
int getfile(char *fname, unsigned char **buf)
93
int getfile(char *fname, unsigned char **buf)
105
{
94
{
106
    FILE *f;
95
    FILE *f;
107
    long l, l2;
96
    long l, l2;
108
   
97
 
109
    f=fopen(fname,"r"); if(f==NULL) return -1;
98
    f=fopen(fname,"r"); if(f==NULL) return -1;
110
    fseek(f,0,SEEK_END); l=ftell(f); fseek(f,0,SEEK_SET);
99
    fseek(f,0,SEEK_END); l=ftell(f); fseek(f,0,SEEK_SET);
111
    if(l>FILE_LENGTH_LIMIT || l<=0) {
100
    if(l>FILE_LENGTH_LIMIT || l<=0) {
112
        fclose(f); return -1;
101
        fclose(f); return -1;
113
    }
102
    }