Browse Source

Formatting

Piotr Czajkowski 6 years ago
parent
commit
e80b83cdcb
3 changed files with 58 additions and 58 deletions
  1. 31 31
      bom.c
  2. 19 19
      bomToolkit.c
  3. 8 8
      test_bom.c

+ 31 - 31
bom.c

@@ -7,66 +7,66 @@ int checkBOM(char *filePath) {
 	FILE *inputFile = fopen(filePath, "r");
 	if (inputFile == NULL) return ERROR;
 
-    unsigned char check[BOMSIZE];
-    if (BOMSIZE != fread(check, BOMSIZE, 1, inputFile)) {
-        if (feof(inputFile)) return NOBOM;
-        if (ferror(inputFile)) return ERROR;
-    }
+	unsigned char check[BOMSIZE];
+	if (BOMSIZE != fread(check, BOMSIZE, 1, inputFile)) {
+		if (feof(inputFile)) return NOBOM;
+		if (ferror(inputFile)) return ERROR;
+	}
 	if (fclose(inputFile)) return ERROR;
 
-    if (!memcmp(&bom, check, BOMSIZE)) return HASBOM;
+	if (!memcmp(&bom, check, BOMSIZE)) return HASBOM;
 	return NOBOM;
 }
 
 char *tempFileName = "tempFile";
 
 int removeBOM(char *filePath) {
-    if (NOBOM == checkBOM(filePath)) return SUCCESS;
+	if (NOBOM == checkBOM(filePath)) return SUCCESS;
 
 	FILE *inputFile = fopen(filePath, "r");
-    if (inputFile == NULL) return ERROR;
+	if (inputFile == NULL) return ERROR;
 
 	if (fseek(inputFile, BOMSIZE, SEEK_SET)) return ERROR;
 
 	FILE *tempFile = fopen(tempFileName, "w");
-    if (tempFile== NULL) return ERROR;
+	if (tempFile== NULL) return ERROR;
 
 	int c = fgetc(inputFile);
 	while (c != EOF) {
 		if (EOF == fputc(c, tempFile)) return ERROR;
 		c = fgetc(inputFile);
 	}
-    if (fclose(tempFile)) return ERROR;
-    if (fclose(inputFile)) return ERROR;
+	if (fclose(tempFile)) return ERROR;
+	if (fclose(inputFile)) return ERROR;
 
-    if (remove(filePath)) return ERROR;
-    if (rename(tempFileName, filePath)) return ERROR;
+	if (remove(filePath)) return ERROR;
+	if (rename(tempFileName, filePath)) return ERROR;
 
-    return SUCCESS;
+	return SUCCESS;
 }
 
 int addBOM(char *filePath) {
-    if (HASBOM == checkBOM(filePath)) return SUCCESS;
+	if (HASBOM == checkBOM(filePath)) return SUCCESS;
 
-    FILE *inputFile = fopen(filePath, "r");
-    if (inputFile == NULL) return ERROR;
+	FILE *inputFile = fopen(filePath, "r");
+	if (inputFile == NULL) return ERROR;
 
-    FILE *tempFile = fopen(tempFileName, "w");
-    if (tempFile== NULL) return ERROR;
+	FILE *tempFile = fopen(tempFileName, "w");
+	if (tempFile== NULL) return ERROR;
 
-    for (int i = 0; i < BOMSIZE; i++)
-        if (EOF == fputc(bom[i], tempFile)) return ERROR;
+	for (int i = 0; i < BOMSIZE; i++)
+		if (EOF == fputc(bom[i], tempFile)) return ERROR;
 
-    int c = fgetc(inputFile);
-    while (c != EOF) {
-        if (EOF == fputc(c, tempFile)) return ERROR;
-        c = fgetc(inputFile);
-    }
-    if (fclose(tempFile)) return ERROR;
-    if (fclose(inputFile)) return ERROR;
+	int c = fgetc(inputFile);
+	while (c != EOF) {
+		if (EOF == fputc(c, tempFile)) return ERROR;
+		c = fgetc(inputFile);
+	}
+	if (fclose(tempFile)) return ERROR;
+	if (fclose(inputFile)) return ERROR;
 
-    if (remove(filePath)) return ERROR;
-    if (rename(tempFileName, filePath)) return ERROR;
+	if (remove(filePath)) return ERROR;
+	if (rename(tempFileName, filePath)) return ERROR;
 
-    return SUCCESS;
+	return SUCCESS;
 }

+ 19 - 19
bomToolkit.c

@@ -1,28 +1,28 @@
 #include "bom.h"
 
 void usage(char *executable) {
-    printf("Usage:\n%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);
+	printf("Usage:\n%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;
-    } 
+	if (argc < 3) {
+		usage(argv[0]);
+		return 1;
+	} 
 
-    char *inputFileName = argv[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;
+	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;
 }

+ 8 - 8
test_bom.c

@@ -13,19 +13,19 @@ void testCheckBOM(void) {
 char *fileBOMRemoval = "./testRemove";
 
 void testRemoveBOM(void) {
-    int result = removeBOM(fileBOMRemoval);
+	int result = removeBOM(fileBOMRemoval);
 	assert(ERROR != result);
-    assert(SUCCESS == result);
-    assert(NOBOM == checkBOM(fileBOMRemoval));
+	assert(SUCCESS == result);
+	assert(NOBOM == checkBOM(fileBOMRemoval));
 }
 
 char *fileBOMAddition = "./testAdd";
 
 void testAddBOM(void) {
-    int result = addBOM(fileBOMAddition);
-    assert(ERROR != result);
-    assert(SUCCESS == result);
-    assert(HASBOM == checkBOM(fileBOMAddition));
+	int result = addBOM(fileBOMAddition);
+	assert(ERROR != result);
+	assert(SUCCESS == result);
+	assert(HASBOM == checkBOM(fileBOMAddition));
 }
 
 int main(int argc, char **argv) {
@@ -33,6 +33,6 @@ int main(int argc, char **argv) {
 	(void)argv;
 	testCheckBOM();
 	testRemoveBOM();
-    testAddBOM();
+	testAddBOM();
 	printf("OK\n");
 }