]> jfr.im git - irc/gameservirc.git/blobdiff - gameserv/news.cpp
synced up with my source
[irc/gameservirc.git] / gameserv / news.cpp
index 2040d2de1b64e918a082fa9dfe2749798a19363b..14933a40225d6e1337595bbd339102e829e16838 100644 (file)
@@ -1,17 +1,23 @@
 #include "extern.h"
+#include <list>
+#include <iterator>
 #include <fstream>
+#include <string>
+#include <stdio.h>
 
 using std::ofstream;
 using std::ifstream;
 
-List<myString> todaysnews;
-void addNews(List<myString> &news, const char *fmt, ...);
-void clearNews(List<myString> &news) {news.deleteNodes();};
-void showNews(char *nick, List<myString> &news);
-void saveNews(char *filename, List<myString> &news);
-void loadNews(char *filename, List<myString> &news);
+using namespace std;
 
-void addNews(List<myString> &news, const char *fmt, ...)
+list<string> todaysnews;
+void addNews(list<string> &news, const char *fmt, ...);
+void clearNews(list<string> &news) {news.clear();};
+void showNews(char *nick, list<string> &news);
+void saveNews(char *filename, list<string> &news);
+void loadNews(char *filename, list<string> &news);
+
+void addNews(list<string> &news, const char *fmt, ...)
 {
     if (fmt[0] == '\0')
         return;
@@ -47,9 +53,10 @@ void addNews(List<myString> &news, const char *fmt, ...)
         log("New News Item: %s", input);
     #endif
 
-    myString *nstring;
-    nstring = new myString(input);
-    news.insertAtBack(nstring);
+    notice(s_GameServ, c_Forest, "News Flash: %s", input);
+    string *nstring;
+    nstring = new string(input);
+    news.push_back(*nstring);
 
     delete [] input;
     delete nstring;
@@ -57,79 +64,70 @@ void addNews(List<myString> &news, const char *fmt, ...)
 va_end(args);
 }
 
-void showNews(char *nick, List<myString> &news)
+void showNews(char *nick, list<string> &news)
 {
-    if (!news.isEmpty())
+  if (!news.empty())
     {
-       ListNode<myString> *it;
-       it = news.First();
-
-       notice(s_GameServ, nick, "The Daily Happenings: ");
-       while (it)
-       {
-           notice(s_GameServ, nick, "%s", it->getData()->getString());
-           it = it->Next();
-       }
-       notice(s_GameServ, nick, "End of News");
+         list<string>::iterator iter;
+         
+         notice(s_GameServ, nick, "The Daily Happenings: ");
+         for (iter=news.begin(); iter != news.end(); iter++)
+               {
+                 notice(s_GameServ, nick, "%s", (*iter).c_str());
+               }
+         notice(s_GameServ, nick, "End of News");
     }
 }
 
-void saveNews(char *filename, List<myString> &news)
+void saveNews(char *filename, list<string> &news)
 {
-    if (news.isEmpty())
-       return;
-
-    ofstream outfile;
-    outfile.open(filename);
-    if (outfile.fail())
+  ofstream outfile;
+  outfile.open(filename);
+  
+  if (outfile.fail())
     {
-       log("Error opening %s", filename);
-       return;
+         log("Error opening %s", filename);
+         return;
     }
-
-    ListNode<myString> *it;
-    it = news.First();
-    while (it)
-    {
-       outfile << it->getData()->getString() << endl;
-       it = it->Next();
+  
+  list<string>::iterator iter;
+  for (iter=news.begin(); iter != news.end(); iter++)
+       {
+         outfile << (*iter).c_str() << endl;
     }
-    outfile.close();
+  outfile.close();
 }
 
-void loadNews(char *filename, List<myString> &news)
+void loadNews(char *filename, list<string> &news)
 {
     // First clear the old news out
-    ListNode<myString> *it, *temp;
-    it = news.First();
-
-    while (it)
-    {
-        temp = it;
-       it = it->Next();
-       delete temp;
-    }
+       news.clear();
 
     // Now load from the file
     ifstream infile;
     infile.open(filename);
     if (infile.fail())
-    {
-       log("Error opening %s", filename);
-       return;
-    }
+         {
+               log("Error opening %s", filename);
+               return;
+         }
 
     char *buf;
-    myString *string;
+    string *str;
     buf = new char [1024];
-
+       
     while (infile.getline(buf, 1024, '\n'))
-    {
-       string = new myString(buf);
-       news.insertAtBack(string);
-       delete string;
-    }
-
+         {
+               if (buf[0] == '\0' || buf[0] == '\n')
+                 {
+                       delete [] buf;
+                       return;
+                 }
+               str = new string(buf);
+               news.push_back(*str);
+               delete str;
+         }
+       
     delete [] buf;
 }