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