| @@ -1,41 +0,0 @@ | |||
| #include "cms_err.h" | |||
| #include <stdio.h> | |||
| #include <unistd.h> | |||
| static char* get_message(cms_err err) | |||
| { | |||
| switch (err) | |||
| { | |||
| case CMS_ERR_NONE: | |||
| return ""; | |||
| case CMS_ERR_UNKNOWN: | |||
| return "Unknown error."; | |||
| case CMS_ERR_MEMORY: | |||
| return "Memory allocation failed."; | |||
| case CMS_ERR_PARSE: | |||
| return "Parse error."; | |||
| case CMS_ERR_FILENOENT: | |||
| return "File doesn't exist."; | |||
| case CMS_ERR_DIRNOENT: | |||
| return "Directory doesn't exist."; | |||
| case CMS_ERR_NOTFILE: | |||
| return "Not a file."; | |||
| case CMS_ERR_NOTDIR: | |||
| return "Not a directory."; | |||
| case CMS_ERR_PERM: | |||
| return "Permission denied."; | |||
| } | |||
| } | |||
| void cms_err_panic(cms_err err, char* msg) | |||
| { | |||
| if (err == CMS_ERR_NONE) | |||
| return; | |||
| if (msg == NULL) | |||
| printf("Error: %s\n", get_message(err)); | |||
| else | |||
| printf("Error: %s (%s)\n", get_message(err), msg); | |||
| exit(1); | |||
| } | |||
| @@ -15,12 +15,15 @@ int cms_util_file_exists(char* fname) | |||
| { | |||
| int f = open(fname, O_RDONLY); | |||
| close(f); | |||
| if (errno == ENOENT) | |||
| //The file doesn't exist if the open command returned the ENOENT error. | |||
| if (f == -1 && errno == ENOENT) | |||
| return 0; | |||
| else | |||
| return 1; | |||
| //If the open command succeeded, we want to close the file descriptor. | |||
| else if (f != -1) | |||
| close(f); | |||
| return 1; | |||
| } | |||
| cms_err cms_util_file_create(char* fname) | |||
| @@ -13,7 +13,8 @@ int main(int argc, char** argv) | |||
| return 1; | |||
| } | |||
| if (strcmp(argv[1], "init") == 0) //Initiate directory | |||
| //Initiate | |||
| if (strcmp(argv[1], "init") == 0) | |||
| { | |||
| if (argc != 3) | |||
| { | |||
| @@ -35,8 +36,15 @@ int main(int argc, char** argv) | |||
| cms_util_file_create(initedPath); | |||
| } | |||
| else if (strcmp(argv[1], "build") == 0) //Build | |||
| //Build | |||
| else if (strcmp(argv[1], "build") == 0) | |||
| { | |||
| if (argc != 3) | |||
| { | |||
| fprintf(stderr, "Usage: %s build <directory>\n", argv[0]); | |||
| return 1; | |||
| } | |||
| char* dirname = argv[2]; | |||
| //Get the path of .cmsinited, which tells us | |||