DtSearch/raima: remove register keyword
[oweals/cde.git] / cde / lib / DtSearch / raima / recwrite.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 /* $XConsortium: recwrite.c /main/2 1996/05/09 04:16:09 drk $ */
24 /*
25  *   COMPONENT_NAME: austext
26  *
27  *   FUNCTIONS: d_recwrite
28  *
29  *   ORIGINS: 157
30  *
31  *   OBJECT CODE ONLY SOURCE MATERIALS
32  */
33 /*-----------------------------------------------------------------------
34    recwrite.c -- db_VISTA current record write module.
35
36    (C) Copyright 1987 by Raima Corporation.
37 -----------------------------------------------------------------------*/
38
39 /* ********************** EDIT HISTORY *******************************
40
41  SCR    DATE    INI                   DESCRIPTION
42 ----- --------- --- -----------------------------------------------------
43   158 15-JUN-88 RSC passed new flag to key_bldcom
44       04-Aug-88 RTK MULTI_TASK changes
45
46 */
47 #include <stdio.h>
48 #include "vista.h"
49 #include "dbtype.h"
50
51
52 /* Write contents to current record
53 */
54 int
55 d_recwrite(rec TASK_PARM DBN_PARM)
56 CONST char FAR *rec; /* ptr to record area */
57 TASK_DECL
58 DBN_DECL
59 {
60 #ifndef  NO_TIMESTAMP
61    ULONG timestamp;
62 #endif
63    INT  rt;        /* record type */
64    char FAR *fptr;     /* field data pointer */
65    char ckey[256]; /* current compound key data */
66    char nkey[256]; /* new compound key data */
67    int stat;
68    int fld;
69    RECORD_ENTRY FAR *rec_ptr;
70    FIELD_ENTRY FAR *fld_ptr;
71
72    DB_ENTER(DB_ID TASK_ID LOCK_SET(SET_IO));
73
74    if ( ! dbopen ) RETURN( dberr(S_DBOPEN) );
75
76    /* Make sure we have a current record */
77    if ( ! curr_rec )
78       RETURN( dberr(S_NOCR) );
79
80    /* Read current record */
81    if ( dio_read( curr_rec, (char FAR * FAR *)&crloc, PGHOLD) != S_OKAY )
82       RETURN( db_status );
83
84    /* Copy record type from record */
85    bytecpy(&rt, crloc, sizeof(INT));
86    rt &= ~RLBMASK; /* mask off rlb */
87 #ifndef  ONE_DB
88    rt += curr_db_table->rt_offset;
89 #endif
90    rec_ptr = &record_table[rt];
91
92    /* Check out each field before they are changed */
93    for (fld = rec_ptr->rt_fields, fld_ptr = &field_table[fld];
94         (fld < size_fd) && (fld_ptr->fd_rec == rt);
95         ++fld, ++fld_ptr) {
96
97       /* Build compound key for new data supplied by user.  Note: cflag
98          must be the same here as in the 1st key_bldcom for r_chkfld */
99       if ( fld_ptr->fd_type == COMKEY ) {
100          key_bldcom(fld, (char FAR *)rec, nkey, FALSE);
101          fptr = nkey;
102       }
103       else
104          fptr = (char FAR *)rec + fld_ptr->fd_ptr - rec_ptr->rt_data;
105
106       if ( ! (fld_ptr->fd_flags & STRUCTFLD) ) {
107          if ( (stat = r_chkfld(fld, fld_ptr, crloc, fptr)) != S_OKAY ) {
108             dio_release(curr_rec);
109             RETURN( db_status = stat );
110          }
111       }
112    }
113    /* Copy data from rec into crloc */
114    for (fld = (rt == size_rt-1) ? (size_fd - 1) :
115                                   ((rec_ptr + 1)->rt_fields - 1),
116                                                    fld_ptr = &field_table[fld];
117         fld >= rec_ptr->rt_fields;
118         --fld, --fld_ptr) {
119       /* go backwards so comkeys are processed first */
120       if ( fld_ptr->fd_type == COMKEY ) {
121          /* build old and new keys */
122          key_bldcom(fld, crloc + rec_ptr->rt_data, ckey, TRUE);
123          key_bldcom(fld, (char FAR *)rec, nkey, TRUE);
124
125          /* make sure value has changed */
126          if ((fldcmp(fld_ptr, ckey, nkey) != 0) &&
127              /* if the key has been stored */
128              (!(fld_ptr->fd_flags & OPTKEYMASK) || r_tstopt(fld_ptr, crloc))) {
129             /* delete the old key */ 
130             if ( key_delete(fld, ckey, curr_rec) == S_OKAY ) {
131                /* insert the new one */
132                if ( key_insert( fld, nkey, curr_rec ) != S_OKAY )
133                   RETURN( db_status );
134             }
135             else 
136                RETURN( db_status == S_NOTFOUND? dberr(S_KEYERR): db_status );
137          }
138       }
139       else if ( ! (STRUCTFLD & fld_ptr->fd_flags) ) {
140          /* ignore sub-fields of structures */
141          if (r_pfld(fld, fld_ptr, crloc,
142                     rec + fld_ptr->fd_ptr - rec_ptr->rt_data,
143                     &curr_rec) != S_OKAY)  {
144             stat = db_status;
145             dio_release(curr_rec);
146             RETURN( db_status = stat );
147          }
148       }
149    }
150 #ifndef  NO_TIMESTAMP
151    /* check for timestamp */
152    if ( rec_ptr->rt_flags & TIMESTAMPED ) {
153       timestamp = dio_pzgetts(rec_ptr->rt_file);
154       bytecpy( crloc + RECUPTIME, &timestamp, sizeof(LONG));
155    }
156    else
157       timestamp = 0L;
158 #endif
159    /* write current record to page */
160    dio_write(curr_rec, NULL, PGFREE);
161 #ifndef  NO_TIMESTAMP
162    if (( db_status == S_OKAY ) && db_tsrecs )
163       cr_time = timestamp;
164 #endif
165    RETURN( db_status );
166 }
167 /* vpp -nOS2 -dUNIX -nBSD -nVANILLA_BSD -nVMS -nMEMLOCK -nWINDOWS -nFAR_ALLOC -f/usr/users/master/config/nonwin recwrite.c */