Ticket #3727: src_filemanager_info.c.diff

File src_filemanager_info.c.diff, 3.0 KB (added by boruch, 7 years ago)
  • (a) mc-github/src/filemanager/info.c vs. (b) info.c_002

    a b  
    104104info_show_info (WInfo * info) 
    105105{ 
    106106    Widget *w = WIDGET (info); 
     107    char *fname; 
     108    size_t fname_len = 0; 
    107109    static int i18n_adjust = 0; 
    108110    static const char *file_label; 
    109111    GString *buff; 
     
    154156 
    155157    default: 
    156158 
     159    case 17: 
     160        { 
     161            /* TODO: 
     162             *   error handling: malloc, popen, fgets*2 
     163             *   handle long lines exceeding panel width 
     164             */ 
     165            FILE *command_stream; 
     166            char *command; 
     167            char *command_pos; 
     168            /* command_substr = "file -b -- '';file -bi -- ''" */ 
     169            const size_t command_substr_len = 28; 
     170            /* size of command_outputs arbitrarily / staticly set */ 
     171#define CMD_OUT_LEN 1024 
     172            char command_output_1[CMD_OUT_LEN]; 
     173            char command_output_2[CMD_OUT_LEN]; 
     174 
     175            fname = current_panel->dir.list[current_panel->selected].fname; 
     176            fname_len = strlen (fname); 
     177            command = malloc ((fname_len * 2) + command_substr_len + 1); 
     178            if (command == NULL) 
     179                goto malloc_error_case_17; 
     180            command_pos = stpcpy (command, "file -b -- '"); 
     181            command_pos = stpcpy (command_pos, fname); 
     182            command_pos = stpcpy (command_pos, "';file -bi -- '"); 
     183            command_pos = stpcpy (command_pos, fname); 
     184            command_pos = stpcpy (command_pos, "'"); 
     185            command_stream = popen (command, "r"); 
     186            fgets (command_output_1, CMD_OUT_LEN, command_stream); 
     187            command_output_1[strlen (command_output_1) - 1] = '\0'; 
     188            fgets (command_output_2, CMD_OUT_LEN, command_stream); 
     189            command_output_2[strlen (command_output_2) - 1] = '\0'; 
     190            widget_move (w, 17, 3); 
     191            str_printf (buff, _("Mime Type:  %s (%s)"), command_output_1, command_output_2); 
     192            tty_print_string (buff->str); 
     193            g_string_set_size (buff, 0); 
     194            pclose (command_stream); 
     195        } 
     196      malloc_error_case_17:    /* Yes, I also hate gotos, but this is a fall-through switch */ 
     197 
    157198    case 16: 
    158199        widget_move (w, 16, 3); 
    159200        if ((myfs_stats.nfree == 0 && myfs_stats.nodes == 0) || 
     
    259300        tty_printf (_("Location:   %Xh:%Xh"), (int) st.st_dev, (int) st.st_ino); 
    260301 
    261302    case 3: 
    262         { 
    263             const char *fname; 
    264  
    265             widget_move (w, 3, 2); 
    266             fname = current_panel->dir.list[current_panel->selected].fname; 
    267             str_printf (buff, file_label, str_trunc (fname, w->cols - i18n_adjust)); 
    268             tty_print_string (buff->str); 
    269         } 
     303        widget_move (w, 3, 2); 
     304        /* fname assignment possibly redundant now; see case 17, above */ 
     305        fname = current_panel->dir.list[current_panel->selected].fname; 
     306        str_printf (buff, file_label, str_trunc (fname, w->cols - i18n_adjust)); 
     307        tty_print_string (buff->str); 
    270308 
    271309    case 2: 
    272310    case 1: