Add GNU LGPL headers to all .c .C and .h files
[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 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 /*%%  (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(isfname)
58     char        *isfname;
59 {
60     /* Append .rec */
61     (void) strcat(isfname, DAT_SUFFIX);
62 }
63
64 /*
65  * _makeind_isfname(isfname)
66  *
67  * Return path to .ind file corresponding to the ISAM file isfname.
68  * Conversion is done in place.
69  */
70
71 void
72 _makeind_isfname(isfname)
73     char        *isfname;
74 {
75     /* Append .ind */
76     (void) strcat(isfname, IND_SUFFIX);
77 }
78
79 /*
80  * _makevar_isfname(isfname)
81  *
82  * Return path to .var file corresponding to the ISAM file isfname.
83  * Conversion is done in place.
84  */
85
86 void
87 _makevar_isfname(isfname)
88     char        *isfname;
89 {
90     /* Append .var */
91     (void) strcat(isfname, VAR_SUFFIX);
92 }
93
94
95 /*
96  * _removelast(path)
97  *
98  * Remove last element of path. E.g. /usr/db/part yields /usr/db.
99  */
100
101 void
102 _removelast(path)
103     char                *path;
104 {
105     register char       *p;
106
107     for (p = path + strlen(path); *--p != '/' && p >= path; ) 
108         *p = '\0';
109 }
110
111 /*
112  * _lastelement(path)
113  *
114  * Return pointer to the last element in the path. 
115  * E.g.: _lastelement("/usr/temp") returns "temp".
116  */
117
118 char *
119 _lastelement(path)
120     char        *path;
121 {
122     register    char    *p;
123     
124     p = path + strlen(path);
125
126     while (*--p != '/' && p > path)
127         { ; }
128
129     return ((*p == '/') ? (p + 1) : p);
130 }