File: gpath.h

package info (click to toggle)
rdiff-backup-fs 1.0.0-8
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 952 kB
  • sloc: sh: 3,800; ansic: 2,944; makefile: 23
file content (144 lines) | stat: -rw-r--r-- 3,816 bytes parent folder | download | duplicates (4)
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
138
139
140
141
142
143
144
#ifndef _GPATH_H_
#define _GPATH_H_

// #define GPATH_DEBUG

#include "../headers.h"
#include "gstring.h"

/*
 * for given path creates new one without multiple '/' and '/' at the end and
 * on the begining of the string
 *
 * @1: location where original string is stored;
 * @2: location where modified string should be copied;
 * @3: length of the original string;
 * @4: length of the modified string;
 */
#define gpthcln(source, dest, len, new_len) {					\
	    dest = calloc(len + 1, sizeof(char));					\
	    int i = 0;												\
	    int j = 0;												\
	    while ((i < len) && (source[i] == '/'))				\
			i++;												\
	    for (; i < len; i++)									\
			if ((source[i] != '/') || (source[i + 1] != '/')){	\
		    	dest[j] = source[i];							\
		    	j = j + 1;										\
	        };													\
	    if (dest[j - 1] == '/')								\
			dest[j - 1] = 0;									\
	    new_len = strlen(dest);									\
	}

/*
 * for given path finds the most nested entry and copies it to the given location;
 *
 * @1: pointer to the location, where entry should be copied;
 * @2: path which is scrutinized;
 *
 * returns: 0 on success and -1 otherwise;
 */
int gpthcld(char **, char *);

/* 
 * for given path finds the most nested entry and sets another point at this place;
 *
 * @1: pointer to a string pointer, that will point at the beginning of the entry;
 * @2: path which is scrutinized;
 *
 * returns: 0 on success and -1 otherwise;
 */
int gpthcldptr(char **, char *);

/*
 * for given path of an archive turns it into path without the archive extensions; it doesn't unpack the file;
 *
 * @1: pointer to the string holding the path;
 *
 * returns: 0 on success and -1 otherwise;
 */
int gpthugz(char **);

/*
 * for given two paths it determines if one is direct child of another
 *
 * @1: path that is supposed to be a parent of the another one;
 * @2: path that is supposed to be a child of the another one;
 *
 * returns: 0 on success and -1 otherwise;
 */
int gpthent(const char *, const char *);

int gpthsub(const char *, const char *);

/*
 * given path is divided into parts (single steps) and stored in an 
 * array of strings
 *
 * @1: path that is supposed to be divided;
 * @2: location where array with parts will be stored;
 *
 * returns: size of the created array or -1 on failure;
 */
int gpthdiv(const char *, char ***);

/*
 * for a given path function extracts its certain part (single step)
 *
 * @1: path from which we extract certain part
 * @2: index of the part in the path, that we want to extract
 *
 * returns: part of the path or NULL on failure
 */
char* gpthprt(const char *, int);

/*
 * if path is not in absolute form, then function turns it into one; then function checks, whether 
 * file pointed by the path exists;
 *
 * @1: pointer to a path
 *
 * returns: 0 if file exists and function is successful, -1 otherwise
 */
int gpthpro(char **);

/*
 * for a given path function extracts file's extension
 *
 * @1: path to the file, which extension is extracted
 *
 * returns: extension of the file; memory must be freed
 */
char * gpthext(const char *);

/*
 * for a given path function extracts file's extension
 *
 * @1: path to the file, which extension is extracted
 *
 * returns: extension of the file; memory is shared with the parameter
 */
char * gpthextptr(char *);

/*
 * for a given path function returns it's depth, meaning number of
 * nested directories/files
 * 
 * @1: pointer to a path
 * 
 * returns: on success depth of the path, -1 otherwise
 */ 
int gpthdpt(const char *);

/*
 * function returns path created from the given by cutting top element
 * 
 * @1: pointer to a path
 * 
 * returns: a new path on success, NULL otherwise (this includes
 * situation, where returning path would be empty)
 */ 
char* gpthcut(const char *);

#endif