File: xst.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 (80 lines) | stat: -rw-r--r-- 1,853 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
#include <stdlib.h>
#include <stdio.h>
#include "wv.h"

void wvFreeXst(Xst **xst)
	{
	Xst *freegroup;
	if ((xst == NULL) || (*xst == NULL))
		return;

	while (*xst != NULL)
        {
        freegroup = *xst;
        *xst = (*xst)->next;
        if (freegroup->u16string != NULL)
            free(freegroup->u16string);
        free(freegroup);
        }
	}

void wvGetXst(Xst **xst,U32 offset,U32 len,FILE *fd)
    {
    U16 clen,i;
    U32 count=0;
    Xst *authorlist;
    Xst *current=NULL;

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

    fseek(fd,offset,SEEK_SET);
    *xst = (Xst*) malloc(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 *)malloc((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*) malloc(sizeof(Xst));
            if (current->next == NULL)
                {
                wvError(("not enough mem for annotation group\n"));
                break;
                }
            current = current->next;
            current->next = NULL;
            current->u16string = NULL;
            }
        }
    }