1 // utility functions not belonging to any particular class
3 #include "includes.hpp"
7 // Extract a field from a string returned by the server
9 void extract(wxString& outputbuf, wxString inputbuf, int parmnum) {
11 wxStringTokenizer *tok = new wxStringTokenizer(inputbuf, "|", FALSE);
13 for (i=0; tok->HasMoreTokens(); ++i) {
14 outputbuf = tok->NextToken();
22 int extract_int(wxString inputbuf, int parmnum) {
25 extract(buf, inputbuf, parmnum);
26 return atoi((const char *)buf);
31 // Convert traditional Citadel variformat text to HTML
32 void variformat_to_html(wxString& outputbuf,
34 bool add_header_and_footer) {
41 // Escape out any reserved characters
43 for (pos=0; pos<inputbuf.Length(); ++pos) {
44 ch = inputbuf.Mid(pos, 1);
55 if (add_header_and_footer) {
56 outputbuf.Append("<HTML><BODY>");
59 // Parse the body of the text
60 while (buf.Length() > 0) {
61 pos = buf.Find('\n', FALSE);
64 pos = buf.Find('\n', FALSE);
66 if (outputbuf.Length() > 0) {
67 if (buf.Left(1) == " ") {
68 outputbuf.Append("<BR>\n");
70 outputbuf.Append(" ");
73 outputbuf.Append(buf.Left(pos));
77 if (add_header_and_footer) {
78 outputbuf.Append("</BODY></HTML>\n");
83 wxString generate_html_header(CitMessage *message,
88 int verbosity = 2; // FIX add a prefs option for this
93 ret = " <H3>";
94 ret += asctime(localtime(&message->timestamp));
95 ret += " from " + message->author;
96 if (message->room.CmpNoCase(ThisRoom))
97 ret += " in " + message->room + "> ";
98 if (message->nodename.CmpNoCase(ThisNode))
99 ret += " @ " + message->nodename;
100 if (message->recipient.Length() > 0)
101 ret += " to " + message->recipient;
107 ret += "<TT>Date: </TT>";
108 ret += asctime(localtime(&message->timestamp));
110 ret += "<TT>From: </TT>" + message->author;
111 ret += " @ " + message->nodename + "<BR>";
112 if (message->recipient.Length() > 0)
113 ret += "<TT>To: </TT>" + message->recipient + "<BR>";
125 // Generic exit stuff
126 void cleanup(int exitcode) {
127 delete ini; // Write configuration to disk
128 exit(exitcode); // Go away.