int main(int argc, char **argv) { // The mode determines if we compress, decompress, or print out the table to // the commandline. // Possibilities: -t, -c, or -d // If it's -d, file has to be of .hurl extension type. // -t, -c, or -d, plus this checks if the file name/extension is valid. eMode mode = getModeOfOperation(argc, argv); // Ensure proper commandline arguments! if (mode == INVALID_MODE) { fprintf(stderr, "Invalid commandline args. Should be:\n%s (-t | -c | -d) file\nOR\n%s -d file.hurl\ni.e.: %s -t MyFile.txt\n", argv[0], argv[0], argv[0]); return -1; } // Name of the file passes in as a commandline arg. char *fileName = argv[2]; // `fileCode` used for error handling. eFileCode fileCode = GenerateTableAndCompressOrDecompress(mode, fileName); // Check if function succeeded. if (fileCode != FILE_SUCCESS) { fprintf(stderr, "Invalid File and commandline Parameter combination.\n"); return -1; } return 0; }
int main(int argc, char **argv) { // The mode determines if we compress, decompress, or print out the table to the commandline. // Possibilities: -t, -c, or -d // If it's -d, file has to be of .huff extension type. eMode mode; char* fileName; // Name of the file passes in as a commandline arg. huffResult* resultArray; // The table of 010101001 codes for each ascii character. eFileCode fileCode; // Used for error handling. mode = getModeOfOperation(argc, argv); // -t, -c, or -d, plus this checks if the file name/extension is valid. // Ensure proper commandline arguments! if (mode == INVALID_MODE) { fprintf(stderr, "Invalid commandline args. Should be:\nhuff (-t | -c) file\nOR\nhuff -d file.huff\ni.e.: ./huff -t MyFile.txt\n"); return 255; } fileName = argv[2]; fileCode = GenerateTableAndCompressOrDecompress(mode, fileName, resultArray); // Check if function succeeded. if (fileCode != FILE_SUCCESS) { fprintf(stderr, "Invalid File and commandline Parameter combination.\n"); return 255; } return 0; }