Commit Graph

25 Commits

Author SHA1 Message Date
FRIGN 695153ac18 Audit cmp(1)
1) Remove the return-value-enum, which is not necessary for a simple
   program like this.
2) Don't disallow both l and s to be specified. This is undefined
   behaviour defined by POSIX, so we don't start demanding things
   from the user.
3) Replace exit() with return (we are in main).
4) Refactor main loop to never return in the loop, but actually
   set the same-value and break, which increases readability.
5) Remove the final fclose()'s. The OS will take care of them, no
   need to become cleansy here.
6) Use idiomatic return-value using same. This concludes the
   increase of readability in the main-loop.
2015-03-11 11:16:40 +01:00
FRIGN 31572c8b0e Clean up #includes 2015-02-14 21:12:23 +01:00
FRIGN 352eedff58 No need to check for stdin on fclose()
as we are not trying to read from it afterwards.
2015-02-07 21:42:41 +01:00
FRIGN cb1b5d532b Handle stdin properly in cmp(1) and remove path comparison
Same paths are undefined behaviour, let's not endorse it.
2015-02-07 21:36:36 +01:00
FRIGN d756dca999 Reuse 'n' in cmp(1)
Factors out one more local variable.
2015-02-07 21:13:54 +01:00
FRIGN 79e45395e5 Refactor cmp(1) code and manpage
The algorithm had some areas which had potential for improvement.
This should make cmp(1) faster.
There have been changes to behaviour as well:

1) If argv[0] and argv[1] are the same, cmp(1) returns Same.
2) POSIX specifies the format of the difference-message to be:
      "%s %s differ: char %d, line %d\n", file1, file2,
      <byte number>, <line number>
   However, as cmp(1) operates on bytes, not characters, I changed
   it to
      "%s %s differ: byte %d, line %d\n", file1, file2,
      <byte number>, <line number>
   This is one example where the standard just keeps the old format
   for backwards-compatibility. As this is harmful, this change
   makes sense in the sense of consistentcy (and because we take
   the difference of char and byte very seriously in sbase, as
   opposed to GNU coreutils).

The manpage has been annotated, reflecting the second change, and
sections shortened where possible.
Thus I marked cmp(1) as finished in README.
2015-02-07 21:05:33 +01:00
sin 102f579d0f cmp(1) is POSIX compliant so mention it in the manpage
Update format specifiers for -l as specified by POSIX.
2014-11-21 12:32:07 +00:00
sin 2d685482af Update cmp(1) manpage to new style and do not allow both -l and -s to be set 2014-11-21 12:04:07 +00:00
sin 4399f35448 Fix two more instances where the check for "-" is insufficient 2014-11-18 21:58:50 +00:00
FRIGN ec8246bbc6 Un-boolify sbase
It actually makes the binaries smaller, the code easier to read
(gems like "val == true", "val == false" are gone) and actually
predictable in the sense of that we actually know what we're
working with (one bitwise operator was quite adventurous and
should now be fixed).

This is also more consistent with the other suckless projects
around which don't use boolean types.
2014-11-14 10:54:20 +00:00
FRIGN eee98ed3a4 Fix coding style
It was about damn time. Consistency is very important in such a
big codebase.
2014-11-13 18:08:43 +00:00
sin 6449db8691 Make both arguments to cmp(1) mandatory and handle "-" properly 2014-11-13 16:01:10 +00:00
Hiltjo Posthuma 6dd138613e cmp: suppress file open error with sflag
Signed-off-by: Hiltjo Posthuma <>
2014-04-09 15:40:44 +01:00
Hiltjo Posthuma eee182cdd7 cmp: fix missing braces
just a style fix, this doesn't change any behaviour since fp[1] is set to stdin above.

Signed-off-by: Hiltjo Posthuma <>
2014-04-01 16:21:06 +01:00
Hiltjo Posthuma 6b45824463 cmp: fix wrong rebase, missing line, sorry
Signed-off-by: Hiltjo Posthuma <>
2014-04-01 16:20:59 +01:00
Hiltjo Posthuma ce28f6ca90 cmp: dont output EOF difference is sflag is set
Signed-off-by: Hiltjo Posthuma <>
2014-04-01 16:20:36 +01:00
Hiltjo Posthuma a7954e8cab cmp: fix line numbers
test case:
	printf 'a\n\na' > t1
	printf 'a\na' > t2
	cmp t1 t2

Signed-off-by: Hiltjo Posthuma <>
2014-04-01 16:20:28 +01:00
Hiltjo Posthuma 1059cf5f17 cmp: make EOF check more clear
Signed-off-by: Hiltjo Posthuma <>
2014-04-01 16:20:21 +01:00
sin 760690c85e Make code a bit more clear 2014-03-04 10:43:51 +00:00
sin c28e2a39ec We should not require both files to be present for cmp(1)
If the second file is not present, read from standard input.
2014-03-04 10:36:54 +00:00
stateless 7216a53a7e Remove unnecessary exit(1) in usage()
Signed-off-by: Christoph Lohmann <>
2013-06-19 19:58:19 +02:00
Christoph Lohmann 4d38f60685 Eliminating the getopt disgrace. 2013-06-14 20:20:47 +02:00
Connor Lane Smith 8ec404cdec update cmp, grep 2011-06-18 06:42:24 +01:00
Connor Lane Smith 8d087ae4fb cmp: cleanup 2011-06-10 02:00:27 +01:00
Connor Lane Smith 188d8ff93a add cmp, thanks stateless 2011-06-10 01:55:12 +01:00