net: Allow connectionless convs to auto bind
[akaros.git] / kern / src / readline.c
index 4ced81d..32548a6 100644 (file)
@@ -1,7 +1,3 @@
-#ifdef __SHARC__
-#pragma nosharc
-#endif
-
 #include <error.h>
 #include <stdio.h>
 #include <assert.h>
@@ -9,7 +5,7 @@
 
 int readline(char *buf, size_t buf_l, const char *prompt, ...)
 {
-       static spinlock_t readline_lock = SPINLOCK_INITIALIZER;
+       static spinlock_t readline_lock = SPINLOCK_INITIALIZER_IRQSAVE;
        int i, c, echoing, retval;
        va_list ap;
 
@@ -24,26 +20,29 @@ int readline(char *buf, size_t buf_l, const char *prompt, ...)
        while (1) {
                c = getchar();
                if (c < 0) {
-                       printk("read error: %e\n", c);  /* %e! */
+                       printk("read error: %d\n", c);
                        retval = i;
                        break;
-               } else if (c >= ' ' && i < buf_l - 1) {
-                       if (echoing)
-                               cputchar(c);
-                       buf[i++] = c;
-               } else if (c == '\b' && i > 0) {
-                       if (echoing)
-                               cputchar(c);
-                       i--;
+               } else if (c == '\b' || c == 0x7f) {
+                       if (i > 0) {
+                               if (echoing)
+                                       cputchar(c);
+                               i--;
+                       }
+                       continue;
                } else if (c == '\n' || c == '\r') {
                        /* sending a \n regardless, since the serial port gives us a \r for
-                        * carriage returns. */
+                        * carriage returns. (probably won't get a \r anymore) */
                        if (echoing)
                                cputchar('\n');
                        assert(i <= buf_l - 1); /* never write to buf_l - 1 til the end */
                        buf[i++] = c;
                        retval =  i;
                        break;
+               } else if (c >= ' ' && i < buf_l - 1) {
+                       if (echoing)
+                               cputchar(c);
+                       buf[i++] = c;
                }
        }
        spin_unlock_irqsave(&readline_lock);