Add GNU LGPL headers to all .c .C and .h files
[oweals/cde.git] / cde / lib / DtSearch / raima / recfrst.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 librararies 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 /* $XConsortium: recfrst.c /main/2 1996/05/09 04:14:13 drk $ */
24 /*
25  *   COMPONENT_NAME: austext
26  *
27  *   FUNCTIONS: d_recfrst
28  *
29  *   ORIGINS: 157
30  *
31  *   OBJECT CODE ONLY SOURCE MATERIALS
32  */
33 /* ********************** EDIT HISTORY *******************************
34
35  SCR    DATE    INI                   DESCRIPTION
36 ----- --------- --- -----------------------------------------------------
37   101 21-Jun-88 RSC Saved type and computed dba into rn_type and rn_dba
38   103 24-Jun-88 RSC Improve generation of single user version
39       04-Aug-88 RTK MULTI_TASK changes
40       18-Aug-88 RSC moved rn_type/dba to separate table
41
42 */
43
44 #include <stdio.h>
45 #include "vista.h"
46 #include "dbtype.h"
47
48
49 /* Find first record of type
50 */
51 d_recfrst( rec TASK_PARM DBN_PARM )
52 int rec;        /* record type/table entry */
53 TASK_DECL
54 DBN_DECL
55 {
56    INT rectype;
57    FILE_NO ftype;
58    DB_ADDR dba;
59    char FAR *recptr;
60 #ifndef SINGLE_USER
61    int dbopen_sv;
62 #endif
63    F_ADDR rno, last;
64    RECORD_ENTRY FAR *rec_ptr;
65
66    DB_ENTER(DB_ID TASK_ID LOCK_SET(RECORD_IO));
67
68    if (nrec_check(rec, &rec, (RECORD_ENTRY FAR * FAR *)&rec_ptr) != S_OKAY)
69       RETURN( db_status );
70 #ifndef  ONE_DB
71    rec -= curr_db_table->rt_offset;
72 #endif
73
74    /* get the normalized number of file containing this record type */
75    ftype = NUM2EXT(rec_ptr->rt_file, ft_offset);
76
77    if ( (last = dio_pznext(rec_ptr->rt_file)) <= 0 )
78       RETURN( db_status );
79
80    rno = 1;
81    do {
82       /* make sure we haven't gone past the end of the file */
83       if ( rno >= last ) RETURN( db_status = S_NOTFOUND );
84
85       /* create the database address to read */
86       dba = ( (FILEMASK & ftype) << FILESHIFT ) | (ADDRMASK & rno);
87
88       /* set up to allow unlocked read */
89 #ifndef SINGLE_USER
90       dbopen_sv = dbopen;
91       dbopen = 2;
92 #endif
93
94       /* read the record */
95       dio_read( dba, (char FAR * FAR *)&recptr, NOPGHOLD );
96 #ifndef SINGLE_USER
97       dbopen = dbopen_sv;
98 #endif
99       if ( db_status != S_OKAY )
100          RETURN( db_status );
101
102       /* get the record type out of the record */
103       bytecpy( &rectype, recptr, sizeof(INT) );
104 #ifndef SINGLE_USER
105       rectype &= ~RLBMASK;
106 #endif
107
108       ++rno;
109    } while ( (int)rectype != rec );
110
111    /* set the current record and type */
112    curr_rec = dba;
113    RN_REF(rn_type) = rectype;
114    RN_REF(rn_dba) = dba;
115
116    RETURN( db_status = S_OKAY );
117 }
118 /* vpp -nOS2 -dUNIX -nBSD -nVANILLA_BSD -nVMS -nMEMLOCK -nWINDOWS -nFAR_ALLOC -f/usr/users/master/config/nonwin recfrst.c */