Quellcode durchsuchen

Added CGP string formatting

Added all command features except FILE


git-svn-id: https://svn.microneil.com/svn/SNF4CGP/trunk@24 59e8e3e7-56fa-483b-b4b4-fa6ab0af3dfc
master
madscientist vor 15 Jahren
Ursprung
Commit
7180b0d31d
4 geänderte Dateien mit 54 neuen und 8 gelöschten Zeilen
  1. 2
    0
      SNF4CGP/InputProcessor.cpp
  2. 48
    5
      SNF4CGP/JobPool.cpp
  3. 3
    3
      SNF4CGP/JobPool.hpp
  4. 1
    0
      SNF4CGP/OutputProcessor.cpp

+ 2
- 0
SNF4CGP/InputProcessor.cpp Datei anzeigen

@@ -52,5 +52,7 @@ Command InputProcessor::getCommand() {
parseCommandType(InputLineStream, NewCommand); // Next is always a command name.
parseCommandData(InputLineStream, NewCommand); // The rest is data for the command.
if(Command::UNKNOWN == NewCommand.Type) NewCommand.Data = InputLine; // Capture unknown inputs for later.
return NewCommand;
}

+ 48
- 5
SNF4CGP/JobPool.cpp Datei anzeigen

@@ -33,25 +33,63 @@ void Job::emitComment(string Comment) {
OutputBuffer.append(O.str());
}
void Job::emitResponsePrevix() {
}
void Job::emitOK() {
ostringstream O;
O << CurrentCommand.Number << " OK" << endl;
OutputBuffer.append(O.str());
}
const string INTFVersion = "1";
void Job::emitINTF() {
ostringstream O;
O << CurrentCommand.Number << " INTF " << INTFVersion << endl;
OutputBuffer.append(O.str());
}
void Job::emitFAIL() {
void Job::emitFAILURE() {
ostringstream O;
O << CurrentCommand.Number << " FAILURE" << endl;
OutputBuffer.append(O.str());
}
string formatAsCGPString(const string& S) {
string CGPString;
CGPString.push_back('"');
for(size_t i = 0; i < S.length(); i++) {
char C = S[i];
switch(C) {
case '\r': break;
case '\t': { CGPString.append("\\t"); break; }
case '\n': { CGPString.append("\\e"); break; }
case '\\': { CGPString.append("\\"); break; }
case '"': { CGPString.append("\\\""); break; }
default: CGPString.push_back(C);
}
}
CGPString.push_back('"');
return CGPString;
}
void Job::emitADDHEADER(string Headers) {
ostringstream O;
O << CurrentCommand.Number << " ADDHEADER " << formatAsCGPString(Headers) << endl;
OutputBuffer.append(O.str());
}
void Job::emitERROR() {
void Job::emitERROR(string Report) {
ostringstream O;
O << CurrentCommand.Number << " ERROR " << formatAsCGPString(Report) << endl;
OutputBuffer.append(O.str());
}
void Job::emitDISCARD() {
ostringstream O;
O << CurrentCommand.Number << " DISCARD" << endl;
OutputBuffer.append(O.str());
}
void Job::emitREJECTED(string Report) {
}
void Job::finalize() {
@@ -64,9 +102,14 @@ void Job::doWakeUp() {
}
void Job::doINTF() {
emitINTF();
}
void Job::doFAIL() {
ostringstream O;
O << "SNF4CGP Does not understand: " << formatAsCGPString(CurrentCommand.Data);
emitComment(O.str());
emitFAILURE();
}
void Job::doFILE() {

+ 3
- 3
SNF4CGP/JobPool.hpp Datei anzeigen

@@ -58,13 +58,13 @@ class Job {
void emitCommentPrefix();
void emitComment(string Comment);
void emitResponsePrevix();
void emitOK();
void emitINTF();
void emitFAIL();
void emitFAILURE();
void emitADDHEADER(string Headers);
void emitERROR();
void emitERROR(string Report);
void emitDISCARD();
void emitREJECTED(string Report);
void finalize();

+ 1
- 0
SNF4CGP/OutputProcessor.cpp Datei anzeigen

@@ -49,6 +49,7 @@ void OutputProcessor::stop() {
void OutputProcessor::handleJob(Job& J) { // Process a job.
CurrentThreadState(PostingResponses);
cout << J.Responses();
cout.flush();
J.clear();
RecycledJobs().drop(J);
}

Laden…
Abbrechen
Speichern