void
grid_coor(char *buffer, com_table *ctp, struct rt_i *UNUSED(rtip))
{
    extern int str_dbl();  /* function to convert string to double */
    int i = 0;
    int rc = 0;    /* the return code value from str_dbl() */
    vect_t Gr;

    while (isspace((int)*(buffer+i)))
	++i;
    if (*(buffer+i) == '\0') {
	/* display current grid coordinates */
	fprintf(stdout, "(h, v, d) = (%4.2f, %4.2f, %4.2f)\n",
	       grid(HORZ) * base2local,
	       grid(VERT) * base2local,
	       grid(DIST) * base2local);
	return;
    }
    if ((rc = str_dbl(buffer+i, &Gr[HORZ])) == 0) {
	/* get horz coor */
	com_usage(ctp);
	return;
    }
    i += rc;
    while (isspace((int)*(buffer+i)))
	++i;
    if ((rc = str_dbl(buffer+i, &Gr[VERT])) == 0) {
	/* get vert coor */
	com_usage(ctp);
	return;
    }
    i += rc;
    while (isspace((int)*(buffer+i)))
	++i;
    if (*(buffer+i) == '\0') {
	/* if there is no dist coor, set default */
	grid(HORZ) = Gr[HORZ] * local2base;
	grid(VERT) = Gr[VERT] * local2base;
	grid2targ();
	return;
    }
    if ((rc = str_dbl(buffer+i, &Gr[DIST])) == 0) {
	/* set dist coor */
	com_usage(ctp);
	return;
    }
    i += rc;
    while (isspace((int)*(buffer+i)))
	++i;
    if (*(buffer+i) != '\0') {
	/* check for garbage at the end of the line */
	com_usage(ctp);
	return;
    }
    grid(HORZ) = Gr[HORZ] * local2base;
    grid(VERT) = Gr[VERT] * local2base;
    grid(DIST) = Gr[DIST] * local2base;
    grid2targ();
}
void
az_el(char *buffer, com_table *ctp, struct rt_i *UNUSED(rtip))
{
    extern int str_dbl();  /* function to convert string to double */
    int i = 0;      /* current position on the *buffer */
    int rc = 0;     /* the return code value from str_dbl()   */
    double az;
    double el;

    while (isspace((int)*(buffer+i)))
	++i;
    if (*(buffer+i) == '\0') {
	/* display current az and el values */
	bu_log("(az, el) = (%4.2f, %4.2f)\n",
	       azimuth(), elevation());
	return;
    }
    if ((rc = str_dbl(buffer+i, &az)) == 0) {
	/* get az value */
	com_usage(ctp);
	return;
    }
    if (fabs(az) > 360) {
	/* check for valid az value */

	bu_log("Error:  |azimuth| <= 360\n");
	return;
    }
    i += rc;
    while (isspace((int)*(buffer+i)))
	++i;
    if ((rc = str_dbl(buffer+i, &el)) == 0) {
	/* get el value */
	com_usage(ctp);
	return;
    }
    if (fabs(el) > 90) {
	/* check for valid el value */
	bu_log("Error:  |elevation| <= 90\n");
	return;
    }
    i += rc;
    while (isspace((int)*(buffer+i)))
	++i;
    if (*(buffer+i) != '\0') {
	/* check for garbage at the end of the line */
	com_usage(ctp);
	return;
    }
    azimuth() = az;
    elevation() = el;
    ae2dir();
}
void
target_coor(char *buffer, com_table *ctp, struct rt_i *UNUSED(rtip))
{
    extern int str_dbl();  /* function to convert string to double */
    int i = 0;
    int rc = 0;     /* the return code value from str_dbl() */
    vect_t Tar;	    /* Target x, y and z */

    while (isspace((int)*(buffer+i)))
	++i;
    if (*(buffer+i) == '\0') {
	/* display current target coors */
	fprintf(stdout, "(x, y, z) = (%4.2f, %4.2f, %4.2f)\n",
	       target(X) * base2local,
	       target(Y) * base2local,
	       target(Z) * base2local);
	return;
    }
    if ((rc = str_dbl(buffer+i, &Tar[X])) == 0) {
	/* get target x coor */
	com_usage(ctp);
	return;
    }
    i += rc;
    while (isspace((int)*(buffer+i)))
	++i;
    if ((rc = str_dbl(buffer+i, &Tar[Y])) == 0) {
	/* get target y coor */
	com_usage(ctp);
	return;
    }
    i += rc;
    while (isspace((int)*(buffer+i)))
	++i;
    if ((rc = str_dbl(buffer+i, &Tar[Z])) == 0) {
	/* get target z coor */
	com_usage(ctp);
	return;
    }
    i += rc;
    while (isspace((int)*(buffer+i)))
	++i;
    if (*(buffer+i) != '\0') {
	/* check for garbage at the end of the line */
	com_usage(ctp);
	return;
    }
    target(X) = Tar[X] * local2base;
    target(Y) = Tar[Y] * local2base;
    target(Z) = Tar[Z] * local2base;
    targ2grid();
}
void
dir_vect(char *buffer, com_table *ctp, struct rt_i *UNUSED(rtip))
{
    extern int str_dbl();  /* function to convert string to double */
    int i = 0;
    int rc = 0;    /* the return code value from str_dbl() */
    vect_t Dir;	   /* Direction vector x, y and z */

    while (isspace((int)*(buffer+i)))
	++i;
    if (*(buffer+i) == '\0') {
	/* display current direct coors */
	fprintf(stdout, "(x, y, z) = (%4.2f, %4.2f, %4.2f)\n",
	       direct(X), direct(Y), direct(Z));
	return;
    }
    if ((rc = str_dbl(buffer+i, &Dir[X])) == 0) {
	/* get direct x coor */
	com_usage(ctp);
	return;
    }
    i += rc;
    while (isspace((int)*(buffer+i)))
	++i;
    if ((rc = str_dbl(buffer+i, &Dir[Y])) == 0) {
	/* get direct y coor */
	com_usage(ctp);
	return;
    }
    i += rc;
    while (isspace((int)*(buffer+i)))
	++i;
    if ((rc = str_dbl(buffer+i, &Dir[Z])) == 0) {
	/* get direct z coor */
	com_usage(ctp);
	return;
    }
    i += rc;
    while (isspace((int)*(buffer+i)))
	++i;
    if (*(buffer+i) != '\0') {
	/* check for garbage at the end of the line */
	com_usage(ctp);
	return;
    }
    VUNITIZE(Dir);
    direct(X) = Dir[X];
    direct(Y) = Dir[Y];
    direct(Z) = Dir[Z];
    dir2ae();
}
void
cm_libdebug(char *buffer, com_table *ctp, struct rt_i *UNUSED(rtip))
{
    char *cp = buffer;

    /* This is really icky -- should have argc, argv interface */

    while (*cp && isascii(*cp) && isspace((int)*cp))
	cp++;

    if (*cp == '\0') {
	/* display current value */
	bu_printb("libdebug ", RT_G_DEBUG, RT_DEBUG_FMT);
	bu_log("\n");
	return;
    }

    /* Set a new value */
    if (sscanf(cp, "%x", (unsigned int *)&RTG.debug) == 1) {
	bu_printb("libdebug ", RT_G_DEBUG, RT_DEBUG_FMT);
	bu_log("\n");
    } else {
	com_usage(ctp);
    }
}
void
nirt_units(char *buffer, com_table *ctp, struct rt_i *rtip)
{
    double tmp_dbl;
    int i = 0;      /* current position on the *buffer */

    double mk_cvt_factor();

    while (isspace((int)*(buffer+i)))
	++i;
    if (*(buffer+i) == '\0') {
	/* display current destination */
	fprintf(stdout, "units = '%s'\n", local_u_name);
	return;
    }

    if (BU_STR_EQUAL(buffer + i, "?")) {
	com_usage(ctp);
	return;
    } else if (BU_STR_EQUAL(buffer + i, "default")) {
	base2local = rtip->rti_dbip->dbi_base2local;
	local2base = rtip->rti_dbip->dbi_local2base;
	bu_strlcpy(local_u_name, bu_units_string(base2local), sizeof(local_u_name));
    } else {
	tmp_dbl = bu_units_conversion(buffer + i);
	if (tmp_dbl <= 0.0) {
	    bu_log("Invalid unit specification: '%s'\n", buffer + i);
	    return;
	}
	bu_strlcpy(local_u_name, buffer + i, sizeof(local_u_name));
	local2base = tmp_dbl;
	base2local = 1.0 / tmp_dbl;
    }
}
Exemplo n.º 7
0
void
state_file(const char *buffer, com_table *ctp, struct rt_i *UNUSED(rtip))
{
    int i = 0;      /* current position on the *buffer */
    static char *new_name;

    while (isspace((int)*(buffer+i)))
	++i;

    if (*(buffer+i) == '\0') {
	/* display current state name */
	printf("statefile = '%s'\n", sf_name);
	return;
    }

    if (BU_STR_EQUAL(buffer + i, "?")) {
	com_usage(ctp);
	return;
    }

    if (BU_STR_EQUAL(buffer + i, "default")) {
	new_name = def_sf_name;
    } else {
	new_name = bu_malloc(strlen(buffer + i)+1, "new_state_filename");
	snprintf(new_name, strlen(buffer+i), "%s", buffer + i);
    }

    /* Clean up from previous output destination */
    if (sf_name != def_sf_name)
	bu_free(sf_name, "new(now old)statefile");

    /* Establish the new destination */
    sf_name = new_name;
}
void
cm_attr(char *buffer, com_table *ctp, struct rt_i *UNUSED(rtip))
{
    while (isascii(*buffer) && isspace((int)*buffer)) buffer++;

    if (strlen(buffer) == 0) {
	com_usage(ctp);
	return;
    }

    if (! bu_strncmp(buffer, "-p", 2)) {
	attrib_print();
	return;
    }

    if (! bu_strncmp(buffer, "-f", 2)) {
	attrib_flush();
	return;
    }

    attrib_add(buffer, &need_prep);
}
void
do_overlap_claims(char *buffer, com_table *ctp, struct rt_i *UNUSED(rtip))
{
    int i = 0;      /* current position on the *buffer */
    int j;
    double mk_cvt_factor();

    while (isspace((int)*(buffer+i)))
	++i;
    if (*(buffer+i) == '\0') {
	/* display current destination */
	bu_log("overlap_claims = '%s'\n", ocname[overlap_claims]);
	return;
    }

    if (BU_STR_EQUAL(buffer + i, "?")) {
	com_usage(ctp);
	return;
    }
    for (j = OVLP_RESOLVE; j <= OVLP_RETAIN; ++j) {
	char numeral[4];
	int k;

	sprintf(numeral, "%d", j);
	if ((BU_STR_EQUAL(buffer + i, ocname[j]))
	    || (BU_STR_EQUAL(buffer + i, numeral))) {
	    overlap_claims = j;
	    for (k = 0; k < 2; ++k)
		if (rti_tab[k] != RTI_NULL)
		    rti_tab[k]->rti_save_overlaps = (j > 0);
	    return;
	}
    }

    bu_log("Invalid overlap_claims specification: '%s'\n", buffer + i);
}
Exemplo n.º 10
0
void
use_air(char *buffer, com_table *ctp, struct rt_i *UNUSED(rtip))
{
    int new_use = 0;      /* current position on the *buffer */
    char response[128];
    char *rp = response;
    char db_title[TITLE_LEN+1];	/* title from MGED database */
    struct rt_i *my_rtip;

    extern char *db_name;		/* Name of MGED database file */

    while (isspace((int)*buffer))
	++buffer;
    if (*buffer == '\0') {
	/* display current value of use_of_air */
	bu_log("use_air = %d\n", ap.a_rt_i->useair);
	return;
    }
    if (!isdigit((int)*buffer)) {
	com_usage(ctp);
	return;
    }
    while (isdigit((int)*buffer)) {
	new_use *= 10;
	new_use += *buffer++ - '0';
    }
    if (new_use && (new_use != 1)) {
	bu_log("Warning: useair=%d specified, will set to 1\n",
	       new_use);
	new_use = 1;
    }
    if (rti_tab[new_use] == RTI_NULL) {
	bu_log(" Air %s in the current directory of database objects.\n",
	       new_use ? "is not included" : "is included");
	bu_log(
	    " To set useair=%d requires building/prepping another directory.\n",
	    new_use);
	bu_log(" Do you want to do that now (y|n)[n]? ");
	bu_fgets(response, sizeof(response), stdin);
	while ((*rp == ' ') || (*rp == '\t'))
	    ++rp;
	if ((*rp != 'y') && (*rp != 'Y')) {
	    bu_log("useair remains %d\n", ap.a_rt_i->useair);
	    return;
	}
	bu_log("Building the directory...");
	if ((my_rtip = rt_dirbuild(db_name, db_title, TITLE_LEN)) == RTI_NULL) {
	    bu_log("Could not load file %s\n", db_name);
	    printusage();
	    bu_exit(1, NULL);
	}
	rti_tab[new_use] = my_rtip;
	my_rtip->useair = new_use;
	my_rtip->rti_save_overlaps = (overlap_claims > 0);

	bu_log("Prepping the geometry...");
	do_rt_gettrees(my_rtip, NULL, 0, &need_prep);
    }
    ap.a_rt_i = rti_tab[new_use];
    ap.a_resource = &res_tab[new_use];
    set_diameter(ap.a_rt_i);
}
Exemplo n.º 11
0
void
direct_output(const char *buffer, com_table *ctp, struct rt_i *UNUSED(rtip))
{
    size_t i = 0;      /* current position on the *buffer */
    size_t j = 0;      /* position of last non-whitespace char in the *buffer */
    FILE *newf;
    static char *new_dest;
    static FILE *(*openfunc)() = 0;

    while (isspace((int)*(buffer+i)))
	++i;

    if (*(buffer+i) == '\0') {
	/* display current destination */
#if defined(HAVE_POPEN) && !defined(STRICT_FLAGS)
	printf("destination = %s%s'\n",
	       (openfunc == popen) ? "'| " : "'", dest_string);
#endif
	return;
    }

    if (BU_STR_EQUAL(buffer + i, "?")) {
	com_usage(ctp);
	return;
    }

    if (BU_STR_EQUAL(buffer + i, "default")) {
	newf = stdout;
	new_dest = def_dest_string;
	openfunc = 0;
    } else {
	if (*(buffer + i) == '|') {
#if defined(HAVE_POPEN) && !defined(STRICT_FLAGS)
	    openfunc=popen;
	    ++i;
#else
	    fprintf(stderr, "Error, support for pipe output is disabled.  Try a redirect instead.\n");
	    return;
#endif
	} else {
	    openfunc=fopen;
	}
	/*Find last non-whitespace character*/
	j = strlen(buffer);
	while (isspace((int)*(buffer+j-1))) j--;

	new_dest = bu_malloc(strlen(buffer + i)+1, "new_dest");

	snprintf(new_dest, j-i+1, "%s", buffer + i);
	if (bu_file_exists(new_dest, NULL)) {
	    fprintf(stderr, "File %s already exists.\n", new_dest);
	    return;
	}
	if ((newf = (*openfunc)(new_dest, "w")) == NULL) {
#if defined(HAVE_POPEN) && !defined(STRICT_FLAGS)
	    fprintf(stderr, "Cannot open %s '%s'\n",
		    (openfunc == popen) ? "pipe" : "file", new_dest);
#endif
	    fprintf(stderr, "Destination remains = '%s'\n", dest_string);

	    bu_free(new_dest, "new(now old)dest");
	    return;
	}


    }

    /* Clean up from previous output destination */
    if (outf != (FILE *)NULL && outf != stdout)
	fclose(outf);

    if (dest_string != def_dest_string)
	bu_free(dest_string, "free dest_string");

    /* Establish the new destination */
    outf = newf;
    dest_string = new_dest;
}
Exemplo n.º 12
0
void
print_item (char *buffer, com_table *ctp, struct rt_i *UNUSED(rtip))
{
    char *bp = buffer;
    char *bp0;
    outval *vtp;


    /* Handle no args, arg=='?', and obvious bad arg */
    if (*bp != '\0')
	++bp;

    while (isspace((int)*bp))
	++bp;

    switch (*bp) {
	case '\0':
	case '?':
	    com_usage(ctp);
	    return;
    }

    /* Read in the list of objects to output */
    while (*bp != '\0') {
	while (isspace((int)*bp))
	    ++bp;

	for (bp0 = bp; (! isspace((int)*bp)) && (*bp != '\0'); ++bp)
	    ;

	if (*bp != '\0')
	    *bp++ = '\0';

	for (vtp = (outval *)(ValTab + 1); vtp->name; ++vtp) {
	    if (BU_STR_EQUAL(vtp->name, bp0)) {
		switch (vtp->type) {
		    case OIT_INT:
			printf("%d\n", vtp->value.ival);
			break;
		    case OIT_FLOAT:
			printf("%g\n", vtp->value.fval * base2local);
			break;
		    case OIT_FNOUNIT:
			printf("%g\n", vtp->value.fval);
			break;
		    case OIT_STRING:
			printf("'%s'\n", vtp->value.sval);
			break;
		    default:
			fflush(stdout);
			fprintf(stderr, "Fatal: Invalid item type %d.  ",
				ValTab[vtp->code_nm].type);
			fprintf(stderr, "This shouldn't happen\n");
			bu_exit (1, NULL);
		}
		break;
	    }
	}

	if (vtp->name == '\0') {
	    fprintf(stderr, "Error: Invalid output item '%s'\n", bp0);
	    return;
	}
    }
}
Exemplo n.º 13
0
void
format_output (const char* buffer, com_table* ctp, struct rt_i *UNUSED(rtip))
{
    const char* bp = buffer;	/* was + 1; */
    int fmt_type = FMT_NONE;
    int i;
    int use_defaults = 0;

    void parse_fmt(const char* uoutspec, int outcom_type);
    void show_ospec(outitem *oil);

    /* Handle no args, arg=='?', and obvious bad arg */
    if (*bp != '\0')
	++bp;
    while (isspace((int)*bp))
	++bp;
    switch (*bp) {
	case 'r':
	    fmt_type = FMT_RAY;
	    break;
	case 'h':
	    fmt_type = FMT_HEAD;
	    break;
	case 'p':
	    fmt_type = FMT_PART;
	    break;
	case 'f':
	    fmt_type = FMT_FOOT;
	    break;
	case 'm':
	    fmt_type = FMT_MISS;
	    break;
	case 'o':
	    fmt_type = FMT_OVLP;
	    break;
	case 'g':
	    fmt_type = FMT_GAP;
	    break;
	default:
	    --bp;
	    break;
    }
    while (isspace((int)*++bp))
	;

    switch (*bp) {
	case '\0':     /* display current output specs */
	    if (fmt_type == FMT_NONE)
		fprintf(stderr, "Error: No output-statement type specified\n");
	    else
		show_ospec(oi_list[fmt_type]);
	    return;
	case '"':
	    if (fmt_type == FMT_NONE) {
		fprintf(stderr, "Error: No output-statement type specified\n");
		return;
	    }
	    break;
	default:
	    if (bu_strncmp(bp, "default", 7) == 0) {
		use_defaults = 1;
		break;
	    }
	    fprintf(stderr, "Error: Illegal format specification: '%s'\n", buffer);
	    /* fall through here */
	case '?':
	    com_usage(ctp);
	    return;
    }

    if (use_defaults) {
	if (fmt_type == FMT_NONE) {
	    for (i = 0; i < FMT_NONE; ++i) {
		parse_fmt(def_fmt[i], i);
	    }
	} else {
	    parse_fmt(def_fmt[fmt_type], fmt_type);
	}
    } else {
	parse_fmt(bp, fmt_type);
    }
}