#include "action_list.h" #include "file.h" #include "myers.h" #include "utilities.h" // main.c #include #include #include #include static void usage(int exitcode) { printf("usage: merk []\n\n diff Displays the difference between the given two files\n"); exit(exitcode); } int main(int argc, char **argv) { if (argc == 2 && (!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help"))) { usage(0); } const char* subcmd = argv[1]; if (strcmp(subcmd, "diff") != 0) { fprintf(stderr, "ERROR: Unknown subcommand: '%s'\n", subcmd); usage(2); } if (strcmp(subcmd, "diff") == 0) { if (argc != 4) { printf("ERROR: too many/too little arguments given!\n"); printf("Usage: merk diff "); exit(1); } File* file1; switch (get_path_type(argv[2])) { case PT_FILE: file1 = new_file(argv[2]); break; case PT_DIR: file1 = NULL; printf("ERROR: first path is a directory and no file!"); break; case PT_NOEXIST: file1 = NULL; printf("ERROR: first path does not exist!"); break; default: file1 = NULL; printf("ERROR: unknown first path!"); } if (!file1) exit(1); File* file2; switch (get_path_type(argv[3])) { case PT_FILE: file2 = new_file(argv[3]); break; case PT_DIR: file2 = NULL; printf("ERROR: second path is a directory and no file!"); break; case PT_NOEXIST: file2 = NULL; printf("ERROR: second path does not exist!"); break; default: file2 = NULL; printf("ERROR: unknown second path!"); } if (!file2) exit(1); ActionList* actions = myers_diff(file1, file2, 0, 0); if (!actions) printf("ERROR: something went wrong while taking the diff!"); else visualize_diff(file1, file2, actions); } else { usage(1); } return 0; }