#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define MAX 200
void
pad(char *site, char *p)
{
char date[11], lyrline[MAX], name[32];
char lyrfn[64] = "lyrics/";
char url[64] = "https://files.catbox.moe/";
int year, month, day, i;
FILE *lyrics;
char *humonth[] = {
"mystery",
"january",
"february",
"march",
"april",
"may",
"june",
"july",
"august",
"september",
"october",
"november",
"december"
};
for ( i = 0; i < 10; ++i )
date[i] = p[i];
date[10] = '\0';
year = (date[0] - 0x30) * 1000;
year += (date[1] - 0x30) * 100;
year += (date[2] - 0x30) * 10;
year += date[3] - 0x30;
month = (date[5] - 0x30) * 10;
month += date[6] - 0x30;
day = (date[8] - 0x30) * 10;
day += date[9] - 0x30;
p = strstr(p, "--") + 2;
i = 1;
while ( ( p[i] == '-' && p[i-1] == '-' ) == 0 ) {
name[i-1] = p[i-1];
++i;
}
name[i-1] = '\0';
p = strstr(p, "SLASH") + 5;
strcat(url, p);
printf("\t\t\t%s\n", "<h2>");
printf( "\t\t\t\t%d ", year);
printf("%s %d\n", humonth[month], day);
printf("\t\t\t%s\n", "</h2>");
printf("\t\t\t%s\n", "<div>");
printf("\t\t\t\t%s%s", "<audio src=\"", url);
printf("%s\n", "\" controls=\"controls\">");
printf("\t\t\t\t\t%s %s\n", "playable from", url);
printf("\t\t\t\t%s\n", "</audio>");
printf("\t\t\t\t%s%s%s", "<a href=\"", site, "Image/");
printf("%s%s\n", name, ".png\" target=\"_blank\">");
printf("\t\t\t\t\t%s%s%s", "<img src=\"", site, "Image/");
printf("%s%s %s ", name, ".png\"", "loading=\"lazy\"");
printf("%s\n\t\t\t\t%s\n", "class=\"cover\">", "</a>");
printf("\t\t\t\t%s\n", "<p>");
strcat(lyrfn, name);
strcat(lyrfn, ".txt");
lyrics = fopen(lyrfn, "r");
if (lyrics == NULL)
puts("RAW!");
else
while (fgets(lyrline, MAX, lyrics) != NULL) {
printf("\t\t\t\t\t%s", lyrline);
printf("\t\t\t\t\t%s\n", "<br>");
}
fclose(lyrics);
printf("\t\t\t\t%s\n", "</p>");
printf("\t\t\t</div>\n");
}
int main()
{
FILE* in = fopen("files.json", "r");
FILE* header = fopen("header/composed.txt", "r");
FILE* footer = fopen("footer/composed.txt", "r");
char line[MAX], buffer[MAX];
char site[32] = "https://kaa.neocities.org/";
char pattern[32] = "Link/", end[32] = ".txt\",";
int patlen = strlen(pattern);
int endlen = strlen(end);
int ch, cnt, len;
char *p;
if ( (in == NULL) || (header == NULL) || (footer == NULL) ) {
puts("That's pungent!");
return 1;
}
while (fgets(line, MAX, header) != NULL)
printf("%s", line);
fclose(header);
fseek(in, 0, SEEK_END);
while ( fseek(in, -2, SEEK_CUR) != -1 ) {
ch = fgetc(in);
for ( cnt = 0; ch != '\n' && ftell(in) > 1; ++cnt ) {
fseek(in, -2, SEEK_CUR);
line[cnt] = ch;
ch = fgetc(in);
}
line[cnt] = ch;
for (len = cnt; cnt >= 0; --cnt)
buffer[len - cnt] = line[cnt];
buffer[len] = '\0';
if ( ( p = strstr(buffer, pattern) ) != NULL) {
p += patlen;
p[ strlen(p) - endlen + 1 ] = '\0';
pad(site, p);
}
}
fclose(in);
while (fgets(line, MAX, footer) != NULL)
printf("%s", line);
fclose(footer);
return 0;
}