Bläddra i källkod

Merge branch 'improve-build-portability'

* improve-build-portability:
  * Make makesort use bdlib
  * Use String::dup where appropriate
  * Optimize some substring calls using new bdlib interface
  * Use bdlib for makeres
  * Use bdlib for makehelp
  * Convert 'makeset' to using bdlib instead of STL
Bryan Drewery 16 år sedan
förälder
incheckning
62aacd3726
11 ändrade filer med 218 tillägg och 562 borttagningar
  1. 8 4
      Makefile.in
  2. 1 1
      lib/bdlib
  3. 8 8
      src/EncryptedStream.c
  4. 8 8
      src/Makefile.in
  5. 55 161
      src/makehelp.c
  6. 50 160
      src/makeres.c
  7. 14 19
      src/makeset.c
  8. 0 0
      src/makesort.c
  9. 6 9
      src/misc.c
  10. 2 2
      src/mod/server.mod/servmsg.c
  11. 66 190
      src/sorthelp.c

+ 8 - 4
Makefile.in

@@ -215,24 +215,28 @@ checkclean.debug:
 	fi)
 	fi)
 	@touch stamp.debug
 	@touch stamp.debug
 
 
-wraith:	checkclean.wraith general
+lib:
+	+@cd lib && $(MAKE)
+
+wraith:	checkclean.wraith lib general
 	@echo ""
 	@echo ""
 	@echo "Making binary"
 	@echo "Making binary"
 	@echo ""
 	@echo ""
 	@echo ""
 	@echo ""
-	+@cd lib && $(MAKE)
 	+@cd src/mod && $(MAKE_BIN) static
 	+@cd src/mod && $(MAKE_BIN) static
 	+@cd src && $(MAKE_BIN) $(BINEXEC)
 	+@cd src && $(MAKE_BIN) $(BINEXEC)
 	@echo ""
 	@echo ""
 
 
 dwraith: debug
 dwraith: debug
 
 
-debug: checkclean.debug general
+lib.debug:
+	+@cd lib && $(MAKE) debug
+
+debug: checkclean.debug lib.debug general
 	@echo ""
 	@echo ""
 	@echo "Making debug binary"
 	@echo "Making debug binary"
 	@echo ""
 	@echo ""
 	@echo ""
 	@echo ""
-	+@cd lib && $(MAKE) debug
 	+@cd src/mod && $(MAKE_DEBUG) static
 	+@cd src/mod && $(MAKE_DEBUG) static
 	+@cd src && $(MAKE_DEBUG) $(BINEXEC)
 	+@cd src && $(MAKE_DEBUG) $(BINEXEC)
 	@echo ""
 	@echo ""

+ 1 - 1
lib/bdlib

@@ -1 +1 @@
-Subproject commit e5cd7b1121b3ffdd0b34b9e4f2b20ad0b7197b24
+Subproject commit 8f5f65508f2009ea5ed4fad659808fcf9e6b4cf0

+ 8 - 8
src/EncryptedStream.c

@@ -22,18 +22,18 @@ int EncryptedStream::loadFile (const int fd) {
   /* Peak at the first few bytes to determine the algorithm used */
   /* Peak at the first few bytes to determine the algorithm used */
   if (str[0] == 0x7F && str[2] == 0x7F) {
   if (str[0] == 0x7F && str[2] == 0x7F) {
     enc_flags = str[1];
     enc_flags = str[1];
-    in_buf = str(3, str.length() - 3);
+    in_buf = str(3);
   } else {
   } else {
     enc_flags |= ENC_NO_HEADER;
     enc_flags |= ENC_NO_HEADER;
 
 
     // Old socksfile format?
     // Old socksfile format?
     if (bd::String(str(0, 5)) == "+enc\n") {
     if (bd::String(str(0, 5)) == "+enc\n") {
       enc_flags |= (ENC_KEEP_NEWLINES|ENC_AES_256_ECB|ENC_BASE64_BROKEN);
       enc_flags |= (ENC_KEEP_NEWLINES|ENC_AES_256_ECB|ENC_BASE64_BROKEN);
-      in_buf = str(5, str.length() - 5);
+      in_buf = str(5);
     } else {
     } else {
       /* Peak at the first block to see if it matches a userfile or an old conf file */
       /* Peak at the first block to see if it matches a userfile or an old conf file */
-      bd::String peek(decrypt_string(key, broken_base64Decode(str(0, 32))));
-      if (peek(0, 4) == "#4v:" || peek(0, 2) == "! ")
+      bd::String my_peek(decrypt_string(key, broken_base64Decode(str(0, 32))));
+      if (my_peek(0, 4) == "#4v:" || my_peek(0, 2) == "! ")
         enc_flags |= (ENC_KEEP_NEWLINES|ENC_AES_256_ECB|ENC_BASE64_BROKEN);
         enc_flags |= (ENC_KEEP_NEWLINES|ENC_AES_256_ECB|ENC_BASE64_BROKEN);
       in_buf = str;
       in_buf = str;
     }
     }
@@ -65,9 +65,9 @@ int EncryptedStream::loadFile (const int fd) {
 
 
 void EncryptedStream::apply_filters(bd::String& buf, const bd::String& IV) const {
 void EncryptedStream::apply_filters(bd::String& buf, const bd::String& IV) const {
   if (enc_flags & ENC_AES_256_CBC) {
   if (enc_flags & ENC_AES_256_CBC) {
-    unsigned char* iv = (unsigned char*) strdup(IV.c_str());
+    unsigned char* iv = (unsigned char*) IV.dup();
     buf = encrypt_string_cbc(key, buf, iv);
     buf = encrypt_string_cbc(key, buf, iv);
-    free(iv);
+    delete[] iv;
   } else if (enc_flags & ENC_AES_256_ECB)
   } else if (enc_flags & ENC_AES_256_ECB)
     buf = encrypt_string(key, buf);
     buf = encrypt_string(key, buf);
 
 
@@ -84,9 +84,9 @@ void EncryptedStream::unapply_filters(bd::String& buf, const bd::String& IV) con
     buf = bd::base64Decode(buf);
     buf = bd::base64Decode(buf);
 
 
   if (enc_flags & ENC_AES_256_CBC) {
   if (enc_flags & ENC_AES_256_CBC) {
-    unsigned char* iv = (unsigned char*) strdup(IV.c_str());
+    unsigned char* iv = (unsigned char*) IV.dup();
     buf = decrypt_string_cbc(key, buf, iv);
     buf = decrypt_string_cbc(key, buf, iv);
-    free(iv);
+    delete[] iv;
   }
   }
   else if (enc_flags & ENC_AES_256_ECB)
   else if (enc_flags & ENC_AES_256_ECB)
     buf = decrypt_string(key, buf);
     buf = decrypt_string(key, buf);

+ 8 - 8
src/Makefile.in

@@ -68,24 +68,24 @@ blah:
 	@echo "Use the build script."
 	@echo "Use the build script."
 	@echo ""
 	@echo ""
 
 
-makeres: makeres.c
+makeres: makeres.c ../lib/bdlib/src/libbdlib.a
 	@echo -e "Compiling: \033[1mmakeres\033[0m"
 	@echo -e "Compiling: \033[1mmakeres\033[0m"
-	@$(CXX) $(CXXFLAGS) -I$(top_srcdir) -I$(top_srcdir)/pack $(CPPFLAGS) makeres.c -o makeres
+	@$(CXX) $(CXXFLAGS) -I$(top_srcdir) -I$(top_srcdir)/pack $(CPPFLAGS) makeres.c ../lib/bdlib/src/libbdlib.a -o makeres
 	@$(STRIP) makeres@EXEEXT@
 	@$(STRIP) makeres@EXEEXT@
 
 
-makeset: makeset.c
+makeset: makeset.c ../lib/bdlib/src/libbdlib.a
 	@echo -e "Compiling: \033[1mmakeset\033[0m"
 	@echo -e "Compiling: \033[1mmakeset\033[0m"
-	@$(CXX) $(CXXFLAGS) -I$(top_srcdir) -I$(top_srcdir)/pack $(CPPFLAGS) makeset.c -o makeset
+	@$(CXX) $(CXXFLAGS) -I$(top_srcdir) -I$(top_srcdir)/pack $(CPPFLAGS) makeset.c ../lib/bdlib/src/libbdlib.a -o makeset
 	@$(STRIP) makeset@EXEEXT@
 	@$(STRIP) makeset@EXEEXT@
 
 
-makehelp: makehelp.c
+makehelp: makehelp.c ../lib/bdlib/src/libbdlib.a
 	@echo -e "Compiling: \033[1mmakehelp\033[0m"
 	@echo -e "Compiling: \033[1mmakehelp\033[0m"
-	@$(CXX) $(CXXFLAGS) -I$(top_srcdir) -I$(top_srcdir)/pack $(CPPFLAGS) makehelp.c -o makehelp
+	@$(CXX) $(CXXFLAGS) -I$(top_srcdir) -I$(top_srcdir)/pack $(CPPFLAGS) makehelp.c ../lib/bdlib/src/libbdlib.a -o makehelp
 	@$(STRIP) makehelp@EXEEXT@
 	@$(STRIP) makehelp@EXEEXT@
 
 
-sorthelp: sorthelp.c
+sorthelp: sorthelp.c ../lib/bdlib/src/libbdlib.a
 	@echo -e "Compiling: \033[1msorthelp\033[0m"
 	@echo -e "Compiling: \033[1msorthelp\033[0m"
-	@$(CXX) $(CXXFLAGS) -I$(top_srcdir) -I$(top_srcdir)/pack $(CPPFLAGS) sorthelp.c -o sorthelp
+	@$(CXX) $(CXXFLAGS) -I$(top_srcdir) -I$(top_srcdir)/pack $(CPPFLAGS) sorthelp.c ../lib/bdlib/src/libbdlib.a -o sorthelp
 	@$(STRIP) sorthelp@EXEEXT@
 	@$(STRIP) sorthelp@EXEEXT@
 
 
 stringfix: stringfix.c common.h ../config.h eggdrop.h
 stringfix: stringfix.c common.h ../config.h eggdrop.h

+ 55 - 161
src/makehelp.c

@@ -1,85 +1,12 @@
 
 
+#include <bdlib/src/String.h>
+#include <bdlib/src/Stream.h>
 #include <string.h>
 #include <string.h>
 #include <stdio.h>
 #include <stdio.h>
 #include <ctype.h>
 #include <ctype.h>
 #include <stdlib.h>
 #include <stdlib.h>
 
 
-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 = NULL;
-
-  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);
-}
-
-
-char *step_thru_file(FILE *fd)
-{
-  char tempBuf[1024] = "";
-  char *retStr = NULL;
-
-  if (fd == NULL) {
-    return NULL;
-  }
-  retStr = NULL;
-  while (!feof(fd)) {
-    if (fgets(tempBuf, sizeof(tempBuf), fd) && !feof(fd)) {
-      if (retStr == NULL) {
-        retStr = (char *) calloc(1, strlen(tempBuf) + 2);
-        strcpy(retStr, tempBuf);
-      } else {
-        retStr = (char *) realloc(retStr, strlen(retStr) + strlen(tempBuf));
-        strcat(retStr, tempBuf);
-      }
-      if (retStr[strlen(retStr)-1] == '\n') {
-        retStr[strlen(retStr)-1] = 0;
-        break;
-      }
-    }
-  }
-  return retStr;
-}
-
-char *newsplit(char **rest)
-{
-  register char *o, *r;
-
-  if (!rest)
-    return *rest = "";
-  o = *rest;
-  while (*o == ' ')
-    o++;
-  r = o;
-  while (*o && (*o != ' '))
-    o++;
-  if (*o)
-    *o++ = 0;
-  *rest = o;
-  return r;
-}
-
-int skipline (char *line, int *skip) {
+int skipline (const char *line, int *skip) {
   static int multi = 0;
   static int multi = 0;
   if ((!strncmp(line, "//", 2))) {
   if ((!strncmp(line, "//", 2))) {
     (*skip)++;
     (*skip)++;
@@ -99,109 +26,76 @@ int skipline (char *line, int *skip) {
 
 
 #define type(hub, leaf) (hub ? 1 : (leaf ? 2 : 0))
 #define type(hub, leaf) (hub ? 1 : (leaf ? 2 : 0))
 
 
-int parse_help(char *infile, char *outfile) {
-  FILE *in = NULL, *out = NULL;
-  char *buffer = NULL, *cmd = NULL;
-  int skip = 0, line = 0, leaf = 0, hub = 0;
+int parse_help(bd::String infile, bd::String outfile) {
+  bd::Stream in, out;
+  bd::String buffer, cmd, buf;
+  size_t pos = 0;
+  int skip = 0, leaf = 0, hub = 0;
 
 
-  if (!(in = fopen(infile, "r"))) {
-    printf("Error: Cannot open '%s' for reading\n", infile);
-    return 1;
-  }
-  if (!(out = fopen(outfile, "w"))) {
-    printf("Error: Cannot open '%s' for writing\n", outfile);
-    return 1;
-  }
-  printf("Parsing help file '%s'", infile);
-  fprintf(out, "/* DO NOT EDIT THIS FILE, EDIT doc/help.txt INSTEAD */\n#ifndef HELP_H\n\
+  in.loadFile(infile);
+  printf("Parsing help file '%s'", infile.c_str());
+  out <<  buf.printf("/* DO NOT EDIT THIS FILE, EDIT doc/help.txt INSTEAD */\n#ifndef HELP_H\n\
 #define HELP_H\n\
 #define HELP_H\n\
-#define STR(x) x\n\
 #include \"cmds.h\"\n\
 #include \"cmds.h\"\n\
 \n\
 \n\
 help_t help[] = \n\
 help_t help[] = \n\
 { \n");
 { \n");
-  while ((!feof(in)) && ((buffer = step_thru_file(in)) != NULL) ) {
-    line++;
-    if ((*buffer)) {
-      if (strchr(buffer, '\n')) *(char*)strchr(buffer, '\n') = 0;
-      if ((skipline(buffer, &skip))) continue;
-      if (buffer[0] == ':') { /* New cmd */
-        char *ifdef = (char *) calloc(1, strlen(buffer) + 1), *p = NULL;
-        int cl = 0, doleaf = 0, dohub = 0;
+  while (in.tell() < in.length()) {
+    buffer = in.getline().chomp();
 
 
-        buffer++;
-        strcpy(ifdef, buffer);
-        p = strchr(ifdef, ':');
-        *p = 0;
-        if (ifdef && ifdef[0]) {
-          if (!strcasecmp(ifdef, "leaf")) {
-            if (hub) { cl = 1; hub = 0; }
-            if (!leaf) {
-              doleaf = leaf = 1;
-            }
-          } else if (!strcasecmp(ifdef, "hub")) {
-            if (leaf) { cl = 1; hub = 0; }
-            if (!hub) {
-              dohub = hub = 1;
-            }
-          }
-        } else { if (leaf || hub) { cl = 1; } leaf = 0; hub = 0;  }
+    if ((skipline(buffer.c_str(), &skip))) continue;
 
 
-        if (cmd && cmd[0]) {		/* CLOSE LAST CMD */
-          if (strchr(cmd, ':'))		/* garbled */
-            fprintf(out,"\")},\n");
-          else
-            fprintf(out,"\"},\n");
-//          if (cl) { cl = 0; fprintf(out, "#endif\n"); }
-//          if (dohub) { dohub = 0; fprintf(out, "#ifdef HUB\n"); }
-//          else if (doleaf) { doleaf = 0; fprintf(out, "#ifdef LEAF\n"); }
-          free(cmd);
-        }
-        p = strchr(buffer, ':');
-        p++;
-        if (strcmp(p, "end")) {		/* NEXT CMD */
-          cmd = (char *) calloc(1, strlen(p) + 1);
+    if (buffer[0] == ':') { /* New cmd */
+      bd::String ifdef(buffer.length());
+      int cl = 0, doleaf = 0, dohub = 0;
 
 
-          strcpy(cmd, p);
-          printf(".");
-//          if (dohub) { dohub = 0; fprintf(out, "#ifdef HUB\n"); }
-//          else if (doleaf) { doleaf = 0; fprintf(out, "#ifdef LEAF\n"); }
-          if (strchr(cmd, ':')) {
-            char *p2 = NULL, *cmdn = (char *) calloc(1,strlen(cmd) + 1);
+      ++buffer;
+      ifdef = newsplit(buffer, ':');
 
 
-            strcpy(cmdn, cmd);
-            p2 = strchr(cmdn, ':');
-            *p2 = 0;
-            fprintf(out, "  {%d, \"%s\", STR(\"", type(dohub, doleaf), cmdn);
-          } else
-            fprintf(out, "  {%d, \"%s\", 0, \"", type(dohub, doleaf), cmd);
-        } else {			/* END */
-          fprintf(out, "  {0, NULL, 0, NULL}\n};\n");
+      if (ifdef.length()) {
+        if (ifdef == "leaf") {
+          if (hub) { cl = 1; hub = 0; }
+          if (!leaf) {
+            doleaf = leaf = 1;
+          }
+        } else if (ifdef == "hub") {
+          if (leaf) { cl = 1; hub = 0; }
+          if (!hub) {
+            dohub = hub = 1;
+          }
         }
         }
-      } else {				/* CMD HELP INFO */
-        fprintf(out, "%s\\n", replace(buffer, "\"", "\\\""));
+      } else { if (leaf || hub) { cl = 1; } leaf = 0; hub = 0;  }
+
+      if (cmd.length()) {		/* CLOSE LAST CMD */
+        if (cmd.find(':') != bd::String::npos)		/* garbled */
+          out << "\")},\n";
+        else
+          out << "\"},\n";
+        cmd.clear();
+      }
+
+      cmd = newsplit(buffer, ':');
+      if (cmd != "end") {		/* NEXT CMD */
+        printf(".");
+        if ((pos = cmd.find(':')) != bd::String::npos)
+          cmd = cmd(0, pos);
+        out << buf.printf("  {%d, \"%s\", 0, \"", type(dohub, doleaf), cmd.c_str());
+      } else {			/* END */
+        out << "  {0, NULL, 0, NULL}\n};\n";
       }
       }
+    } else {				/* CMD HELP INFO */
+      out << buf.printf("%s\\n", buffer.sub("\"", "\\\"").c_str());
     }
     }
-    buffer = NULL;
   }
   }
-  fprintf(out, "#endif /* HELP_H */\n");
+  out << "#endif /* HELP_H */\n";
   printf(" Success\n");
   printf(" Success\n");
-  if (in) fclose(in);
-  if (out) fclose(out);
+
+  out.writeFile(outfile);
   return 0;
   return 0;
 }
 }
 
 
 int main(int argc, char **argv) {
 int main(int argc, char **argv) {
-  char *in = NULL, *out = NULL;
-  int ret = 0;
-
   if (argc < 3) return 1;
   if (argc < 3) return 1;
-  in = (char *) calloc(1, strlen(argv[1]) + 1);
-  strcpy(in, argv[1]);
-  out = (char *) calloc(1, strlen(argv[2]) + 1);
-  strcpy(out, argv[2]);
-  ret = parse_help(in, out);
-  free(in);
-  free(out);
-  return ret;
+  bd::String in(argv[1]), out(argv[2]);
+  return parse_help(in, out);
 }
 }

+ 50 - 160
src/makeres.c

@@ -1,101 +1,13 @@
 
 
+#include <bdlib/src/String.h>
+#include <bdlib/src/Stream.h>
 #include <string.h>
 #include <string.h>
 #include <stdio.h>
 #include <stdio.h>
 #include <ctype.h>
 #include <ctype.h>
 #include <stdlib.h>
 #include <stdlib.h>
+#include <algorithm>
 
 
-static char lower_resps[1024] = "";
-
-char *strtoupper(char *string)
-{
-  static char ret[51] = "";
-  int i = 0;
-
-  while (*string) {
-    ret[i] = toupper(*string);
-    i++;
-    string++;
-    ret[i] = 0;
-  }
-  return ret;
-}
-
-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 = NULL;
-
-  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);
-}
-
-
-char *step_thru_file(FILE *fd)
-{
-  char tempBuf[1024] = "";
-  char *retStr = NULL;
-
-  if (fd == NULL) {
-    return NULL;
-  }
-  retStr = NULL;
-  while (!feof(fd)) {
-    if (fgets(tempBuf, sizeof(tempBuf), fd) && !feof(fd)) {
-      if (retStr == NULL) {
-        retStr = (char *) calloc(1, strlen(tempBuf) + 2);
-        strcpy(retStr, tempBuf);
-      } else {
-        retStr = (char *) realloc(retStr, strlen(retStr) + strlen(tempBuf));
-        strcat(retStr, tempBuf);
-      }
-      if (retStr[strlen(retStr)-1] == '\n') {
-        retStr[strlen(retStr)-1] = 0;
-        break;
-      }
-    }
-  }
-  return retStr;
-}
-
-char *newsplit(char **rest)
-{
-  register char *o, *r;
-
-  if (!rest)
-    return *rest = "";
-  o = *rest;
-  while (*o == ' ')
-    o++;
-  r = o;
-  while (*o && (*o != ' '))
-    o++;
-  if (*o)
-    *o++ = 0;
-  *rest = o;
-  return r;
-}
-
-int skipline (char *line, int *skip) {
+int skipline (const char *line, int *skip) {
   static int multi = 0;
   static int multi = 0;
   if ((!strncmp(line, "//", 2))) {
   if ((!strncmp(line, "//", 2))) {
     (*skip)++;
     (*skip)++;
@@ -113,95 +25,73 @@ int skipline (char *line, int *skip) {
   return (*skip);
   return (*skip);
 }
 }
 
 
-int parse_res(char *in, char *out, char *outs) {
-  FILE *inf = NULL, *outf = NULL, *outsf = NULL;
-  char *buffer = NULL, *cmd = NULL;
-  int skip = 0, line = 0, total_responses = 0;
+int parse_res(const bd::String& inFile, const bd::String& outFile, const bd::String& outsFile) {
+  bd::Stream in, out, outs;
+  bd::String buffer, cmd, buf, lower_resps;
 
 
-  if (!(inf = fopen(in, "r"))) {
-    printf("Error: Cannot open '%s' for reading\n", in);
-    return 1;
-  }
-  if (!(outf = fopen(out, "w"))) {
-    printf("Error: Cannot open '%s' for writing\n", out);
-    return 1;
-  }
-  if (!(outsf = fopen(outs, "w"))) {
-    printf("Error: Cannot open '%s' for writing\n", outs);
-    return 1;
-  }
-  printf("Parsing res file '%s'", in);
+  int skip = 0, total_responses = 0;
 
 
-  fprintf(outf, "/* DO NOT EDIT THIS FILE. */\n\
+  in.loadFile(inFile);
+  printf("Parsing res file '%s'", inFile.c_str());
+
+  out << buf.printf( "/* DO NOT EDIT THIS FILE. */\n\
 #ifndef _RESPONSE_H\n\
 #ifndef _RESPONSE_H\n\
 #define _RESPONSE_H\n\
 #define _RESPONSE_H\n\
 \n\
 \n\
 typedef unsigned int response_t;\n\n\
 typedef unsigned int response_t;\n\n\
 enum {\n");
 enum {\n");
 
 
-  fprintf(outsf, "/* DO NOT EDIT THIS FILE. */\n\
+  outs << buf.printf("/* DO NOT EDIT THIS FILE. */\n\
 #ifndef _RESPONSES_H\n\
 #ifndef _RESPONSES_H\n\
 #define _RESPONSES_H\n\
 #define _RESPONSES_H\n\
 \n\
 \n\
 typedef const char * res_t;\n\n");
 typedef const char * res_t;\n\n");
 
 
-  while ((!feof(inf)) && ((buffer = step_thru_file(inf)) != NULL) ) {
-    line++;
-    if ((*buffer)) {
-      if (strchr(buffer, '\n')) *(char*)strchr(buffer, '\n') = 0;
-      if ((skipline(buffer, &skip))) continue;
-      if (buffer[0] == ':') { /* New cmd */
-        char *p = NULL;
-
-        if (cmd && cmd[0]) {		/* CLOSE LAST RES */
-          fprintf(outf, ",\n");	/* for enum */
-          fprintf(outsf, "\tNULL\n};\n\n");
-          free(cmd);
-        }
-        p = strchr(buffer, ':');
-        p++;
-        if (strcmp(p, "end")) {		/* NEXT RES */
-          cmd = (char *) calloc(1, strlen(p) + 1);
-
-          total_responses++;
-          strcpy(cmd, p);
-          printf(".");
+  while (in.tell() < in.length()) {
+    buffer = in.getline().chomp();
+    if ((skipline(buffer.c_str(), &skip))) continue;
+    if (buffer[0] == ':') { /* New cmd */
+      if (cmd.length()) {		/* CLOSE LAST RES */
+        out << ",\n";	/* for enum */
+        outs << "\tNULL\n};\n\n";
+        cmd.clear();
+      }
 
 
-          fprintf(outf, "\tRES_%s", strtoupper(cmd));
-          if (total_responses == 1)
-            fprintf(outf, " = 1");
-          fprintf(outsf, "static res_t res_%s[] = {\n", cmd);
-          sprintf(&lower_resps[strlen(lower_resps)], ",\n\tres_%s", cmd);
-        } else {			/* END */
-          fprintf(outf, "\tRES_END\n};\n\n#define RES_TYPES %d\n", total_responses);
-          fprintf(outf, "const char *response(response_t);\nvoid init_responses();\nconst char *r_banned(struct chanset_t* chan);\n\n#endif /* !_RESPONSE_H */\n");
-          fprintf(outsf, "static res_t *res[] = {\n\tNULL%s\n};\n#endif /* !_RESPONSES_H */\n", lower_resps);
-        }
-      } else {				/* NEXT RES TEXT */
-        buffer++;
-        fprintf(outsf, "\t\"%s\",\n", buffer);
-/*        fprintf(outf, "%s\\n", replace(buffer, "\"", "\\\"")); */
+      cmd = buffer(1);
+      if (cmd != "end") {		/* NEXT RES */
+        ++total_responses;
+        printf(".");
+
+        bd::String cmdUpper(cmd);
+        std::transform(cmdUpper.begin(), cmdUpper.end(), cmdUpper.mdata(), (int(*)(int)) toupper);
+        out << buf.printf("\tRES_%s", cmdUpper.c_str());
+        if (total_responses == 1)
+          out << " = 1";
+        outs << buf.printf("static res_t res_%s[] = {\n", cmd.c_str());
+        lower_resps += buf.printf(",\n\tres_%s", cmd.c_str());
+      } else {			/* END */
+        out << buf.printf("\tRES_END\n};\n\n#define RES_TYPES %d\n", total_responses);
+        out << buf.printf("const char *response(response_t);\nvoid init_responses();\nconst char *r_banned(struct chanset_t* chan);\n\n#endif /* !_RESPONSE_H */\n");
+        outs << buf.printf("static res_t *res[] = {\n\tNULL%s\n};\n#endif /* !_RESPONSES_H */\n", lower_resps.c_str());
       }
       }
+    } else {				/* NEXT RES TEXT */
+      ++buffer;
+      outs << buf.printf("\t\"%s\",\n", buffer.c_str());
     }
     }
-    buffer = NULL;
   }
   }
   printf(" Success\n");
   printf(" Success\n");
-  if (inf) fclose(inf);
-  if (outf) fclose(outf);
-  if (outsf) fclose(outsf);
+
+  out.writeFile(outFile);
+  outs.writeFile(outsFile);
   return 0;
   return 0;
 }
 }
 
 
 int main(int argc, char **argv) {
 int main(int argc, char **argv) {
-  char *in = NULL, out[1024] = "", outs[1024] = "";
-  int ret = 0;
-
   if (argc < 3) return 1;
   if (argc < 3) return 1;
-  in = (char *) calloc(1, strlen(argv[1]) + 1);
-  strcpy(in, argv[1]);
-  sprintf(out, "%s/response.h%s", argv[2], argc == 4 ? "~" : "");
-  sprintf(outs, "%s/responses.h%s", argv[2], argc == 4 ? "~" : "");
-  ret = parse_res(in, out, outs);
-  free(in);
-  return ret;
+
+  bd::String in(argv[1]), out, outs;
+
+  out.printf("%s/response.h%s", argv[2], argc == 4 ? "~" : "");
+  outs.printf("%s/responses.h%s", argv[2], argc == 4 ? "~" : "");
+  return parse_res(in, out, outs);
 }
 }

+ 14 - 19
src/makeset.c

@@ -1,6 +1,5 @@
-#include <iostream>
-#include <fstream>
-#include <string>
+#include <bdlib/src/Stream.h>
+#include <bdlib/src/String.h>
 #include <cctype>
 #include <cctype>
 #include <algorithm>
 #include <algorithm>
 #include <cstring>
 #include <cstring>
@@ -10,41 +9,37 @@ int main(int argc, char *argv[]) {
   if (argc == 2)
   if (argc == 2)
     return 1;
     return 1;
 
 
-  fstream file;
-  ofstream out;
-  file.open(argv[1]);
-  out.open(argv[2]);
+  bd::Stream file, out;
+  file.loadFile(argv[1]);
 
 
-
-  char line[1024] = "";
-  string type;
+  bd::String type, line;
   char c;
   char c;
 
 
-  while (file.getline(line, sizeof(line))) {
+  while (file.tell() < file.length()) {
+    line = file.getline().chomp();
     if (line[0] == '#') continue;
     if (line[0] == '#') continue;
     if (line[0] == ':') {
     if (line[0] == ':') {
-      type = &line[1];
+      type = line(1);
       if (type == "end")
       if (type == "end")
         break;
         break;
 
 
-      transform(type.begin(), type.end(), type.begin(), (int(*)(int)) toupper);
+      transform(type.begin(), type.end(), type.mdata(), (int(*)(int)) toupper);
 
 
       type = "DEFAULT_" + type;
       type = "DEFAULT_" + type;
-      out << "#define " << type << " \"\\" << endl;
+      out << "#define " << type << " \"\\" << "\n";
     } else {
     } else {
       if (!type.length()) 
       if (!type.length()) 
         continue;
         continue;
 
 
       out << line;
       out << line;
-      c = file.peek();
+      c = file.peek()[0];
       if (strchr("\n:", c)) {
       if (strchr("\n:", c)) {
-        out << "\"\n" << endl;
+        out << "\"\n\n";
         type = "";
         type = "";
       } else
       } else
-        out << ",\\" << endl;
+        out << ",\\\n";
     }
     }
   }
   }
 
 
-  file.close();
-  out.close();
+  out.writeFile(argv[2]);
 }
 }

+ 0 - 0
src/makesort.c


+ 6 - 9
src/misc.c

@@ -652,11 +652,11 @@ readsocks(const char *fname)
     else if (type == STR("+buildts"))
     else if (type == STR("+buildts"))
       old_buildts = strtol(str.c_str(), NULL, 10);
       old_buildts = strtol(str.c_str(), NULL, 10);
     else if (type == STR("+botname"))
     else if (type == STR("+botname"))
-      nick = strdup(str.c_str());
+      nick = str.dup();
     else if (type == STR("+ip4"))
     else if (type == STR("+ip4"))
-      ip4 = strdup(str.c_str());
+      ip4 = str.dup();
     else if (type == STR("+ip6"))
     else if (type == STR("+ip6"))
-      ip6 = strdup(str.c_str());
+      ip6 = str.dup();
     else if (type == STR("+serv_cache")) {
     else if (type == STR("+serv_cache")) {
       if (!cached_005 && str.find(STR("005")))
       if (!cached_005 && str.find(STR("005")))
         cached_005 = 1;
         cached_005 = 1;
@@ -695,16 +695,13 @@ readsocks(const char *fname)
       reset_chans = 1;
       reset_chans = 1;
     }
     }
   }
   }
-  if (nick)
-    free(nick);
+  delete[] nick;
+  delete[] ip4;
+  delete[] ip6;
   if (jnick)
   if (jnick)
     free(jnick);
     free(jnick);
   if (socksfile)
   if (socksfile)
     free(socksfile);
     free(socksfile);
-  if (ip4)
-    free(ip4);
-  if (ip6)
-    free(ip6);
 }
 }
 
 
 
 

+ 2 - 2
src/mod/server.mod/servmsg.c

@@ -1835,7 +1835,7 @@ static void server_dns_callback(int id, void *client_data, const char *host, bd:
       goto fatal_dns;
       goto fatal_dns;
     }
     }
   }
   }
-  ip = strdup(ip_from_dns.c_str());
+  ip = ip_from_dns.dup();
 
 
   get_addr(ip, &addr);
   get_addr(ip, &addr);
  
  
@@ -1882,7 +1882,7 @@ static void server_dns_callback(int id, void *client_data, const char *host, bd:
     /* Wait for async result now */
     /* Wait for async result now */
   }
   }
 
 
-  free(ip);
+  delete[] ip;
   return;
   return;
 
 
 fatal_dns:
 fatal_dns:

+ 66 - 190
src/sorthelp.c

@@ -1,116 +1,21 @@
-/*
- * Copyright (C) 1997 Robey Pointer
- * Copyright (C) 1999 - 2002 Eggheads Development Team
- * Copyright (C) 2002 - 2008 Bryan Drewery
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
- */
-
-
 #include <string.h>
 #include <string.h>
 #include <stdio.h>
 #include <stdio.h>
 #include <ctype.h>
 #include <ctype.h>
 #include <stdlib.h>
 #include <stdlib.h>
+#include <bdlib/src/String.h>
+#include <bdlib/src/Stream.h>
 
 
 typedef struct {
 typedef struct {
   int leaf;
   int leaf;
   int hub;
   int hub;
-  char *name;
-  char *txt;
+  bd::String* name;
+  bd::String* txt;
 } cmds;
 } cmds;
 
 
-#define BUFSIZE 20240
-
 cmds cmdlist[900];
 cmds cmdlist[900];
 int cmdi = 0;
 int cmdi = 0;
 
 
-char *replace(char *string, char *oldie, char *newbie)
-{
-  static char newstring[BUFSIZE] = "";
-  int str_index, newstr_index, oldie_index, end, new_len, old_len, cpy_len;
-  char *c = NULL;
-
-  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);
-}
-
-char *step_thru_file(FILE *fd)
-{
-  char tempBuf[BUFSIZE] = "", *retStr = NULL;
-
-  if (fd == NULL) {
-    return NULL;
-  }
-  retStr = NULL;
-  while (!feof(fd)) {
-    fgets(tempBuf, sizeof(tempBuf), fd);
-    if (!feof(fd)) {
-      if (retStr == NULL) {
-        retStr = (char *) calloc(1, strlen(tempBuf) + 2);
-        strcpy(retStr, tempBuf);
-      } else {
-        retStr = (char *) realloc(retStr, strlen(retStr) + strlen(tempBuf));
-        strcat(retStr, tempBuf);
-      }
-      if (retStr[strlen(retStr)-1] == '\n') {
-        retStr[strlen(retStr)-1] = 0;
-        break;
-      }
-    }
-  }
-  return retStr;
-}
-
-char *newsplit(char **rest)
-{
-  register char *o, *r;
-
-  if (!rest)
-    return *rest = "";
-  o = *rest;
-  while (*o == ' ')
-    o++;
-  r = o;
-  while (*o && (*o != ' '))
-    o++;
-  if (*o)
-    *o++ = 0;
-  *rest = o;
-  return r;
-}
-
-int skipline (char *line, int *skip) {
+int skipline (const char *line, int *skip) {
   static int multi = 0;
   static int multi = 0;
 
 
   if ((!strncmp(line, "//", 2))) {
   if ((!strncmp(line, "//", 2))) {
@@ -131,113 +36,84 @@ int skipline (char *line, int *skip) {
 
 
 int my_cmp (const cmds *c1, const cmds *c2)
 int my_cmp (const cmds *c1, const cmds *c2)
 {
 {
-  return strcmp (c1->name, c2->name);
+  return c1->name->compare(*(c2->name));
 }
 }
 
 
-int parse_help(char *infile, char *outfile) {
-  FILE *in = NULL, *out = NULL;
-  char *buffer = NULL, my_buf[BUFSIZE] = "", *fulllist = (char *) calloc(1, 1);
-  int skip = 0, line = 0, i = 0, leaf = 0, hub = 0;
-
-  if (!(in = fopen(infile, "r"))) {
-    printf("Error: Cannot open '%s' for reading\n", infile);
-    return 1;
-  }
-  printf("Sorting help file '%s'", infile);
-  while ((!feof(in)) && ((buffer = step_thru_file(in)) != NULL) ) {
-
-    line++;
-    if ((*buffer)) {
-      if (strchr(buffer, '\n')) *(char*)strchr(buffer, '\n') = 0;
-      if ((skipline(buffer, &skip))) continue;
-      if (buffer[0] == ':') { //New cmd 
-        char *ifdef = (char *) calloc(1, strlen(buffer) + 1), *p;
-
-        buffer++;
-        strcpy(ifdef, buffer);
-        p = strchr(ifdef, ':');
-        *p = 0;
-        if (ifdef && ifdef[0]) {
-          if (!strcasecmp(ifdef, "leaf"))
-            leaf++;
-          else if (!strcasecmp(ifdef, "hub"))
-            hub++;
-        }
+int parse_help(const bd::String& infile, const bd::String& outfile) {
+  bd::Stream in, out;
+  bd::String buffer, ifdef, my_buf, fulllist;
+  int skip = 0, i = 0, leaf = 0, hub = 0;
+
+  in.loadFile(infile);
+  printf("Sorting help file '%s'", infile.c_str());
+  while (in.tell() < in.length()) {
+    buffer = in.getline().chomp();
+
+    if ((skipline(buffer.c_str(), &skip))) continue;
+    if (buffer[0] == ':') { //New cmd
+      ++buffer;
+      ifdef = newsplit(buffer, ':');
+
+      if (ifdef.length()) {
+        if (ifdef == "leaf")
+          leaf++;
+        else if (ifdef == "hub")
+          hub++;
+      }
 
 
-        /* finish last command */
-        if (my_buf && my_buf[0]) {
-          my_buf[strlen(my_buf)] = 0;
-          cmdlist[cmdi].txt = (char *) calloc(1, strlen(my_buf) + 1);
-          strcpy(cmdlist[cmdi].txt, my_buf);
-          i++;
-          cmdi++;
-        }
-	/* move on to next cmd now */
-        p = strchr(buffer, ':');
-        p++;
-        if (strcmp(p, "end")) {		/* NEXT CMD */
-          printf(".");
-          my_buf[0] = 0;
-          cmdlist[cmdi].leaf = leaf;
-          cmdlist[cmdi].hub = hub;
-          hub = leaf = 0;
-          for (i = 0; i < cmdi; i++ )	/* Eliminate duplicates */
-            if (!strcmp(cmdlist[i].name, p)) {
-              printf("\b[%s]", p);
-              cmdi--;
-              my_buf[0] = 0;
-              continue;
-            }
-          cmdlist[cmdi].name = (char *) calloc(1, strlen(p) + 1);
-          strcpy(cmdlist[cmdi].name, p);
-        } else {			/* END */
-          break;
+      /* finish last command */
+      if (my_buf.length()) {
+        cmdlist[cmdi].txt = new bd::String(my_buf);
+        ++i;
+        ++cmdi;
+        my_buf.clear();
+      }
+      /* move on to next cmd now */
+      if (buffer !=  "end") {		/* NEXT CMD */
+        printf(".");
+        cmdlist[cmdi].leaf = leaf;
+        cmdlist[cmdi].hub = hub;
+        hub = leaf = 0;
+        for (i = 0; i < cmdi; i++ ) {	/* Eliminate duplicates */
+          if (cmdlist[i].name && *(cmdlist[i].name) == buffer) {
+            printf("\b[%s]", buffer.c_str());
+            --cmdi;
+            continue;
+          }
         }
         }
-      } else {				/* CMD HELP INFO */
-        strcat(my_buf, buffer);
-        strcat(my_buf, "\\n");
+        cmdlist[cmdi].name = new bd::String(buffer);
+      } else {			/* END */
+        break;
       }
       }
+    } else {				/* CMD HELP INFO */
+      my_buf += buffer + "{NEWLINE}";
     }
     }
-    buffer = NULL;
-  }
-  if (in) fclose(in);
-  if (!(out = fopen(outfile, "w"))) {
-    printf("Error: Cannot open '%s' for writing\n", outfile);
-    return 1;
   }
   }
+
   qsort(cmdlist, cmdi, sizeof(cmds), (int (*)(const void *, const void *)) &my_cmp);
   qsort(cmdlist, cmdi, sizeof(cmds), (int (*)(const void *, const void *)) &my_cmp);
 
 
+  bd::String buf;
   for (i = 0; i < cmdi; i++ ) {
   for (i = 0; i < cmdi; i++ ) {
-    fulllist = (char *) realloc(fulllist, strlen(fulllist) + strlen(cmdlist[i].name) + 2);
-    strcat(fulllist, cmdlist[i].name);
-    strcat(fulllist, " ");
-    fprintf(out, ":");
-    if (cmdlist[i].leaf) fprintf(out, "leaf");
-    else if (cmdlist[i].hub) fprintf(out, "hub");
-    fprintf(out, ":%s\n", cmdlist[i].name);
-    fprintf(out, "%s", replace(cmdlist[i].txt, "\\n", "\n"));
+    fulllist += *(cmdlist[i].name) + " ";
+    out << ":";
+    if (cmdlist[i].leaf) out << "leaf";
+    else if (cmdlist[i].hub) out << "hub";
+    out << buf.printf(":%s\n", cmdlist[i].name->c_str());
+    out << cmdlist[i].txt->sub("{NEWLINE}", "\n");
   }
   }
 
 
-  fprintf(out, "::end\n");
-  if (out) fclose(out);
+  out << "::end\n";
+
+  out.writeFile(outfile);
   printf(" Success\n");
   printf(" Success\n");
-  fulllist[strlen(fulllist)] = 0;
-  printf("Sorted (%d): %s\n", cmdi, fulllist);
+  printf("Sorted (%d): %s\n", cmdi, fulllist.c_str());
   return 0;
   return 0;
 }
 }
 
 
 int main(int argc, char **argv) {
 int main(int argc, char **argv) {
-  char *in = NULL, *out = NULL;
-  int ret = 0;
-
   if (argc < 3) return 1;
   if (argc < 3) return 1;
-  in = (char *) calloc(1, strlen(argv[1]) + 1);
-  strcpy(in, argv[1]);
-  out = (char *) calloc(1, strlen(argv[2]) + 1);
-  strcpy(out, argv[2]);
-  ret = parse_help(in, out);
-  free(in);
-  free(out);
-  return ret;
+
+  bd::String in(argv[1]), out(argv[2]);
+  return parse_help(in, out);
 }
 }