Exemple #1
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;
}
Exemple #2
0
HIDDEN void
do_silly_nastran_shortcuts(void)
{
    int field_no;

    for (field_no=0; field_no < NO_OF_FIELDS; field_no++) {
	if (BU_STR_EQUAL(curr_rec[field_no], "=")) {
	    bu_strlcpy(curr_rec[field_no], prev_rec[field_no], FIELD_LENGTH);
	} else if (BU_STR_EQUAL(curr_rec[field_no], "==")) {
	    while (field_no < NO_OF_FIELDS) {
		bu_strlcpy(curr_rec[field_no], prev_rec[field_no], FIELD_LENGTH);
		field_no++;
	    }
	} else if (curr_rec[field_no][0] == '*') {
	    int i=0;

	    while (curr_rec[field_no][++i] == '(');

	    if (strchr(prev_rec[field_no], '.')) {
		fastf_t a, b;

		a = atof(prev_rec[field_no]);
		b = atof(&curr_rec[field_no][i]);
		sprintf(curr_rec[field_no], "%-#*E", FIELD_LENGTH-6, a+b);
	    } else {
		int a, b;

		a = atoi(prev_rec[field_no]);
		b = atoi(&curr_rec[field_no][i]);
		sprintf(curr_rec[field_no], "%d", a+b);
	    }
	}
    }
}
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;
    }
}
Exemple #4
0
int
bu_file_delete(const char *path)
{
    int fd = 0;
    int ret = 0;
    int retry = 0;
    struct stat sb;

    /* reject empty, special, or non-existent paths */
    if (!path
	|| BU_STR_EQUAL(path, "")
	|| BU_STR_EQUAL(path, ".")
	|| BU_STR_EQUAL(path, "..")
	|| !bu_file_exists(path, &fd))
    {
	return 0;
    }

    do {

	if (retry++) {
	    /* second pass, try to force deletion by changing file
	     * permissions (similar to rm -f).
	     */
	    if (fstat(fd, &sb) == -1) {
		break;
	    }
	    bu_fchmod(fd, (sb.st_mode|S_IRWXU));
	}

	ret = (remove(path) == 0) ? 0 : 1;

    } while (ret == 0 && retry < 2);
    close(fd);

    /* all boils down to whether the file still exists, not whether
     * remove thinks it succeeded.
     */
    if (bu_file_exists(path, &fd)) {
	/* failure */
	if (retry > 1) {
	    /* restore original file permission */
	    bu_fchmod(fd, sb.st_mode);
	}
	close(fd);
	return 0;
    } else {
	/* deleted */
	return 1;
    }
}
/*
 *	Get ascii input file and output file names.
 */
int
main(int argc, char **argv)
{
    char		*afile = "-", *bfile = "nmg.g";
    FILE		*fpin;
    struct rt_wdb	*fpout;

    if ( BU_STR_EQUAL(argv[1],"-h") || BU_STR_EQUAL(argv[1],"-?")) {
	usage();
	bu_exit(1, NULL);
    }

    if (isatty(fileno(stdin)) && isatty(fileno(stdout)) && argc == 1) {
	usage();
	bu_log("       Program continues running:\n");
    }

    bu_setprogname(argv[0]);

    /* Get ascii NMG input file name. */
    if (bu_optind >= argc || (int)(*argv[1]) == '-') {
	fpin = stdin;
	setmode(fileno(fpin), O_BINARY);
	bu_log("%s: will be reading from stdin\n",argv[0]);
    } else {
	afile = argv[bu_optind];
	if ((fpin = fopen(afile, "rb")) == NULL) {
	    fprintf(stderr,
		    "%s: cannot open %s for reading\n",
		    argv[0], afile);
	    bu_exit(1, NULL);
	}
    bu_log("%s: will be reading from file %s\n",argv[0],afile);
    }

    /* Get BRL-CAD output data base name. */
    bu_optind++;
    if (bu_optind < argc)
	bfile = argv[bu_optind];
    if ((fpout = wdb_fopen(bfile)) == NULL) {
	fprintf(stderr, "%s: cannot open %s for writing\n",
		argv[0], bfile);
	bu_exit(1, NULL);
    }
    bu_log("%s: will be creating file %s\n",argv[0],bfile);

    ascii_to_brlcad(fpin, fpout, "nmg", NULL);
    fclose(fpin);
    wdb_close(fpout);
    return 0;
}
Exemple #6
0
int
main(int argc, char *argv[])
{
    point_t a, b, c, d;
    struct rt_wdb *fp;
    struct rt_nurb_internal *si;
    char *filename = "spltest.g";
    int helpflag;

    if (argc < 1 || argc > 2) {
    	printusage(argv);
	bu_exit(1,NULL);
    }

    helpflag = (argc == 2 && ( BU_STR_EQUAL(argv[1],"-h") || BU_STR_EQUAL(argv[1],"-?")));
    if (argc == 1 || helpflag) {
    	printusage(argv);
	if (helpflag)
		bu_exit(1,NULL);
	bu_log("       Program continues running:\n");
    }

    if (argc == 2)
	filename = argv[1];

    if ((fp = wdb_fopen(filename)) == NULL) {
	perror("unable to open geometry database for writing");
	bu_exit(1, "unable to open new database [%s]\n", filename);
    }

    mk_id(fp, "Mike's Spline Test");

    VSET(a,  0,  0,  0);
    VSET(b, 10,  0,  -5);
    VSET(c, 10, 10,  10);
    VSET(d,  0, 10,  0);

    BU_ALLOC(si, struct rt_nurb_internal);
    si->magic = RT_NURB_INTERNAL_MAGIC;
    si->nsrf = 0;
    si->srfs = (struct face_g_snurb **)bu_malloc(sizeof(struct face_g_snurb *)*100, "allocate snurb ptrs");

    make_face(si, a, b, c, d, 2);

    /* wdb_export */
    mk_export_fwrite(fp, "spltest", (void *)si, ID_BSPLINE);
    bu_log("Saving file %s\n",filename);

    return 0;
}
Exemple #7
0
static int
GetArgs(int argc, const char *argv[])			/* process command arguments */
    /* argument count */
    /* argument strings */
{
    static int iflag = 0;	/* set if "-i" option found */
    static int oflag = 0;	/* set if "-o" option found */
    int c;		/* option letter */

    bu_optind = 1;
    while ((c = bu_getopt(argc, (char * const *)argv, "i:o:h?")) != -1)
	switch (c) {
	    case 'i':
		if (iflag) {
		    printf("cad_parea: too many -i options\n");
		    return 0;
		}
		iflag = 1;

		if (!BU_STR_EQUAL(bu_optarg, "-")
		    && freopen(bu_optarg, "r", stdin) == NULL
		    ) {
		    printf("cad_parea: can't open \"%s\" for reading\n", bu_optarg);
		    return 0;
		}
		break;

	    case 'o':
		if (oflag) {
		    printf("cad_parea: too many -o options\n");
		    return 0;
		}
		oflag = 1;

		if (!BU_STR_EQUAL(bu_optarg, "-")
		    && freopen(bu_optarg, "w", stdout) == NULL
		    ) {
		    printf("cad_parea: can't open \"%s\" for writing\n", bu_optarg);
		    return 0;
		}
		break;

	    default:
		Usage();	/* print usage message */
		return 0;
	}

    return 1;
}
int
main(int argc, char **argv)
{
    fb *fbp;
    FILE *fp;
    int fbsize = 512;
    int i;

    while (argc > 1) {
	if (BU_STR_EQUAL(argv[1], "-H")) {
	    fbsize = 1024;
	} else if (argv[1][0] == '-') {
	    if ( (!BU_STR_EQUAL(argv[1], "-?")) && (!BU_STR_EQUAL(argv[1], "-h")) )
		fprintf(stderr, "fb-cmap: unknown flag %s\n", argv[1]);
	    bu_exit(1, "%s", usage);
	} else
	    break;	/* must be a filename */
	argc--;
	argv++;
    }

    if (argc > 1) {
	if ((fp = fopen(argv[1], "wb")) == NULL) {
	    fprintf(stderr, "fb-cmap: can't open \"%s\"\n", argv[1]);
	    bu_exit(2, "%s", usage);
	}
    } else {
	fp = stdout;
	if (isatty(fileno(fp)))
	    fprintf(stderr, "%s       Program continues running:\n", usage);
    }

    if ((fbp = fb_open(NULL, fbsize, fbsize)) == FB_NULL)
	bu_exit(2, "Unable to open framebuffer\n");

    i = fb_rmap(fbp, &cm);
    fb_close(fbp);
    if (i < 0) {
	bu_exit(3, "fb-cmap: can't read colormap\n");
    }

    for (i = 0; i <= 255; i++) {
	fprintf(fp, "%d\t%04x %04x %04x\n", i,
		cm.cm_red[i], cm.cm_green[i], cm.cm_blue[i]);
    }

    return 0;
}
Exemple #9
0
/* Test against basename UNIX tool */
void
automatic_test(const char *input)
{

    char buf_input[1000];
    char *ans = NULL;
    char *res = (char *)bu_calloc(strlen(buf_input), sizeof(char), "automatic_test res");

#ifdef HAVE_BASENAME
    if (input)
	bu_strlcpy(buf_input, input, strlen(input)+1);

    /* build UNIX 'basename' command */
    if (!input)
	ans = basename(NULL);
    else
	ans = basename(buf_input);

    if (!input)
	bu_basename(res, NULL);
    else
	bu_basename(res, buf_input);

    if (BU_STR_EQUAL(res, ans))
	printf("%24s -> %24s [PASSED]\n", input, res);
    else
	bu_exit(EXIT_FAILURE, "%24s -> %24s (should be: %s) [FAIL]\n", input, res, ans);
    bu_free(res, NULL);

#else
    printf("BASENAME not available on this platform\n");
#endif
    /* FIXME: this does not functionally halt */
}
struct directory *
db_lookup(const struct db_i *dbip, const char *name, int noisy)
{
    struct directory *dp;
    char n0;
    char n1;

    if (!name || name[0] == '\0') {
	if (noisy || RT_G_DEBUG&DEBUG_DB)
	    bu_log("db_lookup received NULL or empty name\n");
	return RT_DIR_NULL;
    }

    n0 = name[0];
    n1 = name[1];

    RT_CK_DBI(dbip);

    dp = dbip->dbi_Head[db_dirhash(name)];
    for (; dp != RT_DIR_NULL; dp=dp->d_forw) {
	char *this_obj;

	/* first two checks are for speed */
	if ((n0 == *(this_obj=dp->d_namep)) && (n1 == this_obj[1]) && (BU_STR_EQUAL(name, this_obj))) {
	    if (RT_G_DEBUG&DEBUG_DB)
		bu_log("db_lookup(%s) %p\n", name, (void *)dp);
	    return dp;
	}
    }

    if (noisy || RT_G_DEBUG&DEBUG_DB)
	bu_log("db_lookup(%s) failed: %s does not exist\n", name, name);

    return RT_DIR_NULL;
}
Exemple #11
0
int
main(int argc, char *argv[])
{
    int i, num;
    double scale = 1.0;
    size_t ret;

    float ibuf[512];
    double obuf[512];

    if (argc > 1) {
	if (!BU_STR_EQUAL(argv[1], "-n"))
	    scale = atof(argv[1]);
	argc--;
    }

    if (argc > 1 || ZERO(scale) || isatty(fileno(stdin)) || isatty(fileno(stdout)))
	bu_exit(1, "Usage: f-d [-n || scale] < floats > doubles\n");

    while ((num = fread(&ibuf[0], sizeof(ibuf[0]), 512, stdin)) > 0) {
	if (EQUAL(scale, 1.0)) {
	    for (i = 0; i < num; i++)
		obuf[i] = ibuf[i];
	} else {
	    for (i = 0; i < num; i++)
		obuf[i] = ibuf[i] * scale;
	}

	ret = fwrite(&obuf[0], sizeof(obuf[0]), num, stdout);
	if (ret != (size_t)num)
	    perror("fwrite");
    }
    return 0;
}
Exemple #12
0
int
compare_tcl_combs(Tcl_Obj *obj1, struct directory *dp1, Tcl_Obj *obj2)
{
    int junk;
    struct bu_vls adjust = BU_VLS_INIT_ZERO;
    int different = 0;

    /* first check if there is any difference */
    if (BU_STR_EQUAL(Tcl_GetStringFromObj(obj1, &junk), Tcl_GetStringFromObj(obj2, &junk)))
	return 0;

    if (mode != HUMAN) {
	bu_vls_printf(&adjust, "db adjust %s", dp1->d_namep);
    }

    different = do_compare(PARAMS, &adjust, obj1, obj2, dp1->d_namep);

    if (mode != HUMAN) {
	printf("%s\n", bu_vls_addr(&adjust));
    }

    bu_vls_free(&adjust);

    return different;
}
Exemple #13
0
void
open_file(FILE **fp, char *name)
{
    /* check for special names */
    if (BU_STR_EQUAL(name, "-")) {
	*fp = stdin;
	return;
    } else if (BU_STR_EQUAL(name, ".")) {
	*fp = fopen("/dev/null", "r");
	return;
    }

    if ((*fp = fopen(name, "r")) == NULL) {
	bu_exit(2, "d2-c: Can't open \"%s\"\n", name);
    }
}
Exemple #14
0
HIDDEN struct bu_cmdhist_obj *
cho_open(ClientData UNUSED(clientData), Tcl_Interp *interp, const char *name)
{
    struct bu_cmdhist_obj *chop;

    /* check to see if command history object exists */
    for (BU_LIST_FOR(chop, bu_cmdhist_obj, &HeadCmdHistObj.l)) {
	if (BU_STR_EQUAL(name, bu_vls_addr(&chop->cho_name))) {
	    Tcl_AppendResult(interp, "ch_open: ", name,
			     " exists.\n", (char *)NULL);
	    return BU_CMDHIST_OBJ_NULL;
	}
    }

    BU_GET(chop, struct bu_cmdhist_obj);
    bu_vls_init(&chop->cho_name);
    bu_vls_strcpy(&chop->cho_name, name);
    BU_LIST_INIT(&chop->cho_head.l);
    bu_vls_init(&chop->cho_head.h_command);
    chop->cho_head.h_start.tv_sec = chop->cho_head.h_start.tv_usec =
	chop->cho_head.h_finish.tv_sec = chop->cho_head.h_finish.tv_usec = 0L;
    chop->cho_head.h_status = TCL_OK;
    chop->cho_curr = &chop->cho_head;

    BU_LIST_APPEND(&HeadCmdHistObj.l, &chop->l);
    return chop;
}
/* return 0 when IS a light or an error occurred. regions are skipped
 * when this function returns 0.
 */
static int
select_non_lights(struct db_tree_state *UNUSED(tsp), const struct db_full_path *pathp, const struct rt_comb_internal *UNUSED(combp), void *UNUSED(client_data))
{
    struct directory *dp;
    struct rt_db_internal intern;
    struct rt_comb_internal *comb;
    int id;

    RT_CK_FULL_PATH(pathp);
    dp = DB_FULL_PATH_CUR_DIR(pathp);

    id = rt_db_get_internal(&intern, dp, dbip, (matp_t)NULL, &rt_uniresource);
    if (id < 0) {
	/* error occurred retrieving object */
	bu_log("Warning: Can not load internal form of %s\n", dp->d_namep);
	return 0;
    }

    if ((dp->d_flags & RT_DIR_COMB) && (id == ID_COMBINATION)) {
	comb = (struct rt_comb_internal *)intern.idb_ptr;
	RT_CK_COMB(comb);
	if (BU_STR_EQUAL(bu_vls_addr(&comb->shader), "light")) {
	    rt_db_free_internal(&intern);
	    return 0;
	}
    }

    return 1;
}
HIDDEN void
find_ref(struct db_i *dbip,
	 struct rt_comb_internal *comb,
	 union tree *comb_leaf,
	 void *object,
	 void *comb_name_ptr,
	 void *user_ptr3,
	 void *UNUSED(user_ptr4))
{
    char *obj_name;
    char *comb_name;
    struct ged *gedp = (struct ged *)user_ptr3;

    if (dbip) RT_CK_DBI(dbip);
    if (comb) RT_CK_COMB(comb);
    RT_CK_TREE(comb_leaf);

    obj_name = (char *)object;
    if (!BU_STR_EQUAL(comb_leaf->tr_l.tl_name, obj_name))
	return;

    comb_name = (char *)comb_name_ptr;

    bu_vls_printf(gedp->ged_result_str, "%s ", comb_name);
}
Exemple #17
0
/**
 * Routine to format the parameters of an ARBN primitive for "db get"
 *
 * Legal requested parameters include:
 *	"N" - number of equations
 *	"P" - list of all the planes
 *	"P#" - the specified plane number (0 based)
 *	no arguments returns everything
 */
int
rt_arbn_get(struct bu_vls *logstr, const struct rt_db_internal *intern, const char *attr)
{
    struct rt_arbn_internal *arbn=(struct rt_arbn_internal *)intern->idb_ptr;
    size_t i;
    long val;

    RT_ARBN_CK_MAGIC(arbn);

    if (attr == (char *)NULL) {
	bu_vls_strcpy(logstr, "arbn");
	bu_vls_printf(logstr, " N %zu", arbn->neqn);
	for (i = 0; i < arbn->neqn; i++) {
	    bu_vls_printf(logstr, " P%zu {%.25g %.25g %.25g %.25g}", i,
			  V4ARGS(arbn->eqn[i]));
	}
    } else if (BU_STR_EQUAL(attr, "N")) {
	bu_vls_printf(logstr, "%zu", arbn->neqn);
    } else if (BU_STR_EQUAL(attr, "P")) {
	for (i = 0; i < arbn->neqn; i++) {
	    bu_vls_printf(logstr, " P%zu {%.25g %.25g %.25g %.25g}", i,
			  V4ARGS(arbn->eqn[i]));
	}
    } else if (attr[0] == 'P') {
	if (isdigit((int)attr[1]) == 0) {
	    bu_vls_printf(logstr, "ERROR: Illegal plane number\n");
	    return BRLCAD_ERROR;
	}

	val = atol(&attr[1]);
	if (val < 0 || (size_t)val >= arbn->neqn) {
	    bu_vls_printf(logstr, "ERROR: Illegal plane number [%ld]\n", val);
	    return BRLCAD_ERROR;
	}
	i = (size_t)val;

	bu_vls_printf(logstr, "%.25g %.25g %.25g %.25g", V4ARGS(arbn->eqn[i]));
    } else {
	bu_vls_printf(logstr, "ERROR: Unknown attribute, choices are N, P, or P#\n");
	return BRLCAD_ERROR;
    }

    return BRLCAD_OK;
}
/**
 * compares an input units string to a reference units name and
 * returns truthfully if they match.  the comparison ignores any
 * embedded whitespace and is case insensitive.
 */
static int
units_name_matches(const char *input, const char *name)
{
    const char *cp;
    int match;
    struct bu_vls normalized_input = BU_VLS_INIT_ZERO;
    struct bu_vls normalized_name = BU_VLS_INIT_ZERO;

    /* convert NULL */
    if (!input)
	input = "";
    if (!name)
	name = "";

    /* skip spaces */
    while (isspace((unsigned char)*input))
	input++;
    while (isspace((unsigned char)*name))
	name++;

    /* quick exit */
    if (tolower((unsigned char)input[0]) != tolower((unsigned char)name[0]))
	return 0;

    cp = input;
    /* skip spaces, convert to lowercase */
    while (*cp != '\0') {
	if (!isspace((unsigned char)*cp))
	    bu_vls_putc(&normalized_input, tolower((unsigned char)*cp));
	cp++;
    }

    cp = name;
    /* skip spaces, convert to lowercase */
    while (*cp != '\0') {
	if (!isspace((unsigned char)*cp))
	    bu_vls_putc(&normalized_name, tolower((unsigned char)*cp));
	cp++;
    }

    /* trim any trailing 's' for plurality */
    if (bu_vls_addr(&normalized_input)[bu_vls_strlen(&normalized_input)-1] == 's') {
	bu_vls_trunc(&normalized_input, -1);
    }
    if (bu_vls_addr(&normalized_name)[bu_vls_strlen(&normalized_name)-1] == 's') {
	bu_vls_trunc(&normalized_name, -1);
    }

    /* compare */
    match = BU_STR_EQUAL(bu_vls_addr(&normalized_input), bu_vls_addr(&normalized_name));

    bu_vls_free(&normalized_input);
    bu_vls_free(&normalized_name);

    return match;
}
Exemple #19
0
/**
 * returns the location of 'name' in the list if it exists, returns
 * -1 otherwise.
 */
static int
index_in_list(struct nametbl l, char *name)
{
    size_t i;

    for (i = 0; i < l.names_used; i++)
	if (BU_STR_EQUAL(bu_vls_addr(&l.names[i].src), name))
	    return i;
    return -1;
}
Exemple #20
0
/*
 * Validate 'point file data format string', determine and output the
 * point-cloud type. A valid null terminated string is expected as
 * input.  The function returns GED_ERROR if the format string is
 * invalid or if null pointers were passed to the function.
 */
int
str2type(const char *format_string, rt_pnt_type *pnt_type, struct bu_vls *ged_result_str)
{
    struct bu_vls str = BU_VLS_INIT_ZERO;
    char *temp_string = (char *)NULL;
    size_t idx = 0;
    size_t format_string_length = 0;
    int ret = GED_OK;

    if ((format_string == (char *)NULL) || (pnt_type == (rt_pnt_type *)NULL)) {
        bu_vls_printf(ged_result_str, "NULL pointer(s) passed to function 'str2type'.\n");
        ret = GED_ERROR;
    } else {
        format_string_length = strlen(format_string);

        /* remove any '?' from format string before testing for point-cloud type */
        for (idx = 0 ; idx < format_string_length ; idx++) {
            if (format_string[idx] != '?') {
                bu_vls_putc(&str, format_string[idx]);
            }
        }

        bu_vls_trimspace(&str);

        temp_string = bu_vls_addr(&str);
        bu_sort(temp_string, strlen(temp_string), sizeof(char), (int (*)(const void *a, const void *b, void *arg))compare_char, NULL);

        if (BU_STR_EQUAL(temp_string, "xyz")) {
            *pnt_type = RT_PNT_TYPE_PNT;
        } else if (BU_STR_EQUAL(temp_string, "bgrxyz")) {
            *pnt_type = RT_PNT_TYPE_COL;
        } else if (BU_STR_EQUAL(temp_string, "sxyz")) {
            *pnt_type = RT_PNT_TYPE_SCA;
        } else if (BU_STR_EQUAL(temp_string, "ijkxyz")) {
            *pnt_type = RT_PNT_TYPE_NRM;
        } else if (BU_STR_EQUAL(temp_string, "bgrsxyz")) {
            *pnt_type = RT_PNT_TYPE_COL_SCA;
        } else if (BU_STR_EQUAL(temp_string, "bgijkrxyz")) {
            *pnt_type = RT_PNT_TYPE_COL_NRM;
        } else if (BU_STR_EQUAL(temp_string, "ijksxyz")) {
            *pnt_type = RT_PNT_TYPE_SCA_NRM;
        } else if (BU_STR_EQUAL(temp_string, "bgijkrsxyz")) {
            *pnt_type = RT_PNT_TYPE_COL_SCA_NRM;
        } else {
            bu_vls_printf(ged_result_str, "Invalid format string '%s'", format_string);
            ret = GED_ERROR;
        }
    }

    bu_vls_free(&str);

    return ret;
}
Exemple #21
0
int
main(int argc, char **argv)
{
    unsigned char ibuf[512];
    double obuf[512];

    int i, num;
    double scale = 1.0;
    size_t ret;

    if (BU_STR_EQUAL(argv[1], "-h") || BU_STR_EQUAL(argv[1], "-?"))
        printusage();

    if (argc > 1) {
        if (BU_STR_EQUAL(argv[1], "-n"))
            scale = 1.0/255.0;
        else
            scale = atof(argv[1]);
        argc--;
    }

    if (argc > 1 || ZERO(scale) || isatty(fileno(stdin))) {
        fprintf(stderr, "bad argument\n");
        printusage();
    }

    while ((num = fread(&ibuf[0], sizeof(ibuf[0]), 512, stdin)) > 0) {
        if (EQUAL(scale, 1.0)) {
            for (i = 0; i < num; i++)
                obuf[i] = ibuf[i];
        } else {
            for (i = 0; i < num; i++)
                obuf[i] = (double)ibuf[i] * scale;
        }

        ret = fwrite(&obuf[0], sizeof(obuf[0]), num, stdout);
        if (ret != (size_t)num)
            perror("fwrite");
    }

    return 0;
}
Exemple #22
0
int
main(int argc, char **argv)
{
    double factor, temp;
    int i, j, doit, of, count, val, *col_list;

    if ( BU_STR_EQUAL(argv[1], "-h") || BU_STR_EQUAL(argv[1], "-?") )
	printusage();
    if (argc < 4)
	printusage();

    sscanf(*(argv+1), "%lf", &factor);
    sscanf(*(argv+2), "%d", &of);
    col_list = (int *) bu_calloc(argc-2, sizeof(int), "int array");
    for (i=3;i<argc;i++) {
	sscanf(*(argv+i), "%d", col_list+(i-3));
    }

    count = 0;
    while (!feof(stdin)) {
	val = scanf("%lf", &temp);
	if (val<1)
	    ;
	else {
	    doit = 0;
	    for (j=0;j<argc-3;j++) {
		if (col_list[j]==count)
		    doit = 1;
	    }
	    if (doit)
		printf("%.10g\t", temp*factor);
	    else
		printf("%.10g\t", temp);
	}
	if (count == (of-1))
	    printf("\n");
	count = (count+1)%of;
    }

    bu_free(col_list, "int array");
    return 0;
}
int
ged_log(struct ged *gedp, int argc, const char *argv[])
{
    static char *usage = "get|start|stop";

    GED_CHECK_DATABASE_OPEN(gedp, GED_ERROR);
    GED_CHECK_READ_ONLY(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;
    }

    if (argc != 2) {
	bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", argv[0], usage);
	return GED_ERROR;
    }

    if (argv[1][0] == 'g' && BU_STR_EQUAL(argv[1], "get")) {
	bu_vls_vlscatzap(gedp->ged_result_str, gedp->ged_log);
	return GED_OK;
    }

    if (argv[1][0] == 's' && BU_STR_EQUAL(argv[1], "start")) {
	bu_log_add_hook(log_hook, (void *)gedp->ged_log);
	return GED_OK;
    }

    if (argv[1][0] == 's' && BU_STR_EQUAL(argv[1], "stop")) {
	bu_log_delete_hook(log_hook, (void *)gedp->ged_log);
	return GED_OK;
    }

    bu_log("Usage: %s %s ", argv[0], usage);
    return GED_ERROR;
}
/*
 * Set/get the unix plot output mode
 *
 * Usage:
 * set_uplotOutputMode [binary|text]
 *
 */
int
ged_set_uplotOutputMode(struct ged *gedp, int argc, const char *argv[])
{
    static const char *usage = "[binary|text]";

    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);

    if (argc > 2) {
	bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", argv[0], usage);
	return GED_ERROR;
    }

    /* Get the plot output mode */
    if (argc == 1) {
	if (gedp->ged_gdp->gd_uplotOutputMode == PL_OUTPUT_MODE_BINARY)
	    bu_vls_printf(gedp->ged_result_str, "binary");
	else
	    bu_vls_printf(gedp->ged_result_str, "text");

	return GED_OK;
    }

    if (argv[1][0] == 'b' &&
	BU_STR_EQUAL("binary", argv[1]))
	gedp->ged_gdp->gd_uplotOutputMode = PL_OUTPUT_MODE_BINARY;
    else if (argv[1][0] == 't' &&
	     BU_STR_EQUAL("text", argv[1]))
	gedp->ged_gdp->gd_uplotOutputMode = PL_OUTPUT_MODE_TEXT;
    else {
	bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", argv[0], usage);
	return GED_ERROR;
    }


    return GED_OK;
}
HIDDEN int
dsk_open(fb *ifp, const char *file, int width, int height)
{
    static char zero = 0;

    FB_CK_FB(ifp);

    /* check for default size */
    if (width == 0)
	width = ifp->if_width;
    if (height == 0)
	height = ifp->if_height;

    if (BU_STR_EQUAL(file, "-")) {
	/*
	 * It is the applications job to write ascending scanlines.
	 * If it does not, then this can be stacked with /dev/mem,
	 * i.e.	/dev/mem -
	 */
	ifp->if_fd = 1;		/* fileno(stdout) */
	ifp->if_width = width;
	ifp->if_height = height;
	ifp->if_seekpos = 0;
	return 0;
    }

    if ((ifp->if_fd = open(file, O_RDWR | O_BINARY, 0)) == -1
	&& (ifp->if_fd = open(file, O_RDONLY | O_BINARY, 0)) == -1) {
	if ((ifp->if_fd = open(file, O_RDWR | O_CREAT | O_BINARY, 0664)) > 0) {
	    /* New file, write byte at end */
	    if (lseek(ifp->if_fd, (height*width*sizeof(RGBpixel)-1), 0) == -1) {
		fb_log("disk_device_open : can not seek to end of new file.\n");
		return -1;
	    }
	    if (write(ifp->if_fd, &zero, 1) < 0) {
		fb_log("disk_device_open : initial write failed.\n");
		return -1;
	    }
	} else
	    return -1;
    }

    setmode(ifp->if_fd, O_BINARY);

    ifp->if_width = width;
    ifp->if_height = height;
    if (lseek(ifp->if_fd, 0, 0) == -1) {
	fb_log("disk_device_open : can not seek to beginning.\n");
	return -1;
    }
    ifp->if_seekpos = 0;
    return 0;
}
Exemple #26
0
int
main(int argc, char *argv[])
{
    static char usage[]="Usage: dsel keep ...\n       or\n       dsel skip keep ...\n\n(must use <inputfile >outputfile)\n";

    int nskip;	/* number to skip */
    int nkeep;	/* number to keep */

    if (isatty(fileno(stdin)) || isatty(fileno(stdout)))
	bu_exit(1, "%s", usage);
    if (BU_STR_EQUAL(argv[1], "-h") || BU_STR_EQUAL(argv[1], "-?"))
	bu_exit(1, "%s", usage);

    if (argc == 2) {
	keep(atoi(argv[1]));
	exit(0);
    }

    while (argc > 1) {
	nskip = atoi(argv[1]);
	argc--;
	argv++;
	if (nskip > 0)
	    skip(nskip);

	if (argc > 1) {
	    nkeep = atoi(argv[1]);
	    argc--;
	    argv++;
	} else {
#define INTEGER_MAX (((int) ~0) >> 1)
	    nkeep = INTEGER_MAX;
	}

	if (nkeep <= 0)
	    exit(0);
	keep(nkeep);
    }
    return 0;
}
Exemple #27
0
int
ged_bot_flip(struct ged *gedp, int argc, const char *argv[])
{
    int i;
    struct directory *dp;
    struct rt_db_internal intern;
    struct rt_bot_internal *bot;
    static const char *usage = "bot [bot2 bot3 ...]";

    GED_CHECK_DATABASE_OPEN(gedp, GED_ERROR);
    GED_CHECK_READ_ONLY(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;
    }

    for (i = 1; i < argc; ++i) {
	/* Skip past any path elements */
	char *obj = (char *)bu_calloc(strlen(argv[i]), sizeof(char), "ged_bot_flip obj");
	bu_basename(obj, argv[i]);

	if (BU_STR_EQUAL(obj, ".")) {
	    /* malformed path, lookup using exactly what was provided */
	    bu_free(obj, "free bu_basename");
	    obj = bu_strdup(argv[i]);
	}

	if ((dp = db_lookup(gedp->ged_wdbp->dbip, obj, LOOKUP_QUIET)) == RT_DIR_NULL) {
	    bu_vls_printf(gedp->ged_result_str, "%s: db_lookup(%s) error\n", argv[0], obj);
	} else {
	    GED_DB_GET_INTERNAL(gedp, &intern, dp, bn_mat_identity, &rt_uniresource, GED_ERROR);

	    if (intern.idb_major_type != DB5_MAJORTYPE_BRLCAD || intern.idb_minor_type != DB5_MINORTYPE_BRLCAD_BOT) {
		bu_vls_printf(gedp->ged_result_str, "%s: %s is not a BOT solid!\n", argv[0], obj);
	    } else {
		bot = (struct rt_bot_internal *)intern.idb_ptr;
		rt_bot_flip(bot);

		GED_DB_PUT_INTERNAL(gedp, dp, &intern, gedp->ged_wdbp->wdb_resp, GED_ERROR);
	    }
	}
	bu_free(obj, "free obj");
    }

    return GED_OK;
}
Exemple #28
0
HIDDEN int
txt_setup(register struct region *rp, struct bu_vls *matparm, void **dpp, const struct mfuncs *mfp, struct rt_i *rtip)
{
    register struct txt_specific *tp;
    int pixelbytes = 3;

    BU_CK_VLS(matparm);
    BU_GET(tp, struct txt_specific);
    *dpp = tp;

    bu_vls_init(&tp->tx_name);

    /* defaults */
    tp->tx_w = tp->tx_n = -1;
    tp->tx_trans_valid = 0;
    tp->tx_scale[X] = 1.0;
    tp->tx_scale[Y] = 1.0;
    tp->tx_mirror = 0;
    tp->tx_datasrc = 0; /* source is auto-located by default */
    tp->tx_binunifp = NULL;
    tp->tx_mp = NULL;

    /* load given values */
    if (bu_struct_parse(matparm, txt_parse, (char *)tp) < 0) {
	BU_PUT(tp, struct txt_specific);
	return -1;
    }

    /* validate values */
    if (tp->tx_w < 0) tp->tx_w = 512;
    if (tp->tx_n < 0) tp->tx_n = tp->tx_w;
    if (tp->tx_trans_valid) rp->reg_transmit = 1;
    BU_CK_VLS(&tp->tx_name);
    if (bu_vls_strlen(&tp->tx_name) <= 0) return -1;
    /* !?! if (tp->tx_name[0] == '\0') return -1;	*/ /* FAIL, no file */

    if (BU_STR_EQUAL(mfp->mf_name, "bwtexture")) pixelbytes = 1;

    /* load the texture from its datasource */
    if (txt_load_datasource(tp, rtip->rti_dbip, tp->tx_w * tp->tx_n * pixelbytes)<0) {
	bu_log("\nERROR: txt_setup() %s %s could not be loaded [source was %s]\n", rp->reg_name, bu_vls_addr(&tp->tx_name), tp->tx_datasrc==TXT_SRC_OBJECT?"object":tp->tx_datasrc==TXT_SRC_FILE?"file":"auto");
	return -1;
    }


    if (rdebug & RDEBUG_SHADE) {
	bu_log("txt_setup: texture loaded!  type=%s name=%s\n", tp->tx_datasrc==TXT_SRC_AUTO?"auto":tp->tx_datasrc==TXT_SRC_OBJECT?"object":tp->tx_datasrc==TXT_SRC_FILE?"file":"unknown", bu_vls_addr(&tp->tx_name));
	bu_struct_print("texture", txt_parse, (char *)tp);
    }

    return 1;				/* OK */
}
Exemple #29
0
int
main(int argc, char **argv)
{
    int depth;

    if (argc != 2 || BU_STR_EQUAL(argv[1],"-h") || BU_STR_EQUAL(argv[1],"-?")) {
	fprintf(stderr, "Usage: pyramid recursion\n      (the argument is of type integer)\n");
	return 1;
    }
    depth = atoi(argv[1]);
    sin60 = sin(60.0 * DEG2RAD);

    outfp = wdb_fopen("pyramid.g");
    printf("Creating file pyramid.g\n");

    mk_id(outfp, "3-D Pyramids");

    do_leaf("leaf");
    do_tree("tree", "leaf", depth);

    return 0;
}
Exemple #30
0
int off2nmg(FILE *fpin, struct rt_wdb *fpout)
{
    char title[64], geom_fname[64];
    char rname[67], sname[67];
    char buf[200], buf2[200];

    FILE *fgeom;
    struct model *m;

    title[0] = geom_fname[0] = '\0';

    bu_fgets(buf, sizeof(buf), fpin);
    while (!feof(fpin)) {
	/* Retrieve the important data */
	if (sscanf(buf, "name %[^\n]s", buf2) > 0)
	    bu_strlcpy(title, buf2, sizeof(title));
	if (sscanf(buf, "geometry %200[^\n]s", buf2) > 0) {
	    char dtype[40], format[40];
	    if (sscanf(buf2, "%40s %40s %64s", dtype, format, geom_fname) != 3)
		bu_exit(1, "Incomplete geometry field in input file.");
	    if (!BU_STR_EQUAL(dtype, "indexed_poly"))
		bu_exit(1, "Unknown geometry data type. Must be \"indexed_poly\".");
	}
	bu_fgets(buf, sizeof(buf), fpin);
    }

    if (strlen(title) < (unsigned)1)
	fprintf(stderr, "Warning: no title\n");

    if (strlen(geom_fname) < (unsigned)1)
	bu_exit(1, "ERROR: no geometry filename given");

    if ((fgeom = fopen(geom_fname, "rb")) == NULL) {
	bu_exit(1, "off2nmg: cannot open %s (geometry description) for reading\n",
		geom_fname);
    }

    m = nmg_mm();
    read_faces(m, fgeom);
    fclose(fgeom);

    snprintf(sname, 67, "s.%s", title);
    snprintf(rname, 67, "r.%s", title);

    mk_id(fpout, title);
    mk_nmg(fpout, sname, m);
    mk_comb1(fpout, rname, sname, 1);

    nmg_km(m);
    return 0;
}