🏗️」 wip: parsing kinda working

This commit is contained in:
2025-08-11 21:52:57 +02:00
parent 8f1abd7940
commit e635977c88
6 changed files with 105 additions and 41 deletions

View File

@ -1,28 +1,48 @@
#pragma once
#include <stdint.h>
typedef struct {
char *name;
char opt;
char *doc;
char *name;
char opt;
char *doc;
uint8_t arg_nb;
uint8_t grp;
} options_t;
static options_t options[] = {
{
"help",
'?',
"give this help list"
},
{
"verbose",
'v',
"verbose output"
}
#define GRP 0 // AKA random useless sh*t
{"usage", 'u', "give a short usage message", 0, GRP},
{"help", '?', "give this help list", 0, GRP},
{"version", 'V', "print program version", 0, GRP},
#undef GRP
#define GRP 1 // AKA mandatory
{"verbose", 'v', "verbose output", 0, GRP},
#undef GRP
#define GRP 2 // AKA bonus
{"count", 'c', "stop after sending NUMBER packets (--count=NUMBER)", 1,
GRP},
{"size", 's', "send NUMBER data octets (--size=NUMBER)", 1, GRP},
{"timeout", 'w', "stop after N seconds (--timeout=N)", 1, GRP}
#undef GRP
};
#define OPT_NB 2
#define OPT_NB 5
#define FT_PING_V 0.1
#define OPT_WHILE \
int i = 0; \
while (i < OPT_NB)
#define OPT_HANDLE(i) \
if (options[i].arg_nb == 1) { \
if (!(av + 1) || !*(av + 1)) { \
return EX_USAGE; \
} \
args->arg[i] = *(av + 1); \
} \
args->opts[i] = true;
/**
* @brief Can be used to print the help message if no host (or addr) are
* provided

View File

@ -1,9 +1,13 @@
#pragma once
#include <help.h>
#include <stdint.h>
#include <stdbool.h>
typedef struct {
bool verbose;
bool opts[OPT_NB];
char *arg[OPT_NB];
} args_t;
/**