changeset 7:8d54d9fdeca3

fixed comments removed daemonization verbose strings' size() -> length()
author Vlad Glagolev <enqlave@gmail.com>
date Sun, 03 Feb 2008 21:29:41 +0300
parents 9be05a31b7f9
children ed800eab1c38
files Makefile sources/Makefile sources/cabal.cpp sources/connection.cpp sources/core.cpp sources/engine.cpp sources/headers/cabal.hpp sources/headers/conf.hpp sources/headers/connection.hpp sources/headers/core.hpp sources/headers/engine.hpp sources/headers/network.hpp sources/headers/os.hpp sources/headers/parser.hpp sources/network.cpp sources/parser.cpp
diffstat 16 files changed, 42 insertions(+), 49 deletions(-) [+]
line wrap: on
line diff
--- a/Makefile	Sun Jan 27 17:23:14 2008 +0300
+++ b/Makefile	Sun Feb 03 21:29:41 2008 +0300
@@ -1,4 +1,3 @@
-#
 # Makefile (2007-05-17)
 #
 # -- CABAL -- primary build script
--- a/sources/Makefile	Sun Jan 27 17:23:14 2008 +0300
+++ b/sources/Makefile	Sun Feb 03 21:29:41 2008 +0300
@@ -1,4 +1,3 @@
-#
 # Makefile (2007-03-05)
 #
 # -- CABAL -- build script
--- a/sources/cabal.cpp	Sun Jan 27 17:23:14 2008 +0300
+++ b/sources/cabal.cpp	Sun Feb 03 21:29:41 2008 +0300
@@ -1,5 +1,4 @@
-/**
- * cabal.cpp (2007-03-03)
+/** cabal.cpp (2007-03-03)
  *
  * -- CABAL -- primary module
  *
@@ -44,7 +43,7 @@
 		<< "\t-d, --daemon		| daemon mode\n" \
 		<< "\t-c, --config <file>	| configuration file\n" \
 		<< "\t-h, --help		| this message\n" \
-		<< "\nCopyright (c) 2007-2008 Vlad Glagolev (BSD license)\n" << endl;
+		<< "\nCopyright (c) 2007-2008 Vlad Glagolev (BSD-licensed)\n" << endl;
 
 	exit(0);
 }
--- a/sources/connection.cpp	Sun Jan 27 17:23:14 2008 +0300
+++ b/sources/connection.cpp	Sun Feb 03 21:29:41 2008 +0300
@@ -1,5 +1,4 @@
-/**
- * connection.cpp (2007-04-12)
+/** connection.cpp (2007-04-12)
  *
  * -- CABAL -- connection base (servers usage)
  *
@@ -34,12 +33,14 @@
 
 	uptime = 0;
 
-	cout << "CONNECTION: opening...\n";
+	if (CABAL->debug)
+		cout << "CONNECTION: opening...\n";
 }
 
 Connection::~Connection()
 {
-	cout << "CONNECTION: closed\n";
+	if (CABAL->debug)
+		cout << "CONNECTION: closed\n";
 }
 
 void Connection::ircConnect()
@@ -48,7 +49,8 @@
 		shut("no hosts defined");
 
 	if (!connected && !connecting) {
-		cout << "CONNECTION: connecting to server: " << current->host << endl;
+		if (CABAL->debug)
+			cout << "CONNECTION: connecting to server: " << current->host << endl;
 
 		if (!resolveHost(current->host, &address)) {
 			cout << "Error: unable to resolve host " << current->host << endl;
--- a/sources/core.cpp	Sun Jan 27 17:23:14 2008 +0300
+++ b/sources/core.cpp	Sun Feb 03 21:29:41 2008 +0300
@@ -18,7 +18,7 @@
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
-#include "core.hpp"
+#include "cabal.hpp" // needed: core.hpp
 
 Connection *C;
 
@@ -47,7 +47,8 @@
 
 	remove(pid);
 
-	cout << "CORE: shutdown complete\n";
+	if (CABAL->debug)
+		cout << "CORE: shutdown complete\n";
 }
 
 void Core::parseCommandLine(int argc, char **argv)
@@ -82,7 +83,8 @@
 	if (!sysconfig)
 		shut("unable to open configuration file");
 	else {
-		cout << "CORE: parsing configuration file: " << config << endl;
+		if (CABAL->debug)
+			cout << "CORE: parsing configuration file: " << config << endl;
 
 		if (servers + 1 < MAX_SERVERS) {
 			connections[++servers] = new Connection();
--- a/sources/engine.cpp	Sun Jan 27 17:23:14 2008 +0300
+++ b/sources/engine.cpp	Sun Feb 03 21:29:41 2008 +0300
@@ -1,5 +1,4 @@
-/**
- * engine.cpp (2007-03-05)
+/** engine.cpp (2007-03-05)
  *
  * -- CABAL -- engine (useful functions)
  *
@@ -19,7 +18,7 @@
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
-#include "engine.hpp"
+#include "cabal.hpp" // needed: engine.hpp
 
 bool daemonize()
 {
@@ -27,7 +26,8 @@
 		cout << "Error: unable to daemonize into background\n";
 		exit(1);
 	} else {
-		cout << "ENGINE: successfully daemonized into background\n";
+		if (CABAL->debug)
+			cout << "ENGINE: successfully daemonized into background\n";
 		return daemon(1, 1) == 0;
 	}
 }
--- a/sources/headers/cabal.hpp	Sun Jan 27 17:23:14 2008 +0300
+++ b/sources/headers/cabal.hpp	Sun Feb 03 21:29:41 2008 +0300
@@ -1,5 +1,4 @@
-/**
- * cabal.hpp (2007-03-04)
+/** cabal.hpp (2007-03-04)
  *
  * -- CABAL -- main header
  *
--- a/sources/headers/conf.hpp	Sun Jan 27 17:23:14 2008 +0300
+++ b/sources/headers/conf.hpp	Sun Feb 03 21:29:41 2008 +0300
@@ -1,5 +1,4 @@
-/**
- * conf.hpp (2007-03-04)
+/** conf.hpp (2007-03-04)
  *
  * -- CABAL -- user configuration
  *
--- a/sources/headers/connection.hpp	Sun Jan 27 17:23:14 2008 +0300
+++ b/sources/headers/connection.hpp	Sun Feb 03 21:29:41 2008 +0300
@@ -1,5 +1,4 @@
-/**
- * connection.hpp (2007-04-12)
+/** connection.hpp (2007-04-12)
  *
  * -- CABAL -- connection header
  *
--- a/sources/headers/core.hpp	Sun Jan 27 17:23:14 2008 +0300
+++ b/sources/headers/core.hpp	Sun Feb 03 21:29:41 2008 +0300
@@ -1,5 +1,4 @@
-/**
- * core.hpp (2007-03-04)
+/** core.hpp (2007-03-04)
  *
  * -- CABAL -- core header
  *
--- a/sources/headers/engine.hpp	Sun Jan 27 17:23:14 2008 +0300
+++ b/sources/headers/engine.hpp	Sun Feb 03 21:29:41 2008 +0300
@@ -1,5 +1,4 @@
-/**
- * engine.hpp (2007-03-05)
+/** engine.hpp (2007-03-05)
  *
  * -- CABAL -- engine header
  *
--- a/sources/headers/network.hpp	Sun Jan 27 17:23:14 2008 +0300
+++ b/sources/headers/network.hpp	Sun Feb 03 21:29:41 2008 +0300
@@ -1,5 +1,4 @@
-/**
- * network.hpp (2007-04-02)
+/** network.hpp (2007-04-02)
  *
  * -- CABAL -- network header
  *
--- a/sources/headers/os.hpp	Sun Jan 27 17:23:14 2008 +0300
+++ b/sources/headers/os.hpp	Sun Feb 03 21:29:41 2008 +0300
@@ -1,5 +1,4 @@
-/**
- * os.hpp (2007-03-04)
+/** os.hpp (2007-03-04)
  *
  * -- CABAL -- operating system detection
  *
--- a/sources/headers/parser.hpp	Sun Jan 27 17:23:14 2008 +0300
+++ b/sources/headers/parser.hpp	Sun Feb 03 21:29:41 2008 +0300
@@ -1,5 +1,4 @@
-/**
- * parser.hpp (2007-05-13)
+/** parser.hpp (2007-05-13)
  *
  * -- CABAL -- irc commands parser header
  *
--- a/sources/network.cpp	Sun Jan 27 17:23:14 2008 +0300
+++ b/sources/network.cpp	Sun Feb 03 21:29:41 2008 +0300
@@ -1,5 +1,4 @@
-/**
- * network.cpp (2007-04-02)
+/** network.cpp (2007-04-02)
  *
  * -- CABAL -- network essentials (sockets, etc.)
  *
@@ -23,14 +22,16 @@
 
 Network::Network()
 {
-	cout << "NETWORK: going online...\n";
+	if (CABAL->debug)
+		cout << "NETWORK: going on-line...\n";
 }
 
 Network::~Network()
 {
 	closeSocket();
 
-	cout << "NETWORK: offline\n";
+	if (CABAL->debug)
+		cout << "NETWORK: off-line\n";
 }
 
 void Network::sendMsg(string m)
@@ -41,7 +42,7 @@
 	if (CABAL->debug)
 		cout << "<- " << cs << " -- " << m << endl;
 
-	send(cs, (m + "\n").c_str(), (m + "\n").size(), 0);
+	send(cs, (m + "\n").c_str(), (m + "\n").length(), 0);
 }
 
 string Network::receiveMsg()
@@ -50,7 +51,7 @@
 		return 0;
 
 	if (canRead(cs)) {
-		string sbuffer = "";
+		string sbuffer;
 		char cbuffer;
 
 		int err = recv(cs, &cbuffer, 1, 0);
@@ -61,8 +62,8 @@
 			while (1) {
 				if (sbuffer[sbuffer.size() - 1] == '\n') {
 					sbuffer = (sbuffer.substr(0, 1) == ":")
-						? sbuffer.substr(1, sbuffer.size() - 3)
-						: sbuffer.substr(0, sbuffer.size() - 2);
+						? sbuffer.substr(1, sbuffer.length() - 3)
+						: sbuffer.substr(0, sbuffer.length() - 2);
 
 					if (CABAL->debug)
 						cout << "-> " << cs << " -- " << sbuffer << endl;
@@ -207,7 +208,8 @@
 	connected = false;
 	connecting = true;
 
-	cout << "NETWORK: socket opened..........: " << cs << endl;
+	if (CABAL->debug)
+		cout << "NETWORK: socket opened..........: " << cs << endl;
 
 	return 1;
 }
@@ -244,7 +246,8 @@
 	connected = true;
 	connecting = false;
 
-	cout << "NETWORK: socket connected.......: " << cs << endl;
+	if (CABAL->debug)
+		cout << "NETWORK: socket connected.......: " << cs << endl;
 
 	return 1;
 }
--- a/sources/parser.cpp	Sun Jan 27 17:23:14 2008 +0300
+++ b/sources/parser.cpp	Sun Feb 03 21:29:41 2008 +0300
@@ -1,5 +1,4 @@
-/**
- * parser.cpp (2007-05-13)
+/** parser.cpp (2007-05-13)
  *
  * -- CABAL -- irc commands parser
  *
@@ -36,10 +35,8 @@
 		char *where = strtok(NULL, " ");
 		char *data = strtok(NULL, "\n");
 
-		if (strchr(who, '!')) {
-			id = strchr(who, '!');
-			id = id.substr(1);
-		}
+		if (strchr(who, '!'))
+			id = strchr(who, '!'), id = id.substr(1);
 
 		if (strtok(who, "!"))
 			name = strtok(who, "!");