Commit Graph

1532 Commits

Author SHA1 Message Date
FRIGN
51390a3c51 Audit sort(1) and mark it as finished
1) Remove the function prototypes. No need for them, as the
   functions are ordered.
2) Add fieldseplen, so the length of the field-separator is not
   calculated nearly each time skipcolumn() is called.
3) rename next_col to skip_to_next_col so the purpose is clear,
   also reorder the conditional accordingly.
4) Put parentheses around certain ternary expressions.
5) BUGFIX: Don't just exit() in check(), but make it return something,
   so we can cleanly fshut() everything.
6) OFF-POSIX: Posix for no apparent reason does not allow more than
   one file when the -c or -C flags are given.
   This can be problematic when you want to check multiple files.
   With the change 5), rewriting check() to return a value, I went
   off-posix after discussing this with Dimitris to just allow
   arbitrary numbers of files. Obviously, this does not break scripts
   and is convenient for everybody who wants to quickly check a big
   amount of files.
   As soon as 1 file is "unsorted", the return value is 1, as expected.
   For convenience reasons, check()'s warning now includes the filename.
7) BUGFIX: Set ret to 2 instead of 1 when the fshut(fp, *argv) fails.
8) BUGFIX: Don't forget to fshut stderr at the end. This would improperly
   return 1 in the following case:
   $ sort -c unsorted_file 2> /dev/full
9) Other style changes, line length, empty line before return.
2015-08-04 12:08:13 +01:00
FRIGN
0a2562e994 Make fname static in cut() in cut(1) 2015-08-04 12:08:13 +01:00
FRIGN
e153447657 Make sort(1) utf-compliant and update README
Make it clear that <blank> characters just are spaces or tabs and
not a special group which needs special treatment for wide characters.

Also, and that was the only problem here, correctly calculate the
offset given by the key definitions for the start- and end-characters
using libutf-utility-functions.

Mark the progress in the README and put parentheses around the missing
flags which are insane to implement for no real gain.
2015-08-03 19:14:52 +01:00
FRIGN
1622089a21 Reorder functions in sort(1)
I kind of missed that the sorting was still not properly done.
parse_flags() and addkeydef() are independent of everything else,
so they can be put at the bottom.
Sorting the other functions reveals the true hierarchy much better.
2015-08-03 10:00:00 +01:00
FRIGN
61ee561728 Factor out parse_keydef() into addkeydef() and reorder functions
Add a small comment explaining the data-structure and sort the
functions according to usage, not alphabetically.
2015-08-03 10:00:00 +01:00
FRIGN
e00cdf226a Use queue.h-macros in sort(1)
This is much easier to read than having yet another handrolled
list implementation.
Tested and more or less clearly equivalent.

Now that I have uni-vac, I'll have enough time to refactor more.
2015-08-02 23:32:17 +01:00
Shiz
8d1ae98163 Call C compiler for linking
Using $(LD) directly for linking can cause issues with cross-compilers
and various other toolchains, as various libraries such as libc may not
be implicitly linked in, causing symbol resolution errors.
Linking through the C compiler frontend solves this issue.
2015-07-31 23:15:42 +01:00
Wolfgang Corcoran-Mathe
625f421f5a join: Use LIMIT macro 2015-07-23 11:51:05 +01:00
Wolfgang Corcoran-Mathe
5dab8bbfa9 find: NULL terminate braces array in exec primary 2015-07-23 11:51:05 +01:00
Christoph Lohmann
015fb69f01 Add LNGARG() to sbase. 2015-07-10 16:45:52 +02:00
Wolfgang Corcoran-Mathe
47c05f9ff4 join: Stricter parsing of -o list
This fixes naive parsing that would happily read a giant string
of numbers into fileno provided the first character was correct.
2015-06-25 12:11:23 +01:00
FRIGN
d0269af73e Remove debug-code in printf(1) 2015-06-22 20:03:55 +01:00
FRIGN
d848bcac4b Fix parameter-usage in printf(1)
1) Don't default to a space for numeric conversions. Instead,
   set flag to 0 and work with it on a case-basis.
   This fixes the wrong output of "printf %d 20" which had a
   space prepended to it (" 20").
2) Add precision for doiuxX, which is zero-padding.
   This fixes the wrong output of "printf %.5d 20" to properly
   print "00020".

Thanks to emg for reporting these!
2015-06-22 20:03:54 +01:00
Wolfgang Corcoran-Mathe
6e7cbdd918 find: Improve prompt spacing with -ok 2015-06-18 14:24:15 +01:00
Wolfgang Corcoran-Mathe
cf769f2d8d find: Fix flushing input buffer with -ok
The original flush-stdin loop (with fgets()) hung until the user
entered some extraneous characters for it to kill.

emg's FIXME about nulls still applies.
2015-06-18 14:24:15 +01:00
Evan Gates
1490b37bd2 NULL terminate braces array in get_ok_arg 2015-06-18 14:24:14 +01:00
Wolfgang Corcoran-Mathe
c5f8294f63 cksum: Skip files with read errors and continue
Previously, 'cksum *' exited early if * contained a directory or
other file causing an fread() error.

Exit status is set to indicate an error has occurred.
2015-06-13 10:39:54 +01:00
FRIGN
a6f8f66ac1 Fix typo in join(1)
This was causing some mysterious output bugs.
Thanks, Wolfgang Corcoran-Mathe!
2015-06-07 09:09:42 +01:00
Eivind Uggedal
9e04a4fcdc ln: allow dangling symlinks 2015-06-07 09:09:42 +01:00
FRIGN
d383612450 Add some info to config.mk
glibc breaks tools on 32bit systems due to a design flaw not allowing
64bit file offsets and only doing so with a cryptic flag.

Also, make sure to tell users about -lrt, which might be needed on
some systems.
2015-06-05 00:23:02 +01:00
FRIGN
198c45ee6d Remove col(1)
Where should I start? It's a rather irrelevant tool and broken as is.
We'll re-add it as soon as the code has been fixed by the original
author.
Until then, better keep it out or some kids get hurt.
2015-06-04 23:54:09 +01:00
Eivind Uggedal
93043beec9 readlink: simplify -f
Use output from realpath(3) directly. This makes usage
with . more consistent with other implementations.
2015-06-04 23:54:09 +01:00
sin
7e035a9a2e sed: Alias -r to -E for GNU compat 2015-06-03 18:51:24 +01:00
Eivind Uggedal
ced76f3b03 sed: support extended regular expressions (-E)
Not specified in POSIX.1-2008.
GNU sed uses -r, openbsd uses -E but aliases -r to -E for compat.
2015-06-03 18:51:24 +01:00
Evan Gates
844267bce4 delete pattern space before updating ranges on c,d,D 2015-06-03 15:37:51 +01:00
FRIGN
78b285deb6 Fix ln(1) symbolic link handling
This was broken in multiple ways. For instance, the overlay-
check of identical files (name and target) was omitted for
symbolic links for some reason.
While at it, I fixed the stat-handling, improved the error-
messages so the right paths were shown and removed the
illegimite bail-out when the target-fstatat failed (we want
only a warning here as well).
2015-05-29 12:08:37 +01:00
FRIGN
d23cc72490 Simplify return & fshut() logic
Get rid of the !!()-constructs and use ret where available (or introduce it).

In some cases, there would be an "abort" on the first fshut-error, but we want
to close all files and report all warnings and then quit, not just the warning
for the first file.
2015-05-26 16:41:43 +01:00
FRIGN
e8a4f37884 Fix tail(1) -n 0 handling and unglobalize some variables
Don't terminate too early. If the given file doesn't exist,
we need the error-message.

Additionally, some variables were globals for no good reason.
2015-05-21 15:43:38 +01:00
Hiltjo Posthuma
fbd128b564 fold: check -N form properly 2015-05-21 15:43:38 +01:00
Hiltjo Posthuma
bc9205cab5 fold: check form -n aswell, > 0 2015-05-21 15:43:38 +01:00
FRIGN
9304b84c92 Use a function pointer in uuencode(1)
This simplifies the code a lot.
2015-05-21 15:43:38 +01:00
FRIGN
9a074144c9 Remove handrolled strcmp()'s
Favor readability over bare-metal.
2015-05-21 15:43:38 +01:00
FRIGN
1797df01e7 Fix uniq(1)
The argument handling was quite garbled up. So I fixed it.
In the process, it drops a lot of locs.

Previously, it would lead to an off-by-one in an edge case, so
stop messing around with argv and use an idiomatic fp- and fname-
array.

Now this works fine and is much easier to read.

This is also the first step towards going back to strcmp() instead
of handrolling the "-"-checks.
2015-05-19 16:51:19 +01:00
Michael Forney
b4adb4bb87 touch: Use both atime and mtime of reference file 2015-05-16 13:34:00 +01:00
Michael Forney
4132561c17 touch: Handle nanosecond timestamps 2015-05-16 13:34:00 +01:00
Michael Forney
1d28fbd6cf mv, cp: Preserve nanosecond timestamps
Otherwise, we run into problems in a typical autoconf-based build
system:

  - config.status is created at some point between two seconds.
  - config.status is run, generating Makefile by first writing to a file
    in /tmp, and then mv-ing it to Makefile.
  - If this mv happens before the beginning of the next second, Makefile
    will be created with the same tv_sec as config.status, but with
    tv_nsec = 0.
  - When make runs, it sees that Makefile is older than config.status,
    and re-runs config.status to generate Makefile.
2015-05-16 13:34:00 +01:00
sin
0ba81a0f84 grep: Remove unused variable 2015-05-16 13:34:00 +01:00
FRIGN
0545d32ce9 Handle '-' consistently
In general, POSIX does not define /dev/std{in, out, err} because it
does not want to depend on the dev-filesystem.
For utilities, it thus introduced the '-'-keyword to denote standard
input (and output in some cases) and the programs have to deal with
it accordingly.

Sadly, the design of many tools doesn't allow strict shell-redirections
and many scripts don't even use this feature when possible.

Thus, we made the decision to implement it consistently across all
tools where it makes sense (namely those which read files).

Along the way, I spotted some behavioural bugs in libutil/crypt.c and
others where it was forgotten to fshut the files after use.
2015-05-16 13:34:00 +01:00
Alexandre Niveau
6be7eaff1b ls: fix option -S for it to work without -lnpFi 2015-05-15 12:07:43 +01:00
sin
f90354bfc9 find: Allow using multiple paths 2015-05-15 12:07:43 +01:00
Evan Gates
86f9ce55a8 need implicit -a between ) and ! 2015-05-13 23:43:33 +01:00
Hiltjo Posthuma
347f0828f3 mktemp improvements
- add -p dir, -t and -u.
- fix dirname(tmp) check (did not check null terminator).

the semantics of mktemp is now the same as OpenBSD mktemp.
2015-05-10 12:58:38 +01:00
Hiltjo Posthuma
590f34c4a9 tar: compatibility, treat reserved type as regular file
References:
- http://www.gnu.org/software/tar/manual/html_node/Standard.html
- http://pubs.opengroup.org/onlinepubs/009695399/basedefs/tar.h.html
2015-05-10 12:58:38 +01:00
Hiltjo Posthuma
9d95321f0b tar: compatibility, allow empty magic aswell 2015-05-10 12:58:38 +01:00
Wolfgang Corcoran-Mathe
00883efc16 join: fix typo 2015-05-09 20:29:52 +01:00
Hiltjo Posthuma
d41095299a tar: ignore more crazy GNU PAX header crap
don't fail, but maybe we should give a warning for this?
2015-05-08 21:36:40 +01:00
Hiltjo Posthuma
deb8a16527 tar: fix checksum calculation (signed/unsigned issue)
some archives gave the error: "malformed tar archive"

test file where this occurred:
   http://nl.alpinelinux.org/alpine/v3.1/main/x86_64/apk-tools-static-2.5.0_rc1-r0.apk
2015-05-08 21:36:40 +01:00
Hiltjo Posthuma
29649762b3 libutil/getlines: fix potential crash
linelen was uninitialized if for example:

$ > empty
$ sort ls.c empty
2015-05-08 16:38:06 +01:00
sin
e3cdcce2ec Clarify that compression is now supported in tar.1 2015-05-08 15:56:21 +01:00
sin
198238bd5d Bump date in tar.1 2015-05-08 15:56:21 +01:00