From owner-svn-src-user@freebsd.org Fri Dec 30 23:14:19 2016 Return-Path: Delivered-To: svn-src-user@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 9AB63C98A11 for ; Fri, 30 Dec 2016 23:14:19 +0000 (UTC) (envelope-from bapt@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 754F71DBA; Fri, 30 Dec 2016 23:14:19 +0000 (UTC) (envelope-from bapt@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id uBUNEI4Z051613; Fri, 30 Dec 2016 23:14:18 GMT (envelope-from bapt@FreeBSD.org) Received: (from bapt@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id uBUNEId6051609; Fri, 30 Dec 2016 23:14:18 GMT (envelope-from bapt@FreeBSD.org) Message-Id: <201612302314.uBUNEId6051609@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: bapt set sender to bapt@FreeBSD.org using -f From: Baptiste Daroussin Date: Fri, 30 Dec 2016 23:14:18 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r310871 - user/bapt/diff X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 30 Dec 2016 23:14:19 -0000 Author: bapt Date: Fri Dec 30 23:14:18 2016 New Revision: 310871 URL: https://svnweb.freebsd.org/changeset/base/310871 Log: Make diff -u header printing similar to GNU diff -u Obtained from: soc2012 Modified: user/bapt/diff/diff.c user/bapt/diff/diff.h user/bapt/diff/diffreg.c Modified: user/bapt/diff/diff.c ============================================================================== --- user/bapt/diff/diff.c Fri Dec 30 23:05:06 2016 (r310870) +++ user/bapt/diff/diff.c Fri Dec 30 23:14:18 2016 (r310871) @@ -39,7 +39,7 @@ __FBSDID("$FreeBSD$"); #include "diff.h" #include "xmalloc.h" -int lflag, Nflag, Pflag, rflag, sflag, Tflag; +int lflag, Nflag, Pflag, rflag, sflag, Tflag, cflag; int diff_format, diff_context, status; int tabsize = 8; char *start, *ifdefname, *diffargs, *label[2], *ignore_pats; @@ -124,6 +124,7 @@ main(int argc, char **argv) break; case 'C': case 'c': + cflag = 1; diff_format = D_CONTEXT; if (optarg != NULL) { l = strtol(optarg, &ep, 10); Modified: user/bapt/diff/diff.h ============================================================================== --- user/bapt/diff/diff.h Fri Dec 30 23:05:06 2016 (r310870) +++ user/bapt/diff/diff.h Fri Dec 30 23:14:18 2016 (r310871) @@ -82,7 +82,7 @@ struct excludes { struct excludes *next; }; -extern int lflag, Nflag, Pflag, rflag, sflag, Tflag; +extern int lflag, Nflag, Pflag, rflag, sflag, Tflag, cflag; extern int diff_format, diff_context, status; extern int tabsize; extern char *start, *ifdefname, *diffargs, *label[2], *ignore_pats; Modified: user/bapt/diff/diffreg.c ============================================================================== --- user/bapt/diff/diffreg.c Fri Dec 30 23:05:06 2016 (r310870) +++ user/bapt/diff/diffreg.c Fri Dec 30 23:14:18 2016 (r310871) @@ -89,6 +89,12 @@ __FBSDID("$FreeBSD$"); #define _PATH_PR "/usr/bin/pr" +#ifdef ST_MTIM_NSEC +# define TIMESPEC_NS(timespec) ((timespec).ST_MTIM_NSEC) +#else +# define TIMESPEC_NS(timespec) 0 +#endif + #define MINIMUM(a, b) (((a) < (b)) ? (a) : (b)) #define MAXIMUM(a, b) (((a) > (b)) ? (a) : (b)) @@ -1529,16 +1535,43 @@ dump_unified_vec(FILE *f1, FILE *f2, int static void print_header(const char *file1, const char *file2) { + const char *time_format; + char buf1[256]; + char buf2[256]; + char end1[10]; + char end2[10]; + struct tm *tm_ptr1, *tm_ptr2; + int nsec1 = TIMESPEC_NS (stb1.st_mtime); + int nsec2 = TIMESPEC_NS (stb2.st_mtime); + +#ifdef ST_MTIM_NSEC + time_format = "%Y-%m-%d %H:%M:%S.%N"; +#else + time_format = "%Y-%m-%d %H:%M:%S"; +#endif + + if (cflag) + time_format = "%c"; + tm_ptr1 = localtime(&stb1.st_mtime); + tm_ptr2 = localtime(&stb2.st_mtime); + strftime(buf1, 256, time_format, tm_ptr1); + strftime(buf2, 256, time_format, tm_ptr2); + if (!cflag) { + strftime(end1, 10, "%z", tm_ptr1); + strftime(end2, 10, "%z", tm_ptr2); + sprintf(buf1, "%s.%.9d %s", buf1, nsec1, end1); + sprintf(buf2, "%s.%.9d %s", buf2, nsec2, end2); + } if (label[0] != NULL) diff_output("%s %s\n", diff_format == D_CONTEXT ? "***" : "---", label[0]); else - diff_output("%s %s\t%s", diff_format == D_CONTEXT ? "***" : "---", - file1, ctime(&stb1.st_mtime)); + diff_output("%s %s\t%s\n", diff_format == D_CONTEXT ? "***" : "---", + file1, buf1); if (label[1] != NULL) diff_output("%s %s\n", diff_format == D_CONTEXT ? "---" : "+++", label[1]); else - diff_output("%s %s\t%s", diff_format == D_CONTEXT ? "---" : "+++", - file2, ctime(&stb2.st_mtime)); + diff_output("%s %s\t%s\n", diff_format == D_CONTEXT ? "---" : "+++", + file2, buf2); }