[brlcad-commits] SF.net SVN: brlcad: [31095] brlcad/trunk
Open Source Solid Modeling CAD
Brought to you by:
brlcad
From: <br...@us...> - 2008-05-14 08:55:32
|
Revision: 31095 http://brlcad.svn.sourceforge.net/brlcad/?rev=31095&view=rev Author: brlcad Date: 2008-05-14 01:55:40 -0700 (Wed, 14 May 2008) Log Message: ----------- make the new ged functions all use const char **argv's so callers can be sure the library doesn't modify their data Modified Paths: -------------- brlcad/trunk/include/ged.h brlcad/trunk/src/libged/edmater.c brlcad/trunk/src/libged/item.c brlcad/trunk/src/libged/log.c brlcad/trunk/src/libged/mater.c brlcad/trunk/src/libged/mirror.c brlcad/trunk/src/libged/rmater.c brlcad/trunk/src/libged/wmater.c Modified: brlcad/trunk/include/ged.h =================================================================== --- brlcad/trunk/include/ged.h 2008-05-14 08:28:23 UTC (rev 31094) +++ brlcad/trunk/include/ged.h 2008-05-14 08:55:40 UTC (rev 31095) @@ -685,7 +685,7 @@ * Usage: * edmater combination1 [combination2 ...] */ -GED_EXPORT BU_EXTERN(int ged_edmater, (struct rt_wdb *wdbp, int argc, char *argv[])); +GED_EXPORT BU_EXTERN(int ged_edmater, (struct rt_wdb *wdbp, int argc, const char *argv[])); /** * Set region ident codes. @@ -693,7 +693,7 @@ * Usage: * item region ident [air [material [los]]] */ -GED_EXPORT BU_EXTERN(int ged_item, (struct rt_wdb *wdbp, int argc, char *argv[])); +GED_EXPORT BU_EXTERN(int ged_item, (struct rt_wdb *wdbp, int argc, const char *argv[])); /** * Used to control logging. @@ -701,7 +701,7 @@ * Usage: * log {get|start|stop} */ -GED_EXPORT BU_EXTERN(int ged_log, (struct rt_wdb *wdbp, int argc, char *argv[])); +GED_EXPORT BU_EXTERN(int ged_log, (struct rt_wdb *wdbp, int argc, const char *argv[])); /** * Modify material information. @@ -709,7 +709,7 @@ * Usage: * mater region_name shader r g b inherit */ -GED_EXPORT BU_EXTERN(int ged_mater, (struct rt_wdb *wdbp, int argc, char *argv[])); +GED_EXPORT BU_EXTERN(int ged_mater, (struct rt_wdb *wdbp, int argc, const char *argv[])); /** * Mirror the primitive or combination along the specified axis. @@ -718,7 +718,7 @@ * mirror [-d dir] [-o origin] [-p scalar_pt] [-x] [-y] [-z] old new * */ -GED_EXPORT BU_EXTERN(int ged_mirror, (struct rt_wdb *wdbp, int argc, char *argv[])); +GED_EXPORT BU_EXTERN(int ged_mirror, (struct rt_wdb *wdbp, int argc, const char *argv[])); /** * Read material properties from a file. @@ -726,7 +726,7 @@ * Usage: * rmater file */ -GED_EXPORT BU_EXTERN(int ged_rmater, (struct rt_wdb *wdbp, int argc, char *argv[])); +GED_EXPORT BU_EXTERN(int ged_rmater, (struct rt_wdb *wdbp, int argc, const char *argv[])); /** * Write material properties to a file for specified combination(s). @@ -734,7 +734,7 @@ * Usage: * wmater file combination1 [combination2 ...] */ -GED_EXPORT BU_EXTERN(int ged_wmater, (struct rt_wdb *wdbp, int argc, char *argv[])); +GED_EXPORT BU_EXTERN(int ged_wmater, (struct rt_wdb *wdbp, int argc, const char *argv[])); Modified: brlcad/trunk/src/libged/edmater.c =================================================================== --- brlcad/trunk/src/libged/edmater.c 2008-05-14 08:28:23 UTC (rev 31094) +++ brlcad/trunk/src/libged/edmater.c 2008-05-14 08:55:40 UTC (rev 31095) @@ -29,12 +29,12 @@ int -ged_edmater(struct rt_wdb *wdbp, int argc, char *argv[]) +ged_edmater(struct rt_wdb *wdbp, int argc, const char *argv[]) { FILE *fp; int i; int status; - char **av; + const char **av; static const char *usage = "comb(s)"; char tmpfil[MAXPATHLEN]; @@ -52,7 +52,7 @@ if (!fp) return TCL_ERROR; - av = (char **)bu_malloc(sizeof(char *)*(argc + 2), "f_edmater: av"); + av = (const char **)bu_malloc(sizeof(char *)*(argc + 2), "f_edmater: av"); av[0] = "wmater"; av[1] = tmpfil; for(i = 2; i < argc + 1; ++i) Modified: brlcad/trunk/src/libged/item.c =================================================================== --- brlcad/trunk/src/libged/item.c 2008-05-14 08:28:23 UTC (rev 31094) +++ brlcad/trunk/src/libged/item.c 2008-05-14 08:55:40 UTC (rev 31095) @@ -27,9 +27,7 @@ #include "ged.h" int -ged_item(struct rt_wdb *wdbp, - int argc, - char *argv[]) +ged_item(struct rt_wdb *wdbp, int argc, const char *argv[]) { int status = GED_OK; register struct directory *dp; Modified: brlcad/trunk/src/libged/log.c =================================================================== --- brlcad/trunk/src/libged/log.c 2008-05-14 08:28:23 UTC (rev 31094) +++ brlcad/trunk/src/libged/log.c 2008-05-14 08:55:40 UTC (rev 31095) @@ -46,9 +46,7 @@ int -ged_log(struct rt_wdb *wdbp, - int argc, - char *argv[]) +ged_log(struct rt_wdb *wdbp, int argc, const char *argv[]) { static char *usage = "get|start|stop"; Modified: brlcad/trunk/src/libged/mater.c =================================================================== --- brlcad/trunk/src/libged/mater.c 2008-05-14 08:28:23 UTC (rev 31094) +++ brlcad/trunk/src/libged/mater.c 2008-05-14 08:55:40 UTC (rev 31095) @@ -27,9 +27,7 @@ int -ged_mater(struct rt_wdb *wdbp, - int argc, - char *argv[]) +ged_mater(struct rt_wdb *wdbp, int argc, const char *argv[]) { int status = GED_OK; register struct directory *dp; Modified: brlcad/trunk/src/libged/mirror.c =================================================================== --- brlcad/trunk/src/libged/mirror.c 2008-05-14 08:28:23 UTC (rev 31094) +++ brlcad/trunk/src/libged/mirror.c 2008-05-14 08:55:40 UTC (rev 31095) @@ -28,9 +28,7 @@ int -ged_mirror(struct rt_wdb *wdbp, - int argc, - char *argv[]) +ged_mirror(struct rt_wdb *wdbp, int argc, const char *argv[]) { register int k; point_t mirror_origin = {0.0, 0.0, 0.0}; @@ -38,6 +36,11 @@ fastf_t mirror_pt = 0.0; static const char *usage = "[-h] [-d dir] [-o origin] [-p scalar_pt] [-x] [-y] [-z] old new"; + int early_out = 0; + + char **nargv; + struct bu_vls vlsargv; + if (wdbp == RT_WDB_NULL) { bu_log("%s: a database must be open to use this command.", argv[0]); return GED_ERROR; @@ -58,10 +61,16 @@ return GED_OK; } + /* get a writable copy of argv */ + bu_vls_init(&vlsargv); + bu_vls_from_argv(&vlsargv, argc, argv); + nargv = bu_calloc(argc+1, sizeof(char *), "calloc f_ill nargv"); + bu_argv_from_string(nargv, argc, bu_vls_addr(&vlsargv)); + bu_optind = 1; /* Process arguments */ - while ((k = bu_getopt(argc, argv, "d:D:hHo:O:p::P:xXyYzZ")) != EOF) { + while ((k = bu_getopt(argc, nargv, "d:D:hHo:O:p::P:xXyYzZ")) != EOF) { switch (k) { case 'd': case 'D': @@ -70,7 +79,7 @@ &mirror_dir[Y], &mirror_dir[Z]) != 3) { bu_vls_printf(&wdbp->wdb_result_str, "Usage: %s %s", argv[0], usage); - return GED_ERROR; + early_out = 1; } break; case 'p': @@ -84,7 +93,7 @@ &mirror_origin[Y], &mirror_origin[Z]) != 3) { bu_vls_printf(&wdbp->wdb_result_str, "Usage: %s %s", argv[0], usage); - return GED_ERROR; + early_out = 1; } break; case 'x': @@ -103,13 +112,25 @@ case 'H': wdbp->wdb_result_flags |= GED_RESULT_FLAGS_HELP_BIT; bu_vls_printf(&wdbp->wdb_result_str, "Usage: %s %s", argv[0], usage); + + bu_free(nargv, "free f_ill nargv"); + bu_vls_free(&vlsargv); + return GED_OK; default: bu_vls_printf(&wdbp->wdb_result_str, "Usage: %s %s", argv[0], usage); - return GED_ERROR; + early_out = 1; + break; } } + bu_free(nargv, "free f_ill nargv"); + bu_vls_free(&vlsargv); + + if (early_out) { + return GED_ERROR; + } + argc -= bu_optind; if (argc < 2) { Modified: brlcad/trunk/src/libged/rmater.c =================================================================== --- brlcad/trunk/src/libged/rmater.c 2008-05-14 08:28:23 UTC (rev 31094) +++ brlcad/trunk/src/libged/rmater.c 2008-05-14 08:55:40 UTC (rev 31095) @@ -76,9 +76,7 @@ int -ged_rmater(struct rt_wdb *wdbp, - int argc, - char *argv[]) +ged_rmater(struct rt_wdb *wdbp, int argc, const char *argv[]) { #ifndef LINELEN #define LINELEN 256 Modified: brlcad/trunk/src/libged/wmater.c =================================================================== --- brlcad/trunk/src/libged/wmater.c 2008-05-14 08:28:23 UTC (rev 31094) +++ brlcad/trunk/src/libged/wmater.c 2008-05-14 08:55:40 UTC (rev 31095) @@ -27,7 +27,7 @@ int -ged_wmater(struct rt_wdb *wdbp, int argc, char *argv[]) +ged_wmater(struct rt_wdb *wdbp, int argc, const char *argv[]) { int i; int status = GED_OK; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |