Commit Graph

1762 Commits

Author SHA1 Message Date
FRIGN
870a75076d Harden parseoffset() even more
1) Check for NULL.
2) Check for empty strings.
3) Clarify error-messages.
2015-09-30 19:44:10 +01:00
FRIGN
8163451249 Check parseoffset return value in od(1)
Yeah, kinda embarassing. Forgot about that.
2015-09-30 19:44:10 +01:00
FRIGN
fc886aa144 Implement od(1) v-flag
If this flag is not given, od(1) automatically replaces duplicate
adjacent lines with an '*' for each reoccurence.
If this flag is set, thus, no such filtering occurs.

In this case this would mean having to somehow keep the last printed
line in some backbuffer, building the next line and then doing the
necessary comparisons. This basically means that we duplicate the
functionality provided with uniq(1).

So instead of

$ od -t a > dump

you'd rather do

$ od -t a | uniq -f 1 -c > dump

Skipping the first field is necessary, as the addresses obviously differ.

Now, I was thinking hard why this flag even exists. If POSIX mandated
to add the address before the asterisk, so we know the offset of duplicate
occurrences, this would make sense. However, this is not the case.

Using uniq(1) also gives nicer output:
~ $ echo "111111111111111111111111111111111111111111111111" | od -t a -v | uniq -f 1 -c
      3 0000000   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1
      1 0000060  nl
      1 0000061

in comparison to

$ echo "111111111111111111111111111111111111111111111111" | od -t a
0000000   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1
*
0000060  nl
0000061

Before working on od(1), I didn't even know it would filter out
duplicate adjacent lines like that. This is also a matter of
predictability.

Concluding, the v-flag is implicitly set and users urged to just
use the existing tools provided by the system.
I don't think we would break scripts either. Firstly, it's rather
unlikely to have duplicate lines exactly matching the line-length of
od(1). Secondly, even if a script did that specifically, in the worst
case there would be a counting error or something.

Given od(1) is mostly used interactively, we can safely assume this
feature is for the benefit of the users.

Ditch this legacy POSIX crap!
 Please enter the commit message for your changes. Lines starting
2015-09-30 19:44:10 +01:00
FRIGN
f8f2a56852 Add -j and -N to od(1) and update README
With parseoffset(), it's rather trivial to implement POSIX' rather
obscure commandments.
The -j and -N-flags should be ready to go!
2015-09-30 19:44:10 +01:00
FRIGN
64929039e9 Don't forget to scale in parseoffset() 2015-09-30 19:44:10 +01:00
FRIGN
007df69fc5 Add parseoffset()
This is a utility function to allow easy parsing of file or other
offsets, automatically taking in regard suffixes, proper bases and
so on, for instance used in split(1) -b or od -j, -N(1).
Of course, POSIX is very arbitrary when it comes to defining the
parsing rules for different tools.
The main focus here lies on being as flexible and consistent as
possible. One central utility-function handling the parsing makes
this stuff a lot more trivial.
2015-09-30 19:44:10 +01:00
FRIGN
7132473947 Some small changes for od(1)
1) Move usage() down above main().
2) Consistently use printaddress() across the code.
3) Use off_t instead of size_t for file offsets.
2015-09-30 19:44:10 +01:00
FRIGN
365f392d3c Properly handle namedict in od(1)
I added the [127]-index but forgot that this increases the length,
breaking a later check.
2015-09-30 19:44:10 +01:00
FRIGN
0d6d1dc02f Check explicit length in od(1)
If you pass an empty string, the null-char will always match
with strchr()!
2015-09-30 19:44:10 +01:00
FRIGN
d49bce7fc8 Refactor parts of od(1)
It was possible to make some sections of the code shorter.
Also fix a bug where the last printed address was always in hex
rather than depending on the radix chosen.
2015-09-30 19:44:10 +01:00
Greg Reagle
fd0d1e4567 Created od, with improvements suggested by FRIGN 2015-09-30 19:44:10 +01:00
Hiltjo Posthuma
521c3734af ls: fix usage line, add f, n and p flag 2015-09-30 19:44:10 +01:00
Hiltjo Posthuma
aba450fd1a ls: printf("%s", s) -> fputs(s, stdout) 2015-09-30 19:44:10 +01:00
Hiltjo Posthuma
874d131728 ls: LEN(pw|grname) -> sizeof() 2015-09-30 19:44:10 +01:00
Hiltjo Posthuma
53be158979 code-style: whitespace fixes 2015-09-30 19:44:10 +01:00
Evan Gates
51009a9600 use CC for sbase-box, remove LD 2015-09-03 19:17:59 +01:00
FRIGN
93f1fc4614 Remove trailing whitespace inside of ls(1) 2015-08-31 18:10:25 +01:00
Quentin Rameau
365e1a324a ls: group sorting options
tflag and Sflag are now grouped under 'sort' var, as suggested by cls.
r-flag handling has been moved inside entcmp().
2015-08-31 18:10:25 +01:00
Quentin Rameau
f1bbe6529a ls: detect infinite loop with recursivity
populate an history of visited directories inodes and search it before
recursing
2015-08-31 18:10:25 +01:00
Quentin Rameau
74b5aa151c ls: correctly handle recursivity
the path is now carried through ls() and lsdir(), directory entries are
listed before recursing.
2015-08-31 18:10:25 +01:00
Quentin Rameau
1905b83cc9 ls: list operands in correct order
sort operands by name, list files first then directory entries
2015-08-31 18:10:25 +01:00
Quentin Rameau
b88ed2ab2d ls: fix -q
Move qflag handling to output() instead of modifying the actual entity
name which broke recursivity.
2015-08-31 18:10:25 +01:00
Wolfgang Corcoran-Mathe
438d2542e4 tail: Don't print garbage when input contains no newlines.
getline(3) expects newline-terminated input. While glibc's
implementation seems to catch unterminated input and zero the
buffer, other versions (notably musl's) do not.

This is a workaround. Garbage will still be read, but
not printed.
2015-08-30 18:36:19 +01:00
sin
1fa942a0ee Add TFTP client as specified by RFC 1350
This client does not support the netascii mode.  The default mode
is octet/binary and should be sufficient.

One thing left to do is to check the source port of the server
to make sure it doesn't change.  If it does, we should ignore the
packet and send an error back without disturbing an existing
transfer.
2015-08-14 13:11:16 +01:00
sin
d6d8c98345 Fix mandoc warnings for sed.1 and find.1 2015-08-14 13:11:16 +01:00
FRIGN
9d429de50d Mark manpages as done in the README for find(1) and sed(1) 2015-08-04 19:46:03 +01:00
Evan Gates
2c0828f3fb add preliminary find(1) manpage 2015-08-04 19:46:03 +01:00
Evan Gates
0bd0c246a5 add preliminary sed(1) manpage 2015-08-04 19:46:03 +01:00
Wolfgang Corcoran-Mathe
ac62259d24 comm: Print first trailing unpaired line in file 1
Previously, a line read from file 1 before a strcmp was
performed would be overwritten and lost. Something like
this:

    comm one_line_file empty_file

produced no output.

This patch is a bit inelegant, but quite simple.
2015-08-04 12:35:44 +01:00
FRIGN
5dc6f3c1e6 Note in the README that find(1) and sed(1) are lacking manpages 2015-08-04 12:08:13 +01:00
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