comparison src/variables.cc @ 4962:0ab18cbe8b5f

[project @ 2004-09-02 16:56:17 by jwe]
author jwe
date Thu, 02 Sep 2004 16:56:17 +0000
parents ed0f3cb6d3d4
children 352d228d409b
comparison
equal deleted inserted replaced
4961:2acb248a653f 4962:0ab18cbe8b5f
660 } 660 }
661 661
662 return retval; 662 return retval;
663 } 663 }
664 664
665 #define GET_IDX(LEN) \
666 static_cast<int> ((LEN-1) * static_cast<double> (rand ()) / RAND_MAX)
667
665 std::string 668 std::string
666 unique_symbol_name (const std::string& basename) 669 unique_symbol_name (const std::string& basename)
667 { 670 {
668 // XXX FIXME XXX Can we be smarter than just adding characters? 671 static const std::string alpha
669 std::string name = basename; 672 = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
670 while (symbol_exist (name, "any")) 673
671 name.append ("X"); 674 static size_t len = alpha.length ();
672 return name; 675
676 std::string nm = basename + alpha[GET_IDX (len)];
677
678 size_t pos = nm.length ();
679
680 if (nm.substr (0, 2) == "__")
681 nm.append ("__");
682
683 while (symbol_exist (nm, "any"))
684 nm.insert (pos++, 1, alpha[GET_IDX (len)]);
685
686 return nm;
673 } 687 }
674 688
675 DEFUN (exist, args, , 689 DEFUN (exist, args, ,
676 "-*- texinfo -*-\n\ 690 "-*- texinfo -*-\n\
677 @deftypefn {Built-in Function} {} exist (@var{name}, @var{type})\n\ 691 @deftypefn {Built-in Function} {} exist (@var{name}, @var{type})\n\