1
0
Fork 0
mirror of https://github.com/tailix/libkernaux.git synced 2024-12-04 11:25:18 -05:00

Add dummy command line parser

This commit is contained in:
Alex Kotov 2020-12-02 01:22:38 +05:00
parent 761fb821d8
commit 5ad5a1300b
Signed by: kotovalexarian
GPG key ID: 553C0EBBEB5D5F08
3 changed files with 68 additions and 0 deletions

View file

@ -1,10 +1,26 @@
#ifndef KERNAUX_INCLUDED_CMDLINE #ifndef KERNAUX_INCLUDED_CMDLINE
#define KERNAUX_INCLUDED_CMDLINE 1 #define KERNAUX_INCLUDED_CMDLINE 1
#include <kernaux/stdlib.h>
#define KERNAUX_CMDLINE_ERROR_MSG_SIZE_MAX 256
#define KERNAUX_CMDLINE_ERROR_MSG_SLEN_MAX \
(KERNAUX_CMDLINE_ERROR_MSG_SIZE_MAX - 1)
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
kernaux_bool kernaux_cmdline_parse(
const char *cmdline,
char *error_msg,
unsigned int *argc,
char **argv,
char *buffer,
unsigned int argv_count_max,
unsigned int arg_size_max
);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View file

@ -1,3 +1,35 @@
#include "config.h" #include "config.h"
#include <kernaux/cmdline.h> #include <kernaux/cmdline.h>
kernaux_bool kernaux_cmdline_parse(
const char *const cmdline,
char *error_msg,
unsigned int *const argc,
char **argv,
char *buffer,
const unsigned int argv_count_max,
const unsigned int arg_size_max
) {
if (
cmdline == KERNAUX_NULL ||
error_msg == KERNAUX_NULL ||
argc == KERNAUX_NULL ||
argv == KERNAUX_NULL ||
argv_count_max == 0 ||
arg_size_max == 0
) {
return KERNAUX_FALSE;
}
kernaux_memset(error_msg, '\0', KERNAUX_CMDLINE_ERROR_MSG_SIZE_MAX);
*argc = 0;
for (unsigned int index = 0; index < argv_count_max; ++index) {
argv[index] = KERNAUX_NULL;
}
kernaux_memset(buffer, '\0', argv_count_max * arg_size_max);
return KERNAUX_TRUE;
}

View file

@ -1,6 +1,26 @@
#include <kernaux/cmdline.h> #include <kernaux/cmdline.h>
#include <assert.h>
static const unsigned int ARGV_COUNT_MAX = 1024;
static const unsigned int ARG_SIZE_MAX = 4096;
int main() int main()
{ {
char error_msg[KERNAUX_CMDLINE_ERROR_MSG_SIZE_MAX];
unsigned int argc;
char *argv[ARGV_COUNT_MAX];
char buffer[ARGV_COUNT_MAX * ARG_SIZE_MAX];
assert(kernaux_cmdline_parse(
"",
error_msg,
&argc,
argv,
buffer,
ARGV_COUNT_MAX,
ARG_SIZE_MAX
));
return 0; return 0;
} }