|
|
1.1 ! root 1: /* ! 2: char id_fmtlib[] = "@(#)fmtlib.c 1.2"; ! 3: * ! 4: * integer to ascii conversion ! 5: */ ! 6: ! 7: #include "fio.h" ! 8: ! 9: char _digit[] = "0123456789abcdefghijklmnopqrstuvwxyz"; ! 10: ! 11: char *icvt(value,ndigit,sign) long value; int *ndigit,*sign; ! 12: { ! 13: static char buf[MAXINTLENGTH+1]; ! 14: register int i; ! 15: long kludge, rem, mask = 0x7fffffff; ! 16: int one = 1; ! 17: char c; ! 18: ! 19: if (value == 0) ! 20: { *sign=0; ! 21: *ndigit=one; ! 22: buf[MAXINTLENGTH]='0'; ! 23: return(&buf[MAXINTLENGTH]); ! 24: } ! 25: else if (signit) /* signed */ ! 26: { ! 27: *sign = (value < 0); ! 28: c = (int)(value % radix); ! 29: value /= radix; ! 30: if (*sign) ! 31: { value = -value; ! 32: c = -c; ! 33: } ! 34: } ! 35: else /* unsigned */ ! 36: { *sign = 0; ! 37: if (value < 0) ! 38: { /* ALL THIS IS TO SIMULATE UNSIGNED MOD & DIV */ ! 39: kludge = mask - (radix - one); ! 40: value &= mask; ! 41: rem = (kludge % radix) + (value % radix); ! 42: value = (kludge / radix) + (value / radix) ! 43: + (rem / radix) + one; ! 44: c = (int)(rem % radix); ! 45: } ! 46: else ! 47: { ! 48: c = (int)(value % radix); ! 49: value /= radix; ! 50: } ! 51: } ! 52: *(buf+MAXINTLENGTH) = _digit[c]; ! 53: for(i=MAXINTLENGTH-one; value!=0; i--) ! 54: { ! 55: c = (int)(value % radix); ! 56: *(buf+i) = _digit[c]; ! 57: value /= radix; ! 58: } ! 59: *ndigit = MAXINTLENGTH - i; ! 60: return(&buf[i+one]); ! 61: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.