View Full Version : Bug in diff?
Wassercrats
02-25-2006, 01:09 AM
I posted this to a low volume newsgroup and I figured I should post it here also to get an opinion before I report it as a bug.
Look at the two files being diffed in the following command, and then
look at the diff output. It's wrong, isn't it? Both files contain the
text "test1test2" with a carriage return between "test1" and "test2".
The diff command below (when I used it locally with just the file
names) omits the "test1" in Putty.diff -y -W 80 http://www.polisource.com/DIFF_CR_TEST.txt
http://www.polisource.com/DIFF_CR_TEST_2.txtIn a similar test on longer files, the diff output included tabs where
there were none, between the carriage return and the text after it, for
a line in the second file.
Terra
02-25-2006, 03:54 AM
It is not wrong, it is merely an illusion...
To unmask the illusion, we pipe the diff output through 'od -c' :QTwand:
0000000 t e s t 1 \r t e s t 2 \t \t \t \t \t
0000020 t e s t 1 \r \t \t \t \t \t t e s t 2
0000040 \n
0000041
When the display sees a '\r', it does just that, it returns the carriage back to the beginning of the line... 'test1' is indeed written, however when '\r' is displayed, carriage goes back and 'test1' is overwritten by 'test2'... I use '\r' quite a bit when creating display counters, so that the verbose numerical counting remains on the same line for display...
printf("\rCount: %d", i++);
You just need to remember that in Unix:
CR == Carriage Return (return carriage to beginning of current line)
and
LF == (implied) Carriage Return + Line Feed (drop down by one line)
The tabs exist because you have requested 'side-by-side' output, and it is using tabs to create the columnar report...
--
Terra
sysAdmin
FutureQuest
Wassercrats
02-25-2006, 04:14 AM
The tabs exist because you have requested 'side-by-side' outputI know that tabs get added in the gutter and sometimes even after the right side, but should they be added right in the middle of the line on the right side, after the '\r'? That's a bug, right?I use '\r' quite a bit when creating display counters, so that the verbose numerical counting remains on the same line for display...That's one of the few benefits to the command prompt over CGI. I created a progress bar for my cgi diff application, and it outputs:
<div style = "width: 100px; height: 12px; border-style: solid; border-width: 1px; margin: 0px; padding: 1px; text-align: left; margin-left: auto; margin-right: auto; background-color: white;}">
<img class = "bar" style = "width: 1px;" alt = "1%" src = "../images/Pixel_Grey150.gif"></img><img class = "bar" style = "width: 1px;" alt = "2%" src = "../images/Pixel_Grey150.gif"></img><img class = "bar" style = "width: 1px;" alt = "3%" src = "../images/Pixel_Grey150.gif"></img><img class = "bar" style = "width: 1px;" alt = "4%" src = "../images/Pixel_Grey150.gif"></img><img class = "bar" style = "width: 1px;" alt = "5%" src = "../images/Pixel_Grey150.gif"></img><img class = "bar" style = "width: 1px;" alt = "6%" src = "../images/Pixel_Grey150.gif"></img><img class = "bar" style = "width: 1px;" alt = "7%" src = "../images/Pixel_Grey150.gif"></img><img class = "bar" style = "width: 1px;" alt = "8%" src = "../images/Pixel_Grey150.gif"></img><img class = "bar" style = "width: 1px;" alt = "9%" src = "../images/Pixel_Grey150.gif"></img><img class = "bar" style = "width: 1px;" alt = "10%" src = "../images/Pixel_Grey150.gif"></img><img class = "bar" style = "width: 1px;" alt = "11%" src = "../images/Pixel_Grey150.gif"></img><img class = "bar" style = "width: 1px;" alt = "12%" src = "../images/Pixel_Grey150.gif"></img><img class = "bar" style = "width: 1px;" alt = "13%" src = "../images/Pixel_Grey150.gif"></img><img class = "bar" style = "width: 1px;" alt = "14%" src = "../images/Pixel_Grey150.gif"></img><img class = "bar" style = "width: 1px;" alt = "15%" src = "../images/Pixel_Grey150.gif"></img><img class = "bar" style = "width: 1px;" alt = "16%" src = "../images/Pixel_Grey150.gif"></img><img class = "bar" style = "width: 1px;" alt = "17%" src = "../images/Pixel_Grey150.gif"></img><img class = "bar" style = "width: 1px;" alt = "18%" src = "../images/Pixel_Grey150.gif"></img><img class = "bar" style = "width: 1px;" alt = "19%" src = "../images/Pixel_Grey150.gif"></img><img class = "bar" style = "width: 1px;" alt = "20%" src = "../images/Pixel_Grey150.gif"></img><img class = "bar" style = "width: 1px;" alt = "21%" src = "../images/Pixel_Grey150.gif"></img><img class = "bar" style = "width: 1px;" alt = "22%" src = "../images/Pixel_Grey150.gif"></img><img class = "bar" style = "width: 1px;" alt = "23%" src = "../images/Pixel_Grey150.gif"></img><img class = "bar" style = "width: 1px;" alt = "24%" src = "../images/Pixel_Grey150.gif"></img><img class = "bar" style = "width: 1px;" alt = "25%" src = "../images/Pixel_Grey150.gif"></img><img class = "bar" style = "width: 1px;" alt = "26%" src = "../images/Pixel_Grey150.gif"></img><img class = "bar" style = "width: 1px;" alt = "27%" src = "../images/Pixel_Grey150.gif"></img><img class = "bar" style = "width: 1px;" alt = "28%" src = "../images/Pixel_Grey150.gif"></img><img class = "bar" style = "width: 1px;" alt = "29%" src = "../images/Pixel_Grey150.gif"></img><img class = "bar" style = "width: 1px;" alt = "30%" src = "../images/Pixel_Grey150.gif"></img><img class = "bar" style = "width: 1px;" alt = "31%" src = "../images/Pixel_Grey150.gif"></img><img class = "bar" style = "width: 1px;" alt = "32%" src = "../images/Pixel_Grey150.gif"></img><img class = "bar" style = "width: 1px;" alt = "33%" src = "../images/Pixel_Grey150.gif"></img><img class = "bar" style = "width: 1px;" alt = "34%" src = "../images/Pixel_Grey150.gif"></img><img class = "bar" style = "width: 1px;" alt = "35%" src = "../images/Pixel_Grey150.gif"></img><img class = "bar" style = "width: 1px;" alt = "36%" src = "../images/Pixel_Grey150.gif"></img><img class = "bar" style = "width: 1px;" alt = "37%" src = "../images/Pixel_Grey150.gif"></img><img class = "bar" style = "width: 1px;" alt = "38%" src = "../images/Pixel_Grey150.gif"></img><img class = "bar" style = "width: 1px;" alt = "39%" src = "../images/Pixel_Grey150.gif"></img><img class = "bar" style = "width: 1px;" alt = "40%" src = "../images/Pixel_Grey150.gif"></img><img class = "bar" style = "width: 1px;" alt = "41%" src = "../images/Pixel_Grey150.gif"></img><img class = "bar" style = "width: 1px;" alt = "42%" src = "../images/Pixel_Grey150.gif"></img><img class = "bar" style = "width: 1px;" alt = "43%" src = "../images/Pixel_Grey150.gif"></img><img class = "bar" style = "width: 1px;" alt = "44%" src = "../images/Pixel_Grey150.gif"></img><img class = "bar" style = "width: 1px;" alt = "45%" src = "../images/Pixel_Grey150.gif"></img><img class = "bar" style = "width: 1px;" alt = "46%" src = "../images/Pixel_Grey150.gif"></img><img class = "bar" style = "width: 1px;" alt = "47%" src = "../images/Pixel_Grey150.gif"></img><img class = "bar" style = "width: 1px;" alt = "48%" src = "../images/Pixel_Grey150.gif"></img><img class = "bar" style = "width: 1px;" alt = "49%" src = "../images/Pixel_Grey150.gif"></img><img class = "bar" style = "width: 1px;" alt = "50%" src = "../images/Pixel_Grey150.gif"></img><img class = "bar" style = "width: 1px;" alt = "51%" src = "../images/Pixel_Grey150.gif"></img><img class = "bar" style = "width: 1px;" alt = "52%" src = "../images/Pixel_Grey150.gif"></img><img class = "bar" style = "width: 1px;" alt = "53%" src = "../images/Pixel_Grey150.gif"></img><img class = "bar" style = "width: 1px;" alt = "54%" src = "../images/Pixel_Grey150.gif"></img><img class = "bar" style = "width: 1px;" alt = "55%" src = "../images/Pixel_Grey150.gif"></img><img class = "bar" style = "width: 1px;" alt = "56%" src = "../images/Pixel_Grey150.gif"></img><img class = "bar" style = "width: 1px;" alt = "57%" src = "../images/Pixel_Grey150.gif"></img><img class = "bar" style = "width: 1px;" alt = "58%" src = "../images/Pixel_Grey150.gif"></img><img class = "bar" style = "width: 1px;" alt = "59%" src = "../images/Pixel_Grey150.gif"></img><img class = "bar" style = "width: 1px;" alt = "60%" src = "../images/Pixel_Grey150.gif"></img><img class = "bar" style = "width: 1px;" alt = "61%" src = "../images/Pixel_Grey150.gif"></img><img class = "bar" style = "width: 1px;" alt = "62%" src = "../images/Pixel_Grey150.gif"></img><img class = "bar" style = "width: 1px;" alt = "63%" src = "../images/Pixel_Grey150.gif"></img><img class = "bar" style = "width: 1px;" alt = "64%" src = "../images/Pixel_Grey150.gif"></img><img class = "bar" style = "width: 1px;" alt = "65%" src = "../images/Pixel_Grey150.gif"></img><img class = "bar" style = "width: 1px;" alt = "66%" src = "../images/Pixel_Grey150.gif"></img><img class = "bar" style = "width: 1px;" alt = "67%" src = "../images/Pixel_Grey150.gif"></img><img class = "bar" style = "width: 1px;" alt = "68%" src = "../images/Pixel_Grey150.gif"></img><img class = "bar" style = "width: 1px;" alt = "69%" src = "../images/Pixel_Grey150.gif"></img><img class = "bar" style = "width: 1px;" alt = "70%" src = "../images/Pixel_Grey150.gif"></img><img class = "bar" style = "width: 1px;" alt = "71%" src = "../images/Pixel_Grey150.gif"></img><img class = "bar" style = "width: 1px;" alt = "72%" src = "../images/Pixel_Grey150.gif"></img><img class = "bar" style = "width: 1px;" alt = "73%" src = "../images/Pixel_Grey150.gif"></img><img class = "bar" style = "width: 1px;" alt = "74%" src = "../images/Pixel_Grey150.gif"></img><img class = "bar" style = "width: 1px;" alt = "75%" src = "../images/Pixel_Grey150.gif"></img><img class = "bar" style = "width: 1px;" alt = "76%" src = "../images/Pixel_Grey150.gif"></img><img class = "bar" style = "width: 1px;" alt = "77%" src = "../images/Pixel_Grey150.gif"></img><img class = "bar" style = "width: 1px;" alt = "78%" src = "../images/Pixel_Grey150.gif"></img><img class = "bar" style = "width: 1px;" alt = "79%" src = "../images/Pixel_Grey150.gif"></img><img class = "bar" style = "width: 1px;" alt = "80%" src = "../images/Pixel_Grey150.gif"></img><img class = "bar" style = "width: 1px;" alt = "81%" src = "../images/Pixel_Grey150.gif"></img><img class = "bar" style = "width: 1px;" alt = "82%" src = "../images/Pixel_Grey150.gif"></img><img class = "bar" style = "width: 1px;" alt = "83%" src = "../images/Pixel_Grey150.gif"></img><img class = "bar" style = "width: 1px;" alt = "84%" src = "../images/Pixel_Grey150.gif"></img><img class = "bar" style = "width: 1px;" alt = "85%" src = "../images/Pixel_Grey150.gif"></img><img class = "bar" style = "width: 1px;" alt = "86%" src = "../images/Pixel_Grey150.gif"></img><img class = "bar" style = "width: 1px;" alt = "87%" src = "../images/Pixel_Grey150.gif"></img><img class = "bar" style = "width: 1px;" alt = "88%" src = "../images/Pixel_Grey150.gif"></img><img class = "bar" style = "width: 1px;" alt = "89%" src = "../images/Pixel_Grey150.gif"></img><img class = "bar" style = "width: 1px;" alt = "90%" src = "../images/Pixel_Grey150.gif"></img><img class = "bar" style = "width: 1px;" alt = "91%" src = "../images/Pixel_Grey150.gif"></img><img class = "bar" style = "width: 1px;" alt = "92%" src = "../images/Pixel_Grey150.gif"></img><img class = "bar" style = "width: 1px;" alt = "93%" src = "../images/Pixel_Grey150.gif"></img><img class = "bar" style = "width: 1px;" alt = "94%" src = "../images/Pixel_Grey150.gif"></img><img class = "bar" style = "width: 1px;" alt = "95%" src = "../images/Pixel_Grey150.gif"></img><img class = "bar" style = "width: 1px;" alt = "96%" src = "../images/Pixel_Grey150.gif"></img><img class = "bar" style = "width: 1px;" alt = "97%" src = "../images/Pixel_Grey150.gif"></img><img class = "bar" style = "width: 1px;" alt = "98%" src = "../images/Pixel_Grey150.gif"></img><img class = "bar" style = "width: 1px;" alt = "99%" src = "../images/Pixel_Grey150.gif"></img><img class = "bar" style = "width: 1px;" alt = "100%" src = "../images/Pixel_Grey150.gif"></img></div>At least the progress bar stays on one line, but I wish the HTML in the source code wrote over itself too.
Terra
02-25-2006, 06:09 AM
That's a bug, right?
Most likely not, it appears it is trying to compensate for the '\r', by ensuring that 'test2' is displayed in the proper location... If it didn't, 'test2' would have been written at the very beginning of the line overwriting the existing first 'test2'...
--
Terra
sysAdmin
FutureQuest
Wassercrats
02-25-2006, 12:33 PM
Oh, so the '\r' brings the cursor only back to the last tab. Otherwise the 'test2' from the left side would have been overwritten...no that's not right...whatever...I think chose the wrong diff for parsing, but I'm already done so it's too late. I found a fix to my script without really knowing what exactly diff is doing.
vBulletin® v3.6.8, Copyright ©2000-2009, Jelsoft Enterprises Ltd.