| 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 | |
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); |