Browse Source

Able to save transformation as bin file

Piotr Czajkowski 5 years ago
parent
commit
b683111e19
4 changed files with 21 additions and 5 deletions
  1. 14 5
      comments.c
  2. 2 0
      comments.h
  3. 3 0
      zip.c
  4. 2 0
      zip.h

+ 14 - 5
comments.c

@@ -7,20 +7,28 @@ void printAuthors(const char *authorName, const char *anonName) {
 	printf("\"%s\" is now \"%s\"\n", authorName, anonName);
 }
 
-char* anonymizeAuthor(binn *authors, const xmlChar *authorName) {
+char* anonymizeAuthor(binn *anonAuthors, const xmlChar *authorName) {
 	static int authorsCount = 0;
 
 	char *name = (char*)authorName;
-	char *newName = binn_object_str(authors, name);
+	char *newName = binn_object_str(anonAuthors, name);
 
 	if (newName)
 		return newName;
 
 	asprintf(&newName, "Author%d", ++authorsCount);
-	binn_object_set_str(authors, name, newName);
+	binn_object_set_str(anonAuthors, name, newName);
+	binn_object_set_str(anonAuthors, newName, name);
 	printAuthors(name, newName);
 	free(newName);
-	return binn_object_str(authors, name);
+
+	return binn_object_str(anonAuthors, name);
+}
+
+void saveAuthors(binn *anonAuthors) {
+	FILE *fp = fopen(binnFile, "w");
+	fwrite(binn_ptr(anonAuthors), binn_size(anonAuthors), 1, fp);
+	fclose(fp);
 }
 
 int processAuthors(const xmlXPathObjectPtr authors) {
@@ -33,7 +41,8 @@ int processAuthors(const xmlXPathObjectPtr authors) {
 		xmlNodeSetContent(authors->nodesetval->nodeTab[i], (xmlChar*)anonAuthor);
 		xmlFree(authorName);
 	}
-
+	
+	saveAuthors(anonAuthors);
 	binn_free(anonAuthors);
 	return 1;
 }

+ 2 - 0
comments.h

@@ -3,4 +3,6 @@
 #include <binn.h>
 #include "xmlbuff.h"
 
+char binnFile[256];
+
 int anonymizeComments(XMLBuff *infile);

+ 3 - 0
zip.c

@@ -59,6 +59,9 @@ int processDOCX(const char *infile, const char *outfile) {
 }
 
 int process(const char *infile, char *outfile) {
+	strcat(binnFile, infile);
+	strcat(binnFile, ".bin");
+
 	if (!outfile || strcmp(infile, outfile) == 0){
 		const char *outfile = "tmpFile.docx";
 		processDOCX(infile, outfile);

+ 2 - 0
zip.h

@@ -4,4 +4,6 @@
 #include <string.h>
 #include "comments.h"
 
+extern char binnFile[256];
+
 int process(char const *infile, char *outfile);