All Projects ā†’ jarun ā†’ Bcal

jarun / Bcal

Licence: gpl-3.0
šŸ”¢ Storage and general-purpose calculator

Programming Languages

c
50402 projects - #5 most used programming language

Projects that are alternatives of or similar to Bcal

Pdd
šŸ“… Tiny date, time diff calculator with piggybacked timers
Stars: āœ­ 218 (-33.74%)
Mutual labels:  terminal, command-line, console, calculator
Imgp
šŸ“ø High-performance cli batch image resizer and rotator
Stars: āœ­ 744 (+126.14%)
Mutual labels:  standalone, terminal, command-line, console
Buku
šŸ”– Personal mini-web in text
Stars: āœ­ 4,825 (+1366.57%)
Mutual labels:  standalone, terminal, command-line, console
Ddgr
šŸ¦† DuckDuckGo from the terminal
Stars: āœ­ 2,243 (+581.76%)
Mutual labels:  standalone, terminal, command-line, console
Googler
šŸ” Google from the terminal
Stars: āœ­ 5,594 (+1600.3%)
Mutual labels:  standalone, terminal, command-line, console
Laravel Zero
A PHP framework for console artisans
Stars: āœ­ 2,821 (+757.45%)
Mutual labels:  standalone, terminal, command-line, console
Word Wrap
Wrap words to a specified length.
Stars: āœ­ 107 (-67.48%)
Mutual labels:  terminal, command-line, console
Nnn
nĀ³ The unorthodox terminal file manager
Stars: āœ­ 13,138 (+3893.31%)
Mutual labels:  terminal, command-line, console
Mandown
man-page inspired Markdown viewer
Stars: āœ­ 173 (-47.42%)
Mutual labels:  terminal, command-line, console
Ascii
šŸ‘¾ ASCII Roulette :: ascii art video chat on the cli
Stars: āœ­ 202 (-38.6%)
Mutual labels:  terminal, command-line, console
Crossline
A small, self-contained, zero-config, MIT licensed, cross-platform, readline and libedit replacement.
Stars: āœ­ 53 (-83.89%)
Mutual labels:  terminal, command-line, console
Cointop
A fast and lightweight interactive terminal based UI application for tracking cryptocurrencies šŸš€
Stars: āœ­ 2,912 (+785.11%)
Mutual labels:  terminal, command-line, console
Jquery.terminal
jQuery Terminal Emulator - JavaScript library for creating web-based terminals with custom commands
Stars: āœ­ 2,623 (+697.26%)
Mutual labels:  terminal, command-line, console
Tooling
Advancing Node.js as a framework for writing great tools
Stars: āœ­ 98 (-70.21%)
Mutual labels:  terminal, command-line, console
Window Size
Reliable way to to get the height and width of the terminal/console in a node.js environment.
Stars: āœ­ 79 (-75.99%)
Mutual labels:  terminal, command-line, console
Smenu
smenu started as a lightweight and flexible terminal menu generator, but quickly evolved into a powerful and versatile CLI selection tool for interactive or scripting use.
Stars: āœ­ 1,906 (+479.33%)
Mutual labels:  terminal, command-line, console
Rang
A Minimal, Header only Modern c++ library for terminal goodies šŸ’„āœØ
Stars: āœ­ 1,080 (+228.27%)
Mutual labels:  terminal, command-line, console
Tldr
šŸ“š Collaborative cheatsheets for console commands
Stars: āœ­ 36,408 (+10966.26%)
Mutual labels:  terminal, command-line, console
Wonders
šŸŒˆ Declarative JavaScript framework to build command-line applications.
Stars: āœ­ 34 (-89.67%)
Mutual labels:  terminal, command-line, console
Mitype
Typing speed test in terminal
Stars: āœ­ 241 (-26.75%)
Mutual labels:  terminal, command-line, console

bcal

Latest release Availability Travis CI Status GitHub CI Status Coverity Scan Build Status License

bcal_asciicast

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 43rd bit of a 64-bit address is set mentally, bcal is for you.

It has a bc mode for general-purpose numerical calculations. Alternatively, it can also invoke calc which works better with expressions involving multiple bases.

bcal follows Ubuntu's standard unit conversion and notation policy. Only 64-bit operating systems are supported.

Love smart and efficient utilities? Explore my repositories. Buy me a cup of coffee if they help you.

Donate via PayPal!

Table of Contents

Features

  • 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
  • show address as LBA:OFFSET
  • convert CHS to LBA and vice versa
  • base conversion to binary, decimal and hex
  • custom sector size, max heads/cylinder and max sectors/track
  • minimal dependencies

Installation

Dependencies

bcal is written in C and depends on standard libc and libreadline. It invokes GNU bc or calc for non-storage expressions.

To use calc:

export BCAL_USE_CALC=1

From a package manager

Install bcal from your package manager. If the version available is dated try an alternative installation method.

Packaging status (expand)


Packaging status

Release packages

Packages for Arch Linux, CentOS, Debian, Fedora, OpenSUSE Leap and Ubuntu are available with the latest stable release.

From source

If you have git installed, clone this repository. Otherwise, download the latest stable release or development version (risky).

Install to default location (/usr/local):

$ make
$ sudo make strip install

To uninstall, run:

$ sudo make uninstall

PREFIX is supported, in case you want to install to a different location.

Termux

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
$ unzip bcal-master.zip
$ cd bcal-master/
$ pkg install make clang readline-dev
$ make strip install

Usage

cmdline options

usage: bcal [-c N] [-f loc] [-s bytes] [expr]
            [N [unit]] [-b [expr]] [-m] [-d] [-h]

Storage expression calculator.

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
            default unit is B (byte), case is ignored
            N can be decimal or '0x' prefixed hex value

optional arguments:
 -c N       show +ve integer N in binary, decimal, hex
 -f loc     convert CHS to LBA or LBA to CHS
            refer to the operational notes in man page
 -s bytes   sector size [default 512]
 -b [expr]  enter bc mode or evaluate expression in bc
 -m         show minimal output (e.g. decimal bytes)
 -d         enable debug information and logs
 -h         show this help

prompt keys:
 b          toggle bc mode
 r          show result from last operation
 s          show sizes of storage types
 ?          show prompt help
 q/double ā†µ quit program

Operational notes

  • 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.
  • 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.
  • Fractional bytes do not exist because they can't be addressed. bcal shows the floor value of non-integer bytes.
  • CHS and LBA syntax:
    • LBA: lLBA-MAX_HEAD-MAX_SECTOR [NOTE: LBA starts with l (case ignored)]
    • CHS: cC-H-S-MAX_HEAD-MAX_SECTOR [NOTE: CHS starts with c (case ignored)]
    • Format conversion arguments must be hyphen separated.
    • Any unspecified value, including the one preceding the first - to the one following the last -, is considered 0 (zero).
    • Examples:
      • c-50--0x12- -> C = 0, H = 50, S = 0, MH = 0x12, MS = 0
      • l50-0x12 -> LBA = 50, MH = 0x12, MS = 0
  • Default values:
    • sector size: 0x200 (512)
    • max heads per cylinder: 0x10 (16)
    • max sectors per track: 0x3f (63)
  • bc variables: scale = 10, ibase = 10. r is synced and can be used in expressions. bc is not called in minimal output mode.

Examples

  1. Evaluate arithmetic expression of storage units.

    $ bcal "(5kb+2mb)/3"
    $ bcal "5 tb / 12"
    $ bcal "2.5mb*3"
    $ bcal "(2giB * 2) / (2kib >> 2)"
    
  2. Convert storage capacity to other units and get address, LBA.

    $ bcal 20140115 b
    $ bcal 0x1335053 B
    $ bcal 0xaabbcc kb
    $ bcal 0xdef Gib
    

    Note that the units are case-insensitive.

  3. Convert storage capacity, set sector size to 4096 to calculate LBA.

    $ bcal 0xaabbcc kb -s 4096
    
  4. Convert LBA to CHS.

    $ bcal -f l500
    $ bcal -f l0x600-18-0x7e
    $ bcal -f l0x300-0x12-0x7e
    
  5. Convert CHS to LBA.

    $ bcal -f c10-10-10
    $ bcal -f c0x10-0x10-0x10
    $ bcal -f c0x10-10-2-0x12
    $ bcal -f c-10-2-0x12
    $ bcal -f c0x10-10--0x12
    
  6. Show binary, decimal and hex representations of a number.

    $ bcal -c 20140115
    $ bcal -c 0b1001100110101000001010011
    $ bcal -c 0x1335053
    bcal> c 20140115  // Interactive mode
    
  7. Invoke bc.

    $ bcal -b '3.5 * 2.1 + 5.7'
    bcal> b  // Interactive mode
    bc vars: scale = 10, ibase = 10, last = r
    bc> 3.5 * 2.1 + 5.7
    
  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. Help and additional information.

    $ man bcal
    $ bcal -h
    

Testing

Due to the nature of the project, it's extremely important to test existing functionality before raising any PR. bcal has several test cases written in test.py. To execute the test cases locally, install pytest and run:

$ make
$ python3 -m pytest test.py

Copyright

Copyright Ā© 2016 Arun Prakash Jana

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].