Exemplo n.º 1
0
void
wvAddCHPXFromBucket6(CHP *achp, UPXF *upxf, STSH *stsh) {
    U8  *pointer;
    U16 i = 0;
    U8  sprm8;
    U16 sprm;

    wvTrace(("cbUPX word 6 is %d\n", upxf->cbUPX));

#ifdef SPRMTEST
    GET_fprintf_HANDLER() (stderr, "\n");
    while (i < upxf->cbUPX) {
        GET_fprintf_HANDLER() (stderr, "%x (%d) ", *(upxf->upx.chpx.grpprl + i),
                               *(upxf->upx.chpx.grpprl + i));
        i++;
    }
    GET_fprintf_HANDLER() (stderr, "\n");
    i = 0;
#endif
    while (i < upxf->cbUPX) {
        sprm8 = bread_8ubit(upxf->upx.chpx.grpprl + i, &i);
#ifdef SPRMTEST
        wvError(("chp word 6 sprm is %x (%d)\n", sprm8, sprm8));
#endif
        sprm = (U16)wvGetrgsprmWord6(sprm8);
#ifdef SPRMTEST
        wvError(("chp word 6 sprm is converted to %x\n", sprm));
#endif

        pointer = upxf->upx.chpx.grpprl + i;
        wvApplySprmFromBucket(WORD6, sprm, NULL, achp, NULL, stsh, pointer,
                              &i, NULL);
    }
}
Exemplo n.º 2
0
int
wvGetFRD_PLCF(FRD **frd, U32 **pos, int *nofrd, U32 offset, U32 len,
              wvStream *fd) {
    int i;

    if (len == 0) {
        *frd   = NULL;
        *pos   = NULL;
        *nofrd = 0;
    } else {
        *nofrd = (len - 4) / 6;
        *pos   = (U32 *)wvMalloc((*nofrd + 1) * sizeof(U32));
        if (*pos == NULL) {
            wvError(
                ("NO MEM 1, failed to alloc %d bytes\n",
                 (*nofrd + 1) * sizeof(U32)));
            return 1;
        }

        *frd = (FRD *)wvMalloc(*nofrd * sizeof(FRD));
        if (*frd == NULL) {
            wvError(
                ("NO MEM 1, failed to alloc %d bytes\n",
                 *nofrd * sizeof(FRD)));
            wvFree(pos);
            return 1;
        }
        wvStream_goto(fd, offset);
        for (i = 0; i < *nofrd + 1; i++)
            (*pos)[i] = read_32ubit(fd);
        for (i = 0; i < *nofrd; i++)
            wvGetFRD(&((*frd)[i]), fd);
    }
    return 0;
}
Exemplo n.º 3
0
Arquivo: fib.c Projeto: AbiWord/wv
wvStream *
wvWhichTableStream (FIB * fib, wvParseStruct * ps)
{
    wvStream *ret;

    if ((wvQuerySupported (fib, NULL) & 0x7fff) == WORD8)
      {
	  if (fib->fWhichTblStm)
	    {
		wvTrace (("1Table\n"));
		ret = ps->tablefd1;
		if (ret == NULL)
		  {
		      wvError (
			       ("!!, the FIB lied to us, (told us to use the 1Table) making a heroic effort to use the other table stream, hold on tight\n"));
		      ret = ps->tablefd0;
		  }
	    }
	  else
	    {
		wvTrace (("0Table\n"));
		ret = ps->tablefd0;
		if (ret == NULL)
		  {
		      wvError (
			       ("!!, the FIB lied to us, (told us to use the 0Table) making a heroic effort to use the other table stream, hold on tight\n"));
		      ret = ps->tablefd1;
		  }
	    }
      }
    else			/* word 7- */
	ret = ps->mainfd;
    return (ret);
}
Exemplo n.º 4
0
void
wvGetXst(Xst **xst, U32 offset, U32 len, wvStream *fd) {
    U16 clen, i;
    U32 count = 0;
    Xst *authorlist;
    Xst *current = NULL;

    if ((len == 0) || (xst == NULL)) {
        *xst = NULL;
        return;
    }

    wvStream_goto(fd, offset);
    *xst       = (Xst *)wvMalloc(sizeof(Xst));
    authorlist = *xst;

    if (authorlist == NULL) {
        wvError(("not enough mem for annotation group\n"));
        return;
    }

    authorlist->next        = NULL;
    authorlist->u16string   = NULL;
    authorlist->noofstrings = 0;
    current = authorlist;

    while (count < len) {
        clen   = read_16ubit(fd);
        count += 2;
        current->u16string = (U16 *)wvMalloc((clen + 1) * sizeof(U16));
        authorlist->noofstrings++;
        if (current->u16string == NULL) {
            wvError(
                ("not enough mem for author string of clen %d\n",
                 clen));
            break;
        }
        for (i = 0; i < clen; i++) {
            current->u16string[i] = read_16ubit(fd);
            count += 2;
        }
        current->u16string[i] = '\0';

        if (count < len) {
            current->next = (Xst *)wvMalloc(sizeof(Xst));
            if (current->next == NULL) {
                wvError(("not enough mem for annotation group\n"));
                break;
            }
            current            = current->next;
            current->next      = NULL;
            current->u16string = NULL;
        }
    }
}
Exemplo n.º 5
0
Arquivo: bte.c Projeto: AbiWord/wv
int
wvGetBTE_PLCF6 (BTE ** bte, U32 ** pos, U32 * nobte, U32 offset, U32 len,
		wvStream * fd)
{
    U32 i;
    if (len == 0)
      {
	  *bte = NULL;
	  *pos = NULL;
	  *nobte = 0;
      }
    else
      {
	  wvTrace (("offset is %x, len is %d\n", offset, len));
	  *nobte = (len - 4) / (cb6BTE + 4);
	  wvTrace (("no of bte is %d at %x\n", *nobte, offset));
	  *pos = (U32 *) wvMalloc ((*nobte + 1) * sizeof (U32));
	  if (*pos == NULL)
	    {
		wvError (
			 ("NO MEM 1, failed to alloc %d bytes\n",
			  (*nobte + 1) * sizeof (U32)));
		return (1);
	    }

	  *bte = (BTE *) wvMalloc (*nobte * sizeof (BTE));
	  if (*bte == NULL)
	    {
		wvError (
			 ("NO MEM 1, failed to alloc %d bytes\n",
			  *nobte * sizeof (BTE)));
		wvFree (pos);
		return (1);
	    }
	  wvStream_goto (fd, offset);
	  for (i = 0; i <= *nobte; i++)
	    {
		(*pos)[i] = read_32ubit (fd);
		wvTrace (("pos is %x\n", (*pos)[i]));
	    }
	  for (i = 0; i < *nobte; i++)
	    {
		wvInitBTE (&((*bte)[i]));
		(*bte)[i].pn = read_16ubit (fd);
	    }
      }
    return (0);
}
Exemplo n.º 6
0
Arquivo: plcf.c Projeto: AbiWord/wv
/*
   this function retrieves a generic PLCF; this is useful since it
   means we do not have to add specific functions for retrieving
   various simple PLCFs (for instance the PLCFs that store information
   about footnotes, endnotes and annotations are just simple arrays of
   U32s)

   plcf - a pointer to a pointer where we should allocate the structure
          the caller needs to free these using wvFree() once not needed
          
   offset - an offset in the stream fd where the PLCF starts
   len - a length in bytes (!!!) of the PLCF
   fd - the stream from which to read the PLCF
*/
int
wvGetPLCF (void ** plcf, U32 offset, U32 len, wvStream * fd)
{
    U32 i, i32, i8;
	
    if (len == 0)
	{
		*plcf = NULL;
	}
    else
	{
		*plcf = wvMalloc (len);
		if (*plcf == NULL)
	    {
			wvError (("NO MEM 1, failed to alloc %d bytes\n",len));
			return (1);
	    }
		
		wvStream_goto (fd, offset);
		
		i32 = len / 4;
		i8  = len % 4;
		
		for (i = 0; i < i32; i++)
			((U32*)(*plcf))[i] = read_32ubit (fd);

		for (i = i32*4; i < i32*4 + i8; i++)
			((U8*)(*plcf))[i] = read_8ubit (fd);
	}
    return (0);
}
Exemplo n.º 7
0
void
wvPutSTSH (STSH * item, U16 cbStshi, wvStream * fd)
{
    U16 i;

    write_16ubit (fd, cbStshi);
    wvPutSTSHI (&(item->Stshi), cbStshi, fd);

    if (item->Stshi.cstd == 0)
	return;

    if (item->std == NULL)
      {
	  wvError (("What the @#*@#*: item->std is null"));
	  return;
      }

    for (i = 0; i < item->Stshi.cstd; i++)
      {
	  write_16ubit (fd, i);	/* TODO: is this right?? i+1?? */
/* TODO *//* wvPutSTD(&(item->std[i]), fd); */
      }

    /* TODO: there must be a setting of styles */
    /* TODO: this probably is not finished */
}
Exemplo n.º 8
0
void
wvGetEscher(escherstruct *item, U32 offset, U32 len, wvStream *fd,
            wvStream *delay) {
    U32    count = 0;
    MSOFBH amsofbh;

    wvStream_goto(fd, offset);
    wvTrace(("offset %x, len %d\n", offset, len));
    wvInitEscher(item);
    while (count < len) {
        count += wvGetMSOFBH(&amsofbh, fd);
        wvTrace(
            ("count is %x,len is %x, next len is %x\n", count, len,
             amsofbh.cbLength));
        wvTrace(("type is %x\n	", amsofbh.fbt));
        switch (amsofbh.fbt) {
            case msofbtDggContainer:
                count +=
                    wvGetDggContainer(&item->dggcontainer, &amsofbh, fd,
                                      delay);
                break;

            case msofbtDgContainer:
                count += wvGetDgContainer(&item->dgcontainer, &amsofbh, fd);
                break;

            default:
                wvError(("Not a container, panic (%x)\n", amsofbh.fbt));
                return;
                break;
        }
    }
    wvTrace(("offset %x, len %d (pos %x)\n", offset, len, wvStream_tell(fd)));
}
Exemplo n.º 9
0
U32
wvGetBstoreContainer(BstoreContainer *item, MSOFBH *msofbh, wvStream *fd,
                     wvStream *delay) {
    MSOFBH amsofbh;
    U32    count = 0;

    while (count < msofbh->cbLength) {
        count += wvGetMSOFBH(&amsofbh, fd);
        wvTrace(("type is %x\n	", amsofbh.fbt));
        switch (amsofbh.fbt) {
            case msofbtBSE:
                wvTrace(("Blip at %x\n", wvStream_tell(fd)));
                item->no_fbse++;
                item->blip =
                    (Blip *)realloc(item->blip,
                                    sizeof(Blip) * item->no_fbse);
                count +=
                    wvGetBlip((&item->blip[item->no_fbse - 1]), fd, delay);
                wvTrace(
                    ("type is %d (number is %d\n",
                     item->blip[item->no_fbse - 1].type, item->no_fbse));
                break;

            default:
                count += wvEatmsofbt(&amsofbh, fd);
                wvError(("Eating type 0x%x\n", amsofbh.fbt));
                break;
        }
    }
    return count;
}
Exemplo n.º 10
0
Arquivo: generic.c Projeto: AbiWord/wv
int
wvGetEmpty_PLCF (U32 ** cps, U32 * nocps, U32 offset, U32 len, wvStream * fd)
{
    U32 i;
    if (len == 0)
      {
	  *cps = NULL;
	  *nocps = 0;
      }
    else
      {
	  *nocps = len / 4;
	  *cps = (U32 *) malloc (*nocps * sizeof (U32));
	  if (*cps == NULL)
	    {
		wvError (
			 ("NO MEM 3, failed to alloc %d bytes\n",
			  *nocps * sizeof (U32)));
		return (1);
	    }
	  wvStream_goto (fd, offset);
	  for (i = 0; i < *nocps; i++)
	      (*cps)[i] = read_32ubit (fd);
      }
    return (0);
}
Exemplo n.º 11
0
/*
 * To apply a UPX.chpx to a UPE.chp, apply the UPX.chpx.grpprl to
 * UPE.chp. Note that a UPE.chp for a paragraph style should always have
 * UPE.chp.istd == istdNormalChar.
 */
void
wvAddCHPXFromBucket(CHP *achp, UPXF *upxf, STSH *stsh) {
    U8  *pointer;
    U16 i = 0;
    U16 sprm;

#ifdef SPRMTEST
    GET_fprintf_HANDLER() (stderr, "\n");
    while (i < upxf->cbUPX) {
        GET_fprintf_HANDLER() (stderr, "%x (%d) ", *(upxf->upx.chpx.grpprl + i),
                               *(upxf->upx.chpx.grpprl + i));
        i++;
    }
    GET_fprintf_HANDLER() (stderr, "\n");
    i = 0;
#endif
    while (i + 2 < upxf->cbUPX) { /* is this check sufficient ?? */
        sprm = bread_16ubit(upxf->upx.chpx.grpprl + i, &i);
#ifdef SPRMTEST
        wvError(("sprm is %x, i is %d\n", sprm, i));
#endif
        pointer = upxf->upx.chpx.grpprl + i;
        wvApplySprmFromBucket(WORD8, sprm, NULL, achp, NULL, stsh, pointer,
                              &i, NULL);
    }
}
Exemplo n.º 12
0
Arquivo: generic.c Projeto: AbiWord/wv
/**
 * Very simple malloc wrapper
 */
void *
wvMalloc (U32 size)
{
    void *p = NULL;
    int ntries = 0;

    if (size == 0)
	return NULL;

    /* loop trying to obtain memory */
    do
      {
	  p = (void *) g_try_malloc (size);
	  if (p)
	      break;
	  ntries++;
      }
    while (ntries < SOME_ARBITRARY_LIMIT);

    if (!p)
      {
	  wvError (("Could not allocate %d bytes\n", size));
	  exit (-1);
      }

    /* zero out the memory */
    memset ( p, 0, size ) ;

    return p;
}
Exemplo n.º 13
0
Arquivo: bte.c Projeto: AbiWord/wv
void
wvListBTE_PLCF (BTE ** bte, U32 ** pos, U32 * nobte)
{
    U32 i = 0;
    for (i = 0; i < *nobte; i++)
	wvError (
		 ("range %x %x is pn %d\n", (*pos)[i], (*pos)[i + 1],
		  (*bte)[i].pn));
}
Exemplo n.º 14
0
Arquivo: bkd.c Projeto: AbiWord/wv
int
wvGetBKD_PLCF (BKD ** bkd, U32 ** pos, U32 * nobkd, U32 offset, U32 len,
	       wvStream * fd)
{
    U32 i;
    if (len == 0)
      {
	  *bkd = NULL;
	  *pos = NULL;
	  *nobkd = 0;
      }
    else
      {
	  *nobkd = (len - 4) / (cbBKD + 4);
	  *pos = (U32 *) wvMalloc ((*nobkd + 1) * sizeof (U32));
	  if (*pos == NULL)
	    {
		wvError (
			 ("NO MEM 1, failed to alloc %d bytes\n",
			  (*nobkd + 1) * sizeof (U32)));
		return (1);
	    }

	  *bkd = (BKD *) wvMalloc (*nobkd * sizeof (BKD));
	  if (*bkd == NULL)
	    {
		wvError (
			 ("NO MEM 1, failed to alloc %d bytes\n",
			  *nobkd * sizeof (BKD)));
		wvFree (pos);
		return (1);
	    }
	  wvStream_goto (fd, offset);
	  for (i = 0; i < *nobkd + 1; i++)
	    {
		(*pos)[i] = read_32ubit (fd);
	    }
	  for (i = 0; i < *nobkd; i++)
	    {
		wvGetBKD (&((*bkd)[i]), fd);
	    }
      }
    return (0);
}
Exemplo n.º 15
0
int
wv0x01(Blip *blip, wvStream *fd, U32 len) {
    MSOFBH       amsofbh;
    FSPContainer item;
    U32          count = 0;
/*    char test[3];*/
    int ret = 0;


    if (fd == NULL)
        return 0;

    /*[email protected] fix hack as outdated look picf*/

    /*
       temp hack to test older included bmps in word 6 and 7,
       should be wrapped in a modern escher strucure before getting
       to here, and then handled as normal
     */

    /*test[2] = '\0';
       test[0] = read_8ubit (fd);
       test[1] = read_8ubit (fd);
       wvStream_rewind (fd);
       if (!(strcmp (test, "BM")))
       {
          blip->blip.bitmap.m_pvBits = fd;
          blip->type = msoblipDIB;
          return (1);
       }
     */
    while (count < len) {
        wvTrace(("count is %x,len is %x\n", count, len));
        count += wvGetMSOFBH(&amsofbh, fd);
        wvTrace(("type is %x\n	", amsofbh.fbt));
        switch (amsofbh.fbt) {
            case msofbtSpContainer:
                wvTrace(("Container at %x\n", wvStream_tell(fd)));
                count += wvGetFSPContainer(&item, &amsofbh, fd);
                wvReleaseFSPContainer(&item);
                break;

            case msofbtBSE:
                wvTrace(("Blip at %x\n", wvStream_tell(fd)));
                count += wvGetBlip(blip, fd, NULL);
                ret    = 1;
                break;

            default:
                wvError(("Not a shape container\n"));
                return 0;
                break;
        }
    }
    return ret;
}
Exemplo n.º 16
0
int
wv0x08(Blip *blip, S32 spid, wvParseStruct *ps) {
    int          ret = 0;
    U32          i;
    escherstruct item;
    FSPContainer *answer = NULL;

    wvTrace(("spid is %x\n", spid));
    wvGetEscher(&item, ps->fib.fcDggInfo, ps->fib.lcbDggInfo, ps->tablefd,
                ps->mainfd);

    for (i = 0; i < item.dgcontainer.no_spgrcontainer; i++) {
        answer = wvFindSPID(&(item.dgcontainer.spgrcontainer[i]), spid);
        if (answer)
            break;
    }

    i = 0;
    if (answer == NULL)
        wvError(("Damn found nothing\n"));
    else if (answer->fopte) {
        while (answer->fopte[i].pid != 0) {
            if (answer->fopte[i].pid == 260) {
                wvTrace(
                    ("has a blip reference of %d\n",
                     answer->fopte[i].op));
                wvTrace(
                    ("no blips is %d\n",
                     item.dggcontainer.bstorecontainer.no_fbse));
                wvTrace(
                    ("type is %d (number is %d\n",
                     item.dggcontainer.bstorecontainer.blip[item.
                                                               dggcontainer.
                                                               bstorecontainer.
                                                               no_fbse -
                                                            1].type,
                     item.dggcontainer.bstorecontainer.no_fbse));
                if (answer->fopte[i].op <=
                    item.dggcontainer.bstorecontainer.no_fbse) {
                    wvTrace(("Copied Blip\n"));
                    wvCopyBlip(blip,
                               &(item.dggcontainer.bstorecontainer.
                                    blip[answer->fopte[i].op - 1]));
                    wvTrace(("type is %d\n", blip->type));
                    ret = 1;
                    break;
                }
            }
            i++;
        }
    }
    wvTrace(("spid is %x\n", spid));
    wvReleaseEscher(&item);
    return ret;
}
Exemplo n.º 17
0
U32
wvGetDgContainer(DgContainer *item, MSOFBH *msofbh, wvStream *fd) {
    MSOFBH amsofbh;
    U32    count = 0;

    item->spcontainer    = NULL;
    item->no_spcontainer = 0;

    while (count < msofbh->cbLength) {
        count += wvGetMSOFBH(&amsofbh, fd);
        wvTrace(
            ("len is %x, type is %x, count %x,fullen %x\n",
             amsofbh.cbLength, amsofbh.fbt, count, msofbh->cbLength));
        wvTrace(("type is %x\n	", amsofbh.fbt));
        switch (amsofbh.fbt) {
            case msofbtDg:
                count += wvGetFDG(&item->fdg, fd);
                break;

            case msofbtSpgrContainer:
                item->no_spgrcontainer++;
                item->spgrcontainer =
                    (SpgrContainer *)realloc(item->spgrcontainer,
                                             sizeof(SpgrContainer) *
                                             item->no_spgrcontainer);
                count +=
                    wvGetSpgrContainer(&
                                       (item->spgrcontainer
                                        [item->no_spgrcontainer - 1]), &amsofbh, fd);
                break;

            case msofbtSpContainer:
                item->no_spcontainer++;
                item->spcontainer =
                    (FSPContainer *)realloc(item->spcontainer,
                                            sizeof(FSPContainer) *
                                            item->no_spcontainer);
                count +=
                    wvGetFSPContainer(&
                                      (item->spcontainer
                                       [item->no_spcontainer - 1]), &amsofbh, fd);
                break;

            default:
                count += wvEatmsofbt(&amsofbh, fd);
                wvError(("Eating type 0x%x\n", amsofbh.fbt));
                break;
        }
    }
    return count;
}
Exemplo n.º 18
0
Arquivo: ffn.c Projeto: clone/wv
void
wvGetFFN_STTBF6 (FFN_STTBF * item, U32 offset, U32 len, wvStream * fd)
{
    U32 count = 0;
    int noffn = 0;
    wvTrace (("reading fonts 6...\n"));
    wvTrace (("seeking to %x, len %d\n", offset, len));
    if (len == 0)
    {
        item->nostrings = 0;
        item->ffn = NULL;
        return;
    }
    wvStream_goto (fd, offset);
    item->extendedflag = 0;
    item->nostrings = 5;	/* lets just set a val to start off with */
    item->extradatalen = 0;
    item->ffn = (FFN *) wvMalloc (item->nostrings * sizeof (FFN));
    if (len != read_16ubit (fd))
        wvError (("FFN STTBF lens differ\n"));
    count += 2;

    while (count < len)
    {
#ifdef DEBUG
        char *dbg;
#endif
        if (noffn == item->nostrings)
        {
            /* need to extend the array just in case */
            item->nostrings += 5;
            item->ffn =
                (FFN *) realloc (item->ffn, item->nostrings * sizeof (FFN));
        }
        wvGetFFN6 (&(item->ffn[noffn]), fd);
        count += (item->ffn[noffn].cbFfnM1 + 1);
#ifdef DEBUG
        dbg = wvWideStrToMB (item->ffn[noffn].xszFfn);
        wvTrace (("font %d: %s\n", noffn, dbg));
        if (dbg)
            wvFree (dbg);
#endif
        noffn++;
    }

    if (item->nostrings != noffn)
        item->nostrings = noffn;

    wvTrace (("done reading fonts 6.\n"));
}
Exemplo n.º 19
0
U32
wvGetDggContainer(DggContainer *item, MSOFBH *msofbh, wvStream *fd,
                  wvStream *delay) {
    MSOFBH amsofbh;
    U32    count = 0;

    while (count < msofbh->cbLength) {
        count += wvGetMSOFBH(&amsofbh, fd);
        wvTrace(
            ("len is %x, type is %x, count %x,fullen %x\n",
             amsofbh.cbLength, amsofbh.fbt, count, msofbh->cbLength));
        wvTrace(("type is %x\n	", amsofbh.fbt));
        switch (amsofbh.fbt) {
            case msofbtDgg:
                count += wvGetDgg(&item->dgg, &amsofbh, fd);
                break;

            case msofbtSplitMenuColors:
                count +=
                    wvGetSplitMenuColors(&item->splitmenucolors, &amsofbh, fd);
                break;

            case msofbtBstoreContainer:
                count +=
                    wvGetBstoreContainer(&item->bstorecontainer, &amsofbh,
                                         fd, delay);
                wvTrace(
                    ("type is %d (number is %d\n",
                     item->bstorecontainer.blip[item->bstorecontainer.
                                                   no_fbse - 1].type,
                     item->bstorecontainer.no_fbse));
                break;

            default:
                count += wvEatmsofbt(&amsofbh, fd);
                wvError(("Eating type 0x%x\n", amsofbh.fbt));
                break;
        }
    }

    /*
       For some reason I appear to have an extra byte associated either with
       this or its wrapper, I will investigate further.
     */
    read_8ubit(fd);
    count++;

    return count;
}
Exemplo n.º 20
0
/*
 * For a character style, the UPE.chpx can be constructed by starting with
 * the first UPE from the based-on style (std.istdBase).
 */
void
wvInitCHPXFromIstd(CHPX *chpx, U16 istdBase, STSH *stsh) {
    if (istdBase == istdNil)
        wvInitCHPX(chpx);
    else {
        if (istdBase >= stsh->Stshi.cstd) {
            wvError(
                ("ISTD out of bounds, requested %d of %d\n",
                 istdBase, stsh->Stshi.cstd));
            wvInitCHPX(chpx);           /*it can't hurt to try and start with a blank istd */
            return;
        } else
            wvCopyCHPX(chpx, &(stsh->std[istdBase].grupe[0].chpx));
    }
}
Exemplo n.º 21
0
int
wvGetBTE_PLCF(BTE **bte, U32 **pos, U32 *nobte, U32 offset, U32 len,
              wvStream *fd) {
    U32 i;

    if (len == 0) {
        *bte   = NULL;
        *pos   = NULL;
        *nobte = 0;
    } else {
        *nobte = (len - 4) / (cbBTE + 4);
        wvTrace(("no of bte is %d at %x\n", *nobte, offset));
        *pos = (U32 *)wvMalloc((*nobte + 1) * sizeof(U32));
        if (*pos == NULL) {
            wvError(
                ("NO MEM 1, failed to alloc %d bytes\n",
                 (*nobte + 1) * sizeof(U32)));
            return 1;
        }

        *bte = (BTE *)wvMalloc(*nobte * sizeof(BTE));
        if (*bte == NULL) {
            wvError(
                ("NO MEM 1, failed to alloc %d bytes\n",
                 *nobte * sizeof(BTE)));
            wvFree(*pos);
            return 1;
        }
        wvStream_goto(fd, offset);
        for (i = 0; i <= *nobte; i++)
            (*pos)[i] = read_32ubit(fd);
        for (i = 0; i < *nobte; i++)
            wvGetBTE(&((*bte)[i]), fd);
    }
    return 0;
}
Exemplo n.º 22
0
Arquivo: dttm.c Projeto: AbiWord/wv
void
wvListDTTM (DTTM * src)
{
    wvError (("min is %d\n", src->mint));
    wvError (("hr is %d\n", src->hr));
    wvError (("dom is %d\n", src->dom));
    wvError (("mon is %d\n", src->mon));
    wvError (("yr is %d\n", src->yr));
    wvError (("wdy is %d\n", src->wdy));
}
Exemplo n.º 23
0
void
wvInitCHPFromIstd(CHP *achp, U16 istdBase, STSH *stsh) {
    wvTrace(("initing from %d\n", istdBase));
    if (istdBase == istdNil) {
        wvInitCHP(achp);

        /* Set the Nil style's fonts from the defaults. */
        achp->ftcAscii = stsh->Stshi.rgftcStandardChpStsh[0];
        achp->ftcFE    = stsh->Stshi.rgftcStandardChpStsh[1];
        achp->ftcOther = stsh->Stshi.rgftcStandardChpStsh[2];
    } else {
        if (istdBase >= stsh->Stshi.cstd) {
            wvError(
                ("ISTD out of bounds, requested %d of %d\n",
                 istdBase, stsh->Stshi.cstd));
            wvInitCHP(achp);            /*it can't hurt to try and start with a blank istd */
            return;
        } else {
            if (stsh->std[istdBase].cupx == 0) {        /*empty slot in the array, i don't think this should happen */
                wvTrace(("Empty style slot used (chp)\n"));
                wvInitCHP(achp);
            } else {
                wvTrace(("type is %d\n", stsh->std[istdBase].sgc));
                switch (stsh->std[istdBase].sgc) {
                    case sgcPara:
                        wvCopyCHP(achp,
                                  &(stsh->std[istdBase].grupe[1].achp));
                        break;

                    case sgcChp:
                        wvInitCHP(achp);
                        wvApplyCHPXFromBucket(achp,
                                              &(stsh->std[istdBase].
                                                   grupe[0].chpx), stsh);
                        strncpy(achp->stylename, stsh->std[istdBase].xstzName, sizeof(achp->stylename));
                        break;
                }
            }
        }
    }
}
Exemplo n.º 24
0
Arquivo: sep.c Projeto: AbiWord/wv
int
wvAddSEPXFromBucket6 (SEP * asep, SEPX * item, STSH * stsh)
{
    U8 *pointer;
    U16 i = 0;
    int ret = 0;
    U8 sprm8;
    U16 sprm;
    Sprm RetSprm;
#ifdef SPRMTEST
    fprintf (stderr, "\n");
    while (i < item->cb)
      {
	  fprintf (stderr, "%x (%d) ", *(item->grpprl + i),
		   *(item->grpprl + i));
	  i++;
      }
    fprintf (stderr, "\n");
    i = 0;
#endif
    while (i < item->cb)
      {
	  sprm8 = bread_8ubit (item->grpprl + i, &i);
#ifdef SPRMTEST
	  wvError (("sep word 6 sprm is %x (%d)\n", sprm8, sprm8));
#endif
	  sprm = (U16) wvGetrgsprmWord6 (sprm8);
#ifdef SPRMTEST
	  wvTrace (("sep word 6 sprm is converted to %x\n", sprm));
#endif
	  pointer = item->grpprl + i;
	  RetSprm =
	      wvApplySprmFromBucket (WORD6, sprm, NULL, NULL, asep, stsh,
				     pointer, &i, NULL);
	  if (RetSprm.sgc == sgcSep)
	      ret = 1;
      }
    return (ret);
}
Exemplo n.º 25
0
int
wvOpenConfig(state_data *myhandle, char *config) {
    FILE *tmp;
    int  i = 0;

    if (config == NULL)
        config = "wvConfig.xml";
    else
        i = 1;
    tmp = fopen(config, "rb");
    if (tmp == NULL) {
        if (i)
            wvError(
                ("Attempt to open %s failed, using %s\n", config,
                 HTMLCONFIG));
        config = XMLCONFIG;
        tmp    = fopen(config, "rb");
    }
    myhandle->path = config;
    myhandle->fp   = tmp;
    return tmp == NULL ? 0 : 1;
}
Exemplo n.º 26
0
int
wvGetBKL_PLCF(BKL **bkl, U32 **pos, U32 *nobkl, U32 bkloffset, U32 bkllen, U32 bkfoffset, U32 bkflen,
              wvStream *fd) {
    BKF *bkf;
    U32 *posf, nobkf;

    U32 i, j;

    if ((bkllen == 0) || (bkflen == 0)) {
        *bkl   = NULL;
        *pos   = NULL;
        *nobkl = 0;
    } else {
        /* the plcbkl table contains offsets only, bkl has to be calculated from bkf */
        *nobkl = (bkllen - 4) / (/*cbBKL +*/ 4);
        *pos   = (U32 *)wvMalloc((*nobkl + 1) * sizeof(U32));
        if (*pos == NULL) {
            wvError(
                ("NO MEM 1, failed to alloc %d bytes\n",
                 (*nobkl + 1) * sizeof(U32)));
            return 1;
        }

        *nobkl = (*nobkl ? *nobkl : 1);
        *bkl   = (BKL *)wvMalloc(*nobkl * sizeof(BKL));
        if (*bkl == NULL) {
            wvError(
                ("NO MEM 1, failed to alloc %d bytes\n",
                 *nobkl * sizeof(BKL)));
            wvFree(*pos);
            return 1;
        }
        wvStream_goto(fd, bkloffset);
        for (i = 0; i <= *nobkl; i++)
            (*pos)[i] = read_32ubit(fd);

        /* now we have to reconstruct the bkl table; we have to get the bkf records,
           and then search them to find one that matches the index we are processing
         */

        if (wvGetBKF_PLCF(&bkf, &posf, &nobkf, bkfoffset, bkflen, fd)) {
            wvError(
                ("call to wvGetBKF_PLCF failed\n"));
            wvFree(*pos);
            wvFree(*bkl);
            return 1;
        }

        for (i = 0; i < *nobkl; i++) {
            for (j = 0; j < nobkf; j++)
                if (bkf[j].ibkl == i)
                    break;

            if (j == nobkf) {
                wvError(
                    ("unmatched closing bookmark\n"));
                wvFree(*pos);
                wvFree(*bkl);
                wvFree(bkf);
                wvFree(posf);
                return 1;
            }

            (*bkl)[i].ibkf = (U16)j;
        }

        wvFree(bkf);
        wvFree(posf);
    }

    return 0;
}
Exemplo n.º 27
0
/*
   Paragraph List Formatting

   Given a paragraph and its corresponding PAP, the following process must be
   followed to find out the paragraph's list information:

 * Using the pap.ilfo, look up the LFO record in the pllfo with that
     (1-based) index.

 * Using the LFO, and the pap.ilvl, check to see if there are any
     overrides for this particular level. If so, and if the override
     pertains to both formatting and start-at value, use the LVL record from
     the correct LFOLVL in the LFO, and skip to step 5.

 * If the override does not pertain to either formatting or start-at
     value, we must look up the LST for this list. Using the LFO's List ID,
     search the rglst for the LST with that List ID.

 * Now, take from this LST any information (formatting or start-at value)
     we still need after consulting the LFO.

 * Once we've got the correct LVL record, apply the lvl.grpprlPapx to the
     PAP. It may adjust the indents and tab settings for the paragraph.

 * Use the other information in the LVL, such as the start at, number
     text, and grpprlChpx, to determine the appearance of the actual
     paragraph number text.
 */
int
wvGetListEntryInfo(wvVersion ver, LVL **finallvl, U32 **nos, U8 **nfcs,
                   LVL *retlvl, LFO **retlfo, PAP *apap, LFO **lfo,
                   LFOLVL *lfolvl, LVL *lvl, U32 *nolfo, LST **lst,
                   U16 *noofLST) {
    LST *alst = NULL;
    U32 i, number = 0;
    S32 j;
    U32 oldno;
    U32 fakeid;

    wvTrace(("given ilfo of %d %d\n", apap->ilfo, apap->ilvl));
    if (apap->ilfo < 0) {
        apap->ilfo = abs(apap->ilfo);
        wvWarning
            ("Insane negative ilfo value, normalizing to %d and hoping for the best\n",
            apap->ilfo);
    }

    if ((apap->ilfo == 2047) || (ver != WORD8)) {
        retlvl->lvlf.iStartAt = apap->anld.iStartAt;
        retlvl->lvlf.nfc      = apap->anld.nfc;
        wvTrace(
            ("start %d,type is %d\n", apap->anld.iStartAt,
             apap->anld.nfc));
        retlvl->lvlf.jc            = apap->anld.jc;
        retlvl->lvlf.fLegal        = 0; /*? */
        retlvl->lvlf.fNoRestart    = 0; /*? */
        retlvl->lvlf.fPrev         = apap->anld.fPrev;
        retlvl->lvlf.fPrevSpace    = apap->anld.fPrevSpace;
        retlvl->lvlf.fWord6        = 1;
        retlvl->lvlf.rgbxchNums[0] = 0; /*wrong for now */
        retlvl->lvlf.ixchFollow    = 2; /*wrong for now */
        retlvl->lvlf.dxaSpace      = apap->anld.dxaSpace;
        retlvl->lvlf.dxaIndent     = apap->anld.dxaIndent;
        retlvl->lvlf.cbGrpprlChpx  = 0;         /* wrong */
        retlvl->lvlf.cbGrpprlPapx  = 0;         /* wrong */
        retlvl->lvlf.reserved1     = 0;
        retlvl->lvlf.reserved2     = 0;
        retlvl->grpprlChpx         = NULL; /* wrong */
        retlvl->grpprlPapx         = NULL; /* wrong */



        /* wrong: begin of numbertext twiddling */
        wvTrace(("before len %d\n", apap->anld.cxchTextBefore));
        wvTrace(("after len %d\n", apap->anld.cxchTextAfter));
        retlvl->numbertext = (XCHAR *)wvMalloc(sizeof(XCHAR) * 64);
        i = 0;
        for ( ; i < apap->anld.cxchTextBefore; i++)
            retlvl->numbertext[i] = apap->anld.rgxch[i];

        retlvl->numbertext[i] = 2;

        for (i = apap->anld.cxchTextBefore; i < apap->anld.cxchTextAfter; i++)
            retlvl->numbertext[i + 1] = apap->anld.rgxch[i];

        retlvl->numbertext[i + 1] = '\0';
        /* end of numbertext twiddling */


        /* temp test */
        if (retlvl->lvlf.nfc > 5)
            retlvl->numbertext[0] = 0;


        /*word 6 anld, parse that instead */
        fakeid = wvCheckSumANLD(&apap->anld);
        wvTrace(("creating a fake id of %x\n", fakeid));
        for (i = 0; i < *nolfo; i++) {
            if (fakeid == (*lfo)[i].lsid) {
                wvTrace(
                    ("This is not the first time we've seen this list\n"));
                apap->ilfo = i + 1;

                if (apap->nLvlAnm >= 10)
                    apap->nLvlAnm -= 10;

                if ((apap->nLvlAnm == 1) || (apap->nLvlAnm == 0))
                    apap->ilvl = 0;
                else
                    apap->ilvl = apap->nLvlAnm - 1;

                if (apap->ilvl >= 10)
                    apap->ilvl -= 10;

                for (i = 0; i < 9; i++)
                    (*nos)[(apap->ilfo - 1) * 9 + i] = 0xffffffffL;
                for (i = 0; i < 9; i++)
                    (*nfcs)[(apap->ilfo - 1) * 9 + i] = 0xff;

                wvTrace(("ilvl %d\n", apap->ilvl));


                /* if this anld is a dodgy one 0x2e */
                if ((apap->ilvl) && (apap->anld.fNumber1 == 0x2e)) {
                    wvTrace(("Suspicious\n"));
                    switch (apap->ilvl) {
                        case 1:
                            if (retlvl->lvlf.nfc == 0)
                                retlvl->lvlf.nfc = 4;
                            else if (retlvl->lvlf.nfc == 1)
                                retlvl->lvlf.nfc = 3;
                            break;

                        case 2:
                            if (retlvl->lvlf.nfc == 0)
                                retlvl->lvlf.nfc = 2;
                            else if (retlvl->lvlf.nfc == 1)
                                retlvl->lvlf.nfc = 0;
                            break;

                        case 3:
                            if (retlvl->lvlf.nfc == 0)
                                retlvl->lvlf.nfc = 4;
                            else if (retlvl->lvlf.nfc == 1)
                                retlvl->lvlf.nfc = 4;
                            break;

                        case 4:
                            if (retlvl->lvlf.nfc == 0)
                                retlvl->lvlf.nfc = 0;
                            else if (retlvl->lvlf.nfc == 1)
                                retlvl->lvlf.nfc = 0;
                            break;

                        case 5:
                            if (retlvl->lvlf.nfc == 0)
                                retlvl->lvlf.nfc = 4;
                            else if (retlvl->lvlf.nfc == 1)
                                retlvl->lvlf.nfc = 4;
                            break;

                        case 6:
                            if (retlvl->lvlf.nfc == 0)
                                retlvl->lvlf.nfc = 2;
                            else if (retlvl->lvlf.nfc == 1)
                                retlvl->lvlf.nfc = 2;
                            break;

                        case 7:
                            if (retlvl->lvlf.nfc == 0)
                                retlvl->lvlf.nfc = 4;
                            else if (retlvl->lvlf.nfc == 1)
                                retlvl->lvlf.nfc = 4;
                            break;

                        case 8:
                            if (retlvl->lvlf.nfc == 0)
                                retlvl->lvlf.nfc = 2;
                            else if (retlvl->lvlf.nfc == 1)
                                retlvl->lvlf.nfc = 2;
                            break;
                    }
                }
                return 0;
            }
        }

        wvTrace(("This is the first time we've seen this list\n"));

        oldno = *nolfo;
        (*nolfo)++;

        /*
           realloc the lfo list to be one bigger,
         */
        *lfo  = (LFO *)realloc(*lfo, sizeof(LFO) * (*nolfo));
        *nos  = (U32 *)realloc(*nos, sizeof(U32) * 9 * (*nolfo));
        *nfcs = (U8 *)realloc(*nfcs, 9 * (*nolfo));
        wvTrace(("nos is now %d long\n", 9 * (*nolfo)));
        *finallvl = (LVL *)realloc(*finallvl, 9 * (*nolfo) * sizeof(LVL));

        apap->ilfo = *nolfo;

        wvTrace(("ilvl is %d, nLvlAnm is %d\n", apap->ilvl, apap->nLvlAnm));
        if (apap->nLvlAnm >= 10)
            apap->nLvlAnm -= 10;

        if ((apap->nLvlAnm == 1) || (apap->nLvlAnm == 0))
            apap->ilvl = 0;
        else
            apap->ilvl = apap->nLvlAnm - 1;

        wvTrace(("ilfo set to %d\n", apap->ilfo));

        /* begin new test */
        (*noofLST)++;
        *lst = (LST *)realloc(*lst, sizeof(LST) * (*noofLST));
        wvInitLST(&(((*lst)[(*noofLST) - 1])));
        (*lst)[(*noofLST) - 1].lstf.lsid = fakeid;
        wvTrace(("ilvl is %d\n", apap->ilvl));
        wvCopyLVL(&(((*lst)[(*noofLST) - 1]).lvl[apap->ilvl]), retlvl);
        /* end new test */
        wvTrace(("End\n"));


        wvInitLFO(&((*lfo)[apap->ilfo - 1]));
        (*lfo)[apap->ilfo - 1].lsid = fakeid;   /*how about this? */
        *retlfo = &((*lfo)[apap->ilfo - 1]);
        for (i = 0; i < 9; i++) {
            (*nos)[(apap->ilfo - 1) * 9 + i]  = 0xffffffffL;
            (*nfcs)[(apap->ilfo - 1) * 9 + i] = 0xff;
            wvInitLVL(&((*finallvl)[(apap->ilfo - 1) * 9 + i]));
            wvCopyLVL(&((*finallvl)[(apap->ilfo - 1) * 9 + i]), retlvl);
        }


        /*
           and set the ilfo and ilvl of the list to point to that fake entry instead
           and we'll have to repeat the procedure for the liststartnos
         */
        return 0;
    } else if (apap->ilfo == 0) {
        /* no number */
        return 0;
    }
    if (apap->ilfo > (S32)(*nolfo)) {
        wvWarning
            ("ilfo no %d, is greater than the number of existing lfo's (%d)\n",
            apap->ilfo, *nolfo);
        return 1;
    }

    /*
       Using the pap.ilfo, look up the LFO record in the pllfo with that
       (1-based) index. == (*lfo)[apap->ilfo]
     */

    *retlfo = &((*lfo)[apap->ilfo - 1]);

    wvTrace(("looking for id %x\n", (*retlfo)->lsid));

    if ((*lfo)[apap->ilfo - 1].clfolvl) {
        /*
           Using the LFO, and the pap.ilvl, check to see if there are any
           overrides for this particular level. If so, and if the override
           pertains to both formatting and start-at value, use the LVL record
           from the correct LFOLVL in the LFO, and skip to step 5.
         */
        wvTrace(("some overridden levels, ilfo %d\n", apap->ilfo));

        /*
           there are some levels overridden, find out if the level being overridden
           is the same as the level the paragraph wants
         */
        for (j = 0; j < apap->ilfo - 1; j++)
            number += (*lfo)[j].clfolvl;

        for (i = 0; i < (*lfo)[apap->ilfo - 1].clfolvl; i++) {
            if (lfolvl[i + number].ilvl == apap->ilvl) {
                /* the requested level is overridden */
                if ((lfolvl[i + number].fFormatting) &&
                    (lfolvl[i + number].fStartAt)) {
                    /*save the existing lvl and swap in this new one instead */
                    alst =
                        wvSearchLST((*lfo)[apap->ilfo - 1].lsid,
                                    *lst, *noofLST);

                    /*use the LVL record from the correct LFOLVL in the LFO */
                    wvCopyLVL(retlvl, &(lvl[i + number]));
                } else if (lfolvl[i + number].fStartAt) {
                    alst =
                        wvSearchLST((*lfo)[apap->ilfo - 1].lsid,
                                    *lst, *noofLST);

                    /* the lvl is the standard one with a new startat value */
                    wvCopyLVL(retlvl, &(alst->lvl[apap->ilvl]));
                    retlvl->lvlf.iStartAt = lfolvl[i + number].iStartAt;
                } else if (lfolvl[i + number].fFormatting) {
                    alst =
                        wvSearchLST((*lfo)[apap->ilfo - 1].lsid,
                                    *lst, *noofLST);

                    /* the lvl is the overridden one, with the original startat */
                    wvCopyLVL(retlvl, &(lvl[i + number]));
                    retlvl->lvlf.iStartAt =
                        alst->lvl[apap->ilvl].lvlf.iStartAt;
                }
            }
        }
    }

    if (alst == NULL) {
        /*
           if there no overridden levels i assume that we
           search for the appropiate LST
         */
        alst = wvSearchLST((*lfo)[apap->ilfo - 1].lsid, *lst, *noofLST);
        if (alst != NULL) {
            wvTrace(("ilvl is %d\n", apap->ilvl));
            if ((alst->lstf.fSimpleList) && (apap->ilvl)) {
                wvWarning
                    ("Level %d requested from list with 1 level\n",
                    apap->ilvl + 1);
                wvCopyLVL(retlvl, &(alst->lvl[0]));
            } else
                wvCopyLVL(retlvl, &(alst->lvl[apap->ilvl]));
            wvTrace(("string len is %d", retlvl->numbertext[0]));
            wvTrace(("offset is %d\n", retlvl->lvlf.rgbxchNums[0]));
        }
    }

    if (alst == NULL) {
        wvError(("No LST found for list\n"));
        return 1;
    }

    return 0;
}
Exemplo n.º 28
0
int
main (int argc, char **argv)
{
    char *config = NULL;
    char *password = NULL;

    int ret;
    state_data myhandle;
    expand_data expandhandle;
    wvParseStruct ps;
    int c, index = 0;
    static struct option long_options[] = {
	{"config", 1, 0, 'x'},
	{"password", 1, 0, 'p'},
	{0, 0, 0, 0}
    };

    if (argc < 2)
	usage ();

    while (1)
      {
	  c = getopt_long (argc, argv, "x:p:", long_options, &index);
	  if (c == -1)
	      break;
	  switch (c)
	    {
	    case 'x':
		if (optarg)
		    config = optarg;
		else
		    wvError (("No config file given to config option"));
		break;
	    case 'p':
		if (optarg)
		    password = optarg;
		else
		    wvError (("No password given to password option"));
		break;
	    default:
		usage ();
		break;
	    }
      }

    wvInit ();
    ret = wvInitParser (&ps, argv[optind]);
    ps.filename = argv[optind];

    if (ret == 4)
      {
	  ret = 0;
	  if (password == NULL)
	    {
		wvError (
			 ("Password required, this is an encrypted document\n"));
		return (-1);
	    }
	  else
	    {
		wvSetPassword (password, &ps);
		if (wvDecrypt97 (&ps))
		  {
		      wvError (("Incorrect Password\n"));
		      return (-1);
		  }
	    }
      }
    else if (ret == 7)
      {
	  ret = 0;
	  if (password == NULL)
	    {
		wvError (
			 ("Password required, this is an encrypted document\n"));
		return (-1);
	    }
	  else
	    {
		wvSetPassword (password, &ps);
		if (wvDecrypt95 (&ps))
		  {
		      wvError (("Incorrect Password\n"));
		      return (-1);
		  }
	    }
      }

    if (ret)
      {
	  wvError (("startup error with file %s\n", argv[1]));
	  wvOLEFree (&ps);
	  return (2);
      }

    wvSetElementHandler (&ps, myelehandler);
    wvSetDocumentHandler (&ps, mydochandler);

    wvInitStateData (&myhandle);

    if (wvOpenConfig (&myhandle,config) == 0)
	wvError (("config file not found\n"));
    else
	ret = wvParseConfig (&myhandle);

    if (!ret)
      {
	  expandhandle.sd = &myhandle;
	  ps.userData = &expandhandle;
	  ret = wvText (&ps);
      }

    wvReleaseStateData (&myhandle);
    if (ret == 2)
	return (2);
    else if (ret != 0)
	ret = -1;
    wvOLEFree (&ps);
    return (ret);
}
Exemplo n.º 29
0
Arquivo: roman.c Projeto: AbiWord/wv
char *
decimalToRoman (long decimal, char *roman)
{
    char *r = roman;
    memset (roman, 0, 81);
    r = roman;
    if (decimal > LARGEST || decimal < 1)
      {
	  *r = '\0';
	  wvError (("roman broke\n"));
	  return roman;
      }
    if (decimal >= Z)
	decimal -= formString (&r, Z, 'Z', '\0');
    if (decimal >= Z - Y)
	decimal -= formString (&r, Z - Y, 'Y', 'Z');
    while (decimal >= Y)
	decimal -= formString (&r, Y, 'Y', '\0');
    if (decimal >= Y - W)
	decimal -= formString (&r, Y - W, 'W', 'Y');
    if (decimal >= N)
	decimal -= formString (&r, N, 'N', '\0');
    if (decimal >= N - W)
	decimal -= formString (&r, N - W, 'W', 'N');
    while (decimal >= W)
	decimal -= formString (&r, W, 'W', '\0');
    if (decimal >= W - U)
	decimal -= formString (&r, W - U, 'U', 'W');
    if (decimal >= B)
	decimal -= formString (&r, B, 'B', '\0');
    if (decimal >= B - U)
	decimal -= formString (&r, B - U, 'U', 'B');
    while (decimal >= U)
	decimal -= formString (&r, U, 'U', '\0');
    if (decimal >= U - S)
	decimal -= formString (&r, U - S, 'S', 'U');
    if (decimal >= T)
	decimal -= formString (&r, T, 'T', '\0');
    if (decimal >= T - S)
	decimal -= formString (&r, T - S, 'S', 'T');
    while (decimal >= S)
	decimal -= formString (&r, S, 'S', '\0');
    if (decimal >= S - Q)
	decimal -= formString (&r, S - Q, 'Q', 'S');
    if (decimal >= R)
	decimal -= formString (&r, R, 'R', '\0');
    if (decimal >= R - Q)
	decimal -= formString (&r, R - Q, 'Q', 'R');
    while (decimal >= Q)
	decimal -= formString (&r, Q, 'Q', '\0');
    if (decimal >= Q - M)
	decimal -= formString (&r, Q - M, 'M', 'Q');
    if (decimal >= P)
	decimal -= formString (&r, P, 'P', '\0');
    if (decimal >= P - M)
	decimal -= formString (&r, P - M, 'M', 'P');
    while (decimal >= M)
	decimal -= formString (&r, M, 'M', '\0');
    if (decimal >= M - C)
	decimal -= formString (&r, M - C, 'C', 'M');
    if (decimal >= D)
	decimal -= formString (&r, D, 'D', '\0');
    if (decimal >= D - C)
	decimal -= formString (&r, D - C, 'C', 'D');
    while (decimal >= C)
	decimal -= formString (&r, C, 'C', '\0');
    if (decimal >= C - X)
	decimal -= formString (&r, C - X, 'X', 'C');
    if (decimal >= L)
	decimal -= formString (&r, L, 'L', '\0');
    if (decimal >= L - X)
	decimal -= formString (&r, L - X, 'X', 'L');
    while (decimal >= X)
	decimal -= formString (&r, X, 'X', '\0');
    switch ((int) decimal)
      {
      case 9:
	  *r++ = 'I';
	  *r++ = 'X';
	  break;
      case 8:
	  *r++ = 'V';
	  *r++ = 'I';
	  *r++ = 'I';
	  *r++ = 'I';
	  break;
      case 7:
	  *r++ = 'V';
	  *r++ = 'I';
	  *r++ = 'I';
	  break;
      case 6:
	  *r++ = 'V';
	  *r++ = 'I';
	  break;
      case 4:
	  *r++ = 'I';
      case 5:
	  *r++ = 'V';
	  break;
      case 3:
	  *r++ = 'I';
      case 2:
	  *r++ = 'I';
      case 1:
	  *r++ = 'I';
	  break;
      }
    return roman;
}
Exemplo n.º 30
0
Arquivo: wvRTF.c Projeto: AbiWord/wv
int
main (int argc, char *argv[])
{
    FILE *input;
    char *fname, *password;
    int ret;

    wvParseStruct ps;
    char *dir = NULL;

    rtfUserData ud;

    static struct option long_options[] = {
	{"charset", 1, 0, 'c'},
	{"password", 1, 0, 'p'},
	{"dir", 1, 0, 'd'},
	{"version", 0, 0, 'v'},
	{"help", 0, 0, '?'},
	{0, 0, 0, 0}
    };

    int c, index = 0;

    if (argc < 2)
      {
	  do_help ();
	  return 1;
      }

    while (1)
      {
	  c = getopt_long (argc, argv, "?vc:p:d:", long_options, &index);
	  if (c == -1)
	      break;
	  switch (c)
	    {
	    case '?':
		do_help ();
		return 0;
	    case 'v':
		do_version ();
		return 0;
	    case 'c':
		if (optarg)
		    charset = optarg;
		else
		    wvError (("No argument given to charset"));
		break;
	    case 'p':
		if (optarg)
		    password = optarg;
		else
		    wvError (("No password given to password option"));
		break;
	    case 'd':
		if (optarg)
		    dir = optarg;
		else
		    wvError (("No directory given to dir option"));
		break;
	    default:
		do_help ();
		return -1;
	    }
      }

    if (optind >= argc)
      {
	  fprintf (stderr, "No file name given to open\n");
	  return -1;
      }

    fname = argv[optind];

    input = fopen (fname, "rb");
    if (!input)
      {
	fprintf (stderr, "Failed to open %s\n", fname);
	  return -1;
      }
    fclose (input);

    wvInit ();
    ret = wvInitParser (&ps, fname);
    ps.filename = fname;
    ps.dir = dir;

    /* set to 0 */
    memset (&ud, 1, sizeof (rtfUserData));
    ps.userData = &ud;

    if (ret & 0x8000)		/* Password protected? */
      {
	  if ((ret & 0x7fff) == WORD8)
	    {
		ret = 0;
		if (password == NULL)
		  {
		      fprintf (stderr,
			       "Password required, this is an encrypted document\n");
		      return -1;
		  }
		else
		  {
		      wvSetPassword (password, &ps);
		      if (wvDecrypt97 (&ps))
			{
			    wvError (("Incorrect Password\n"));
			    return -1;
			}
		  }
	    }
	  else if (((ret & 0x7fff) == WORD7) || ((ret & 0x7fff) == WORD6))
	    {
		ret = 0;
		if (password == NULL)
		  {
		      fprintf (stderr,
			       "Password required, this is an encrypted document\n");
		      return -1;
		  }
		else
		  {
		      wvSetPassword (password, &ps);
		      if (wvDecrypt95 (&ps))
			{
			    wvError (("Incorrect Password\n"));
			    return -1;
			}
		  }
	    }
      }

    if (ret)
      {
	  wvError (("startup error\n"));
	  wvOLEFree (&ps);
	  return -1;
      }

    wvSetElementHandler (&ps, eleProc);
    wvSetDocumentHandler (&ps, docProc);
    wvSetCharHandler (&ps, charProc);
    wvSetSpecialCharHandler (&ps, specCharProc);

    wvText (&ps);

    /* free associated memory */
    wvOLEFree (&ps);

    return 0;
}