aboutsummaryrefslogtreecommitdiff
path: root/src/output.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/output.c')
-rw-r--r--src/output.c93
1 files changed, 91 insertions, 2 deletions
diff --git a/src/output.c b/src/output.c
index 04cafe7..5c68f17 100644
--- a/src/output.c
+++ b/src/output.c
@@ -25,6 +25,8 @@
/* === DEFINITIONS === */
+#define DM_OUT_FORMAT_MAX_LEN 80
+
#define out_vsep fputc('|', stdout)
#define out_print_newline() fputc('\n', stdout)
@@ -40,6 +42,7 @@ void out_print_time_by_option(struct list_node *ptr);
void out_print_type(struct list_node *ptr);
void out_print_user_name(struct list_node *ptr);
+void out_print_format_string_header(const char *format);
/* === IMPLEMENTATION === */
@@ -174,7 +177,7 @@ inline void out_print_time(time_t tv) {
tm = localtime(&tv);
if (option_timestamp_long) {
strftime(timestamp, sizeof(timestamp), "%Y%m%d %H:%M:%S %Z", tm);
- printf(" %20s ", timestamp);
+ printf(" %22s ", timestamp);
} else {
strftime(timestamp, sizeof(timestamp), "%H:%M:%S", tm);
printf(" %8s ", timestamp);
@@ -286,6 +289,83 @@ inline void out_print_permissions(struct list_node *ptr) {
printf(" %4o ", mode);
}
+inline void out_print_format_string_header(const char *format) {
+ size_t i=0, format_len=0;
+ char header[4096] = "";
+ char *pos = header;
+
+ if (format == NULL) return;
+ DBGTRC("DEBUG: format string: \"%s\"\n", format);
+
+
+ format_len = strnlen(format, DM_OUT_FORMAT_MAX_LEN);
+ /* Prevent buffer overflow, with the header string 32 byte buffer */
+ for (i=0; (i < format_len) && (strlen(header) < 4064); i++) {
+ switch (format[i]) {
+ case 'n':
+ sprintf(pos, " FILE ");
+ break;
+ case 's':
+ sprintf(pos, " %11s ", "SIZE ");
+ break;
+ case 't':
+ if (option_timestamp_long) {
+ sprintf(pos, " %c%-21s ", toupper(option_time_field), "TIME");
+ } else {
+ sprintf(pos, " %c%-7s ", toupper(option_time_field), "TIME");
+ }
+ break;
+ case 'A':
+ if (option_timestamp_long) {
+ sprintf(pos, " %-22s ", "ACCESS TIME");
+ } else {
+ sprintf(pos, " %-8s ", "ATIME");
+ }
+ break;
+ case 'C':
+ if (option_timestamp_long) {
+ sprintf(pos, " %-22s ", "CREATION TIME");
+ } else {
+ sprintf(pos, " %-8s ", "CTIME");
+ }
+ break;
+ case 'M':
+ if (option_timestamp_long) {
+ sprintf(pos, " %-22s ", "MODIFICATION TIME");
+ } else {
+ sprintf(pos, " %-8s ", "MTIME");
+ }
+ break;
+ case 'T':
+ sprintf(pos, " %-12s ", "TYPE");
+ break;
+ case 'u':
+ sprintf(pos, " %-4s ", "UID");
+ break;
+ case 'g':
+ sprintf(pos, " %-4s ", "GID");
+ break;
+ case 'U':
+ sprintf(pos, " %-10s ", "USER");
+ break;
+ case 'G':
+ sprintf(pos, " %-10s ", "GROUP");
+ break;
+ case 'p':
+ sprintf(pos, " %-4s ", "PERM");
+ break;
+ case ' ':
+ break;
+ default:
+ LOGERR("WARNING: Invalid character 0x%02X ignoring it\n", format[i]);
+ break;
+ };
+ pos = &header[strlen(header)];
+ }
+ printf("%s\n", header);
+ fputc_width_x('-', strlen(header), stdout);
+ out_print_newline();
+}
/* === END OF FORMATTING FUNCTIONS === */
@@ -305,6 +385,10 @@ void print_list(struct list_head *list) {
}
}
+ if (option_print_header) {
+ out_print_format_string_header("stn");
+ }
+
ptr = lh->first;
while (ptr != NULL) {
out_print_size(ptr);
@@ -370,7 +454,12 @@ void print_list_formatted(const char *format, struct list_head *list) {
/* Note: the maximum length needs to be adjusted if the strings
* shall contain more complicated settings */
- format_len = strnlen(format, 80);
+ format_len = strnlen(format, DM_OUT_FORMAT_MAX_LEN);
+ DBGTRC("DEBUG: format_len = %lu\n", format_len);
+
+ if (option_print_header) {
+ out_print_format_string_header(format);
+ }
ptr = lh->first;
while (ptr != NULL) {