Improved report format

This commit is contained in:
Thomas Schmitt 2008-02-19 18:41:12 +00:00
parent 4c961a6cd4
commit e0525b9d2e

View File

@ -22,6 +22,49 @@
#include <errno.h> #include <errno.h>
#include <fcntl.h> #include <fcntl.h>
#include <string.h> #include <string.h>
#include <time.h>
char *Ftypetxt(mode_t st_mode, int flag)
{
if(S_ISDIR(st_mode))
return("directory");
else if(S_ISREG(st_mode))
return("regular_file");
else if(S_ISLNK(st_mode))
return("symbolic_link");
else if(S_ISBLK(st_mode))
return("block_device");
else if(S_ISCHR(st_mode))
return("char_device");
else if(S_ISFIFO(st_mode))
return("name_pipe");
else if(S_ISSOCK(st_mode))
return("unix_socket");
return("unknown");
}
char *Ftimetxt(time_t t, char timetext[40], int flag)
{
char *rpt;
struct tm tms, *tmpt;
static char months[12][4]= { "Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
tmpt= localtime_r(&t, &tms);
rpt= timetext;
rpt[0]= 0;
if(tmpt==0)
sprintf(rpt+strlen(rpt), "%12.f", (double) t);
else if(time(NULL)-t < 180*86400 && time(NULL)-t >= 0)
sprintf(rpt+strlen(rpt), "%3s %2d %2.2d:%2.2d",
months[tms.tm_mon], tms.tm_mday, tms.tm_hour, tms.tm_min);
else
sprintf(rpt+strlen(rpt), "%3s %2d %4.4d",
months[tms.tm_mon], tms.tm_mday, 1900+tms.tm_year);
return(timetext);
}
/* @param flag bit0= compare atime /* @param flag bit0= compare atime
@ -31,7 +74,7 @@ int Compare_2_files(char *adr1, char *adr2, char *adrc, int flag)
{ {
struct stat s1, s2; struct stat s1, s2;
int ret, differs= 0, r1, r2, fd1= -1, fd2= -1, i, done; int ret, differs= 0, r1, r2, fd1= -1, fd2= -1, i, done;
char buf1[4096], buf2[4096], a[4096]; char buf1[4096], buf2[4096], a[4096], ttx1[40], ttx2[40];
off_t r1count= 0, r2count= 0, diffcount= 0, first_diff= -1; off_t r1count= 0, r2count= 0, diffcount= 0, first_diff= -1;
ret= lstat(adr1, &s1); ret= lstat(adr1, &s1);
@ -39,22 +82,7 @@ int Compare_2_files(char *adr1, char *adr2, char *adrc, int flag)
printf("? %s : cannot lstat() : %s\n", adr1, strerror(errno)); printf("? %s : cannot lstat() : %s\n", adr1, strerror(errno));
return(0); return(0);
} }
if(S_ISDIR(s1.st_mode)) strcpy(a, Ftypetxt(s1.st_mode, 0));
strcpy(a, "d");
else if(S_ISREG(s1.st_mode))
strcpy(a, "-");
else if(S_ISLNK(s1.st_mode))
strcpy(a, "l");
else if(S_ISBLK(s1.st_mode))
strcpy(a, "b");
else if(S_ISCHR(s1.st_mode))
strcpy(a, "c");
else if(S_ISFIFO(s1.st_mode))
strcpy(a, "p");
else if(S_ISSOCK(s1.st_mode))
strcpy(a, "s");
else
strcpy(a, "?");
strcat(a, " "); strcat(a, " ");
if(adrc[0]) if(adrc[0])
strcat(a, adrc); strcat(a, adrc);
@ -69,7 +97,11 @@ int Compare_2_files(char *adr1, char *adr2, char *adrc, int flag)
/* Attributes */ /* Attributes */
if(s1.st_mode != s2.st_mode) { if(s1.st_mode != s2.st_mode) {
if((s1.st_mode&~S_IFMT)!=(s2.st_mode&~S_IFMT))
printf("%s : st_mode : %7.7o <> %7.7o\n", a, s1.st_mode, s2.st_mode); printf("%s : st_mode : %7.7o <> %7.7o\n", a, s1.st_mode, s2.st_mode);
if((s1.st_mode&S_IFMT)!=(s2.st_mode&S_IFMT))
printf("%s : type : %s <> %s\n",
a, Ftypetxt(s1.st_mode, 0), Ftypetxt(s2.st_mode, 0));
differs= 1; differs= 1;
} }
if(s1.st_uid != s2.st_uid) { if(s1.st_uid != s2.st_uid) {
@ -90,26 +122,33 @@ int Compare_2_files(char *adr1, char *adr2, char *adrc, int flag)
} }
} }
if(S_ISREG(s2.st_mode) && s1.st_size != s2.st_size) { if(S_ISREG(s2.st_mode) && s1.st_size != s2.st_size) {
printf("%s : st_size : %.f <> %.f\n", printf("%s : st_size : %.f <> %.f diff= %.f\n",
a, (double) s1.st_size, (double) s2.st_size); a, (double) s1.st_size, (double) s2.st_size,
((double) s1.st_size) - (double) s2.st_size);
differs= 1; differs= 1;
} }
if(s1.st_mtime != s2.st_mtime) { if(s1.st_mtime != s2.st_mtime) {
printf("%s : st_mtime : %u <> %u\n", printf("%s : st_mtime : %s <> %s diff= %.f s\n",
a, (unsigned int) s1.st_mtime, (unsigned int) s2.st_mtime); a, Ftimetxt(s1.st_mtime, ttx1, 0),
Ftimetxt(s2.st_mtime, ttx2, 0),
((double) s1.st_mtime) - (double) s2.st_mtime);
differs= 1; differs= 1;
} }
if(flag&1) { if(flag&1) {
if(s1.st_atime != s2.st_atime) { if(s1.st_atime != s2.st_atime) {
printf("%s : st_atime : %u <> %u\n", printf("%s : st_atime : %s <> %s diff= %.f s\n",
a, (unsigned int) s1.st_atime, (unsigned int) s2.st_atime); a, Ftimetxt(s1.st_atime, ttx1, 0),
Ftimetxt(s2.st_atime, ttx2, 0),
((double) s1.st_atime) - (double) s2.st_atime);
differs= 1; differs= 1;
} }
} }
if(flag&2) { if(flag&2) {
if(s1.st_ctime != s2.st_ctime) { if(s1.st_ctime != s2.st_ctime) {
printf("%s : st_ctime : %u <> %u\n", printf("%s : st_ctime : %s <> %s diff= %.f s\n",
a, (unsigned int) s1.st_ctime, (unsigned int) s2.st_ctime); a, Ftimetxt(s1.st_ctime, ttx1, 0),
Ftimetxt(s2.st_ctime, ttx2, 0),
((double) s1.st_ctime) - (double) s2.st_ctime);
differs= 1; differs= 1;
} }
} }