GNU Octave  4.0.0
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-2015 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 #ifdef 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 <sys/types.h>
37 #include <unistd.h>
38 
39 #include "vasnprintf.h"
40 
41 #include "dir-ops.h"
42 #include "file-ops.h"
43 #include "file-stat.h"
44 #include "lo-mappers.h"
45 #include "lo-utils.h"
46 #include "oct-cmplx.h"
47 #include "oct-env.h"
48 #include "oct-locbuf.h"
49 #include "pathsearch.h"
50 #include "quit.h"
51 #include "str-vec.h"
52 
53 #include "Cell.h"
54 #include <defaults.h>
55 #include "defun.h"
56 #include "dirfns.h"
57 #include "error.h"
58 #include "gripes.h"
59 #include "input.h"
60 #include "lex.h"
61 #include "load-path.h"
62 #include "oct-errno.h"
63 #include "oct-hist.h"
64 #include "oct-obj.h"
65 #include "ov-range.h"
66 #include "pager.h"
67 #include "parse.h"
68 #include "sysdep.h"
69 #include "toplev.h"
70 #include "unwind-prot.h"
71 #include "utils.h"
72 #include "variables.h"
73 
74 // Return TRUE if S is a valid identifier.
75 
76 bool
77 valid_identifier (const char *s)
78 {
79  if (! s || ! (isalpha (*s) || *s == '_' || *s == '$'))
80  return false;
81 
82  while (*++s != '\0')
83  if (! (isalnum (*s) || *s == '_' || *s == '$'))
84  return false;
85 
86  return true;
87 }
88 
89 bool
90 valid_identifier (const std::string& s)
91 {
92  return valid_identifier (s.c_str ());
93 }
94 
95 DEFUN (isvarname, args, ,
96  "-*- texinfo -*-\n\
97 @deftypefn {Built-in Function} {} isvarname (@var{name})\n\
98 Return true if @var{name} is a valid variable name.\n\
99 @seealso{iskeyword, exist, who}\n\
100 @end deftypefn")
101 {
102  octave_value retval = false;
103 
104  int nargin = args.length ();
105 
106  if (nargin != 1)
107  print_usage ();
108  else if (args(0).is_string ())
109  {
110  std::string varname = args(0).string_value ();
111  retval = valid_identifier (varname) && ! is_keyword (varname);
112  }
113 
114  return retval;
115 }
116 
117 /*
118 %!assert (isvarname ("foo"), true)
119 %!assert (isvarname ("_foo"), true)
120 %!assert (isvarname ("_1"), true)
121 %!assert (isvarname ("1foo"), false)
122 %!assert (isvarname (""), false)
123 %!assert (isvarname (12), false)
124 %!assert (isvarname ("foo+bar"), false)
125 
126 %!error isvarname ()
127 %!error isvarname ("foo", "bar");
128 */
129 
130 // Return TRUE if F and G are both names for the same file.
131 
132 bool
133 same_file (const std::string& f, const std::string& g)
134 {
135  return same_file_internal (f, g);
136 }
137 
138 int
139 almost_match (const std::string& std, const std::string& s, int min_match_len,
140  int case_sens)
141 {
142  int stdlen = std.length ();
143  int slen = s.length ();
144 
145  return (slen <= stdlen
146  && slen >= min_match_len
147  && (case_sens
148  ? (strncmp (std.c_str (), s.c_str (), slen) == 0)
149  : (octave_strncasecmp (std.c_str (), s.c_str (), slen) == 0)));
150 }
151 
152 // Ugh.
153 
154 int
155 keyword_almost_match (const char * const *std, int *min_len,
156  const std::string& s,
157  int min_toks_to_match, int max_toks)
158 {
159  int status = 0;
160  int tok_count = 0;
161  int toks_matched = 0;
162 
163  if (s.empty () || max_toks < 1)
164  return status;
165 
166  char *kw = strsave (s.c_str ());
167 
168  char *t = kw;
169  while (*t != '\0')
170  {
171  if (*t == '\t')
172  *t = ' ';
173  t++;
174  }
175 
176  char *beg = kw;
177  while (*beg == ' ')
178  beg++;
179 
180  if (*beg == '\0')
181  return status;
182 
183 
184  const char **to_match = new const char * [max_toks + 1];
185  const char * const *s1 = std;
186  const char **s2 = to_match;
187 
188  if (! s1 || ! s2)
189  goto done;
190 
191  s2[tok_count] = beg;
192  char *end;
193  while ((end = strchr (beg, ' ')) != 0)
194  {
195  *end = '\0';
196  beg = end + 1;
197 
198  while (*beg == ' ')
199  beg++;
200 
201  if (*beg == '\0')
202  break;
203 
204  tok_count++;
205  if (tok_count >= max_toks)
206  goto done;
207 
208  s2[tok_count] = beg;
209  }
210  s2[tok_count+1] = 0;
211 
212  s2 = to_match;
213 
214  for (;;)
215  {
216  if (! almost_match (*s1, *s2, min_len[toks_matched], 0))
217  goto done;
218 
219  toks_matched++;
220 
221  s1++;
222  s2++;
223 
224  if (! *s2)
225  {
226  status = (toks_matched >= min_toks_to_match);
227  goto done;
228  }
229 
230  if (! *s1)
231  goto done;
232  }
233 
234 done:
235 
236  delete [] kw;
237  delete [] to_match;
238 
239  return status;
240 }
241 
242 // Return nonzero if either NR or NC is zero. Return -1 if this
243 // should be considered fatal; return 1 if this is ok.
244 
245 int
246 empty_arg (const char * /* name */, octave_idx_type nr, octave_idx_type nc)
247 {
248  return (nr == 0 || nc == 0);
249 }
250 
251 // See if the given file is in the path.
252 
253 std::string
254 search_path_for_file (const std::string& path, const string_vector& names)
255 {
256  dir_path p (path);
257 
258  return octave_env::make_absolute (p.find_first_of (names));
259 }
260 
261 // Find all locations of the given file in the path.
262 
264 search_path_for_all_files (const std::string& path, const string_vector& names)
265 {
266  dir_path p (path);
267 
268  string_vector sv = p.find_all_first_of (names);
269 
270  octave_idx_type len = sv.length ();
271 
272  for (octave_idx_type i = 0; i < len; i++)
273  sv[i] = octave_env::make_absolute (sv[i]);
274 
275  return sv;
276 }
277 
278 static string_vector
280 {
281  octave_idx_type len = sv.length ();
282 
283  string_vector retval (len);
284 
285  for (octave_idx_type i = 0; i < len; i++)
286  retval[i] = octave_env::make_absolute (sv[i]);
287 
288  return retval;
289 }
290 
291 DEFUN (file_in_loadpath, args, ,
292  "-*- texinfo -*-\n\
293 @deftypefn {Built-in Function} {} file_in_loadpath (@var{file})\n\
294 @deftypefnx {Built-in Function} {} file_in_loadpath (@var{file}, \"all\")\n\
295 \n\
296 Return the absolute name of @var{file} if it can be found in\n\
297 the list of directories specified by @code{path}.\n\
298 \n\
299 If no file is found, return an empty character string.\n\
300 \n\
301 If the first argument is a cell array of strings, search each directory of\n\
302 the loadpath for element of the cell array and return the first that\n\
303 matches.\n\
304 \n\
305 If the second optional argument @qcode{\"all\"} is supplied, return a cell\n\
306 array containing the list of all files that have the same name in the path.\n\
307 If no files are found, return an empty cell array.\n\
308 @seealso{file_in_path, dir_in_loadpath, path}\n\
309 @end deftypefn")
310 {
311  octave_value retval;
312 
313  int nargin = args.length ();
314 
315  if (nargin == 1 || nargin == 2)
316  {
317  string_vector names = args(0).all_strings ();
318 
319  if (! error_state && names.length () > 0)
320  {
321  if (nargin == 1)
322  retval =
324  else if (nargin == 2)
325  {
326  std::string opt = args(1).string_value ();
327 
328  if (! error_state && opt == "all")
329  retval = Cell (make_absolute
330  (load_path::find_all_first_of (names)));
331  else
332  error ("file_in_loadpath: invalid option");
333  }
334  }
335  else
336  error ("file_in_loadpath: FILE argument must be a string");
337  }
338  else
339  print_usage ();
340 
341  return retval;
342 }
343 
344 /*
345 %!test
346 %! f = file_in_loadpath ("plot.m");
347 %! assert (ischar (f));
348 %! assert (! isempty (f));
349 
350 %!test
351 %! f = file_in_loadpath ("$$probably_!!_not_&&_a_!!_file$$");
352 %! assert (f, "");
353 
354 %!test
355 %! lst = file_in_loadpath ("$$probably_!!_not_&&_a_!!_file$$", "all");
356 %! assert (lst, {});
357 
358 %!error file_in_loadpath ()
359 %!error file_in_loadpath ("foo", "bar", 1)
360 %!error file_in_loadpath ([])
361 %!error file_in_loadpath ("plot.m", "bar")
362 */
363 
364 DEFUN (file_in_path, args, ,
365  "-*- texinfo -*-\n\
366 @deftypefn {Built-in Function} {} file_in_path (@var{path}, @var{file})\n\
367 @deftypefnx {Built-in Function} {} file_in_path (@var{path}, @var{file}, \"all\")\n\
368 Return the absolute name of @var{file} if it can be found in @var{path}.\n\
369 \n\
370 The value of @var{path} should be a colon-separated list of directories in\n\
371 the format described for @code{path}. If no file is found, return an empty\n\
372 character string. For example:\n\
373 \n\
374 @example\n\
375 @group\n\
376 file_in_path (EXEC_PATH, \"sh\")\n\
377  @result{} \"/bin/sh\"\n\
378 @end group\n\
379 @end example\n\
380 \n\
381 If the second argument is a cell array of strings, search each directory of\n\
382 the path for element of the cell array and return the first that matches.\n\
383 \n\
384 If the third optional argument @qcode{\"all\"} is supplied, return a cell\n\
385 array containing the list of all files that have the same name in the path.\n\
386 If no files are found, return an empty cell array.\n\
387 @seealso{file_in_loadpath, dir_in_loadpath, path}\n\
388 @end deftypefn")
389 {
390  octave_value retval;
391 
392  int nargin = args.length ();
393 
394  if (nargin == 2 || nargin == 3)
395  {
396  if (args(0).is_string ())
397  {
398  std::string path = args(0).string_value ();
399 
400  string_vector names = args(1).all_strings ();
401 
402  if (! error_state && names.length () > 0)
403  {
404  if (nargin == 2)
405  retval = search_path_for_file (path, names);
406  else if (nargin == 3)
407  {
408  std::string opt = args(2).string_value ();
409 
410  if (! error_state && opt == "all")
411  retval = Cell (make_absolute
412  (search_path_for_all_files (path, names)));
413  else
414  error ("file_in_path: invalid option");
415  }
416  }
417  else
418  error ("file_in_path: all arguments must be strings");
419  }
420  else
421  error ("file_in_path: PATH must be a string");
422  }
423  else
424  print_usage ();
425 
426  return retval;
427 }
428 
429 /*
430 %!test
431 %! f = file_in_path (path (), "plot.m");
432 %! assert (ischar (f));
433 %! assert (! isempty (f));
434 
435 %!test
436 %! f = file_in_path (path (), "$$probably_!!_not_&&_a_!!_file$$");
437 %! assert (f, "");
438 
439 %!test
440 %! lst = file_in_path (path (), "$$probably_!!_not_&&_a_!!_file$$", "all");
441 %! assert (lst, {});
442 
443 %!error file_in_path ()
444 %!error file_in_path ("foo")
445 %!error file_in_path ("foo", "bar", "baz", 1)
446 %!error file_in_path ([])
447 %!error file_in_path (path (), [])
448 %!error file_in_path (path (), "plot.m", "bar")
449 */
450 
451 std::string
452 file_in_path (const std::string& name, const std::string& suffix)
453 {
454  std::string nm = name;
455 
456  if (! suffix.empty ())
457  nm.append (suffix);
458 
460 }
461 
462 std::string
463 find_data_file_in_load_path (const std::string& fcn,
464  const std::string& file,
465  bool require_regular_file)
466 {
467  std::string fname = file;
468 
469  if (! (octave_env::absolute_pathname (fname)
471  {
472  // Load path will also search "." first, but we don't want to
473  // issue a warning if the file is found in the current directory,
474  // so do an explicit check for that.
475 
476  file_stat fs (fname);
477 
478  bool local_file_ok
479  = fs.exists () && (fs.is_reg () || ! require_regular_file);
480 
481  if (! local_file_ok)
482  {
483  // Not directly found; search load path.
484 
485  std::string tmp
487 
488  if (! tmp.empty ())
489  {
490  gripe_data_file_in_path (fcn, tmp);
491 
492  fname = tmp;
493  }
494  }
495  }
496 
497  return fname;
498 }
499 
500 // See if there is an function file in the path. If so, return the
501 // full path to the file.
502 
503 std::string
504 fcn_file_in_path (const std::string& name)
505 {
506  std::string retval;
507 
508  int len = name.length ();
509 
510  if (len > 0)
511  {
513  {
514  file_stat fs (name);
515 
516  if (fs.exists () && ! fs.is_dir ())
517  retval = name;
518  }
519  else if (len > 2 && name[len - 2] == '.' && name[len - 1] == 'm')
520  retval = load_path::find_fcn_file (name.substr (0, len-2));
521  else
522  {
523  std::string fname = name;
524  size_t pos = name.find_first_of (Vfilemarker);
525  if (pos != std::string::npos)
526  fname = name.substr (0, pos);
527 
528  retval = load_path::find_fcn_file (fname);
529  }
530  }
531 
532  return retval;
533 }
534 
535 // See if there is a directory called "name" in the path and if it
536 // contains a Contents.m file return the full path to this file.
537 
538 std::string
539 contents_file_in_path (const std::string& dir)
540 {
541  std::string retval;
542 
543  if (dir.length () > 0)
544  {
545  std::string tcontents = file_ops::concat (load_path::find_dir (dir),
546  std::string ("Contents.m"));
547 
548  file_stat fs (tcontents);
549 
550  if (fs.exists ())
551  retval = octave_env::make_absolute (tcontents);
552  }
553 
554  return retval;
555 }
556 
557 // See if there is a .oct file in the path. If so, return the
558 // full path to the file.
559 
560 std::string
561 oct_file_in_path (const std::string& name)
562 {
563  std::string retval;
564 
565  int len = name.length ();
566 
567  if (len > 0)
568  {
570  {
571  file_stat fs (name);
572 
573  if (fs.exists ())
574  retval = name;
575  }
576  else if (len > 4 && name[len - 4] == '.' && name[len - 3] == 'o'
577  && name[len - 2] == 'c' && name[len - 1] == 't')
578  retval = load_path::find_oct_file (name.substr (0, len-4));
579  else
580  retval = load_path::find_oct_file (name);
581  }
582 
583  return retval;
584 }
585 
586 // See if there is a .mex file in the path. If so, return the
587 // full path to the file.
588 
589 std::string
590 mex_file_in_path (const std::string& name)
591 {
592  std::string retval;
593 
594  int len = name.length ();
595 
596  if (len > 0)
597  {
599  {
600  file_stat fs (name);
601 
602  if (fs.exists ())
603  retval = name;
604  }
605  else if (len > 4 && name[len - 4] == '.' && name[len - 3] == 'm'
606  && name[len - 2] == 'e' && name[len - 1] == 'x')
607  retval = load_path::find_mex_file (name.substr (0, len-4));
608  else
609  retval = load_path::find_mex_file (name);
610  }
611 
612  return retval;
613 }
614 
615 // Replace backslash escapes in a string with the real values.
616 
617 std::string
618 do_string_escapes (const std::string& s)
619 {
620  std::string retval;
621 
622  size_t i = 0;
623  size_t j = 0;
624  size_t len = s.length ();
625 
626  retval.resize (len);
627 
628  while (j < len)
629  {
630  if (s[j] == '\\' && j+1 < len)
631  {
632  switch (s[++j])
633  {
634  case '0':
635  retval[i] = '\0';
636  break;
637 
638  case 'a':
639  retval[i] = '\a';
640  break;
641 
642  case 'b': // backspace
643  retval[i] = '\b';
644  break;
645 
646  case 'f': // formfeed
647  retval[i] = '\f';
648  break;
649 
650  case 'n': // newline
651  retval[i] = '\n';
652  break;
653 
654  case 'r': // carriage return
655  retval[i] = '\r';
656  break;
657 
658  case 't': // horizontal tab
659  retval[i] = '\t';
660  break;
661 
662  case 'v': // vertical tab
663  retval[i] = '\v';
664  break;
665 
666  case '\\': // backslash
667  retval[i] = '\\';
668  break;
669 
670  case '\'': // quote
671  retval[i] = '\'';
672  break;
673 
674  case '"': // double quote
675  retval[i] = '"';
676  break;
677 
678  default:
679  warning ("unrecognized escape sequence '\\%c' --\
680  converting to '%c'", s[j], s[j]);
681  retval[i] = s[j];
682  break;
683  }
684  }
685  else
686  {
687  retval[i] = s[j];
688  }
689 
690  i++;
691  j++;
692  }
693 
694  retval.resize (i);
695 
696  return retval;
697 }
698 
699 DEFUN (do_string_escapes, args, ,
700  "-*- texinfo -*-\n\
701 @deftypefn {Built-in Function} {} do_string_escapes (@var{string})\n\
702 Convert escape sequences in @var{string} to the characters they represent.\n\
703 \n\
704 Escape sequences begin with a leading backslash\n\
705 (@qcode{'@xbackslashchar{}'}) followed by 1--3 characters\n\
706 (.e.g., @qcode{\"@xbackslashchar{}n\"} => newline).\n\
707 @seealso{undo_string_escapes}\n\
708 @end deftypefn")
709 {
710  octave_value retval;
711 
712  int nargin = args.length ();
713 
714  if (nargin == 1)
715  {
716  if (args(0).is_string ())
717  retval = do_string_escapes (args(0).string_value ());
718  else
719  error ("do_string_escapes: STRING argument must be of type string");
720  }
721  else
722  print_usage ();
723 
724  return retval;
725 }
726 
727 /*
728 %!assert (do_string_escapes ('foo\nbar'), "foo\nbar")
729 %!assert (do_string_escapes ("foo\\nbar"), "foo\nbar")
730 %!assert (do_string_escapes ("foo\\nbar"), ["foo", char(10), "bar"])
731 %!assert ("foo\nbar", ["foo", char(10), "bar"])
732 
733 %!assert (do_string_escapes ('\0\a\b\f\n\r\t\v'), "\0\a\b\f\n\r\t\v")
734 %!assert (do_string_escapes ("\\0\\a\\b\\f\\n\\r\\t\\v"), "\0\a\b\f\n\r\t\v")
735 %!assert (do_string_escapes ("\\0\\a\\b\\f\\n\\r\\t\\v"),
736 %! char ([0, 7, 8, 12, 10, 13, 9, 11]))
737 %!assert ("\0\a\b\f\n\r\t\v", char ([0, 7, 8, 12, 10, 13, 9, 11]))
738 
739 %!assert (do_string_escapes ('\\'), "\\")
740 %!assert (do_string_escapes ("\\\\"), "\\")
741 %!assert (do_string_escapes ("\\\\"), char (92))
742 
743 %!assert (do_string_escapes ('\''single-quoted\'''), "'single-quoted'")
744 %!assert (do_string_escapes ("\\'single-quoted\\'"), "'single-quoted'")
745 %!assert (do_string_escapes ('\"double-quoted\"'), "\"double-quoted\"")
746 %!assert (do_string_escapes ("\\\"double-quoted\\\""), "\"double-quoted\"")
747 
748 %!error do_string_escapes ()
749 %!error do_string_escapes ("foo", "bar")
750 %!error do_string_escapes (3)
751 */
752 
753 const char *
755 {
756  if (! c)
757  return "";
758 
759  switch (c)
760  {
761  case '\0':
762  return "\\0";
763 
764  case '\a':
765  return "\\a";
766 
767  case '\b': // backspace
768  return "\\b";
769 
770  case '\f': // formfeed
771  return "\\f";
772 
773  case '\n': // newline
774  return "\\n";
775 
776  case '\r': // carriage return
777  return "\\r";
778 
779  case '\t': // horizontal tab
780  return "\\t";
781 
782  case '\v': // vertical tab
783  return "\\v";
784 
785  case '\\': // backslash
786  return "\\\\";
787 
788  case '"': // double quote
789  return "\\\"";
790 
791  default:
792  {
793  static char retval[2];
794  retval[0] = c;
795  retval[1] = '\0';
796  return retval;
797  }
798  }
799 }
800 
801 std::string
802 undo_string_escapes (const std::string& s)
803 {
804  std::string retval;
805 
806  for (size_t i = 0; i < s.length (); i++)
807  retval.append (undo_string_escape (s[i]));
808 
809  return retval;
810 }
811 
812 DEFUN (undo_string_escapes, args, ,
813  "-*- texinfo -*-\n\
814 @deftypefn {Built-in Function} {} undo_string_escapes (@var{s})\n\
815 Convert special characters in strings back to their escaped forms.\n\
816 \n\
817 For example, the expression\n\
818 \n\
819 @example\n\
820 bell = \"\\a\";\n\
821 @end example\n\
822 \n\
823 @noindent\n\
824 assigns the value of the alert character (control-g, ASCII code 7) to the\n\
825 string variable @code{bell}. If this string is printed, the system will\n\
826 ring the terminal bell (if it is possible). This is normally the desired\n\
827 outcome. However, sometimes it is useful to be able to print the original\n\
828 representation of the string, with the special characters replaced by their\n\
829 escape sequences. For example,\n\
830 \n\
831 @example\n\
832 @group\n\
833 octave:13> undo_string_escapes (bell)\n\
834 ans = \\a\n\
835 @end group\n\
836 @end example\n\
837 \n\
838 @noindent\n\
839 replaces the unprintable alert character with its printable representation.\n\
840 @seealso{do_string_escapes}\n\
841 @end deftypefn")
842 {
843  octave_value retval;
844 
845  int nargin = args.length ();
846 
847  if (nargin == 1)
848  {
849  if (args(0).is_string ())
850  retval = undo_string_escapes (args(0).string_value ());
851  else
852  error ("undo_string_escapes: S argument must be a string");
853  }
854  else
855  print_usage ();
856 
857  return retval;
858 }
859 
860 /*
861 %!assert (undo_string_escapes ("foo\nbar"), 'foo\nbar')
862 %!assert (undo_string_escapes ("foo\nbar"), "foo\\nbar")
863 %!assert (undo_string_escapes (["foo", char(10), "bar"]), "foo\\nbar")
864 
865 %!assert (undo_string_escapes ("\a\b\f\n\r\t\v"), '\a\b\f\n\r\t\v')
866 %!assert (undo_string_escapes ("\a\b\f\n\r\t\v"), "\\a\\b\\f\\n\\r\\t\\v")
867 %!assert (undo_string_escapes (char ([7, 8, 12, 10, 13, 9, 11])),
868 %! "\\a\\b\\f\\n\\r\\t\\v")
869 
870 %!assert (undo_string_escapes ("\\"), '\\')
871 %!assert (undo_string_escapes ("\\"), "\\\\")
872 %!assert (undo_string_escapes (char (92)), "\\\\")
873 
874 %!assert (undo_string_escapes ("\"double-quoted\""), '\"double-quoted\"')
875 %!assert (undo_string_escapes ("\"double-quoted\""), "\\\"double-quoted\\\"")
876 
877 %!error undo_string_escapes ()
878 %!error undo_string_escapes ("foo", "bar")
879 %!error undo_string_escapes (3)
880 */
881 
882 DEFUN (is_absolute_filename, args, ,
883  "-*- texinfo -*-\n\
884 @deftypefn {Built-in Function} {} is_absolute_filename (@var{file})\n\
885 Return true if @var{file} is an absolute filename.\n\
886 @seealso{is_rooted_relative_filename, make_absolute_filename, isdir}\n\
887 @end deftypefn")
888 {
889  octave_value retval = false;
890 
891  if (args.length () == 1)
892  retval = (args(0).is_string ()
893  && octave_env::absolute_pathname (args(0).string_value ()));
894  else
895  print_usage ();
896 
897  return retval;
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 
907 DEFUN (is_rooted_relative_filename, args, ,
908  "-*- texinfo -*-\n\
909 @deftypefn {Built-in Function} {} is_rooted_relative_filename (@var{file})\n\
910 Return true if @var{file} is a rooted-relative filename.\n\
911 @seealso{is_absolute_filename, make_absolute_filename, isdir}\n\
912 @end deftypefn")
913 {
914  octave_value retval = false;
915 
916  if (args.length () == 1)
917  retval = (args(0).is_string ()
918  && octave_env::rooted_relative_pathname (args(0).string_value ()));
919  else
920  print_usage ();
921 
922  return retval;
923 }
924 
925 /*
926 ## FIXME: We need system-dependent tests here.
927 
928 %!error is_rooted_relative_filename ()
929 %!error is_rooted_relative_filename ("foo", "bar")
930 */
931 
932 DEFUN (make_absolute_filename, args, ,
933  "-*- texinfo -*-\n\
934 @deftypefn {Built-in Function} {} make_absolute_filename (@var{file})\n\
935 Return the full name of @var{file} beginning from the root of the file\n\
936 system.\n\
937 \n\
938 No check is done for the existence of @var{file}.\n\
939 @seealso{canonicalize_file_name, is_absolute_filename, is_rooted_relative_filename, isdir}\n\
940 @end deftypefn")
941 {
942  octave_value retval = std::string ();
943 
944  if (args.length () == 1)
945  {
946  std::string nm = args(0).string_value ();
947 
948  if (! error_state)
949  retval = octave_env::make_absolute (nm);
950  else
951  error ("make_absolute_filename: FILE argument must be a file name");
952  }
953  else
954  print_usage ();
955 
956  return retval;
957 }
958 
959 /*
960 ## FIXME: We need system-dependent tests here.
961 
962 %!error make_absolute_filename ()
963 %!error make_absolute_filename ("foo", "bar")
964 */
965 
966 DEFUN (dir_in_loadpath, args, ,
967  "-*- texinfo -*-\n\
968 @deftypefn {Built-in Function} {} dir_in_loadpath (@var{dir})\n\
969 @deftypefnx {Built-in Function} {} dir_in_loadpath (@var{dir}, \"all\")\n\
970 Return the full name of the path element matching @var{dir}.\n\
971 \n\
972 The match is performed at the end of each path element. For example, if\n\
973 @var{dir} is @qcode{\"foo/bar\"}, it matches the path element\n\
974 @nospell{@qcode{\"/some/dir/foo/bar\"}}, but not\n\
975 @nospell{@qcode{\"/some/dir/foo/bar/baz\"}}\n\
976 @nospell{@qcode{\"/some/dir/allfoo/bar\"}}.\n\
977 \n\
978 If the optional second argument is supplied, return a cell array containing\n\
979 all name matches rather than just the first.\n\
980 @seealso{file_in_path, file_in_loadpath, path}\n\
981 @end deftypefn")
982 {
983  octave_value retval = std::string ();
984 
985  int nargin = args.length ();
986 
987  std::string dir;
988 
989  if (nargin == 1 || nargin == 2)
990  {
991  dir = args(0).string_value ();
992 
993  if (! error_state)
994  {
995  if (nargin == 1)
996  retval = load_path::find_dir (dir);
997  else if (nargin == 2)
998  retval = Cell (load_path::find_matching_dirs (dir));
999  }
1000  else
1001  error ("dir_in_loadpath: DIR must be a directory name");
1002  }
1003  else
1004  print_usage ();
1005 
1006  return retval;
1007 }
1008 
1009 /*
1010 %!test
1011 %! f = dir_in_loadpath ("plot");
1012 %! assert (ischar (f));
1013 %! assert (! isempty (f));
1014 
1015 %!test
1016 %! f = dir_in_loadpath ("$$probably_!!_not_&&_a_!!_dir$$");
1017 %! assert (f, "");
1018 
1019 %!test
1020 %! lst = dir_in_loadpath ("$$probably_!!_not_&&_a_!!_dir$$", "all");
1021 %! assert (lst, {});
1022 
1023 %!error dir_in_loadpath ()
1024 %!error dir_in_loadpath ("foo", "bar", 1)
1025 */
1026 
1027 DEFUNX ("errno", Ferrno, args, ,
1028  "-*- texinfo -*-\n\
1029 @deftypefn {Built-in Function} {@var{err} =} errno ()\n\
1030 @deftypefnx {Built-in Function} {@var{err} =} errno (@var{val})\n\
1031 @deftypefnx {Built-in Function} {@var{err} =} errno (@var{name})\n\
1032 Return the current value of the system-dependent variable errno,\n\
1033 set its value to @var{val} and return the previous value, or return\n\
1034 the named error code given @var{name} as a character string, or -1\n\
1035 if @var{name} is not found.\n\
1036 @seealso{errno_list}\n\
1037 @end deftypefn")
1038 {
1039  octave_value retval;
1040 
1041  int nargin = args.length ();
1042 
1043  if (nargin == 1)
1044  {
1045  if (args(0).is_string ())
1046  {
1047  std::string nm = args(0).string_value ();
1048 
1049  retval = octave_errno::lookup (nm);
1050  }
1051  else
1052  {
1053  int val = args(0).int_value ();
1054 
1055  if (! error_state)
1056  retval = octave_errno::set (val);
1057  else
1058  error ("errno: argument must be string or integer");
1059  }
1060  }
1061  else if (nargin == 0)
1062  retval = octave_errno::get ();
1063  else
1064  print_usage ();
1065 
1066  return retval;
1067 }
1068 
1069 /*
1070 %!assert (isnumeric (errno ()))
1071 
1072 %!test
1073 %! lst = errno_list ();
1074 %! fns = fieldnames (lst);
1075 %! oldval = errno (fns{1});
1076 %! assert (isnumeric (oldval));
1077 %! errno (oldval);
1078 %! newval = errno ();
1079 %! assert (oldval, newval);
1080 
1081 %!error errno ("foo", 1)
1082 */
1083 
1084 DEFUN (errno_list, args, ,
1085  "-*- texinfo -*-\n\
1086 @deftypefn {Built-in Function} {} errno_list ()\n\
1087 Return a structure containing the system-dependent errno values.\n\
1088 @seealso{errno}\n\
1089 @end deftypefn")
1090 {
1091  octave_value retval;
1092 
1093  if (args.length () == 0)
1094  retval = octave_errno::list ();
1095  else
1096  print_usage ();
1097 
1098  return retval;
1099 }
1100 
1101 /*
1102 %!assert (isstruct (errno_list ()))
1103 
1104 %!error errno_list ("foo")
1105 */
1106 
1107 static void
1108 check_dimensions (octave_idx_type& nr, octave_idx_type& nc, const char *warnfor)
1109 {
1110  if (nr < 0 || nc < 0)
1111  {
1112  warning_with_id ("Octave:neg-dim-as-zero",
1113  "%s: converting negative dimension to zero", warnfor);
1114 
1115  nr = (nr < 0) ? 0 : nr;
1116  nc = (nc < 0) ? 0 : nc;
1117  }
1118 }
1119 
1120 void
1121 check_dimensions (dim_vector& dim, const char *warnfor)
1122 {
1123  bool neg = false;
1124 
1125  for (int i = 0; i < dim.length (); i++)
1126  {
1127  if (dim(i) < 0)
1128  {
1129  dim(i) = 0;
1130  neg = true;
1131  }
1132  }
1133 
1134  if (neg)
1135  warning_with_id ("Octave:neg-dim-as-zero",
1136  "%s: converting negative dimension to zero", warnfor);
1137 }
1138 
1139 
1140 void
1141 get_dimensions (const octave_value& a, const char *warn_for,
1142  dim_vector& dim)
1143 {
1144  if (a.is_scalar_type ())
1145  {
1146  dim.resize (2);
1147  dim(0) = a.int_value ();
1148  dim(1) = dim(0);
1149  }
1150  else
1151  {
1152  octave_idx_type nr = a.rows ();
1153  octave_idx_type nc = a.columns ();
1154 
1155  if (nr == 1 || nc == 1)
1156  {
1157  Array<double> v = a.vector_value ();
1158 
1159  if (error_state)
1160  return;
1161 
1162  octave_idx_type n = v.length ();
1163  dim.resize (n);
1164  for (octave_idx_type i = 0; i < n; i++)
1165  dim(i) = static_cast<int> (fix (v(i)));
1166  }
1167  else
1168  error ("%s (A): use %s (size (A)) instead", warn_for, warn_for);
1169  }
1170 
1171  if (! error_state)
1172  check_dimensions (dim, warn_for); // May set error_state.
1173 }
1174 
1175 
1176 void
1177 get_dimensions (const octave_value& a, const char *warn_for,
1179 {
1180  if (a.is_scalar_type ())
1181  {
1182  nr = nc = a.int_value ();
1183  }
1184  else
1185  {
1186  nr = a.rows ();
1187  nc = a.columns ();
1188 
1189  if ((nr == 1 && nc == 2) || (nr == 2 && nc == 1))
1190  {
1191  Array<double> v = a.vector_value ();
1192 
1193  if (error_state)
1194  return;
1195 
1196  nr = static_cast<octave_idx_type> (fix (v (0)));
1197  nc = static_cast<octave_idx_type> (fix (v (1)));
1198  }
1199  else
1200  error ("%s (A): use %s (size (A)) instead", warn_for, warn_for);
1201  }
1202 
1203  if (! error_state)
1204  check_dimensions (nr, nc, warn_for); // May set error_state.
1205 }
1206 
1207 void
1209  const char *warn_for, octave_idx_type& nr, octave_idx_type& nc)
1210 {
1211  nr = a.is_empty () ? 0 : a.int_value ();
1212  nc = b.is_empty () ? 0 : b.int_value ();
1213 
1214  if (error_state)
1215  error ("%s: expecting two scalar arguments", warn_for);
1216  else
1217  check_dimensions (nr, nc, warn_for); // May set error_state.
1218 }
1219 
1221 dims_to_numel (const dim_vector& dims, const octave_value_list& idx)
1222 {
1223  octave_idx_type retval;
1224 
1225  octave_idx_type len = idx.length ();
1226 
1227  if (len == 0)
1228  retval = dims.numel ();
1229  else
1230  {
1231  const dim_vector dv = dims.redim (len);
1232  retval = 1;
1233  for (octave_idx_type i = 0; i < len; i++)
1234  {
1235  octave_value idxi = idx(i);
1236  if (idxi.is_magic_colon ())
1237  retval *= dv(i);
1238  else if (idxi.is_numeric_type ())
1239  retval *= idxi.numel ();
1240  else
1241  {
1242  idx_vector jdx = idxi.index_vector ();
1243  if (error_state)
1244  break;
1245  retval *= jdx.length (dv(i));
1246  }
1247  }
1248  }
1249 
1250  return retval;
1251 }
1252 
1253 Matrix
1255 {
1256  Matrix m (nr, nc, 0.0);
1257 
1258  if (nr > 0 && nc > 0)
1259  {
1260  octave_idx_type n = std::min (nr, nc);
1261 
1262  for (octave_idx_type i = 0; i < n; i++)
1263  m (i, i) = 1.0;
1264  }
1265 
1266  return m;
1267 }
1268 
1271 {
1272  FloatMatrix m (nr, nc, 0.0);
1273 
1274  if (nr > 0 && nc > 0)
1275  {
1276  octave_idx_type n = std::min (nr, nc);
1277 
1278  for (octave_idx_type i = 0; i < n; i++)
1279  m (i, i) = 1.0;
1280  }
1281 
1282  return m;
1283 }
1284 
1285 size_t
1286 octave_format (std::ostream& os, const char *fmt, ...)
1287 {
1288  size_t retval;
1289 
1290  va_list args;
1291  va_start (args, fmt);
1292 
1293  retval = octave_vformat (os, fmt, args);
1294 
1295  va_end (args);
1296 
1297  return retval;
1298 }
1299 
1300 size_t
1301 octave_vformat (std::ostream& os, const char *fmt, va_list args)
1302 {
1303  std::string s = octave_vasprintf (fmt, args);
1304 
1305  os << s;
1306 
1307  return s.length ();
1308 }
1309 
1310 std::string
1311 octave_vasprintf (const char *fmt, va_list args)
1312 {
1313  std::string retval;
1314 
1315  char *result;
1316 
1317  int status = gnulib::vasprintf (&result, fmt, args);
1318 
1319  if (status >= 0)
1320  {
1321  retval = result;
1322  ::free (result);
1323  }
1324 
1325  return retval;
1326 }
1327 
1328 std::string
1329 octave_asprintf (const char *fmt, ...)
1330 {
1331  std::string retval;
1332 
1333  va_list args;
1334  va_start (args, fmt);
1335 
1336  retval = octave_vasprintf (fmt, args);
1337 
1338  va_end (args);
1339 
1340  return retval;
1341 }
1342 
1343 void
1344 octave_sleep (double seconds)
1345 {
1346  if (seconds > 0)
1347  {
1348  double t;
1349 
1350  unsigned int usec
1351  = static_cast<unsigned int> (modf (seconds, &t) * 1000000);
1352 
1353  unsigned int sec
1356  : static_cast<unsigned int> (t));
1357 
1358  // Versions of these functions that accept unsigned int args are
1359  // defined in cutils.c.
1360  octave_sleep (sec);
1361  octave_usleep (usec);
1362 
1363  octave_quit ();
1364  }
1365 }
1366 
1367 DEFUN (isindex, args, ,
1368  "-*- texinfo -*-\n\
1369 @deftypefn {Built-in Function} {} isindex (@var{ind})\n\
1370 @deftypefnx {Built-in Function} {} isindex (@var{ind}, @var{n})\n\
1371 Return true if @var{ind} is a valid index.\n\
1372 \n\
1373 Valid indices are either positive integers (although possibly of real data\n\
1374 type), or logical arrays.\n\
1375 \n\
1376 If present, @var{n} specifies the maximum extent of the dimension to be\n\
1377 indexed. When possible the internal result is cached so that subsequent\n\
1378 indexing using @var{ind} will not perform the check again.\n\
1379 \n\
1380 Implementation Note: Strings are first converted to double values before the\n\
1381 checks for valid indices are made. Unless a string contains the NULL\n\
1382 character @nospell{\"\\0\"}, it will always be a valid index.\n\
1383 @end deftypefn")
1384 {
1385  octave_value retval;
1386  int nargin = args.length ();
1387  octave_idx_type n = 0;
1388 
1389  if (nargin == 2)
1390  n = args(1).idx_type_value ();
1391  else if (nargin != 1)
1392  print_usage ();
1393 
1394  if (! error_state)
1395  {
1396  unwind_protect frame;
1397 
1398  frame.protect_var (error_state);
1399 
1401  discard_error_messages = true;
1402 
1403  try
1404  {
1405  idx_vector idx = args(0).index_vector (true);
1406 
1407  if (! error_state)
1408  {
1409  if (nargin == 2)
1410  retval = idx.extent (n) <= n;
1411  else
1412  retval = true;
1413  }
1414  else
1415  retval = false;
1416  }
1417  catch (octave_execution_exception)
1418  {
1419  retval = false;
1420  }
1421  }
1422 
1423  return retval;
1424 }
1425 
1426 /*
1427 %!assert (isindex ([1, 2, 3]))
1428 %!assert (isindex (1:3))
1429 %!assert (isindex (1:3, 2), false)
1430 %!assert (isindex ([1, 2, -3]), false)
1431 
1432 %!error isindex ()
1433 %!error isindex (1:3, 2, 3)
1434 */
1435 
1438  const char *fun_name, const octave_value_list& args,
1439  int nargout)
1440 {
1441  octave_value_list new_args = args, retval;
1442  int nargin = args.length ();
1443  OCTAVE_LOCAL_BUFFER (bool, iscell, nargin);
1444  OCTAVE_LOCAL_BUFFER (Cell, cells, nargin);
1445  OCTAVE_LOCAL_BUFFER (Cell, rcells, nargout);
1446 
1447  const Cell *ccells = cells;
1448 
1449  octave_idx_type numel = 1;
1450  dim_vector dims (1, 1);
1451 
1452  for (int i = 0; i < nargin; i++)
1453  {
1454  octave_value arg = new_args(i);
1455  iscell[i] = arg.is_cell ();
1456  if (iscell[i])
1457  {
1458  cells[i] = arg.cell_value ();
1459  octave_idx_type n = ccells[i].numel ();
1460  if (n == 1)
1461  {
1462  iscell[i] = false;
1463  new_args(i) = ccells[i](0);
1464  }
1465  else if (numel == 1)
1466  {
1467  numel = n;
1468  dims = ccells[i].dims ();
1469  }
1470  else if (dims != ccells[i].dims ())
1471  {
1472  error ("%s: cell arguments must have matching sizes", fun_name);
1473  break;
1474  }
1475  }
1476  }
1477 
1478  if (! error_state)
1479  {
1480  for (int i = 0; i < nargout; i++)
1481  rcells[i].clear (dims);
1482 
1483  for (octave_idx_type j = 0; j < numel; j++)
1484  {
1485  for (int i = 0; i < nargin; i++)
1486  if (iscell[i])
1487  new_args(i) = ccells[i](j);
1488 
1489  octave_quit ();
1490 
1491  const octave_value_list tmp = fun (new_args, nargout);
1492 
1493  if (tmp.length () < nargout)
1494  {
1495  error ("%s: do_simple_cellfun: internal error", fun_name);
1496  break;
1497  }
1498  else
1499  {
1500  for (int i = 0; i < nargout; i++)
1501  rcells[i](j) = tmp(i);
1502  }
1503  }
1504  }
1505 
1506  if (! error_state)
1507  {
1508  retval.resize (nargout);
1509  for (int i = 0; i < nargout; i++)
1510  retval(i) = rcells[i];
1511  }
1512 
1513  return retval;
1514 }
1515 
1518  const char *fun_name, const octave_value_list& args)
1519 {
1520  octave_value retval;
1521  const octave_value_list tmp = do_simple_cellfun (fun, fun_name, args, 1);
1522  if (tmp.length () > 0)
1523  retval = tmp(0);
1524 
1525  return retval;
1526 }
1527 
1529 {
1530  stream.flags (oflags);
1531  stream.precision (oprecision);
1532  stream.width (owidth);
1533  stream.fill (ofill);
1534 }
1535 
1536 DEFUN (isstudent, args, ,
1537  "-*- texinfo -*-\n\
1538 @deftypefn {Built-in Function} {} isstudent ()\n\
1539 Return true if running in the student edition of @sc{matlab}.\n\
1540 \n\
1541 @code{isstudent} always returns false in Octave.\n\
1542 @seealso{false}\n\
1543 @end deftypefn")
1544 {
1545  if (args.length () != 0)
1546  print_usage ();
1547 
1548  return octave_value (false);
1549 }
1550 
1551 /*
1552 %!assert (isstudent (), false)
1553 
1554 %!error isstudent (1)
1555 */
bool is_reg(void) const
Definition: file-stat.cc:74
void warning_with_id(const char *id, const char *fmt,...)
Definition: error.cc:696
size_t octave_vformat(std::ostream &os, const char *fmt, va_list args)
Definition: utils.cc:1301
void get_dimensions(const octave_value &a, const char *warn_for, dim_vector &dim)
Definition: utils.cc:1141
static void clear(octave_shlib &oct_file)
Definition: dynamic-ld.cc:236
std::string find_data_file_in_load_path(const std::string &fcn, const std::string &file, bool require_regular_file)
Definition: utils.cc:463
std::string find_first_of(const string_vector &names)
Definition: pathsearch.cc:132
Definition: Cell.h:35
octave_idx_type length(octave_idx_type n=0) const
Definition: idx-vector.h:551
static string_vector find_matching_dirs(const std::string &dir)
Definition: load-path.h:209
std::string octave_asprintf(const char *fmt,...)
Definition: utils.cc:1329
bool same_file(const std::string &f, const std::string &g)
Definition: utils.cc:133
octave_idx_type rows(void) const
Definition: ov.h:473
std::string mex_file_in_path(const std::string &name)
Definition: utils.cc:590
std::streamsize oprecision
Definition: utils.h:151
OCTINTERP_API void print_usage(void)
Definition: defun.cc:51
octave_idx_type numel(void) const
Number of elements in the array.
Definition: Array.h:275
octave_idx_type length(void) const
Definition: oct-obj.h:89
bool is_scalar_type(void) const
Definition: ov.h:657
bool is_numeric_type(void) const
Definition: ov.h:663
static char * strsave(const char *s)
Definition: main.cc:414
static std::string find_file(const std::string &file)
Definition: load-path.h:197
int int_value(bool req_int=false, bool frc_str_conv=false) const
Definition: ov.h:730
static string_vector make_absolute(const string_vector &sv)
Definition: utils.cc:279
void resize(int n, int fill_value=0)
Definition: dim-vector.h:287
static std::string find_first_of(const string_vector &files)
Definition: load-path.h:215
void protect_var(T &var)
#define DEFUN(name, args_name, nargout_name, doc)
Definition: defun.h:44
void error(const char *fmt,...)
Definition: error.cc:476
void octave_sleep(double seconds)
Definition: utils.cc:1344
STL namespace.
static string_vector names(const map_type &lst)
Definition: help.cc:782
int empty_arg(const char *, octave_idx_type nr, octave_idx_type nc)
Definition: utils.cc:246
bool is_cell(void) const
Definition: ov.h:529
static std::string find_mex_file(const std::string &fcn, const std::string &pack_name=std::string())
Definition: load-path.h:187
std::string file_in_path(const std::string &name, const std::string &suffix)
Definition: utils.cc:452
std::string fcn_file_in_path(const std::string &name)
Definition: utils.cc:504
bool is_keyword(const std::string &s)
Definition: lex.cc:4522
OCTAVE_API int octave_strncasecmp(const char *s1, const char *s2, size_t n)
Definition: lo-cutils.c:60
static void check_dimensions(octave_idx_type &nr, octave_idx_type &nc, const char *warnfor)
Definition: utils.cc:1108
octave_idx_type numel(int n=0) const
Number of elements that a matrix with this dimensions would have.
Definition: dim-vector.h:361
Matrix identity_matrix(octave_idx_type nr, octave_idx_type nc)
Definition: utils.cc:1254
size_t octave_format(std::ostream &os, const char *fmt,...)
Definition: utils.cc:1286
std::string contents_file_in_path(const std::string &dir)
Definition: utils.cc:539
static std::string find_oct_file(const std::string &fcn, const std::string &pack_name=std::string())
Definition: load-path.h:177
Cell cell_value(void) const
Definition: ov.cc:1566
idx_vector index_vector(bool require_integers=false) const
Definition: ov.h:463
void gripe_data_file_in_path(const std::string &fcn, const std::string &file)
Definition: gripes.cc:250
std::string octave_vasprintf(const char *fmt, va_list args)
Definition: utils.cc:1311
int almost_match(const std::string &std, const std::string &s, int min_match_len, int case_sens)
Definition: utils.cc:139
const dim_vector & dims(void) const
Return a const-reference so that dims ()(i) works efficiently.
Definition: Array.h:337
static std::string concat(const std::string &, const std::string &)
Definition: file-ops.cc:360
octave_idx_type columns(void) const
Definition: ov.h:475
F77_RET_T const double const double * f
bool valid_identifier(const char *s)
Definition: utils.cc:77
octave_idx_type numel(const octave_value_list &idx)
Definition: ov.h:395
bool same_file_internal(const std::string &file1, const std::string &file2)
Definition: sysdep.cc:246
bool exists(void) const
Definition: file-stat.h:134
static std::string make_absolute(const std::string &s, const std::string &dot_path=get_current_directory())
Definition: oct-env.cc:132
int error_state
Definition: error.cc:101
const char * undo_string_escape(char c)
Definition: utils.cc:754
#define DEFUNX(name, fname, args_name, nargout_name, doc)
Definition: defun.h:52
bool is_magic_colon(void) const
Definition: ov.h:589
static int get(void)
Definition: oct-errno.h:52
dim_vector redim(int n) const
Definition: dim-vector.cc:266
octave_idx_type length(void) const
Definition: ov.cc:1525
static bool absolute_pathname(const std::string &s)
Definition: oct-env.cc:111
Definition: dMatrix.h:35
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:155
static bool rooted_relative_pathname(const std::string &s)
Definition: oct-env.cc:118
std::string oct_file_in_path(const std::string &name)
Definition: utils.cc:561
double arg(double x)
Definition: lo-mappers.h:37
std::ios::fmtflags oflags
Definition: utils.h:150
std::string search_path_for_file(const std::string &path, const string_vector &names)
Definition: utils.cc:254
static std::string find_fcn_file(const std::string &fcn, const std::string &pack_name=std::string())
Definition: load-path.h:167
void warning(const char *fmt,...)
Definition: error.cc:681
Handles the reference counting for all the derived classes.
Definition: Array.h:45
charNDArray max(char d, const charNDArray &m)
Definition: chNDArray.cc:233
octave_idx_type length(void) const
Number of elements in the array.
Definition: Array.h:267
string_vector find_all_first_of(const string_vector &names)
Definition: pathsearch.cc:139
bool is_empty(void) const
Definition: ov.h:526
octave_idx_type extent(octave_idx_type n) const
Definition: idx-vector.h:554
std::string undo_string_escapes(const std::string &s)
Definition: utils.cc:802
char Vfilemarker
Definition: input.cc:127
void free(void *)
octave_idx_type dims_to_numel(const dim_vector &dims, const octave_value_list &idx)
Definition: utils.cc:1221
static int lookup(const std::string &name)
Definition: oct-errno.cc:717
Array< double > vector_value(bool frc_str_conv=false, bool frc_vec_conv=false) const
Definition: ov.cc:1690
bool is_dir(void) const
Definition: file-stat.cc:56
FloatMatrix float_identity_matrix(octave_idx_type nr, octave_idx_type nc)
Definition: utils.cc:1270
std::string do_string_escapes(const std::string &s)
Definition: utils.cc:618
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)
Definition: utils.cc:1437
#define OCTAVE_LOCAL_BUFFER(T, buf, size)
Definition: oct-locbuf.h:197
double fix(double x)
Definition: lo-mappers.h:39
static std::string find_dir(const std::string &dir)
Definition: load-path.h:203
static octave_scalar_map list(void)
Definition: oct-errno.cc:723
string_vector search_path_for_all_files(const std::string &path, const string_vector &names)
Definition: utils.cc:264
void octave_usleep(unsigned int useconds)
Definition: cutils.c:42
bool discard_error_messages
Definition: error.cc:118
static int set(int val)
Definition: oct-errno.h:54
int length(void) const
Definition: dim-vector.h:281
OCTAVE_EXPORT octave_value_list Ferrno(const octave_value_list &args, int)
Definition: utils.cc:1037
static string_vector find_all_first_of(const string_vector &files)
Definition: load-path.h:221
return octave_value(v1.char_array_value().concat(v2.char_array_value(), ra_idx),((a1.is_sq_string()||a2.is_sq_string())? '\'': '"'))
charNDArray min(char d, const charNDArray &m)
Definition: chNDArray.cc:210