HIDDEN int move_all_file(struct ged *gedp, int nflag, const char *file) { FILE *fp; char line[512]; if ((fp=fopen(file, "r")) == NULL) { bu_vls_printf(gedp->ged_result_str, "cannot open %s\n", file); return GED_ERROR; } while (bu_fgets(line, sizeof(line), fp) != NULL) { char *cp; char *new_av[3]; /* Skip comments */ if ((cp = strchr(line, '#')) != NULL) *cp = '\0'; if (bu_argv_from_string(new_av, 2, line) != 2) continue; move_all_func(gedp, nflag, (const char *)new_av[0], (const char *)new_av[1]); } fclose(fp); return GED_OK; }
static int isst_load_g(ClientData UNUSED(clientData), Tcl_Interp *interp, int objc, Tcl_Obj *const *objv) { struct isst_s *isst; char **argv; int argc; double az, el; struct bu_vls tclstr = BU_VLS_INIT_ZERO; vect_t vec; Togl *togl; if (objc < 4) { Tcl_WrongNumArgs(interp, 1, objv, "load_g pathname object"); return TCL_ERROR; } if (Togl_GetToglFromObj(interp, objv[1], &togl) != TCL_OK) { return TCL_ERROR; } isst = (struct isst_s *) Togl_GetClientData(togl); argv = (char **)malloc(sizeof(char *) * (strlen(Tcl_GetString(objv[3])) + 1)); /* allocate way too much. */ argc = bu_argv_from_string(argv, strlen(Tcl_GetString(objv[3])), Tcl_GetString(objv[3])); load_g(isst->tie, Tcl_GetString(objv[2]), argc, (const char **)argv, &(isst->meshes)); free(argv); VSETALL(isst->camera.pos, isst->tie->radius); VMOVE(isst->camera.focus, isst->tie->mid); VMOVE(isst->camera_pos_init, isst->camera.pos); VMOVE(isst->camera_focus_init, isst->camera.focus); /* Set the initial az and el values in Tcl/Tk */ VSUB2(vec, isst->camera.pos, isst->camera.focus); VUNITIZE(vec); AZEL_FROM_V3DIR(az, el, vec); az = az * -DEG2RAD; el = el * -DEG2RAD; bu_vls_sprintf(&tclstr, "%f", az); Tcl_SetVar(interp, "az", bu_vls_addr(&tclstr), 0); bu_vls_sprintf(&tclstr, "%f", el); Tcl_SetVar(interp, "el", bu_vls_addr(&tclstr), 0); bu_vls_free(&tclstr); render_phong_init(&isst->camera.render, NULL); isst->ogl = 1; isst->w = Togl_Width(togl); isst->h = Togl_Height(togl); resize_isst(isst); isst->t1 = bu_gettime(); isst->t2 = bu_gettime(); return TCL_OK; }
/* * The only argument is the name of the database file. */ void ph_dirbuild(struct pkg_conn *UNUSED(pc), char *buf) { long max_argc = 0; char **argv = NULL; struct rt_i *rtip = NULL; size_t n = 0; if (debug) fprintf(stderr, "ph_dirbuild: %s\n", buf); for (n = 0; n < strlen(buf); n++) { if (isspace((int)buf[n])) max_argc++; } argv = (char **)bu_calloc(max_argc+1, sizeof(char *), "alloc argv"); if ((bu_argv_from_string(argv, max_argc, buf)) <= 0) { /* No words in input */ (void)free(buf); bu_free(argv, "free argv"); return; } if (seen_dirbuild) { bu_log("ph_dirbuild: MSG_DIRBUILD already seen, ignored\n"); (void)free(buf); bu_free(argv, "free argv"); return; } title_file = bu_strdup(argv[0]); bu_free(argv, "free argv"); /* Build directory of GED database */ if ((rtip=rt_dirbuild(title_file, idbuf, sizeof(idbuf))) == RTI_NULL) bu_exit(2, "ph_dirbuild: rt_dirbuild(%s) failure\n", title_file); APP.a_rt_i = rtip; seen_dirbuild = 1; /* * Initialize all the per-CPU memory resources. * Go for the max, as TCL interface may change npsw as we run. */ for (n=0; n < MAX_PSW; n++) { rt_init_resource(&resource[n], n, rtip); bn_rand_init(resource[n].re_randptr, n); } if (pkg_send(MSG_DIRBUILD_REPLY, idbuf, strlen(idbuf)+1, pcsrv) < 0) fprintf(stderr, "MSG_DIRBUILD_REPLY error\n"); }
void fast4_arg_process(const char *args) { if (!args) return; char *input = bu_strdup(args); char **argv = (char **)bu_calloc(strlen(args) + 1, sizeof(char *), "argv array"); int argc = bu_argv_from_string(argv, strlen(args), input); option::Stats stats(Fast4Usage, argc, argv); option::Option *options = (option::Option *)bu_calloc(stats.options_max, sizeof(option::Option), "options"); option::Option *buffer= (option::Option *)bu_calloc(stats.buffer_max, sizeof(option::Option), "options"); option::Parser parse(Fast4Usage, argc, argv, options, buffer); if (options[FAST4_WARN_DEFAULT_NAMES]) { bu_log("FASTGEN 4 opt: %s:%s\n", options[FAST4_WARN_DEFAULT_NAMES].name, options[FAST4_WARN_DEFAULT_NAMES].arg); } bu_free(input, "input"); bu_free(options, "free options"); bu_free(buffer, "free buffer"); }
/* * Each word in the command buffer is the name of a treetop. */ void ph_gettrees(struct pkg_conn *UNUSED(pc), char *buf) { size_t n = 0; long max_argc = 0; char **argv = NULL; int argc = 0; struct rt_i *rtip = APP.a_rt_i; RT_CK_RTI(rtip); if (debug) fprintf(stderr, "ph_gettrees: %s\n", buf); /* Copy values from command line options into rtip */ rtip->useair = use_air; if (rt_dist_tol > 0) { rtip->rti_tol.dist = rt_dist_tol; rtip->rti_tol.dist_sq = rt_dist_tol * rt_dist_tol; } if (rt_perp_tol > 0) { rtip->rti_tol.perp = rt_perp_tol; rtip->rti_tol.para = 1 - rt_perp_tol; } for (n = 0; n < strlen(buf); n++) { if (isspace((int)buf[n])) max_argc++; } argv = (char **)bu_calloc(max_argc+1, sizeof(char *), "alloc argv"); if ((argc = bu_argv_from_string(argv, max_argc, buf)) <= 0) { /* No words in input */ (void)free(buf); bu_free(argv, "free argv"); return; } title_obj = bu_strdup(argv[0]); if (rtip->needprep == 0) { /* First clean up after the end of the previous frame */ if (debug)bu_log("Cleaning previous model\n"); view_end(&APP); view_cleanup(rtip); rt_clean(rtip); if (rdebug&RDEBUG_RTMEM_END) bu_prmem("After rt_clean"); } /* Load the desired portion of the model */ if (rt_gettrees(rtip, argc, (const char **)argv, npsw) < 0) fprintf(stderr, "rt_gettrees(%s) FAILED\n", argv[0]); bu_free(argv, "free argv"); /* In case it changed from startup time via an OPT command */ if (npsw > 1) { RTG.rtg_parallel = 1; } else RTG.rtg_parallel = 0; seen_gettrees = 1; (void)free(buf); prepare(); /* Acknowledge that we are ready */ if (pkg_send(MSG_GETTREES_REPLY, title_obj, strlen(title_obj)+1, pcsrv) < 0) fprintf(stderr, "MSG_START error\n"); }
void do_lines(FILE *fp, char *buffer) { #define TOKLEN 128 char token[TOKLEN]; int ntokenwords; register char *cp; register char *tp; int i; for ( line=0; /*NIL*/; line++ ) { linebuf[0] = '\0'; (void)bu_fgets( linebuf, sizeof(linebuf), fp ); if ( feof(fp) ) break; /* Skip blank or commented out lines */ if ( linebuf[0] == '\0' || linebuf[0] == '#' || linebuf[0] == '\n' ) continue; if (debug) { fprintf(stderr, "Prototype=\n%s", buffer); fprintf(stderr, "Line %d='%s'\n", line, linebuf); } /* Here, there is no way to check for too many words */ nwords = bu_argv_from_string( chanwords, NCHANS, linebuf ); for ( cp=buffer; *cp != '\0'; ) { if (debug) fputc( *cp, stderr ); /* Copy all plain text, verbatim */ if ( *cp != '@' ) { putc( *cp++, stdout ); continue; } /* An '@' sign has been seen, slurp up a token */ cp++; /* skip '@' */ if ( *cp == '@' ) { /* Double '@' is escape for single one * (just like ARPANET TACs) */ putc( '@', stdout ); cp++; /* skip '@' */ continue; } if ( *cp == '(' ) { cp++; /* skip '(' */ tp = token; while ( *cp && *cp != ')' && tp<&token[TOKLEN-1]) { *tp++ = *cp++; } *tp++ = '\0'; cp++; /* skip ')' */ } else if ( isdigit( *cp ) ) { tp = token; while ( isdigit( *cp ) && tp<&token[TOKLEN-1] ) { *tp++ = *cp++; } *tp++ = '\0'; } else { fprintf( stderr, "Line %d: Bad sequence '@%c'\n", line, *cp); fprintf( stdout, "@%c", *cp++ ); continue; } if (debug) fprintf(stderr, "token='%s'\n", token); if ( isdigit( token[0] ) ) { fputs( chanwords[str2chan_index(token)], stdout ); continue; } if ( strcmp( token, "line" ) == 0 ) { fprintf(stdout, "%d", line ); continue; } if ( strcmp( token, "time" ) == 0 ) { fputs( chanwords[0], stdout ); continue; } /* Check here for multi-word tokens */ ntokenwords = bu_argv_from_string( tokenwords, NTOKENWORDS, token ); /* If first character of a word is '@' or '%', that * signifies substituting the value of the * indicated channel. Otherwise the word is literal. */ for ( i=1; i<ntokenwords; i++ ) { char c; int chan; c = tokenwords[i][0]; if ( c != '@' && c != '%' ) continue; chan = str2chan_index( &tokenwords[i][1] ); tokenwords[i] = chanwords[chan]; } if ( (i=multi_words( tokenwords, ntokenwords )) >= 0 ) continue; if ( i == -1 ) { fprintf(stderr, "Line %d: keyword @(%s) encountered error\n", line, token); fprintf(stdout, "@(%s)", token ); } else { fprintf(stderr, "Line %d: keyword @(%s) unknown\n", line, token); fprintf(stdout, "@(%s)", token ); } for ( i=0; i<ntokenwords; i++ ) { fprintf( stderr, "word[%2d] = '%s'\n", i, tokenwords[i] ); } } } }
int f_eac(ClientData clientData, Tcl_Interp *interp, int argc, char **argv) { int j; int item; struct directory *dp; struct bu_vls v; int new_argc; int lim; CHECK_DBI_NULL; if (argc < 2) { struct bu_vls vls; bu_vls_init(&vls); bu_vls_printf(&vls, "help eac"); Tcl_Eval(interp, bu_vls_addr(&vls)); bu_vls_free(&vls); return TCL_ERROR; } bu_vls_init( &v ); if ( setjmp( jmp_env ) == 0 ) (void)signal( SIGINT, sig3); /* allow interupts */ else { bu_vls_free( &v ); return TCL_OK; } bu_vls_strcat( &v, "e" ); lim = 1; for ( j=1; j<argc; j++) { item = atoi( argv[j] ); if ( item < 1 ) continue; FOR_ALL_DIRECTORY_START(dp, dbip) { struct rt_db_internal intern; struct rt_comb_internal *comb; if ( !(dp->d_flags & DIR_REGION) ) continue; if ( rt_db_get_internal( &intern, dp, dbip, (fastf_t *)NULL, &rt_uniresource ) < 0 ) TCL_READ_ERR_return; comb = (struct rt_comb_internal *)intern.idb_ptr; if ( comb->region_id != 0 || comb->aircode != item ) { rt_comb_ifree( &intern, &rt_uniresource ); continue; } rt_comb_ifree( &intern, &rt_uniresource ); bu_vls_strcat( &v, " " ); bu_vls_strcat( &v, dp->d_namep ); lim++; } FOR_ALL_DIRECTORY_END; } if ( lim > 1 ) { int retval; const char **new_argv; new_argv = (char **)bu_calloc( lim+1, sizeof( char *), "f_eac: new_argv" ); new_argc = bu_argv_from_string( new_argv, lim, bu_vls_addr( &v ) ); retval = cmd_draw( clientData, interp, new_argc, new_argv ); bu_free( (genptr_t)new_argv, "f_eac: new_argv" ); bu_vls_free( &v ); (void)signal( SIGINT, SIG_IGN ); return retval; } else { bu_vls_free( &v ); (void)signal( SIGINT, SIG_IGN ); return TCL_OK; } }
int ged_draw_guts(struct ged *gedp, int argc, const char *argv[], int kind) { size_t i; int drawtrees_retval; int flag_A_attr=0; int flag_o_nonunique=1; int last_opt=0; struct bu_vls vls = BU_VLS_INIT_ZERO; static const char *usage = "<[-R -C#/#/# -s] objects> | <-o -A attribute name/value pairs>"; /* #define DEBUG_TIMING 1 */ #ifdef DEBUG_TIMING int64_t elapsedtime; #endif GED_CHECK_DATABASE_OPEN(gedp, GED_ERROR); GED_CHECK_DRAWABLE(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 == 1) { bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", argv[0], usage); return GED_HELP; } #ifdef DEBUG_TIMING elapsedtime = bu_gettime(); #endif /* skip past cmd */ --argc; ++argv; /* check args for "-A" (attributes) and "-o" */ for (i = 0; i < (size_t)argc; i++) { char *ptr_A=NULL; char *ptr_o=NULL; char *c; if (*argv[i] != '-') { /* Done checking options. If our display is non-empty, * add -R to keep current view. */ if (BU_LIST_NON_EMPTY(gedp->ged_gdp->gd_headDisplay)) { bu_vls_strcat(&vls, " -R"); } break; } ptr_A=strchr(argv[i], 'A'); if (ptr_A) flag_A_attr = 1; ptr_o=strchr(argv[i], 'o'); if (ptr_o) flag_o_nonunique = 2; last_opt = i; if (!ptr_A && !ptr_o) { bu_vls_putc(&vls, ' '); bu_vls_strcat(&vls, argv[i]); continue; } if (strlen(argv[i]) == ((size_t)1 + (ptr_A != NULL) + (ptr_o != NULL))) { /* argv[i] is just a "-A" or "-o" */ continue; } /* copy args other than "-A" or "-o" */ bu_vls_putc(&vls, ' '); c = (char *)argv[i]; while (*c != '\0') { if (*c != 'A' && *c != 'o') { bu_vls_putc(&vls, *c); } c++; } } if (flag_A_attr) { /* args are attribute name/value pairs */ struct bu_attribute_value_set avs; int max_count=0; int remaining_args=0; int new_argc=0; char **new_argv=NULL; struct bu_ptbl *tbl; remaining_args = argc - last_opt - 1; if (remaining_args < 2 || remaining_args%2) { bu_vls_printf(gedp->ged_result_str, "Error: must have even number of arguments (name/value pairs)\n"); bu_vls_free(&vls); return GED_ERROR; } bu_avs_init(&avs, (argc - last_opt)/2, "ged_draw_guts avs"); i = 0; while (i < (size_t)argc) { if (*argv[i] == '-') { i++; continue; } /* this is a name/value pair */ if (flag_o_nonunique == 2) { bu_avs_add_nonunique(&avs, argv[i], argv[i+1]); } else { bu_avs_add(&avs, argv[i], argv[i+1]); } i += 2; } tbl = db_lookup_by_attr(gedp->ged_wdbp->dbip, RT_DIR_REGION | RT_DIR_SOLID | RT_DIR_COMB, &avs, flag_o_nonunique); bu_avs_free(&avs); if (!tbl) { bu_log("Error: db_lookup_by_attr() failed!!\n"); bu_vls_free(&vls); return TCL_ERROR; } if (BU_PTBL_LEN(tbl) < 1) { /* nothing matched, just return */ bu_vls_free(&vls); return TCL_OK; } for (i = 0; i < BU_PTBL_LEN(tbl); i++) { struct directory *dp; dp = (struct directory *)BU_PTBL_GET(tbl, i); bu_vls_putc(&vls, ' '); bu_vls_strcat(&vls, dp->d_namep); } max_count = BU_PTBL_LEN(tbl) + last_opt + 1; bu_ptbl_free(tbl); bu_free((char *)tbl, "ged_draw_guts ptbl"); new_argv = (char **)bu_calloc(max_count+1, sizeof(char *), "ged_draw_guts new_argv"); new_argc = bu_argv_from_string(new_argv, max_count, bu_vls_addr(&vls)); /* First, delete any mention of these objects. * Silently skip any leading options (which start with minus signs). */ for (i = 0; i < (size_t)new_argc; ++i) { /* Skip any options */ if (new_argv[i][0] == '-') { /* If this option requires an argument which was * provided separately (e.g. '-C 0/255/0' instead of * '-C0/255/0'), skip the argument too. */ if (strlen(argv[i]) == 2 && strchr("mxCP", argv[i][1])) { i++; } continue; } dl_erasePathFromDisplay(gedp->ged_gdp->gd_headDisplay, gedp->ged_wdbp->dbip, gedp->ged_free_vlist_callback, new_argv[i], 0, gedp->freesolid); } drawtrees_retval = _ged_drawtrees(gedp, new_argc, (const char **)new_argv, kind, (struct _ged_client_data *)0); bu_vls_free(&vls); bu_free((char *)new_argv, "ged_draw_guts new_argv"); if (drawtrees_retval) { return GED_ERROR; } } else { int empty_display; bu_vls_free(&vls); empty_display = 1; if (BU_LIST_NON_EMPTY(gedp->ged_gdp->gd_headDisplay)) { empty_display = 0; } /* First, delete any mention of these objects. * Silently skip any leading options (which start with minus signs). */ for (i = 0; i < (size_t)argc; ++i) { /* Skip any options */ if (argv[i][0] == '-') { /* If this option requires an argument which was * provided separately (e.g. '-C 0/255/0' instead of * '-C0/255/0'), skip the argument too. */ if (strlen(argv[i]) == 2 && strchr("mxCP", argv[i][1])) { i++; } continue; } dl_erasePathFromDisplay(gedp->ged_gdp->gd_headDisplay, gedp->ged_wdbp->dbip, gedp->ged_free_vlist_callback, argv[i], 0, gedp->freesolid); } /* if our display is non-empty add -R to keep current view */ if (!empty_display) { int new_argc; char **new_argv; new_argc = argc + 1; new_argv = (char **)bu_malloc(new_argc * sizeof(char *), "ged_draw_guts new_argv"); new_argv[0] = bu_strdup("-R"); for (i = 0; i < (size_t)argc; ++i) { new_argv[i + 1] = bu_strdup(argv[i]); } drawtrees_retval = _ged_drawtrees(gedp, new_argc, (const char **)new_argv, kind, (struct _ged_client_data *)0); for (i = 0; i < (size_t)new_argc; ++i) { bu_free(new_argv[i], "ged_draw_guts new_argv[i] - bu_strdup(argv[i])"); } bu_free(new_argv, "ged_draw_guts new_argv"); } else { drawtrees_retval = _ged_drawtrees(gedp, argc, argv, kind, (struct _ged_client_data *)0); } if (drawtrees_retval) { return GED_ERROR; } } #ifdef DEBUG_TIMING elapsedtime = bu_gettime() - elapsedtime; { int seconds = elapsedtime / 1000000; int minutes = seconds / 60; int hours = minutes / 60; minutes = minutes % 60; seconds = seconds %60; bu_vls_printf(gedp->ged_result_str, "Elapsed time: %02d:%02d:%02d\n", hours, minutes, seconds); } #endif return GED_OK; }