Use mutexes in epoll instead of spinlocks
[akaros.git] / user / parlib / debugfmt.c
index 8804e0b..1392b68 100644 (file)
@@ -1,19 +1,14 @@
-#include <ros/common.h>
+#include <parlib/common.h>
 #include <ros/errno.h>
 #include <string.h>
-#include <ros_debug.h>
+#include <parlib/ros_debug.h>
 
 /*
  * Print a number (base <= 16) in reverse order,
  * using specified putch function and associated pointer putdat.
  */
-#ifdef __DEPUTY__
-static void printnum(void (*putch)(int, TV(t)), TV(t) putdat,
-                        unsigned long long num, unsigned base, int width, int padc)
-#else
 static void printnum(void (*putch)(int, void**), void **putdat,
                         unsigned long long num, unsigned base, int width, int padc)
-#endif
 {
        // first recursively print all preceding (more significant) digits
        if (num >= base) {
@@ -28,42 +23,12 @@ static void printnum(void (*putch)(int, void**), void **putdat,
        putch("0123456789abcdef"[num % base], putdat);
 }
 
-// Get an unsigned int of various possible sizes from a varargs list,
-// depending on the lflag parameter.
-static unsigned long long getuint(va_list *ap, int lflag)
-{
-       if (lflag >= 2)
-               return va_arg(*ap, unsigned long long);
-       else if (lflag)
-               return va_arg(*ap, unsigned long);
-       else
-               return va_arg(*ap, unsigned int);
-}
-
-// Same as getuint but signed - can't use getuint
-// because of sign extension
-static long long getint(va_list *ap, int lflag)
-{
-       if (lflag >= 2)
-               return va_arg(*ap, long long);
-       else if (lflag)
-               return va_arg(*ap, long);
-       else
-               return va_arg(*ap, int);
-}
-
-
 // Main function to format and print a string.
-#ifdef __DEPUTY__
-void ros_debugfmt(void (*putch)(int, TV(t)), TV(t) putdat, const char *fmt, ...);
-void ros_vdebugfmt(void (*putch)(int, TV(t)), TV(t) putdat, const char *fmt, va_list ap)
-#else
-void ros_debugfmt(void (*putch)(int, void**), void **putdat, const char *fmt, ...);
-void ros_vdebugfmt(void (*putch)(int, void**), void **putdat, const char *fmt, va_list ap)
-#endif
+void akaros_vprintfmt(void (*putch)(int, void**), void **putdat,
+                      const char *fmt, va_list ap)
 {
-       register const char *NTS p;
-       const char *NTS last_fmt;
+       register const char *p;
+       const char *last_fmt;
        register int ch, err;
        unsigned long long num;
        int base, lflag, width, precision, altflag;
@@ -145,9 +110,16 @@ void ros_vdebugfmt(void (*putch)(int, void**), void **putdat, const char *fmt, v
                        break;
 
                // string
+/*
+               case 'r':
+                       p = current_errstr();
+                       /* oh, barf. Now we look like glibc. * /
+                       goto putstring;
+*/
                case 's':
-                       if ((p = va_arg(ap, char *NT)) == NULL)
+                       if ((p = va_arg(ap, char *)) == NULL)
                                p = "(null)";
+//putstring:
                        if (width > 0 && padc != '-')
                                for (width -= strnlen(p, precision); width > 0; width--)
                                        putch(padc, putdat);
@@ -163,9 +135,13 @@ void ros_vdebugfmt(void (*putch)(int, void**), void **putdat, const char *fmt, v
                                putch(' ', putdat);
                        break;
 
-               // (signed) decimal
-               case 'd':
-                       num = getint(&ap, lflag);
+               case 'd': /* (signed) decimal */
+                       if (lflag >= 2)
+                               num = va_arg(ap, long long);
+                       else if (lflag)
+                               num = va_arg(ap, long);
+                       else
+                               num = va_arg(ap, int);
                        if ((long long) num < 0) {
                                putch('-', putdat);
                                num = -(long long) num;
@@ -173,17 +149,21 @@ void ros_vdebugfmt(void (*putch)(int, void**), void **putdat, const char *fmt, v
                        base = 10;
                        goto number;
 
-               // unsigned decimal
-               case 'u':
-                       num = getuint(&ap, lflag);
-                       base = 10;
-                       goto number;
-
-               // (unsigned) octal
-               case 'o':
-                       // should do something with padding so it's always 3 octits
-                       num = getuint(&ap, lflag);
-                       base = 8;
+               case 'u': /* unsigned decimal */
+               case 'o': /* (unsigned) octal */
+               case 'x': /* (unsigned) hexadecimal */
+                       if (lflag >= 2)
+                               num = va_arg(ap, unsigned long long);
+                       else if (lflag)
+                               num = va_arg(ap, unsigned long);
+                       else
+                               num = va_arg(ap, unsigned int);
+                       if (ch == 'u')
+                               base = 10;
+                       else if (ch == 'o')
+                               base = 8;
+                       else    /* x */
+                               base = 16;
                        goto number;
 
                // pointer
@@ -195,10 +175,6 @@ void ros_vdebugfmt(void (*putch)(int, void**), void **putdat, const char *fmt, v
                        base = 16;
                        goto number;
 
-               // (unsigned) hexadecimal
-               case 'x':
-                       num = getuint(&ap, lflag);
-                       base = 16;
                number:
                        printnum(putch, putdat, num, base, width, padc);
                        break;
@@ -218,17 +194,3 @@ void ros_vdebugfmt(void (*putch)(int, void**), void **putdat, const char *fmt, v
                }
        }
 }
-
-#ifdef __DEPUTY__
-void ros_debugfmt(void (*putch)(int, TV(t)), TV(t) putdat, const char *fmt, ...)
-#else
-void ros_debugfmt(void (*putch)(int, void**), void **putdat, const char *fmt, ...)
-#endif
-{
-       va_list ap;
-
-       va_start(ap, fmt);
-       ros_vdebugfmt(putch, putdat, fmt, ap);
-       va_end(ap);
-}
-