Browse Source

Added bomToolkit

Piotr Czajkowski 6 years ago
parent
commit
f6b70503dd
3 changed files with 42 additions and 3 deletions
  1. 1 0
      .gitignore
  2. 28 0
      bomToolkit.c
  3. 13 3
      makefile

+ 1 - 0
.gitignore

@@ -1 +1,2 @@
 *.dSYM/
+*.o

+ 28 - 0
bomToolkit.c

@@ -0,0 +1,28 @@
+#include "bom.h"
+
+void usage(char *executable) {
+    printf("Usage: %s <filePath> c - to check for BOM.\n", executable);
+    printf("%s <filePath> r - to remove BOM.\n", executable);
+    printf("%s <filePath> a - to add BOM.\n", executable);
+}
+
+int main(int argc, char **argv) {
+    if (argc < 3) {
+        usage(argv[0]);
+        return 1;
+    } 
+
+    char *inputFileName = argv[1];
+
+    if (strcmp(argv[2], "c") == 0) {
+        checkBOM(inputFileName) == HASBOM ? printf("%s has BOM.\n", inputFileName) : printf("%s has no BOM.\n", inputFileName);
+    }
+    if (strcmp(argv[2], "r") == 0) {
+        removeBOM(inputFileName) == SUCCESS ? printf("BOM removed from %s.\n", inputFileName) : printf("Error removing BOM from %s!\n", inputFileName);
+    }
+    if (strcmp(argv[2], "a") == 0) {
+        addBOM(inputFileName) == SUCCESS ? printf("BOM added to %s.\n", inputFileName) : printf("Error adding BOM to %s!\n", inputFileName);
+    }
+   
+    return 0;
+}

+ 13 - 3
makefile

@@ -1,16 +1,26 @@
 CFLAGS=-g -Wall -Wextra -O3 -std=gnu99
 objects=bom.o
+mingw=x86_64-w64-mingw32-gcc
 
-test_bom: $(objects)
+bomToolkit: $(objects)
 
 clean:
 	@rm *.o
 
-test: test_bom
-	@rm *.o
+test:
+	cc $(CFLAGS) -c bom.c
+	cc $(CFLAGS) test_bom.c $(objects) -o test_bom
 	@cp testBOM testRemove
 	@cp testNoBOM testAdd
 	@./test_bom
 	@rm test_bom
 	@rm testRemove
 	@rm testAdd
+
+win/bomToolkit.exe:
+	$(mingw) $(CFLAGS) -c bom.c
+	$(mingw) $(CFLAGS) bomToolkit.c $(objects) -o $@
+
+win: win/bomToolkit.exe
+
+default: bomToolkit