[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [28965] trunk/blender/source: BLI_args cleanup

Martin Poirier theeth at yahoo.com
Mon May 24 20:53:45 CEST 2010


Revision: 28965
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=28965
Author:   theeth
Date:     2010-05-24 20:53:45 +0200 (Mon, 24 May 2010)

Log Message:
-----------
BLI_args cleanup

Adding documentation strings in argument data.

--help is auto generated (options not manually categorized end up in the "others" section at the bottom)

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/BKE_utildefines.h
    trunk/blender/source/blender/blenlib/BLI_args.h
    trunk/blender/source/blender/blenlib/intern/BLI_args.c
    trunk/blender/source/creator/creator.c

Modified: trunk/blender/source/blender/blenkernel/BKE_utildefines.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_utildefines.h	2010-05-24 16:12:58 UTC (rev 28964)
+++ trunk/blender/source/blender/blenkernel/BKE_utildefines.h	2010-05-24 18:53:45 UTC (rev 28965)
@@ -38,6 +38,9 @@
 #define TRUE 1
 #endif
 
+/* Macro to convert a value to string in the preprocessor */
+#define QUOTE(x) #x
+
 /* these values need to be hardcoded in structs, dna does not recognize defines */
 /* also defined in DNA_space_types.h */
 #ifndef FILE_MAXDIR

Modified: trunk/blender/source/blender/blenlib/BLI_args.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_args.h	2010-05-24 16:12:58 UTC (rev 28964)
+++ trunk/blender/source/blender/blenlib/BLI_args.h	2010-05-24 18:53:45 UTC (rev 28965)
@@ -41,14 +41,18 @@
 struct bArgs *BLI_argsInit(int argc, char **argv);
 void BLI_argsFree(struct bArgs *ba);
 
-/* pass starts at 1, -1 means valid all the time */
-void BLI_argsAdd(struct bArgs *ba, char *arg, int pass, BA_ArgCallback cb, void *data);
-void BLI_argsAddPair(struct bArgs *ba, char *arg_short, char *arg_long, int pass, BA_ArgCallback cb, void *data);
+/* pass starts at 1, -1 means valid all the time
+ * short_arg or long_arg can be null to specify no short or long versions
+ * */
+void BLI_argsAdd(struct bArgs *ba, int pass, char *short_arg, char *long_arg, char *doc, BA_ArgCallback cb, void *data);
+/* short_case and long_case specify if those arguments are case specific */
+void BLI_argsAddCase(struct bArgs *ba, int pass, char *short_arg, int short_case, char *long_arg, int long_case, char *doc, BA_ArgCallback cb, void *data);
 
-void BLI_argsAddCase(struct bArgs *ba, char *arg, int pass, BA_ArgCallback cb, void *data); /* not case specific */
-
 void BLI_argsParse(struct bArgs *ba, int pass, BA_ArgCallback default_cb, void *data);
 
+void BLI_argsPrintArgDoc(struct bArgs *ba, char *arg);
+void BLI_argsPrintOtherDoc(struct bArgs *ba);
+
 void BLI_argsPrint(struct bArgs *ba);
 char **BLI_argsArgv(struct bArgs *ba);
 

Modified: trunk/blender/source/blender/blenlib/intern/BLI_args.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/BLI_args.c	2010-05-24 16:12:58 UTC (rev 28964)
+++ trunk/blender/source/blender/blenlib/intern/BLI_args.c	2010-05-24 18:53:45 UTC (rev 28965)
@@ -33,10 +33,22 @@
 
 #include "MEM_guardedalloc.h"
 
+#include "BLI_listbase.h"
 #include "BLI_string.h"
 #include "BLI_args.h"
 #include "BLI_ghash.h"
 
+char NO_DOCS[] = "NO DOCUMENTATION SPECIFIED";
+
+struct bArgDoc;
+typedef struct bArgDoc {
+	struct bArgDoc *next, *prev;
+	char *short_arg;
+	char *long_arg;
+	char *documentation;
+	int  done;
+} bArgDoc;
+
 typedef struct bAKey {
 	char *arg;
 	uintptr_t pass; /* cast easier */
@@ -47,9 +59,11 @@
 	bAKey *key;
 	BA_ArgCallback func;
 	void *data;
+	bArgDoc *doc;
 } bArgument;
 
 struct bArgs {
+	ListBase docs;
 	GHash  *items;
 	int 	argc;
 	char  **argv;
@@ -70,7 +84,7 @@
 static unsigned int	keyhash(void *ptr)
 {
 	bAKey *k = ptr;
-	return case_strhash(k->arg) ^ BLI_ghashutil_inthash((void*)k->pass);
+	return case_strhash(k->arg); // ^ BLI_ghashutil_inthash((void*)k->pass);
 }
 
 static int keycmp(void *a, void *b)
@@ -103,6 +117,7 @@
 	bArgs *ba = MEM_callocN(sizeof(bArgs), "bArgs");
 	ba->passes = MEM_callocN(sizeof(int) * argc, "bArgs passes");
 	ba->items = BLI_ghash_new(keyhash, keycmp, "bArgs passes gh");
+	ba->docs.first = ba->docs.last = NULL;
 	ba->argc = argc;
 	ba->argv = argv;
 
@@ -118,6 +133,7 @@
 {
 	BLI_ghash_free(ba->items, freeItem, freeItem);
 	MEM_freeN(ba->passes);
+	BLI_freelistN(&ba->docs);
 	MEM_freeN(ba);
 }
 
@@ -134,8 +150,26 @@
 	return ba->argv;
 }
 
-static void internalAdd(struct bArgs *ba, char *arg, int pass, int case_str, BA_ArgCallback cb, void *data)
+static bArgDoc *internalDocs(struct bArgs *ba, char *short_arg, char *long_arg, char *doc)
 {
+	bArgDoc *d;
+
+	d = MEM_callocN(sizeof(bArgDoc), "bArgDoc");
+
+	if (doc == NULL)
+		doc = NO_DOCS;
+
+	d->short_arg = short_arg;
+	d->long_arg = long_arg;
+	d->documentation = doc;
+
+	BLI_addtail(&ba->docs, d);
+
+	return d;
+}
+
+static void internalAdd(struct bArgs *ba, char *arg, int pass, int case_str, BA_ArgCallback cb, void *data, bArgDoc *d)
+{
 	bArgument *a;
 	bAKey *key;
 
@@ -157,36 +191,73 @@
 	a->key = key;
 	a->func = cb;
 	a->data = data;
+	a->doc = d;
 
 	BLI_ghash_insert(ba->items, key, a);
 }
 
-void BLI_argsAdd(struct bArgs *ba, char *arg, int pass, BA_ArgCallback cb, void *data)
+void BLI_argsAddCase(struct bArgs *ba, int pass, char *short_arg, int short_case, char *long_arg, int long_case, char *doc, BA_ArgCallback cb, void *data)
 {
-	internalAdd(ba, arg, pass, 0, cb, data);
+	bArgDoc *d = internalDocs(ba, short_arg, long_arg, doc);
+
+	if (short_arg)
+		internalAdd(ba, short_arg, pass, short_case, cb, data, d);
+
+	if (long_arg)
+		internalAdd(ba, long_arg, pass, long_case, cb, data, d);
+
+
 }
 
-void BLI_argsAddPair(struct bArgs *ba, char *arg_short, char *arg_long, int pass, BA_ArgCallback cb, void *data)
+void BLI_argsAdd(struct bArgs *ba, int pass, char *short_arg, char *long_arg, char *doc, BA_ArgCallback cb, void *data)
 {
-	internalAdd(ba, arg_short, pass, 0, cb, data);
-	internalAdd(ba, arg_long, pass, 0, cb, data);
+	BLI_argsAddCase(ba, pass, short_arg, 0, long_arg, 0, doc, cb, data);
 }
 
-void BLI_argsAddCase(struct bArgs *ba, char *arg, int pass, BA_ArgCallback cb, void *data)
+static void internalDocPrint(bArgDoc *d)
 {
-	internalAdd(ba, arg, pass, 1, cb, data);
+	if (d->short_arg && d->long_arg)
+		printf("%s or %s", d->short_arg, d->long_arg);
+	else if (d->short_arg)
+		printf("%s", d->short_arg);
+	else if (d->long_arg)
+		printf("%s", d->long_arg);
+
+	printf(" %s\n\n", d->documentation);
 }
 
+void BLI_argsPrintArgDoc(struct bArgs *ba, char *arg)
+{
+	bArgument *a = lookUp(ba, arg, -1, -1);
 
+	if (a)
+	{
+		bArgDoc *d = a->doc;
+
+		internalDocPrint(d);
+
+		d->done = 1;
+	}
+}
+
+void BLI_argsPrintOtherDoc(struct bArgs *ba)
+{
+	bArgDoc *d;
+
+	for( d = ba->docs.first; d; d = d->next)
+	{
+		if (d->done == 0)
+		{
+			internalDocPrint(d);
+		}
+	}
+}
+
 void BLI_argsParse(struct bArgs *ba, int pass, BA_ArgCallback default_cb, void *default_data)
 {
 	int i = 0;
 
 	for( i = 1; i < ba->argc; i++) { /* skip argv[0] */
-		/* stop on -- */
-		if (BLI_streq(ba->argv[i], "--"))
-			break;
-
 		if (ba->passes[i] == 0) {
 			 /* -1 signal what side of the comparison it is */
 			bArgument *a = lookUp(ba, ba->argv[i], pass, -1);

Modified: trunk/blender/source/creator/creator.c
===================================================================
--- trunk/blender/source/creator/creator.c	2010-05-24 16:12:58 UTC (rev 28964)
+++ trunk/blender/source/creator/creator.c	2010-05-24 18:53:45 UTC (rev 28965)
@@ -195,119 +195,77 @@
 
 static int print_help(int argc, char **argv, void *data)
 {
+	bArgs *ba = (bArgs*)data;
+
 	printf ("Blender %d.%02d (sub %d) Build\n", BLENDER_VERSION/100, BLENDER_VERSION%100, BLENDER_SUBVERSION);
 	printf ("Usage: blender [args ...] [file] [args ...]\n\n");
 
 	printf ("Render Options:\n");
-	printf ("  -b or --background <file>\n");
-	printf ("    Load <file> in background (often used for background rendering)\n\n");
+	BLI_argsPrintArgDoc(ba, "-b");
+	BLI_argsPrintArgDoc(ba, "--render-anim");
+	BLI_argsPrintArgDoc(ba, "--scene");
+	BLI_argsPrintArgDoc(ba, "--render-frame");
+	BLI_argsPrintArgDoc(ba, "--frame-start");
+	BLI_argsPrintArgDoc(ba, "--frame-end");
+	BLI_argsPrintArgDoc(ba, "--frame-jump");
+	BLI_argsPrintArgDoc(ba, "--render-output");
+	BLI_argsPrintArgDoc(ba, "--engine");
 	
-	printf ("    -a or --render-anim\n");
-	printf ("      Render frames from start to end (inclusive), only works when used after -b\n\n");
-	
-	printf ("    -S or --scene <name>\n");
-	printf ("      Set the active scene <name> for rendering, only works when used after -b\n\n");
-	
-	printf ("    -f or --render-frame <frame>\n");
-	printf ("      Render frame <frame> and save it.\n\n");
-	
-	printf ("    -s or --frame-start <frame>\n");
-	printf ("      Set start to frame <frame> (use before the -a argument).\n\n");
-	
-	
-	printf ("    -e or --frame-end <frame>\n");
-	printf ("      Set end to frame <frame> (use before the -a argument).\n\n");
-	
-	printf ("    -o or --render-output <path>\n");
-	printf ("      Set the render path and file name.\n");
-	printf ("      Use // at the start of the path to\n");
-	printf ("        render relative to the blend file.\n");
-	printf ("      The # characters are replaced by the frame number, and used to define zero padding.\n");
-	printf ("        ani_##_test.png becomes ani_01_test.png\n");
-	printf ("        test-######.png becomes test-000001.png\n");
-	printf ("        When the filename does not contain #, The suffix #### is added to the filename\n");
-	printf ("      The frame number will be added at the end of the filename.\n");
-	printf ("        eg: blender -b foobar.blend -o //render_ -F PNG -x 1 -a\n");
-	printf ("        //render_ becomes //render_####, writing frames as //render_0001.png//\n");
-
-	printf ("    -E or --engine <engine>\n");
-	printf ("      Specify the render engine.\n");
-	printf ("      use -E help to list available engines.\n\n");
-	
+	printf("\n");
 	printf ("Format Options:\n");
-	printf ("  -F or --render-format <format>\n");
-	printf ("    Set the render format, Valid options are...\n");
-	printf ("      TGA IRIS JPEG MOVIE IRIZ RAWTGA\n");
-	printf ("      AVIRAW AVIJPEG PNG BMP FRAMESERVER\n");
-	printf ("    (formats that can be compiled into blender, not available on all systems)\n");
-	printf ("      HDR TIFF EXR MULTILAYER MPEG AVICODEC QUICKTIME CINEON DPX DDS\n\n");
+	BLI_argsPrintArgDoc(ba, "--render-format");
+	BLI_argsPrintArgDoc(ba, "--use-extension");
+	BLI_argsPrintArgDoc(ba, "--threads");
 
-	printf ("  -x or --use-extension <bool>\n");
-	printf ("    Set option to add the file extension to the end of the file.\n\n");
-
-	printf ("  -t or --threads <threads>\n");
-	printf ("    Use amount of <threads> for rendering (background mode only).\n");
-	printf ("    [1-%d], 0 for systems processor count.\n\n", BLENDER_MAX_THREADS);
-
+	printf("\n");
 	printf ("Animation Playback Options:\n");
-	printf ("  -a <options> <file(s)>\tPlayback <file(s)>, only operates this way when -b is not used.\n");

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list