Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
BitchX
GitHub Repository: BitchX/BitchX1.3
Path: blob/master/dll/nap/dragonap/napster/args.c
1074 views
1
/*
2
napster code base by Drago ([email protected])
3
released: 11-30-99
4
*/
5
6
#include <stdio.h>
7
#include <string.h>
8
#include <assert.h>
9
10
int main(void) {
11
char **argv;
12
13
printf("%d\n", getargs(strdup("buddhempseed 1916592664 6699 \"E:\\New
14
Folder\\mp3\\Korn - Twist Chi.mp3\" 7cf872d13eed1822b840144d77dc5329 7"),
15
&argv));
16
17
}
18
19
int getargs(char *s, char ***sargs) {
20
char *orig;
21
int escape=0;
22
char *beginword;
23
char *endword;
24
char **args=NULL;
25
int argc=0;
26
int myidx=0;
27
28
beginword=s;
29
endword=NULL;
30
31
while (1) {
32
switch(*s) {
33
case '"':
34
escape^=1;
35
break;
36
37
case ' ':
38
if (!escape)
39
endword=s;
40
break;
41
}
42
s++;
43
if (*s=='\0') endword=s;
44
if (endword) {
45
int len=endword-beginword;
46
char tmp[len+1];
47
strncpy(tmp, beginword, len);
48
tmp[len]=0;
49
endword=NULL;
50
beginword=s;
51
myidx=argc;
52
argc++;
53
args=(char **) realloc(args, sizeof(char *) * argc);
54
assert(args!=NULL);
55
args[myidx]=strdup(tmp);
56
}
57
if (!*s) break;
58
}
59
myidx=argc;
60
argc++;
61
args=(char **) realloc(args, sizeof(char *) * argc);
62
assert(args!=NULL);
63
args[myidx]=NULL;
64
*sargs=args;
65
return argc-1;
66
}
67
68
69