added basic interface of the shellmatta option parser + started adding a test module
This commit is contained in:
103
src/shellmatta_opt.c
Normal file
103
src/shellmatta_opt.c
Normal file
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
* Copyright (c) 2019 Stefan Strobel <stefan.strobel@shimatta.net>
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file shellmatta_opt.c
|
||||
* @brief option parser implementation of the shellmatta
|
||||
* @author Stefan Strobel <stefan.strobel@shimatta.net>
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup shellmatta_opt
|
||||
* @{
|
||||
*/
|
||||
|
||||
#include "shellmatta_opt.h"
|
||||
#include "shellmatta_utils.h"
|
||||
#include "shellmatta.h"
|
||||
#include <string.h>
|
||||
|
||||
/**
|
||||
* @brief scans the current input and parses options in getopt style
|
||||
* @param[in] handle shellmatta handle
|
||||
* @param[in] optionString option string e.g. "cd:e::"
|
||||
* @param[out] option pointer to store the detected option to
|
||||
* @param[out] argument pointer to store the argument string to (can be NULL)
|
||||
* @param[out] argLen pointer to store the argument lengh to (can be NULL)
|
||||
*/
|
||||
shellmatta_retCode_t shellmatta_opt( shellmatta_handle_t handle,
|
||||
char *optionString,
|
||||
char *option,
|
||||
char **argument,
|
||||
uint32_t *argLen)
|
||||
{
|
||||
shellmatta_retCode_t ret = SHELLMATTA_USE_FAULT;
|
||||
shellmatta_instance_t *inst = (shellmatta_instance_t*)handle;
|
||||
|
||||
/** -# check parameters for plausibility */
|
||||
if( (NULL != inst)
|
||||
&& (SHELLMATTA_MAGIC == inst->magic)
|
||||
&& (NULL != optionString)
|
||||
&& (NULL != option))
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
(void)argument;
|
||||
(void)argLen;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief scans the current input and parses options in getopt_long style
|
||||
* @param[in] handle shellmatta handle
|
||||
* @param[in] longOptions option structure - pointer to array of type #shellmatta_opt_long_t
|
||||
* @param[out] option pointer to store the detected option to
|
||||
* @param[out] argument pointer to store the argument string to (can be NULL)
|
||||
* @param[out] argLen pointer to store the argument lengh to (can be NULL)
|
||||
*/
|
||||
shellmatta_retCode_t shellmatta_opt_long( shellmatta_handle_t handle,
|
||||
shellmatta_opt_long_t *longOptions,
|
||||
char *option,
|
||||
char **argument,
|
||||
uint32_t *argLen)
|
||||
{
|
||||
shellmatta_retCode_t ret = SHELLMATTA_USE_FAULT;
|
||||
shellmatta_instance_t *inst = (shellmatta_instance_t*)handle;
|
||||
|
||||
/** -# check parameters for plausibility */
|
||||
if( (NULL != inst)
|
||||
&& (SHELLMATTA_MAGIC == inst->magic)
|
||||
&& (NULL != longOptions)
|
||||
&& (NULL != option))
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
(void)argument;
|
||||
(void)argLen;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief initializes the option parser instance
|
||||
* @param[in, out] inst pointer to a shellmatta instance
|
||||
*/
|
||||
shellmatta_retCode_t shellmatta_opt_init(shellmatta_instance_t *inst)
|
||||
{
|
||||
/*! -# initialize all relevant option parser variables */
|
||||
inst->optionParser.offset = 0u;
|
||||
|
||||
return SHELLMATTA_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
42
src/shellmatta_opt.h
Normal file
42
src/shellmatta_opt.h
Normal file
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright (c) 2019 Stefan Strobel <stefan.strobel@shimatta.net>
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file shellmatta_opt.h
|
||||
* @brief option parser implementation of the shellmatta
|
||||
* @author Stefan Strobel <stefan.strobel@shimatta.net>
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup shellmatta_opt
|
||||
* @{
|
||||
*/
|
||||
#ifndef _SHELLMATTA_OPT_H_
|
||||
#define _SHELLMATTA_OPT_H_
|
||||
|
||||
#include "shellmatta.h"
|
||||
#include <stdint.h>
|
||||
|
||||
shellmatta_retCode_t shellmatta_opt( shellmatta_handle_t handle,
|
||||
char *optionString,
|
||||
char *option,
|
||||
char **argument,
|
||||
uint32_t *argLen);
|
||||
|
||||
shellmatta_retCode_t shellmatta_opt_long( shellmatta_handle_t handle,
|
||||
shellmatta_opt_long_t *longOptions,
|
||||
char *option,
|
||||
char **argument,
|
||||
uint32_t *argLen);
|
||||
|
||||
shellmatta_retCode_t shellmatta_opt_init( shellmatta_instance_t *inst);
|
||||
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
|
Reference in New Issue
Block a user