|
@@ -36,7 +36,7 @@ static shellmatta_retCode_t findNextHunk(shellmatta_instance_t *inst)
|
|
uint32_t exeptionOffset = 0u;
|
|
uint32_t exeptionOffset = 0u;
|
|
char quotation = '\0'; /* holds the current quotation mark if any */
|
|
char quotation = '\0'; /* holds the current quotation mark if any */
|
|
|
|
|
|
- /*! -# find beginning of next hunk */
|
|
|
|
|
|
+ /** -# find beginning of next hunk */
|
|
while( (newOffset < inst->inputCount)
|
|
while( (newOffset < inst->inputCount)
|
|
&& ((' ' == inst->buffer[newOffset])
|
|
&& ((' ' == inst->buffer[newOffset])
|
|
|| ('\0' == inst->buffer[newOffset])))
|
|
|| ('\0' == inst->buffer[newOffset])))
|
|
@@ -46,21 +46,21 @@ static shellmatta_retCode_t findNextHunk(shellmatta_instance_t *inst)
|
|
|
|
|
|
inst->optionParser.offset = newOffset;
|
|
inst->optionParser.offset = newOffset;
|
|
|
|
|
|
- /*! -# determine length */
|
|
|
|
|
|
+ /** -# determine length */
|
|
while((newOffset < inst->inputCount)
|
|
while((newOffset < inst->inputCount)
|
|
&& (((' ' != inst->buffer[newOffset]) && ('\0' != inst->buffer[newOffset])) || '\0' != quotation))
|
|
&& (((' ' != inst->buffer[newOffset]) && ('\0' != inst->buffer[newOffset])) || '\0' != quotation))
|
|
{
|
|
{
|
|
- /*! -# check for new quotation */
|
|
|
|
|
|
+ /** -# check for new quotation */
|
|
if((('\'' == inst->buffer[newOffset]) || ('"' == inst->buffer[newOffset])) && (quotation == '\0'))
|
|
if((('\'' == inst->buffer[newOffset]) || ('"' == inst->buffer[newOffset])) && (quotation == '\0'))
|
|
{
|
|
{
|
|
quotation = inst->buffer[newOffset];
|
|
quotation = inst->buffer[newOffset];
|
|
exeptionOffset ++;
|
|
exeptionOffset ++;
|
|
}
|
|
}
|
|
- /*! -# check if quotation has ended */
|
|
|
|
|
|
+ /** -# check if quotation has ended */
|
|
else if(quotation == inst->buffer[newOffset])
|
|
else if(quotation == inst->buffer[newOffset])
|
|
{
|
|
{
|
|
exeptionOffset ++;
|
|
exeptionOffset ++;
|
|
- /*! -# check if quotation is excaped */
|
|
|
|
|
|
+ /** -# check if quotation is excaped */
|
|
if('\\' != inst->buffer[newOffset - 1u])
|
|
if('\\' != inst->buffer[newOffset - 1u])
|
|
{
|
|
{
|
|
quotation = '\0';
|
|
quotation = '\0';
|
|
@@ -72,7 +72,7 @@ static shellmatta_retCode_t findNextHunk(shellmatta_instance_t *inst)
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
- /*! -# shift back chars */
|
|
|
|
|
|
+ /** -# shift back chars */
|
|
if(0u != exeptionOffset)
|
|
if(0u != exeptionOffset)
|
|
{
|
|
{
|
|
inst->buffer[newOffset - exeptionOffset] = inst->buffer[newOffset];
|
|
inst->buffer[newOffset - exeptionOffset] = inst->buffer[newOffset];
|
|
@@ -84,7 +84,7 @@ static shellmatta_retCode_t findNextHunk(shellmatta_instance_t *inst)
|
|
inst->optionParser.nextOffset = newOffset;
|
|
inst->optionParser.nextOffset = newOffset;
|
|
inst->optionParser.len = newOffset - inst->optionParser.offset - exeptionOffset;
|
|
inst->optionParser.len = newOffset - inst->optionParser.offset - exeptionOffset;
|
|
|
|
|
|
- /*! -# add terminating 0 */
|
|
|
|
|
|
+ /** -# add terminating 0 */
|
|
inst->buffer[inst->optionParser.offset + inst->optionParser.len] = '\0';
|
|
inst->buffer[inst->optionParser.offset + inst->optionParser.len] = '\0';
|
|
|
|
|
|
if((inst->optionParser.offset < inst->inputCount) && (0u != inst->optionParser.len) && ('\0' == quotation))
|
|
if((inst->optionParser.offset < inst->inputCount) && (0u != inst->optionParser.len) && ('\0' == quotation))
|
|
@@ -104,7 +104,7 @@ static char peekNextHunk(shellmatta_instance_t *inst)
|
|
{
|
|
{
|
|
uint32_t newOffset = inst->optionParser.nextOffset;
|
|
uint32_t newOffset = inst->optionParser.nextOffset;
|
|
|
|
|
|
- /*! -# find beginning of next hunk */
|
|
|
|
|
|
+ /** -# find beginning of next hunk */
|
|
while( (newOffset < inst->inputCount)
|
|
while( (newOffset < inst->inputCount)
|
|
&& ((' ' == inst->buffer[newOffset])
|
|
&& ((' ' == inst->buffer[newOffset])
|
|
|| ('\0' == inst->buffer[newOffset])))
|
|
|| ('\0' == inst->buffer[newOffset])))
|
|
@@ -132,22 +132,22 @@ static shellmatta_retCode_t parseShortOpt( shellmatta_instance_t *inst,
|
|
char *buffer = &inst->buffer[inst->optionParser.offset];
|
|
char *buffer = &inst->buffer[inst->optionParser.offset];
|
|
uint32_t i;
|
|
uint32_t i;
|
|
|
|
|
|
- /*! -# check for correct syntax */
|
|
|
|
|
|
+ /** -# check for correct syntax */
|
|
if((2u == inst->optionParser.len) && ('-' == buffer[0u]) && ('-' != buffer[1u]) && ('\0' != buffer[1u]))
|
|
if((2u == inst->optionParser.len) && ('-' == buffer[0u]) && ('-' != buffer[1u]) && ('\0' != buffer[1u]))
|
|
{
|
|
{
|
|
*option = '\0';
|
|
*option = '\0';
|
|
|
|
|
|
- /*! -# search for option character in option string */
|
|
|
|
|
|
+ /** -# search for option character in option string */
|
|
for(i = 0u; ('\0' != optionString[i]) && ('\0' == *option); i ++)
|
|
for(i = 0u; ('\0' != optionString[i]) && ('\0' == *option); i ++)
|
|
{
|
|
{
|
|
if(buffer[1u] == optionString[i])
|
|
if(buffer[1u] == optionString[i])
|
|
{
|
|
{
|
|
ret = SHELLMATTA_OK;
|
|
ret = SHELLMATTA_OK;
|
|
|
|
|
|
- /*! -# return found option character */
|
|
|
|
|
|
+ /** -# return found option character */
|
|
*option = buffer[1u];
|
|
*option = buffer[1u];
|
|
|
|
|
|
- /*! -# check if an argument is required or optional */
|
|
|
|
|
|
+ /** -# check if an argument is required or optional */
|
|
if(':' == optionString[i + 1u])
|
|
if(':' == optionString[i + 1u])
|
|
{
|
|
{
|
|
*argtype = SHELLMATTA_OPT_ARG_REQUIRED;
|
|
*argtype = SHELLMATTA_OPT_ARG_REQUIRED;
|
|
@@ -163,7 +163,7 @@ static shellmatta_retCode_t parseShortOpt( shellmatta_instance_t *inst,
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- /*! -# skip "--" */
|
|
|
|
|
|
+ /** -# skip "--" */
|
|
else if((2u == inst->optionParser.len) && ('-' == buffer[0u]) && ('-' == buffer[1u]))
|
|
else if((2u == inst->optionParser.len) && ('-' == buffer[0u]) && ('-' == buffer[1u]))
|
|
{
|
|
{
|
|
ret = SHELLMATTA_CONTINUE;
|
|
ret = SHELLMATTA_CONTINUE;
|
|
@@ -194,39 +194,39 @@ static shellmatta_retCode_t parseLongOpt( shellmatta_instance_t *inst,
|
|
char *buffer = &inst->buffer[inst->optionParser.offset];
|
|
char *buffer = &inst->buffer[inst->optionParser.offset];
|
|
uint32_t i;
|
|
uint32_t i;
|
|
|
|
|
|
- /*! -# check for correct syntax for short options */
|
|
|
|
|
|
+ /** -# check for correct syntax for short options */
|
|
if((2u == inst->optionParser.len) && ('-' == buffer[0u]) && ('-' != buffer[1u]) && ('\0' != buffer[1u]))
|
|
if((2u == inst->optionParser.len) && ('-' == buffer[0u]) && ('-' != buffer[1u]) && ('\0' != buffer[1u]))
|
|
{
|
|
{
|
|
- /*! -# search for option character in option list */
|
|
|
|
|
|
+ /** -# search for option character in option list */
|
|
for(i = 0u; ('\0' != longOptions[i].paramShort) && ('\0' == *option); i ++)
|
|
for(i = 0u; ('\0' != longOptions[i].paramShort) && ('\0' == *option); i ++)
|
|
{
|
|
{
|
|
if(buffer[1u] == longOptions[i].paramShort)
|
|
if(buffer[1u] == longOptions[i].paramShort)
|
|
{
|
|
{
|
|
ret = SHELLMATTA_OK;
|
|
ret = SHELLMATTA_OK;
|
|
|
|
|
|
- /*! -# return found option character */
|
|
|
|
|
|
+ /** -# return found option character */
|
|
*option = longOptions[i].paramShort;
|
|
*option = longOptions[i].paramShort;
|
|
*argtype = longOptions[i].argtype;
|
|
*argtype = longOptions[i].argtype;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- /*! -# check for correct syntax for long options */
|
|
|
|
|
|
+ /** -# check for correct syntax for long options */
|
|
else if((3u <= inst->optionParser.len) && ('-' == buffer[0u]) && ('-' == buffer[1u]))
|
|
else if((3u <= inst->optionParser.len) && ('-' == buffer[0u]) && ('-' == buffer[1u]))
|
|
{
|
|
{
|
|
- /*! -# search for long option in option list */
|
|
|
|
|
|
+ /** -# search for long option in option list */
|
|
for(i = 0u; ('\0' != longOptions[i].paramShort) && ('\0' == *option); i ++)
|
|
for(i = 0u; ('\0' != longOptions[i].paramShort) && ('\0' == *option); i ++)
|
|
{
|
|
{
|
|
if(0 == strcmp(&buffer[2u], longOptions[i].paramLong))
|
|
if(0 == strcmp(&buffer[2u], longOptions[i].paramLong))
|
|
{
|
|
{
|
|
ret = SHELLMATTA_OK;
|
|
ret = SHELLMATTA_OK;
|
|
|
|
|
|
- /*! -# return found option character */
|
|
|
|
|
|
+ /** -# return found option character */
|
|
*option = longOptions[i].paramShort;
|
|
*option = longOptions[i].paramShort;
|
|
*argtype = longOptions[i].argtype;
|
|
*argtype = longOptions[i].argtype;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- /*! -# ignore "--" */
|
|
|
|
|
|
+ /** -# ignore "--" */
|
|
else if((2u == inst->optionParser.len) && ('-' == buffer[0u]) && ('-' == buffer[1u]))
|
|
else if((2u == inst->optionParser.len) && ('-' == buffer[0u]) && ('-' == buffer[1u]))
|
|
{
|
|
{
|
|
*option = '\0';
|
|
*option = '\0';
|
|
@@ -279,13 +279,13 @@ static shellmatta_retCode_t shellmatta_opt_int( shellmatta_handle_t handle,
|
|
*argLen = 0u;
|
|
*argLen = 0u;
|
|
}
|
|
}
|
|
|
|
|
|
- /*! -# do this until we find a not skipable argument */
|
|
|
|
|
|
+ /** -# do this until we find a not skipable argument */
|
|
do
|
|
do
|
|
{
|
|
{
|
|
ret = findNextHunk(inst);
|
|
ret = findNextHunk(inst);
|
|
if(SHELLMATTA_OK == ret)
|
|
if(SHELLMATTA_OK == ret)
|
|
{
|
|
{
|
|
- /*! -# call the matching parse function */
|
|
|
|
|
|
+ /** -# call the matching parse function */
|
|
if(NULL != optionString)
|
|
if(NULL != optionString)
|
|
{
|
|
{
|
|
ret = parseShortOpt(inst, optionString, option, &argtype);
|
|
ret = parseShortOpt(inst, optionString, option, &argtype);
|
|
@@ -299,7 +299,7 @@ static shellmatta_retCode_t shellmatta_opt_int( shellmatta_handle_t handle,
|
|
ret = SHELLMATTA_USE_FAULT;
|
|
ret = SHELLMATTA_USE_FAULT;
|
|
}
|
|
}
|
|
|
|
|
|
- /*! -# when no option is found return this as raw argument */
|
|
|
|
|
|
+ /** -# when no option is found return this as raw argument */
|
|
if(SHELLMATTA_ERROR == ret)
|
|
if(SHELLMATTA_ERROR == ret)
|
|
{
|
|
{
|
|
if(NULL != argument)
|
|
if(NULL != argument)
|
|
@@ -314,7 +314,7 @@ static shellmatta_retCode_t shellmatta_opt_int( shellmatta_handle_t handle,
|
|
}
|
|
}
|
|
else if(SHELLMATTA_USE_FAULT == ret)
|
|
else if(SHELLMATTA_USE_FAULT == ret)
|
|
{
|
|
{
|
|
- /*! -# nothing to do - just return errorcode */
|
|
|
|
|
|
+ /** -# nothing to do - just return errorcode */
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
@@ -333,7 +333,7 @@ static shellmatta_retCode_t shellmatta_opt_int( shellmatta_handle_t handle,
|
|
}
|
|
}
|
|
break;
|
|
break;
|
|
case SHELLMATTA_OPT_ARG_OPTIONAL:
|
|
case SHELLMATTA_OPT_ARG_OPTIONAL:
|
|
- /*! -# treat anything not starting with '-' as argument */
|
|
|
|
|
|
+ /** -# treat anything not starting with '-' as argument */
|
|
if('-' != peekNextHunk(inst))
|
|
if('-' != peekNextHunk(inst))
|
|
{
|
|
{
|
|
ret = findNextHunk(inst);
|
|
ret = findNextHunk(inst);
|
|
@@ -412,7 +412,7 @@ shellmatta_retCode_t shellmatta_opt_long( shellmatta_handle_t handle,
|
|
*/
|
|
*/
|
|
shellmatta_retCode_t shellmatta_opt_init(shellmatta_instance_t *inst, uint32_t argStart)
|
|
shellmatta_retCode_t shellmatta_opt_init(shellmatta_instance_t *inst, uint32_t argStart)
|
|
{
|
|
{
|
|
- /*! -# initialize all relevant option parser variables */
|
|
|
|
|
|
+ /** -# initialize all relevant option parser variables */
|
|
inst->optionParser.nextOffset = argStart;
|
|
inst->optionParser.nextOffset = argStart;
|
|
|
|
|
|
return SHELLMATTA_OK;
|
|
return SHELLMATTA_OK;
|