Sorry My mistake (again), this is the complete file. ________________________________ From: haroon maqsood <[email protected]> Sent: Wednesday, August 29, 2018 10:24 PM To: Samuel Holland; [email protected] Subject: Re: [Toybox] [PENDING] [fold.c] [Question]
Hi, you are right. PFA a patch for unit tests i added that can maybe go in when fold moves from pending??, the main intention is to discuss what i was unable to communicate(limitation on my part), i added a comment too so if anyone can cross check , that would be helpful ________________________________ From: Samuel Holland <[email protected]> Sent: Monday, August 27, 2018 10:28 PM To: haroon maqsood; [email protected] Subject: Re: [Toybox] [PENDING] [fold.c] [Question] Hi, On 08/27/18 03:09, haroon maqsood wrote: > Hi Rob, > I started working on fold.c cleanup, > going through the code, and testing it out, i have a couple of questions. > > 1. gnu fold engulfs \n unconditionally i.e if there is a \n after the fold > has > happened that redundant \n does not make it to the output , that kind of > makes sense but the posix spec only mentions carriage returns and only if > the -b option is not specified. (Note* That the current pending/fold > outputs > an extra new line.) If a line is exactly the length that a newline would need to go after the last character, no additional newline should be added. If there is, that's a bug. If you're referring to a different situation, please give an example. > 2. the current fold implementation has unfold capability , that i think > should > not be squeezed in fold (as of yet), my plan is to have unfold as a > separate > utility that uses infrastructure from fold if necessary, or at least make > unfold as a config option, please share your thoughts on this. > 3. The tabstop thing is bit confusing for me, as the posix spec says "Tab > stops > shall be at each column position such that n modulo 8 equals 1." ( from > this i understand that given the column the next column where the tab ends > should be a column whose modulo 8 returns 1 , kind of this pseudo code ? > where start is the current column. (am i understanding it right ?) > > int get_next_ts(int start) > { > if (start <= 1) > return 9; > > if ((start % 8) == 1) > return start; > > return get_next_ts(++start); > } Yes, this is correct. A more idiomatic algorithm would be: int get_next_ts(int start) { return ((start + 8) & -8) + 1; } > Haroon Samuel
From d7fb7ada99a8cbf512905b85d2fd42e7d59b1769 Mon Sep 17 00:00:00 2001 From: "[email protected]" <[email protected]> Date: Wed, 29 Aug 2018 23:27:17 +0100 Subject: [PATCH] added fold test for discussion --- tests/fold.test | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100755 tests/fold.test diff --git a/tests/fold.test b/tests/fold.test new file mode 100755 index 0000000..ab3353d --- /dev/null +++ b/tests/fold.test @@ -0,0 +1,15 @@ +#!/bin/bash + +[ -f testing.sh ] && . testing.sh + +#testing "name" "command" "result" "infile" "stdin" + +#copied from gnu, but according to what i understand the output should be. + +testing "fold_test_1" "fold -w2 -s" "a\t\n" "" "a\t" +testing "fold_test_2" "fold -w4 -s" "abcd\nef \nd\n" "" "abcdef d\n" +testing "fold_test_3" "fold -w4 -s" "a \ncd \nfgh\n" "" "a cd fgh\n" +testing "fold_test_4" "fold -w4 -s" "abc \nef\n" "" "abc ef\n" + +#the question i posted +testing "fold_test_5" "fold -w1" "a\nb\nc\nd\n" "" "abcd" -- 2.17.1
_______________________________________________ Toybox mailing list [email protected] http://lists.landley.net/listinfo.cgi/toybox-landley.net
