Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: c1fd71a9a8fc7447d705fc1e0b56e2ad58c4623d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#!/usr/bin/python3
#*******************************************************************************
# Copyright (c) 2016 The Eclipse Foundation and others.
#
# This program and the accompanying materials
# are made available under the terms of the Eclipse Public License 2.0
# which accompanies this distribution, and is available at
# https://www.eclipse.org/legal/epl-2.0/
#
# SPDX-License-Identifier: EPL-2.0
#
# Contributors:
#     Rolf Theunissen - initial version, adapted from dynamic_deprecated.py
#*******************************************************************************

import sys
import re
from urllib.request import urlopen
from html.parser import HTMLParser

API_GTK2_STABLE_URL = "https://developer.gnome.org/gtk2/stable/api-index-full.html"
API_GTK3_0_URL = "https://developer.gnome.org/gtk3/3.0/api-index-full.html"
API_GTK3_STABLE_URL = "https://developer.gnome.org/gtk3/stable/api-index-full.html"
API_GTK3_DEPRECATED_URL = "https://developer.gnome.org/gtk3/stable/api-index-deprecated.html"

OS_FILE = "./../../org.eclipse.swt/Eclipse SWT PI/gtk/library/os.c"
FUNCTION_LIST = []
GTK2_FUNCTION_LIST = []
GTK30_FUNCTION_LIST = []
GTK3x_FUNCTION_LIST = []
GTK3x_DEPR_FUNCTION_LIST = []

GTK2_GTK30_SHARED_FUNCTION_LIST = []
GTK2_GTK3x_SHARED_FUNCTION_LIST = []

# This script is Python 3 only.
#
# USAGE OPTIONS:
# <no option specified>: prints list of deprecated dynamic functions to console.
# -f: writes the list of deprecated dynamic functions to a file called dynamic_deprecated_functions.txt.
#     The file is in the same directory as the script

def download_symbols(api_url):
    # Fetch symbols from api_url
    with urlopen(api_url) as url:
        dep_file = url.read()

    return str(dep_file);

def download_gtk2_stable_symbols():
    return download_symbols(API_GTK2_STABLE_URL);

def download_gtk3_0_symbols():
    return download_symbols(API_GTK3_0_URL);

def download_gtk3_stable_symbols():
    return download_symbols(API_GTK3_STABLE_URL);

def download_gtk3_deprecated_symbols():
    return download_symbols(API_GTK3_DEPRECATED_URL);

def populate_function_list():
    # Read os_custom.h from file
    with open(OS_FILE) as f:
        os_custom = f.read()

    return str(os_custom);

def find_gtk_version_functions(custom_str, gtk2_str, gtk30_str, gtk3x_str, gtk3x_dpr_str):
    regex = r"((GTK|GDK)_LOAD_FUNCTION\(fp, (\w+))+"
    matchList = re.findall(regex, custom_str)

    # Search through list of regex matches, strip the "_LIB" and populate
    # the dynamic function list.
    for match in matchList:
        function_name = match[2]
        FUNCTION_LIST.append(function_name)

    # Check each dynamic function and see if it's deprecated: if so, populate
    # the deprecated function list.
    for func in FUNCTION_LIST:
        func_tag = ">" + func + "<"
        if func_tag in gtk2_str:
            GTK2_FUNCTION_LIST.append(func)
        if func_tag in gtk30_str:
            GTK30_FUNCTION_LIST.append(func)
        if func_tag in gtk3x_str:
            GTK3x_FUNCTION_LIST.append(func)
        if func_tag in gtk3x_dpr_str:
            GTK3x_DEPR_FUNCTION_LIST.append(func)
    return;

def find_gtk2_and_gtk3_shared():
    for func in GTK2_FUNCTION_LIST:
        if func in GTK30_FUNCTION_LIST:
            GTK2_GTK30_SHARED_FUNCTION_LIST.append(func)
        elif func in GTK30_FUNCTION_LIST:
            GTK2_GTK3x_SHARED_FUNCTION_LIST.append(func)


if __name__ == "__main__":
    gtk2functions = download_gtk2_stable_symbols()
    gtk30functions = download_gtk3_0_symbols()
    gtk3xfunctions = download_gtk3_stable_symbols()
    gtk3xdeprecated = download_gtk3_deprecated_symbols()

    os_custom_str = populate_function_list()

    find_gtk_version_functions(os_custom_str, gtk2functions, gtk30functions,
            gtk3xfunctions, gtk3xdeprecated)

    find_gtk2_and_gtk3_shared()

    # If the user specified the "-f" option, the output will be written to
    # a file named "dynamic_deprecated_functions.txt"
    if len(sys.argv) == 2 and "-f" in str(sys.argv):
        with open("dynamic_gtk2x_gtk30_shared_functions.txt","w") as f:
            for i in GTK2_GTK30_SHARED_FUNCTION_LIST:
                if i in GTK3x_DEPR_FUNCTION_LIST:
                    f.write ("#")
                f.write(i + "\n")
            f.close()
        with open("dynamic_gtk2x_gtk3x_shared_functions.txt","w") as f:
            for i in GTK2_GTK3x_SHARED_FUNCTION_LIST:
                if i in GTK3x_DEPR_FUNCTION_LIST:
                    f.write ("#")
                f.write(i + "\n")
            f.close()
    # If no options are specified, print the list to console
    else:
        print ("# GTK2.x - GTK3.0 SHARED")
        for i in GTK2_GTK30_SHARED_FUNCTION_LIST:
            if i in GTK3x_DEPR_FUNCTION_LIST:
                print("#" + i)
            else:
                print(i)

        print()
        print ("# GTK2.x - GTK3.x SHARED")
        for i in GTK2_GTK3x_SHARED_FUNCTION_LIST:
            if i in GTK3x_DEPR_FUNCTION_LIST:
                print("#" + i)
            else:
                print(i)
    sys.exit(0)

Back to the top