supplierdeeply

Disabling script parameter list sorting (patch included)

  • 5 Replies
  • 2899 Views
*

Offline fudgey

  • *****
  • 1705
  • a570is
Disabling script parameter list sorting (patch included)
« on: 06 / July / 2008, 14:14:16 »
Advertisements
When a script grows a bit in size and has more than a few parameters, it becomes essential for usability that those parameters are listed in an ergonomic order on the script settings menu.

CHDK always lists @param a first, then b and z last on the script menu. Moving parameters up and down the list in a finished script to give it a finishing touch (or when using it as basis for a new script) is tedious as it requires manual search & replace of all involved single character variables. This is a near-certain way for introducing a bug or two.

So, I went ahead and patched CHDK a bit so that the script settings menu shows parameters in the order they are listed in the script instead of sorting them in alphabetical order. So, if a user wants to move his favorite parameters to the top, all that needs to be done is to move the @param lines around a bit.

Obviously this affects current scripts, but I don't consider this a break of backwards compatibility since the scripts and parameters work exactly as they did before, they just appear in a different order on the menu AND ONLY IF the script author didn't list them in alphabetical order for one reason or another. Actually my MDFB is one of the affected scripts...when I first wrote it I thought the parameters would move around on the list at will but I later noticed they didn't and just gave up.

These diffs are against allbest trunk-436. I haven't taken a look at the juciphox tree to see if this affects Lua, which I believe doesn't suffer from the single letter variable disease of uBasic.

Modified files and functions are:

core/script.c: script_scan(), process_param()
include/script.h
core/gui.c: gui_update_script_submenu()


Code: [Select]
--- core/script.c-trunk436      2008-07-06 20:41:08.000000000 +0300
+++ core/script.c       2008-07-06 21:00:16.000000000 +0300
@@ -72,6 +72,7 @@
 
 char script_title[36];
 char script_params[SCRIPT_NUM_PARAMS][28];
+int script_param_order[SCRIPT_NUM_PARAMS];
 char script_console_buf[SCRIPT_CONSOLE_NUM_LINES][SCRIPT_CONSOLE_LINE_LENGTH+1];
 static int script_console_lines=0;
 //-------------------------------------------------------------------
@@ -88,7 +89,7 @@
 }
 
 //-------------------------------------------------------------------
-static void process_param(const char *param) {
+static int process_param(const char *param) {
     register const char *ptr = param;
     register int n, i=0;
 
@@ -102,7 +103,9 @@
             ++i;
         }
         script_params[n][i]=0;
-    } // ??? else produce error message
+        n++;
+    } else n=0; // ??? else produce error message   
+    return n; // n=1 if '@param a' was processed, n=2 for 'b' ... n=26 for 'z'. n=0 if failed.
 }
 
 //-------------------------------------------------------------------
@@ -121,7 +124,7 @@
 //-------------------------------------------------------------------
 static void script_scan(const char *fn, int update_vars) {
     register const char *ptr = state_ubasic_script;
-    register int i;
+    register int i,j=0,n;
     char *c;
 
     c=strrchr(fn, '/');
@@ -129,6 +132,7 @@
     script_title[sizeof(script_title)-1]=0;
     for (i=0; i<SCRIPT_NUM_PARAMS; ++i) {
         script_params[i][0]=0;
+        script_param_order[i]=0;
     }
 
     while (ptr[0]) {
@@ -139,7 +143,11 @@
                 process_title(ptr);
             } else if (strncmp("@param", ptr, 6)==0) {
                 ptr+=6;
-                process_param(ptr);
+                n=process_param(ptr); // n=1 if '@param a' was processed, n=2 for 'b' ... n=26 for 'z'. n=0 if failed.
+                if (n>0 && n<SCRIPT_NUM_PARAMS) {
+                  script_param_order[j]=n;
+                  j++;
+                }
             } else if (update_vars && strncmp("@default", ptr, 8)==0) {
                 ptr+=8;
                 process_default(ptr);

Code: [Select]
--- include/script.h-trunk436   2008-07-06 20:41:22.000000000 +0300
+++ include/script.h    2008-07-06 20:43:40.000000000 +0300
@@ -10,6 +10,7 @@
 
 extern char script_title[36];
 extern char script_params[SCRIPT_NUM_PARAMS][28];
+extern int script_param_order[SCRIPT_NUM_PARAMS];
 
 //-------------------------------------------------------------------
 extern void script_load(const char *fn);

Code: [Select]
--- core/gui.c-trunk436 2008-07-06 20:41:00.000000000 +0300
+++ core/gui.c  2008-07-06 20:45:04.000000000 +0300
@@ -1341,10 +1341,10 @@
         script_submenu_items[p]=script_submenu_items_top[i];
     }
     for (i=0; i<SCRIPT_NUM_PARAMS; ++i) {
-        if (script_params[i][0]) {
-            script_submenu_items[p].text=(int)script_params[i];
+        if (script_param_order[i]) {
+            script_submenu_items[p].text=(int)script_params[script_param_order[i]-1];
             script_submenu_items[p].type=MENUITEM_INT;
-            script_submenu_items[p].value=&conf.ubasic_vars[i];
+            script_submenu_items[p].value=&conf.ubasic_vars[script_param_order[i]-1];
             ++p;
         }
     }

*

Offline fudgey

  • *****
  • 1705
  • a570is
Re: Disabling script parameter list sorting (patch included)
« Reply #1 on: 06 / July / 2008, 14:15:37 »
And here's a pair of dead-simple scripts to demonstrate the patch:

Code: [Select]
@title param test abc

@param a first param a
@default a 1

@param b second param b
@default b 2

@param c third param c
@default c 3

print "abc",a,b,c
end

Code: [Select]
@title param test cba

@param c first param c
@default c 1

@param b second param b
@default b 2

@param a third param a
@default a 3

print "abc",a,b,c
end

*

Offline Jucifer

  • *****
  • 251
  • [A710IS]
Re: Disabling script parameter list sorting (patch included)
« Reply #2 on: 06 / July / 2008, 16:35:05 »
if this affects Lua, which I believe doesn't suffer from the single letter variable disease of uBasic.

User-definable variables are the same a-z also for Lua scripts.
(committed your patch to the juciphox branch)

*

Offline PhyrePhoX

  • *****
  • 2253
  • make RAW not WAR
    • PhyreWorX
Re: Disabling script parameter list sorting (patch included)
« Reply #3 on: 29 / August / 2008, 07:17:10 »
heya, recieved bugreports regarding this patch - param z seems to be ignored in the paramlist, if you define a default value, it isnt listed in the paramlist. havent actually verified this, however i recieved multiple bureports in the german forum.
perhaps one of you can look into this!?


*

Offline fudgey

  • *****
  • 1705
  • a570is
Re: Disabling script parameter list sorting (patch included)
« Reply #4 on: 29 / August / 2008, 14:16:04 »
Hmm... in script.c function script_scan

Code: [Select]
                n=process_param(ptr, 0); // n=1 if '@param a' was processed, n=2 for 'b' ... n=26 for 'z'. n=0 if failed.
                if (n>0 && n<SCRIPT_NUM_PARAMS) {
                  script_param_order[j]=n;

I think should be
Code: [Select]
                n=process_param(ptr, 0); // n=1 if '@param a' was processed, n=2 for 'b' ... n=26 for 'z'. n=0 if failed.
                if (n>0 && n<=SCRIPT_NUM_PARAMS) {
                  script_param_order[j]=n;

SCRIPT_NUM_PARAMS is 26 after all... my bad.

*

Offline PhyrePhoX

  • *****
  • 2253
  • make RAW not WAR
    • PhyreWorX
Re: Disabling script parameter list sorting (patch included)
« Reply #5 on: 29 / August / 2008, 14:26:18 »
thx, will be in next commit.

 

Related Topics