Просмотр исходного кода

Improve robustness of compiler tools

Daniele Bartolini 12 лет назад
Родитель
Сommit
96364fd8b9
3 измененных файлов с 44 добавлено и 5 удалено
  1. 8 5
      tools/compilers/resource-hash.cpp
  2. 18 0
      tools/compilers/tga/main.cpp
  3. 18 0
      tools/compilers/txt/main.cpp

+ 8 - 5
tools/compilers/resource-hash.cpp

@@ -6,7 +6,6 @@
 using namespace crown;
 
 const char* resource_in = NULL;
-const char* resource_out = NULL;
 uint32_t hash_seed = 0;
 
 void print_help_message(const char* program_name);
@@ -17,6 +16,12 @@ int main(int argc, char** argv)
 {
 	parse_command_line(argc, argv);
 
+	if (resource_in == NULL)
+	{
+		printf("%s: ERROR: you have to specify the resource name with `--resource-in`\n", argv[0]);
+		exit(-1);
+	}
+
 	char resource_basename[256];
 	char resource_extension[256];
 	
@@ -35,9 +40,7 @@ int main(int argc, char** argv)
 	string::strncat(out_filename, resource_basename, 512);
 	string::strncat(out_filename, resource_extension, 512);
 
-	resource_out = out_filename;
-
-	printf("%s\n", resource_out);
+	printf("%s\n", out_filename);
 
 	return 0;
 }
@@ -114,4 +117,4 @@ void print_help_message(const char* program_name)
 	printf("  --help                  Show this help.\n");
 	printf("  --resource-in <name>    The <name> of the input resource.\n");
 	printf("  --seed <value>          The unsigned integer <value> of the hash seed.\n");
-}
+}

+ 18 - 0
tools/compilers/tga/main.cpp

@@ -19,6 +19,24 @@ void parse_command_line(int argc, char** argv);
 int main(int argc, char** argv)
 {
 	parse_command_line(argc, argv);
+
+	if (root_path == NULL)
+	{
+		printf("%s: ERROR: you have to specify the root path with `--root-path`\n", argv[0]);
+		exit(-1);
+	}
+
+	if (dest_path == NULL)
+	{
+		printf("%s: ERROR: you have to specify the destination path with `--dest-path`\n", argv[0]);
+		exit(-1);
+	}
+
+	if (resource_in == NULL)
+	{
+		printf("%s: ERROR: you have to specify the resource name with `--resource-in`\n", argv[0]);
+		exit(-1);
+	}
 	
 	// FIXME: validate input
 

+ 18 - 0
tools/compilers/txt/main.cpp

@@ -43,6 +43,24 @@ void parse_command_line(int argc, char** argv);
 int main(int argc, char** argv)
 {
 	parse_command_line(argc, argv);
+
+	if (root_path == NULL)
+	{
+		printf("%s: ERROR: you have to specify the root path with `--root-path`\n", argv[0]);
+		exit(-1);
+	}
+
+	if (dest_path == NULL)
+	{
+		printf("%s: ERROR: you have to specify the destination path with `--dest-path`\n", argv[0]);
+		exit(-1);
+	}
+
+	if (resource_in == NULL)
+	{
+		printf("%s: ERROR: you have to specify the resource name with `--resource-in`\n", argv[0]);
+		exit(-1);
+	}
 	
 	// FIXME: validate input