Beispiel #1
0
void
prepare(void)
{
    struct rt_i *rtip = APP.a_rt_i;

    RT_CK_RTI(rtip);

    if (debug)  fprintf(stderr, "prepare()\n");

    /*
     * initialize application -- it will allocate 1 line and
     * set buf_mode=1, as well as do mlib_init().
     */
    (void)view_init(&APP, title_file, title_obj, 0, 0);

    do_prep(rtip);

    if (rtip->nsolids <= 0)
	bu_exit(3, "ph_matrix: No solids remain after prep.\n");

    grid_setup();

    /* initialize lighting */
    view_2init(&APP, NULL);

    rtip->nshots = 0;
    rtip->nmiss_model = 0;
    rtip->nmiss_tree = 0;
    rtip->nmiss_solid = 0;
    rtip->nmiss = 0;
    rtip->nhits = 0;
    rtip->rti_nrays = 0;

}
int main()
{
    do_prep();

    uint_t t;
    RawWriter rw;
    rw.init();

    RawReader rr;
    rr.init();
    t = rr.getu32();

    assert (t <= T_MAX);
    for (uint_t i = 0; i < t; i++) {
        uint_t n;
        n = rr.getu32();
        uint_t res = do_calc(n);
        rw.putu32(res);
    }

    rw.write_all();

    return 0;
}
Beispiel #3
0
_public int gidx_wr_write(gidx_wr_t wr, int fd)
{
	size_t strtab_sz, idxblk_sz, chblk_sz;
	unsigned int i, j, c_idx, s_ofs;
	struct wr_field **flayout = NULL;
	struct wr_chunk **clayout = NULL;
	gidx_off_t first_chunk, data_sz;
	size_t align;
	fobuf_t buf;

	idxblk_sz = wr->wr_num_fields * sizeof(struct gidx_idx);
	strtab_sz = do_prep(wr);
	if ( 0 == strtab_sz )
		return 0;

	if ( !size_up_chunks(wr) )
		return 0;

	chblk_sz = wr->wr_tot_chunks * sizeof(struct gidx_chunk);

	DEBUG("allocated %p", wr);
	first_chunk = sizeof(struct gidx_hdr) + idxblk_sz +
			chblk_sz + strtab_sz;
	align = GIDX_ALIGN_BYTES(first_chunk);
	first_chunk = ALIGN_GIDX(first_chunk);

	INFO("%u indices, %u chunks, %zu byte strtab",
		wr->wr_num_fields, wr->wr_tot_chunks, strtab_sz);
	INFO("%zu byte header, %zu bytes indexes, %zu bytes chunks, "
		"%zu bytes strtab, %zu bytes align",
		sizeof(struct gidx_hdr), idxblk_sz,
		chblk_sz, strtab_sz, align);
	INFO("first chunk begins at 0x%"GIDX_PRIx_OFS, first_chunk);

	buf = fobuf_new(fd, 0);
	if ( NULL == buf )
		return 0;

	if ( !write_header(buf, wr->wr_num_fields,
				wr->wr_tot_chunks, strtab_sz) )
		goto abort;

	flayout = calloc(wr->wr_num_fields, sizeof(*flayout));
	if ( NULL == flayout )
		goto abort;
	for (i = 0; i < wr->wr_num_fields; i++)
		flayout[i] = wr->wr_field + i;
	sort(flayout, wr->wr_num_fields, sizeof(*flayout), f_cmp);

	for(s_ofs = c_idx = i = 0; i < wr->wr_num_fields; i++) {
		if ( !write_index(buf, flayout[i], &c_idx, &s_ofs) )
			goto abort;
	}

	clayout = calloc(wr->wr_tot_chunks, sizeof(*clayout));
	if ( NULL == clayout )
		goto abort;
	for (i = 0; i < wr->wr_tot_chunks; i++)
		clayout[i] = wr->wr_chunk + i;

	data_sz = layout_chunks(clayout, wr->wr_tot_chunks, first_chunk);
	if ( 0 == data_sz )
		goto abort;

	INFO("%"GIDX_PRIu_OFS" bytes data, total file size expeted at 0x%."GIDX_PRIx_OFS,
		data_sz, first_chunk + data_sz);
	for(i = 0; i < wr->wr_num_fields; i++) {
		for(j = 0; j < flayout[i]->f_num_chunks; j++) {
			if ( !write_chdr(buf, flayout[i]->f_chunk + j) )
				goto abort;
		}
	}

	for(i = 0; i < wr->wr_num_fields; i++) {
		if ( !fobuf_write(buf, flayout[i]->f_name,
					strlen(flayout[i]->f_name)) )
			goto abort;
	}

	if ( !fobuf_write(buf, alignbuf, align) )
		goto abort;

	for(i = 0; i < wr->wr_tot_chunks; i++) {
		switch(clayout[i]->c_blkid) {
		case -1:
			switch(clayout[i]->c_format) {
			case GIDX_CHUNK_OID_BLOCK:
				if ( !write_oid_block(buf, wr, clayout[i]) )
					goto abort_state;
				break;
			case GIDX_CHUNK_SKEY_TBL:
				if ( !write_sk_tbl(buf, wr, clayout[i]) )
					goto abort_state;
				break;
			case GIDX_CHUNK_SKEY_BLOCK:
				if ( !write_sk_block(buf, wr, clayout[i]) )
					goto abort_state;
				break;
			default:
				ERR("Bad system chunk format 0x%.2x",
					clayout[i]->c_format);
				goto abort_state;
			}
			break;
		default:
			assert(clayout[i]->c_blkid >= 0);
			assert(clayout[i]->c_blkid <= 0xffff);
			if ( !write_user_chunk(buf, clayout[i]) )
				goto abort;
			break;
		}
	}

	free(flayout);
	free(clayout);
	return fobuf_close(buf);
abort_state:
	for(i = 0; i < wr->wr_num_fields; i++) {
		free(wr->wr_field[i].f_ctx);
		wr->wr_field[i].f_ctx = NULL;
	}
abort:
	ERR("write aborted");
	fobuf_abort(buf);
	free(flayout);
	free(clayout);
	return 0;
}