svn commit: samba r8355 - in branches/SAMBA_4_0: source/scripting/ejs source/scripting/libjs source/setup testprogs/ejs

tridge at samba.org tridge at samba.org
Tue Jul 12 06:57:26 GMT 2005


Author: tridge
Date: 2005-07-12 06:57:25 +0000 (Tue, 12 Jul 2005)
New Revision: 8355

WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=8355

Log:
- added a vsprintf() function

- removed the --outputdir option from provision, as its not used any
  more (as ejs knows the real paths)









Modified:
   branches/SAMBA_4_0/source/scripting/ejs/smbcalls_string.c
   branches/SAMBA_4_0/source/scripting/libjs/base.js
   branches/SAMBA_4_0/source/setup/provision
   branches/SAMBA_4_0/testprogs/ejs/bugs.js
   branches/SAMBA_4_0/testprogs/ejs/sprintf.js


Changeset:
Modified: branches/SAMBA_4_0/source/scripting/ejs/smbcalls_string.c
===================================================================
--- branches/SAMBA_4_0/source/scripting/ejs/smbcalls_string.c	2005-07-12 06:39:36 UTC (rev 8354)
+++ branches/SAMBA_4_0/source/scripting/ejs/smbcalls_string.c	2005-07-12 06:57:25 UTC (rev 8355)
@@ -272,6 +272,41 @@
 }
 
 /*
+  used to build your own print function
+     str = vsprintf(args);
+*/
+static int ejs_vsprintf(MprVarHandle eid, int argc, struct MprVar **argv)
+{
+	struct MprVar **args, *len, *v;
+	int i, ret, length;
+	if (argc != 1 || argv[0]->type != MPR_TYPE_OBJECT) {
+		ejsSetErrorMsg(eid, "vsprintf invalid arguments");
+		return -1;
+	}
+	v = argv[0];
+	len = mprGetProperty(v, "length", NULL);
+	if (len == NULL) {
+		ejsSetErrorMsg(eid, "vsprintf takes an array");
+		return -1;
+	}
+	length = mprToInt(len);
+	args = talloc_array(mprMemCtx(), struct MprVar *, length);
+	if (args == NULL) {
+		return -1;
+	}
+
+	for (i=0;i<length;i++) {
+		char idx[16];
+		mprItoa(i, idx, sizeof(idx));
+		args[i] = mprGetProperty(v, idx, NULL);
+	}
+	
+	ret = ejs_sprintf(eid, length, args);
+	talloc_free(args);
+	return ret;
+}
+
+/*
   setup C functions that be called from ejs
 */
 void smb_setup_ejs_string(void)
@@ -281,4 +316,5 @@
 	ejsDefineStringCFunction(-1, "split", ejs_split, NULL, MPR_VAR_SCRIPT_HANDLE);
 	ejsDefineCFunction(-1, "join", ejs_join, NULL, MPR_VAR_SCRIPT_HANDLE);
 	ejsDefineCFunction(-1, "sprintf", ejs_sprintf, NULL, MPR_VAR_SCRIPT_HANDLE);
+	ejsDefineCFunction(-1, "vsprintf", ejs_vsprintf, NULL, MPR_VAR_SCRIPT_HANDLE);
 }

Modified: branches/SAMBA_4_0/source/scripting/libjs/base.js
===================================================================
--- branches/SAMBA_4_0/source/scripting/libjs/base.js	2005-07-12 06:39:36 UTC (rev 8354)
+++ branches/SAMBA_4_0/source/scripting/libjs/base.js	2005-07-12 06:57:25 UTC (rev 8355)
@@ -10,6 +10,14 @@
 HAVE_BASE_JS=1
 
 /*
+  an essential function!
+*/
+function printf()
+{
+	print(vsprintf(arguments));
+}
+
+/*
   helper function to setup a rpc io object, ready for input
 */
 function irpcObj()

Modified: branches/SAMBA_4_0/source/setup/provision
===================================================================
--- branches/SAMBA_4_0/source/setup/provision	2005-07-12 06:39:36 UTC (rev 8354)
+++ branches/SAMBA_4_0/source/setup/provision	2005-07-12 06:57:25 UTC (rev 8355)
@@ -26,7 +26,6 @@
 		'nogroup=s',
 		'wheel=s',
 		'users=s',
-		'outputdir=s',
 		'quiet');
 if (ok == false) {
    println("Failed to parse options: " + options.ERROR);
@@ -200,7 +199,6 @@
  --host-ip	IPADDRESS	set ipaddress
  --host-guid	GUID		set hostguid (otherwise random)
  --invocationid	GUID		set invocationid (otherwise random)
- --outputdir	OUTPUTDIR	set output directory
  --adminpass	PASSWORD	choose admin password (otherwise random)
  --krbtgtpass	PASSWORD	choose krbtgt password (otherwise random)
  --machinepass	PASSWORD	choose machine password (otherwise random)

Modified: branches/SAMBA_4_0/testprogs/ejs/bugs.js
===================================================================
--- branches/SAMBA_4_0/testprogs/ejs/bugs.js	2005-07-12 06:39:36 UTC (rev 8354)
+++ branches/SAMBA_4_0/testprogs/ejs/bugs.js	2005-07-12 06:57:25 UTC (rev 8355)
@@ -8,6 +8,7 @@
 /****************************************
 demo a bug in constructing arrays
 fix at http://build.samba.org/build.pl?function=diff;tree=samba4;revision=7124
+status: FIXED
 *****************************************/
 function arraybug() {
 	 var a;
@@ -38,6 +39,7 @@
 /****************************************
 demo a bug in variable arguments
 fix at http://build.samba.org/build.pl?function=diff;tree=samba4;revision=7085
+status: FIXED
 *****************************************/
 function argsbug() {
 	 println("we should have been called with 3 arguments");
@@ -51,6 +53,7 @@
 /****************************************
 demo a bug in constructing objects
 no fix available yet
+status: SUBMITTED
 *****************************************/
 function MyObj() {
 	 var o = new Object();
@@ -68,10 +71,23 @@
 	 assert(o2.test == 42);
 }
 
+/*
+ demo a expression handling bug
+ status: SUBMITTED
+*/
+function exprbug() {
+	var a = new Array(10);
+	var i;
+	for (i=0;i<4;i++) {
+		a[1+(i*2)] = i;
+		a[2+(i*2)] = i*2;
+	}
+}
 
 /****************************************
 demo lack of recursion
 fix in http://build.samba.org/build.pl?function=diff;tree=samba4;revision=7127
+status: FIXED
 *****************************************/
 function fibonacci(n) {
 	if (n < 3) {
@@ -87,9 +103,25 @@
 	 }
 }
 
+/****************************************
+demo lack of function variables inside functions
+status: FIXED IN SAMBA
+*****************************************/
+function callback()
+{
+	return "testing";
+}
 
+function fnbug(c)
+{
+	s = c();
+	assert(s == "testing");
+}
+
 /* run the tests */
 arraybug();
 argsbug("one", "two", "three");
 recursebug();
-objbug()
+exprbug();
+fnbug(callback);
+objbug();

Modified: branches/SAMBA_4_0/testprogs/ejs/sprintf.js
===================================================================
--- branches/SAMBA_4_0/testprogs/ejs/sprintf.js	2005-07-12 06:39:36 UTC (rev 8354)
+++ branches/SAMBA_4_0/testprogs/ejs/sprintf.js	2005-07-12 06:57:25 UTC (rev 8355)
@@ -11,6 +11,11 @@
 	assert(s == v);
 }
 
+function xprintf()
+{
+	return "XX{" + vsprintf(arguments) + "}XX";
+}
+
 check_result(sprintf("%d", 7), "7");
 check_result(sprintf("%04d", 42), "0042");
 check_result(sprintf("my string=%7.2s", "foo%7"), "my string=     fo");
@@ -19,4 +24,6 @@
 check_result(sprintf("blah=%.0f", 1032), "blah=1032");
 check_result(sprintf("%4.2f%%", 72.32), "72.32%");
 
+check_result(xprintf("%4.2f%% and %s", 72.32, "foo"),"XX{72.32% and foo}XX");
+
 println("ALL OK");



More information about the samba-cvs mailing list