Files
zenith-cli/main.c
T

123 lines
3.3 KiB
C
Raw Normal View History

2026-09-02 15:28:15 +06:00
#include <stdio.h>
2026-09-03 21:00:32 +06:00
#include <stdlib.h>
#include <string.h>
2026-09-03 21:50:18 +06:00
#include <stdlib.h>
2026-09-02 15:28:15 +06:00
2026-09-03 21:00:32 +06:00
#include "libs/argparse.h"
#include "curl/curl.h"
2026-09-02 15:28:15 +06:00
struct Scheme{
char fg_color[8];
char sub_fg_color[8];
char bg_color[8];
char sub_bg_color[8];
char accent[8];
char sub_accent[8];
};
void write_pallete(const struct Scheme *s){
2026-09-03 21:00:32 +06:00
//s->bg_color
2026-09-02 15:28:15 +06:00
}
2026-09-03 21:50:18 +06:00
int download_wall(const char* link, const char* path){
CURL* curl;
FILE* fp;
2026-09-03 21:00:32 +06:00
CURLcode res;
2026-09-02 15:28:15 +06:00
2026-09-03 21:00:32 +06:00
curl_global_init(CURL_GLOBAL_ALL);
curl = curl_easy_init();
if(curl) {
2026-09-03 21:50:18 +06:00
fp = fopen(path, "wb");
2026-09-03 21:00:32 +06:00
if(fp == NULL) {
2026-09-03 21:50:18 +06:00
fprintf(stderr, \
"ошибка: не удалось создать или открыть файл %s\n", path);
2026-09-03 21:00:32 +06:00
curl_easy_cleanup(curl);
curl_global_cleanup();
return 1;
}
curl_easy_setopt(curl, CURLOPT_URL, link);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
res = curl_easy_perform(curl);
if(res != CURLE_OK) {
2026-09-03 21:50:18 +06:00
fprintf(stderr, "ошибка скачивания: %s\n", \
curl_easy_strerror(res));
2026-09-03 21:00:32 +06:00
}
fclose(fp);
curl_easy_cleanup(curl);
}
curl_global_cleanup();
return 0;
}
int main(int argc, const char **argv) {
const char* link = NULL;
2026-09-03 21:50:18 +06:00
const char* user_home = getenv("HOME");
const char* filename = "wallpaper.jpg";
char* raw_scheme_path = NULL;
char* raw_wall_path = NULL;
char wall_output[512];
char path[512];
int is_pastel = 0;
2026-09-03 21:00:32 +06:00
struct argparse_option options[] = {
OPT_HELP(),
2026-09-03 21:50:18 +06:00
OPT_STRING(0,"link", &link, \
"ссылка на изображение с сайта wallhave.cc", NULL, 0, 0),
OPT_BOOLEAN('p', "pastel", &is_pastel, \
"создать пастельные палитры", NULL, 0, 0),
OPT_STRING(0,"scheme-output", &raw_scheme_path,\
"директория для сохранения палитр", NULL, 0, 0),
OPT_STRING(0,"wall-output", &raw_wall_path, \
"директория для сохранения обоев", NULL, 0, 0),
2026-09-03 21:00:32 +06:00
OPT_END(),
};
struct argparse argparse;
argparse_init(&argparse, options, NULL, 0);
argc = argparse_parse(&argparse, argc, argv);
2026-09-03 21:50:18 +06:00
if (raw_wall_path == NULL){
wall_output[0] = '.';
wall_output[1] = '/';
}
else if (raw_wall_path[0] == '~'){
snprintf(wall_output, sizeof(wall_output), \
"%s%s", user_home, raw_wall_path + 1);
}
snprintf(path, sizeof(path), "%s%s", wall_output, filename);
download_wall(link, path);
2026-09-03 21:00:32 +06:00
return 0;
}
/*
2026-09-03 21:50:18 +06:00
аргументы
2026-09-03 21:00:32 +06:00
zenith-cli --link="link" -p/--pastel --scheme-output="path" --wall-output="path"
2026-09-03 21:50:18 +06:00
примеры использования
если передать пустую строку, то файл сохранится в директории утилиты
./zenith-cli --link="https://w.wallhaven.cc/full/gw/wallhaven-gwd313.jpg" --wall-output=""
ОБЯЗАТЕЛЬНО указывать в пути в конце /. потом мб добавлю проверку и автодополнение
./zenith-cli --link="https://w.wallhaven.cc/full/gw/wallhaven-gwd313.jpg" --wall-output="/home/ivan/"
./zenith-cli --link="https://w.wallhaven.cc/full/gw/wallhaven-gwd313.jpg" --wall-output="~/"
2026-09-03 21:00:32 +06:00
*/