/* 
* Projekt wiki: Dateiliste ausgeben
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <dirent.h>
#include <sys/param.h>

void read_dir(char *dirname);

int main(int argc, char *argv[])
  {
  char dirname[MAXNAMELEN+1] = "/home/wiki/";  /* --> Laenge reicht garantiert  */

  read_dir(dirname);
  return EXIT_SUCCESS;
  }


void read_dir(char *dirname)
  {
  DIR *dir;
  struct dirent *dirzeiger;
  char dateiname[MAXNAMELEN+1];      /* NAME_MAX definiert in types.h */
  printf("%s\n",dirname);

  printf("<HTML>\n<HEAD>\n<TITLE>Lexikon-Dateiauswahl</TITLE>\n</HEAD>\n<BODY>\n");
  printf("<H1>Lexikon-Dateiauswahl</H1>\n");
  printf("<FORM method=POST action=\"http://localhost/~testuser/www/cgi-bin/wiki.cgi\">\n");
  printf("<SELECT NAME=\"Datei\" SIZE=\"5\">\n");
  dir = opendir(dirname);
  if(dir != NULL)
    {
    while((dirzeiger = readdir(dir)) != NULL)
      {
      strcpy(dateiname,(*dirzeiger).d_name);
      if (dateiname[0] != '.')
        printf("<OPTION>%s</OPTION>\n",dateiname);
      }
    closedir(dir);
    }
  printf("</SELECT>");
  printf("<INPUT TYPE=\"SUBMIT\" NAME=\"SUBMIT\" VALUE=\"Absenden\">");
  printf("</FORM>\n</BODY>\n</HTML>");
  }
