「🏗️」 wip: added the print message
This commit is contained in:
@ -1,5 +1,28 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
char *name;
|
||||||
|
char opt;
|
||||||
|
char *doc;
|
||||||
|
} options_t;
|
||||||
|
|
||||||
|
static options_t options[] = {
|
||||||
|
{
|
||||||
|
"help",
|
||||||
|
'?',
|
||||||
|
"give this help list"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"verbose",
|
||||||
|
'v',
|
||||||
|
"verbose output"
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#define OPT_NB 2
|
||||||
|
|
||||||
|
#define FT_PING_V 0.1
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Can be used to print the help message if no host (or addr) are
|
* @brief Can be used to print the help message if no host (or addr) are
|
||||||
* provided
|
* provided
|
||||||
|
@ -1,11 +1,13 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
typedef struct {
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
bool verbose;
|
||||||
} args_t;
|
} args_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Can be used to parse the command line options
|
* @brief Can be used to parse the command line options
|
||||||
* @param av The argv of the program
|
* @param av The argv of the program
|
||||||
*/
|
*/
|
||||||
int opt_parse(char **av, args_t *args);
|
int opt_parse(char **av, args_t *args);
|
||||||
|
19
src/help.c
19
src/help.c
@ -1,13 +1,22 @@
|
|||||||
#include <help.h>
|
#include <help.h>
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
struct options {
|
void print_help(void) {
|
||||||
char opt;
|
uint16_t i = 0;
|
||||||
char *desc;
|
|
||||||
};
|
|
||||||
|
|
||||||
void print_help(void) {}
|
printf("Usage: ping [OPTION...] HOST ...\n");
|
||||||
|
printf("Send ICMP ECHO_REQUEST packets to network hosts.\n\n");
|
||||||
|
|
||||||
|
while (i < OPT_NB) {
|
||||||
|
printf(" -%c, --%s:\t %s\n", options[i].opt, options[i].name, options[i].doc);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
printf("\nMandatory or optional arguments to long options are also mandatory "
|
||||||
|
"or optional\nfor any corresponding short options.\n\n");
|
||||||
|
printf("Report bugs to <noreply@adjoly.fr> (pls don't).\n");
|
||||||
|
}
|
||||||
|
|
||||||
void print_no_host(char *av) {
|
void print_no_host(char *av) {
|
||||||
printf("%s: missing host operand\n", av);
|
printf("%s: missing host operand\n", av);
|
||||||
|
@ -10,7 +10,9 @@ int main(int ac, char **av) {
|
|||||||
args_t args;
|
args_t args;
|
||||||
if (ac > 1) {
|
if (ac > 1) {
|
||||||
int ret = opt_parse(av, &args);
|
int ret = opt_parse(av, &args);
|
||||||
if (ret != EXIT_SUCCESS)
|
if (ret == -1)
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
else if (ret != EXIT_SUCCESS)
|
||||||
return ret;
|
return ret;
|
||||||
else
|
else
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
|
@ -1,20 +1,29 @@
|
|||||||
#include <help.h>
|
#include <help.h>
|
||||||
#include <ping.h>
|
|
||||||
#include <opt_parse.h>
|
#include <opt_parse.h>
|
||||||
|
#include <ping.h>
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <sysexits.h>
|
#include <sysexits.h>
|
||||||
|
|
||||||
int opt_parse(char **av, args_t *args) {
|
int opt_parse(char **av, args_t *args) {
|
||||||
char *exec_name = *av;
|
char *exec_name = *av;
|
||||||
|
|
||||||
(void)args;
|
(void)args;
|
||||||
while (*av != NULL) {
|
while (*av != NULL) {
|
||||||
char *a = *av;
|
char *a = *av;
|
||||||
|
|
||||||
if (*a == '-') {
|
if (*a == '-') {
|
||||||
printf("omg an opt\n");
|
switch ((char)*(a + 1)) {
|
||||||
|
case '-':
|
||||||
|
break;
|
||||||
|
case '?':
|
||||||
|
print_help();
|
||||||
|
return -1;
|
||||||
|
case 'v':
|
||||||
|
printf("verboseeee");
|
||||||
|
break;
|
||||||
|
};
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -28,6 +37,5 @@ int opt_parse(char **av, args_t *args) {
|
|||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// 127.0.0.1 localhost : no error wtf EZ 42 parsing + ratio
|
// 127.0.0.1 localhost : no error wtf EZ 42 parsing + ratio
|
||||||
// -v 127.0.0.1
|
// -v 127.0.0.1
|
||||||
|
Reference in New Issue
Block a user