Просмотр исходного кода

Added replace() from celdrop

svn: 31
Ray Atkinson 23 лет назад
Родитель
Сommit
f7b513d7bf
4 измененных файлов с 34 добавлено и 1 удалено
  1. 30 0
      src/misc.c
  2. 1 0
      src/mod/module.h
  3. 2 1
      src/modules.c
  4. 1 0
      src/proto.h

+ 30 - 0
src/misc.c

@@ -2782,3 +2782,33 @@ char *degarble(int len, char *g)
   return (char *) garble_buffer[garble_ptr];
   return (char *) garble_buffer[garble_ptr];
 }
 }
 #endif
 #endif
+
+
+char *replace (char *string, char *oldie, char *newbie)
+{
+  static char newstring[1024] = "";
+  int str_index, newstr_index, oldie_index, end, new_len, old_len, cpy_len;
+  char *c;
+  if (string == NULL) return "";
+  if ((c = (char *) strstr(string, oldie)) == NULL) return string;
+  new_len = strlen(newbie);
+  old_len = strlen(oldie);
+  end = strlen(string) - old_len;
+  oldie_index = c - string;
+  newstr_index = 0;
+  str_index = 0;
+  while(str_index <= end && c != NULL) {
+    cpy_len = oldie_index-str_index;
+    strncpy(newstring + newstr_index, string + str_index, cpy_len);
+    newstr_index += cpy_len;
+    str_index += cpy_len;
+    strcpy(newstring + newstr_index, newbie);
+    newstr_index += new_len;
+    str_index += old_len;
+    if((c = (char *) strstr(string + str_index, oldie)) != NULL)
+     oldie_index = c - string;
+  }
+  strcpy(newstring + newstr_index, string + str_index);
+  return (newstring);
+}
+

+ 1 - 0
src/mod/module.h

@@ -526,6 +526,7 @@
 #define myip6 ((char *)(global[324]))
 #define myip6 ((char *)(global[324]))
 /* 325 - 328 */
 /* 325 - 328 */
 #define cmdprefix ((char *)(global[325]))
 #define cmdprefix ((char *)(global[325]))
+#define replace ((char*(*)(char *, char *, char *))global[326])
 
 
 
 
 /* This is for blowfish module, couldnt be bothered making a whole new .h
 /* This is for blowfish module, couldnt be bothered making a whole new .h

+ 2 - 1
src/modules.c

@@ -560,7 +560,8 @@ Function global_table[] =
   (Function) authkey,
   (Function) authkey,
   (Function) myip,
   (Function) myip,
   (Function) myip6,
   (Function) myip6,
-  (Function) cmdprefix
+  (Function) cmdprefix,
+  (Function) replace
 
 
 
 
 };
 };

+ 1 - 0
src/proto.h

@@ -216,6 +216,7 @@ char *progname();
 void init_settings();
 void init_settings();
 
 
 /* misc.c */
 /* misc.c */
+char *replace(char *, char *, char *);
 #ifdef S_GARBLESTRINGS
 #ifdef S_GARBLESTRINGS
 char *degarble(int, char *);
 char *degarble(int, char *);
 #endif
 #endif