Make MiniScript Portable Again!

Make MiniScript Portable Again!

By Hatty Hacker | Hatty Hacking | 9 Nov 2021


MiniScript Build on Haiku, Minoca, and OpenBSD

Big brain, mini... "script"

MiniScript looks really neat.
MiniScript is annoyingly neat.
Getting started docs in `.pdf`s instead of Markdown/Raw-text, kinda "homely" documentation when compared with megacorp scripting langs...
And the fact that they actually care about performance instead of portability.

But it builds on Windows, Mac, and Linux!
Even FreeBSD!
Stop whining you entitled millennial wannabe that wears a hat and calls thineself hacker!
Don't like sumthin'bout it?
How about a commit, huuuuuuuuuuuh?

No.
I don't `git` anymore.
I'm sorta like an archaeologist, if that helps give an idea...
So, here's my hack for getting yet-anoother-obscure-lahnghuagee on mah obsd home setup.


Initial Make

As with all gnunixy hipsters' projects, thou needest `gmake`.
Probably some other libs, I've installed too much crap on my obsd system related to dev stuff.
I'm getting lazier with each passing moment.

Okie doke, you know the drift...
We `cd` into the `MiniScript-cpp` folder (after "extinguishing" the `MiniScript-cs` one) and run our `gmake`:


...
src/MiniScript/Dictionary.h:343: error: 'nullptr' was not declared in this scope
In file included from src/MiniScript/UnitTest.cpp:21:
src/MiniScript/String.h: In constructor 'MiniScript::StringStorage::StringStorage()':
src/MiniScript/String.h:25: error: 'nullptr' was not declared in this scope
src/MiniScript/String.h: In constructor 'MiniScript::String::String()':
src/MiniScript/String.h:66: error: 'nullptr' was not declared in this scope
src/MiniScript/String.h: In member function 'const char* MiniScript::String::data() const':
src/MiniScript/String.h:92: error: 'nullptr' was not declared in this scope
src/MiniScript/String.h: In member function 'void MiniScript::String::release()':
src/MiniScript/String.h:177: error: 'nullptr' was not declared in this scope
src/MiniScript/String.h: In member function 'void MiniScript::String::forget()':
src/MiniScript/String.h:179: error: 'nullptr' was not declared in this scope
src/MiniScript/String.h: In constructor 'MiniScript::String::String(int, char)':
src/MiniScript/String.h:191: error: 'nullptr' was not declared in this scope
src/MiniScript/String.h: In constructor 'MiniScript::String::String(const char*)':
src/MiniScript/String.h:203: error: 'nullptr' was not declared in this scope
src/MiniScript/String.h: In constructor 'MiniScript::String::String(const char*, size_t)':
src/MiniScript/String.h:212: error: 'nullptr' was not declared in this scope
src/MiniScript/String.h: In member function 'MiniScript::String& MiniScript::String::operator=(const char*)':
src/MiniScript/String.h:230: error: 'nullptr' was not declared in this scope
src/MiniScript/String.h: In member function 'int MiniScript::String::Compare(const MiniScript::String&) const':
src/MiniScript/String.h:272: error: 'nullptr' was not declared in this scope
src/MiniScript/String.h:274: error: 'nullptr' was not declared in this scope
src/MiniScript/String.h: In member function 'MiniScript::String MiniScript::String::ToLower() const':
src/MiniScript/String.h:504: error: 'nullptr' was not declared in this scope
...

...which gives me PTSD.

I srsly haz problem, wanting to run the most obscure crap on things it wasn't intentionally targeted for.
I'm like those wild dental patients in the (original and '86) Little Shop of Horrors movies.
Some people are predisposed to suffering...


Remake the Make

My first guess was to not check the `Makefile` like a sane individual but trigger myself again instead by doing `make`, using the BSD-Make command...

Wow.
You can say that backwards.
I was never a with-honors graduate from my MIS graduating class of like, 20 people.
You can tell.

Finally, I go to the `Makefile` like I do any other time and find out `CC=gcc`.
I am not "gnu" to the suffering of that over-engineered tripe, as well as peeving off the Lignux community in the process of saying that.
I, like Stallman, prefer LiGNUx over GNU/Linux, less syllables...
However, I like `clang` and it's the default on OpenBSD.
I pray it will work:


clang -o miniscript src/*.cpp src/editline/complete.c src/editline/editline.c src/editline/sysunix.c src/MiniScript/*.cpp -Isrc -Isrc/editline -Isrc/MiniScript -lstdc++ -lm
src/ShellIntrinsics.cpp:44:12: fatal error: 'sys/sendfile.h' file not found
#include <sys/sendfile.h>
^~~~~~~~~~~~~~~~
1 error generated.
src/MiniScript/MiniscriptTAC.cpp:287:12: warning: 28 enumeration values not handled in switch: 'Noop', 'AssignA', 'AssignImplicit'... [-Wswitch]
switch (op) {
^
1 warning generated.
gmake: *** [Makefile:6: miniscript] Error 1

 

...and I begin singing the `M*A*S*H*` theme in quiet, lonely desperation in the cold, drafty attic.


Fixing the `ShellIntrinsics` File

The `src/ShellIntrinsics.cpp` file is actually well-written, but there was a design choice that I can understand though disdain: use the kernel.
Now I prefer portability over performance, seeking a hybrid model that will default to the most portable solution if the performant ones are not supported.
After hours on `w3m`, `Badwolf`, `YaCy`, `DuckDuckGo`, and `/usr/include` with `/usr/local/include`, etc...
I find that OpenBSD seemingly has no performant way of copying files via the kernel.
Plus, I wanna try this out on Haiku and Minoca.

Windows is cool for the `static int UnixishCopyFile(const char* source, const char* destination)` function.
But anyhting else, nawhp.
That function is the problem, because it calls lignux's `sendfile.h`'s `sendfile()` or osx/fbsd's `copyfile.h`'s `fcopyfile()`.
No known `*file.h` exists in OpenBSD and there is no `sendfile()` or `fcopyfile()`.
We have to roll our own.

Like any true computer-programming-hacker-software-engineer-developer-perse-dood-guy-thing I was given divine revalation.
It came to me, just like the other times I found out stuff on me own.
Totally not borrowed this time around...
(I don't know `C++` I hate the syntax and prefer `C`'s simplicity)

Yes, I could do it in `C` -- HUSH.

There are a few options, such as trying to hack around making our own "dummy" version of the file copy.
Instead, we'll follow the setup and put in a witty 4-liner like any other use case:


#elif defined(__HAIKU__) || defined(__MINOCA__) || defined(__OpenBSD__)
int result = 0;
std::ifstream src(source, std::ios::binary);
std::ofstream dst(destination, std::ios::binary);
dst << src.rdbuf();

...on line 115.
We have to remember that the header doesn't exist, so we need a use case to avoid more PTSD:


#elif defined(__HAIKU__) || defined(__MINOCA__) || defined(__OpenBSD__)
// Haiku, Minoca, OpenBSD, etc all have no noticible implementation
// of copyfile.h or sendfile.h in /usr/include and /usr/local/include,
// so we ignore here

...on line 43.


Either Process.kill() or Beer(me)

Then we `gmake` and cry ourselves to sleep...

WAIT!!!!

`ls`, doest thou lie?


Makefile README.md miniscript src test.ms

 

I see myself a `miniscript` executable application!
We can run it and mess around, learning as we go.
But does our thing work?
You know, the thing?
The thing... I sent you?


> ./miniscript test.ms
test.ms loaded. Hello, world!
Working directory: /home/user/Downloads/pl/miniscript/miniscript-master/MiniScript-cpp
Copying: Hey -> HEY
Copying: Ho -> HO
Copying: Hoo-ah -> HOO-AH
All done!

 

Let's `ls` because it seems like it worked...


Makefile README.md fileToRead.txt fileToWrite.txt miniscript src test.ms

 

Okay, so...


> cat fileToRead.txt
Hey
Ho
Hoo-ah

> cat fileToWrite.txt
HEY
HO
HOO-AH

 

...it worked!


Thanks for reading, HattyHacking;

How do you rate this article?

1


Hatty Hacker
Hatty Hacker

Recreational programming and tech-xploration to everyday life and morel madness! Videos are campy and awkward on purpose. Also the official home of Fake News!


Hatty Hacking
Hatty Hacking

A deeper look into the videos by the Hatty Hacker (http://hattyhacker.com/).

Publish0x

Send a $0.01 microtip in crypto to the author, and earn yourself as you read!

20% to author / 80% to me.
We pay the tips from our rewards pool.