aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/literasc.py
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/literasc.py')
-rwxr-xr-xplugins/literasc.py36
1 files changed, 25 insertions, 11 deletions
diff --git a/plugins/literasc.py b/plugins/literasc.py
index b7b65cd..0bcd8f2 100755
--- a/plugins/literasc.py
+++ b/plugins/literasc.py
@@ -20,7 +20,7 @@ def format_text(text):
def format_code(lang, code):
if code.strip() == '':
return code
-
+
head = '[source,%s]' % lang
sep = '-' * len(head) + '\n'
return head + '\n' + sep + code.strip('\n') + '\n' + sep
@@ -36,16 +36,30 @@ def format_c_source(filename, file):
for line in file:
code += line
+ # Skip initial license comment
+ if code[0:2] == '/*':
+ code = code[code.find('*/') + 2:]
+
for c in code:
if prev_c == '/' and c == '*':
- output += format_code('c', chunk[0:len(chunk)-1])
- in_comment = True
in_comment_start = True
n_stars = 1
- chunk = ''
+ elif in_comment_start:
+ if c == '*':
+ n_stars += 1
+ else:
+ if n_stars > 1:
+ output += format_code('c', chunk[0:len(chunk) - 1])
+ chunk = ''
+ in_comment = True
+ else:
+ chunk += '*' + c
+ in_comment_start = False
elif in_comment and prev_c == '*' and c == '/':
- if n_stars > 2:
- output += format_text(chunk[0:len(chunk)-1])
+ if n_stars > 1:
+ output += format_text(chunk[0:len(chunk) - 1])
+ else:
+ output += format_code('c', '/* ' + chunk[0:len(chunk) - 1] + '*/')
in_comment = False
in_comment_start = False
chunk = ''
@@ -73,7 +87,7 @@ def format_ttl_source(filename, file):
chunk = line
else:
if is_comment:
- output += format_code('txt', chunk)
+ output += format_code('turtle', chunk)
in_comment = True
chunk = line.strip().lstrip('# ') + ' \n'
else:
@@ -82,7 +96,7 @@ def format_ttl_source(filename, file):
if in_comment:
return output + format_text(chunk)
else:
- return output + format_code('txt', chunk)
+ return output + format_code('turtle', chunk)
def gen(out, filenames):
for filename in filenames:
@@ -91,7 +105,7 @@ def gen(out, filenames):
sys.stderr.write('Failed to open file %s\n' % filename)
continue
- if filename.endswith('.c'):
+ if filename.endswith('.c') or filename.endswith('.h'):
out.write(format_c_source(filename, file))
elif filename.endswith('.ttl') or filename.endswith('.ttl.in'):
out.write(format_ttl_source(filename, file))
@@ -101,10 +115,10 @@ def gen(out, filenames):
out.write('\n')
else:
sys.stderr.write("Unknown source format `%s'" % (
- filename[filename.find('.'):]))
+ filename[filename.find('.'):]))
file.close()
-
+
if __name__ == "__main__":
if len(sys.argv) < 2:
sys.stderr.write('Usage: %s FILENAME...\n' % sys.argv[1])