From 8828e75a9ee7a5408ad00ad17e9878a2740cc866 Mon Sep 17 00:00:00 2001 From: kaa Date: Fri, 23 Jun 2023 11:19:51 -0700 Subject: "Initial." --- composed.c | 141 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 141 insertions(+) create mode 100755 composed.c (limited to 'composed.c') diff --git a/composed.c b/composed.c new file mode 100755 index 0000000..c913113 --- /dev/null +++ b/composed.c @@ -0,0 +1,141 @@ +#include +#include +#include + +#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", "

"); + printf( "\t\t\t\t%d ", year); + printf("%s %d\n", humonth[month], day); + printf("\t\t\t%s\n", "

"); + + printf("\t\t\t%s\n", "
"); + printf("\t\t\t\t%s%s", ""); + printf("\t\t\t\t%s%s%s", ""); + printf("\t\t\t\t\t%s%s%s", "", ""); + printf("\t\t\t\t%s\n", "

"); + + 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", "
"); + } + + fclose(lyrics); + printf("\t\t\t\t%s\n", "

"); + + printf("\t\t\t
\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; +} -- cgit v1.2.3