2015-07-11 07:51:30 +02:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
2013-07-19 18:29:53 +02:00
|
|
|
import glob
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
|
2013-08-04 12:01:34 +02:00
|
|
|
verbose = '--verbose' in sys.argv
|
|
|
|
dump = '--dump' in sys.argv
|
|
|
|
internal = '--internal' in sys.argv
|
|
|
|
|
2013-07-19 18:29:53 +02:00
|
|
|
paths = ['include/libtorrent/*.hpp', 'include/libtorrent/kademlia/*.hpp', 'include/libtorrent/extensions/*.hpp']
|
|
|
|
|
2013-08-04 12:01:34 +02:00
|
|
|
if internal:
|
|
|
|
paths.append('include/libtorrent/aux_/*.hpp')
|
|
|
|
|
2013-07-19 18:29:53 +02:00
|
|
|
files = []
|
|
|
|
|
|
|
|
for p in paths:
|
|
|
|
files.extend(glob.glob(os.path.join('..', p)))
|
|
|
|
|
|
|
|
functions = []
|
|
|
|
classes = []
|
|
|
|
enums = []
|
|
|
|
|
2013-07-21 23:23:21 +02:00
|
|
|
# maps filename to overview description
|
|
|
|
overviews = {}
|
|
|
|
|
2013-07-19 18:29:53 +02:00
|
|
|
# maps names -> URL
|
|
|
|
symbols = {}
|
|
|
|
|
2013-08-11 18:57:33 +02:00
|
|
|
# some files that need pre-processing to turn symbols into
|
|
|
|
# links into the reference documentation
|
|
|
|
preprocess_rst = \
|
|
|
|
{
|
|
|
|
'manual.rst':'manual-ref.rst',
|
2014-07-06 21:18:00 +02:00
|
|
|
'settings.rst':'settings-ref.rst'
|
2013-08-11 18:57:33 +02:00
|
|
|
}
|
2013-08-11 08:04:24 +02:00
|
|
|
|
2013-08-11 18:57:33 +02:00
|
|
|
# some pre-defined sections from the main manual
|
2013-08-11 08:04:24 +02:00
|
|
|
symbols = \
|
|
|
|
{
|
2013-08-12 05:18:43 +02:00
|
|
|
"queuing_": "manual-ref.html#queuing",
|
|
|
|
"fast-resume_": "manual-ref.html#fast-resume",
|
|
|
|
"storage-allocation_": "manual-ref.html#storage-allocation",
|
|
|
|
"alerts_": "manual-ref.html#alerts",
|
|
|
|
"upnp-and-nat-pmp_": "manual-ref.html#upnp-and-nat-pmp",
|
|
|
|
"http-seeding_": "manual-ref.html#http-seeding",
|
|
|
|
"metadata-from-peers_": "manual-ref.html#metadata-from-peers",
|
|
|
|
"magnet-links_": "manual-ref.html#magnet-links",
|
|
|
|
"ssl-torrents_": "manual-ref.html#ssl-torrents",
|
2014-07-06 21:18:00 +02:00
|
|
|
"dynamic-loading-of-torrent-files_": "manual-ref.html#dynamic-loading-of-torrent-files",
|
|
|
|
"session-statistics_": "manual-ref.html#session-statistics",
|
|
|
|
"peer-classes_": "manual-ref.html#peer-classes"
|
2013-08-11 08:04:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static_links = \
|
|
|
|
{
|
2013-08-17 04:00:41 +02:00
|
|
|
".. _`BEP 3`: http://bittorrent.org/beps/bep_0003.html",
|
2013-08-11 08:04:24 +02:00
|
|
|
".. _`BEP 17`: http://bittorrent.org/beps/bep_0017.html",
|
|
|
|
".. _`BEP 19`: http://bittorrent.org/beps/bep_0019.html"
|
|
|
|
}
|
|
|
|
|
2013-08-04 12:01:34 +02:00
|
|
|
anon_index = 0
|
2013-07-19 18:29:53 +02:00
|
|
|
|
|
|
|
category_mapping = {
|
2015-03-13 06:42:18 +01:00
|
|
|
'ed25519.hpp': 'ed25519',
|
2015-03-14 22:55:26 +01:00
|
|
|
'session.hpp': 'Core',
|
|
|
|
'add_torrent_params.hpp': 'Core',
|
|
|
|
'session_status.hpp': 'Core',
|
2013-07-19 18:29:53 +02:00
|
|
|
'error_code.hpp': 'Error Codes',
|
|
|
|
'file.hpp': 'File',
|
2013-08-02 06:52:11 +02:00
|
|
|
'storage.hpp': 'Custom Storage',
|
2013-07-19 18:29:53 +02:00
|
|
|
'storage_defs.hpp': 'Storage',
|
|
|
|
'file_storage.hpp': 'Storage',
|
2013-08-02 06:52:11 +02:00
|
|
|
'file_pool.hpp': 'Custom Storage',
|
2013-07-19 18:29:53 +02:00
|
|
|
'extensions.hpp': 'Plugins',
|
|
|
|
'ut_metadata.hpp': 'Plugins',
|
|
|
|
'ut_pex.hpp': 'Plugins',
|
|
|
|
'ut_trackers.hpp': 'Plugins',
|
|
|
|
'metadata_transfer.hpp': 'Plugins',
|
|
|
|
'smart_ban.hpp': 'Plugins',
|
|
|
|
'lt_trackers.hpp': 'Plugins',
|
|
|
|
'create_torrent.hpp': 'Create Torrents',
|
|
|
|
'alert.hpp': 'Alerts',
|
|
|
|
'alert_types.hpp': 'Alerts',
|
|
|
|
'bencode.hpp': 'Bencoding',
|
|
|
|
'lazy_entry.hpp': 'Bencoding',
|
2015-03-12 06:20:12 +01:00
|
|
|
'bdecode.hpp': 'Bdecoding',
|
2013-07-19 18:29:53 +02:00
|
|
|
'entry.hpp': 'Bencoding',
|
|
|
|
'time.hpp': 'Time',
|
2015-03-14 22:55:26 +01:00
|
|
|
'escape_string.hpp': 'Utility',
|
2013-07-19 18:29:53 +02:00
|
|
|
'enum_net.hpp': 'Network',
|
|
|
|
'broadcast_socket.hpp': 'Network',
|
|
|
|
'socket.hpp': 'Network',
|
|
|
|
'socket_io.hpp': 'Network',
|
2013-07-19 18:57:07 +02:00
|
|
|
'bitfield.hpp': 'Utility',
|
2013-08-07 05:46:54 +02:00
|
|
|
'sha1_hash.hpp': 'Utility',
|
2015-03-14 22:55:26 +01:00
|
|
|
'hasher.hpp': 'Utility',
|
2013-07-19 18:57:07 +02:00
|
|
|
'identify_client.hpp': 'Utility',
|
|
|
|
'thread.hpp': 'Utility',
|
2013-07-25 07:08:35 +02:00
|
|
|
'ip_filter.hpp': 'Filter',
|
2013-08-06 04:50:57 +02:00
|
|
|
'session_settings.hpp': 'Settings',
|
2014-07-06 21:18:00 +02:00
|
|
|
'settings_pack.hpp': 'Settings',
|
2015-02-15 06:17:09 +01:00
|
|
|
'operations.hpp': 'Alerts',
|
2015-03-14 22:55:26 +01:00
|
|
|
'disk_buffer_holder.hpp': 'Custom Storage',
|
|
|
|
'alert_dispatcher.hpp': 'Alerts',
|
2013-08-06 04:50:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
category_fun_mapping = {
|
|
|
|
'min_memory_usage()': 'Settings',
|
|
|
|
'high_performance_seed()': 'Settings',
|
2015-03-14 22:55:26 +01:00
|
|
|
'cache_status': 'Core',
|
2013-07-19 18:29:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
def categorize_symbol(name, filename):
|
|
|
|
f = os.path.split(filename)[1]
|
|
|
|
|
2014-02-02 05:07:36 +01:00
|
|
|
if name.endswith('_category()') \
|
2013-07-19 18:29:53 +02:00
|
|
|
or name.endswith('_error_code') \
|
|
|
|
or name.endswith('error_code_enum'):
|
|
|
|
return 'Error Codes'
|
|
|
|
|
2013-08-06 04:50:57 +02:00
|
|
|
if name in category_fun_mapping:
|
|
|
|
return category_fun_mapping[name]
|
|
|
|
|
2014-02-02 05:07:36 +01:00
|
|
|
if f in category_mapping:
|
|
|
|
return category_mapping[f]
|
|
|
|
|
2013-07-19 18:57:07 +02:00
|
|
|
return 'Core'
|
2013-07-19 18:29:53 +02:00
|
|
|
|
2013-08-16 07:07:09 +02:00
|
|
|
def suppress_warning(filename, name):
|
|
|
|
f = os.path.split(filename)[1]
|
|
|
|
if f != 'alert_types.hpp': return False
|
|
|
|
|
|
|
|
# if name.endswith('_alert') or name == 'message()':
|
|
|
|
return True
|
|
|
|
|
|
|
|
# return False
|
|
|
|
|
2013-07-21 07:04:04 +02:00
|
|
|
def first_item(itr):
|
|
|
|
for i in itr:
|
|
|
|
return i
|
|
|
|
return None
|
|
|
|
|
2013-07-21 23:23:21 +02:00
|
|
|
def is_visible(desc):
|
2013-11-10 22:28:22 +01:00
|
|
|
if desc.strip().startswith('hidden'): return False
|
2013-08-04 12:01:34 +02:00
|
|
|
if internal: return True
|
2013-11-10 22:28:22 +01:00
|
|
|
if desc.strip().startswith('internal'): return False
|
2013-07-21 23:23:21 +02:00
|
|
|
return True
|
|
|
|
|
2013-07-21 07:04:04 +02:00
|
|
|
def highlight_signature(s):
|
2013-07-21 17:47:30 +02:00
|
|
|
name = s.split('(')
|
|
|
|
name2 = name[0].split(' ')
|
2013-08-11 18:57:33 +02:00
|
|
|
if len(name2[-1]) == 0: return s
|
2014-04-27 22:18:11 +02:00
|
|
|
|
|
|
|
# make the name of the function bold
|
2013-07-24 07:04:46 +02:00
|
|
|
name2[-1] = '**' + name2[-1] + '** '
|
2014-04-28 06:46:33 +02:00
|
|
|
|
|
|
|
# if there is a return value, make sure we preserve pointer types
|
|
|
|
if len(name2) > 1:
|
|
|
|
name2[0] = name2[0].replace('*', '\\*')
|
2013-07-21 17:47:30 +02:00
|
|
|
name[0] = ' '.join(name2)
|
2014-04-27 22:18:11 +02:00
|
|
|
|
|
|
|
# we have to escape asterisks, since this is rendered into
|
|
|
|
# a parsed literal in rst
|
|
|
|
name[1] = name[1].replace('*', '\\*')
|
2014-04-28 06:46:33 +02:00
|
|
|
|
2015-03-14 02:51:08 +01:00
|
|
|
# we also have to escape colons
|
|
|
|
name[1] = name[1].replace(':', '\\:')
|
|
|
|
|
2014-04-28 06:46:33 +02:00
|
|
|
# comments in signatures are italic
|
|
|
|
name[1] = name[1].replace('/\\*', '*/\\*')
|
|
|
|
name[1] = name[1].replace('\\*/', '\\*/*')
|
2013-07-21 17:47:30 +02:00
|
|
|
return '('.join(name)
|
2013-07-21 07:04:04 +02:00
|
|
|
|
2013-07-19 18:29:53 +02:00
|
|
|
def html_sanitize(s):
|
|
|
|
ret = ''
|
|
|
|
for i in s:
|
|
|
|
if i == '<': ret += '<'
|
|
|
|
elif i == '>': ret += '>'
|
|
|
|
elif i == '&': ret += '&'
|
|
|
|
else: ret += i
|
|
|
|
return ret
|
|
|
|
|
|
|
|
def looks_like_variable(line):
|
|
|
|
line = line.strip()
|
|
|
|
if not line.endswith(';'): return False
|
|
|
|
if not ' ' in line and not '\t' in line: return False
|
|
|
|
if line.startswith('friend '): return False
|
|
|
|
if line.startswith('enum '): return False
|
|
|
|
if line.startswith(','): return False
|
|
|
|
if line.startswith(':'): return False
|
2013-08-19 05:44:35 +02:00
|
|
|
if line.startswith('typedef'): return False
|
2013-07-19 18:29:53 +02:00
|
|
|
return True
|
|
|
|
|
|
|
|
def looks_like_function(line):
|
2013-12-19 06:35:47 +01:00
|
|
|
if line.startswith('friend'): return False
|
2013-07-21 23:23:21 +02:00
|
|
|
if '::' in line.split('(')[0].split(' ')[-1]: return False
|
2013-07-19 18:29:53 +02:00
|
|
|
if line.startswith(','): return False
|
|
|
|
if line.startswith(':'): return False
|
|
|
|
return '(' in line;
|
|
|
|
|
|
|
|
def parse_function(lno, lines, filename):
|
|
|
|
current_fun = {}
|
|
|
|
|
|
|
|
start_paren = 0
|
|
|
|
end_paren = 0
|
|
|
|
signature = ''
|
|
|
|
|
|
|
|
while lno < len(lines):
|
|
|
|
l = lines[lno].strip()
|
|
|
|
lno += 1
|
|
|
|
if l.startswith('//'): continue
|
|
|
|
|
|
|
|
start_paren += l.count('(')
|
|
|
|
end_paren += l.count(')')
|
|
|
|
|
2013-08-04 12:01:34 +02:00
|
|
|
sig_line = l.replace('TORRENT_EXPORT ', '').replace('TORRENT_EXTRA_EXPORT','').strip()
|
2013-07-19 18:29:53 +02:00
|
|
|
if signature != '': sig_line = '\n ' + sig_line
|
|
|
|
signature += sig_line
|
|
|
|
if verbose: print 'fun %s' % l
|
|
|
|
|
|
|
|
if start_paren > 0 and start_paren == end_paren:
|
|
|
|
if signature[-1] != ';':
|
|
|
|
# we also need to consume the function body
|
|
|
|
start_paren = 0
|
|
|
|
end_paren = 0
|
|
|
|
for i in range(len(signature)):
|
|
|
|
if signature[i] == '(': start_paren += 1
|
|
|
|
elif signature[i] == ')': end_paren += 1
|
|
|
|
|
|
|
|
if start_paren > 0 and start_paren == end_paren:
|
|
|
|
for k in range(i, len(signature)):
|
|
|
|
if signature[k] == ':' or signature[k] == '{':
|
|
|
|
signature = signature[0:k].strip()
|
|
|
|
break
|
|
|
|
break
|
|
|
|
|
|
|
|
lno = consume_block(lno - 1, lines)
|
|
|
|
signature += ';'
|
2013-08-17 21:31:45 +02:00
|
|
|
ret = [{ 'file': filename[11:], 'signatures': set([ signature ]), 'names': set([ signature.split('(')[0].split(' ')[-1].strip() + '()'])}, lno]
|
|
|
|
if first_item(ret[0]['names']) == '()': return [None, lno]
|
|
|
|
return ret
|
2013-07-19 18:29:53 +02:00
|
|
|
if len(signature) > 0:
|
|
|
|
print '\x1b[31mFAILED TO PARSE FUNCTION\x1b[0m %s\nline: %d\nfile: %s' % (signature, lno, filename)
|
|
|
|
return [None, lno]
|
|
|
|
|
|
|
|
def parse_class(lno, lines, filename):
|
|
|
|
start_brace = 0
|
|
|
|
end_brace = 0
|
|
|
|
|
|
|
|
name = ''
|
|
|
|
funs = []
|
|
|
|
fields = []
|
|
|
|
enums = []
|
|
|
|
state = 'public'
|
|
|
|
context = ''
|
|
|
|
class_type = 'struct'
|
2013-07-20 22:11:01 +02:00
|
|
|
blanks = 0
|
2013-08-17 09:01:03 +02:00
|
|
|
decl = ''
|
2013-07-19 18:29:53 +02:00
|
|
|
|
|
|
|
while lno < len(lines):
|
|
|
|
l = lines[lno].strip()
|
2013-08-17 09:01:03 +02:00
|
|
|
decl += lines[lno].replace('TORRENT_EXPORT ', '').replace('TORRENT_EXTRA_EXPORT', '').split('{')[0].strip()
|
2013-07-19 18:29:53 +02:00
|
|
|
if '{' in l: break
|
|
|
|
if verbose: print 'class %s' % l
|
|
|
|
lno += 1
|
|
|
|
|
2013-08-17 09:01:03 +02:00
|
|
|
if decl.startswith('class'):
|
2013-07-19 18:29:53 +02:00
|
|
|
state = 'private'
|
|
|
|
class_type = 'class'
|
|
|
|
|
2015-12-28 04:37:44 +01:00
|
|
|
name = decl.split(':')[0].replace('class ', '').replace('struct ', '').replace('TORRENT_FINAL', '').strip()
|
|
|
|
|
2013-08-17 09:01:03 +02:00
|
|
|
|
2013-07-19 18:29:53 +02:00
|
|
|
while lno < len(lines):
|
|
|
|
l = lines[lno].strip()
|
|
|
|
lno += 1
|
|
|
|
|
2013-07-20 22:11:01 +02:00
|
|
|
if l == '':
|
|
|
|
blanks += 1
|
2013-07-21 23:23:21 +02:00
|
|
|
context = ''
|
2013-07-20 22:11:01 +02:00
|
|
|
continue
|
|
|
|
|
2013-07-19 18:29:53 +02:00
|
|
|
if l.startswith('/*'):
|
|
|
|
lno = consume_comment(lno - 1, lines)
|
|
|
|
continue
|
|
|
|
|
|
|
|
if l.startswith('#'):
|
2013-11-17 23:38:37 +01:00
|
|
|
lno = consume_ifdef(lno - 1, lines, True)
|
2013-07-19 18:29:53 +02:00
|
|
|
continue
|
|
|
|
|
|
|
|
if 'TORRENT_DEFINE_ALERT' in l:
|
|
|
|
if verbose: print 'xx %s' % l
|
2013-07-20 22:11:01 +02:00
|
|
|
blanks += 1
|
2013-07-19 18:29:53 +02:00
|
|
|
continue
|
|
|
|
if 'TORRENT_DEPRECATED' in l:
|
|
|
|
if verbose: print 'xx %s' % l
|
2013-07-20 22:11:01 +02:00
|
|
|
blanks += 1
|
2013-07-19 18:29:53 +02:00
|
|
|
continue
|
|
|
|
|
|
|
|
if l.startswith('//'):
|
|
|
|
if verbose: print 'desc %s' % l
|
2013-07-26 08:11:10 +02:00
|
|
|
l = l[2:]
|
2013-07-24 07:04:46 +02:00
|
|
|
if len(l) and l[0] == ' ': l = l[1:]
|
2013-07-19 18:29:53 +02:00
|
|
|
context += l + '\n'
|
|
|
|
continue
|
|
|
|
|
|
|
|
start_brace += l.count('{')
|
|
|
|
end_brace += l.count('}')
|
|
|
|
|
|
|
|
if l == 'private:': state = 'private'
|
|
|
|
elif l == 'protected:': state = 'protected'
|
|
|
|
elif l == 'public:': state = 'public'
|
|
|
|
|
|
|
|
if start_brace > 0 and start_brace == end_brace:
|
2013-08-17 09:01:03 +02:00
|
|
|
return [{ 'file': filename[11:], 'enums': enums, 'fields':fields, 'type': class_type, 'name': name, 'decl': decl, 'fun': funs}, lno]
|
2013-07-19 18:29:53 +02:00
|
|
|
|
|
|
|
if state != 'public' and not internal:
|
|
|
|
if verbose: print 'private %s' % l
|
2013-07-20 22:11:01 +02:00
|
|
|
blanks += 1
|
2013-07-19 18:29:53 +02:00
|
|
|
continue
|
|
|
|
|
|
|
|
if start_brace - end_brace > 1:
|
|
|
|
if verbose: print 'scope %s' % l
|
2013-07-20 22:11:01 +02:00
|
|
|
blanks += 1
|
2013-07-19 18:29:53 +02:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if looks_like_function(l):
|
|
|
|
current_fun, lno = parse_function(lno - 1, lines, filename)
|
2013-07-21 23:23:21 +02:00
|
|
|
if current_fun != None and is_visible(context):
|
2013-07-20 22:11:01 +02:00
|
|
|
if context == '' and blanks == 0 and len(funs):
|
2013-07-21 07:04:04 +02:00
|
|
|
funs[-1]['signatures'].update(current_fun['signatures'])
|
|
|
|
funs[-1]['names'].update(current_fun['names'])
|
2013-07-20 22:11:01 +02:00
|
|
|
else:
|
|
|
|
current_fun['desc'] = context
|
2013-08-16 07:07:09 +02:00
|
|
|
if context == '' and not suppress_warning(filename, first_item(current_fun['names'])):
|
2013-11-28 09:49:02 +01:00
|
|
|
print 'WARNING: member function "%s" is not documented: \x1b[34m%s:%d\x1b[0m' \
|
2013-11-21 18:47:53 +01:00
|
|
|
% (name + '::' + first_item(current_fun['names']), filename, lno)
|
2013-07-20 22:11:01 +02:00
|
|
|
funs.append(current_fun)
|
2013-11-29 06:29:39 +01:00
|
|
|
context = ''
|
|
|
|
blanks = 0
|
2013-07-19 18:29:53 +02:00
|
|
|
continue
|
|
|
|
|
|
|
|
if looks_like_variable(l):
|
2013-07-21 23:23:21 +02:00
|
|
|
if not is_visible(context):
|
2013-07-21 17:47:30 +02:00
|
|
|
continue
|
2013-07-21 07:04:04 +02:00
|
|
|
n = l.split(' ')[-1].split(':')[0].split(';')[0]
|
|
|
|
if context == '' and blanks == 0 and len(fields):
|
|
|
|
fields[-1]['names'].append(n)
|
|
|
|
fields[-1]['signatures'].append(l)
|
|
|
|
else:
|
2013-08-16 07:07:09 +02:00
|
|
|
if context == '' and not suppress_warning(filename, n):
|
2013-11-28 09:49:02 +01:00
|
|
|
print 'WARNING: field "%s" is not documented: \x1b[34m%s:%d\x1b[0m' \
|
2013-11-21 18:47:53 +01:00
|
|
|
% (name + '::' + n, filename, lno)
|
2013-07-21 07:04:04 +02:00
|
|
|
fields.append({'signatures': [l], 'names': [n], 'desc': context})
|
2013-07-19 18:29:53 +02:00
|
|
|
context = ''
|
2013-07-21 07:04:04 +02:00
|
|
|
blanks = 0
|
2013-07-19 18:29:53 +02:00
|
|
|
continue
|
|
|
|
|
|
|
|
if l.startswith('enum '):
|
2013-11-29 06:29:39 +01:00
|
|
|
if not is_visible(context):
|
|
|
|
consume_block(lno - 1, lines)
|
|
|
|
else:
|
|
|
|
enum, lno = parse_enum(lno - 1, lines, filename)
|
|
|
|
if enum != None:
|
|
|
|
enum['desc'] = context
|
|
|
|
if context == '' and not suppress_warning(filename, enum['name']):
|
|
|
|
print 'WARNING: enum "%s" is not documented: \x1b[34m%s:%d\x1b[0m' \
|
|
|
|
% (name + '::' + enum['name'], filename, lno)
|
|
|
|
enums.append(enum)
|
|
|
|
context = ''
|
2013-07-19 18:29:53 +02:00
|
|
|
continue
|
|
|
|
|
|
|
|
context = ''
|
|
|
|
if verbose: print '?? %s' % l
|
2015-07-11 07:51:30 +02:00
|
|
|
|
2013-07-19 18:29:53 +02:00
|
|
|
if len(name) > 0:
|
|
|
|
print '\x1b[31mFAILED TO PARSE CLASS\x1b[0m %s\nfile: %s:%d' % (name, filename, lno)
|
|
|
|
return [None, lno]
|
|
|
|
|
|
|
|
def parse_enum(lno, lines, filename):
|
|
|
|
start_brace = 0
|
|
|
|
end_brace = 0
|
2013-08-04 12:01:34 +02:00
|
|
|
global anon_index
|
2013-07-19 18:29:53 +02:00
|
|
|
|
|
|
|
l = lines[lno].strip()
|
|
|
|
name = l.replace('enum ', '').split('{')[0].strip()
|
|
|
|
if len(name) == 0:
|
2013-08-04 12:01:34 +02:00
|
|
|
if not internal:
|
2013-11-28 09:49:02 +01:00
|
|
|
print 'WARNING: anonymous enum at: \x1b[34m%s:%d\x1b[0m' % (filename, lno)
|
2013-08-04 12:01:34 +02:00
|
|
|
lno = consume_block(lno - 1, lines)
|
|
|
|
return [None, lno]
|
|
|
|
name = 'anonymous_enum_%d' % anon_index
|
|
|
|
anon_index += 1
|
2013-07-19 18:29:53 +02:00
|
|
|
|
|
|
|
values = []
|
|
|
|
context = ''
|
|
|
|
if not '{' in l:
|
|
|
|
if verbose: print 'enum %s' % lines[lno]
|
|
|
|
lno += 1
|
|
|
|
|
2013-08-04 11:02:19 +02:00
|
|
|
val = 0
|
2013-07-19 18:29:53 +02:00
|
|
|
while lno < len(lines):
|
|
|
|
l = lines[lno].strip()
|
|
|
|
lno += 1
|
|
|
|
|
|
|
|
if l.startswith('//'):
|
|
|
|
if verbose: print 'desc %s' % l
|
2013-07-26 08:11:10 +02:00
|
|
|
l = l[2:]
|
2013-07-24 07:04:46 +02:00
|
|
|
if len(l) and l[0] == ' ': l = l[1:]
|
2013-07-19 18:29:53 +02:00
|
|
|
context += l + '\n'
|
|
|
|
continue
|
|
|
|
|
|
|
|
if l.startswith('#'):
|
|
|
|
lno = consume_ifdef(lno - 1, lines)
|
|
|
|
continue
|
|
|
|
|
|
|
|
start_brace += l.count('{')
|
|
|
|
end_brace += l.count('}')
|
|
|
|
|
2015-07-11 07:51:30 +02:00
|
|
|
if '{' in l:
|
2013-07-19 18:29:53 +02:00
|
|
|
l = l.split('{')[1]
|
|
|
|
l = l.split('}')[0]
|
|
|
|
|
|
|
|
if len(l):
|
2013-07-20 22:11:01 +02:00
|
|
|
if verbose: print 'enumv %s' % lines[lno-1]
|
2013-07-19 18:29:53 +02:00
|
|
|
for v in l.split(','):
|
2013-08-04 11:02:19 +02:00
|
|
|
v = v.strip();
|
|
|
|
if v.startswith('//'): break
|
2013-07-19 18:29:53 +02:00
|
|
|
if v == '': continue
|
2013-08-04 11:02:19 +02:00
|
|
|
valstr = ''
|
|
|
|
try:
|
|
|
|
if '=' in v: val = int(v.split('=')[1].strip(), 0)
|
|
|
|
valstr = str(val)
|
|
|
|
except: pass
|
|
|
|
|
|
|
|
if '=' in v: v = v.split('=')[0].strip()
|
2013-07-21 23:23:21 +02:00
|
|
|
if is_visible(context):
|
2013-08-04 11:02:19 +02:00
|
|
|
values.append({'name': v.strip(), 'desc': context, 'val': valstr})
|
|
|
|
if verbose: print 'enumv %s' % valstr
|
2013-07-19 18:29:53 +02:00
|
|
|
context = ''
|
2013-08-04 11:02:19 +02:00
|
|
|
val += 1
|
2013-07-19 18:29:53 +02:00
|
|
|
else:
|
|
|
|
if verbose: print '?? %s' % lines[lno-1]
|
|
|
|
|
|
|
|
if start_brace > 0 and start_brace == end_brace:
|
2013-07-20 01:53:57 +02:00
|
|
|
return [{'file': filename[11:], 'name': name, 'values': values}, lno]
|
2013-07-19 18:29:53 +02:00
|
|
|
|
|
|
|
if len(name) > 0:
|
|
|
|
print '\x1b[31mFAILED TO PARSE ENUM\x1b[0m %s\nline: %d\nfile: %s' % (name, lno, filename)
|
|
|
|
return [None, lno]
|
|
|
|
|
|
|
|
def consume_block(lno, lines):
|
|
|
|
start_brace = 0
|
|
|
|
end_brace = 0
|
|
|
|
|
|
|
|
while lno < len(lines):
|
|
|
|
l = lines[lno].strip()
|
|
|
|
if verbose: print 'xx %s' % l
|
|
|
|
lno += 1
|
|
|
|
|
|
|
|
start_brace += l.count('{')
|
|
|
|
end_brace += l.count('}')
|
|
|
|
|
|
|
|
if start_brace > 0 and start_brace == end_brace:
|
|
|
|
break
|
|
|
|
return lno
|
|
|
|
|
|
|
|
def consume_comment(lno, lines):
|
|
|
|
while lno < len(lines):
|
|
|
|
l = lines[lno].strip()
|
|
|
|
if verbose: print 'xx %s' % l
|
|
|
|
lno += 1
|
|
|
|
if '*/' in l: break
|
|
|
|
|
|
|
|
return lno
|
|
|
|
|
2013-11-29 06:29:39 +01:00
|
|
|
def trim_define(l):
|
|
|
|
return l.replace('#ifndef', '').replace('#ifdef', '') \
|
|
|
|
.replace('#if', '').replace('defined', '') \
|
|
|
|
.replace('TORRENT_USE_IPV6', '').replace('TORRENT_NO_DEPRECATE', '') \
|
|
|
|
.replace('||', '').replace('&&', '').replace('(', '').replace(')','') \
|
|
|
|
.replace('!', '').replace('\\', '').strip()
|
|
|
|
|
2013-11-17 23:38:37 +01:00
|
|
|
def consume_ifdef(lno, lines, warn_on_ifdefs = False):
|
2013-07-19 18:29:53 +02:00
|
|
|
l = lines[lno].strip()
|
|
|
|
lno += 1
|
|
|
|
|
|
|
|
start_if = 1
|
|
|
|
end_if = 0
|
|
|
|
|
|
|
|
if verbose: print 'prep %s' % l
|
|
|
|
|
2014-10-21 23:45:35 +02:00
|
|
|
if warn_on_ifdefs and ('TORRENT_DEBUG' in l):
|
2013-11-29 06:29:39 +01:00
|
|
|
while l.endswith('\\'):
|
|
|
|
lno += 1
|
|
|
|
l += lines[lno].strip()
|
|
|
|
if verbose: print 'prep %s' % lines[lno].trim()
|
|
|
|
define = trim_define(l)
|
|
|
|
print '\x1b[31mWARNING: possible ABI breakage in public struct! "%s" \x1b[34m %s:%d\x1b[0m' % \
|
|
|
|
(define, filename, lno)
|
|
|
|
# we've already warned once, no need to do it twice
|
|
|
|
warn_on_ifdefs = False
|
2013-11-17 23:38:37 +01:00
|
|
|
|
|
|
|
if warn_on_ifdefs and '#if' in l:
|
2013-11-29 06:29:39 +01:00
|
|
|
while l.endswith('\\'):
|
|
|
|
lno += 1
|
|
|
|
l += lines[lno].strip()
|
|
|
|
if verbose: print 'prep %s' % lines[lno].trim()
|
|
|
|
define = trim_define(l)
|
2013-11-17 23:38:37 +01:00
|
|
|
if define != '':
|
2013-11-29 06:29:39 +01:00
|
|
|
print '\x1b[33msensitive define in public struct: "%s"\x1b[34m %s:%d\x1b[0m' % (define, filename, lno)
|
2013-11-17 23:38:37 +01:00
|
|
|
|
2013-07-19 18:29:53 +02:00
|
|
|
if l == '#ifndef TORRENT_NO_DEPRECATE' or \
|
|
|
|
l == '#ifdef TORRENT_DEBUG' or \
|
2014-01-20 05:57:25 +01:00
|
|
|
(l.startswith('#if ') and ' TORRENT_USE_ASSERTS' in l) or \
|
|
|
|
(l.startswith('#if ') and ' TORRENT_USE_INVARIANT_CHECKS' in l) or \
|
2013-07-21 23:23:21 +02:00
|
|
|
l == '#ifdef TORRENT_ASIO_DEBUGGING' or \
|
|
|
|
(l.startswith('#if') and 'defined TORRENT_DEBUG' in l) or \
|
|
|
|
(l.startswith('#if') and 'defined TORRENT_ASIO_DEBUGGING' in l):
|
2013-07-19 18:29:53 +02:00
|
|
|
while lno < len(lines):
|
|
|
|
l = lines[lno].strip()
|
|
|
|
lno += 1
|
|
|
|
if verbose: print 'prep %s' % l
|
|
|
|
if l.startswith('#endif'): end_if += 1
|
|
|
|
if l.startswith('#if'): start_if += 1
|
|
|
|
if l == '#else' and start_if - end_if == 1: break
|
|
|
|
if start_if - end_if == 0: break
|
|
|
|
return lno
|
2013-08-17 21:31:45 +02:00
|
|
|
else:
|
|
|
|
while l.endswith('\\') and lno < len(lines):
|
|
|
|
l = lines[lno].strip()
|
|
|
|
lno += 1
|
|
|
|
if verbose: print 'prep %s' % l
|
2013-07-19 18:29:53 +02:00
|
|
|
|
|
|
|
return lno
|
|
|
|
|
|
|
|
for filename in files:
|
|
|
|
h = open(filename)
|
|
|
|
lines = h.read().split('\n')
|
|
|
|
|
|
|
|
if verbose: print '\n=== %s ===\n' % filename
|
|
|
|
|
2013-07-20 22:11:01 +02:00
|
|
|
blanks = 0
|
2013-07-19 18:29:53 +02:00
|
|
|
lno = 0
|
|
|
|
while lno < len(lines):
|
|
|
|
l = lines[lno].strip()
|
|
|
|
lno += 1
|
|
|
|
|
2013-07-20 22:11:01 +02:00
|
|
|
if l == '':
|
|
|
|
blanks += 1
|
2013-07-21 23:23:21 +02:00
|
|
|
context = ''
|
2013-07-20 22:11:01 +02:00
|
|
|
continue
|
|
|
|
|
2013-07-21 23:23:21 +02:00
|
|
|
if l.startswith('//') and l[2:].strip() == 'OVERVIEW':
|
|
|
|
# this is a section overview
|
|
|
|
current_overview = ''
|
|
|
|
while lno < len(lines):
|
|
|
|
l = lines[lno].strip()
|
|
|
|
lno += 1
|
|
|
|
if not l.startswith('//'):
|
|
|
|
# end of overview
|
|
|
|
overviews[filename[11:]] = current_overview
|
|
|
|
current_overview = ''
|
|
|
|
break
|
2013-08-12 05:18:43 +02:00
|
|
|
l = l[2:]
|
|
|
|
if l.startswith(' '): l = l[1:]
|
|
|
|
current_overview += l + '\n'
|
2013-07-21 23:23:21 +02:00
|
|
|
|
2013-07-19 18:29:53 +02:00
|
|
|
if l.startswith('//'):
|
|
|
|
if verbose: print 'desc %s' % l
|
2013-07-26 08:11:10 +02:00
|
|
|
l = l[2:]
|
2013-07-24 07:04:46 +02:00
|
|
|
if len(l) and l[0] == ' ': l = l[1:]
|
2013-07-19 18:29:53 +02:00
|
|
|
context += l + '\n'
|
|
|
|
continue
|
|
|
|
|
|
|
|
if l.startswith('/*'):
|
|
|
|
lno = consume_comment(lno - 1, lines)
|
|
|
|
continue
|
|
|
|
|
|
|
|
if l.startswith('#'):
|
|
|
|
lno = consume_ifdef(lno - 1, lines)
|
|
|
|
continue
|
|
|
|
|
2013-08-04 12:01:34 +02:00
|
|
|
if (l == 'namespace detail' or \
|
|
|
|
l == 'namespace aux') \
|
|
|
|
and not internal:
|
2013-07-21 23:23:21 +02:00
|
|
|
lno = consume_block(lno, lines)
|
|
|
|
continue
|
|
|
|
|
2013-07-19 18:29:53 +02:00
|
|
|
if 'TORRENT_CFG' in l:
|
2013-07-20 22:11:01 +02:00
|
|
|
blanks += 1
|
2013-07-19 18:29:53 +02:00
|
|
|
if verbose: print 'xx %s' % l
|
|
|
|
continue
|
|
|
|
if 'TORRENT_DEPRECATED' in l:
|
2013-11-29 06:29:39 +01:00
|
|
|
if ('class ' in l or 'struct ' in l) and not ';' in l:
|
|
|
|
lno = consume_block(lno - 1, lines)
|
|
|
|
context = ''
|
2013-07-20 22:11:01 +02:00
|
|
|
blanks += 1
|
2013-07-19 18:29:53 +02:00
|
|
|
if verbose: print 'xx %s' % l
|
|
|
|
continue
|
|
|
|
|
2013-08-12 18:24:37 +02:00
|
|
|
if 'TORRENT_EXPORT ' in l or l.startswith('inline ') or l.startswith('template') or internal:
|
2013-08-11 18:57:33 +02:00
|
|
|
if l.startswith('class ') or l.startswith('struct '):
|
2013-08-04 12:01:34 +02:00
|
|
|
if not l.endswith(';'):
|
|
|
|
current_class, lno = parse_class(lno -1, lines, filename)
|
|
|
|
if current_class != None and is_visible(context):
|
|
|
|
current_class['desc'] = context
|
2013-11-21 18:47:53 +01:00
|
|
|
if context == '':
|
2013-11-28 09:49:02 +01:00
|
|
|
print 'WARNING: class "%s" is not documented: \x1b[34m%s:%d\x1b[0m' \
|
2013-11-21 18:47:53 +01:00
|
|
|
% (current_class['name'], filename, lno)
|
2013-08-04 12:01:34 +02:00
|
|
|
classes.append(current_class)
|
2013-07-19 18:29:53 +02:00
|
|
|
context = ''
|
2013-07-20 22:11:01 +02:00
|
|
|
blanks += 1
|
2013-07-19 18:29:53 +02:00
|
|
|
continue
|
|
|
|
|
|
|
|
if looks_like_function(l):
|
|
|
|
current_fun, lno = parse_function(lno - 1, lines, filename)
|
2013-07-21 23:23:21 +02:00
|
|
|
if current_fun != None and is_visible(context):
|
2013-07-20 22:11:01 +02:00
|
|
|
if context == '' and blanks == 0 and len(functions):
|
2013-07-21 07:04:04 +02:00
|
|
|
functions[-1]['signatures'].update(current_fun['signatures'])
|
|
|
|
functions[-1]['names'].update(current_fun['names'])
|
2013-07-20 22:11:01 +02:00
|
|
|
else:
|
|
|
|
current_fun['desc'] = context
|
2013-11-21 18:47:53 +01:00
|
|
|
if context == '':
|
2013-11-28 09:49:02 +01:00
|
|
|
print 'WARNING: function "%s" is not documented: \x1b[34m%s:%d\x1b[0m' \
|
2013-11-21 18:47:53 +01:00
|
|
|
% (first_item(current_fun['names']), filename, lno)
|
2013-07-20 22:11:01 +02:00
|
|
|
functions.append(current_fun)
|
2013-11-29 06:29:39 +01:00
|
|
|
context = ''
|
2013-07-20 22:11:01 +02:00
|
|
|
blanks = 0
|
2013-07-19 18:29:53 +02:00
|
|
|
continue
|
|
|
|
|
|
|
|
if ('class ' in l or 'struct ' in l) and not ';' in l:
|
|
|
|
lno = consume_block(lno - 1, lines)
|
|
|
|
context = ''
|
2013-07-20 22:11:01 +02:00
|
|
|
blanks += 1
|
2013-07-19 18:29:53 +02:00
|
|
|
continue
|
|
|
|
|
|
|
|
if l.startswith('enum '):
|
2013-11-29 06:29:39 +01:00
|
|
|
if not is_visible(context):
|
|
|
|
consume_block(lno - 1, lines)
|
|
|
|
else:
|
|
|
|
current_enum, lno = parse_enum(lno - 1, lines, filename)
|
|
|
|
if current_enum != None and is_visible(context):
|
|
|
|
current_enum['desc'] = context
|
|
|
|
if context == '':
|
|
|
|
print 'WARNING: enum "%s" is not documented: \x1b[34m%s:%d\x1b[0m' \
|
|
|
|
% (current_enum['name'], filename, lno)
|
|
|
|
enums.append(current_enum)
|
2013-07-19 18:29:53 +02:00
|
|
|
context = ''
|
2013-07-20 22:11:01 +02:00
|
|
|
blanks += 1
|
2013-07-19 18:29:53 +02:00
|
|
|
continue
|
|
|
|
|
2013-07-20 22:11:01 +02:00
|
|
|
blanks += 1
|
2013-07-19 18:29:53 +02:00
|
|
|
if verbose: print '?? %s' % l
|
|
|
|
|
|
|
|
context = ''
|
|
|
|
h.close()
|
|
|
|
|
2013-08-05 07:26:15 +02:00
|
|
|
# ====================================================================
|
|
|
|
#
|
|
|
|
# RENDER PART
|
|
|
|
#
|
|
|
|
# ====================================================================
|
|
|
|
|
|
|
|
|
2013-07-19 18:29:53 +02:00
|
|
|
if dump:
|
|
|
|
|
|
|
|
if verbose: print '\n===============================\n'
|
|
|
|
|
|
|
|
for c in classes:
|
|
|
|
print '\x1b[4m%s\x1b[0m %s\n{' % (c['type'], c['name'])
|
|
|
|
for f in c['fun']:
|
2013-07-21 07:04:04 +02:00
|
|
|
for s in f['signatures']:
|
|
|
|
print ' %s' % s.replace('\n', '\n ')
|
2013-07-19 18:29:53 +02:00
|
|
|
|
|
|
|
if len(c['fun']) > 0 and len(c['fields']) > 0: print ''
|
|
|
|
|
|
|
|
for f in c['fields']:
|
2013-07-21 07:04:04 +02:00
|
|
|
for s in f['signatures']:
|
|
|
|
print ' %s' % s
|
2013-07-19 18:29:53 +02:00
|
|
|
|
|
|
|
if len(c['fields']) > 0 and len(c['enums']) > 0: print ''
|
|
|
|
|
|
|
|
for e in c['enums']:
|
|
|
|
print ' \x1b[4menum\x1b[0m %s\n {' % e['name']
|
|
|
|
for v in e['values']:
|
|
|
|
print ' %s' % v['name']
|
|
|
|
print ' };'
|
|
|
|
print '};\n'
|
|
|
|
|
|
|
|
for f in functions:
|
|
|
|
print '%s' % f['signature']
|
|
|
|
|
|
|
|
for e in enums:
|
|
|
|
print '\x1b[4menum\x1b[0m %s\n{' % e['name']
|
|
|
|
for v in e['values']:
|
|
|
|
print ' %s' % v['name']
|
|
|
|
print '};'
|
|
|
|
|
|
|
|
categories = {}
|
|
|
|
|
|
|
|
for c in classes:
|
|
|
|
cat = categorize_symbol(c['name'], c['file'])
|
|
|
|
if not cat in categories:
|
2013-07-24 07:04:46 +02:00
|
|
|
categories[cat] = { 'classes': [], 'functions': [], 'enums': [], 'filename': 'reference-%s.rst' % cat.replace(' ', '_')}
|
2013-07-21 23:23:21 +02:00
|
|
|
|
|
|
|
if c['file'] in overviews:
|
|
|
|
categories[cat]['overview'] = overviews[c['file']]
|
|
|
|
|
2013-08-05 07:26:15 +02:00
|
|
|
filename = categories[cat]['filename'].replace('.rst', '.html') + '#'
|
2013-07-19 18:29:53 +02:00
|
|
|
categories[cat]['classes'].append(c)
|
2013-08-05 07:26:15 +02:00
|
|
|
symbols[c['name']] = filename + c['name']
|
|
|
|
for f in c['fun']:
|
|
|
|
for n in f['names']:
|
|
|
|
symbols[n] = filename + n
|
2013-08-09 03:44:42 +02:00
|
|
|
symbols[c['name'] + '::' + n] = filename + n
|
|
|
|
|
|
|
|
for f in c['fields']:
|
|
|
|
for n in f['names']:
|
|
|
|
symbols[c['name'] + '::' + n] = filename + n
|
2013-08-05 07:26:15 +02:00
|
|
|
|
|
|
|
for e in c['enums']:
|
|
|
|
symbols[e['name']] = filename + e['name']
|
2013-08-12 05:18:43 +02:00
|
|
|
symbols[c['name'] + '::' + e['name']] = filename + e['name']
|
2013-08-05 07:26:15 +02:00
|
|
|
for v in e['values']:
|
2013-08-09 03:44:42 +02:00
|
|
|
# symbols[v['name']] = filename + v['name']
|
|
|
|
symbols[e['name'] + '::' + v['name']] = filename + v['name']
|
|
|
|
symbols[c['name'] + '::' + v['name']] = filename + v['name']
|
2013-07-19 18:29:53 +02:00
|
|
|
|
|
|
|
for f in functions:
|
2013-07-21 07:04:04 +02:00
|
|
|
cat = categorize_symbol(first_item(f['names']), f['file'])
|
2013-07-19 18:29:53 +02:00
|
|
|
if not cat in categories:
|
2013-07-24 07:04:46 +02:00
|
|
|
categories[cat] = { 'classes': [], 'functions': [], 'enums': [], 'filename': 'reference-%s.rst' % cat.replace(' ', '_')}
|
2013-07-21 23:23:21 +02:00
|
|
|
|
|
|
|
if f['file'] in overviews:
|
|
|
|
categories[cat]['overview'] = overviews[f['file']]
|
|
|
|
|
2013-07-21 07:04:04 +02:00
|
|
|
for n in f['names']:
|
2013-07-25 07:08:35 +02:00
|
|
|
symbols[n] = categories[cat]['filename'].replace('.rst', '.html') + '#' + n
|
2013-07-19 18:29:53 +02:00
|
|
|
categories[cat]['functions'].append(f)
|
|
|
|
|
|
|
|
for e in enums:
|
|
|
|
cat = categorize_symbol(e['name'], e['file'])
|
|
|
|
if not cat in categories:
|
2013-07-24 07:04:46 +02:00
|
|
|
categories[cat] = { 'classes': [], 'functions': [], 'enums': [], 'filename': 'reference-%s.rst' % cat.replace(' ', '_')}
|
2013-07-19 18:29:53 +02:00
|
|
|
categories[cat]['enums'].append(e)
|
2013-08-09 03:44:42 +02:00
|
|
|
filename = categories[cat]['filename'].replace('.rst', '.html') + '#'
|
|
|
|
symbols[e['name']] = filename + e['name']
|
|
|
|
for v in e['values']:
|
|
|
|
symbols[e['name'] + '::' + v['name']] = filename + v['name']
|
2013-07-19 18:29:53 +02:00
|
|
|
|
|
|
|
def print_declared_in(out, o):
|
2013-07-24 07:04:46 +02:00
|
|
|
out.write('Declared in "%s"\n\n' % print_link(o['file'], '../include/%s' % o['file']))
|
2013-08-05 07:26:15 +02:00
|
|
|
print >>out, dump_link_targets()
|
|
|
|
|
|
|
|
# returns RST marked up string
|
|
|
|
def linkify_symbols(string):
|
|
|
|
lines = string.split('\n')
|
|
|
|
ret = []
|
2013-08-11 18:57:33 +02:00
|
|
|
in_literal = False
|
2014-07-06 21:18:00 +02:00
|
|
|
lno = 0
|
2013-08-05 07:26:15 +02:00
|
|
|
for l in lines:
|
2014-07-06 21:18:00 +02:00
|
|
|
lno += 1
|
|
|
|
# don't touch headlines, i.e. lines whose
|
|
|
|
# next line entirely contains one of =, - or .
|
|
|
|
if (lno < len(lines)-1): next_line = lines[lno]
|
|
|
|
else: next_line = ''
|
|
|
|
|
|
|
|
if len(next_line) > 0 and lines[lno].replace('=',''). \
|
|
|
|
replace('-','').replace('.', '') == '':
|
|
|
|
ret.append(l)
|
|
|
|
continue
|
|
|
|
|
2013-08-11 18:57:33 +02:00
|
|
|
if l.startswith('|'):
|
2013-08-05 07:26:15 +02:00
|
|
|
ret.append(l)
|
|
|
|
continue
|
2013-08-11 18:57:33 +02:00
|
|
|
if in_literal and not l.startswith('\t') and not l == '':
|
|
|
|
# print ' end literal: "%s"' % l
|
|
|
|
in_literal = False
|
|
|
|
if in_literal:
|
|
|
|
# print ' literal: "%s"' % l
|
|
|
|
ret.append(l)
|
|
|
|
continue
|
2015-10-07 06:48:43 +02:00
|
|
|
if l.strip() == '.. parsed-literal::' or \
|
|
|
|
l.strip().startswith('.. code::') or \
|
|
|
|
(not l.strip().startswith('..') and l.endswith('::')):
|
2013-08-11 18:57:33 +02:00
|
|
|
# print ' start literal: "%s"' % l
|
|
|
|
in_literal = True
|
2013-08-05 07:26:15 +02:00
|
|
|
words = l.split(' ')
|
2013-08-11 18:57:33 +02:00
|
|
|
|
2013-08-05 07:26:15 +02:00
|
|
|
for i in range(len(words)):
|
|
|
|
# it's important to preserve leading
|
|
|
|
# tabs, since that's relevant for
|
|
|
|
# rst markup
|
2014-04-28 06:46:33 +02:00
|
|
|
|
|
|
|
leading = ''
|
|
|
|
w = words[i]
|
|
|
|
|
|
|
|
if len(w) == 0: continue
|
|
|
|
|
|
|
|
while len(w) > 0 and \
|
|
|
|
w[0] in ['\t', ' ', '(', '[', '{']:
|
|
|
|
leading += w[0]
|
|
|
|
w = w[1:]
|
2013-08-05 07:26:15 +02:00
|
|
|
|
|
|
|
# preserve commas and dots at the end
|
2014-04-28 06:46:33 +02:00
|
|
|
w = w.strip()
|
2013-08-05 07:26:15 +02:00
|
|
|
trailing = ''
|
2013-08-11 18:57:33 +02:00
|
|
|
|
2013-08-11 08:04:24 +02:00
|
|
|
if len(w) == 0: continue
|
|
|
|
|
2014-04-28 06:46:33 +02:00
|
|
|
while len(w) > 1 and w[-1] in ['.', ',', ')'] and w[-2:] != '()':
|
2013-08-11 18:57:33 +02:00
|
|
|
trailing = w[-1] + trailing
|
2013-08-05 07:26:15 +02:00
|
|
|
w = w[:-1]
|
2013-08-11 08:04:24 +02:00
|
|
|
|
|
|
|
link_name = w;
|
|
|
|
|
2013-08-11 18:57:33 +02:00
|
|
|
# print w
|
|
|
|
|
|
|
|
if len(w) == 0: continue
|
|
|
|
|
2013-08-11 08:04:24 +02:00
|
|
|
if link_name[-1] == '_': link_name = link_name[:-1]
|
|
|
|
|
2013-08-05 07:26:15 +02:00
|
|
|
if w in symbols:
|
2013-08-11 08:04:24 +02:00
|
|
|
link_name = link_name.replace('-', ' ')
|
2013-08-11 18:57:33 +02:00
|
|
|
# print ' found %s -> %s' % (w, link_name)
|
2014-04-28 06:46:33 +02:00
|
|
|
words[i] = leading + print_link(link_name, symbols[w]) + trailing
|
2013-08-05 07:26:15 +02:00
|
|
|
ret.append(' '.join(words))
|
|
|
|
return '\n'.join(ret)
|
2013-07-24 07:04:46 +02:00
|
|
|
|
|
|
|
link_targets = []
|
|
|
|
|
|
|
|
def print_link(name, target):
|
|
|
|
global link_targets
|
|
|
|
link_targets.append(target)
|
|
|
|
return "`%s`__" % name
|
|
|
|
|
2015-03-13 06:42:18 +01:00
|
|
|
def dump_link_targets(indent = ''):
|
2013-07-24 07:04:46 +02:00
|
|
|
global link_targets
|
2014-07-06 21:18:00 +02:00
|
|
|
ret = '\n'
|
2013-07-24 07:04:46 +02:00
|
|
|
for l in link_targets:
|
2015-03-13 06:42:18 +01:00
|
|
|
ret += '%s__ %s\n' % (indent, l)
|
2013-07-24 07:04:46 +02:00
|
|
|
link_targets = []
|
|
|
|
return ret
|
|
|
|
|
2015-03-13 06:42:18 +01:00
|
|
|
def heading(string, c, indent = ''):
|
2015-03-14 22:55:26 +01:00
|
|
|
string = string.strip()
|
2015-03-13 06:42:18 +01:00
|
|
|
return '\n' + indent + string + '\n' + indent + (c * len(string)) + '\n'
|
2013-07-24 07:04:46 +02:00
|
|
|
|
2015-03-14 22:55:26 +01:00
|
|
|
def render_enums(out, enums, print_declared_reference, header_level):
|
2013-08-05 07:26:15 +02:00
|
|
|
for e in enums:
|
|
|
|
print >>out, '.. raw:: html\n'
|
|
|
|
print >>out, '\t<a name="%s"></a>' % e['name']
|
|
|
|
print >>out, ''
|
2015-03-14 22:55:26 +01:00
|
|
|
print >>out, heading('enum %s' % e['name'], header_level)
|
2013-08-17 21:31:45 +02:00
|
|
|
|
|
|
|
print_declared_in(out, e)
|
|
|
|
|
2013-08-05 07:26:15 +02:00
|
|
|
width = [len('name'), len('value'), len('description')]
|
|
|
|
|
|
|
|
for i in range(len(e['values'])):
|
|
|
|
e['values'][i]['desc'] = linkify_symbols(e['values'][i]['desc'])
|
|
|
|
|
|
|
|
for v in e['values']:
|
|
|
|
width[0] = max(width[0], len(v['name']))
|
|
|
|
width[1] = max(width[1], len(v['val']))
|
|
|
|
for d in v['desc'].split('\n'):
|
|
|
|
width[2] = max(width[2], len(d))
|
|
|
|
|
|
|
|
print >>out, '+-' + ('-' * width[0]) + '-+-' + ('-' * width[1]) + '-+-' + ('-' * width[2]) + '-+'
|
|
|
|
print >>out, '| ' + 'name'.ljust(width[0]) + ' | ' + 'value'.ljust(width[1]) + ' | ' + 'description'.ljust(width[2]) + ' |'
|
|
|
|
print >>out, '+=' + ('=' * width[0]) + '=+=' + ('=' * width[1]) + '=+=' + ('=' * width[2]) + '=+'
|
|
|
|
for v in e['values']:
|
|
|
|
d = v['desc'].split('\n')
|
|
|
|
if len(d) == 0: d = ['']
|
|
|
|
print >>out, '| ' + v['name'].ljust(width[0]) + ' | ' + v['val'].ljust(width[1]) + ' | ' + d[0].ljust(width[2]) + ' |'
|
|
|
|
for s in d[1:]:
|
|
|
|
print >>out, '| ' + (' ' * width[0]) + ' | ' + (' ' * width[1]) + ' | ' + s.ljust(width[2]) + ' |'
|
|
|
|
print >>out, '+-' + ('-' * width[0]) + '-+-' + ('-' * width[1]) + '-+-' + ('-' * width[2]) + '-+'
|
|
|
|
print >>out, ''
|
|
|
|
|
|
|
|
print >>out, dump_link_targets()
|
|
|
|
|
2015-03-13 06:42:18 +01:00
|
|
|
sections = \
|
|
|
|
{
|
|
|
|
'Core': 0,
|
|
|
|
'Session': 0,
|
|
|
|
'Settings': 0,
|
|
|
|
|
|
|
|
'Bencoding': 1,
|
|
|
|
'Bdecoding': 1,
|
|
|
|
'Filter': 1,
|
|
|
|
'Error Codes': 1,
|
|
|
|
'Create Torrents': 1,
|
|
|
|
|
|
|
|
'ed25519': 2,
|
|
|
|
'Utility': 2,
|
|
|
|
'Storage': 2,
|
|
|
|
'Custom Storage': 2,
|
|
|
|
'Plugins': 2,
|
|
|
|
|
|
|
|
'Alerts': 3
|
|
|
|
}
|
2013-08-05 07:26:15 +02:00
|
|
|
|
2015-03-13 06:42:18 +01:00
|
|
|
def print_toc(out, categories, s):
|
|
|
|
for cat in categories:
|
|
|
|
if (s != 2 and cat not in sections) or \
|
|
|
|
(cat in sections and sections[cat] != s): continue
|
2013-07-24 07:04:46 +02:00
|
|
|
|
2015-03-13 06:42:18 +01:00
|
|
|
print >>out, '\t.. rubric:: %s\n' % cat
|
2013-07-24 07:04:46 +02:00
|
|
|
|
2015-03-13 06:42:18 +01:00
|
|
|
if 'overview' in categories[cat]:
|
|
|
|
print >>out, '\t| overview__'
|
2013-07-19 18:29:53 +02:00
|
|
|
|
2015-03-13 06:42:18 +01:00
|
|
|
category_filename = categories[cat]['filename'].replace('.rst', '.html')
|
|
|
|
for c in categories[cat]['classes']:
|
|
|
|
print >>out, '\t| ' + print_link(c['name'], symbols[c['name']])
|
|
|
|
for f in categories[cat]['functions']:
|
|
|
|
for n in f['names']:
|
|
|
|
print >>out, '\t| ' + print_link(n, symbols[n])
|
|
|
|
for e in categories[cat]['enums']:
|
|
|
|
print >>out, '\t| ' + print_link(e['name'], symbols[e['name']])
|
|
|
|
print >>out, ''
|
2013-07-24 07:04:46 +02:00
|
|
|
|
2015-03-13 06:42:18 +01:00
|
|
|
if 'overview' in categories[cat]:
|
|
|
|
print >>out, '\t__ %s#overview' % categories[cat]['filename'].replace('.rst', '.html')
|
|
|
|
print >>out, dump_link_targets('\t')
|
2013-08-18 22:17:11 +02:00
|
|
|
|
2013-07-24 07:04:46 +02:00
|
|
|
|
2015-03-13 06:42:18 +01:00
|
|
|
out = open('reference.rst', 'w+')
|
|
|
|
out.write('''=======================
|
|
|
|
reference documentation
|
|
|
|
=======================
|
2013-07-24 07:04:46 +02:00
|
|
|
|
2015-03-13 06:42:18 +01:00
|
|
|
''')
|
2013-07-24 07:04:46 +02:00
|
|
|
|
2015-03-13 06:42:18 +01:00
|
|
|
for i in range(4):
|
2013-07-24 07:04:46 +02:00
|
|
|
|
2015-03-13 06:42:18 +01:00
|
|
|
out.write('.. container:: main-toc\n\n')
|
|
|
|
print_toc(out, categories, i)
|
2013-07-19 18:29:53 +02:00
|
|
|
|
|
|
|
out.close()
|
|
|
|
|
|
|
|
for cat in categories:
|
|
|
|
out = open(categories[cat]['filename'], 'w+')
|
|
|
|
|
|
|
|
classes = categories[cat]['classes']
|
|
|
|
functions = categories[cat]['functions']
|
|
|
|
enums = categories[cat]['enums']
|
|
|
|
|
2013-08-17 04:00:41 +02:00
|
|
|
out.write('''
|
2014-10-14 04:06:20 +02:00
|
|
|
:Author: Arvid Norberg, arvid@libtorrent.org
|
2014-10-22 09:05:10 +02:00
|
|
|
:Version: 1.1.0
|
2013-08-17 04:00:41 +02:00
|
|
|
|
2015-03-14 02:51:08 +01:00
|
|
|
%s
|
|
|
|
|
2013-08-17 04:00:41 +02:00
|
|
|
.. contents:: Table of contents
|
2015-03-14 02:51:08 +01:00
|
|
|
:depth: 2
|
2013-08-17 04:00:41 +02:00
|
|
|
:backlinks: none
|
|
|
|
|
2015-03-14 02:51:08 +01:00
|
|
|
''' % heading(cat, '='))
|
2013-08-17 04:00:41 +02:00
|
|
|
|
2013-07-21 23:23:21 +02:00
|
|
|
if 'overview' in categories[cat]:
|
2013-08-17 09:01:03 +02:00
|
|
|
out.write('%s\n' % linkify_symbols(categories[cat]['overview']))
|
2013-07-21 23:23:21 +02:00
|
|
|
|
2013-07-19 18:29:53 +02:00
|
|
|
for c in classes:
|
2013-07-25 06:56:24 +02:00
|
|
|
|
|
|
|
print >>out, '.. raw:: html\n'
|
|
|
|
print >>out, '\t<a name="%s"></a>' % c['name']
|
|
|
|
print >>out, ''
|
|
|
|
|
2013-07-24 07:04:46 +02:00
|
|
|
out.write('%s\n' % heading(c['name'], '-'))
|
2013-07-19 18:29:53 +02:00
|
|
|
print_declared_in(out, c)
|
2013-08-05 07:26:15 +02:00
|
|
|
c['desc'] = linkify_symbols(c['desc'])
|
|
|
|
out.write('%s\n' % c['desc'])
|
|
|
|
print >>out, dump_link_targets()
|
|
|
|
|
|
|
|
print >>out,'\n.. parsed-literal::\n\t'
|
2013-07-19 18:29:53 +02:00
|
|
|
|
2013-07-24 07:04:46 +02:00
|
|
|
block = '\n%s\n{\n' % c['decl']
|
2013-07-19 18:29:53 +02:00
|
|
|
for f in c['fun']:
|
2013-07-21 07:04:04 +02:00
|
|
|
for s in f['signatures']:
|
2013-07-24 07:04:46 +02:00
|
|
|
block += ' %s\n' % highlight_signature(s.replace('\n', '\n '))
|
2013-07-19 18:29:53 +02:00
|
|
|
|
2013-07-24 07:04:46 +02:00
|
|
|
if len(c['fun']) > 0 and len(c['enums']) > 0: block += '\n'
|
2013-07-19 18:29:53 +02:00
|
|
|
|
|
|
|
first = True
|
|
|
|
for e in c['enums']:
|
|
|
|
if not first:
|
2013-07-24 07:04:46 +02:00
|
|
|
block += '\n'
|
2013-07-19 18:29:53 +02:00
|
|
|
first = False
|
2013-07-24 07:04:46 +02:00
|
|
|
block += ' enum %s\n {\n' % e['name']
|
2013-07-19 18:29:53 +02:00
|
|
|
for v in e['values']:
|
2013-07-24 07:04:46 +02:00
|
|
|
block += ' %s,\n' % v['name']
|
|
|
|
block += ' };\n'
|
2013-07-19 18:29:53 +02:00
|
|
|
|
2013-07-24 07:04:46 +02:00
|
|
|
if len(c['fun']) + len(c['enums']) > 0 and len(c['fields']): block += '\n'
|
2013-07-19 18:29:53 +02:00
|
|
|
|
|
|
|
for f in c['fields']:
|
2013-07-21 07:04:04 +02:00
|
|
|
for s in f['signatures']:
|
2013-07-24 07:04:46 +02:00
|
|
|
block += ' %s\n' % s
|
|
|
|
|
|
|
|
block += '};'
|
2013-07-19 18:29:53 +02:00
|
|
|
|
2013-07-24 07:04:46 +02:00
|
|
|
print >>out, block.replace('\n', '\n\t') + '\n'
|
2013-07-19 18:29:53 +02:00
|
|
|
|
|
|
|
for f in c['fun']:
|
|
|
|
if f['desc'] == '': continue
|
2013-07-24 07:04:46 +02:00
|
|
|
title = ''
|
2013-07-25 06:56:24 +02:00
|
|
|
print >>out, '.. raw:: html\n'
|
|
|
|
for n in f['names']:
|
|
|
|
print >>out, '\t<a name="%s"></a>' % n
|
|
|
|
print >>out, ''
|
2013-07-21 07:04:04 +02:00
|
|
|
for n in f['names']:
|
2013-08-05 07:26:15 +02:00
|
|
|
title += '%s ' % n
|
2013-07-24 07:04:46 +02:00
|
|
|
print >>out, heading(title.strip(), '.')
|
|
|
|
|
|
|
|
block = '.. parsed-literal::\n\n'
|
|
|
|
|
2013-07-21 07:04:04 +02:00
|
|
|
for s in f['signatures']:
|
2013-07-24 07:04:46 +02:00
|
|
|
block += highlight_signature(s.replace('\n', '\n ')) + '\n'
|
|
|
|
print >>out, '%s\n' % block.replace('\n', '\n\t')
|
2013-08-05 07:26:15 +02:00
|
|
|
f['desc'] = linkify_symbols(f['desc'])
|
2013-07-24 07:04:46 +02:00
|
|
|
print >>out, '%s' % f['desc']
|
2015-07-11 07:51:30 +02:00
|
|
|
|
2013-08-05 07:26:15 +02:00
|
|
|
print >>out, dump_link_targets()
|
2013-07-19 18:29:53 +02:00
|
|
|
|
2015-03-14 22:55:26 +01:00
|
|
|
render_enums(out, c['enums'], False, '.')
|
2013-07-19 18:29:53 +02:00
|
|
|
|
2013-07-19 18:57:07 +02:00
|
|
|
for f in c['fields']:
|
|
|
|
if f['desc'] == '': continue
|
2013-07-25 06:56:24 +02:00
|
|
|
|
|
|
|
print >>out, '.. raw:: html\n'
|
|
|
|
for n in f['names']:
|
|
|
|
print >>out, '\t<a name="%s"></a>' % n
|
|
|
|
print >>out, ''
|
|
|
|
|
2013-07-21 07:04:04 +02:00
|
|
|
for n in f['names']:
|
2013-07-24 07:04:46 +02:00
|
|
|
print >>out, '%s ' % n,
|
|
|
|
print >>out, ''
|
2013-08-05 07:26:15 +02:00
|
|
|
f['desc'] = linkify_symbols(f['desc'])
|
2013-07-24 07:04:46 +02:00
|
|
|
print >>out, '\t%s' % f['desc'].replace('\n', '\n\t')
|
2013-07-19 18:57:07 +02:00
|
|
|
|
2013-08-05 07:26:15 +02:00
|
|
|
print >>out, dump_link_targets()
|
|
|
|
|
2013-07-19 18:57:07 +02:00
|
|
|
|
2013-07-19 18:29:53 +02:00
|
|
|
for f in functions:
|
2013-07-24 07:04:46 +02:00
|
|
|
h = ''
|
2013-07-25 06:56:24 +02:00
|
|
|
print >>out, '.. raw:: html\n'
|
|
|
|
for n in f['names']:
|
|
|
|
print >>out, '\t<a name="%s"></a>' % n
|
|
|
|
print >>out, ''
|
2013-07-21 07:04:04 +02:00
|
|
|
for n in f['names']:
|
2013-08-05 07:26:15 +02:00
|
|
|
h += '%s ' % n
|
2015-03-14 22:55:26 +01:00
|
|
|
print >>out, heading(h, '-')
|
2013-07-19 18:29:53 +02:00
|
|
|
print_declared_in(out, f)
|
2013-07-21 07:04:04 +02:00
|
|
|
|
2013-07-24 07:04:46 +02:00
|
|
|
block = '.. parsed-literal::\n\n'
|
2013-07-21 07:04:04 +02:00
|
|
|
for s in f['signatures']:
|
2013-07-24 07:04:46 +02:00
|
|
|
block += highlight_signature(s) + '\n'
|
|
|
|
|
|
|
|
print >>out, '%s\n' % block.replace('\n', '\n\t')
|
2013-08-05 07:26:15 +02:00
|
|
|
print >>out, linkify_symbols(f['desc'])
|
2013-07-24 07:04:46 +02:00
|
|
|
|
2013-08-05 07:26:15 +02:00
|
|
|
print >>out, dump_link_targets()
|
2015-07-11 07:51:30 +02:00
|
|
|
|
2015-03-14 22:55:26 +01:00
|
|
|
render_enums(out, enums, True, '-')
|
2013-07-24 07:04:46 +02:00
|
|
|
|
|
|
|
print >>out, dump_link_targets()
|
2013-07-19 18:29:53 +02:00
|
|
|
|
2013-08-11 08:04:24 +02:00
|
|
|
for i in static_links:
|
|
|
|
print >>out, i
|
|
|
|
|
2013-07-19 18:29:53 +02:00
|
|
|
out.close()
|
|
|
|
|
2013-08-11 18:57:33 +02:00
|
|
|
#for s in symbols:
|
|
|
|
# print s
|
|
|
|
|
|
|
|
for i,o in preprocess_rst.items():
|
|
|
|
f = open(i, 'r')
|
|
|
|
out = open(o, 'w+')
|
|
|
|
print 'processing %s -> %s' % (i, o)
|
|
|
|
l = linkify_symbols(f.read())
|
|
|
|
print >>out, l,
|
|
|
|
|
|
|
|
print >>out, dump_link_targets()
|
|
|
|
|
|
|
|
out.close()
|
|
|
|
f.close()
|
2015-07-11 07:51:30 +02:00
|
|
|
|
2013-08-11 18:57:33 +02:00
|
|
|
|