2 Copyright (C) 1994-2007 Frans Slothouber, Jacco van Weert, Petteri Kettunen,
3 Bernd Koesling, Thomas Aglassinger, Anthon Pang, Stefan Kost, David Druffner,
4 Sasha Vasko, Kai Hofmann, Thierry Pierron, Friedrich Haase, and Gergely Budai.
6 This file is part of ROBODoc
8 ROBODoc is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
34 /****h* ROBODoc/Filename
36 * Functions to deal with keeping track
37 * of filenames and directory names.
41 /****f* Filename/RB_Get_RB_Filename
46 struct RB_Filename* RB_Get_RB_Filename( char *arg_filename, struct RB_Path *arg_rb_path )
49 * o arg_rb_filename --
52 * Create a new RB_Filename structure based on arg_filename and
57 struct RB_Filename *rb_filename =
58 ( struct RB_Filename * ) malloc( sizeof( struct RB_Filename ) );
59 rb_filename->name = ( char * ) malloc( strlen( arg_filename ) + 1 );
60 rb_filename->docname = 0;
61 rb_filename->fullname = 0;
62 rb_filename->fulldocname = 0;
63 strcpy( rb_filename->name, arg_filename );
64 rb_filename->path = arg_rb_path;
70 struct RB_Filename *RB_Copy_RB_Filename( struct RB_Filename* arg_rb_filename )
72 return RB_Get_RB_Filename( arg_rb_filename->name, arg_rb_filename->path );
77 RB_Filename_Dump( struct RB_Filename *arg_rb_filename )
79 printf( "[%s %s %s] ", RB_Get_Path( arg_rb_filename ),
80 RB_Get_Filename( arg_rb_filename ),
81 RB_Get_Extension( arg_rb_filename ) );
82 printf( "%s\n", Get_Fullname( arg_rb_filename ) );
85 /*x**f* Filename/RB_Free_RB_Filename
87 * RB_Free_RB_Filename -- free a RB_Filename structure.
94 RB_Free_RB_Filename( struct RB_Filename *arg_rb_filename )
96 free( arg_rb_filename->name );
97 if ( arg_rb_filename->docname )
99 free( arg_rb_filename->docname );
101 if ( arg_rb_filename->fullname )
103 free( arg_rb_filename->fullname );
105 if ( arg_rb_filename->fulldocname )
107 free( arg_rb_filename->fulldocname );
109 free( arg_rb_filename );
112 /* Set the fulldoc name, this is used in singledoc mode
113 * since there the docname is preset by the user and not
114 * derived from the sourcefile name.
117 void RB_Set_FullDocname( struct RB_Filename *arg_rb_filename, char* name )
119 arg_rb_filename->fulldocname = RB_StrDup( name );
122 /* TODO Documentation RB_Get_FullDocname */
124 RB_Get_FullDocname( struct RB_Filename *arg_rb_filename )
126 char *result = arg_rb_filename->fulldocname;
128 if ( result == NULL )
130 unsigned int size = strlen( arg_rb_filename->docname ) +
131 strlen( arg_rb_filename->path->docname ) + 1;
132 result = ( char * ) malloc( size * sizeof( char ) );
135 strcat( result, arg_rb_filename->path->docname );
136 strcat( result, arg_rb_filename->docname );
137 /* Save the result so it can be reused later on, and we can properly deallocate it. */
138 arg_rb_filename->fulldocname = result;
144 /****f* Filename/Get_Fullname
149 char* Get_Fullname( struct RB_Filename *arg_rb_filename )
152 * Give the full name of the file, that is the name of
153 * the file including the extension and the path.
154 * The path can be relative or absolute.
156 * The string returned is owned by this function
157 * so don't change it.
161 char *result = arg_rb_filename->fullname;
163 if ( result == NULL )
165 unsigned int size = strlen( arg_rb_filename->name ) +
166 strlen( arg_rb_filename->path->name ) + 1;
167 result = ( char * ) malloc( size * sizeof( char ) );
170 strcat( result, arg_rb_filename->path->name );
171 strcat( result, arg_rb_filename->name );
172 /* Save the result so it can be reused later on, and we can properly deallocate it. */
173 arg_rb_filename->fullname = result;
179 /****f* Filename/RB_Get_Path
182 char* RB_Get_Path( struct RB_Filename *arg_rb_filename )
185 * Give the path for this file.
187 * The string returned is owned by this function
188 * so don't change it.
192 return arg_rb_filename->path->name;
196 /****f* Filename/RB_Get_Extension
198 * RB_Get_Extension --
200 * Give the extension of this file. That is the part after
201 * the last '.' if there is any.
204 char* RB_Get_Extension( struct RB_Filename *arg_rb_filename )
207 * pointer to the extension
208 * pointer to a '\0' if no extension was found.
210 * The string returned is owned by this function
211 * so don't change it.
215 char *c = arg_rb_filename->name;
218 for ( c += i; c != arg_rb_filename->name && ( *c != '.' ); --c )
228 c = arg_rb_filename->name;
235 /****f* Filename/RB_Get_Filename
239 * Give the name of this file. That is the name
240 * of the file without its path but with the
244 char* RB_Get_Filename( struct RB_Filename *arg_rb_filename )
247 * pointer to the extension
248 * pointer to a '\0' if no extension was found.
250 * The string returned is owned by this function
251 * so don't change it.
255 return arg_rb_filename->name;