2 base js library functions
3 Copyright Andrew Tridgell 2005
4 released under the GNU GPL v2 or later
7 if (global["HAVE_BASE_JS"] != undefined) {
12 /* bring the string functions into the global frame */
16 an essential function!
20 print(vsprintf(arguments));
24 helper function to setup a rpc io object, ready for input
29 o.input = new Object();
34 check that a status result is OK
36 function check_status_ok(status)
38 if (status.is_ok != true) {
41 assert(status.is_ok == true);
45 check that two arrays are equal
47 function check_array_equal(a1, a2)
49 assert(a1.length == a2.length);
50 for (i=0; i<a1.length; i++) {
51 assert(a1[i] == a2[i]);
56 check that an array is all zeros
58 function check_array_zero(a)
60 for (i=0; i<a.length; i++) {
66 substitute strings of the form ${NAME} in str, replacing
67 with substitutions from subobj
69 function substitute_var(str, subobj)
71 var list = split("${", str);
73 for (i=1;i<list.length;i++) {
74 var list2 = split("}", list[i], 1);
75 if ((list2.length < 2) && (list2[0] + "}" != list[i])) {
80 if (typeof(subobj[key]) == "undefined") {
81 val = "${" + key + "}";
82 } else if (typeof(subobj[key]) == "string") {
89 list[i] = join("", list2);
91 return join("", list);
95 return "s" if a number should be shown as plural