瀏覽代碼

* Convert 'makeset' to using bdlib instead of STL

Bryan Drewery 16 年之前
父節點
當前提交
e828afc6fa
共有 5 個文件被更改,包括 27 次插入28 次删除
  1. 8 4
      Makefile.in
  2. 1 1
      lib/bdlib
  3. 2 2
      src/EncryptedStream.c
  4. 2 2
      src/Makefile.in
  5. 14 19
      src/makeset.c

+ 8 - 4
Makefile.in

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

+ 1 - 1
lib/bdlib

@@ -1 +1 @@
-Subproject commit e5cd7b1121b3ffdd0b34b9e4f2b20ad0b7197b24
+Subproject commit 7a7a3b18a3d95930da277acd9b6f14ed9ee91828

+ 2 - 2
src/EncryptedStream.c

@@ -32,8 +32,8 @@ int EncryptedStream::loadFile (const int fd) {
       in_buf = str(5, str.length() - 5);
     } else {
       /* 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);
       in_buf = str;
     }

+ 2 - 2
src/Makefile.in

@@ -73,9 +73,9 @@ makeres: makeres.c
 	@$(CXX) $(CXXFLAGS) -I$(top_srcdir) -I$(top_srcdir)/pack $(CPPFLAGS) makeres.c -o makeres
 	@$(STRIP) makeres@EXEEXT@
 
-makeset: makeset.c
+makeset: makeset.c ../lib/bdlib/src/libbdlib.a
 	@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@
 
 makehelp: makehelp.c

+ 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 <algorithm>
 #include <cstring>
@@ -10,41 +9,37 @@ int main(int argc, char *argv[]) {
   if (argc == 2)
     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;
 
-  while (file.getline(line, sizeof(line))) {
+  while (file.tell() < file.length()) {
+    line = file.getline().chomp();
     if (line[0] == '#') continue;
     if (line[0] == ':') {
-      type = &line[1];
+      type = line(1, line.length() - 1);
       if (type == "end")
         break;
 
-      transform(type.begin(), type.end(), type.begin(), (int(*)(int)) toupper);
+      transform(type.begin(), type.end(), type.mdata(), (int(*)(int)) toupper);
 
       type = "DEFAULT_" + type;
-      out << "#define " << type << " \"\\" << endl;
+      out << "#define " << type << " \"\\" << "\n";
     } else {
       if (!type.length()) 
         continue;
 
       out << line;
-      c = file.peek();
+      c = file.peek()[0];
       if (strchr("\n:", c)) {
-        out << "\"\n" << endl;
+        out << "\"\n\n";
         type = "";
       } else
-        out << ",\\" << endl;
+        out << ",\\\n";
     }
   }
 
-  file.close();
-  out.close();
+  out.writeFile(argv[2]);
 }