On 11/4/23 11:51, Oliver Webb via Toybox wrote: > Heya, I added a -L[ongest line] option to wc > > I thought that this option was considered and discarded since > it isn't that hard to implement and is a GNU extension. But grep-ing through > the list archives shows no mention of a -L option in relation to wc.
Because it's not in posix, not in the default output, and nobody ever asked for it. Did you spot it in use in the wild? > I added the -L option in the below patch, along with a couple of tests for it. > GNU wc -L doesn't count newlines, so it makes sense that toybox's one > shouldn't. > the "(signed)" cast is so the output is never "-1" > > Also, when I originally tried to implement this option, I appended it > to the end of the option string. Then -l started acting in the same way as -L. > Which made me take a look at generated/flags.h to check if options were being > parsed > case-sensitively. > > Then I realized that option strings are parsed into "FLAG_" macros backwards. > (End -> Start, First options get higher value flags) > Which from my searching isn't mentioned in lib/args.c, nor scripts/make.sh. Lines 20-22 of lib/args.c: * Each option in the get_opt string corresponds to a bit position in the * return value. The rightmost argument is (1<<0), the next to last is (1<<1) * and so on. If the option isn't seen in argv[], its bit remains 0. https://landley.net/toybox/code.html#lib_args has a more elaborate description. The bits are in the same order that binary digits go in. If option string abcd has bits 1010 (I.E. 0x0a) then -a and -c were set and -b and -d weren't. Rob _______________________________________________ Toybox mailing list Toybox@lists.landley.net http://lists.landley.net/listinfo.cgi/toybox-landley.net