/*

  MkDir - create directory in a file system.

*/
#include <vo_stdio.h>
#include <volink.h>     /* Linker directives like DLLENTRY */
#include <apploader.h>  /* RunLibraryFunction etc */
#include <string.h>
#include <unistd.h>
#include <kernel.h>
#include "mkdir.h"


ioresult main(char *parameters) {
  int nParam, i;
  char *p = parameters;
  ioresult retCode = S_ERROR;
  int verbose = 0;

  nParam = RunProgram("ParamSpl", (u_int16)parameters);
  for (i=0; i<nParam; i++) {
    if (!strcmp(p, "-h")) {
      printf("Usage: MkDir [fulPath|-v|+v|-h]\n"
	     "fulPath\tFull path to the directory to create\n"
	     "-v|+v\tVerbose on/off\n"
	     "-h\tShow this help\n");
      goto finally_ok;
    } else if (!strcmp(p, "-v")) {
      verbose = 1;
    } else if (!strcmp(p, "+v")) {
      verbose = 0;
    } else if (p[0] == '-') {
      printf("E: Unknown parameter \"%s\"\n", p);
      goto finally;
    } else {
      if (retCode = MkDir(parameters)) {
	printf("E: Couldn't create \"%s\"\n", parameters);
      } else if (verbose) {
	printf("Created \"%s\"\n", parameters);
      }
    }
    p += strlen(p)+1;
  }

 finally_ok:
  retCode = S_OK;
 finally:
  return retCode;
}
