Пример #1
0
static void print_raw_ansi(char *buf, size_t buflen, buffered_output_t *output)
{
	size_t i;
	
	for (i = 0; i < buflen; i++)
	{
		if (buf[i] == 0x1b)
			html_output("*", 1, output);
		else
			html_output(&buf[i], 1, output);
	}
}
Пример #2
0
//****************************************************************************
int CTerminal::save_terminal_contents(char *outfile, file_type_e file_type)
{
   FILE *fd = NULL ;
   int lcount = 0 ;
   term_lview_item_p lvptr ;
   char msgstr[260] ;

   char dbuffer [9];
   char tbuffer [9];
   _strdate( dbuffer );
   _strtime( tbuffer );

   switch (file_type) {
   case FTYP_TEXT:
      fd = fopen(outfile, "a+t") ;
      if (fd == NULL) {
         return -(int)GetLastError();
      }
      fseek(fd, 0, SEEK_END) ;
      fprintf(fd, "***********************************************************************\n") ;
      fprintf(fd, "Date/Time of report: %s, %s\n", dbuffer, tbuffer) ;
      for (lvptr = tlv_top; lvptr != NULL; lvptr = lvptr->next) {
         lcount++ ;
         fprintf(fd, "%s\n", lvptr->msg) ;
      }
      break;

   case FTYP_HTML:
      if (file_exists(outfile)) {
         //  from January 1999 MSDN:
         //  When a file is opened with the "a" or "a+" access type, 
         //  all write operations occur at the end of the file. 
         //  The file pointer can be repositioned using fseek or rewind, 
         //  but is always moved back to the end of the file before any 
         //  write operation is carried out. 
         //  Thus, existing data cannot be overwritten.
         // syslog("appending to existing file\n") ;
         fd = fopen(outfile, "r+t") ;
         if (fd == NULL) {
            return -(int)GetLastError();
         }
         fseek(fd, 0, SEEK_END) ;
         //  back up pointer to over-write closing HTML tags
         fseek(fd, (long) -16, SEEK_CUR) ; 
      } else {
         // syslog("writing to html file\n") ;
         fd = fopen(outfile, "wt") ;
         if (fd == NULL) {
            return -(int)GetLastError();
         }
         fprintf(fd, "<html><head><title>%s</title>"
                     //  STYLE was not needed once I converted to using PRE tag.
                     // "<STYLE type='text/css'>\n"
                     // "* { font-family: Courier, monospace }\n"
                     // "</STYLE>\n"
                     "</head><body>\n", outfile) ;
      }
      fprintf(fd, "<pre>\n") ;
      html_output(fd, WIN_BGREEN, WIN_GREY, "***********************************************************************") ;
      sprintf(msgstr, "Date/Time of report: %s, %s", dbuffer, tbuffer) ;
      html_output(fd, WIN_BGREEN, WIN_GREY, msgstr) ;
      for (lvptr = tlv_top; lvptr != NULL; lvptr = lvptr->next) {
         lcount++ ;
         // fprintf(fd, "%s\n", lvptr->msg) ;
         html_output(fd, lvptr->fgnd, lvptr->bgnd, lvptr->msg) ;
      }
      fprintf(fd, "</pre>\n") ;
      fprintf(fd, "</body></html>\n") ;
      break;

   // default:
   //    return -(int)ERROR_INVALID_DATA;
      // break;
   }

   if (fd != NULL) {
      fflush(fd) ;
      fclose(fd) ;
      clear_message_area();
      return lcount ;
   } 
   termout("invalid file_type [%u]", (uint) file_type) ;
   return -(int) ERROR_INVALID_DATA;
}