basin main

#include
#include
#include
#include
#include

#include “basin.h”

int main(int argc, char **argv) {
int stage = 0;
for (;;) {
int option_index;
int opt = getopt_long(
argc, argv,
(struct option[]) {
{“stage-1”, no_argument, NULL, 1},
{“stage-2”, no_argument, NULL, 2},
{“stage-3”, no_argument, NULL, 3},
{“stage-4”, no_argument, NULL, 4},
{0, 0, 0, ‘?’},
&option_index

if (opt == -1) {

switch (opt) {
stage = opt;
default: {
fprintf(stderr, “Usage: %s [–stage-1|–stage-2|–stage-3|–stage-4]\n”, argv[0]);
return EXIT_FAILURE;

switch (stage) {
if (argc – optind < 1) { fprintf(stderr, "Usage: %s --stage-1 [ …]\n”, argv[0]);
return EXIT_FAILURE;
char *outfile = argv[optind];
char **files = argv + optind + 1;
size_t num_files = argc – optind – 1;
stage_1(outfile, files, num_files);
if (argc – optind != 2) {
fprintf(stderr, “Usage: %s –stage-2 \n”, argv[0]);
return EXIT_FAILURE;
char *outfile = argv[optind];
char *infile = argv[optind + 1];
stage_2(outfile, infile);
if (argc – optind != 2) {
fprintf(stderr, “Usage: %s –stage-3 \n”, argv[0]);
return EXIT_FAILURE;
char *outfile = argv[optind];
char *infile = argv[optind + 1];
stage_3(outfile, infile);
if (argc – optind != 1) {
fprintf(stderr, “Usage: %s –stage-4 \n”, argv[0]);
return EXIT_FAILURE;
char *infile = argv[optind];
stage_4(infile);
fprintf(stderr, “Usage: %s [–stage-1|–stage-2|–stage-3|–stage-4]\n”, argv[0]);
return EXIT_FAILURE;

return EXIT_SUCCESS;