// HTML_ColorerPage2.cpp: implementation of the HTML_ColorerPage2 class. // ////////////////////////////////////////////////////////////////////// #include "../HTML/HTML_all.h" #include "HTML_ColorerPage2.h" ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// HTML_ColorerPage2::HTML_ColorerPage2() { } HTML_ColorerPage2::~HTML_ColorerPage2() { } HTML_ColorerPage* HTML_ColorerPage2::generatePage() { HTML_TextArea* ta; //create general things HTML_ColorerPage::generatePage(); doc->setTitle("Colorer -> Results"); //header row = table->newRow(); cell = row->newCell(); cell->bold()->write("Copy results"); ta = table->newRow()->newCell()->setAlign("center")->newTextArea(); ta ->setCols("80") ->setRows("25") ->setWrap("off") ->setName("asm"); //do the thing ta->write(getResults()); //display errors printErrors(); return(this); } const char* HTML_ColorerPage2::getResults() { FILE* tmp; FILE* old; char ch[2]; fpos_t filestart = 0; output = ""; ch[1] = '\0'; tmp = tmpfile(); if(tmp != NULL) { //redirect Lex output to a file old = yyout; yyout = tmp; //convert to HTML convertInputToHTML(); //call Lex scan_string(input.c_str()); //restore yyout yyout = old; //reset file pointer fsetpos(tmp, &filestart); //read the file to a string while(fread(&ch, 1, 1, tmp) == 1) { output.append(ch); } fclose(tmp); if(keywordsDetected == 0) //global { error("No distinct assembler keywords detected in the input text"); } } return(output.c_str()); } HTML_ColorerPage2* HTML_ColorerPage2::convertInputToHTML() { int i; int size; int pos = 0; int spaces; char ch[2]=" "; if(isHTML) { return(this); } output = "\n\n\n" "\n\n
\n";

	size = input.size();
	for(i = 0; i < size; i++)
	{
			pos++;
			switch(input[i])
			{
			case '\t':
				if(fillTabs != 0)
				{
					spaces = pos - 1; //old position
					pos = spaces - spaces % fillTabs + fillTabs; //new position
					spaces = pos - spaces; //difference
					while(spaces != 0)
					{
						output.append(" ");
						spaces--;
					}
				}
				else
				{
					output.append("\t");
				}
				break;
			case '\n':
				output.append("\n");
				pos = 0; //reset position
				break;
			case '<':
				output.append("<");
				break;
			case '>':
				output.append(">");
				break;
			case '&':
				output.append("&");
				break;
			case '\"':
				output.append(""");
				break;
			default:
				ch[0] = input[i];
				output.append(ch);
				break;
			}
	}
	output.append("\n
\n\n\n"); input = output; output = ""; return(this); }