diff options
| -rw-r--r-- | .gitignore | 2 | ||||
| -rw-r--r-- | CMakeLists.txt | 3 | ||||
| -rw-r--r-- | main.c | 24 | ||||
| -rw-r--r-- | reloc.h | 1 | ||||
| -rw-r--r-- | version.h.in | 5 | 
5 files changed, 29 insertions, 6 deletions
@@ -7,5 +7,5 @@ cmake_install.cmake  install_manifest.txt  compile_commands.json  CTestTestfile.cmake +build  reloc - diff --git a/CMakeLists.txt b/CMakeLists.txt index fc688f9..583d65c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,9 +1,12 @@  cmake_minimum_required(VERSION 2.8.11)  project(reloc C) +set(VERSION "1.0.0")  set(CMAKE_C_STANDARD 99)  set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 -Wall -Wextra") +configure_file(version.h.in version.h) +include_directories("${CMAKE_BINARY_DIR}")  add_executable(reloc main.c reloc.h)  install(TARGETS reloc  	RUNTIME DESTINATION bin) @@ -115,6 +115,11 @@ void reloc_replace(RelocMatch *match, const char *rstr) {  } +void show_version() { +    printf("%s\n", VERSION); +} + +  int main(int argc, char *argv[]) {      char *program = argv[0];      char *program_relative = strrchr(program, DIRSEP); @@ -122,20 +127,29 @@ int main(int argc, char *argv[]) {          program = program_relative + 1;      } +    for (int i = 0; i < argc; i++) { +        if (!strcmp(argv[i], "--version") || !strcmp(argv[i], "-V")) { +            show_version(); +            exit(0); +        } +    } +      if (argc < 5) { -        printf("%s <str1> <str2> <input_file> <output_file>\n" +        printf("%s [-V] <str1> <str2> <input_file> <output_file>\n"                 "\n"                 "Arguments:\n" -               "str1 - Pattern to search for\n" -               "str2 - Replace str1 with contents of str2\n" -               "input_file - Path to input file\n" -               "output_file - Path to output file\n" +               "--version (-V) - Display version and exit\n" +               "str1           - Pattern to search for\n" +               "str2           - Replace str1 with contents of str2\n" +               "input_file     - Path to input file\n" +               "output_file    - Path to output file\n"                 "\n"                 "Example:\n"                 "%s /original/path /new/path input.bin output.bin\n"                 "\n", program, program);          exit(1);      } +      char *needle = strdup(argv[1]);      char *replacement = strdup(argv[2]);      char *input_file = strdup(argv[3]); @@ -8,6 +8,7 @@  #include <stdio.h>  #include <stdlib.h>  #include <string.h> +#include "version.h"  #if defined(_WIN32) || defined(_WIN64)  #define DIRSEP '\\' diff --git a/version.h.in b/version.h.in new file mode 100644 index 0000000..d6a4edf --- /dev/null +++ b/version.h.in @@ -0,0 +1,5 @@ +#ifndef RELOC_VERSION_H + +#define VERSION "1.0.0" + +#endif // RELOC_VERSION_H  | 
