def parse_script_line(l):
+ tip = 'No tooltip'
try:
pieces = l.split("'")
name = pieces[1].replace('...','')
- version, fname, userdir = pieces[2].strip().split()
- tip = pieces[3]
+ data = pieces[2].strip().split()
+ version = data[0]
+ userdir = data[-1]
+ fname = data[1]
+ i = 1
+ while not fname.endswith('.py'):
+ i += 1
+ fname = '%s %s' % (fname, data[i])
+ if len(pieces) > 3: tip = pieces[3]
except:
return None
char line[255], w1[255], w2[255], tooltip[255], *tip;
char upythondir[FILE_MAX];
char *homedir = NULL;
- int parsing, version, is_userdir;
+ int parsing, version, w2_len, is_userdir;
short group;
BPyMenu *pymenu = NULL;
else if( line[0] == '\n' )
continue;
else if( line[0] == '\'' ) { /* menu entry */
- parsing =
+/* parsing =
sscanf( line,
"'%[^']' %d %s %d '%[^']'\n",
w1, &version, w2, &is_userdir,
tooltip );
-
- if( parsing <= 0 ) { /* invalid line, get rid of it */
+*/
+ /* previously filenames with spaces were not supported;
+ * this adds support for that w/o breaking the existing
+ * few, exotic scripts that parse the Bpymenus file */
+ parsing = sscanf( line,
+ "'%[^']' %d %[^'\n] '%[^']'\n",
+ w1, &version, w2, tooltip );
+ if( parsing <= 0 ) { /* invalid line, get rid of it */
fgets( line, 255, fp );
- } else if( parsing == 5 )
+ } else if( parsing == 4 )
tip = tooltip; /* has tooltip */
+ w2_len = strlen(w2);
+ if( w2[w2_len-1] == ' ') {
+ w2[w2_len-1] = '\0';
+ w2_len -= 1;
+ }
+ if( w2[w2_len-1] == '1') is_userdir = 1;
+ else is_userdir = 0;
+ w2[w2_len-2] = '\0';
+
pymenu = bpymenu_AddEntry( group,
( short ) version,
w1, w2, is_userdir,
}
/* bpymenu_ParseFile:
- * recursively scans folders looking for scripts to register.
- *
- * This function scans the scripts directory looking for .py files with the
- * right header and menu info, using that to fill the bpymenu structs.
- * is_userdir defines if the script is in the default scripts dir or the
- * user defined one (U.pythondir: is_userdir == 1).
- * Speed is important.
+ * parse a given .py file looking for a proper header.
*
* The first line of the script must be '#!BPY'.
* The header registration lines must appear between the first pair of