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