xmhtml

browser with Motif
git clone git://bvnf.space/xmhtml.git
Log | Files | Refs

commit e67a073b5864be9e8c0360d29e394949d98629cc
parent ba55d516ceb4a11baac7e4d5f29d77766eefda51
Author: aabacchus <ben@bvnf.space>
Date:   Mon,  5 Dec 2022 17:18:12 +0000

shitty awful .txt handling

Diffstat:
Mxmhtml.c | 33+++++++++++++++++++++++++++++++--
1 file changed, 31 insertions(+), 2 deletions(-)

diff --git a/xmhtml.c b/xmhtml.c @@ -223,7 +223,7 @@ loadFile(String filename) { String file_to_open = filename; FILE *file; - int size; + int size, istxt = 0; static String content; struct stat sb; @@ -240,6 +240,11 @@ loadFile(String filename) file_to_open = "index.html"; } + if (strcmp(filename + strlen(file_to_open) - 4, ".txt") == 0) { + istxt = 1; + fprintf(stdout, "IS TXT\n"); + } + /* open the given file */ if((file = fopen(file_to_open, "r")) == NULL) { @@ -255,6 +260,10 @@ loadFile(String filename) perror("ftell"); rewind(file); + int filesize = size; + if (istxt) + size += 11; /* for <pre> </pre> */ + /* allocate a buffer large enough to contain the entire file */ if((content = malloc(size+1)) == NULL) { @@ -263,14 +272,34 @@ loadFile(String filename) } /* now read the contents of this file */ - if((fread(content, 1, size, file)) != size) + if (istxt) { + content[0] = '<'; + content[1] = 'p'; + content[2] = 'r'; + content[3] = 'e'; + content[4] = '>'; + } + if((fread(istxt ? content + 5 : content, 1, filesize, file)) != filesize) printf("Warning: did not read entire file!\n"); + if (istxt) { + content[size - 6] = '<'; + content[size - 5] = '/'; + content[size - 4] = 'p'; + content[size - 3] = 'r'; + content[size - 2] = 'e'; + content[size - 1] = '>'; + } + fclose(file); /* sanity */ content[size] = '\0'; + if (istxt) { + fprintf(stdout, "TXT file is:\n%s\n", content); + } + return(content); }