Skip to content

Commit

Permalink
Merge pull request #87 from NeroBurner/more_const_and_std_string
Browse files Browse the repository at this point in the history
More const and std string
  • Loading branch information
GeneMosher committed Feb 16, 2019
2 parents 06d3b2e + de1e610 commit 721ac11
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 65 deletions.
84 changes: 28 additions & 56 deletions main/printer.cc
Expand Up @@ -121,8 +121,6 @@ Printer::Printer()
target_type = TARGET_NONE;
host_name.Set("");
port_no = 0;
have_title = 0;
page_title.Set("");
kitchen_mode = PRINT_LARGE | PRINT_NARROW;
pulse = -1;
term_name.Set("");
Expand All @@ -148,8 +146,6 @@ Printer::Printer(const genericChar* host, int port, const genericChar* targetstr
target_type = type;
host_name.Set(host);
port_no = port;
have_title = 0;
page_title.Set("");
kitchen_mode = PRINT_LARGE | PRINT_NARROW;
pulse = -1;
term_name.Set("");
Expand Down Expand Up @@ -222,10 +218,10 @@ int Printer::IsType(int type)
return retval;
}

int Printer::SetTitle(const genericChar* title)
int Printer::SetTitle(const std::string &title)
{
page_title.Set(title);
have_title = 1;
page_title = title;
have_title = true;
return 0;
}

Expand Down Expand Up @@ -479,7 +475,7 @@ int Printer::MakeFileName(genericChar* buffer, const genericChar* source, const
if (source != NULL)
strncpy(title, source, STRLENGTH);
else if (have_title)
strncpy(title, page_title.Value(), STRLENGTH);
strncpy(title, page_title.c_str(), STRLENGTH);
else
strncpy(title, GENERIC_TITLE, STRLENGTH);
len = strlen(title);
Expand Down Expand Up @@ -611,7 +607,7 @@ int Printer::EmailPrint()
}
email.AddTo(target.Value());
email.AddFrom(settings->email_replyto.Value());
email.AddSubject(page_title.Value());
email.AddSubject(page_title.c_str());

// now read in the file and add it to the email
fd = open(temp_name.Value(), O_RDONLY);
Expand Down Expand Up @@ -763,7 +759,7 @@ void Printer::DebugPrint(int printall)
printf(" Temp Name: %s\n", temp_name.Value());
printf(" Target: %s\n", target.Value());
printf(" Host Name: %s\n", host_name.Value());
printf(" Page Title: %s\n", page_title.Value());
printf(" Page Title: %s\n", page_title.c_str());
printf(" Last Mode: %d\n", last_mode);
printf(" Last Color: %d\n", last_color);
printf(" Last Uni: %d\n", last_uni);
Expand Down Expand Up @@ -807,8 +803,6 @@ PrinterIthaca::PrinterIthaca(const genericChar* host, int port, const genericCha
target_type = type;
host_name.Set(host);
port_no = port;
have_title = 0;
page_title.Set("");
pulse = -1;
term_name.Set("");
}
Expand Down Expand Up @@ -859,8 +853,8 @@ int PrinterIthaca::End()

FormFeed();
Close();
have_title = 0;
page_title.Set(""); // reset the title for a new print job
have_title = false;
page_title.clear(); // reset the title for a new print job
return 0;
}

Expand Down Expand Up @@ -1001,8 +995,6 @@ PrinterStar::PrinterStar(const genericChar* host, int port, const genericChar* t
target_type = type;
host_name.Set(host);
port_no = port;
have_title = 0;
page_title.Set("");
pulse = -1;
term_name.Set("");
}
Expand Down Expand Up @@ -1081,8 +1073,8 @@ int PrinterStar::End()
LineFeed(END_PAGE);
CutPaper();
Close();
have_title = 0;
page_title.Set(""); // reset the title for a new print job
have_title = false;
page_title.clear(); // reset the title for a new print job
return 0;
}

Expand Down Expand Up @@ -1234,8 +1226,6 @@ PrinterEpson::PrinterEpson(const genericChar* host, int port, const genericChar*
target_type = type;
host_name.Set(host);
port_no = port;
have_title = 0;
page_title.Set("");
pulse = -1;
term_name.Set("");
}
Expand Down Expand Up @@ -1310,8 +1300,8 @@ int PrinterEpson::End()
LineFeed(END_PAGE);
CutPaper();
Close();
have_title = 0;
page_title.Set(""); // reset the title for a new print job
have_title = false;
page_title.clear(); // reset the title for a new print job
return 0;
}

Expand Down Expand Up @@ -1457,8 +1447,6 @@ PrinterHP::PrinterHP(const genericChar* host, int port, const genericChar* targe
target_type = type;
host_name.Set(host);
port_no = port;
have_title = 0;
page_title.Set("");
pulse = -1;
term_name.Set("");
}
Expand Down Expand Up @@ -1515,8 +1503,8 @@ int PrinterHP::End()

FormFeed();
Close();
have_title = 0;
page_title.Set(""); // reset the title for a new print job
have_title = false;
page_title.clear(); // reset the title for a new print job
return 0;
}

Expand Down Expand Up @@ -1636,8 +1624,6 @@ PrinterHTML::PrinterHTML(const genericChar* host, int port, const genericChar* t
target_type = type;
host_name.Set(host);
port_no = port;
have_title = 0;
page_title.Set("");
pulse = -1;
term_name.Set("");
}
Expand Down Expand Up @@ -1721,8 +1707,8 @@ int PrinterHTML::End()

Write("</pre>\n</body>\n</html>");
Close();
have_title = 0;
page_title.Set(""); // reset the title for a new print job
have_title = false;
page_title.clear(); // reset the title for a new print job
return 0;
}

Expand All @@ -1732,9 +1718,9 @@ int PrinterHTML::Init()
genericChar buffer[STRLENGTH];

Write("<html>\n<head>", 0);
if (have_title == 0)
page_title.Set(GENERIC_TITLE);
snprintf(buffer, STRLENGTH, "<title>%s</title>", page_title.Value());
if (!have_title)
page_title = GENERIC_TITLE;
snprintf(buffer, STRLENGTH, "<title>%s</title>", page_title.c_str());
Write(buffer, 0);
Write("</head>", 0);
Write("<body>", 0);
Expand Down Expand Up @@ -1786,8 +1772,6 @@ PrinterPostScript::PrinterPostScript()
target_type = TARGET_NONE;
host_name.Set("");
port_no = 0;
have_title = 0;
page_title.Set("");
putbuffer[0] = '\0';
putbuffidx = 0;
pulse = -1;
Expand All @@ -1814,8 +1798,6 @@ PrinterPostScript::PrinterPostScript(const genericChar* host, int port, const ge
target_type = type;
host_name.Set(host);
port_no = port;
have_title = 0;
page_title.Set("");
putbuffer[0] = '\0';
putbuffidx = 0;
pulse = -1;
Expand Down Expand Up @@ -1877,8 +1859,8 @@ int PrinterPostScript::End()
write(temp_fd, showstring, strlen(showstring));

Close();
have_title = 0;
page_title.Set(""); // reset the title for a new print job
have_title = false;
page_title.clear(); // reset the title for a new print job
return 0;
}

Expand Down Expand Up @@ -1944,9 +1926,9 @@ int PrinterPostScript::Init()
break;
idx += 1;
}
if (have_title == 0)
page_title.Set(GENERIC_TITLE);
snprintf(buffer, STRLENGTH, "(%s) ShowTitleText\n", page_title.Value());
if (!have_title)
page_title = GENERIC_TITLE;
snprintf(buffer, STRLENGTH, "(%s) ShowTitleText\n", page_title.c_str());
write(temp_fd, buffer, strlen(buffer));
return 0;
}
Expand Down Expand Up @@ -2170,8 +2152,6 @@ PrinterPDF::PrinterPDF()
target_type = TARGET_NONE;
host_name.Set("");
port_no = 0;
have_title = 0;
page_title.Set("");
pulse = -1;
term_name.Set("");
}
Expand All @@ -2196,8 +2176,6 @@ PrinterPDF::PrinterPDF(const genericChar* host, int port, const genericChar* tar
target_type = type;
host_name.Set(host);
port_no = port;
have_title = 0;
page_title.Set("");
pulse = -1;
term_name.Set("");
}
Expand Down Expand Up @@ -2258,8 +2236,6 @@ PrinterReceiptText::PrinterReceiptText()
target_type = 0;
host_name.Set("");
port_no = 0;
have_title = 0;
page_title.Set("");
pulse = -1;
term_name.Set("");
}
Expand All @@ -2284,8 +2260,6 @@ PrinterReceiptText::PrinterReceiptText(const genericChar* host, int port, const
target_type = type;
host_name.Set(host);
port_no = port;
have_title = 0;
page_title.Set("");
pulse = -1;
term_name.Set("");
}
Expand All @@ -2308,17 +2282,17 @@ int PrinterReceiptText::End()
return 1;

Close();
have_title = 0;
page_title.Set(""); // reset the title for a new print job
have_title = false;
page_title.clear(); // reset the title for a new print job
return 0;
}

int PrinterReceiptText::Init()
{
FnTrace("PrinterReceiptText::Init()");

if (have_title == 0)
page_title.Set(GENERIC_TITLE);
if (!have_title)
page_title = GENERIC_TITLE;

return 0;
}
Expand Down Expand Up @@ -2368,8 +2342,6 @@ PrinterReportText::PrinterReportText(const genericChar* host, int port, const ge
target_type = type;
host_name.Set(host);
port_no = port;
have_title = 0;
page_title.Set("");
pulse = -1;
term_name.Set("");
}
Expand Down
8 changes: 5 additions & 3 deletions main/printer.hh
Expand Up @@ -23,6 +23,8 @@

#include "utility.hh"

#include <string>

/**** Definitions ****/
#define PRINT_RED 1 // use red ink (if available)
#define PRINT_BOLD 2 // bold text
Expand Down Expand Up @@ -119,8 +121,8 @@ protected:
int port_no; // TCP/IP port number
int active_flags; // flags always on (print mode)
int printer_type; // receipt, report, etc.
int have_title;
Str page_title;
bool have_title = false;
std::string page_title;
int kitchen_mode;

virtual int WriteFlags(int flags) = 0;
Expand All @@ -146,7 +148,7 @@ public:
virtual int KitchenMode() { return kitchen_mode; }
virtual int SetType(int type);
virtual int IsType(int type);
virtual int SetTitle(const genericChar* title);
virtual int SetTitle(const std::string &title);
virtual int Open();
virtual int Close();
virtual int ParallelPrint();
Expand Down
2 changes: 1 addition & 1 deletion main/system.cc
Expand Up @@ -342,7 +342,7 @@ Archive *System::NewArchive()
return archive;
}

Archive *System::FindByTime(TimeInfo &timevar)
Archive *System::FindByTime(const TimeInfo &timevar)
{
FnTrace("System::FindByTime()");
Archive *archive = ArchiveListEnd();
Expand Down
2 changes: 1 addition & 1 deletion main/system.hh
Expand Up @@ -170,7 +170,7 @@ public:
int Remove(Archive *archive);
Archive *NewArchive();
// start a new archive
Archive *FindByTime(TimeInfo &tm);
Archive *FindByTime(const TimeInfo &tm);
// finds archive containing time
Archive *FindByStart(TimeInfo &tm);
// finds 1st archive starting at or after time
Expand Down
4 changes: 2 additions & 2 deletions main/terminal.cc
Expand Up @@ -3131,13 +3131,13 @@ const genericChar* Terminal::Translate(const genericChar* str, int lang, int cle
return MasterLocale->Translate(str, lang, clear);
}

const genericChar* Terminal::TimeDate(TimeInfo &timevar, int format, int lang)
const genericChar* Terminal::TimeDate(const TimeInfo &timevar, int format, int lang)
{
FnTrace("Terminal::TimeDate(timeinfo, int, int)");
return MasterLocale->TimeDate(GetSettings(), timevar, format, lang);
}

const genericChar* Terminal::TimeDate(genericChar* buffer, TimeInfo &timevar, int format, int lang)
const genericChar* Terminal::TimeDate(genericChar* buffer, const TimeInfo &timevar, int format, int lang)
{
FnTrace("Terminal::TimeDate(char, timeinfo, int, int)");
return MasterLocale->TimeDate(GetSettings(), timevar, format, lang, buffer);
Expand Down
4 changes: 2 additions & 2 deletions main/terminal.hh
Expand Up @@ -527,8 +527,8 @@ public:
int FrameID(int frame, int state=0);

const genericChar* Translate(const char* string, int lang = LANG_PHRASE, int clear = 0); // calls proper local object for text translation
const genericChar* TimeDate(TimeInfo &tm, int format, int lang = LANG_PHRASE);
const genericChar* TimeDate(char* str, TimeInfo &tm, int format, int lang = LANG_PHRASE); // returns time and date formated & translated
const genericChar* TimeDate(const TimeInfo &tm, int format, int lang = LANG_PHRASE);
const genericChar* TimeDate(char* str, const TimeInfo &tm, int format, int lang = LANG_PHRASE); // returns time and date formated & translated
const genericChar* PageNo(int current, int max, int lang = LANG_PHRASE); // returns nicely formated & translated page numbers
const genericChar* UserName(int user_id);
genericChar* UserName(char* str, int user_id); // returns string with user name
Expand Down

0 comments on commit 721ac11

Please sign in to comment.