diff options
author | Arnold D. Robbins <arnold@skeeve.com> | 2014-04-11 07:44:22 +0300 |
---|---|---|
committer | Arnold D. Robbins <arnold@skeeve.com> | 2014-04-11 07:44:22 +0300 |
commit | ebb6772e9eabeb81e3cc9305a6bec7adf7aad450 (patch) | |
tree | 2cf743f82791db19cc7e31cab86b1fc9a4d5ddbb /builtin.c | |
parent | e069c636968370f0899d5e4ebaeb9c2341804245 (diff) | |
parent | a4b59faf911743b30f2e6e979c4f9c1ea0669ac3 (diff) | |
download | egawk-ebb6772e9eabeb81e3cc9305a6bec7adf7aad450.tar.gz egawk-ebb6772e9eabeb81e3cc9305a6bec7adf7aad450.tar.bz2 egawk-ebb6772e9eabeb81e3cc9305a6bec7adf7aad450.zip |
Merge branch 'master' into comment
Diffstat (limited to 'builtin.c')
-rw-r--r-- | builtin.c | 44 |
1 files changed, 30 insertions, 14 deletions
@@ -3,7 +3,7 @@ */ /* - * Copyright (C) 1986, 1988, 1989, 1991-2013 the Free Software Foundation, Inc. + * Copyright (C) 1986, 1988, 1989, 1991-2014 the Free Software Foundation, Inc. * * This file is part of GAWK, the GNU implementation of the * AWK Programming Language. @@ -719,7 +719,7 @@ format_tree( mpz_ptr zi; mpfr_ptr mf; #endif - enum { MP_INT_WITH_PREC = 1, MP_INT_WITHOUT_PREC, MP_FLOAT } fmt_type; + enum { MP_NONE = 0, MP_INT_WITH_PREC = 1, MP_INT_WITHOUT_PREC, MP_FLOAT } fmt_type; static const char sp[] = " "; static const char zero_string[] = "0"; @@ -817,7 +817,7 @@ format_tree( mf = NULL; zi = NULL; #endif - fmt_type = 0; + fmt_type = MP_NONE; lj = alt = big_flag = bigbig_flag = small_flag = false; fill = sp; @@ -994,9 +994,7 @@ check_pos: goto check_pos; case '\'': #if defined(HAVE_LOCALE_H) - /* allow quote_flag if there is a thousands separator. */ - if (loc.thousands_sep[0] != '\0') - quote_flag = true; + quote_flag = true; goto check_pos; #else goto retry; @@ -1196,6 +1194,9 @@ out0: } if (i < 1) goto out_of_range; +#if defined(HAVE_LOCALE_H) + quote_flag = (quote_flag && loc.thousands_sep[0] != 0); +#endif chp = &cpbufs[1].buf[i-1]; ii = jj = 0; do { @@ -1203,8 +1204,14 @@ out0: chp--; i--; #if defined(HAVE_LOCALE_H) if (quote_flag && loc.grouping[ii] && ++jj == loc.grouping[ii]) { - if (i) /* only add if more digits coming */ - PREPEND(loc.thousands_sep[0]); /* XXX - assumption it's one char */ + if (i) { /* only add if more digits coming */ + int k; + const char *ts = loc.thousands_sep; + + for (k = strlen(ts) - 1; k >= 0; k--) { + PREPEND(ts[k]); + } + } if (loc.grouping[ii+1] == 0) jj = 0; /* keep using current val in loc.grouping[ii] */ else if (loc.grouping[ii+1] == CHAR_MAX) @@ -1360,6 +1367,9 @@ mpf1: #ifdef HAVE_MPFR int0: #endif +#if defined(HAVE_LOCALE_H) + quote_flag = (quote_flag && loc.thousands_sep[0] != 0); +#endif /* * When to fill with zeroes is of course not simple. * First: No zero fill if left-justifying. @@ -1378,8 +1388,14 @@ mpf1: uval /= base; #if defined(HAVE_LOCALE_H) if (base == 10 && quote_flag && loc.grouping[ii] && ++jj == loc.grouping[ii]) { - if (uval) /* only add if more digits coming */ - PREPEND(loc.thousands_sep[0]); /* XXX --- assumption it's one char */ + if (uval) { /* only add if more digits coming */ + int k; + const char *ts = loc.thousands_sep; + + for (k = strlen(ts) - 1; k >= 0; k--) { + PREPEND(ts[k]); + } + } if (loc.grouping[ii+1] == 0) jj = 0; /* keep using current val in loc.grouping[ii] */ else if (loc.grouping[ii+1] == CHAR_MAX) @@ -1999,10 +2015,10 @@ do_mktime(int nargs) & hour, & minute, & second, & dst); - if (do_lint /* Ready? Set! Go: */ - && ( (second < 0 || second > 60) - || (minute < 0 || minute > 60) - || (hour < 0 || hour > 23) + if ( do_lint /* Ready? Set! Go: */ + && ( (second < 0 || second > 60) + || (minute < 0 || minute > 59) + || (hour < 0 || hour > 23) /* FIXME ISO 8601 allows 24 ? */ || (day < 1 || day > 31) || (month < 1 || month > 12) )) lintwarn(_("mktime: at least one of the values is out of the default range")); |