File: path.c

package info (click to toggle)
robodoc 4.99.40-1
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 1,560 kB
  • ctags: 978
  • sloc: ansic: 14,067; sh: 3,711; perl: 155; makefile: 108
file content (137 lines) | stat: -rw-r--r-- 3,702 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/*
Copyright (C) 1994-2007  Frans Slothouber, Jacco van Weert, Petteri Kettunen,
Bernd Koesling, Thomas Aglassinger, Anthon Pang, Stefan Kost, David Druffner,
Sasha Vasko, Kai Hofmann, Thierry Pierron, Friedrich Haase, and Gergely Budai.

This file is part of ROBODoc

ROBODoc is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.

*/

#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include "path.h"
#include "robodoc.h"
#include "headers.h"
#include "util.h"

#ifdef DMALLOC
#include <dmalloc.h>
#endif

/* TODO Documentation */

struct RB_Path     *
RB_Get_RB_Path( char *arg_pathname )
{
    struct RB_Path     *rb_path;
    int                 needs_slash = FALSE;

    if ( strlen( arg_pathname ) == 0 )
    {
        RB_Panic( "Trying to use a path with as name \"\"\n" );
        return 0;               /* Keep the compiler happy. */
    }
    else
    {
        /* Check if the path ends with a / if not we will need to add one. */
        needs_slash = ( arg_pathname[strlen( arg_pathname ) - 1] != '/' );
        rb_path = ( struct RB_Path * ) malloc( sizeof( struct RB_Path ) );

        if ( ! rb_path )
        {
            RB_Panic( "Out of memory! %s()\n", "RB_Get_RB_Path" );
        }

        /* 2 extra for the '/' and '\0'  */
        rb_path->name =
            ( char * ) calloc( strlen( arg_pathname ) + 2, sizeof( char ) );

        if ( ! rb_path->name )
        {
            RB_Panic( "Out of memory! %s()\n", "RB_Get_RB_Path" );
        }

        *( rb_path->name ) = '\0';
        rb_path->parent = NULL;
        rb_path->next = NULL;
        strcat( rb_path->name, arg_pathname );
        if ( needs_slash )
        {
            strcat( rb_path->name, "/" );
        }
        rb_path->docname = NULL;
    }
    return rb_path;
}

/*x**f* ROBODoc/RB_Get_RB_Path2
 * NAME
 *   RB_Get_RB_Path2 -- create a new RB_Path structure.
 * FUNCTION
 * NOTE
 *   Has a wrong name...
 *****
 */

/* TODO Documentation */
struct RB_Path     *
RB_Get_RB_Path2( char *arg_current_path, char *arg_subdirectory )
{
    struct RB_Path     *rb_path;
    rb_path = ( struct RB_Path * ) malloc( sizeof( struct RB_Path ) );
    /* allocate memory for the path name,
       it will consist of the current_pathname plus the
       subdirectory plus a '\0' */
    rb_path->name =
        ( char * ) malloc( strlen( arg_current_path ) +
                           strlen( arg_subdirectory ) + 2 );

    if ( ! rb_path->name )
    {
        RB_Panic( "Out of memory! %s()\n", "RB_Get_RB_Path2" );
    }

    strcpy( rb_path->name, arg_current_path );
    strcat( rb_path->name, arg_subdirectory );
    if ( arg_subdirectory[strlen( arg_subdirectory ) - 1] != '/' )
    {
        strcat( rb_path->name, "/" );
    }
    rb_path->docname = NULL;
    rb_path->parent = NULL;
    rb_path->next = 0;
    return rb_path;
}

/*x**f* ROBODoc/RB_Free_RB_Path
 * NAME
 *   RB_Free_RB_Path -- free a RB_Path structure.
 *****
 * TODO Documentation
 */

void
RB_Free_RB_Path( struct RB_Path *arg_rb_path )
{
    free( arg_rb_path->name );
    if ( arg_rb_path->docname )
    {
        free( arg_rb_path->docname );
    }
    free( arg_rb_path );
}