Add GNU LGPL headers to all .c .C and .h files
[oweals/cde.git] / cde / programs / dtinfo / dtinfo / src / UAS / Base / UAS_BookcaseEntry.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 // $TOG: UAS_BookcaseEntry.C /main/5 1998/04/17 11:40:44 mgreess $
24 #include "UAS_BookcaseEntry.hh"
25
26 #include <string.h>
27
28 static const char *
29 UASbasename(const char *path)
30 {
31     if (!path)
32         return NULL;
33
34     const char *p;
35
36     for (p = path + strlen(path) - 1; *p != '/' && p != path; p--);
37
38     if (*p == '/')
39         p++;
40
41     return p;
42 }
43
44
45 // /////////////////////////////////////////////////////////////////
46 // UAS_BookcaseEntry - ctor, dtor
47 // /////////////////////////////////////////////////////////////////
48
49 UAS_BookcaseEntry::UAS_BookcaseEntry(UAS_Pointer<UAS_Common> &bookcase,
50                                      int searchable) 
51 : f_searchable(searchable),
52   f_name(0),
53   f_base_num(-1)
54 {
55     const char *bc_path = bookcase->id();
56     if (! bc_path) {
57         f_name = f_path = NULL;
58     }
59     else {
60
61         const char *bc_name = UASbasename(bc_path);
62
63         f_name = new char[strlen(bc_name)+1];
64         strcpy(f_name, bc_name);
65
66         f_path = new char[strlen(bc_path)+1];
67         strcpy (f_path, bc_path);
68     }
69
70    f_infolib_id  = bookcase->lid();
71    f_bookcase_id = bookcase->bid();
72 }
73
74 UAS_BookcaseEntry::~UAS_BookcaseEntry()
75 {
76     if (f_name) delete f_name;
77     if (f_path) delete f_path;
78 }
79
80
81 void
82 UAS_BookcaseEntry::set_book_list (UAS_ObjList<int> &list)
83
84     f_book_list = list;         // replace it 
85 }