Hi Peter,

almost correct. The first comment should be "// may point to an optional string typically containing 6 spaces". prompt can be 0 and then no prompt is printed. Otherwise the function pushes the prompt (backwards) back into stdin. Whether that works is a matter of the underlying operating system. The man page of ungetc() says that only 1 ungetc() char is guaranteed but we push 6. Another question is whether
an ungetc() into stdin will occur on C++ cin?

The main use case for this were scripts where it does not matter too much if a prompt is printed or not. Note also that pushing chars back into stdin has a different effect than just printing the prompt
- there are  cases where the prompt should be editable (⍞ I believe).

/// Jürgen


On 06/01/2014 04:22 AM, Peter Teeson wrote:
Hi Jürgen:
Well please help me properly understand the no_readline function in Input.cc. Because it's called instead of the readline library because of the --rawCIN.
I've made comments of my interpretation of the code but am probably wrong.
So I'd appreciate any contribution to my very rusty C++.

no_readline(const UCS_string * prompt)
{
if (prompt)// points at 6 spaces x'20'
    {
      CIN << '\r' << *prompt << flush;// CIN is an ostream see Output.cc
      UTF8_string prompt_utf(*prompt);
      loop(p, prompt_utf.size())// ungets those spaces from stdin
        {
const int cc = prompt_utf[prompt_utf.size() - p - 1];
          ungetc(cc & 0xFF, stdin);
        }
    }
etc

Much appreciated and

respect…

Peter

On 2014-05-31, at 11:13 AM, Juergen Sauermann <juergen.sauerm...@t-online.de <mailto:juergen.sauerm...@t-online.de>> wrote:
Hi Peter,

looks OK to me. (Note: as of recently *apl -s* does the same as your command line options).

--rawCIN reads directly from the file (stdin in this case) without outputting any prompts. The line numbers in the ∇-editor count as prompts and are therefore suppressed as well.

However when you display the function with [⎕] then the line numbers are not prompts
but output of the editor.

/// Jürgen


Reply via email to