Merge branch 'master' into cde-next
[oweals/cde.git] / cde / lib / tt / mini_isam / isfname.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 /*%%  (c) Copyright 1993, 1994 Hewlett-Packard Company                   */
24 /*%%  (c) Copyright 1993, 1994 International Business Machines Corp.     */
25 /*%%  (c) Copyright 1993, 1994 Sun Microsystems, Inc.                    */
26 /*%%  (c) Copyright 1993, 1994 Novell, Inc.                              */
27 /*%%  $XConsortium: isfname.c /main/3 1995/10/23 11:40:04 rswiston $                                                     */
28 /*
29  * Copyright (c) 1988 by Sun Microsystems, Inc.
30  */
31
32 /*
33  * isfname.c
34  *
35  * Description:
36  *      Functions to translate ISAM file name to .rec, .ind, and .var file
37  *      names. Also, several auxiliary functions that deal with path names.
38  *
39  */
40
41 #include "isam_impl.h"
42
43 void _removelast();
44 char *_lastelement();
45
46 /*
47  * _makedat_isfname(isfname)
48  *
49  * Return path to .rec file corresponding to the ISAM file isfname.
50  * Conversion is done in place.
51  */
52
53 void
54 _makedat_isfname(char *isfname)
55 {
56     /* Append .rec */
57     (void) strcat(isfname, DAT_SUFFIX);
58 }
59
60 /*
61  * _makeind_isfname(isfname)
62  *
63  * Return path to .ind file corresponding to the ISAM file isfname.
64  * Conversion is done in place.
65  */
66
67 void
68 _makeind_isfname(char *isfname)
69 {
70     /* Append .ind */
71     (void) strcat(isfname, IND_SUFFIX);
72 }
73
74 /*
75  * _makevar_isfname(isfname)
76  *
77  * Return path to .var file corresponding to the ISAM file isfname.
78  * Conversion is done in place.
79  */
80
81 void
82 _makevar_isfname(char *isfname)
83 {
84     /* Append .var */
85     (void) strcat(isfname, VAR_SUFFIX);
86 }
87
88
89 /*
90  * _removelast(path)
91  *
92  * Remove last element of path. E.g. /usr/db/part yields /usr/db.
93  */
94
95 void
96 _removelast(char *path)
97 {
98     char        *p;
99
100     for (p = path + strlen(path); *--p != '/' && p >= path; ) 
101         *p = '\0';
102 }
103
104 /*
105  * _lastelement(path)
106  *
107  * Return pointer to the last element in the path. 
108  * E.g.: _lastelement("/usr/temp") returns "temp".
109  */
110
111 char *
112 _lastelement(char *path)
113 {
114     register    char    *p;
115     
116     p = path + strlen(path);
117
118     while (*--p != '/' && p > path)
119         { ; }
120
121     return ((*p == '/') ? (p + 1) : p);
122 }