1
0
Fork 0
mirror of https://gitlab.com/niansa/simpsh-httpd.git synced 2025-03-06 20:53:36 +01:00
simpsh-httpd/cport/filelist.c
2020-08-04 14:53:23 +02:00

46 lines
1.3 KiB
C

void filelist() {
struct databuffer thisdb;
struct databuffer thisdb2;
thisdb = auto_db("<html>\n"
" <head>\n"
" <title>Index of: ");
db_append(&outfile, &thisdb);
db_append(&outfile, &url);
thisdb = auto_db("</title>\n"
" </head>\n"
" <body>\n"
" <p>");
db_append(&outfile, &thisdb);
db_append(&outfile, &url);
thisdb = auto_db("</p>\n"
" <h2>Directory list:</h2><br />\n"
" <a href=\"../\">..</a><br />\n");
db_append(&outfile, &thisdb);
struct databuffer filelist = file_listdir(db_raw(&file));
const char *filenameptr = filelist.data;
bool lastwasbegin = false;
for (; filenameptr != filelist.data + filelist.len; filenameptr++) {
if (*filenameptr != 0 && !lastwasbegin) {
if (filenameptr[0] != '.') {
thisdb2 = auto_db(filenameptr);
thisdb = auto_db(" <a href=\"./");
db_append(&outfile, &thisdb);
db_append(&outfile, &thisdb2);
thisdb = auto_db("\">");
db_append(&outfile, &thisdb);
db_append(&outfile, &thisdb2);
thisdb = auto_db("</a><br />\n");
db_append(&outfile, &thisdb);
}
lastwasbegin = true;
} else if (*filenameptr == 0) {
lastwasbegin = false;
}
}
thisdb = auto_db(" </body>\n"
"</html>\n");
db_append(&outfile, &thisdb);
}