GNU Octave  4.4.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
utils.cc
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 1993-2018 John W. Eaton
4 Copyright (C) 2010 VZLU Prague
5 
6 This file is part of Octave.
7 
8 Octave is free software: you can redistribute it and/or modify it
9 under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
12 
13 Octave is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17 
18 You should have received a copy of the GNU General Public License
19 along with Octave; see the file COPYING. If not, see
20 <https://www.gnu.org/licenses/>.
21 
22 */
23 
24 #if defined (HAVE_CONFIG_H)
25 # include "config.h"
26 #endif
27 
28 #include <cerrno>
29 #include <cstring>
30 
31 #include <fstream>
32 #include <iostream>
33 #include <limits>
34 #include <string>
35 
36 #include "dir-ops.h"
37 #include "file-ops.h"
38 #include "file-stat.h"
39 #include "lo-mappers.h"
40 #include "lo-utils.h"
41 #include "nanosleep-wrapper.h"
42 #include "oct-cmplx.h"
43 #include "oct-env.h"
44 #include "oct-locbuf.h"
45 #include "pathsearch.h"
46 #include "quit.h"
47 #include "str-vec.h"
48 #include "vasprintf-wrapper.h"
49 
50 #include "Cell.h"
51 #include "defaults.h"
52 #include "defun.h"
53 #include "dirfns.h"
54 #include "error.h"
55 #include "errwarn.h"
56 #include "interpreter-private.h"
57 #include "interpreter.h"
58 #include "lex.h"
59 #include "load-path.h"
60 #include "oct-errno.h"
61 #include "oct-hist.h"
62 #include "ovl.h"
63 #include "ov-range.h"
64 #include "pager.h"
65 #include "parse.h"
66 #include "sysdep.h"
67 #include "unwind-prot.h"
68 #include "utils.h"
69 #include "variables.h"
70 
71 // Return TRUE if S is a valid identifier.
72 
73 bool
74 valid_identifier (const char *s)
75 {
76  if (! s || ! (isalpha (*s) || *s == '_' || *s == '$'))
77  return false;
78 
79  while (*++s != '\0')
80  if (! (isalnum (*s) || *s == '_' || *s == '$'))
81  return false;
82 
83  return true;
84 }
85 
86 bool
88 {
89  return valid_identifier (s.c_str ());
90 }
91 
92 DEFUN (isvarname, args, ,
93  doc: /* -*- texinfo -*-
94 @deftypefn {} {} isvarname (@var{name})
95 Return true if @var{name} is a valid variable name.
96 @seealso{iskeyword, exist, who}
97 @end deftypefn */)
98 {
99  if (args.length () != 1)
100  print_usage ();
101 
103 
104  if (args(0).is_string ())
105  {
106  std::string varname = args(0).string_value ();
107 
108  retval = valid_identifier (varname) && ! octave::is_keyword (varname);
109  }
110 
111  return retval;
112 }
113 
114 /*
115 %!assert (isvarname ("foo"), true)
116 %!assert (isvarname ("_foo"), true)
117 %!assert (isvarname ("_1"), true)
118 %!assert (isvarname ("1foo"), false)
119 %!assert (isvarname (""), false)
120 %!assert (isvarname (12), false)
121 %!assert (isvarname ("foo+bar"), false)
122 
123 %!error isvarname ()
124 %!error isvarname ("foo", "bar")
125 */
126 
127 // Return TRUE if F and G are both names for the same file.
128 
129 bool
130 same_file (const std::string& f, const std::string& g)
131 {
132  return same_file_internal (f, g);
133 }
134 
135 int
136 almost_match (const std::string& std, const std::string& s, int min_match_len,
137  int case_sens)
138 {
139  int stdlen = std.length ();
140  int slen = s.length ();
141 
142  return (slen <= stdlen
143  && slen >= min_match_len
144  && (case_sens
145  ? (strncmp (std.c_str (), s.c_str (), slen) == 0)
146  : (octave_strncasecmp (std.c_str (), s.c_str (), slen) == 0)));
147 }
148 
149 // Ugh.
150 
151 int
152 keyword_almost_match (const char * const *std, int *min_len,
153  const std::string& s,
154  int min_toks_to_match, int max_toks)
155 {
156  int status = 0;
157  int tok_count = 0;
158  int toks_matched = 0;
159 
160  if (s.empty () || max_toks < 1)
161  return status;
162 
163  char *kw = strsave (s.c_str ());
164 
165  char *t = kw;
166  while (*t != '\0')
167  {
168  if (*t == '\t')
169  *t = ' ';
170  t++;
171  }
172 
173  char *beg = kw;
174  while (*beg == ' ')
175  beg++;
176 
177  if (*beg == '\0')
178  return status;
179 
180  const char **to_match = new const char * [max_toks + 1];
181  const char * const *s1 = std;
182  const char **s2 = to_match;
183 
184  if (! s1 || ! s2)
185  goto done;
186 
187  s2[tok_count] = beg;
188  char *end;
189  while ((end = strchr (beg, ' ')) != nullptr)
190  {
191  *end = '\0';
192  beg = end + 1;
193 
194  while (*beg == ' ')
195  beg++;
196 
197  if (*beg == '\0')
198  break;
199 
200  tok_count++;
201  if (tok_count >= max_toks)
202  goto done;
203 
204  s2[tok_count] = beg;
205  }
206  s2[tok_count+1] = nullptr;
207 
208  s2 = to_match;
209 
210  for (;;)
211  {
212  if (! almost_match (*s1, *s2, min_len[toks_matched], 0))
213  goto done;
214 
215  toks_matched++;
216 
217  s1++;
218  s2++;
219 
220  if (! *s2)
221  {
222  status = (toks_matched >= min_toks_to_match);
223  goto done;
224  }
225 
226  if (! *s1)
227  goto done;
228  }
229 
230 done:
231 
232  delete [] kw;
233  delete [] to_match;
234 
235  return status;
236 }
237 
238 int
239 empty_arg (const char * /* name */, octave_idx_type nr, octave_idx_type nc)
240 {
241  return (nr == 0 || nc == 0);
242 }
243 
244 // See if the given file is in the path.
245 
247 search_path_for_file (const std::string& path, const string_vector& names)
248 {
249  octave::directory_path p (path);
250 
251  return octave::sys::env::make_absolute (p.find_first_of (names.std_list ()));
252 }
253 
254 // Find all locations of the given file in the path.
255 
258 {
259  octave::directory_path p (path);
260 
261  string_vector sv = p.find_all_first_of (names.std_list ());
262 
263  octave_idx_type len = sv.numel ();
264 
265  for (octave_idx_type i = 0; i < len; i++)
266  sv[i] = octave::sys::env::make_absolute (sv[i]);
267 
268  return sv;
269 }
270 
271 static string_vector
273 {
274  octave_idx_type len = sv.numel ();
275 
276  string_vector retval (len);
277 
278  for (octave_idx_type i = 0; i < len; i++)
280 
281  return retval;
282 }
283 
284 DEFMETHOD (file_in_loadpath, interp, args, ,
285  doc: /* -*- texinfo -*-
286 @deftypefn {} {@var{fname} =} file_in_loadpath (@var{file})
287 @deftypefnx {} {@var{fname} =} file_in_loadpath (@var{file}, "all")
288 Return the absolute name of @var{file} if it can be found in the list of
289 directories specified by @code{path}.
290 
291 If no file is found, return an empty character string.
292 
293 When @var{file} is already an absolute name, the name is checked against the
294 file system instead of Octave's loadpath. In this case, if @var{file} exists
295 it will be returned in @var{fname}, otherwise an empty string is returned.
296 
297 If the first argument is a cell array of strings, search each directory of
298 the loadpath for element of the cell array and return the first that
299 matches.
300 
301 If the second optional argument @qcode{"all"} is supplied, return a cell
302 array containing the list of all files that have the same name in the path.
303 If no files are found, return an empty cell array.
304 @seealso{file_in_path, dir_in_loadpath, path}
305 @end deftypefn */)
306 {
307  int nargin = args.length ();
308 
310  print_usage ();
311 
312  string_vector names = args(0).xstring_vector_value ("file_in_loadpath: FILE argument must be a string");
313 
314  if (names.empty ())
315  error ("file_in_loadpath: FILE argument must not be empty");
316 
317  octave::load_path& lp = interp.get_load_path ();
318 
319  if (nargin == 1)
320  return ovl (octave::sys::env::make_absolute (lp.find_first_of (names)));
321  else
322  {
323  std::string opt = args(1).xstring_value ("file_in_loadpath: optional second argument must be a string");
324 
325  if (opt != "all")
326  error (R"(file_in_loadpath: "all" is only valid second argument)");
327 
328  return ovl (Cell (make_absolute (lp.find_all_first_of (names))));
329  }
330 }
331 
332 /*
333 %!test
334 %! f = file_in_loadpath ("plot.m");
335 %! assert (ischar (f));
336 %! assert (! isempty (f));
337 
338 %!test
339 %! f = file_in_loadpath ("$$probably_!! _not_&&_a_!! _file$$");
340 %! assert (f, "");
341 
342 %!test
343 %! lst = file_in_loadpath ("$$probably_!! _not_&&_a_!! _file$$", "all");
344 %! assert (lst, {});
345 
346 %!error file_in_loadpath ()
347 %!error file_in_loadpath ("foo", "bar", 1)
348 %!error file_in_loadpath ([])
349 %!error file_in_loadpath ("plot.m", "bar")
350 */
351 
352 DEFUN (file_in_path, args, ,
353  doc: /* -*- texinfo -*-
354 @deftypefn {} {} file_in_path (@var{path}, @var{file})
355 @deftypefnx {} {} file_in_path (@var{path}, @var{file}, "all")
356 Return the absolute name of @var{file} if it can be found in @var{path}.
357 
358 The value of @var{path} should be a colon-separated list of directories in
359 the format described for @code{path}. If no file is found, return an empty
360 character string. For example:
361 
362 @example
363 @group
364 file_in_path (EXEC_PATH, "sh")
365  @result{} "/bin/sh"
366 @end group
367 @end example
368 
369 If the second argument is a cell array of strings, search each directory of
370 the path for element of the cell array and return the first that matches.
371 
372 If the third optional argument @qcode{"all"} is supplied, return a cell
373 array containing the list of all files that have the same name in the path.
374 If no files are found, return an empty cell array.
375 @seealso{file_in_loadpath, dir_in_loadpath, path}
376 @end deftypefn */)
377 {
378  int nargin = args.length ();
379 
381  print_usage ();
382 
383  std::string path = args(0).xstring_value ("file_in_path: PATH must be a string");
384 
385  string_vector names = args(1).xstring_vector_value ("file_in_path: FILE argument must be a string");
386 
387  if (names.empty ())
388  error ("file_in_path: FILE argument must not be empty");
389 
390  if (nargin == 2)
391  return ovl (search_path_for_file (path, names));
392  else
393  {
394  std::string opt = args(2).xstring_value ("file_in_path: optional third argument must be a string");
395 
396  if (opt != "all")
397  error (R"(file_in_path: "all" is only valid third argument)");
398 
399  return ovl (Cell (make_absolute (search_path_for_all_files (path, names))));
400  }
401 }
402 
403 /*
404 %!test
405 %! f = file_in_path (path (), "plot.m");
406 %! assert (ischar (f));
407 %! assert (! isempty (f));
408 
409 %!test
410 %! f = file_in_path (path (), "$$probably_!! _not_&&_a_!! _file$$");
411 %! assert (f, "");
412 
413 %!test
414 %! lst = file_in_path (path (), "$$probably_!! _not_&&_a_!! _file$$", "all");
415 %! assert (lst, {});
416 
417 %!error file_in_path ()
418 %!error file_in_path ("foo")
419 %!error file_in_path ("foo", "bar", "baz", 1)
420 %!error file_in_path ([])
421 %!error file_in_path (path (), [])
422 %!error file_in_path (path (), "plot.m", "bar")
423 */
424 
426 file_in_path (const std::string& name, const std::string& suffix)
427 {
428  std::string nm = name;
429 
430  if (! suffix.empty ())
431  nm.append (suffix);
432 
433  octave::load_path& lp = octave::__get_load_path__ ("file_in_path");
434 
436 }
437 
440  const std::string& file,
441  bool require_regular_file)
442 {
444 
447  {
448  // Load path will also search "." first, but we don't want to
449  // issue a warning if the file is found in the current directory,
450  // so do an explicit check for that.
452 
453  bool local_file_ok
454  = fs.exists () && (fs.is_reg () || ! require_regular_file);
455 
456  if (! local_file_ok)
457  {
458  octave::load_path& lp =
459  octave::__get_load_path__ ("find_data_file_in_load_path");
460 
461  // Not directly found; search load path.
464 
465  if (! tmp.empty ())
466  {
468 
469  fname = tmp;
470  }
471  }
472  }
473 
474  return fname;
475 }
476 
477 // See if there is an function file in the path.
478 // If so, return the full path to the file.
479 
482 {
484 
485  int len = name.length ();
486 
487  if (len > 0)
488  {
490  {
492 
493  if (fs.exists () && ! fs.is_dir ())
494  retval = name;
495  }
496  else if (len > 2 && name[len - 2] == '.' && name[len - 1] == 'm')
497  {
498  octave::load_path& lp = octave::__get_load_path__ ("fcn_file_in_path");
499 
500  retval = lp.find_fcn_file (name.substr (0, len-2));
501  }
502  else
503  {
505  size_t pos = name.find_first_of ('>');
506  if (pos != std::string::npos)
507  fname = name.substr (0, pos);
508 
509  octave::load_path& lp = octave::__get_load_path__ ("fcn_file_in_path");
510 
511  retval = lp.find_fcn_file (fname);
512  }
513  }
514 
515  return retval;
516 }
517 
518 // See if there is a directory called "name" in the path and if it
519 // contains a Contents.m file. If so, return the full path to this file.
520 
523 {
525 
526  if (! dir.empty ())
527  {
528  octave::load_path& lp = octave::__get_load_path__ ("contents_in_file_path");
529 
530  std::string tcontents
531  = octave::sys::file_ops::concat (lp.find_dir (dir), "Contents.m");
532 
533  octave::sys::file_stat fs (tcontents);
534 
535  if (fs.exists ())
537  }
538 
539  return retval;
540 }
541 
542 // Deprecated in 4.2, remove in version 5.
543 // See if there is a .oct file in the path.
544 // If so, return the full path to the file.
545 
548 {
550 
551  int len = name.length ();
552 
553  if (len > 0)
554  {
556  {
558 
559  if (fs.exists ())
560  retval = name;
561  }
562  else if (len > 4 && name.find (".oct", len-5))
563  {
564  octave::load_path& lp = octave::__get_load_path__ ("oct_file_in_path");
565 
566  retval = lp.find_oct_file (name.substr (0, len-4));
567  }
568  else
569  {
570  octave::load_path& lp = octave::__get_load_path__ ("oct_file_in_path");
571 
572  retval = lp.find_oct_file (name);
573  }
574  }
575 
576  return retval;
577 }
578 
579 // Deprecated in 4.2, remove in version 5.
580 // See if there is a .mex file in the path.
581 // If so, return the full path to the file.
582 
585 {
587 
588  int len = name.length ();
589 
590  if (len > 0)
591  {
593  {
595 
596  if (fs.exists ())
597  retval = name;
598  }
599  else if (len > 4 && name.find (".mex", len-5))
600  {
601  octave::load_path& lp = octave::__get_load_path__ ("mex_file_in_path");
602 
603  retval = lp.find_mex_file (name.substr (0, len-4));
604  }
605  else
606  {
607  octave::load_path& lp = octave::__get_load_path__ ("mex_file_in_path");
608 
609  retval = lp.find_mex_file (name);
610  }
611  }
612 
613  return retval;
614 }
615 
616 // Replace backslash escapes in a string with the real values.
617 
620 {
622 
623  size_t i = 0;
624  size_t j = 0;
625  size_t len = s.length ();
626 
627  retval.resize (len);
628 
629  while (j < len)
630  {
631  if (s[j] == '\\' && j+1 < len)
632  {
633  switch (s[++j])
634  {
635  case 'a': // alarm
636  retval[i] = '\a';
637  break;
638 
639  case 'b': // backspace
640  retval[i] = '\b';
641  break;
642 
643  case 'f': // formfeed
644  retval[i] = '\f';
645  break;
646 
647  case 'n': // newline
648  retval[i] = '\n';
649  break;
650 
651  case 'r': // carriage return
652  retval[i] = '\r';
653  break;
654 
655  case 't': // horizontal tab
656  retval[i] = '\t';
657  break;
658 
659  case 'v': // vertical tab
660  retval[i] = '\v';
661  break;
662 
663  case '\\': // backslash
664  retval[i] = '\\';
665  break;
666 
667  case '\'': // quote
668  retval[i] = '\'';
669  break;
670 
671  case '"': // double quote
672  retval[i] = '"';
673  break;
674 
675  case '0':
676  case '1':
677  case '2':
678  case '3':
679  case '4':
680  case '5':
681  case '6':
682  case '7': // octal input
683  {
684  size_t k;
685  int tmpi = s[j] - '0';
686  for (k = j+1; k < std::min (j+3, len); k++)
687  {
688  int digit = s[k] - '0';
689  if (digit < 0 || digit > 7)
690  break;
691  tmpi <<= 3;
692  tmpi += digit;
693  }
694  retval[i] = tmpi;
695  j = k - 1;
696  break;
697  }
698 
699  case 'x': // hex input
700  {
701  size_t k;
702  int tmpi = 0;
703  for (k = j+1; k < std::min (j+3, len); k++)
704  {
705  if (! isxdigit (s[k]))
706  break;
707 
708  tmpi <<= 4;
709  int digit = s[k];
710  if (digit >= 'a')
711  tmpi += digit - 'a' + 10;
712  else if (digit >= 'A')
713  tmpi += digit - 'A' + 10;
714  else
715  tmpi += digit - '0';
716  }
717 
718  if (k == j+1)
719  warning (R"(malformed hex escape sequence '\x' -- converting to '\0')");
720 
721  retval[i] = tmpi;
722  j = k - 1;
723  break;
724  }
725 
726  default:
727  warning (R"(unrecognized escape sequence '\%c' -- converting to '%c')", s[j], s[j]);
728  retval[i] = s[j];
729  break;
730  }
731  }
732  else
733  retval[i] = s[j];
734 
735  i++;
736  j++;
737  }
738 
739  retval.resize (i);
740 
741  return retval;
742 }
743 
744 DEFUN (do_string_escapes, args, ,
745  doc: /* -*- texinfo -*-
746 @deftypefn {} {} do_string_escapes (@var{string})
747 Convert escape sequences in @var{string} to the characters they represent.
748 
749 Escape sequences begin with a leading backslash
750 (@qcode{'@xbackslashchar{}'}) followed by 1--3 characters
751 (.e.g., @qcode{"@xbackslashchar{}n"} => newline).
752 @seealso{undo_string_escapes}
753 @end deftypefn */)
754 {
755  if (args.length () != 1)
756  print_usage ();
757 
758  std::string str = args(0).xstring_value ("do_string_escapes: STRING argument must be of type string");
759 
760  return ovl (do_string_escapes (str));
761 }
762 
763 /*
764 %!assert (do_string_escapes ('foo\nbar'), "foo\nbar")
765 %!assert (do_string_escapes ("foo\\nbar"), "foo\nbar")
766 %!assert (do_string_escapes ("foo\\nbar"), ["foo", char(10), "bar"])
767 %!assert ("foo\nbar", ["foo", char(10), "bar"])
768 
769 %!assert (do_string_escapes ('\0\a\b\f\n\r\t\v'), "\0\a\b\f\n\r\t\v")
770 %!assert (do_string_escapes ("\\0\\a\\b\\f\\n\\r\\t\\v"), "\0\a\b\f\n\r\t\v")
771 %!assert (do_string_escapes ("\\0\\a\\b\\f\\n\\r\\t\\v"),
772 %! char ([0, 7, 8, 12, 10, 13, 9, 11]))
773 %!assert ("\0\a\b\f\n\r\t\v", char ([0, 7, 8, 12, 10, 13, 9, 11]))
774 
775 %!assert (do_string_escapes ('\\'), "\\")
776 %!assert (do_string_escapes ("\\\\"), "\\")
777 %!assert (do_string_escapes ("\\\\"), char (92))
778 
779 %!assert (do_string_escapes ('\''single-quoted\'''), "'single-quoted'")
780 %!assert (do_string_escapes ("\\'single-quoted\\'"), "'single-quoted'")
781 %!assert (do_string_escapes ('\"double-quoted\"'), "\"double-quoted\"")
782 %!assert (do_string_escapes ("\\\"double-quoted\\\""), "\"double-quoted\"")
783 
784 %!assert (do_string_escapes ('A\4B'), ["A" char(4) "B"])
785 %!assert (do_string_escapes ('A\45B'), ["A" char(37) "B"])
786 %!assert (do_string_escapes ('A\123B'), ["A" char(83) "B"])
787 %!assert (sprintf ('\117\143\164\141\166\145'), "Octave")
788 
789 %!assert (do_string_escapes ('A\x4G'), ["A" char(4) "G"])
790 %!assert (do_string_escapes ('A\x4AG'), ["A" char(74) "G"])
791 %!assert (sprintf ('\x4f\x63\x74\x61\x76\x65'), "Octave")
792 
793 %!error do_string_escapes ()
794 %!error do_string_escapes ("foo", "bar")
795 %!error <STRING argument> do_string_escapes (3)
796 %!warning <malformed hex escape sequence> do_string_escapes ('\xG');
797 %!warning <unrecognized escape sequence> do_string_escapes ('\G');
798 */
799 
800 const char *
801 undo_string_escape (char c)
802 {
803  if (! c)
804  return "";
805 
806  switch (c)
807  {
808  case '\0':
809  return R"(\0)";
810 
811  case '\a':
812  return R"(\a)";
813 
814  case '\b': // backspace
815  return R"(\b)";
816 
817  case '\f': // formfeed
818  return R"(\f)";
819 
820  case '\n': // newline
821  return R"(\n)";
822 
823  case '\r': // carriage return
824  return R"(\r)";
825 
826  case '\t': // horizontal tab
827  return R"(\t)";
828 
829  case '\v': // vertical tab
830  return R"(\v)";
831 
832  case '\\': // backslash
833  return R"(\\)";
834 
835  case '"': // double quote
836  return R"(\")";
837 
838  default:
839  {
840  static char retval[2] {'\0', '\0'};
841 
842  retval[0] = c;
843  return retval;
844  }
845  }
846 }
847 
850 {
852 
853  for (size_t i = 0; i < s.length (); i++)
855 
856  return retval;
857 }
858 
859 DEFUN (undo_string_escapes, args, ,
860  doc: /* -*- texinfo -*-
861 @deftypefn {} {} undo_string_escapes (@var{s})
862 Convert special characters in strings back to their escaped forms.
863 
864 For example, the expression
865 
866 @example
867 bell = "\a";
868 @end example
869 
870 @noindent
871 assigns the value of the alert character (control-g, ASCII code 7) to the
872 string variable @code{bell}. If this string is printed, the system will
873 ring the terminal bell (if it is possible). This is normally the desired
874 outcome. However, sometimes it is useful to be able to print the original
875 representation of the string, with the special characters replaced by their
876 escape sequences. For example,
877 
878 @example
879 @group
880 octave:13> undo_string_escapes (bell)
881 ans = \a
882 @end group
883 @end example
884 
885 @noindent
886 replaces the unprintable alert character with its printable representation.
887 @seealso{do_string_escapes}
888 @end deftypefn */)
889 {
890  if (args.length () != 1)
891  print_usage ();
892 
893  std::string str = args(0).xstring_value ("undo_string_escapes: S argument must be a string");
894 
895  return ovl (undo_string_escapes (str));
896 }
897 
898 /*
899 %!assert (undo_string_escapes ("foo\nbar"), 'foo\nbar')
900 %!assert (undo_string_escapes ("foo\nbar"), "foo\\nbar")
901 %!assert (undo_string_escapes (["foo", char(10), "bar"]), "foo\\nbar")
902 
903 %!assert (undo_string_escapes ("\a\b\f\n\r\t\v"), '\a\b\f\n\r\t\v')
904 %!assert (undo_string_escapes ("\a\b\f\n\r\t\v"), "\\a\\b\\f\\n\\r\\t\\v")
905 %!assert (undo_string_escapes (char ([7, 8, 12, 10, 13, 9, 11])),
906 %! "\\a\\b\\f\\n\\r\\t\\v")
907 
908 %!assert (undo_string_escapes ("\\"), '\\')
909 %!assert (undo_string_escapes ("\\"), "\\\\")
910 %!assert (undo_string_escapes (char (92)), "\\\\")
911 
912 %!assert (undo_string_escapes ("\"double-quoted\""), '\"double-quoted\"')
913 %!assert (undo_string_escapes ("\"double-quoted\""), "\\\"double-quoted\\\"")
914 
915 %!error undo_string_escapes ()
916 %!error undo_string_escapes ("foo", "bar")
917 %!error undo_string_escapes (3)
918 */
919 
920 DEFUN (is_absolute_filename, args, ,
921  doc: /* -*- texinfo -*-
922 @deftypefn {} {} is_absolute_filename (@var{file})
923 Return true if @var{file} is an absolute filename.
924 @seealso{is_rooted_relative_filename, make_absolute_filename, isdir}
925 @end deftypefn */)
926 {
927  if (args.length () != 1)
928  print_usage ();
929 
930  return ovl (args(0).is_string ()
931  && octave::sys::env::absolute_pathname (args(0).string_value ()));
932 }
933 
934 /*
935 ## FIXME: We need system-dependent tests here.
936 
937 %!error is_absolute_filename ()
938 %!error is_absolute_filename ("foo", "bar")
939 */
940 
942  doc: /* -*- texinfo -*-
943 @deftypefn {} {} is_rooted_relative_filename (@var{file})
944 Return true if @var{file} is a rooted-relative filename.
945 @seealso{is_absolute_filename, make_absolute_filename, isdir}
946 @end deftypefn */)
947 {
948  if (args.length () != 1)
949  print_usage ();
950 
951  return ovl (args(0).is_string ()
952  && octave::sys::env::rooted_relative_pathname (args(0).string_value ()));
953 }
954 
955 /*
956 ## FIXME: We need system-dependent tests here.
957 
958 %!error is_rooted_relative_filename ()
959 %!error is_rooted_relative_filename ("foo", "bar")
960 */
961 
962 DEFUN (make_absolute_filename, args, ,
963  doc: /* -*- texinfo -*-
964 @deftypefn {} {} make_absolute_filename (@var{file})
965 Return the full name of @var{file} beginning from the root of the file
966 system.
967 
968 No check is done for the existence of @var{file}.
969 @seealso{canonicalize_file_name, is_absolute_filename, is_rooted_relative_filename, isdir}
970 @end deftypefn */)
971 {
972  if (args.length () != 1)
973  print_usage ();
974 
975  std::string nm = args(0).xstring_value ("make_absolute_filename: FILE argument must be a filename");
976 
978 }
979 
980 /*
981 ## FIXME: We need system-dependent tests here.
982 
983 %!error make_absolute_filename ()
984 %!error make_absolute_filename ("foo", "bar")
985 */
986 
987 DEFMETHOD (dir_in_loadpath, interp, args, ,
988  doc: /* -*- texinfo -*-
989 @deftypefn {} {@var{dirname} =} dir_in_loadpath (@var{dir})
990 @deftypefnx {} {@var{dirname} =} dir_in_loadpath (@var{dir}, "all")
991 Return the absolute name of the loadpath element matching @var{dir} if it can
992 be found in the list of directories specified by @code{path}.
993 
994 If no match is found, return an empty character string.
995 
996 The match is performed at the end of each path element. For example, if
997 @var{dir} is @qcode{"foo/bar"}, it matches the path element
998 @nospell{@qcode{"/some/dir/foo/bar"}}, but not
999 @nospell{@qcode{"/some/dir/foo/bar/baz"}}
1000 @nospell{@qcode{"/some/dir/allfoo/bar"}}. When @var{dir} is an absolute name,
1001 rather than just a path fragment, it is matched against the file system
1002 instead of Octave's loadpath. In this case, if @var{dir} exists it will be
1003 returned in @var{dirname}, otherwise an empty string is returned.
1004 
1005 If the optional second argument is supplied, return a cell array containing
1006 all name matches rather than just the first.
1007 @seealso{file_in_path, file_in_loadpath, path}
1008 @end deftypefn */)
1009 {
1010  int nargin = args.length ();
1011 
1012  if (nargin < 1 || nargin > 2)
1013  print_usage ();
1014 
1015  std::string dir;
1016 
1017  dir = args(0).xstring_value ("dir_in_loadpath: DIR must be a directory name");
1018 
1019  octave::load_path& lp = interp.get_load_path ();
1020 
1021  if (nargin == 1)
1022  return ovl (lp.find_dir (dir));
1023  else
1024  return ovl (Cell (lp.find_matching_dirs (dir)));
1025 }
1026 
1027 /*
1028 %!test
1029 %! f = dir_in_loadpath ("plot");
1030 %! assert (ischar (f));
1031 %! assert (! isempty (f));
1032 
1033 %!test
1034 %! f = dir_in_loadpath ("$$probably_!! _not_&&_a_!! _dir$$");
1035 %! assert (f, "");
1036 
1037 %!test
1038 %! lst = dir_in_loadpath ("$$probably_!! _not_&&_a_!! _dir$$", "all");
1039 %! assert (lst, {});
1040 
1041 %!error dir_in_loadpath ()
1042 %!error dir_in_loadpath ("foo", "bar", 1)
1043 */
1044 
1045 DEFUNX ("errno", Ferrno, args, ,
1046  doc: /* -*- texinfo -*-
1047 @deftypefn {} {@var{err} =} errno ()
1048 @deftypefnx {} {@var{err} =} errno (@var{val})
1049 @deftypefnx {} {@var{err} =} errno (@var{name})
1050 Query or set the system-dependent variable errno.
1051 
1052 When called with no inputs, return the current value of errno.
1053 
1054 When called with a numeric input @var{val}, set the current value of errno
1055 to the specified value. The previous value of errno is returned as @var{err}.
1056 
1057 When called with a character string @var{name}, return the numeric value of
1058 errno which corresponds to the specified error code. If @var{name} is not
1059 a recognized error code then -1 is returned.
1060 
1061 @seealso{errno_list}
1062 @end deftypefn */)
1063 {
1064  int nargin = args.length ();
1065 
1066  if (nargin > 1)
1067  print_usage ();
1068 
1070 
1071  if (nargin == 1)
1072  {
1073  if (args(0).is_string ())
1074  {
1075  std::string nm = args(0).string_value ();
1076 
1078  }
1079  else
1080  {
1081  int val = args(0).xint_value ("errno: argument must be string or integer");
1082 
1084  }
1085  }
1086  else
1088 
1089  return retval;
1090 }
1091 
1092 /*
1093 %!assert (isnumeric (errno ()))
1094 
1095 %!test
1096 %! lst = errno_list ();
1097 %! fns = fieldnames (lst);
1098 %! oldval = errno (fns{1});
1099 %! assert (isnumeric (oldval));
1100 %! errno (oldval);
1101 %! newval = errno ();
1102 %! assert (oldval, newval);
1103 
1104 %!error errno ("foo", 1)
1105 */
1106 
1107 DEFUN (errno_list, args, ,
1108  doc: /* -*- texinfo -*-
1109 @deftypefn {} {} errno_list ()
1110 Return a structure containing the system-dependent errno values.
1111 @seealso{errno}
1112 @end deftypefn */)
1113 {
1114  if (args.length () != 0)
1115  print_usage ();
1116 
1117  return ovl (octave_errno::list ());
1118 }
1119 
1120 /*
1121 %!assert (isstruct (errno_list ()))
1122 
1123 %!error errno_list ("foo")
1124 */
1125 
1126 static void
1127 check_dimensions (octave_idx_type& nr, octave_idx_type& nc, const char *warnfor)
1128 {
1129  if (nr < 0 || nc < 0)
1130  {
1131  warning_with_id ("Octave:neg-dim-as-zero",
1132  "%s: converting negative dimension to zero", warnfor);
1133 
1134  nr = (nr < 0) ? 0 : nr;
1135  nc = (nc < 0) ? 0 : nc;
1136  }
1137 }
1138 
1139 void
1140 check_dimensions (dim_vector& dim, const char *warnfor)
1141 {
1142  bool neg = false;
1143 
1144  for (int i = 0; i < dim.ndims (); i++)
1145  {
1146  if (dim(i) < 0)
1147  {
1148  dim(i) = 0;
1149  neg = true;
1150  }
1151  }
1152 
1153  if (neg)
1154  warning_with_id ("Octave:neg-dim-as-zero",
1155  "%s: converting negative dimension to zero", warnfor);
1156 }
1157 
1158 void
1159 get_dimensions (const octave_value& a, const char *warn_for,
1160  dim_vector& dim)
1161 {
1162  // We support dimensions to be specified by any vector, even if it's a
1163  // vector of dimensions 0x1, 1x0, 1x1x0, or 1x1x6. If the vector ends
1164  // up being empty, the final dimensions end up being 0x0.
1165  if (! a.dims ().isvector ())
1166  error ("%s (A): use %s (size (A)) instead", warn_for, warn_for);
1167 
1168  const Array<octave_idx_type> v = a.octave_idx_type_vector_value ();
1169  const octave_idx_type n = v.numel ();
1170 
1171  dim.resize (n); // even if n < 2, resize sets it back to 2
1172  if (n == 0)
1173  {
1174  dim(0) = 0;
1175  dim(1) = 0;
1176  }
1177  else if (n == 1)
1178  {
1179  dim(0) = v(0);
1180  dim(1) = v(0);
1181  }
1182  else
1183  for (octave_idx_type i = 0; i < n; i++)
1184  dim(i) = v(i);
1185 
1186  check_dimensions (dim, warn_for);
1187 }
1188 
1189 void
1190 get_dimensions (const octave_value& a, const char *warn_for,
1192 {
1193  if (a.is_scalar_type ())
1194  {
1195  nr = nc = a.idx_type_value ();
1196  }
1197  else
1198  {
1199  nr = a.rows ();
1200  nc = a.columns ();
1201 
1202  if ((nr != 1 || nc != 2) && (nr != 2 || nc != 1))
1203  error ("%s (A): use %s (size (A)) instead", warn_for, warn_for);
1204 
1205  Array<double> v = a.vector_value ();
1206  nr = static_cast<octave_idx_type> (octave::math::fix (v(0)));
1207  nc = static_cast<octave_idx_type> (octave::math::fix (v(1)));
1208  }
1209 
1210  check_dimensions (nr, nc, warn_for);
1211 }
1212 
1213 void
1214 get_dimensions (const octave_value& a, const octave_value& b,
1215  const char *warn_for, octave_idx_type& nr, octave_idx_type& nc)
1216 {
1217  nr = a.isempty ()
1218  ? 0 : a.idx_type_value ("%s: row dimension must be a scalar", warn_for);
1219  nc = b.isempty ()
1220  ? 0 : b.idx_type_value ("%s: column dimension must be a scalar", warn_for);
1221 
1222  check_dimensions (nr, nc, warn_for);
1223 }
1224 
1226 dims_to_numel (const dim_vector& dims, const octave_value_list& idx_arg)
1227 {
1229 
1230  octave_idx_type len = idx_arg.length ();
1231 
1232  if (len == 0)
1233  retval = dims.numel ();
1234  else
1235  {
1236  const dim_vector dv = dims.redim (len);
1237  retval = 1;
1238  for (octave_idx_type i = 0; i < len; i++)
1239  {
1240  octave_value idxi = idx_arg(i);
1241  if (idxi.is_magic_colon ())
1242  retval *= dv(i);
1243  else if (idxi.isnumeric ())
1244  retval *= idxi.numel ();
1245  else
1246  {
1247  try
1248  {
1249  idx_vector jdx = idxi.index_vector ();
1250 
1251  retval *= jdx.length (dv(i));
1252  }
1253  catch (const octave::index_exception& e)
1254  {
1255  std::string idx = e.idx ();
1256  std::string msg = e.details ();
1257 
1258  error ("dims_to_numel: Invalid IDX %s. %s",
1259  idx.c_str (), msg.c_str ());
1260  }
1261  }
1262  }
1263  }
1264 
1265  return retval;
1266 }
1267 
1268 Matrix
1270 {
1271  Matrix m (nr, nc, 0.0);
1272 
1273  if (nr > 0 && nc > 0)
1274  {
1275  octave_idx_type n = std::min (nr, nc);
1276 
1277  for (octave_idx_type i = 0; i < n; i++)
1278  m (i, i) = 1.0;
1279  }
1280 
1281  return m;
1282 }
1283 
1286 {
1287  FloatMatrix m (nr, nc, 0.0);
1288 
1289  if (nr > 0 && nc > 0)
1290  {
1291  octave_idx_type n = std::min (nr, nc);
1292 
1293  for (octave_idx_type i = 0; i < n; i++)
1294  m (i, i) = 1.0;
1295  }
1296 
1297  return m;
1298 }
1299 
1300 size_t
1301 octave_format (std::ostream& os, const char *fmt, ...)
1302 {
1303  size_t retval;
1304 
1305  va_list args;
1306  va_start (args, fmt);
1307 
1308  retval = octave_vformat (os, fmt, args);
1309 
1310  va_end (args);
1311 
1312  return retval;
1313 }
1314 
1315 size_t
1316 octave_vformat (std::ostream& os, const char *fmt, va_list args)
1317 {
1318  std::string s = octave_vasprintf (fmt, args);
1319 
1320  os << s;
1321 
1322  return s.length ();
1323 }
1324 
1326 octave_vasprintf (const char *fmt, va_list args)
1327 {
1329 
1330  char *result;
1331 
1332  int status = octave_vasprintf_wrapper (&result, fmt, args);
1333 
1334  if (status >= 0)
1335  {
1336  retval = result;
1337  ::free (result);
1338  }
1339 
1340  return retval;
1341 }
1342 
1344 octave_asprintf (const char *fmt, ...)
1345 {
1347 
1348  va_list args;
1349  va_start (args, fmt);
1350 
1351  retval = octave_vasprintf (fmt, args);
1352 
1353  va_end (args);
1354 
1355  return retval;
1356 }
1357 
1358 // FIXME: sleep is complicated because we want it to be interruptible.
1359 // With the way this program handles signals, the sleep system call
1360 // won't respond to SIGINT. Maybe there is a better way than
1361 // breaking this up into multiple shorter intervals?
1362 
1363 void
1364 octave_sleep (double seconds)
1365 {
1366  if (seconds <= 0)
1367  return;
1368 
1369  // Split delay into whole seconds and the remainder as a decimal
1370  // fraction.
1371 
1372  double fraction = std::modf (seconds, &seconds);
1373 
1374  // Further split the fractional seconds into whole tenths and the
1375  // nearest number of nanoseconds remaining.
1376 
1377  double tenths = 0;
1378  fraction = std::modf (fraction * 10, &tenths) / 10;
1379  fraction = std::round (fraction * 1000000000);
1380 
1381  // Sleep for the hundredths portion.
1382 
1383  struct timespec hundredths_delay = { 0, static_cast<long> (fraction) };
1384 
1385  octave_nanosleep_wrapper (&hundredths_delay, nullptr);
1386 
1387  // Sleep for the whole tenths portion, allowing interrupts every
1388  // tenth.
1389 
1390  struct timespec one_tenth = { 0, 100000000 };
1391 
1392  for (int i = 0; i < static_cast<int> (tenths); i++)
1393  {
1394  octave_nanosleep_wrapper (&one_tenth, nullptr);
1395 
1396  octave_quit ();
1397  }
1398 
1399  // Sleep for the whole seconds portion, allowing interrupts every
1400  // tenth.
1401 
1402  time_t sec = ((seconds > std::numeric_limits<time_t>::max ())
1404  : static_cast<time_t> (seconds));
1405 
1406  for (time_t s = 0; s < sec; s++)
1407  {
1408  for (int i = 0; i < 10; i++)
1409  {
1410  octave_nanosleep_wrapper (&one_tenth, nullptr);
1411 
1412  octave_quit ();
1413  }
1414  }
1415 }
1416 
1417 DEFUN (isindex, args, ,
1418  doc: /* -*- texinfo -*-
1419 @deftypefn {} {} isindex (@var{ind})
1420 @deftypefnx {} {} isindex (@var{ind}, @var{n})
1421 Return true if @var{ind} is a valid index.
1422 
1423 Valid indices are either positive integers (although possibly of real data
1424 type), or logical arrays.
1425 
1426 If present, @var{n} specifies the maximum extent of the dimension to be
1427 indexed. When possible the internal result is cached so that subsequent
1428 indexing using @var{ind} will not perform the check again.
1429 
1430 Implementation Note: Strings are first converted to double values before the
1431 checks for valid indices are made. Unless a string contains the NULL
1432 character @nospell{"@xbackslashchar{}0"}, it will always be a valid index.
1433 @end deftypefn */)
1434 {
1435  int nargin = args.length ();
1436 
1437  if (nargin < 1 || nargin > 2)
1438  print_usage ();
1439 
1440  octave_idx_type n = 0;
1441  if (nargin == 2)
1442  n = args(1).idx_type_value ();
1443 
1445 
1447 
1449  discard_error_messages = true;
1450 
1451  try
1452  {
1453  idx_vector idx = args(0).index_vector (true);
1454 
1455  if (nargin == 2)
1456  retval = idx.extent (n) <= n;
1457  else
1458  retval = true;
1459  }
1460  catch (const octave::execution_exception&)
1461  {
1463 
1464  retval = false;
1465  }
1466 
1467  return retval;
1468 }
1469 
1470 /*
1471 %!assert (isindex ([1, 2, 3]))
1472 %!assert (isindex (1:3))
1473 %!assert (isindex (1:3, 2), false)
1474 %!assert (isindex ([1, 2, -3]), false)
1475 
1476 %!error isindex ()
1477 %!error isindex (1:3, 2, 3)
1478 */
1479 
1482  const char *fun_name, const octave_value_list& args,
1483  int nargout)
1484 {
1485  octave_value_list new_args = args;
1487  int nargin = args.length ();
1488  OCTAVE_LOCAL_BUFFER (bool, iscell, nargin);
1489  OCTAVE_LOCAL_BUFFER (Cell, cells, nargin);
1490  OCTAVE_LOCAL_BUFFER (Cell, rcells, nargout);
1491 
1492  const Cell *ccells = cells;
1493 
1494  octave_idx_type numel = 1;
1495  dim_vector dims (1, 1);
1496 
1497  for (int i = 0; i < nargin; i++)
1498  {
1499  octave_value arg = new_args(i);
1500  iscell[i] = arg.iscell ();
1501  if (iscell[i])
1502  {
1503  cells[i] = arg.cell_value ();
1504  octave_idx_type n = ccells[i].numel ();
1505  if (n == 1)
1506  {
1507  iscell[i] = false;
1508  new_args(i) = ccells[i](0);
1509  }
1510  else if (numel == 1)
1511  {
1512  numel = n;
1513  dims = ccells[i].dims ();
1514  }
1515  else if (dims != ccells[i].dims ())
1516  error ("%s: cell arguments must have matching sizes", fun_name);
1517  }
1518  }
1519 
1520  for (int i = 0; i < nargout; i++)
1521  rcells[i].clear (dims);
1522 
1523  for (octave_idx_type j = 0; j < numel; j++)
1524  {
1525  for (int i = 0; i < nargin; i++)
1526  if (iscell[i])
1527  new_args(i) = ccells[i](j);
1528 
1529  octave_quit ();
1530 
1531  const octave_value_list tmp = fun (new_args, nargout);
1532 
1533  if (tmp.length () < nargout)
1534  error ("%s: do_simple_cellfun: internal error", fun_name);
1535 
1536  for (int i = 0; i < nargout; i++)
1537  rcells[i](j) = tmp(i);
1538  }
1539 
1540  retval.resize (nargout);
1541 
1542  for (int i = 0; i < nargout; i++)
1543  retval(i) = rcells[i];
1544 
1545  return retval;
1546 }
1547 
1550  const char *fun_name, const octave_value_list& args)
1551 {
1553 
1554  const octave_value_list tmp = do_simple_cellfun (fun, fun_name, args, 1);
1555 
1556  if (tmp.length () > 0)
1557  retval = tmp(0);
1558 
1559  return retval;
1560 }
1561 
1562 DEFUN (isstudent, args, ,
1563  doc: /* -*- texinfo -*-
1564 @deftypefn {} {} isstudent ()
1565 Return true if running in the student edition of @sc{matlab}.
1566 
1567 @code{isstudent} always returns false in Octave.
1568 @seealso{false}
1569 @end deftypefn */)
1570 {
1571  if (args.length () != 0)
1572  print_usage ();
1573 
1574  return ovl (false);
1575 }
1576 
1577 /*
1578 %!assert (isstudent (), false)
1579 
1580 %!error isstudent (1)
1581 */
void warning_with_id(const char *id, const char *fmt,...)
Definition: error.cc:816
std::string find_first_of(const string_vector &files) const
Definition: load-path.cc:575
OCTINTERP_API void octave_sleep(double seconds)
Definition: Cell.h:37
For example cd octave end example noindent changes the current working directory to file
Definition: dirfns.cc:124
bool same_file(const std::string &f, const std::string &g)
Definition: utils.cc:130
#define DEFMETHOD(name, interp_name, args_name, nargout_name, doc)
Macro to define a builtin method.
Definition: defun.h:135
OCTINTERP_API std::string oct_file_in_path(const std::string &)
fname
Definition: load-save.cc:767
static void recover_from_exception(void)
octave_idx_type extent(octave_idx_type n) const
Definition: idx-vector.h:560
OCTAVE_EXPORT octave_value_list who nd deftypefn *octave_value retval
Definition: utils.cc:102
OCTINTERP_API void print_usage(void)
Definition: defun.cc:54
idx_vector index_vector(bool require_integers=false) const
Definition: ov.h:462
OCTINTERP_API size_t octave_vformat(std::ostream &os, const char *fmt, va_list args)
identity matrix If supplied two scalar respectively For allows like xample val
Definition: data.cc:4986
F77_RET_T const F77_REAL const F77_REAL F77_REAL &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE &F77_RET_T const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &F77_RET_T const F77_DBLE const F77_DBLE * f
s2
Definition: sub2ind.cc:107
OCTINTERP_API std::string undo_string_escapes(const std::string &s)
OCTINTERP_API std::string fcn_file_in_path(const std::string &)
octave_value_list & append(const octave_value &val)
Definition: ovl.cc:83
string_vector find_all_first_of(const string_vector &files) const
Definition: load-path.cc:652
for large enough k
Definition: lu.cc:617
static string_vector make_absolute(const string_vector &sv)
Definition: utils.cc:272
void resize(int n, int fill_value=0)
Definition: dim-vector.h:310
is already an absolute name
Definition: utils.cc:305
#define DEFUN(name, args_name, nargout_name, doc)
Macro to define a builtin function.
Definition: defun.h:53
OCTINTERP_API octave_idx_type dims_to_numel(const dim_vector &dims, const octave_value_list &idx)
std::string find_oct_file(const std::string &fcn, const std::string &pack_name="")
Definition: load-path.h:136
void error(const char *fmt,...)
Definition: error.cc:578
bool is_magic_colon(void) const
Definition: ov.h:625
STL namespace.
const dim_vector & dims(void) const
Return a const-reference so that dims ()(i) works efficiently.
Definition: Array.h:442
int empty_arg(const char *, octave_idx_type nr, octave_idx_type nc)
Definition: utils.cc:239
OCTINTERP_API std::string file_in_path(const std::string &, const std::string &)
static bool rooted_relative_pathname(const std::string &s)
Definition: oct-env.cc:115
OCTAVE_EXPORT octave_value_list return the number of command line arguments passed to Octave If called with the optional argument the function t
Definition: ov-usr-fcn.cc:997
std::string find_mex_file(const std::string &fcn, const std::string &pack_name="")
Definition: load-path.h:143
nd example oindent opens the file binary numeric values will be read assuming they are stored in IEEE format with the least significant bit and then converted to the native representation Opening a file that is already open simply opens it again and returns a separate file id It is not an error to open a file several though writing to the same file through several different file ids may produce unexpected results The possible values of text mode reading and writing automatically converts linefeeds to the appropriate line end character for the you may append a you must also open the file in binary mode The parameter conversions are currently only supported for and permissions will be set to and then everything is written in a single operation This is very efficient and improves performance c
Definition: file-io.cc:587
double fix(double x)
Definition: lo-mappers.h:127
s
Definition: file-io.cc:2729
std::string find_dir(const std::string &dir) const
Definition: load-path.cc:483
i e
Definition: data.cc:2591
bool is_dir(void) const
Definition: file-stat.cc:57
OCTAVE_API int octave_strncasecmp(const char *s1, const char *s2, size_t n)
Definition: lo-cutils.c:46
std::string find_fcn_file(const std::string &fcn, const std::string &pack_name="")
Definition: load-path.h:129
octave_value arg
Definition: pr-output.cc:3244
octave_function * fcn
Definition: ov-class.cc:1754
calling an anonymous function involves an overhead quite comparable to the overhead of an m file function Passing a handle to a built in function is because the interpreter is not involved in the internal loop For a
Definition: cellfun.cc:400
int almost_match(const std::string &std, const std::string &s, int min_match_len, int case_sens)
Definition: utils.cc:136
int octave_vasprintf_wrapper(char **buf, const char *fmt, va_list args)
static std::string make_absolute(const std::string &s, const std::string &dot_path=get_current_directory())
Definition: oct-env.cc:129
std::string concat(const std::string &dir, const std::string &file)
Definition: file-ops.cc:344
OCTINTERP_API std::string contents_file_in_path(const std::string &)
done
Definition: syscalls.cc:251
OCTAVE_EXPORT octave_value_list isdir nd deftypefn *std::string nm
Definition: utils.cc:975
OCTAVE_EXPORT octave_value_list return the number of command line arguments passed to Octave If called with the optional argument the function xample nargout(@histc)
Definition: ov-usr-fcn.cc:997
void warn_data_file_in_path(const std::string &fcn, const std::string &file)
Definition: errwarn.cc:306
OCTINTERP_API std::string octave_asprintf(const char *fmt,...)
bool valid_identifier(const char *s)
Definition: utils.cc:74
octave_idx_type numel(const octave_value_list &idx)
Definition: ov.h:412
bool same_file_internal(const std::string &file1, const std::string &file2)
Definition: sysdep.cc:255
bool iscell(void) const
Definition: ov.h:536
OCTINTERP_API std::string octave_vasprintf(const char *fmt, va_list args)
std::string find_file(const std::string &file) const
Definition: load-path.cc:428
static bool absolute_pathname(const std::string &s)
Definition: oct-env.cc:108
#define DEFUNX(name, fname, args_name, nargout_name, doc)
Macro to define a builtin function with certain internal name.
Definition: defun.h:82
double tmp
Definition: data.cc:6252
octave_idx_type length(octave_idx_type n=0) const
Definition: idx-vector.h:557
static int get(void)
Definition: oct-errno.h:53
Definition: dMatrix.h:36
OCTAVE_EXPORT octave_value_list is_rooted_relative_filename
Definition: utils.cc:970
int keyword_almost_match(const char *const *std, int *min_len, const std::string &s, int min_toks_to_match, int max_toks)
Definition: utils.cc:152
bool is_keyword(const std::string &s)
OCTINTERP_API size_t octave_format(std::ostream &os, const char *fmt,...)
the exceeded dimensions are set to if fewer subscripts than dimensions are the exceeding dimensions are merged into the final requested dimension For consider the following dims
Definition: sub2ind.cc:255
return ovl(undo_string_escapes(str))
load_path & __get_load_path__(const std::string &who)
bool empty(void) const
Definition: str-vec.h:79
With real return the complex result
Definition: data.cc:3260
std::string search_path_for_file(const std::string &path, const string_vector &names)
Definition: utils.cc:247
OCTINTERP_API void get_dimensions(const octave_value &a, const char *warn_for, dim_vector &dim)
OCTINTERP_API FloatMatrix float_identity_matrix(octave_idx_type nr, octave_idx_type nc)
std::string str
Definition: utils.cc:893
void warning(const char *fmt,...)
Definition: error.cc:801
octave::unwind_protect frame
Definition: graphics.cc:12190
bool is_reg(void) const
Definition: file-stat.cc:75
charNDArray max(char d, const charNDArray &m)
Definition: chNDArray.cc:227
T::size_type numel(const T &str)
Definition: oct-string.cc:61
static char * strsave(const char *s)
Definition: main.in.cc:190
OCTINTERP_API std::string find_data_file_in_load_path(const std::string &fcn, const std::string &file, bool require_regular_file=false)
OCTINTERP_API const char * undo_string_escape(char c)
OCTINTERP_API std::string do_string_escapes(const std::string &s)
p
Definition: lu.cc:138
static int lookup(const std::string &name)
OCTINTERP_API Matrix identity_matrix(octave_idx_type nr, octave_idx_type nc)
OCTINTERP_API octave_value_list do_simple_cellfun(octave_value_list(*fun)(const octave_value_list &, int), const char *fun_name, const octave_value_list &args, int nargout)
octave_idx_type length(void) const
Definition: ovl.h:96
b
Definition: cellfun.cc:400
#define OCTAVE_LOCAL_BUFFER(T, buf, size)
Definition: oct-locbuf.h:41
OCTINTERP_API std::string mex_file_in_path(const std::string &)
bool exists(void) const
Definition: file-stat.h:144
octave::sys::file_stat fs(filename)
void resize(octave_idx_type n, const octave_value &rfv=octave_value())
Definition: ovl.h:100
double round(double x)
Definition: lo-mappers.h:145
args.length() nargin
Definition: file-io.cc:589
for i
Definition: data.cc:5264
static octave_scalar_map list(void)
octave_idx_type ndims(void) const
Number of dimensions.
Definition: dim-vector.h:295
string_vector search_path_for_all_files(const std::string &path, const string_vector &names)
Definition: utils.cc:257
bool strncmp(const T &str_a, const T &str_b, const typename T::size_type n)
True if the first N characters are the same.
Definition: oct-string.cc:146
std::list< std::string > std_list(void) const
Definition: str-vec.cc:169
octave_idx_type numel(void) const
Number of elements in the array.
Definition: Array.h:366
Vector representing the dimensions (size) of an Array.
Definition: dim-vector.h:87
bool discard_error_messages
Definition: error.cc:119
static int set(int val)
Definition: oct-errno.h:55
int octave_nanosleep_wrapper(const struct timespec *requested, struct timespec *remaining)
OCTINTERP_API void check_dimensions(dim_vector &dim, const char *warnfor)
If this string is the system will ring the terminal sometimes it is useful to be able to print the original representation of the string
Definition: utils.cc:888
dim_vector dv
Definition: sub2ind.cc:263
octave::stream os
Definition: file-io.cc:627
Cell cell_value(void) const
bool isnumeric(void) const
Definition: ov.h:723
string_vector find_matching_dirs(const std::string &dir) const
Definition: load-path.cc:529
charNDArray min(char d, const charNDArray &m)
Definition: chNDArray.cc:204