/* Copyright (c) 2026 The Solidite Developers
*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. */
#include <iostream>
#include <locale>
#include <string>
#include <cstring>
int main(int argc, char* argv[]) {
// locale work
std::locale::global(std::locale(""));
std::cerr.imbue(std::locale());
if (argc < 2) {
std::cerr << "not enough arguments\n";
return 1;
}
std::string to_stdout = std::string(argv[1]);
if (to_stdout.find("/") != std::string::npos)
to_stdout = ".";
while (to_stdout.length() > 1)
// ensure that string is non-empty first
if (to_stdout[to_stdout.length() - 1] == '/')
to_stdout.pop_back();
else
break;
const size_t POS = to_stdout.find_last_of("/");
if (POS != std::string::npos && POS != 0) {
to_stdout = to_stdout.substr(0, POS);
} else if (POS == 0)
to_stdout = "/";
if (to_stdout.empty()) {
std::cout << ".\n";
return 0;
}
std::cout << to_stdout + '\n';
return 0;
}
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>