Chris's Wiki :: blog/unix/EdDesignedForCookedInput Commentshttps://utcc.utoronto.ca/~cks/space/blog/unix/EdDesignedForCookedInput?atomcommentsDWiki2019-04-19T05:45:57ZRecent comments in Chris's Wiki :: blog/unix/EdDesignedForCookedInput.By frankg on /blog/unix/EdDesignedForCookedInputtag:CSpace:blog/unix/EdDesignedForCookedInput:b310c13d37e18d5cf444ac8a4ce7c0a7c76dfc50frankg<div class="wikitext"><p>"where it reads whole lines"</p>
<p>I had to pull up my source because that did not sound like the way Ken writes code to me and it's not quite right. It's correct in no stty call is made to set raw mode but all terminal IO is done with unbuffered single char reads. This is from v6 but v7 is basically the same.</p>
<pre>
if (read(0, &lastc, 1) <= 0)
return(lastc = EOF);
</pre>
<p>Reading, writing files, and some other bits work with blocks in v6.</p>
<p>By v7 getline had been introduced for some operations. It was used for file I/O, joins, and moves. It's not the standard getline yet and ed has it's own buffering. Terminal I/O still used single char reads which adds characters to an array called linebuf. The block and single char I/O use the same linebuf so without following the code it can be difficult to determine how linebuf is being used.</p>
<p>I looked at the code because I was surprised it used cooked mode and indeed it does. It should have been obvious on old systems without a curses library properly handling backspace and erase would best be left up to the system. </p>
<p>For those interested in learning ed the book Ed Mastery by Michael Lucas is great. if you used ed on systems before vi existed you can stare with wonder at a book dedicated to ed like I did when I first saw it.</p>
</div>2019-04-19T05:45:57Z