tt/mini_isam: remove all ancient sccsid blocks
[oweals/cde.git] / cde / lib / tt / mini_isam / iskeyaux.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: iskeyaux.c /main/3 1995/10/23 11:41:11 rswiston $                                                    */
28 /*
29  * Copyright (c) 1988 by Sun Microsystems, Inc.
30  */
31
32
33 /*
34  * iskeyaux.c
35  *
36  * Description:
37  *      Auxiliary key related functions
38  */
39
40 #include "isam_impl.h"
41
42 Blkno _isgetfreekpage();
43
44 /* 
45  * _isindex_extract() 
46  *
47  * Extract key parts from record buffer
48  */
49
50 void
51 _iskey_extract (Keydesc2 *pkeydesc2, char *recp, char *keyp)
52 {
53     int         i;
54     struct keypart2 *ppart;
55     int                 nparts;
56
57     nparts = pkeydesc2->k2_nparts;
58     ppart = pkeydesc2->k2_part;
59
60     /*
61      * XXX - This is a kludge to fix a problem with keys of an odd (ODD as
62      * not even) length that are extended to the nearest multiple of 2.
63      *
64      * It would be better to use bzero() here and not to call it in
65      * add1key etc. But this change was done just during the FCS process
66      * and may be robust even though it's not the cleanest thing under
67      * the sun.
68      */
69
70     keyp[pkeydesc2->k2_len - 1] = '\0';
71
72     for (i = 0; i < nparts; i++) {
73         memcpy( keyp + ppart->kp2_offset,recp + ppart->kp2_start,
74                ppart->kp2_leng);
75         ppart++;
76     }
77 }
78
79 /*
80  * _allockpage()
81  *
82  * Allocate an initialize new key page.
83  * 
84  * blkno, Output parameter
85  */
86
87 Bufhdr *
88 _allockpage(Fcb *fcb, int capac, int level, Blkno *blkno)
89 {
90     Bufhdr              *pbufhdr;
91     char                *p;
92
93     *blkno = _isindfreel_alloc(fcb);
94
95     /* Fix the block in cache */
96     pbufhdr = _isdisk_fix(fcb, fcb->indfd, *blkno, ISFIXNOREAD);
97     
98     p = pbufhdr->isb_buffer;
99
100     memset(p, 0, ISPAGESIZE);
101
102     /* Mark page as B-tree page. */
103     stshort((short)PT_INDEX, p + BT_TYPE_OFF);
104
105     /* Store page capacity. */
106     stshort((short)capac, p + BT_CAPAC_OFF);
107
108     /* Store B-tree level. */
109     stshort((short)level, p + BT_LEVEL_OFF);
110
111     return (pbufhdr);
112 }