]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
Merge topic branch t/net into master
authorAndre Noll <maan@tuebingen.mpg.de>
Mon, 7 Nov 2022 16:34:31 +0000 (17:34 +0100)
committerAndre Noll <maan@tuebingen.mpg.de>
Mon, 7 Nov 2022 16:39:13 +0000 (17:39 +0100)
A moderately sized series which contains a bunch of simple cleanups
for net.c and net.h.

* refs/heads/t/net:
  net: De-doxify static functions.
  net: Refer to correct man page in stringify_port().
  net: Pass true/false instead of 0/1 to makesock().
  net: Demote log level of error message in makesock().
  net: Rename para_connect_simple() -> para_connect().
  net: Make is_valid_ipv{4,6}_address() local to net.c.
  net: Remove IPPROTO_DCCP define.
  net: Make single-use macros local.
  net: Combine documentation of struct flowopts.
  net: Drop extern keyword of function declarations.

Makefile.real
NEWS.md
client_common.c
error.h
gui_theme.c
mood.c
string.c
string.h

index 9c426673233f927d7d324c3cf76b970a0e2c23b2..bf3cb6e0ff0616f3618c778c11731651d9a4151c 100644 (file)
@@ -313,7 +313,7 @@ distclean: clean
        $(call SAY, DISTCLEAN)
        rm -f Makefile autoscan.log config.status config.log
        rm -f config.h configure config.h.in
-maintainer-clean: distclean
+maintainer-clean: distclean test-clean
        $(call SAY, MAINTAINER-CLEAN)
        rm -f *.tar.bz2 *.tar.xz
        rm -f GPATH GRTAGS GSYMS GTAGS
diff --git a/NEWS.md b/NEWS.md
index 5a00175c3255702b03ec86e0af1938863f53ba4d..c21cc858ef2c4ab5030a4f1e8996921dd9585513 100644 (file)
--- a/NEWS.md
+++ b/NEWS.md
@@ -1,6 +1,15 @@
 NEWS
 ====
 
+------------------------------------------
+0.7.2 (to be announced) "optical friction"
+------------------------------------------
+
+- Minor cleanup of the net subsystem.
+
+Downloads:
+[tarball](./releases/paraslash-git.tar.xz)
+
 --------------------------------------
 0.7.1 (2022-10-03) "digital spindrift"
 --------------------------------------
@@ -27,6 +36,7 @@ usual mix of bug fixes and minor improvements not mentioned here.
   requires support from the compiler, the oldest supported gcc version
   has been bumped to gcc-5.4 (released in 2015).
 
+Downloads:
 [tarball](./releases/paraslash-0.7.1.tar.xz),
 [signature](./releases/paraslash-0.7.1.tar.xz.asc)
 
index 9bcfcb827bb867674f8363f1d114b349c2fc7f76..95e59fd29de2015fcc65443a4ffc6442387ec0f8 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 6f4acf37a318834f95614ccc1365c12208048b90..f71e802b5c6561d4d5b7340209a76cebf3235206 100644 (file)
@@ -122,16 +122,16 @@ static void init_theme_colorful_blackness(struct gui_theme *t)
        d[SI_status_flags].align = LEFT;
        d[SI_status_flags].x = 11;
        d[SI_status_flags].y = 17;
-       d[SI_status_flags].len = 10;
+       d[SI_status_flags].len = 8;
 
        d[SI_image_id].prefix = "img: ";
        d[SI_image_id].postfix = "";
        d[SI_image_id].color.fg = COLOR_RED;
        d[SI_image_id].color.bg = COLOR_BLACK;
        d[SI_image_id].align = CENTER;
-       d[SI_image_id].x = 21;
+       d[SI_image_id].x = 19;
        d[SI_image_id].y = 17;
-       d[SI_image_id].len = 10;
+       d[SI_image_id].len = 12;
 
        d[SI_lyrics_id].prefix = "lyr: ";
        d[SI_lyrics_id].postfix = "";
diff --git a/mood.c b/mood.c
index bcc9bc57d1a37520ca71f93d5d93a7fe1e2e2927..d47c54efa360b856c63b660fd4cdb5b81d442b68 100644 (file)
--- a/mood.c
+++ b/mood.c
@@ -249,20 +249,22 @@ int mood_check_callback(struct afs_callback_arg *aca)
  * overflows and rounding errors we store the common divisor of the
  * correction factors separately.
  */
-static int64_t normalized_value(int64_t x, int64_t n, int64_t sum, int64_t qd)
-{
-       if (!n || !qd)
-               return 0;
-       return 100 * (n * x - sum) / (int64_t)int_sqrt(n) / (int64_t)int_sqrt(qd);
-}
-
 static long compute_score(struct afs_info *afsi)
 {
-       long score = -normalized_value(afsi->num_played, statistics.num,
-               statistics.num_played_sum, statistics.num_played_qd);
-       score -= normalized_value(afsi->last_played, statistics.num,
-               statistics.last_played_sum, statistics.last_played_qd);
-       return score / 2;
+       int64_t mean_n, mean_l,score_n, score_l;
+
+       assert(statistics.normalization_divisor > 0);
+       assert(statistics.num > 0);
+       mean_n = statistics.num_played_sum / statistics.num;
+       mean_l = statistics.last_played_sum / statistics.num;
+
+       score_n = -((int64_t)afsi->num_played - mean_n)
+               * statistics.num_played_correction
+               / statistics.normalization_divisor;
+       score_l = -((int64_t)afsi->last_played - mean_l)
+               * statistics.last_played_correction
+               / statistics.normalization_divisor;
+       return (score_n + score_l) / 2;
 }
 
 static int add_afs_statistics(const struct osl_row *row)
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);