src/c2html.c

Tue, 23 Aug 2016 13:59:48 +0200

author
Mike Becker <universe@uap-core.de>
date
Tue, 23 Aug 2016 13:59:48 +0200
changeset 40
903b46fc4214
parent 39
ac35daceb24c
child 41
c06ab07fd29d
permissions
-rw-r--r--

fixes plaintext output

23
f44a185b678b fixed licenses
Mike Becker <universe@uap-core.de>
parents: 22
diff changeset
1 /*
f44a185b678b fixed licenses
Mike Becker <universe@uap-core.de>
parents: 22
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
f44a185b678b fixed licenses
Mike Becker <universe@uap-core.de>
parents: 22
diff changeset
3 *
35
abaf2489c549 adjusted copyright info
Mike Becker <universe@uap-core.de>
parents: 30
diff changeset
4 * Copyright 2016 Mike Becker. All rights reserved.
23
f44a185b678b fixed licenses
Mike Becker <universe@uap-core.de>
parents: 22
diff changeset
5 *
f44a185b678b fixed licenses
Mike Becker <universe@uap-core.de>
parents: 22
diff changeset
6 * Redistribution and use in source and binary forms, with or without
f44a185b678b fixed licenses
Mike Becker <universe@uap-core.de>
parents: 22
diff changeset
7 * modification, are permitted provided that the following conditions are met:
f44a185b678b fixed licenses
Mike Becker <universe@uap-core.de>
parents: 22
diff changeset
8 *
f44a185b678b fixed licenses
Mike Becker <universe@uap-core.de>
parents: 22
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
f44a185b678b fixed licenses
Mike Becker <universe@uap-core.de>
parents: 22
diff changeset
10 * notice, this list of conditions and the following disclaimer.
f44a185b678b fixed licenses
Mike Becker <universe@uap-core.de>
parents: 22
diff changeset
11 *
f44a185b678b fixed licenses
Mike Becker <universe@uap-core.de>
parents: 22
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
f44a185b678b fixed licenses
Mike Becker <universe@uap-core.de>
parents: 22
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
f44a185b678b fixed licenses
Mike Becker <universe@uap-core.de>
parents: 22
diff changeset
14 * documentation and/or other materials provided with the distribution.
f44a185b678b fixed licenses
Mike Becker <universe@uap-core.de>
parents: 22
diff changeset
15 *
f44a185b678b fixed licenses
Mike Becker <universe@uap-core.de>
parents: 22
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
f44a185b678b fixed licenses
Mike Becker <universe@uap-core.de>
parents: 22
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
f44a185b678b fixed licenses
Mike Becker <universe@uap-core.de>
parents: 22
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
f44a185b678b fixed licenses
Mike Becker <universe@uap-core.de>
parents: 22
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
f44a185b678b fixed licenses
Mike Becker <universe@uap-core.de>
parents: 22
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
f44a185b678b fixed licenses
Mike Becker <universe@uap-core.de>
parents: 22
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
f44a185b678b fixed licenses
Mike Becker <universe@uap-core.de>
parents: 22
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
f44a185b678b fixed licenses
Mike Becker <universe@uap-core.de>
parents: 22
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
f44a185b678b fixed licenses
Mike Becker <universe@uap-core.de>
parents: 22
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
f44a185b678b fixed licenses
Mike Becker <universe@uap-core.de>
parents: 22
diff changeset
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
f44a185b678b fixed licenses
Mike Becker <universe@uap-core.de>
parents: 22
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
f44a185b678b fixed licenses
Mike Becker <universe@uap-core.de>
parents: 22
diff changeset
27 *
f44a185b678b fixed licenses
Mike Becker <universe@uap-core.de>
parents: 22
diff changeset
28 */
22
f463693b5eeb added command line parameters for header and footer file
Mike Becker <universe@uap-core.de>
parents: 21
diff changeset
29 #include "c2html.h"
1
12c482ea4fc4 first prototype: creates unformatted output with line numbers
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
30
39
ac35daceb24c adds UCX + changes how the input file is read (uses an consecutive memory area now)
Mike Becker <universe@uap-core.de>
parents: 38
diff changeset
31 #include "ucx/buffer.h"
ac35daceb24c adds UCX + changes how the input file is read (uses an consecutive memory area now)
Mike Becker <universe@uap-core.de>
parents: 38
diff changeset
32 #include "ucx/list.h"
ac35daceb24c adds UCX + changes how the input file is read (uses an consecutive memory area now)
Mike Becker <universe@uap-core.de>
parents: 38
diff changeset
33 #include "ucx/utils.h"
1
12c482ea4fc4 first prototype: creates unformatted output with line numbers
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
34
12c482ea4fc4 first prototype: creates unformatted output with line numbers
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
35 void printhelp() {
19
2e812df2b231 formatted with 4 spaces
Mike Becker <universe@uap-core.de>
parents: 18
diff changeset
36 printf("Formats source code using HTML.\n\nUsage:\n"
2e812df2b231 formatted with 4 spaces
Mike Becker <universe@uap-core.de>
parents: 18
diff changeset
37 " c2html [Options] FILE\n\n"
2e812df2b231 formatted with 4 spaces
Mike Becker <universe@uap-core.de>
parents: 18
diff changeset
38 " Options:\n"
2e812df2b231 formatted with 4 spaces
Mike Becker <universe@uap-core.de>
parents: 18
diff changeset
39 " -h Prints this help message\n"
2e812df2b231 formatted with 4 spaces
Mike Becker <universe@uap-core.de>
parents: 18
diff changeset
40 " -j Highlight Java instead of C source code\n"
2e812df2b231 formatted with 4 spaces
Mike Becker <universe@uap-core.de>
parents: 18
diff changeset
41 " -o <output> Output file (stdout, if not specified)\n"
22
f463693b5eeb added command line parameters for header and footer file
Mike Becker <universe@uap-core.de>
parents: 21
diff changeset
42 " -H <header> Prepend header file\n"
f463693b5eeb added command line parameters for header and footer file
Mike Becker <universe@uap-core.de>
parents: 21
diff changeset
43 " -F <footer> Append footer file\n"
19
2e812df2b231 formatted with 4 spaces
Mike Becker <universe@uap-core.de>
parents: 18
diff changeset
44 " -p Disable highlighting (plain text)\n"
24
e43dee5892f4 improved code structure and added option for disabling line numbers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
45 " -l Disable line numbers\n"
37
1a67185e5496 adds version number and changes build system
Mike Becker <universe@uap-core.de>
parents: 36
diff changeset
46 " -V, -v Prints version and exits\n"
19
2e812df2b231 formatted with 4 spaces
Mike Becker <universe@uap-core.de>
parents: 18
diff changeset
47 "\n");
1
12c482ea4fc4 first prototype: creates unformatted output with line numbers
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
48 }
12c482ea4fc4 first prototype: creates unformatted output with line numbers
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
49
22
f463693b5eeb added command line parameters for header and footer file
Mike Becker <universe@uap-core.de>
parents: 21
diff changeset
50 int copyfile(char *filename, FILE *dest) {
f463693b5eeb added command line parameters for header and footer file
Mike Becker <universe@uap-core.de>
parents: 21
diff changeset
51 if (!filename) {
f463693b5eeb added command line parameters for header and footer file
Mike Becker <universe@uap-core.de>
parents: 21
diff changeset
52 return 0;
f463693b5eeb added command line parameters for header and footer file
Mike Becker <universe@uap-core.de>
parents: 21
diff changeset
53 }
f463693b5eeb added command line parameters for header and footer file
Mike Becker <universe@uap-core.de>
parents: 21
diff changeset
54
f463693b5eeb added command line parameters for header and footer file
Mike Becker <universe@uap-core.de>
parents: 21
diff changeset
55 FILE *src = fopen(filename, "r");
f463693b5eeb added command line parameters for header and footer file
Mike Becker <universe@uap-core.de>
parents: 21
diff changeset
56 if (src) {
f463693b5eeb added command line parameters for header and footer file
Mike Becker <universe@uap-core.de>
parents: 21
diff changeset
57 char buf[4096];
f463693b5eeb added command line parameters for header and footer file
Mike Becker <universe@uap-core.de>
parents: 21
diff changeset
58 int r;
f463693b5eeb added command line parameters for header and footer file
Mike Becker <universe@uap-core.de>
parents: 21
diff changeset
59 while ((r = fread(buf, 1, 4096, src)) > 0) {
f463693b5eeb added command line parameters for header and footer file
Mike Becker <universe@uap-core.de>
parents: 21
diff changeset
60 fwrite(buf, 1, r, dest);
f463693b5eeb added command line parameters for header and footer file
Mike Becker <universe@uap-core.de>
parents: 21
diff changeset
61 }
f463693b5eeb added command line parameters for header and footer file
Mike Becker <universe@uap-core.de>
parents: 21
diff changeset
62 fclose(src);
f463693b5eeb added command line parameters for header and footer file
Mike Becker <universe@uap-core.de>
parents: 21
diff changeset
63 return 0;
f463693b5eeb added command line parameters for header and footer file
Mike Becker <universe@uap-core.de>
parents: 21
diff changeset
64 } else {
39
ac35daceb24c adds UCX + changes how the input file is read (uses an consecutive memory area now)
Mike Becker <universe@uap-core.de>
parents: 38
diff changeset
65 return 1;
24
e43dee5892f4 improved code structure and added option for disabling line numbers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
66 }
e43dee5892f4 improved code structure and added option for disabling line numbers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
67 }
e43dee5892f4 improved code structure and added option for disabling line numbers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
68
e43dee5892f4 improved code structure and added option for disabling line numbers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
69 #define WRITECONST(stream, out, cstr) out(cstr, 1, sizeof(cstr)-1, stream)
e43dee5892f4 improved code structure and added option for disabling line numbers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
70 int formatfile(
e43dee5892f4 improved code structure and added option for disabling line numbers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
71 highlighter_t *highlighter,
39
ac35daceb24c adds UCX + changes how the input file is read (uses an consecutive memory area now)
Mike Becker <universe@uap-core.de>
parents: 38
diff changeset
72 UcxList *in,
ac35daceb24c adds UCX + changes how the input file is read (uses an consecutive memory area now)
Mike Becker <universe@uap-core.de>
parents: 38
diff changeset
73 write_func out,
24
e43dee5892f4 improved code structure and added option for disabling line numbers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
74 void *stream,
39
ac35daceb24c adds UCX + changes how the input file is read (uses an consecutive memory area now)
Mike Becker <universe@uap-core.de>
parents: 38
diff changeset
75 int showlineno) {
ac35daceb24c adds UCX + changes how the input file is read (uses an consecutive memory area now)
Mike Becker <universe@uap-core.de>
parents: 38
diff changeset
76 size_t lines = ucx_list_size(in);
24
e43dee5892f4 improved code structure and added option for disabling line numbers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
77
39
ac35daceb24c adds UCX + changes how the input file is read (uses an consecutive memory area now)
Mike Becker <universe@uap-core.de>
parents: 38
diff changeset
78 UcxBuffer *line = ucx_buffer_new(NULL, 1024, UCX_BUFFER_AUTOEXTEND);
24
e43dee5892f4 improved code structure and added option for disabling line numbers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
79 if(!line) {
e43dee5892f4 improved code structure and added option for disabling line numbers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
80 return 1;
22
f463693b5eeb added command line parameters for header and footer file
Mike Becker <universe@uap-core.de>
parents: 21
diff changeset
81 }
24
e43dee5892f4 improved code structure and added option for disabling line numbers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
82 WRITECONST(stream, out, "<pre>\n");
e43dee5892f4 improved code structure and added option for disabling line numbers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
83
39
ac35daceb24c adds UCX + changes how the input file is read (uses an consecutive memory area now)
Mike Becker <universe@uap-core.de>
parents: 38
diff changeset
84 int lnw;
ac35daceb24c adds UCX + changes how the input file is read (uses an consecutive memory area now)
Mike Becker <universe@uap-core.de>
parents: 38
diff changeset
85 {
ac35daceb24c adds UCX + changes how the input file is read (uses an consecutive memory area now)
Mike Becker <universe@uap-core.de>
parents: 38
diff changeset
86 lnw = 1;
ac35daceb24c adds UCX + changes how the input file is read (uses an consecutive memory area now)
Mike Becker <universe@uap-core.de>
parents: 38
diff changeset
87 int p = 1;
ac35daceb24c adds UCX + changes how the input file is read (uses an consecutive memory area now)
Mike Becker <universe@uap-core.de>
parents: 38
diff changeset
88 while ((p*=10) < lines) lnw++;
ac35daceb24c adds UCX + changes how the input file is read (uses an consecutive memory area now)
Mike Becker <universe@uap-core.de>
parents: 38
diff changeset
89 }
ac35daceb24c adds UCX + changes how the input file is read (uses an consecutive memory area now)
Mike Becker <universe@uap-core.de>
parents: 38
diff changeset
90
ac35daceb24c adds UCX + changes how the input file is read (uses an consecutive memory area now)
Mike Becker <universe@uap-core.de>
parents: 38
diff changeset
91 size_t lineno = 0;
ac35daceb24c adds UCX + changes how the input file is read (uses an consecutive memory area now)
Mike Becker <universe@uap-core.de>
parents: 38
diff changeset
92 UCX_FOREACH(sourceline, in) {
ac35daceb24c adds UCX + changes how the input file is read (uses an consecutive memory area now)
Mike Becker <universe@uap-core.de>
parents: 38
diff changeset
93 lineno++;
ac35daceb24c adds UCX + changes how the input file is read (uses an consecutive memory area now)
Mike Becker <universe@uap-core.de>
parents: 38
diff changeset
94 /* TODO: backwards compatibility: replace line->space in all occasions
ac35daceb24c adds UCX + changes how the input file is read (uses an consecutive memory area now)
Mike Becker <universe@uap-core.de>
parents: 38
diff changeset
95 * and use UcxBuffer functions
ac35daceb24c adds UCX + changes how the input file is read (uses an consecutive memory area now)
Mike Becker <universe@uap-core.de>
parents: 38
diff changeset
96 */
24
e43dee5892f4 improved code structure and added option for disabling line numbers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
97 if (highlighter) {
39
ac35daceb24c adds UCX + changes how the input file is read (uses an consecutive memory area now)
Mike Becker <universe@uap-core.de>
parents: 38
diff changeset
98 highlighter->parser(sourceline->data, line->space, highlighter);
24
e43dee5892f4 improved code structure and added option for disabling line numbers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
99 } else {
39
ac35daceb24c adds UCX + changes how the input file is read (uses an consecutive memory area now)
Mike Becker <universe@uap-core.de>
parents: 38
diff changeset
100 char *c = sourceline->data;
30
0bfd4d6f086a added HTML escaping for plain text files
Mike Becker <universe@uap-core.de>
parents: 27
diff changeset
101 size_t dp = 0;
40
903b46fc4214 fixes plaintext output
Mike Becker <universe@uap-core.de>
parents: 39
diff changeset
102 while (*c && *c != '\n') {
39
ac35daceb24c adds UCX + changes how the input file is read (uses an consecutive memory area now)
Mike Becker <universe@uap-core.de>
parents: 38
diff changeset
103 dp = writeescapedchar(line->space, dp, *c);
30
0bfd4d6f086a added HTML escaping for plain text files
Mike Becker <universe@uap-core.de>
parents: 27
diff changeset
104 c++;
0bfd4d6f086a added HTML escaping for plain text files
Mike Becker <universe@uap-core.de>
parents: 27
diff changeset
105 }
40
903b46fc4214 fixes plaintext output
Mike Becker <universe@uap-core.de>
parents: 39
diff changeset
106 line->space[dp++] = '\n';
39
ac35daceb24c adds UCX + changes how the input file is read (uses an consecutive memory area now)
Mike Becker <universe@uap-core.de>
parents: 38
diff changeset
107 line->space[dp] = '\0';
24
e43dee5892f4 improved code structure and added option for disabling line numbers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
108 }
30
0bfd4d6f086a added HTML escaping for plain text files
Mike Becker <universe@uap-core.de>
parents: 27
diff changeset
109
24
e43dee5892f4 improved code structure and added option for disabling line numbers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
110 // write line number
39
ac35daceb24c adds UCX + changes how the input file is read (uses an consecutive memory area now)
Mike Becker <universe@uap-core.de>
parents: 38
diff changeset
111 if (showlineno) {
24
e43dee5892f4 improved code structure and added option for disabling line numbers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
112 WRITECONST(stream, out, "<span class=\"c2html-lineno\">");
27
53fd8595378c added links for line numbers
Mike Becker <universe@uap-core.de>
parents: 25
diff changeset
113 char lnbuf[128];
53fd8595378c added links for line numbers
Mike Becker <universe@uap-core.de>
parents: 25
diff changeset
114 int len;
53fd8595378c added links for line numbers
Mike Becker <universe@uap-core.de>
parents: 25
diff changeset
115 // line number link
53fd8595378c added links for line numbers
Mike Becker <universe@uap-core.de>
parents: 25
diff changeset
116 len = snprintf(lnbuf, 128, "<a name=\"l%d\" href=\"#l%d\">",
39
ac35daceb24c adds UCX + changes how the input file is read (uses an consecutive memory area now)
Mike Becker <universe@uap-core.de>
parents: 38
diff changeset
117 lineno, lineno);
24
e43dee5892f4 improved code structure and added option for disabling line numbers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
118 out(lnbuf, 1, len, stream);
27
53fd8595378c added links for line numbers
Mike Becker <universe@uap-core.de>
parents: 25
diff changeset
119 // justified line number
39
ac35daceb24c adds UCX + changes how the input file is read (uses an consecutive memory area now)
Mike Becker <universe@uap-core.de>
parents: 38
diff changeset
120 len = snprintf(lnbuf, 128, "%*d ", lnw, lineno);
27
53fd8595378c added links for line numbers
Mike Becker <universe@uap-core.de>
parents: 25
diff changeset
121 out(lnbuf, 1, len, stream);
53fd8595378c added links for line numbers
Mike Becker <universe@uap-core.de>
parents: 25
diff changeset
122 WRITECONST(stream, out, "</a></span> ");
24
e43dee5892f4 improved code structure and added option for disabling line numbers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
123 }
e43dee5892f4 improved code structure and added option for disabling line numbers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
124
e43dee5892f4 improved code structure and added option for disabling line numbers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
125 // write formated (or plain) code line
39
ac35daceb24c adds UCX + changes how the input file is read (uses an consecutive memory area now)
Mike Becker <universe@uap-core.de>
parents: 38
diff changeset
126 out(line->space, 1, strlen(line->space), stream);
24
e43dee5892f4 improved code structure and added option for disabling line numbers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
127 }
e43dee5892f4 improved code structure and added option for disabling line numbers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
128
e43dee5892f4 improved code structure and added option for disabling line numbers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
129 WRITECONST(stream, out, "</pre>\n");
39
ac35daceb24c adds UCX + changes how the input file is read (uses an consecutive memory area now)
Mike Becker <universe@uap-core.de>
parents: 38
diff changeset
130 ucx_buffer_free(line);
24
e43dee5892f4 improved code structure and added option for disabling line numbers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
131 return 0;
e43dee5892f4 improved code structure and added option for disabling line numbers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
132 }
e43dee5892f4 improved code structure and added option for disabling line numbers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
133
e43dee5892f4 improved code structure and added option for disabling line numbers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
134 void init_c_highlighter(highlighter_t *highlighter) {
e43dee5892f4 improved code structure and added option for disabling line numbers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
135 memset(highlighter, 0, sizeof(highlighter_t));
36
be60c22cddfe fixed possible naming conflicts with is.* functions
Mike Becker <universe@uap-core.de>
parents: 35
diff changeset
136 highlighter->isdirective = check_cdirective;
be60c22cddfe fixed possible naming conflicts with is.* functions
Mike Becker <universe@uap-core.de>
parents: 35
diff changeset
137 highlighter->istype = check_ctype;
24
e43dee5892f4 improved code structure and added option for disabling line numbers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
138 highlighter->keywords = ckeywords;
e43dee5892f4 improved code structure and added option for disabling line numbers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
139 highlighter->parser = cparseline;
e43dee5892f4 improved code structure and added option for disabling line numbers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
140 }
e43dee5892f4 improved code structure and added option for disabling line numbers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
141
e43dee5892f4 improved code structure and added option for disabling line numbers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
142 void init_java_highlighter(highlighter_t *highlighter) {
e43dee5892f4 improved code structure and added option for disabling line numbers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
143 memset(highlighter, 0, sizeof(highlighter_t));
36
be60c22cddfe fixed possible naming conflicts with is.* functions
Mike Becker <universe@uap-core.de>
parents: 35
diff changeset
144 highlighter->isdirective = check_jdirective;
be60c22cddfe fixed possible naming conflicts with is.* functions
Mike Becker <universe@uap-core.de>
parents: 35
diff changeset
145 highlighter->istype = check_jtype;
24
e43dee5892f4 improved code structure and added option for disabling line numbers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
146 highlighter->keywords = jkeywords;
e43dee5892f4 improved code structure and added option for disabling line numbers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
147 highlighter->parser = jparseline;
22
f463693b5eeb added command line parameters for header and footer file
Mike Becker <universe@uap-core.de>
parents: 21
diff changeset
148 }
f463693b5eeb added command line parameters for header and footer file
Mike Becker <universe@uap-core.de>
parents: 21
diff changeset
149
39
ac35daceb24c adds UCX + changes how the input file is read (uses an consecutive memory area now)
Mike Becker <universe@uap-core.de>
parents: 38
diff changeset
150 enum source_type {
ac35daceb24c adds UCX + changes how the input file is read (uses an consecutive memory area now)
Mike Becker <universe@uap-core.de>
parents: 38
diff changeset
151 SOURCE_C,
ac35daceb24c adds UCX + changes how the input file is read (uses an consecutive memory area now)
Mike Becker <universe@uap-core.de>
parents: 38
diff changeset
152 SOURCE_JAVA,
ac35daceb24c adds UCX + changes how the input file is read (uses an consecutive memory area now)
Mike Becker <universe@uap-core.de>
parents: 38
diff changeset
153 SOURCE_PLAIN
ac35daceb24c adds UCX + changes how the input file is read (uses an consecutive memory area now)
Mike Becker <universe@uap-core.de>
parents: 38
diff changeset
154 };
ac35daceb24c adds UCX + changes how the input file is read (uses an consecutive memory area now)
Mike Becker <universe@uap-core.de>
parents: 38
diff changeset
155
1
12c482ea4fc4 first prototype: creates unformatted output with line numbers
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
156 int main(int argc, char** argv) {
22
f463693b5eeb added command line parameters for header and footer file
Mike Becker <universe@uap-core.de>
parents: 21
diff changeset
157 int retcode = EXIT_SUCCESS;
f463693b5eeb added command line parameters for header and footer file
Mike Becker <universe@uap-core.de>
parents: 21
diff changeset
158
39
ac35daceb24c adds UCX + changes how the input file is read (uses an consecutive memory area now)
Mike Becker <universe@uap-core.de>
parents: 38
diff changeset
159 Settings settings;
22
f463693b5eeb added command line parameters for header and footer file
Mike Becker <universe@uap-core.de>
parents: 21
diff changeset
160 memset(&settings, 0, sizeof(settings));
24
e43dee5892f4 improved code structure and added option for disabling line numbers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
161 settings.showlinenumbers = 1;
22
f463693b5eeb added command line parameters for header and footer file
Mike Becker <universe@uap-core.de>
parents: 21
diff changeset
162
39
ac35daceb24c adds UCX + changes how the input file is read (uses an consecutive memory area now)
Mike Becker <universe@uap-core.de>
parents: 38
diff changeset
163 enum source_type sourcetype = SOURCE_C;
19
2e812df2b231 formatted with 4 spaces
Mike Becker <universe@uap-core.de>
parents: 18
diff changeset
164
2e812df2b231 formatted with 4 spaces
Mike Becker <universe@uap-core.de>
parents: 18
diff changeset
165 char optc;
37
1a67185e5496 adds version number and changes build system
Mike Becker <universe@uap-core.de>
parents: 36
diff changeset
166 while ((optc = getopt(argc, argv, "hljo:pH:F:vV")) != -1) {
19
2e812df2b231 formatted with 4 spaces
Mike Becker <universe@uap-core.de>
parents: 18
diff changeset
167 switch (optc) {
2e812df2b231 formatted with 4 spaces
Mike Becker <universe@uap-core.de>
parents: 18
diff changeset
168 case 'o':
2e812df2b231 formatted with 4 spaces
Mike Becker <universe@uap-core.de>
parents: 18
diff changeset
169 if (!(optarg[0] == '-' && optarg[1] == 0)) {
2e812df2b231 formatted with 4 spaces
Mike Becker <universe@uap-core.de>
parents: 18
diff changeset
170 settings.outfilename = optarg;
2e812df2b231 formatted with 4 spaces
Mike Becker <universe@uap-core.de>
parents: 18
diff changeset
171 }
2e812df2b231 formatted with 4 spaces
Mike Becker <universe@uap-core.de>
parents: 18
diff changeset
172 break;
22
f463693b5eeb added command line parameters for header and footer file
Mike Becker <universe@uap-core.de>
parents: 21
diff changeset
173 case 'F':
f463693b5eeb added command line parameters for header and footer file
Mike Becker <universe@uap-core.de>
parents: 21
diff changeset
174 settings.footerfile = optarg;
f463693b5eeb added command line parameters for header and footer file
Mike Becker <universe@uap-core.de>
parents: 21
diff changeset
175 break;
f463693b5eeb added command line parameters for header and footer file
Mike Becker <universe@uap-core.de>
parents: 21
diff changeset
176 case 'H':
f463693b5eeb added command line parameters for header and footer file
Mike Becker <universe@uap-core.de>
parents: 21
diff changeset
177 settings.headerfile = optarg;
f463693b5eeb added command line parameters for header and footer file
Mike Becker <universe@uap-core.de>
parents: 21
diff changeset
178 break;
19
2e812df2b231 formatted with 4 spaces
Mike Becker <universe@uap-core.de>
parents: 18
diff changeset
179 case 'j':
39
ac35daceb24c adds UCX + changes how the input file is read (uses an consecutive memory area now)
Mike Becker <universe@uap-core.de>
parents: 38
diff changeset
180 sourcetype = SOURCE_JAVA;
19
2e812df2b231 formatted with 4 spaces
Mike Becker <universe@uap-core.de>
parents: 18
diff changeset
181 break;
2e812df2b231 formatted with 4 spaces
Mike Becker <universe@uap-core.de>
parents: 18
diff changeset
182 case 'p':
39
ac35daceb24c adds UCX + changes how the input file is read (uses an consecutive memory area now)
Mike Becker <universe@uap-core.de>
parents: 38
diff changeset
183 sourcetype = SOURCE_PLAIN;
19
2e812df2b231 formatted with 4 spaces
Mike Becker <universe@uap-core.de>
parents: 18
diff changeset
184 break;
24
e43dee5892f4 improved code structure and added option for disabling line numbers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
185 case 'l':
e43dee5892f4 improved code structure and added option for disabling line numbers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
186 settings.showlinenumbers = 0;
e43dee5892f4 improved code structure and added option for disabling line numbers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
187 break;
19
2e812df2b231 formatted with 4 spaces
Mike Becker <universe@uap-core.de>
parents: 18
diff changeset
188 case 'h':
2e812df2b231 formatted with 4 spaces
Mike Becker <universe@uap-core.de>
parents: 18
diff changeset
189 printhelp();
38
77c158821738 use macros for exit codes
Mike Becker <universe@uap-core.de>
parents: 37
diff changeset
190 return EXIT_SUCCESS;
37
1a67185e5496 adds version number and changes build system
Mike Becker <universe@uap-core.de>
parents: 36
diff changeset
191 case 'v':
1a67185e5496 adds version number and changes build system
Mike Becker <universe@uap-core.de>
parents: 36
diff changeset
192 case 'V':
1a67185e5496 adds version number and changes build system
Mike Becker <universe@uap-core.de>
parents: 36
diff changeset
193 #ifdef VERSION_DEVELOP
1a67185e5496 adds version number and changes build system
Mike Becker <universe@uap-core.de>
parents: 36
diff changeset
194 printf("%d.%d (unstable)\n", VERSION_MAJOR, VERSION_MINOR);
1a67185e5496 adds version number and changes build system
Mike Becker <universe@uap-core.de>
parents: 36
diff changeset
195 #else
1a67185e5496 adds version number and changes build system
Mike Becker <universe@uap-core.de>
parents: 36
diff changeset
196 printf("%d.%d\n", VERSION_MAJOR, VERSION_MINOR);
1a67185e5496 adds version number and changes build system
Mike Becker <universe@uap-core.de>
parents: 36
diff changeset
197 #endif
38
77c158821738 use macros for exit codes
Mike Becker <universe@uap-core.de>
parents: 37
diff changeset
198 return EXIT_SUCCESS;
19
2e812df2b231 formatted with 4 spaces
Mike Becker <universe@uap-core.de>
parents: 18
diff changeset
199 default:
38
77c158821738 use macros for exit codes
Mike Becker <universe@uap-core.de>
parents: 37
diff changeset
200 return EXIT_FAILURE;
11
c59fe73459fd option for output file
Mike Becker <universe@uap-core.de>
parents: 6
diff changeset
201 }
19
2e812df2b231 formatted with 4 spaces
Mike Becker <universe@uap-core.de>
parents: 18
diff changeset
202 }
2e812df2b231 formatted with 4 spaces
Mike Becker <universe@uap-core.de>
parents: 18
diff changeset
203
2e812df2b231 formatted with 4 spaces
Mike Becker <universe@uap-core.de>
parents: 18
diff changeset
204 if (optind != argc-1) {
11
c59fe73459fd option for output file
Mike Becker <universe@uap-core.de>
parents: 6
diff changeset
205 printhelp();
c59fe73459fd option for output file
Mike Becker <universe@uap-core.de>
parents: 6
diff changeset
206 return 1;
19
2e812df2b231 formatted with 4 spaces
Mike Becker <universe@uap-core.de>
parents: 18
diff changeset
207 } else {
2e812df2b231 formatted with 4 spaces
Mike Becker <universe@uap-core.de>
parents: 18
diff changeset
208 settings.infilename = argv[optind];
22
f463693b5eeb added command line parameters for header and footer file
Mike Becker <universe@uap-core.de>
parents: 21
diff changeset
209 FILE *fout;
f463693b5eeb added command line parameters for header and footer file
Mike Becker <universe@uap-core.de>
parents: 21
diff changeset
210 if (settings.outfilename) {
f463693b5eeb added command line parameters for header and footer file
Mike Becker <universe@uap-core.de>
parents: 21
diff changeset
211 fout = fopen(settings.outfilename, "w");
f463693b5eeb added command line parameters for header and footer file
Mike Becker <universe@uap-core.de>
parents: 21
diff changeset
212 if (!fout) {
f463693b5eeb added command line parameters for header and footer file
Mike Becker <universe@uap-core.de>
parents: 21
diff changeset
213 perror("Error opening output file");
38
77c158821738 use macros for exit codes
Mike Becker <universe@uap-core.de>
parents: 37
diff changeset
214 return EXIT_FAILURE;
22
f463693b5eeb added command line parameters for header and footer file
Mike Becker <universe@uap-core.de>
parents: 21
diff changeset
215 }
f463693b5eeb added command line parameters for header and footer file
Mike Becker <universe@uap-core.de>
parents: 21
diff changeset
216 } else {
f463693b5eeb added command line parameters for header and footer file
Mike Becker <universe@uap-core.de>
parents: 21
diff changeset
217 fout = stdout;
f463693b5eeb added command line parameters for header and footer file
Mike Becker <universe@uap-core.de>
parents: 21
diff changeset
218 }
f463693b5eeb added command line parameters for header and footer file
Mike Becker <universe@uap-core.de>
parents: 21
diff changeset
219
f463693b5eeb added command line parameters for header and footer file
Mike Becker <universe@uap-core.de>
parents: 21
diff changeset
220 if (copyfile(settings.headerfile, fout)) {
f463693b5eeb added command line parameters for header and footer file
Mike Becker <universe@uap-core.de>
parents: 21
diff changeset
221 perror("Error opening header file");
38
77c158821738 use macros for exit codes
Mike Becker <universe@uap-core.de>
parents: 37
diff changeset
222 retcode = EXIT_FAILURE;
22
f463693b5eeb added command line parameters for header and footer file
Mike Becker <universe@uap-core.de>
parents: 21
diff changeset
223 goto prog_end;
f463693b5eeb added command line parameters for header and footer file
Mike Becker <universe@uap-core.de>
parents: 21
diff changeset
224 }
24
e43dee5892f4 improved code structure and added option for disabling line numbers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
225
e43dee5892f4 improved code structure and added option for disabling line numbers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
226 highlighter_t highlighter;
e43dee5892f4 improved code structure and added option for disabling line numbers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
227 highlighter_t *hptr = &highlighter;
39
ac35daceb24c adds UCX + changes how the input file is read (uses an consecutive memory area now)
Mike Becker <universe@uap-core.de>
parents: 38
diff changeset
228 switch (sourcetype) {
ac35daceb24c adds UCX + changes how the input file is read (uses an consecutive memory area now)
Mike Becker <universe@uap-core.de>
parents: 38
diff changeset
229 case SOURCE_C:
24
e43dee5892f4 improved code structure and added option for disabling line numbers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
230 init_c_highlighter(&highlighter);
e43dee5892f4 improved code structure and added option for disabling line numbers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
231 break;
39
ac35daceb24c adds UCX + changes how the input file is read (uses an consecutive memory area now)
Mike Becker <universe@uap-core.de>
parents: 38
diff changeset
232 case SOURCE_JAVA:
24
e43dee5892f4 improved code structure and added option for disabling line numbers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
233 init_java_highlighter(&highlighter);
e43dee5892f4 improved code structure and added option for disabling line numbers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
234 break;
39
ac35daceb24c adds UCX + changes how the input file is read (uses an consecutive memory area now)
Mike Becker <universe@uap-core.de>
parents: 38
diff changeset
235 case SOURCE_PLAIN:
24
e43dee5892f4 improved code structure and added option for disabling line numbers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
236 hptr = NULL;
e43dee5892f4 improved code structure and added option for disabling line numbers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
237 break;
39
ac35daceb24c adds UCX + changes how the input file is read (uses an consecutive memory area now)
Mike Becker <universe@uap-core.de>
parents: 38
diff changeset
238 default: /* should be unreachable */
ac35daceb24c adds UCX + changes how the input file is read (uses an consecutive memory area now)
Mike Becker <universe@uap-core.de>
parents: 38
diff changeset
239 fprintf(stderr, "error in enum source_type\n");
ac35daceb24c adds UCX + changes how the input file is read (uses an consecutive memory area now)
Mike Becker <universe@uap-core.de>
parents: 38
diff changeset
240 retcode = EXIT_FAILURE;
ac35daceb24c adds UCX + changes how the input file is read (uses an consecutive memory area now)
Mike Becker <universe@uap-core.de>
parents: 38
diff changeset
241 goto prog_end;
24
e43dee5892f4 improved code structure and added option for disabling line numbers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
242 }
11
c59fe73459fd option for output file
Mike Becker <universe@uap-core.de>
parents: 6
diff changeset
243
39
ac35daceb24c adds UCX + changes how the input file is read (uses an consecutive memory area now)
Mike Becker <universe@uap-core.de>
parents: 38
diff changeset
244 FILE *inputfile = fopen(settings.infilename, "r");
19
2e812df2b231 formatted with 4 spaces
Mike Becker <universe@uap-core.de>
parents: 18
diff changeset
245 if (inputfile) {
39
ac35daceb24c adds UCX + changes how the input file is read (uses an consecutive memory area now)
Mike Becker <universe@uap-core.de>
parents: 38
diff changeset
246 UcxBuffer *filebuf = ucx_buffer_new(NULL,
ac35daceb24c adds UCX + changes how the input file is read (uses an consecutive memory area now)
Mike Becker <universe@uap-core.de>
parents: 38
diff changeset
247 2048, UCX_BUFFER_AUTOEXTEND);
ac35daceb24c adds UCX + changes how the input file is read (uses an consecutive memory area now)
Mike Becker <universe@uap-core.de>
parents: 38
diff changeset
248 {
ac35daceb24c adds UCX + changes how the input file is read (uses an consecutive memory area now)
Mike Becker <universe@uap-core.de>
parents: 38
diff changeset
249 const size_t tmpbufsize = 512;
ac35daceb24c adds UCX + changes how the input file is read (uses an consecutive memory area now)
Mike Becker <universe@uap-core.de>
parents: 38
diff changeset
250 char *tmpbuf = malloc(tmpbufsize);
ac35daceb24c adds UCX + changes how the input file is read (uses an consecutive memory area now)
Mike Becker <universe@uap-core.de>
parents: 38
diff changeset
251 ucx_stream_copy(inputfile, filebuf, (read_func) fread,
ac35daceb24c adds UCX + changes how the input file is read (uses an consecutive memory area now)
Mike Becker <universe@uap-core.de>
parents: 38
diff changeset
252 (write_func) ucx_buffer_write,
ac35daceb24c adds UCX + changes how the input file is read (uses an consecutive memory area now)
Mike Becker <universe@uap-core.de>
parents: 38
diff changeset
253 tmpbuf, tmpbufsize, (size_t)-1);
ac35daceb24c adds UCX + changes how the input file is read (uses an consecutive memory area now)
Mike Becker <universe@uap-core.de>
parents: 38
diff changeset
254 free(tmpbuf);
ac35daceb24c adds UCX + changes how the input file is read (uses an consecutive memory area now)
Mike Becker <universe@uap-core.de>
parents: 38
diff changeset
255 }
ac35daceb24c adds UCX + changes how the input file is read (uses an consecutive memory area now)
Mike Becker <universe@uap-core.de>
parents: 38
diff changeset
256 fclose(inputfile);
ac35daceb24c adds UCX + changes how the input file is read (uses an consecutive memory area now)
Mike Becker <universe@uap-core.de>
parents: 38
diff changeset
257
ac35daceb24c adds UCX + changes how the input file is read (uses an consecutive memory area now)
Mike Becker <universe@uap-core.de>
parents: 38
diff changeset
258 UcxList *inputlines = ucx_list_append(NULL, filebuf->space);
ac35daceb24c adds UCX + changes how the input file is read (uses an consecutive memory area now)
Mike Becker <universe@uap-core.de>
parents: 38
diff changeset
259 for (size_t i = 1 ; i < filebuf->size ; i++) {
ac35daceb24c adds UCX + changes how the input file is read (uses an consecutive memory area now)
Mike Becker <universe@uap-core.de>
parents: 38
diff changeset
260 if (filebuf->space[i] == '\r') {
ac35daceb24c adds UCX + changes how the input file is read (uses an consecutive memory area now)
Mike Becker <universe@uap-core.de>
parents: 38
diff changeset
261 filebuf->space[i] = '\n'; i++;
ac35daceb24c adds UCX + changes how the input file is read (uses an consecutive memory area now)
Mike Becker <universe@uap-core.de>
parents: 38
diff changeset
262 }
ac35daceb24c adds UCX + changes how the input file is read (uses an consecutive memory area now)
Mike Becker <universe@uap-core.de>
parents: 38
diff changeset
263 if (filebuf->space[i] == '\n' && i+1 < filebuf->size) {
ac35daceb24c adds UCX + changes how the input file is read (uses an consecutive memory area now)
Mike Becker <universe@uap-core.de>
parents: 38
diff changeset
264 ucx_list_append(inputlines, filebuf->space+i+1);
ac35daceb24c adds UCX + changes how the input file is read (uses an consecutive memory area now)
Mike Becker <universe@uap-core.de>
parents: 38
diff changeset
265 }
ac35daceb24c adds UCX + changes how the input file is read (uses an consecutive memory area now)
Mike Becker <universe@uap-core.de>
parents: 38
diff changeset
266 }
ac35daceb24c adds UCX + changes how the input file is read (uses an consecutive memory area now)
Mike Becker <universe@uap-core.de>
parents: 38
diff changeset
267
24
e43dee5892f4 improved code structure and added option for disabling line numbers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
268 formatfile(
e43dee5892f4 improved code structure and added option for disabling line numbers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
269 hptr,
39
ac35daceb24c adds UCX + changes how the input file is read (uses an consecutive memory area now)
Mike Becker <universe@uap-core.de>
parents: 38
diff changeset
270 inputlines,
ac35daceb24c adds UCX + changes how the input file is read (uses an consecutive memory area now)
Mike Becker <universe@uap-core.de>
parents: 38
diff changeset
271 (write_func) fwrite,
24
e43dee5892f4 improved code structure and added option for disabling line numbers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
272 fout,
e43dee5892f4 improved code structure and added option for disabling line numbers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
273 settings.showlinenumbers);
39
ac35daceb24c adds UCX + changes how the input file is read (uses an consecutive memory area now)
Mike Becker <universe@uap-core.de>
parents: 38
diff changeset
274 ucx_buffer_free(filebuf);
22
f463693b5eeb added command line parameters for header and footer file
Mike Becker <universe@uap-core.de>
parents: 21
diff changeset
275 } else {
f463693b5eeb added command line parameters for header and footer file
Mike Becker <universe@uap-core.de>
parents: 21
diff changeset
276 perror("Error opening input file");
38
77c158821738 use macros for exit codes
Mike Becker <universe@uap-core.de>
parents: 37
diff changeset
277 retcode = EXIT_FAILURE;
24
e43dee5892f4 improved code structure and added option for disabling line numbers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
278 }
e43dee5892f4 improved code structure and added option for disabling line numbers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
279
e43dee5892f4 improved code structure and added option for disabling line numbers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
280 if (copyfile(settings.footerfile, fout)) {
e43dee5892f4 improved code structure and added option for disabling line numbers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
281 perror("Error opening footer file");
38
77c158821738 use macros for exit codes
Mike Becker <universe@uap-core.de>
parents: 37
diff changeset
282 retcode = EXIT_FAILURE;
22
f463693b5eeb added command line parameters for header and footer file
Mike Becker <universe@uap-core.de>
parents: 21
diff changeset
283 }
f463693b5eeb added command line parameters for header and footer file
Mike Becker <universe@uap-core.de>
parents: 21
diff changeset
284
f463693b5eeb added command line parameters for header and footer file
Mike Becker <universe@uap-core.de>
parents: 21
diff changeset
285 prog_end:
f463693b5eeb added command line parameters for header and footer file
Mike Becker <universe@uap-core.de>
parents: 21
diff changeset
286 if (fout != stdout) {
f463693b5eeb added command line parameters for header and footer file
Mike Becker <universe@uap-core.de>
parents: 21
diff changeset
287 fclose(fout);
12
7ce5c4b51959 option for plaintext
Mike Becker <universe@uap-core.de>
parents: 11
diff changeset
288 }
19
2e812df2b231 formatted with 4 spaces
Mike Becker <universe@uap-core.de>
parents: 18
diff changeset
289
22
f463693b5eeb added command line parameters for header and footer file
Mike Becker <universe@uap-core.de>
parents: 21
diff changeset
290 return retcode;
1
12c482ea4fc4 first prototype: creates unformatted output with line numbers
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
291 }
12c482ea4fc4 first prototype: creates unformatted output with line numbers
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
292 }
12c482ea4fc4 first prototype: creates unformatted output with line numbers
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
293

mercurial