
###	 -----
###----- FIXME ----- THIS SHOULD partly happen in  ../../main/paste.c !!! ---
###	 -----

##-- As long as format(.) does not work with digits ...
if(format(pi, digits=1) != "3" || format(pi, digits=3) != "3.14") {

	.format.Internal <- format
	## 'format' is <primitive>  defined in	../../../main/paste.c

	format <- function(x, ...) UseMethod("format")
	format.default <- function(x, trim=FALSE, digits= .Options$digits)
	{
		if(!missing(digits)) {
			op <- options(digits=digits)
			on.exit(options(op))
		}
		.format.Internal(x, trim=trim)
	}
}

formatC <-
function (x, digits=NULL, width=max(0, digits) + 1, format=NULL,
	flag="", mode=NULL)
{
	# Copyright (C) Martin Maechler, 1994-1998
	blank.chars <- function(no)
		sapply(no+1, function(n) paste(character(n), collapse=" "))
	if (is.null(x)) return("")
	n <- length(x)
	if (missing(mode))
		mode <- storage.mode(x)
	else if (any(mode == c("real", "integer")))
		storage.mode(x) <- mode
	else stop("\"mode\" must be \"real\" or \"integer\"")
	if (mode == "character" || (!is.null(format) && format == "s")) {
		if (mode != "character") {
			warning("should give \"character\" argument for format=\"s\" -- COERCE")
			x <- as.character(x)
		}
		nc <- nchar(x)
		if (width < 0) {
			flag <- "-"
			width <- -width
		}
		pad <- blank.chars(pmax(0, width - nc))
		## for R <= 0.49 (incompatibility to S), pad may be list:
		if(is.list(pad)) {
			pad[sapply(pad,length) == 0] <- list("")
			pad <- unlist(pad)
		}
		if (flag == "-")
			return(paste(x, pad, sep = ""))
		else	return(paste(pad, x, sep = ""))
	}
	some.special <- !all(Ok <- is.finite(x))
	if (some.special) {
		nQ <- nchar(rQ <- as.character(x[!Ok]))
		nX <- pmax(width - nQ, 0)
		#-- number of characters to add
		x[!Ok] <- 0
	}
	if (missing(format) || is.null(format))
		format <- if (mode == "integer")
			"d"
		else "g"
	else {
		if (any(format == c("f", "e", "E", "g", "G"))) {
			if (mode == "integer")
				mode <- storage.mode(x) <- "real"
		}
		else if (format == "d") {
			if (mode != "integer")
				mode <- storage.mode(x) <- "integer"
		}
		else stop("\"format\" must be in {\"f\",\"e\",\"E\",\"g\",\"G\", \"s\"}" )
	}
	if (missing(digits) || is.null(digits))
		digits <- if (mode == "integer") 2 else 4
	if (width == 0)
		stop("\"width\" must not be 0")
	i.strlen <-
	  pmax(abs(width),
	       if(format == "f") {
		 xEx <- as.integer(floor(log10(abs(x+ifelse(x==0,1,0)))))
		 as.integer(x < 0 | flag!="") + abs(digits) + 2 + pmax(xEx,0)
	       } else rep(abs(digits)+8, n) # format == "g" or "e"
	       )
	r <- .C("str_signif",
		x = x,
		n = n,
		mode = as.character(mode),
		width = as.integer(width),
		digits = as.integer(digits),
		format = as.character(format),
		flag = as.character(flag),
		result = blank.chars(i.strlen) )$result
	if (some.special)
		r[!Ok] <- rQ
	if (!is.null(x.atr <- attributes(x)))
		attributes(r) <- x.atr
	r
}
