OSDN Git Service

\e$B%A%1%C%H\e(B #30714 xprintf\e$B%b%8%e!<%k$N:o=|$H\e(Bntstdio\e$B%b%8%e!<%k$NDI2C\e(B
authorShinichiro Nakamura <shinta.main.jp@gmail.com>
Sun, 10 Feb 2013 07:53:48 +0000 (16:53 +0900)
committerShinichiro Nakamura <shinta.main.jp@gmail.com>
Sun, 10 Feb 2013 07:53:48 +0000 (16:53 +0900)
http://shinta-main-jp.blogspot.jp/2013/02/ntstdio.html

uzumeapp/kernel/config/blackfin/bsp_bluetank/Makefile.config
uzumeapp/kernel/uzume/ntshell/ntshell_task.c
uzumeapp/kernel/uzume/ntshell/ntstdio.c [new file with mode: 0644]
uzumeapp/kernel/uzume/ntshell/ntstdio.h [new file with mode: 0644]
uzumeapp/kernel/uzume/ntshell/xprintf.c [deleted file]
uzumeapp/kernel/uzume/ntshell/xprintf.h [deleted file]

index ce23fbf..371641c 100644 (file)
@@ -20,7 +20,7 @@ KERNEL_DIR := $(KERNEL_DIR) :$(SRCDIR)/config/$(CPU)/$(SYS) :$(SRCDIR)/config/$(
 KERNEL_ASMOBJS := $(KERNEL_ASMOBJS)
 KERNEL_COBJS := $(KERNEL_COBJS) chip_config.o uart.o chip_debugboot.o chip_dump.o
 KERNEL_COBJS := $(KERNEL_COBJS) i2s_subsystem.o i2c_subsystem.o rotenc.o uzume_callback.o sgtl5000.o bsp_bluetank.o
-KERNEL_COBJS := $(KERNEL_COBJS) ntlibc.o ntopt.o ntshell.o ntshell_task.o text_editor.o text_history.o vtrecv.o vtsend.o xprintf.o
+KERNEL_COBJS := $(KERNEL_COBJS) ntlibc.o ntopt.o ntshell.o ntshell_task.o text_editor.o text_history.o vtrecv.o vtsend.o ntstdio.o
 
 #
 # リンカスクリプトの定義
index be8b52e..b3f37dc 100644 (file)
 #include "ntshell.h"
 #include "ntshell_task.h"
 #include "ntlibc.h"
-#include "xprintf.h"
+#include "ntstdio.h"
 
 #define SERIAL_PORT_ID  (1)
 
 static ntshell_t ntshell;
+static NTSTDIO ntstdio;
 
 static int func_read(char *buf, int cnt, void *extobj)
 {
@@ -78,13 +79,10 @@ static unsigned char uxi(void)
     return c;
 }
 
-void (*xfunc_out)(unsigned char) = uxo;
-unsigned char (*xfunc_in)(void) = uxi;
-
 static int func_callback(const char *text, void *extobj)
 {
     if (ntlibc_strlen(text) > 0) {
-        xprintf("User command is '%s'\r\n", text);
+        ntstdio_printf(&ntstdio, "User command is '%s'\r\n", text);
     }
     return 0;
 }
@@ -96,6 +94,7 @@ void ntshell_task(VP_INT exinf)
                 (IOCTL_CRLF | IOCTL_FCSND | IOCTL_FCRCV))
             );
 
+    ntstdio_init(&ntstdio, uxo, uxi);
     ntshell_init(&ntshell, func_read, func_write, func_callback, (void *)&ntshell);
     ntshell_set_prompt(&ntshell, "UZUME>");
     ntshell_execute(&ntshell);
diff --git a/uzumeapp/kernel/uzume/ntshell/ntstdio.c b/uzumeapp/kernel/uzume/ntshell/ntstdio.c
new file mode 100644 (file)
index 0000000..b09c33f
--- /dev/null
@@ -0,0 +1,369 @@
+/**
+ * @file ntstdio.c
+ * @author Shinichiro Nakamura
+ * @brief Natural Tiny Standard I/O Module
+ * @details
+ * The Natural Tiny Standard I/O Module based on xprintf by ChaN.
+ * xprintf is a universal string handler for user console interface.
+ */
+
+/*------------------------------------------------------------------------/
+/  Universal string handler for user console interface
+/-------------------------------------------------------------------------/
+/
+/  Copyright (C) 2011, ChaN, all right reserved.
+/
+/ * This software is a free software and there is NO WARRANTY.
+/ * No restriction on use. You can use, modify and redistribute it for
+/   personal, non-profit or commercial products UNDER YOUR RESPONSIBILITY.
+/ * Redistributions of source code must retain the above copyright notice.
+/
+/-------------------------------------------------------------------------*/
+
+/*
+ * ===============================================================
+ * Natural Tiny Standard I/O Module
+ * ===============================================================
+ * Copyright (c) 2013 Shinichiro Nakamura
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ * ===============================================================
+ */
+
+#include <stdarg.h>
+#include "ntstdio.h"
+
+#define FLAG_ZERO_PADDED    (1 << 0)
+#define FLAG_LEFT_JUSTIFIED (1 << 1)
+#define FLAG_SIZE_LONG_INT  (1 << 2)
+#define FLAG_SIGNED_DECIMAL (1 << 3)
+
+/*
+ * ntstdio_printf("%d", 1234);            "1234"
+ * ntstdio_printf("%6d,%3d%%", -200, 5);  "  -200,  5%"
+ * ntstdio_printf("%-6u", 100);           "100   "
+ * ntstdio_printf("%ld", 12345678L);      "12345678"
+ * ntstdio_printf("%04x", 0xA3);          "00a3"
+ * ntstdio_printf("%08LX", 0x123ABC);     "00123ABC"
+ * ntstdio_printf("%016b", 0x550F);       "0101010100001111"
+ * ntstdio_printf("%s", "String");        "String"
+ * ntstdio_printf("%-4s", "abc");         "abc "
+ * ntstdio_printf("%4s", "abc");          " abc"
+ * ntstdio_printf("%c", 'a');             "a"
+ * ntstdio_printf("%f", 10.0);            <ntstdio_printf lacks floating point support>
+ */
+
+static void xvprintf(NTSTDIO *handle, const char *fmt, va_list arp)
+{
+    unsigned int i, j;
+    unsigned int flag, radix, width;
+    unsigned long value;
+    char s[16], c, d, *p;
+
+    while (1) {
+        /*
+         * Get a character.
+         */
+        c = *fmt++;
+        if (!c) {
+            /*
+             * End of the format.
+             */
+            break;
+        }
+        if (c != '%') {
+            /*
+             * Pass through it if not a % sequense
+             */
+            ntstdio_putc(handle, c);
+            continue;
+        }
+
+        /*
+         * Reset the flag.
+         */
+        flag = 0;
+
+        /*
+         * Get the first character of the sequense.
+         */
+        c = *fmt++;
+        if (c == '0') {
+            flag = FLAG_ZERO_PADDED;
+            c = *fmt++;
+        } else {
+            if (c == '-') {
+                flag = FLAG_LEFT_JUSTIFIED;
+                c = *fmt++;
+            }
+        }
+        /*
+         * Calculate the minimum width.
+         */
+        for (width = 0; (c >= '0') && (c <= '9'); c = *fmt++) {
+            width = (width * 10) + (c - '0');
+        }
+        if ((c == 'l') || (c == 'L')) {
+            flag |= FLAG_SIZE_LONG_INT;
+            c = *fmt++;
+        }
+        if (!c) {
+            /*
+             * End of the format.
+             */
+            break;
+        }
+        d = c;
+        if (d >= 'a') {
+            d -= 0x20;
+        }
+        /* Type is... */
+        switch (d) {
+            case 'S' :
+                /* String */
+                p = va_arg(arp, char*);
+                for (j = 0; p[j]; j++) {
+                }
+                while (!(flag & FLAG_LEFT_JUSTIFIED) && (j++ < width)) {
+                    ntstdio_putc(handle, ' ');
+                }
+                ntstdio_puts(handle, p);
+                while (j++ < width) {
+                    ntstdio_putc(handle, ' ');
+                }
+                continue;
+            case 'C' :
+                /* Character */
+                ntstdio_putc(handle, (char)va_arg(arp, int));
+                continue;
+            case 'B' :
+                /* Binary */
+                radix = 2;
+                break;
+            case 'O' :
+                /* Octal */
+                radix = 8;
+                break;
+            case 'D' :
+                /* Signed decimal */
+                radix = 10;
+                break;
+            case 'U' :
+                /* Unsigned decimal */
+                radix = 10;
+                break;
+            case 'X' :
+                /* Hexdecimal */
+                radix = 16;
+                break;
+            default:
+                /* Unknown type (passthrough) */
+                ntstdio_putc(handle, c);
+                continue;
+        }
+
+        /*
+         * Get an argument and put it in numeral.
+         */
+        value = (flag & FLAG_SIZE_LONG_INT) ? va_arg(arp, long) : ((d == 'D') ? (long)va_arg(arp, int) : (long)va_arg(arp, unsigned int));
+        if ((d == 'D') && (value & 0x80000000)) {
+            value = 0 - value;
+            flag |= FLAG_SIGNED_DECIMAL;
+        }
+        i = 0;
+        do {
+            d = (char)(value % radix);
+            value /= radix;
+            if (d > 9) {
+                d += (c == 'x') ? 0x27 : 0x07;
+            }
+            s[i++] = d + '0';
+        } while (value && (i < sizeof(s)));
+        if (flag & FLAG_SIGNED_DECIMAL) {
+            s[i++] = '-';
+        }
+        j = i;
+        d = (flag & FLAG_ZERO_PADDED) ? '0' : ' ';
+        while (!(flag & FLAG_LEFT_JUSTIFIED) && (j++ < width)) {
+            ntstdio_putc(handle, d);
+        }
+        do {
+            ntstdio_putc(handle, s[--i]);
+        } while(i);
+        while (j++ < width) {
+            ntstdio_putc(handle, ' ');
+        }
+    }
+}
+
+void ntstdio_init(NTSTDIO *handle, NTSTDIO_XO xo, NTSTDIO_XI xi)
+{
+    handle->xo = xo;
+    handle->xi = xi;
+    handle->outptr = 0;
+}
+
+void ntstdio_putc(NTSTDIO *handle, char c)
+{
+    if ((NTSTDIO_CR_CRLF) && (c == '\n')) {
+        ntstdio_putc(handle, '\r');
+    }
+
+    if (handle->outptr) {
+        *(handle->outptr)++ = (unsigned char)c;
+        return;
+    }
+
+    if (handle->xo) {
+        handle->xo((unsigned char)c);
+    }
+}
+
+void ntstdio_puts(NTSTDIO *handle, const char *str)
+{
+    while (*str) {
+        ntstdio_putc(handle, *str++);
+    }
+}
+
+void ntstdio_fputs(NTSTDIO *handle, NTSTDIO_XO xo, const char *str)
+{
+    void (*pf)(unsigned char);
+
+    /* Save current output device */
+    pf = handle->xo;
+    /* Switch output to specified device */
+    handle->xo = xo;
+
+    while (*str) {
+        ntstdio_putc(handle, *str++);
+    }
+
+    /* Restore output device */
+    handle->xo = pf;
+}
+
+void ntstdio_printf(NTSTDIO *handle, const char *fmt, ...)
+{
+    va_list arp;
+    va_start(arp, fmt);
+    xvprintf(handle, fmt, arp);
+    va_end(arp);
+}
+
+void ntstdio_sprintf(NTSTDIO *handle, char *buf, const char *fmt, ...)
+{
+    va_list arp;
+    /* Switch destination for memory */
+    handle->outptr = buf;
+    va_start(arp, fmt);
+    xvprintf(handle, fmt, arp);
+    va_end(arp);
+
+    /* Terminate output string with a \0 */
+    *(handle->outptr) = 0;
+    /* Switch destination for device */
+    handle->outptr = 0;
+}
+
+void ntstdio_fprintf(NTSTDIO *handle, NTSTDIO_XO xo, const char *fmt, ...)
+{
+    va_list arp;
+    void (*pf)(unsigned char);
+
+    /* Save current output device */
+    pf = handle->xo;
+    /* Switch output to specified device */
+    handle->xo = xo;
+
+    va_start(arp, fmt);
+    xvprintf(handle, fmt, arp);
+    va_end(arp);
+
+    /* Restore output device */
+    handle->xo = pf;
+}
+
+/* 0:End of stream, 1:A line arrived */
+int ntstdio_gets(NTSTDIO *handle, char *buf, int len)
+{
+    int c, i;
+
+    if (!handle->xi) {
+        /* No input function specified */
+        return 0;
+    }
+
+    i = 0;
+    for (;;) {
+        /* Get a char from the incoming stream */
+        c = handle->xi();
+        if (!c) {
+            /* End of stream */
+            return 0;
+        }
+        if (c == '\r') {
+            /* End of line */
+            break;
+        }
+        if ((c == '\b') && i) {
+            /* Back space */
+            i--;
+            if (NTSTDIO_LINE_ECHO) {
+                ntstdio_putc(handle, c);
+            }
+            continue;
+        }
+        if ((c >= ' ') && (i < len - 1)) {
+            /* Visible chars */
+            buf[i++] = c;
+            if (NTSTDIO_LINE_ECHO) {
+                ntstdio_putc(handle, c);
+            }
+        }
+    }
+    buf[i] = 0;
+    /* Terminate with a \0 */
+    if (NTSTDIO_LINE_ECHO) {
+        ntstdio_putc(handle, '\n');
+    }
+    return 1;
+}
+
+/* 0:End of stream, 1:A line arrived */
+int ntstdio_fgets(NTSTDIO *handle, NTSTDIO_XI xi, char *buf, int len)
+{
+    unsigned char (*pf)(void);
+    int n;
+
+    /* Save current input device */
+    pf = handle->xi;
+    /* Switch input to specified device */
+    handle->xi = xi;
+    /* Get a line */
+    n = ntstdio_gets(handle, buf, len);
+    /* Restore input device */
+    handle->xi = pf;
+
+    return n;
+}
+
diff --git a/uzumeapp/kernel/uzume/ntshell/ntstdio.h b/uzumeapp/kernel/uzume/ntshell/ntstdio.h
new file mode 100644 (file)
index 0000000..f0fd763
--- /dev/null
@@ -0,0 +1,87 @@
+/**
+ * @file ntstdio.h
+ * @author Shinichiro Nakamura
+ * @brief Natural Tiny Standard I/O Module
+ * @details
+ * The Natural Tiny Standard I/O Module based on xprintf by ChaN.
+ * xprintf is a universal string handler for user console interface.
+ */
+
+/*------------------------------------------------------------------------/
+/  Universal string handler for user console interface
+/-------------------------------------------------------------------------/
+/
+/  Copyright (C) 2011, ChaN, all right reserved.
+/
+/ * This software is a free software and there is NO WARRANTY.
+/ * No restriction on use. You can use, modify and redistribute it for
+/   personal, non-profit or commercial products UNDER YOUR RESPONSIBILITY.
+/ * Redistributions of source code must retain the above copyright notice.
+/
+/-------------------------------------------------------------------------*/
+
+/*
+ * ===============================================================
+ * Natural Tiny Standard I/O Module
+ * ===============================================================
+ * Copyright (c) 2013 Shinichiro Nakamura
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ * ===============================================================
+ */
+
+#ifndef NTSTDIO_H
+#define NTSTDIO_H
+
+/**
+ * 1: Convert \n ==> \r\n in the output char.
+ */
+#define NTSTDIO_CR_CRLF    (1)
+
+/**
+ * 1: Echo back input chars in ntstdio_gets function.
+ */
+#define NTSTDIO_LINE_ECHO  (1)
+
+typedef void (*NTSTDIO_XO)(unsigned char c);
+typedef unsigned char (*NTSTDIO_XI)(void);
+
+typedef struct {
+    NTSTDIO_XO xo;
+    NTSTDIO_XI xi;
+    char *outptr;
+} NTSTDIO;
+
+void ntstdio_init(NTSTDIO *handle, NTSTDIO_XO xo, NTSTDIO_XI xi);
+
+void ntstdio_putc(NTSTDIO *handle, char c);
+void ntstdio_puts(NTSTDIO *handle, const char *str);
+void ntstdio_fputs(NTSTDIO *handle, NTSTDIO_XO xo, const char *str);
+void ntstdio_printf(NTSTDIO *handle, const char *fmt, ...);
+void ntstdio_sprintf(NTSTDIO *handle, char *buf, const char *fmt, ...);
+void ntstdio_fprintf(NTSTDIO *handle, NTSTDIO_XO xo, const char *fmt, ...);
+
+int ntstdio_gets(NTSTDIO *handle, char *buf, int len);
+int ntstdio_fgets(NTSTDIO *handle, NTSTDIO_XI xi, char *buf, int len);
+
+#endif
+
diff --git a/uzumeapp/kernel/uzume/ntshell/xprintf.c b/uzumeapp/kernel/uzume/ntshell/xprintf.c
deleted file mode 100644 (file)
index fde70b2..0000000
+++ /dev/null
@@ -1,395 +0,0 @@
-/*------------------------------------------------------------------------/\r
-  /  Universal string handler for user console interface\r
-  /-------------------------------------------------------------------------/\r
-  /\r
-  /  Copyright (C) 2011, ChaN, all right reserved.\r
-  /\r
-  / * This software is a free software and there is NO WARRANTY.\r
-  / * No restriction on use. You can use, modify and redistribute it for\r
-  /   personal, non-profit or commercial products UNDER YOUR RESPONSIBILITY.\r
-  / * Redistributions of source code must retain the above copyright notice.\r
-  /\r
-  /-------------------------------------------------------------------------*/\r
-\r
-#include "xprintf.h"\r
-\r
-\r
-#if _USE_XFUNC_OUT\r
-#include <stdarg.h>\r
-void (*xfunc_out)(unsigned char); /* Pointer to the output stream */\r
-static char *outptr;\r
-\r
-/*----------------------------------------------*/\r
-/* Put a character                              */\r
-/*----------------------------------------------*/\r
-\r
-void xputc (char c)\r
-{\r
-    if (_CR_CRLF && c == '\n') xputc('\r');  /* CR -> CRLF */\r
-\r
-    if (outptr) {\r
-        *outptr++ = (unsigned char)c;\r
-        return;\r
-    }\r
-\r
-    if (xfunc_out) xfunc_out((unsigned char)c);\r
-}\r
-\r
-\r
-\r
-/*----------------------------------------------*/\r
-/* Put a null-terminated string                 */\r
-/*----------------------------------------------*/\r
-\r
-void xputs (     /* Put a string to the default device */\r
-        const char* str    /* Pointer to the string */\r
-        )\r
-{\r
-    while (*str)\r
-        xputc(*str++);\r
-}\r
-\r
-\r
-    void xfputs (     /* Put a string to the specified device */\r
-            void(*func)(unsigned char), /* Pointer to the output function */\r
-            const char* str    /* Pointer to the string */\r
-            )\r
-{\r
-    void (*pf)(unsigned char);\r
-\r
-\r
-    pf = xfunc_out;  /* Save current output device */\r
-    xfunc_out = func; /* Switch output to specified device */\r
-    while (*str)  /* Put the string */\r
-        xputc(*str++);\r
-    xfunc_out = pf;  /* Restore output device */\r
-}\r
-\r
-\r
-\r
-/*----------------------------------------------*/\r
-/* Formatted string output                      */\r
-/*----------------------------------------------*/\r
-/*  xprintf("%d", 1234);   "1234"\r
-    xprintf("%6d,%3d%%", -200, 5); "  -200,  5%"\r
-    xprintf("%-6u", 100);   "100   "\r
-    xprintf("%ld", 12345678L);  "12345678"\r
-    xprintf("%04x", 0xA3);   "00a3"\r
-    xprintf("%08LX", 0x123ABC);  "00123ABC"\r
-    xprintf("%016b", 0x550F);  "0101010100001111"\r
-    xprintf("%s", "String");  "String"\r
-    xprintf("%-4s", "abc");   "abc "\r
-    xprintf("%4s", "abc");   " abc"\r
-    xprintf("%c", 'a');    "a"\r
-    xprintf("%f", 10.0);            <xprintf lacks floating point support>\r
-    */\r
-\r
-    static\r
-void xvprintf (\r
-        const char* fmt, /* Pointer to the format string */\r
-        va_list arp   /* Pointer to arguments */\r
-        )\r
-{\r
-    unsigned int r, i, j, w, f;\r
-    unsigned long v;\r
-    char s[16], c, d, *p;\r
-\r
-\r
-    for (;;) {\r
-        c = *fmt++;     /* Get a char */\r
-        if (!c) break;    /* End of format? */\r
-        if (c != '%') {    /* Pass through it if not a % sequense */\r
-            xputc(c); continue;\r
-        }\r
-        f = 0;\r
-        c = *fmt++;     /* Get first char of the sequense */\r
-        if (c == '0') {    /* Flag: '0' padded */\r
-            f = 1; c = *fmt++;\r
-        } else {\r
-            if (c == '-') {   /* Flag: left justified */\r
-                f = 2; c = *fmt++;\r
-            }\r
-        }\r
-        for (w = 0; c >= '0' && c <= '9'; c = *fmt++) /* Minimum width */\r
-            w = w * 10 + c - '0';\r
-        if (c == 'l' || c == 'L') { /* Prefix: Size is long int */\r
-            f |= 4; c = *fmt++;\r
-        }\r
-        if (!c) break;    /* End of format? */\r
-        d = c;\r
-        if (d >= 'a') d -= 0x20;\r
-        switch (d) {    /* Type is... */\r
-            case 'S' :     /* String */\r
-                p = va_arg(arp, char*);\r
-                for (j = 0; p[j]; j++) ;\r
-                while (!(f & 2) && j++ < w) xputc(' ');\r
-                xputs(p);\r
-                while (j++ < w) xputc(' ');\r
-                continue;\r
-            case 'C' :     /* Character */\r
-                xputc((char)va_arg(arp, int)); continue;\r
-            case 'B' :     /* Binary */\r
-                r = 2; break;\r
-            case 'O' :     /* Octal */\r
-                r = 8; break;\r
-            case 'D' :     /* Signed decimal */\r
-            case 'U' :     /* Unsigned decimal */\r
-                r = 10; break;\r
-            case 'X' :     /* Hexdecimal */\r
-                r = 16; break;\r
-            default:     /* Unknown type (passthrough) */\r
-                xputc(c); continue;\r
-        }\r
-\r
-        /* Get an argument and put it in numeral */\r
-        v = (f & 4) ? va_arg(arp, long) : ((d == 'D') ? (long)va_arg(arp, int) : (long)va_arg(arp, unsigned int));\r
-        if (d == 'D' && (v & 0x80000000)) {\r
-            v = 0 - v;\r
-            f |= 8;\r
-        }\r
-        i = 0;\r
-        do {\r
-            d = (char)(v % r); v /= r;\r
-            if (d > 9) d += (c == 'x') ? 0x27 : 0x07;\r
-            s[i++] = d + '0';\r
-        } while (v && i < sizeof(s));\r
-        if (f & 8) s[i++] = '-';\r
-        j = i; d = (f & 1) ? '0' : ' ';\r
-        while (!(f & 2) && j++ < w) xputc(d);\r
-        do xputc(s[--i]); while(i);\r
-        while (j++ < w) xputc(' ');\r
-    }\r
-}\r
-\r
-\r
-void xprintf (   /* Put a formatted string to the default device */\r
-        const char* fmt, /* Pointer to the format string */\r
-        ...     /* Optional arguments */\r
-        )\r
-{\r
-    va_list arp;\r
-\r
-\r
-    va_start(arp, fmt);\r
-    xvprintf(fmt, arp);\r
-    va_end(arp);\r
-}\r
-\r
-\r
-void xsprintf (   /* Put a formatted string to the memory */\r
-        char* buff,   /* Pointer to the output buffer */\r
-        const char* fmt, /* Pointer to the format string */\r
-        ...     /* Optional arguments */\r
-        )\r
-{\r
-    va_list arp;\r
-\r
-\r
-    outptr = buff;  /* Switch destination for memory */\r
-\r
-    va_start(arp, fmt);\r
-    xvprintf(fmt, arp);\r
-    va_end(arp);\r
-\r
-    *outptr = 0;  /* Terminate output string with a \0 */\r
-    outptr = 0;   /* Switch destination for device */\r
-}\r
-\r
-\r
-    void xfprintf (     /* Put a formatted string to the specified device */\r
-            void(*func)(unsigned char), /* Pointer to the output function */\r
-            const char* fmt,   /* Pointer to the format string */\r
-            ...       /* Optional arguments */\r
-            )\r
-{\r
-    va_list arp;\r
-    void (*pf)(unsigned char);\r
-\r
-\r
-    pf = xfunc_out;  /* Save current output device */\r
-    xfunc_out = func; /* Switch output to specified device */\r
-\r
-    va_start(arp, fmt);\r
-    xvprintf(fmt, arp);\r
-    va_end(arp);\r
-\r
-    xfunc_out = pf;  /* Restore output device */\r
-}\r
-\r
-\r
-\r
-/*----------------------------------------------*/\r
-/* Dump a line of binary dump                   */\r
-/*----------------------------------------------*/\r
-\r
-void put_dump (\r
-        const void* buff,  /* Pointer to the array to be dumped */\r
-        unsigned long addr,  /* Heading address value */\r
-        int len,    /* Number of items to be dumped */\r
-        int width    /* Size of the items (DF_CHAR, DF_SHORT, DF_LONG) */\r
-        )\r
-{\r
-    int i;\r
-    const unsigned char *bp;\r
-    const unsigned short *sp;\r
-    const unsigned long *lp;\r
-\r
-\r
-    xprintf("%08lX ", addr);  /* address */\r
-\r
-    switch (width) {\r
-        case DW_CHAR:\r
-            bp = buff;\r
-            for (i = 0; i < len; i++)  /* Hexdecimal dump */\r
-                xprintf(" %02X", bp[i]);\r
-            xputc(' ');\r
-            for (i = 0; i < len; i++)  /* ASCII dump */\r
-                xputc((bp[i] >= ' ' && bp[i] <= '~') ? bp[i] : '.');\r
-            break;\r
-        case DW_SHORT:\r
-            sp = buff;\r
-            do        /* Hexdecimal dump */\r
-                xprintf(" %04X", *sp++);\r
-            while (--len);\r
-            break;\r
-        case DW_LONG:\r
-            lp = buff;\r
-            do        /* Hexdecimal dump */\r
-                xprintf(" %08LX", *lp++);\r
-            while (--len);\r
-            break;\r
-    }\r
-\r
-    xputc('\n');\r
-}\r
-\r
-#endif /* _USE_XFUNC_OUT */\r
-\r
-\r
-\r
-#if _USE_XFUNC_IN\r
-unsigned char (*xfunc_in)(void); /* Pointer to the input stream */\r
-\r
-/*----------------------------------------------*/\r
-/* Get a line from the input                    */\r
-/*----------------------------------------------*/\r
-\r
-int xgets (  /* 0:End of stream, 1:A line arrived */\r
-        char* buff, /* Pointer to the buffer */\r
-        int len  /* Buffer length */\r
-        )\r
-{\r
-    int c, i;\r
-\r
-\r
-    if (!xfunc_in) return 0;  /* No input function specified */\r
-\r
-    i = 0;\r
-    for (;;) {\r
-        c = xfunc_in();    /* Get a char from the incoming stream */\r
-        if (!c) return 0;   /* End of stream? */\r
-        if (c == '\r') break;  /* End of line? */\r
-        if (c == '\b' && i) {  /* Back space? */\r
-            i--;\r
-            if (_LINE_ECHO) xputc(c);\r
-            continue;\r
-        }\r
-        if (c >= ' ' && i < len - 1) { /* Visible chars */\r
-            buff[i++] = c;\r
-            if (_LINE_ECHO) xputc(c);\r
-        }\r
-    }\r
-    buff[i] = 0; /* Terminate with a \0 */\r
-    if (_LINE_ECHO) xputc('\n');\r
-    return 1;\r
-}\r
-\r
-\r
-    int xfgets ( /* 0:End of stream, 1:A line arrived */\r
-            unsigned char (*func)(void), /* Pointer to the input stream function */\r
-            char* buff, /* Pointer to the buffer */\r
-            int len  /* Buffer length */\r
-            )\r
-{\r
-    unsigned char (*pf)(void);\r
-    int n;\r
-\r
-\r
-    pf = xfunc_in;   /* Save current input device */\r
-    xfunc_in = func;  /* Switch input to specified device */\r
-    n = xgets(buff, len); /* Get a line */\r
-    xfunc_in = pf;   /* Restore input device */\r
-\r
-    return n;\r
-}\r
-\r
-\r
-/*----------------------------------------------*/\r
-/* Get a value of the string                    */\r
-/*----------------------------------------------*/\r
-/* "123 -5   0x3ff 0b1111 0377  w "\r
-   ^                           1st call returns 123 and next ptr\r
-   ^                        2nd call returns -5 and next ptr\r
-   ^                3rd call returns 1023 and next ptr\r
-   ^         4th call returns 15 and next ptr\r
-   ^    5th call returns 255 and next ptr\r
-   ^ 6th call fails and returns 0\r
-   */\r
-\r
-int xatoi (   /* 0:Failed, 1:Successful */\r
-        char **str,  /* Pointer to pointer to the string */\r
-        long *res  /* Pointer to the valiable to store the value */\r
-        )\r
-{\r
-    unsigned long val;\r
-    unsigned char c, r, s = 0;\r
-\r
-\r
-    *res = 0;\r
-\r
-    while ((c = **str) == ' ') (*str)++; /* Skip leading spaces */\r
-\r
-    if (c == '-') {  /* negative? */\r
-        s = 1;\r
-        c = *(++(*str));\r
-    }\r
-\r
-    if (c == '0') {\r
-        c = *(++(*str));\r
-        switch (c) {\r
-            case 'x':  /* hexdecimal */\r
-                r = 16; c = *(++(*str));\r
-                break;\r
-            case 'b':  /* binary */\r
-                r = 2; c = *(++(*str));\r
-                break;\r
-            default:\r
-                if (c <= ' ') return 1; /* single zero */\r
-                if (c < '0' || c > '9') return 0; /* invalid char */\r
-                r = 8;  /* octal */\r
-        }\r
-    } else {\r
-        if (c < '0' || c > '9') return 0; /* EOL or invalid char */\r
-        r = 10;   /* decimal */\r
-    }\r
-\r
-    val = 0;\r
-    while (c > ' ') {\r
-        if (c >= 'a') c -= 0x20;\r
-        c -= '0';\r
-        if (c >= 17) {\r
-            c -= 7;\r
-            if (c <= 9) return 0; /* invalid char */\r
-        }\r
-        if (c >= r) return 0;  /* invalid char for current radix */\r
-        val = val * r + c;\r
-        c = *(++(*str));\r
-    }\r
-    if (s) val = 0 - val;   /* apply sign if needed */\r
-\r
-    *res = val;\r
-    return 1;\r
-}\r
-\r
-#endif /* _USE_XFUNC_IN */\r
-\r
diff --git a/uzumeapp/kernel/uzume/ntshell/xprintf.h b/uzumeapp/kernel/uzume/ntshell/xprintf.h
deleted file mode 100644 (file)
index 4a8af14..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-/*------------------------------------------------------------------------*/\r
-/* Universal string handler for user console interface  (C)ChaN, 2011     */\r
-/*------------------------------------------------------------------------*/\r
-\r
-#ifndef _STRFUNC\r
-#define _STRFUNC\r
-\r
-#define _USE_XFUNC_OUT  1 /* 1: Use output functions */\r
-#define _CR_CRLF        1 /* 1: Convert \n ==> \r\n in the output char */\r
-\r
-#define _USE_XFUNC_IN   1 /* 1: Use input function */\r
-#define _LINE_ECHO      1 /* 1: Echo back input chars in xgets function */\r
-\r
-\r
-#if _USE_XFUNC_OUT\r
-#define xdev_out(func) xfunc_out = (void(*)(unsigned char))(func)\r
-extern void (*xfunc_out)(unsigned char);\r
-void xputc (char c);\r
-void xputs (const char* str);\r
-void xfputs (void (*func)(unsigned char), const char* str);\r
-void xprintf (const char* fmt, ...);\r
-void xsprintf (char* buff, const char* fmt, ...);\r
-void xfprintf (void (*func)(unsigned char), const char* fmt, ...);\r
-void put_dump (const void* buff, unsigned long addr, int len, int width);\r
-#define DW_CHAR  sizeof(char)\r
-#define DW_SHORT sizeof(short)\r
-#define DW_LONG  sizeof(long)\r
-#endif\r
-\r
-#if _USE_XFUNC_IN\r
-#define xdev_in(func) xfunc_in = (unsigned char(*)(void))(func)\r
-extern unsigned char (*xfunc_in)(void);\r
-int xgets (char* buff, int len);\r
-int xfgets (unsigned char (*func)(void), char* buff, int len);\r
-int xatoi (char** str, long* res);\r
-#endif\r
-\r
-#endif\r
-\r