aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbeber <beber>2005-12-06 15:48:53 +0000
committerbeber <beber>2005-12-06 15:48:53 +0000
commitc61f1a44f1754dea185541e556f1091838aec693 (patch)
tree5fa8a72d7ef9486673b051ac2e7b6adeffa90d6b
parentAdd ebuild (diff)
downloadespik-c61f1a44f1754dea185541e556f1091838aec693.tar.xz
start a function for debug printf
-rw-r--r--src/espik_debug.c38
-rw-r--r--src/espik_debug.h1
-rw-r--r--tst/va_test.c47
3 files changed, 84 insertions, 2 deletions
diff --git a/src/espik_debug.c b/src/espik_debug.c
index 0ea9c24..d072890 100644
--- a/src/espik_debug.c
+++ b/src/espik_debug.c
@@ -1,8 +1,9 @@
-#include "espik_debug.h"
-
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
+#include <sys/varargs.h>
+
+#include "espik_debug.h"
#ifdef __GLIBC__
# include <execinfo.h>
@@ -12,6 +13,39 @@
# include <signal.h>
#endif /* _ESPIK_DEBUG_ */
+static int indent_level = 0;
+
+void espik_debug_print (char *fct, ...)
+{
+#if _ESPIK_DEBUG_
+ va_list ap;
+ char c, *s;
+ int d;
+
+ va_start (ap, fct);
+ while (*fct)
+ {
+ fprintf (stderr, ">fct : %c\n", *(fct+1));
+ switch (*fct++)
+ {
+ case 's': s = va_arg (ap, char*);
+ fprintf (stderr, "%s", s);
+ break;
+ case 'd': d = va_arg (ap, int);
+ fprintf (stderr, "%d", d);
+ break;
+ case 'c': c = va_arg (ap, char);
+ fprintf (stderr, "%c", c);
+ break;
+ default : fprintf (stderr, "Unknown type : %c\n", *fct);
+ }
+ fprintf (stderr, "<fct : %c\n", *fct);
+ }
+
+ va_end (ap);
+#endif
+}
+
inline void espik_debug_bt (int num)
{
#ifdef __GLIBC__
diff --git a/src/espik_debug.h b/src/espik_debug.h
index 5baacf8..c1f35f3 100644
--- a/src/espik_debug.h
+++ b/src/espik_debug.h
@@ -3,6 +3,7 @@
#include "espik_global.h"
+void espik_debug_print (char *fct, ...);
inline void espik_bt (void);
void espik_debug_init();
void kill_me (short num);
diff --git a/tst/va_test.c b/tst/va_test.c
new file mode 100644
index 0000000..d92e1aa
--- /dev/null
+++ b/tst/va_test.c
@@ -0,0 +1,47 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdarg.h>
+
+void espik_debug_print (char *fct, ...)
+{
+ va_list ap;
+ char c, *s;
+ int d, e;
+
+ va_start (ap, fct);
+ printf("fct : %s\n", *(fct+1));
+ while (*fct)
+ {
+// fprintf (stderr, ">fct : %c\n", *(fct+1));
+ switch (*fct++)
+ {
+ case 's': s = va_arg (ap, char*);
+ fprintf (stderr, "%s", s);
+ break;
+ case 'd': d = va_arg (ap, int);
+ fprintf (stderr, "%d", d);
+ break;
+ default :
+// case 'c':
+ e = va_arg (ap, int);
+ fprintf (stderr, "%c", (char)e);
+ break;
+// default : fprintf (stderr, "Unknown type : %c\n", *fct);
+ }
+ // fprintf (stderr, "<fct : %c\n", *fct);
+ }
+ fprintf (stderr, "\n");
+
+ va_end (ap);
+}
+
+int main()
+{
+ int a = 10;
+ char b = 'c';
+ char c[] = "totomadit";
+
+ espik_debug_print ("a : %d\n", a);
+
+ return (0);
+}