[brlcad-commits] SF.net SVN: brlcad:[37260] brlcad/trunk/src/libged/gqa.c
Open Source Solid Modeling CAD
Brought to you by:
brlcad
From: <br...@us...> - 2010-01-14 21:35:03
|
Revision: 37260 http://brlcad.svn.sourceforge.net/brlcad/?rev=37260&view=rev Author: brlcad Date: 2010-01-14 21:34:53 +0000 (Thu, 14 Jan 2010) Log Message: ----------- fix gqa crash on 64-bit linux where strsep() is not defined (due to strict compilation, it's a bsd extension). the 32-bit int return value getting cast to a 64-bit pointer was badness. instead rewrite the units parsing to use strtok() since it's c89, also taking the opportunity to get rid of the unnecessary goto logic. while we're at it, take care of fstat/fileno warnings along with a strdup() -> bu_strdup() fix. Modified Paths: -------------- brlcad/trunk/src/libged/gqa.c Modified: brlcad/trunk/src/libged/gqa.c =================================================================== --- brlcad/trunk/src/libged/gqa.c 2010-01-14 21:07:28 UTC (rev 37259) +++ brlcad/trunk/src/libged/gqa.c 2010-01-14 21:34:53 UTC (rev 37260) @@ -696,23 +696,38 @@ char *ptr = bu_optarg; const struct cvt_tab *cv; static const char *dim[3] = {"length", "volume", "weight"}; - char *units_name[3]; + char *units_name[3] = {NULL, NULL, NULL}; + char **units_ap; - for (i=0; i < 3 && ptr; i++) { - units_name[i] = strsep(&ptr, ", "); + /* fill in units_name with the names we parse out */ + units_ap = units_name; - /* make sure the unit value is in the table */ - if (*units_name[i] != '\0') { - for (cv= &units_tab[i][0]; cv->name[0] != '\0'; cv++) { - if (!strcmp(cv->name, units_name[i])) { - goto found_cv; - } + /* acquire unit names */ + *units_ap = strtok(ptr, ", "); + for (i = 0; i < 3 && ptr; i++) { + int found_unit; + + /* got something? */ + if (*units_ap == NULL) + break; + + /* got something valid? */ + found_unit = 0; + for (cv = &units_tab[i][0]; cv->name[0] != '\0'; cv++) { + if (units_name[i] && strcmp(cv->name, units_name[i]) == 0) { + units[i] = cv; + found_unit = 1; + break; } + } + + if (!found_unit) { bu_vls_printf(&_ged_current_gedp->ged_result_str, "Units \"%s\" not found in coversion table\n", units_name[i]); return -1; - found_cv: - units[i] = cv; } + + ++units_ap; + *units_ap = strtok(NULL, ", "); } bu_vls_printf(&_ged_current_gedp->ged_result_str, "Units: "); @@ -847,26 +862,20 @@ int get_densities_from_file(char *name) { - FILE *fp; struct stat sb; - char *buf; - int ret; - if ((fp=fopen(name, "rb")) == (FILE *)NULL) { -#if 1 + FILE *fp = (FILE *)NULL; + char *buf = NULL; + int ret = 0; + + fp = fopen(name, "rb"); + if (fp == (FILE *)NULL) { bu_vls_printf(&_ged_current_gedp->ged_result_str, "Could not open file - %s\n", name); -#else - perror(name); -#endif return GED_ERROR; } - if (fstat(fileno(fp), &sb)) { -#if 1 - bu_vls_printf(&_ged_current_gedp->ged_result_str, "Could not fstat file - %s\n", name); -#else - perror(name); -#endif + if (stat(name, &sb)) { + bu_vls_printf(&_ged_current_gedp->ged_result_str, "Could not read file - %s\n", name); return GED_ERROR; } @@ -1575,7 +1584,7 @@ find_cmd_line_obj(struct per_obj_data *obj_rpt, const char *name) { int i; - char *str = strdup(name); + char *str = bu_strdup(name); char *p; if ((p=strchr(str, '/'))) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |