]> git.sur5r.net Git - cc65/blobdiff - src/common/xsprintf.c
Only for jumps, the lib uses named asm labels in branches
[cc65] / src / common / xsprintf.c
index ea63b6d7e7df690570907ef262ed20acecf5ab13..a7d26d5ef76ec12c87ee5104976e96826ab0b744 100644 (file)
@@ -7,7 +7,7 @@
 /*                                                                           */
 /*                                                                           */
 /* (C) 2000-2004 Ullrich von Bassewitz                                       */
-/*               Römerstrasse 52                                             */
+/*               Roemerstrasse 52                                            */
 /*               D-70794 Filderstadt                                         */
 /* EMail:        uz@cc65.org                                                 */
 /*                                                                           */
 
 
 /* The following is a very basic vsnprintf like function called xvsnprintf. It
- * features only the basic format specifiers (especially the floating point
- * stuff is missing), but may be extended if required. Reason for supplying
- * my own implementation is that vsnprintf is standard but not implemented by
- * older compilers, and some that implement it, don't adhere to the standard
- * (for example Microsoft with its _vsnprintf).
- */
+** features only the basic format specifiers (especially the floating point
+** stuff is missing), but may be extended if required. Reason for supplying
+** my own implementation is that vsnprintf is standard but not implemented by
+** older compilers, and some that implement it, don't adhere to the standard
+** (for example Microsoft with its _vsnprintf).
+*/
 
 typedef struct {
 
@@ -73,9 +73,9 @@ typedef struct {
     size_t      BufFill;
 
     /* Argument string buffer and string buffer pointer. The string buffer
-     * must be big enough to hold a converted integer of the largest type
-     * including an optional sign and terminating zero.
-     */
+    ** must be big enough to hold a converted integer of the largest type
+    ** including an optional sign and terminating zero.
+    */
     char        ArgBuf[256];
     int         ArgLen;
 
@@ -223,9 +223,9 @@ static void FormatInt (PrintfCtrl* P, uintmax_t Val)
     ToStr (P, Val);
 
     /* The default precision for all integer conversions is one. This means
-     * that the fPrec flag is always set and does not need to be checked
-     * later on.
-     */
+    ** that the fPrec flag is always set and does not need to be checked
+    ** later on.
+    */
     if ((P->Flags & fPrec) == 0) {
         P->Flags |= fPrec;
         P->Prec = 1;
@@ -305,9 +305,9 @@ static void FormatStr (PrintfCtrl* P, const char* Val)
     unsigned WidthPadding;
 
     /* Get the string length limited to the precision. Beware: We cannot use
-     * strlen here, because if a precision is given, the string may not be
-     * zero terminated.
-     */
+    ** strlen here, because if a precision is given, the string may not be
+    ** zero terminated.
+    */
     int Len;
     if ((P->Flags & fPrec) != 0) {
         const char* S = memchr (Val, '\0', P->Prec);
@@ -352,14 +352,14 @@ static void StoreOffset (PrintfCtrl* P)
 /* Store the current output offset (%n format spec) */
 {
     switch (P->LengthMod) {
-        case lmChar:     *va_arg (P->ap, int*)       = P->BufFill;
-        case lmShort:    *va_arg (P->ap, int*)       = P->BufFill;
-        case lmInt:      *va_arg (P->ap, int*)       = P->BufFill;
-        case lmLong:     *va_arg (P->ap, long*)      = P->BufFill;
-        case lmIntMax:   *va_arg (P->ap, intmax_t*)  = P->BufFill;
-        case lmSizeT:    *va_arg (P->ap, size_t*)    = P->BufFill;
-        case lmPtrDiffT: *va_arg (P->ap, ptrdiff_t*) = P->BufFill;
-        default: FAIL ("Invalid size modifier for %n format spec in xvsnprintf");
+        case lmChar:     *va_arg (P->ap, int*)       = P->BufFill; break;
+        case lmShort:    *va_arg (P->ap, int*)       = P->BufFill; break;
+        case lmInt:      *va_arg (P->ap, int*)       = P->BufFill; break;
+        case lmLong:     *va_arg (P->ap, long*)      = P->BufFill; break;
+        case lmIntMax:   *va_arg (P->ap, intmax_t*)  = P->BufFill; break;
+        case lmSizeT:    *va_arg (P->ap, size_t*)    = P->BufFill; break;
+        case lmPtrDiffT: *va_arg (P->ap, ptrdiff_t*) = P->BufFill; break;
+        default: FAIL ("Invalid size modifier for %n format spec. in xvsnprintf()");
     }
 }
 
@@ -367,8 +367,8 @@ static void StoreOffset (PrintfCtrl* P)
 
 int xvsnprintf (char* Buf, size_t Size, const char* Format, va_list ap)
 /* A basic vsnprintf implementation. Does currently only support integer
- * formats.
- */
+** formats.
+*/
 {
     PrintfCtrl P;
     int Done;
@@ -418,8 +418,8 @@ int xvsnprintf (char* Buf, size_t Size, const char* Format, va_list ap)
         if (F == '*') {
             P.Width = va_arg (P.ap, int);
             /* A negative field width argument is taken as a - flag followed
-             * by a positive field width.
-             */
+            ** by a positive field width.
+            */
             if (P.Width < 0) {
                 P.Flags |= fMinus;
                 P.Width = -P.Width;
@@ -445,8 +445,8 @@ int xvsnprintf (char* Buf, size_t Size, const char* Format, va_list ap)
             if (F == '*') {
                 P.Prec = va_arg (P.ap, int);
                 /* A negative precision argument is taken as if the precision
-                 * were omitted.
-                 */
+                ** were omitted.
+                */
                 if (P.Prec < 0) {
                     P.Flags &= ~fPrec;
                 }
@@ -462,8 +462,8 @@ int xvsnprintf (char* Buf, size_t Size, const char* Format, va_list ap)
                 }
             } else if (F == '-') {
                 /* A negative precision argument is taken as if the precision
-                 * were omitted.
-                 */
+                ** were omitted.
+                */
                 F = *Format++;          /* Skip the minus */
                 while (IsDigit (F = *Format++)) ;
                 P.Flags &= ~fPrec;
@@ -581,8 +581,8 @@ int xvsnprintf (char* Buf, size_t Size, const char* Format, va_list ap)
                     /* Handle the length by using a precision */
                     if ((P.Flags & fPrec) != 0) {
                         /* Precision already specified, use length of string 
-                         * if less.
-                         */
+                        ** if less.
+                        */
                         if ((unsigned) P.Prec > SB_GetLen (S)) {
                             P.Prec = SB_GetLen (S);
                         }
@@ -622,9 +622,9 @@ int xvsnprintf (char* Buf, size_t Size, const char* Format, va_list ap)
     va_end (P.ap);
 
     /* Terminate the output string and return the number of chars that had
-     * been written if the buffer was large enough.
-     * Beware: The terminating zero is not counted for the function result!
-     */
+    ** been written if the buffer was large enough.
+    ** Beware: The terminating zero is not counted for the function result!
+    */
     AddChar (&P, '\0');
     return P.BufFill - 1;
 }
@@ -633,8 +633,8 @@ int xvsnprintf (char* Buf, size_t Size, const char* Format, va_list ap)
 
 int xsnprintf (char* Buf, size_t Size, const char* Format, ...)
 /* A basic snprintf implementation. Does currently only support integer
- * formats.
- */
+** formats.
+*/
 {
     int Res;
     va_list ap;