/* * M A I N * */ int main(int argc, char **argv) { char *prototype; /* Contains full text of prototype document */ char proto_file[256] = {0}; FILE *table; char table_file[256] = {0}; if ( argc < 2 || argc > 3 ) { fprintf(stderr, "Usage: tabsub prototype_file [table_file]\n"); bu_exit(12, NULL); } bu_strlcpy(proto_file, argv[1], sizeof(proto_file)); /* Acquire in-core copy of prototype file */ get_proto( &prototype, proto_file ); if ( argc < 3 ) { table = stdin; } else { bu_strlcpy(table_file, argv[2], sizeof(table_file)); if ( (table = fopen( table_file, "r" )) == NULL ) { perror( table_file ); bu_exit(3, NULL); } } do_lines( table, prototype ); return 0; }
/* Set certain default lighting info. */ static void init_Lgts(void) { /* Ambient lighting. */ bu_strlcpy(lgts[0].name, "EYE", sizeof(lgts[0].name)); lgts[0].beam = 0; lgts[0].over = 0; lgts[0].rgb[0] = 255; lgts[0].rgb[1] = 255; lgts[0].rgb[2] = 255; lgts[0].azim = 30.0/RAD2DEG; lgts[0].elev = 30.0/RAD2DEG; lgts[0].dist = 0.0; lgts[0].energy = 0.4; lgts[0].stp = SOLTAB_NULL; /* Primary lighting. */ bu_strlcpy(lgts[1].name, "LIGHT", sizeof(lgts[1].name)); lgts[1].beam = 0; lgts[1].over = 1; lgts[1].rgb[0] = 255; lgts[1].rgb[1] = 255; lgts[1].rgb[2] = 255; lgts[1].azim = 60.0/RAD2DEG; lgts[1].elev = 60.0/RAD2DEG; lgts[1].dist = 10000.0; lgts[1].energy = 1.0; lgts[1].stp = SOLTAB_NULL; lgt_db_size = 2; return; }
char * bu_realpath(const char *path, char *resolved_path) { if (!resolved_path) resolved_path = (char *) bu_calloc(MAXPATHLEN, sizeof(char), "resolved_path alloc"); #if defined(HAVE_WORKING_REALPATH_FUNCTION) { char *dirpath = NULL; dirpath = realpath(path, resolved_path); if (!dirpath) { /* if path lookup failed, resort to simple copy */ bu_strlcpy(resolved_path, path, (size_t)MAXPATHLEN); } } #elif defined(HAVE_GETFULLPATHNAME) /* Best solution currently available for Windows * See https://www.securecoding.cert.org/confluence/display/seccode/FIO02-C.+Canonicalize+path+names+originating+from+untrusted+sources */ GetFullPathName(path, MAXPATHLEN, resolved_path, NULL); #else /* Last resort - if NOTHING is defined, do a simple copy */ bu_strlcpy(resolved_path, path, (size_t)MAXPATHLEN); #endif return resolved_path; }
int parse_args(int ac, char **av) { int c; if (! (progname=strrchr(*av, '/'))) progname = *av; else ++progname; bu_strlcpy(plotfilename, progname, sizeof(plotfilename)); bu_strlcat(plotfilename, ".plot3", sizeof(plotfilename)); bu_strlcpy(mfilename, progname, sizeof(mfilename)); bu_strlcat(mfilename, ".g", sizeof(mfilename)); /* get all the option flags from the command line */ while ((c=bu_getopt(ac, av, options)) != -1) switch (c) { case '3' : manifold[3] = 0; break; case '2' : manifold[2] = 0; break; case '1' : manifold[1] = 0; break; case '0' : manifold[0] = 0; break; default : usage((char *)NULL,1); break; } return bu_optind; }
HIDDEN void get_large_field_input(FILE *fp, int write_flag) { char **tmp_rec; int field_no; int card_len; int last_field; int i; tmp_rec = prev_rec; prev_rec = curr_rec; curr_rec = tmp_rec; for ( field_no=0; field_no < NO_OF_FIELDS; field_no ++ ) curr_rec[field_no][0] = '\0'; card_len = strlen( line ); last_field = (card_len - 8)/16 + 1; if ( ((last_field - 1) * 16 + 8) < card_len ) last_field++; if ( last_field > 5 ) last_field = 5; bu_strlcpy( curr_rec[0], line, 8 ); curr_rec[0][8] = '\0'; for ( field_no=1; field_no < last_field; field_no++ ) { bu_strlcpy( curr_rec[field_no], &line[field_no*16 - 8], 16 ); curr_rec[field_no][16] = '\0'; } /* remove the newline from the end of the last field */ i = strlen( curr_rec[last_field-1] ) - 1; while ( isspace( curr_rec[last_field-1][i] ) || curr_rec[last_field-1][i] == '\012' || curr_rec[last_field-1][i] == '\015' ) i--; curr_rec[last_field-1][++i] = '\0'; if ( next_line[0] == '*' ) { if ( !get_next_record( fp, 0, 0 ) ) { bu_exit(1, "unexpected end of INPUT at line #%d\n", line_count ); } card_len = strlen( line ); last_field = (card_len - 8)/16 + 1; if ( ((last_field - 1) * 16 + 8) < card_len ) last_field++; if ( last_field > 5 ) last_field = 5; last_field += 4; for ( field_no=5; field_no < last_field; field_no++ ) { bu_strlcpy( curr_rec[field_no], &line[(field_no-4)*16 - 8], 16 ); curr_rec[field_no][16] = '\0'; } } if ( write_flag ) write_fields(); }
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; } }
HIDDEN void get_small_field_input(FILE *fp, int write_flag) { char **tmp_rec; int field_no; int card_len; int last_field; tmp_rec = prev_rec; prev_rec = curr_rec; curr_rec = tmp_rec; for ( field_no=0; field_no < NO_OF_FIELDS; field_no ++ ) curr_rec[field_no][0] = '\0'; card_len = strlen( line ); last_field = card_len/8 + 1; if ( (last_field * 8) < card_len ) last_field++; if ( last_field > 9 ) last_field = 9; bu_strlcpy( curr_rec[0], line, 8 ); curr_rec[0][8] = '\0'; for ( field_no=2; field_no < last_field+1; field_no++ ) { bu_strlcpy( curr_rec[field_no-1], &line[(field_no-1)*8], 8 ); curr_rec[field_no-1][8] = '\0'; } if ( next_line[0] == '+' ) { if ( !get_next_record( fp, 0, 0 ) ) { bu_exit(1, "unexpected end of INPUT at line #%d\n", line_count ); } card_len = strlen( line ); last_field = card_len/8 + 1; if ( (last_field * 8) < card_len ) last_field++; if ( last_field > 9 ) last_field = 9; last_field += 9; for ( field_no=10; field_no < last_field+1; field_no++ ) { bu_strlcpy( curr_rec[field_no-1], &line[(field_no-9)*8], 8 ); curr_rec[field_no-1][8] = '\0'; } } if ( write_flag ) write_fields(); }
int main(int argc, char **argv) { int c = 0; int in_num = 0; int format = 0; /* 0 = XML, 1 = HTML */ int list = 0; char outfile[MAXPATHLEN] = "attributes.xml"; char xref_id[MAXPATHLEN] = "auto_attributes"; const char *usage_str = "[-o output file] [-x xref id] [-f format number (0 = XML, 1 = HTML)] [-l]"; while ((c=bu_getopt(argc, argv, "f:lo:x:")) != -1) { switch (c) { case 'o' : memset(outfile, 0, MAXPATHLEN); bu_strlcpy(outfile, bu_optarg, MAXPATHLEN); break; case 'x' : memset(xref_id, 0, MAXPATHLEN); bu_strlcpy(xref_id, bu_optarg, MAXPATHLEN); break; case 'f' : sscanf(bu_optarg, "%d", &in_num); format = in_num; break; case 'l' : list = 1; break; default: bu_log("%s: %s\n", argv[0], usage_str); return -1; } } switch (format) { case 0: if (list) { gen_attr_xml_list(outfile, xref_id); } else { gen_attr_xml_table(outfile, xref_id); } break; case 1: break; default: bu_log("Error - unknown format %d\n", format); return -1; } return 0; }
void X_fb_open(void) { char *X_name = "/dev/X"; if ((fbp = (FBIO *)calloc(sizeof(FBIO), 1)) == FBIO_NULL) { Tcl_AppendResult(interp, "X_dm_init: failed to allocate framebuffer memory\n", (char *)NULL); return; } *fbp = X24_interface; /* struct copy */ fbp->if_name = bu_malloc((unsigned)strlen(X_name)+1, "if_name"); bu_strlcpy(fbp->if_name, X_name, strlen(X_name)+1); /* Mark OK by filling in magic number */ fbp->if_magic = FB_MAGIC; _X24_open_existing(fbp, ((struct dm_xvars *)dmp->dm_vars.pub_vars)->dpy, ((struct x_vars *)dmp->dm_vars.priv_vars)->pix, ((struct dm_xvars *)dmp->dm_vars.pub_vars)->win, ((struct dm_xvars *)dmp->dm_vars.pub_vars)->cmap, ((struct dm_xvars *)dmp->dm_vars.pub_vars)->vip, dmp->dm_width, dmp->dm_height, ((struct x_vars *)dmp->dm_vars.priv_vars)->gc); }
/* 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 */ }
/* c o l _ p r t ( ) Print list of names in tabular columns. */ int col_prt( char *list[], int ct ) { char buf[MAX_COL+2]; register int i, column, spaces; for ( i = 0, column = 0; i < ct; i++ ) { if ( column + strlen( list[i] ) > MAX_COL ) { SEND_LN(); i--; } else { bu_strlcpy( &buf[column], list[i], MAX_COL+2-column ); column += strlen( list[i] ); spaces = NAMESIZE - (column % NAMESIZE ); if ( column + spaces < MAX_COL ) for (; spaces > 0; spaces-- ) buf[column++] = ' '; else SEND_LN(); } } SEND_LN(); return ct; }
/* * Attempt to guess the file type. Understands ImageMagick style * FMT:filename as being preferred, but will attempt to guess based on * extension as well. * * I suck. I'll fix this later. Honest. * * FIXME: assuming trimmedname is BUFSIZ is a crash waiting to bite * someone down the road. should pass a size or use a vls or have it * return the string as as return type (making the int type be an int* * argument instead that gets set). */ ICV_IMAGE_FORMAT icv_guess_file_format(const char *filename, char *trimmedname) { /* look for the FMT: header */ #define CMP(name) if (!bu_strncmp(filename, #name":", strlen(#name))) {bu_strlcpy(trimmedname, filename+strlen(#name)+1, BUFSIZ);return ICV_IMAGE_##name; } CMP(PIX); CMP(PNG); CMP(PPM); CMP(BMP); CMP(BW); CMP(DPIX) #undef CMP /* no format header found, copy the name as it is */ bu_strlcpy(trimmedname, filename, BUFSIZ); /* and guess based on extension */ #define CMP(name, ext) if (!bu_strncmp(filename+strlen(filename)-strlen(#name)-1, "."#ext, strlen(#name)+1)) return ICV_IMAGE_##name; CMP(PIX, pix); CMP(PNG, png); CMP(PPM, ppm); CMP(BMP, bmp); CMP(BW, bw); CMP(DPIX, dpix); #undef CMP /* defaulting to PIX */ return ICV_IMAGE_UNKNOWN; }
void Wgl_fb_open() { char *wgl_name = "/dev/wgl"; if ((fbp = (FBIO *)calloc(sizeof(FBIO), 1)) == FBIO_NULL) { Tcl_AppendResult(interp, "Wgl_fb_open: failed to allocate framebuffer memory\n", (char *)NULL); return; } *fbp = wgl_interface; /* struct copy */ fbp->if_name = bu_malloc((unsigned)strlen(wgl_name)+1, "if_name"); bu_strlcpy(fbp->if_name, wgl_name, strlen(wgl_name)+1); /* Mark OK by filling in magic number */ fbp->if_magic = FB_MAGIC; _wgl_open_existing(fbp, ((struct dm_xvars *)dmp->dm_vars.pub_vars)->dpy, ((struct dm_xvars *)dmp->dm_vars.pub_vars)->win, ((struct dm_xvars *)dmp->dm_vars.pub_vars)->cmap, ((struct dm_xvars *)dmp->dm_vars.pub_vars)->vip, ((struct dm_xvars *)dmp->dm_vars.pub_vars)->hdc, dmp->dm_width, dmp->dm_height, ((struct wgl_vars *)dmp->dm_vars.priv_vars)->glxc, ((struct wgl_vars *)dmp->dm_vars.priv_vars)->mvars.doublebuffer, 0); }
void rt_vlist_export(struct bu_vls *vls, struct bu_list *hp, const char *name) { register struct bn_vlist *vp; size_t nelem; size_t namelen; size_t nbytes; unsigned char *buf; unsigned char *bp; BU_CK_VLS(vls); /* Count number of element in the vlist */ nelem = 0; for (BU_LIST_FOR(vp, bn_vlist, hp)) { nelem += vp->nused; } /* Build output buffer for binary transmission * nelem[4], String[n+1], cmds[nelem*1], pts[3*nelem*8] */ namelen = strlen(name)+1; nbytes = namelen + 4 + nelem * (1+ELEMENTS_PER_VECT*SIZEOF_NETWORK_DOUBLE) + 2; /* FIXME: this is pretty much an abuse of vls. should be using * vlb for variable-length byte buffers. */ bu_vls_setlen(vls, (int)nbytes); buf = (unsigned char *)bu_vls_addr(vls); *(uint32_t *)buf = htonl((uint32_t)nelem); bp = buf+sizeof(uint32_t); bu_strlcpy((char *)bp, name, namelen); bp += namelen; /* Output cmds, as bytes */ for (BU_LIST_FOR(vp, bn_vlist, hp)) { register int i; register int nused = vp->nused; register int *cmd = vp->cmd; for (i = 0; i < nused; i++) { *bp++ = *cmd++; } } /* Output points, as three 8-byte doubles */ for (BU_LIST_FOR(vp, bn_vlist, hp)) { register int i; register int nused = vp->nused; register point_t *pt = vp->pt; /* must be double for import and export */ double point[ELEMENTS_PER_POINT]; for (i = 0; i < nused; i++) { VMOVE(point, pt[i]); /* convert fastf_t to double */ htond(bp, (unsigned char *)point, ELEMENTS_PER_VECT); bp += ELEMENTS_PER_VECT*SIZEOF_NETWORK_DOUBLE; } } }
/** * Builds a directory of the object names. * * Allocate and initialize information for this instance of an RT * model database. * * Returns - * (struct rt_i *) Success * RTI_NULL Fatal Error */ struct rt_i * rt_dirbuild(const char *filename, char *buf, int len) { register struct rt_i *rtip; register struct db_i *dbip; /* Database instance ptr */ if (rt_uniresource.re_magic == 0) rt_init_resource(&rt_uniresource, 0, NULL); if ((dbip = db_open(filename, DB_OPEN_READONLY)) == DBI_NULL) return RTI_NULL; /* FAIL */ RT_CK_DBI(dbip); if (db_dirbuild(dbip) < 0) { db_close(dbip); return RTI_NULL; /* FAIL */ } rtip = rt_new_rti(dbip); /* clones dbip */ db_close(dbip); /* releases original dbip */ if (buf != (char *)NULL) bu_strlcpy(buf, dbip->dbi_title, len); return rtip; /* OK */ }
/** * Return basename of path, removing leading slashes and trailing suffix. */ static char * basename_without_suffix(const char *p1, const char *suff) { char *p2, *p3; static char buf[128]; /* find the basename */ p2 = (char *)p1; while (*p1) { if (*p1++ == '/') p2 = (char *)p1; } /* find the end of suffix */ for (p3=(char *)suff; *p3; p3++) ; /* early out */ while (p1>p2 && p3>suff) { if (*--p3 != *--p1) return p2; } /* stash and return filename, sans suffix */ bu_strlcpy(buf, p2, p1-p2+1); return buf; }
/* * This FORTRAN interface expects REAL args (single precision). */ void PL_FORTRAN(f2symb, F2SYMB)(FILE **fp, char *string, float *x, float *y, float *scale, float *theta) { char buf[128] = {0}; bu_strlcpy( buf, string, sizeof(buf) ); tp_2symbol( *fp, buf, *x, *y, *scale, *theta ); }
void do_quad(char *line) { int element_id; int pt1, pt2, pt3, pt4; fastf_t thick = 0.0; int pos = 0; bu_strlcpy(field, &line[8], sizeof(field)); element_id = atoi( field ); if ( debug ) bu_log( "do_quad: %s\n", line ); if ( !bot ) bot = element_id; if ( faces == NULL ) { faces = (int *)bu_malloc( GRID_BLOCK*3*sizeof( int ), "faces" ); thickness = (fastf_t *)bu_malloc( GRID_BLOCK*sizeof( fastf_t ), "thickness" ); facemode = (char *)bu_malloc( GRID_BLOCK*sizeof( char ), "facemode" ); face_size = GRID_BLOCK; face_count = 0; } bu_strlcpy(field, &line[24], sizeof(field)); pt1 = atoi( field ); bu_strlcpy(field, &line[32], sizeof(field)); pt2 = atoi( field ); bu_strlcpy(field, &line[40], sizeof(field)); pt3 = atoi( field ); bu_strlcpy(field, &line[48], sizeof(field)); pt4 = atoi( field ); if ( mode == PLATE_MODE ) { bu_strlcpy(field, &line[56], sizeof(field)); thick = atof( field ) * 25.4; bu_strlcpy(field, &line[64], sizeof(field)); pos = atoi( field ); if ( pos == 0 ) /* use default */ pos = POS_FRONT; if ( pos != POS_CENTER && pos != POS_FRONT ) { bu_log( "do_quad: illegal postion parameter (%d), must be one or two\n", pos ); bu_log( "\telement %d, component %d, group %d\n", element_id, comp_id, group_id ); return; } } Add_bot_face( pt1, pt2, pt3, thick, pos ); Add_bot_face( pt1, pt3, pt4, thick, pos ); }
HIDDEN int wdb_add_operand(Tcl_Interp *interp, struct bu_list *hp, char *name) { char *ptr_lparen; char *ptr_rparen; int name_len; union tree *node; struct tokens *tok; BU_CK_LIST_HEAD(hp); ptr_lparen = strchr(name, '('); ptr_rparen = strchr(name, ')'); RT_GET_TREE( node, &rt_uniresource ); node->magic = RT_TREE_MAGIC; node->tr_op = OP_DB_LEAF; node->tr_l.tl_mat = (matp_t)NULL; if (ptr_lparen || ptr_rparen) { int tmp1, tmp2; if (ptr_rparen) tmp1 = ptr_rparen - name; else tmp1 = (-1); if (ptr_lparen) tmp2 = ptr_lparen - name; else tmp2 = (-1); if (tmp2 == (-1) && tmp1 > 0) name_len = tmp1; else if (tmp1 == (-1) && tmp2 > 0) name_len = tmp2; else if (tmp1 > 0 && tmp2 > 0) { if (tmp1 < tmp2) name_len = tmp1; else name_len = tmp2; } else { Tcl_AppendResult(interp, "Cannot determine length of operand name: ", name, ", aborting\n", (char *)NULL); return (0); } } else name_len = strlen( name ); node->tr_l.tl_name = (char *)bu_malloc(name_len+1, "node name"); bu_strlcpy(node->tr_l.tl_name, name, name_len+1); tok = (struct tokens *)bu_malloc(sizeof(struct tokens), "tok"); tok->type = WDB_TOK_TREE; tok->tp = node; BU_LIST_INSERT(hp, &tok->l); return (name_len); }
int main(int argc, char **argv) { int c = 0, image, cache; char proj[64], temp[64]; signal(SIGINT, finish); if (argc == 1) { help(); return EXIT_FAILURE; } /* Initialize */ cache = 0; image = 0; proj[0] = 0; /* Parse command line options */ while ((c = #ifdef HAVE_GETOPT_LONG getopt_long(argc, argv, shortopts, longopts, NULL) #else getopt(argc, argv, shortopts) #endif )!= -1) { switch (c) { case 'c': cache = 1; break; case 'd': image = 1; break; case 'h': help(); return EXIT_SUCCESS; default: help(); return EXIT_FAILURE; } } argc -= optind; argv += optind; bu_strlcpy(proj, argv[0], sizeof(proj)); if (proj[0]) { bench(proj, cache, image); } else { help(); return EXIT_FAILURE; } return EXIT_SUCCESS; }
int output_torii(const char *fileName, int levels, const torusLevels_t torii, const char *name) { char scratch[256]; bu_strlcpy(scratch, name, sizeof(scratch)); bu_strlcat(scratch, "_0", sizeof(scratch)); bu_log("output_torii to file \"%s\" for %d levels using \"%s.c\" as the combination name", fileName, levels, name); return 0; }
HIDDEN int add_operand(struct ged *gedp, struct bu_list *hp, char *name) { char *ptr_lparen; char *ptr_rparen; int name_len; union tree *node; struct tokens *tok; BU_CK_LIST_HEAD(hp); ptr_lparen = strchr(name, '('); ptr_rparen = strchr(name, ')'); RT_GET_TREE(node, &rt_uniresource); node->tr_op = OP_DB_LEAF; node->tr_l.tl_mat = (matp_t)NULL; if (ptr_lparen || ptr_rparen) { int tmp1, tmp2; if (ptr_rparen) tmp1 = ptr_rparen - name; else tmp1 = (-1); if (ptr_lparen) tmp2 = ptr_lparen - name; else tmp2 = (-1); if (tmp2 == (-1) && tmp1 > 0) name_len = tmp1; else if (tmp1 == (-1) && tmp2 > 0) name_len = tmp2; else if (tmp1 > 0 && tmp2 > 0) { if (tmp1 < tmp2) name_len = tmp1; else name_len = tmp2; } else { bu_vls_printf(gedp->ged_result_str, "Cannot determine length of operand name: %s, aborting\n", name); return 0; } } else name_len = (int)strlen(name); node->tr_l.tl_name = (char *)bu_malloc(name_len+1, "node name"); bu_strlcpy(node->tr_l.tl_name, name, name_len+1); BU_ALLOC(tok, struct tokens); tok->type = TOK_TREE; tok->tp = node; BU_LIST_INSERT(hp, &tok->l); return name_len; }
void do_grid(char *line) { int grid_no; fastf_t x, y, z; if ( RT_G_DEBUG&DEBUG_MEM_FULL && bu_mem_barriercheck() ) bu_log( "ERROR: bu_mem_barriercheck failed at start of do_grid\n" ); bu_strlcpy(field, &line[8], sizeof(field)); grid_no = atoi( field ); if ( grid_no < 1 ) { bu_log( "ERROR: grid id number = %d\n", grid_no ); bu_bomb( "BAD GRID ID NUMBER\n" ); } bu_strlcpy(field, &line[24], sizeof(field)); x = atof( field ); bu_strlcpy(field, &line[32], sizeof(field)); y = atof( field ); bu_strlcpy(field, &line[40], sizeof(field)); z = atof( field ); while ( grid_no > grid_size - 1 ) { grid_size += GRID_BLOCK; grid_pts = (point_t *)bu_realloc( (char *)grid_pts, grid_size * sizeof( point_t ), "fast4-g: grid_pts" ); } VSET( grid_pts[grid_no], x*25.4, y*25.4, z*25.4 ); if ( grid_no > max_grid_no ) max_grid_no = grid_no; if ( RT_G_DEBUG&DEBUG_MEM_FULL && bu_mem_barriercheck() ) bu_log( "ERROR: bu_mem_barriercheck failed at end of do_grid\n" ); }
char * db_path_to_string(const struct db_full_path *pp) { char *cp; char *buf; size_t len; size_t rem; size_t i; long j; RT_CK_FULL_PATH(pp); BU_ASSERT_SIZE_T(pp->fp_len, <, LONG_MAX); len = 3; /* leading slash, trailing null, spare */ for (j=pp->fp_len-1; j >= 0; j--) { if (pp->fp_names[j]) len += strlen(pp->fp_names[j]->d_namep) + 1; else len += 16; } buf = (char *)bu_malloc(len, "pathname string"); cp = buf; rem = len; for (i = 0; i < pp->fp_len; i++) { *cp++ = '/'; rem--; if (pp->fp_names[i]) { bu_strlcpy(cp, pp->fp_names[i]->d_namep, rem); rem -= strlen(pp->fp_names[i]->d_namep); } else { bu_strlcpy(cp, "**NULL**", rem); rem -= 8; } cp += strlen(cp); } *cp++ = '\0'; return buf; }
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; }
void Make_name(char *ptr, const char *form, const char *base, int number) { char scrat[NAMESIZE]; int len; bu_strlcpy( ptr, base, NAMESIZE ); snprintf( scrat, NAMESIZE, form, number ); len = strlen( ptr ) + strlen( scrat ); if ( len > (NAMESIZE-1) ) ptr[ (NAMESIZE-1) - strlen( scrat ) ] = '\0'; bu_strlcat( ptr, scrat, NAMESIZE ); }
void _ged_cvt_vlblock_to_solids(struct ged *gedp, struct bn_vlblock *vbp, const char *name, int copy) { size_t i; char shortname[32] = {0}; char namebuf[64] = {0}; bu_strlcpy(shortname, name, sizeof(shortname)); for (i = 0; i < vbp->nused; i++) { if (BU_LIST_IS_EMPTY(&(vbp->head[i]))) continue; snprintf(namebuf, 64, "%s%lx", shortname, vbp->rgb[i]); invent_solid(gedp->ged_gdp->gd_headDisplay, gedp->ged_wdbp->dbip, gedp->ged_create_vlist_solid_callback, gedp->ged_free_vlist_callback, namebuf, &vbp->head[i], vbp->rgb[i], copy, 0.0, 0, gedp->freesolid, 0); } }
double rt_read_timer(char *str, int len) { struct bu_vls vls = BU_VLS_INIT_ZERO; double cpu; int todo; if (!str) return rt_get_timer((struct bu_vls *)0, (double *)0); cpu = rt_get_timer(&vls, (double *)0); todo = bu_vls_strlen(&vls); if (todo > len) todo = len; bu_strlcpy(str, bu_vls_addr(&vls), todo); return cpu; }
/** * Take a FORTRAN string with a length, and return a pointer to null * terminated copy of that string in a STATIC buffer. */ static char * fr_string_f2c(char *str, int maxlen) { static char buf[512]; int len; int i; len = sizeof(buf); if (maxlen < len) len = maxlen; bu_strlcpy(buf, str, len); /* Remove any trailing blanks */ for (i=(int)strlen(buf)-1; i >= 0; i--) { if (buf[i] != ' ' && buf[i] != '\n') break; buf[i] = '\0'; } return buf; }