Revision: 48388
http://brlcad.svn.sourceforge.net/brlcad/?rev=48388&view=rev
Author: r_weiss
Date: 2012-01-11 15:30:34 +0000 (Wed, 11 Jan 2012)
Log Message:
-----------
Cleanup of iges-g and g-iges converters. Removed a possible race condition by
using the 'access' function instead of 'stat'. Cleanup of logic for creating
unique brlcad names.
Modified Paths:
--------------
brlcad/trunk/src/conv/iges/check_names.c
brlcad/trunk/src/conv/iges/g-iges.c
Modified: brlcad/trunk/src/conv/iges/check_names.c
===================================================================
--- brlcad/trunk/src/conv/iges/check_names.c 2012-01-11 15:13:52 UTC (rev
48387)
+++ brlcad/trunk/src/conv/iges/check_names.c 2012-01-11 15:30:34 UTC (rev
48388)
@@ -44,14 +44,15 @@
/* Check if name already in list */
ptr = name_root;
while (ptr) {
- if (!strncmp(ptr->name, name, NAMESIZE+1))
+ if (!strcmp(ptr->name, name)) {
return ptr->name;
+ }
ptr = ptr->next;
}
/* add this name to the list */
- ptr = (struct name_list *)bu_malloc(sizeof(struct name_list),
"Add_brl_name: ptr");
- bu_strlcpy(ptr->name, name, NAMESIZE+1);
+ ptr = (struct name_list *)bu_calloc(1, sizeof(struct name_list),
"Add_brl_name: ptr");
+ bu_strlcpy(ptr->name, name, namelen+1);
ptr->next = name_root;
name_root = ptr;
@@ -60,100 +61,92 @@
char *
-Make_unique_brl_name(name)
- char *name;
-{
+Make_unique_brl_name(char *name) {
+
+ int found_str_end, name_unique;
+ size_t namelen, i, idx;
struct name_list *ptr;
- int found;
- size_t namelen;
- size_t char_ptr;
- size_t i, j;
+ char char_value;
- /* replace white space */
- namelen = strlen(name);
- for (i=0; i<namelen; i++) {
- if (isspace(name[i]) || name[i] == '/')
- name[i] = '_';
+ if (!name) {
+ bu_exit(1, "iges-g; name is null pointer\n");
+ return (char *)NULL;
}
- /* check if name is already unique */
- found = 0;
- ptr = name_root;
- while (ptr) {
- if (!strncmp(ptr->name, name, NAMESIZE+1)) {
- found = 1;
- break;
- }
- ptr = ptr->next;
+ found_str_end = 0;
+ for (i = 0 ; i < NAMESIZE+1 ; i++) {
+ if (name[i] == '\0') {
+ found_str_end = 1;
+ namelen = i;
+ break;
+ }
}
- if (!found)
- return Add_brl_name(name);
+ if (!found_str_end) {
+ bu_exit(1, "iges-g; corrupt name string\n");
+ return (char *)NULL;
+ }
- /* name is not unique, make it unique with a single character suffix */
- if (namelen < NAMESIZE)
- char_ptr = namelen;
- else
- char_ptr = NAMESIZE - 1;
+ /* replace white space */
+ for (i = 0 ; i < namelen ; i++) {
+ if (isspace(name[i]) || name[i] == '/') {
+ name[i] = '_';
+ }
+ }
- i = 0;
- while (found && 'A'+i <= 'z') {
- name[char_ptr] = 'A' + (char)i;
- name[char_ptr+1] = '\0';
- found = 0;
- ptr = name_root;
- while (ptr) {
- if (!strncmp(ptr->name, name, NAMESIZE+1)) {
- found = 1;
- break;
- }
- ptr = ptr->next;
- }
- i++;
- if ('A'+i == '[')
- i = 'a' - 'A';
+ if (namelen > 0) {
+ ptr = name_root;
+ name_unique = 1;
+ while (ptr) {
+ if (!strcmp(name, ptr->name)) {
+ name_unique = 0;
+ break;
+ }
+ ptr = ptr->next;
+ }
+ if (name_unique) {
+ return Add_brl_name(name);
+ }
}
- if (!found)
- return Add_brl_name(name);
+ idx = namelen;
+ char_value = 'A';
+ name_unique = 0;
+ while (!name_unique && idx < NAMESIZE) {
+ if (idx == 0 && char_value == 'A') {
+ name[idx] = char_value;
+ name[idx+1] = '\0';
+ char_value++;
+ }
+ ptr = name_root;
+ name_unique = 1;
+ while (ptr) {
+ if (!strcmp(name, ptr->name)) {
+ name_unique = 0;
+ break;
+ }
+ ptr = ptr->next;
+ }
+ if (!name_unique) {
+ name[idx] = char_value;
+ name[idx+1] = '\0';
+ if (char_value == 'Z') {
+ char_value = 'a';
+ } else if (char_value == 'z') {
+ idx++;
+ char_value = 'A';
+ } else {
+ char_value++;
+ }
+ }
+ }
-
- /* still not unique! Try two character suffix */
- char_ptr--;
- i = 0;
- j = 0;
- while (found && 'A'+i <= 'z' && 'A'+j <= 'z') {
- name[char_ptr] = 'A'+ (char)i;
- name[char_ptr+1] = 'A'+ (char)j;
- name[char_ptr+2] = '\0';
- found = 0;
- ptr = name_root;
- while (ptr) {
- if (!strncmp(ptr->name, name, NAMESIZE+1)) {
- found = 1;
- break;
- }
- ptr = ptr->next;
- }
- j++;
- if ('A'+j == '[')
- j = 'a' - 'A';
-
- if ('A'+j > 'z') {
- j = 0;
- i++;
- }
-
- if ('A'+i == '[')
- i = 'a' - 'A';
+ if (name_unique) {
+ return Add_brl_name(name);
}
- if (!found) {
- /* not likely */
- bu_exit(1, "Could not make name unique: (%s)\n", name);
- return (char *)NULL; /* make the compilers happy */
- } else
- return Add_brl_name(name);
+ bu_exit(1, "Could not make name unique: (%s)\n", name);
+ return (char *)NULL; /* make compilers happy */
}
@@ -522,7 +515,6 @@
void
Check_names()
{
-
int i;
bu_log("Looking for Name Entities...\n");
@@ -577,6 +569,7 @@
}
bu_log("Assigning names to entities without names...\n");
+
for (i=0; i < totentities; i++) {
char tmp_name[NAMESIZE+1];
@@ -657,3 +650,4 @@
* End:
* ex: shiftwidth=4 tabstop=8
*/
+
Modified: brlcad/trunk/src/conv/iges/g-iges.c
===================================================================
--- brlcad/trunk/src/conv/iges/g-iges.c 2012-01-11 15:13:52 UTC (rev 48387)
+++ brlcad/trunk/src/conv/iges/g-iges.c 2012-01-11 15:30:34 UTC (rev 48388)
@@ -556,7 +556,6 @@
char *multi_name;
size_t len;
int unique=0;
- struct stat stat_ptr;
char suffix[SUFFIX_LEN+1];
/* construct a unique file name */
@@ -566,7 +565,7 @@
bu_strlcpy(suffix, "a", sizeof(suffix));
suffix[0]--;
while (!unique) {
- if (stat(multi_name, &stat_ptr)) {
+ if (!access(multi_name, R_OK)) {
unique = 1;
break;
}
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Ridiculously easy VDI. With Citrix VDI-in-a-Box, you don't need a complex
infrastructure or vast IT resources to deliver seamless, secure access to
virtual desktops. With this all-in-one solution, easily deploy virtual
desktops for less than the cost of PCs and save 60% on VDI infrastructure
costs. Try it free! http://p.sf.net/sfu/Citrix-VDIinabox
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits