예제 #1
0
void img_dmap_write(FILE *f, img_dmap_t *dmap) {
    int count;
    short int has_uppers;

    /* Write the identifier */
    write_word((u_int32_t *)"DMAP", f);

    /* Write the width and height */
    write_short(&dmap->w, f);
    write_short(&dmap->h, f);

    if (dmap->uppers == NULL)
	has_uppers = 0;
    else
	has_uppers = 1;
    
    write_short(&has_uppers, f);

    /* Write the distances */
    for (count = 0; count < dmap->w * dmap->h; count++)
	write_double(&(dmap->dists[count]), f);

    /* Write each vector */
    for (count = 0; count < dmap->w * dmap->h; count++) {
	write_double(&(Vx(dmap->nns[count])), f);
	write_double(&(Vy(dmap->nns[count])), f);
    }

    if (dmap->uppers != NULL) {
	for (count = 0; count < dmap->w * dmap->h; count++) {
	    write_short(&Vx(dmap->uppers[count]), f);
	    write_short(&Vy(dmap->uppers[count]), f);
	}
    }
}
/**
 * @brief Writes MMC marker.
 *
 * @param buffer
 * @param img
 */
void write_mcc_marker(type_buffer *buffer, type_mcc *mcc) {
	int length;
	int i,j;
	
	write_short(buffer, MCC);
	length=5 + 6 * mcc->count;

	for(i=0; i<mcc->count; ++i) {
		length += mcc->data[i].input_count * (1 << mcc->data[i].input_component_type) + mcc->data[i].output_count * ( 1 << mcc->data[i].output_component_type);
	}

	write_int(buffer, length);
	write_byte(buffer, mcc->index);

	type_mcc_data* data;

	for(i=0; i<mcc->count; ++i) {
		data = &mcc->data[i];
		write_byte(buffer, data->type);
		write_short(buffer, data->input_count | ( data->input_component_type << 14));
		for(j=0; j<data->input_count * (1 << data->input_component_type); ++j) {
			write_byte(buffer, data->input_components[j]);
		}
		write_short(buffer, data->output_count | ( data->output_component_type << 14));
		for(j=0; j<data->output_count * (1 << data->output_component_type); ++j) {
			write_byte(buffer, data->output_components[j]);
		}
		if(data->type & 2) {
			write_byte(buffer, data->atk | (data->ads << 4));
		} else {
			write_byte(buffer, data->decorrelation_transform_matrix | ( data->deccorelation_transform_offset << 4));
		}
	}
}
예제 #3
0
파일: BmpWrite.cpp 프로젝트: jnsdbr/ss2010
int BmpWrite::operator=(Image& img) {
   long BytesPerLine;
   long BufferSize;
   int x,y;
   unsigned char* buffer;
   if (NULL !=f ) {
      width  = img.Width();
      height = img.Height();
      BytesPerLine = Align32(width*3);
      BufferSize = BytesPerLine*height;
      // Bitmap File Header
      fwrite("BM",1,2,f);
      write_long(14+40+BufferSize);
      write_short(0);
      write_short(0);
      write_long(14+40);
      // DIB Header
      write_long(40);
      write_long(width);
      write_long(height);
      write_short(1);
      write_short(24);
      write_long(0);
      write_long(BufferSize);
      write_long(0);
      write_long(0);
      write_long(0);
      write_long(0);
      // no LUT
      ;
      // write pixel data
      for (y=0;y<height;y++) {
         for (x=0;x<width;x++) {
            write_char(img[y][x].Blue());
            write_char(img[y][x].Green());
            write_char(img[y][x].Red());
            buffer +=3;
         }
         for (int i=BytesPerLine-3*x;i>0;i--) {
            write_char(0);
         }
      }
      fclose(f);
      f = NULL;
      return 0;
   } else {
      return 1;
   }
}
예제 #4
0
파일: writer.cpp 프로젝트: kichik/nsis-1
// size in this case is the length of the string to write.
void writer_sink::write_string(const TCHAR *s, size_t size)
{
#ifdef _UNICODE
  if (m_build_unicode)
  {
    bool strEnd = false;
    TCHAR ch;
    for (; size ; size--)
    {
      if (!strEnd)
      {
        ch = *s++;
        if (ch == _T('\0'))
          strEnd = true;
      }
      write_short(ch);
    }
  }
  else
  {
    char *wb = new char[size];
    memset(wb, 0, size);
    WideCharToMultiByte(CP_ACP, 0, s, -1, wb, size, NULL, NULL);
    write_data(wb, size);
    delete [] wb;
 }
#else
  char *wb = new char[size];
  memset(wb, 0, size);
  strncpy(wb, s, size);
  write_data(wb, size);
  delete [] wb;
#endif
}
예제 #5
0
파일: writer.cpp 프로젝트: kichik/nsis
// size in this case is the length of the string to write.
void writer_sink::write_string(const TCHAR *s, size_t size)
{
#ifdef _UNICODE
  if (m_ti.is_unicode())
  {
    bool strEnd = false;
    TCHAR ch = L'\0';
    for (; size ; size--)
    {
      if (!strEnd)
      {
        ch = *s++;
        if (ch == _T('\0'))
          strEnd = true;
      }
      write_short(ch);
    }
  }
  else
  {
    char *wb = new char[size];
    memset(wb, 0, size);
    WideCharToMultiByte(CP_ACP, 0, s, -1, wb, (int)size, NULL, NULL);
    write_data(wb, size);
    delete [] wb;
 }
#else
  //TODO: Why does this allocate memory? It could just write the string and a manual zero character?
  char *wb = new char[size];
  memset(wb, 0, size);
  strncpy(wb, s, size);
  write_data(wb, size);
  delete [] wb;
#endif
}
예제 #6
0
파일: AuWrite.c 프로젝트: aosm/X11
static int
write_counted_string (unsigned short count, char *string, FILE *file)
{
    if (write_short (count, file) == 0)
	return 0;
    if (fwrite (string, (int) sizeof (char), (int) count, file) != count)
	return 0;
    return 1;
}
예제 #7
0
파일: ascii1.c 프로젝트: FuzzyHobbit/mordor
int write_object_basic(FILE *fp, int index, object *obj)
{
	int	i;
	
/* begin of object data */
	write_int(fp, index);  /* object # */
	
	printf("Writing object %s\n", obj->name );

	write_chars(fp, obj->name, sizeof(obj->name));
	write_chars(fp, obj->description, sizeof(obj->description));
	for (i = 0; i != 3; i++)
		write_chars(fp, obj->key[i], sizeof(obj->key[i]));
	write_chars(fp, obj->use_output, sizeof(obj->use_output));
	write_long(fp, obj->value);
	write_short(fp, obj->weight);
	
	write_char(fp, obj->type);
	write_char(fp, obj->adjustment);
	
	write_short(fp, obj->shotsmax);
	write_short(fp, obj->shotscur);
	write_short(fp, obj->ndice);
	write_short(fp, obj->sdice);
	write_short(fp, obj->pdice);
	
	write_char(fp, obj->armor);
	write_char(fp, obj->wearflag);
	write_char(fp, obj->magicpower);
	write_char(fp, obj->magicrealm);
	write_short(fp, obj->special);
	write_chars(fp, obj->flags, sizeof(obj->flags));
	write_char(fp, obj->questnum);
	write_char(fp,obj->strength);
	write_char(fp,obj->dexterity);
	write_char(fp,obj->constitution);
	write_char(fp,obj->intelligence);
	write_char(fp,obj->piety);
	for (i = 0; i != 16; i++)
		write_short(fp, obj->sets_flag[i]);
	write_short(fp,obj->special1);
	write_long(fp,obj->special2);

	
/* end of object data */

	return(0);
	
}
예제 #8
0
파일: cfgdump.c 프로젝트: LogosBible/mono
static void
write_string (MonoCompile *cfg, const char *str)
{
	size_t len = strnlen (str, 0x2000);
	write_int (cfg, (int) len);

	gunichar2 *u = u8to16 (str);
	for (int i = 0; i < len; i++)
		write_short (cfg, u[i]);
}
예제 #9
0
	void OutPacket::write_string(const std::string& str)
	{
		int16_t length = static_cast<int16_t>(str.length());
		write_short(length);

		for (int16_t i = 0; i < length; i++)
		{
			write_byte(str[i]);
		}
	}
예제 #10
0
파일: g_save.c 프로젝트: Jenco420/q2pro
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__);
    }
}
예제 #11
0
char * Slot_encode(Slot *slot, size_t *len){
    logmsg(LOG_DEBUG, "Encoding slot.");
    if (slot == NULL){
	Slot *emptyslot = Slot_new_empty();
        char *data = Slot_encode(emptyslot, len);
	Slot_free(emptyslot);
	return data;
    }
	
    char *data;
    size_t pos = 0;
    if (Slot_is_empty(slot)){
	data = malloc(sizeof(char) * SIZE_SHORT);
	pos += write_short(slot->id, data + pos);
	*len = pos;
	return data;
    }

    if (slot->nbt_len == -1){
	data = malloc(sizeof(char) *
		      (SIZE_SHORT + SIZE_BYTE + SIZE_SHORT + SIZE_SHORT));
    } else {
	data = malloc(sizeof(char) *
		      (SIZE_SHORT + SIZE_BYTE + SIZE_SHORT + SIZE_SHORT +
		       slot->nbt_len));
    }
    
    pos += write_short(slot->id, data+pos);
    pos += write_char(slot->count, data+pos);
    pos += write_short(slot->damage, data+pos);
    pos += write_short(slot->nbt_len, data+pos);

    if (slot->nbt_len != -1){
	memcpy(data+pos, slot->nbt, slot->nbt_len);
	pos += slot->nbt_len;
    }
    *len = pos;
    return data;
}
예제 #12
0
int
XauWriteAuth (FILE *auth_file, Xauth *auth)
{
    if (write_short (auth->family, auth_file) == 0)
	return 0;
    if (write_counted_string (auth->address_length, auth->address, auth_file) == 0)
	return 0;
    if (write_counted_string (auth->number_length, auth->number, auth_file) == 0)
	return 0;
    if (write_counted_string (auth->name_length, auth->name, auth_file) == 0)
	return 0;
    if (write_counted_string (auth->data_length, auth->data, auth_file) == 0)
	return 0;
    return 1;
}
/**
 * @brief Writes MCT marker.
 *
 * @param buffer
 * @param img
 */
void write_mct_marker(type_buffer *buffer, type_mct *mct) {
	int length;
	uint8_t Smct;
	int i;
	
	write_short(buffer, MCT);
	length = 5 + mct->length*(1<<mct->element_type);
	write_int(buffer, length);
	Smct = (mct->element_type << 6);
	Smct |= (mct->type << 4);
	Smct |= mct->index;
	write_byte(buffer, Smct);
	
	for(i=0; i<length-5; ++i) {
		write_byte(buffer, mct->data[i]);
	}
}
예제 #14
0
파일: cfgdump.c 프로젝트: LogosBible/mono
static void
write_pool (MonoCompile *cfg, ConstantPoolEntry *entry)
{
	if (!entry || !entry->data) {
		write_byte (cfg, POOL_NULL);
		return;
	}

	short *cp_index = (short *) g_hash_table_lookup (cfg->gdump_ctx->constant_pool, entry);
	if (cp_index == NULL)
		add_pool_entry (cfg, entry);
	else {
		switch (entry->pt) {
			case PT_STRING: write_byte (cfg, POOL_STRING); break;
			case PT_METHOD: write_byte (cfg, POOL_METHOD); break;
			case PT_ENUMKLASS: write_byte (cfg, POOL_KLASS); break;
			case PT_KLASS: write_byte (cfg, POOL_KLASS); break;
			case PT_SIGNATURE: write_byte (cfg, POOL_SIGNATURE); break;
			case PT_OPTYPE: write_byte (cfg, POOL_NODE_CLASS); break;
			case PT_INPUTTYPE: write_byte (cfg, POOL_ENUM); break;
		}
		write_short (cfg, *cp_index);
	}
}
예제 #15
0
static glui32 write_stackstate(dest_t *dest, int portable)
{
  glui32 res;
  glui32 lx;
  glui32 lastframe;

  /* If we're storing for the purpose of undo, we don't need to do any
     byte-swapping, because the result will only be used by this session. */
  if (!portable) {
    res = write_buffer(dest, stack, stackptr);
    if (res)
      return res;
    return 0;
  }

  /* Write a portable stack image. To do this, we have to write stack
     frames in order, bottom to top. Remember that the last word of
     every stack frame is a pointer to the beginning of that stack frame.
     (This includes the last frame, because the save opcode pushes on
     a call stub before it calls perform_save().) */

  lastframe = (glui32)(-1);
  while (1) {
    glui32 frameend, frm, frm2, frm3;
    unsigned char loctype, loccount;
    glui32 numlocals, frlen, locpos;

    /* Find the next stack frame (after the one in lastframe). Sadly,
       this requires searching the stack from the top down. We have to
       do this for *every* frame, which takes N^2 time overall. But
       save routines usually aren't nested very deep. 
       If it becomes a practical problem, we can build a stack-frame 
       array, which requires dynamic allocation. */
    for (frm = stackptr, frameend = stackptr;
         frm != 0 && (frm2 = Stk4(frm-4)) != lastframe;
         frameend = frm, frm = frm2) { };

    /* Write out the frame. */
    frm2 = frm;

    frlen = Stk4(frm2);
    frm2 += 4;
    res = write_long(dest, frlen);
    if (res)
      return res;
    locpos = Stk4(frm2);
    frm2 += 4;
    res = write_long(dest, locpos);
    if (res)
      return res;

    frm3 = frm2;

    numlocals = 0;
    while (1) {
      loctype = Stk1(frm2);
      frm2 += 1;
      loccount = Stk1(frm2);
      frm2 += 1;

      res = write_byte(dest, loctype);
      if (res)
        return res;
      res = write_byte(dest, loccount);
      if (res)
        return res;

      if (loctype == 0 && loccount == 0)
        break;

      numlocals++;
    }

    if ((numlocals & 1) == 0) {
      res = write_byte(dest, 0);
      if (res)
        return res;
      res = write_byte(dest, 0);
      if (res)
        return res;
      frm2 += 2;
    }

    if (frm2 != frm+locpos)
      fatal_error("Inconsistent stack frame during save.");

    /* Write out the locals. */
    for (lx=0; lx<numlocals; lx++) {
      loctype = Stk1(frm3);
      frm3 += 1;
      loccount = Stk1(frm3);
      frm3 += 1;
      
      if (loctype == 0 && loccount == 0)
        break;

      /* Put in up to 0, 1, or 3 bytes of padding, depending on loctype. */
      while (frm2 & (loctype-1)) {
        res = write_byte(dest, 0);
        if (res)
          return res;
        frm2 += 1;
      }

      /* Put in this set of locals. */
      switch (loctype) {

      case 1:
        do {
          res = write_byte(dest, Stk1(frm2));
          if (res)
            return res;
          frm2 += 1;
          loccount--;
        } while (loccount);
        break;

      case 2:
        do {
          res = write_short(dest, Stk2(frm2));
          if (res)
            return res;
          frm2 += 2;
          loccount--;
        } while (loccount);
        break;

      case 4:
        do {
          res = write_long(dest, Stk4(frm2));
          if (res)
            return res;
          frm2 += 4;
          loccount--;
        } while (loccount);
        break;

      }
    }

    if (frm2 != frm+frlen)
      fatal_error("Inconsistent stack frame during save.");

    while (frm2 < frameend) {
      res = write_long(dest, Stk4(frm2));
      if (res)
        return res;
      frm2 += 4;
    }

    /* Go on to the next frame. */
    if (frameend == stackptr)
      break; /* All done. */
    lastframe = frm;
  }

  return 0;
}
예제 #16
0
/* Constructs and queues a request packet describing the http query pointed
 * to by 'start'.
 */
int make_request_packet(Server *serv, int fd, int num_chars)
{
    struct sockaddr_in client_name, local_name;
    int client_namelen, local_namelen;
    int free_start, free_end;
    int packet_length;
    char *request;
    int len;

    client_namelen = sizeof(struct sockaddr_in);
    if (getpeername(fd, (struct sockaddr *) &client_name, &client_namelen) < 0)
    {
	syslog(LOG_INFO, "make_request_packet: failed to get peer "
		"name: %m\n");
	return 0;
    }
    local_namelen = sizeof(struct sockaddr_in);
    if (getsockname(fd, (struct sockaddr *) &local_name, &local_namelen) < 0)
    {
	syslog(LOG_INFO, "make_request_packet: failed to get sock name: %m\n");
	return 0;
    }
    change_state(serv, fd, fs_requested_backend);
    /* locate the free end of the buffer (possibly appending to previous
     * control packets) */
    append_data(serv, serv->control_fd, &free_start, &free_end, fs_output);
    /* reserve the first 4 bytes of the packet for the size field */
    packet_length = PAK_COM_OFF;
    /* add command field to packet */
    serv->writebuf.buffer[free_start + packet_length++] = PAK_REQUEST;
    /* add unique ID field to packet */
    write_long(&serv->writebuf.buffer[free_start], &packet_length,
	    (getpid() & 0xffff) | (fd << 16), 1);
    /* add client IP field to packet */
    write_long(&serv->writebuf.buffer[free_start], &packet_length,
	    client_name.sin_addr.s_addr, 0);
    /* add local IP field to packet */
    write_long(&serv->writebuf.buffer[free_start], &packet_length,
	    local_name.sin_addr.s_addr, 0);
    /* add local port field to packet */
    write_short(&serv->writebuf.buffer[free_start], &packet_length,
	    serv->port, 1);
    /* write the http headers */
    request = &serv->writebuf.buffer[serv->writebuf.pos[fd]];
    while (request[0] == '\r' || request[0] == '\n')
	request++;
    for (len = 0; len < num_chars && !isspace(request[len]); len++)
	;
    if (len < num_chars)
    {
	write_string(&serv->writebuf.buffer[free_start], &packet_length,
		"method");
	write_string_n(&serv->writebuf.buffer[free_start], &packet_length,
		request, len);
	num_chars -= len;
	request += len;
	for (len = 0; len < num_chars && isspace(request[len]); len++)
	    ;
	if (len < num_chars)
	{
	    num_chars -= len;
	    request += len;
	    for (len = 0; request[len] && !isspace(request[len]); len++)
		;
	    write_string(&serv->writebuf.buffer[free_start], &packet_length,
		    "uri");
	    write_string_n(&serv->writebuf.buffer[free_start], &packet_length,
		    request, len);
	    num_chars -= len;
	    request += len;
	    for (len = 0; len < num_chars && isspace(request[len]); len++)
		;
	    if (len < num_chars)
	    {
		num_chars -= len;
		request += len;
		for (len = 0; request[len] && !isspace(request[len]); len++)
		    ;
		write_string(&serv->writebuf.buffer[free_start],
			&packet_length, "version");
		write_string_n(&serv->writebuf.buffer[free_start],
			&packet_length, request, len);
		/* each line should end with \r\n.  Be a bit lenient, and
		 * allow just \r or \n, too.  End of request is indicated
		 * by two such lines in a row */
		if (request[len] == '\r')
		    len++;
		if (request[len] == '\n')
		    len++;
		num_chars -= len;
		request += len;
		/* find "field: value\r\n" on successive lines, adding them
		 * to the buffer as field\0value\0 */
		while (num_chars > 0 && request[0] != '\r' &&
			request[0] != '\n')
		{
		    for (len = 0; len < num_chars && request[len] != ':' &&
			    request[len] != '\r' && request[len] != '\n'; len++)
			;
		    if (len < num_chars && request[len] == ':')
		    {
			write_string_n(&serv->writebuf.buffer[free_start],
				&packet_length, request, len);
			for (len++; len < num_chars && isspace(request[len]);
				len++)
			    ;
			num_chars -= len;
			request += len;
			for (len = 0; len < num_chars && request[len] != '\r' &&
				request[len] != '\n'; len++)
			    ;
			write_string_n(&serv->writebuf.buffer[free_start],
				&packet_length, request, len);
		    }
		    if (request[len] == '\r')
			len++;
		    if (request[len] == '\n')
			len++;
		    num_chars -= len;
		    request += len;
		}
	    }
	}
    }
    /* set first 4 bytes of packet to the total packet length */
    write_long(&serv->writebuf.buffer[free_start], NULL,
	    packet_length, 1);
    /* add the packet to the output buffer properly */
    if (free_end - free_start < packet_length)
	fatal(serv, "request packet overflowed the buffer\n");
    add_data(serv, serv->control_fd, NULL, free_start, packet_length,
	    fs_output);
    return 1;
}
예제 #17
0
int make_backend_error_packet(Server *serv, int fd, u32 ip, u16 nbo_port)
{
    struct sockaddr_in local_name;
    struct sockaddr_in remote_name;
    int local_namelen;
    int remote_namelen;
    int packet_length;
    int free_start, free_end;

    local_namelen = sizeof(struct sockaddr_in);
    if (getsockname(fd, (struct sockaddr *) &local_name, &local_namelen) < 0)
    {
	syslog(LOG_INFO, "make_backend_error_packet: failed to get sock "
		"name: %m\n");
	return 0;
    }
    /* locate the free end of the buffer (possibly appending to previous
     * control packets) */
    append_data(serv, serv->control_fd, &free_start, &free_end, fs_output);
    packet_length = PAK_COM_OFF;
    /* write control code */
    serv->writebuf.buffer[free_start + packet_length++] = PAK_BE_ERROR;
    /* write unique id */
    write_long(&serv->writebuf.buffer[free_start], &packet_length,
	    (getpid() & 0xffff) | (fd << 16), 1);
    /* add local IP field to packet */
    write_long(&serv->writebuf.buffer[free_start], &packet_length,
	    local_name.sin_addr.s_addr, 0);
    /* add local port field to packet */
    write_short(&serv->writebuf.buffer[free_start], &packet_length,
	    serv->port, 1);
    if (serv->fd_partner[fd] == -1)
    {
	/* the connection failed straight away, so we've still got the ip
	 * and port (already in network byte order) to use */
	write_long(&serv->writebuf.buffer[free_start], &packet_length, ip, 0);
	write_short(&serv->writebuf.buffer[free_start], &packet_length,
		nbo_port, 0);
    }
    else
    {
	/* else the partner (which is the failed backend fd) has the ip and
	 * port stored in serv->fd_connection_* */
	write_long(&serv->writebuf.buffer[free_start], &packet_length,
		serv->fd_connection_ip[serv->fd_partner[fd]], 0);
	write_short(&serv->writebuf.buffer[free_start], &packet_length,
		serv->fd_connection_port[serv->fd_partner[fd]], 1);
    }
    /* add client IP field to packet */
    remote_namelen = sizeof(struct sockaddr_in);
    if (getpeername(fd,  (struct sockaddr *) &remote_name,
	    &remote_namelen) == -1)
    {
	syslog(LOG_INFO, "make_backend_error_packet: failed to getpeer "
		"name: %m\n");
	return 0;
    }
    write_long(&serv->writebuf.buffer[free_start], &packet_length,
	    remote_name.sin_addr.s_addr, 0);
    /* write length */
    write_long(&serv->writebuf.buffer[free_start], NULL, packet_length, 1);
    /* add the packet to the output buffer properly */
    if (free_end - free_start < packet_length)
	fatal(serv, "unable to fit backend_error packet in static buffer\n");
    add_data(serv, serv->control_fd, NULL, free_start, packet_length,
	    fs_output);
    return 1;
}
예제 #18
0
파일: ascii1.c 프로젝트: FuzzyHobbit/mordor
int write_room(FILE *fp, room *rom)
{
	int	i;
	char perm_only;
	short   cnt;
	xtag    *xp;
	ctag    *cp;
	otag    *op;
	struct exit_	*exit;
	
	perm_only = 0;  /* all objects, monsters */

	printf("Writing room number %d\n", rom->rom_num );

/* begin of room data */
	fprintf(fp, "#begrom\n");
	
	write_short(fp, rom->rom_num);
	write_chars(fp, rom->name, sizeof(rom->name));
	write_char(fp, rom->lolevel);
	write_char(fp, rom->hilevel);
	write_short(fp, rom->special);
	write_char(fp, rom->trap);
	write_short(fp, rom->trapexit);
	write_chars(fp, rom->track, sizeof(rom->track));
	write_chars(fp, rom->flags, sizeof(rom->flags));
	
	for (i = 0; i != 10; i++)
		write_short(fp, rom->random[i]);
	
	write_char(fp, rom->traffic);
	
	for (i = 0; i != 10; i++)
		write_lasttime(fp, rom->perm_mon[i]);
	for (i = 0; i != 10; i++)
		write_lasttime(fp, rom->perm_obj[i]);
	
	write_long(fp, rom->beenhere);
	write_long(fp, rom->established);
	write_short(fp, rom->death_rom);
	write_char(fp,rom->zone_type);
	write_char(fp,rom->zone_subtype);
	write_char(fp,rom->env_type);
	write_short(fp,rom->special1);
	write_long(fp,rom->special2);

	
	/* short description */
	if(rom->short_desc) {
		write_short(fp, (short)(strlen(rom->short_desc)+1)); /* # of characters to read in */
		write_chars(fp, rom->short_desc, strlen(rom->short_desc)+1);
	} else {
		write_short(fp, 0);
	}
		
	/* long description */
	if(rom->long_desc) {
		write_short(fp, (short)(strlen(rom->long_desc)+1));  /* # of characters to read in */
		write_chars(fp, rom->long_desc, strlen(rom->long_desc)+1);
	} else {
		write_short(fp, 0);
	}
		
	/* object description */
	if(rom->obj_desc) {
		write_short(fp, (short)(strlen(rom->obj_desc)+1));  /* # of characters to read in */
		write_chars(fp, rom->obj_desc, strlen(rom->obj_desc)+1);
	} else {
		write_short(fp, 0);
	}

	/* exits */
	cnt = count_ext(rom);
	write_int(fp, cnt);
	
	xp = rom->first_ext;
	while(xp) {
		exit = xp->ext;
/* write exit structure */
		write_chars(fp, exit->name, sizeof(exit->name));
		write_short(fp, exit->room);
		write_chars(fp, exit->flags, sizeof(exit->flags));
		write_lasttime(fp, exit->ltime);
		write_lasttime(fp, exit->random);
		write_chars(fp, exit->rand_mesg[0], sizeof(exit->rand_mesg[0]));
		write_chars(fp, exit->rand_mesg[1], sizeof(exit->rand_mesg[1]));
		write_char(fp, exit->key);
/* end exit structure */
	
		xp = xp->next_tag;
	}
	
/* monsters */
	cnt = count_mon(rom, perm_only);
	write_int(fp, cnt);
	
	cp = rom->first_mon;
	while(cp) {
		if(!perm_only || (perm_only && cp->crt->flags[0] & 1))
			write_creature(fp, -1, cp->crt);
		cp = cp->next_tag;
	}
	
/* objects */
	cnt = count_ite(rom, perm_only);
	write_int(fp, cnt);
	
	op = rom->first_obj;
	while(op) {
		if(!perm_only || (perm_only && op->obj->flags[0] & 1))
			write_object(fp, -1, op->obj);
		op = op->next_tag;
	}
/* end of room data */
	fprintf(fp, "#endrom\n");

	return(0);
}
예제 #19
0
파일: cfgdump.c 프로젝트: LogosBible/mono
static void
write_instructions (MonoCompile *cfg, int instruction_count)
{
	MonoBasicBlock *bb;
	write_int (cfg, instruction_count);
	for (bb = cfg->bb_entry; bb; bb = bb->next_bb) {
		MonoInst *insn;
		cfg_debug ("== bb: %d (in: %d, out: %d) ==", bb->block_num, bb->in_count, bb->out_count);
		for (insn = bb->code; insn; insn = insn->next) {
			int i;
			int *id = (int *) g_hash_table_lookup (cfg->gdump_ctx->insn2id, insn);
			g_assert (id);
			write_int (cfg, *id);

			// hardcoded node class: only one input and NUM_SUCCESSOR successors
			write_pool (cfg, create_cp_entry (cfg, (void *) insn, PT_OPTYPE));
			write_byte (cfg, cfg->bb_entry->code != insn);

			// properties
			write_short (cfg, 2);

			// property #1
			GString *insndesc = mono_print_ins_index_strbuf (-1, insn);
			cfg_debug ("dumping node [%2d]: %s", *id, insndesc->str);
			write_pool (cfg, create_cp_entry (cfg, (void *) "fullname", PT_STRING));
			write_byte (cfg, PROPERTY_POOL);
			write_pool (cfg, create_cp_entry (cfg, (void *) insndesc->str, PT_STRING));
			g_string_free (insndesc, TRUE);

			// property #2
			write_pool (cfg, create_cp_entry (cfg, (void *) "category", PT_STRING));
			write_byte (cfg, PROPERTY_POOL);
			if (bb->in_count > 1 && bb->code == insn)
				write_pool (cfg, create_cp_entry (cfg, (void *) "merge", PT_STRING));
			else if (bb->code == insn)
				write_pool (cfg, create_cp_entry (cfg, (void *) "begin", PT_STRING));
			else if (MONO_IS_COND_BRANCH_OP (insn))
				write_pool (cfg, create_cp_entry (cfg, (void *) "controlSplit", PT_STRING));
			else if (MONO_IS_PHI (insn))
				write_pool (cfg, create_cp_entry (cfg, (void *) "phi", PT_STRING));
			else if (!MONO_INS_HAS_NO_SIDE_EFFECT (insn))
				write_pool (cfg, create_cp_entry (cfg, (void *) "state", PT_STRING));
			else
				write_pool (cfg, create_cp_entry (cfg, (void *) "fixed", PT_STRING));
			// end of properties
			write_int (cfg, -1); // never set predecessor.

			int *next_id;
			if (insn->next != NULL) {
				next_id = (int *) g_hash_table_lookup (cfg->gdump_ctx->insn2id, insn->next);
				g_assert (next_id);
				cfg_debug ("\tsuccessor' : [%2d]", *next_id);
				write_int (cfg, *next_id);
				for (i = 1; i < NUM_SUCCESSOR; i++)
					write_int (cfg, -1);
			} else {
				g_assert (bb->out_count < NUM_SUCCESSOR);
				for (i = 0; (i < bb->out_count) && (i < NUM_SUCCESSOR); i++) {
					if (bb->out_bb[i]->code == NULL)
						write_int (cfg, -1);
					else {
						next_id = (int *) g_hash_table_lookup (cfg->gdump_ctx->insn2id, bb->out_bb[i]->code);
						if (next_id)
							cfg_debug ("\tsuccessor'': [%2d]", *next_id);
						write_int (cfg, next_id ? *next_id : -1);
					}
				}
				for (; i < NUM_SUCCESSOR; i++)
					write_int (cfg, -1);
			}
		}
	}
}
예제 #20
0
파일: cfgdump.c 프로젝트: LogosBible/mono
static void
add_pool_entry (MonoCompile *cfg, ConstantPoolEntry *entry)
{
	int *cp_id= (int *) mono_mempool_alloc0 (cfg->mempool, sizeof (int));
	*cp_id = cfg->gdump_ctx->next_cp_id;
	g_hash_table_insert (cfg->gdump_ctx->constant_pool, entry, cp_id);
	write_byte (cfg, POOL_NEW);
	write_short (cfg, cfg->gdump_ctx->next_cp_id++);
	switch (entry->pt) {
		case PT_STRING:
			write_byte (cfg, POOL_STRING);
			write_string (cfg, (char *) entry->data);
			break;
		case PT_METHOD: {
			MonoMethod *method = (MonoMethod *) entry->data;
			write_byte (cfg, POOL_METHOD);
			write_pool (cfg, create_cp_entry (cfg, (void *) method->klass, PT_KLASS));
			write_pool (cfg, create_cp_entry (cfg, (void *) method->name, PT_STRING));
			write_pool (cfg, create_cp_entry (cfg, (void *) method->signature, PT_SIGNATURE));
			write_int (cfg, (int) method->flags);
			write_int (cfg, -1); // don't transmit bytecode.
			break;
		}
		case PT_KLASS: {
			MonoClass *klass = (MonoClass *) entry->data;
			write_byte (cfg, POOL_KLASS);
			write_string (cfg, m_class_get_name (klass));
			write_byte (cfg, KLASS);
			break;
		}
		case PT_SIGNATURE: {
			write_byte (cfg, POOL_SIGNATURE);
			MonoMethodSignature *sig = (MonoMethodSignature *) entry->data;
			write_short (cfg, sig->param_count);
			for (int i = 0; i < sig->param_count; i++) {
				GString *sbuf = g_string_new (NULL);
				mono_type_get_desc (sbuf, sig->params [i], TRUE);
				write_pool (cfg, create_cp_entry (cfg, (void *) sbuf->str, PT_STRING));
				g_string_free (sbuf, TRUE);
			}
			GString *sbuf = g_string_new (NULL);
			mono_type_get_desc (sbuf, sig->ret, TRUE);
			write_pool (cfg, create_cp_entry (cfg, (void *) sbuf->str, PT_STRING));
			g_string_free (sbuf, TRUE);
			break;
		}
		case PT_OPTYPE: {
			MonoInst *insn = (MonoInst *) entry->data;
			write_byte (cfg, POOL_NODE_CLASS);

			write_string (cfg, mono_inst_name (insn->opcode));
			GString *insndesc = mono_print_ins_index_strbuf (-1, insn);
			int len = strnlen (insndesc->str, 0x2000);
#define CUTOFF 40
			if (len > CUTOFF) {
				insndesc->str[CUTOFF] = '\0';
				insndesc->str[CUTOFF - 1] = '.';
				insndesc->str[CUTOFF - 2] = '.';
			}
			write_string (cfg, insndesc->str);
			if (len > CUTOFF)
				insndesc->str[CUTOFF] = ' ';
			g_string_free (insndesc, TRUE);

			// one predecessor
			write_short (cfg, 1);
			write_byte (cfg, 0);
			write_pool (cfg, create_cp_entry (cfg, (void *) "predecessor", PT_STRING));
			write_pool (cfg, create_cp_entry (cfg, (void *) NULL, PT_INPUTTYPE));

			// make NUM_SUCCESSOR successor edges, not everyone will be used.
#define NUM_SUCCESSOR 5
			write_short (cfg, NUM_SUCCESSOR);
			for (int i = 0; i < NUM_SUCCESSOR; i++) {
				char *str = g_strdup ("successor1");
				str[9] = '0' + i;
				write_byte (cfg, 0);
				write_pool (cfg, create_cp_entry (cfg, (void *) str, PT_STRING));
			}

			break;
		}
		case PT_INPUTTYPE: {
			write_byte (cfg, POOL_ENUM);
			write_pool (cfg, create_cp_entry (cfg, (void *) NULL, PT_ENUMKLASS));
			write_int (cfg, 0);
			break;
		}
		case PT_ENUMKLASS: {
			write_byte (cfg, POOL_KLASS);
			write_string (cfg, "InputType");
			write_byte (cfg, ENUM_KLASS);
			write_int (cfg, 1);
			write_pool (cfg, create_cp_entry (cfg, (void *) "fixed", PT_STRING));
			break;
		}
	}
}
예제 #21
0
파일: ascii1.c 프로젝트: FuzzyHobbit/mordor
int write_creature_basic(FILE *fp, int index, creature *crt)
{
	int	i;

	printf("Writing creature %s\n", crt->name );

/* begin of creature data */
	write_int(fp, index);  /* creature # */
	
	write_chars(fp, crt->name, sizeof(crt->name));
	write_chars(fp, crt->description, sizeof(crt->description));
	write_chars(fp, crt->talk, sizeof(crt->talk));
	write_chars(fp, crt->password, sizeof(crt->password));
	for (i = 0; i != 3; i++)
		write_chars(fp, crt->key[i], sizeof(crt->key[i]));
	
	write_short(fp, crt->fd);
	
	write_char(fp, crt->level);
	write_char(fp, crt->type);
	write_char(fp, crt->class);
	write_char(fp, crt->race);
	write_char(fp, crt->numwander);
	
	write_short(fp, crt->alignment);
	
	write_char(fp, crt->strength);
	write_char(fp, crt->dexterity);
	write_char(fp, crt->constitution);
	write_char(fp, crt->intelligence);
	write_char(fp, crt->piety);
	
	write_short(fp, crt->hpmax);
	write_short(fp, crt->hpcur);
	write_short(fp, crt->mpmax);
	write_short(fp, crt->mpcur);
	
	write_char(fp, crt->armor);
	write_char(fp, crt->thaco);
	
	write_long(fp, crt->experience);
	write_long(fp, crt->gold);
	
	write_short(fp, crt->ndice);
	write_short(fp, crt->sdice);
	write_short(fp, crt->pdice);

	write_short(fp, crt->special);
	
	for (i=0; i != 6; i++)
		write_long(fp, crt->proficiency[i]);
	for (i=0; i < 8; i++)
		write_long(fp, crt->realm[i]);

	write_chars(fp, crt->spells, sizeof(crt->spells));
	write_chars(fp, crt->flags, sizeof(crt->flags));
	write_chars(fp, crt->quests, sizeof(crt->quests));
	write_char(fp, crt->questnum);
	
	for (i=0; i != 10; i++)
		write_short(fp, crt->carry[i]);
	write_short(fp, crt->rom_num);
	
	for (i=0; i != 10; i++) {
		write_char(fp, crt->daily[i].max);
		write_char(fp, crt->daily[i].cur);
		write_long(fp, crt->daily[i].ltime);
	}
	
	for (i=0; i < 45; i++)
		write_lasttime(fp, crt->lasttime[i]);
	write_long(fp,crt->bank_balance);
	write_chars(fp,crt->title, sizeof(crt->title));
	for(i=0; i != 5; i++)
		write_short(fp, crt->misc_stats[i]);
	write_short(fp,crt->clanindex);
	write_long(fp,crt->clanexp);
	write_char(fp,crt->guildtype);
	write_long(fp,crt->guildexp);
	write_short(fp,crt->special1);
	write_long(fp,crt->special2);
	
/* end of creature data */

	return(0);

}
예제 #22
0
// parses the memwatch data format from a string
unsigned long long read_string_data(const char* in, void** vdata, void** vmask) {

  *vdata = NULL;
  if (vmask)
    *vmask = NULL;
  unsigned char** data = (unsigned char**)vdata;
  unsigned char** mask = (unsigned char**)vmask;

  int read, chr = 0;
  int string = 0, unicode_string = 0, comment = 0, multiline_comment = 0, high = 1;
  int filename = 0, filename_start;
  unsigned long size = 0;
  int endian = 0;
  while (in[0]) {
    read = 0;

    // if between // and a newline, don't write to output buffer
    if (comment) {
      if (in[0] == '\n')
        comment = 0;
      in++;

    // if between /* and */, don't write to output buffer
    } else if (multiline_comment) {
      if (in[0] == '*' && in[1] == '/') {
        multiline_comment = 0;
        in++;
      }
      in++;

    // if between quotes, read bytes to output buffer, unescaping
    } else if (string) {
      if (in[0] == '\"')
        string = 0;
      else if (in[0] == '\\') { // unescape char after a backslash
        if (!in[1])
          return size;
        if (in[1] == 'n') {
          write_byte('\n');
        } else if (in[1] == 'r') {
          write_byte('\r');
        } else if (in[1] == 't') {
          write_byte('\t');
        } else {
          write_byte(in[1]);
        }
        in++;
      } else
        write_byte(in[0]);
      in++;

    // if between single quotes, word-expand bytes to output buffer, unescaping
    } else if (unicode_string) {
      if (in[0] == '\'')
        unicode_string = 0;
      else if (in[0] == '\\') { // unescape char after a backslash
        if (!in[1])
          return size;
        if (in[1] == 'n') {
          write_short('\n');
        } else if (in[1] == 'r') {
          write_short('\r');
        } else if (in[1] == 't') {
          write_short('\t');
        } else {
          write_short(in[1]);
        }
        if (endian)
          bswap(&(*data)[size - 2], 2);
        in++;
      } else {
        write_short(in[0]);
        if (endian)
          bswap(&(*data)[size - 2], 2);
      }
      in++;

    // if between <>, read a file name, then stick that file into the buffer
    } else if (filename) {
      if (in[0] == '>') {
        filename = 0;
        write_byte(0); // null-terminate the filename
        // TODO: support <filename@offset:size> syntax

        // open the file, read it into the buffer, close the file
        FILE* f = fopen((char*)(*data + filename_start), "rb");
        if (!f) {
          if (data)
            free(data);
          return 0;
        }
        fseek(f, 0, SEEK_END);
        int file_size = ftell(f);
        size = filename_start + file_size;
        *data = realloc(*data, size);
        fseek(f, 0, SEEK_SET);
        fread((*data + filename_start), 1, file_size, f);
        fclose(f);
      } else
        write_byte(in[0]);
      in++;

    // ? is an unknown byte, but only if the caller wants a mask
    } else if (in[0] == '?' && vmask) {
      write_blank();
      in++;

    // $ changes the endian-ness
    } else if (in[0] == '$') {
      endian = !endian;
      in++;

    // # signifies a decimal number
    } else if (in[0] == '#') { // 8-bit
      unsigned long long value;
      in++;
      if (in[0] == '#') { // 16-bit
        in++;
        if (in[0] == '#') { // 32-bit
          in++;
          if (in[0] == '#') { // 64-bit
            in++;
            expand(8);
            parse_ull(in, (unsigned long long*)(&((*data)[size - 8])), 0);
            if (endian)
              bswap(&((*data)[size - 8]), 8);
            if (mask)
              *(unsigned long long*)(&((*mask)[size - 8])) = 0xFFFFFFFFFFFFFFFF;
          } else {
            expand(4);
            parse_ull(in, &value, 0);
            if (endian)
              bswap(&value, 4);
            *(int32_t*)(&((*data)[size - 4])) = value;
            if (mask)
              *(uint32_t*)(&((*mask)[size - 4])) = 0xFFFFFFFF;
          }
        } else {
          expand(2);
          parse_ull(in, &value, 0);
          if (endian)
            bswap(&value, 2);
          *(int16_t*)(&((*data)[size - 2])) = value;
          if (mask)
            *(uint16_t*)(&((*mask)[size - 2])) = 0xFFFF;
        }
      } else {
        expand(1);
        parse_ull(in, &value, 0);
        *(int8_t*)(&((*data)[size - 1])) = value;
        if (mask)
          *(uint8_t*)(&((*mask)[size - 1])) = 0xFF;
      }
      if (in[0] == '-')
        in++;
      while (isdigit(in[0]))
        in++;

    // % is a float, %% is a double
    } else if (in[0] == '%') {
      in++;
      if (in[0] == '%') {
        in++;
        expand(8);
        double* value = (double*)(&((*data)[size - 8]));
        sscanf(in, "%lf", value);
        if (endian)
          bswap(value, 8);
        if (mask)
          *(unsigned long long*)(&((*mask)[size - 8])) = 0xFFFFFFFFFFFFFFFF;
      } else {
        expand(4);
        float* value = (float*)(&((*data)[size - 4]));
        sscanf(in, "%f", value);
        if (endian)
          bswap(value, 4);
        if (mask)
          *(uint32_t*)(&((*mask)[size - 4])) = 0xFFFFFFFF;
      }
      if (in[0] == '-')
        in++;
      while (isdigit(in[0]) || (in[0] == '.'))
        in++;

    // anything else is a hex digit
    } else {
      if ((in[0] >= '0') && (in[0] <= '9')) {
        read = 1;
        chr |= (in[0] - '0');
      }
      if ((in[0] >= 'A') && (in[0] <= 'F')) {
        read = 1;
        chr |= (in[0] - 'A' + 0x0A);
      }
      if ((in[0] >= 'a') && (in[0] <= 'f')) {
        read = 1;
        chr |= (in[0] - 'a' + 0x0A);
      }
      if (in[0] == '\"')
        string = 1;
      if (in[0] == '\'')
        unicode_string = 1;
      if (in[0] == '/' && in[1] == '/')
        comment = 1;
      if (in[0] == '/' && in[1] == '*')
        multiline_comment = 1;
      if (in[0] == '<') {
        filename = 1;
        filename_start = size;
      }
      in++;
    }

    if (read) {
      if (high)
        chr = chr << 4;
      else {
        write_byte(chr);
        chr = 0;
      }
      high = !high;
    }
  }
  return size;
}
예제 #23
0
파일: ascii1.c 프로젝트: FuzzyHobbit/mordor
void write_lasttime(FILE *fp, struct lasttime lt)
{
	write_long(fp, lt.interval);
	write_long(fp, lt.ltime);
	write_short(fp, lt.misc);
}
예제 #24
0
	OutPacket::OutPacket(int16_t opcode)
	{
		write_short(opcode);
	}
예제 #25
0
	void OutPacket::write_point(Point<int16_t> position)
	{
		write_short(position.x());
		write_short(position.y());
	}
예제 #26
0
파일: tiff.c 프로젝트: nejmd/JPEG
/* Initialisation du fichier TIFF résultat, avec les paramètres suivants:
   - width: la largeur de l'image ;
   - height: la hauteur de l'image ;
   - row_per_strip: le nombre de lignes de pixels par bande.
 */
struct tiff_file_desc *init_tiff_file (const char *file_name,
                                       uint32_t width,
                                       uint32_t height,
                                       uint32_t row_per_strip)
{
        FILE *file = NULL;
        struct tiff_file_desc *tfd = calloc(1, sizeof(struct tiff_file_desc));
        uint32_t line_size;

        if (tfd == NULL)
                return NULL;


        /* Allocate & check write_buf */
        tfd->row_size = width * 3;

        tfd->write_buf = malloc(tfd->row_size);
        if (tfd->write_buf == NULL)
                return NULL;


        /* Allocate & check strip_offsets */
        tfd->nb_strips = height / row_per_strip;

        if (height % row_per_strip)
                tfd->nb_strips++;

        tfd->strip_offsets = malloc(tfd->nb_strips * sizeof(uint32_t));
        if (tfd->strip_offsets == NULL)
                return NULL;


        /* Allocate & check strip_bytes */
        tfd->strip_bytes = malloc(tfd->nb_strips * sizeof(uint32_t));
        if (tfd->strip_bytes == NULL)
                return NULL;


        file = fopen(file_name, "wb");
        if (file == NULL)
                return NULL;

        tfd->file = file;

        tfd->is_le = true;
        tfd->width = width;
        tfd->height = height;
        tfd->rows_per_strip = row_per_strip;


        /* Software comment definition */
        const char *comment = COMMENT;
        const uint32_t comment_size = strlen(comment) + 1;


        /* Header construction */
        const uint32_t ifd_offset = 8 + comment_size;
        const uint16_t entry_count = 13;

        /* Endianness + TIFF identification */
        write_short(tfd, LITTLE_ENDIAN);
        write_short(tfd, 42);

        /* IFD offset */
        write_long(tfd, ifd_offset);

        /* Software comment */
        fwrite(comment, 1, comment_size, file);


        uint32_t next = ifd_offset + 2 + 12 * entry_count + 4;

        /* IFD data */
        write_short(tfd, entry_count);

        /* Image Width */
        write_short(tfd, IMAGE_WIDTH);
        write_short(tfd, LONG);
        write_long(tfd, 1);
        write_long(tfd, tfd->width);

        /* Image Length */
        write_short(tfd, IMAGE_LENGTH);
        write_short(tfd, LONG);
        write_long(tfd, 1);
        write_long(tfd, tfd->height);


        /* BitsPerSample */
        write_short(tfd, BITS_PER_SAMPLE);
        write_short(tfd, SHORT);
        write_long(tfd, 3);
        write_long(tfd, next);
        next += 3 * 2;

        /* Compression */
        write_short(tfd, COMPRESSION);
        write_short(tfd, SHORT);
        write_long(tfd, 1);
        write_long(tfd, 1);

        /* PhotometricInterpretation */
        write_short(tfd, PHOTOMETRIC);
        write_short(tfd, SHORT);
        write_long(tfd, 1);
        write_long(tfd, 2);

        /* StripOffsets */
        write_short(tfd, STRIP_OFFSETS);
        write_short(tfd, LONG);
        write_long(tfd, tfd->nb_strips);

        const uint32_t strips_pos = next + 16;
        uint32_t line_offset = strips_pos;


        /* One row handling */
        if (tfd->nb_strips > 1) {
                line_offset += 8 * tfd->nb_strips;
                write_long(tfd, strips_pos);
        }

        else {
                write_long(tfd, line_offset);
                tfd->strip_offsets[0] = line_offset;
        }


        /* SamplesPerPixel */
        write_short(tfd, SAMPLES_PER_PIXEL);
        write_short(tfd, SHORT);
        write_long(tfd, 1);
        write_long(tfd, 3);

        /* RowsPerStrip */
        write_short(tfd, ROWS_PER_STRIP);
        write_short(tfd, LONG);
        write_long(tfd, 1);
        write_long(tfd, tfd->rows_per_strip);

        /* StripByteCounts */
        write_short(tfd, STRIP_BYTE_COUNTS);
        write_short(tfd, LONG);
        write_long(tfd, tfd->nb_strips);


        /* Last line's height */
        uint32_t line_height = tfd->height % tfd->rows_per_strip;

        if (tfd->height > 0  && line_height == 0)
                line_height = tfd->rows_per_strip;


        /* One row handling */
        if (tfd->nb_strips > 1) {
                line_size = tfd->rows_per_strip * tfd->width * 3;
                write_long(tfd, strips_pos + 4 * tfd->nb_strips);
        }

        else {
                line_size = line_height * tfd->width * 3;
                write_long(tfd, line_size);

                tfd->strip_bytes[0] = line_size;
        }


        /* XResolution */
        write_short(tfd, X_RESOLUTION);
        write_short(tfd, RATIONAL);
        write_long(tfd, 1);
        write_long(tfd, next);
        next += 2 * 4;

        /* YResolution */
        write_short(tfd, Y_RESOLUTION);
        write_short(tfd, RATIONAL);
        write_long(tfd, 1);
        write_long(tfd, next);
        next += 2 * 4;

        /* ResolutionUnit */
        write_short(tfd, RESOLUTION_UNIT);
        write_short(tfd, SHORT);
        write_long(tfd, 1);
        write_long(tfd, 2);

        /* Software */
        write_short(tfd, SOFTWARE);
        write_short(tfd, ASCII);
        write_long(tfd, comment_size);
        write_long(tfd, 8);


        /* No other IFD */
        write_long(tfd, 0);


        /* BitsPerSample data */
        write_short(tfd, 8);
        write_short(tfd, 8);
        write_short(tfd, 8);

        /* XResolution data */
        write_long(tfd, 100);
        write_long(tfd, 1);

        /* YResolution data */
        write_long(tfd, 100);
        write_long(tfd, 1);


        /* Initialize internal writing data */
        tfd->current_line = 0;
        tfd->line_size = line_size;

        /* Initialize the first MCU position */
        tfd->next_pos_mcu = 0;

        /* If there are multiple strips */
        if (tfd->nb_strips > 1) {

                /* Write all StripOffsets */
                for (uint32_t i = 0; i < tfd->nb_strips; i++){
                        write_long(tfd, line_offset);
                        tfd->strip_offsets[i] = line_offset;

                        line_offset += line_size;
                }


                /* StripByteCounts data */
                for (uint32_t i = 0; i < tfd->nb_strips - 1; i++) {
                        write_long(tfd, line_size);
                        tfd->strip_bytes[i] = line_size;
                }

                /* Last line's size */
                line_size = line_height * tfd->width*3;
                tfd->strip_bytes[tfd->nb_strips-1] = line_size;

                write_long(tfd, line_size);
        }


        return tfd;
}
예제 #27
0
/*{{{  DO_MSG*/
static void
DO_MSG(
    struct share_msg msg, /* message to send */
    char *data            /* pointer to data */
    )
{
  switch (msg.type & TYPE_MASK) {
  /*{{{  T_SCREEN*/
  case T_SCREEN:
    write_short(&(msg.type), 1);
    write_short(&(msg.stuff[0]), 4);
    if (msg.stuff[3] != 0)
      write_char(data, bit_size(msg.stuff[1], msg.stuff[2], 1));
    break;
  /*}}}  */
  /*{{{  T_BLIT*/
  case T_BLIT:
    write_short(&(msg.type), 1);
    write_short(&(msg.stuff[0]), 8);
    break;
  /*}}}  */
  /*{{{  T_WRITE*/
  case T_WRITE:
    write_short(&(msg.type), 1);
    write_short(&(msg.stuff[0]), 5);
    break;
  /*}}}  */
  /*{{{  T_LINE*/
  case T_LINE:
    write_short(&(msg.type), 1);
    write_short(&(msg.stuff[0]), 5);
    break;
  /*}}}  */
  /*{{{  T_DATA*/
  case T_DATA:
    write_short(&(msg.type), 1);
    write_short(&(msg.stuff[0]), 4);
    if (msg.stuff[3] != 0)
      write_char(data, bit_size(msg.stuff[1], msg.stuff[2], 1));
    break;
  /*}}}  */
  /*{{{  T_NOP*/
  case T_NOP:
    write_short(&(msg.type), 1);
    if ((msg.type & 0xF) > 0)
      write_char(data, msg.type & 0xF);
  /*}}}  */
  /*{{{  T_POINT*/
  case T_POINT:
    write_short(&(msg.type), 1);
    write_short(&(msg.stuff[0]), 3);
    break;
  /*}}}  */
  /*{{{  T_TIME*/
  case T_TIME:
    write_short(&(msg.type), 1);
    write_short(&(msg.stuff[0]), 2);
    break;
  /*}}}  */
  /*{{{  T_KILL*/
  case T_KILL:
    write_short(&(msg.type), 1);
    write_short(&(msg.stuff[0]), 1);
    break;
  /*}}}  */
  /*{{{  T_BYTESCROLL*/
  case T_BYTESCROLL:
    write_short(&(msg.type), 1);
    write_short(&(msg.stuff[0]), 6);
    break;
    /*}}}  */
  }
}