date and time created 88/07/21 17:35:57 by marc
authorMarc Teitelbaum <marc@ucbvax.Berkeley.EDU>
Fri, 22 Jul 1988 08:35:57 +0000 (00:35 -0800)
committerMarc Teitelbaum <marc@ucbvax.Berkeley.EDU>
Fri, 22 Jul 1988 08:35:57 +0000 (00:35 -0800)
SCCS-vsn: local/toolchest/ksh/shlib/utos.c 1.1

usr/src/local/toolchest/ksh/shlib/utos.c [new file with mode: 0644]

diff --git a/usr/src/local/toolchest/ksh/shlib/utos.c b/usr/src/local/toolchest/ksh/shlib/utos.c
new file mode 100644 (file)
index 0000000..cbd3a95
--- /dev/null
@@ -0,0 +1,118 @@
+/*
+
+ *      Copyright (c) 1984, 1985, 1986 AT&T
+ *      All Rights Reserved
+
+ *      THIS IS UNPUBLISHED PROPRIETARY SOURCE 
+ *      CODE OF AT&T.
+ *      The copyright notice above does not 
+ *      evidence any actual or intended
+ *      publication of such source code.
+
+ */
+/* @(#)utos.c  1.1 */
+
+/*
+ *   UTOS.C
+ *
+ *   Programmer:  D. G. Korn
+ *
+ *         Date:  May 3, 1982
+ *
+ *
+ *
+ *   LTOS (SINT, BASE)
+ *
+ *        Return a pointer to a string denoting the value of
+ *        the signed long integer SINT in base BASE.
+ *
+ *   UTOS (USINT, BASE)
+ *
+ *        Return a pointer to a string denoting the value of
+ *        the unsigned long integer USINT in base BASE.
+ *
+ *
+ *
+ *   See Also:  arith(III)
+ */
+
+
+#define BASEMAX         (4+16*sizeof(int))
+static char hexstr[BASEMAX];
+extern char hdigits[];
+char *utos();
+char *ltos();
+
+/*
+ *   LTOS (SINT, BASE)
+ *
+ *        long USINT;
+ *
+ *        int BASE;
+ *
+ *   Return a pointer to a string denoting the value of SINT 
+ *   in base BASE.  The string will be stored within HEXSTR.
+ *   It will begin with the base followed by a single '#'.
+ *   A minus sign will be prepended for negative numbers
+ *
+ */
+
+
+char *ltos(sint,base)
+long sint;
+int base;
+{
+       register char *sp;
+       register long l = (sint>=0?sint:-sint);
+#ifdef pdp11
+       sp = utos(l,base);
+#else
+       sp = utos((unsigned long)l,base);
+#endif /* pdp11 */
+       if(sint<0)
+               *--sp = '-';
+       return(sp);
+}
+
+/*
+ *   UTOS (USINT, BASE)
+ *
+ *        unsigned USINT;
+ *
+ *        int BASE;
+ *
+ *   Return a pointer to a string denoting the value of USINT 
+ *   in base BASE.  The string will be stored within HEXSTR.
+ *   It will begin with the base followed by a single '#'.
+ *
+ */
+
+
+
+char *utos(usint,base)
+register int base;
+#ifdef pdp11
+ /* unsigned longs are not supported on pdp11 */
+long usint;
+{
+       long l = usint;
+#else
+unsigned long usint;
+{
+       register unsigned long l = usint;
+#endif /* pdp11 */
+       register char *cp = hexstr+(BASEMAX-1);
+       if(base < 2 || base > BASEMAX)
+               return(cp);
+       for(*cp = 0;cp > hexstr && l;l /= base)
+               *--cp = hdigits[(l%base)<<1];
+       if(usint==0)
+               *--cp = '0';
+       if(base==10)
+               return(cp);
+       *--cp = '#';
+       *--cp = hdigits[(base%10)<<1];
+       if(base /= 10)
+               *--cp = hdigits[(base%10)<<1];
+       return(cp);     
+}