xref: /titanic_51/usr/src/lib/libast/common/uwin/a64l.c (revision c93c462eec9d46f84d567abf52eb29a27c2e134b)
1 /***********************************************************************
2 *                                                                      *
3 *               This software is part of the ast package               *
4 *          Copyright (c) 1985-2008 AT&T Intellectual Property          *
5 *                      and is licensed under the                       *
6 *                  Common Public License, Version 1.0                  *
7 *                    by AT&T Intellectual Property                     *
8 *                                                                      *
9 *                A copy of the License is available at                 *
10 *            http://www.opensource.org/licenses/cpl1.0.txt             *
11 *         (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9)         *
12 *                                                                      *
13 *              Information and Software Systems Research               *
14 *                            AT&T Research                             *
15 *                           Florham Park NJ                            *
16 *                                                                      *
17 *                 Glenn Fowler <gsf@research.att.com>                  *
18 *                  David Korn <dgk@research.att.com>                   *
19 *                   Phong Vo <kpv@research.att.com>                    *
20 *                                                                      *
21 ***********************************************************************/
22 #include "FEATURE/uwin"
23 
24 #if !_UWIN || _lib_a64l
25 
26 void _STUB_a64l(){}
27 
28 #else
29 
30 #define a64l	______a64l
31 #define l64a	______l64a
32 
33 #include	<stdlib.h>
34 #include	<string.h>
35 
36 #undef	a64l
37 #undef	l64a
38 
39 #if defined(__EXPORT__)
40 #define extern		__EXPORT__
41 #endif
42 
43 static char letter[65] = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
44 
45 extern long a64l(const char *str)
46 {
47 	register unsigned long ul = 0;
48 	register int n = 6;
49 	register int c;
50 	register char *cp;
51 	for(n=0; n <6; n++)
52 	{
53 		if((c= *str++)==0)
54 			break;
55 		if(!(cp=strchr(letter,c)))
56 			break;
57 		ul |= (cp-letter)<< (6*n);
58 	}
59 	return((long)ul);
60 }
61 
62 extern char *l64a(long l)
63 {
64 	static char buff[7];
65 	unsigned ul = ((unsigned long)l & 0xffffffff);
66 	register char *cp = buff;
67 	while(ul>0)
68 	{
69 		*cp++ = letter[ul&077];
70 		ul >>= 6;
71 	}
72 	*cp = 0;
73 	return(buff);
74 }
75 
76 #endif
77