示例#1
0
int
main(int argc, char *argv[])
{
	START(argc, argv, "pmem_is_pmem_posix");

	if (argc < 4)
		UT_FATAL("usage: %s op addr len type [op addr len type ...]",
				argv[0]);

	/* insert memory regions to the list */
	int i;
	for (i = 1; i < argc; ) {
		UT_ASSERT(i + 2 < argc);

		errno = 0;
		void *addr = (void *)strtoull(argv[i + 1], NULL, 0);
		UT_ASSERTeq(errno, 0);

		size_t len = strtoull(argv[i + 2], NULL, 0);
		UT_ASSERTeq(errno, 0);

		int ret;

		switch (argv[i][0]) {
		case 'a':
			ret = util_range_register(addr, len, "",
					str2type(argv[i + 3]));
			if (ret != 0)
				UT_OUT("%s", pmem_errormsg());
			i += 4;
			break;
		case 'r':
			ret = util_range_unregister(addr, len);
			UT_ASSERTeq(ret, 0);
			i += 3;
			break;
		case 't':
			UT_OUT("addr %p len %zu is_pmem %d",
					addr, len, pmem_is_pmem(addr, len));
			i += 3;
			break;
		case 'f':
			do_fault_injection_register(addr, len,
					str2type(argv[i + 3]));
			i += 4;
			break;
		case 's':
			do_fault_injection_split(addr, len);
			i += 3;
			break;
		default:
			FATAL("invalid op '%c'", argv[i][0]);
		}
	}

	DONE(NULL);
}
示例#2
0
文件: utils.c 项目: cran/RGtk2
USER_OBJECT_
getNumericType(USER_OBJECT_ s)
{
  /* Get the numeric type code for an R object */
  /*return asRNumeric(TYPEOF(s));*/
  /* Instead, get the numeric type for an R type name */
  return asRNumeric(str2type(asCString(s)));
}
示例#3
0
void
DrawCSTags(Tcl_Interp *interp,                                       /* in */
	   int x1,
	   int x2,
	   int tag_num,
	   GAnnotations *annotation,
	   int offset,
	   char *win_name,
	   int width,
	   int contig_num,
	   int read_num)
{
    char type[100];
    char *colour = tag_db[0].bg_colour;
    char cmd[1024], str[5];
    int k;                                                       /* counter */

    sprintf(type, "{tag %s t_%d num_%d rnum_%d}",
	    type2str(annotation->type,str), tag_num, contig_num, read_num);

    /* find tag colour in tag_db */
    for (k = 0; k < tag_db_count; k++){

	if (annotation->type == str2type(tag_db[k].id)) {

/*
	    sprintf(type, "{tag %s t_%d num_%d}", tag_db[k].search_id,
		    tag_num, contig_num);
*/
	    colour = tag_db[k].bg_colour;
	    break;

	}  /* end if */

    } /* end for */

    /* check that TagArray type and colour been allocated */
    if (type == NULL) {

	verror(ERR_WARN, "CalcTags",
	       "tag type not in tag database");
	return;

    } /* end if */

    sprintf(cmd, "%s create rectangle %d %d %d %d "
	    "-fill %s -tags %s -width %d -outline %s\n",
	    win_name, x1, offset, x2 + 1, offset, colour, type, width, colour);

    Tcl_Eval(interp, cmd);

    /* printf("cmd %s \n", cmd); */
}
示例#4
0
/*
 * Sets the annotation type, passed in as a string but held in a 4-byte int.
 * This also attempts to set the cached copy of the type held within the
 * bin range array.
 *
 * Returns 0 on success
 *        -1 on failure
 */
int anno_ele_set_type(GapIO *io, anno_ele_t **e, char *str) {
    int type;
    char stype[5];
    anno_ele_t *ae;

    if (!(ae = cache_rw(io, *e)))
	return -1;

    /* Get integer type */
    memset(stype, 0, 5);
    strncpy(stype, str, 4);
    type = str2type(stype);

    /* Update annotation */
    ae->tag_type = type;

    /* Also update range_t cached copy of type */
    if (ae->bin) {
	bin_index_t *bin = (bin_index_t *)cache_search(io, GT_Bin, ae->bin);
	range_t *r = NULL;
	int i, nranges;

	if (!bin)
	    return -1;
	if (!(bin = cache_rw(io, bin)))
	    return -1;

	/*
	 * Find the index into the bin range.
	 * FIXME: we should add a bin_index element, as seen in seq_t,
	 * to avoid the brute force loop. This doesn't have to be
	 * permanently stored - a cached copy would suffice.
	 */
	nranges = bin->rng ? ArrayMax(bin->rng) : 0;
	for (i = 0; i < nranges; i++) {
	    r = arrp(range_t, bin->rng, i);
	    if (r->flags & GRANGE_FLAG_UNUSED)
		continue;

	    if (r->rec == ae->rec)
		break;
	}
	if (i == nranges)
	    return -1;

	bin->flags |= BIN_RANGE_UPDATED;
	r->mqual = type;
    }

    *e = ae;

    return 0;
}
示例#5
0
int edview_search_tag_type(edview *xx, int dir, int strand, char *value) {
    contig_iterator *iter;
    int start, end;
    rangec_t *r;
    rangec_t *(*ifunc)(GapIO *io, contig_iterator *ci);
    int type = str2type(value);
    contig_t *c = cache_search(xx->io, GT_Contig, xx->cnum);

    if (dir) {
	start = xx->cursor_apos + (dir ? 1 : -1);
	end   = c->end;
	ifunc = contig_iter_next;
    } else {
	start = c->start;
	end   = xx->cursor_apos + (dir ? 1 : -1);
	ifunc = contig_iter_prev;
    }

    iter = contig_iter_new_by_type(xx->io, xx->cnum, 1,
				   dir == 1 ? CITER_FIRST : CITER_LAST,
				   start, end, GRANGE_FLAG_ISANNO);
    if (!iter)
	/* Can happen legitimately when we're already at the end of contig */
	return -1;

    while (r = ifunc(xx->io, iter)) {
	if ((dir  && r->start < start) ||
	    (!dir && r->start > end))
	    continue;

	if (r->mqual == type) 
	    break;
    }

    if (r) {
	if (r->flags & GRANGE_FLAG_TAG_SEQ) {
	    int pos;
	    sequence_get_position(xx->io, r->pair_rec, NULL, &pos, NULL, NULL);
	    pos = r->start - pos;
	    edSetCursorPos(xx, GT_Seq, r->pair_rec, pos, 1);
	} else {
	    edSetCursorPos(xx, GT_Contig, xx->cnum, r->start, 1);
	}
	contig_iter_del(iter);
	return 0;
    }

    contig_iter_del(iter);
    return -1;
}
示例#6
0
文件: builtin.c 项目: o-/Rexperiments
/* vector(mode="logical", length=0) */
SEXP attribute_hidden do_makevector(SEXP call, SEXP op, SEXP args, SEXP rho)
{
    R_xlen_t len;
    SEXP s;
    SEXPTYPE mode;
    checkArity(op, args);
    if (length(CADR(args)) != 1) error(_("invalid '%s' argument"), "length");
    len = asVecSize(CADR(args));
    if (len < 0) error(_("invalid '%s' argument"), "length");
    s = coerceVector(CAR(args), STRSXP);
    if (length(s) != 1) error(_("invalid '%s' argument"), "mode");
    mode = str2type(CHAR(STRING_ELT(s, 0))); /* ASCII */
    if (mode == -1 && streql(CHAR(STRING_ELT(s, 0)), "double"))
	mode = REALSXP;
    switch (mode) {
    case LGLSXP:
    case INTSXP:
    case REALSXP:
    case CPLXSXP:
    case STRSXP:
    case EXPRSXP:
    case VECSXP:
    case RAWSXP:
	s = allocVector(mode, len);
	break;
    case LISTSXP:
	if (len > INT_MAX) error("too long for a pairlist");
	s = allocList((int) len);
	break;
    default:
	error(_("vector: cannot make a vector of mode '%s'."),
	      translateChar(STRING_ELT(s, 0))); /* should be ASCII */
    }
    if (mode == INTSXP || mode == LGLSXP)
	Memzero(INTEGER(s), len);
    else if (mode == REALSXP)
	Memzero(REAL(s), len);
    else if (mode == CPLXSXP)
	Memzero(COMPLEX(s), len);
    else if (mode == RAWSXP)
	Memzero(RAW(s), len);
    /* other cases: list/expression have "NULL", ok */
    return s;
}
示例#7
0
Device::Device(QObject* parent, const QString& id)
    : QObject(parent)
    , m_deviceId(id)
    , m_pairStatus(Device::Paired)
    , m_protocolVersion(NetworkPackage::ProtocolVersion) //We don't know it yet
{
    KdeConnectConfig::DeviceInfo info = KdeConnectConfig::instance()->getTrustedDevice(id);

    m_deviceName = info.deviceName;
    m_deviceType = str2type(info.deviceType);
    m_publicKey = QCA::RSAPublicKey::fromPEM(info.publicKey);

    m_pairingTimeut.setSingleShot(true);
    m_pairingTimeut.setInterval(30 * 1000);  //30 seconds of timeout
    connect(&m_pairingTimeut, SIGNAL(timeout()),
            this, SLOT(pairingTimeout()));

    //Register in bus
    QDBusConnection::sessionBus().registerObject(dbusPath(), this, QDBusConnection::ExportScriptableContents | QDBusConnection::ExportAdaptors);
}
示例#8
0
文件: foton.c 项目: rolfrm/Photon
int main(int argc, char *argv[] ){
  parse_args(argv, argc);
  logd("Running from %s\n", exec_path);
  if(run_test){
    log("Running tests...\n");
    lisp_current_compiler = lisp_make_compiler();
    set_compile_out(lisp_current_compiler, c_compile_out);
    TEST(test_intern_expr);
    TEST(test_symbols);
    //TEST(test_lisp_parser);
    TEST(test_type_pool);
    //TEST(test_lisp2c);
    return 0;
  }

  if(file_to_run != NULL){
    char * filename = argv[1];
    if(access(filename, F_OK) == -1){
      loge("Error: File '%s' does not exist\n", filename);
      return 1;
    }
    lisp_current_compiler = lisp_make_compiler();
    set_compile_out(lisp_current_compiler, c_compile_out);
    lisp_load_base(exec_path);
    define_variable(get_symbol("break-on-errors"),str2type("bool"),&break_on_errors, true);
    compile_status status = lisp_run_script_file(argv[1]);
    if(status == COMPILE_ERROR){
      return -1;
    }
    return 0;
  }
  
  log("Unable to handle arguments: ");
  for(int i = 1; i < argc; i++){
    log("%s ", argv[i]);
  }
  log("\n");
  logd("Add the name of an existing file like this: './foton growth.lisp'\n");

  return 0;
}
示例#9
0
Device::Device(QObject* parent, const NetworkPackage& identityPackage, DeviceLink* dl)
    : QObject(parent)
    , m_deviceId(identityPackage.get<QString>("deviceId"))
    , m_deviceName(identityPackage.get<QString>("deviceName"))
    , m_deviceType(str2type(identityPackage.get<QString>("deviceType")))
    , m_pairStatus(Device::NotPaired)
    , m_protocolVersion(identityPackage.get<int>("protocolVersion", -1))
{
    addLink(identityPackage, dl);

    //Register in bus
    QDBusConnection::sessionBus().registerObject(dbusPath(), this, QDBusConnection::ExportScriptableContents | QDBusConnection::ExportAdaptors);

    //Implement deprecated signals
    connect(this, &Device::pairingChanged, this, [this](bool newPairing) {
        if (newPairing)
            Q_EMIT pairingSuccesful();
        else
            Q_EMIT unpaired();
    });
}
示例#10
0
static void
set_prop(topo_hdl_t *thp, tnode_t *node, nvlist_t *fmri, struct prop_args *pp)
{
	int ret, err = 0;
	topo_type_t type;
	nvlist_t *nvl, *f = NULL;
	char *end;

	if (pp->prop == NULL || pp->type == NULL || pp->value == NULL)
		return;

	if ((type = str2type(pp->type)) == TOPO_TYPE_INVALID) {
		(void) fprintf(stderr, "%s: invalid property type %s for %s\n",
		    g_pname, pp->type, pp->prop);
		return;
	}

	if (nvlist_alloc(&nvl, NV_UNIQUE_NAME, 0) != 0) {
		(void) fprintf(stderr, "%s: nvlist allocation failed for "
		    "%s=%s:%s\n", g_pname, pp->prop, pp->type, pp->value);
		return;
	}
	ret = nvlist_add_string(nvl, TOPO_PROP_VAL_NAME, pp->prop);
	ret |= nvlist_add_uint32(nvl, TOPO_PROP_VAL_TYPE, type);
	if (ret != 0) {
		(void) fprintf(stderr, "%s: invalid property type %s for %s\n",
		    g_pname, pp->type, pp->prop);
		nvlist_free(nvl);
		return;
	}

	errno = 0;
	switch (type) {
		case TOPO_TYPE_INT32:
		{
			int32_t val;

			val = strtol(pp->value, &end, 0);
			if (errno == ERANGE) {
				ret = -1;
				break;
			}
			ret = nvlist_add_int32(nvl, TOPO_PROP_VAL_VAL, val);
			break;
		}
		case TOPO_TYPE_UINT32:
		{
			uint32_t val;

			val = strtoul(pp->value, &end, 0);
			if (errno == ERANGE) {
				ret = -1;
				break;
			}
			ret = nvlist_add_uint32(nvl, TOPO_PROP_VAL_VAL, val);
			break;
		}
		case TOPO_TYPE_INT64:
		{
			int64_t val;

			val = strtoll(pp->value, &end, 0);
			if (errno == ERANGE) {
				ret = -1;
				break;
			}
			ret = nvlist_add_int64(nvl, TOPO_PROP_VAL_VAL, val);
			break;
		}
		case TOPO_TYPE_UINT64:
		{
			uint64_t val;

			val = strtoull(pp->value, &end, 0);
			if (errno == ERANGE) {
				ret = -1;
				break;
			}
			ret = nvlist_add_uint64(nvl, TOPO_PROP_VAL_VAL, val);
			break;
		}
		case TOPO_TYPE_STRING:
		{
			ret = nvlist_add_string(nvl, TOPO_PROP_VAL_VAL,
			    pp->value);
			break;
		}
		case TOPO_TYPE_FMRI:
		{
			if ((ret = topo_fmri_str2nvl(thp, pp->value, &f, &err))
			    < 0)
				break;

			if ((ret = nvlist_add_nvlist(nvl, TOPO_PROP_VAL_VAL,
			    f)) != 0)
				err = ETOPO_PROP_NVL;
			break;
		}
		default:
			ret = -1;
	}

	if (ret != 0) {
		(void) fprintf(stderr, "%s: unable to set property value for "
		    "%s: %s\n", g_pname, pp->prop,  topo_strerror(err));
		nvlist_free(nvl);
		return;
	}

	if (node != NULL) {
		if (topo_prop_setprop(node, pp->group, nvl, TOPO_PROP_MUTABLE,
		    f, &ret) < 0) {
			(void) fprintf(stderr, "%s: unable to set property "
			    "value for " "%s=%s:%s: %s\n", g_pname, pp->prop,
			    pp->type, pp->value, topo_strerror(ret));
			nvlist_free(nvl);
			nvlist_free(f);
			return;
		}
	} else {
		if (topo_fmri_setprop(thp, fmri,  pp->group, nvl,
		    TOPO_PROP_MUTABLE, f, &ret) < 0) {
			(void) fprintf(stderr, "%s: unable to set property "
			    "value for " "%s=%s:%s: %s\n", g_pname, pp->prop,
			    pp->type, pp->value, topo_strerror(ret));
			nvlist_free(nvl);
			nvlist_free(f);
			return;
		}
	}

	nvlist_free(nvl);

	/*
	 * Now, get the property back for printing
	 */
	if (node != NULL) {
		if (topo_prop_getprop(node, pp->group, pp->prop, f, &nvl,
		    &err) < 0) {
			(void) fprintf(stderr, "%s: failed to get %s.%s: %s\n",
			    g_pname, pp->group, pp->prop, topo_strerror(err));
			nvlist_free(f);
			return;
		}
	} else {
		if (topo_fmri_getprop(thp, fmri, pp->group, pp->prop,
		    f, &nvl, &err) < 0) {
			(void) fprintf(stderr, "%s: failed to get %s.%s: %s\n",
			    g_pname, pp->group, pp->prop, topo_strerror(err));
			nvlist_free(f);
			return;
		}
	}

	print_pgroup(thp, node, pp->group, NULL, NULL, 0);
	print_prop_nameval(thp, node, nvl);
	nvlist_free(nvl);

	nvlist_free(f);
}
示例#11
0
文件: baf.c 项目: svn2github/staden
int parse_baf(GapIO *io, char *fn, tg_args *a) {
    int nseqs = 0, nobj = 0, ntags = 0, ncontigs = 0;
    struct stat sb;
    zfp *fp;
    off_t pos;
    contig_t *c = NULL;
    tg_pair_t *pair = NULL;
    baf_block *b, *co = NULL;
    int last_obj_type = 0;
    int last_obj_pos = 0;
    tg_rec last_obj_rec = 0;
    tg_rec last_cnt_rec = 0;
    int last_cnt_pos = 0;
    int last_obj_orient = 0;
    
    
	
    printf("Loading %s...\n", fn);
    if (-1 == stat(fn, &sb) ||
	NULL == (fp = zfopen(fn, "r"))) {
	perror(fn);
	return -1;
    }

    if (a->pair_reads) {
	pair = create_pair(a->pair_queue);
    }

    /* Loop:
     * Read 1 block of data.
     * If contig, create contig
     * If read, insert it, insert to index.
     * Anything else - reject for now
     */
    pos = 0;
    while (b = baf_next_block(fp)) {
	int delay_destroy = 0;

	switch (b->type) {
	case CO: {
	    char *contig = baf_block_value(b, CO);

	    if (co)
		baf_block_destroy(co);

	    co = b;
	    delay_destroy = 1;

	    ncontigs++;
	    
	    create_new_contig(io, &c, contig, a->merge_contigs);

	    /* For anno */
	    last_obj_type = GT_Contig;
	    last_obj_rec = c->rec;
	    last_obj_pos = c->start + 1;
	    last_cnt_rec = c->rec;
	    last_cnt_pos = c->start + 1;
	    last_obj_orient = 0;

	    break;
	}

	case RD: {
	    seq_t seq;
	    int flags;
	    char *tname;
	    tg_rec recno;
	    int is_pair = 0;

	    /* Construct seq struct */
	    if (-1 == construct_seq_from_block(a, &seq, b, &tname)) {
		fprintf(stderr, "Failed to parse read block for seq %d\n",
			nseqs);
		break;
	    }

	    /* Create range, save sequence */
	    flags = GRANGE_FLAG_TYPE_SINGLE;
	    
	    if (seq.flags & SEQ_END_REV)
		flags |= GRANGE_FLAG_END_REV;
	    else
		flags |= GRANGE_FLAG_END_FWD;
	    if (seq.len < 0)
		flags |= GRANGE_FLAG_COMP1;
		
	    if (pair) is_pair = 1;
		
	    recno = save_range_sequence(io, &seq, seq.mapping_qual, pair,
					is_pair, tname, c, a, flags, NULL);

	    /* For anno */
	    last_obj_type = GT_Seq;
	    last_obj_rec = recno;
	    if (seq.len >= 0) {
		last_obj_pos = seq.pos;
		last_obj_orient = 0;
	    } else {
		last_obj_pos = seq.pos - seq.len - 1;
		last_obj_orient = 1;
	    }

	    nseqs++;
	    
	    break;
	}

	case AN: {
	    range_t r;
	    anno_ele_t *e;
	    char *typ = baf_block_value(b, AN);
	    char *loc = baf_block_value(b, LO);
	    char *len = baf_block_value(b, LL);
	    char *txt = baf_block_value(b, TX);
	    char *at  = baf_block_value(b, AT);
	    int an_pos;
	    bin_index_t *bin;
	    int anno_obj_type;

	    if (!(a->data_type & DATA_ANNO))
		break;

	    if (txt)
		unescape_line(txt);

	    if (last_obj_type == GT_Contig || (at && *at == 'C'))
		anno_obj_type = GT_Contig;
	    else
		anno_obj_type = GT_Seq;

	    if (!loc) {
		an_pos = last_obj_pos;
	    } else {
		if (*loc == '@') {
		    an_pos = atoi(loc+1);
		} else {
		    if (anno_obj_type == GT_Contig) {
			if (last_obj_orient == 0)
			    an_pos = last_cnt_pos + atoi(loc)-1;
			else
			    an_pos = last_cnt_pos - (atoi(loc)-1)
				- (len ? atoi(len)-1 : 0);
		    } else {
			if (last_obj_orient == 0)
			    an_pos = last_obj_pos + atoi(loc)-1;
			else
			    an_pos = last_obj_pos - (atoi(loc)-1)
				- (len ? atoi(len)-1 : 0);
		    }
		}
	    }

	    r.start = an_pos;
	    r.end = an_pos + (len ? atoi(len)-1 : 0);

	    r.mqual = str2type(typ);
	    r.pair_rec = (anno_obj_type == GT_Contig)
		? last_cnt_rec
		: last_obj_rec;

	    r.flags = GRANGE_FLAG_ISANNO;
	    if (GT_Seq == anno_obj_type)
		r.flags |= GRANGE_FLAG_TAG_SEQ;
	    r.rec = anno_ele_new(io, 0, anno_obj_type, r.pair_rec, 0,
				 str2type(typ), txt);
	    e = (anno_ele_t *)cache_search(io, GT_AnnoEle, r.rec);
	    e = cache_rw(io, e);
	
	    bin = bin_add_range(io, &c, &r, NULL, NULL, 0);
	    e->bin = bin->rec;

	    ntags++;
	    break;
	}

	case 0:
	    /* blank line */
	    break;

	default:
	    printf("Unsupported block type '%s'\n",
		   linetype2str(b->type));
	}

	if (!delay_destroy)
	    baf_block_destroy(b);

	if ((++nobj & 0xfff) == 0) {
	    int perc = 0;

	    pos = zftello(fp);
	    perc = 100.0 * pos / sb.st_size;
	    printf("\r%d%c", perc, (nobj & 0x3fff) ? '%' : '*');
	    fflush(stdout);
	    if ((nobj & 0x3fff) == 0)
		cache_flush(io);
	}

#if 1
	if ((nobj & 0x3fff) == 0) {
	    static int perc = 0;
	    if (perc < 100.0 * pos / sb.st_size) {
		perc = 100.0 * pos / sb.st_size;
		printf("\r%d%%", perc);
		//HacheTableStats(io->cache, stdout);
		//HacheTableStats(((GDB **)io->dbh)[0]->gfile->idx_hash, stdout);
		{
		    static struct timeval last, curr;
		    static int first = 1;
		    static int last_obj = 0;
		    static int last_contigs = 0;
		    long delta;

		    gettimeofday(&curr, NULL);
		    if (first) {
			last = curr;
			first = 0;
		    }

		    delta = (curr.tv_sec - last.tv_sec) * 1000000
			+ (curr.tv_usec - last.tv_usec);
		    printf(" - %g sec %d obj (%d contigs)\n", delta/1000000.0,
			   nobj - last_obj, ncontigs - last_contigs);
		    last = curr;
		    last_obj = nobj;
		    last_contigs = ncontigs;
		}
		fflush(stdout);
	    }
	}
#endif
    }
    
    if (pair && !a->fast_mode) {  
	finish_pairs(io, pair);
    }
    
    if (co)
	baf_block_destroy(co);

    cache_flush(io);
    zfclose(fp);

    printf("\nLoaded %12d contigs\n",     ncontigs);
    printf("       %12d sequences\n",   nseqs);
    printf("       %12d annotations\n", ntags);

    if (pair) delete_pair(pair);

    if (c)
	cache_decr(io, c);

    return 0;
}
示例#12
0
/*
 * 'make_pnts' command for importing point-cloud data into a 'pnts'
 * primitive.
 *
 * Input values:
 * argv[1] object name
 * argv[2] filename with path
 * argv[3] point data file format string
 * argv[4] point data file units string or conversion factor to millimeters
 * argv[5] default size of each point
 *
 */
int
ged_make_pnts(struct ged *gedp, int argc, const char *argv[])
{
    struct directory *dp;
    struct rt_db_internal internal;

    rt_pnt_type type;
    double local2base;
    unsigned long numPoints = 0;
    struct rt_pnts_internal *pnts;

    double defaultSize = 0.0;
    void *headPoint = NULL;

    FILE *fp;

    int temp_string_index = 0; /* index into temp_string, set to first character in temp_string, i.e. the start */
    unsigned long int num_doubles_read = 0; /* counters of double read from file */

    int current_character_double = 0; /* flag indicating if current character read is part of a double or delimiter */
    int previous_character_double = 0; /* flag indicating if previously read character was part of a double or delimiter */

    unsigned long int num_characters_read_from_file = 0;  /* counter of number of characters read from file */
    unsigned long int start_offset_of_current_double = 0; /* character offset from start of file for current double */
    int found_double = 0; /* flag indicating if double encountered in file and needs to be processed */
    int found_eof = 0; /* flag indicating if end-of-file encountered when reading file */
    int done_processing_format_string = 0; /* flag indicating if loop processing format string should be exited */

    char *temp_char_ptr = (char *)NULL;

    int buf = 0; /* raw character read from file */
    double temp_double = 0.0;
    char temp_string[1024];
    int temp_string_size = 1024;  /* number of characters that can be stored in temp_string including null terminator character */
    /* it is expected that the character representation of a double will never exceed this size string */
    char *endp = (char *)NULL;

    struct bu_vls format_string = BU_VLS_INIT_ZERO;
    size_t format_string_index = 0;

    unsigned int num_doubles_per_point = 0;

    void *point = NULL;

    char **prompt;

    static const char *usage = "point_cloud_name filename_with_path file_format file_data_units default_point_size";

    prompt = &p_make_pnts[0];

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

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

    /* prompt for point-cloud name */
    if (argc < 2) {
        bu_vls_printf(gedp->ged_result_str, "%s", prompt[0]);
        return GED_MORE;
    }

    GED_CHECK_EXISTS(gedp, argv[1], LOOKUP_QUIET, GED_ERROR);

    /* prompt for data file name with path */
    if (argc < 3) {
        bu_vls_printf(gedp->ged_result_str, "%s", prompt[1]);
        return GED_MORE;
    }

    /* prompt for data file format */
    if (argc < 4) {
        bu_vls_printf(gedp->ged_result_str, "%s", prompt[2]);
        return GED_MORE;
    }

    /* Validate 'point file data format string' and return point-cloud type. */
    if (str2type(argv[3], &type, gedp->ged_result_str) == GED_ERROR) {
        return GED_ERROR;
    }

    /* prompt for data file units */
    if (argc < 5) {
        bu_vls_printf(gedp->ged_result_str, "%s", prompt[3]);
        return GED_MORE;
    }

    /* Validate the unit string and return conversion factor to millimeters. */
    if (str2mm(argv[4], &local2base, gedp->ged_result_str) == GED_ERROR) {
        return GED_ERROR;
    }

    /* prompt for default point size */
    if (argc < 6) {
        bu_vls_printf(gedp->ged_result_str, "%s", prompt[4]);
        return GED_MORE;
    }

    defaultSize = strtod(argv[5], &endp);
    if ((endp != argv[5]) && (*endp == '\0')) {
        /* convert to double success */
        if (defaultSize < 0.0) {
            bu_vls_printf(gedp->ged_result_str, "Default point size '%lf' must be non-negative.\n", defaultSize);
            return GED_ERROR;
        }
    } else {
        bu_vls_printf(gedp->ged_result_str, "Invalid default point size '%s'\n", argv[5]);
        return GED_ERROR;
    }

    bu_vls_strcat(&format_string, argv[3]);
    bu_vls_trimspace(&format_string);

    /* init database structure */
    RT_DB_INTERNAL_INIT(&internal);
    internal.idb_major_type = DB5_MAJORTYPE_BRLCAD;
    internal.idb_type = ID_PNTS;
    internal.idb_meth = &OBJ[ID_PNTS];
    BU_ALLOC(internal.idb_ptr, struct rt_pnts_internal);

    /* init internal structure */
    pnts = (struct rt_pnts_internal *) internal.idb_ptr;
    pnts->magic = RT_PNTS_INTERNAL_MAGIC;
    pnts->scale = defaultSize;
    pnts->type = type;
    pnts->count = numPoints;  /* set again later */
    pnts->point = NULL;

    /* empty list head */
    switch (type) {
    case RT_PNT_TYPE_PNT:
        BU_ALLOC(headPoint, struct pnt);
        BU_LIST_INIT(&(((struct pnt *)headPoint)->l));
        num_doubles_per_point = 3;
        break;
    case RT_PNT_TYPE_COL:
        BU_ALLOC(headPoint, struct pnt_color);
        BU_LIST_INIT(&(((struct pnt_color *)headPoint)->l));
        num_doubles_per_point = 6;
        break;
    case RT_PNT_TYPE_SCA:
        BU_ALLOC(headPoint, struct pnt_scale);
        BU_LIST_INIT(&(((struct pnt_scale *)headPoint)->l));
        num_doubles_per_point = 4;
        break;
    case RT_PNT_TYPE_NRM:
        BU_ALLOC(headPoint, struct pnt_normal);
        BU_LIST_INIT(&(((struct pnt_normal *)headPoint)->l));
        num_doubles_per_point = 6;
        break;
    case RT_PNT_TYPE_COL_SCA:
        BU_ALLOC(headPoint, struct pnt_color_scale);
        BU_LIST_INIT(&(((struct pnt_color_scale *)headPoint)->l));
        num_doubles_per_point = 7;
        break;
    case RT_PNT_TYPE_COL_NRM:
        BU_ALLOC(headPoint, struct pnt_color_normal);
        BU_LIST_INIT(&(((struct pnt_color_normal *)headPoint)->l));
        num_doubles_per_point = 9;
        break;
    case RT_PNT_TYPE_SCA_NRM:
        BU_ALLOC(headPoint, struct pnt_scale_normal);
        BU_LIST_INIT(&(((struct pnt_scale_normal *)headPoint)->l));
        num_doubles_per_point = 7;
        break;
    case RT_PNT_TYPE_COL_SCA_NRM:
        BU_ALLOC(headPoint, struct pnt_color_scale_normal);
        BU_LIST_INIT(&(((struct pnt_color_scale_normal *)headPoint)->l));
        num_doubles_per_point = 10;
        break;
    }
    BU_ASSERT_PTR(headPoint, !=, NULL);
    pnts->point = headPoint;

    if ((fp=fopen(argv[2], "rb")) == NULL) {
        bu_vls_printf(gedp->ged_result_str, "Make '%s' failed. ", argv[1]);
        bu_vls_printf(gedp->ged_result_str, "Could not open file '%s'.\n", argv[2]);
        bu_vls_free(&format_string);
        rt_db_free_internal(&internal);
        return GED_ERROR;
    }

    while (!found_eof) {
        /* points_loop */
        /* allocate memory for single point structure for current point-cloud type */
        switch (type) {
        case RT_PNT_TYPE_PNT:
            BU_ALLOC(point, struct pnt);
            break;
        case RT_PNT_TYPE_COL:
            BU_ALLOC(point, struct pnt_color);
            break;
        case RT_PNT_TYPE_SCA:
            BU_ALLOC(point, struct pnt_scale);
            break;
        case RT_PNT_TYPE_NRM:
            BU_ALLOC(point, struct pnt_normal);
            break;
        case RT_PNT_TYPE_COL_SCA:
            BU_ALLOC(point, struct pnt_color_scale);
            break;
        case RT_PNT_TYPE_COL_NRM:
            BU_ALLOC(point, struct pnt_color_normal);
            break;
        case RT_PNT_TYPE_SCA_NRM:
            BU_ALLOC(point, struct pnt_scale_normal);
            break;
        case RT_PNT_TYPE_COL_SCA_NRM:
            BU_ALLOC(point, struct pnt_color_scale_normal);
            break;
        }

        /* make sure we have something */
        BU_ASSERT_PTR(point, !=, NULL);

        while (!found_eof && !done_processing_format_string) {
            /* format_string_loop */
            char format = '\0';

            while (!found_eof  && !found_double) {
                /* find_doubles_loop */
                format = bu_vls_addr(&format_string)[format_string_index];

                buf = fgetc(fp);

                num_characters_read_from_file++;

                if (feof(fp)) {
                    if (ferror(fp)) {
                        perror("ERROR: Problem reading file, system error message");
                        fclose(fp);
                        bu_vls_printf(gedp->ged_result_str, "Make '%s' failed. ", argv[1]);
                        bu_vls_printf(gedp->ged_result_str, "Unable to read file at byte '%lu'.\n", num_characters_read_from_file);
                        bu_vls_free(&format_string);
                        rt_db_free_internal(&internal);
                        return GED_ERROR;
                    } else {
                        found_eof = 1;
                    }
                }

                if (found_eof) {
                    fclose(fp);
                    current_character_double = 0;
                    if (num_doubles_read == 0) {
                        bu_vls_printf(gedp->ged_result_str, "Make '%s' failed. ", argv[1]);
                        bu_vls_printf(gedp->ged_result_str, "No data in file '%s'.\n", argv[2]);
                        bu_vls_free(&format_string);
                        rt_db_free_internal(&internal);
                        return GED_ERROR;
                    }
                } else {
                    temp_char_ptr = strchr("0123456789.+-eE", buf);
                    if (temp_char_ptr != NULL) {
                        /* character read is part of a double */
                        current_character_double = 1;
                    } else {
                        current_character_double = 0;
                    }
                }

                if (previous_character_double && current_character_double) {
                    if (temp_string_index >= temp_string_size) {
                        fclose(fp);
                        bu_vls_printf(gedp->ged_result_str, "Make '%s' failed. ", argv[1]);
                        bu_vls_printf(gedp->ged_result_str, "String representing double too large, exceeds '%d' character limit. ", temp_string_size - 1);
                        report_import_error_location(num_doubles_read, num_doubles_per_point, start_offset_of_current_double,
                                                     format, gedp->ged_result_str);
                        bu_vls_free(&format_string);
                        rt_db_free_internal(&internal);
                        return GED_ERROR;
                    }
                    temp_string[temp_string_index] = (char)buf;
                    temp_string_index++;
                }

                if (previous_character_double && !current_character_double) {
                    if (temp_string_index >= temp_string_size) {
                        fclose(fp);
                        bu_vls_printf(gedp->ged_result_str, "Make '%s' failed. ", argv[1]);
                        bu_vls_printf(gedp->ged_result_str, "String representing double too large, exceeds '%d' character limit. ", temp_string_size - 1);
                        report_import_error_location(num_doubles_read, num_doubles_per_point, start_offset_of_current_double,
                                                     format, gedp->ged_result_str);
                        bu_vls_free(&format_string);
                        rt_db_free_internal(&internal);
                        return GED_ERROR;
                    }
                    temp_string[temp_string_index] = '\0';

                    /* do not convert string to double for format character '?' */
                    if (format != '?') {
                        temp_double = strtod(temp_string, &endp);
                        if (!((endp != temp_string) && (*endp == '\0'))) {
                            fclose(fp);
                            bu_vls_printf(gedp->ged_result_str, "Make '%s' failed. ", argv[1]);
                            bu_vls_printf(gedp->ged_result_str, "Unable to convert string '%s' to double. ", temp_string);
                            report_import_error_location(num_doubles_read, num_doubles_per_point, start_offset_of_current_double,
                                                         format, gedp->ged_result_str);
                            bu_vls_free(&format_string);
                            rt_db_free_internal(&internal);
                            return GED_ERROR;
                        }
                        num_doubles_read++;
                    } else {
                        temp_double = 0.0;
                    }

                    temp_string_index = 0;
                    found_double = 1;
                    previous_character_double = current_character_double;
                }

                if (!previous_character_double && current_character_double) {
                    temp_string[temp_string_index] = (char)buf;
                    temp_string_index++;
                    start_offset_of_current_double = num_characters_read_from_file;
                    previous_character_double = current_character_double;
                }

            } /* loop exits when eof encountered (and/or) double found */

            if (found_double) {

                /* insert double into point structure for current point-cloud type */
                /* do not attempt to insert double into point structure for format character '?' */
                if (format != '?') {
                    switch (type) {
                    case RT_PNT_TYPE_PNT:
                        INSERT_COORDINATE_INTO_STRUCTURE(pnt, format, (temp_double * local2base));
                        break;
                    case RT_PNT_TYPE_COL:
                        INSERT_COORDINATE_INTO_STRUCTURE(pnt_color, format, (temp_double * local2base));
                        INSERT_COLOR_INTO_STRUCTURE(pnt_color, format, temp_double);
                        break;
                    case RT_PNT_TYPE_SCA:
                        INSERT_COORDINATE_INTO_STRUCTURE(pnt_scale, format, (temp_double * local2base));
                        INSERT_SCALE_INTO_STRUCTURE(pnt_scale, format, (temp_double * local2base));
                        break;
                    case RT_PNT_TYPE_NRM:
                        INSERT_COORDINATE_INTO_STRUCTURE(pnt_normal, format, (temp_double * local2base));
                        INSERT_NORMAL_INTO_STRUCTURE(pnt_normal, format, (temp_double * local2base));
                        break;
                    case RT_PNT_TYPE_COL_SCA:
                        INSERT_COORDINATE_INTO_STRUCTURE(pnt_color_scale, format, (temp_double * local2base));
                        INSERT_COLOR_INTO_STRUCTURE(pnt_color_scale, format, temp_double);
                        INSERT_SCALE_INTO_STRUCTURE(pnt_color_scale, format, (temp_double * local2base));
                        break;
                    case RT_PNT_TYPE_COL_NRM:
                        INSERT_COORDINATE_INTO_STRUCTURE(pnt_color_normal, format, (temp_double * local2base));
                        INSERT_COLOR_INTO_STRUCTURE(pnt_color_normal, format, temp_double);
                        INSERT_NORMAL_INTO_STRUCTURE(pnt_color_normal, format, (temp_double * local2base));
                        break;
                    case RT_PNT_TYPE_SCA_NRM:
                        INSERT_COORDINATE_INTO_STRUCTURE(pnt_scale_normal, format, (temp_double * local2base));
                        INSERT_SCALE_INTO_STRUCTURE(pnt_scale_normal, format, (temp_double * local2base));
                        INSERT_NORMAL_INTO_STRUCTURE(pnt_scale_normal, format, (temp_double * local2base));
                        break;
                    case RT_PNT_TYPE_COL_SCA_NRM:
                        INSERT_COORDINATE_INTO_STRUCTURE(pnt_color_scale_normal, format, (temp_double * local2base));
                        INSERT_COLOR_INTO_STRUCTURE(pnt_color_scale_normal, format, temp_double);
                        INSERT_SCALE_INTO_STRUCTURE(pnt_color_scale_normal, format, (temp_double * local2base));
                        INSERT_NORMAL_INTO_STRUCTURE(pnt_color_scale_normal, format, (temp_double * local2base));
                        break;
                    }
                }
                found_double = 0;  /* allows loop to continue */
                format_string_index++;
                if (format_string_index >= bu_vls_strlen(&format_string)) {
                    done_processing_format_string = 1;
                }
            }

        } /* loop exits when eof encountered (and/or) all doubles for
	   * a single point are stored in point structure
	   */

        if (done_processing_format_string) {
            /* push single point structure onto linked-list of points
             * which makeup the point-cloud.
             */
            switch (type) {
            case RT_PNT_TYPE_PNT:
                BU_LIST_PUSH(&(((struct pnt *)headPoint)->l), &((struct pnt *)point)->l);
                break;
            case RT_PNT_TYPE_COL:
                BU_LIST_PUSH(&(((struct pnt_color *)headPoint)->l), &((struct pnt_color *)point)->l);
                break;
            case RT_PNT_TYPE_SCA:
                BU_LIST_PUSH(&(((struct pnt_scale *)headPoint)->l), &((struct pnt_scale *)point)->l);
                break;
            case RT_PNT_TYPE_NRM:
                BU_LIST_PUSH(&(((struct pnt_normal *)headPoint)->l), &((struct pnt_normal *)point)->l);
                break;
            case RT_PNT_TYPE_COL_SCA:
                BU_LIST_PUSH(&(((struct pnt_color_scale *)headPoint)->l), &((struct pnt_color_scale *)point)->l);
                break;
            case RT_PNT_TYPE_COL_NRM:
                BU_LIST_PUSH(&(((struct pnt_color_normal *)headPoint)->l), &((struct pnt_color_normal *)point)->l);
                break;
            case RT_PNT_TYPE_SCA_NRM:
                BU_LIST_PUSH(&(((struct pnt_scale_normal *)headPoint)->l), &((struct pnt_scale_normal *)point)->l);
                break;
            case RT_PNT_TYPE_COL_SCA_NRM:
                BU_LIST_PUSH(&(((struct pnt_color_scale_normal *)headPoint)->l), &((struct pnt_color_scale_normal *)point)->l);
                break;
            }
            numPoints++;
            format_string_index = 0;
            done_processing_format_string = 0;
        }

    } /* loop exits when eof encountered */

    if (num_doubles_read < num_doubles_per_point) {
        bu_vls_printf(gedp->ged_result_str, "Make '%s' failed. Number of values read inconsistent with point-cloud type ", argv[1]);
        bu_vls_printf(gedp->ged_result_str, "defined by format string '%V'. The number of values read must be an even ", format_string);
        bu_vls_printf(gedp->ged_result_str, "multiple of %d but read %lu values.\n", num_doubles_per_point, num_doubles_read);
        bu_vls_free(&format_string);
        rt_db_free_internal(&internal);
        return GED_ERROR;
    }

    if (num_doubles_read % num_doubles_per_point) {
        bu_vls_printf(gedp->ged_result_str, "Make '%s' failed. Number of values read inconsistent with point-cloud type ", argv[1]);
        bu_vls_printf(gedp->ged_result_str, "defined by format string '%V'. The number of values read must be an even ", format_string);
        bu_vls_printf(gedp->ged_result_str, "multiple of %d but read %lu values.\n", num_doubles_per_point, num_doubles_read);
        bu_vls_free(&format_string);
        rt_db_free_internal(&internal);
        return GED_ERROR;
    }

    pnts->count = numPoints;

    GED_DB_DIRADD(gedp, dp, argv[1], RT_DIR_PHONY_ADDR, 0, RT_DIR_SOLID, (void *)&internal.idb_type, GED_ERROR);
    GED_DB_PUT_INTERNAL(gedp, dp, &internal, &rt_uniresource, GED_ERROR);

    bu_vls_free(&format_string);

    bu_vls_printf(gedp->ged_result_str, "Make '%s' success, %lu values read, %lu points imported.\n", argv[1], num_doubles_read, numPoints);

    return GED_OK;
}