/*+JMJ
 * cmd.c - tir HTML renderer command line interface
 * Copyright 2011 David Meyer <papa@freeshell.org>
 */

#include <stdio.h>
#include <string.h>
#include "krcompat.h"

/* IDENTIFICATION: *************************************************/

#define PROGRAM "tirrender"
#define VERSION "0.0"
#define COPYRIGHT "Copyright 2011 David Meyer"
#define CONTACT "David Meyer <papa@freeshell.org>"
#define DESCRIPTION "tir HTML renderer for files and directories"
#define USAGE "Usage: tirrender [-hV] [-d DATASET] [-l LOCATION] [-f FILE]"

/* MAIN: ***********************************************************/

int main(argc, argv)
  int argc;
  char *argv[];
{
  int a, n;
  char *dataset, *location, *file;

  for (a = 1; a < argc; a++) {

    if (!strcmp(argv[a], "-d")) {
      dataset = malloc(strlen(argv[++a])+1);
      strcpy(dataset, argv[a]);
    }
    else if (!strncmp(argv[a], "-d", 2)) {
      dataset = malloc(strlen(argv[a])-1);
      strcpy(dataset, argv[a]+2);
    }

    else if (!strcmp(argv[a], "-l")) {
      location = malloc(strlen(argv[++a])+1);
      strcpy(location, argv[a]);
    }
    else if (!strncmp(argv[a], "-l", 2)) {
      location = malloc(strlen(argv[a])-1);
      strcpy(location, argv[a]+2);
    }

    else if (!strcmp(argv[a], "-f")) {
      file = malloc(strlen(argv[++a])+1);
      strcpy(file, argv[a]);
    }
    else if (!strncmp(argv[a], "-f", 2)) {
      file = malloc(strlen(argv[a])-1);
      strcpy(file, argv[a]+2);
    }

    else if (argv[a][0] == '-') {
      for (n = 1; n < strlen(argv[a]); n++) {
	if (argv[a][n] == 'h') {
	  printf("Help message\n");
	  return 0;
	}
	else if (argv[a][n] == 'V') {
	  printf("Version message\n");
	  return 0;
	}
	else {
	  printf("Invalid option: -%c\n%s\n", argv[a][n], USAGE);
	  return 0;
	}
      }
    }

    else {
      printf("Invalid argument: %s\n%s\n", argv[a], USAGE);
      return 0;
    }
  }
  printf("dataset=%s location=%s file=%s\n", dataset, location, file);
  return 0;
}