Subversion Repositories Kolibri OS

Rev

Rev 4921 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4921 Rev 6099
Line 112... Line 112...
112
<>, <>, <>, <>.
112
<>, <>, <>, <>.
113
*/
113
*/
Line 114... Line 114...
114
 
114
 
115
#if defined(LIBC_SCCS) && !defined(lint)
115
#if defined(LIBC_SCCS) && !defined(lint)
116
/*static char *sccsid = "from: @(#)vfprintf.c	5.50 (Berkeley) 12/16/92";*/
116
/*static char *sccsid = "from: @(#)vfprintf.c	5.50 (Berkeley) 12/16/92";*/
117
static char *rcsid = "$Id: vfprintf.c,v 1.43 2002/08/13 02:40:06 fitzsim Exp $";
117
static char *rcsid = "$Id$";
Line 118... Line 118...
118
#endif /* LIBC_SCCS and not lint */
118
#endif /* LIBC_SCCS and not lint */
119
 
119
 
120
/*
120
/*
Line 855... Line 855...
855
#endif
855
#endif
Line 856... Line 856...
856
 
856
 
857
#ifndef STRING_ONLY
857
#ifndef STRING_ONLY
858
	/* Initialize std streams if not dealing with sprintf family.  */
858
	/* Initialize std streams if not dealing with sprintf family.  */
859
	CHECK_INIT (data, fp);
859
	CHECK_INIT (data, fp);
Line 860... Line 860...
860
    _newlib_flockfile_start (fp);
860
	_newlib_flockfile_start (fp);
Line 861... Line 861...
861
 
861
 
862
	ORIENT(fp, -1);
862
	ORIENT(fp, -1);
Line 962... Line 962...
962
			thousands_sep = _localeconv_r (data)->thousands_sep;
962
			thousands_sep = _localeconv_r (data)->thousands_sep;
963
			thsnd_len = strlen (thousands_sep);
963
			thsnd_len = strlen (thousands_sep);
964
			grouping = _localeconv_r (data)->grouping;
964
			grouping = _localeconv_r (data)->grouping;
965
			if (thsnd_len > 0 && grouping && *grouping)
965
			if (thsnd_len > 0 && grouping && *grouping)
966
			  flags |= GROUPING;
966
			  flags |= GROUPING;
967
		  goto rflag;
967
			goto rflag;
968
#endif
968
#endif
969
		case ' ':
969
		case ' ':
970
			/*
970
			/*
971
			 * ``If the space and + flags both appear, the space
971
			 * ``If the space and + flags both appear, the space
972
			 * flag will be ignored.''
972
			 * flag will be ignored.''
Line 1336... Line 1336...
1336
# ifdef _WANT_IO_C99_FORMATS
1336
# ifdef _WANT_IO_C99_FORMATS
1337
				flags &= ~GROUPING;
1337
				flags &= ~GROUPING;
1338
# endif
1338
# endif
1339
			} else {
1339
			} else {
1340
				if (ch == 'f') {		/* f fmt */
1340
				if (ch == 'f') {		/* f fmt */
1341
				if (expt > 0) {
1341
					if (expt > 0) {
-
 
1342
						size = expt;
-
 
1343
						if (prec || flags & ALT)
-
 
1344
							size += prec + 1;
-
 
1345
					} else	/* "0.X" */
-
 
1346
						size = (prec || flags & ALT)
-
 
1347
							  ? prec + 2
-
 
1348
							  : 1;
-
 
1349
				} else if (expt >= ndig) { /* fixed g fmt */
1342
					size = expt;
1350
					size = expt;
1343
					if (prec || flags & ALT)
-
 
1344
						size += prec + 1;
-
 
1345
				} else	/* "0.X" */
-
 
1346
					size = (prec || flags & ALT)
-
 
1347
						  ? prec + 2
-
 
1348
						  : 1;
-
 
1349
			} else if (expt >= ndig) {	/* fixed g fmt */
-
 
1350
				size = expt;
-
 
1351
				if (flags & ALT)
1351
					if (flags & ALT)
1352
					++size;
1352
						++size;
1353
			} else
1353
				} else
1354
				size = ndig + (expt > 0 ?
1354
					size = ndig + (expt > 0 ?
1355
					1 : 2 - expt);
1355
						1 : 2 - expt);
1356
# ifdef _WANT_IO_C99_FORMATS
1356
# ifdef _WANT_IO_C99_FORMATS
1357
				if ((flags & GROUPING) && expt > 0) {
1357
				if ((flags & GROUPING) && expt > 0) {
1358
					/* space for thousands' grouping */
1358
					/* space for thousands' grouping */
1359
					nseps = nrepeats = 0;
1359
					nseps = nrepeats = 0;
1360
					lead = expt;
1360
					lead = expt;
Line 1519... Line 1519...
1519
				 * NUL in the first `prec' characters, and
1519
				 * NUL in the first `prec' characters, and
1520
				 * strlen () will go further.
1520
				 * strlen () will go further.
1521
				 */
1521
				 */
1522
				char *p = memchr (cp, 0, prec);
1522
				char *p = memchr (cp, 0, prec);
Line 1523... Line 1523...
1523
 
1523
 
1524
				if (p != NULL) {
1524
				if (p != NULL)
1525
					size = p - cp;
-
 
1526
					if (size > prec)
-
 
1527
						size = prec;
1525
					size = p - cp;
1528
				} else
1526
				else
1529
					size = prec;
1527
					size = prec;
1530
			} else
1528
			} else
Line 1531... Line 1529...
1531
				size = strlen (cp);
1529
				size = strlen (cp);
Line 1596... Line 1594...
1596
					}
1594
					}
1597
#ifdef _WANT_IO_C99_FORMATS
1595
#ifdef _WANT_IO_C99_FORMATS
1598
					ndig = 0;
1596
					ndig = 0;
1599
#endif
1597
#endif
1600
					do {
1598
					do {
1601
						*--cp = to_char (_uquad % 10);
1599
					  *--cp = to_char (_uquad % 10);
1602
#ifdef _WANT_IO_C99_FORMATS
1600
#ifdef _WANT_IO_C99_FORMATS
1603
					  ndig++;
1601
					  ndig++;
1604
					  /* If (*grouping == CHAR_MAX) then no
1602
					  /* If (*grouping == CHAR_MAX) then no
1605
					     more grouping */
1603
					     more grouping */
1606
					  if ((flags & GROUPING)
1604
					  if ((flags & GROUPING)
Line 1617... Line 1615...
1617
					       next cases. */
1615
					       next cases. */
1618
					    if (grouping[1] != '\0')
1616
					    if (grouping[1] != '\0')
1619
					      grouping++;
1617
					      grouping++;
1620
					  }
1618
					  }
1621
#endif
1619
#endif
1622
						_uquad /= 10;
1620
					  _uquad /= 10;
1623
					} while (_uquad != 0);
1621
					} while (_uquad != 0);
1624
					break;
1622
					break;
Line 1625... Line 1623...
1625
 
1623
 
1626
				case HEX:
1624
				case HEX:
Line 1742... Line 1740...
1742
					    if (cp > convbuf + ndig)
1740
					    if (cp > convbuf + ndig)
1743
						cp = convbuf + ndig;
1741
						cp = convbuf + ndig;
1744
					}
1742
					}
1745
#endif
1743
#endif
1746
					if (expt < ndig || flags & ALT)
1744
					if (expt < ndig || flags & ALT)
1747
					PRINT (decimal_point, decp_len);
1745
					    PRINT (decimal_point, decp_len);
1748
					PRINTANDPAD (cp, convbuf + ndig,
1746
					PRINTANDPAD (cp, convbuf + ndig,
1749
						     ndig - expt, zeroes);
1747
						     ndig - expt, zeroes);
1750
				}
1748
				}
1751
			} else {	/* 'a', 'A', 'e', or 'E' */
1749
			} else {	/* 'a', 'A', 'e', or 'E' */
1752
				if (ndig > 1 || flags & ALT) {
1750
				if (ndig > 1 || flags & ALT) {