Example #1
0
int main(int argc, char **argv)
{
    FILE    *file;
    Hubyte   mac[6];

    mac[0] = 0x00;    mac[1] = 0xE0;
    mac[2] = 0x18;    mac[3] = 0xE4;
    mac[4] = 0xB2;    mac[5] = 0x74;

    eth_init( mac );
    setup_ncurses();

    num_packets = 0;
    num_bytes   = 0;
    res_total   = 0;
    res_number  = 0;
    res_max     = 0;
    res_min     = 0;
    
    file = open_file( argv[1] );
    log_data( file );

    close_ncurses();
    eth_destroy();
    return 0;
}
Example #2
0
int main(int argc, char * const * argv) {
    int n_screen_log_lines = 5;
    char *cvalue = NULL;
    int index;
    int option;
    struct timeval start_time;
    gettimeofday(&start_time, NULL);

    opterr = 0;
    while ((option = getopt (argc, argv, "0123456789n:")) != -1)
      switch (option) {
          case '0': n_screen_log_lines = 0; break;
          case '1': n_screen_log_lines = 1; break;
          case '2': n_screen_log_lines = 2; break;
          case '3': n_screen_log_lines = 3; break;
          case '4': n_screen_log_lines = 4; break;
          case '5': n_screen_log_lines = 5; break;
          case '6': n_screen_log_lines = 6; break;
          case '7': n_screen_log_lines = 7; break;
          case '8': n_screen_log_lines = 8; break;
          case '9': n_screen_log_lines = 9; break;
          case 'n':
            sscanf(optarg, "%d", &n_screen_log_lines);
            break;
          case '?':
            if (optopt == 'n')
              fprintf (stderr, "Option -%c requires an argument.\n", optopt);
            else if (isprint (optopt))
              fprintf (stderr, "Unknown option `-%c'.\n", optopt);
            else
              fprintf (stderr, "Unknown option character `\\x%x'.\n", optopt);
            return 1;
          default:
            abort ();
      }
    //printf ("num log lines = %d\n", n_screen_log_lines);

    int buf_index = 0;
    FILE *log_file;
    int num_buffers = n_screen_log_lines ? : 2;
    char buffer[num_buffers][LINE_BUFFER_SIZE];

    // Retrieve first line of input.  Default is to use it for determining log file name.
    char * fgets_return = fgets(buffer[buf_index], LINE_BUFFER_SIZE, stdin);
    if (fgets_return == NULL) return 0;

    // Open log file.
    char * filename;
    if (optind < argc) {
        filename = (char *)argv[optind];
    } else {
        char filename_buf[128];
        filename = filename_buf;
        // Use first word as file name.
        // Scan for space.
        char c;
        int space_loc = 0;
        while ((c = buffer[buf_index][space_loc]) != 0) {
            if (c == ' ') {
                break;
            }
            space_loc++;
        }
        int last_char_loc = space_loc;
        if (buffer[buf_index][last_char_loc] != ' ') last_char_loc -= 1;
        if (last_char_loc > 123 ) last_char_loc = 123;
        if (last_char_loc < 0 ) last_char_loc = 0;
        strncpy(filename, buffer[buf_index], last_char_loc);
        strcpy(&filename[last_char_loc], ".log");
        printf("\t\t\t\tLog file: %s\n", filename );
    }
    log_file = fopen(filename, "w");
    
    // Set up ncurses
    term_type = getenv("TERM");
    if (term_type == NULL || *term_type == '\0') {
        term_type = "unknown";
    }
    term_in = fopen("/dev/tty", "r");
    if (term_in == NULL) {
        perror("fopen(/dev/tty)");
        return 1;
    }
    setup_ncurses();
    // Done setting up ncurses

    int throttle_mode = TRUE;
    
    // Read input and write output loop
    while(fgets_return != NULL) {
        if (ncurses_active) {
            /*
            struct timeval end_time;
            gettimeofday(&end_time, NULL);
            long usec = end_time.tv_usec - start_time.tv_usec;
            int long_time_elapsed = (usec < 0 || usec > (1000 * 10));
            int c = getchar();
            ungetc(c, stdin);
            int input_waiting = (c != EOF); 
            if (!input_waiting || long_time_elapsed) {
            */
                printw("%s", buffer[buf_index]);
                refresh();      // Ask ncurses to update the screen.
                /*
                gettimeofday(&start_time, NULL);
            }
            */
        }
        fputs(buffer[buf_index], log_file); 
        buf_index++;
        if (buf_index >= num_buffers) buf_index = 0;
        fgets_return = fgets(buffer[buf_index], LINE_BUFFER_SIZE, stdin);
    }
    endwin();   // ncurses mode exit.

    // Log the last few lines to stdout.
    int j;
    for (j = 0; j < n_screen_log_lines; j++) {
        fputs(buffer[buf_index], stdout);
        buf_index += 1;
        if (buf_index >= n_screen_log_lines) buf_index = 0;
    }

    return 0;
}
Example #3
0
static void catch_alarm(int signo) {
    //printf("\t\t\t\t\tAlarm caught.\n");
    setup_ncurses();
}