Extract enum callback_status to a separate module

Document the interface, refer to this documentation at declarations of
each_* functions.
diff --git a/ChangeLog b/ChangeLog
index 48b7ede..c08f83d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2012-09-25  Petr Machata  <pmachata@redhat.com>
 
+	* callback.h: New file.
+	* proc.h (enum callback_status): Move to callback.h.
+
+2012-09-25  Petr Machata  <pmachata@redhat.com>
+
 	* sysdeps/linux-gnu/x86/arch.h (FORK_EXEC_SYSCALLS): Remove.
 
 2012-09-22  Petr Machata  <pmachata@redhat.com>
diff --git a/Makefile.am b/Makefile.am
index 177a498..47161f8 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -85,6 +85,7 @@
 	type.h \
 	value.h \
 	value_dict.h \
+	callback.h \
 	expr.h \
 	fetch.h \
 	vect.h \
diff --git a/callback.h b/callback.h
new file mode 100644
index 0000000..31e5c8f
--- /dev/null
+++ b/callback.h
@@ -0,0 +1,50 @@
+/*
+ * This file is part of ltrace.
+ * Copyright (C) 2011,2012 Petr Machata, Red Hat Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ */
+
+#ifndef _CALLBACK_H_
+#define _CALLBACK_H_
+
+/* Notes on the iteration interface used across ltrace.  Typically the
+ * iteration function looks something like this:
+ *
+ *   foo *each_foo(foo *start_after,
+ *                 enum callback_status (*cb)(foo *f, void *data),
+ *                 void *data);
+ *
+ * The iteration starts after the element designated by START_AFTER,
+ * or at the first element if START_AFTER is NULL.  CB is then called
+ * for each element of the collection.  DATA is passed verbatim to CB.
+ * If CB returns CBS_STOP, the iteration stops and the current element
+ * is returned.  That element can then be passed as START_AFTER to
+ * restart the iteration.  NULL is returned when iteration ends.
+ *
+ * CBS_FAIL is not currently handled, and essentially means the same
+ * thing as CBS_STOP.  There's no provision for returning error
+ * states.  Errors need to be signaled to the caller via DATA,
+ * together with any other data that the callback needs.
+ */
+enum callback_status {
+	CBS_STOP, /* The iteration should stop.  */
+	CBS_CONT, /* The iteration should continue.  */
+	CBS_FAIL, /* There was an error.  The iteration should stop
+		   * and return error.  */
+};
+
+#endif /* _CALLBACK_H_ */
diff --git a/filter.c b/filter.c
index 003010d..bf77b76 100644
--- a/filter.c
+++ b/filter.c
@@ -25,6 +25,7 @@
 
 #include "filter.h"
 #include "library.h"
+#include "callback.h"
 
 void
 filter_init(struct filter *filt)
diff --git a/library.c b/library.c
index 2ce3427..cbd4a35 100644
--- a/library.c
+++ b/library.c
@@ -25,8 +25,9 @@
 #include <assert.h>
 
 #include "library.h"
-#include "proc.h" // for enum callback_status
+#include "callback.h"
 #include "debug.h"
+#include "dict.h"
 #include "backend.h" // for arch_library_symbol_init, arch_library_init
 
 #ifndef ARCH_HAVE_LIBRARY_DATA
diff --git a/library.h b/library.h
index 876a533..f207502 100644
--- a/library.h
+++ b/library.h
@@ -23,6 +23,7 @@
 #define _LIBRARY_H_
 
 #include <stdint.h>
+#include "callback.h"
 #include "sysdep.h"
 
 struct Process;
@@ -144,9 +145,8 @@
 void library_set_pathname(struct library *lib,
 			  const char *new_name, int own_name);
 
-/* Iterate through list of symbols of library LIB.  Restarts are
- * supported via START_AFTER (see each_process for details of
- * iteration interface).  */
+/* Iterate through list of symbols of library LIB.  See callback.h for
+ * notes on this interface.  */
 struct library_symbol *library_each_symbol
 	(struct library *lib, struct library_symbol *start_after,
 	 enum callback_status (*cb)(struct library_symbol *, void *),
diff --git a/proc.h b/proc.h
index 64c37a9..b61e420 100644
--- a/proc.h
+++ b/proc.h
@@ -34,20 +34,11 @@
 #include "ltrace.h"
 #include "dict.h"
 #include "sysdep.h"
+#include "callback.h"
 
 struct library;
 struct breakpoint;
 
-/* XXX Move this somewhere where it makes sense.  When the mess in
- * common.h is disentangled, that would actually be a good place for
- * this.  */
-enum callback_status {
-	CBS_STOP, /* The iteration should stop.  */
-	CBS_CONT, /* The iteration should continue.  */
-	CBS_FAIL, /* There was an error.  The iteration should stop
-		   * and return error.  */
-};
-
 struct event_handler {
 	/* Event handler that overrides the default one.  Should
 	 * return NULL if the event was handled, otherwise the
@@ -184,28 +175,16 @@
  * Returns 0 on success or a negative value on failure.  */
 int process_clone(struct Process *retp, struct Process *proc, pid_t pid);
 
-/* Iterate through the processes that ltrace currently traces.  CB is
- * called for each process.  Tasks are considered to be processes for
- * the purpose of this iterator.
- *
- * Notes on this iteration interface: The iteration starts after the
- * process designated by START_AFTER, or at the first process if
- * START_AFTER is NULL.  DATA is passed verbatim to CB.  If CB returns
- * CBS_STOP, the iteration stops and the current iterator is returned.
- * That iterator can then be used to restart the iteration.  NULL is
- * returned when iteration ends.
- *
- * There's no provision for returning error states.  Errors need to be
- * signaled to the caller via DATA, together with any other data that
- * the callback needs.  */
+/* Iterate through the processes that ltrace currently traces.  Tasks
+ * are considered to be processes for the purpose of this iterator.
+ * See callback.h for notes on iteration interfaces.  */
 Process *each_process(Process *start_after,
 		      enum callback_status (*cb)(struct Process *proc,
 						 void *data),
 		      void *data);
 
-/* Iterate through list of tasks of given process PROC.  Restarts are
- * supported via START_AFTER (see each_process for details of
- * iteration interface).  */
+/* Iterate through list of tasks of given process PROC.  See
+ * callback.h for notes on iteration interfaces.  */
 Process *each_task(struct Process *proc, struct Process *start_after,
 		   enum callback_status (*cb)(struct Process *proc,
 					      void *data),
@@ -227,8 +206,8 @@
  * was found and unlinked, otherwise returns a negative value.  */
 int proc_remove_library(struct Process *proc, struct library *lib);
 
-/* Iterate through the libraries of PROC.  See each_process for
- * detailed description of the iteration interface.  */
+/* Iterate through the libraries of PROC.  See callback.h for notes on
+ * iteration interfaces.  */
 struct library *proc_each_library(struct Process *proc, struct library *start,
 				  enum callback_status (*cb)(struct Process *p,
 							     struct library *l,
@@ -242,8 +221,8 @@
  * does not find BP in PROC, it's hard error guarded by assertion.  */
 void proc_remove_breakpoint(struct Process *proc, struct breakpoint *bp);
 
-/* Iterate through the libraries of PROC.  See each_process for
- * detailed description of the iteration interface.  */
+/* Iterate through the breakpoints of PROC.  See callback.h for notes
+ * on iteration interfaces.  */
 void *proc_each_breakpoint(struct Process *proc, void *start,
 			   enum callback_status (*cb)(struct Process *proc,
 						      struct breakpoint *bp,