changeset 6:9be05a31b7f9

Enqlave IRC Network => Vaygr IRC Network -Os optimizations by default temporary functions' arguments rename *char => NULL bool => true|false renamed some global vars, removed debug info
author Vlad Glagolev <enqlave@gmail.com>
date Sun, 27 Jan 2008 17:23:14 +0300
parents 0faceb076254
children 8d54d9fdeca3
files README sources/Makefile sources/connection.cpp sources/headers/core.hpp sources/headers/network.hpp sources/headers/os.hpp sources/headers/parser.hpp sources/network.cpp sources/parser.cpp
diffstat 9 files changed, 51 insertions(+), 61 deletions(-) [+]
line wrap: on
line diff
--- a/README	Thu Jan 24 21:00:52 2008 +0300
+++ b/README	Sun Jan 27 17:23:14 2008 +0300
@@ -18,7 +18,7 @@
 	OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 
 	- If you find bugs, improve something or just want to give ideas,
-	feel free to contact me on Enqlave IRC Network:
+	feel free to contact me on Vaygr IRC Network:
 
 	server: irc.enqlave.net / channel: #cabal
 
--- a/sources/Makefile	Thu Jan 24 21:00:52 2008 +0300
+++ b/sources/Makefile	Sun Jan 27 17:23:14 2008 +0300
@@ -20,7 +20,7 @@
 #
 
 CXX = c++
-CXXFLAGS = -g -O2 -ansi -Wall
+CXXFLAGS = -g -Os -ansi -Wall
 CPPFLAGS = -I/usr/include -Iheaders
 LDFLAGS = -L/usr/lib
 BIN = ../cabal
--- a/sources/connection.cpp	Thu Jan 24 21:00:52 2008 +0300
+++ b/sources/connection.cpp	Sun Jan 27 17:23:14 2008 +0300
@@ -19,7 +19,7 @@
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
-#include "cabal.hpp" // required: core.h
+#include "cabal.hpp" // required: core.hpp
 
 Connection::Connection():
 	nick(NICK),
@@ -28,7 +28,7 @@
 	chan(CHANNEL),
 	key(CHANNEL_KEY)
 {
-	hosts = current = 0;
+	hosts = current = NULL;
 
 	now = CABAL->now;
 
@@ -96,41 +96,41 @@
 	}
 }
 
-void Connection::ircPass(string pass)
+void Connection::ircPass(string p)
 {
-	sendMsg("PASS " + pass);
+	sendMsg("PASS " + p);
 }
 
-void Connection::ircNick(string nnick)
+void Connection::ircNick(string n)
 {
-	sendMsg("NICK " + (nnick != "" ? nnick : NICK));
+	sendMsg("NICK " + (n != "" ? n: NICK));
 }
 
-void Connection::ircUser(string nuser, string nname)
+void Connection::ircUser(string u, string n)
 {
-	sendMsg("USER " + nuser + (virtualhost != 0 ? " " + (string)virtualhost + \
-		" " : " 0 ") + (string)current->host + " :" + nname);
+	sendMsg("USER " + u + (virtualhost ? " " + (string)virtualhost + " ": \
+			" 0 ") + (string)current->host + " :" + n);
 }
 
-void Connection::ircAway(string away)
+void Connection::ircAway(string m)
 {
-	sendMsg("AWAY :" + away);
+	sendMsg("AWAY :" + m);
 }
 
-void Connection::ircJoin(string chan, string key)
+void Connection::ircJoin(string c, string k)
 {
-	sendMsg("JOIN " + chan + (key != "" ? " " + key : ""));
+	sendMsg("JOIN " + c + (k != "" ? " " + k: ""));
 }
 
-void Connection::ircPart(string chan)
+void Connection::ircPart(string c)
 {
-	sendMsg("PART " + chan);
+	sendMsg("PART " + c);
 }
 
-void Connection::ircCycle(string chan)
+void Connection::ircCycle(string c)
 {
-	sendMsg("PART " + chan);
-	sendMsg("JOIN " + chan);
+	sendMsg("PART " + c);
+	sendMsg("JOIN " + c);
 }
 
 Connection::host_type *Connection::addHost(host_type *list, pchar host, \
--- a/sources/headers/core.hpp	Thu Jan 24 21:00:52 2008 +0300
+++ b/sources/headers/core.hpp	Sun Jan 27 17:23:14 2008 +0300
@@ -44,7 +44,7 @@
 	int servers;
 	Connection *connections[MAX_SERVERS];
 
-	const char *pid;
+	pchar pid;
 	char *config;
 
 	char commander;
--- a/sources/headers/network.hpp	Thu Jan 24 21:00:52 2008 +0300
+++ b/sources/headers/network.hpp	Sun Jan 27 17:23:14 2008 +0300
@@ -47,7 +47,7 @@
 
 	bool openHost();
 	bool resolveHost(pchar, address_type *, int inet = 0);
-	bool activateTCP(int, pchar host = 0);
+	bool activateTCP(int, pchar host = NULL);
 
 	int canRead(int);
 	int canWrite(int);
--- a/sources/headers/os.hpp	Thu Jan 24 21:00:52 2008 +0300
+++ b/sources/headers/os.hpp	Sun Jan 27 17:23:14 2008 +0300
@@ -24,6 +24,7 @@
 
 #include "conf.hpp"
 
+// permament char pointer
 typedef const char *pchar;
 
 #if HAVE_FSTREAM
--- a/sources/headers/parser.hpp	Thu Jan 24 21:00:52 2008 +0300
+++ b/sources/headers/parser.hpp	Sun Jan 27 17:23:14 2008 +0300
@@ -31,12 +31,12 @@
 
 	void Parse(Connection *);
 
-	string alien;
-	string alienID;
-	string alienAction;
-	string alienLocation;
-	string alienCommand;
-	string alienMessage;
+	string name;
+	string id;
+	string place;
+	string action;
+	string command;
+	string message;
 };
 
 #endif // _PARSER_HPP_
--- a/sources/network.cpp	Thu Jan 24 21:00:52 2008 +0300
+++ b/sources/network.cpp	Sun Jan 27 17:23:14 2008 +0300
@@ -137,7 +137,7 @@
 	freeaddrinfo(reso);
 
 	return e;
-#else
+#else // ! ENABLE_IPV6
 	if (inet && inet != AF_INET)
 		return 0;
 
@@ -154,7 +154,7 @@
 		memcpy(&a->sa.sin_addr.s_addr, he->h_addr_list[0], he->h_length);
 
 	return 1;
-#endif  // ENABLE_IPV6
+#endif // ENABLE_IPV6
 }
 
 bool Network::activateTCP(int port, pchar host)
@@ -204,8 +204,8 @@
 
 	setsockopt(cs, IPPROTO_TCP, TCP_NODELAY, (pchar)&parm, sizeof(parm));
 
-	connected = 0;
-	connecting = 1;
+	connected = false;
+	connecting = true;
 
 	cout << "NETWORK: socket opened..........: " << cs << endl;
 
--- a/sources/parser.cpp	Thu Jan 24 21:00:52 2008 +0300
+++ b/sources/parser.cpp	Sun Jan 27 17:23:14 2008 +0300
@@ -34,56 +34,45 @@
 		char *who = strtok(line, " ");
 		char *what = strtok(NULL, " ");
 		char *where = strtok(NULL, " ");
-		char *message = strtok(NULL, "\n");
+		char *data = strtok(NULL, "\n");
 
 		if (strchr(who, '!')) {
-			alienID = strchr(who, '!');
-			alienID = alienID.substr(1);
+			id = strchr(who, '!');
+			id = id.substr(1);
 		}
 
 		if (strtok(who, "!"))
-			alien = strtok(who, "!");
+			name = strtok(who, "!");
 
-		alienAction = what;
+		action = what;
 
 		if (*where == ':')
-			alienLocation = ++where;
+			place = ++where;
 		else {
-			alienLocation = where;
+			place = where;
 
-			if (message) {
-				if (alienLocation == S->nick)
-					alienLocation = alien;
+			if (data) {
+				if (place == S->nick)
+					place = name;
 
-				alienMessage = (*message == ':') ? ++message: message;
+				message = (*data == ':') ? ++data: data;
 
-				if (*message == CABAL->commander && ++message) {
-					if (strchr(message, ' ')) {
-						alienCommand = strtok(message, " ");
-						alienMessage = strtok(NULL, "\n");
+				if (*data == CABAL->commander && ++data) {
+					if (strchr(data, ' ')) {
+						command = strtok(data, " ");
+						message = strtok(NULL, "\n");
 					} else
-						alienCommand = message;
+						command = data;
 				}
 			}
 		}
 
 		delete[] line;
-
-/* DEBUG
-		cout
-			<< "-----------------------------------\n" \
-			<< "Alien:      \t" << alien << endl \
-			<< "Alien ID:\t" << alienID << endl \
-			<< "Alien action:\t" << alienAction << endl \
-			<< "Alien location:\t" << alienLocation << endl \
-			<< "Alien command:\t" << alienCommand << endl \
-			<< "Alien message:\t" << alienMessage << endl \
-			<< "-----------------------------------\n";
-*/	}
+	}
 }
 
 void Parser::Parse(Connection *S)
 {
-	if (alienCommand == "die" && alienID == "stealth@ru.raver")
+	if (command == "die" && id == "stealth@ru.raver")
 		shut("Requested shutdown");
 }