changeset 30266:38ee67b5ec9f

input.cc: throw error if second argument does not equal 's' Same behavior with Matlab R2021a and is indeed confusing for users coming from the C-programming language. See for example Octave Discourse https://octave.discourse.group/t/calling-the-input-function-with-two-arguments/1749
author Kai T. Ohlhus <k.ohlhus@gmail.com>
date Mon, 01 Nov 2021 11:36:08 +0900
parents 3c60814448ea
children 535f97bb5f86
files libinterp/corefcn/input.cc
diffstat 1 files changed, 10 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/corefcn/input.cc	Sun Oct 31 18:25:33 2021 +0100
+++ b/libinterp/corefcn/input.cc	Mon Nov 01 11:36:08 2021 +0900
@@ -695,12 +695,18 @@
   {
     octave_value_list retval;
 
-    int read_as_string = 0;
+    std::string prompt = args(0).xstring_value ("input: unrecognized argument");
 
-    if (args.length () == 2)
-      read_as_string++;
+    bool read_as_string = false;
+    if (args.length () == 2)  // `input (..., "s")`?
+      {
+        std::string literal
+          = args(1).xstring_value ("input: second argument must be 's'.");
+        if (literal.length () != 1 || literal[0] != 's')
+          error ("input: second argument must be 's'.");
 
-    std::string prompt = args(0).xstring_value ("input: unrecognized argument");
+        read_as_string = true;
+      }
 
     output_system& output_sys = m_interpreter.get_output_system ();