~sircmpwn/ctools

daf56a7c653538f0b95cc0c9e15cc3d817d18547 — Drew DeVault 1 year, 2 months ago a05a24b
cmp: fix -s, add man page
4 files changed, 60 insertions(+), 5 deletions(-)

A doc/cmp.1.scd
M doc/meson.build
M src/cmp.c
M test/cmp
A doc/cmp.1.scd => doc/cmp.1.scd +53 -0
@@ 0,0 1,53 @@
cmp(1) "ctools"

# NAME

cmp - compare two files

# SYNOPSIS

*cmp* [-l|-s] _file1_ _file2_

# DESCRIPTION

*cmp* will compare two text files and find the location of the first character
which differs between them. If a difference is found, it will print the
character index and line number at which the difference was found.

# OPTIONS

*-l*
	When a difference is found, instead of printing a human-friendly
	message, print the index (in decimal) and the offending characters
	found there (in octal), separated with spaces.

*-s*
	Do not output anything if the files differ, instead the exit status
	must be consulted to determine the result.

The *-l* and *-s* options are mutually exclusive.

# EXIT STATUS

|] 0
:[ The files are identical
|  1
:  The files are different
|  >1
:  An error occured

# UNSPECIFIED BEHAVIOR

The POSIX standard does not unambiguously specify the behavior of this command
under certain conditions. Under such conditions, the ctools implementation of
*cmp* behaves as follows:

- If an error occurs and *-s* was specified, *cmp* may randomly choose not to
  print the appropriate diagnostic messages to stderr.

# DISCLAIMER

This command is part of ctools and is compatible with POSIX-1.2017, and may
optionally support XSI extensions. This man page is not intended to be a
complete reference, and where it disagrees with the specification, the
specification takes precedence.

M doc/meson.build => doc/meson.build +4 -2
@@ 9,6 9,7 @@ man_files = [
	'chown.1',
	'chmod.1',
	'cksum.1',
	'cmp.1',
	'false.1',
	'true.1',
]


@@ 24,8 25,9 @@ foreach page : man_files
		input: filename,
		output: output,
		command: [
			sh, '-c', '@0@ < @INPUT@ > @OUTPUT@'.format(
				scdoc_prog.path())
			sh, '-c', '@0@ < @INPUT@ > @1@'.format(
				scdoc_prog.path(),
				join_paths(meson.current_build_dir(), output))
		],
		install: true,
		install_dir: '@0@/man@1@'.format(mandir, section)

M src/cmp.c => src/cmp.c +2 -2
@@ 120,10 120,10 @@ main(int argc, char *argv[])
				++lineno;
			}
		} else {
			if (mode != LOUD) {
			if (mode == DEFAULT) {
				printf("%s %s differ: char %zu, line %zu\n",
				       file1, file2, len + 1, lineno + 1);
			} else {
			} else if (mode == LOUD) {
				printf("%zu %o %o\n", len + 1, a, b);
			}
			ret = 1;

M test/cmp => test/cmp +1 -1
@@ 24,7 24,7 @@ should_handle_lflag() (
)

should_handle_sflag() (
	[ "$(echo test | cmp -s "$HARNESS" $HARNESS)" = "" ]
	[ "$(echo test | cmp -s "$HARNESS" -)" = "" ]
)

should_handle_exitcode() (