a61e5220eafd5d9a6b5d5206890d6208daf3082b
[oweals/cde.git] / cde / lib / tt / mini_isam / isindexconv.c
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these libraries and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 /*%%  (c) Copyright 1993, 1994 Hewlett-Packard Company                   */
24 /*%%  (c) Copyright 1993, 1994 International Business Machines Corp.     */
25 /*%%  (c) Copyright 1993, 1994 Sun Microsystems, Inc.                    */
26 /*%%  (c) Copyright 1993, 1994 Novell, Inc.                              */
27 /*%%  $XConsortium: isindexconv.c /main/3 1995/10/23 11:40:48 rswiston $                                                         */
28 #ifndef lint
29 static char sccsid[] = "@(#)isindexconv.c 1.3 89/07/17 Copyr 1988 Sun Micro";
30 #endif
31 /*
32  * Copyright (c) 1988 by Sun Microsystems, Inc.
33  */
34
35 /*
36  * isindexconv.c
37  *
38  * Description:
39  *      Encode/decode key descriptor
40  */
41
42 #include "isam_impl.h"
43
44 void
45 stkey(Keydesc2 *pkeydesc2, char *p)
46 {
47     int                         i;
48     struct keypart2     *ppart;
49     char               *pp;
50     int                         nparts;
51
52     stshort(pkeydesc2->k2_flags, p + K2_FLAGS_OFF);
53     stshort(pkeydesc2->k2_nparts, p + K2_NPARTS_OFF);
54     stshort(pkeydesc2->k2_len, p + K2_LEN_OFF);
55     stblkno(pkeydesc2->k2_rootnode, p + K2_ROOT_OFF);
56     stlong((long)pkeydesc2->k2_keyid, p + K2_KEYID_OFF);
57
58     ppart = pkeydesc2->k2_part;
59     pp    = p + K2_KEYPART_OFF;
60     nparts = pkeydesc2->k2_nparts + 1;       /* +1 for recno part */
61
62     if (ALLOWS_DUPS2(pkeydesc2))             /* +1 for dups serial number*/
63         nparts++;
64  
65     for (i = 0; i < nparts;i++) {
66         stshort(ppart->kp2_start, pp);
67         pp += SHORTSIZE;
68  
69         stshort(ppart->kp2_leng, pp);
70         pp += SHORTSIZE;
71  
72         stshort(ppart->kp2_type, pp);
73         pp += SHORTSIZE;
74  
75         stshort(ppart->kp2_offset, pp);
76         pp += SHORTSIZE;
77         
78         ppart++;
79     }
80 }      
81
82 void
83 ldkey(struct keydesc2 *pkeydesc2, char *p)
84 {
85     int                         i;
86     struct keypart2    *ppart;
87     char               *pp;
88     int                         nparts;
89
90     memset ((char *) pkeydesc2, 0, sizeof (*pkeydesc2));
91     pkeydesc2->k2_flags = ldshort(p + K2_FLAGS_OFF);
92     pkeydesc2->k2_nparts = ldshort(p + K2_NPARTS_OFF);
93     pkeydesc2->k2_len = ldshort(p + K2_LEN_OFF);
94     pkeydesc2->k2_rootnode = ldblkno(p + K2_ROOT_OFF);
95     pkeydesc2->k2_keyid = ldlong(p + K2_KEYID_OFF);
96
97     ppart = pkeydesc2->k2_part;
98     pp    = p + K2_KEYPART_OFF;
99     nparts = pkeydesc2->k2_nparts + 1;       /* +1 for recno part */
100
101     if (ALLOWS_DUPS2(pkeydesc2))             /* +1 for dups serial number*/
102         nparts++;
103
104     for (i = 0; i < nparts;i++) {
105         ppart->kp2_start = ldunshort(pp);
106         pp += SHORTSIZE;
107
108         ppart->kp2_leng = ldshort(pp);
109         pp += SHORTSIZE;
110
111         ppart->kp2_type = ldshort(pp);
112         pp += SHORTSIZE;
113
114         ppart->kp2_offset = ldunshort(pp);
115         pp += SHORTSIZE;
116         
117         ppart++;
118     }
119 }