Пример #1
0
static void write_field(FILE *f, const save_field_t *field, void *base)
{
    void *p = (byte *)base + field->ofs;
    int i;

    switch (field->type) {
    case F_BYTE:
        write_data(p, field->size, f);
        break;
    case F_SHORT:
        for (i = 0; i < field->size; i++) {
            write_short(f, ((short *)p)[i]);
        }
        break;
    case F_INT:
        for (i = 0; i < field->size; i++) {
            write_int(f, ((int *)p)[i]);
        }
        break;
    case F_FLOAT:
        for (i = 0; i < field->size; i++) {
            write_float(f, ((float *)p)[i]);
        }
        break;
    case F_VECTOR:
        write_vector(f, (vec_t *)p);
        break;

    case F_ZSTRING:
        write_string(f, (char *)p);
        break;
    case F_LSTRING:
        write_string(f, *(char **)p);
        break;

    case F_EDICT:
        write_index(f, *(void **)p, sizeof(edict_t), g_edicts, MAX_EDICTS - 1);
        break;
    case F_CLIENT:
        write_index(f, *(void **)p, sizeof(gclient_t), game.clients, game.maxclients - 1);
        break;
    case F_ITEM:
        write_index(f, *(void **)p, sizeof(gitem_t), itemlist, game.num_items - 1);
        break;

    case F_POINTER:
        write_pointer(f, *(void **)p, field->size);
        break;

    default:
        gi.error("%s: unknown field type", __func__);
    }
}
Пример #2
0
/* definitions */
void *static_deflate(void *io_struct)
{
	io *io_s = (io *) io_struct;
	prepare_input_output(io_s);
	cyclic_queue *cqbuff = new_cyclic_queue(LEN_SIZE_Q, false);

	write_static_header(io_s);

	byte buff[LEN_MAX];
	size_t count = fread(buff, EL_SIZE, LEN_MAX, io_s->input);
	push_back_cyclic_queue(cqbuff, buff, count);

	byte front_b;
	size_t offset, length, last_count;
	while (!isempty_cyclic_queue(cqbuff)) {
		search_cyclic_queue(io_s->cqdict, cqbuff, &offset, &length);
		if (offset == 0 && length == 0) {
			front_b = front_cyclic_queue(cqbuff);
			write_literal(io_s, front_b);
			move_front_cyclic_queue(cqbuff, io_s->cqdict, 1);
		} else {
			write_pointer(io_s, length, offset);
			move_front_cyclic_queue(cqbuff, io_s->cqdict, length);
		}
		
		if (length == 0)
			length = 1;

		if (count < io_s->block_size) {
			if (count + length > io_s->block_size)
				length = count + length - io_s->block_size;
			last_count = fread(buff, EL_SIZE, length, io_s->input);
			push_back_cyclic_queue(cqbuff, buff, last_count);
			count += last_count;
		}
	}
	io_s->block_size = count;

	write_end_of_block(io_s);
	if (io_s->isfinal)
		byte_flush(io_s);

	delete_cyclic_queue(cqbuff);
	io_s->result = get_output_size(io_s);
	pthread_exit(NULL);
}
Пример #3
0
int start(void)
#endif
{
  int i;
  uint32_t apl;
  float ong;
  uint64_t apl64;
  uint16_t apl16;
  uint8_t apl8;
  void* ptr;
  double ong64;
  
  for (i = 0; i < 10; ++i) {
    apl64 = read_uint64("apples64");
    #ifdef RUN
    fprintf(stderr, "\n(%d.a) got a 64 bit apple: %llu..", i, apl64);
    #endif
    
    ong64 = (double)apl64;
    write_float64("oranges64", ong64);
    #ifdef RUN
    fprintf(stderr, "\nsent a (double) orange: %le.", ong64);
    #endif

    apl = read_uint32("apples32");
    #ifdef RUN
    fprintf(stderr, "\n(%d.b) got a 32-bit apple: %d.", i, apl);
    #endif
    
    ong = (float)apl;
    write_float32("oranges32", ong);
    #ifdef RUN
    fprintf(stderr, "\nsent a (float) orange: %f.", ong);
    #endif

    apl16 = read_uint16("apples16");
    #ifdef RUN
    fprintf(stderr, "\n(%d.c) got a 16-bit apple: %d.", i, apl16);
    #endif
    
    apl8 = (uint8_t)apl;
    write_uint8("oranges8", apl8);
    #ifdef RUN
    fprintf(stderr, "\nsent an 8-bit orange: %d.", apl8);
    #endif

    ptr = read_pointer("apples32");
    #ifdef RUN
    fprintf(stderr, "\n(%d.d) got a pointer apple: %d.", i, (unsigned int) ptr);
    #endif
    
    write_pointer("oranges32", ptr);
    #ifdef RUN
    fprintf(stderr, "\nsent a pointer orange: %d.", (unsigned int) ptr);
    #endif
  }

  #ifdef RUN
  fprintf(stderr, "\n");
  #endif
  return 0;
}
Пример #4
0
void write_uintptr(char *id, uint32_t* data)
{
	write_pointer(id,(void*) data);
}
Пример #5
0
int start (void)
#endif
{
    uint64_t apl64;
    uint32_t i, apl;
    uint16_t apl16;
    uint8_t apl8,my_apl8;
    void *sptr, *rptr;
    double ong64, my_ong64;
    float ong, my_ong;
    int failure = 0;

    i = 0;

    while (i < 10) {
#ifdef RUN
        apl = rand();
#else
        apl = i + 1;
#endif
        my_ong = (float)apl;
        my_ong64 = (double)apl;
        apl64  = (uint64_t)apl;
        apl16  = (uint16_t)apl;
        my_apl8  = (uint8_t)apl16;

        write_uint64("apples64", apl64);
#ifdef RUN
        fprintf(stderr, "\n(%d.a) sent a 64-bit apple: %llu..", i, apl64);
#endif

        ong64 = read_float64("oranges64");

#ifdef RUN
        fprintf(stderr, "\ngot a (double) orange: %le.", ong64);
#endif

        failure |= (my_ong64 != ong64);

        write_uint32("apples32", apl);
#ifdef RUN
        fprintf(stderr, "\n(%d.b) sent a 32-bit apple: %d.", i, apl);
#endif

        ong = read_float32("oranges32");
#ifdef RUN
        fprintf(stderr, "\ngot a (float) orange: %f.", ong);
#endif

        failure |= (my_ong != ong);

        write_uint16("apples16", apl16);
#ifdef RUN
        fprintf(stderr, "\n(%d.c) sent a 16-bit apple: %d.", i, apl16);
#endif

        apl8 = read_uint8("oranges8");
#ifdef RUN
        fprintf(stderr, "\ngot an 8-bit orange: %d.", apl8);
#endif

        sptr = (void*) &apl;
        write_pointer("apples32", sptr);
#ifdef RUN
        fprintf(stderr, "\n(%d.d) sent a pointer apple: %d.", i, (unsigned int)sptr);
#endif

        rptr = read_pointer("oranges32");
#ifdef RUN
        fprintf(stderr, "\ngot a pointer orange: %d.",(unsigned int) rptr);
#endif

        failure |= (sptr != rptr);
        ++i;
    }

#ifdef RUN
    if (failure == 0)
        fprintf(stderr, "\nAll conversions successful.\n");
    else
        fprintf(stderr, "\nSome conversion(s) failed.\n");
#endif

    return failure;
}