15129044dSC.J. Collier/*-
25129044dSC.J. Collier *   BSD LICENSE
35129044dSC.J. Collier *
45129044dSC.J. Collier *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
55129044dSC.J. Collier *   All rights reserved.
65129044dSC.J. Collier *
75129044dSC.J. Collier *   Redistribution and use in source and binary forms, with or without
85129044dSC.J. Collier *   modification, are permitted provided that the following conditions
95129044dSC.J. Collier *   are met:
105129044dSC.J. Collier *
115129044dSC.J. Collier *     * Redistributions of source code must retain the above copyright
125129044dSC.J. Collier *       notice, this list of conditions and the following disclaimer.
135129044dSC.J. Collier *     * Redistributions in binary form must reproduce the above copyright
145129044dSC.J. Collier *       notice, this list of conditions and the following disclaimer in
155129044dSC.J. Collier *       the documentation and/or other materials provided with the
165129044dSC.J. Collier *       distribution.
175129044dSC.J. Collier *     * Neither the name of Intel Corporation nor the names of its
185129044dSC.J. Collier *       contributors may be used to endorse or promote products derived
195129044dSC.J. Collier *       from this software without specific prior written permission.
205129044dSC.J. Collier *
215129044dSC.J. Collier *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
225129044dSC.J. Collier *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
235129044dSC.J. Collier *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
245129044dSC.J. Collier *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
255129044dSC.J. Collier *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
265129044dSC.J. Collier *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
275129044dSC.J. Collier *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
285129044dSC.J. Collier *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
295129044dSC.J. Collier *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
305129044dSC.J. Collier *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
315129044dSC.J. Collier *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
325129044dSC.J. Collier */
335129044dSC.J. Collier
345129044dSC.J. Collier/*
355129044dSC.J. Collier * Copyright (c) 2009, Olivier MATZ <zer0@droids-corp.org>
365129044dSC.J. Collier * All rights reserved.
375129044dSC.J. Collier * Redistribution and use in source and binary forms, with or without
385129044dSC.J. Collier * modification, are permitted provided that the following conditions are met:
395129044dSC.J. Collier *
405129044dSC.J. Collier *     * Redistributions of source code must retain the above copyright
415129044dSC.J. Collier *       notice, this list of conditions and the following disclaimer.
425129044dSC.J. Collier *     * Redistributions in binary form must reproduce the above copyright
435129044dSC.J. Collier *       notice, this list of conditions and the following disclaimer in the
445129044dSC.J. Collier *       documentation and/or other materials provided with the distribution.
455129044dSC.J. Collier *     * Neither the name of the University of California, Berkeley nor the
465129044dSC.J. Collier *       names of its contributors may be used to endorse or promote products
475129044dSC.J. Collier *       derived from this software without specific prior written permission.
485129044dSC.J. Collier *
495129044dSC.J. Collier * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY
505129044dSC.J. Collier * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
515129044dSC.J. Collier * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
525129044dSC.J. Collier * DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY
535129044dSC.J. Collier * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
545129044dSC.J. Collier * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
555129044dSC.J. Collier * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
565129044dSC.J. Collier * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
575129044dSC.J. Collier * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
585129044dSC.J. Collier * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
595129044dSC.J. Collier */
605129044dSC.J. Collier
615129044dSC.J. Collier#ifndef _PARSE_STRING_H_
625129044dSC.J. Collier#define _PARSE_STRING_H_
635129044dSC.J. Collier
645129044dSC.J. Collier#include <cmdline_parse.h>
655129044dSC.J. Collier
665129044dSC.J. Collier#ifdef __cplusplus
675129044dSC.J. Collierextern "C" {
685129044dSC.J. Collier#endif
695129044dSC.J. Collier
705129044dSC.J. Collier/* size of a parsed string */
715129044dSC.J. Collier#define STR_TOKEN_SIZE 128
725129044dSC.J. Collier
73809f0800SChristian Ehrhardt/* size of a parsed multi string */
74809f0800SChristian Ehrhardt#define STR_MULTI_TOKEN_SIZE 4096
75809f0800SChristian Ehrhardt
765129044dSC.J. Colliertypedef char cmdline_fixed_string_t[STR_TOKEN_SIZE];
775129044dSC.J. Collier
78809f0800SChristian Ehrhardttypedef char cmdline_multi_string_t[STR_MULTI_TOKEN_SIZE];
79809f0800SChristian Ehrhardt
805129044dSC.J. Collierstruct cmdline_token_string_data {
815129044dSC.J. Collier	const char *str;
825129044dSC.J. Collier};
835129044dSC.J. Collier
845129044dSC.J. Collierstruct cmdline_token_string {
855129044dSC.J. Collier	struct cmdline_token_hdr hdr;
865129044dSC.J. Collier	struct cmdline_token_string_data string_data;
875129044dSC.J. Collier};
885129044dSC.J. Colliertypedef struct cmdline_token_string cmdline_parse_token_string_t;
895129044dSC.J. Collier
905129044dSC.J. Collierextern struct cmdline_token_ops cmdline_token_string_ops;
915129044dSC.J. Collier
925129044dSC.J. Collierint cmdline_parse_string(cmdline_parse_token_hdr_t *tk, const char *srcbuf,
935129044dSC.J. Collier	void *res, unsigned ressize);
945129044dSC.J. Collierint cmdline_complete_get_nb_string(cmdline_parse_token_hdr_t *tk);
955129044dSC.J. Collierint cmdline_complete_get_elt_string(cmdline_parse_token_hdr_t *tk, int idx,
965129044dSC.J. Collier				    char *dstbuf, unsigned int size);
975129044dSC.J. Collierint cmdline_get_help_string(cmdline_parse_token_hdr_t *tk, char *dstbuf,
985129044dSC.J. Collier			    unsigned int size);
995129044dSC.J. Collier
100809f0800SChristian Ehrhardt/**
101809f0800SChristian Ehrhardt* Token marked as TOKEN_STRING_MULTI takes entire parsing string
102809f0800SChristian Ehrhardt* until “#” sign appear. Everything after “#” sign is treated as a comment.
103809f0800SChristian Ehrhardt*
104809f0800SChristian Ehrhardt* Note:
105809f0800SChristian Ehrhardt* In this case second parameter of TOKEN_STRING_INITIALIZER must be a type of
106809f0800SChristian Ehrhardt* cmdline_multi_string_t.
107809f0800SChristian Ehrhardt*/
108809f0800SChristian Ehrhardt#define TOKEN_STRING_MULTI ""
109809f0800SChristian Ehrhardt
1105129044dSC.J. Collier#define TOKEN_STRING_INITIALIZER(structure, field, string)  \
1115129044dSC.J. Collier{                                                           \
1125129044dSC.J. Collier	/* hdr */                                               \
1135129044dSC.J. Collier	{                                                       \
1145129044dSC.J. Collier		&cmdline_token_string_ops,      /* ops */           \
1155129044dSC.J. Collier		offsetof(structure, field),     /* offset */        \
1165129044dSC.J. Collier	},                                                      \
1175129044dSC.J. Collier	/* string_data */                                       \
1185129044dSC.J. Collier	{                                                       \
1195129044dSC.J. Collier		string,                         /* str */           \
1205129044dSC.J. Collier	},                                                      \
1215129044dSC.J. Collier}
1225129044dSC.J. Collier
1235129044dSC.J. Collier#ifdef __cplusplus
1245129044dSC.J. Collier}
1255129044dSC.J. Collier#endif
1265129044dSC.J. Collier
1275129044dSC.J. Collier#endif /* _PARSE_STRING_H_ */
128