File: lvl.c

package info (click to toggle)
abiword 0.7.7-1
  • links: PTS
  • area: main
  • in suites: potato
  • size: 20,604 kB
  • ctags: 18,358
  • sloc: cpp: 88,791; ansic: 66,296; sh: 7,777; makefile: 3,397; xml: 687; perl: 361; awk: 273; sed: 36; csh: 28
file content (142 lines) | stat: -rw-r--r-- 3,141 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#include <stdlib.h>
#include <stdio.h>
#include "wv.h"

void wvInitLVL(LVL *lvl)
	{
	lvl->grpprlPapx=NULL;
	lvl->grpprlChpx=NULL;
	lvl->numbertext=NULL;
	wvInitLVLF(&(lvl->lvlf));
	}

void wvCopyLVL(LVL *dest,LVL *src)
	{
	int len,i;
	wvReleaseLVL(dest);
	wvInitLVL(dest);

	wvCopyLVLF(&(dest->lvlf),&(src->lvlf));


	if (src->lvlf.cbGrpprlPapx > 0)
		{
		dest->grpprlPapx = (U8 *)malloc(src->lvlf.cbGrpprlPapx);
		memcpy(dest->grpprlPapx,src->grpprlPapx,src->lvlf.cbGrpprlPapx);
		}		
	else
		dest->grpprlPapx = NULL;

	if (src->lvlf.cbGrpprlChpx > 0)
		{
		dest->grpprlChpx = (U8 *)malloc(src->lvlf.cbGrpprlChpx);
		memcpy(dest->grpprlChpx,src->grpprlChpx,src->lvlf.cbGrpprlChpx);
		}	
	else
		dest->grpprlChpx = NULL;
	
	if (src->numbertext==NULL)
		dest->numbertext=NULL;
	else
		{
		len = src->numbertext[0];
		dest->numbertext = (U16 *)malloc(sizeof(U16)*(len +2));
		memcpy(dest->numbertext,src->numbertext,len+2);
		}
	}

void wvGetLVL(LVL *lvl,FILE *fd)
	{
	int len,i;
	wvGetLVLF(&(lvl->lvlf),fd);
	if (lvl->lvlf.cbGrpprlPapx > 0)
		{
		lvl->grpprlPapx = (U8 *)malloc(lvl->lvlf.cbGrpprlPapx);
		fread(lvl->grpprlPapx,sizeof(U8),lvl->lvlf.cbGrpprlPapx,fd);
		}		
	else
		lvl->grpprlPapx = NULL;
	if (lvl->lvlf.cbGrpprlChpx > 0)
		{
		lvl->grpprlChpx = (U8 *)malloc(lvl->lvlf.cbGrpprlChpx);
		fread(lvl->grpprlChpx,sizeof(U8),lvl->lvlf.cbGrpprlChpx,fd);
		}	
	else
		lvl->grpprlChpx = NULL;
	len = read_16ubit(fd);
	if (len > 0)
		{
		lvl->numbertext = (U16 *)malloc(sizeof(U16)*(len +2));
		lvl->numbertext[0] = len;
		fread(&(lvl->numbertext[1]),sizeof(U16),len,fd);
		lvl->numbertext[len-1] = 0;
		}
	else
		lvl->numbertext = NULL;
	wvTrace(("len is %d\n",len));
	}

void wvReleaseLVL(LVL *lvl)
	{
	if (lvl == NULL)
		return;
	wvFree(lvl->grpprlPapx);
	wvFree(lvl->grpprlChpx);
	wvFree(lvl->numbertext);
	}

void wvCopyLVLF(LVLF *dest,LVLF *src)
	{
	memcpy(dest,src,sizeof(LVLF));
	}

void wvGetLVLF(LVLF *item,FILE *fd)
	{
	U8 temp8;
	int i;
#ifdef PURIFY
	wvInitLVLF(item);
#endif
	item->iStartAt = read_32ubit(fd);
	wvTrace(("iStartAt is %d\n",item->iStartAt));
    item->nfc = getc(fd);
	temp8 = getc(fd);
    item->jc = temp8 & 0x03;
   	item->fLegal = (temp8 & 0x04) >>2;
    item->fNoRestart = (temp8 & 0x08) >> 3;
    item->fPrev = (temp8 & 0x10) >> 4;
    item->fPrevSpace = (temp8 & 0x20) >> 5;
    item->fWord6 = (temp8 & 0x40) >> 6;
    item->reserved1 = (temp8 & 0x80) >> 7;
	for (i=0;i<9;i++)
    	item->rgbxchNums[i] = getc(fd); 
    item->ixchFollow = getc(fd);;
    item->dxaSpace = read_32ubit(fd);      
    item->dxaIndent = read_32ubit(fd);     
    item->cbGrpprlChpx = getc(fd);
    item->cbGrpprlPapx = getc(fd);
    item->reserved2 = read_16ubit(fd);;  
	}


void wvInitLVLF(LVLF *item)
	{
	int i;
	item->iStartAt = 1;
    item->nfc = 0;
    item->jc = 0;
   	item->fLegal = 0;
    item->fNoRestart = 0;
    item->fPrev = 0;
    item->fPrevSpace = 0;
    item->fWord6 = 0;
    item->reserved1 = 0;
	for (i=0;i<9;i++)
    	item->rgbxchNums[i] = 0;
    item->ixchFollow = 0;
    item->dxaSpace = 0;
    item->dxaIndent = 0;
    item->cbGrpprlChpx = 0;
    item->cbGrpprlPapx = 0;
    item->reserved2 = 0;
	}