d677b52164237da93665e62bdbf0ea18f68211c3
[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 #ifndef lint
29 static char sccsid[] = "@(#)isfname.c 1.3 89/07/17 Copyr 1988 Sun Micro";
30 #endif
31 /*
32  * Copyright (c) 1988 by Sun Microsystems, Inc.
33  */
34
35 /*
36  * isfname.c
37  *
38  * Description:
39  *      Functions to translate ISAM file name to .rec, .ind, and .var file
40  *      names. Also, several auxiliary functions that deal with path names.
41  *
42  */
43
44 #include "isam_impl.h"
45
46 void _removelast();
47 char *_lastelement();
48
49 /*
50  * _makedat_isfname(isfname)
51  *
52  * Return path to .rec file corresponding to the ISAM file isfname.
53  * Conversion is done in place.
54  */
55
56 void
57 _makedat_isfname(char *isfname)
58 {
59     /* Append .rec */
60     (void) strcat(isfname, DAT_SUFFIX);
61 }
62
63 /*
64  * _makeind_isfname(isfname)
65  *
66  * Return path to .ind file corresponding to the ISAM file isfname.
67  * Conversion is done in place.
68  */
69
70 void
71 _makeind_isfname(char *isfname)
72 {
73     /* Append .ind */
74     (void) strcat(isfname, IND_SUFFIX);
75 }
76
77 /*
78  * _makevar_isfname(isfname)
79  *
80  * Return path to .var file corresponding to the ISAM file isfname.
81  * Conversion is done in place.
82  */
83
84 void
85 _makevar_isfname(char *isfname)
86 {
87     /* Append .var */
88     (void) strcat(isfname, VAR_SUFFIX);
89 }
90
91
92 /*
93  * _removelast(path)
94  *
95  * Remove last element of path. E.g. /usr/db/part yields /usr/db.
96  */
97
98 void
99 _removelast(char *path)
100 {
101     char        *p;
102
103     for (p = path + strlen(path); *--p != '/' && p >= path; ) 
104         *p = '\0';
105 }
106
107 /*
108  * _lastelement(path)
109  *
110  * Return pointer to the last element in the path. 
111  * E.g.: _lastelement("/usr/temp") returns "temp".
112  */
113
114 char *
115 _lastelement(char *path)
116 {
117     register    char    *p;
118     
119     p = path + strlen(path);
120
121     while (*--p != '/' && p > path)
122         { ; }
123
124     return ((*p == '/') ? (p + 1) : p);
125 }