ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/gclib/tophat_cpp/GBase.cpp
(Generate patch)
# Line 3 | Line 3
3   #include <ctype.h>
4   #include <sys/stat.h>
5  
6 + #ifndef S_ISDIR
7 + #define S_ISDIR(mode)  (((mode) & S_IFMT) == S_IFDIR)
8 + #endif
9 +
10 + #ifndef S_ISREG
11 + #define S_ISREG(mode)  (((mode) & S_IFMT) == S_IFREG)
12 + #endif
13 +
14   static char msg[4069];
15   /*
16   #ifdef _DEFINE_WIN32_FSEEKO
# Line 155 | Line 163
163    return copy;
164    }
165  
166 < int Gstrcmp(char* a, char* b) {
166 > int Gstrcmp(const char* a, const char* b, int n) {
167   if (a==NULL || b==NULL) {
168     return a==NULL ? -1 : 1;
169     }
170 < else return strcmp(a,b);
170 > else {
171 >   if (n<0) return strcmp(a,b);
172 >       else return strncmp(a,b,n);
173 > }
174 >
175   }
176  
177 < int Gstricmp(const char* a, const char* b) {
177 > int Gstricmp(const char* a, const char* b, int n) {
178   if (a==NULL || b==NULL) return a==NULL ? -1 : 1;
179   register int ua, ub;
180 < while ((*a!=0) && (*b!=0)) {
181 <  ua=tolower((unsigned char)*a);
182 <  ub=tolower((unsigned char)*b);
183 <  a++;b++;
184 <  if (ua!=ub) return ua < ub ? -1 : 1;
180 > if (n<0) {
181 >   while ((*a!=0) && (*b!=0)) {
182 >    ua=tolower((unsigned char)*a);
183 >    ub=tolower((unsigned char)*b);
184 >    a++;b++;
185 >    if (ua!=ub) return ua < ub ? -1 : 1;
186 >    }
187 >    return (*a == 0) ? ( (*b == 0) ? 0 : -1 ) : 1 ;
188 >  }
189 > else {
190 >   while (n && (*a!=0) && (*b!=0)) {
191 >    ua=tolower((unsigned char)*a);
192 >    ub=tolower((unsigned char)*b);
193 >    a++;b++;n--;
194 >    if (ua!=ub) return ua < ub ? -1 : 1;
195 >    }
196 >    //return (*a == 0) ? ( (*b == 0) ? 0 : -1 ) : 1 ;
197 >   if (n==0) return 0;
198 >   else { return (*a == 0) ? ( (*b == 0) ? 0 : -1 ) : 1 ; }
199    }
174  return (*a == 0) ? ( (*b == 0) ? 0 : -1 ) : 1 ;
200   }
201  
202   int strsplit(char* str, char** fields, int maxfields, const char* delim) {
# Line 489 | Line 514
514    if (slen==0) slen=strlen(str);
515    int l=0;
516    int r=slen-1;
517 <  register char c;
517 >  char c;
518    while (l<r) {
519       c=str[l];str[l]=str[r];
520       str[r]=c;
496     //swap(str[l],str[r]);
521       l++;r--;
522       }
523    return str;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines