Browse Source

Keep it simple

Piotr Czajkowski 5 years ago
parent
commit
339f697a37
5 changed files with 13 additions and 29 deletions
  1. 6 6
      anonymize.c
  2. 1 1
      comments.c
  3. 1 4
      comments.h
  4. 3 15
      zip.c
  5. 2 3
      zip.h

+ 6 - 6
anonymize.c

@@ -1,7 +1,7 @@
 #include <stdio.h>
 #include "zip.h"
 
-extern int action;
+int deanonymize;
 
 int main(int argc, char **argv) {
 	if (argc < 2) {
@@ -13,19 +13,19 @@ int main(int argc, char **argv) {
 
 	if (argc > 2) {
 		if (strcmp(argv[2], "-d") == 0) {
-			action = 1;
+			deanonymize = 1;
 
 			if (argc > 3) {
-				deanonymize(argv[1], argv[3]);
+				process(argv[1], argv[3]);
 				return 0;
 			}
 
-			deanonymize(argv[1], NULL);
+			process(argv[1], NULL);
 			return 0;
 		}
 		
-		anonymize(argv[1], argv[2]);
+		process(argv[1], argv[2]);
 	}
 	else
-		anonymize(argv[1], NULL);
+		process(argv[1], NULL);
 }

+ 1 - 1
comments.c

@@ -94,7 +94,7 @@ int deanonymizeAuthors(const xmlXPathObjectPtr authors) {
 }
 
 int processAuthors(const xmlXPathObjectPtr authors) {
-	if (action == DEANONYMIZE)
+	if (deanonymize)
 		return deanonymizeAuthors(authors);
 	
 	return anonymizeAuthors(authors);

+ 1 - 4
comments.h

@@ -3,10 +3,7 @@
 #include <binn.h>
 #include "xmlbuff.h"
 
-#define ANONYMIZE 0
-#define DEANONYMIZE 1
-
 extern char binnFile[256];
-extern int action;
+extern int deanonymize;
 
 int anonymizeComments(XMLBuff *infile);

+ 3 - 15
zip.c

@@ -60,27 +60,14 @@ int processDOCX(const char *infile, const char *outfile) {
 	return 1;
 }
 
-int anonymize(const char *infile, char *outfile) {
-	if (!outfile || strcmp(infile, outfile) == 0){
+int process(const char *infile, char *outfile) {
+	if (!outfile || deanonymize) {
 		strcat(binnFile, infile);
 		strcat(binnFile, ".bin");
-
-		const char *outfile = "tmpFile.docx";
-		processDOCX(infile, outfile);
-		remove(infile);
-		rename(outfile, infile);
 	} else {
 		strcat(binnFile, outfile);
 		strcat(binnFile, ".bin");
-
-		processDOCX(infile, outfile);
 	}
-	return 1;
-}
-
-int deanonymize(const char *infile, char *outfile) {
-	strcat(binnFile, infile);
-	strcat(binnFile, ".bin");
 
 	if (!outfile || strcmp(infile, outfile) == 0){
 		const char *outfile = "tmpFile.docx";
@@ -90,5 +77,6 @@ int deanonymize(const char *infile, char *outfile) {
 	} else {
 		processDOCX(infile, outfile);
 	}
+
 	return 1;
 }

+ 2 - 3
zip.h

@@ -5,7 +5,6 @@
 #include "comments.h"
 
 char binnFile[256];
-int action;
+extern int deanonymize;
 
-int anonymize(char const *infile, char *outfile);
-int deanonymize(char const *infile, char *outfile);
+int process(char const *infile, char *outfile);