[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Minios-devel] [UNIKRAFT PATCH 2/4] lib/nolibc: sscanf reorganize functions inside file



Just put them in the order they are used - so no prototypes are needed

Signed-off-by: Yuri Volchkov <yuri.volchkov@xxxxxxxxx>
---
 lib/nolibc/sscanf.c | 199 ++++++++++++++++++++++----------------------
 1 file changed, 98 insertions(+), 101 deletions(-)

diff --git a/lib/nolibc/sscanf.c b/lib/nolibc/sscanf.c
index 806ca4f..149bfbd 100644
--- a/lib/nolibc/sscanf.c
+++ b/lib/nolibc/sscanf.c
@@ -84,18 +84,96 @@ __FBSDID("$FreeBSD$");
 #define        CT_INT          3       /* integer, i.e., strtoq or strtouq */
 typedef u_quad_t (*ccfntype)(const char *, char **, int);
 
-static const u_char *__sccl(char *, const u_char *);
-
-int
-sscanf(const char *ibuf, const char *fmt, ...)
+/*
+ * Fill in the given table from the scanset at the given format
+ * (just after `[').  Return a pointer to the character past the
+ * closing `]'.  The table has a 1 wherever characters should be
+ * considered part of the scanset.
+ */
+static const u_char *
+__sccl(char *tab, const u_char *fmt)
 {
-       va_list ap;
-       int ret;
-       
-       va_start(ap, fmt);
-       ret = vsscanf(ibuf, fmt, ap);
-       va_end(ap);
-       return(ret);
+       int c, n, v;
+
+       /* first `clear' the whole table */
+       c = *fmt++;             /* first char hat => negated scanset */
+       if (c == '^') {
+               v = 1;          /* default => accept */
+               c = *fmt++;     /* get new first char */
+       } else
+               v = 0;          /* default => reject */
+
+       /* XXX: Will not work if sizeof(tab*) > sizeof(char) */
+       for (n = 0; n < 256; n++)
+                    tab[n] = v;        /* memset(tab, v, 256) */
+
+       if (c == 0)
+               return (fmt - 1);/* format ended before closing ] */
+
+       /*
+        * Now set the entries corresponding to the actual scanset
+        * to the opposite of the above.
+        *
+        * The first character may be ']' (or '-') without being special;
+        * the last character may be '-'.
+        */
+       v = 1 - v;
+       for (;;) {
+               tab[c] = v;             /* take character c */
+doswitch:
+               n = *fmt++;             /* and examine the next */
+               switch (n) {
+
+               case 0:                 /* format ended too soon */
+                       return (fmt - 1);
+
+               case '-':
+                       /*
+                        * A scanset of the form
+                        *      [01+-]
+                        * is defined as `the digit 0, the digit 1,
+                        * the character +, the character -', but
+                        * the effect of a scanset such as
+                        *      [a-zA-Z0-9]
+                        * is implementation defined.  The V7 Unix
+                        * scanf treats `a-z' as `the letters a through
+                        * z', but treats `a-a' as `the letter a, the
+                        * character -, and the letter a'.
+                        *
+                        * For compatibility, the `-' is not considered
+                        * to define a range if the character following
+                        * it is either a close bracket (required by ANSI)
+                        * or is not numerically greater than the character
+                        * we just stored in the table (c).
+                        */
+                       n = *fmt;
+                       if (n == ']' || n < c) {
+                               c = '-';
+                               break;  /* resume the for(;;) */
+                       }
+                       fmt++;
+                       /* fill in the range */
+                       do {
+                           tab[++c] = v;
+                       } while (c < n);
+                       c = n;
+                       /*
+                        * Alas, the V7 Unix scanf also treats formats
+                        * such as [a-c-e] as `the letters a through e'.
+                        * This too is permitted by the standard....
+                        */
+                       goto doswitch;
+                       break;
+
+               case ']':               /* end of scanset */
+                       return (fmt);
+
+               default:                /* just another character */
+                       c = n;
+                       break;
+               }
+       }
+       /* NOTREACHED */
 }
 
 int
@@ -547,95 +625,14 @@ match_failure:
        return (nassigned);
 }
 
-/*
- * Fill in the given table from the scanset at the given format
- * (just after `[').  Return a pointer to the character past the
- * closing `]'.  The table has a 1 wherever characters should be
- * considered part of the scanset.
- */
-static const u_char *
-__sccl(char *tab, const u_char *fmt)
+int
+sscanf(const char *ibuf, const char *fmt, ...)
 {
-       int c, n, v;
-
-       /* first `clear' the whole table */
-       c = *fmt++;             /* first char hat => negated scanset */
-       if (c == '^') {
-               v = 1;          /* default => accept */
-               c = *fmt++;     /* get new first char */
-       } else
-               v = 0;          /* default => reject */
-
-       /* XXX: Will not work if sizeof(tab*) > sizeof(char) */
-       for (n = 0; n < 256; n++)
-                    tab[n] = v;        /* memset(tab, v, 256) */
-
-       if (c == 0)
-               return (fmt - 1);/* format ended before closing ] */
-
-       /*
-        * Now set the entries corresponding to the actual scanset
-        * to the opposite of the above.
-        *
-        * The first character may be ']' (or '-') without being special;
-        * the last character may be '-'.
-        */
-       v = 1 - v;
-       for (;;) {
-               tab[c] = v;             /* take character c */
-doswitch:
-               n = *fmt++;             /* and examine the next */
-               switch (n) {
-
-               case 0:                 /* format ended too soon */
-                       return (fmt - 1);
-
-               case '-':
-                       /*
-                        * A scanset of the form
-                        *      [01+-]
-                        * is defined as `the digit 0, the digit 1,
-                        * the character +, the character -', but
-                        * the effect of a scanset such as
-                        *      [a-zA-Z0-9]
-                        * is implementation defined.  The V7 Unix
-                        * scanf treats `a-z' as `the letters a through
-                        * z', but treats `a-a' as `the letter a, the
-                        * character -, and the letter a'.
-                        *
-                        * For compatibility, the `-' is not considered
-                        * to define a range if the character following
-                        * it is either a close bracket (required by ANSI)
-                        * or is not numerically greater than the character
-                        * we just stored in the table (c).
-                        */
-                       n = *fmt;
-                       if (n == ']' || n < c) {
-                               c = '-';
-                               break;  /* resume the for(;;) */
-                       }
-                       fmt++;
-                       /* fill in the range */
-                       do {
-                           tab[++c] = v;
-                       } while (c < n);
-                       c = n;
-                       /*
-                        * Alas, the V7 Unix scanf also treats formats
-                        * such as [a-c-e] as `the letters a through e'.
-                        * This too is permitted by the standard....
-                        */
-                       goto doswitch;
-                       break;
-
-               case ']':               /* end of scanset */
-                       return (fmt);
-
-               default:                /* just another character */
-                       c = n;
-                       break;
-               }
-       }
-       /* NOTREACHED */
+       va_list ap;
+       int ret;
+       
+       va_start(ap, fmt);
+       ret = vsscanf(ibuf, fmt, ap);
+       va_end(ap);
+       return(ret);
 }
-
-- 
2.17.1


_______________________________________________
Minios-devel mailing list
Minios-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/minios-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.