00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057 #include <sys/types.h>
00058 #include <string.h>
00059 #include <stdlib.h>
00060 #include "gis.h"
00061
00062 #ifndef NULL
00063 #define NULL 0
00064 #endif
00065
00066 static char *G_strend (char *S)
00067 {
00068 while (*S)
00069 S++;
00070 return (S);
00071 }
00072
00073 char *G_strcpy (char *T, const char *F)
00074 {
00075 char *d = T;
00076
00077 while ((*d++ = *F++))
00078 ;
00079 return (T);
00080 }
00081
00082 char *G_chrcpy (char *T, const char *F, int n)
00083 {
00084 char *d = T;
00085
00086 while (n--)
00087 *d++ = *F++;
00088 *d = '\0';
00089 return (T);
00090 }
00091
00092 char *G_strncpy (char *T, const char *F, int n)
00093 {
00094 char *d = T;
00095
00096 while (n-- && *F)
00097 *d++ = *F++;
00098 *d = '\0';
00099 return (T);
00100 }
00101
00102 char *G_strmov (char *T, const char *F)
00103 {
00104 char *d = T;
00105
00106 while (*F)
00107 *d++ = *F++;
00108 return (T);
00109 }
00110
00111 char *G_chrmov (char *T, const char *F, int n)
00112 {
00113 char *d = T;
00114
00115 while (n--)
00116 *d++ = *F++;
00117 return (T);
00118 }
00119
00120 char *G_strcat (char *T, const char *F)
00121 {
00122 G_strcpy (G_strend (T), F);
00123 return (T);
00124 }
00125
00126 char *G_chrcat (char *T, const char *F, int n)
00127 {
00128 G_chrcpy (G_strend (T), F, n);
00129 return (T);
00130 }
00131
00132 int G_strcasecmp(const char *x, const char *y)
00133 {
00134 int xx,yy;
00135
00136 if (!x)
00137 return y ? -1 : 0;
00138 if (!y)
00139 return x ? 1 : 0;
00140 while (*x && *y)
00141 {
00142 xx = *x++;
00143 yy = *y++;
00144 if (xx >= 'A' && xx <= 'Z')
00145 xx = xx + 'a' - 'A';
00146 if (yy >= 'A' && yy <= 'Z')
00147 yy = yy + 'a' - 'A';
00148 if (xx < yy) return -1;
00149 if (xx > yy) return 1;
00150 }
00151 if (*x) return 1;
00152 if (*y) return -1;
00153 return 0;
00154 }
00155
00156 char *G_strstr(char *mainString, const char *subString)
00157 {
00158 const char *p;
00159 char *q;
00160 int length;
00161
00162 p = subString;
00163 q = mainString;
00164 length = strlen(subString);
00165
00166 do {
00167 while (*q != '\0' && *q != *p) {
00168 q++;
00169 }
00170 } while (*q != '\0' && strncmp(p, q, length) != 0 && q++);
00171
00172
00173 if (*q == '\0') {
00174 return NULL;
00175 } else {
00176 return q;
00177 }
00178 }
00179
00180
00181 char *G_strdup(const char *string)
00182 {
00183 char *p;
00184
00185 p = malloc(strlen(string) + 1);
00186
00187 if (p != NULL) {
00188 strcpy(p, string);
00189 }
00190
00191 return p;
00192 }
00193
00194
00195 char *G_strchg(char* bug, char character, char new) {
00196
00197
00198
00199 char *help = bug;
00200 while(*help) {
00201 if (*help==character)
00202 *help=new;
00203 help++;
00204 }
00205 return bug;
00206 }
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222 char *G_str_replace(char* buffer, const char* old_str, const char* new_str)
00223 {
00224
00225 char *B, *R;
00226 const char *N;
00227 char *replace;
00228 int count, len;
00229
00230
00231 if (old_str == NULL || new_str == NULL)
00232 return G_strdup (buffer);
00233
00234 if (buffer == NULL)
00235 return NULL;
00236
00237
00238 B = strstr (buffer, old_str);
00239 if (B == NULL)
00240
00241 return G_strdup (buffer);
00242
00243 if (strlen (new_str) > strlen (old_str)) {
00244
00245 count = 0;
00246 len = strlen (old_str);
00247 B = buffer;
00248 while(B != NULL && *B != '\0') {
00249 B = G_strstr (B, old_str);
00250 if (B != NULL) {
00251 B += len;
00252 count++;
00253 }
00254 }
00255
00256 len = count * (strlen(new_str) - strlen(old_str))
00257 + strlen(buffer);
00258
00259 }
00260 else
00261 len = strlen(buffer);
00262
00263
00264 replace = G_malloc (len + 1);
00265 if (replace == NULL)
00266 return NULL;
00267
00268
00269 B = buffer;
00270 R = replace;
00271 len = strlen (old_str);
00272 while(*B != '\0') {
00273 if (*B == old_str[0] && strncmp (B, old_str, len) == 0) {
00274 N = new_str;
00275 while (*N != '\0')
00276 *R++ = *N++;
00277 B += len;
00278 }
00279 else {
00280 *R++ = *B++;
00281 }
00282 }
00283 *R='\0';
00284
00285 return replace;
00286 }