@@ 1,3 1,4 @@
+#include <_stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ 31,10 32,9 @@ int strfind(const char* haystack, char needle) {
return i;
}
-void write_item_data(char* restrict row, const char* restrict template, FILE* out) {
+void write_item_data(char* restrict row, const char* restrict template, FILE* out, const char* restrict pref) {
char prettyDate[64];
char* tok = strtok(row, "\t");
- const char* pref = "item-";
char* label = malloc(strlen(pref) + strlen(tok) + 2);
sprintf(label, "%s%s", pref, tok);
char* data[8];
@@ 44,7 44,6 @@ void write_item_data(char* restrict row, const char* restrict template, FILE* ou
struct tm bdate;
strptime(date, "%Y-%m-%dT%H:%M:%S%z", &bdate);
strftime(prettyDate, 64, "%H:%M", &bdate);
- //fprintf(stderr, "%s\n", prettyDate);
tok = strtok(NULL, "\t");
while (tok != NULL) {
@@ 62,14 61,16 @@ void write_item_data(char* restrict row, const char* restrict template, FILE* ou
const char magic[] = "<!-- ANCHOR";
if (strncmp(templateLine, magic, sizeof(magic) - 1) != 0) {
- fprintf(stderr, "ERR: Invalid template provided!\n");
+ fprintf(stderr, "WARN: Indescriminate template provided!\n");
fprintf(stderr, "<template>:%i: %s\n", 1, templateLine);
- return;
+ nextLine = -1;
+ } else {
+ char* tagName = (templateLine + sizeof(magic));
+ tagName[strfind(tagName, ' ')] = '\0';
+ fprintf(out, "<%s id=\"%s\">\n", tagName, data[0]);
+ fflush(out);
}
- char* tagName = (templateLine + sizeof(magic));
- tagName[strfind(tagName, ' ')] = '\0';
- fprintf(out, "<%s id=\"%s\">\n", tagName, data[0]);
- fflush(out);
+
int needlePos = strfind(template + nextLine, '\n');
while (needlePos != 0) {
if (bufSize <= needlePos) {
@@ 86,9 87,13 @@ void write_item_data(char* restrict row, const char* restrict template, FILE* ou
int offset = strlen("<!-- LINK ");
unsigned char idx = templateLine[offset] - 0x30;
fprintf(out, "<a href=\"%s\">", data[idx]);
- } else if (strncmp(templateLine, "<!-- DATE", strlen("<!-- DATE") - 1) == 0){
+ } else if (strncmp(templateLine, "<!-- DATE", strlen("<!-- DATE") - 1) == 0) {
fputs(prettyDate, out);
- } else {
+ } else if (strncmp(templateLine, "<!-- ATOM", strlen("<!-- ATOM") - 1) == 0) {
+ fprintf(out, "<link rel=\"alternate\" type=\"text/html\" href=\"https://m1kadev.nl/%s#%s\" />", pref, data[0]);
+ fprintf(out, "<id>tag:february.m1kadev.nl,2026:feed/%s</id>", data[0]);
+ fprintf(out, "<updated>%s</updated>", date);
+ } else {
fputs(templateLine, out);
}
nextLine += needlePos;
@@ 114,17 119,22 @@ int main(int argc, char* argv[]) {
FILE* data = fopen(argv[1], "r");
char* itemTemplate = read_to_string(argv[2]);
- FILE* index = fopen(argv[3], "r");
FILE* output = fopen(argv[4], "w");
+ FILE* index = NULL;
+
char buf[512];
- while (fgets(buf, sizeof(buf), index) != NULL) {
- if (strncmp(buf, "<!-- PUT", 7) == 0) {
- break;
- } else {
- fputs(buf, output);
- }
+ if (strncmp(argv[3], "NONE", strlen("NONE")) != 0) {
+ FILE* index = fopen(argv[3], "r");
+ while (fgets(buf, sizeof(buf), index) != NULL) {
+ if (strncmp(buf, "<!-- PUT", 7) == 0) {
+ break;
+ } else {
+ fputs(buf, output);
+ }
+ }
}
+
if (fgets(buf, sizeof(buf), data) == NULL) {
fprintf(stderr, "could not read tsv header, bailing");
fclose(data);
@@ 132,18 142,24 @@ int main(int argc, char* argv[]) {
return -1;
}
+ const char* pCname = strtok(buf, "\t");
+ char* cname = malloc(strlen(pCname) + 1);
+ strcpy(cname, pCname);
+
while (fgets(buf, sizeof(buf), data) != NULL) {
- write_item_data(buf, itemTemplate, output);
+ write_item_data(buf, itemTemplate, output, cname);
}
- while (fgets(buf, sizeof(buf), index) != NULL) {
+ while (index != NULL && fgets(buf, sizeof(buf), index) != NULL) {
fputs(buf, output);
}
fclose(data);
- fclose(index);
+ if (index != NULL)
+ fclose(index);
fclose(output);
free(itemTemplate);
+ free(cname);
return 0;
}
@@ 2,10 2,12 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <time.h>
int main(int argc, char* argv[]) {
if (argc <= 2) {
fprintf(stderr, "Usage: ./mkpage <input> <output>\n");
+ return -1;
}
FILE* input = fopen(argv[1], "rb");
if (input == NULL) {
@@ 51,16 53,24 @@ int main(int argc, char* argv[]) {
fseek(load, 0, SEEK_SET);
char* readBuf = malloc(file_size);
size_t bytesRead = fread(readBuf, file_size, 1, load);
- if (bytesRead <= 0) {
- fputs("Failed to read from LOADed file\n", stderr);
- fclose(load);
- fclose(input);
- fclose(output);
- return -1;
- }
+ if (bytesRead <= 0) {
+ fputs("Failed to read from LOADed file\n", stderr);
+ fclose(load);
+ fclose(input);
+ fclose(output);
+ return -1;
+ }
fputs(readBuf, output);
free(readBuf);
fclose(load);
+ } else if (strncmp(commandPtr, "STAMP", 4) == 0) {
+ time_t pTime;
+ time(&pTime);
+ struct tm* date;
+ date = gmtime(&pTime);
+ char strTime[64];
+ strftime(strTime, sizeof(strTime), "%Y-%m-%dT%H:%M:%SZ", date);
+ fprintf(output, "<updated>%s</updated>", strTime);
}
} else {
fputs(buf, output);