「🏗️」 wip: started the parsing of the args
This commit is contained in:
5
.clang-format
Normal file
5
.clang-format
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
UseTab: Always
|
||||||
|
IndentWidth: 4
|
||||||
|
TabWidth: 4
|
||||||
|
AlignConsecutiveDeclarations: true
|
||||||
|
ConstructorInitializerIndentWidth: 4
|
3
.gitignore
vendored
3
.gitignore
vendored
@ -59,3 +59,6 @@ Module.symvers
|
|||||||
Mkfile.old
|
Mkfile.old
|
||||||
dkms.conf
|
dkms.conf
|
||||||
|
|
||||||
|
# clangd shit
|
||||||
|
compile_commands.json
|
||||||
|
.cache
|
||||||
|
9
includes/help.h
Normal file
9
includes/help.h
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Can be used to print the help message if no host (or addr) are
|
||||||
|
* provided
|
||||||
|
*/
|
||||||
|
void print_no_host(char *av);
|
||||||
|
|
||||||
|
void print_help(void);
|
11
includes/opt_parse.h
Normal file
11
includes/opt_parse.h
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
|
||||||
|
} args_t;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Can be used to parse the command line options
|
||||||
|
* @param av The argv of the program
|
||||||
|
*/
|
||||||
|
int opt_parse(char **av, args_t *args);
|
1
includes/ping.h
Normal file
1
includes/ping.h
Normal file
@ -0,0 +1 @@
|
|||||||
|
#pragma once
|
15
src/help.c
Normal file
15
src/help.c
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
#include <help.h>
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
struct options {
|
||||||
|
char opt;
|
||||||
|
char *desc;
|
||||||
|
};
|
||||||
|
|
||||||
|
void print_help(void) {}
|
||||||
|
|
||||||
|
void print_no_host(char *av) {
|
||||||
|
printf("%s: missing host operand\n", av);
|
||||||
|
printf("Try 'ping --help' or 'ping -?' for more information.\n");
|
||||||
|
}
|
23
src/main.c
23
src/main.c
@ -1,5 +1,22 @@
|
|||||||
#include <stdio.h>
|
#include "sysexits.h"
|
||||||
|
#include <help.h>
|
||||||
|
#include <opt_parse.h>
|
||||||
|
#include <ping.h>
|
||||||
|
|
||||||
int main(void){
|
#include <stdio.h>
|
||||||
printf("asdf asdfa");
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
int main(int ac, char **av) {
|
||||||
|
args_t args;
|
||||||
|
if (ac > 1) {
|
||||||
|
int ret = opt_parse(av, &args);
|
||||||
|
if (ret != EXIT_SUCCESS)
|
||||||
|
return ret;
|
||||||
|
else
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
} else {
|
||||||
|
print_no_host(*av);
|
||||||
|
return EX_USAGE;
|
||||||
|
}
|
||||||
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
33
src/opt_parse.c
Normal file
33
src/opt_parse.c
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
#include <help.h>
|
||||||
|
#include <ping.h>
|
||||||
|
#include <opt_parse.h>
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <sysexits.h>
|
||||||
|
|
||||||
|
int opt_parse(char **av, args_t *args) {
|
||||||
|
char *exec_name = *av;
|
||||||
|
|
||||||
|
(void)args;
|
||||||
|
while (*av != NULL) {
|
||||||
|
char *a = *av;
|
||||||
|
|
||||||
|
if (*a == '-') {
|
||||||
|
printf("omg an opt\n");
|
||||||
|
} else {
|
||||||
|
|
||||||
|
}
|
||||||
|
av++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (av) {
|
||||||
|
print_no_host(exec_name);
|
||||||
|
return EX_USAGE;
|
||||||
|
}
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// 127.0.0.1 localhost : no error wtf EZ 42 parsing + ratio
|
||||||
|
// -v 127.0.0.1
|
Reference in New Issue
Block a user