#include #include #include #include #include #include "mothra.h" /* * fd is the result of a successful open(name, OREAD), * where name is the name of a directory. We convert * this into an html page containing links to the files * in the directory. */ int dir2html(char *name, int fd){ int p[2], first; Dir *dir; int i, n; if(pipe(p)==-1){ close(fd); return -1; } switch(rfork(RFFDG|RFPROC|RFNOWAIT)){ case -1: close(fd); return -1; case 0: close(p[1]); fprint(p[0], "\n"); fprint(p[0], "Directory %s\n", name); fprint(p[0], "\n"); fprint(p[0], "\n"); fprint(p[0], "

%s

\n", name); fprint(p[0], "
    \n"); first=1; while((n = dirread(fd, &dir)) > 0) { for (i = 0; i < n; i++) fprint(p[0], "
  • %s%s\n", name, dir[i].name, dir[i].name, dir[i].mode&DMDIR?"/":""); free(dir); } fprint(p[0], "
\n"); fprint(p[0], "\n"); _exits(0); default: close(fd); close(p[0]); return p[1]; } }