You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by GitBox <gi...@apache.org> on 2018/06/28 06:20:23 UTC
[GitHub] kasjer commented on a change in pull request #1127: util/cmd:
Package for parsing = pairs.
kasjer commented on a change in pull request #1127: util/cmd: Package for parsing <key>=<value> pairs.
URL: https://github.com/apache/mynewt-core/pull/1127#discussion_r198718068
##########
File path: util/cmd/include/cmd/cmd.h
##########
@@ -0,0 +1,694 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#ifndef H_UTIL_CMD_
+#define H_UTIL_CMD_
+
+#include <inttypes.h>
+#include <stdbool.h>
+struct mn_in6_addr;
+
+/**
+ * @brief Finds the argument with the specified key.
+ *
+ * Given a key, finds the first argument with the following contents:
+ *
+ * <key>=[val]
+ *
+ * @param argc The argument count.
+ * @param argv The argument list.
+ * @param key The key to search for.
+ * @param out_val On success, points to the start of the located
+ * value string.
+ *
+ * @return Pointer to argument on success; -1 on failure.
+ */
+char *cmd_arg_find(int argc, char **argv, const char *key, char **out_val);
+
+/**
+ * @brief Extracts the argument with the specified key.
+ *
+ * Given a key, finds the first argument with the following contents:
+ *
+ * <key>=[val]
+ *
+ * This function modifies the argument list such that this argument won't be
+ * found on a subsequent search.
+ *
+ * @param argc The argument count.
+ * @param argv The argument list.
+ * @param key The key to search for.
+ * @param out_val On success, points to the start of the located
+ * value string.
+ *
+ * @return Pointer to argument on success; -1 on failure.
+ */
+char *cmd_arg_extract(int argc, char **argv, const char *key, char **out_val);
+
+/**
+ * @brief Finds a string value with the specified key.
+ *
+ * Given a key, finds the first argument with the following contents:
+ *
+ * <key>=[val]
+ *
+ * @param argc The argument count.
+ * @param argv The argument list.
+ * @param key The key to search for.
+ * @param out_s On success, points to the start of the located
+ * value string.
+ *
+ * @return 0 on success; system error code on failure.
+ */
+int cmd_arg_find_str(int argc, char **argv, const char *key, char **out_s);
Review comment:
argv and out_s could be const char ** since strings are not changed just array, this applies to all the functions, but this could be a valid design decision to not have const
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services