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/>.
35 /* TODO Documentation */
38 RB_Get_RB_Path( char *arg_pathname )
40 struct RB_Path *rb_path;
41 int needs_slash = FALSE;
43 if ( strlen( arg_pathname ) == 0 )
45 RB_Panic( "Trying to use a path with as name \"\"\n" );
46 return 0; /* Keep the compiler happy. */
50 /* Check if the path ends with a / if not we will need to add one. */
51 needs_slash = ( arg_pathname[strlen( arg_pathname ) - 1] != '/' );
52 rb_path = ( struct RB_Path * ) malloc( sizeof( struct RB_Path ) );
56 RB_Panic( "Out of memory! %s()\n", "RB_Get_RB_Path" );
59 /* 2 extra for the '/' and '\0' */
61 ( char * ) calloc( strlen( arg_pathname ) + 2, sizeof( char ) );
63 if ( ! rb_path->name )
65 RB_Panic( "Out of memory! %s()\n", "RB_Get_RB_Path" );
68 *( rb_path->name ) = '\0';
69 rb_path->parent = NULL;
71 strcat( rb_path->name, arg_pathname );
74 strcat( rb_path->name, "/" );
76 rb_path->docname = NULL;
81 /*x**f* ROBODoc/RB_Get_RB_Path2
83 * RB_Get_RB_Path2 -- create a new RB_Path structure.
90 /* TODO Documentation */
92 RB_Get_RB_Path2( char *arg_current_path, char *arg_subdirectory )
94 struct RB_Path *rb_path;
95 rb_path = ( struct RB_Path * ) malloc( sizeof( struct RB_Path ) );
96 /* allocate memory for the path name,
97 it will consist of the current_pathname plus the
98 subdirectory plus a '\0' */
100 ( char * ) malloc( strlen( arg_current_path ) +
101 strlen( arg_subdirectory ) + 2 );
103 if ( ! rb_path->name )
105 RB_Panic( "Out of memory! %s()\n", "RB_Get_RB_Path2" );
108 strcpy( rb_path->name, arg_current_path );
109 strcat( rb_path->name, arg_subdirectory );
110 if ( arg_subdirectory[strlen( arg_subdirectory ) - 1] != '/' )
112 strcat( rb_path->name, "/" );
114 rb_path->docname = NULL;
115 rb_path->parent = NULL;
120 /*x**f* ROBODoc/RB_Free_RB_Path
122 * RB_Free_RB_Path -- free a RB_Path structure.
128 RB_Free_RB_Path( struct RB_Path *arg_rb_path )
130 free( arg_rb_path->name );
131 if ( arg_rb_path->docname )
133 free( arg_rb_path->docname );