Codebase list bcal / e0dcdda
New upstream version 2.1+git20190806.6c8d325 SZ Lin (林上智) 4 years ago
7 changed file(s) with 51 addition(s) and 37 deletion(s). Raw diff Collapse all Expand all
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'
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'
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
33 DOCDIR = $(DESTDIR)$(PREFIX)/share/doc/bcal
44 STRIP ?= strip
55
6 CFLAGS ?= -O3
7 CFLAGS += -Wall -Wextra -Wno-unused-parameter -Werror
8 LDLIBS = -lreadline
6 CFLAGS_OPTIMIZATION ?= -O3
7 CFLAGS_WARNINGS ?= -Wall -Wextra -Wno-unused-parameter -Werror
8
9 LDLIBS_READLINE ?= -lreadline
10
11 CFLAGS += $(CFLAGS_OPTIMIZATION) $(CFLAGS_WARNINGS)
12 LDLIBS += $(LDLIBS_READLINE)
913
1014 SRC = $(wildcard src/*.c)
1115 INCLUDE = -Iinc
1216
1317 bcal: $(SRC)
14 $(CC) $(CFLAGS) $(INCLUDE) -o bcal $(SRC) $(LDLIBS)
18 $(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) $(INCLUDE) -o bcal $(SRC) $(LDLIBS)
1519
1620 all: bcal
1721
1822 x86: $(SRC)
19 $(CC) -m64 $(CFLAGS) $(INCLUDE) -o bcal $(SRC) $(LDLIBS)
23 $(CC) -m64 $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) $(INCLUDE) -o bcal $(SRC) $(LDLIBS)
2024 strip bcal
2125
2226 distclean: clean
66 <a href="https://packages.debian.org/search?keywords=bcal&searchon=names&exact=1"><img src="https://img.shields.io/badge/debian-9+-blue.svg?maxAge=2592000" alt="Debian Stretch+" /></a>
77 <a href="https://apps.fedoraproject.org/packages/bcal"><img src="https://img.shields.io/badge/fedora-27+-blue.svg?maxAge=2592000" alt="Fedora 27+" /></a>
88 <a href="https://packages.ubuntu.com/search?keywords=bcal&searchon=names&exact=1"><img src="https://img.shields.io/badge/ubuntu-17.04+-blue.svg?maxAge=2592000" alt="Ubuntu Zesty+" /></a>
9 <a href="https://launchpad.net/~twodopeshaggy/+archive/ubuntu/jarun/"><img src="https://img.shields.io/badge/ubuntu-PPA-blue.svg?maxAge=2592000" alt="Ubuntu PPA" /></a>
109 <p>
1110
1211 <p align="center">
12 <a href="https://repology.org/metapackage/bcal"><img src="https://repology.org/badge/tiny-repos/bcal.svg" alt="Availability"></a>
1313 <a href="https://travis-ci.org/jarun/bcal"><img src="https://img.shields.io/travis/jarun/bcal/master.svg" alt="Build Status" /></a>
1414 <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>
1515 <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>
1919 <a href="https://asciinema.org/a/168719"><img src="https://asciinema.org/a/168719.png" alt="bcal_asciicast" width="600"/></a>
2020 </p>
2121
22 `bcal` (*Byte CALculator*) is a REPL CLI utility for storage expressions, unit conversions or address calculations. 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.
22 `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.
2323
2424 It has a [`bc`](https://www.gnu.org/software/bc/manual/html_mono/bc.html) mode for general-purpose numerical calculations.
2525
2828 *Love smart and efficient utilities? Explore [my repositories](https://github.com/jarun?tab=repositories). Buy me a cup of coffee if they help you.*
2929
3030 <p align="center">
31 <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-green.svg" alt="Donate via PayPal!" /></a>
31 <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>
3232 </p>
3333
3434 ### Table of Contents
7171 - [AUR](https://aur.archlinux.org/packages/bcal/) (`yay -S bcal`)
7272 - [Debian](https://packages.debian.org/search?keywords=bcal&searchon=names&exact=1) (`apt-get install bcal`)
7373 - [Fedora](https://apps.fedoraproject.org/packages/bcal) (`dnf install bcal`)
74 - [Homebrew](http://formulae.brew.sh/formula/bcal) (`brew install bcal`)
74 - [FreeBSD](https://www.freshports.org/math/bcal/) (`pkg install bcal`)
75 - [macOS/Homebrew](http://formulae.brew.sh/formula/bcal) (`brew install bcal`)
7576 - [NixOS](https://github.com/NixOS/nixpkgs/tree/master/pkgs/applications/science/math/bcal) (`nix-env -i bcal`)
77 - [pkgsrc](http://pkgsrc.se/math/bcal) (`pkg_add bcal`)
7678 - [Raspbian Testing](https://archive.raspbian.org/raspbian/pool/main/b/bcal/) (`apt-get install bcal`)
7779 - [Ubuntu](https://packages.ubuntu.com/search?keywords=bcal&searchon=names&exact=1) (`apt-get install bcal`)
78 - [Ubuntu PPA](https://launchpad.net/~twodopeshaggy/+archive/ubuntu/jarun/) (`apt-get install bcal`)
7980 - [Void Linux](https://github.com/void-linux/void-packages/tree/master/srcpkgs/bcal) (`xbps-install -S bcal`)
8081
8182 #### Release packages
164165 - sector size: 0x200 (512)
165166 - max heads per cylinder: 0x10 (16)
166167 - max sectors per track: 0x3f (63)
167 - **bc variables**: `scale` = 10, `ibase` = 10. `last` and `r` are synced when toggling `bc` mode. `bc` is not called in minimal output mode.
168 - **bc variables**: `scale` = 10, `ibase` = 10. `last` is synced to `r` when toggling from `bc` to `bcal`. Syncing `r` to `last` works with GNU `bc`. `bc` is not called in minimal output mode.
168169
169170 ### Examples
170171
6262 - max sectors per track: 0x3f (63)
6363 .PP
6464 .IP 10. 4
65 \fBbc variables\fR: \fIscale\fR = 10, \fIibase\fR = 10. \fIlast\fR and \fIr\fR are synced when toggling \fIbc\fR mode. \fIbc\fR is not called in minimal output mode.
65 \fBbc variables\fR: \fIscale\fR = 10, \fIibase\fR = 10. \fIlast\fR is synced to \fIr\fR when toggling from \fIbc\fR to \fBbcal\fR. Syncing \fIr\fR to \fIlast\fR works with GNU \fIbc\fR. \fIbc\fR is not called in minimal output mode.
6666 .SH OPTIONS
6767 .TP
6868 .BI "-c=" N
1212 - gcc
1313 deps:
1414 - readline
15 container: "base/archlinux"
15 container: "archlinux/base"
1616 centos7.1:
1717 builddeps:
1818 - make
170170 static int try_bc(char *expr)
171171 {
172172 pid_t pid;
173 int pipe_pc[2], pipe_cp[2], ret;
173 int pipe_pc[2], pipe_cp[2];
174174 size_t len, count = 0;
175 ssize_t ret;
175176
176177 if (!expr) {
177178 if (curexpr)
204205 dup2(pipe_cp[1], STDOUT_FILENO); // Give stdout to parent
205206 dup2(pipe_cp[1], STDERR_FILENO); // Give stderr to parent
206207
207 ret = execlp("bc", "bc", "-q", (char*) NULL);
208 ret = execlp("bc", "bc", (char*) NULL);
208209 log(ERROR, "execlp() failed!\n");
209210 exit(ret);
210211 }
215216 exit(-1);
216217 }
217218
219 #ifdef __GNU_LIBRARY__
218220 if (write(pipe_pc[1], "last=", 5) != 5) {
219221 log(ERROR, "write(2)! [%s]\n", strerror(errno));
220222 exit(-1);
221223 }
222224
223225 if (lastres.p[0]) {
224 ret = strlen(lastres.p);
226 ret = (ssize_t)strlen(lastres.p);
225227 if (write(pipe_pc[1], lastres.p, ret) != ret) {
226228 log(ERROR, "write(3)! [%s]\n", strerror(errno));
227229 exit(-1);
237239 log(ERROR, "write(5)! [%s]\n", strerror(errno));
238240 exit(-1);
239241 }
240
241 ret = strlen(expr);
242 #endif
243
244 ret = (ssize_t)strlen(expr);
242245 if (write(pipe_pc[1], expr, ret) != ret) {
243246 log(ERROR, "write(6)! [%s]\n", strerror(errno));
244247 exit(-1);
11611164
11621165 static int bstricmp(const char *s1, const char *s2)
11631166 {
1164 while (*s1 && (tolower(*s1) == tolower(*s2))) {
1167 while ((int)*s1 && (tolower((int)*s1) == tolower((int)*s2))) {
11651168 ++s1;
11661169 ++s2;
11671170 }
14291432 dequeue(front, rear, &arg);
14301433
14311434 /* Check if arg is an operator */
1432 if (strlen(arg.p) == 1 && !isdigit(arg.p[0])) {
1435 if (strlen(arg.p) == 1 && !isdigit((int)arg.p[0])) {
14331436 pop(&est, &raw_b);
14341437 pop(&est, &raw_a);
14351438
16081611 }
16091612
16101613 /* Check if a char is operator or not */
1611 static int isoperator(char c)
1614 static int isoperator(int c)
16121615 {
16131616 switch (c) {
16141617 case '+':
16481651 if (!s || !*s)
16491652 return;
16501653
1651 int len = strlen(s) - 1;
1654 int len = (int)strlen(s) - 1;
16521655
16531656 if (s[len] == '\n')
16541657 --len;
1655 while (len >= 0 && (isspace(s[len]) || s[len] == '\"' || s[len] == '\''))
1658 while (len >= 0 && (isspace((int)s[len]) || s[len] == '\"' || s[len] == '\''))
16561659 --len;
16571660 s[len + 1] = '\0';
16581661
16591662 len = 0;
1660 while (s[len] && (isspace(s[len]) || s[len] == '\"' || s[len] == '\''))
1663 while (s[len] && (isspace((int)s[len]) || s[len] == '\"' || s[len] == '\''))
16611664 ++len;
16621665
16631666 if (len) {
16771680
16781681 while (*s != '\0') {
16791682 /* We should not combine 0xn b*/
1680 if (!isspace(*s) || (*(s + 1) == 'b')) {
1683 if (!isspace((int)*s) || (*(s + 1) == 'b')) {
16811684 *p = *s;
16821685 ++p;
16831686 }
17251728 return NULL;
17261729 }
17271730
1728 if (isoperator(exp[i]) && isalpha(exp[i + 1]) && (exp[i + 1] != 'r')) {
1731 if (isoperator((int)exp[i]) && isalpha((int)exp[i + 1]) && (exp[i + 1] != 'r')) {
17291732 log(ERROR, "invalid expression\n");
17301733 free(parsed);
17311734 return NULL;
17321735 }
17331736
1734 if ((isdigit(exp[i]) && isoperator(exp[i + 1])) ||
1735 (isoperator(exp[i]) && (isdigit(exp[i + 1]) ||
1736 isoperator(exp[i + 1]))) ||
1737 (isalpha(exp[i]) && isoperator(exp[i + 1])) ||
1738 (isoperator(exp[i]) && (exp[i + 1] == 'r'))) {
1737 if ((isdigit((int)exp[i]) && isoperator((int)exp[i + 1])) ||
1738 (isoperator((int)exp[i]) && (isdigit((int)exp[i + 1]) ||
1739 isoperator((int)exp[i + 1]))) ||
1740 (isalpha((int)exp[i]) && isoperator((int)exp[i + 1])) ||
1741 (isoperator((int)exp[i]) && ((int)exp[i + 1] == 'r'))) {
17391742 if (exp[i] == '<' || exp[i] == '>') { /* handle shift operators << and >> */
17401743 if (prev != exp[i] && exp[i] != exp[i + 1]) {
17411744 log(ERROR, "invalid operator %c\n", exp[i]);
18041807 }
18051808
18061809 if (!unit) {
1807 int unitchars = 0, len = strlen(value);
1810 int unitchars = 0, len = (int)strlen(value);
18081811
18091812 while (len) {
1810 if (!isalpha(value[len - 1]))
1813 if (!isalpha((int)value[len - 1]))
18111814 break;
18121815
18131816 ++unitchars;
19221925 char *expr = fixexpr(exp, &ret); /* Make parsing compatible */
19231926 char *ptr;
19241927
1925 log(DEBUG, "expr: %s\n", expr);
1928 if (expr)
1929 log(DEBUG, "expr: %s\n", expr);
19261930
19271931 if (expr == NULL) {
19281932 if (ret)
20282032 case 'f':
20292033 operation = 1;
20302034
2031 if (tolower(*optarg) == 'c') {
2035 if (tolower((int)*optarg) == 'c') {
20322036 maxuint_t lba = 0;
20332037
20342038 if (chs2lba(optarg + 1, &lba)) {
20372041 printhex_u128(lba);
20382042 printf("\n\n");
20392043 }
2040 } else if (tolower(*optarg) == 'l') {
2044 } else if (tolower((int)*optarg) == 'l') {
20412045 t_chs chs;
20422046
20432047 if (lba2chs(optarg + 1, &chs)) {
21362140 case 'b':
21372141 cfg.bcmode ^= 1;
21382142 if (cfg.bcmode) {
2143 #ifdef __GNU_LIBRARY__
21392144 printf("bc vars: scale = 10, ibase = 10, last = r\n");
2145 #else
2146 printf("bc vars: scale = 10, ibase = 10, last = 0\n");
2147 #endif
21402148 strncpy(prompt, "bc> ", 5);
21412149 } else
21422150 strncpy(prompt, "bcal> ", 7);