int ansi_buf::overflow(int c) { if(c == EOF) return 0; if(m_processing_ansi == 1) { if( c == '[' ) // Code terminator { m_code = ""; m_attributes = 0; m_processing_ansi = 2; return(0); } else m_processing_ansi = 0; } if(m_processing_ansi == 2) { if( c == ';' ) // Code terminator { process_code(); m_code = ""; return(0); } else if( c == 'm' ) { m_processing_ansi = false; process_code(); set_attributes(); return(0); } else { m_code.append(reinterpret_cast<char*>(&c), 1); return(0); } } if(c == '\033') { m_processing_ansi = 1; m_code = ""; return(0); } return m_streambuf->sputc(c); }
/* ------------------------------------------- */ int main (int argc, char *argv[]) { char line[LINESZ]; FILE *inFile_p, *outFile_p; char *ptr; int count, largestCount; unsigned lineNum; char code[LINESZ], newcode[LINESZ]; int ret; double coverage; unsigned colour; process_cmdline_args (argc, argv); // open files inFile_p = fopen (inFileName_pG, "r"); if (inFile_p == NULL) { perror ("fopen (inFile)"); return 1; } outFile_p = fopen (outFileName_pG, "w"); if (outFile_p == NULL) { perror ("fopen (outFile)"); return 1; } largestCount = find_largest_count (inFile_p); // start output file fprintf (outFile_p, "<html>\n"); fprintf (outFile_p, "<head><title>%s</title></head>\n", outFileName_pG); fprintf (outFile_p, "<body style=\"padding: 2em 1em 2em 110px; background-position: top left; background-attachment: fixed; background-repeat: no-repeat; background-image: url(gcov2html-check.png);\" bgcolor=\"#000000\"><pre>\n"); // parse through gcov file // to create output while (fgets (line, LINESZ, inFile_p) != NULL) { if (strncmp (line, "function", 8) == 0) continue; if (strncmp (line, "call", 4) == 0) continue; if (strncmp (line, "branch", 6) == 0) continue; // get count ret = sscanf (line, " %d", &count); if (ret == 0) { if (strncmp (line, " #####", 9) == 0) count = 0; else count = -1; } // get line number // skip ':' ptr = strstr (line, ":"); ++ptr; sscanf (ptr, " %u", &lineNum); // get rest of line (code) // skip ':' ptr = strstr (ptr, ":"); ++ptr; strcpy (code, ptr); // remove trailing '\n' ptr = code; while ((*ptr != '\n') && *ptr) ++ptr; *ptr = 0; // calculate colour if (count == -1) colour = 0xffffff; else { coverage = (double)count / (double)largestCount; colour = get_colour (coverage); } process_code (code, newcode, LINESZ); fprintf (outFile_p, "<font color=\"#%06x\">%s</font>\n", colour, newcode); } // end output file fprintf (outFile_p, "</pre></body>\n"); fprintf (outFile_p, "</html>"); // done free (inFileName_pG); free (outFileName_pG); fclose (outFile_p); fclose (inFile_p); return 0; }