uncrustify as demanded.
[oweals/gnunet.git] / src / fs / fs_getopt.c
index bfe45957e99c313a41954bcfadd8ed87398fcca1..4f53f64a54c0cd88c792976ee86152840c9aad03 100644 (file)
@@ -2,21 +2,21 @@
      This file is part of GNUnet.
      Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009 GNUnet e.V.
 
-     GNUnet is free software; you can redistribute it and/or modify
-     it under the terms of the GNU General Public License as published
-     by the Free Software Foundation; either version 3, or (at your
-     option) any later version.
+     GNUnet is free software: you can redistribute it and/or modify it
+     under the terms of the GNU Affero General Public License as published
+     by the Free Software Foundation, either version 3 of the License,
+     or (at your option) any later version.
 
      GNUnet is distributed in the hope that it will be useful, but
      WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-     General Public License for more details.
+     Affero General Public License for more details.
 
-     You should have received a copy of the GNU General Public License
-     along with GNUnet; see the file COPYING.  If not, write to the
-     Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-     Boston, MA 02110-1301, USA.
-*/
+     You should have received a copy of the GNU Affero General Public License
+     along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+     SPDX-License-Identifier: AGPL3.0-or-later
+ */
 
 /**
  * @file fs/fs_getopt.c
  * @param scls must be of type "struct GNUNET_FS_Uri **"
  * @param option name of the option (typically 'k')
  * @param value command line argument given
- * @return GNUNET_OK on success
+ * @return #GNUNET_OK on success
  */
 static int
-getopt_set_keywords (struct GNUNET_GETOPT_CommandLineProcessorContext
-                     *ctx, void *scls, const char *option,
-                      const char *value)
+getopt_set_keywords(struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
+                    void *scls,
+                    const char *option,
+                    const char *value)
 {
   struct GNUNET_FS_Uri **uri = scls;
   struct GNUNET_FS_Uri *u = *uri;
   char *val;
   size_t slen;
 
-  if (u == NULL)
-  {
-    u = GNUNET_new (struct GNUNET_FS_Uri);
-    *uri = u;
-    u->type = GNUNET_FS_URI_KSK;
-    u->data.ksk.keywordCount = 0;
-    u->data.ksk.keywords = NULL;
-  }
-  else
-  {
-    GNUNET_assert (u->type == GNUNET_FS_URI_KSK);
-  }
-  slen = strlen (value);
-  if (slen == 0)
-    return GNUNET_SYSERR;       /* cannot be empty */
-  if (value[0] == '+')
-  {
-    /* simply preserve the "mandatory" flag */
-    if (slen < 2)
-      return GNUNET_SYSERR;     /* empty keywords not allowed */
-    if ((value[1] == '"') && (slen > 3) && (value[slen - 1] == '"'))
+  if (NULL == u)
     {
-      /* remove the quotes, keep the '+' */
-      val = GNUNET_malloc (slen - 1);
-      val[0] = '+';
-      GNUNET_memcpy (&val[1], &value[2], slen - 3);
-      val[slen - 2] = '\0';
+      u = GNUNET_new(struct GNUNET_FS_Uri);
+      *uri = u;
+      u->type = GNUNET_FS_URI_KSK;
+      u->data.ksk.keywordCount = 0;
+      u->data.ksk.keywords = NULL;
     }
-    else
+  else
     {
-      /* no quotes, just keep the '+' */
-      val = GNUNET_strdup (value);
+      GNUNET_assert(GNUNET_FS_URI_KSK == u->type);
     }
-  }
-  else
-  {
-    if ((value[0] == '"') && (slen > 2) && (value[slen - 1] == '"'))
+  slen = strlen(value);
+  if (0 == slen)
+    return GNUNET_SYSERR;       /* cannot be empty */
+  if (value[0] == '+')
     {
-      /* remove the quotes, add a space */
-      val = GNUNET_malloc (slen);
-      val[0] = ' ';
-      GNUNET_memcpy (&val[1], &value[1], slen - 2);
-      val[slen - 1] = '\0';
+      /* simply preserve the "mandatory" flag */
+      if (slen < 2)
+        return GNUNET_SYSERR;   /* empty keywords not allowed */
+      if ((value[1] == '"') && (slen > 3) && (value[slen - 1] == '"'))
+        {
+          /* remove the quotes, keep the '+' */
+          val = GNUNET_malloc(slen - 1);
+          val[0] = '+';
+          GNUNET_memcpy(&val[1],
+                        &value[2],
+                        slen - 3);
+          val[slen - 2] = '\0';
+        }
+      else
+        {
+          /* no quotes, just keep the '+' */
+          val = GNUNET_strdup(value);
+        }
     }
-    else
+  else
     {
-      /* add a space to indicate "not mandatory" */
-      val = GNUNET_malloc (slen + 2);
-      strcpy (val, " ");
-      strcat (val, value);
+      if ((value[0] == '"') && (slen > 2) && (value[slen - 1] == '"'))
+        {
+          /* remove the quotes, add a space */
+          val = GNUNET_malloc(slen);
+          val[0] = ' ';
+          GNUNET_memcpy(&val[1],
+                        &value[1],
+                        slen - 2);
+          val[slen - 1] = '\0';
+        }
+      else
+        {
+          /* add a space to indicate "not mandatory" */
+          val = GNUNET_malloc(slen + 2);
+          strcpy(val, " ");
+          strcat(val, value);
+        }
     }
-  }
-  GNUNET_array_append (u->data.ksk.keywords, u->data.ksk.keywordCount, val);
+  GNUNET_array_append(u->data.ksk.keywords,
+                      u->data.ksk.keywordCount,
+                      val);
   return GNUNET_OK;
 }
 
+
 /**
  * Allow user to specify keywords.
  *
@@ -118,11 +126,11 @@ getopt_set_keywords (struct GNUNET_GETOPT_CommandLineProcessorContext
  * @param[out] topKeywords set to the desired value
  */
 struct GNUNET_GETOPT_CommandLineOption
-GNUNET_FS_GETOPT_KEYWORDS (char shortName,
-                           const char *name,
-                           const char *argumentHelp,
-                           const char *description,
-                           struct GNUNET_FS_Uri **topKeywords)
+GNUNET_FS_GETOPT_KEYWORDS(char shortName,
+                          const char *name,
+                          const char *argumentHelp,
+                          const char *description,
+                          struct GNUNET_FS_Uri **topKeywords)
 {
   struct GNUNET_GETOPT_CommandLineOption clo = {
     .shortName = shortName,
@@ -131,12 +139,13 @@ GNUNET_FS_GETOPT_KEYWORDS (char shortName,
     .description = description,
     .require_argument = 1,
     .processor = &getopt_set_keywords,
-    .scls = (void *) topKeywords  
+    .scls = (void *)topKeywords
   };
 
   return clo;
 }
 
+
 /**
  * Command-line option parser function that allows the user to specify
  * one or more '-m' options with metadata.  Each specified entry of
@@ -150,12 +159,13 @@ GNUNET_FS_GETOPT_KEYWORDS (char shortName,
  * @return #GNUNET_OK on success
  */
 static int
-getopt_set_metadata (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
-                     void *scls,
-                     const char *option,
-                     const char *value)
+getopt_set_metadata(struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
+                    void *scls,
+                    const char *option,
+                    const char *value)
 {
   struct GNUNET_CONTAINER_MetaData **mm = scls;
+
 #if HAVE_EXTRACTOR_H && HAVE_LIBEXTRACTOR
   enum EXTRACTOR_MetaType type;
   const char *typename;
@@ -166,66 +176,66 @@ getopt_set_metadata (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
 
   meta = *mm;
   if (meta == NULL)
-  {
-    meta = GNUNET_CONTAINER_meta_data_create ();
-    *mm = meta;
-  }
+    {
+      meta = GNUNET_CONTAINER_meta_data_create();
+      *mm = meta;
+    }
 
   /* Use GNUNET_STRINGS_get_utf8_args() in main() to acquire utf-8-encoded
    * commandline arguments, so that the following line is not needed.
    */
   /*tmp = GNUNET_STRINGS_to_utf8 (value, strlen (value), locale_charset ());*/
-  tmp = GNUNET_strdup (value);
+  tmp = GNUNET_strdup(value);
 #if HAVE_EXTRACTOR_H && HAVE_LIBEXTRACTOR
-  type = EXTRACTOR_metatype_get_max ();
+  type = EXTRACTOR_metatype_get_max();
   while (type > 0)
-  {
-    type--;
-    typename = EXTRACTOR_metatype_to_string (type);
-    typename_i18n = dgettext (LIBEXTRACTOR_GETTEXT_DOMAIN, typename);
-    if ((strlen (tmp) >= strlen (typename) + 1) &&
-        (tmp[strlen (typename)] == ':') &&
-        (0 == strncmp (typename, tmp, strlen (typename))))
-    {
-      GNUNET_CONTAINER_meta_data_insert (meta, "<gnunet>", type,
-                                         EXTRACTOR_METAFORMAT_UTF8,
-                                         "text/plain",
-                                         &tmp[strlen (typename) + 1],
-                                         strlen (&tmp[strlen (typename) + 1]) +
-                                         1);
-      GNUNET_free (tmp);
-      tmp = NULL;
-      break;
-    }
-    if ((strlen (tmp) >= strlen (typename_i18n) + 1) &&
-        (tmp[strlen (typename_i18n)] == ':') &&
-        (0 == strncmp (typename_i18n, tmp, strlen (typename_i18n))))
     {
-      GNUNET_CONTAINER_meta_data_insert (meta, "<gnunet>", type,
-                                         EXTRACTOR_METAFORMAT_UTF8,
-                                         "text/plain",
-                                         &tmp[strlen (typename_i18n) + 1],
-                                         strlen (&tmp
-                                                 [strlen (typename_i18n) + 1]) +
-                                         1);
-      GNUNET_free (tmp);
-      tmp = NULL;
-      break;
+      type--;
+      typename = EXTRACTOR_metatype_to_string(type);
+      typename_i18n = dgettext(LIBEXTRACTOR_GETTEXT_DOMAIN, typename);
+      if ((strlen(tmp) >= strlen(typename) + 1) &&
+          (tmp[strlen(typename)] == ':') &&
+          (0 == strncmp(typename, tmp, strlen(typename))))
+        {
+          GNUNET_CONTAINER_meta_data_insert(meta, "<gnunet>", type,
+                                            EXTRACTOR_METAFORMAT_UTF8,
+                                            "text/plain",
+                                            &tmp[strlen(typename) + 1],
+                                            strlen(&tmp[strlen(typename) + 1]) +
+                                            1);
+          GNUNET_free(tmp);
+          tmp = NULL;
+          break;
+        }
+      if ((strlen(tmp) >= strlen(typename_i18n) + 1) &&
+          (tmp[strlen(typename_i18n)] == ':') &&
+          (0 == strncmp(typename_i18n, tmp, strlen(typename_i18n))))
+        {
+          GNUNET_CONTAINER_meta_data_insert(meta, "<gnunet>", type,
+                                            EXTRACTOR_METAFORMAT_UTF8,
+                                            "text/plain",
+                                            &tmp[strlen(typename_i18n) + 1],
+                                            strlen(&tmp
+                                                   [strlen(typename_i18n) + 1]) +
+                                            1);
+          GNUNET_free(tmp);
+          tmp = NULL;
+          break;
+        }
     }
-  }
 #endif
 
   if (NULL != tmp)
-  {
-    GNUNET_CONTAINER_meta_data_insert (meta, "<gnunet>",
-                                       EXTRACTOR_METATYPE_UNKNOWN,
-                                       EXTRACTOR_METAFORMAT_UTF8, "text/plain",
-                                       tmp, strlen (tmp) + 1);
-    GNUNET_free (tmp);
-    printf (_
-            ("Unknown metadata type in metadata option `%s'.  Using metadata type `unknown' instead.\n"),
-            value);
-  }
+    {
+      GNUNET_CONTAINER_meta_data_insert(meta, "<gnunet>",
+                                        EXTRACTOR_METATYPE_UNKNOWN,
+                                        EXTRACTOR_METAFORMAT_UTF8, "text/plain",
+                                        tmp, strlen(tmp) + 1);
+      GNUNET_free(tmp);
+      printf(_
+               ("Unknown metadata type in metadata option `%s'.  Using metadata type `unknown' instead.\n"),
+             value);
+    }
   return GNUNET_OK;
 }
 
@@ -239,11 +249,11 @@ getopt_set_metadata (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
  * @param[out] metadata set to the desired value
  */
 struct GNUNET_GETOPT_CommandLineOption
-GNUNET_FS_GETOPT_METADATA (char shortName,
-                           const char *name,
-                           const char *argumentHelp,
-                           const char *description,
-                           struct GNUNET_CONTAINER_MetaData **meta)
+GNUNET_FS_GETOPT_METADATA(char shortName,
+                          const char *name,
+                          const char *argumentHelp,
+                          const char *description,
+                          struct GNUNET_CONTAINER_MetaData **meta)
 {
   struct GNUNET_GETOPT_CommandLineOption clo = {
     .shortName = shortName,
@@ -252,7 +262,7 @@ GNUNET_FS_GETOPT_METADATA (char shortName,
     .description = description,
     .require_argument = 1,
     .processor = &getopt_set_metadata,
-    .scls = (void *) meta
+    .scls = (void *)meta
   };
 
   return clo;