Thread: [brlcad-commits] SF.net SVN: brlcad:[50521] brlcad/trunk/src/libged/red.c (Page 5)
Open Source Solid Modeling CAD
Brought to you by:
brlcad
From: <r_...@us...> - 2012-05-11 20:26:36
|
Revision: 50521 http://brlcad.svn.sourceforge.net/brlcad/?rev=50521&view=rev Author: r_weiss Date: 2012-05-11 20:26:29 +0000 (Fri, 11 May 2012) Log Message: ----------- Updated function 'ged_red' in file 'red.c'. Fixed a bug where regions were incorrectly being automatically converted to combinations when editied with the mged 'red' command. Fixed bugs in the mged 'red' command input parameter error checking. Improved some of the error messages in the mged and archer 'red' command. Modified Paths: -------------- brlcad/trunk/src/libged/red.c Modified: brlcad/trunk/src/libged/red.c =================================================================== --- brlcad/trunk/src/libged/red.c 2012-05-11 20:06:53 UTC (rev 50520) +++ brlcad/trunk/src/libged/red.c 2012-05-11 20:26:29 UTC (rev 50521) @@ -729,7 +729,7 @@ int -ged_red(struct ged *gedp, int argc, const char *argv[]) +ged_red(struct ged *gedp, int argc, const char **argv) { FILE *fp; int c, counter; @@ -738,7 +738,7 @@ struct directory *dp, *tmp_dp; struct rt_db_internal intern; struct rt_comb_internal *comb; - static const char *usage = "comb"; + static const char *usage = "{[ region | combination | group ]}"; const char *editstring = NULL; const char *av[3]; struct bu_vls comb_name = BU_VLS_INIT_ZERO; @@ -749,9 +749,23 @@ GED_CHECK_DATABASE_OPEN(gedp, GED_ERROR); GED_CHECK_ARGC_GT_0(gedp, argc, GED_ERROR); + /* initialize result */ + bu_vls_trunc(gedp->ged_result_str, 0); + + /* must be wanting help */ + if (argc < 2) { + bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", "red", usage); + return GED_HELP; + } + + if (argc > 4) { + bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", "red", usage); + return GED_ERROR; + } + bu_optind = 1; /* First, grab the editstring off of the argv list */ - while ((c = bu_getopt(argc, (char * const *)argv, "E:")) != -1) { + while ((c = bu_getopt(argc, (char **)argv, "E:")) != -1) { switch (c) { case 'E' : editstring = bu_optarg; @@ -766,20 +780,6 @@ argc -= bu_optind - 1; argv += bu_optind - 1; - /* initialize result */ - bu_vls_trunc(gedp->ged_result_str, 0); - - /* must be wanting help */ - if (argc <= 2) { - bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", "red", usage); - return GED_HELP; - } - - if (argc != 3) { - bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", "red", usage); - return GED_ERROR; - } - dp = db_lookup(gedp->ged_wdbp->dbip, argv[1], LOOKUP_QUIET); /* Now, sanity check to make sure a comb is listed instead of a @@ -798,13 +798,14 @@ * object names. */ bu_vls_sprintf(&temp_name, "%s_red%d", dp->d_namep, counter); - if (db_lookup(gedp->ged_wdbp->dbip, bu_vls_addr(&temp_name), LOOKUP_QUIET) == RT_DIR_NULL) + if (db_lookup(gedp->ged_wdbp->dbip, bu_vls_addr(&temp_name), LOOKUP_QUIET) == RT_DIR_NULL) { have_tmp_name = 1; - else + } else { counter++; + } } if (!(dp->d_flags & RT_DIR_COMB)) { - bu_vls_printf(gedp->ged_result_str, "%s: %s must be a combination to use this command\n", argv[0], argv[1]); + bu_vls_printf(gedp->ged_result_str, "%s must be a region, combination or group\n", argv[1]); bu_vls_free(&comb_name); bu_vls_free(&temp_name); return GED_ERROR; @@ -823,8 +824,8 @@ /* Make a file for the text editor, stash name in _ged_tmpfil */ fp = bu_temp_file(_ged_tmpfil, MAXPATHLEN); if (fp == (FILE *)0) { - bu_vls_printf(gedp->ged_result_str, "%s: unable to edit %s\n", argv[0], argv[1]); - bu_vls_printf(gedp->ged_result_str, "%s: unable to create %s\n", argv[0], _ged_tmpfil); + bu_vls_printf(gedp->ged_result_str, "Unable to edit %s\n", argv[1]); + bu_vls_printf(gedp->ged_result_str, "Unable to create %s\n", _ged_tmpfil); bu_vls_free(&comb_name); bu_vls_free(&temp_name); return GED_ERROR; @@ -832,7 +833,7 @@ /* Write the combination components to the file */ if (write_comb(gedp, comb, argv[1])) { - bu_vls_printf(gedp->ged_result_str, "%s: unable to edit %s\n", argv[0], argv[1]); + bu_vls_printf(gedp->ged_result_str, "Unable to edit %s\n", argv[1]); (void)fclose(fp); goto cleanup; } @@ -848,7 +849,7 @@ */ if (gedp->ged_wdbp->dbip->dbi_read_only) { - bu_vls_printf(gedp->ged_result_str, "%s: Database is READ-ONLY.\nNo changes were made.\n", *argv); + bu_vls_printf(gedp->ged_result_str, "Database is READ-ONLY.\nNo changes were made.\n"); goto cleanup; } @@ -865,7 +866,7 @@ goto cleanup; } - if ((tmp_dp = db_diradd(gedp->ged_wdbp->dbip, bu_vls_addr(&temp_name), RT_DIR_PHONY_ADDR, 0, RT_DIR_COMB, (genptr_t)&intern.idb_type)) == RT_DIR_NULL) { + if ((tmp_dp = db_diradd(gedp->ged_wdbp->dbip, bu_vls_addr(&temp_name), RT_DIR_PHONY_ADDR, 0, dp->d_flags, (genptr_t)&intern.idb_type)) == RT_DIR_NULL) { bu_vls_printf(gedp->ged_result_str, "Cannot save copy of %s, no changed made\n", bu_vls_addr(&temp_name)); goto cleanup; } @@ -895,7 +896,7 @@ /* Something went wrong - kill the temporary comb */ - bu_vls_printf(gedp->ged_result_str, "%s: Error in edited region, no changes made\n", *argv); + bu_vls_printf(gedp->ged_result_str, "Problem in edited region, no changes made\n"); av[0] = "kill"; av[1] = bu_vls_addr(&temp_name); @@ -920,7 +921,7 @@ (void)ged_kill(gedp, 2, (const char **)av); } else { /* not forced, can't overwrite destination, can't proceed */ - bu_vls_printf(gedp->ged_result_str, "%s: Error - %s already exists\n", *argv, bu_vls_addr(&final_name)); + bu_vls_printf(gedp->ged_result_str, "%s already exists\n", bu_vls_addr(&final_name)); goto cleanup; } } @@ -929,7 +930,7 @@ /* if we ended up with an empty final name, print an error message and head for cleanup */ if (strlen(bu_vls_addr(&final_name)) == 0) { - bu_vls_printf(gedp->ged_result_str, "%s: Error - no target name supplied\n", *argv); + bu_vls_printf(gedp->ged_result_str, "Problem reading target name\n"); goto cleanup; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <br...@us...> - 2012-05-14 20:57:36
|
Revision: 50540 http://brlcad.svn.sourceforge.net/brlcad/?rev=50540&view=rev Author: brlcad Date: 2012-05-14 20:57:28 +0000 (Mon, 14 May 2012) Log Message: ----------- shouldn't muddle our own terminology with redundancy. regions and groups are combinations. (plus the serial comma was missing and the usage implied an option null set) Modified Paths: -------------- brlcad/trunk/src/libged/red.c Modified: brlcad/trunk/src/libged/red.c =================================================================== --- brlcad/trunk/src/libged/red.c 2012-05-14 20:54:17 UTC (rev 50539) +++ brlcad/trunk/src/libged/red.c 2012-05-14 20:57:28 UTC (rev 50540) @@ -738,7 +738,7 @@ struct directory *dp, *tmp_dp; struct rt_db_internal intern; struct rt_comb_internal *comb; - static const char *usage = "{[ region | combination | group ]}"; + static const char *usage = "{combination}"; const char *editstring = NULL; const char *av[3]; struct bu_vls comb_name = BU_VLS_INIT_ZERO; @@ -805,7 +805,7 @@ } } if (!(dp->d_flags & RT_DIR_COMB)) { - bu_vls_printf(gedp->ged_result_str, "%s must be a region, combination or group\n", argv[1]); + bu_vls_printf(gedp->ged_result_str, "%s must be a combination\n", argv[1]); bu_vls_free(&comb_name); bu_vls_free(&temp_name); return GED_ERROR; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <r_...@us...> - 2012-05-17 20:21:01
|
Revision: 50594 http://brlcad.svn.sourceforge.net/brlcad/?rev=50594&view=rev Author: r_weiss Date: 2012-05-17 20:20:54 +0000 (Thu, 17 May 2012) Log Message: ----------- Updated function "build_comb" in file "libged/red.c". Changed the call to function "db5_sync_attr_to_comb" to pass in the directory instead of the combination name. Modified Paths: -------------- brlcad/trunk/src/libged/red.c Modified: brlcad/trunk/src/libged/red.c =================================================================== --- brlcad/trunk/src/libged/red.c 2012-05-17 20:18:44 UTC (rev 50593) +++ brlcad/trunk/src/libged/red.c 2012-05-17 20:20:54 UTC (rev 50594) @@ -556,7 +556,7 @@ comb->tree = tp; db5_standardize_avs(&avs); - db5_sync_attr_to_comb(comb, &avs, dp->d_namep); + db5_sync_attr_to_comb(comb, &avs, dp); db5_sync_comb_to_attr(&avs, comb); if (rt_db_put_internal(dp, gedp->ged_wdbp->dbip, &intern, &rt_uniresource) < 0) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <r_...@us...> - 2012-06-01 18:59:57
|
Revision: 50811 http://brlcad.svn.sourceforge.net/brlcad/?rev=50811&view=rev Author: r_weiss Date: 2012-06-01 18:59:50 +0000 (Fri, 01 Jun 2012) Log Message: ----------- Added more error checking to mged/archer 'red' command. Fixed a one off problem which could cause issues. Modified Paths: -------------- brlcad/trunk/src/libged/red.c Modified: brlcad/trunk/src/libged/red.c =================================================================== --- brlcad/trunk/src/libged/red.c 2012-06-01 18:51:19 UTC (rev 50810) +++ brlcad/trunk/src/libged/red.c 2012-06-01 18:59:50 UTC (rev 50811) @@ -214,7 +214,7 @@ struct bu_vls next_op_vls = BU_VLS_INIT_ZERO; struct bu_mapped_file *redtmpfile; int attrstart, attrend, attrcumulative, name_end; - int ret, gedret, combtagstart, combtagend; + int ret, reti, gedret, combtagstart, combtagend; struct bu_attribute_value_set avs; matp_t matrix = {0}; @@ -242,12 +242,17 @@ } /* Set up the regular expressions */ - regcomp(&nonwhitespace_regex, "([^[:space:]])", REG_EXTENDED); - regcomp(&attr_regex, "(.+[[:space:]]+=.*)", REG_EXTENDED|REG_NEWLINE); + reti = 0; + reti |= regcomp(&nonwhitespace_regex, "([^[:space:]])", REG_EXTENDED); + reti |= regcomp(&attr_regex, "(.+[[:space:]]+=.*)", REG_EXTENDED|REG_NEWLINE); bu_vls_sprintf(¤t_substring, "(%s)", combtree_header); - regcomp(&combtree_regex, bu_vls_addr(¤t_substring), REG_EXTENDED); - regcomp(&combtree_op_regex, "([[:blank:]]+[[.-.][.+.]u][[:blank:]]+)", REG_EXTENDED); + reti |= regcomp(&combtree_regex, bu_vls_addr(¤t_substring), REG_EXTENDED); + reti |= regcomp(&combtree_op_regex, "([[:blank:]]+[[.-.][.+.]u][[:blank:]]+)", REG_EXTENDED); + if (reti) { + bu_vls_printf(gedp->ged_result_str, "Unable to compile regular expression.\n"); + return -1; + } /* Need somewhere to hold the results - initially, size according to attribute regex */ result_locations = (regmatch_t *)bu_calloc(attr_regex.re_nsub, sizeof(regmatch_t), "array to hold answers from regex"); @@ -363,7 +368,7 @@ ret = regexec(&combtree_op_regex, currptr, combtree_op_regex.re_nsub , result_locations, 0); node_count++; } - currptr = (const char *)(redtmpfile->buf) + combtagend; + currptr = (const char *)(redtmpfile->buf) + combtagend + 1; name_end = 0; ret = regexec(&combtree_op_regex, currptr, combtree_op_regex.re_nsub , result_locations, 0); @@ -627,7 +632,7 @@ } fprintf(fp, "%s%s = \n", attr, bu_vls_addr(&spacer)); } - fprintf(fp, "%s", combseparator); + fprintf(fp, "%s\n", combseparator); fclose(fp); bu_vls_free(&spacer); return GED_OK; @@ -691,7 +696,7 @@ } bu_vls_free(&spacer); - fprintf(fp, "%s", combseparator); + fprintf(fp, "%s\n", combseparator); for (i = 0; i<actual_count; i++) { char op; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <r_...@us...> - 2012-06-02 01:35:48
|
Revision: 50820 http://brlcad.svn.sourceforge.net/brlcad/?rev=50820&view=rev Author: r_weiss Date: 2012-06-02 01:35:40 +0000 (Sat, 02 Jun 2012) Log Message: ----------- Update to mged/archer 'red' command to improve error reporting. Modified Paths: -------------- brlcad/trunk/src/libged/red.c Modified: brlcad/trunk/src/libged/red.c =================================================================== --- brlcad/trunk/src/libged/red.c 2012-06-01 22:44:45 UTC (rev 50819) +++ brlcad/trunk/src/libged/red.c 2012-06-02 01:35:40 UTC (rev 50820) @@ -224,7 +224,7 @@ /* Standard sanity checks */ if (gedp->ged_wdbp->dbip == DBI_NULL) - return -1; + return GED_ERROR; GED_DB_GET_INTERNAL(gedp, &intern, dp, (fastf_t *)NULL, &rt_uniresource, GED_ERROR); comb = (struct rt_comb_internal *)intern.idb_ptr; @@ -238,7 +238,7 @@ redtmpfile = bu_open_mapped_file(_ged_tmpfil, (char *)NULL); if (!redtmpfile) { bu_vls_printf(gedp->ged_result_str, "Cannot open temporary file %s\n", _ged_tmpfil); - return -1; + return GED_ERROR; } /* Set up the regular expressions */ @@ -251,7 +251,7 @@ if (reti) { bu_vls_printf(gedp->ged_result_str, "Unable to compile regular expression.\n"); - return -1; + return GED_ERROR; } /* Need somewhere to hold the results - initially, size according to attribute regex */ @@ -281,7 +281,7 @@ bu_free(result_locations, "free regex results array\n"); bu_close_mapped_file(redtmpfile); - return -1; + return GED_ERROR; } } else { bu_vls_printf(gedp->ged_result_str, "cannot locate comb tree, aborting\n"); @@ -293,7 +293,7 @@ bu_free(result_locations, "free regex results array\n"); bu_close_mapped_file(redtmpfile); - return -1; + return GED_ERROR; } /* Parsing the file is handled in two stages - attributes and combination tree. Start with attributes */ @@ -315,7 +315,7 @@ bu_free(result_locations, "free regex results array\n"); bu_close_mapped_file(redtmpfile); - return -1; + return GED_ERROR; } else { /* matched */ @@ -567,14 +567,14 @@ if (rt_db_put_internal(dp, gedp->ged_wdbp->dbip, &intern, &rt_uniresource) < 0) { bu_vls_printf(gedp->ged_result_str, "build_comb %s: Cannot apply tree\n", dp->d_namep); bu_avs_free(&avs); - return -1; + return GED_ERROR; } if(db5_replace_attributes(dp, &avs, gedp->ged_wdbp->dbip)) bu_vls_printf(gedp->ged_result_str, "build_comb %s: Failed to update attributes\n", dp->d_namep); bu_avs_free(&avs); - return node_count; + return GED_OK; } @@ -897,7 +897,7 @@ } /* reconstitute the new combination */ - if (build_comb(gedp, tmp_dp, &final_name) < 0) { + if ((ret = build_comb(gedp, tmp_dp, &final_name)) != GED_OK) { /* Something went wrong - kill the temporary comb */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <r_...@us...> - 2012-06-05 03:34:42
|
Revision: 50872 http://brlcad.svn.sourceforge.net/brlcad/?rev=50872&view=rev Author: r_weiss Date: 2012-06-05 03:34:34 +0000 (Tue, 05 Jun 2012) Log Message: ----------- Updated the mged/archer 'red' command. Improved editing of matrices in Windows. Modified Paths: -------------- brlcad/trunk/src/libged/red.c Modified: brlcad/trunk/src/libged/red.c =================================================================== --- brlcad/trunk/src/libged/red.c 2012-06-05 02:09:34 UTC (rev 50871) +++ brlcad/trunk/src/libged/red.c 2012-06-05 03:34:34 UTC (rev 50872) @@ -104,7 +104,7 @@ const char *floatptr; const char *float_string = "[+-]?[0-9]*[.]?[0-9]+([eE][+-]?[0-9]+)?"; - bu_vls_sprintf(¤t_substring, "(%s[[:space:]]+)", float_string); + bu_vls_sprintf(¤t_substring, "(%s)", float_string); regcomp(&matrix_entry, bu_vls_addr(¤t_substring), REG_EXTENDED); bu_vls_sprintf(¤t_substring, /* broken into two strings so auto-formatting @@ -113,7 +113,7 @@ "[[:space:]]+(%s[[:space:]]+)" "{15}(%s)", float_string, float_string); regcomp(&full_matrix, bu_vls_addr(¤t_substring), REG_EXTENDED); - regcomp(&nonwhitespace_regex, "([^[:blank:]])", REG_EXTENDED); + regcomp(&nonwhitespace_regex, "([^[:space:]])", REG_EXTENDED); float_locations = (regmatch_t *)bu_calloc(full_matrix.re_nsub, sizeof(regmatch_t), "array to hold answers from regex"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <r_...@us...> - 2012-06-08 04:51:31
|
Revision: 51012 http://brlcad.svn.sourceforge.net/brlcad/?rev=51012&view=rev Author: r_weiss Date: 2012-06-08 04:51:25 +0000 (Fri, 08 Jun 2012) Log Message: ----------- Update to mged/archer 'red' command to improve reliability on windows. Added more type casting of arrays. Modified Paths: -------------- brlcad/trunk/src/libged/red.c Modified: brlcad/trunk/src/libged/red.c =================================================================== --- brlcad/trunk/src/libged/red.c 2012-06-08 04:39:56 UTC (rev 51011) +++ brlcad/trunk/src/libged/red.c 2012-06-08 04:51:25 UTC (rev 51012) @@ -40,7 +40,7 @@ char _ged_tmpfil[MAXPATHLEN] = {0}; static const char combseparator[] = "---------- Combination Tree ----------\n"; -static const char *combtree_header = "---*[[:space:]]*Combination Tree[[:space:]]*---*\r?\n"; +static const char combtree_header[] = "---*[[:space:]]*Combination Tree[[:space:]]*---*\r?\n"; static int @@ -93,7 +93,7 @@ int -_ged_find_matrix(struct ged *gedp, const char *currptr, int strlength, matp_t *matrix, int *name_end) +_ged_find_matrix(struct ged *gedp, const char (*currptr)[], int strlength, matp_t *matrix, int *name_end) { int ret = 1; regex_t matrix_entry, full_matrix, nonwhitespace_regex; @@ -101,8 +101,8 @@ struct bu_vls current_substring = BU_VLS_INIT_ZERO; struct bu_vls matrix_substring = BU_VLS_INIT_ZERO; int floatcnt, tail_start; - const char *floatptr; - const char *float_string = "[+-]?[0-9]*[.]?[0-9]+([eE][+-]?[0-9]+)?"; + const char (*floatptr)[]; + const char float_string[] = "[+-]?[0-9]*[.]?[0-9]+([eE][+-]?[0-9]+)?"; bu_vls_sprintf(¤t_substring, "(%s)", float_string); regcomp(&matrix_entry, bu_vls_addr(¤t_substring), REG_EXTENDED); @@ -121,7 +121,7 @@ float_locations[0].rm_so = 0; float_locations[0].rm_eo = strlength; while (floatcnt < 16 && floatcnt >= 0) { - if (regexec(&matrix_entry, currptr, matrix_entry.re_nsub, float_locations, REG_STARTEND) == 0) { + if (regexec(&matrix_entry, (const char *)currptr, matrix_entry.re_nsub, float_locations, REG_STARTEND) == 0) { /* matched */ floatcnt++; float_locations[0].rm_so = float_locations[0].rm_eo; @@ -134,26 +134,26 @@ /* Possible matrix - use matrix regex to locate it */ float_locations[0].rm_so = 0; float_locations[0].rm_eo = strlength; - if (regexec(&full_matrix, currptr, full_matrix.re_nsub, float_locations, REG_STARTEND) == 0) { + if (regexec(&full_matrix, (const char *)currptr, full_matrix.re_nsub, float_locations, REG_STARTEND) == 0) { /* matched */ bu_vls_trunc(&matrix_substring, 0); - bu_vls_strncpy(&matrix_substring, currptr + float_locations[0].rm_so, float_locations[0].rm_eo - float_locations[0].rm_so); + bu_vls_strncpy(&matrix_substring, (const char *)((char *)currptr + float_locations[0].rm_so), float_locations[0].rm_eo - float_locations[0].rm_so); *name_end = float_locations[0].rm_so; tail_start = float_locations[0].rm_eo; (*matrix) = (matp_t)bu_calloc(16, sizeof(fastf_t), "red: matrix"); - floatptr = bu_vls_addr(&matrix_substring); + floatptr = (const char (*)[])bu_vls_addr(&matrix_substring); floatcnt = 0; float_locations[0].rm_so = 0; float_locations[0].rm_eo = bu_vls_strlen(&matrix_substring); while (floatcnt < 16) { - if (regexec(&matrix_entry, floatptr, matrix_entry.re_nsub, float_locations, REG_STARTEND) == 0) { + if (regexec(&matrix_entry, (const char *)floatptr, matrix_entry.re_nsub, float_locations, REG_STARTEND) == 0) { /* matched */ bu_vls_trunc(¤t_substring, 0); - bu_vls_strncpy(¤t_substring, currptr + float_locations[0].rm_so, float_locations[0].rm_eo - float_locations[0].rm_so); - (*matrix)[floatcnt] = atof(floatptr); - floatptr = floatptr + float_locations[0].rm_eo; + bu_vls_strncpy(¤t_substring, (const char *)((char *)currptr + float_locations[0].rm_so), float_locations[0].rm_eo - float_locations[0].rm_so); + (*matrix)[floatcnt] = atof((char *)floatptr); + floatptr = (const char (*)[])((char *)floatptr + float_locations[0].rm_eo); float_locations[0].rm_so = 0; - float_locations[0].rm_eo = strlen(floatptr); + float_locations[0].rm_eo = strlen((char *)floatptr); floatcnt++; } else { bu_vls_sprintf(¤t_substring, "%s", floatptr); @@ -163,7 +163,7 @@ } bu_vls_free(&matrix_substring); bu_vls_trunc(¤t_substring, 0); - bu_vls_strncpy(¤t_substring, currptr + tail_start, strlength - tail_start - 1); + bu_vls_strncpy(¤t_substring, (const char *)((char *)currptr + tail_start), strlength - tail_start - 1); /* Need to check for non-whitespace in the distance-from-end zone */ if (regexec(&nonwhitespace_regex, bu_vls_addr(¤t_substring), nonwhitespace_regex.re_nsub, float_locations, 0) == 0) { /* matched */ @@ -204,8 +204,8 @@ int tree_index=0; struct rt_db_internal intern; struct rt_tree_array *rt_tree_array; - const char *currptr; - regex_t nonwhitespace_regex, attr_regex, combtree_regex, combtree_op_regex; + const char (*currptr)[]; + regex_t nonwhitespace_regex, attr_regex, combtree_regex, combtree_op_regex; regmatch_t *result_locations; struct bu_vls current_substring = BU_VLS_INIT_ZERO; struct bu_vls attr_vls = BU_VLS_INIT_ZERO; @@ -260,15 +260,15 @@ /* First thing, find the beginning of the tree definition. Without that, file is invalid. Even an empty comb must * include this header. */ - currptr = (const char *)(redtmpfile->buf); - ret = regexec(&combtree_regex, currptr, combtree_regex.re_nsub , result_locations, 0); + currptr = (const char (*)[])(redtmpfile->buf); + ret = regexec(&combtree_regex, (const char *)currptr, combtree_regex.re_nsub , result_locations, 0); if (ret == 0) { /* matched */ combtagstart = result_locations[0].rm_so; combtagend = result_locations[0].rm_eo; attrcumulative = 0; - if (regexec(&combtree_regex, currptr + combtagend, combtree_regex.re_nsub, result_locations, 0) == 0) { + if (regexec(&combtree_regex, (const char *)((char *)currptr + combtagend), combtree_regex.re_nsub, result_locations, 0) == 0) { /* matched */ bu_vls_printf(gedp->ged_result_str, "ERROR - multiple instances of comb tree header \"%s\" in temp file!", combtree_header); @@ -300,7 +300,7 @@ bu_avs_init_empty(&avs); while (attrcumulative < combtagstart - 1) { /* If attributes are present, the first line must match the attr regex - mult-line attribute names are not supported. */ - if (regexec(&attr_regex, currptr, attr_regex.re_nsub , result_locations, 0) != 0) { + if (regexec(&attr_regex, (const char *)currptr, attr_regex.re_nsub , result_locations, 0) != 0) { /* did NOT match */ bu_vls_printf(gedp->ged_result_str, "invalid attribute line\n"); @@ -326,7 +326,7 @@ attrstart = result_locations[0].rm_so; attrend = result_locations[0].rm_eo; attrcumulative += attrend; - if (regexec(&attr_regex, (const char *)(redtmpfile->buf) + attrcumulative, attr_regex.re_nsub , result_locations, 0) == 0) { + if (regexec(&attr_regex, (const char *)((char *)(redtmpfile->buf) + attrcumulative), attr_regex.re_nsub , result_locations, 0) == 0) { /* matched */ if (attrcumulative + result_locations[0].rm_eo < combtagstart) { @@ -341,7 +341,7 @@ attrcumulative = combtagstart; } bu_vls_trunc(¤t_substring, 0); - bu_vls_strncpy(¤t_substring, currptr + attrstart, attrend - attrstart); + bu_vls_strncpy(¤t_substring, (const char *)((char *)currptr + attrstart), attrend - attrstart); if (get_attr_val_pair(bu_vls_addr(¤t_substring), &attr_vls, &val_vls)) { if (BU_STR_EQUAL(bu_vls_addr(&attr_vls), "name")) { bu_vls_sprintf(target_name, "%s", bu_vls_addr(&val_vls)); @@ -349,7 +349,7 @@ if (!BU_STR_EQUAL(bu_vls_addr(&val_vls), "") && !BU_STR_EQUAL(bu_vls_addr(&attr_vls), "name")) (void)bu_avs_add(&avs, bu_vls_addr(&attr_vls), bu_vls_addr(&val_vls)); } - currptr = currptr + attrend; + currptr = (const char (*)[])((char *)currptr + attrend); } } @@ -360,25 +360,25 @@ /* Now, the comb tree. First, count the number of operators - without at least one, the comb tree is empty * and we need to know how many there are before allocating rt_tree_array memory. */ - currptr = (const char *)(redtmpfile->buf) + combtagend; + currptr = (const char (*)[])((char *)(redtmpfile->buf) + combtagend); node_count = 0; - ret = regexec(&combtree_op_regex, currptr, combtree_op_regex.re_nsub , result_locations, 0); + ret = regexec(&combtree_op_regex, (const char *)currptr, combtree_op_regex.re_nsub , result_locations, 0); while (ret == 0) { - currptr = currptr + result_locations[0].rm_eo; - ret = regexec(&combtree_op_regex, currptr, combtree_op_regex.re_nsub , result_locations, 0); + currptr = (const char (*)[])((char *)currptr + result_locations[0].rm_eo); + ret = regexec(&combtree_op_regex, (const char *)currptr, combtree_op_regex.re_nsub , result_locations, 0); node_count++; } - currptr = (const char *)(redtmpfile->buf) + combtagend + 1; + currptr = (const char (*)[])((char *)(redtmpfile->buf) + combtagend + 1); name_end = 0; - ret = regexec(&combtree_op_regex, currptr, combtree_op_regex.re_nsub , result_locations, 0); + ret = regexec(&combtree_op_regex, (const char *)currptr, combtree_op_regex.re_nsub , result_locations, 0); if (ret == 0) { /* matched */ /* Check for non-whitespace garbage between first operator and start of comb tree definition */ result_locations[0].rm_eo = result_locations[0].rm_so; result_locations[0].rm_so = 0; - if (regexec(&nonwhitespace_regex, currptr, nonwhitespace_regex.re_nsub, result_locations, REG_STARTEND) == 0) { + if (regexec(&nonwhitespace_regex, (const char *)currptr, nonwhitespace_regex.re_nsub, result_locations, REG_STARTEND) == 0) { /* matched */ bu_vls_printf(gedp->ged_result_str, "Saw something other than comb tree entries after comb tree tag - error!\n"); @@ -395,27 +395,27 @@ return GED_ERROR; } - ret = regexec(&combtree_op_regex, currptr, combtree_op_regex.re_nsub , result_locations, 0); + ret = regexec(&combtree_op_regex, (const char *)currptr, combtree_op_regex.re_nsub , result_locations, 0); bu_vls_trunc(&next_op_vls, 0); - bu_vls_strncpy(&next_op_vls, currptr + result_locations[0].rm_so, result_locations[0].rm_eo - result_locations[0].rm_so); + bu_vls_strncpy(&next_op_vls, (const char *)((char *)currptr + result_locations[0].rm_so), result_locations[0].rm_eo - result_locations[0].rm_so); bu_vls_trimspace(&next_op_vls); - currptr = currptr + result_locations[0].rm_eo; + currptr = (const char (*)[])((char *)currptr + result_locations[0].rm_eo); rt_tree_array = (struct rt_tree_array *)bu_calloc(node_count, sizeof(struct rt_tree_array), "tree list"); /* As long as we have operators ahead of us in the tree, we have comb entries to handle */ while (ret == 0) { - ret = regexec(&combtree_op_regex, currptr, combtree_op_regex.re_nsub , result_locations, 0); + ret = regexec(&combtree_op_regex, (const char *)currptr, combtree_op_regex.re_nsub , result_locations, 0); bu_vls_sprintf(&curr_op_vls, "%s", bu_vls_addr(&next_op_vls)); if (ret == 0) { /* matched */ bu_vls_trunc(&next_op_vls, 0); - bu_vls_strncpy(&next_op_vls, currptr + result_locations[0].rm_so, result_locations[0].rm_eo - result_locations[0].rm_so); + bu_vls_strncpy(&next_op_vls, (const char *)((char *)currptr + result_locations[0].rm_so), result_locations[0].rm_eo - result_locations[0].rm_so); bu_vls_trimspace(&next_op_vls); name_end = result_locations[0].rm_so; } else { - name_end = strlen(currptr); + name_end = strlen((char *)currptr); } bu_vls_trunc(¤t_substring, 0); - bu_vls_strncpy(¤t_substring, currptr, name_end); + bu_vls_strncpy(¤t_substring, (char *)currptr, name_end); if (!bu_vls_strlen(¤t_substring)) { bu_vls_printf(gedp->ged_result_str, "Zero length substring\n"); bu_vls_free(¤t_substring); @@ -453,9 +453,9 @@ } } bu_vls_trunc(¤t_substring, 0); - bu_vls_strncpy(¤t_substring, currptr, name_end); + bu_vls_strncpy(¤t_substring, (char *)currptr, name_end); bu_vls_trimspace(¤t_substring); - currptr = currptr + result_locations[0].rm_eo; + currptr = (const char (*)[])((char *)currptr + result_locations[0].rm_eo); if (bu_vls_addr(&curr_op_vls)[0] != '-') nonsubs++; @@ -828,7 +828,7 @@ /* Make a file for the text editor, stash name in _ged_tmpfil */ fp = bu_temp_file(_ged_tmpfil, MAXPATHLEN); - if (fp == (FILE *)0) { + if (fp == (FILE *)0) { bu_vls_printf(gedp->ged_result_str, "Unable to edit %s\n", argv[1]); bu_vls_printf(gedp->ged_result_str, "Unable to create %s\n", _ged_tmpfil); bu_vls_free(&comb_name); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <br...@us...> - 2012-06-15 19:19:31
|
Revision: 51175 http://brlcad.svn.sourceforge.net/brlcad/?rev=51175&view=rev Author: brlcad Date: 2012-06-15 19:19:24 +0000 (Fri, 15 Jun 2012) Log Message: ----------- revert r51012. it's unclear how the comment is true, improving reliability on Windows, because the casts are not right. they describe an array of character pointers (char*[]), but then that's repeatedly used as a 'char *' with casts forced everywhere. needing casts pervasively like that is a sign something is fundamentally wrong. casts should be rare. Revision Links: -------------- http://brlcad.svn.sourceforge.net/brlcad/?rev=51012&view=rev Modified Paths: -------------- brlcad/trunk/src/libged/red.c Modified: brlcad/trunk/src/libged/red.c =================================================================== --- brlcad/trunk/src/libged/red.c 2012-06-15 19:11:41 UTC (rev 51174) +++ brlcad/trunk/src/libged/red.c 2012-06-15 19:19:24 UTC (rev 51175) @@ -40,7 +40,7 @@ char _ged_tmpfil[MAXPATHLEN] = {0}; static const char combseparator[] = "---------- Combination Tree ----------\n"; -static const char combtree_header[] = "---*[[:space:]]*Combination Tree[[:space:]]*---*\r?\n"; +static const char *combtree_header = "---*[[:space:]]*Combination Tree[[:space:]]*---*\r?\n"; static int @@ -93,7 +93,7 @@ int -_ged_find_matrix(struct ged *gedp, const char (*currptr)[], int strlength, matp_t *matrix, int *name_end) +_ged_find_matrix(struct ged *gedp, const char *currptr, int strlength, matp_t *matrix, int *name_end) { int ret = 1; regex_t matrix_entry, full_matrix, nonwhitespace_regex; @@ -101,8 +101,8 @@ struct bu_vls current_substring = BU_VLS_INIT_ZERO; struct bu_vls matrix_substring = BU_VLS_INIT_ZERO; int floatcnt, tail_start; - const char (*floatptr)[]; - const char float_string[] = "[+-]?[0-9]*[.]?[0-9]+([eE][+-]?[0-9]+)?"; + const char *floatptr; + const char *float_string = "[+-]?[0-9]*[.]?[0-9]+([eE][+-]?[0-9]+)?"; bu_vls_sprintf(¤t_substring, "(%s)", float_string); regcomp(&matrix_entry, bu_vls_addr(¤t_substring), REG_EXTENDED); @@ -121,7 +121,7 @@ float_locations[0].rm_so = 0; float_locations[0].rm_eo = strlength; while (floatcnt < 16 && floatcnt >= 0) { - if (regexec(&matrix_entry, (const char *)currptr, matrix_entry.re_nsub, float_locations, REG_STARTEND) == 0) { + if (regexec(&matrix_entry, currptr, matrix_entry.re_nsub, float_locations, REG_STARTEND) == 0) { /* matched */ floatcnt++; float_locations[0].rm_so = float_locations[0].rm_eo; @@ -134,26 +134,26 @@ /* Possible matrix - use matrix regex to locate it */ float_locations[0].rm_so = 0; float_locations[0].rm_eo = strlength; - if (regexec(&full_matrix, (const char *)currptr, full_matrix.re_nsub, float_locations, REG_STARTEND) == 0) { + if (regexec(&full_matrix, currptr, full_matrix.re_nsub, float_locations, REG_STARTEND) == 0) { /* matched */ bu_vls_trunc(&matrix_substring, 0); - bu_vls_strncpy(&matrix_substring, (const char *)((char *)currptr + float_locations[0].rm_so), float_locations[0].rm_eo - float_locations[0].rm_so); + bu_vls_strncpy(&matrix_substring, currptr + float_locations[0].rm_so, float_locations[0].rm_eo - float_locations[0].rm_so); *name_end = float_locations[0].rm_so; tail_start = float_locations[0].rm_eo; (*matrix) = (matp_t)bu_calloc(16, sizeof(fastf_t), "red: matrix"); - floatptr = (const char (*)[])bu_vls_addr(&matrix_substring); + floatptr = bu_vls_addr(&matrix_substring); floatcnt = 0; float_locations[0].rm_so = 0; float_locations[0].rm_eo = bu_vls_strlen(&matrix_substring); while (floatcnt < 16) { - if (regexec(&matrix_entry, (const char *)floatptr, matrix_entry.re_nsub, float_locations, REG_STARTEND) == 0) { + if (regexec(&matrix_entry, floatptr, matrix_entry.re_nsub, float_locations, REG_STARTEND) == 0) { /* matched */ bu_vls_trunc(¤t_substring, 0); - bu_vls_strncpy(¤t_substring, (const char *)((char *)currptr + float_locations[0].rm_so), float_locations[0].rm_eo - float_locations[0].rm_so); - (*matrix)[floatcnt] = atof((char *)floatptr); - floatptr = (const char (*)[])((char *)floatptr + float_locations[0].rm_eo); + bu_vls_strncpy(¤t_substring, currptr + float_locations[0].rm_so, float_locations[0].rm_eo - float_locations[0].rm_so); + (*matrix)[floatcnt] = atof(floatptr); + floatptr = floatptr + float_locations[0].rm_eo; float_locations[0].rm_so = 0; - float_locations[0].rm_eo = strlen((char *)floatptr); + float_locations[0].rm_eo = strlen(floatptr); floatcnt++; } else { bu_vls_sprintf(¤t_substring, "%s", floatptr); @@ -163,7 +163,7 @@ } bu_vls_free(&matrix_substring); bu_vls_trunc(¤t_substring, 0); - bu_vls_strncpy(¤t_substring, (const char *)((char *)currptr + tail_start), strlength - tail_start - 1); + bu_vls_strncpy(¤t_substring, currptr + tail_start, strlength - tail_start - 1); /* Need to check for non-whitespace in the distance-from-end zone */ if (regexec(&nonwhitespace_regex, bu_vls_addr(¤t_substring), nonwhitespace_regex.re_nsub, float_locations, 0) == 0) { /* matched */ @@ -204,8 +204,8 @@ int tree_index=0; struct rt_db_internal intern; struct rt_tree_array *rt_tree_array; - const char (*currptr)[]; - regex_t nonwhitespace_regex, attr_regex, combtree_regex, combtree_op_regex; + const char *currptr; + regex_t nonwhitespace_regex, attr_regex, combtree_regex, combtree_op_regex; regmatch_t *result_locations; struct bu_vls current_substring = BU_VLS_INIT_ZERO; struct bu_vls attr_vls = BU_VLS_INIT_ZERO; @@ -260,15 +260,15 @@ /* First thing, find the beginning of the tree definition. Without that, file is invalid. Even an empty comb must * include this header. */ - currptr = (const char (*)[])(redtmpfile->buf); - ret = regexec(&combtree_regex, (const char *)currptr, combtree_regex.re_nsub , result_locations, 0); + currptr = (const char *)(redtmpfile->buf); + ret = regexec(&combtree_regex, currptr, combtree_regex.re_nsub , result_locations, 0); if (ret == 0) { /* matched */ combtagstart = result_locations[0].rm_so; combtagend = result_locations[0].rm_eo; attrcumulative = 0; - if (regexec(&combtree_regex, (const char *)((char *)currptr + combtagend), combtree_regex.re_nsub, result_locations, 0) == 0) { + if (regexec(&combtree_regex, currptr + combtagend, combtree_regex.re_nsub, result_locations, 0) == 0) { /* matched */ bu_vls_printf(gedp->ged_result_str, "ERROR - multiple instances of comb tree header \"%s\" in temp file!", combtree_header); @@ -300,7 +300,7 @@ bu_avs_init_empty(&avs); while (attrcumulative < combtagstart - 1) { /* If attributes are present, the first line must match the attr regex - mult-line attribute names are not supported. */ - if (regexec(&attr_regex, (const char *)currptr, attr_regex.re_nsub , result_locations, 0) != 0) { + if (regexec(&attr_regex, currptr, attr_regex.re_nsub , result_locations, 0) != 0) { /* did NOT match */ bu_vls_printf(gedp->ged_result_str, "invalid attribute line\n"); @@ -326,7 +326,7 @@ attrstart = result_locations[0].rm_so; attrend = result_locations[0].rm_eo; attrcumulative += attrend; - if (regexec(&attr_regex, (const char *)((char *)(redtmpfile->buf) + attrcumulative), attr_regex.re_nsub , result_locations, 0) == 0) { + if (regexec(&attr_regex, (const char *)(redtmpfile->buf) + attrcumulative, attr_regex.re_nsub , result_locations, 0) == 0) { /* matched */ if (attrcumulative + result_locations[0].rm_eo < combtagstart) { @@ -341,7 +341,7 @@ attrcumulative = combtagstart; } bu_vls_trunc(¤t_substring, 0); - bu_vls_strncpy(¤t_substring, (const char *)((char *)currptr + attrstart), attrend - attrstart); + bu_vls_strncpy(¤t_substring, currptr + attrstart, attrend - attrstart); if (get_attr_val_pair(bu_vls_addr(¤t_substring), &attr_vls, &val_vls)) { if (BU_STR_EQUAL(bu_vls_addr(&attr_vls), "name")) { bu_vls_sprintf(target_name, "%s", bu_vls_addr(&val_vls)); @@ -349,7 +349,7 @@ if (!BU_STR_EQUAL(bu_vls_addr(&val_vls), "") && !BU_STR_EQUAL(bu_vls_addr(&attr_vls), "name")) (void)bu_avs_add(&avs, bu_vls_addr(&attr_vls), bu_vls_addr(&val_vls)); } - currptr = (const char (*)[])((char *)currptr + attrend); + currptr = currptr + attrend; } } @@ -360,25 +360,25 @@ /* Now, the comb tree. First, count the number of operators - without at least one, the comb tree is empty * and we need to know how many there are before allocating rt_tree_array memory. */ - currptr = (const char (*)[])((char *)(redtmpfile->buf) + combtagend); + currptr = (const char *)(redtmpfile->buf) + combtagend; node_count = 0; - ret = regexec(&combtree_op_regex, (const char *)currptr, combtree_op_regex.re_nsub , result_locations, 0); + ret = regexec(&combtree_op_regex, currptr, combtree_op_regex.re_nsub , result_locations, 0); while (ret == 0) { - currptr = (const char (*)[])((char *)currptr + result_locations[0].rm_eo); - ret = regexec(&combtree_op_regex, (const char *)currptr, combtree_op_regex.re_nsub , result_locations, 0); + currptr = currptr + result_locations[0].rm_eo; + ret = regexec(&combtree_op_regex, currptr, combtree_op_regex.re_nsub , result_locations, 0); node_count++; } - currptr = (const char (*)[])((char *)(redtmpfile->buf) + combtagend + 1); + currptr = (const char *)(redtmpfile->buf) + combtagend + 1; name_end = 0; - ret = regexec(&combtree_op_regex, (const char *)currptr, combtree_op_regex.re_nsub , result_locations, 0); + ret = regexec(&combtree_op_regex, currptr, combtree_op_regex.re_nsub , result_locations, 0); if (ret == 0) { /* matched */ /* Check for non-whitespace garbage between first operator and start of comb tree definition */ result_locations[0].rm_eo = result_locations[0].rm_so; result_locations[0].rm_so = 0; - if (regexec(&nonwhitespace_regex, (const char *)currptr, nonwhitespace_regex.re_nsub, result_locations, REG_STARTEND) == 0) { + if (regexec(&nonwhitespace_regex, currptr, nonwhitespace_regex.re_nsub, result_locations, REG_STARTEND) == 0) { /* matched */ bu_vls_printf(gedp->ged_result_str, "Saw something other than comb tree entries after comb tree tag - error!\n"); @@ -395,27 +395,27 @@ return GED_ERROR; } - ret = regexec(&combtree_op_regex, (const char *)currptr, combtree_op_regex.re_nsub , result_locations, 0); + ret = regexec(&combtree_op_regex, currptr, combtree_op_regex.re_nsub , result_locations, 0); bu_vls_trunc(&next_op_vls, 0); - bu_vls_strncpy(&next_op_vls, (const char *)((char *)currptr + result_locations[0].rm_so), result_locations[0].rm_eo - result_locations[0].rm_so); + bu_vls_strncpy(&next_op_vls, currptr + result_locations[0].rm_so, result_locations[0].rm_eo - result_locations[0].rm_so); bu_vls_trimspace(&next_op_vls); - currptr = (const char (*)[])((char *)currptr + result_locations[0].rm_eo); + currptr = currptr + result_locations[0].rm_eo; rt_tree_array = (struct rt_tree_array *)bu_calloc(node_count, sizeof(struct rt_tree_array), "tree list"); /* As long as we have operators ahead of us in the tree, we have comb entries to handle */ while (ret == 0) { - ret = regexec(&combtree_op_regex, (const char *)currptr, combtree_op_regex.re_nsub , result_locations, 0); + ret = regexec(&combtree_op_regex, currptr, combtree_op_regex.re_nsub , result_locations, 0); bu_vls_sprintf(&curr_op_vls, "%s", bu_vls_addr(&next_op_vls)); if (ret == 0) { /* matched */ bu_vls_trunc(&next_op_vls, 0); - bu_vls_strncpy(&next_op_vls, (const char *)((char *)currptr + result_locations[0].rm_so), result_locations[0].rm_eo - result_locations[0].rm_so); + bu_vls_strncpy(&next_op_vls, currptr + result_locations[0].rm_so, result_locations[0].rm_eo - result_locations[0].rm_so); bu_vls_trimspace(&next_op_vls); name_end = result_locations[0].rm_so; } else { - name_end = strlen((char *)currptr); + name_end = strlen(currptr); } bu_vls_trunc(¤t_substring, 0); - bu_vls_strncpy(¤t_substring, (char *)currptr, name_end); + bu_vls_strncpy(¤t_substring, currptr, name_end); if (!bu_vls_strlen(¤t_substring)) { bu_vls_printf(gedp->ged_result_str, "Zero length substring\n"); bu_vls_free(¤t_substring); @@ -453,9 +453,9 @@ } } bu_vls_trunc(¤t_substring, 0); - bu_vls_strncpy(¤t_substring, (char *)currptr, name_end); + bu_vls_strncpy(¤t_substring, currptr, name_end); bu_vls_trimspace(¤t_substring); - currptr = (const char (*)[])((char *)currptr + result_locations[0].rm_eo); + currptr = currptr + result_locations[0].rm_eo; if (bu_vls_addr(&curr_op_vls)[0] != '-') nonsubs++; @@ -828,7 +828,7 @@ /* Make a file for the text editor, stash name in _ged_tmpfil */ fp = bu_temp_file(_ged_tmpfil, MAXPATHLEN); - if (fp == (FILE *)0) { + if (fp == (FILE *)0) { bu_vls_printf(gedp->ged_result_str, "Unable to edit %s\n", argv[1]); bu_vls_printf(gedp->ged_result_str, "Unable to create %s\n", _ged_tmpfil); bu_vls_free(&comb_name); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <r_...@us...> - 2012-07-20 16:01:11
|
Revision: 51623 http://brlcad.svn.sourceforge.net/brlcad/?rev=51623&view=rev Author: r_weiss Date: 2012-07-20 16:01:05 +0000 (Fri, 20 Jul 2012) Log Message: ----------- Update to file "red.c" functions "_ged_find_matrix" and "ged_red". Fixed a problem with the regular expression reading a matrix and added code to save error messages deleted by functions "ged_kill" and "ged_move". Modified Paths: -------------- brlcad/trunk/src/libged/red.c Modified: brlcad/trunk/src/libged/red.c =================================================================== --- brlcad/trunk/src/libged/red.c 2012-07-20 16:00:19 UTC (rev 51622) +++ brlcad/trunk/src/libged/red.c 2012-07-20 16:01:05 UTC (rev 51623) @@ -104,7 +104,7 @@ const char *floatptr; const char *float_string = "[+-]?[0-9]*[.]?[0-9]+([eE][+-]?[0-9]+)?"; - bu_vls_sprintf(¤t_substring, "(%s)", float_string); + bu_vls_sprintf(¤t_substring, "(%s[[:space:]]+)", float_string); regcomp(&matrix_entry, bu_vls_addr(¤t_substring), REG_EXTENDED); bu_vls_sprintf(¤t_substring, /* broken into two strings so auto-formatting @@ -749,6 +749,7 @@ struct bu_vls comb_name = BU_VLS_INIT_ZERO; struct bu_vls temp_name = BU_VLS_INIT_ZERO; struct bu_vls final_name = BU_VLS_INIT_ZERO; + struct bu_vls tmp_ged_result_str = BU_VLS_INIT_ZERO; int force_flag = 0; GED_CHECK_DATABASE_OPEN(gedp, GED_ERROR); @@ -903,11 +904,17 @@ bu_vls_printf(gedp->ged_result_str, "Problem in edited region, no changes made\n"); + /* save ged_result_str */ + bu_vls_sprintf(&tmp_ged_result_str, "%s", bu_vls_addr(gedp->ged_result_str)); + av[0] = "kill"; av[1] = bu_vls_addr(&temp_name); av[2] = NULL; (void)ged_kill(gedp, 2, (const char **)av); + /* restore ged_result_str */ + bu_vls_printf(gedp->ged_result_str, "%s", bu_vls_addr(&tmp_ged_result_str)); + goto cleanup; } @@ -923,7 +930,15 @@ av[0] = "kill"; av[1] = bu_vls_addr(&final_name); av[2] = NULL; + + /* save ged_result_str */ + bu_vls_sprintf(&tmp_ged_result_str, "%s", bu_vls_addr(gedp->ged_result_str)); + (void)ged_kill(gedp, 2, (const char **)av); + + /* restore ged_result_str */ + bu_vls_printf(gedp->ged_result_str, "%s", bu_vls_addr(&tmp_ged_result_str)); + } else { /* not forced, can't overwrite destination, can't proceed */ bu_vls_printf(gedp->ged_result_str, "%s already exists\n", bu_vls_addr(&final_name)); @@ -948,14 +963,27 @@ av[0] = "kill"; av[1] = bu_vls_addr(&comb_name); av[2] = NULL; + + /* save ged_result_str */ + bu_vls_sprintf(&tmp_ged_result_str, "%s", bu_vls_addr(gedp->ged_result_str)); + (void)ged_kill(gedp, 2, (const char **)av); + + /* restore ged_result_str */ + bu_vls_printf(gedp->ged_result_str, "%s", bu_vls_addr(&tmp_ged_result_str)); } } av[0] = "mv"; av[1] = bu_vls_addr(&temp_name); av[2] = bu_vls_addr(&final_name); + + /* save ged_result_str */ + bu_vls_sprintf(&tmp_ged_result_str, "%s", bu_vls_addr(gedp->ged_result_str)); + (void)ged_move(gedp, 3, (const char **)av); + /* restore ged_result_str */ + bu_vls_printf(gedp->ged_result_str, "%s", bu_vls_addr(&tmp_ged_result_str)); } /* if we have reached cleanup by now, everything was fine */ ret = GED_OK; @@ -966,6 +994,7 @@ bu_vls_free(&final_name); bu_vls_free(&comb_name); bu_vls_free(&temp_name); + bu_vls_free(&tmp_ged_result_str); return ret; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <r_...@us...> - 2013-04-19 21:38:37
|
Revision: 55199 http://brlcad.svn.sourceforge.net/brlcad/?rev=55199&view=rev Author: r_weiss Date: 2013-04-19 21:38:30 +0000 (Fri, 19 Apr 2013) Log Message: ----------- Bug fix for mged "red" command which was preventing the temp file to be opened in the native text editor on Windows 64bit. Modified Paths: -------------- brlcad/trunk/src/libged/red.c Modified: brlcad/trunk/src/libged/red.c =================================================================== --- brlcad/trunk/src/libged/red.c 2013-04-19 21:35:51 UTC (rev 55198) +++ brlcad/trunk/src/libged/red.c 2013-04-19 21:38:30 UTC (rev 55199) @@ -837,6 +837,9 @@ return GED_ERROR; } + /* Close the temp file since 'write_comb' opens it. */ + (void)fclose(fp); + /* Write the combination components to the file */ if (write_comb(gedp, comb, argv[1])) { bu_vls_printf(gedp->ged_result_str, "Unable to edit %s\n", argv[1]); @@ -844,6 +847,9 @@ goto cleanup; } + /* Close the temp file so it will be written to disk. The temp file now + * contains the data for the combination which is to then be edited. + */ (void)fclose(fp); /* Edit the file */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <r_...@us...> - 2013-04-22 14:34:37
|
Revision: 55202 http://brlcad.svn.sourceforge.net/brlcad/?rev=55202&view=rev Author: r_weiss Date: 2013-04-22 14:34:30 +0000 (Mon, 22 Apr 2013) Log Message: ----------- Bug fix in mged 'red' command to fix a double 'fclose'. Modified Paths: -------------- brlcad/trunk/src/libged/red.c Modified: brlcad/trunk/src/libged/red.c =================================================================== --- brlcad/trunk/src/libged/red.c 2013-04-22 14:09:08 UTC (rev 55201) +++ brlcad/trunk/src/libged/red.c 2013-04-22 14:34:30 UTC (rev 55202) @@ -843,15 +843,9 @@ /* Write the combination components to the file */ if (write_comb(gedp, comb, argv[1])) { bu_vls_printf(gedp->ged_result_str, "Unable to edit %s\n", argv[1]); - (void)fclose(fp); goto cleanup; } - /* Close the temp file so it will be written to disk. The temp file now - * contains the data for the combination which is to then be edited. - */ - (void)fclose(fp); - /* Edit the file */ if (_ged_editit(editstring, _ged_tmpfil)) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <br...@us...> - 2014-09-18 20:01:07
|
Revision: 62844 http://sourceforge.net/p/brlcad/code/62844 Author: brlcad Date: 2014-09-18 20:01:02 +0000 (Thu, 18 Sep 2014) Log Message: ----------- eliminate dead debuggin code Modified Paths: -------------- brlcad/trunk/src/libged/red.c Modified: brlcad/trunk/src/libged/red.c =================================================================== --- brlcad/trunk/src/libged/red.c 2014-09-18 20:00:20 UTC (rev 62843) +++ brlcad/trunk/src/libged/red.c 2014-09-18 20:01:02 UTC (rev 62844) @@ -520,33 +520,6 @@ bu_free(result_locations, "free regex results array\n"); bu_close_mapped_file(redtmpfile); -/* Debugging print stuff */ -/* - bu_avs_print(&avs, "Regex based avs build\n"); - printf("\n"); - int i, m; - fastf_t tmp; - for (i = 0; i < tree_index; i++) { - char op; - - switch (rt_tree_array[i].tl_op) { - case OP_UNION: - op = DB_OP_UNION; - break; - case OP_INTERSECT: - op = DB_OP_INTERSECT; - break; - case OP_SUBTRACT: - op = DB_OP_SUBTRACT; - break; - default: - printf("write_comb: Illegal op code in tree\n"); - } - printf(" %c %s\n", op, rt_tree_array[i].tl_tree->tr_l.tl_name); - bn_mat_print("in rt_tree_array", rt_tree_array[i].tl_tree->tr_l.tl_mat); - printf("\n"); - } -*/ if (nonsubs == 0 && node_count) { bu_vls_printf(gedp->ged_result_str, "Cannot create a combination with all subtraction operators\n"); bu_avs_free(&avs); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sta...@us...> - 2010-05-06 18:27:25
|
Revision: 39052 http://brlcad.svn.sourceforge.net/brlcad/?rev=39052&view=rev Author: starseeker Date: 2010-05-06 18:27:18 +0000 (Thu, 06 May 2010) Log Message: ----------- Make the red command display all attributes, and preserve them when the editor is closed. Previously the make-a-copy-and-apply-attributes-from-file approach was dumping any attributes not recognized and loaded by red, which included any attribute except the 'standard' attributes Modified Paths: -------------- brlcad/trunk/src/libged/red.c Modified: brlcad/trunk/src/libged/red.c =================================================================== --- brlcad/trunk/src/libged/red.c 2010-05-06 18:13:07 UTC (rev 39051) +++ brlcad/trunk/src/libged/red.c 2010-05-06 18:27:18 UTC (rev 39052) @@ -69,7 +69,36 @@ return(ptr2); } +static int +get_attr_val_pair(char *line, struct bu_vls *attr, struct bu_vls *val) +{ + char *ptr1; + size_t j; + /* find the '=' */ + ptr1 = strchr(&line[0], '='); + if (!ptr1) + return 0; + + /* Everything from the beginning to the = is the attribute name*/ + bu_vls_strncpy(attr, line, ptr1 - &line[0]); + + /* skip any white space before the value */ + ++ptr1; + while (isspace(*(++ptr1))); + + /* eliminate trailing white space */ + j = strlen(line); + while (isspace(line[--j])); + line[j+1] = '\0'; + + /* Grab the attribute value */ + bu_vls_strcpy(val, ptr1); + + return 1; +} + + static int check_comb(struct ged *gedp) { @@ -412,8 +441,13 @@ union tree *tp; matp_t matrix; int ret=0; + struct bu_vls attr_vls; + struct bu_vls val_vls; + struct bu_attribute_value_set avs; + struct bu_attribute_value_pair *avpp; - if (gedp->ged_wdbp->dbip == DBI_NULL) + + if (gedp->ged_wdbp->dbip == DBI_NULL) return GED_OK; if (comb) { @@ -426,6 +460,10 @@ return GED_ERROR; } + bu_vls_init(&attr_vls); + bu_vls_init(&val_vls); + bu_avs_init_empty(&avs); + /* empty the existing combination */ if (comb && comb->tree) { db_free_tree(comb->tree, &rt_uniresource); @@ -570,8 +608,12 @@ else comb->inherit = 0; continue; - } else if (!strncmp(&line[i], "COMBINATION:", 12)) + } else if (!strncmp(&line[i], "COMBINATION:", 12)) { + get_attr_val_pair(line, &attr_vls, &val_vls); + (void)bu_avs_add(&avs, bu_vls_addr(&attr_vls), bu_vls_addr(&val_vls)); + db5_update_attributes(dp, &avs, gedp->ged_wdbp->dbip); continue; + } done2=0; ptr = strtok(line, _delims); @@ -629,6 +671,9 @@ if (rt_tree_array) bu_free((char *)rt_tree_array, "red: tree list"); fclose(fp); + bu_vls_free(&attr_vls); + bu_vls_free(&val_vls); + bu_avs_free(&avs); return(1); } matrix[k] = atof(ptr); @@ -677,6 +722,9 @@ bu_free(new_name, "new_name"); } + bu_vls_free(&attr_vls); + bu_vls_free(&val_vls); + bu_avs_free(&avs); return ret; } @@ -708,11 +756,18 @@ { /* Writes the file for later editing */ struct rt_tree_array *rt_tree_array; + struct bu_attribute_value_set avs; + struct bu_attribute_value_pair *avpp; + struct directory *dp; FILE *fp; int i; int node_count; int actual_count; + bu_avs_init_empty(&avs); + + GED_DB_LOOKUP(gedp, dp, name, LOOKUP_QUIET, GED_ERROR); + if (comb) RT_CK_COMB(comb); @@ -787,6 +842,21 @@ else fprintf(fp, "INHERIT=No\n"); + if (!db5_get_attributes(gedp->ged_wdbp->dbip, &avs, dp)) { + /* Print out any non-standard attributes - region and region_id + * are case insensitive as far as key properties being set, need + * to check if this is true for the rest of them. + */ + avpp = avs.avp; + for (i=0; i < avs.count; i++, avpp++) { + if ((strcasecmp(avpp->name, "REGION")) && (strcasecmp(avpp->name, "REGION_ID")) && + (strcmp(avpp->name, "AIRCODE")) && (strcmp(avpp->name, "GIFT_MATERIAL")) && + (strcmp(avpp->name, "LOS")) && (strcmp(avpp->name, "COLOR")) && + (strcmp(avpp->name, "SHADER")) && (strcmp(avpp->name, "INHERIT"))) + fprintf(fp, "%s=%s\n", avpp->name, avpp->value); + } + } + fprintf(fp, "COMBINATION:\n"); for (i=0; i<actual_count; i++) { @@ -805,18 +875,21 @@ default: bu_vls_printf(&gedp->ged_result_str, "write_comb: Illegal op code in tree\n"); fclose(fp); + bu_avs_free(&avs); return GED_ERROR; } if (fprintf(fp, " %c %s", op, rt_tree_array[i].tl_tree->tr_l.tl_name) <= 0) { bu_vls_printf(&gedp->ged_result_str, "write_comb: Cannot write to temporary file (%s). Aborting edit\n", _ged_tmpfil); fclose(fp); + bu_avs_free(&avs); return GED_ERROR; } _ged_print_matrix(fp, rt_tree_array[i].tl_tree->tr_l.tl_mat); fprintf(fp, "\n"); } fclose(fp); + bu_avs_free(&avs); return GED_OK; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <br...@us...> - 2018-02-26 20:06:35
|
Revision: 70751 http://sourceforge.net/p/brlcad/code/70751 Author: brlcad Date: 2018-02-26 20:06:32 +0000 (Mon, 26 Feb 2018) Log Message: ----------- REG_STARTEND isn't POSIX.2 so try to rework the code. of the four places using REG_STARTEND in regexec(), it doesn't look like three actually need it since they scanned from so=0. however, one did so we try a rewrite which increments the string offset. Modified Paths: -------------- brlcad/trunk/src/libged/red.c Modified: brlcad/trunk/src/libged/red.c =================================================================== --- brlcad/trunk/src/libged/red.c 2018-02-26 18:20:10 UTC (rev 70750) +++ brlcad/trunk/src/libged/red.c 2018-02-26 20:06:32 UTC (rev 70751) @@ -41,6 +41,7 @@ #include "./ged_private.h" + /* also accessed by put_comb.c */ char _ged_tmpfil[MAXPATHLEN] = {0}; @@ -101,6 +102,7 @@ _ged_find_matrix(struct ged *gedp, const char *currptr, int strlength, matp_t *matrix, int *name_end) { int ret = 1; + int rret = 0; regex_t matrix_entry, full_matrix, nonwhitespace_regex; regmatch_t *float_locations; struct bu_vls current_substring = BU_VLS_INIT_ZERO; @@ -108,6 +110,9 @@ int floatcnt, tail_start; const char *floatptr; const char *float_string = "[+-]?[0-9]*[.]?[0-9]+([eE][+-]?[0-9]+)?"; +#ifndef REG_STARTEND + int skip = 0; +#endif bu_vls_sprintf(¤t_substring, "(%s[[:space:]]+)", float_string); regcomp(&matrix_entry, bu_vls_addr(¤t_substring), REG_EXTENDED); @@ -126,9 +131,17 @@ float_locations[0].rm_so = 0; float_locations[0].rm_eo = strlength; while (floatcnt < 16 && floatcnt >= 0) { - if (regexec(&matrix_entry, currptr, matrix_entry.re_nsub, float_locations, REG_STARTEND) == 0) { +#ifdef REG_STARTEND + rret = regexec(&matrix_entry, currptr, matrix_entry.re_nsub, float_locations, REG_STARTEND); +#else + rret = regexec(&matrix_entry, currptr+skip, matrix_entry.re_nsub, float_locations, 0); +#endif + if (rret == 0) { /* matched */ floatcnt++; +#ifndef REG_STARTEND + skip += float_locations[0].rm_eo; +#endif float_locations[0].rm_so = float_locations[0].rm_eo; float_locations[0].rm_eo = strlength; } else { @@ -139,7 +152,7 @@ /* Possible matrix - use matrix regex to locate it */ float_locations[0].rm_so = 0; float_locations[0].rm_eo = strlength; - if (regexec(&full_matrix, currptr, full_matrix.re_nsub, float_locations, REG_STARTEND) == 0) { + if (regexec(&full_matrix, currptr, full_matrix.re_nsub, float_locations, 0) == 0) { /* matched */ bu_vls_trunc(&matrix_substring, 0); bu_vls_strncpy(&matrix_substring, currptr + float_locations[0].rm_so, float_locations[0].rm_eo - float_locations[0].rm_so); @@ -151,7 +164,8 @@ float_locations[0].rm_so = 0; float_locations[0].rm_eo = bu_vls_strlen(&matrix_substring); while (floatcnt < 16) { - if (regexec(&matrix_entry, floatptr, matrix_entry.re_nsub, float_locations, REG_STARTEND) == 0) { + rret = regexec(&matrix_entry, floatptr, matrix_entry.re_nsub, float_locations, 0); + if (rret == 0) { /* matched */ bu_vls_trunc(¤t_substring, 0); bu_vls_strncpy(¤t_substring, currptr + float_locations[0].rm_so, float_locations[0].rm_eo - float_locations[0].rm_so); @@ -266,7 +280,7 @@ * include this header. */ currptr = (const char *)(redtmpfile->buf); - ret = regexec(&combtree_regex, currptr, combtree_regex.re_nsub , result_locations, 0); + ret = regexec(&combtree_regex, currptr, combtree_regex.re_nsub, result_locations, 0); if (ret == 0) { /* matched */ @@ -305,7 +319,7 @@ bu_avs_init_empty(&avs); while (attrcumulative < combtagstart - 1) { /* If attributes are present, the first line must match the attr regex - mult-line attribute names are not supported. */ - if (regexec(&attr_regex, currptr, attr_regex.re_nsub , result_locations, 0) != 0) { + if (regexec(&attr_regex, currptr, attr_regex.re_nsub, result_locations, 0) != 0) { /* did NOT match */ bu_vls_printf(gedp->ged_result_str, "invalid attribute line\n"); @@ -331,7 +345,7 @@ attrstart = result_locations[0].rm_so; attrend = result_locations[0].rm_eo; attrcumulative += attrend; - if (regexec(&attr_regex, (const char *)(redtmpfile->buf) + attrcumulative, attr_regex.re_nsub , result_locations, 0) == 0) { + if (regexec(&attr_regex, (const char *)(redtmpfile->buf) + attrcumulative, attr_regex.re_nsub, result_locations, 0) == 0) { /* matched */ if (attrcumulative + result_locations[0].rm_eo < combtagstart) { @@ -367,16 +381,16 @@ * and we need to know how many there are before allocating rt_tree_array memory. */ currptr = (const char *)(redtmpfile->buf) + combtagend; node_count = 0; - ret = regexec(&combtree_op_regex, currptr, combtree_op_regex.re_nsub , result_locations, 0); + ret = regexec(&combtree_op_regex, currptr, combtree_op_regex.re_nsub, result_locations, 0); while (ret == 0) { currptr = currptr + result_locations[0].rm_eo; - ret = regexec(&combtree_op_regex, currptr, combtree_op_regex.re_nsub , result_locations, 0); + ret = regexec(&combtree_op_regex, currptr, combtree_op_regex.re_nsub, result_locations, 0); node_count++; } currptr = (const char *)(redtmpfile->buf) + combtagend + 1; name_end = 0; - ret = regexec(&combtree_op_regex, currptr, combtree_op_regex.re_nsub , result_locations, 0); + ret = regexec(&combtree_op_regex, currptr, combtree_op_regex.re_nsub, result_locations, 0); if (ret == 0) { /* matched */ @@ -383,7 +397,7 @@ /* Check for non-whitespace garbage between first operator and start of comb tree definition */ result_locations[0].rm_eo = result_locations[0].rm_so; result_locations[0].rm_so = 0; - if (regexec(&nonwhitespace_regex, currptr, nonwhitespace_regex.re_nsub, result_locations, REG_STARTEND) == 0) { + if (regexec(&nonwhitespace_regex, currptr, nonwhitespace_regex.re_nsub, result_locations, 0) == 0) { /* matched */ bu_vls_printf(gedp->ged_result_str, "Saw something other than comb tree entries after comb tree tag - error!\n"); @@ -400,7 +414,7 @@ return GED_ERROR; } - ret = regexec(&combtree_op_regex, currptr, combtree_op_regex.re_nsub , result_locations, 0); + ret = regexec(&combtree_op_regex, currptr, combtree_op_regex.re_nsub, result_locations, 0); bu_vls_trunc(&next_op_vls, 0); bu_vls_strncpy(&next_op_vls, currptr + result_locations[0].rm_so, result_locations[0].rm_eo - result_locations[0].rm_so); bu_vls_trimspace(&next_op_vls); @@ -410,7 +424,7 @@ while (ret == 0) { db_op_t op; - ret = regexec(&combtree_op_regex, currptr, combtree_op_regex.re_nsub , result_locations, 0); + ret = regexec(&combtree_op_regex, currptr, combtree_op_regex.re_nsub, result_locations, 0); bu_vls_sprintf(&curr_op_vls, "%s", bu_vls_addr(&next_op_vls)); if (ret == 0) { /* matched */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sta...@us...> - 2018-09-20 16:34:38
|
Revision: 71766 http://sourceforge.net/p/brlcad/code/71766 Author: starseeker Date: 2018-09-20 16:34:33 +0000 (Thu, 20 Sep 2018) Log Message: ----------- Fix a red command regression introduced in r70751 - with the removal of REG_STARTEND the non-whitespace check after the comb tag was not limited to checking between the comb tag itself and the first legitimate comb instance entry. This unconstrained match resulted in its matching with and reporting the comb entry itself as erroneous content, which in turn resulted in all red operations failing. Surprisingly this didn't seem to break our regress-red test reliably, although it did break on some systems... perhaps (since we were still setting the rm_so and rm_eo values) whether the regexec matching scope was unbounded or not ended up being implementation dependent? Modified Paths: -------------- brlcad/trunk/src/libged/red.c Modified: brlcad/trunk/src/libged/red.c =================================================================== --- brlcad/trunk/src/libged/red.c 2018-09-20 14:52:49 UTC (rev 71765) +++ brlcad/trunk/src/libged/red.c 2018-09-20 16:34:33 UTC (rev 71766) @@ -395,11 +395,10 @@ ret = regexec(&combtree_op_regex, currptr, combtree_op_regex.re_nsub, result_locations, 0); if (ret == 0) { /* matched */ + int cstart = result_locations[0].rm_so; /* Check for non-whitespace garbage between first operator and start of comb tree definition */ - result_locations[0].rm_eo = result_locations[0].rm_so; - result_locations[0].rm_so = 0; - if (regexec(&nonwhitespace_regex, currptr, nonwhitespace_regex.re_nsub, result_locations, 0) == 0) { + if ((regexec(&nonwhitespace_regex, currptr, nonwhitespace_regex.re_nsub, result_locations, 0) == 0) && result_locations[0].rm_so < cstart) { /* matched */ bu_vls_printf(gedp->ged_result_str, "Saw something other than comb tree entries after comb tree tag - error!\n"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <br...@us...> - 2020-07-10 04:23:51
|
Revision: 76297 http://sourceforge.net/p/brlcad/code/76297 Author: brlcad Date: 2020-07-10 04:23:49 +0000 (Fri, 10 Jul 2020) Log Message: ----------- no longer true Modified Paths: -------------- brlcad/trunk/src/libged/red.c Modified: brlcad/trunk/src/libged/red.c =================================================================== --- brlcad/trunk/src/libged/red.c 2020-07-10 04:10:15 UTC (rev 76296) +++ brlcad/trunk/src/libged/red.c 2020-07-10 04:23:49 UTC (rev 76297) @@ -40,7 +40,6 @@ #include "./ged_private.h" -/* also accessed by put_comb.c */ char _ged_tmpfil[MAXPATHLEN] = {0}; static const char combseparator[] = "---------- Combination Tree ----------\n"; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |