Aliases and argument parser

This commit is contained in:
Abdelrahman Said 2023-10-21 18:57:09 +01:00
parent ac19a69379
commit fb4a2946b7
3 changed files with 66 additions and 0 deletions

27
include/aliases.h Normal file
View File

@ -0,0 +1,27 @@
#ifndef ALIASES_H
#define ALIASES_H
#include <stdint.h>
#define u8 uint8_t
#define u16 uint16_t
#define u32 uint32_t
#define u64 uint64_t
#define i8 int8_t
#define i16 int16_t
#define i32 int32_t
#define i64 int64_t
#define f32 float
#define f64 double
#define f128 long double
#define INTERNAL static
#define PERSISTENT static
#ifdef __cplusplus
#define CLASS_MEMBER static
#endif // __cplusplus
#endif // !ALIASES_H

20
include/argparse.h Normal file
View File

@ -0,0 +1,20 @@
#ifndef ARGPARSE_H
#define ARGPARSE_H
#include "aliases.h"
#include <linux/limits.h>
#include <stdbool.h>
typedef struct {
char dir[PATH_MAX];
char output[PATH_MAX];
} pckr_args_t;
typedef struct {
bool succeeded;
pckr_args_t args;
} argparser_t;
argparser_t parse_args(i32 argc, char *argv[]);
#endif // !ARGPARSE_H

19
src/argparse.c Normal file
View File

@ -0,0 +1,19 @@
#include "argparse.h"
#include <stdbool.h>
#include <stdlib.h>
argparser_t parse_args(i32 argc, char *argv[]) {
if (argc != 3) {
return (argparser_t){0};
}
argparser_t output = {
.succeeded = true,
.args = (pckr_args_t){0},
};
realpath(argv[1], output.args.dir);
realpath(argv[2], output.args.output);
return output;
}