From 0c4bc5a362ea4ba9d5e43e5a5a0d921de8f5f084 Mon Sep 17 00:00:00 2001 From: Laurent MONIN Date: Sun, 29 Jan 2006 17:53:26 +0100 Subject: [PATCH] FSP: reduce code redundancy, introducing display_entry(). --- src/protocol/fsp/fsp.c | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/src/protocol/fsp/fsp.c b/src/protocol/fsp/fsp.c index d18f33b9f..b887ebbf7 100644 --- a/src/protocol/fsp/fsp.c +++ b/src/protocol/fsp/fsp.c @@ -81,6 +81,18 @@ compare(FSP_RDENTRY *a, FSP_RDENTRY *b) return strcmp(a->name, b->name); } +static void +display_entry(FSP_RDENTRY *fentry, unsigned char dircolor[]) +{ + printf("%10d\t", fentry->size, + fentry->name, fentry->type == FSP_RDTYPE_DIR ? "/" : ""); + if (fentry->type == FSP_RDTYPE_DIR && *dircolor) + printf("", dircolor); + printf("%s", fentry->name); + if (fentry->type == FSP_RDTYPE_DIR && *dircolor) + printf(""); + puts(""); +} static void sort_and_display_entries(FSP_DIR *dir, unsigned char dircolor[]) @@ -106,14 +118,7 @@ sort_and_display_entries(FSP_DIR *dir, unsigned char dircolor[]) (int (*)(const void *, const void *)) compare); for (i = 0; i < size; i++) { - printf("%10d\t", table[i].size, table[i].name, - table[i].type == FSP_RDTYPE_DIR ? "/" : ""); - if (table[i].type == FSP_RDTYPE_DIR && *dircolor) - printf("", dircolor); - printf("%s", table[i].name); - if (table[i].type == FSP_RDTYPE_DIR && *dircolor) - printf(""); - puts(""); + display_entry(&table[i], dircolor); } } @@ -153,14 +158,7 @@ fsp_directory(FSP_SESSION *ses, struct uri *uri) while (!fsp_readdir_native(dir, &fentry, &fresult)) { if (!fresult) break; - printf("%10d\t", fentry.size, - fentry.name, fentry.type == FSP_RDTYPE_DIR ? "/" : ""); - if (fentry.type == FSP_RDTYPE_DIR && *dircolor) - printf("", dircolor); - printf("%s", fentry.name); - if (fentry.type == FSP_RDTYPE_DIR && *dircolor) - printf(""); - puts(""); + display_entry(&fentry, dircolor); } fsp_closedir(dir); }