aboutsummaryrefslogtreecommitdiff
path: root/usr.bin/diff/diff.c
Commit message (Collapse)AuthorAgeFilesLines
* diff: Fix usage message and documentation.Dag-Erling Smørgrav2024-08-011-1/+1
| | | | | | | | | | | | | The `--ignore-all-space` option was incorrectly documented as `--ignore-all-blanks` in some (but not all) places. MFC after: 3 days PR: 280434 Sponsored by: Klara, Inc. Reviewed by: 0mp, markj Differential Revision: https://reviews.freebsd.org/D46160 (cherry picked from commit ab830de9f58c1b257e42b4fbdd46b3ca6a837ee6)
* Remove $FreeBSD$: one-line .c patternWarner Losh2023-08-231-2/+0
| | | | | | | Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/ Similar commit in main: (cherry picked from commit 1d386b48a555)
* diff: fix incorrectly displaying files as duplicatesJamie Landeg-Jones2021-02-011-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When diff hits certain access errors, function diffreg() shows the error message, and then returns to the calling function, which calls print_status() with the return value. However, in these cases, the return value isn't changed from the initial default value of D_SAME. Normally, print_status() with a value of D_SAME does nothing, so this works out ok, however, if the "-s" flag is set, a message is displayed showing identicality: case D_SAME: if (sflag) printf("Files %s%s and %s%s are identical\n", path1, entry, path2, entry); break; This then produces such results as: % diff -s /COPYRIGHT /var/run/rpcbind.sock diff: /var/run/rpcbind.sock: Operation not supported Files /COPYRIGHT and /var/run/rpcbind.sock are identical % diff -s /COPYRIGHT /etc/master.passwd diff: /etc/master.passwd: Permission denied Files /COPYRIGHT and /etc/master.passwd are identical Create a D_ERROR status which is returned in such cases, and print_status() then deals with that status seperately from D_SAME PR: 252614 MFC after: 1 week (cherry picked from commit fefb3c46a80fdde6f307e73a2b5b5aed806df1ce)
* diff: don't force the format to 'context' with -p immediatelyKyle Evans2020-10-271-11/+2
| | | | | | | | | | | | | | | Instead, leave the fomat as unspecified (if it hasn't been) and use the -p flag as a hint to 'context' if no other formatting option is specified. This fixes `diff -purw`, used frequently by emaste, and matches the behavior of its GNU counterpart. PR: 250015 Reviewed by: emaste MFC after: 1 week Notes: svn path=/head/; revision=367076
* diff: restore compatibility with GNU diff regarding -N optionBaptiste Daroussin2020-06-011-4/+25
| | | | | | | | | | | | | When -N is used the missing files are treated as empty. PR: 233402 Submitted by: Fehmi Noyan Isi <fnoyanisi@yahoo.com> Reported by: Roman Neuhauser <roman@sigpipe.cz> MFC after: 3 days Differential Revision: D25081 Notes: svn path=/head/; revision=361689
* Restore compatibility with GNU diff regarding --labelBaptiste Daroussin2020-06-011-0/+3
| | | | | | | | | | | | | | | | Various options to "diff(1)" show filenames, and traditionally make use of the "--label" parameter, if set. Restore this behaviour in BSD diff. While here add a regression test PR: 244533 Submitted by: Jamie Landeg-Jones <jamie@catflap.org> MFC after: 3 days Notes: svn path=/head/; revision=361688
* diff(1): don't reject specifying the same format multiple timesKyle Evans2020-04-281-10/+21
| | | | | | | | | | | | | | | | | | | | | This may happen, for instance, if one happens to have an alias of diff to diff -up and attempts to specify the amount of context on top of that. Aliases like this may cause other problems, but if they're really not ever generating non-unified diffs then we should at least not break that use-case. In addition, we'll now pick up a format mismatch if -p is specified with !contextual && !unified && !unset. Fix up a small trailing whitespace nit in the tests while we're here, and add tests to make sure that we can double up all the formatting options. Reported by: jbeich MFC after: 3 days Notes: svn path=/head/; revision=360437
* diff(1): reject conflicting formatting optionsKyle Evans2020-04-201-2/+33
| | | | | | | | | | | | | | | | | | | This matches GNU diff(1) behavior and, more importantly, eliminates any source of confusion if multiple formatting options are specified. Note that the committed diff differs slightly from the submitted: I've modified it so that we initialize diff_format to something that isn't an accepted format option so that we can also reject --normal -c and -c --normal, which would've otherwise been accepted because the default was --normal. After option parsing we default it to D_NORMAL if it's still unset. PR: 243975 Submitted by: fehmi noyan isi MFC after: 1 week Notes: svn path=/head/; revision=360125
* diff: fix segfault with --tabsize and no/malformed argumentKyle Evans2020-02-131-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | --tabsize was previously listed as optional_argument, but didn't account for the optionality of it in the argument handling. This is irrelevant -- the manpage doesn't indicate that the argument is optional, and indeed there's no clear interpretation of omitting the argument because there's no other side effect of --tabsize. The "malformed" argument part of the header on this message is simply referring to usage like this: % diff --tabsize 4 A B With an optional_argument, the argument must be attached to the parameter directly (e.g. --tabsize=4), so the argument is effectively NULL with the above invocation as if no argument had been passed. PR: 243974 Submitted by: fehmi noyan isi <fnoyanisi yahoo com> (diff.c portion) MFC after: 3 days Notes: svn path=/head/; revision=357875
* diff: implement -y (--side-by-side) along with -W and --suppress-common-linesBaptiste Daroussin2020-02-071-5/+28
| | | | | | | | | PR: 219933 Submitted by: fehmi noyan isi <fnoyanisi@yahoo.com> MFC after: 3 weeks Notes: svn path=/head/; revision=357648
* When system calls indicate an error they return -1, not some arbitraryBaptiste Daroussin2020-01-141-3/+3
| | | | | | | | | | value < 0. errno is only updated in this case. Obtained from: OpenBSD MFC after: 3 days Notes: svn path=/head/; revision=356725
* diff(1): Implement -B/--ignore-blank-linesKyle Evans2018-08-191-5/+9
| | | | | | | | | | | | | | | | As noted by cem in r338035, coccinelle invokes diff(1) with the -B flag. This was not previously implemented here, so one was forced to create a link for GNU diff to /usr/local/bin/diff Implement the -B flag and add some primitive tests for it. It is implemented in the same fashion that -I is implemented; each chunk's lines are scanned, and if a non-blank line is encountered then the chunk will be output. Otherwise, it's skipped. MFC after: 2 weeks Notes: svn path=/head/; revision=338039
* Add -H as an alias for --speed-large-file to match GNU diff.John Baldwin2017-06-021-5/+5
| | | | | | | | | | | This is undocumented to match GNU diff where -H is also undocumented. Some existing software (such as kompare) uses this option by default. Reviewed by: emaste, rpokala Differential Revision: https://reviews.freebsd.org/D11022 Notes: svn path=/head/; revision=319489
* Implement a basic --changed-group-formatBaptiste Daroussin2017-04-201-0/+7
| | | | | | | | | | | | | etcupdate(8) requires that option, while GNU diff supports many more variation of that options, their behaviour beside the simple verion implemented here are quite inconsistent as such I do not plan to implement those. The only special keyword supported by this implementation are: %< and %> %= is not implemented as the documentation of GNU diff says: common lines, but it actually when tested print the changes from the first file Notes: svn path=/head/; revision=317194
* Clean up headers declarationBaptiste Daroussin2017-04-151-2/+0
| | | | Notes: svn path=/head/; revision=316959
* add a stub --speed-large-files for compatibility with GNU diffBaptiste Daroussin2017-04-081-0/+4
| | | | | | | | There is no intention to implement it, but lots of scripts/tools using diff(1) passes GNU diff option Notes: svn path=/head/; revision=316639
* Use strndup(3) instead of malloc + memcpyBaptiste Daroussin2017-03-221-3/+2
| | | | Notes: svn path=/head/; revision=315746
* Implement a stub --horizon-lines=NUM for compatibility with GNU diff3Baptiste Daroussin2017-03-121-0/+4
| | | | | | | | | | some options of GNU diff3 would call diff with --horizon-lines, rcs is depending on that. Reported by: antoine Notes: svn path=/head/; revision=315103
* Import diff from OpenBSD and remove GNU diffBaptiste Daroussin2017-03-111-0/+454
Some of the modifications from the previous summer of code has been integrated Modification for compatibility with GNU diff output has been added Main difference with OpenBSD: Implement multiple GNU diff options: * --ignore-file-name-case * --no-ignore-file-name-case * --normal * --tabsize * --strip-trailing-cr Make diff -p compatible with GNU diff Implement diff -l Make diff -r compatible with GNU diff Capsicumize diffing 2 regular files Add a simple test suite Approved by: AsiaBSDcon devsummit Obtained from: OpenBSD, GSoC Relnotes: yes Notes: svn path=/head/; revision=315051