Esempio n. 1
0
File: dttm.c Progetto: AbiWord/wv
/* 
 * dont free the char * back from this, its engine is
 * ctime
*/
char *
wvDTTMtoUnix (DTTM * src)
{
    /* 
       im concerned with the lack of yday to i run it
       through the system to fill it in before using asctime
     */
    time_t t;
    struct tm out;
    wvListDTTM (src);
    out.tm_sec = 0;
    out.tm_min = src->mint;
    out.tm_hour = src->hr;
    out.tm_mday = src->dom;
    out.tm_mon = src->mon - 1;
    out.tm_year = src->yr;
    out.tm_wday = src->wdy;
    out.tm_yday = 0;
    out.tm_isdst = -1;
    t = mktime (&out);
    if (t == -1)
      {
	  wvWarning ("Bad Time!!, not critical error\n");
	  return (NULL);
      }
    return (ctime (&t));
}
U32
wvGetDgg(Dgg *dgg, MSOFBH *amsofbh, wvStream *fd) {
    U32 count = 0;
    U32 no;
    U32 i;

    count += wvGetFDGG(&dgg->fdgg, fd);
    if (dgg->fdgg.cidcl != 0) {
        wvTrace(("There are %d bytes left\n", amsofbh->cbLength - count));
        no = (amsofbh->cbLength - count) / 8;
        if (no != dgg->fdgg.cidcl) {
            wvWarning
                ("Must be %d, not %d as specs, test algor gives %d\n", no,
                dgg->fdgg.cidcl, dgg->fdgg.cspSaved - dgg->fdgg.cidcl);
        }
        if (no) {
            dgg->fidcl = (FIDCL *)wvMalloc(sizeof(FIDCL) * no);
            for (i = 0; i < no; i++)
                count += wvGetFIDCL(&(dgg->fidcl[i]), fd);
        }
    }
    return count;
}
Esempio n. 3
0
File: table.c Progetto: AbiWord/wv
int
wvCellBgColor (int whichrow, int whichcell, int nocells, int norows, TLP * tlp)
{
    if (whichrow == norows - 1)
	whichrow = 3;
    else if (whichrow > 0)
      {
	  if (isodd (whichrow))
	      whichrow = 2;
	  else
	      whichrow = 1;
      }

    if (whichcell == nocells - 1)
	whichcell = 3;
    else if (whichcell > 0)
      {
	  if (isodd (whichcell))
	      whichcell = 2;
	  else
	      whichcell = 1;
      }

    wvTrace (
	     ("the cell index and bgcolor is %d %d %d,%d (last cell and row are %d %d)\n",
	      tlp->itl, whichrow, whichcell,
	      cellbgcolors[tlp->itl][whichrow][whichcell], nocells, norows));
    if (tlp->itl >= 40)
      {
	  wvWarning
	      ("Table Look %d requested, but theres only %d in the list\n",
	       tlp->itl + 1, 40);
	  return (8);
      }
    return (cellbgcolors[tlp->itl][whichrow][whichcell]);
}
Esempio n. 4
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;
}
Esempio n. 5
0
File: table.c Progetto: AbiWord/wv
/*
-------------------------
|          |            |
-------------------------
|   | | |    |     |    |
-------------------------
|                       |
-------------------------
|     |         |       |
-------------------------

==>

|   | | |  | |  |  |    |

As in this example we create a list of cell begin
positions which is a superset of all begin
positions in all rows, once we have this list we
restart at the top of the table and figure out
how many spans each cell has to achieve to match
back up to its original boundaries.

We will have to match boundaries that are with in
3 units of eachother to be the same boundary as
that occurs frequently in word tables, (gagh!)
*/
void
wvSetTableInfo (wvParseStruct * ps, TAP * ptap, int no)
{
    BintreeInfo tree;
    Node *testn, *testp;
    int i, j, k;

    if (ps->vmerges)
      {
	  wvTrace (("vmerges is not NULL\n"));
	  for (i = 0; i < ps->norows; i++)
	      wvFree (ps->vmerges[i]);
	  wvFree (ps->vmerges);
	  ps->vmerges = NULL;
      }

    if (no == 0)
      {
	  wvWarning ("Broken tables, continuing and hoping for the best\n");
	  ps->nocellbounds = 0;
	  return;
      }

    InitBintree (&tree, cellCompLT, cellCompEQ);

    wvTrace (("we still ok, no is %d\n", no));

    for (i = 0; i < no; i++)
      {
		  for (j = 0; j < ptap[i].itcMac + 1; j++)
	    {
		wvTrace (("%d\n", ptap[i].rgdxaCenter[j]));
		InsertNode (&tree, (void *) &(ptap[i].rgdxaCenter[j]));
	    }
      }
    wvTrace (("end of in\n"));

    testn = NextNode (&tree, NULL);

    ps->nocellbounds = tree.no_in_tree;
    wvFree (ps->cellbounds);
    if (tree.no_in_tree)
	ps->cellbounds = (S16 *) wvMalloc (sizeof (S16) * tree.no_in_tree);
    else
	ps->cellbounds = NULL;

    i = 0;
    wvTrace (("No in tree is %d\n", tree.no_in_tree));
    while (testn != NULL)
      {
	  ps->cellbounds[i++] = *((S16 *) testn->Data);
	  wvTrace (("cellbound are %d\n", ps->cellbounds[i - 1]));
	  testp = NextNode (&tree, testn);
	  wvDeleteNode (&tree, testn);
	  testn = testp;
      }
    wvTrace (("No in tree according to i is %d\n", i));

    wvTrace (("end of out\n"));

    ps->vmerges = (S16 **) wvMalloc (sizeof (S16 *) * no);
    wvTrace (("no of rows is %d\n", no));
    for (i = 0; i < no; i++)
      {
	  ps->vmerges[i] = (S16 *) wvMalloc (sizeof (S16) * ptap[i].itcMac);
	  wvTrace (("no of cells is %d\n", ptap[i].itcMac));
	  for (j = 0; j < ptap[i].itcMac; j++)
	      ps->vmerges[i][j] = 1;
      }

    for (i = no - 1; i > 0; i--)
      {
	  for (j = 0; j < ptap[i].itcMac; j++)
	    {
		wvTrace (
			 ("Vertical merge is %d\n",
			  ptap[i].rgtc[j].fVertMerge));
		if (ptap[i].rgtc[j].fVertMerge)
		  {
		      wvTrace (
			       ("Vertical merge found, row %d, cell %d\n", i,
				j));
		      /* 
		         find a cell above me with the same boundaries
		         if it is also merged increment it, and set myself to 0
		         else leave me alone
		       */
		      for (k = 0; k < ptap[i - 1].itcMac; k++)	/* the row above */
			{
			    wvTrace (
				     ("cell begins are %d %d\n",
				      ptap[i - 1].rgdxaCenter[k],
				      ptap[i].rgdxaCenter[j]));
			    wvTrace (
				     ("cell ends are %d %d\n",
				      ptap[i - 1].rgdxaCenter[k + 1],
				      ptap[i].rgdxaCenter[j + 1]));

			    if (
				(cellCompEQ
				 ((void *) &(ptap[i - 1].rgdxaCenter[k]),
				  (void *) &(ptap[i].rgdxaCenter[j])))
				&&
				(cellCompEQ
				 ((void *) &(ptap[i - 1].rgdxaCenter[k + 1]),
				  (void *) &(ptap[i].rgdxaCenter[j + 1]))))
			      {
				  wvTrace (("found a cell above me, yippee\n"));
				  if (ptap[i - 1].rgtc[k].fVertMerge)
				    {
					ps->vmerges[i - 1][k] +=
					    ps->vmerges[i][j];
					ps->vmerges[i][j] = 0;
				    }
			      }

			}
		  }
	    }
      }


    for (i = 0; i < no; i++)
	for (j = 0; j < ptap[i].itcMac; j++)
	    wvTrace (("rowspan numbers are %d\n", ps->vmerges[i][j]));
}