Adapt to tree-sitter style
This commit is contained in:
@@ -1,11 +1,11 @@
|
|||||||
#include <stdexcept>
|
#include "pixels.hpp"
|
||||||
#include <string>
|
|
||||||
#include <sstream>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <sys/wait.h>
|
|
||||||
#include <libscerror.hpp>
|
#include <libscerror.hpp>
|
||||||
#include <libscterm.hpp>
|
#include <libscterm.hpp>
|
||||||
#include "pixels.hpp"
|
#include <sstream>
|
||||||
|
#include <stdexcept>
|
||||||
|
#include <string>
|
||||||
|
#include <sys/wait.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
static std::string resize_str() {
|
static std::string resize_str() {
|
||||||
sc::term t{STDOUT_FILENO};
|
sc::term t{STDOUT_FILENO};
|
||||||
@@ -16,7 +16,8 @@ static std::string resize_str() {
|
|||||||
return oss.str();
|
return oss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
void convert(const std::string& path) { // try to convert to ppm using ImageMagick
|
void convert(
|
||||||
|
const std::string &path) { // try to convert to ppm using ImageMagick
|
||||||
int pfd[2];
|
int pfd[2];
|
||||||
throw_if_min1_msg(pipe(pfd), "could not create pipe");
|
throw_if_min1_msg(pipe(pfd), "could not create pipe");
|
||||||
|
|
||||||
@@ -31,9 +32,11 @@ void convert(const std::string& path) { // try to convert to ppm using ImageMagi
|
|||||||
throw_if_min1(close(pfd[0]));
|
throw_if_min1(close(pfd[0]));
|
||||||
throw_if_min1(close(pfd[1]));
|
throw_if_min1(close(pfd[1]));
|
||||||
|
|
||||||
int res = execlp("magick", "magick", path.c_str(), "-resize", resize.c_str(), "ppm:-", nullptr);
|
int res = execlp("magick", "magick", path.c_str(), "-resize",
|
||||||
|
resize.c_str(), "ppm:-", nullptr);
|
||||||
if (res == -1) { // probably "magick" not found, try "convert"
|
if (res == -1) { // probably "magick" not found, try "convert"
|
||||||
res = execlp("convert", "convert", path.c_str(), "-resize", resize.c_str(), "ppm:-", nullptr);
|
res = execlp("convert", "convert", path.c_str(), "-resize",
|
||||||
|
resize.c_str(), "ppm:-", nullptr);
|
||||||
if (res == -1) { // no ImageMagick, abort
|
if (res == -1) { // no ImageMagick, abort
|
||||||
throw std::runtime_error{"no ImageMagick installed, abort"};
|
throw std::runtime_error{"no ImageMagick installed, abort"};
|
||||||
}
|
}
|
||||||
|
|||||||
27
src/main.cpp
27
src/main.cpp
@@ -1,13 +1,13 @@
|
|||||||
#include <iostream>
|
|
||||||
#include <cstdlib>
|
|
||||||
#include <string>
|
|
||||||
#include <stdexcept>
|
|
||||||
#include <getopt.h>
|
|
||||||
#include <netpbm/pam.h>
|
|
||||||
#include <libscstring.hpp>
|
|
||||||
#include "version.hpp"
|
|
||||||
#include "pixels.hpp"
|
|
||||||
#include "conversion.hpp"
|
#include "conversion.hpp"
|
||||||
|
#include "pixels.hpp"
|
||||||
|
#include "version.hpp"
|
||||||
|
#include <cstdlib>
|
||||||
|
#include <getopt.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include <libscstring.hpp>
|
||||||
|
#include <netpbm/pam.h>
|
||||||
|
#include <stdexcept>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
static void print_help() {
|
static void print_help() {
|
||||||
std::cout << "usage: termage [-h|--version] <imagefile>\n";
|
std::cout << "usage: termage [-h|--version] <imagefile>\n";
|
||||||
@@ -19,12 +19,11 @@ int main(int argc, char* argv[]) {
|
|||||||
try {
|
try {
|
||||||
pm_init("termage", 0);
|
pm_init("termage", 0);
|
||||||
int opt_char, opt_val;
|
int opt_char, opt_val;
|
||||||
struct option long_options[] = {
|
struct option long_options[] = {{"help", no_argument, nullptr, 'h'},
|
||||||
{"help", no_argument, nullptr, 'h'},
|
|
||||||
{"version", no_argument, &opt_val, 1},
|
{"version", no_argument, &opt_val, 1},
|
||||||
{nullptr, 0, nullptr, 0}
|
{nullptr, 0, nullptr, 0}};
|
||||||
};
|
while ((opt_char = getopt_long(argc, argv, "h", long_options, nullptr)) !=
|
||||||
while ((opt_char = getopt_long(argc, argv, "h", long_options, nullptr)) != -1) {
|
-1) {
|
||||||
std::string arg{optarg ? optarg : ""};
|
std::string arg{optarg ? optarg : ""};
|
||||||
switch (opt_char) {
|
switch (opt_char) {
|
||||||
case 0: {
|
case 0: {
|
||||||
|
|||||||
@@ -1,13 +1,15 @@
|
|||||||
#include <memory>
|
|
||||||
#include <libscterm.hpp>
|
|
||||||
#include <netpbm/pam.h>
|
|
||||||
#include "pixels.hpp"
|
#include "pixels.hpp"
|
||||||
|
#include <libscterm.hpp>
|
||||||
|
#include <memory>
|
||||||
|
#include <netpbm/pam.h>
|
||||||
|
|
||||||
void write_image(std::ostream &os, FILE *in) {
|
void write_image(std::ostream &os, FILE *in) {
|
||||||
struct pam info;
|
struct pam info;
|
||||||
pnm_readpaminit(in, &info, PAM_STRUCT_SIZE(tuple_type));
|
pnm_readpaminit(in, &info, PAM_STRUCT_SIZE(tuple_type));
|
||||||
std::unique_ptr<tuple, void(*)(void*)> row1 {pnm_allocpamrow(&info), pm_freerow};
|
std::unique_ptr<tuple, void (*)(void *)> row1{pnm_allocpamrow(&info),
|
||||||
std::unique_ptr<tuple, void(*)(void*)> row2 {pnm_allocpamrow(&info), pm_freerow};
|
pm_freerow};
|
||||||
|
std::unique_ptr<tuple, void (*)(void *)> row2{pnm_allocpamrow(&info),
|
||||||
|
pm_freerow};
|
||||||
for (int y = 0; y < info.height; y += 2) {
|
for (int y = 0; y < info.height; y += 2) {
|
||||||
tuple *t1{row1.get()};
|
tuple *t1{row1.get()};
|
||||||
tuple *t2{row2.get()};
|
tuple *t2{row2.get()};
|
||||||
@@ -30,11 +32,10 @@ void write_image(std::ostream& os, FILE* in) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void write_image(std::ostream& os) {
|
void write_image(std::ostream &os) { write_image(os, stdin); }
|
||||||
write_image(os, stdin);
|
|
||||||
}
|
|
||||||
|
|
||||||
void write_image(std::ostream &os, const std::string &path) {
|
void write_image(std::ostream &os, const std::string &path) {
|
||||||
std::unique_ptr<FILE, void(*)(FILE*)> infile {pm_openr(path.c_str()), pm_close};
|
std::unique_ptr<FILE, void (*)(FILE *)> infile{pm_openr(path.c_str()),
|
||||||
|
pm_close};
|
||||||
write_image(os, infile.get());
|
write_image(os, infile.get());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,8 +2,8 @@
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
std::string termage_version() {
|
std::string termage_version() {
|
||||||
#include "version.inc"
|
|
||||||
#include "commit.inc"
|
#include "commit.inc"
|
||||||
|
#include "version.inc"
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
oss << "termage version " << version;
|
oss << "termage version " << version;
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
|
|||||||
Reference in New Issue
Block a user