File: misc.cc

package info (click to toggle)
qftp 0.98-2
  • links: PTS
  • area: main
  • in suites: slink
  • size: 216 kB
  • ctags: 235
  • sloc: cpp: 2,017; makefile: 77
file content (59 lines) | stat: -rw-r--r-- 1,011 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
#include <ctype.h>
#include <string.h>

int procargs(char *s, char *f[])
{
       char *p;
        int i = 0, j;
        p = s;

        while (*p) {
                f[i++] = p;
                while (*p && !isspace(*p))
                        p++;
                if (!*p)
                        break;
                *p++ = 0;
                while (*p && isspace(*p))
                        p++;
	}
        *p++ = 0;
        *p = 0;
        f[i] = 0;
	for (j = i;j < 100;j++)
		f[j] = 0;
        return i;
}


char *split(char *cwd, char *s, char *path)
{
	char *p, *p2, *p3;
	if (s)
		p = s;
	else
		p = "";
	if (*p == '/') {
		if (!(p2 = strrchr(&p[1], '/'))) {
			p2 = &p[1];
			p3 = p2;
		} else
			p3 = p2 + 1;
			
		strncpy(path, p, p2 - p);
		path[p2 - p] = 0;
		p = p3;
	} else {
		if (!(p2 = strrchr(p, '/'))) {
			strcpy(path, cwd);
		} else {
			strcpy(path, cwd);
			p3 = path + strlen(path);
			*p3++  = '/';
			strncpy(p3, p, p2 - p);
			p3[p2 - p] = 0;
			p = p2 + 1;
		}
	}
	return p;
}