<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>libmemo/messaging.h</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -26,6 +26,7 @@
 #include &quot;messages.h&quot;
 #include &quot;xmalloc.h&quot;
 #include &quot;macros.h&quot;
+#include &quot;messaging.h&quot;
 
 #define REPLY_PARSE_SCRIPT LIBDIR&quot;/parse-reply.pl&quot;
 #define failed(x) die(&quot;%s failed at %s:%i\n&quot;, x, __FILE__, __LINE__)
@@ -36,13 +37,11 @@ memo_send_test(memo_database *db, unsigned words, const char *email) {
 }
 
 /*
- * TODO: split this function into smaller ones. It's huge.
- * A general refactoring would also be welcome.
+ * TODO: A general refactoring would be welcome.
  */
 int
 memo_check_reply(FILE *reply, memo_database *db, char **report) {
 	int input[2], output[2], pid;
-	char buf[50];
 	if (pipe(input) || pipe(output))
 		failed(&quot;pipe&quot;);
 	if ((pid = fork()) &lt; 0) {
@@ -60,55 +59,65 @@ memo_check_reply(FILE *reply, memo_database *db, char **report) {
 	} else {
 		/* We're the parent. */
 		int status;
-		FILE *parsed;
 		if (close(input[0]) || close(output[1]))
 			failed(&quot;close&quot;);
-		while (!feof(reply)) {
-			int count;
-			count = fread(buf, sizeof(char), ARRAY_SIZE(buf), reply);
-			if (count &lt; 1)
-				continue;
-			if (write(input[1], buf, count) &lt; 1)
-				die(&quot;write&quot;);
-		}
-		if (close(input[1]))
-			failed(&quot;close&quot;);
+		send_data_to_checking_script(reply, input[1]);
 		if (wait(&amp;status) &lt; 0) {
 			perror(&quot;wait&quot;);
 			failed(&quot;wait&quot;);
 		}
-		if ((parsed = fdopen(output[0],&quot;r&quot;)) == NULL)
-			failed(&quot;fdopen&quot;);
-		while (!feof(parsed)) {
-			/* TODO: That's not a very portable way of reading lines. */
-			int count, match;
-			static int qn = 0, an = 0;
-			static char *question = NULL, *answer = NULL;
-			memo_word *question_word, *answer_word;
-			count = getline(&amp;question, &amp;qn, parsed);
-			if (count &lt; 1)
-				continue;
-			question[count-1] = '\0';
-			count = getline(&amp;answer, &amp;an, parsed);
-			if (count &lt; 1)
-				continue;
-			answer[count-1] = '\0';
-			question_word = memo_database_find_word_by_value(db, question);
+		read_data_from_checking_script(output[0], db);
+	}
+	return 0;
+}
+
+void
+send_data_to_checking_script(FILE *data, int fd) {
+	char buf[50];
+	while (!feof(data)) {
+		int count;
+		count = fread(buf, sizeof(char), ARRAY_SIZE(buf), data);
+		if (count &lt; 1)
+			continue;
+		if (write(fd, buf, count) &lt; 1)
+			die(&quot;write&quot;);
+	}
+	if (close(fd))
+		failed(&quot;close&quot;);
+}
+
+void
+read_data_from_checking_script(int fd, memo_database *db) {
+	FILE *parsed;
+	if ((parsed = fdopen(fd, &quot;r&quot;)) == NULL)
+		failed(&quot;fdopen&quot;);
+	while (!feof(parsed)) {
+		/* TODO: That's not a very portable way of reading lines. */
+		int count, match;
+		static int qn = 0, an = 0;
+		static char *question = NULL, *answer = NULL;
+		memo_word *question_word, *answer_word;
+		count = getline(&amp;question, &amp;qn, parsed);
+		if (count &lt; 1)
+			continue;
+		question[count-1] = '\0';
+		count = getline(&amp;answer, &amp;an, parsed);
+		if (count &lt; 1)
+			continue;
+		answer[count-1] = '\0';
+		question_word = memo_database_find_word_by_value(db, question);
+		if (question_word) {
 			answer_word = memo_database_find_word_by_value(db, answer);
-			if (question_word) {
-				if (answer_word &amp;&amp; memo_word_check_translation(question_word,
-							answer_word) == 0) {
-					memo_word_inc_positive_answers(question_word);
-				} else {
-					memo_word_inc_negative_answers(question_word);
-				}
-				memo_word_update(question_word);
+			if (answer_word &amp;&amp; memo_word_check_translation(question_word,
+						answer_word) == 0) {
+				memo_word_inc_positive_answers(question_word);
+			} else {
+				memo_word_inc_negative_answers(question_word);
 			}
-			if (question_word)
-				memo_word_free(question_word);
+			memo_word_update(question_word);
+			memo_word_free(question_word);
 			if (answer_word)
 				memo_word_free(answer_word);
 		}
 	}
-	return 0;
 }</diff>
      <filename>libmemo/messaging.c</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>b09759ececef9dc02698487692dc97106cdb1f21</id>
    </parent>
  </parents>
  <author>
    <name>Jan St&#281;pie&#324;</name>
    <login>jstepien</login>
    <email>jstepien@users.sourceforge.net</email>
  </author>
  <url>http://github.com/jstepien/memo/commit/6d20c3b1cc7646f53ab759dfef5a1cca158af290</url>
  <id>6d20c3b1cc7646f53ab759dfef5a1cca158af290</id>
  <committed-date>2009-02-19T13:51:00-08:00</committed-date>
  <authored-date>2009-02-19T13:51:00-08:00</authored-date>
  <message>Refactoring in libmemo/messaging.c.</message>
  <tree>94a806b6b90d1a476eeaf6877c2e5963c8aa5c1a</tree>
  <committer>
    <name>Jan St&#281;pie&#324;</name>
    <login>jstepien</login>
    <email>jstepien@users.sourceforge.net</email>
  </committer>
</commit>
