Add GNU LGPL headers to all .c .C and .h files
[oweals/cde.git] / cde / lib / DtSearch / dtsrswab.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 /*
24  *   COMPONENT_NAME: austext
25  *
26  *   FUNCTIONS: swab_dbrec
27  *              swab_objrec
28  *
29  *   ORIGINS: 27
30  *
31  *   (C) COPYRIGHT International Business Machines Corp. 1996
32  *   All Rights Reserved
33  *   Licensed Materials - Property of IBM
34  *   US Government Users Restricted Rights - Use, duplication or
35  *   disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
36  */
37 /********************* DTSRSWAB.C **********************************
38  * $XConsortium: dtsrswab.c /main/2 1996/10/28 13:58:11 drk $
39  * July 1996.
40  * These functions byte swap and other manipulations on
41  * DtSearch or_...  structures to ensure that database records
42  * are maintained in a canonical format no matter what machine
43  * they are used on.
44  * The functions use the standard htonl, htons, ntohl, and ntohs
45  * network conversion functions for byte order neutrality.
46  * They use the DtSrINT16 and DtSrINT32 typedefs in Search.h
47  * to control integer size.
48  * The external database records are in the canonical,
49  * big-endian "network" order.
50  * So that they can be defined as "null" macros on big endian machines,
51  * the functions (1) always byte swap in place and  (2) always succeed.
52  *
53  * $Log$
54  */
55 #include "SearchP.h"
56
57 /********************************/
58 /*                              */
59 /*          swab_objrec         */
60 /*                              */
61 /********************************/
62 void    swab_objrec (struct or_objrec *rec,  SWABDIR direction)
63 {
64 #ifndef BYTE_SWAP
65     return;
66 #else
67     if (direction == NTOH) {
68         NTOHL (rec->or_objflags);
69         NTOHL (rec->or_objuflags);
70         NTOHL (rec->or_objsize);
71         NTOHL (rec->or_objdate);
72         NTOHL (rec->or_objsecmask);
73
74         NTOHS (rec->or_objaccess);
75         NTOHS (rec->or_objtype);
76         NTOHS (rec->or_objcost);
77         NTOHS (rec->or_objhdroffset);
78         NTOHS (rec->or_objeureka);
79     }
80     else {      /* going the other direction */
81         HTONL (rec->or_objflags);
82         HTONL (rec->or_objuflags);
83         HTONL (rec->or_objsize);
84         HTONL (rec->or_objdate);
85         HTONL (rec->or_objsecmask);
86
87         HTONS (rec->or_objaccess);
88         HTONS (rec->or_objtype);
89         HTONS (rec->or_objcost);
90         HTONS (rec->or_objhdroffset);
91         HTONS (rec->or_objeureka);
92     }
93     return;
94 #endif /* BYTE_SWAP */
95 }  /* swab_objrec() */
96
97
98 /********************************/
99 /*                              */
100 /*          swab_dbrec          */
101 /*                              */
102 /********************************/
103 void    swab_dbrec (struct or_dbrec *rec,  SWABDIR direction)
104 {
105 #ifndef BYTE_SWAP
106     return;
107 #else
108     if (direction == NTOH) {
109         NTOHL (rec->or_dbflags);
110         NTOHL (rec->or_dbuflags);
111         NTOHL (rec->or_reccount);
112         NTOHL (rec->or_maxdba);
113         NTOHL (rec->or_availd99);
114         NTOHL (rec->or_unavaild99);
115         NTOHL (rec->or_hufid);
116         NTOHL (rec->or_dbsecmask);
117
118         NTOHS (rec->or_dbotype);
119         NTOHS (rec->or_compflags);
120         NTOHS (rec->or_dbaccess);
121         NTOHS (rec->or_minwordsz);
122         NTOHS (rec->or_maxwordsz);
123         NTOHS (rec->or_recslots);
124         NTOHS (rec->or_fzkeysz);
125         NTOHS (rec->or_abstrsz);
126         NTOHS (rec->or_language);
127     }
128
129     else {      /* going the other direction */
130         HTONL (rec->or_dbflags);
131         HTONL (rec->or_dbuflags);
132         HTONL (rec->or_reccount);
133         HTONL (rec->or_maxdba);
134         HTONL (rec->or_availd99);
135         HTONL (rec->or_unavaild99);
136         HTONL (rec->or_hufid);
137         HTONL (rec->or_dbsecmask);
138
139         HTONS (rec->or_dbotype);
140         HTONS (rec->or_compflags);
141         HTONS (rec->or_dbaccess);
142         HTONS (rec->or_minwordsz);
143         HTONS (rec->or_maxwordsz);
144         HTONS (rec->or_recslots);
145         HTONS (rec->or_fzkeysz);
146         HTONS (rec->or_abstrsz);
147         HTONS (rec->or_language);
148     }
149     return;
150 #endif /* BYTE_SWAP */
151 }  /* swab_dbrec() */
152
153 /********************* DTSRSWAB.C **********************************/