/
solidbase
/
C2_SimpleBashUtils
Обзор
Документация
Войти
/
solidbase
/
C2_SimpleBashUtils
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
develop
src/cat/options.c
70 строк
1 KB
Dmitrii Isaev
style: reformat files with clang-format
29 ноя 2025, 07:41
29 ноя 2025, 07:41
a48c279
Код
Авторство
О чём код?
#include "options.h" #include <getopt.h> #include <unistd.h> static const struct option long_opts[] = { {"number", no_argument, NULL, 'n'}, {"number-nonblank", no_argument, NULL, 'b'}, {"squeeze-blank", no_argument, NULL, 's'}, {NULL, 0, NULL, 0}}; int parse_options(int argc, char* const argv[], Options* opts, int* first_file_index) { if (!opts || !first_file_index) { return -1; } opts->n = 0; opts->b = 0; opts->s = 0; opts->e = 0; opts->t = 0; opts->E = 0; opts->T = 0; opts->v = 0; int status = 0; int ch = 0; while ((ch = getopt_long(argc, argv, "nbseEtTv", long_opts, NULL)) != -1) { switch (ch) { case 'n': opts->n = 1; break; case 'b': opts->b = 1; break; case 's': opts->s = 1; break; case 'e': opts->e = 1; break; case 't': opts->t = 1; break; case 'E': opts->E = 1; break; case 'T': opts->T = 1; break; case 'v': opts->v = 1; break; default: status = -1; break; } if (status != 0) { break; } } if (status == 0) { *first_file_index = optind; } return status; }