|
@@ -2,7 +2,7 @@
|
2
|
2
|
|
3
|
3
|
## listings-extx.py -- Some program to get named entries for listings-ext
|
4
|
4
|
## Author: Jonathan P. Spratte <j.spratte(at)yahoo.de>
|
5
|
|
-## Version: 1.0
|
|
5
|
+## Version: 1.0.1
|
6
|
6
|
## Keywords: LaTeX, listings
|
7
|
7
|
## Copyright (C) 2019 Jonathan P. Spratte <j.spratte(at)yahoo.de>
|
8
|
8
|
##-------------------------------------------------------------------
|
|
@@ -85,7 +85,7 @@ class Object(object): # hacky way to have a nice parameters structure {{{
|
85
|
85
|
pass# }}}
|
86
|
86
|
|
87
|
87
|
def print_version():# {{{
|
88
|
|
- print("listings-extx.py v1.0")
|
|
88
|
+ print("listings-extx.py v1.0.1")
|
89
|
89
|
print("Copyright (C) 2019 Jonathan P. Spratte")
|
90
|
90
|
print_wrapped(
|
91
|
91
|
"License GPLv3+: GNU GPL version 3 or later "
|
|
@@ -134,6 +134,8 @@ def arg_parse(name,argv,parameters):# {{{
|
134
|
134
|
parameters.comment_char = arg
|
135
|
135
|
elif opt in ("-o", "--output-file"):
|
136
|
136
|
parameters.output = arg
|
|
137
|
+ elif opt in ("-p", "--prefix"):
|
|
138
|
+ parameters.prefix = arg
|
137
|
139
|
elif opt in ("-S", "--silent"):
|
138
|
140
|
parameters.silent = True
|
139
|
141
|
elif opt in ("-s", "--spaces"):
|
|
@@ -180,39 +182,44 @@ def give_help(name,err=0):# {{{
|
180
|
182
|
"prefix every identifier with the processed file's basename "
|
181
|
183
|
+ "followed by a period."
|
182
|
184
|
)
|
183
|
|
- print_opt("-c, --comment-char <regex>",
|
|
185
|
+ print_opt("-c, --comment-char=<regex>",
|
184
|
186
|
"use <regex> as the comment starting character. For "
|
185
|
187
|
+ "instance to match C-style comments this would be '//|/\*'."
|
186
|
188
|
)
|
187
|
189
|
print_opt("-h", "print this help and exit")
|
|
190
|
+ print_opt("-o, --output-file=<output filename>",
|
|
191
|
+ "if this argument is present, the output "
|
|
192
|
+ + "will be written into a file <output filename>; "
|
|
193
|
+ + "if <output filename> is an empty string, the output is "
|
|
194
|
+ + "redirected into a file with a basename corresponding to the "
|
|
195
|
+ + "name of the current directory with the extension '.lst'"
|
|
196
|
+ )
|
|
197
|
+ print_opt("-p, --prefix=<string>",
|
|
198
|
+ "prefix every identifier with this <string>, if both this and the "
|
|
199
|
+ + "'--basename' option is used, the prefix is added before the "
|
|
200
|
+ + "basename."
|
|
201
|
+ )
|
188
|
202
|
print_opt("-S, --silent",
|
189
|
203
|
"If used the program doesn't report which files to process and "
|
190
|
204
|
+ "where to write the output to."
|
191
|
205
|
)
|
192
|
|
- print_opt("-s, --spaces <choice>",
|
|
206
|
+ print_opt("-s, --spaces=<choice>",
|
193
|
207
|
"Defines how spaces at the begin of the line are handled. "
|
194
|
208
|
+ "<choice> must be one of:"
|
195
|
209
|
)
|
196
|
210
|
print_opt("'must'",
|
197
|
211
|
"(default) there must be spaces before the start of the "
|
198
|
212
|
+ "comment",
|
199
|
|
- indent="\t\t", moreindent=" "
|
|
213
|
+ indent="\t\t", moreindent=" "
|
200
|
214
|
)
|
201
|
215
|
print_opt("'can'",
|
202
|
216
|
"there can be spaces before the start of the comment",
|
203
|
|
- indent="\t\t", moreindent="\t\t "
|
|
217
|
+ indent="\t\t", moreindent=" "
|
204
|
218
|
)
|
205
|
219
|
print_opt("'none'",
|
206
|
220
|
"no spaces are allowed before the start of the comment",
|
207
|
|
- indent="\t\t", moreindent="\t\t "
|
|
221
|
+ indent="\t\t", moreindent=" "
|
208
|
222
|
)
|
209
|
|
- print_opt("-o, --output-file <output filename>",
|
210
|
|
- "if this argument is present, the output "
|
211
|
|
- + "will be written into a file <output filename>; "
|
212
|
|
- + "if <output filename> is an empty string, the output is "
|
213
|
|
- + "redirected into a file with a basename corresponding to the "
|
214
|
|
- + "name of the current directory with the extension '.lst'"
|
215
|
|
- )
|
216
|
223
|
print_opt("-v, --version", "Print some version information and exit")
|
217
|
224
|
quit(err)# }}}
|
218
|
225
|
|
|
@@ -322,9 +329,9 @@ def process_file(fname, parameters):# {{{
|
322
|
329
|
be = [ (name, lines) for name, lines in be.items() ]
|
323
|
330
|
return (fname, ba + bj + be)# }}}
|
324
|
331
|
|
325
|
|
-def write_code_point(f, code_point, out, basename):# {{{
|
|
332
|
+def write_code_point(f, code_point, out, prefix, basename):# {{{
|
326
|
333
|
b = Path(f).stem + "." if basename else ""
|
327
|
|
- out.write("\\lstdef{"+b+code_point[0]+"}{"+f+"}{"+code_point[1]+"}\n")# }}}
|
|
334
|
+ out.write("\\lstdef{"+p+b+code_point[0]+"}{"+f+"}{"+code_point[1]+"}\n")# }}}
|
328
|
335
|
|
329
|
336
|
def main(name,args):# {{{
|
330
|
337
|
parameters = Object()
|
|
@@ -335,6 +342,7 @@ def main(name,args):# {{{
|
335
|
342
|
parameters.comment_char = False
|
336
|
343
|
parameters.basename = False
|
337
|
344
|
parameters.no_spaces = 0
|
|
345
|
+ parameters.prefix = ""
|
338
|
346
|
arg_parse(name,args,parameters)
|
339
|
347
|
if len(parameters.files) == 0:
|
340
|
348
|
eprint("No input files given")
|
|
@@ -371,7 +379,7 @@ def main(name,args):# {{{
|
371
|
379
|
if not needs_close: print()
|
372
|
380
|
for f, cc in code_points:
|
373
|
381
|
for c in cc:
|
374
|
|
- write_code_point(f, c, out, parameters.basename)
|
|
382
|
+ write_code_point(f, c, out, parameters.prefix, parameters.basename)
|
375
|
383
|
if needs_close: out.close()# }}}
|
376
|
384
|
|
377
|
385
|
if __name__ == "__main__":
|