Browse Source

Moving from dict to binn

Piotr Czajkowski 5 years ago
parent
commit
792a54c4e4
3 changed files with 17 additions and 15 deletions
  1. 13 11
      comments.c
  2. 1 1
      comments.h
  3. 3 3
      makefile

+ 13 - 11
comments.c

@@ -3,37 +3,39 @@
 #include "comments.h"
 #include "stopif.h"
 
-char* anonymizeAuthor(dictionary *authors, const xmlChar *authorName) {
+char* anonymizeAuthor(binn *authors, const xmlChar *authorName) {
+	static int authorsCount = 0;
+
 	char *name = (char*)authorName;
-	char *newName = (char*)dictionary_find(authors, name);
+	char *newName = binn_object_str(authors, name);
 
 	if (newName)
 		return newName;
 
-	asprintf(&newName, "Author%d", authors->length+1);
-	dictionary_add(authors, name, newName);
+	asprintf(&newName, "Author%d", ++authorsCount);
+	binn_object_set_str(authors, name, newName);
 	free(newName);
-	return (char*)dictionary_find(authors, name);
+	return binn_object_str(authors, name);
 }
 
-void printAuthors(const dictionary *authors) {
-	for (int i=0; i<authors->length; i++)
-		printf("\"%s\" is now \"%s\"\n", authors->pairs[i]->key, (char*)authors->pairs[i]->value);
+void printAuthors(const xmlChar *authorName, const char *anonName) {
+	printf("\"%s\" is now \"%s\"\n", authorName, anonName);
 }
 
 int processAuthors(const xmlXPathObjectPtr authors) {
-	dictionary *anonAuthors = dictionary_new();
+	binn *anonAuthors = binn_object();
 
 	for (int i=0; i < authors->nodesetval->nodeNr; i++){
 		xmlChar *authorName = (xmlChar*)"";		
 		authorName = xmlNodeGetContent(authors->nodesetval->nodeTab[i]);
 		char *anonAuthor = anonymizeAuthor(anonAuthors, authorName);
 		xmlNodeSetContent(authors->nodesetval->nodeTab[i], (xmlChar*)anonAuthor);
+
+		printAuthors(authorName, anonAuthor);
 		xmlFree(authorName);
 	}
 
-	printAuthors(anonAuthors);
-	dictionary_free(anonAuthors);
+	binn_free(anonAuthors);
 	return 1;
 }
 

+ 1 - 1
comments.h

@@ -1,6 +1,6 @@
 #include <libxml2/libxml/xpath.h>
 #include <libxml2/libxml/xpathInternals.h>
-#include "dict.h"
+#include <binn.h>
 #include "xmlbuff.h"
 
 int anonymizeComments(XMLBuff *infile);

+ 3 - 3
makefile

@@ -1,11 +1,11 @@
 CFLAGS=`pkg-config --cflags --libs libxml-2.0` -g -Wall -Wextra -O3 -std=gnu99
-LDLIBS=`pkg-config --libs libxml-2.0` -larchive
+LDLIBS=`pkg-config --libs libxml-2.0` -larchive -lbinn
 objects=keyval.o dict.o comments.o zip.o xmlbuff.o
 mingwCFLAGS=`x86_64-w64-mingw32-pkg-config --cflags --libs libxml-2.0` -g -Wall -Wextra -O3 -std=gnu99
-mingwLDLIBS=`x86_64-w64-mingw32-pkg-config --libs libxml-2.0` -larchive
+mingwLDLIBS=`x86_64-w64-mingw32-pkg-config --libs libxml-2.0` -larchive -lbinn
 mingw=x86_64-w64-mingw32-gcc
 MACCFLAGS=`pkg-config --cflags --libs libxml-2.0 libarchive` -g -Wall -Wextra -O3 -std=gnu99
-MACLDLIBS=`pkg-config --libs libxml-2.0 libarchive`
+MACLDLIBS=`pkg-config --libs libxml-2.0 libarchive` -lbinn
 
 anonymize: $(objects)