Удалён парсер флагов написанный LLM, и дописан свой
This commit is contained in:
parent
dcd0f80dbf
commit
b5c0f5ba02
3 changed files with 23 additions and 75 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -2,6 +2,7 @@ build/
|
|||
.kdev4/
|
||||
*~
|
||||
WebDisk_C.kdev4
|
||||
.cache
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,29 +1,35 @@
|
|||
#pragma once
|
||||
#include <getopt.h>
|
||||
#include <string.h>
|
||||
|
||||
void print_help(const char *progname) {
|
||||
printf("Использование: %s [опции]\n", progname);
|
||||
printf(" -h, --help показать это сообщение\n");
|
||||
printf(" -r, --recursion N указать глубину json\n");
|
||||
printf(" -j, --json вывод в виде json\n");
|
||||
printf(" -d, --directory путь для сканируемой директории\n");
|
||||
}
|
||||
|
||||
|
||||
void aaa(int* argc, char *argv[]){
|
||||
void args_pars(int* argc, char *argv[]){
|
||||
const struct option long_options[] = {
|
||||
{"help", no_argument, 0, 'h'},
|
||||
{"recursion", required_argument, 0, 'r'},
|
||||
{"json", no_argument, 0, 'j'},
|
||||
{"directory", required_argument, 0, 'd'},
|
||||
{0, 0, 0, 0}
|
||||
};
|
||||
|
||||
int opt;
|
||||
while ((opt = getopt_long(*argc, argv, "hr:j", long_options, NULL)) != -1) {
|
||||
while ((opt = getopt_long(*argc, argv, "hr:d:j", long_options, NULL)) != -1) {
|
||||
switch (opt) {
|
||||
case 'h':
|
||||
print_help(argv[0]);
|
||||
exit(0);
|
||||
break;
|
||||
case 'd':
|
||||
opts.dir = optarg;
|
||||
break;
|
||||
case 'r':
|
||||
opts.recursion = atoi(optarg);
|
||||
break;
|
||||
|
|
|
|||
85
main.c
85
main.c
|
|
@ -30,7 +30,7 @@ unsigned narenas = 4;
|
|||
|
||||
|
||||
#define DEBUG 0
|
||||
#define jemalloc 0
|
||||
#define jemalloc 1
|
||||
|
||||
#if defined(DEBUG) && DEBUG > 1
|
||||
#define DEBUG_PRINT(fmt, args...) fprintf(stderr, "DEBUG: %s:%d:%s(): " fmt, \
|
||||
|
|
@ -46,6 +46,7 @@ unsigned narenas = 4;
|
|||
struct opts_struct{
|
||||
int recursion;
|
||||
int json;
|
||||
char* dir;
|
||||
};
|
||||
struct opts_struct opts;
|
||||
struct tred_pizdec{
|
||||
|
|
@ -341,68 +342,6 @@ void scan_dir(struct metadata *mata){
|
|||
}
|
||||
DEBUG_PRINT("Готово!\n");
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
bool has_j;
|
||||
bool has_r;
|
||||
int r_value;
|
||||
char path[1024];
|
||||
} Options;
|
||||
|
||||
bool parse_args(int argc, char *argv[], Options *opts) { // II LLM
|
||||
opts->has_j = 0;
|
||||
opts->has_r = 0;
|
||||
opts->r_value = 0;
|
||||
opts->path[0] = '\0';
|
||||
|
||||
for (int i = 1; i < argc; i++) {
|
||||
char *arg = argv[i];
|
||||
|
||||
if (arg[0] == '-') {
|
||||
// Обрабатываем каждый символ после '-'
|
||||
for (int j = 1; arg[j] != '\0'; j++) {
|
||||
if (arg[j] == 'j') {
|
||||
opts->has_j = 1;
|
||||
} else if (arg[j] == 'r') {
|
||||
opts->has_r = 1;
|
||||
|
||||
// Проверка: есть ли сразу число после 'r'
|
||||
if (isdigit((unsigned char)arg[j + 1])) {
|
||||
opts->r_value = atoi(&arg[j + 1]);
|
||||
break; // всё остальное — часть числа, не флаг
|
||||
} else if (i + 1 < argc) {
|
||||
// Иначе, число должно быть в следующем аргументе
|
||||
opts->r_value = atoi(argv[++i]);
|
||||
break;
|
||||
} else {
|
||||
fprintf(stderr, "Ошибка: -r требует числовой аргумент\n");
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
fprintf(stderr, "Неизвестный флаг: -%c\n", arg[j]);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Первый аргумент без '-' — путь
|
||||
if (opts->path[0] == '\0') {
|
||||
strncpy(opts->path, arg, sizeof(opts->path) - 1);
|
||||
opts->path[sizeof(opts->path) - 1] = '\0';
|
||||
} else {
|
||||
fprintf(stderr, "Ошибка: путь уже указан\n");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (opts->path[0] == '\0') {
|
||||
fprintf(stderr, "Ошибка: путь не указан\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
bool js_logok, int_depth=0;
|
||||
|
||||
cJSON *print_statistik(cJSON *main_Array, struct dir_list_struct* list, char* output, int i){
|
||||
|
|
@ -446,22 +385,25 @@ int main(int argc, char *argv[]){
|
|||
char *path;
|
||||
setlocale(LC_ALL, "");
|
||||
//printf("Your locale is: %s\n", setlocale(LC_CTYPE, NULL));
|
||||
opts.json=0;
|
||||
args_pars(&argc, argv);
|
||||
/*
|
||||
Options opts;
|
||||
if (!parse_args(argc, argv, &opts)) {
|
||||
return 1;
|
||||
}
|
||||
*/
|
||||
|
||||
printf("Путь: %s\n", opts.path);
|
||||
printf("Флаг -j: %s\n", opts.has_j ? "да" : "нет");
|
||||
if (opts.has_r) {
|
||||
printf("Флаг -r: да, значение: %d\n", opts.r_value);
|
||||
printf("Путь: %s\n", opts.dir);
|
||||
printf("Флаг -j: %s\n", opts.json ? "да" : "нет");
|
||||
if (opts.recursion) {
|
||||
printf("Флаг -r: да, значение: %d\n", opts.recursion);
|
||||
} else {
|
||||
printf("Флаг -r: нет\n");
|
||||
}
|
||||
js_logok = opts.has_j;
|
||||
int_depth = opts.r_value;
|
||||
path = opts.path;
|
||||
|
||||
js_logok = opts.json;
|
||||
int_depth = opts.recursion;
|
||||
path = opts.dir;
|
||||
|
||||
struct metadata * mata = je_malloc(sizeof(stack_element));
|
||||
meta_data_init(mata);
|
||||
|
|
@ -485,7 +427,6 @@ int main(int argc, char *argv[]){
|
|||
struct dir_list_struct* list = mata->dir_list;
|
||||
cJSON *main_Array = cJSON_CreateArray();
|
||||
main_Array = print_statistik(main_Array, list, output, 0);
|
||||
|
||||
//while(list->next != NULL);
|
||||
//save_cache(mata, int cache_size)
|
||||
DEBUG_PRINT("ПППП!\n");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue