OpenIndiana and Solaris port
[oweals/cde.git] / cde / programs / dtinfo / DtMmdb / oliasdb / c_api_book_test.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: c_api_book_test.C /main/5 1996/08/21 15:52:51 drk $ */
24
25 #include "oliasdb/DtMmdb.h"
26 #include <stdio.h>
27
28 extern "C"
29 void showBook(DtMmdbInfoRequest* req)
30 {
31     const char* str = 0;
32     DtMmdbHandle* id = 0;
33     unsigned int l;
34     int x ;
35     DtMmdbHandle** ids;
36
37     if ( req == 0 ) return ;
38
39     str = DtMmdbBookGetShortTitle(req, &l);
40     if ( str )
41        fprintf(stderr, "        bookInfo: shortTitle=%s\n", str);
42
43     str = DtMmdbBookGetLongTitle(req, &l);
44     if ( str )
45        fprintf(stderr, "        bookInfo: longTitle=%s\n", str);
46
47     id = DtMmdbBookGetTocObjectId(req);
48     if ( id )
49         fprintf(stderr, "        bookInfo: TOC section id=%s\n", DtMmdbHandleToString(id));
50     DtMmdbFreeHandle(id);
51
52     x = DtMmdbBookGetSeqNum(req);
53     fprintf(stderr, "        bookInfo: seqnum =%d\n", x);
54
55     str =DtMmdbBookGetSeqLIcense(req, &l);
56     if ( str )
57        fprintf(stderr, "        bookInfo: license term=%s\n", str);
58
59     ids = DtMmdbBookGetTabList(req, &l);
60     if (ids) {
61       for ( x=0; x<(int)l; x++ )
62         fprintf(stderr, "        bookInfo: tab section id=%s\n", DtMmdbHandleToString(ids[x]));
63     }
64     DtMmdbFreeHandleList(ids);
65 }
66
67 /*  TOC section's oid ask key */
68 extern "C"
69 int test_book1(int argc, char** argv)
70 {
71    int j = 0;
72    int i = -1;
73    DtMmdbInfoRequest* req = 0;
74
75    switch ( argc ) {
76      case 5:
77       {
78        i = DtMmdbOpenInfoLib(argv[2], argv[3], DtMmdbFalse);
79        j = DtMmdbGetBookCaseByName(i, argv[3]);
80
81        req = newDtMmdbInfoRequestWithPrimaryOid(j, argv[4]);
82        showBook(req);
83
84        DtMmdbFreeInfoRequest(req);
85        DtMmdbCloseInfoLib(i);
86
87        break;
88       }
89      default:
90        fprintf(stderr, "invalid arguments\n");
91    }
92
93    fprintf(stderr, "infolib desc=%d\n", i);
94    return 0;
95 }
96
97 /* book's oid as key */
98 extern "C"
99 int test_book2(int argc, char** argv)
100 {
101    int j = 0;
102    int i = -1;
103    DtMmdbInfoRequest* req = 0;
104
105    switch ( argc ) {
106      case 5:
107       {
108        i = DtMmdbOpenInfoLib(argv[2], argv[3], DtMmdbFalse);
109        j = DtMmdbGetBookCaseByName(i, argv[3]);
110
111        req = newDtMmdbInfoRequestWithSecondaryOid(j, argv[4]);
112        showBook(req);
113
114        DtMmdbFreeInfoRequest(req);
115        DtMmdbCloseInfoLib(i);
116
117        break;
118       }
119       default:
120        fprintf(stderr, "invalid arguments\n");
121    }
122
123    fprintf(stderr, "infolib desc=%d\n", i);
124    return 0;
125 }
126
127 /* book's seq number as key */
128 extern "C"
129 int test_book3(int argc, char** argv)
130 {
131    int j = 0;
132    int i = -1;
133    DtMmdbInfoRequest* req = 0;
134
135    switch ( argc ) {
136      case 5:
137       {
138        i = DtMmdbOpenInfoLib(argv[2], argv[3], DtMmdbFalse);
139        j = DtMmdbGetBookCaseByName(i, argv[3]);
140
141        req = newDtMmdbInfoRequestWithSeqnum(j, argv[4]);
142        showBook(req);
143
144        DtMmdbFreeInfoRequest(req);
145        DtMmdbCloseInfoLib(i);
146
147        break;
148       }
149       default:
150        fprintf(stderr, "invalid arguments\n");
151    }
152
153    fprintf(stderr, "infolib desc=%d\n", i);
154    return 0;
155 }
156