Skip to content

config: remove remaining "advanced" flags

Romain Vimont requested to merge rom1v/vlc:advc into master

The config "advanced" flag was unused and has been removed by 6a7a137f.

The unused parameter has been removed from many add_*() macros:

The parameter advc remained in 6 macros (but was unused internally):

  • add_string()
  • add_bool()
  • add_integer()
  • add_integer_with_range()
  • add_float()
  • add_float_with_range()

This MR removes them.

The diff may be view locally with:

git fetch origin merge-requests/200/head && git show FETCH_HEAD

It is humanly impossible to fix them manually.

It's not trivial to fix them automatically (for example with a simple sed):

  • many calls are multi-line
  • many calls contains quoted commas
  • many calls contains parameters with an additional level of parentheses

I initially wanted to use coccinelle with a patch looking like:

@@
expression a,b,c,d,e;
@@

-add_string(a,b,c,d,e)
+add_string(a,b,c,d)

Unfortunately, the specific syntax of VLC module macros could not be parsed:

parse error 
 = File "src/libvlc-module.c", line 1537, column 4, charpos = 67773
  around = 'set_description',
  whole content =     set_description( N_("core program") )

Then, I attempted to use simple regexes (and fix the remaining manually), but there were too many instances of add_*() with parameters containing a pair of parentheses, or string parameters containing commas, so it was too cumbersome.

I finally wrote a quick-and-dirty automaton:

#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

int main() {
    enum state {
        NONE,
        A,
        AD,
        ADD,
        ADD_,
        ADD_S,
        ADD_ST,
        ADD_STR,
        ADD_STRI,
        ADD_STRIN,
        ADD_STRING,
        ADD_I,
        ADD_IN,
        ADD_INT,
        ADD_INTE,
        ADD_INTEG,
        ADD_INTEGE,
        ADD_INTEGER,
        ADD_INTEGER_,
        ADD_INTEGER_W,
        ADD_INTEGER_WI,
        ADD_INTEGER_WIT,
        ADD_INTEGER_WITH,
        ADD_INTEGER_WITH_,
        ADD_INTEGER_WITH_R,
        ADD_INTEGER_WITH_RA,
        ADD_INTEGER_WITH_RAN,
        ADD_INTEGER_WITH_RANG,
        ADD_INTEGER_WITH_RANGE,
        ADD_B,
        ADD_BO,
        ADD_BOO,
        ADD_BOOL,
        ADD_F,
        ADD_FL,
        ADD_FLO,
        ADD_FLOA,
        ADD_FLOAT,
        ADD_FLOAT_,
        ADD_FLOAT_W,
        ADD_FLOAT_WI,
        ADD_FLOAT_WIT,
        ADD_FLOAT_WITH,
        ADD_FLOAT_WITH_,
        ADD_FLOAT_WITH_R,
        ADD_FLOAT_WITH_RA,
        ADD_FLOAT_WITH_RAN,
        ADD_FLOAT_WITH_RANG,
        ADD_FLOAT_WITH_RANGE,
    } state = NONE;

    bool inhibit = false;

    bool quote = false;
    unsigned paren = 0;
    unsigned param = 0;

    int previous = 0;
    int c;
#define TR(INIT,CHAR,NEW) \
    case INIT: \
        state = c == CHAR ? NEW : NONE; \
        break

    while ((c = getchar()) != -1) {
        switch (state) {
            case NONE:
                if (c == 'a')
                    state = A;
                break;
            TR(A, 'd', AD);
            TR(AD, 'd', ADD);
            TR(ADD, '_', ADD_);
            case ADD_:
                if (c == 's')
                    state = ADD_S;
                else if (c == 'i')
                    state = ADD_I;
                else if (c == 'b')
                    state = ADD_B;
                else if (c == 'f')
                    state = ADD_F;
                else
                    state = NONE;
                break;
            TR(ADD_S, 't', ADD_ST);
            TR(ADD_ST, 'r', ADD_STR);
            TR(ADD_STR, 'i', ADD_STRI);
            TR(ADD_STRI, 'n', ADD_STRIN);
            TR(ADD_STRIN, 'g', ADD_STRING);

            TR(ADD_I, 'n', ADD_IN);
            TR(ADD_IN, 't', ADD_INT);
            TR(ADD_INT, 'e', ADD_INTE);
            TR(ADD_INTE, 'g', ADD_INTEG);
            TR(ADD_INTEG, 'e', ADD_INTEGE);
            TR(ADD_INTEGE, 'r', ADD_INTEGER);

            TR(ADD_INTEGER_, 'w', ADD_INTEGER_W);
            TR(ADD_INTEGER_W, 'i', ADD_INTEGER_WI);
            TR(ADD_INTEGER_WI, 't', ADD_INTEGER_WIT);
            TR(ADD_INTEGER_WIT, 'h', ADD_INTEGER_WITH);
            TR(ADD_INTEGER_WITH, '_', ADD_INTEGER_WITH_);
            TR(ADD_INTEGER_WITH_, 'r', ADD_INTEGER_WITH_R);
            TR(ADD_INTEGER_WITH_R, 'a', ADD_INTEGER_WITH_RA);
            TR(ADD_INTEGER_WITH_RA, 'n', ADD_INTEGER_WITH_RAN);
            TR(ADD_INTEGER_WITH_RAN, 'g', ADD_INTEGER_WITH_RANG);
            TR(ADD_INTEGER_WITH_RANG, 'e', ADD_INTEGER_WITH_RANGE);

            TR(ADD_B, 'o', ADD_BO);
            TR(ADD_BO, 'o', ADD_BOO);
            TR(ADD_BOO, 'l', ADD_BOOL);

            TR(ADD_F, 'l', ADD_FL);
            TR(ADD_FL, 'o', ADD_FLO);
            TR(ADD_FLO, 'a', ADD_FLOA);
            TR(ADD_FLOA, 't', ADD_FLOAT);

            TR(ADD_FLOAT_, 'w', ADD_FLOAT_W);
            TR(ADD_FLOAT_W, 'i', ADD_FLOAT_WI);
            TR(ADD_FLOAT_WI, 't', ADD_FLOAT_WIT);
            TR(ADD_FLOAT_WIT, 'h', ADD_FLOAT_WITH);
            TR(ADD_FLOAT_WITH, '_', ADD_FLOAT_WITH_);
            TR(ADD_FLOAT_WITH_, 'r', ADD_FLOAT_WITH_R);
            TR(ADD_FLOAT_WITH_R, 'a', ADD_FLOAT_WITH_RA);
            TR(ADD_FLOAT_WITH_RA, 'n', ADD_FLOAT_WITH_RAN);
            TR(ADD_FLOAT_WITH_RAN, 'g', ADD_FLOAT_WITH_RANG);
            TR(ADD_FLOAT_WITH_RANG, 'e', ADD_FLOAT_WITH_RANGE);

            case ADD_INTEGER:
            case ADD_STRING:
            case ADD_BOOL:
            case ADD_FLOAT:
            case ADD_INTEGER_WITH_RANGE:
            case ADD_FLOAT_WITH_RANGE:
                if (paren == 0 && c == '_') {
                    if (state == ADD_FLOAT) {
                        state = ADD_FLOAT_;
                        break;
                    } else if (state == ADD_INTEGER) {
                        state = ADD_INTEGER_;
                        break;
                    }
                }
                if (paren == 0 && c != ' ' && c != '(') {
                    state = NONE;
                    break;
                }
                unsigned param_to_remove = 4;
                if (state == ADD_FLOAT_WITH_RANGE || state == ADD_INTEGER_WITH_RANGE)
                    param_to_remove += 2;
                switch (c) {
                    case ',':
                        if (!quote && paren < 2) {
                            ++param;
                            if (param >= param_to_remove)
                                inhibit = true;
                        }
                        break;
                    case '"':
                        quote = !quote; // escaping quotes is not managed
                        break;
                    case '(':
                        if (!quote)
                            ++paren;
                        break;
                    case ')':
                        if (!quote) {
                            --paren;
                            if (paren == 0) {
                                state = NONE;
                                param = 0;
                                if (inhibit && previous == ' ')
                                    putchar(' '); // leave a space if there was one
                                inhibit = false;
                            }
                        }
                        break;
                }
                break;
        }
        if (!inhibit)
            putchar(c);
        previous = c;
    }

    return 0;
}

And a little wrapper script, to run in the root VLC repository:

#!/bin/bash
cleanup() {
    echo "$1"
    <"$1" ./fix > /tmp/file
    mv /tmp/file "$1"
}

export -f cleanup
find include src modules -type f \( -name '*\.c' -o -name '*\.h' -o -name '*\.hpp' -o -name '*\.cpp' -o -name '\*.m' \) -exec bash -c 'cleanup "{}"' ';'

In the end, I had to fix 2 things manually (one due to a #ifdef and the other because the calls were hidden by an additional level of macros):

diff --git a/modules/demux/mock.c b/modules/demux/mock.c
index d645520ad0..3767d7b0ff 100644
--- a/modules/demux/mock.c
+++ b/modules/demux/mock.c
@@ -184,7 +184,7 @@ var_Read_float(const char *psz)
     READ(group_name##_##var_name, group_name.var_name, getter)
 
 #define DECLARE_MODULE_OPTIONS(var_name, type, module_header_type, getter, default_value) \
-    module_header_type("mock-"#var_name, default_value, #var_name, NULL, true) \
+    module_header_type("mock-"#var_name, default_value, #var_name, NULL) \
     change_volatile() \
     change_safe()
 #define DECLARE_MODULE_SUBOPTIONS(a,b,c,d,e,f) \
diff --git a/modules/gui/qt/qt.cpp b/modules/gui/qt/qt.cpp
index 7932954990..f486c3b634 100644
--- a/modules/gui/qt/qt.cpp
+++ b/modules/gui/qt/qt.cpp
@@ -339,7 +339,7 @@ vlc_module_begin ()
 #else
               true                               /* but not on linux */,
 #endif
-              QT_CLIENT_SIDE_DECORATION_TEXT )
+              QT_CLIENT_SIDE_DECORATION_TEXT, QT_CLIENT_SIDE_DECORATION_LONGTEXT )
 #endif
 
     add_bool( "qt-menubar", false, QT_MENUBAR_TEXT, QT_MENUBAR_LONGTEXT )

This MR is the result of the script + the patch above.

Edited by Romain Vimont

Merge request reports

Loading