Change indent to 2 spaces

This commit is contained in:
2026-04-02 06:14:26 +02:00
parent 8aa1ea4df7
commit a2b2e5404a
2 changed files with 133 additions and 123 deletions

View File

@@ -1,12 +1,11 @@
#include <iostream>
#include <cstdlib>
#include <string>
#include <stdexcept>
#include <climits>
#include <algorithm>
#include <getopt.h>
#include <libscnumerics.hpp>
#include "version.hpp"
#include <algorithm>
#include <cstdlib>
#include <getopt.h>
#include <iostream>
#include <libscnumerics.hpp>
#include <stdexcept>
#include <string>
// globals
std::string upper{"ABCDEFGHIJKLMNOPQRSTUVWXYZ"};
@@ -34,9 +33,9 @@ int main(int argc, char* argv[]) {
{"symbol", required_argument, nullptr, 's'},
{"special", required_argument, nullptr, 'S'},
{"upper", required_argument, nullptr, 'u'},
{nullptr, 0, nullptr, 0}
};
while ((opt_char = getopt_long(argc, argv, "c:u:l:d:s:S:", long_options, nullptr)) != -1) {
{nullptr, 0, nullptr, 0}};
while ((opt_char = getopt_long(argc, argv, "c:u:l:d:s:S:", long_options,
nullptr)) != -1) {
std::string arg{optarg ? optarg : ""};
switch (opt_char) {
case 0: {
@@ -51,25 +50,33 @@ int main(int argc, char* argv[]) {
case 'u':
valid += upper;
min_upper = std::atoi(optarg);
if (min_upper < 0) throw std::runtime_error("minimum amout of upper case must be zero or more");
if (min_upper < 0)
throw std::runtime_error(
"minimum amout of upper case must be zero or more");
noflags = false;
break;
case 'l':
valid += lower;
min_lower = std::atoi(optarg);
if (min_upper < 0) throw std::runtime_error("minimum amout of lower case must be zero or more");
if (min_upper < 0)
throw std::runtime_error(
"minimum amout of lower case must be zero or more");
noflags = false;
break;
case 'd':
valid += digits;
min_digits = std::atoi(optarg);
if (min_upper < 0) throw std::runtime_error("minimum amout of digits must be zero or more");
if (min_upper < 0)
throw std::runtime_error(
"minimum amout of digits must be zero or more");
noflags = false;
break;
case 's':
valid += symbols;
min_symbols = std::atoi(optarg);
if (min_upper < 0) throw std::runtime_error("minimum amout of symbols must be zero or more");
if (min_upper < 0)
throw std::runtime_error(
"minimum amout of symbols must be zero or more");
noflags = false;
break;
case 'S':
@@ -88,9 +95,11 @@ int main(int argc, char* argv[]) {
if (noflags) {
valid = upper + lower + digits + symbols;
}
int num_free_choice = len - min_digits - min_lower - min_upper - min_symbols;
int num_free_choice =
len - min_digits - min_lower - min_upper - min_symbols;
if (num_free_choice < 0) {
throw std::runtime_error("total minimum required exceeds password length");
throw std::runtime_error(
"total minimum required exceeds password length");
}
std::string password;
for (int i = 0; i < min_digits; ++i) {
@@ -111,7 +120,8 @@ int main(int argc, char* argv[]) {
for (int i = 0; i < num_free_choice; ++i) {
password += sc::random::choice<char>(valid.begin(), valid.end());
}
std::shuffle(password.begin(), password.end(), sc::random::instance().engine());
std::shuffle(password.begin(), password.end(),
sc::random::instance().engine());
std::cout << password << std::endl;
} catch (const std::exception &ex) {
std::cerr << "pw: " << ex.what() << '\n';

View File

@@ -2,8 +2,8 @@
#include <sstream>
std::string pw_version() {
#include "version.inc"
#include "commit.inc"
#include "version.inc"
std::ostringstream oss;
oss << "pw version " << version;
#ifdef DEBUG