📄 fiolib.c
字号:
sprintf(cp,vp,vec.u32[0],vec.u32[1],vec.u32[2],vec.u32[3]); RESET_VECTOR_FMT(vp); break; }#endif /* _WRS_ALTIVEC_SUPPORT */ ulongLongVal = (unsigned long long) (unsigned int) va_arg(vaList, void *);/* NOSTRICT */ base = HEX; xdigs = "0123456789abcdef"; doHexPrefix = TRUE; ch = 'x'; goto nosign; case 's': if ((cp = va_arg(vaList, char *)) == NULL) cp = "(null)"; if (prec >= 0) { /* can't use strlen; can only look for the * NUL in the first `prec' characters, and * strlen() will go further. */ char *p = (char *)memchr(cp, 0, prec); if (p != NULL) { size = p - cp; if (size > prec) size = prec; } else size = prec; } else size = strlen(cp); sign = EOS; break; case 'U': doLongInt = TRUE; /* FALLTHROUGH */ case 'u':#ifdef _WRS_ALTIVEC_SUPPORT if (doVector) { SET_VECTOR_FMT(vp,doShortInt?8:4); if (doShortInt) sprintf(cp,vp,vec.u16[0],vec.u16[1],vec.u16[2],vec.u16[3], vec.u16[4],vec.u16[5],vec.u16[6],vec.u16[7]); else sprintf(cp,vp,vec.u32[0],vec.u32[1],vec.u32[2],vec.u32[3]); RESET_VECTOR_FMT(vp); break; }#endif /* _WRS_ALTIVEC_SUPPORT */ ulongLongVal = UARG(); base = DEC; goto nosign; case 'X': xdigs = "0123456789ABCDEF"; goto hex; case 'x': xdigs = "0123456789abcdef";hex:#ifdef _WRS_ALTIVEC_SUPPORT if (doVector) { SET_VECTOR_FMT(vp,doShortInt?8:4); if (doShortInt) sprintf(cp,vp,vec.s16[0],vec.s16[1],vec.s16[2],vec.s16[3], vec.s16[4],vec.s16[5],vec.s16[6],vec.s16[7]); else sprintf(cp,vp,vec.s32[0],vec.s32[1],vec.s32[2],vec.s32[3]); RESET_VECTOR_FMT(vp); break; }#endif /* _WRS_ALTIVEC_SUPPORT */ ulongLongVal = UARG(); base = HEX; /* leading 0x/X only if non-zero */ if (doAlt && (ulongLongVal != 0)) doHexPrefix = TRUE; /* unsigned conversions */nosign: sign = EOS; /* ... diouXx conversions ... if a precision is * specified, the 0 flag will be ignored. -- ANSI X3J11 */number: if ((dprec = prec) >= 0) doZeroPad = FALSE; /* The result of converting a zero value with an * explicit precision of zero is no characters. * -- ANSI X3J11 */ cp = buf + BUF; if ((ulongLongVal != 0) || (prec != 0)) { /* unsigned mod is hard, and unsigned mod * by a constant is easier than that by * a variable; hence this switch. */ switch (base) { case OCT: do { *--cp = to_char(ulongLongVal & 7); ulongLongVal >>= 3; } while (ulongLongVal); /* handle octal leading 0 */ if (doAlt && (*cp != '0')) *--cp = '0'; break; case DEC: /* many numbers are 1 digit */ while (ulongLongVal >= 10) { *--cp = to_char(ulongLongVal % 10); ulongLongVal /= 10; } *--cp = to_char(ulongLongVal); break; case HEX: do { *--cp = xdigs[ulongLongVal & 15]; ulongLongVal >>= 4; } while (ulongLongVal); break; default: cp = "bug in vfprintf: bad base"; size = strlen(cp); goto skipsize; } } size = buf + BUF - cp;skipsize: break; case 'L': /* NOT IMPLEMENTED */ goto rflag; case 'e': case 'E': case 'f': case 'g': case 'G':#ifdef _WRS_ALTIVEC_SUPPORT if (doVector) { SET_VECTOR_FMT(vp,4); sprintf(cp,vp,vec.f32[0],vec.f32[1],vec.f32[2],vec.f32[3]); RESET_VECTOR_FMT(vp); break; }#endif /* _WRS_ALTIVEC_SUPPORT */ if (fioFltFormatRtn != NULL) { oldprec = prec; /* in case of strange float */ if (prec > MAXFRACT) /* do realistic precision */ { if (((ch != 'g') && (ch != 'G')) || doAlt) fpprec = prec - MAXFRACT; prec = MAXFRACT; /* they asked for it! */ } else if (prec == -1) prec = 6; /* ANSI default precision */ cp = buf; /* where to fill in result */ *cp = EOS; /* EOS terminate just in case */#if ((CPU_FAMILY != I960) && (CPU_FAMILY != PPC)) size = (*fioFltFormatRtn) (&vaList,prec,doAlt,ch, &doSign,cp,buf+sizeof(buf));#else size = (*fioFltFormatRtn) (vaList, prec, doAlt, ch, &doSign,cp,buf+sizeof(buf));#endif if ((int)size < 0) /* strange value (Nan,Inf,..) */ { size = -size; /* get string length */ prec = oldprec; /* old precision (not default)*/ doZeroPad = FALSE; /* don't pad with zeroes */ if (doSign) /* is strange value signed? */ sign = '-'; } else { if (doSign) sign = '-'; if (*cp == EOS) cp++; } break; } /* FALLTHROUGH if no floating point format routine */ default: /* "%?" prints ?, unless ? is NULL */ if (ch == EOS) return (ret); /* pretend it was %c with argument ch */ cp = buf; *cp = ch; size = 1; sign = EOS; break; } /* All reasonable formats wind up here. At this point, * `cp' points to a string which (if not doLAdjust) * should be padded out to `width' places. If * doZeroPad, it should first be prefixed by any * sign or other prefix; otherwise, it should be blank * padded before the prefix is emitted. After any * left-hand padding and prefixing, emit zeroes * required by a decimal [diouxX] precision, then print * the string proper, then emit zeroes required by any * leftover floating precision; finally, if doLAdjust, * pad with blanks. */ /* * compute actual size, so we know how much to pad. * fieldsz excludes decimal prec; realsz includes it */ fieldsz = size + fpprec; if (sign) { fieldsz++; if (fieldSzIncludeSign) dprec++; } else if (doHexPrefix) fieldsz += 2; realsz = (dprec > fieldsz) ? dprec : fieldsz; /* right-adjusting blank padding */ if (!doLAdjust && !doZeroPad) PAD(width - realsz, blanks); /* prefix */ if (sign) { if ((*outRoutine) (&sign, 1, outarg) != OK) return (ERROR); } else if (doHexPrefix) { ox[0] = '0'; ox[1] = ch; if ((*outRoutine) (ox, 2, outarg) != OK) return (ERROR); } /* right-adjusting zero padding */ if (!doLAdjust && doZeroPad) PAD(width - realsz, zeroes); /* leading zeroes from decimal precision */ PAD(dprec - fieldsz, zeroes); /* the string or number proper */ if ((*outRoutine) (cp, size, outarg) != OK) return (ERROR); /* trailing floating point zeroes */ PAD(fpprec, zeroes); /* left-adjusting padding (always blank) */ if (doLAdjust) PAD(width - realsz, blanks); /* finally, adjust ret */ ret += (width > realsz) ? width : realsz; } }/********************************************************************************* putbuf - put characters in a buffer** This routine is a support routine for sprintf().* This routine copies length bytes from source to destination, leaving the* destination buffer pointer pointing at byte following block copied.*/LOCAL STATUS putbuf ( char *inbuf, /* pointer to source buffer */ int length, /* number of bytes to copy */ char **outptr /* pointer to destination buffer */ ) { bcopy (inbuf, *outptr, length); *outptr += length; return (OK); }/********************************************************************************* printbuf - printf() support routine: print characters in a buffer*/LOCAL STATUS printbuf ( char *buf, int nbytes, int fd ) { return (write (fd, buf, nbytes) == nbytes ? OK : ERROR); }/********************************************************************************* fioRead - read a buffer** This routine repeatedly calls the routine read() until <maxbytes> have* been read into <buffer>. If EOF is reached, the number of bytes read* will be less than <maxbytes>.** RETURNS:* The number of bytes read, or ERROR if there is an error during the read* operation.** SEE ALSO: read()*/int fioRead ( int fd, /* file descriptor of file to read */ char * buffer, /* buffer to receive input */ int maxbytes /* maximum number of bytes to read */ ) { int original_maxbytes = maxbytes; int nbytes; while (maxbytes > 0) { nbytes = read (fd, buffer, maxbytes); if (nbytes < 0) return (ERROR); if (nbytes == 0) return (original_maxbytes - maxbytes); maxbytes -= nbytes; buffer += nbytes; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -