Codebase list bcal / 2a97923
New upstream version 2.3 SZ Lin (林上智) 2 years ago
11 changed file(s) with 333 addition(s) and 75 deletion(s). Raw diff Collapse all Expand all
0 version: 2
1
2 jobs:
3 compile:
4 docker:
5 - image: ubuntu:20.04
6 working_directory: ~/bcal
7 environment:
8 CI_FORCE_TEST: 1
9 steps:
10 - run:
11 command: |
12 apt update -qq
13 DEBIAN_FRONTEND="noninteractive" TZ="America/New_York" apt-get -y install tzdata
14 apt install -y --no-install-recommends git make libreadline-dev
15 apt install -y --no-install-recommends gcc-7 gcc-8 gcc-9 gcc-10
16 apt install -y --no-install-recommends clang-6.0 clang-7 clang-8 clang-9 clang-10 clang-11 clang-tidy-11
17 - checkout
18 - run:
19 command: |
20 export CFLAGS=-Werror
21 make clean
22 echo
23 echo "########## gcc-7 ##########"
24 CC=gcc-7 make strip
25 ls -l bcal
26 make clean
27 echo
28 echo "########## gcc-8 ##########"
29 CC=gcc-8 make strip
30 ls -l bcal
31 make clean
32 echo
33 echo "########## gcc-9 ##########"
34 CC=gcc-9 make strip
35 ls -l bcal
36 make clean
37 echo
38 echo "########## gcc-10 ##########"
39 CC=gcc-10 make strip
40 ls -l bcal
41 make clean
42 echo
43 echo "########## clang-6 ##########"
44 CC=clang-6.0 make strip
45 ls -l bcal
46 make clean
47 echo
48 echo "########## clang-7 ##########"
49 CC=clang-7 make strip
50 ls -l bcal
51 make clean
52 echo
53 echo "########## clang-8 ##########"
54 CC=clang-8 make strip
55 ls -l bcal
56 make clean
57 echo
58 echo "########## clang-9 ##########"
59 CC=clang-9 make strip
60 ls -l bcal
61 make clean
62 echo
63 echo "########## clang-10 ##########"
64 CC=clang-10 make strip
65 ls -l bcal
66 make clean
67 echo
68 echo "########## clang-11 ##########"
69 CC=clang-11 make strip
70 ls -l bcal
71 make clean
72 echo
73 echo "########## clang-tidy-11 ##########"
74 clang-tidy-11 **/*.h **/*.c -- -Iinc
75
76 package-and-publish:
77 machine: true
78 working_directory: ~/bcal
79 steps:
80 - checkout
81 - run:
82 name: "auto-generate packages"
83 command: |
84 # Create dist directory if it doesn't exist
85 mkdir ./dist
86 # Clean up
87 rm -rf ./dist/*
88 # Pack source
89 git archive -o ../${CIRCLE_PROJECT_REPONAME}-${CIRCLE_TAG}.tar.gz --format tar.gz --prefix=${CIRCLE_PROJECT_REPONAME}-${CIRCLE_TAG#v}/ ${CIRCLE_TAG}
90 # Use latest installed python3 from pyenv
91 export PYENV_VERSION="$(pyenv versions | grep -Po '\b3\.\d+\.\d+' | tail -1)"
92 #pip install packagecore
93 #packagecore -c misc/packagecore/packagecore.yaml -o ./dist/ ${CIRCLE_TAG#v}
94 # Move source pack to dist
95 mv ../${CIRCLE_PROJECT_REPONAME}-${CIRCLE_TAG}.tar.gz ./dist/
96
97 - run:
98 name: "publish to GitHub"
99 command: |
100 go get github.com/tcnksm/ghr
101 ghr -t ${GITHUB_API_TOKEN} -u ${CIRCLE_PROJECT_USERNAME} -r ${CIRCLE_PROJECT_REPONAME} -c ${CIRCLE_SHA1} -replace ${CIRCLE_TAG} ./dist/
102
103 workflows:
104 version: 2
105
106 test:
107 jobs: &all-tests
108 - compile
109
110 nightly:
111 triggers:
112 - schedule:
113 cron: "0 0 * * 6"
114 filters:
115 branches:
116 only:
117 - master
118 jobs: *all-tests
119
120 publish-github-release:
121 jobs:
122 - package-and-publish:
123 filters:
124 tags:
125 only: /^v.*/
126 branches:
127 ignore: /.*/
00 ---
1 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'
1 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'
22 WarningsAsErrors: '*'
33 HeaderFilterRegex: '.*(?<!lookup3.c)$'
44 FormatStyle: 'file'
0 custom: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=RMLTQ76JSXJ4Q
0 github: jarun
0 name: ci
1
2 on:
3 push:
4 branches: [master]
5 pull_request:
6 branches: [master]
7
8 jobs:
9 macOS-gcc:
10 runs-on: macOS-latest
11 steps:
12 - uses: actions/checkout@v2
13 - name: Compile with gcc
14 env:
15 CC: gcc
16 run: |
17 brew upgrade python
18 pip3 install logilab-common
19 pip3 install pytest
20 make clean
21 make
22 pytest ./test.py
23 make clean
24 macOS-clang:
25 runs-on: macOS-latest
26 steps:
27 - uses: actions/checkout@v2
28 - name: Compile with clang
29 env:
30 CC: clang
31 run: |
32 brew update
33 brew upgrade python
34 pip3 install logilab-common
35 pip3 install pytest
36 brew install llvm
37 export PATH="/usr/local/opt/llvm/bin:$PATH"
38 make clean
39 make
40 pytest ./test.py
41 make clean
42 clang-tidy **/*.h **/*.c -- -Iinc
0 name: 'Lock threads'
1
2 on:
3 schedule:
4 - cron: '0 0 * * *'
5
6 jobs:
7 lock:
8 runs-on: ubuntu-latest
9 steps:
10 - uses: dessant/lock-threads@v2
11 with:
12 github-token: ${{ github.token }}
13 issue-lock-inactive-days: '30'
14 issue-lock-reason: ''
15 pr-lock-inactive-days: '30'
16 pr-lock-reason: ''
00 language: c
1 arch :
2 - amd64
3 - ppc64le
14 sudo: required
25 services:
36 - docker
811 matrix:
912 include:
1013 - os: linux
11 dist: trusty
14 dist: focal
1215 compiler: gcc
1316 - os: linux
14 dist: trusty
17 dist: focal
1518 compiler: clang
1619 # - os: linux
1720 # compiler: musl-gcc
2124 # - musl
2225 # - musl-dev
2326 # - musl-tools
24 - os: osx
25 compiler: gcc
26 - os: osx
27 compiler: clang
27 # - os: osx
28 # compiler: gcc
29 # - os: osx
30 # compiler: clang
2831
2932 install:
3033 - if [ $TRAVIS_OS_NAME = linux ]; then
5154 - rm -rf $REPO/.git
5255 - tar -czf $REPO-${TRAVIS_TAG}.tar.gz $REPO
5356 - cd $REPO
54 - sudo apt-get update -qy
55 - sudo apt-get install -qy python3 python3-pip
56 - sudo python3 -m pip install --upgrade pip
57 - sudo python3 -m pip install --upgrade packagecore setuptools
58 - packagecore -o dist/ "${TRAVIS_TAG#v}"
5957 - mv ../$REPO-${TRAVIS_TAG}.tar.gz dist/
6058
6159 deploy:
0 bcal v2.3
1 2021-10-09
2
3 - show binary conversion output in octets for readabilityA
4 - handle `^D`
5 - quit program or 'exit' or 'quit'
6 - fix broken terminal with calc as backend on "undefined input" (#36)
7
8 -------------------------------------------------------------------------------
9
010 bcal v2.2
111 2020-01-07
212
22 <p align="center">
33 <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>
44 <a href="https://repology.org/project/bcal/versions"><img src="https://repology.org/badge/tiny-repos/bcal.svg" alt="Availability"></a>
5 <a href="https://travis-ci.org/jarun/bcal"><img src="https://img.shields.io/travis/jarun/bcal/master.svg" alt="Build Status" /></a>
5 <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>
6 <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>
67 <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>
7 <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>
8 <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>
89 </p>
910
1011 <p align="center">
11 <a href="https://asciinema.org/a/168719"><img src="https://asciinema.org/a/168719.png" alt="bcal_asciicast" width="600"/></a>
12 <a href="https://asciinema.org/a/168719"><img src="https://asciinema.org/a/168719.svg" alt="bcal_asciicast" width="600"/></a>
1213 </p>
1314
14 `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.
15
16 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.
17
18 `bcal` follows Ubuntu's standard unit conversion and notation [policy](https://wiki.ubuntu.com/UnitsPolicy). Only 64-bit operating systems are supported.
19
20 *Love smart and efficient utilities? Explore [my repositories](https://github.com/jarun?tab=repositories). Buy me a cup of coffee if they help you.*
21
22 <p align="center">
23 <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>
24 </p>
15 `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.
16
17 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.
18
19 `bcal` uses [SI and IEC binary prefixes](https://en.wikipedia.org/wiki/Binary_prefix) and supports 64-bit Operating Systems only.
2520
2621 ### Table of Contents
2722
4439 - REPL and single execution modes
4540 - evaluate arithmetic expressions involving storage units
4641 - perform general purpose calculations (using bc or calc)
42 - works with piped input or file redirection
4743 - convert to IEC/SI standard data storage units
4844 - interactive mode with the last valid result stored for reuse
4945 - show the address in bytes
9793 `bcal` can be compiled and installed from source in the Termux environment on `aarch64` Android devices. Instructions:
9894
9995 ```
100 $ aria2c https://github.com/jarun/bcal/archive/master.zip
96 $ wget https://github.com/jarun/bcal/archive/master.zip
10197 $ unzip bcal-master.zip
10298 $ cd bcal-master/
10399 $ pkg install make clang readline-dev
117113 positional arguments:
118114 expr expression in decimal/hex operands
119115 N [unit] capacity in B/KiB/MiB/GiB/TiB/kB/MB/GB/TB
120 see https://wiki.ubuntu.com/UnitsPolicy
116 https://en.wikipedia.org/wiki/Binary_prefix
121117 default unit is B (byte), case is ignored
122118 N can be decimal or '0x' prefixed hex value
123119
143139
144140 - **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**.
145141 - **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).
146 - **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.
142 - **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.
147143 - **Numeric representation**: Decimal and hex are recognized in expressions and unit conversions. Binary is also recognized in other operations.
148144 - **Syntax**: Prefix hex inputs with `0x`, binary inputs with `0b`.
149145 - **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.
204200 bcal> b // Interactive mode
205201 bc vars: scale = 10, ibase = 10, last = r
206202 bc> 3.5 * 2.1 + 5.7
207 8. Help and additional information.
208
209 $ man bcal
210 $ bcal -h
203 8. Pipe input.
204
205 $ printf '15 kib + 15 gib \n r / 5' | bcal -m
206 $ printf '15 + 15 + 2' | bcal -bm
207 9. Redirect from file.
208
209 $ cat expr
210 15 gib + 15 kib
211 r / 5
212 $ bcal -m < expr
213 10. Use as a general-purpose calculator.
214
215 $ bcal -b
211216
212217 ### Testing
213218
0 .TH "BCAL" "1" "07 Jan 2020" "Version 2.2" "User Commands"
0 .TH "BCAL" "1" "15 Oct 2021" "Version 2.3" "User Commands"
11 .SH NAME
22 bcal \- Storage expression calculator.
33 .SH SYNOPSIS
44 .B bcal [-c N] [-f loc] [-s bytes] [expr] [N [unit]] [-b [expr]] [-m] [-d] [-h]
55 .SH DESCRIPTION
66 .B bcal
7 (Byte CALculator) is a command-line utility to help with numerical calculations and expressions involving data storage units, addressing, base conversion etc.
8 .PP
9 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:
7 (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.
8 .PP
9 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:
1010 .PP
1111 .EX
1212 .B export BCAL_USE_CALC=1
1313 .EE
1414 .PP
15 \fBbcal\fR follows Ubuntu's standard unit conversion and notation policy:
16 .br
17 .I https://wiki.ubuntu.com/UnitsPolicy
15 \fBbcal\fR uses [SI and IEC binary prefixes]:
16 .I https://en.wikipedia.org/wiki/Binary_prefix
1817 .PP
1918 .SH FEATURES
2019 .PP
2120 * evaluate arithmetic expressions involving storage units
2221 * perform general purpose calculations (using bc or calc)
22 * works with piped input or file redirection
2323 * convert to IEC/SI standard data storage units
2424 * interactive mode with the last valid result stored for reuse
2525 * show the address in bytes
3737 \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).
3838 .PP
3939 .IP 3. 4
40 \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.
40 \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.
4141 .PP
4242 .IP 4. 4
4343 \fBNumeric representation\fR: Decimal and hex are recognized in expressions and unit conversions. Binary is also recognized in other operations.
183183 .B bc vars: scale = 10, ibase = 10, last = r
184184 .B bc> 3.5 * 2.1 + 5.7
185185 .EE
186 .PP
187 .IP 8. 4
188 Pipe input.
189 .PP
190 .EX
191 .IP
192 .B $ printf '15 kib + 15 gib \en r / 5' | bcal -m
193 .B $ printf '15 + 15 + 2' | bcal -bm
194 .EE
195 .PP
196 .IP 9. 4
197 Redirect from file.
198 .PP
199 .EX
200 .IP
201 .B $ cat expr
202 .B 15 gib + 15 kib
203 .B r / 5
204 .B $ bcal -m < expr
205 .EE
206 .PP
207 .IP 10. 4
208 Use as a general-purpose calculator.
209 .PP
210 .EX
211 .IP
212 .B $ bcal -b
213 .EE
186214 .SH AUTHORS
187215 Arun Prakash Jana <engineerarun@gmail.com>
188216 .SH HOME
2222 #include <stdio.h>
2323 #include <string.h>
2424 #include <unistd.h>
25 #include <sys/types.h>
26 #include <sys/wait.h>
27 #include <signal.h>
2528 #include <readline/history.h>
2629 #include <readline/readline.h>
2730 #include "dslib.h"
3841 #define FLOAT_WIDTH 40
3942 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
4043 #define MAX_BITS 128
41 #define _ALIGNMENT_MASK 0xF
44 #define ALIGNMENT_MASK_4BIT 0xF
4245
4346 typedef unsigned char bool;
4447 typedef unsigned char uchar;
7073 uchar loglvl : 2;
7174 } settings;
7275
73 static char *VERSION = "2.2";
76 static char *VERSION = "2.3";
7477 static char *units[] = {"b", "kib", "mib", "gib", "tib", "kb", "mb", "gb", "tb"};
7578 static char *logarr[] = {"ERROR", "WARNING", "INFO", "DEBUG"};
7679
117120 static ulong *s, *d;
118121 static size_t len, blocks;
119122 static const uint lsize = sizeof(ulong);
120 static const uint _WSHIFT = (sizeof(ulong) == 8) ? 3 : 2;
123 static const uint WORD_SHIFT = (sizeof(ulong) == 8) ? 3 : 2;
121124
122125 if (!src || !dest || !n)
123126 return 0;
133136 * To enable -O3 ensure src and dest are 16-byte aligned
134137 * More info: http://www.felixcloutier.com/x86/MOVDQA.html
135138 */
136 if ((n >= lsize) && (((ulong)src & _ALIGNMENT_MASK) == 0 && ((ulong)dest & _ALIGNMENT_MASK) == 0)) {
139 if ((n >= lsize) && (((ulong)src & ALIGNMENT_MASK_4BIT) == 0
140 && ((ulong)dest & ALIGNMENT_MASK_4BIT) == 0)) {
137141 s = (ulong *)src;
138142 d = (ulong *)dest;
139 blocks = n >> _WSHIFT;
143 blocks = n >> WORD_SHIFT;
140144 n &= lsize - 1;
141145
142146 while (blocks) {
185189
186190 log(DEBUG, "expression: \"%s\"\n", expr);
187191
192 if (!strcmp(expr, "quit") || !strcmp(expr, "exit"))
193 exit(0);
194
188195 if (pipe(pipe_pc) == -1 || pipe(pipe_cp) == -1) {
189196 log(ERROR, "pipe()!\n");
190197 exit(EXIT_FAILURE);
207214 dup2(pipe_cp[1], STDOUT_FILENO); // Give stdout to parent
208215 dup2(pipe_cp[1], STDERR_FILENO); // Give stderr to parent
209216
210 ret = execlp(ptr, ptr, (char*) NULL);
217 int ret = execlp(ptr, ptr, (char*) NULL);
211218 log(ERROR, "execlp() failed!\n");
212219 exit(ret);
213220 }
262269 exit(-1);
263270 }
264271
272 if (write(pipe_pc[1], "quit\n", 5) != 5) {
273 log(ERROR, "write(7)! [%s]\n", strerror(errno));
274 exit(-1);
275 }
276
277 if (cfg.calc)
278 kill(pid, SIGTERM);
279
280 close(pipe_cp[0]);
281 close(pipe_pc[1]);
282
265283 buffer[ret] = '\0';
266284
267285 if (buffer[0] != '(') {
270288 ++ptr;
271289
272290 printf("%s", ptr);
291 if (cfg.calc && strstr(ptr, "is undefined"))
292 return -1;
293
273294 len = bstrlcpy(lastres.p, ptr, NUM_LEN);
274295
275296 /* remove newline appended at the end of result by bc */
301322 static void binprint(maxuint_t n)
302323 {
303324 int count = MAX_BITS - 1;
304 char binstr[MAX_BITS + 1] = {0};
325 int pos = MAX_BITS + (MAX_BITS >> 2) - 1;
326 char binstr[MAX_BITS + (MAX_BITS >> 2) + 1] = {0};
305327
306328 if (!n) {
307 printf("0b0");
329 printf("0");
308330 return;
309331 }
310332
311333 while (n && count >= 0) {
312 binstr[count] = "01"[n & 1];
334 binstr[pos] = "01"[n & 1];
335 --pos;
336 n >>= 1;
337 if (n && count && !(count & 7)) {
338 binstr[pos] = ' ';
339 --pos;
340 }
313341 --count;
314 n >>= 1;
315 }
316
317 ++count;
318
319 printf("0b%s", binstr + count);
342 }
343
344 ++pos;
345
346 printf("%s", binstr + pos);
320347 }
321348
322349 static char *getstr_u128(maxuint_t n, char *buf)
351378
352379 static void printval(maxfloat_t val, char *unit)
353380 {
354 if (val - (maxuint_t)val == 0)
381 if (val - (maxuint_t)val == 0) // NOLINT
355382 printf("%40s %s\n", getstr_u128((maxuint_t)val, uint_buf), unit);
356383 else
357384 printf("%s %s\n", getstr_f128(val, float_buf), unit);
539566 /* Convert and print in IEC standard units */
540567
541568 printf("\n IEC standard (base 2)\n\n");
542 val = bytes / (maxfloat_t)1024;
569 val = (maxfloat_t)bytes / 1024;
543570 printval(val, "KiB");
544571
545 val = bytes / (maxfloat_t)(1 << 20);
572 val = (maxfloat_t)bytes / (1 << 20);
546573 printval(val, "MiB");
547574
548 val = bytes / (maxfloat_t)(1 << 30);
575 val = (maxfloat_t)bytes / (1 << 30);
549576 printval(val, "GiB");
550577
551 val = bytes / (maxfloat_t)((maxuint_t)1 << 40);
578 val = (maxfloat_t)bytes / ((unsigned long long)1 << 40);
552579 printval(val, "TiB");
553580
554581 /* Convert and print in SI standard values */
555582
556583 printf("\n SI standard (base 10)\n\n");
557 val = bytes / (maxfloat_t)1000;
584 val = (maxfloat_t)bytes / 1000;
558585 printval(val, "kB");
559586
560 val = bytes / (maxfloat_t)1000000;
587 val = (maxfloat_t)bytes / 1000000;
561588 printval(val, "MB");
562589
563 val = bytes / (maxfloat_t)1000000000;
590 val = (maxfloat_t)bytes / 1000000000;
564591 printval(val, "GB");
565592
566 val = bytes / (maxfloat_t)1000000000000;
593 val = (maxfloat_t)bytes / 1000000000000;
567594 printval(val, "TB");
568595
569596 return bytes;
10201047 return FALSE;
10211048 }
10221049
1023
1024 *lba = param[3] * param[4] * param[0]; /* MH * MS * C */
1025 *lba += param[4] * param[1]; /* MS * H */
1050 *lba = (maxuint_t)param[3] * param[4] * param[0]; /* MH * MS * C */
1051 *lba += (maxuint_t)param[4] * param[1]; /* MS * H */
10261052
10271053 *lba += param[2] - 1; /* S - 1 */
10281054
11511177 positional arguments:\n\
11521178 expr expression in decimal/hex operands\n\
11531179 N [unit] capacity in B/KiB/MiB/GiB/TiB/kB/MB/GB/TB\n\
1154 see https://wiki.ubuntu.com/UnitsPolicy\n\
1180 https://en.wikipedia.org/wiki/Binary_prefix\n\
11551181 default unit is B (byte), case is ignored\n\
11561182 N can be decimal or '0x' prefixed hex value\n\n\
11571183 optional arguments:\n\
21102136
21112137 printf("q/double Enter -> quit, ? -> help\n");
21122138 while ((tmp = readline(prompt)) != NULL) {
2139 if (!tmp)
2140 exit(0);
2141
21132142 /* Quit on double Enter */
21142143 if (tmp[0] == '\0') {
21152144 if (enters == 1) {
148148
149149 b'ERROR: invalid input\n\n', # 49
150150 b'ERROR: invalid input\n\n', # 50
151 b' (b) 0b0\n (d) 0\n (h) 0x0\n\n', # 51
152 b' (b) 0b11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n (d) 340282366920938463463374607431768211455\n (h) 0xffffffffffffffffffffffffffffffff\n\n', # 52
153 b' (b) 0b11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n (d) 340282366920938463463374607431768211455\n (h) 0xffffffffffffffffffffffffffffffff\n\n', # 53
154 b' (b) 0b11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n (d) 340282366920938463463374607431768211455\n (h) 0xffffffffffffffffffffffffffffffff\n\n', # 54
155 b' (b) 0b1111111111111111111111111111111111111111111111111111111111111111\n (d) 18446744073709551615\n (h) 0xffffffffffffffff\n\n', # 55
151 b' (b) 0\n (d) 0\n (h) 0x0\n\n', # 51
152 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
153 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
154 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
155 b' (b) 11111111 11111111 11111111 11111111 11111111 11111111 11111111 11111111\n (d) 18446744073709551615\n (h) 0xffffffffffffffff\n\n', # 55
156156 b'ERROR: invalid input\n\n', # 56
157157 b'WARNING: result truncated\n0\n', # 57
158158 b'0\n', # 58