]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
Open-code find_arg().
authorAndre Noll <maan@tuebingen.mpg.de>
Thu, 25 Aug 2022 14:33:29 +0000 (16:33 +0200)
committerAndre Noll <maan@tuebingen.mpg.de>
Mon, 3 Oct 2022 20:42:13 +0000 (22:42 +0200)
There is only one caller in client_common.c, so open-code the logic
there and get rid of the public function and the unused error code.

client_common.c
error.h
string.c
string.h

index f476a1c4ada24ddf4a7c5a825048ab7df9e7d9f5..64f6c67612a5c665b87dcdb8d3e051bc7500b455 100644 (file)
@@ -255,9 +255,15 @@ static int send_sb_command(struct client_task *ct)
        return send_sb(ct, 0, command, len, SBD_COMMAND, false);
 }
 
+/* Find out if the given string is contained in the features vector. */
 static bool has_feature(const char *feature, struct client_task *ct)
 {
-       return find_arg(feature, ct->features) >= 0? true : false;
+       if (!ct->features)
+               return false;
+       for (int i = 0; ct->features[i]; i++)
+               if (strcmp(feature, ct->features[i]) == 0)
+                       return i;
+       return false;
 }
 
 /*
diff --git a/error.h b/error.h
index a644b96777db3ea27803d870babe49b0e744de4b..82920ea8007e0d17d9de4b02ead6d402c9a334b4 100644 (file)
--- a/error.h
+++ b/error.h
@@ -29,7 +29,6 @@
        PARA_ERROR(AO_OPEN_LIVE, "ao: could not open audio device"), \
        PARA_ERROR(AO_PLAY, "ao_play() failed"), \
        PARA_ERROR(AO_PTHREAD, "pthread error"), \
-       PARA_ERROR(ARG_NOT_FOUND, "argument not found in arg vector"), \
        PARA_ERROR(ASN1_PARSE, "could not parse ASN.1 key"), \
        PARA_ERROR(ATOI_JUNK_AT_END, "further characters after number"), \
        PARA_ERROR(ATOI_NO_DIGITS, "no digits found in string"), \
index 2c6d35d60e7c69900826f8ddbbd7b1e16fb8cbd4..46b346235f17ffb696f43d22d3dcfde4c75ba4ca 100644 (file)
--- a/string.c
+++ b/string.c
@@ -806,27 +806,6 @@ int create_shifted_argv(const char *buf, const char *delim, char ***result)
        return create_argv_offset(1, buf, delim, result);
 }
 
-/**
- * Find out if the given string is contained in the arg vector.
- *
- * \param arg The string to look for.
- * \param argv The array to search.
- *
- * \return The first index whose value equals \a arg, or \p -E_ARG_NOT_FOUND if
- * arg was not found in \a argv.
- */
-int find_arg(const char *arg, char **argv)
-{
-       int i;
-
-       if (!argv)
-               return -E_ARG_NOT_FOUND;
-       for (i = 0; argv[i]; i++)
-               if (strcmp(arg, argv[i]) == 0)
-                       return i;
-       return -E_ARG_NOT_FOUND;
-}
-
 /**
  * Compile a regular expression.
  *
index 060d65403bc5b0294010b582032eb5ed8ab10d49..d773600fbf0a0168584235a5098beabb110a3416 100644 (file)
--- a/string.h
+++ b/string.h
@@ -88,7 +88,6 @@ int para_atoi32(const char *str, int32_t *value);
 int read_size_header(const char *buf);
 int create_argv(const char *buf, const char *delim, char ***result);
 int create_shifted_argv(const char *buf, const char *delim, char ***result);
-int find_arg(const char *arg, char **argv);
 void free_argv(char **argv);
 int para_regcomp(regex_t *preg, const char *regex, int cflags);
 void freep(void *arg);