Script 'mail_helper' called by obssrc Hello community, here is the log from the commit of package bcal for openSUSE:Factory checked in at 2022-04-19 09:58:51 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/bcal (Old) and /work/SRC/openSUSE:Factory/.bcal.new.1941 (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "bcal" Tue Apr 19 09:58:51 2022 rev:5 rq:970658 version:2.4 Changes: -------- --- /work/SRC/openSUSE:Factory/bcal/bcal.changes 2021-03-17 20:19:59.547320598 +0100 +++ /work/SRC/openSUSE:Factory/.bcal.new.1941/bcal.changes 2022-04-19 09:59:51.575688683 +0200 @@ -1,0 +2,12 @@ +Mon Apr 18 15:16:35 UTC 2022 - Ferdinand Thiessen <r...@fthiessen.de> + +- Update to version 2.4 + * Support "exit" and "quit" at prompt + * Fix lint report +- Update to version 2.3 + * Show binary conversion output in octets for readability + * Handle CTRL+D + * Quit program or 'exit' or 'quit' + * Fix broken terminal with calc as backend on "undefined input" + +------------------------------------------------------------------- Old: ---- bcal-2.2.tar.gz New: ---- bcal-2.4.tar.gz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ bcal.spec ++++++ --- /var/tmp/diff_new_pack.tROlIU/_old 2022-04-19 09:59:51.991689224 +0200 +++ /var/tmp/diff_new_pack.tROlIU/_new 2022-04-19 09:59:51.995689229 +0200 @@ -1,7 +1,7 @@ # # spec file for package bcal # -# Copyright (c) 2021 SUSE LLC +# Copyright (c) 2022 SUSE LLC # Copyright (c) 2018 Dilawar Singh <dilawar.s.raj...@gmail.com> # # All modifications and additions to the file contributed by third parties @@ -22,7 +22,7 @@ License: GPL-3.0-only Group: Productivity/Scientific/Math URL: http://www.github.com/jarun/bcal -Version: 2.2 +Version: 2.4 Release: 0 Source0: https://github.com/jarun/bcal/archive/v%{version}.tar.gz#/%{name}-%{version}.tar.gz BuildRequires: readline-devel @@ -40,7 +40,7 @@ %build export CFLAGS="%{optflags}" -make %{?_smp_mflags} +%make_build %install %make_install PREFIX=%{_prefix} DOCDIR=%{buildroot}/%{_prefix}/share/doc/%{name} ++++++ bcal-2.2.tar.gz -> bcal-2.4.tar.gz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/bcal-2.2/.circleci/config.yml new/bcal-2.4/.circleci/config.yml --- old/bcal-2.2/.circleci/config.yml 1970-01-01 01:00:00.000000000 +0100 +++ new/bcal-2.4/.circleci/config.yml 2022-01-24 16:26:20.000000000 +0100 @@ -0,0 +1,128 @@ +version: 2 + +jobs: + compile: + docker: + - image: ubuntu:20.04 + working_directory: ~/bcal + environment: + CI_FORCE_TEST: 1 + steps: + - run: + command: | + apt update -qq + DEBIAN_FRONTEND="noninteractive" TZ="America/New_York" apt-get -y install tzdata + apt install -y --no-install-recommends git make libreadline-dev + apt install -y --no-install-recommends gcc-7 gcc-8 gcc-9 gcc-10 + apt install -y --no-install-recommends clang-6.0 clang-7 clang-8 clang-9 clang-10 clang-11 clang-tidy-11 + - checkout + - run: + command: | + export CFLAGS=-Werror + make clean + echo + echo "########## gcc-7 ##########" + CC=gcc-7 make strip + ls -l bcal + make clean + echo + echo "########## gcc-8 ##########" + CC=gcc-8 make strip + ls -l bcal + make clean + echo + echo "########## gcc-9 ##########" + CC=gcc-9 make strip + ls -l bcal + make clean + echo + echo "########## gcc-10 ##########" + CC=gcc-10 make strip + ls -l bcal + make clean + echo + echo "########## clang-6 ##########" + CC=clang-6.0 make strip + ls -l bcal + make clean + echo + echo "########## clang-7 ##########" + CC=clang-7 make strip + ls -l bcal + make clean + echo + echo "########## clang-8 ##########" + CC=clang-8 make strip + ls -l bcal + make clean + echo + echo "########## clang-9 ##########" + CC=clang-9 make strip + ls -l bcal + make clean + echo + echo "########## clang-10 ##########" + CC=clang-10 make strip + ls -l bcal + make clean + echo + echo "########## clang-11 ##########" + CC=clang-11 make strip + ls -l bcal + make clean + echo + echo "########## clang-tidy-11 ##########" + clang-tidy-11 **/*.h **/*.c -- -Iinc + + package-and-publish: + machine: true + working_directory: ~/bcal + steps: + - checkout + - run: + name: "auto-generate packages" + command: | + # Create dist directory if it doesn't exist + mkdir ./dist + # Clean up + rm -rf ./dist/* + # Pack source + git archive -o ../${CIRCLE_PROJECT_REPONAME}-${CIRCLE_TAG}.tar.gz --format tar.gz --prefix=${CIRCLE_PROJECT_REPONAME}-${CIRCLE_TAG#v}/ ${CIRCLE_TAG} + # Use latest installed python3 from pyenv + export PYENV_VERSION="$(pyenv versions | grep -Po '\b3\.\d+\.\d+' | tail -1)" + #pip install packagecore + #packagecore -c misc/packagecore/packagecore.yaml -o ./dist/ ${CIRCLE_TAG#v} + # Move source pack to dist + mv ../${CIRCLE_PROJECT_REPONAME}-${CIRCLE_TAG}.tar.gz ./dist/ + + - run: + name: "publish to GitHub" + command: | + go get github.com/tcnksm/ghr + ghr -t ${GITHUB_API_TOKEN} -u ${CIRCLE_PROJECT_USERNAME} -r ${CIRCLE_PROJECT_REPONAME} -c ${CIRCLE_SHA1} -replace ${CIRCLE_TAG} ./dist/ + +workflows: + version: 2 + + test: + jobs: &all-tests + - compile + + nightly: + triggers: + - schedule: + cron: "0 0 * * 6" + filters: + branches: + only: + - master + jobs: *all-tests + + publish-github-release: + jobs: + - package-and-publish: + filters: + tags: + only: /^v.*/ + branches: + ignore: /.*/ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/bcal-2.2/.clang-tidy new/bcal-2.4/.clang-tidy --- old/bcal-2.2/.clang-tidy 2020-01-07 15:45:52.000000000 +0100 +++ new/bcal-2.4/.clang-tidy 2022-01-24 16:26:20.000000000 +0100 @@ -1,5 +1,5 @@ --- -Checks: 'clang-diagnostic-*,clang-analyzer-*,readability-*,modernize-*,bugprone-*,misc-*,-misc-unused-parameters,google-runtime-int,-llvm-header-guard,fuchsia-restrict-system-includes,-clang-analyzer-valist.Uninitialized,-clang-analyzer-security.insecureAPI.rand,-clang-analyzer-alpha.*,-readability-magic-numbers,-readability-braces-around-statements,-readability-isolate-declaration' +Checks: 'clang-diagnostic-*,clang-analyzer-*,readability-*,modernize-*,bugprone-*,misc-*,-misc-unused-parameters,google-runtime-int,-llvm-header-guard,fuchsia-restrict-system-includes,-clang-analyzer-valist.Uninitialized,-clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling,-clang-analyzer-security.insecureAPI.rand,-clang-analyzer-alpha.*,-readability-magic-numbers,-readability-braces-around-statements,-readability-function-cognitive-complexity,-readability-isolate-declaration,-bugprone-easily-swappable-parameters' WarningsAsErrors: '*' HeaderFilterRegex: '.*(?<!lookup3.c)$' FormatStyle: 'file' diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/bcal-2.2/.github/FUNDING.yml new/bcal-2.4/.github/FUNDING.yml --- old/bcal-2.2/.github/FUNDING.yml 2020-01-07 15:45:52.000000000 +0100 +++ new/bcal-2.4/.github/FUNDING.yml 2022-01-24 16:26:20.000000000 +0100 @@ -1 +1 @@ -custom: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=RMLTQ76JSXJ4Q +github: jarun diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/bcal-2.2/.github/workflows/ci.yml new/bcal-2.4/.github/workflows/ci.yml --- old/bcal-2.2/.github/workflows/ci.yml 1970-01-01 01:00:00.000000000 +0100 +++ new/bcal-2.4/.github/workflows/ci.yml 2022-01-24 16:26:20.000000000 +0100 @@ -0,0 +1,43 @@ +name: ci + +on: + push: + branches: [master] + pull_request: + branches: [master] + +jobs: + macOS-gcc: + runs-on: macOS-latest + steps: + - uses: actions/checkout@v2 + - name: Compile with gcc + env: + CC: gcc + run: | + brew upgrade python + pip3 install logilab-common + pip3 install pytest + make clean + make + pytest ./test.py + make clean + macOS-clang: + runs-on: macOS-latest + steps: + - uses: actions/checkout@v2 + - name: Compile with clang + env: + CC: clang + run: | + brew update + brew upgrade python + pip3 install logilab-common + pip3 install pytest + brew install llvm + export PATH="/usr/local/opt/llvm/bin:$PATH" + make clean + make + pytest ./test.py + make clean + clang-tidy **/*.h **/*.c -- -Iinc diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/bcal-2.2/.github/workflows/lock.yml new/bcal-2.4/.github/workflows/lock.yml --- old/bcal-2.2/.github/workflows/lock.yml 1970-01-01 01:00:00.000000000 +0100 +++ new/bcal-2.4/.github/workflows/lock.yml 2022-01-24 16:26:20.000000000 +0100 @@ -0,0 +1,17 @@ +name: 'Lock threads' + +on: + schedule: + - cron: '0 0 * * *' + +jobs: + lock: + runs-on: ubuntu-latest + steps: + - uses: dessant/lock-threads@v2 + with: + github-token: ${{ github.token }} + issue-lock-inactive-days: '30' + issue-lock-reason: '' + pr-lock-inactive-days: '30' + pr-lock-reason: '' diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/bcal-2.2/.travis.yml new/bcal-2.4/.travis.yml --- old/bcal-2.2/.travis.yml 2020-01-07 15:45:52.000000000 +0100 +++ new/bcal-2.4/.travis.yml 2022-01-24 16:26:20.000000000 +0100 @@ -1,4 +1,7 @@ language: c +arch : +- amd64 +- ppc64le sudo: required services: - docker @@ -9,10 +12,10 @@ matrix: include: - os: linux - dist: trusty + dist: focal compiler: gcc - os: linux - dist: trusty + dist: focal compiler: clang # - os: linux # compiler: musl-gcc @@ -22,10 +25,10 @@ # - musl # - musl-dev # - musl-tools - - os: osx - compiler: gcc - - os: osx - compiler: clang +# - os: osx +# compiler: gcc +# - os: osx +# compiler: clang install: - if [ $TRAVIS_OS_NAME = linux ]; then @@ -52,11 +55,6 @@ - rm -rf $REPO/.git - tar -czf $REPO-${TRAVIS_TAG}.tar.gz $REPO - cd $REPO - - sudo apt-get update -qy - - sudo apt-get install -qy python3 python3-pip - - sudo python3 -m pip install --upgrade pip - - sudo python3 -m pip install --upgrade packagecore setuptools - - packagecore -o dist/ "${TRAVIS_TAG#v}" - mv ../$REPO-${TRAVIS_TAG}.tar.gz dist/ deploy: diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/bcal-2.2/CHANGELOG new/bcal-2.4/CHANGELOG --- old/bcal-2.2/CHANGELOG 2020-01-07 15:45:52.000000000 +0100 +++ new/bcal-2.4/CHANGELOG 2022-01-24 16:26:20.000000000 +0100 @@ -1,3 +1,21 @@ +bcal v2.4 +2022-01-24 + +- support "exit" and "quit" at prompt +- fix lint report + +------------------------------------------------------------------------------- + +bcal v2.3 +2021-10-09 + +- show binary conversion output in octets for readability +- handle `^D` +- quit program or 'exit' or 'quit' +- fix broken terminal with calc as backend on "undefined input" (#36) + +------------------------------------------------------------------------------- + bcal v2.2 2020-01-07 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/bcal-2.2/README.md new/bcal-2.4/README.md --- old/bcal-2.2/README.md 2020-01-07 15:45:52.000000000 +0100 +++ new/bcal-2.4/README.md 2022-01-24 16:26:20.000000000 +0100 @@ -3,26 +3,21 @@ <p align="center"> <a href="https://github.com/jarun/bcal/releases/latest"><img src="https://img.shields.io/github/release/jarun/bcal.svg?maxAge=600" alt="Latest release" /></a> <a href="https://repology.org/project/bcal/versions"><img src="https://repology.org/badge/tiny-repos/bcal.svg" alt="Availability"></a> -<a href="https://travis-ci.org/jarun/bcal"><img src="https://img.shields.io/travis/jarun/bcal/master.svg" alt="Build Status" /></a> +<a href="https://travis-ci.org/jarun/bcal"><img src="https://img.shields.io/travis/jarun/bcal/master.svg?label=travis" alt="Travis CI Status" /></a> +<a href="https://github.com/jarun/bcal/actions"><img src="https://github.com/jarun/bcal/workflows/ci/badge.svg?branch=master" alt="GitHub CI Status" /></a> <a href="https://scan.coverity.com/projects/jarun-bcal"><img src="https://img.shields.io/coverity/scan/17148.svg" alt="Coverity Scan Build Status" /></a> -<a href="https://github.com/jarun/bcal/blob/master/LICENSE"><img src="https://img.shields.io/badge/license-GPLv3-yellow.svg?maxAge=2592000" alt="License" /></a> +<a href="https://github.com/jarun/bcal/blob/master/LICENSE"><img src="https://img.shields.io/badge/license-GPLv3-yellowgreen.svg?maxAge=2592000" alt="License" /></a> </p> <p align="center"> -<a href="https://asciinema.org/a/168719"><img src="https://asciinema.org/a/168719.png" alt="bcal_asciicast" width="600"/></a> +<a href="https://asciinema.org/a/168719"><img src="https://asciinema.org/a/168719.svg" alt="bcal_asciicast" width="600"/></a> </p> -`bcal` (*Byte CALculator*) is a REPL CLI utility for storage expression evaluation, unit conversion and address calculation. If you can't calculate the hex address offset for (512 - 16) MiB, or the value when the 43<sup>rd</sup> bit of a 64-bit address is set mentally, `bcal` is for you. +`bcal` (*Byte CALculator*) is a REPL CLI utility for storage expression (e.g. `"(2GiB * 2) / (2KiB >> 2)"`) evaluation, SI/IEC conversion, byte address calculation, base conversion and LBA/CHS calculation. It's very useful for those who deal with bits, bytes, addresses and binary prefixes frequently. -It has a [`bc`](https://www.gnu.org/software/bc/manual/html_mono/bc.html) mode for general-purpose numerical calculations. Alternatively, it can also invoke [`calc`](http://www.isthe.com/chongo/tech/comp/calc/) which works better with expressions involving multiple bases. +It has a [`bc`](https://www.gnu.org/software/bc/manual/html_mono/bc.html) mode for general-purpose numerical calculations. Alternatively, it can also invoke the more featured [`calc`](http://www.isthe.com/chongo/tech/comp/calc/) which works better with expressions involving multiple bases. -`bcal` follows Ubuntu's standard unit conversion and notation [policy](https://wiki.ubuntu.com/UnitsPolicy). Only 64-bit operating systems are supported. - -*Love smart and efficient utilities? Explore [my repositories](https://github.com/jarun?tab=repositories). Buy me a cup of coffee if they help you.* - -<p align="center"> -<a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=RMLTQ76JSXJ4Q"><img src="https://img.shields.io/badge/PayPal-donate-1eb0fc.svg" alt="Donate via PayPal!" /></a> -</p> +`bcal` uses [SI and IEC binary prefixes](https://en.wikipedia.org/wiki/Binary_prefix) and supports 64-bit Operating Systems only. ### Table of Contents @@ -30,7 +25,6 @@ - [Installation](#installation) - [Dependencies](#dependencies) - [From a package manager](#from-a-package-manager) - - [Release packages](#release-packages) - [From source](#from-source) - [Termux](#termux) - [Usage](#usage) @@ -45,6 +39,7 @@ - REPL and single execution modes - evaluate arithmetic expressions involving storage units - perform general purpose calculations (using bc or calc) +- works with piped input or file redirection - convert to IEC/SI standard data storage units - interactive mode with the last valid result stored for reuse - show the address in bytes @@ -75,10 +70,6 @@ </p> </details> -#### Release packages - -Packages for Arch Linux, CentOS, Debian, Fedora, OpenSUSE Leap and Ubuntu are available with the [latest stable release](https://github.com/jarun/bcal/releases/latest). - #### From source If you have git installed, clone this repository. Otherwise, download the [latest stable release](https://github.com/jarun/bcal/releases/latest) or [development version](https://github.com/jarun/bcal/archive/master.zip) (*risky*). @@ -98,7 +89,7 @@ `bcal` can be compiled and installed from source in the Termux environment on `aarch64` Android devices. Instructions: ``` -$ aria2c https://github.com/jarun/bcal/archive/master.zip +$ wget https://github.com/jarun/bcal/archive/master.zip $ unzip bcal-master.zip $ cd bcal-master/ $ pkg install make clang readline-dev @@ -118,7 +109,7 @@ positional arguments: expr expression in decimal/hex operands N [unit] capacity in B/KiB/MiB/GiB/TiB/kB/MB/GB/TB - see https://wiki.ubuntu.com/UnitsPolicy + https://en.wikipedia.org/wiki/Binary_prefix default unit is B (byte), case is ignored N can be decimal or '0x' prefixed hex value @@ -144,7 +135,7 @@ - **Interactive mode**: `bcal` enters the REPL mode if no arguments are provided. Storage unit conversion, base conversion and expression evaluation are supported in this mode. The last valid result is stored in the variable **r**. - **Expression**: Expression passed as argument in one-shot mode must be within double quotes. Inner spaces are ignored. Supported operators: `+`, `-`, `*`, `/`, `%` and C bitwise operators (except `~` due to storage width dependency). -- **N [unit]**: `N` can be a decimal or '0x' prefixed hex value. `unit` can be B/KiB/MiB/GiB/TiB/kB/MB/GB/TB following Ubuntu policy. Default is byte. As all of these tokens are unique, `unit` is case-insensitive. +- **N [unit]**: `N` can be a decimal or '0x' prefixed hex value. `unit` can be B/KiB/MiB/GiB/TiB/kB/MB/GB/TB. Default is Byte. As all of these tokens are unique, `unit` is case-insensitive. - **Numeric representation**: Decimal and hex are recognized in expressions and unit conversions. Binary is also recognized in other operations. - **Syntax**: Prefix hex inputs with `0x`, binary inputs with `0b`. - **Precision**: 128 bits if `__uint128_t` is available or 64 bits for numerical conversions. Floating point operations use `long double`. Negative values in storage expressions are unsupported. Only 64-bit operating systems are supported. @@ -205,10 +196,19 @@ bcal> b // Interactive mode bc vars: scale = 10, ibase = 10, last = r bc> 3.5 * 2.1 + 5.7 -8. Help and additional information. +8. Pipe input. + + $ printf '15 kib + 15 gib \n r / 5' | bcal -m + $ printf '15 + 15 + 2' | bcal -bm +9. Redirect from file. + + $ cat expr + 15 gib + 15 kib + r / 5 + $ bcal -m < expr +10. Use as a general-purpose calculator. - $ man bcal - $ bcal -h + $ bcal -b ### Testing diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/bcal-2.2/bcal.1 new/bcal-2.4/bcal.1 --- old/bcal-2.2/bcal.1 2020-01-07 15:45:52.000000000 +0100 +++ new/bcal-2.4/bcal.1 2022-01-24 16:26:20.000000000 +0100 @@ -1,26 +1,26 @@ -.TH "BCAL" "1" "07 Jan 2020" "Version 2.2" "User Commands" +.TH "BCAL" "1" "24 Jan 2022" "Version 2.4" "User Commands" .SH NAME bcal \- Storage expression calculator. .SH SYNOPSIS .B bcal [-c N] [-f loc] [-s bytes] [expr] [N [unit]] [-b [expr]] [-m] [-d] [-h] .SH DESCRIPTION .B bcal -(Byte CALculator) is a command-line utility to help with numerical calculations and expressions involving data storage units, addressing, base conversion etc. +(Byte CALculator) is a command-line utility to help with numerical calculations and expressions involving binary prefixes, SI/IEC conversion, byte addressing, base conversion, LBA/CHS calculation etc. .PP -It invokes GNU \fBbc\fR for non-storage expressions. Alternatively, it can also invoke \fBcalc\fR (\fIhttp://www.isthe.com/chongo/tech/comp/calc/\fR) which works better with expressions involving multiple bases. To use \fBcalc\fR: +It invokes GNU \fBbc\fR for non-storage expressions. Alternatively, it can also invoke \fBcalc\fR (\fIhttp://www.isthe.com/chongo/tech/comp/calc/\fR). To use \fBcalc\fR: .PP .EX .B export BCAL_USE_CALC=1 .EE .PP -\fBbcal\fR follows Ubuntu's standard unit conversion and notation policy: -.br -.I https://wiki.ubuntu.com/UnitsPolicy +\fBbcal\fR uses [SI and IEC binary prefixes]: +.I https://en.wikipedia.org/wiki/Binary_prefix .PP .SH FEATURES .PP * evaluate arithmetic expressions involving storage units * perform general purpose calculations (using bc or calc) + * works with piped input or file redirection * convert to IEC/SI standard data storage units * interactive mode with the last valid result stored for reuse * show the address in bytes @@ -38,7 +38,7 @@ \fBExpression\fR: Expression passed as argument in one-shot mode must be within double quotes. Inner spaces are ignored. Supported operators: +, -, *, /, % and C bitwise operators (except ~ due to storage width dependency). .PP .IP 3. 4 -\fBN [unit]\fR: \fIN\fR can be a decimal or '0x' prefixed hex value. \fIunit\fR can be B/KiB/MiB/GiB/TiB/kB/MB/GB/TB following Ubuntu policy. Default is byte. As all of these tokens are unique, \fIunit\fR is case-insensitive. +\fBN [unit]\fR: \fIN\fR can be a decimal or '0x' prefixed hex value. \fIunit\fR can be B/KiB/MiB/GiB/TiB/kB/MB/GB/TB. Default is Byte. As all of these tokens are unique, \fIunit\fR is case-insensitive. .PP .IP 4. 4 \fBNumeric representation\fR: Decimal and hex are recognized in expressions and unit conversions. Binary is also recognized in other operations. @@ -184,6 +184,34 @@ .B bc vars: scale = 10, ibase = 10, last = r .B bc> 3.5 * 2.1 + 5.7 .EE +.PP +.IP 8. 4 +Pipe input. +.PP +.EX +.IP +.B $ printf '15 kib + 15 gib \en r / 5' | bcal -m +.B $ printf '15 + 15 + 2' | bcal -bm +.EE +.PP +.IP 9. 4 +Redirect from file. +.PP +.EX +.IP +.B $ cat expr +.B 15 gib + 15 kib +.B r / 5 +.B $ bcal -m < expr +.EE +.PP +.IP 10. 4 +Use as a general-purpose calculator. +.PP +.EX +.IP +.B $ bcal -b +.EE .SH AUTHORS Arun Prakash Jana <engineera...@gmail.com> .SH HOME diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/bcal-2.2/src/bcal.c new/bcal-2.4/src/bcal.c --- old/bcal-2.2/src/bcal.c 2020-01-07 15:45:52.000000000 +0100 +++ new/bcal-2.4/src/bcal.c 2022-01-24 16:26:20.000000000 +0100 @@ -23,6 +23,9 @@ #include <stdio.h> #include <string.h> #include <unistd.h> +#include <sys/types.h> +#include <sys/wait.h> +#include <signal.h> #include <readline/history.h> #include <readline/readline.h> #include "dslib.h" @@ -39,7 +42,7 @@ #define FLOAT_WIDTH 40 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) #define MAX_BITS 128 -#define _ALIGNMENT_MASK 0xF +#define ALIGNMENT_MASK_4BIT 0xF typedef unsigned char bool; typedef unsigned char uchar; @@ -71,7 +74,7 @@ uchar loglvl : 2; } settings; -static char *VERSION = "2.2"; +static char *VERSION = "2.4"; static char *units[] = {"b", "kib", "mib", "gib", "tib", "kb", "mb", "gb", "tb"}; static char *logarr[] = {"ERROR", "WARNING", "INFO", "DEBUG"}; @@ -118,7 +121,7 @@ static ulong *s, *d; static size_t len, blocks; static const uint lsize = sizeof(ulong); - static const uint _WSHIFT = (sizeof(ulong) == 8) ? 3 : 2; + static const uint WORD_SHIFT = (sizeof(ulong) == 8) ? 3 : 2; if (!src || !dest || !n) return 0; @@ -134,10 +137,11 @@ * To enable -O3 ensure src and dest are 16-byte aligned * More info: http://www.felixcloutier.com/x86/MOVDQA.html */ - if ((n >= lsize) && (((ulong)src & _ALIGNMENT_MASK) == 0 && ((ulong)dest & _ALIGNMENT_MASK) == 0)) { + if ((n >= lsize) && (((ulong)src & ALIGNMENT_MASK_4BIT) == 0 + && ((ulong)dest & ALIGNMENT_MASK_4BIT) == 0)) { s = (ulong *)src; d = (ulong *)dest; - blocks = n >> _WSHIFT; + blocks = n >> WORD_SHIFT; n &= lsize - 1; while (blocks) { @@ -165,6 +169,13 @@ return len; } +static bool program_exit(const char *str) +{ + if (!strcmp(str, "exit") || !strcmp(str, "quit")) + return TRUE; + return FALSE; +} + /* * Try to evaluate en expression using bc * If argument is NULL, global curexpr is picked @@ -186,6 +197,9 @@ log(DEBUG, "expression: \"%s\"\n", expr); + if (program_exit(expr)) + exit(0); + if (pipe(pipe_pc) == -1 || pipe(pipe_cp) == -1) { log(ERROR, "pipe()!\n"); exit(EXIT_FAILURE); @@ -208,7 +222,7 @@ dup2(pipe_cp[1], STDOUT_FILENO); // Give stdout to parent dup2(pipe_cp[1], STDERR_FILENO); // Give stderr to parent - ret = execlp(ptr, ptr, (char*) NULL); + int ret = execlp(ptr, ptr, (char*) NULL); log(ERROR, "execlp() failed!\n"); exit(ret); } @@ -263,6 +277,17 @@ exit(-1); } + if (write(pipe_pc[1], "quit\n", 5) != 5) { + log(ERROR, "write(7)! [%s]\n", strerror(errno)); + exit(-1); + } + + if (cfg.calc) + kill(pid, SIGTERM); + + close(pipe_cp[0]); + close(pipe_pc[1]); + buffer[ret] = '\0'; if (buffer[0] != '(') { @@ -271,6 +296,9 @@ ++ptr; printf("%s", ptr); + if (cfg.calc && strstr(ptr, "is undefined")) + return -1; + len = bstrlcpy(lastres.p, ptr, NUM_LEN); /* remove newline appended at the end of result by bc */ @@ -302,22 +330,28 @@ static void binprint(maxuint_t n) { int count = MAX_BITS - 1; - char binstr[MAX_BITS + 1] = {0}; + int pos = MAX_BITS + (MAX_BITS >> 2) - 1; + char binstr[MAX_BITS + (MAX_BITS >> 2) + 1] = {0}; if (!n) { - printf("0b0"); + printf("0"); return; } while (n && count >= 0) { - binstr[count] = "01"[n & 1]; - --count; + binstr[pos] = "01"[n & 1]; + --pos; n >>= 1; + if (n && count && !(count & 7)) { + binstr[pos] = ' '; + --pos; + } + --count; } - ++count; + ++pos; - printf("0b%s", binstr + count); + printf("%s", binstr + pos); } static char *getstr_u128(maxuint_t n, char *buf) @@ -352,7 +386,7 @@ static void printval(maxfloat_t val, char *unit) { - if (val - (maxuint_t)val == 0) + if (val - (maxuint_t)val == 0) // NOLINT printf("%40s %s\n", getstr_u128((maxuint_t)val, uint_buf), unit); else printf("%s %s\n", getstr_f128(val, float_buf), unit); @@ -540,31 +574,31 @@ /* Convert and print in IEC standard units */ printf("\n IEC standard (base 2)\n\n"); - val = bytes / (maxfloat_t)1024; + val = (maxfloat_t)bytes / 1024; printval(val, "KiB"); - val = bytes / (maxfloat_t)(1 << 20); + val = (maxfloat_t)bytes / (1 << 20); printval(val, "MiB"); - val = bytes / (maxfloat_t)(1 << 30); + val = (maxfloat_t)bytes / (1 << 30); printval(val, "GiB"); - val = bytes / (maxfloat_t)((maxuint_t)1 << 40); + val = (maxfloat_t)bytes / ((unsigned long long)1 << 40); printval(val, "TiB"); /* Convert and print in SI standard values */ printf("\n SI standard (base 10)\n\n"); - val = bytes / (maxfloat_t)1000; + val = (maxfloat_t)bytes / 1000; printval(val, "kB"); - val = bytes / (maxfloat_t)1000000; + val = (maxfloat_t)bytes / 1000000; printval(val, "MB"); - val = bytes / (maxfloat_t)1000000000; + val = (maxfloat_t)bytes / 1000000000; printval(val, "GB"); - val = bytes / (maxfloat_t)1000000000000; + val = (maxfloat_t)bytes / 1000000000000; printval(val, "TB"); return bytes; @@ -1021,9 +1055,8 @@ return FALSE; } - - *lba = param[3] * param[4] * param[0]; /* MH * MS * C */ - *lba += param[4] * param[1]; /* MS * H */ + *lba = (maxuint_t)param[3] * param[4] * param[0]; /* MH * MS * C */ + *lba += (maxuint_t)param[4] * param[1]; /* MS * H */ *lba += param[2] - 1; /* S - 1 */ @@ -1152,7 +1185,7 @@ positional arguments:\n\ expr expression in decimal/hex operands\n\ N [unit] capacity in B/KiB/MiB/GiB/TiB/kB/MB/GB/TB\n\ - see https://wiki.ubuntu.com/UnitsPolicy\n\ + https://en.wikipedia.org/wiki/Binary_prefix\n\ default unit is B (byte), case is ignored\n\ N can be decimal or '0x' prefixed hex value\n\n\ optional arguments:\n\ @@ -2111,6 +2144,14 @@ printf("q/double Enter -> quit, ? -> help\n"); while ((tmp = readline(prompt)) != NULL) { + if (!tmp) + exit(0); + + if (program_exit(tmp)) { + free(tmp); + exit(0); + } + /* Quit on double Enter */ if (tmp[0] == '\0') { if (enters == 1) { diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/bcal-2.2/test.py new/bcal-2.4/test.py --- old/bcal-2.2/test.py 2020-01-07 15:45:52.000000000 +0100 +++ new/bcal-2.4/test.py 2022-01-24 16:26:20.000000000 +0100 @@ -149,11 +149,11 @@ b'ERROR: invalid input\n\n', # 49 b'ERROR: invalid input\n\n', # 50 - b' (b) 0b0\n (d) 0\n (h) 0x0\n\n', # 51 - b' (b) 0b11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n (d) 340282366920938463463374607431768211455\n (h) 0xffffffffffffffffffffffffffffffff\n\n', # 52 - b' (b) 0b11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n (d) 340282366920938463463374607431768211455\n (h) 0xffffffffffffffffffffffffffffffff\n\n', # 53 - b' (b) 0b11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n (d) 340282366920938463463374607431768211455\n (h) 0xffffffffffffffffffffffffffffffff\n\n', # 54 - b' (b) 0b1111111111111111111111111111111111111111111111111111111111111111\n (d) 18446744073709551615\n (h) 0xffffffffffffffff\n\n', # 55 + b' (b) 0\n (d) 0\n (h) 0x0\n\n', # 51 + b' (b) 11111111 11111111 11111111 11111111 11111111 11111111 11111111 11111111 11111111 11111111 11111111 11111111 11111111 11111111 11111111 11111111\n (d) 340282366920938463463374607431768211455\n (h) 0xffffffffffffffffffffffffffffffff\n\n', # 52 + b' (b) 11111111 11111111 11111111 11111111 11111111 11111111 11111111 11111111 11111111 11111111 11111111 11111111 11111111 11111111 11111111 11111111\n (d) 340282366920938463463374607431768211455\n (h) 0xffffffffffffffffffffffffffffffff\n\n', # 53 + b' (b) 11111111 11111111 11111111 11111111 11111111 11111111 11111111 11111111 11111111 11111111 11111111 11111111 11111111 11111111 11111111 11111111\n (d) 340282366920938463463374607431768211455\n (h) 0xffffffffffffffffffffffffffffffff\n\n', # 54 + b' (b) 11111111 11111111 11111111 11111111 11111111 11111111 11111111 11111111\n (d) 18446744073709551615\n (h) 0xffffffffffffffff\n\n', # 55 b'ERROR: invalid input\n\n', # 56 b'WARNING: result truncated\n0\n', # 57 b'0\n', # 58