2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
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)
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
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
23 /* $XConsortium: recwrite.c /main/2 1996/05/09 04:16:09 drk $ */
25 * COMPONENT_NAME: austext
27 * FUNCTIONS: d_recwrite
31 * OBJECT CODE ONLY SOURCE MATERIALS
33 /*-----------------------------------------------------------------------
34 recwrite.c -- db_VISTA current record write module.
36 (C) Copyright 1987 by Raima Corporation.
37 -----------------------------------------------------------------------*/
39 /* ********************** EDIT HISTORY *******************************
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
52 /* Write contents to current record
55 d_recwrite(rec TASK_PARM DBN_PARM)
56 CONST char FAR *rec; /* ptr to record area */
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 */
69 RECORD_ENTRY FAR *rec_ptr;
70 FIELD_ENTRY FAR *fld_ptr;
72 DB_ENTER(DB_ID TASK_ID LOCK_SET(SET_IO));
74 if ( ! dbopen ) RETURN( dberr(S_DBOPEN) );
76 /* Make sure we have a current record */
78 RETURN( dberr(S_NOCR) );
80 /* Read current record */
81 if ( dio_read( curr_rec, (char FAR * FAR *)&crloc, PGHOLD) != S_OKAY )
84 /* Copy record type from record */
85 bytecpy(&rt, crloc, sizeof(INT));
86 rt &= ~RLBMASK; /* mask off rlb */
88 rt += curr_db_table->rt_offset;
90 rec_ptr = &record_table[rt];
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);
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);
104 fptr = (char FAR *)rec + fld_ptr->fd_ptr - rec_ptr->rt_data;
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 );
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;
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);
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 )
136 RETURN( db_status == S_NOTFOUND? dberr(S_KEYERR): db_status );
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) {
145 dio_release(curr_rec);
146 RETURN( db_status = stat );
151 /* check for timestamp */
152 if ( rec_ptr->rt_flags & TIMESTAMPED ) {
153 timestamp = dio_pzgetts(rec_ptr->rt_file);
154 bytecpy( crloc + RECUPTIME, ×tamp, sizeof(LONG));
159 /* write current record to page */
160 dio_write(curr_rec, NULL, PGFREE);
162 if (( db_status == S_OKAY ) && db_tsrecs )
167 /* vpp -nOS2 -dUNIX -nBSD -nVANILLA_BSD -nVMS -nMEMLOCK -nWINDOWS -nFAR_ALLOC -f/usr/users/master/config/nonwin recwrite.c */