Bug 284557 - [NEW PORT] math/pcalc: Programmer's command line calculator
Summary: [NEW PORT] math/pcalc: Programmer's command line calculator
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: --- Affects Some People
Assignee: Yuri Victorovich
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2025-02-04 09:38 UTC by Paco Pascal
Modified: 2025-02-21 23:58 UTC (History)
3 users (show)

See Also:


Attachments
Patch for adding math/pcalc to ports (2.54 KB, patch)
2025-02-04 09:38 UTC, Paco Pascal
no flags Details | Diff
patch-math_pcalc.diff (2.16 KB, patch)
2025-02-04 21:01 UTC, Paco Pascal
no flags Details | Diff
patch-math_pcalc.diff (3.01 KB, patch)
2025-02-04 22:30 UTC, Paco Pascal
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Paco Pascal 2025-02-04 09:38:44 UTC
Created attachment 257216 [details]
Patch for adding math/pcalc to ports

This is a new port for pcalc which is a command line calculator developed by Peter Glen and Mike Frysinger.

For more information about the software, you can visit:
  - https://vapier.github.io/pcalc/
  - https://github.com/vapier/pcalc
Comment 1 Daniel Engberg freebsd_committer freebsd_triage 2025-02-04 17:30:16 UTC
Hi,

https://docs.freebsd.org/en/books/porters-handbook/book/#makefile-master_sites-github

Review "Table 5" 
Review "Example 16"

do-test section --> TEST_TARGET= check
https://docs.freebsd.org/en/books/porters-handbook/book/#make-test

Why are we installing AUTHORS and COPYING?

Why override do-install?

EXAMPLE, README, SYNTAX should be defined as DOCS

Best regards,
Daniel
Comment 2 Paco Pascal 2025-02-04 21:01:30 UTC
Created attachment 257239 [details]
patch-math_pcalc.diff

By installing AUTHORS and COPYING, I was mimicking what other ports do. My system has 41 packages that installed AUTHORS and 32 that installed either LICENSE or COPYING. I'm indifferent to installing them.

As for overriding do-install, that seemed cleaner than patching pcalc's Makefile for such a simple installation and is consistent with other ports. I think using ${INSTALL_PROGRAM} via do-install was cleaner than patching Makefile and running ${STRIPCMD} in post-install. 

I'm unsure how to handle the PORTDOCS in the plist, if at all. Generating pkg-plist produces,

    bin/pcalc
    %%PORTDOCS%%%%DOCSDIR%%/EXAMPLE
    %%PORTDOCS%%%%DOCSDIR%%/README.md
    %%PORTDOCS%%%%DOCSDIR%%/SYNTAX.md

which causes `make check-plist` to fail.

// Paco
Comment 3 Daniel Engberg freebsd_committer freebsd_triage 2025-02-04 21:10:24 UTC
(In reply to Paco Pascal from comment #2)
I would argue that it's incorrect ;)

https://docs.freebsd.org/en/books/porters-handbook/book/#install-documentation
Explains PORTDOCS (you're looking for PORTDOCS=)

Rule of thumb, do not try to outsmart the framework and/or over-engineer your port.

If the binary ends up in the correct path just strip the binary as Porters Handbook suggests (search for STRIP_CMD)

Best regards,
Daniel
Comment 4 Paco Pascal 2025-02-04 22:30:28 UTC
Created attachment 257242 [details]
patch-math_pcalc.diff
Comment 5 Paco Pascal 2025-02-04 22:44:07 UTC
(In reply to Daniel Engberg from comment #3)

I hope this last patch is sufficient. 🤞

// Paco
Comment 6 Yuri Victorovich freebsd_committer freebsd_triage 2025-02-21 07:04:31 UTC
Committed, thanks!
Comment 7 commit-hook freebsd_committer freebsd_triage 2025-02-21 07:05:39 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/ports/commit/?id=1f1b52823126722ceb9cd8c0275dbf563cef9f5a

commit 1f1b52823126722ceb9cd8c0275dbf563cef9f5a
Author:     Paco Pascal <me@pacopascal.com>
AuthorDate: 2025-02-21 06:24:54 +0000
Commit:     Yuri Victorovich <yuri@FreeBSD.org>
CommitDate: 2025-02-21 07:04:34 +0000

    math/pcalc: New port: Command line util for doing hex/dec/oct/bin math quickly

    PR:             284557

 math/Makefile                         |  1 +
 math/pcalc/Makefile (new)             | 31 +++++++++++++++++++++++++++++++
 math/pcalc/distinfo (new)             |  3 +++
 math/pcalc/files/patch-Makefile (new) | 24 ++++++++++++++++++++++++
 math/pcalc/pkg-descr (new)            | 10 ++++++++++
 5 files changed, 69 insertions(+)
Comment 8 Andriy Gapon freebsd_committer freebsd_triage 2025-02-21 14:03:44 UTC
pcalc sounds interesting, but its main selling point does not sound very appealing to me :-)

E.g.:
$ echo $((0x1234 + 0x20))
4692
$ echo $((0x1234 % 0x20))
20
$ printf '%#x\n' $((0x1234 % 0x20))
0x14
$ echo $((0x10 + 010 + 10))
34
$ echo $((0x10 + 010 + 10 + 0b10))
36

Shell itself can do quite a bit of math already.
Comment 9 Yuri Victorovich freebsd_committer freebsd_triage 2025-02-21 16:44:34 UTC
(In reply to Andriy Gapon from comment #8)

pcalc can also compute functions like exp(), sin().
Comment 10 Daniel Engberg freebsd_committer freebsd_triage 2025-02-21 17:09:54 UTC
There's also math/quich
Comment 11 Robert Clausecker freebsd_committer freebsd_triage 2025-02-21 22:32:20 UTC
(In reply to Yuri Victorovich from comment #9)

So can bc(1).
Comment 12 Yuri Victorovich freebsd_committer freebsd_triage 2025-02-21 22:35:49 UTC
(In reply to Robert Clausecker from comment #11)


$ bc -e "sin(0.001)"

Runtime error: undefined function: sin()
    0: (main)
Comment 13 Robert Clausecker freebsd_committer freebsd_triage 2025-02-21 22:46:34 UTC
(In reply to Yuri Victorovich from comment #12)

Seriously?

I guess you could try to read the man page of tools before concluding that they don't work...
Comment 14 Paco Pascal 2025-02-21 23:45:00 UTC
pcalc isn't going to end world hunger but it's a third party tool I've had in my environments for decades. It's something I reach for when I need it. There's plenty of alternatives, but pcalc provides better UI (in my opinion) for knocking out hex/bin values quickly. For the sake of argument, in bc I can do the following to get the values of 1 to 10 in binary

  bc -e "obase=2; $(seq -s ';' 1 10)"

In pcalc, it's just,

  pcalc `seq 1 10`

That's cleaner to call from acme, emacs, or some other tool that has a shell frontend. It's less featureful than bc, but sometimes less is more. And now I can automate it's installation easier with a "pkg install pcalc". Thank you.
Comment 15 Paco Pascal 2025-02-21 23:58:34 UTC
(In reply to Yuri Victorovich from comment #12)

And I'm pretty sure Yuri is trolling. He knows it's: bc -l -e 'sin(0.001)'