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