| 838 | /* Handle comparisons. */ |
| 839 | |
| 840 | static VALUE * |
| 841 | eval2 (bool evaluate) |
| 842 | { |
| 843 | #ifdef EVAL_TRACE |
| 844 | trace ("eval2"); |
| 845 | #endif |
| 846 | VALUE *l = eval3 (evaluate); |
| 847 | while (true) |
| 848 | { |
| 849 | enum |
| 850 | { |
| 851 | less_than, less_equal, equal, not_equal, greater_equal, greater_than |
| 852 | } fxn; |
| 853 | |
| 854 | if (nextarg ("<")) |
| 855 | fxn = less_than; |
| 856 | else if (nextarg ("<=")) |
| 857 | fxn = less_equal; |
| 858 | else if (nextarg ("=") || nextarg ("==")) |
| 859 | fxn = equal; |
| 860 | else if (nextarg ("!=")) |
| 861 | fxn = not_equal; |
| 862 | else if (nextarg (">=")) |
| 863 | fxn = greater_equal; |
| 864 | else if (nextarg (">")) |
| 865 | fxn = greater_than; |
| 866 | else |
| 867 | return l; |
| 868 | VALUE *r = eval3 (evaluate); |
| 869 | |
| 870 | bool val = false; |
| 871 | if (evaluate) |
| 872 | { |
| 873 | tostring (l); |
| 874 | tostring (r); |
| 875 | |
| 876 | int cmp; |
| 877 | if (looks_like_integer (l->u.s) && looks_like_integer (r->u.s)) |
| 878 | cmp = strintcmp (l->u.s, r->u.s); |
| 879 | else |
| 880 | { |
| 881 | errno = 0; |
| 882 | cmp = strcoll (l->u.s, r->u.s); |
| 883 | |
| 884 | if (errno) |
| 885 | { |
| 886 | error (0, errno, _("string comparison failed")); |
| 887 | error (0, 0, _("set LC_ALL='C' to work around the problem")); |
| 888 | error (EXPR_INVALID, 0, |
| 889 | _("the strings compared were %s and %s"), |
| 890 | quotearg_n_style (0, locale_quoting_style, l->u.s), |
| 891 | quotearg_n_style (1, locale_quoting_style, r->u.s)); |
| 892 | } |
| 893 | } |
| 894 | |
| 895 | switch (fxn) |
| 896 | { |
| 897 | case less_than: val = (cmp < 0); break; |