<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Hi,</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
you are right.</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
PFA a patch for unit tests i added that can maybe go in when fold moves from pending??,</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
the main intention is to discuss what i was unable to communicate(limitation on my part), i added a comment too</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
so if anyone can cross check , that would be helpful<br>
</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
</div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font style="font-size:11pt" face="Calibri, sans-serif" color="#000000"><b>From:</b> Samuel Holland <samuel@sholland.org><br>
<b>Sent:</b> Monday, August 27, 2018 10:28 PM<br>
<b>To:</b> haroon maqsood; toybox@lists.landley.net<br>
<b>Subject:</b> Re: [Toybox] [PENDING] [fold.c] [Question]</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt;">
<div class="PlainText">Hi,<br>
<br>
On 08/27/18 03:09, haroon maqsood wrote:<br>
> Hi Rob,<br>
> I started working on fold.c cleanup,<br>
> going through the code, and testing it out, i have a couple of questions.<br>
> <br>
>  1. gnu fold engulfs \n unconditionally i.e if there is a \n after the fold has<br>
>     happened that redundant \n does not make it to the output , that kind of<br>
>     makes sense but the posix spec only mentions carriage returns and only if<br>
>     the -b option is not specified. (Note* That the current pending/fold outputs<br>
>     an extra new line.)<br>
<br>
If a line is exactly the length that a newline would need to go after the last<br>
character, no additional newline should be added. If there is, that's a bug. If<br>
you're referring to a different situation, please give an example.<br>
<br>
>  2. the current fold implementation has unfold capability , that i think should<br>
>     not be squeezed in fold (as of yet), my plan is to have unfold as a separate<br>
>     utility that uses infrastructure from fold if necessary, or at least make<br>
>     unfold as a config option, please share your thoughts on this.<br>
>  3. The tabstop thing is bit confusing for me, as the posix spec says "Tab stops<br>
>     shall be at each column position such that n modulo 8 equals 1." ( from<br>
>     this i understand that given the column the next column where the tab ends<br>
>     should be a column whose modulo 8 returns 1 , kind of this pseudo code ?<br>
>     where start is the current column. (am i understanding it right ?)<br>
> <br>
> int get_next_ts(int start)<br>
> {<br>
>      if (start <= 1)<br>
>           return 9;<br>
>     <br>
>      if ((start % 8) == 1)<br>
>           return start;<br>
>  <br>
>      return get_next_ts(++start);<br>
> }<br>
<br>
Yes, this is correct. A more idiomatic algorithm would be:<br>
<br>
int get_next_ts(int start)<br>
{<br>
        return ((start + 8) & -8) + 1;<br>
}<br>
<br>
> Haroon<br>
<br>
Samuel<br>
</div>
</span></font></div>
</body>
</html>