-
Notifications
You must be signed in to change notification settings - Fork 0
/
parsebutterparams.h
141 lines (134 loc) · 3.89 KB
/
parsebutterparams.h
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
//Zachary Keffaber, 2021/11/5, ButtermilkParamParser
#include <stdio.h>
#include <string.h>
char *butterparam(char *line, int type, int occurrence) {
char *returnkey = "NULL"; //making returnkey a string that says NULL rather than actually being null. Maximum trolling capacity
int c = 0;
int occurrenceindex = 1;
int charindex = 0;
int charindex2 = 0;
int charindex3 = 0;
int tempint = 0;
int instring = 0;
char newparams[strlen(line)];
char newvalue[strlen(line)];
//fp=fopen("testwrite.txt", "w");
//fprintf(fp, "aba");
//fclose(fp);
charindex = 0;
charindex2 = 0;
tempint = 0;
c = 0;
while (tempint == 0){
if (line[charindex] == '(' || line[charindex] == ','){
if (occurrence != occurrenceindex){
occurrenceindex++;
} else {
tempint++;
}
}
charindex++;
}
tempint = 0; //ignore spaces
while (tempint == 0){
if (line[charindex] == ' '){
charindex++;
} else {
tempint++;
}
}
tempint = 0;
while (charindex+tempint<strlen(line)){
if (line[charindex+tempint] == ')' || line[charindex+tempint] == ','){
charindex2 = tempint;
}
tempint++;
}
tempint = 0;
if (charindex+1==charindex2){
return 0;
}
char params[charindex2];
char value[charindex2];
memcpy(params,&line[charindex],charindex2);
params[charindex2] = '\0';
//value[c] = '\0';
charindex = 0;
charindex2 = 1;
charindex3 = 0;
c = 0;
instring = 0;
for(int i = 0; i < strlen(params); ++i) {
if (params[i] == '\"' && (!(params[i-1] == '\\'))){
if (instring == 1) {
instring = 0;
} else {
instring = 1;
}
}
if (instring == 0 && params[i] == '=' && (!(params[i-1] == '\\'))){
//printf("\nThis is me!!! i = %d charindex = %d params = %s\n",i,charindex,params);
//the below while is where the printf issue is
while (params[i-charindex-1] == ' ' && i-charindex > 0){
charindex++;
}
//deadpos (printf)
charindex2 = 1;
while (params[i+charindex2] == ' ' && i+charindex2 < strlen(params)){
charindex2++;
}
//deadpos (printf)
charindex3 = 0;
while (params[i+charindex2+charindex3] != ',' && i+charindex2+charindex3 < strlen(params)){
charindex3++;
}
while (c < charindex3) {
value[c] = params[i+charindex2+c];
c++;
}
value[charindex3] = '\0';
//deadpos (printf)
/*
memcpy(value,&line[i+charindex2],strlen(line)-(i+charindex2+charindex3));
value[strlen(line)-(i+charindex2+charindex3)] = '\0';
*/
params[i-charindex] = '\0';
//char newparams[strlen(params)];
unsigned int iicount = 0;
while (!(iicount == i-charindex)){
iicount = i-charindex;
}
unsigned int iisbg = 0;
while (!(iisbg == 1)){
iisbg = 1;
}
iisbg -= 1;
while (iisbg<iicount){ //i think this is fixed now???
//printf("\n\nis this safe? iisbg:%d%c\n\n",iisbg,params[iisbg]);
newparams[iisbg] = params[iisbg];
iisbg += 1;
}
newparams[iisbg] = '\0';
//printf("\nii: %d%s\n",iisbg,newparams);
//note: deadpos (printf) now safe!!! yaya!!!
for (unsigned int ii = 0; ii < strlen(value); ii++){
newvalue[ii] = value[ii];
}
newvalue[strlen(value)] = '\0';
//deadpos (printf)
//v
}
//deadpos (printf)
}
//semi-deadpos (printf)
if (type == 0){ //type 0 is parameter, 1 is value
printf("\n\n%s",newparams);
returnkey = params;
return returnkey;
} else {
printf("\n\n%s",newvalue);
returnkey = value;
return returnkey;
}
return 0;
}