summaryrefslogtreecommitdiff
path: root/src/expr.c
AgeCommit message (Collapse)Author
2012-01-09maint: src/*.c: change remaining quotes (without embedded spaces)Jim Meyering
Run this (twice): git grep -E -l '`[^ ]+'\' src/*.c \ |xargs perl -pi -e 's/`([^ ]+'\'')/'\''$1/'
2012-01-09maint: convert `...' to '...' in --help outputJim Meyering
All affected lines end with \ or \n\, so run this command until it produces no new changes (4 times): git grep -E -l '`[^ ]+'\''.*\\' src \ |xargs perl -pi -e 's/`([^ ]+'\''.*\\)/'\''$1/'
2012-01-07maint: use new emit_try_help in place of equivalent fprintfJim Meyering
Run this command: perl -0777 -pi -e \ 's/fprintf \(stderr, _\("Try `%s --help.*\n.*;/emit_try_help ();/m'\ src/*.c
2012-01-01maint: update all copyright year number rangesJim Meyering
Run "make update-copyright".
2011-07-02maint: use "const" and "pure" function attributes where possibleJim Meyering
* configure.ac (WARN_CFLAGS): Add -Wsuggest-attribute=const, -Wsuggest-attribute=pure and -Wsuggest-attribute=noreturn. (GNULIB_WARN_CFLAGS): But do not add them here... yet. * src/chown-core.h (chopt_free, uid_to_name): Add function attribute(s). * src/copy.c (is_ancestor, valid_options): Likewise. * src/copy.h (chown_failure_ok): Likewise. * src/dd.c (operand_matches, operand_is): Likewise. * src/df.c (selected_fstype, excluded_fstype): Likewise. * src/expr.c (null looks_like_integer): Likewise. * src/md5sum.c (hex_digits): Likewise. * src/od.c (get_lcm): Likewise. * src/pathchk.c (component_start, component_len): Likewise. * src/pinky.c (count_ampersands): Likewise. * src/pr.c (cols_ready_to_print): Likewise. * src/ptx.c (search_table): Likewise. * src/sort.c (find_unit_order): Likewise. * src/stty.c (mode_type_flag, string_to_baud, baud_to_value): Likewise. * src/system.h (gcd, lcm): Likewise. * src/tr.c (is_char_class_member, look_up_char_class): Likewise. (star_digits_closebracket): Likewise. * src/uniq.c (find_field): Likewise. * src/wc.c (compute_number_width): Likewise. * lib/xfts.h (cycle_warning_required): Likewise. * gl/lib/randint.h (randint_get_source): Likewise. * gl/lib/randperm.c (ceil_lg): Likewise. * gl/lib/randperm.h (randperm_bound): Likewise. * lib/strnumcmp.h (strintcmp): Likewise.
2011-05-26maint: accommodate gcc's -Wstrict-overflow optionJim Meyering
* src/factor.c (factor_using_pollard_rho): Change type of "i" to unsigned to avoid warning from gcc's -Wstrict-overflow. * src/expr.c: Use an unsigned intermediate. * src/dircolors.c (main): Reorder operations to avoid the risk of pointer overflow. * src/tr.c (squeeze_filter): Change NOT_A_CHAR from an anonymous "enum" to an "int", to avoid this warning: tr.c:1624:10: error: assuming signed overflow does not occur when simplifying conditional to constant [-Werror=strict-overflow] * src/pr.c (main): Make index "i" unsigned.
2011-05-19maint: correct typos involving misuse of "a" and "an"Jim Meyering
* NEWS: "an misleading" * src/expr.c: "a integer * src/ptx.c (find_occurs_in_text): "a end" * src/shred.c (do_wipefd): "a infinite" * src/sort.c (SUBTHREAD_LINES_HEURISTIC): "an dual-core" (compare_random): "an checksum" * cfg.mk (old_NEWS_hash): Update, since the typo was in old news.
2011-01-01maint: update all copyright year number rangesJim Meyering
Run "make update-copyright".
2010-05-31maint: make spacing around "=" consistent, even in IF_LINTJim Meyering
E.g., - size_t desired_width IF_LINT (= 0); + size_t desired_width IF_LINT ( = 0); Use this command: g grep -l IF_LINT | grep '\.[ch]$' \ | xargs perl -pi -e 's/(IF_LINT \()= /$1 = /'
2010-02-25expr: clarify error messageEric Blake
* src/expr.c (eval4, eval3): Clarify that expr expects integers, and not the broader category of numbers. * tests/misc/expr: Update test accordingly. Suggested by Dan Jacobson.
2010-01-01maint: update all FSF copyright year lists to include 2010Jim Meyering
Use this command: git ls-files | grep -v COPYING \ | xargs env UPDATE_COPYRIGHT_USE_INTERVALS=1 \ build-aux/update-copyright
2009-09-23maint: Use logical rather than bitwise operators on boolsPádraig Brady
This is because bitwise operators are: - confusing and inconsistent in a boolean context - non short circuiting - brittle in C89 where bool can be an int (so > 1)
2009-09-23maint: expr: avoid compiler warnings without GMPPádraig Brady
* src/expr.c (mpz_clear, mpz_get_str, mpz_out_str) [!HAVE_GMP]: Reference unused arguments.
2009-09-21doc: mention the texinfo documentation in --helpPádraig Brady
* src/system.h: Rename emit_bug_reporting_address() to emit_ancillary_info() and update it to not print the translation project address in en_* locales, and _do_ print it in the 'C' (and other) locales so that it's included in the default man page. Also mention how to invoke the texinfo documentation for each command. Also move the "hard-locale.h" include to the 8 files that now use it. * man/help2man: Strip the newly added texinfo reference from the --help output as a more verbose version is already added by help2man. Suggestion from C de-Avillez
2009-08-25global: convert indentation-TABs to spacesJim Meyering
Transformed via this shell code: t=$'\t' git ls-files \ | grep -vE '(^|/)((GNU)?[Mm]akefile|ChangeLog)|\.(am|mk)$' \ | grep -vE 'tests/pr/|help2man' \ | xargs grep -lE "^ *$t" \ | xargs perl -MText::Tabs -ni -le \ '$m=/^( *\t[ \t]*)(.*)/; print $m ? expand($1) . $2 : $_'
2009-06-23maint: update all Copyright year lists to include 2009Jim Meyering
2008-10-20expr: Fixup authorsPádraig Brady
* src/expr.c: Standardise the format of AUTHORS to that used in other utils with multiple authors. Also add Paul Eggert since he basically rewrote it with his bignum fixes. * AUTHORS (expr): Add Paul Eggert.
2008-10-15expr: remove --bignum and --no-bignum optionsPaul Eggert
* doc/coreutils.texi (expr invocation): Remove the --bignum and --no-bignum options. They weren't really needed, and they broke longstanding (albeit nonportable) scripts. * src/expr.c: Don't include <assert.h>. Include "inttostr.h", "long-options.h", "verify.h". Check at compile-time that size_t fits in unsigned long int, as the code assumes this in several places. (HAVE_GMP): Define to 0 if not defined, for convenience. (mpz_t, mpz_clear, mpz_init_set_ui, mpz_init_set_str, mpz_add): (mpz_sub, mpz_mul, mpz_tdiv_q, mpz_tdiv_r, mpz_get_str, mpz_sgn): (mpz_fits_ulong_p, mpz_get_ui, mpz_out_str): Supply substitutes when !HAVE_GMP, which work well enough for expr's purposes. (mp_integer): Remove. All integers are gmp, if gmp is available. (struct valinfo): Remove 'z' member; no longer needed. The 'i' member is always of type mpz_t. (enum arithmetic_mode, MP_NEVER, MP_ALWAYS, MP_AUTO, mode): Remove; no longer needed. (usage): Remove documentation of --bignum and --no-bignum. (integer_overflow): Abort if error misbehaves, to pacify GCC. Restore old message on arithmetic overflow, to be conservative. (die): Omit exit_status parameter; not needed (is always EXPR_FAILURE). (string_too_long, USE_BIGNUM, NO_USE_BIGNUM, long_options): Remove; no longer needed. (main): Don't use getopt_long; this breaks old nonportable scripts. (int_value): Arg is unsigned, in case we have strings whose length exceeds LONG_MAX (!). (int_value, freev, printv, null, tostring, toarith): (eval6, eval4, eval3): Always use mpz_ functions, to simplify the code. (substr_value): Remove; no longer needed. (getsize): Simplify the API: one arg rather than 3. Don't assume unsigned long int fits in size_t. (promote, domult, dodivide, doadd): Remove; no longer needed. * tests/misc/expr: Don't use --bignum to test for bignum support. Instead, use big numbers to test this.
2008-10-15expr: don't interpret argv[0] as an operandJim Meyering
* src/expr.c (main): Given a first argument like -22 (negative, with two or more digits), expr would decrement optind to 0 and then attempt to evaluate argv[0].
2008-08-14"expr --bignum 1" now fails when expr is built without libgmpJim Meyering
* src/expr.c (main): When --bignum is requested, yet expr was built without libgmp, exit nonzero (3) in addition to giving a diagnostic.
2008-08-09expr: avoid compiler warningsJim Meyering
* src/expr.c (die): New "noreturn" function to wrap one-arg use of error (string_too_long): Use die rather than error. (toint): Remove definition of now-unused function. (eval6): Remove a little duplication. Use die rather than error. (dodivide): Remove declaration of now-unused variable.
2008-08-06expr: support arbitrary-precision arithmeticJames Youngman
* src/Makefile.am (expr_LDADD): Link expr against GNU MP. * doc/coreutils.texi (expr invocation): Describe --bignum, --no-bignum. Explain the new arbitrary-precision functionality. * NEWS: Indicate that arbitrary-precision arithmetic is now supported in expr. * src/expr.c (enum valtype): Added mp_integer, signifying a GNU MP number. (usage): Document the new options --bignum and --no-bignum which force and prohibit the use of arbitrary-precision arithmetic, respectively. (long_options): data structure for getopt_long, which we need to use to parse the options mentioned above. (main): parse these options with getopt_long instead of parse_long_options. (valinfo): Downgrade the numeric member of the union from intmax_t to signed long, since MP lacks functions for promoting an intmax_t to an arbitrary-precision quantity. (enum arithmetic_mode): Represents the current choice between --bignum, --no-bignum and the default (automatically switch from one to the other if needed). (integer_overflow): issue a more explicit error message indicating that MP is not available. (string_too_long): new function, emits a fatal error message for the case where an argument to the 'index' expression is too long for a string offset to be represented. (int_value): With --bignum, create the value as mp_integer rather than plain integer. (substr_value): factored out of eval6; implements "substr". (freev): also destroy mp_integer values. Check that no mp_integer values exist if --no-bignum was specified. (printv, null, tostring): support mp_integer. (toint): new funtion for converting from string or mp_integer to integer. (getsize): extracts a size_t value from a VALUE object; used to implement substr. (promote): promotes a value from integer to mp_integer. (domult, dodivide): functions for multiplication and division, factored out of eval4. (doadd): addition/subraction function, factpred out of eval3. (eval3): support mp_integer types; call doadd. (eval4): support mp_integer types; call domult, dodivide. (eval6): support mp_integer offsets and lengths for "substr" and "index". * TODO: Mention that expr supports arbitrary-precision arithmetic, and suggest that this might also be a good idea for seq. * AUTHORS (expr): Add James Youngman.
2008-06-27factor out time_t-to-string conversion idiomJim Meyering
* src/system.h: Include "inttostr.h". (timetostr): New function, factored out of... * src/date.c (show_date): Use timetostr. * src/du.c (show_date): Likewise. * src/ls.c (print_long_format): Likewise. * src/pinky.c (time_string): Likewise. * src/stat.c (human_time): Likewise. * src/*.c: Don't include inttostr.h, since system.h does. * src/c99-to-c89.diff: Adjust offsets.
2008-06-08standardize some error messagesBo Borgerson
* maint.mk: (sc_error_message_warn_fatal, sc_error_message_uppercase): (sc_error_message_period): Add automatic checks for non-standard error messages. * .x-sc_error_message_uppercase: explicit exclusion for this check * src/cp.c: Standardize some error messages. * src/date.c: Likewise. * src/dircolors.c: Likewise. * src/du.c: Likewise. * src/expr.c: Likewise. * src/install.c: Likewise. * src/join.c: Likewise. * src/ln.c: Likewise. * src/mv.c: Likewise. * src/od.c: Likewise. * src/pr.c: Likewise. * src/split.c: Likewise. * src/truncate.c: Likewise. * src/wc.c: Likewise. * tests/du/files0-from: Expect new error message. * tests/misc/join: Likewise. * tests/misc/split-a: Likewise. * tests/misc/wc-files0-from: Likewise. * tests/misc/xstrtol: Likewise. * lib/xmemxfrm.c: Likewise.
2008-06-03use gnulib's progname moduleJim Meyering
* bootstrap.conf (gnulib_modules): Add progname. * src/*.c (program_name): Remove declaration. * (main): Call set_program_name rather than setting program_name. * src/nice.c (main): Cast program_name to "(char *)". * src/prog-fprintf.c: Include "system.h" * src/system.h: Include "progname.h". * maint.mk (sc_program_name): Adjust rule. Suggestion from Eric Blake.
2008-06-02declare program_name consistentlyJim Meyering
* src/base64.c: Likewise. * src/basename.c: Likewise. * src/cat.c: Likewise. * src/chcon.c: Likewise. * src/chgrp.c: Likewise. * src/chmod.c: Likewise. * src/chown.c: Likewise. * src/chroot.c: Likewise. * src/cksum.c: Likewise. * src/comm.c: Likewise. * src/cp.c: Likewise. * src/csplit.c: Likewise. * src/cut.c: Likewise. * src/date.c: Likewise. * src/dd.c: Likewise. * src/df.c: Likewise. * src/dircolors.c: Likewise. * src/dirname.c: Likewise. * src/du.c: Likewise. * src/echo.c: Likewise. * src/env.c: Likewise. * src/expand.c: Likewise. * src/expr.c: Likewise. * src/factor.c: Likewise. * src/fmt.c: Likewise. * src/fold.c: Likewise. * src/groups.c: Likewise. * src/head.c: Likewise. * src/hostid.c: Likewise. * src/hostname.c: Likewise. * src/id.c: Likewise. * src/install.c: Likewise. * src/join.c: Likewise. * src/kill.c: Likewise. * src/link.c: Likewise. * src/ln.c: Likewise. * src/logname.c: Likewise. * src/ls.c: Likewise. * src/md5sum.c: Likewise. * src/mkdir.c: Likewise. * src/mkfifo.c: Likewise. * src/mknod.c: Likewise. * src/mktemp.c: Likewise. * src/mv.c: Likewise. * src/nice.c: Likewise. * src/nl.c: Likewise. * src/nohup.c: Likewise. * src/od.c: Likewise. * src/paste.c: Likewise. * src/pathchk.c: Likewise. * src/pinky.c: Likewise. * src/pr.c: Likewise. * src/printenv.c: Likewise. * src/printf.c: Likewise. * src/ptx.c: Likewise. * src/pwd.c: Likewise. * src/readlink.c: Likewise. * src/rm.c: Likewise. * src/rmdir.c: Likewise. * src/runcon.c: Likewise. * src/seq.c: Likewise. * src/setuidgid.c: Likewise. * src/shuf.c: Likewise. * src/sleep.c: Likewise. * src/sort.c: Likewise. * src/split.c: Likewise. * src/stat.c: Likewise. * src/stty.c: Likewise. * src/su.c: Likewise. * src/sum.c: Likewise. * src/sync.c: Likewise. * src/tac.c: Likewise. * src/tail.c: Likewise. * src/tee.c: Likewise. * src/test.c: Likewise. * src/timeout.c: Likewise. * src/touch.c: Likewise. * src/tr.c: Likewise. * src/true.c: Likewise. * src/tsort.c: Likewise. * src/tty.c: Likewise. * src/uname.c: Likewise. * src/unexpand.c: Likewise. * src/uniq.c: Likewise. * src/unlink.c: Likewise. * src/uptime.c: Likewise. * src/users.c: Likewise. * src/wc.c: Likewise. * src/who.c: Likewise. * src/whoami.c: Likewise. * src/yes.c: Likewise.
2008-05-26adjust copyright datesJim Meyering
2008-05-26convert single-author programs to use proper_nameJim Meyering
g grep -E -l 'define AUTHORS "[^,]+"$'|xargs perl -pi -e \ 's/(define AUTHORS) ("[^,]+")$/$1 proper_name ($2)/'
2007-10-25Tell xgettext that "ARG1 % ARG2" is not a C format string.Micah Cowan
* src/expr.c (usage): Add a comment to override xgettext's default behavior, which would classify "ARG1 % ARG2" as a fprintf-style format string.
2007-08-30Use PACKAGE_NAME instead of GNU_PACKAGE.Eric Blake
* src/Makefile.am (.sh, uninstall-local): Adjust all users of hand-rolled GNU_PACKAGE to instead use autoconf-provided PACKAGE_NAME. * src/basename.c (main): Likewise. * src/chroot.c (main): Likewise. * src/dirname.c (main): Likewise. * src/echo.c (main): Likewise. * src/expr.c (main): Likewise. * src/factor.c (main): Likewise. * src/groups.sh (version): Likewise. Also, reflect change in --version output due to GPLv3. * src/hostid.c (main): Likewise. * src/hostname.c (main): Likewise. * src/link.c (main): Likewise. * src/logname.c (main): Likewise. * src/nice.c (main): Likewise. * src/nohup.c (main): Likewise. * src/printenv.c (main): Likewise. * src/printf.c (main): Likewise. * src/pwd.c (main): Likewise. * src/setuidgid.c (main): Likewise. * src/sleep.c (main): Likewise. * src/system.h (case_GETOPT_VERSION_CHAR): Likewise. * src/test.c (main): Likewise. * src/true.c (main): Likewise. * src/unlink.c (main): Likewise. * src/uptime.c (main): Likewise. * src/users.c (main): Likewise. * src/whoami.c (main): Likewise. * src/yes.c (main): Likewise. * configure.ac (AC_CHECK_DECLS): No need to check strtoimax, strtoumax, since gnulib does this.
2007-07-23Update all copyright notices to use the newer form.Jim Meyering
2007-07-10Change "version 2" to "version 3" in all copyright notices.Jim Meyering
2007-06-15Don't include "quote.h" when it is not used.Jim Meyering
* src/md5sum.c: Remove unnecessary inclusion of "quote.h". * src/expr.c: Likewise. * src/shred.c: Likewise. * Makefile.maint (sc_prohibit_quote_without_use): New rule. * src/c99-to-c89.diff: Adjust offsets.
2007-03-28Help translators include translation team's web or email address.Jim Meyering
* src/system.h (emit_bug_reporting_address): New function. * src/base64.c: Use it rather than a literal printf. * src/basename.c, src/cat.c, src/chgrp.c, src/chmod.c: * src/chown.c, src/chroot.c, src/cksum.c, src/comm.c, src/cp.c: * src/csplit.c, src/cut.c, src/date.c, src/dd.c, src/df.c: * src/dircolors.c, src/dirname.c, src/du.c, src/echo.c, src/env.c: * src/expand.c, src/expr.c, src/factor.c, src/fmt.c, src/fold.c: * src/head.c, src/hostid.c, src/hostname.c, src/id.c, src/install.c: * src/join.c, src/kill.c, src/link.c, src/ln.c, src/logname.c: * src/ls.c, src/md5sum.c, src/mkdir.c, src/mkfifo.c, src/mknod.c: * src/mv.c, src/nice.c, src/nl.c, src/nohup.c, src/od.c: * src/paste.c, src/pathchk.c, src/pinky.c, src/pr.c, src/printenv.c: * src/printf.c, src/ptx.c, src/pwd.c, src/readlink.c, src/rm.c: * src/rmdir.c, src/seq.c, src/setuidgid.c, src/shred.c, src/shuf.c: * src/sleep.c, src/sort.c, src/split.c, src/stat.c, src/stty.c: * src/su.c, src/sum.c, src/sync.c, src/system.h, src/tac.c: * src/tail.c, src/tee.c, src/test.c, src/touch.c, src/tr.c: * src/true.c, src/tsort.c, src/tty.c, src/uname.c, src/unexpand.c: * src/uniq.c, src/unlink.c, src/uptime.c, src/users.c, src/wc.c: * src/who.c, src/whoami.c, src/yes.c: Likewise.
2007-01-11Avoid a leak in expr's implementation of the ":" (match) operator.Jim Meyering
* src/expr.c (docolon): Free the regexp buffer using regfree, rather than doing it manually, being careful to set fastmap to NULL first. Free any re_regs.start and .end members, if necessary.
2006-10-25* src/cat.c (infile): Add "const" to declaration.Jim Meyering
* src/csplit.c (prefix): Likewise. * src/printf.c (cfcc_msg): Likewise. * src/tail.c (valid_file_spec): Likewise. * src/cut.c (cut_file): Likewise, for a parameter. * src/expr.c (str_value): Likewise. * src/fold.c (fold_file): Likewise. * src/pr.c (init_header): Likewise. * src/dircolors.c (dc_parse_stream): Likewise, for a local. * src/tr.c (make_printable_str): Likewise. * src/nl.c (body_type, header_type, footer_type, current_type): (separator_str, build_type_arg, nl_file): Likewise, for many. * src/paste.c (main): Don't assign a read-only string to 'optarg'. * src/tac.c (separator, tac_seekable, copy_to_temp): Likewise.
2006-09-11(eval6): Fix buffer overrun, or bad performance, ifPaul Eggert
substr's last operand is very large. Performance problem reported by Sebastian Kreft.
2006-06-08(eval4): Detect overflow properly when multiplying INTMAX_MIN * -1.Paul Eggert
2006-06-07Don't claim x86 behavior is erroneous in a comment.Paul Eggert
2006-06-07(integer_overflow): New function.Paul Eggert
(eval4, eval3): Check for integer overflow.
2006-04-12Clear the RE_NO_EMPTY_RANGES re syntax option, as this is a less intrusivePaul Eggert
change from the old (Emacs) behavior, and POSIX allows us to treat [z-a] as an empty range.
2006-04-12(docolon): Set re_syntax_options to a value that is compatible withPaul Eggert
what POSIX requires. Also, don't let anchors match newline; this fixes an incompatibility with tradition and with POSIX. Don't warn about leading ^. POSIX says it is unspecified whether ^ is a special character, which means that implementations can either treat it as special or not, but either way a warning is not allowed (unless the regexp is otherwise invalid). Instead, anchor the expression but treat ^ as an anchor; this is the traditional behavior (e.g., Solaris 10). (eval4, eval3, eval2): Treat non-numeric args, division by zero, and the like as invalid expressions (exit status 2), not as failure of 'expr' (exit status 3). This is more consistent with how Solaris behaves.
2006-04-11(docolon): Allocate and use a fastmap.Paul Eggert
Don't bother allocating a buffer.
2005-09-13(docolon): Add IF_LINT check to avoid GCC warning.Paul Eggert
2005-09-09* src/expr.c (docolon): 64-bit regex fixes.Paul Eggert
2005-06-16whoops: Adding quote(...) isn't enough :)Jim Meyering
remove quotes from the string, too.
2005-06-16Don't embed `this'-style quotes in format strings.Jim Meyering
Include "quote.h". Rather than this: error (..., "...`%s'...", arg); do this: error (..., "...%s...", quote (arg));
2005-05-27Include strnumcmp.h, xstrtol.h.Paul Eggert
(looks_like_integer): New function. (toarith): Use it. Also, use xstrtoimax rather than rolling our own diagnostics. (eval2): Don't look for trouble if !evaluate; this simplifies things. Compare numbers using string comparison, so that overflow is not possible.
2005-05-26(toarith): Fix a sign error introduced on 2005-01-14.Jim Meyering
2005-05-14Update FSF postal mail address.Jim Meyering