Browse Source

-p added

master
Jonathan Spratte 1 year ago
parent
commit
52cede0bb4
5 changed files with 52 additions and 26 deletions
  1. 2
    0
      .gitignore
  2. 1
    1
      README.md
  3. BIN
      documentation.pdf
  4. 24
    8
      documentation.tex
  5. 25
    17
      listings-extx.py

+ 2
- 0
.gitignore View File

@@ -1,3 +1,5 @@
1 1
 documentation.aux
2 2
 documentation.log
3
+documentation.out
4
+documentation.toc
3 5
 example.lst

+ 1
- 1
README.md View File

@@ -5,7 +5,7 @@ Author
5 5
 : Jonathan P. Spratte
6 6
 
7 7
 Version
8
-: 1.0
8
+: 1.0.1
9 9
 
10 10
 Copyright (c)
11 11
 : 2019 Jonathan P. Spratte

BIN
documentation.pdf View File


+ 24
- 8
documentation.tex View File

@@ -10,14 +10,14 @@
10 10
 \makeatother
11 11
 
12 12
 \title{\py}
13
-\author{Jonathan P.\@ Spratte}
13
+\subtitle{1.0.1}
14
+\author{Jonathan P.\@ Spratte\thanks{\texttt{jspratte(at)yahoo.de}}}
14 15
 \date{\today}
15 16
 
16 17
 \usepackage{listings}
17 18
 \usepackage{listings-ext}
18 19
 \usepackage{enumitem}
19 20
 \usepackage{xcolor}
20
-\usepackage[]{url}
21 21
 %% call listings-extx.py with:
22 22
 %%   ./listings-extx.py -o example.lst example.c
23 23
 \input{example.lst}
@@ -42,8 +42,11 @@
42 42
     ,keywordstyle=[3]{\bfseries\color{blue!50!black}}
43 43
   }
44 44
 
45
+\usepackage[colorlinks]{hyperref}
46
+
45 47
 \begin{document}
46 48
 \maketitle
49
+\tableofcontents
47 50
 
48 51
 \section{Introduction}
49 52
 \py\ was created because I liked the idea of the \pkg{listings-ext} package and
@@ -55,7 +58,7 @@ This script does extract lines and line ranges from a source file and outputs
55 58
 those ranges with \cs{lstdef}-calls so that \pkg{listings-ext} can understand
56 59
 them. Line ranges are marked using formatted comments.
57 60
 
58
-This script require Python3 to be installed, it contains a shebang
61
+This script requires Python3 to be installed, it contains a shebang
59 62
 \lstinline|#!/bin/python3| which should run the correct Python version on most
60 63
 Unix systems on which Python3 is installed. However this doesn't work on Windows
61 64
 where you'll have to call it with \lstinline|python listings-extx.py|.
@@ -127,6 +130,10 @@ few command line parameters to control its behaviour, the order doesn't matter,
127 130
 parameters can be given before or after file names. Arguments to parameters are
128 131
 always mandatory. The output will be printed
129 132
 to \texttt{stdout} by default.
133
+\begin{lstlisting}[style=regex, keywordstyle={}]
134
+listings-extx.py [<options>] <filename> ...
135
+\end{lstlisting}
136
+\meta{options} can be any number of:
130 137
 \begin{description}[font=-\ttfamily]
131 138
   \item[a, --abs-path]
132 139
     use the absolute file path instead of the path given as argument.
@@ -138,6 +145,14 @@ to \texttt{stdout} by default.
138 145
     to match C-style comments this would be \lstinline{'//|/\*'}.
139 146
   \item[h]
140 147
     print a short help and exit
148
+  \item[o, --output-file=\meta{output filename}]
149
+    if this argument is present, the output will be written into a file
150
+    \meta{output filename}; if \meta{output filename} is an empty string, the
151
+    output is redirected into a file with a basename corresponding to the name
152
+    of the current directory with the extension '.lst'.
153
+  \item[p, --prefix=\meta{string}]
154
+    prefix every identifier with this \meta{string}, if both this and the
155
+    \texttt{--basename} option is used, the prefix is added before the basename.
141 156
   \item[S, --silent]
142 157
     If used the program doesn't report which files to process and where to write
143 158
     the output to.
@@ -152,11 +167,6 @@ to \texttt{stdout} by default.
152 167
       \item['none']
153 168
         no spaces are allowed before the start of the comment
154 169
     \end{description}
155
-  \item[o, --output-file=\meta{output filename}]
156
-    if this argument is present, the output will be written into a file
157
-    \meta{output filename}; if \meta{output filename} is an empty string, the
158
-    output is redirected into a file with a basename corresponding to the name
159
-    of the current directory with the extension '.lst'.
160 170
   \item[v, --version]
161 171
     Print some version information and exit
162 172
 \end{description}
@@ -173,6 +183,12 @@ listings-extx.py -o example.lst example.c
173 183
 The following is the output in \file{example.lst}:
174 184
 \lstinputlisting[language=TeX]{example.lst}
175 185
 
186
+\section{Bugreports}
187
+If you find any bugs, you can report them via mail (see the footnote on the
188
+first page; please use a descriptive subject). This script is hosted at
189
+\url{https://gitlass.de/jonathan/listings-extx.py}, you could report bugs there,
190
+too, but chances are you don't have an account there.
191
+
176 192
 \begin{thebibliography}{9}
177 193
   \bibitem{lstext}
178 194
     Jobst Hoffmann,

+ 25
- 17
listings-extx.py View File

@@ -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__":

Loading…
Cancel
Save