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) {
13 an essential function!
17 print(vsprintf(arguments));
21 helper function to setup a rpc io object, ready for input
26 o.input = new Object();
31 check that a status result is OK
33 function check_status_ok(status)
35 if (status.is_ok != true) {
38 assert(status.is_ok == true);
42 check that two arrays are equal
44 function check_array_equal(a1, a2)
46 assert(a1.length == a2.length);
47 for (i=0; i<a1.length; i++) {
48 assert(a1[i] == a2[i]);
53 check that an array is all zeros
55 function check_array_zero(a)
57 for (i=0; i<a.length; i++) {
63 substitute strings of the form ${NAME} in str, replacing
64 with substitutions from subobj
66 function substitute_var(str, subobj)
68 var list = split("${", str);
70 for (i=1;i<list.length;i++) {
71 var list2 = split("}", list[i]);
72 if (list2.length < 2) {
77 if (typeof(subobj[key]) == "undefined") {
78 val = "${" + key + "}";
79 } else if (typeof(subobj[key]) == "string") {
86 list[i] = join("", list2);
88 return join("", list);
92 return "s" if a number should be shown as plural