示例#1
0
static void
standard_output (void)
{
  /* CSV */
  if (conf.output_format && strcmp ("csv", conf.output_format) == 0)
    output_csv (logger, holder);
  /* JSON */
  else if (conf.output_format && strcmp ("json", conf.output_format) == 0)
    output_json (logger, holder);
  /* HTML */
  else
    output_html (logger, holder);
}
// After calling CreateCollage(), call this function to save result
// collage to a html file specified by out_put_html_path.
bool CollageBasic::OutputCollageHtml(const std::string output_html_path) {
  assert(canvas_alpha_ != -1);
  assert(canvas_width_ != -1);
  std::ofstream output_html(output_html_path.c_str());
  if (!output_html) {
    std::cout << "Error: OutputCollageHtml" << std::endl;
  }
  
  output_html << "<!DOCTYPE html>\n";
  output_html << "<html>\n";
  output_html << "<h1 style=\"text-align:left\">\n";
  output_html << "\tImage Collage\n";
  output_html << "</h1>\n";
  output_html << "<hr //>\n";
  output_html << "\t<body>\n";
  output_html << "\t\t<div style=\"position:absolute;\">\n";
  for (int i = 0; i < image_num_; ++i) {
    int img_ind = tree_leaves_[i]->image_index_;
    output_html << "\t\t\t<a href=\"";
    output_html << image_path_vec_[img_ind];
    output_html << "\">\n";
    output_html << "\t\t\t\t<img src=\"";
    output_html << image_path_vec_[img_ind];
    output_html << "\" style=\"position:absolute; width:";
    output_html << tree_leaves_[i]->position_.width_;
    output_html << "px; height:";
    output_html << tree_leaves_[i]->position_.height_;
    output_html << "px; left:";
    output_html << tree_leaves_[i]->position_.x_;
    output_html << "px; top:";
    output_html << tree_leaves_[i]->position_.y_;
    output_html << "px;\">\n";
    output_html << "\t\t\t</a>\n";
  }
  output_html << "\t\t</div>\n";
  output_html << "\t</body>\n";
  output_html << "</html>";
  output_html.close();
  return true;
}
示例#3
0
int
main (int argc, char **argv)
{
  int quit = 0;

#if defined(__GLIBC__)
  setup_signal_handlers ();
#endif

  /* command line/config options */
  verify_global_config (argc, argv);
  parse_conf_file (&argc, &argv);
  parse_cmd_line (argc, argv);

  /* initialize storage */
  init_storage ();
  /* setup to use the current locale */
  set_locale ();

#ifdef HAVE_LIBGEOIP
  init_geoip ();
#endif

  /* init logger */
  logger = init_log ();
  /* init parsing spinner */
  parsing_spinner = new_gspinner ();
  parsing_spinner->process = &logger->process;

  /* outputting to stdout */
  if (conf.output_html) {
    ui_spinner_create (parsing_spinner);
    goto out;
  }

  /* init curses */
  set_input_opts ();
  if (conf.no_color || has_colors () == FALSE) {
    conf.color_scheme = NO_COLOR;
    conf.no_color = 1;
  } else {
    start_color ();
  }
  init_colors ();
  init_windows (&header_win, &main_win);
  set_curses_spinner (parsing_spinner);

  /* configuration dialog */
  if (isatty (STDIN_FILENO) && (conf.log_format == NULL || conf.load_conf_dlg)) {
    refresh ();
    quit = verify_format (logger, parsing_spinner);
  }
  /* straight parsing */
  else {
    ui_spinner_create (parsing_spinner);
  }

out:

  /* main processing event */
  time (&start_proc);
  if (conf.load_from_disk)
    set_general_stats ();
  else if (!quit && parse_log (&logger, NULL, -1))
    FATAL ("Error while processing file");

  logger->offset = logger->process;

  /* no valid entries to process from the log */
  if ((logger->process == 0) || (logger->process == logger->invalid))
    FATAL ("Nothing valid to process.");

  /* init reverse lookup thread */
  gdns_init ();
  parse_initial_sort ();
  allocate_holder ();

  end_spinner ();
  time (&end_proc);

  /* stdout */
  if (conf.output_html) {
    /* CSV */
    if (conf.output_format && strcmp ("csv", conf.output_format) == 0)
      output_csv (logger, holder);
    /* JSON */
    else if (conf.output_format && strcmp ("json", conf.output_format) == 0)
      output_json (logger, holder);
    /* HTML */
    else
      output_html (logger, holder);
  }
  /* curses */
  else {
    allocate_data ();
    if (!conf.skip_term_resolver)
      gdns_thread_create ();

    render_screens ();
    get_keys ();

    attroff (COLOR_PAIR (COL_WHITE));
    /* restore tty modes and reset
     * terminal into non-visual mode */
    endwin ();
  }
  /* clean */
  house_keeping ();

  return EXIT_SUCCESS;
}
示例#4
0
int main(int argc, char **argv)
{
    if(argc < 2) { fprintf(stderr, "Usage: %s [port]\n", argv[0]); return 1; }

    int socket_server, socket_client;
    struct sockaddr_in address_server, address_client;
    handle_put_address(&address_server, "0.0.0.0", atoi(argv[1]));

    handle_socket_open_tcp(&socket_server);
    handle_socket_bind(socket_server, &address_server);
    handle_socket_listen(socket_server, 10);
    while(true)
    {
        handle_socket_accept(&socket_client, socket_server, &address_client);

        char request[HANDLE_HTTP_BUFFER_SIZE];
        read(socket_client, request, sizeof(request));
        if(! strncmp(request, "GET", 3))
        {
            handle_http_header_status(socket_client, 200);
            handle_http_header(socket_client);

            socklen_t address_len = sizeof(address_client);

            char remote_addr[HANDLE_HTTP_BUFFER_SIZE];
            getpeername(socket_client, (struct sockaddr *)&address_client, &address_len);
            handle_get_address(remote_addr, &address_client);

            char time_local[HANDLE_HTTP_BUFFER_SIZE];
            time_t ct = time(NULL);
            struct tm *lt = localtime(&ct);
            strftime(time_local, sizeof(time_local), "%d/%b/%Y:%H:%M:%S %z", lt);

            FILE *log_f = fopen(log_fname, "a");
            int status = 0, byte_sent = 0;
            char remote_user[] = "-", request_head[] = "-", http_referer[] = "-", http_user_agent[] = "-";
            fprintf(log_f,
                "%s - %s [%s] \"%s\" %d %d \"%s\" \"%s\"\n"
                , remote_addr
                , remote_user
                , time_local
                , request_head
                , status
                , byte_sent
                , http_referer
                , http_user_agent
            );
            fclose(log_f);

            char *output[3] = { remote_addr, http_user_agent, request };
            output_html(socket_client, output);
            handle_socket_close(socket_client);
        }
        else
        {
            handle_http_header_status(socket_client, 400);
            handle_socket_close(socket_client);
        }
    }

    return 0;
}
示例#5
0
文件: ctohtml.c 项目: HarryR/sanos
void convert_file(char *source_filename) {
  char html_filename[NAME_MAX + 1];
  char *relative_filename;
  char *base_filename;
  char *ext, *p;
  int is_c = 0;
  int is_asm = 0;
  FILE *src;
  FILE *out;
  int line_num;
  char line[STRSIZE];
  char filename[STRSIZE];
  char token[STRSIZE];
  char url[STRSIZE];
  int in_comment;
  
  relative_filename = source_filename + source_prefix_len;
  ext = "";
  base_filename = relative_filename;
  p = relative_filename;
  while (*p) {
    if (*p == '/') {
      base_filename = p + 1;
      ext = "";
    }
    if (*p == '.') ext = p;
    p++;
  }
  
  strcpy(html_filename, output_dir);
  strcat(html_filename, "/");
  strcat(html_filename, relative_filename);
  strcat(html_filename, ".html");

  if (strcmp(ext, ".c") == 0) is_c = 1;
  if (strcmp(ext, ".h") == 0) is_c = 1;
  if (strcmp(ext, ".cpp") == 0) is_c = 1;
  if (strcmp(ext, ".asm") == 0) is_asm = 1;
  if (strcmp(ext, ".s") == 0) is_asm = 1;

  if (!is_c && !is_asm) return;
  
  src = fopen(source_filename, "rt");
  if (!src) {
    perror(source_filename);
    return;
  }
  
  out = fopen(html_filename, "wb");
  if (!out) {
    perror(html_filename);
    return;
  }

  fprintf(out, "<html>\r\n");
  fprintf(out, "<head>\r\n");
  fprintf(out, "<title>%s - %s</title>\r\n", base_filename, title);
  fprintf(out, "<style type='text/css'>\r\n");
  fprintf(out, "a:link {text-decoration: none; color:inherit}\r\n");
  fprintf(out, "a:visited {text-decoration: none; color:inherit}\r\n");
  fprintf(out, "a:active {text-decoration: none; color:inherit}\r\n");
  fprintf(out, "</style>\r\n");
  fprintf(out, "</head>\r\n");
  fprintf(out, "<body>\r\n");
  if (source_index) {
    fprintf(out, "<p style='float: right'><a href='/sanos/source/index.html'>Goto sanos source index</a></p>");
  }
  fprintf(out, "<pre>\r\n");
  
  line_num = 1;
  in_comment = 0;
  while (fgets(line, sizeof line, src)) {
    char *p = line;
    char *end = line;
    while (*end && *end != '\r' && *end != '\n') end++;
    *end = 0;
    
    if (in_comment) {
      char *comment_start = p;
      fprintf(out, "<font color='green'>");
      while (p < end) {
        if (p[0] == '*' && p[1] == '/') {
          p += 2;
          output_html(out, comment_start, p);
          in_comment = 0;
          fprintf(out, "</font>");
          break;
        }
        p++;
      }
    }

    fprintf(out, "<a name=':%d'></a>", line_num);
    
    if (!is_c) {
      output_html(out, p, end);
      p = end;
    }

    while (p < end) {
      if (p[0] == '/' && p[1] == '/') {
        fprintf(out, "<font color='green'>");
        output_html(out, p, end);
        fprintf(out, "</font>");
        p = end;
      } else if (p[0] == '/' && p[1] == '*') {
        char *comment_start = p;
        fprintf(out, "<font color='green'>");
        while (p < end) {
          if (p[0] == '*' && p[1] == '/') {
            p += 2;
            output_html(out, comment_start, p);
            in_comment = 0;
            fprintf(out, "</font>");
            break;
          }
          p++;
        }
      } else if (*p == '\'' || *p == '"') {
        char *start = p++;
        while (*p && *p != *start) {
          if (*p == '\\' && *(p + 1)) p++;
          p++;
        }
        if (*p) p++;
        fprintf(out, "<font color='brown'>");
        output_html(out, start, p);
        fprintf(out, "</font>");
      } else if (*p == '#' || *p == '_' || isalpha(*p)) {
        char *start = p++;
        while (*p && (*p == '_' || isalnum(*p))) p++;
        memcpy(token, start, p - start);
        token[p - start] = 0;
        if (is_keyword(token)) {
          fprintf(out, "<font color='blue'>");
          output_html(out, start, p);
          fprintf(out, "</font>");
          
          if (strncmp(start, "#include", 8) == 0) {
            start = p;
            while (isspace(*p)) p++;
            output_html(out, start, p);
            
            if (*p == '"' || *p == '<') {
              int stdincl = *p == '<';
              output_html(out, p, p + 1);
              start = ++p;
              while (*p && *p != '>' && *p != '"') p++;
              if (stdincl) {
                char *base;
                
                strcpy(filename, include_dir);
                strcat(filename, "/");
                base = filename + strlen(filename);
                memcpy(base, start, p - start);
                base[p - start] = 0;
              } else {
                int pathlen = base_filename - relative_filename;
                int fnlen = p - start;
                memcpy(filename, relative_filename, pathlen);
                memcpy(filename + pathlen, start, fnlen);
                filename[pathlen + fnlen] = 0;
              }
              relative_url(relative_filename, filename, url);
              fprintf(out, "<a href='%s.html'>", url);
              output_html(out, start, p);
              fprintf(out, "</a>");
              if (*p) {
                output_html(out, p, p + 1);
                p++;
              }
            }
          }
        } else {
          struct tag *tag = find_tag(token, relative_filename);
          if (tag) {
            int self;
            
            relative_url(relative_filename, tag->file, url);
            self = strcmp(url, base_filename) == 0 && tag->line == line_num;
            if (!self) fprintf(out, "<a href='%s.html#:%d'>", url, tag->line);
            output_html(out, start, p);
            if (!self) fprintf(out, "</a>");
          } else {
            output_html(out, start, p);
          }
        }
      } else {
        output_html(out, p, p + 1);
        p++;
      }
    }
    if (in_comment) fprintf(out, "</font>");
    fprintf(out, "\r\n", line);
    line_num++;
  }
  
  fprintf(out, "</pre>\r\n");
  fprintf(out, "</body>\r\n");
  fprintf(out, "</html>\r\n");

  fclose(src);
  fclose(out);
}