Skip to content

Commit a13adca

Browse files
committed
make coder more readable
1 parent 6963627 commit a13adca

2 files changed

Lines changed: 45 additions & 42 deletions

File tree

getpage.exe

0 Bytes
Binary file not shown.

src/getpage.c

Lines changed: 45 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -12,29 +12,29 @@ int getString(char* src, char* find, char ret[])
1212
}
1313

1414
void extractResources(
15-
const char *beg[],
16-
const int blength,
17-
const char *end[],
18-
const int elength,
15+
const char *search_begin[],
16+
const int begin_size,
17+
const char *search_end[],
18+
const int end_size,
1919
int *start,
2020
char urls[][URL_CHRS],
21-
char nline[]
21+
char process_line[]
2222
)
2323
{
24-
char line[TXT_CHRS] = {0};
24+
char temp_line[TXT_CHRS] = {0};
2525
int i = 0, j = 0, k = *start, len = 0, find = 0;
2626
char *next = NULL, *ps = NULL, *pe = NULL, *lp = NULL;
27-
strcpy(line, nline);
28-
lp = line;
29-
for (i = 0; i < blength; i++) {
27+
strcpy(temp_line, process_line);
28+
lp = temp_line;
29+
for (i = 0; i < begin_size; i++) {
3030
find = 0;
31-
ps = strstr(lp, beg[i]);
31+
ps = strstr(lp, search_begin[i]);
3232
if (ps) {
33-
next = ps + strlen(beg[i]);
34-
for (j = 0; j < elength; j++) {
35-
pe = strstr(next, end[j]);
33+
next = ps + strlen(search_begin[i]);
34+
for (j = 0; j < end_size; j++) {
35+
pe = strstr(next, search_end[j]);
3636
if (!find && pe) {
37-
len = pe + strlen(end[j]) - next;
37+
len = pe + strlen(search_end[j]) - next;
3838
strncpy(urls[k], next, URL_CHRS);
3939
urls[k][len] = 0;
4040
ps = strstr(lp, urls[k]);
@@ -45,7 +45,7 @@ void extractResources(
4545
// strip out addition text from source code
4646
*(ps + 5 + strlen(ps + len)) = 0;
4747
//back loop up for next search token
48-
if (strstr(next, beg[i])) {
48+
if (strstr(next, search_begin[i])) {
4949
lp = next;
5050
i--;
5151
}
@@ -56,17 +56,16 @@ void extractResources(
5656
*start = k;
5757
}
5858
}
59-
strcpy(nline, line);
59+
strcpy(process_line, temp_line);
6060
}
6161
int getTextTutorial(
6262
const char *url,
63-
const char *fold,
64-
const char *mst,
65-
const char *med,
66-
const char *beg[],
67-
const int blength,
68-
const char *end[],
69-
const int elength,
63+
const char *match_start,
64+
const char *match_end,
65+
const char *search_begin[],
66+
const int begin_size,
67+
const char *search_end[],
68+
const int end_size,
7069
FILE *hp,
7170
char urls[][URL_CHRS]
7271
)
@@ -86,11 +85,11 @@ int getTextTutorial(
8685
}
8786
while (fgets(line, sizeof(line), fp) != NULL) {
8887
if (start && matched) {break;}
89-
if (strstr(line, mst) != NULL) {start = 1;}
88+
if (strstr(line, match_start) != NULL) {start = 1;}
9089
if (start && !matched) {
91-
extractResources(beg, blength, end, elength, &k, urls, line);
90+
extractResources(search_begin, begin_size, search_end, end_size, &k, urls, line);
9291
fprintf(hp, "%s", line);
93-
if (strstr(line, med) != NULL) {matched = 1;}
92+
if (strstr(line, match_end) != NULL) {matched = 1;}
9493
}
9594
memset(line, 0, sizeof(line));
9695
}
@@ -120,9 +119,9 @@ void writeHTMLEnd(FILE *fp)
120119
fclose(fp);
121120
}
122121

123-
void downloadResources(char* fold, char urls[][URL_CHRS], int urlCount)
122+
void downloadResources(char* folder, char urls[][URL_CHRS], int urlCount)
124123
{
125-
char fname[CMD_CHRS] = {0};
124+
char fname[URL_CHRS] = {0};
126125
char curlcmd[CMD_CHRS] = {0};
127126
char fullurl[URL_CHRS] = {0};
128127
char resurl[URL_CHRS] = {0};
@@ -141,9 +140,9 @@ void downloadResources(char* fold, char urls[][URL_CHRS], int urlCount)
141140
curlcmd,
142141
"@if not exist \"..\\%s\\img\\%s\" "
143142
"curl %s -o \"..\\%s\\img\\%s\" \"%s\" 2>NUL",
144-
fold, fname,
143+
folder, fname,
145144
strlen(proxyConf) ? proxyConf : "",
146-
fold, fname, fullurl
145+
folder, fname, fullurl
147146
);
148147
printf("downloading %s\n", fullurl);
149148
system(curlcmd);
@@ -154,25 +153,28 @@ void prepareTextTuroial(char *url, char *folder, char *title)
154153
{
155154
FILE *fp = NULL;
156155
int urlCount = 0;
157-
const char* mst = "<section class=";
158-
const char* med = "</section>";
159-
const char* beg[] = { "src=\"", "srcset=\"", "x, "};
160-
const char* end[] = {
156+
const char* match_start = "<section class=";
157+
const char* match_end = "</section>";
158+
const char* search_begin[] = { "src=\"", "srcset=\"", "x, "};
159+
const char* search_end[] = {
161160
".png", ".jpg", ".gif", ".mov", ".mp4", ".zip",
162161
".png ", ".jpg ", ".gif "
163162
};
164-
char pagefile[CMD_CHRS] = {0};
163+
char page_file[CMD_CHRS] = {0};
165164
char urls[MAX_IMGS][URL_CHRS] = {0};
166165

167-
sprintf(pagefile, "..\\%s\\index.html", folder);
166+
sprintf(page_file, "..\\%s\\index.html", folder);
168167
printf("saving tutorial to %s\\index.html\n", folder);
169-
fp = fopen(pagefile, "w");
170-
if(fp == NULL){perror("writing error: index.html");return;}
168+
fp = fopen(page_file, "w");
169+
if(fp == NULL){
170+
perror("writing error: index.html");
171+
return;
172+
}
171173
writeHtmlHead(fp, title);
172174
urlCount = getTextTutorial(
173-
url, folder, mst, med,
174-
beg, sizeof(beg)/sizeof(beg[0]),
175-
end, sizeof(end)/sizeof(end[0]),
175+
url, match_start, match_end,
176+
search_begin, sizeof(search_begin)/sizeof(search_begin[0]),
177+
search_end, sizeof(search_end)/sizeof(search_end[0]),
176178
fp, urls
177179
);
178180
writeHTMLEnd(fp);
@@ -343,6 +345,7 @@ int main(int argc, char* argv[])
343345
printf("preparing %sm/%s\n", find[2], info[2]);
344346
}
345347
}
346-
fclose(yp);fclose(fp);
348+
fclose(yp);
349+
fclose(fp);
347350
return 0;
348351
}

0 commit comments

Comments
 (0)