1 /* wvWare
2  * Copyright (C) Caolan McNamara, Dom Lachowicz, and others
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
17  * 02111-1307, USA.
18  */
19 
20 #ifdef HAVE_CONFIG_H
21 #include "config.h"
22 #endif
23 
24 #include <stdlib.h>
25 #include <stdio.h>
26 #include "wv.h"
27 
28 void
wvListFTXBXS(FTXBXS * item)29 wvListFTXBXS (FTXBXS * item)
30 {
31     wvError (("%d\n", item->cTxbx_iNextReuse));
32     wvError (("%d\n", item->cReusable));
33     wvError (("%d\n", item->fReusable));
34     wvError (("%d\n", item->reserved));
35     wvError (("%d\n", item->lid));
36     wvError (("%d\n", item->txidUndo));
37 }
38 
39 
40 void
wvGetFTXBXS(FTXBXS * item,wvStream * fd)41 wvGetFTXBXS (FTXBXS * item, wvStream * fd)
42 {
43     item->cTxbx_iNextReuse = (S32) read_32ubit (fd);
44     item->cReusable = (S32) read_32ubit (fd);
45     item->fReusable = (S16) read_16ubit (fd);
46     item->reserved = (S32) read_32ubit (fd);
47     item->lid = (S32) read_32ubit (fd);
48     item->txidUndo = (S32) read_32ubit (fd);
49     /* wvListFTXBXS (item); */
50 }
51 
52 int
wvGetFTXBXS_PLCF(FTXBXS ** ftxbxs,U32 ** pos,U32 * noftxbxs,U32 offset,U32 len,wvStream * fd)53 wvGetFTXBXS_PLCF (FTXBXS ** ftxbxs, U32 ** pos, U32 * noftxbxs, U32 offset,
54 		  U32 len, wvStream * fd)
55 {
56     U32 i;
57     if (len == 0)
58       {
59 	  *ftxbxs = NULL;
60 	  *pos = NULL;
61 	  *noftxbxs = 0;
62       }
63     else
64       {
65 	  *noftxbxs = (len - 4) / (cbFTXBXS + 4);
66 	  *pos = (U32 *) wvMalloc ((*noftxbxs + 1) * sizeof (U32));
67 	  if (*pos == NULL)
68 	    {
69 		wvError (
70 			 ("NO MEM 1, failed to alloc %d bytes\n",
71 			  (*noftxbxs + 1) * sizeof (U32)));
72 		return (1);
73 	    }
74 
75 	  *ftxbxs = (FTXBXS *) wvMalloc ((*noftxbxs + 1) * sizeof (FTXBXS));
76 	  if (*ftxbxs == NULL)
77 	    {
78 		wvError (
79 			 ("NO MEM 1, failed to alloc %d bytes\n",
80 			  *noftxbxs * sizeof (FTXBXS)));
81 		wvFree (pos);
82 		return (1);
83 	    }
84 	  wvStream_goto (fd, offset);
85 	  for (i = 0; i < *noftxbxs + 1; i++)
86 	      (*pos)[i] = read_32ubit (fd);
87 	  for (i = 0; i < *noftxbxs; i++)
88 	      wvGetFTXBXS (&((*ftxbxs)[i]), fd);
89       }
90     return (0);
91 }
92