26 long i, j, len, excess, width;
29 max_strlen = min_width;
30 for (i = 0; i < n_headers; i++) {
32 width = format_length(item[i]) + 2;
33 if (width > max_strlen)
35 }
else if ((len = strlen(item[i])) > max_strlen)
39 for (i = 0; i < n_headers; i++) {
41 excess = max_strlen - strlen(item[i]);
42 len = excess / 2.0 + 0.5;
43 ptr = header[i] + strlen(header[i]);
44 for (j = 0; j < len; j++, ptr++)
48 strcat(header[i], item[i]);
49 ptr = header[i] + strlen(header[i]);
50 for (j = 0; j < excess; j++, ptr++)
54 excess = max_strlen - format_length(item[i]);
56 ptr = header[i] + strlen(header[i]);
57 for (j = 0; j < len; j++, ptr++)
62 ptr = header[i] + strlen(header[i]);
63 for (j = 0; j < excess; j++, ptr++)
70long format_length(
char *format) {
75 if (*ptr !=
'%' || *(ptr + 1) ==
'%' || 1 != sscanf(ptr + 1,
"%ld", &width) || width <= 0)
76 bomb(
"format specifier invalid", NULL);
107 header[0] = name_header;
108 header[1] = unit_header;
109 header[2] = printf_string;
112 item[2] = new_format;
113 add_to_headers(header, 3, item, min_width, 2);
void bomb(char *error, char *usage)
Reports error messages to the terminal and aborts the program.