/*--------------------------------------------------------------- * Copyright (c) 1999,2000,2001,2002,2003 * The Board of Trustees of the University of Illinois * All Rights Reserved. *--------------------------------------------------------------- * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software (Iperf) and associated * documentation files (the "Software"), to deal in the Software * without restriction, including without limitation the * rights to use, copy, modify, merge, publish, distribute, * sublicense, and/or sell copies of the Software, and to permit * persons to whom the Software is furnished to do * so, subject to the following conditions: * * * Redistributions of source code must retain the above * copyright notice, this list of conditions and * the following disclaimers. * * * Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimers in the documentation and/or other materials * provided with the distribution. * * * Neither the names of the University of Illinois, NCSA, * nor the names of its contributors may be used to endorse * or promote products derived from this Software without * specific prior written permission. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE CONTIBUTORS OR COPYRIGHT * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, * ARISING FROM, OUT OF OR IN CONNECTION WITH THE * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * ________________________________________________________________ * National Laboratory for Applied Network Research * National Center for Supercomputing Applications * University of Illinois at Urbana-Champaign * http://www.ncsa.uiuc.edu * ________________________________________________________________ * * stdio.c * by Mark Gates <mgates@nlanr.net> * and Ajay Tirumalla <tirumala@ncsa.uiuc.edu> * ------------------------------------------------------------------- * input and output numbers, converting with kilo, mega, giga
* ------------------------------------------------------------------- */
/* ------------------------------------------------------------------- * byte_atof * * Given a string of form #x where # is a number and x is a format * character listed below, this returns the interpreted integer. * Gg, Mm, Kk are giga, mega, kilo respectively
* ------------------------------------------------------------------- */
/* ------------------------------------------------------------------- * byte_atoi * * Given a string of form #x where # is a number and x is a format * character listed below, this returns the interpreted integer. * Gg, Mm, Kk are giga, mega, kilo respectively
* ------------------------------------------------------------------- */
/* labels for bit formats [kmg] */ constchar* kLabel_bit[] =
{ "bit", "Kbit", "Mbit", "Gbit"
};
/* ------------------------------------------------------------------- * byte_snprintf * * Given a number in bytes and a format, converts the number and * prints it out with a bits or bytes label. * B, K, M, G, A for Byte, Kbyte, Mbyte, Gbyte, adaptive byte * b, k, m, g, a for bit, Kbit, Mbit, Gbit, adaptive bit * adaptive picks the "best" one based on the number. * outString should be at least 11 chars long * (4 digits + space + 5 chars max + null)
* ------------------------------------------------------------------- */
void byte_snprintf( char* outString, int inLen, double inNum, char inFormat ) { int conv; constchar* suffix; constchar* format;
/* convert to bits for [bkmga] */ if ( ! isupper( (int)inFormat ) ) {
inNum *= 8;
}
/* print such that we always fit in 4 places */ if ( inNum < 9.995 ) { /* 9.995 would be rounded to 10.0 */
format = "%4.2f %s"; /* #.## */
} elseif ( inNum < 99.95 ) { /* 99.95 would be rounded to 100 */
format = "%4.1f %s"; /* ##.# */
} elseif ( inNum < 999.5 ) { /* 999.5 would be rounded to 1000 */
format = "%4.0f %s"; /* ### */
} else { /* 1000-1024 fits in 4 places * If not using Adaptive sizes then
* this code will not control spaces*/
format = "%4.0f %s"; /* #### */
}
snprintf( outString, inLen, format, inNum, suffix );
} /* end byte_snprintf */
/* ------------------------------------------------------------------- * redirect * * redirect the stdout into a specified file * return: none
* ------------------------------------------------------------------- */
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.32Bemerkung:
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.