pastebin

Paste #n8Q -- näytä pelkkänä tekstinä -- uusi tämän pohjalta

Värjäys: Tyyli: ensimmäinen rivinumero: Tabin korvaus:

  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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
Generating dependency matrix...
Squaring dependency matrix...
Squaring dependency matrix again...
Squaring dependency matrix again...
Squaring dependency matrix again...
ban.cpp	4
base64.cpp	1
biome.cpp	27
camera.cpp	61
cavegen.cpp	45
chat.cpp	13
client.cpp	70
clientmap.cpp	62
clientobject.cpp	14
clientserver.cpp	9
clouds.cpp	21
collision.cpp	41
connection.cpp	24
content_abm.cpp	58
content_cao.cpp	52
content_cso.cpp	37
content_mapblock.cpp	26
content_mapnode.cpp	17
content_nodemeta.cpp	21
content_sao.cpp	59
convert_json.cpp	19
craftdef.cpp	20
debug.cpp	5
defaultsettings.cpp	18
dungeongen.cpp	45
emerge.cpp	78
environment.cpp	68
farmesh.cpp	55
filecache.cpp	9
filesys.cpp	4
game.cpp	85
genericobject.cpp	12
guiChatConsole.cpp	59
guiDeathScreen.cpp	56
guiEngine.cpp	43
guiFileSelectMenu.cpp	10
guiFormSpecMenu.cpp	27
guiKeyChangeMenu.cpp	60
guiMessageMenu.cpp	16
guiPasswordChange.cpp	56
guiPauseMenu.cpp	21
guiTextInputMenu.cpp	28
guiVolumeChange.cpp	57
hud.cpp	56
intlGUIEditBox.cpp	8
inventory.cpp	20
inventorymanager.cpp	53
itemdef.cpp	33
keycode.cpp	18
light.cpp	6
localplayer.cpp	43
log.cpp	6
main.cpp	69
map.cpp	66
mapblock.cpp	41
mapblock_mesh.cpp	48
mapgen.cpp	55
mapgen_indev.cpp	46
mapgen_math.cpp	60
mapgen_singlenode.cpp	58
mapgen_v6.cpp	65
mapgen_v7.cpp	67
mapnode.cpp	20
mapsector.cpp	53
mesh.cpp	8
mods.cpp	22
nameidmapping.cpp	9
nodedef.cpp	27
nodemetadata.cpp	19
nodetimer.cpp	10
noise.cpp	10
object_properties.cpp	9
particles.cpp	43
pathfinder.cpp	47
player.cpp	33
porting.cpp	12
quicktune.cpp	4
rollback.cpp	24
rollback_interface.cpp	40
script/common/c_content.cpp	67
script/common/c_converter.cpp	9
script/common/c_internal.cpp	7
script/common/c_types.cpp	11
script/cpp_api/s_base.cpp	24
script/cpp_api/s_entity.cpp	16
script/cpp_api/s_env.cpp	49
script/cpp_api/s_inventory.cpp	24
script/cpp_api/s_item.cpp	56
script/cpp_api/s_mainmenu.cpp	11
script/cpp_api/s_node.cpp	57
script/cpp_api/s_nodemeta.cpp	57
script/cpp_api/s_player.cpp	6
script/cpp_api/s_server.cpp	11
script/cpp_api/scriptapi.cpp	28
script/lua_api/l_base.cpp	24
script/lua_api/l_craft.cpp	58
script/lua_api/l_env.cpp	80
script/lua_api/l_inventory.cpp	57
script/lua_api/l_item.cpp	71
script/lua_api/l_mainmenu.cpp	75
script/lua_api/l_mapgen.cpp	67
script/lua_api/l_nodemeta.cpp	45
script/lua_api/l_nodetimer.cpp	40
script/lua_api/l_noise.cpp	23
script/lua_api/l_object.cpp	64
script/lua_api/l_particles.cpp	55
script/lua_api/l_rollback.cpp	57
script/lua_api/l_server.cpp	56
script/lua_api/l_util.cpp	29
script/lua_api/l_vmanip.cpp	56
script/lua_api/luaapi.cpp	56
serialization.cpp	9
server.cpp	93
serverlist.cpp	21
serverobject.cpp	18
sha1.cpp	1
shader.cpp	22
sky.cpp	10
socket.cpp	18
sound.cpp	6
sound_openal.cpp	15
staticobject.cpp	12
subgame.cpp	18
test.cpp	50
tile.cpp	24
tool.cpp	19
treegen.cpp	37
util/directiontables.cpp	3
util/numeric.cpp	7
util/pointedthing.cpp	9
util/serialize.cpp	8
util/string.cpp	11
util/timetaker.cpp	4
voxel.cpp	35
voxelalgorithms.cpp	17




#!/usr/bin/env python2
# -*- coding: utf-8 -*-

# This program is free software. It comes without any warranty, to
# the extent permitted by applicable law. You can redistribute it
# and/or modify it under the terms of the Do What The Fuck You Want
# To Public License, Version 2, as published by Sam Hocevar. See
# COPYING for more details.

# 2013-08-11: made by kahrl

import os
import sys
import re
import getopt

scriptpath = os.path.abspath(__file__)
basepath = os.path.realpath(os.path.join(os.path.dirname(scriptpath), '../src'))
os.chdir(basepath)

def is_cpp(name):
    return name[-4:] == '.cpp'

def is_h(name):
    return name[-2:] == '.h'

def get_codefiles_set():
    subpaths = ['', 'script/common', 'script/cpp_api', 'script/lua_api', 'util']
    codefiles_set = set()
    for subpath in subpaths:
        for filename in os.listdir(os.path.join('.', subpath)):
            filepath = os.path.join(subpath, filename)
            if os.path.isfile(filepath):
                if is_cpp(filepath) or is_h(filepath):
                    codefiles_set.add(filepath)
    return codefiles_set

def get_included_file(includetext, curpath, codefiles_set):
    includepaths = [curpath, '', 'script']
    for includepath in includepaths:
        filepath = os.path.normpath(os.path.join(includepath, includetext))
        if filepath in codefiles_set:
            return filepath
    return None

def get_includes(filepath, codefiles_set):
    includes_set = set()
    curpath = os.path.dirname(filepath)
    with open(filepath) as f:
        for line in f:
            match = re.match(r'^\s*#\s*include\s+"([^"]+)"\s*$', line)
            if match:
                included_file = get_included_file(
                        match.group(1), curpath, codefiles_set)
                if included_file is not None:
                    includes_set.add(included_file)
                else:
                    #print(repr(line))
                    pass
    return sorted(includes_set)

def make_depend_matrix(codefiles, codefiles_set):
    n = len(codefiles)
    mat = [[0 for j in range(0,n)] for i in range(0,n)]
    codefiles_index = dict()
    for i in range(0,n):
        codefiles_index[codefiles[i]] = i
    for i in range(0,n):
        filepath = codefiles[i]
        for include in get_includes(filepath, codefiles_set):
            j = codefiles_index[include]
            mat[i][j] = 1
        mat[i][i] = 1
    return mat

def square_depend_matrix(mat):
    n = len(mat)
    mat2 = [[0 for j in range(0,n)] for i in range(0,n)]
    changed = False
    for i in range(0,n):
        for j in range(0,n):
            if mat[i][j] == 0:
                for k in range(0,n):
                    if mat[i][k] != 0 and mat[k][j] != 0:
                        mat2[i][j] = 1
                        changed = True
                        break
            else:
                mat2[i][j] = 1
    if changed:
        for i in range(0,n):
            mat[i] = mat2[i]
    return changed

def print_depends(codefiles, mat, only_sources):
    n = len(codefiles)
    for i in range(0,n):
        if not only_sources or is_cpp(codefiles[i]):
            for j in range(0,n):
                if i != j and mat[i][j] != 0:
                    print(codefiles[i] + '\t' + codefiles[j])

def print_depend_stats(codefiles, mat, only_sources):
    n = len(codefiles)
    for i in range(0,n):
        if not only_sources or is_cpp(codefiles[i]):
            # minus one because the diagonal of mat is ones,
            # but we don't want to count it
            print(codefiles[i] + '\t' + str(mat[i].count(1)-1))


codefiles_set = get_codefiles_set()
codefiles = sorted(codefiles_set)

sys.stderr.write('Generating dependency matrix...\n')
mat = make_depend_matrix(codefiles, codefiles_set)

sys.stderr.write('Squaring dependency matrix...\n')
while square_depend_matrix(mat):
    sys.stderr.write('Squaring dependency matrix again...\n')

print_depend_stats(codefiles, mat, True)