#include #include #include #define MAX 200 int checkdir(char *line) { int i; for (i = strlen(line) - 1; i >= 0; --i) if (line[i] == '.') return 1; else if (line[i] == '/') return 0; return 0; } int filter(char *pattern, char *buffer, char *line) { if (strcmp(pattern, buffer) != 0) return 1; else if (checkdir(line) == 0) return 1; return 0; } void rip(char *in, char *out, int startlen, int endlen) { int len = strlen(in); int i; for (i = startlen; i < len - endlen - 1; ++i) out[i - startlen] = in[i]; out[i - startlen] = '\0'; } void stripendfn(char *name) { int i; for (i = strlen(name) - 1; i >= 0; --i) if (name[i] == '/') { name[i] = '\0'; return; } } void striprest(char *name) { int i; for (i = 1; i < strlen(name); ++i) if (name[i] == '/') { name[i] = '\0'; return; } } int cntdl(char *name) { int i; int dl = 0; for (i = 0; i < strlen(name); ++i) if (name[i] == '/') dl += 1; return dl; } void splitdir(char *preout, int predl, char *site, char *out) { char *p = preout + 1; char *buffer = calloc(MAX, sizeof(char)); strcpy(buffer, preout); char *delim = "/"; int i; printf("%s", "╠═╡"); strcpy(buffer, p); striprest(buffer); if (checkdir(buffer) == 0) { printf("%s", buffer); printf("%s", "│"); } else { printf("%s%s%s%s%s%s", "", buffer, ""); } for (i = 0; i < predl; ++i) { p = strstr(p, delim) + 1; strcpy(buffer, p); striprest(buffer); if (checkdir(buffer) == 0) { printf("%s", buffer); printf("%s", "│"); } else { printf("%s%s%s%s%s%s", "", buffer, ""); } } putchar('\n'); } int pad(char *site, char *out, char *preout, int predl) { int dl = cntdl(out); char buffer[MAX], preoutbup[MAX]; char *p; strcpy(preoutbup, preout); strcpy(buffer, preout); strcpy(preout, "/"); strcat(preout, buffer); if (predl == -1) { printf("\n%s\n", "╥"); return dl; } else if (predl == 0) { printf("%s", "╠═╡"); p = preout + 1; printf("%s%s%s%s%s%s\n", "", p, ""); } else splitdir(preout, predl, site, out); return dl; } int main(int argc, char **argv) { FILE* in = fopen("files.json", "r"); FILE* header = fopen("header/files.txt", "r"); FILE* footer = fopen("footer/files.txt", "r"); char line[MAX], buffer[MAX]; char out[MAX], preout[MAX]; char pattern[32] = " \"path\": \""; char site[64] = "https://kaa.neocities.org/"; char end[32] = "\","; int i, patlen, endlen, predl; if ((in == NULL) || (header == NULL) || (footer == NULL)) { puts("That's pungent!"); return 1; } patlen = strlen(pattern); endlen = strlen(end); predl = -1; preout[0] = '\0'; while (fgets(line, MAX, header) != NULL) printf("%s", line); fclose(header); while (fgets(line, MAX, in) != NULL) { for (i = 0; i < patlen; ++i) buffer[i] = line[i]; if (filter(pattern, buffer, line) == 0) { rip(line, out, patlen, endlen); predl = pad(site, out, preout, predl); strcpy(preout, out); } } fclose(in); printf("%s", "╨"); while (fgets(line, MAX, footer) != NULL) printf("%s", line); fclose(footer); return 0; }