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:
parent
761fb821d8
commit
5ad5a1300b
3 changed files with 68 additions and 0 deletions
|
@ -1,10 +1,26 @@
|
|||
#ifndef KERNAUX_INCLUDED_CMDLINE
|
||||
#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
|
||||
extern "C" {
|
||||
#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
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -1,3 +1,35 @@
|
|||
#include "config.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;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,26 @@
|
|||
#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()
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue