summaryrefslogtreecommitdiffstats
path: root/dimension/main.c
blob: 8f5aa9f5a6695e6aa1867d5ed341602e79673b6d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*************************************************************************
 * Copyright (C) 2009 Tavian Barnes <tavianator@gmail.com>               *
 *                                                                       *
 * This file is part of Dimension.                                       *
 *                                                                       *
 * Dimension is free software; you can redistribute it and/or modify it  *
 * under the terms of the GNU General Public License as published by the *
 * Free Software Foundation; either version 3 of the License, or (at     *
 * your option) any later version.                                       *
 *                                                                       *
 * Dimension is distributed in the hope that it will be useful, but      *
 * WITHOUT ANY WARRANTY; without even the implied warranty of            *
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
 * General Public License for more details.                              *
 *                                                                       *
 * You should have received a copy of the GNU General Public License     *
 * along with this program.  If not, see <http://www.gnu.org/licenses/>. *
 *************************************************************************/

#include "../libdimension/dimension.h"
#include <stdlib.h>
#include <getopt.h>

const char *output = NULL, *input = NULL;
int tokenize = 0;

int
main(int argc, char **argv) {
  /* Parse the command-line options */

  static struct option long_options[] = {
    { "output",   required_argument, NULL,      'o' },
    { "input",    required_argument, NULL,      'i' },
    { "tokenize", no_argument,       &tokenize, 1   },
    { 0,          0,                 0,         0   }
  };
  int opt, opt_index;

  while (1) {
    opt = getopt_long(argc, argv, "o:i:", long_options, &opt_index);

    if (opt == -1)
      break;

    switch (opt) {
    case 0:
      /* Option set a flag - do nothing here */
      break;

    case 'o':
      if (output) {
        dmnsn_error(DMNSN_SEVERITY_HIGH, "--output specified more than once.");
      } else {
        output = optarg;
      }
      break;

    case 'i':
      if (input) {
        dmnsn_error(DMNSN_SEVERITY_HIGH, "--input specified more than once.");
      } else {
        input = optarg;
      }
      break;

    default:
      dmnsn_error(DMNSN_SEVERITY_HIGH, "Error parsing command line.");
    };
  }

  if (optind == argc - 1) {
    if (input) {
      dmnsn_error(DMNSN_SEVERITY_HIGH, "Multiple input files specified.");
    } else {
      input = argv[optind];
    }
  } else if (optind < argc) {
    dmnsn_error(DMNSN_SEVERITY_HIGH, "Invalid extranious command line options.");
  }

  if (!output) {
    dmnsn_error(DMNSN_SEVERITY_HIGH, "No output file specified.");
  }
  if (!input) {
    dmnsn_error(DMNSN_SEVERITY_HIGH, "No input file specified.");
  }

  return EXIT_SUCCESS;
}