Example #1
0
int32_t ZAP_GetInfo(xadArchiveInfo *ai)
{
  uint8_t buffer[4], *textin = NULL;
  struct xadTextInfo *ti;
  int32_t err = XADERR_OK;
  uint32_t tfsize;


  /* read and skip header ID text */
  READLONG(tfsize); 
  SKIP(tfsize);

  /* read attached textfile (if it exists) */
  READLONG(tfsize);
  xdi->xdi_DataPos = ai->xai_InPos + tfsize;

  if (tfsize) {
    ti = new xadTextInfo();
    xdi->xdi_TextInfo = ti;

	textin = malloc(tfsize);
    READ(textin, tfsize);
    ti->xti_Size = EndGetM32(textin+tfsize-4);
    ti->xti_Text = malloc(ti->xti_Size+1);
    if ((err = ZAP_decrunch(textin, ti->xti_Text, tfsize))) 
		// -> throw
		goto exit_handler;
    ti->xti_Text[ti->xti_Size] = '\0';
  }
  else {
    xdi->xdi_TextInfo = NULL;
  }
    
exit_handler:
  if (textin) FREE(textin);

  if (err) {
    if (!xdi) return err;
    ai->xai_Flags |= XADAIF_FILECORRUPT;
    ai->xai_LastError = err;
  }
  return XADERR_OK;
}
Example #2
0
/* read and load font, return incore font structure*/
static PMWCFONT
fnt_load_font(const char *path)
{
	FILEP ifp;
	PMWCFONT pf = NULL;
	int i;
	unsigned short maxwidth, height, ascent, pad;
	unsigned long firstchar, defaultchar, size;
	unsigned long nbits, noffset, nwidth;
	char version[4+1];
	char name[64+1];
	char copyright[256+1];
	char fname[256];

	ifp = FOPEN(path, "rb");

	if (!ifp) {
		strcpy(fname, FNT_FONT_DIR "/");
		strcpy(fname + sizeof(FNT_FONT_DIR), path);
		ifp = FOPEN(fname, "rb");
		
		/* Try to grab it from the MWFONTDIR directory */
		if (!ifp) {
			char *env = getenv("MWFONTDIR");
			if (env) {
				sprintf(fname, "%s/%s", env, path);
				
				printf("Trying to get font from %s\n", fname);
				ifp = FOPEN(fname, "rb");
			}
		}
		
	}
	if (!ifp)
		return NULL;

	/* read magic and version #*/
	memset(version, 0, sizeof(version));
	if (READSTR(ifp, version, 4) != 4)
		goto errout;
	if (strcmp(version, VERSION) != 0)
		goto errout;

	pf = (PMWCFONT)calloc(1, sizeof(MWCFONT));
	if (!pf)
		goto errout;

	/* internal font name*/
	if (READSTRPAD(ifp, name, 64) != 64)
		goto errout;
	pf->name = (char *)malloc(strlen(name)+1);
	if (!pf->name)
		goto errout;
	strcpy(pf->name, name);

	/* copyright, not currently stored*/
	if (READSTRPAD(ifp, copyright, 256) != 256)
		goto errout;

	/* font info*/
	if (!READSHORT(ifp, &maxwidth))
		goto errout;
	pf->maxwidth = maxwidth;
	if (!READSHORT(ifp, &height))
		goto errout;
	pf->height = height;
	if (!READSHORT(ifp, &ascent))
		goto errout;
	pf->ascent = ascent;
	if (!READSHORT(ifp, &pad))
		goto errout;
	if (!READLONG(ifp, &firstchar))
		goto errout;
	pf->firstchar = firstchar;
	if (!READLONG(ifp, &defaultchar))
		goto errout;
	pf->defaultchar = defaultchar;
	if (!READLONG(ifp, &size))
		goto errout;
	pf->size = size;

	/* variable font data sizes*/
	/* # words of MWIMAGEBITS*/
	if (!READLONG(ifp, &nbits))
		goto errout;
	pf->bits = (MWIMAGEBITS *)malloc(nbits * sizeof(MWIMAGEBITS));
	if (!pf->bits)
		goto errout;
	pf->bits_size = nbits;

	/* # longs of offset*/
	if (!READLONG(ifp, &noffset))
		goto errout;
	if (noffset) {
		pf->offset = (unsigned long *)malloc(noffset * sizeof(unsigned long));
		if (!pf->offset)
			goto errout;
	}

	/* # bytes of width*/
	if (!READLONG(ifp, &nwidth))
		goto errout;
	if (nwidth) {
		pf->width = (unsigned char *)malloc(nwidth * sizeof(unsigned char));
		if (!pf->width)
			goto errout;
	}

	/* variable font data*/
	for (i=0; i<nbits; ++i)
		if (!READSHORT(ifp, &pf->bits[i]))
			goto errout;
	/* pad to longword boundary*/
	if (ftell(ifp) & 02)
		if (!READSHORT(ifp, &pf->bits[i]))
			goto errout;
	if (noffset)
		for (i=0; i<pf->size; ++i)
			if (!READLONG(ifp, &pf->offset[i]))
				goto errout;
	if (nwidth)
		for (i=0; i<pf->size; ++i)
			if (!READBYTE(ifp, &pf->width[i]))
				goto errout;
	
	FCLOSE(ifp);
	return pf;	/* success!*/

errout:
	FCLOSE(ifp);
	if (!pf)
		return NULL;
	if (pf->name)
		free(pf->name);
	if (pf->bits)
		free(pf->bits);
	if (pf->offset)
		free(pf->offset);
	if (pf->width)
		free(pf->width);
	free(pf);
	return NULL;
}