#include <my_global.h>#include "m_string.h"Include dependency graph for int2str.c:

Go to the source code of this file.
Functions | |
| char * | int2str (register long int val, register char *dst, register int radix, int upcase) |
| char * | int10_to_str (long int val, char *dst, int radix) |
Variables | |
| char NEAR | _dig_vec_upper [] |
| char NEAR | _dig_vec_lower [] |
| char* int10_to_str | ( | long int | val, | |
| char * | dst, | |||
| int | radix | |||
| ) |
Definition at line 132 of file int2str.c.
00133 { 00134 char buffer[65]; 00135 register char *p; 00136 long int new_val; 00137 00138 if (radix < 0) /* -10 */ 00139 { 00140 if (val < 0) 00141 { 00142 *dst++ = '-'; 00143 val = -val; 00144 } 00145 } 00146 00147 p = &buffer[sizeof(buffer)-1]; 00148 *p = '\0'; 00149 new_val= (long) ((unsigned long int) val / 10); 00150 *--p = '0'+ (char) ((unsigned long int) val - (unsigned long) new_val * 10); 00151 val = new_val; 00152 00153 while (val != 0) 00154 { 00155 new_val=val/10; 00156 *--p = '0' + (char) (val-new_val*10); 00157 val= new_val; 00158 } 00159 while ((*dst++ = *p++) != 0) ; 00160 return dst-1; 00161 }
| char* int2str | ( | register long int | val, | |
| register char * | dst, | |||
| register int | radix, | |||
| int | upcase | |||
| ) |
Definition at line 54 of file int2str.c.
References _dig_vec_lower, _dig_vec_upper, buffer, NullS, and p.
00056 { 00057 char buffer[65]; 00058 register char *p; 00059 long int new_val; 00060 char *dig_vec= upcase ? _dig_vec_upper : _dig_vec_lower; 00061 00062 if (radix < 0) 00063 { 00064 if (radix < -36 || radix > -2) 00065 return NullS; 00066 if (val < 0) 00067 { 00068 *dst++ = '-'; 00069 val = -val; 00070 } 00071 radix = -radix; 00072 } 00073 else if (radix > 36 || radix < 2) 00074 return NullS; 00075 00076 /* 00077 The slightly contorted code which follows is due to the fact that 00078 few machines directly support unsigned long / and %. Certainly 00079 the VAX C compiler generates a subroutine call. In the interests 00080 of efficiency (hollow laugh) I let this happen for the first digit 00081 only; after that "val" will be in range so that signed integer 00082 division will do. Sorry 'bout that. CHECK THE CODE PRODUCED BY 00083 YOUR C COMPILER. The first % and / should be unsigned, the second 00084 % and / signed, but C compilers tend to be extraordinarily 00085 sensitive to minor details of style. This works on a VAX, that's 00086 all I claim for it. 00087 */ 00088 p = &buffer[sizeof(buffer)-1]; 00089 *p = '\0'; 00090 new_val=(ulong) val / (ulong) radix; 00091 *--p = dig_vec[(uchar) ((ulong) val- (ulong) new_val*(ulong) radix)]; 00092 val = new_val; 00093 #ifdef HAVE_LDIV 00094 while (val != 0) 00095 { 00096 ldiv_t res; 00097 res=ldiv(val,radix); 00098 *--p = dig_vec[res.rem]; 00099 val= res.quot; 00100 } 00101 #else 00102 while (val != 0) 00103 { 00104 new_val=val/radix; 00105 *--p = dig_vec[(uchar) (val-new_val*radix)]; 00106 val= new_val; 00107 } 00108 #endif 00109 while ((*dst++ = *p++) != 0) ; 00110 return dst-1; 00111 }
| char NEAR _dig_vec_lower[] |
| char NEAR _dig_vec_upper[] |
1.4.7

