コード例 #1
0
ファイル: setup.c プロジェクト: kanzure/brlcad
/**
 * Register all MGED commands.
 */
HIDDEN void
cmd_setup(void)
{
    struct cmdtab *ctp;
    struct bu_vls temp = BU_VLS_INIT_ZERO;
    const char *pathname;
    char buffer[1024];

    /* from cmd.c */
    extern int glob_compat_mode;
    extern int output_as_return;

    for (ctp = mged_cmdtab; ctp->name != NULL; ctp++) {
	bu_vls_strcpy(&temp, "_mged_");
	bu_vls_strcat(&temp, ctp->name);

	(void)Tcl_CreateCommand(INTERP, ctp->name, ctp->tcl_func,
				(ClientData)ctp, (Tcl_CmdDeleteProc *)NULL);
	(void)Tcl_CreateCommand(INTERP, bu_vls_addr(&temp), ctp->tcl_func,
				(ClientData)ctp, (Tcl_CmdDeleteProc *)NULL);
    }

    /* overrides/wraps the built-in tree command */

    /* Locate the BRL-CAD-specific Tcl scripts */
    pathname = bu_brlcad_data("tclscripts", 1);
    snprintf(buffer, sizeof(buffer), "%s", pathname);

    /* link some tcl variables to these corresponding globals */
    Tcl_LinkVar(INTERP, "glob_compat_mode", (char *)&glob_compat_mode, TCL_LINK_BOOLEAN);
    Tcl_LinkVar(INTERP, "output_as_return", (char *)&output_as_return, TCL_LINK_BOOLEAN);

    /* Provide Tcl interfaces to the fundamental BRL-CAD libraries */
    if (Bu_Init(INTERP) == TCL_ERROR) {
      bu_log("Bu_Init ERROR:\n%s\n", Tcl_GetStringResult(INTERP));
    }
    Bn_Init(INTERP);
    Rt_Init(INTERP);
    Go_Init(INTERP);
    Wdb_Init(INTERP);

    tkwin = NULL;

    bu_vls_free(&temp);
}
コード例 #2
0
/**
 * List formats installed in global nirt data directory
 */
void
listformats(void)
{
    size_t files, i;
    char **filearray = NULL;
    char suffix[6]="*.nrt";
    FILE *cfPtr = NULL;
    int fnddesc;

    struct bu_vls nirtfilespath = BU_VLS_INIT_ZERO;
    struct bu_vls nirtpathtofile = BU_VLS_INIT_ZERO;
    struct bu_vls vlsfileline = BU_VLS_INIT_ZERO;

    /* get a nirt directory listing */
    bu_vls_printf(&nirtfilespath, "%s", bu_brlcad_data("nirt", 0));
    files = bu_dir_list(bu_vls_addr(&nirtfilespath), suffix, &filearray);

    /* open every nirt file we find and extract the description */
    for (i = 0; i < files; i++) {
	bu_vls_trunc(&nirtpathtofile, 0);
	bu_vls_trunc(&vlsfileline, 0);
	bu_vls_printf(&nirtpathtofile, "%s/%s", bu_vls_addr(&nirtfilespath), filearray[i]);
	cfPtr = fopen(bu_vls_addr(&nirtpathtofile), "rb");
	fnddesc = 0;
	while (bu_vls_gets(&vlsfileline, cfPtr) && fnddesc == 0) {
	    if (bu_strncmp(bu_vls_addr(&vlsfileline), "# Description: ", 15) == 0) {
		fnddesc = 1;
		bu_log("%s\n", bu_vls_addr(&vlsfileline)+15);
	    }
	    bu_vls_trunc(&vlsfileline, 0);
	}
	fclose(cfPtr);
    }

    /* release resources */
    bu_free_argv(files, filearray);
    bu_vls_free(&vlsfileline);
    bu_vls_free(&nirtfilespath);
    bu_vls_free(&nirtpathtofile);
}
コード例 #3
0
/**
 * string is a literal or a file name
 */
static void
enqueue_script(struct bu_list *qp, int type, char *string)
{
    struct script_rec *srp;
    FILE *cfPtr;
    struct bu_vls str = BU_VLS_INIT_ZERO;

    BU_CK_LIST_HEAD(qp);

    BU_ALLOC(srp, struct script_rec);
    srp->sr_magic = SCRIPT_REC_MAGIC;
    srp->sr_type = type;
    bu_vls_init(&(srp->sr_script));

    /*Check if supplied file name is local or in brlcad's nirt data dir*/
    if (type == READING_FILE) {
	bu_vls_trunc(&str, 0);
	bu_vls_printf(&str, "%s", string);
	cfPtr = fopen(bu_vls_addr(&str), "rb");
	if (cfPtr == NULL) {
	    bu_vls_trunc(&str, 0);
	    bu_vls_printf(&str, "%s/%s.nrt", bu_brlcad_data("nirt", 0), string);
	    cfPtr = fopen(bu_vls_addr(&str), "rb");
	    if (cfPtr != NULL) {
		fclose(cfPtr);
	    } else {
		bu_vls_trunc(&str, 0);
		bu_vls_printf(&str, "%s", string);
	    }
	} else {
	    fclose(cfPtr);
	}
	bu_vls_printf(&(srp->sr_script), "%s", bu_vls_addr(&str));
    } else {
	bu_vls_strcat(&(srp->sr_script), string);
    }
    BU_LIST_INSERT(qp, &(srp->l));
    bu_vls_free(&str);
}
コード例 #4
0
struct vfont_file
get_font(const char* fontname, void (*vfont_log)(const char *fmt, ...))
{
    struct vfont_file font;
    struct header lochdr;
    static char	fname[FONTNAMESZ];

    /* Initialize vfont */
    memset(&font, 0, sizeof(struct vfont_file));

    if (fontname == NULL)
	fontname = FONTNAME;

    if (fontname[0] != '/') {
	/* absolute path */
	const char *vfont = bu_brlcad_data("vfont", 1);
	if (vfont)
	    snprintf(fname, FONTNAMESZ, "%s/%s", vfont, fontname);
	else
	    bu_strlcpy(fname, fontname, sizeof(fname));
    } else
	bu_strlcpy(fname, fontname, sizeof(fname));

    /* Open the file and read in the header information. */
    font.ffdes = fopen(fname, "rb");
    if (font.ffdes == NULL) {
	if (vfont_log)
	    vfont_log("Error opening font file '%s'\n", fname);

	font.ffdes = NULL;
	return font;
    }

    if (fread((char *)&lochdr, (int)sizeof(struct header), 1, font.ffdes) != 1) {
	if (vfont_log)
	    vfont_log("get_Font() read failed!\n");
	font.ffdes = NULL;
	return font;
    }

    SWAB(lochdr.magic);
    SWAB(lochdr.size);
    SWAB(lochdr.maxx);
    SWAB(lochdr.maxy);
    SWAB(lochdr.xtend);

    if (lochdr.magic != 0436) {
	if (vfont_log)
	    vfont_log("Not a font file \"%s\": magic=0%o\n", fname, (int)lochdr.magic);
	font.ffdes = NULL;
	return font;
    }
    font.hdr = lochdr;

    /* Read in the directory for the font. */
    if (fread((char *) font.dir, (int)sizeof(struct dispatch), 256, font.ffdes) != 256) {
	if (vfont_log)
	    vfont_log("get_Font() read failed!\n");
	font.ffdes = NULL;
	return font;
    }

    /* Addresses of characters in the file are relative to point in
     * the file after the directory, so grab the current position.
     */
    font.offset = bu_ftell(font.ffdes);

    return font;
}
コード例 #5
0
struct vfont *
vfont_get(char *font)
{
    register struct vfont *vfp = VFONT_NULL;
    register FILE *fp = NULL;
    register int i;
    char fname[FONTNAMESZ];
    unsigned char header[2*5];		/* 5 16-bit vax shorts */
    unsigned char dispatch[10*256];	/* 256 10-byte structs */
    uint16_t magic;
    int size;
    const char *const_font;

    const_font = (font == NULL) ? DEFAULT_FONT : (const char *)font;

    /* Open the file and read in the header information. */
    if ((fp = fopen(const_font, "rb")) == NULL) {
	snprintf(fname, FONTNAMESZ, "%s/%s", (char *)bu_brlcad_data("vfont", 0), const_font);
	if ((fp = fopen(fname, "rb")) == NULL) {
	    snprintf(fname, FONTNAMESZ, "%s/%s", FONTDIR2, const_font);
	    if ((fp = fopen(fname, "rb")) == NULL) {
		return VFONT_NULL;
	    }
	}
    }
    if (fread((char *)header, sizeof(header), 1, fp) != 1 ||
	fread((char *)dispatch, sizeof(dispatch), 1, fp) != 1) {
	fprintf(stderr, "vfont_get(%s):  header read error\n", fname);
	fclose(fp);
	return VFONT_NULL;
    }
    magic = _vax_gshort(&header[0*2]) & 0xFFFF;
    size = _vax_gshort(&header[1*2]) & 0xFFFF;	/* unsigned short */

    if (UNLIKELY(magic != 0436)) {
	fprintf(stderr, "vfont_get(%s):  bad magic number 0%o\n",
		fname, magic);
	fclose(fp);
	return VFONT_NULL;
    }

    /* Read in the bit maps */
    BU_ALLOC(vfp, struct vfont);
    vfp->vf_bits = (char *)bu_malloc((size_t)size, "vfont bits");
    if (fread(vfp->vf_bits, (size_t)size, 1, fp) != 1) {
	fprintf(stderr, "vfont_get(%s):  bitmap read error\n", fname);
	fclose(fp);
	bu_free(vfp->vf_bits, "vfont bits");
	bu_free((char *)vfp, "vfont");
	return VFONT_NULL;
    }

    /*
     * Convert VAX data in header[] and dispatch[] arrays to native
     * machine form.
     */
    vfp->vf_maxx = _vax_gshort(&header[2*2]);
    vfp->vf_maxy = _vax_gshort(&header[3*2]);
    vfp->vf_xtend = _vax_gshort(&header[4*2]);

    for (i=0; i<255; i++) {
	register struct vfont_dispatch *vdp = &(vfp->vf_dispatch[i]);
	register unsigned char *cp = &dispatch[i*10];

	vdp->vd_addr = _vax_gshort(&cp[0]);
	vdp->vd_nbytes = _vax_gshort(&cp[2]);
	vdp->vd_up = SXT(cp[4]);
	vdp->vd_down = SXT(cp[5]);
	vdp->vd_left = SXT(cp[6]);
	vdp->vd_right = SXT(cp[7]);
	vdp->vd_width = _vax_gshort(&cp[8]);
    }
    fclose(fp);
    return vfp;
}