Browse Source

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 15 years ago
parent
commit
7180b0d31d
4 changed files with 54 additions and 8 deletions
  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 View File

parseCommandType(InputLineStream, NewCommand); // Next is always a command name. parseCommandType(InputLineStream, NewCommand); // Next is always a command name.
parseCommandData(InputLineStream, NewCommand); // The rest is data for the command. 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; return NewCommand;
} }

+ 48
- 5
SNF4CGP/JobPool.cpp View File

OutputBuffer.append(O.str()); OutputBuffer.append(O.str());
} }
void Job::emitResponsePrevix() {
}
void Job::emitOK() { void Job::emitOK() {
ostringstream O;
O << CurrentCommand.Number << " OK" << endl;
OutputBuffer.append(O.str());
} }
const string INTFVersion = "1";
void Job::emitINTF() { 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) { 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() { void Job::emitDISCARD() {
ostringstream O;
O << CurrentCommand.Number << " DISCARD" << endl;
OutputBuffer.append(O.str());
}
void Job::emitREJECTED(string Report) {
} }
void Job::finalize() { void Job::finalize() {
} }
void Job::doINTF() { void Job::doINTF() {
emitINTF();
} }
void Job::doFAIL() { void Job::doFAIL() {
ostringstream O;
O << "SNF4CGP Does not understand: " << formatAsCGPString(CurrentCommand.Data);
emitComment(O.str());
emitFAILURE();
} }
void Job::doFILE() { void Job::doFILE() {

+ 3
- 3
SNF4CGP/JobPool.hpp View File

void emitCommentPrefix(); void emitCommentPrefix();
void emitComment(string Comment); void emitComment(string Comment);
void emitResponsePrevix();
void emitOK(); void emitOK();
void emitINTF(); void emitINTF();
void emitFAIL();
void emitFAILURE();
void emitADDHEADER(string Headers); void emitADDHEADER(string Headers);
void emitERROR();
void emitERROR(string Report);
void emitDISCARD(); void emitDISCARD();
void emitREJECTED(string Report);
void finalize(); void finalize();

+ 1
- 0
SNF4CGP/OutputProcessor.cpp View File

void OutputProcessor::handleJob(Job& J) { // Process a job. void OutputProcessor::handleJob(Job& J) { // Process a job.
CurrentThreadState(PostingResponses); CurrentThreadState(PostingResponses);
cout << J.Responses(); cout << J.Responses();
cout.flush();
J.clear(); J.clear();
RecycledJobs().drop(J); RecycledJobs().drop(J);
} }

Loading…
Cancel
Save