GNU Octave  4.2.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
utils.cc
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 1993-2017 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 the
10 Free Software Foundation; either version 3 of the License, or (at your
11 option) any later version.
12 
13 Octave is distributed in the hope that it will be useful, but WITHOUT
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 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 <http://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 "input.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, ' ')) != 0)
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] = 0;
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 
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++)
279  retval[i] = octave::sys::env::make_absolute (sv[i]);
280 
281  return retval;
282 }
283 
284 DEFUN (file_in_loadpath, args, ,
285  doc: /* -*- texinfo -*-
286 @deftypefn {} {} file_in_loadpath (@var{file})
287 @deftypefnx {} {} file_in_loadpath (@var{file}, "all")
288 
289 Return the absolute name of @var{file} if it can be found in
290 the list of directories specified by @code{path}.
291 
292 If no file is found, return an empty character string.
293 
294 If the first argument is a cell array of strings, search each directory of
295 the loadpath for element of the cell array and return the first that
296 matches.
297 
298 If the second optional argument @qcode{"all"} is supplied, return a cell
299 array containing the list of all files that have the same name in the path.
300 If no files are found, return an empty cell array.
301 @seealso{file_in_path, dir_in_loadpath, path}
302 @end deftypefn */)
303 {
304  int nargin = args.length ();
305 
306  if (nargin < 1 || nargin > 2)
307  print_usage ();
308 
309  string_vector names = args(0).xstring_vector_value ("file_in_loadpath: FILE argument must be a string");
310 
311  if (names.empty ())
312  error ("file_in_loadpath: FILE argument must not be empty");
313 
314  if (nargin == 1)
316  else
317  {
318  std::string opt = args(1).xstring_value ("file_in_loadpath: optional second argument must be a string");
319 
320  if (opt != "all")
321  error ("file_in_loadpath: \"all\" is only valid second argument");
322 
323  return ovl (Cell (make_absolute (load_path::find_all_first_of (names))));
324  }
325 }
326 
327 /*
328 %!test
329 %! f = file_in_loadpath ("plot.m");
330 %! assert (ischar (f));
331 %! assert (! isempty (f));
332 
333 %!test
334 %! f = file_in_loadpath ("$$probably_!! _not_&&_a_!! _file$$");
335 %! assert (f, "");
336 
337 %!test
338 %! lst = file_in_loadpath ("$$probably_!! _not_&&_a_!! _file$$", "all");
339 %! assert (lst, {});
340 
341 %!error file_in_loadpath ()
342 %!error file_in_loadpath ("foo", "bar", 1)
343 %!error file_in_loadpath ([])
344 %!error file_in_loadpath ("plot.m", "bar")
345 */
346 
348  doc: /* -*- texinfo -*-
349 @deftypefn {} {} file_in_path (@var{path}, @var{file})
350 @deftypefnx {} {} file_in_path (@var{path}, @var{file}, "all")
351 Return the absolute name of @var{file} if it can be found in @var{path}.
352 
353 The value of @var{path} should be a colon-separated list of directories in
354 the format described for @code{path}. If no file is found, return an empty
355 character string. For example:
356 
357 @example
358 @group
359 file_in_path (EXEC_PATH, "sh")
360  @result{} "/bin/sh"
361 @end group
362 @end example
363 
364 If the second argument is a cell array of strings, search each directory of
365 the path for element of the cell array and return the first that matches.
366 
367 If the third optional argument @qcode{"all"} is supplied, return a cell
368 array containing the list of all files that have the same name in the path.
369 If no files are found, return an empty cell array.
370 @seealso{file_in_loadpath, dir_in_loadpath, path}
371 @end deftypefn */)
372 {
373  int nargin = args.length ();
374 
375  if (nargin < 2 || nargin > 3)
376  print_usage ();
377 
378  std::string path = args(0).xstring_value ("file_in_path: PATH must be a string");
379 
380  string_vector names = args(1).xstring_vector_value ("file_in_path: FILE argument must be a string");
381 
382  if (names.empty ())
383  error ("file_in_path: FILE argument must not be empty");
384 
385  if (nargin == 2)
386  return ovl (search_path_for_file (path, names));
387  else
388  {
389  std::string opt = args(2).xstring_value ("file_in_path: optional third argument must be a string");
390 
391  if (opt != "all")
392  error ("file_in_path: \"all\" is only valid third argument");
393 
394  return ovl (Cell (make_absolute (search_path_for_all_files (path, names))));
395  }
396 }
397 
398 /*
399 %!test
400 %! f = file_in_path (path (), "plot.m");
401 %! assert (ischar (f));
402 %! assert (! isempty (f));
403 
404 %!test
405 %! f = file_in_path (path (), "$$probably_!! _not_&&_a_!! _file$$");
406 %! assert (f, "");
407 
408 %!test
409 %! lst = file_in_path (path (), "$$probably_!! _not_&&_a_!! _file$$", "all");
410 %! assert (lst, {});
411 
412 %!error file_in_path ()
413 %!error file_in_path ("foo")
414 %!error file_in_path ("foo", "bar", "baz", 1)
415 %!error file_in_path ([])
416 %!error file_in_path (path (), [])
417 %!error file_in_path (path (), "plot.m", "bar")
418 */
419 
421 file_in_path (const std::string& name, const std::string& suffix)
422 {
423  std::string nm = name;
424 
425  if (! suffix.empty ())
426  nm.append (suffix);
427 
429 }
430 
433  const std::string& file,
434  bool require_regular_file)
435 {
437 
440  {
441  // Load path will also search "." first, but we don't want to
442  // issue a warning if the file is found in the current directory,
443  // so do an explicit check for that.
444  octave::sys::file_stat fs (fname);
445 
446  bool local_file_ok
447  = fs.exists () && (fs.is_reg () || ! require_regular_file);
448 
449  if (! local_file_ok)
450  {
451  // Not directly found; search load path.
454 
455  if (! tmp.empty ())
456  {
457  warn_data_file_in_path (fcn, tmp);
458 
459  fname = tmp;
460  }
461  }
462  }
463 
464  return fname;
465 }
466 
467 // See if there is an function file in the path.
468 // If so, return the full path to the file.
469 
471 fcn_file_in_path (const std::string& name)
472 {
474 
475  int len = name.length ();
476 
477  if (len > 0)
478  {
480  {
481  octave::sys::file_stat fs (name);
482 
483  if (fs.exists () && ! fs.is_dir ())
484  retval = name;
485  }
486  else if (len > 2 && name[len - 2] == '.' && name[len - 1] == 'm')
487  retval = load_path::find_fcn_file (name.substr (0, len-2));
488  else
489  {
490  std::string fname = name;
491  size_t pos = name.find_first_of (Vfilemarker);
492  if (pos != std::string::npos)
493  fname = name.substr (0, pos);
494 
495  retval = load_path::find_fcn_file (fname);
496  }
497  }
498 
499  return retval;
500 }
501 
502 // See if there is a directory called "name" in the path and if it
503 // contains a Contents.m file. If so, return the full path to this file.
504 
507 {
509 
510  if (dir.length () > 0)
511  {
513  std::string ("Contents.m"));
514 
515  octave::sys::file_stat fs (tcontents);
516 
517  if (fs.exists ())
518  retval = octave::sys::env::make_absolute (tcontents);
519  }
520 
521  return retval;
522 }
523 
524 // Deprecated in 4.2, remove in 4.6.
525 // See if there is a .oct file in the path.
526 // If so, return the full path to the file.
527 
529 oct_file_in_path (const std::string& name)
530 {
532 
533  int len = name.length ();
534 
535  if (len > 0)
536  {
538  {
539  octave::sys::file_stat fs (name);
540 
541  if (fs.exists ())
542  retval = name;
543  }
544  else if (len > 4 && name.find (".oct", len-5))
545  retval = load_path::find_oct_file (name.substr (0, len-4));
546  else
547  retval = load_path::find_oct_file (name);
548  }
549 
550  return retval;
551 }
552 
553 // Deprecated in 4.2, remove in 4.6.
554 // See if there is a .mex file in the path.
555 // If so, return the full path to the file.
556 
558 mex_file_in_path (const std::string& name)
559 {
561 
562  int len = name.length ();
563 
564  if (len > 0)
565  {
567  {
568  octave::sys::file_stat fs (name);
569 
570  if (fs.exists ())
571  retval = name;
572  }
573  else if (len > 4 && name.find (".mex", len-5))
574  retval = load_path::find_mex_file (name.substr (0, len-4));
575  else
576  retval = load_path::find_mex_file (name);
577  }
578 
579  return retval;
580 }
581 
582 // Replace backslash escapes in a string with the real values.
583 
586 {
588 
589  size_t i = 0;
590  size_t j = 0;
591  size_t len = s.length ();
592 
593  retval.resize (len);
594 
595  while (j < len)
596  {
597  if (s[j] == '\\' && j+1 < len)
598  {
599  switch (s[++j])
600  {
601  case 'a': // alarm
602  retval[i] = '\a';
603  break;
604 
605  case 'b': // backspace
606  retval[i] = '\b';
607  break;
608 
609  case 'f': // formfeed
610  retval[i] = '\f';
611  break;
612 
613  case 'n': // newline
614  retval[i] = '\n';
615  break;
616 
617  case 'r': // carriage return
618  retval[i] = '\r';
619  break;
620 
621  case 't': // horizontal tab
622  retval[i] = '\t';
623  break;
624 
625  case 'v': // vertical tab
626  retval[i] = '\v';
627  break;
628 
629  case '\\': // backslash
630  retval[i] = '\\';
631  break;
632 
633  case '\'': // quote
634  retval[i] = '\'';
635  break;
636 
637  case '"': // double quote
638  retval[i] = '"';
639  break;
640 
641  case '0':
642  case '1':
643  case '2':
644  case '3':
645  case '4':
646  case '5':
647  case '6':
648  case '7': // octal input
649  {
650  size_t k;
651  int tmpi = s[j] - '0';
652  for (k = j+1; k < std::min (j+3, len); k++)
653  {
654  int digit = s[k] - '0';
655  if (digit < 0 || digit > 7)
656  break;
657  tmpi <<= 3;
658  tmpi += digit;
659  }
660  retval[i] = tmpi;
661  j = k - 1;
662  break;
663  }
664 
665  case 'x': // hex input
666  {
667  size_t k;
668  int tmpi = 0;
669  for (k = j+1; k < std::min (j+3, len); k++)
670  {
671  if (! isxdigit (s[k]))
672  break;
673 
674  tmpi <<= 4;
675  int digit = s[k];
676  if (digit >= 'a')
677  tmpi += digit - 'a' + 10;
678  else if (digit >= 'A')
679  tmpi += digit - 'A' + 10;
680  else
681  tmpi += digit - '0';
682  }
683 
684  if (k == j+1)
685  warning ("malformed hex escape sequence '\\x' -- converting to '\\0'");
686 
687  retval[i] = tmpi;
688  j = k - 1;
689  break;
690  }
691 
692  default:
693  warning ("unrecognized escape sequence '\\%c' -- converting to '%c'", s[j], s[j]);
694  retval[i] = s[j];
695  break;
696  }
697  }
698  else
699  retval[i] = s[j];
700 
701  i++;
702  j++;
703  }
704 
705  retval.resize (i);
706 
707  return retval;
708 }
709 
711  doc: /* -*- texinfo -*-
712 @deftypefn {} {} do_string_escapes (@var{string})
713 Convert escape sequences in @var{string} to the characters they represent.
714 
715 Escape sequences begin with a leading backslash
716 (@qcode{'@xbackslashchar{}'}) followed by 1--3 characters
717 (.e.g., @qcode{"@xbackslashchar{}n"} => newline).
718 @seealso{undo_string_escapes}
719 @end deftypefn */)
720 {
721  if (args.length () != 1)
722  print_usage ();
723 
724  std::string str = args(0).xstring_value ("do_string_escapes: STRING argument must be of type string");
725 
726  return ovl (do_string_escapes (str));
727 }
728 
729 /*
730 %!assert (do_string_escapes ('foo\nbar'), "foo\nbar")
731 %!assert (do_string_escapes ("foo\\nbar"), "foo\nbar")
732 %!assert (do_string_escapes ("foo\\nbar"), ["foo", char(10), "bar"])
733 %!assert ("foo\nbar", ["foo", char(10), "bar"])
734 
735 %!assert (do_string_escapes ('\0\a\b\f\n\r\t\v'), "\0\a\b\f\n\r\t\v")
736 %!assert (do_string_escapes ("\\0\\a\\b\\f\\n\\r\\t\\v"), "\0\a\b\f\n\r\t\v")
737 %!assert (do_string_escapes ("\\0\\a\\b\\f\\n\\r\\t\\v"),
738 %! char ([0, 7, 8, 12, 10, 13, 9, 11]))
739 %!assert ("\0\a\b\f\n\r\t\v", char ([0, 7, 8, 12, 10, 13, 9, 11]))
740 
741 %!assert (do_string_escapes ('\\'), "\\")
742 %!assert (do_string_escapes ("\\\\"), "\\")
743 %!assert (do_string_escapes ("\\\\"), char (92))
744 
745 %!assert (do_string_escapes ('\''single-quoted\'''), "'single-quoted'")
746 %!assert (do_string_escapes ("\\'single-quoted\\'"), "'single-quoted'")
747 %!assert (do_string_escapes ('\"double-quoted\"'), "\"double-quoted\"")
748 %!assert (do_string_escapes ("\\\"double-quoted\\\""), "\"double-quoted\"")
749 
750 %!assert (do_string_escapes ('A\4B'), ["A" char(4) "B"])
751 %!assert (do_string_escapes ('A\45B'), ["A" char(37) "B"])
752 %!assert (do_string_escapes ('A\123B'), ["A" char(83) "B"])
753 %!assert (sprintf ('\117\143\164\141\166\145'), "Octave")
754 
755 %!assert (do_string_escapes ('A\x4G'), ["A" char(4) "G"])
756 %!assert (do_string_escapes ('A\x4AG'), ["A" char(74) "G"])
757 %!assert (sprintf ('\x4f\x63\x74\x61\x76\x65'), "Octave")
758 
759 %!error do_string_escapes ()
760 %!error do_string_escapes ("foo", "bar")
761 %!error <STRING argument> do_string_escapes (3)
762 %!warning <malformed hex escape sequence> do_string_escapes ('\xG');
763 %!warning <unrecognized escape sequence> do_string_escapes ('\G');
764 */
765 
766 const char *
767 undo_string_escape (char c)
768 {
769  if (! c)
770  return "";
771 
772  switch (c)
773  {
774  case '\0':
775  return "\\0";
776 
777  case '\a':
778  return "\\a";
779 
780  case '\b': // backspace
781  return "\\b";
782 
783  case '\f': // formfeed
784  return "\\f";
785 
786  case '\n': // newline
787  return "\\n";
788 
789  case '\r': // carriage return
790  return "\\r";
791 
792  case '\t': // horizontal tab
793  return "\\t";
794 
795  case '\v': // vertical tab
796  return "\\v";
797 
798  case '\\': // backslash
799  return "\\\\";
800 
801  case '"': // double quote
802  return "\\\"";
803 
804  default:
805  {
806  static char retval[2] = "\0";
807 
808  retval[0] = c;
809  return retval;
810  }
811  }
812 }
813 
816 {
818 
819  for (size_t i = 0; i < s.length (); i++)
820  retval.append (undo_string_escape (s[i]));
821 
822  return retval;
823 }
824 
826  doc: /* -*- texinfo -*-
827 @deftypefn {} {} undo_string_escapes (@var{s})
828 Convert special characters in strings back to their escaped forms.
829 
830 For example, the expression
831 
832 @example
833 bell = "\a";
834 @end example
835 
836 @noindent
837 assigns the value of the alert character (control-g, ASCII code 7) to the
838 string variable @code{bell}. If this string is printed, the system will
839 ring the terminal bell (if it is possible). This is normally the desired
840 outcome. However, sometimes it is useful to be able to print the original
841 representation of the string, with the special characters replaced by their
842 escape sequences. For example,
843 
844 @example
845 @group
846 octave:13> undo_string_escapes (bell)
847 ans = \a
848 @end group
849 @end example
850 
851 @noindent
852 replaces the unprintable alert character with its printable representation.
853 @seealso{do_string_escapes}
854 @end deftypefn */)
855 {
856  if (args.length () != 1)
857  print_usage ();
858 
859  std::string str = args(0).xstring_value ("undo_string_escapes: S argument must be a string");
860 
861  return ovl (undo_string_escapes (str));
862 }
863 
864 /*
865 %!assert (undo_string_escapes ("foo\nbar"), 'foo\nbar')
866 %!assert (undo_string_escapes ("foo\nbar"), "foo\\nbar")
867 %!assert (undo_string_escapes (["foo", char(10), "bar"]), "foo\\nbar")
868 
869 %!assert (undo_string_escapes ("\a\b\f\n\r\t\v"), '\a\b\f\n\r\t\v')
870 %!assert (undo_string_escapes ("\a\b\f\n\r\t\v"), "\\a\\b\\f\\n\\r\\t\\v")
871 %!assert (undo_string_escapes (char ([7, 8, 12, 10, 13, 9, 11])),
872 %! "\\a\\b\\f\\n\\r\\t\\v")
873 
874 %!assert (undo_string_escapes ("\\"), '\\')
875 %!assert (undo_string_escapes ("\\"), "\\\\")
876 %!assert (undo_string_escapes (char (92)), "\\\\")
877 
878 %!assert (undo_string_escapes ("\"double-quoted\""), '\"double-quoted\"')
879 %!assert (undo_string_escapes ("\"double-quoted\""), "\\\"double-quoted\\\"")
880 
881 %!error undo_string_escapes ()
882 %!error undo_string_escapes ("foo", "bar")
883 %!error undo_string_escapes (3)
884 */
885 
886 DEFUN (is_absolute_filename, args, ,
887  doc: /* -*- texinfo -*-
888 @deftypefn {} {} is_absolute_filename (@var{file})
889 Return true if @var{file} is an absolute filename.
890 @seealso{is_rooted_relative_filename, make_absolute_filename, isdir}
891 @end deftypefn */)
892 {
893  if (args.length () != 1)
894  print_usage ();
895 
896  return ovl (args(0).is_string ()
897  && octave::sys::env::absolute_pathname (args(0).string_value ()));
898 }
899 
900 /*
901 ## FIXME: We need system-dependent tests here.
902 
903 %!error is_absolute_filename ()
904 %!error is_absolute_filename ("foo", "bar")
905 */
906 
908  doc: /* -*- texinfo -*-
909 @deftypefn {} {} is_rooted_relative_filename (@var{file})
910 Return true if @var{file} is a rooted-relative filename.
911 @seealso{is_absolute_filename, make_absolute_filename, isdir}
912 @end deftypefn */)
913 {
914  if (args.length () != 1)
915  print_usage ();
916 
917  return ovl (args(0).is_string ()
918  && octave::sys::env::rooted_relative_pathname (args(0).string_value ()));
919 }
920 
921 /*
922 ## FIXME: We need system-dependent tests here.
923 
924 %!error is_rooted_relative_filename ()
925 %!error is_rooted_relative_filename ("foo", "bar")
926 */
927 
928 DEFUN (make_absolute_filename, args, ,
929  doc: /* -*- texinfo -*-
930 @deftypefn {} {} make_absolute_filename (@var{file})
931 Return the full name of @var{file} beginning from the root of the file
932 system.
933 
934 No check is done for the existence of @var{file}.
935 @seealso{canonicalize_file_name, is_absolute_filename, is_rooted_relative_filename, isdir}
936 @end deftypefn */)
937 {
938  if (args.length () != 1)
939  print_usage ();
940 
941  std::string nm = args(0).xstring_value ("make_absolute_filename: FILE argument must be a filename");
942 
943  return ovl (octave::sys::env::make_absolute (nm));
944 }
945 
946 /*
947 ## FIXME: We need system-dependent tests here.
948 
949 %!error make_absolute_filename ()
950 %!error make_absolute_filename ("foo", "bar")
951 */
952 
953 DEFUN (dir_in_loadpath, args, ,
954  doc: /* -*- texinfo -*-
955 @deftypefn {} {} dir_in_loadpath (@var{dir})
956 @deftypefnx {} {} dir_in_loadpath (@var{dir}, "all")
957 Return the full name of the path element matching @var{dir}.
958 
959 The match is performed at the end of each path element. For example, if
960 @var{dir} is @qcode{"foo/bar"}, it matches the path element
961 @nospell{@qcode{"/some/dir/foo/bar"}}, but not
962 @nospell{@qcode{"/some/dir/foo/bar/baz"}}
963 @nospell{@qcode{"/some/dir/allfoo/bar"}}.
964 
965 If the optional second argument is supplied, return a cell array containing
966 all name matches rather than just the first.
967 @seealso{file_in_path, file_in_loadpath, path}
968 @end deftypefn */)
969 {
970  int nargin = args.length ();
971 
972  if (nargin < 1 || nargin > 2)
973  print_usage ();
974 
975  std::string dir;
976 
977  dir = args(0).xstring_value ("dir_in_loadpath: DIR must be a directory name");
978 
979  if (nargin == 1)
980  return ovl (load_path::find_dir (dir));
981  else
982  return ovl (Cell (load_path::find_matching_dirs (dir)));
983 }
984 
985 /*
986 %!test
987 %! f = dir_in_loadpath ("plot");
988 %! assert (ischar (f));
989 %! assert (! isempty (f));
990 
991 %!test
992 %! f = dir_in_loadpath ("$$probably_!! _not_&&_a_!! _dir$$");
993 %! assert (f, "");
994 
995 %!test
996 %! lst = dir_in_loadpath ("$$probably_!! _not_&&_a_!! _dir$$", "all");
997 %! assert (lst, {});
998 
999 %!error dir_in_loadpath ()
1000 %!error dir_in_loadpath ("foo", "bar", 1)
1001 */
1002 
1003 DEFUNX ("errno", Ferrno, args, ,
1004  doc: /* -*- texinfo -*-
1005 @deftypefn {} {@var{err} =} errno ()
1006 @deftypefnx {} {@var{err} =} errno (@var{val})
1007 @deftypefnx {} {@var{err} =} errno (@var{name})
1008 Return the current value of the system-dependent variable errno,
1009 set its value to @var{val} and return the previous value, or return
1010 the named error code given @var{name} as a character string, or -1
1011 if @var{name} is not found.
1012 @seealso{errno_list}
1013 @end deftypefn */)
1014 {
1015  int nargin = args.length ();
1016 
1017  if (nargin > 1)
1018  print_usage ();
1019 
1021 
1022  if (nargin == 1)
1023  {
1024  if (args(0).is_string ())
1025  {
1026  std::string nm = args(0).string_value ();
1027 
1028  retval = octave_errno::lookup (nm);
1029  }
1030  else
1031  {
1032  int val = args(0).xint_value ("errno: argument must be string or integer");
1033 
1034  retval = octave_errno::set (val);
1035  }
1036  }
1037  else
1038  retval = octave_errno::get ();
1039 
1040  return retval;
1041 }
1042 
1043 /*
1044 %!assert (isnumeric (errno ()))
1045 
1046 %!test
1047 %! lst = errno_list ();
1048 %! fns = fieldnames (lst);
1049 %! oldval = errno (fns{1});
1050 %! assert (isnumeric (oldval));
1051 %! errno (oldval);
1052 %! newval = errno ();
1053 %! assert (oldval, newval);
1054 
1055 %!error errno ("foo", 1)
1056 */
1057 
1058 DEFUN (errno_list, args, ,
1059  doc: /* -*- texinfo -*-
1060 @deftypefn {} {} errno_list ()
1061 Return a structure containing the system-dependent errno values.
1062 @seealso{errno}
1063 @end deftypefn */)
1064 {
1065  if (args.length () != 0)
1066  print_usage ();
1067 
1068  return ovl (octave_errno::list ());
1069 }
1070 
1071 /*
1072 %!assert (isstruct (errno_list ()))
1073 
1074 %!error errno_list ("foo")
1075 */
1076 
1077 static void
1078 check_dimensions (octave_idx_type& nr, octave_idx_type& nc, const char *warnfor)
1079 {
1080  if (nr < 0 || nc < 0)
1081  {
1082  warning_with_id ("Octave:neg-dim-as-zero",
1083  "%s: converting negative dimension to zero", warnfor);
1084 
1085  nr = (nr < 0) ? 0 : nr;
1086  nc = (nc < 0) ? 0 : nc;
1087  }
1088 }
1089 
1090 void
1091 check_dimensions (dim_vector& dim, const char *warnfor)
1092 {
1093  bool neg = false;
1094 
1095  for (int i = 0; i < dim.ndims (); i++)
1096  {
1097  if (dim(i) < 0)
1098  {
1099  dim(i) = 0;
1100  neg = true;
1101  }
1102  }
1103 
1104  if (neg)
1105  warning_with_id ("Octave:neg-dim-as-zero",
1106  "%s: converting negative dimension to zero", warnfor);
1107 }
1108 
1109 void
1110 get_dimensions (const octave_value& a, const char *warn_for,
1111  dim_vector& dim)
1112 {
1113  // We support dimensions to be specified by any vector, even if it's a
1114  // vector of dimensions 0x1, 1x0, 1x1x0, or 1x1x6. If the vector ends
1115  // up being empty, the final dimensions end up being 0x0.
1116  if (! a.dims ().is_vector ())
1117  error ("%s (A): use %s (size (A)) instead", warn_for, warn_for);
1118 
1119  const Array<int> v = a.int_vector_value ();
1120  const octave_idx_type n = v.numel ();
1121 
1122  dim.resize (n); // even if n < 2, resize sets it back to 2
1123  if (n == 0)
1124  {
1125  dim(0) = 0;
1126  dim(1) = 0;
1127  }
1128  else if (n == 1)
1129  {
1130  dim(0) = v(0);
1131  dim(1) = v(0);
1132  }
1133  else
1134  for (octave_idx_type i = 0; i < n; i++)
1135  dim(i) = v(i);
1136 
1137  check_dimensions (dim, warn_for);
1138 }
1139 
1140 void
1141 get_dimensions (const octave_value& a, const char *warn_for,
1143 {
1144  if (a.is_scalar_type ())
1145  {
1146  nr = nc = a.idx_type_value ();
1147  }
1148  else
1149  {
1150  nr = a.rows ();
1151  nc = a.columns ();
1152 
1153  if ((nr != 1 || nc != 2) && (nr != 2 || nc != 1))
1154  error ("%s (A): use %s (size (A)) instead", warn_for, warn_for);
1155 
1156  Array<double> v = a.vector_value ();
1157  nr = static_cast<octave_idx_type> (octave::math::fix (v(0)));
1158  nc = static_cast<octave_idx_type> (octave::math::fix (v(1)));
1159  }
1160 
1161  check_dimensions (nr, nc, warn_for);
1162 }
1163 
1164 void
1165 get_dimensions (const octave_value& a, const octave_value& b,
1166  const char *warn_for, octave_idx_type& nr, octave_idx_type& nc)
1167 {
1168  nr = a.is_empty ()
1169  ? 0 : a.idx_type_value ("%s: row dimension must be a scalar", warn_for);
1170  nc = b.is_empty ()
1171  ? 0 : b.idx_type_value ("%s: column dimension must be a scalar", warn_for);
1172 
1173  check_dimensions (nr, nc, warn_for);
1174 }
1175 
1177 dims_to_numel (const dim_vector& dims, const octave_value_list& idx_arg)
1178 {
1180 
1181  octave_idx_type len = idx_arg.length ();
1182 
1183  if (len == 0)
1184  retval = dims.numel ();
1185  else
1186  {
1187  const dim_vector dv = dims.redim (len);
1188  retval = 1;
1189  for (octave_idx_type i = 0; i < len; i++)
1190  {
1191  octave_value idxi = idx_arg(i);
1192  if (idxi.is_magic_colon ())
1193  retval *= dv(i);
1194  else if (idxi.is_numeric_type ())
1195  retval *= idxi.numel ();
1196  else
1197  {
1198  try
1199  {
1200  idx_vector jdx = idxi.index_vector ();
1201 
1202  retval *= jdx.length (dv(i));
1203  }
1204  catch (const octave::index_exception& e)
1205  {
1206  std::string idx = e.idx ();
1207  std::string msg = e.details ();
1208 
1209  error ("dims_to_numel: Invalid IDX %s. %s",
1210  idx.c_str (), msg.c_str ());
1211  }
1212  }
1213  }
1214  }
1215 
1216  return retval;
1217 }
1218 
1219 Matrix
1221 {
1222  Matrix m (nr, nc, 0.0);
1223 
1224  if (nr > 0 && nc > 0)
1225  {
1226  octave_idx_type n = std::min (nr, nc);
1227 
1228  for (octave_idx_type i = 0; i < n; i++)
1229  m (i, i) = 1.0;
1230  }
1231 
1232  return m;
1233 }
1234 
1237 {
1238  FloatMatrix m (nr, nc, 0.0);
1239 
1240  if (nr > 0 && nc > 0)
1241  {
1242  octave_idx_type n = std::min (nr, nc);
1243 
1244  for (octave_idx_type i = 0; i < n; i++)
1245  m (i, i) = 1.0;
1246  }
1247 
1248  return m;
1249 }
1250 
1251 size_t
1252 octave_format (std::ostream& os, const char *fmt, ...)
1253 {
1254  size_t retval;
1255 
1256  va_list args;
1257  va_start (args, fmt);
1258 
1259  retval = octave_vformat (os, fmt, args);
1260 
1261  va_end (args);
1262 
1263  return retval;
1264 }
1265 
1266 size_t
1267 octave_vformat (std::ostream& os, const char *fmt, va_list args)
1268 {
1269  std::string s = octave_vasprintf (fmt, args);
1270 
1271  os << s;
1272 
1273  return s.length ();
1274 }
1275 
1277 octave_vasprintf (const char *fmt, va_list args)
1278 {
1280 
1281  char *result;
1282 
1283  int status = octave_vasprintf_wrapper (&result, fmt, args);
1284 
1285  if (status >= 0)
1286  {
1287  retval = result;
1288  ::free (result);
1289  }
1290 
1291  return retval;
1292 }
1293 
1295 octave_asprintf (const char *fmt, ...)
1296 {
1298 
1299  va_list args;
1300  va_start (args, fmt);
1301 
1302  retval = octave_vasprintf (fmt, args);
1303 
1304  va_end (args);
1305 
1306  return retval;
1307 }
1308 
1309 void
1310 octave_sleep (double seconds)
1311 {
1312  if (seconds <= 0)
1313  return;
1314 
1315  double fraction = std::modf (seconds, &seconds);
1316  fraction = std::floor (fraction * 1000000000); // nanoseconds
1317 
1318  time_t sec = ((seconds > std::numeric_limits<time_t>::max ())
1320  : static_cast<time_t> (seconds));
1321 
1322  struct timespec delay = { sec, static_cast<long> (fraction) };
1323  struct timespec remaining;
1324  octave_nanosleep_wrapper (&delay, &remaining);
1325 
1326  octave_quit ();
1327 }
1328 
1329 DEFUN (isindex, args, ,
1330  doc: /* -*- texinfo -*-
1331 @deftypefn {} {} isindex (@var{ind})
1332 @deftypefnx {} {} isindex (@var{ind}, @var{n})
1333 Return true if @var{ind} is a valid index.
1334 
1335 Valid indices are either positive integers (although possibly of real data
1336 type), or logical arrays.
1337 
1338 If present, @var{n} specifies the maximum extent of the dimension to be
1339 indexed. When possible the internal result is cached so that subsequent
1340 indexing using @var{ind} will not perform the check again.
1341 
1342 Implementation Note: Strings are first converted to double values before the
1343 checks for valid indices are made. Unless a string contains the NULL
1344 character @nospell{"@xbackslashchar{}0"}, it will always be a valid index.
1345 @end deftypefn */)
1346 {
1347  int nargin = args.length ();
1348 
1349  if (nargin < 1 || nargin > 2)
1350  print_usage ();
1351 
1352  octave_idx_type n = 0;
1353  if (nargin == 2)
1354  n = args(1).idx_type_value ();
1355 
1357 
1359 
1361  discard_error_messages = true;
1362 
1363  try
1364  {
1365  idx_vector idx = args(0).index_vector (true);
1366 
1367  if (nargin == 2)
1368  retval = idx.extent (n) <= n;
1369  else
1370  retval = true;
1371  }
1372  catch (const octave::execution_exception&)
1373  {
1375 
1376  retval = false;
1377  }
1378 
1379  return retval;
1380 }
1381 
1382 /*
1383 %!assert (isindex ([1, 2, 3]))
1384 %!assert (isindex (1:3))
1385 %!assert (isindex (1:3, 2), false)
1386 %!assert (isindex ([1, 2, -3]), false)
1387 
1388 %!error isindex ()
1389 %!error isindex (1:3, 2, 3)
1390 */
1391 
1394  const char *fun_name, const octave_value_list& args,
1395  int nargout)
1396 {
1397  octave_value_list new_args = args;
1399  int nargin = args.length ();
1400  OCTAVE_LOCAL_BUFFER (bool, iscell, nargin);
1401  OCTAVE_LOCAL_BUFFER (Cell, cells, nargin);
1402  OCTAVE_LOCAL_BUFFER (Cell, rcells, nargout);
1403 
1404  const Cell *ccells = cells;
1405 
1406  octave_idx_type numel = 1;
1407  dim_vector dims (1, 1);
1408 
1409  for (int i = 0; i < nargin; i++)
1410  {
1411  octave_value arg = new_args(i);
1412  iscell[i] = arg.is_cell ();
1413  if (iscell[i])
1414  {
1415  cells[i] = arg.cell_value ();
1416  octave_idx_type n = ccells[i].numel ();
1417  if (n == 1)
1418  {
1419  iscell[i] = false;
1420  new_args(i) = ccells[i](0);
1421  }
1422  else if (numel == 1)
1423  {
1424  numel = n;
1425  dims = ccells[i].dims ();
1426  }
1427  else if (dims != ccells[i].dims ())
1428  error ("%s: cell arguments must have matching sizes", fun_name);
1429  }
1430  }
1431 
1432  for (int i = 0; i < nargout; i++)
1433  rcells[i].clear (dims);
1434 
1435  for (octave_idx_type j = 0; j < numel; j++)
1436  {
1437  for (int i = 0; i < nargin; i++)
1438  if (iscell[i])
1439  new_args(i) = ccells[i](j);
1440 
1441  octave_quit ();
1442 
1443  const octave_value_list tmp = fun (new_args, nargout);
1444 
1445  if (tmp.length () < nargout)
1446  error ("%s: do_simple_cellfun: internal error", fun_name);
1447 
1448  for (int i = 0; i < nargout; i++)
1449  rcells[i](j) = tmp(i);
1450  }
1451 
1452  retval.resize (nargout);
1453 
1454  for (int i = 0; i < nargout; i++)
1455  retval(i) = rcells[i];
1456 
1457  return retval;
1458 }
1459 
1462  const char *fun_name, const octave_value_list& args)
1463 {
1465 
1466  const octave_value_list tmp = do_simple_cellfun (fun, fun_name, args, 1);
1467 
1468  if (tmp.length () > 0)
1469  retval = tmp(0);
1470 
1471  return retval;
1472 }
1473 
1474 DEFUN (isstudent, args, ,
1475  doc: /* -*- texinfo -*-
1476 @deftypefn {} {} isstudent ()
1477 Return true if running in the student edition of @sc{matlab}.
1478 
1479 @code{isstudent} always returns false in Octave.
1480 @seealso{false}
1481 @end deftypefn */)
1482 {
1483  if (args.length () != 0)
1484  print_usage ();
1485 
1486  return ovl (false);
1487 }
1488 
1489 /*
1490 %!assert (isstudent (), false)
1491 
1492 %!error isstudent (1)
1493 */
void warning_with_id(const char *id, const char *fmt,...)
Definition: error.cc:803
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:120
octave_idx_type length(octave_idx_type n=0) const
Definition: idx-vector.h:541
static string_vector find_matching_dirs(const std::string &dir)
Definition: load-path.h:212
bool same_file(const std::string &f, const std::string &g)
Definition: utils.cc:130
OCTINTERP_API std::string oct_file_in_path(const std::string &)
fname
Definition: load-save.cc:754
octave_idx_type rows(void) const
Definition: ov.h:489
std::string find_first_of(const std::list< std::string > &names)
Definition: pathsearch.cc:105
bool is_vector(void) const
Definition: dim-vector.h:458
OCTAVE_EXPORT octave_value_list who nd deftypefn *octave_value retval
Definition: utils.cc:102
OCTINTERP_API void print_usage(void)
Definition: defun.cc:52
octave_idx_type numel(void) const
Number of elements in the array.
Definition: Array.h:363
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:5068
F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &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 F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &F77_RET_T F77_REAL F77_REAL &F77_RET_T F77_DBLE F77_DBLE &F77_RET_T const F77_DBLE const F77_DBLE * f
s2
Definition: sub2ind.cc:107
octave_idx_type length(void) const
Definition: ovl.h:96
OCTINTERP_API std::string undo_string_escapes(const std::string &s)
OCTINTERP_API std::string fcn_file_in_path(const std::string &)
bool is_scalar_type(void) const
Definition: ov.h:673
octave_value_list & append(const octave_value &val)
Definition: ovl.cc:85
bool is_numeric_type(void) const
Definition: ov.h:679
bool empty(void) const
Definition: str-vec.h:79
static char * strsave(const char *s)
Definition: main.cc:183
for large enough k
Definition: lu.cc:606
static std::string find_file(const std::string &file)
Definition: load-path.h:200
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:316
static std::string find_first_of(const string_vector &files)
Definition: load-path.h:218
void protect_var(T &var)
#define DEFUN(name, args_name, nargout_name, doc)
Definition: defun.h:46
OCTINTERP_API octave_idx_type dims_to_numel(const dim_vector &dims, const octave_value_list &idx)
void error(const char *fmt,...)
Definition: error.cc:570
STL namespace.
std::string idx(void) const
int empty_arg(const char *, octave_idx_type nr, octave_idx_type nc)
Definition: utils.cc:239
bool is_cell(void) const
Definition: ov.h:545
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:935
double fix(double x)
Definition: lo-mappers.h:158
s
Definition: file-io.cc:2682
octave_idx_type idx_type_value(bool req_int=false, bool frc_str_conv=false) const
Definition: ov.cc:1677
i e
Definition: data.cc:2724
OCTAVE_API int octave_strncasecmp(const char *s1, const char *s2, size_t n)
Definition: lo-cutils.c:46
octave_value arg
Definition: pr-output.cc:3440
octave_idx_type numel(int n=0) const
Number of elements that a matrix with this dimensions would have.
Definition: dim-vector.h:389
octave_function * fcn
Definition: ov-class.cc:1743
bool is_reg(void) const
Definition: file-stat.cc:75
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:398
Cell cell_value(void) const
Definition: ov.cc:1687
idx_vector index_vector(bool require_integers=false) const
Definition: ov.h:479
JNIEnv void * args
Definition: ov-java.cc:67
int almost_match(const std::string &std, const std::string &s, int min_match_len, int case_sens)
Definition: utils.cc:136
static std::string find_mex_file(const std::string &fcn, const std::string &pack_name="")
Definition: load-path.h:190
const dim_vector & dims(void) const
Return a const-reference so that dims ()(i) works efficiently.
Definition: Array.h:439
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
bool is_dir(void) const
Definition: file-stat.cc:57
OCTINTERP_API std::string contents_file_in_path(const std::string &)
octave_idx_type columns(void) const
Definition: ov.h:491
done
Definition: syscalls.cc:248
OCTAVE_EXPORT octave_value_list any number nd example oindent prints the prompt xample Pick a any number!nd example oindent and waits for the user to enter a value The string entered by the user is evaluated as an so it may be a literal a variable name
Definition: input.cc:871
OCTAVE_EXPORT octave_value_list isdir nd deftypefn *std::string nm
Definition: utils.cc:941
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:935
void warn_data_file_in_path(const std::string &fcn, const std::string &file)
Definition: errwarn.cc:300
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:411
bool same_file_internal(const std::string &file1, const std::string &file2)
Definition: sysdep.cc:264
nd deftypefn *octave_map m
Definition: ov-struct.cc:2058
int nargin
Definition: graphics.cc:10115
OCTINTERP_API std::string octave_vasprintf(const char *fmt, va_list args)
static bool absolute_pathname(const std::string &s)
Definition: oct-env.cc:108
static std::string find_oct_file(const std::string &fcn, const std::string &pack_name="")
Definition: load-path.h:180
#define DEFUNX(name, fname, args_name, nargout_name, doc)
Definition: defun.h:54
double tmp
Definition: data.cc:6300
bool is_magic_colon(void) const
Definition: ov.h:605
static int get(void)
Definition: oct-errno.h:54
dim_vector redim(int n) const
Definition: dim-vector.cc:275
std::list< std::string > find_all_first_of(const std::list< std::string > &names)
Definition: pathsearch.cc:112
bool exists(void) const
Definition: file-stat.h:144
OCTINTERP_API octave_value_list Ferrno(const octave_value_list &=octave_value_list(), int=0)
Definition: dMatrix.h:37
OCTAVE_EXPORT octave_value_list is_rooted_relative_filename
Definition: utils.cc:936
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)
Definition: lex.cc:4529
the sparsity preserving column transformation such that that defines the pivoting threshold can be given in which case it defines the c
Definition: lu.cc:138
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))
dim_vector dims(void) const
Definition: ov.h:486
With real return the complex result
Definition: data.cc:3375
static std::string concat(const std::string &, const std::string &)
Definition: file-ops.cc:375
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:859
void warning(const char *fmt,...)
Definition: error.cc:788
octave::unwind_protect frame
Definition: graphics.cc:11584
void recover_from_exception(void)
Definition: interpreter.cc:200
charNDArray max(char d, const charNDArray &m)
Definition: chNDArray.cc:228
bool is_empty(void) const
Definition: ov.h:542
octave_idx_type extent(octave_idx_type n) const
Definition: idx-vector.h:544
static std::string find_fcn_file(const std::string &fcn, const std::string &pack_name="")
Definition: load-path.h:170
T::size_type numel(const T &str)
Definition: oct-string.cc:61
OCTINTERP_API std::string find_data_file_in_load_path(const std::string &fcn, const std::string &file, bool require_regular_file=false)
char Vfilemarker
Definition: input.cc:124
OCTINTERP_API const char * undo_string_escape(char c)
void free(void *)
OCTINTERP_API std::string do_string_escapes(const std::string &s)
=val(i)}if ode{val(i)}occurs in table i
Definition: lookup.cc:239
p
Definition: lu.cc:138
static int lookup(const std::string &name)
Definition: oct-errno.cc:713
OCTINTERP_API Matrix identity_matrix(octave_idx_type nr, octave_idx_type nc)
Array< double > vector_value(bool frc_str_conv=false, bool frc_vec_conv=false) const
Definition: ov.cc:1798
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 ndims(void) const
Number of dimensions.
Definition: dim-vector.h:301
b
Definition: cellfun.cc:398
#define OCTAVE_LOCAL_BUFFER(T, buf, size)
Definition: oct-locbuf.h:200
OCTINTERP_API std::string mex_file_in_path(const std::string &)
octave::sys::file_stat fs(filename)
void resize(octave_idx_type n, const octave_value &rfv=octave_value())
Definition: ovl.h:100
static std::string find_dir(const std::string &dir)
Definition: load-path.h:206
std::list< std::string > std_list(void) const
Definition: str-vec.cc:169
double floor(double x)
Definition: lo-mappers.cc:330
static octave_scalar_map list(void)
Definition: oct-errno.cc:719
Array< int > int_vector_value(bool req_int=false, bool frc_str_conv=false, bool frc_vec_conv=false) const
Definition: ov.cc:1822
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
virtual std::string details(void) const =0
Vector representing the dimensions (size) of an Array.
Definition: dim-vector.h:87
bool discard_error_messages
Definition: error.cc:118
static int set(int val)
Definition: oct-errno.h:56
int octave_nanosleep_wrapper(const struct timespec *requested, struct timespec *remaining)
static void clear(octave::dynamic_library &oct_file)
Definition: dynamic-ld.cc:230
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:854
dim_vector dv
Definition: sub2ind.cc:263
static string_vector find_all_first_of(const string_vector &files)
Definition: load-path.h:224
charNDArray min(char d, const charNDArray &m)
Definition: chNDArray.cc:205