Ticket #3727: src_filemanager_info.c.diff_v02

File src_filemanager_info.c.diff_v02, 5.9 KB (added by boruch, 5 years ago)

Separates out filesystem info from file info; correct2 two TRAVIS warnings

Line 
1--- mc-github/src/filemanager/info.c_orig       2016-11-17 13:46:14.597732771 -0500
2+++ mc-github/src/filemanager/info.c    2016-11-18 04:42:52.913005798 -0500
3@@ -104,6 +104,8 @@
4 info_show_info (WInfo * info)
5 {
6     Widget *w = WIDGET (info);
7+    char *fname;
8+    size_t fname_len = 0;
9     static int i18n_adjust = 0;
10     static const char *file_label;
11     GString *buff;
12@@ -154,8 +156,8 @@
13 
14     default:
15 
16-    case 16:
17-        widget_move (w, 16, 3);
18+    case 18:
19+        widget_move (w, 18, 3);
20         if ((myfs_stats.nfree == 0 && myfs_stats.nodes == 0) ||
21             (myfs_stats.nfree == (uintmax_t) (-1) && myfs_stats.nodes == (uintmax_t) (-1)))
22             tty_print_string (_("No node information"));
23@@ -169,9 +171,8 @@
24                         myfs_stats.nfree, myfs_stats.nodes,
25                         myfs_stats.nodes == 0 ? 0 :
26                         (int) (100 * (long double) myfs_stats.nfree / myfs_stats.nodes));
27-
28-    case 15:
29-        widget_move (w, 15, 3);
30+    case 17:
31+        widget_move (w, 17, 3);
32         if (myfs_stats.avail == 0 && myfs_stats.total == 0)
33             tty_print_string (_("No space information"));
34         else
35@@ -184,26 +185,67 @@
36                         myfs_stats.total == 0 ? 0 :
37                         (int) (100 * (long double) myfs_stats.avail / myfs_stats.total));
38         }
39-
40-    case 14:
41-        widget_move (w, 14, 3);
42+    case 16:
43+        widget_move (w, 16, 3);
44         tty_printf (_("Type:       %s"),
45                     myfs_stats.typename ? myfs_stats.typename : _("non-local vfs"));
46         if (myfs_stats.type != 0xffff && myfs_stats.type != -1)
47             tty_printf (" (%Xh)", myfs_stats.type);
48-
49-    case 13:
50-        widget_move (w, 13, 3);
51+    case 15:
52+        widget_move (w, 15, 3);
53         str_printf (buff, _("Device:     %s"),
54                     str_trunc (myfs_stats.device, w->cols - i18n_adjust));
55         tty_print_string (buff->str);
56         g_string_set_size (buff, 0);
57-    case 12:
58-        widget_move (w, 12, 3);
59+    case 14:
60+        widget_move (w, 14, 2);
61         str_printf (buff, _("Filesystem: %s"),
62                     str_trunc (myfs_stats.mpoint, w->cols - i18n_adjust));
63         tty_print_string (buff->str);
64         g_string_set_size (buff, 0);
65+    case 13:
66+        /* Placeholder comment for blank line */
67+    case 12:
68+        {
69+            /* TODO:
70+             *   error handling: malloc, popen, fgets*2
71+             *   handle long lines exceeding panel width
72+             */
73+            FILE *command_stream;
74+            char *command;
75+            char *command_pos;
76+            /* command_substr = "file -b -- '';file -bi -- ''" */
77+            const size_t command_substr_len = 28;
78+            /* size of command_outputs arbitrarily / staticly set */
79+#define CMD_OUT_LEN 1024
80+            char command_output_1[CMD_OUT_LEN];
81+            char command_output_2[CMD_OUT_LEN];
82+             /* data sink to avoid build errors. Do not use for logic */
83+            char *sink;
84+
85+            fname = current_panel->dir.list[current_panel->selected].fname;
86+            fname_len = strlen (fname);
87+            command = malloc ((fname_len * 2) + command_substr_len + 1);
88+            if (command == NULL)
89+                goto malloc_error_case_17;
90+            command_pos = stpcpy (command, "file -b -- '");
91+            command_pos = stpcpy (command_pos, fname);
92+            command_pos = stpcpy (command_pos, "';file -bi -- '");
93+            command_pos = stpcpy (command_pos, fname);
94+            command_pos = stpcpy (command_pos, "'");
95+            command_stream = popen (command, "r");
96+            sink = fgets (command_output_1, CMD_OUT_LEN, command_stream);
97+            command_output_1[strlen (command_output_1) - 1] = '\0';
98+            sink = fgets (command_output_2, CMD_OUT_LEN, command_stream);
99+            command_output_2[strlen (command_output_2) - 1] = '\0';
100+            widget_move (w, 12, 3);
101+            str_printf (buff, _("Mime Type:  %s (%s)"), command_output_1, command_output_2);
102+            tty_print_string (buff->str);
103+            g_string_set_size (buff, 0);
104+            pclose (command_stream);
105+            free(command);
106+        }
107+      malloc_error_case_17:    /* Yes, I also hate gotos, but this is a fall-through switch */
108     case 11:
109         widget_move (w, 11, 3);
110         str_printf (buff, _("Accessed:   %s"), file_date (st.st_atime));
111@@ -222,7 +264,6 @@
112         str_printf (buff, _("Changed:    %s"), file_date (st.st_ctime));
113         tty_print_string (buff->str);
114         g_string_set_size (buff, 0);
115-
116     case 8:
117         widget_move (w, 8, 3);
118 #ifdef HAVE_STRUCT_STAT_ST_RDEV
119@@ -240,33 +281,25 @@
120                                   (unsigned long) st.st_blocks), (unsigned long) st.st_blocks);
121 #endif
122         }
123-
124     case 7:
125         widget_move (w, 7, 3);
126         tty_printf (_("Owner:      %s/%s"), get_owner (st.st_uid), get_group (st.st_gid));
127-
128     case 6:
129         widget_move (w, 6, 3);
130         tty_printf (_("Links:      %d"), (int) st.st_nlink);
131-
132     case 5:
133         widget_move (w, 5, 3);
134         tty_printf (_("Mode:       %s (%04o)"),
135                     string_perm (st.st_mode), (unsigned) st.st_mode & 07777);
136-
137     case 4:
138         widget_move (w, 4, 3);
139         tty_printf (_("Location:   %Xh:%Xh"), (int) st.st_dev, (int) st.st_ino);
140-
141     case 3:
142-        {
143-            const char *fname;
144-
145-            widget_move (w, 3, 2);
146-            fname = current_panel->dir.list[current_panel->selected].fname;
147-            str_printf (buff, file_label, str_trunc (fname, w->cols - i18n_adjust));
148-            tty_print_string (buff->str);
149-        }
150+        widget_move (w, 3, 2);
151+        /* fname assignment possibly redundant now; see case 17, above */
152+        fname = current_panel->dir.list[current_panel->selected].fname;
153+        str_printf (buff, file_label, str_trunc (fname, w->cols - i18n_adjust));
154+        tty_print_string (buff->str);
155 
156     case 2:
157     case 1: