Ticket #2290: mc-4.8.10-refresh-size+time-gtod.patch

File mc-4.8.10-refresh-size+time-gtod.patch, 3.0 KB (added by sknaumov, 10 years ago)

The same patch as mc-4.8.10-refresh-size+time.patch, but uses gettimeofday() instead of clock_gettime().

  • src/filemanager/find.c

    diff -uNr mc-4.8.10.configured/src/filemanager/find.c mc-4.8.10.refresh-size+time-gtod/src/filemanager/find.c
    old new  
    149149static gboolean is_start = FALSE;       /* Status of the start/stop toggle button */ 
    150150static char *old_dir = NULL; 
    151151 
     152#define MAX_REFRESH_INTERVAL  50000        /* 50 ms */ 
     153#define MIN_REFRESH_FILE_SIZE (256 * 1024) /* 256 KB */ 
     154static struct timeval last_refresh; 
     155 
    152156/* Where did we stop */ 
    153157static gboolean resuming; 
    154158static int last_line; 
     
    978982    int file_fd; 
    979983    gboolean ret_val = FALSE; 
    980984    vfs_path_t *vpath; 
     985    struct timeval tv; 
     986    time_t seconds; 
     987    suseconds_t useconds; 
     988    gboolean status_updated = FALSE; 
    981989 
    982990    vpath = vfs_path_build_filename (directory, filename, (char *) NULL); 
    983991 
     
    9931001    if (file_fd == -1) 
    9941002        return FALSE; 
    9951003 
    996     g_snprintf (buffer, sizeof (buffer), _("Grepping in %s"), filename); 
    997     status_update (str_trunc (buffer, WIDGET (h)->cols - 8)); 
     1004    /* get time elapsed from last refresh */ 
     1005    if (-1 == gettimeofday(&tv, NULL)) { 
     1006        tv.tv_sec = 0; 
     1007        tv.tv_usec = 0; 
     1008        last_refresh = tv; 
     1009    } 
     1010    seconds = tv.tv_sec - last_refresh.tv_sec; 
     1011    useconds = tv.tv_usec - last_refresh.tv_usec; 
     1012    if (useconds < 0) { 
     1013        seconds -= 1; 
     1014        useconds += 1000000; 
     1015    } 
     1016 
     1017    if (s.st_size >= MIN_REFRESH_FILE_SIZE || 
     1018        seconds > 0 || 
     1019        useconds > MAX_REFRESH_INTERVAL) 
     1020    { 
     1021        g_snprintf (buffer, sizeof (buffer), _("Grepping in %s"), filename); 
     1022        status_update (str_trunc (buffer, WIDGET (h)->cols - 8)); 
    9981023 
    999     mc_refresh (); 
     1024        mc_refresh (); 
     1025        last_refresh = tv; 
     1026        status_updated = TRUE; 
     1027    } 
    10001028 
    10011029    tty_enable_interrupt_key (); 
    10021030    tty_got_interrupt (); 
     
    10631091                && mc_search_run (search_content_handle, 
    10641092                                  (const void *) strbuf, 0, i, &found_len)) 
    10651093            { 
     1094                if (status_updated == FALSE) { 
     1095                    /* if we add results for a file, we have to ensure that 
     1096                       name of this file is shown in status bar */ 
     1097                    g_snprintf (result, sizeof (result), _("Grepping in %s"), filename); 
     1098                    status_update (str_trunc (result, WIDGET (h)->cols - 8)); 
     1099                    mc_refresh (); 
     1100                    last_refresh = tv; 
     1101                    status_updated = TRUE; 
     1102                } 
     1103 
    10661104                g_snprintf (result, sizeof (result), "%d:%s", line, filename); 
    10671105                find_add_match (directory, result); 
    10681106                found = TRUE; 
     
    18041842        if (pattern[0] == '\0') 
    18051843            break;              /* nothing search */ 
    18061844 
     1845        last_refresh.tv_sec = 0; 
     1846        last_refresh.tv_usec = 0; 
     1847 
    18071848        dirname = filename = NULL; 
    18081849        is_start = FALSE; 
    18091850        clock_gettime(CLOCK_MONOTONIC, &begin);