started argument parsing using argp

This commit is contained in:
root committed 2026-06-22 23:16:45 +02:00
1 parent 7b1511e31a
commit 62542734b5
4 files changed
+131 -7

No files matched your search

+89
View File
@@ -0,0 +1,89 @@
#include <argp.h>
#include "arguments.h"
// function prototypes
static error_t arg_parser( int key, char* arg, struct argp_state* state );
// global variable definitions
const char* argp_program_version = "0.1";
static char description[] = "`scan` is an alternative to `ls` with better colour support and builtin tree view.";
static char argument_description[] = "ARGUMENTS:";
static struct argp_option options[] =
{
{
"all",
'a',
NULL,
OPTION_ARG_OPTIONAL,
"show all items (including hidden ones)",
0
},
{
"almost-all",
'A',
NULL,
OPTION_ARG_OPTIONAL,
"same --all, excluding . and ..",
0
},
{
"group-directories",
'g',
NULL,
OPTION_ARG_OPTIONAL,
"group directories at the top",
0
},
{
"human-readable",
'h',
NULL,
OPTION_ARG_OPTIONAL,
"show sizes in human readable format",
0
},
{
"long",
'l',
NULL,
OPTION_ARG_OPTIONAL,
"use long listing format",
0
},
{
"tree",
'T',
NULL,
OPTION_ARG_OPTIONAL,
"use tree listing format",
0
}
};
static struct argp parser = {
options,
arg_parser,
argument_description,
description,
NULL,
NULL,
NULL
};
// module logic
error_t parse_args( int argc, char** argv, arguments_t* arguments )
{
// TODO: revisit ARG_INDEX for handling unknown arguments
return argp_parse(&parser, argc, argv, 0, NULL, arguments);
}
static error_t arg_parser( int key, char* arg, struct argp_state* state )
{
( void )key;
( void )arg;
( void )state;
return 0;
}