Mercurial > hg > octave-lyh
annotate doc/interpreter/munge-texi.cc @ 15524:15628a84a4fa stable
Document form of warning IDs is NAMESPACE:WARNING-NAME (bug #37559)
* errors.txi: Add explanation of warning ID form to documentation.
Correct example code to properly use warning IDs.
* error.cc (Fwarning): Document form of warning ID in warning()
docstring.
author | Rik <rik@octave.org> |
---|---|
date | Mon, 15 Oct 2012 07:18:31 -0700 |
parents | d174210ce1ec |
children |
rev | line source |
---|---|
3313 | 1 /* |
2 | |
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
12174
diff
changeset
|
3 Copyright (C) 1999-2012 John W. Eaton |
3313 | 4 |
5 This file is part of Octave. | |
6 | |
7 Octave is free software; you can redistribute it and/or modify it | |
8 under the terms of the GNU General Public License as published by the | |
7016 | 9 Free Software Foundation; either version 3 of the License, or (at your |
10 option) any later version. | |
3313 | 11 |
12 Octave is distributed in the hope that it will be useful, but WITHOUT | |
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 for more details. | |
16 | |
17 You should have received a copy of the GNU General Public License | |
7016 | 18 along with Octave; see the file COPYING. If not, see |
19 <http://www.gnu.org/licenses/>. | |
3313 | 20 |
21 */ | |
22 | |
4177 | 23 #include <cctype> |
3575 | 24 #include <iostream> |
25 #include <fstream> | |
3294 | 26 #include <string> |
4215 | 27 #include <map> |
3294 | 28 |
7048 | 29 #include <cstdlib> |
30 #include <cstring> | |
31 | |
9906 | 32 static std::string top_srcdir; |
33 | |
3294 | 34 static const char doc_delim = ''; |
35 | |
4178 | 36 static std::map<std::string, std::string> help_text; |
4177 | 37 |
3294 | 38 static void |
3575 | 39 fatal (const std::string& msg) |
3294 | 40 { |
3575 | 41 std::cerr << msg << "\n"; |
3294 | 42 exit (1); |
43 } | |
44 | |
45 static void | |
46 usage (void) | |
47 { | |
9906 | 48 std::cerr << "usage: munge-texi TOP-SRCDIR DOCSTRING-FILE < file\n"; |
3294 | 49 exit (1); |
50 } | |
51 | |
3575 | 52 static std::string |
3576 | 53 extract_symbol_name (std::istream& is) |
3294 | 54 { |
3575 | 55 std::string symbol_name; |
3294 | 56 |
57 int c; | |
58 while ((c = is.get ()) != EOF && c != '\n') | |
10076 | 59 symbol_name += static_cast<char> (c); |
3294 | 60 |
61 return symbol_name; | |
62 } | |
63 | |
3575 | 64 static std::string |
65 extract_docstring (std::istream& is) | |
3294 | 66 { |
3575 | 67 std::string doc; |
3294 | 68 |
69 int c; | |
70 while ((c = is.get ()) != EOF && c != doc_delim) | |
8287
f3dbea0e8a1d
Adapted munge-texi to expand @seealso commands to texinfo references
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7048
diff
changeset
|
71 { |
f3dbea0e8a1d
Adapted munge-texi to expand @seealso commands to texinfo references
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7048
diff
changeset
|
72 // Expand @seealso commands to Texinfo references. |
f3dbea0e8a1d
Adapted munge-texi to expand @seealso commands to texinfo references
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7048
diff
changeset
|
73 if (c == '@') |
f3dbea0e8a1d
Adapted munge-texi to expand @seealso commands to texinfo references
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7048
diff
changeset
|
74 { |
f3dbea0e8a1d
Adapted munge-texi to expand @seealso commands to texinfo references
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7048
diff
changeset
|
75 char buf[16]; |
f3dbea0e8a1d
Adapted munge-texi to expand @seealso commands to texinfo references
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7048
diff
changeset
|
76 int i = 0; |
10076 | 77 buf[i++] = static_cast<char> (c); |
12174 | 78 |
79 if (( buf[i++] = static_cast<char> (is.get ())) == 's' | |
10076 | 80 && (buf[i++] = static_cast<char> (is.get ())) == 'e' |
81 && (buf[i++] = static_cast<char> (is.get ())) == 'e' | |
82 && (buf[i++] = static_cast<char> (is.get ())) == 'a' | |
83 && (buf[i++] = static_cast<char> (is.get ())) == 'l' | |
84 && (buf[i++] = static_cast<char> (is.get ())) == 's' | |
85 && (buf[i++] = static_cast<char> (is.get ())) == 'o' | |
86 && (buf[i++] = static_cast<char> (is.get ())) == '{') | |
8287
f3dbea0e8a1d
Adapted munge-texi to expand @seealso commands to texinfo references
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7048
diff
changeset
|
87 { |
f3dbea0e8a1d
Adapted munge-texi to expand @seealso commands to texinfo references
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7048
diff
changeset
|
88 doc += "@seealso{"; |
12174 | 89 |
8287
f3dbea0e8a1d
Adapted munge-texi to expand @seealso commands to texinfo references
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7048
diff
changeset
|
90 bool first = true; |
12174 | 91 |
8287
f3dbea0e8a1d
Adapted munge-texi to expand @seealso commands to texinfo references
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7048
diff
changeset
|
92 // process @seealso parameters |
f3dbea0e8a1d
Adapted munge-texi to expand @seealso commands to texinfo references
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7048
diff
changeset
|
93 while ((c = is.get ()) != EOF |
f3dbea0e8a1d
Adapted munge-texi to expand @seealso commands to texinfo references
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7048
diff
changeset
|
94 && c != doc_delim |
12174 | 95 && c != '}') |
8287
f3dbea0e8a1d
Adapted munge-texi to expand @seealso commands to texinfo references
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7048
diff
changeset
|
96 { |
f3dbea0e8a1d
Adapted munge-texi to expand @seealso commands to texinfo references
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7048
diff
changeset
|
97 // ignore whitespace and delimiters |
12174 | 98 while ( c == ' ' |
8287
f3dbea0e8a1d
Adapted munge-texi to expand @seealso commands to texinfo references
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7048
diff
changeset
|
99 || c == '\t' |
f3dbea0e8a1d
Adapted munge-texi to expand @seealso commands to texinfo references
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7048
diff
changeset
|
100 || c == '\r' |
f3dbea0e8a1d
Adapted munge-texi to expand @seealso commands to texinfo references
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7048
diff
changeset
|
101 || c == '\n' |
f3dbea0e8a1d
Adapted munge-texi to expand @seealso commands to texinfo references
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7048
diff
changeset
|
102 || c == ',') |
f3dbea0e8a1d
Adapted munge-texi to expand @seealso commands to texinfo references
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7048
diff
changeset
|
103 { |
f3dbea0e8a1d
Adapted munge-texi to expand @seealso commands to texinfo references
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7048
diff
changeset
|
104 c = is.get (); |
f3dbea0e8a1d
Adapted munge-texi to expand @seealso commands to texinfo references
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7048
diff
changeset
|
105 } |
12174 | 106 |
8287
f3dbea0e8a1d
Adapted munge-texi to expand @seealso commands to texinfo references
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7048
diff
changeset
|
107 // test for end of @seealso |
12174 | 108 if (c == '}') |
8287
f3dbea0e8a1d
Adapted munge-texi to expand @seealso commands to texinfo references
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7048
diff
changeset
|
109 break; |
12174 | 110 |
8287
f3dbea0e8a1d
Adapted munge-texi to expand @seealso commands to texinfo references
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7048
diff
changeset
|
111 // get function name |
10162
9f9eb9d2eefd
doc/interpreter/munge-texi.cc: untabify and delete emacs local variable settings
John W. Eaton <jwe@octave.org>
parents:
10076
diff
changeset
|
112 std::string function_name; |
12174 | 113 do |
10076 | 114 function_name += static_cast<char> (c); |
8287
f3dbea0e8a1d
Adapted munge-texi to expand @seealso commands to texinfo references
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7048
diff
changeset
|
115 while ((c = is.get ()) != EOF |
f3dbea0e8a1d
Adapted munge-texi to expand @seealso commands to texinfo references
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7048
diff
changeset
|
116 && c != doc_delim |
f3dbea0e8a1d
Adapted munge-texi to expand @seealso commands to texinfo references
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7048
diff
changeset
|
117 && c != ' ' |
f3dbea0e8a1d
Adapted munge-texi to expand @seealso commands to texinfo references
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7048
diff
changeset
|
118 && c != '\t' |
f3dbea0e8a1d
Adapted munge-texi to expand @seealso commands to texinfo references
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7048
diff
changeset
|
119 && c != '\r' |
f3dbea0e8a1d
Adapted munge-texi to expand @seealso commands to texinfo references
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7048
diff
changeset
|
120 && c != '\n' |
f3dbea0e8a1d
Adapted munge-texi to expand @seealso commands to texinfo references
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7048
diff
changeset
|
121 && c != ',' |
f3dbea0e8a1d
Adapted munge-texi to expand @seealso commands to texinfo references
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7048
diff
changeset
|
122 && c != '}'); |
f3dbea0e8a1d
Adapted munge-texi to expand @seealso commands to texinfo references
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7048
diff
changeset
|
123 if (first) |
f3dbea0e8a1d
Adapted munge-texi to expand @seealso commands to texinfo references
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7048
diff
changeset
|
124 first = false; |
f3dbea0e8a1d
Adapted munge-texi to expand @seealso commands to texinfo references
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7048
diff
changeset
|
125 else |
f3dbea0e8a1d
Adapted munge-texi to expand @seealso commands to texinfo references
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7048
diff
changeset
|
126 doc += ", "; |
3294 | 127 |
10162
9f9eb9d2eefd
doc/interpreter/munge-texi.cc: untabify and delete emacs local variable settings
John W. Eaton <jwe@octave.org>
parents:
10076
diff
changeset
|
128 if (function_name[0] == '@') |
9f9eb9d2eefd
doc/interpreter/munge-texi.cc: untabify and delete emacs local variable settings
John W. Eaton <jwe@octave.org>
parents:
10076
diff
changeset
|
129 function_name = "@" + function_name; |
9891
1506a17832c9
doc building fixes for class methods
John W. Eaton <jwe@octave.org>
parents:
9794
diff
changeset
|
130 |
8287
f3dbea0e8a1d
Adapted munge-texi to expand @seealso commands to texinfo references
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7048
diff
changeset
|
131 doc += "@ref{doc-" + function_name + ",," |
10162
9f9eb9d2eefd
doc/interpreter/munge-texi.cc: untabify and delete emacs local variable settings
John W. Eaton <jwe@octave.org>
parents:
10076
diff
changeset
|
132 + function_name + "}"; |
8287
f3dbea0e8a1d
Adapted munge-texi to expand @seealso commands to texinfo references
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7048
diff
changeset
|
133 |
f3dbea0e8a1d
Adapted munge-texi to expand @seealso commands to texinfo references
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7048
diff
changeset
|
134 // test for end of @seealso |
12174 | 135 if (c == '}') |
8287
f3dbea0e8a1d
Adapted munge-texi to expand @seealso commands to texinfo references
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7048
diff
changeset
|
136 break; |
f3dbea0e8a1d
Adapted munge-texi to expand @seealso commands to texinfo references
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7048
diff
changeset
|
137 } |
f3dbea0e8a1d
Adapted munge-texi to expand @seealso commands to texinfo references
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7048
diff
changeset
|
138 if (c == '}') |
10076 | 139 doc += static_cast<char> (c); |
8287
f3dbea0e8a1d
Adapted munge-texi to expand @seealso commands to texinfo references
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7048
diff
changeset
|
140 } |
f3dbea0e8a1d
Adapted munge-texi to expand @seealso commands to texinfo references
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7048
diff
changeset
|
141 else |
f3dbea0e8a1d
Adapted munge-texi to expand @seealso commands to texinfo references
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7048
diff
changeset
|
142 { |
f3dbea0e8a1d
Adapted munge-texi to expand @seealso commands to texinfo references
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7048
diff
changeset
|
143 for (int j = 0; j < i; j++) |
f3dbea0e8a1d
Adapted munge-texi to expand @seealso commands to texinfo references
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7048
diff
changeset
|
144 doc += buf[j]; |
f3dbea0e8a1d
Adapted munge-texi to expand @seealso commands to texinfo references
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7048
diff
changeset
|
145 } |
f3dbea0e8a1d
Adapted munge-texi to expand @seealso commands to texinfo references
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7048
diff
changeset
|
146 } |
f3dbea0e8a1d
Adapted munge-texi to expand @seealso commands to texinfo references
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7048
diff
changeset
|
147 else |
10076 | 148 doc += static_cast<char> (c); |
8287
f3dbea0e8a1d
Adapted munge-texi to expand @seealso commands to texinfo references
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7048
diff
changeset
|
149 } |
3294 | 150 return doc; |
151 } | |
152 | |
153 static void | |
5334 | 154 skip_comments (std::ifstream& is) |
155 { | |
156 int c; | |
157 | |
158 bool in_comment = false; | |
159 | |
160 while ((c = is.get ()) != EOF) | |
161 { | |
162 if (c == '#') | |
10162
9f9eb9d2eefd
doc/interpreter/munge-texi.cc: untabify and delete emacs local variable settings
John W. Eaton <jwe@octave.org>
parents:
10076
diff
changeset
|
163 in_comment = true; |
5334 | 164 else if (c == '\n') |
10162
9f9eb9d2eefd
doc/interpreter/munge-texi.cc: untabify and delete emacs local variable settings
John W. Eaton <jwe@octave.org>
parents:
10076
diff
changeset
|
165 in_comment = false; |
5334 | 166 else if (! (in_comment || ::isspace (c))) |
10162
9f9eb9d2eefd
doc/interpreter/munge-texi.cc: untabify and delete emacs local variable settings
John W. Eaton <jwe@octave.org>
parents:
10076
diff
changeset
|
167 { |
9f9eb9d2eefd
doc/interpreter/munge-texi.cc: untabify and delete emacs local variable settings
John W. Eaton <jwe@octave.org>
parents:
10076
diff
changeset
|
168 is.putback (c); |
9f9eb9d2eefd
doc/interpreter/munge-texi.cc: untabify and delete emacs local variable settings
John W. Eaton <jwe@octave.org>
parents:
10076
diff
changeset
|
169 break; |
9f9eb9d2eefd
doc/interpreter/munge-texi.cc: untabify and delete emacs local variable settings
John W. Eaton <jwe@octave.org>
parents:
10076
diff
changeset
|
170 } |
5334 | 171 } |
172 } | |
173 | |
174 static void | |
3575 | 175 process_doc_file (const std::string& fname) |
3294 | 176 { |
3575 | 177 std::ifstream infile (fname.c_str ()); |
3294 | 178 |
179 if (infile) | |
180 { | |
5334 | 181 skip_comments (infile); |
182 | |
3294 | 183 if (infile.get () != doc_delim) |
10162
9f9eb9d2eefd
doc/interpreter/munge-texi.cc: untabify and delete emacs local variable settings
John W. Eaton <jwe@octave.org>
parents:
10076
diff
changeset
|
184 fatal ("invalid doc file format"); |
3294 | 185 |
3575 | 186 std::string symbol_name; |
3294 | 187 |
188 do | |
10162
9f9eb9d2eefd
doc/interpreter/munge-texi.cc: untabify and delete emacs local variable settings
John W. Eaton <jwe@octave.org>
parents:
10076
diff
changeset
|
189 { |
9f9eb9d2eefd
doc/interpreter/munge-texi.cc: untabify and delete emacs local variable settings
John W. Eaton <jwe@octave.org>
parents:
10076
diff
changeset
|
190 symbol_name = extract_symbol_name (infile); |
3294 | 191 |
10162
9f9eb9d2eefd
doc/interpreter/munge-texi.cc: untabify and delete emacs local variable settings
John W. Eaton <jwe@octave.org>
parents:
10076
diff
changeset
|
192 if (! symbol_name.empty ()) |
9f9eb9d2eefd
doc/interpreter/munge-texi.cc: untabify and delete emacs local variable settings
John W. Eaton <jwe@octave.org>
parents:
10076
diff
changeset
|
193 { |
9f9eb9d2eefd
doc/interpreter/munge-texi.cc: untabify and delete emacs local variable settings
John W. Eaton <jwe@octave.org>
parents:
10076
diff
changeset
|
194 std::string doc_string = extract_docstring (infile); |
3294 | 195 |
10162
9f9eb9d2eefd
doc/interpreter/munge-texi.cc: untabify and delete emacs local variable settings
John W. Eaton <jwe@octave.org>
parents:
10076
diff
changeset
|
196 if (help_text.find (symbol_name) != help_text.end ()) |
9f9eb9d2eefd
doc/interpreter/munge-texi.cc: untabify and delete emacs local variable settings
John W. Eaton <jwe@octave.org>
parents:
10076
diff
changeset
|
197 std::cerr << "ignoring duplicate entry for " |
9f9eb9d2eefd
doc/interpreter/munge-texi.cc: untabify and delete emacs local variable settings
John W. Eaton <jwe@octave.org>
parents:
10076
diff
changeset
|
198 << symbol_name << "\n"; |
9f9eb9d2eefd
doc/interpreter/munge-texi.cc: untabify and delete emacs local variable settings
John W. Eaton <jwe@octave.org>
parents:
10076
diff
changeset
|
199 else |
9f9eb9d2eefd
doc/interpreter/munge-texi.cc: untabify and delete emacs local variable settings
John W. Eaton <jwe@octave.org>
parents:
10076
diff
changeset
|
200 help_text[symbol_name] = doc_string; |
9f9eb9d2eefd
doc/interpreter/munge-texi.cc: untabify and delete emacs local variable settings
John W. Eaton <jwe@octave.org>
parents:
10076
diff
changeset
|
201 } |
9f9eb9d2eefd
doc/interpreter/munge-texi.cc: untabify and delete emacs local variable settings
John W. Eaton <jwe@octave.org>
parents:
10076
diff
changeset
|
202 } |
3294 | 203 while (! symbol_name.empty ()); |
204 } | |
205 else | |
206 fatal ("unable to open docfile"); | |
207 } | |
208 | |
9906 | 209 static bool |
210 recover_from_macro (std::ostream& os, char *buf, int i) | |
211 { | |
212 bool bol = false; | |
213 | |
214 buf[i] = '\0'; | |
215 os << buf; | |
216 | |
217 if (buf[i - 1] == '\n') | |
218 bol = true; | |
219 | |
220 return bol; | |
221 } | |
222 | |
223 static void | |
224 process_example_file (const std::string& file_name, std::ostream& os) | |
225 { | |
226 std::ifstream infile (file_name.c_str ()); | |
227 | |
228 if (infile) | |
229 { | |
230 os << "@verbatim\n"; | |
231 | |
232 int c; | |
233 int clast = 0; | |
234 | |
235 while ((c = infile.get ()) != EOF) | |
10162
9f9eb9d2eefd
doc/interpreter/munge-texi.cc: untabify and delete emacs local variable settings
John W. Eaton <jwe@octave.org>
parents:
10076
diff
changeset
|
236 { |
9f9eb9d2eefd
doc/interpreter/munge-texi.cc: untabify and delete emacs local variable settings
John W. Eaton <jwe@octave.org>
parents:
10076
diff
changeset
|
237 os << static_cast<char> (c); |
9f9eb9d2eefd
doc/interpreter/munge-texi.cc: untabify and delete emacs local variable settings
John W. Eaton <jwe@octave.org>
parents:
10076
diff
changeset
|
238 clast = c; |
9f9eb9d2eefd
doc/interpreter/munge-texi.cc: untabify and delete emacs local variable settings
John W. Eaton <jwe@octave.org>
parents:
10076
diff
changeset
|
239 } |
9906 | 240 |
241 if (clast != '\n') | |
10162
9f9eb9d2eefd
doc/interpreter/munge-texi.cc: untabify and delete emacs local variable settings
John W. Eaton <jwe@octave.org>
parents:
10076
diff
changeset
|
242 os << "\n"; |
9906 | 243 |
244 os << "@end verbatim\n"; | |
245 } | |
246 else | |
247 fatal ("unable to open example file " + file_name); | |
248 } | |
249 | |
3294 | 250 static void |
3575 | 251 process_texi_input_file (std::istream& is, std::ostream& os) |
3294 | 252 { |
3404 | 253 os << "@c DO NOT EDIT! Generated automatically by munge-texi.\n\n"; |
3294 | 254 |
255 bool bol = true; | |
256 | |
257 int c; | |
258 while ((c = is.get ()) != EOF) | |
259 { | |
260 if (bol) | |
10162
9f9eb9d2eefd
doc/interpreter/munge-texi.cc: untabify and delete emacs local variable settings
John W. Eaton <jwe@octave.org>
parents:
10076
diff
changeset
|
261 { |
9f9eb9d2eefd
doc/interpreter/munge-texi.cc: untabify and delete emacs local variable settings
John W. Eaton <jwe@octave.org>
parents:
10076
diff
changeset
|
262 if (c == '@') |
9f9eb9d2eefd
doc/interpreter/munge-texi.cc: untabify and delete emacs local variable settings
John W. Eaton <jwe@octave.org>
parents:
10076
diff
changeset
|
263 { |
9f9eb9d2eefd
doc/interpreter/munge-texi.cc: untabify and delete emacs local variable settings
John W. Eaton <jwe@octave.org>
parents:
10076
diff
changeset
|
264 char buf[16]; |
9f9eb9d2eefd
doc/interpreter/munge-texi.cc: untabify and delete emacs local variable settings
John W. Eaton <jwe@octave.org>
parents:
10076
diff
changeset
|
265 int i = 0; |
9f9eb9d2eefd
doc/interpreter/munge-texi.cc: untabify and delete emacs local variable settings
John W. Eaton <jwe@octave.org>
parents:
10076
diff
changeset
|
266 buf[i++] = static_cast<char> (c); |
3294 | 267 |
10162
9f9eb9d2eefd
doc/interpreter/munge-texi.cc: untabify and delete emacs local variable settings
John W. Eaton <jwe@octave.org>
parents:
10076
diff
changeset
|
268 buf[i++] = c = static_cast<char> (is.get ()); |
9906 | 269 |
10162
9f9eb9d2eefd
doc/interpreter/munge-texi.cc: untabify and delete emacs local variable settings
John W. Eaton <jwe@octave.org>
parents:
10076
diff
changeset
|
270 if (c == 'D') |
9f9eb9d2eefd
doc/interpreter/munge-texi.cc: untabify and delete emacs local variable settings
John W. Eaton <jwe@octave.org>
parents:
10076
diff
changeset
|
271 { |
9f9eb9d2eefd
doc/interpreter/munge-texi.cc: untabify and delete emacs local variable settings
John W. Eaton <jwe@octave.org>
parents:
10076
diff
changeset
|
272 std::string symbol_name; |
3294 | 273 |
10162
9f9eb9d2eefd
doc/interpreter/munge-texi.cc: untabify and delete emacs local variable settings
John W. Eaton <jwe@octave.org>
parents:
10076
diff
changeset
|
274 if ( (buf[i++] = static_cast<char> (is.get ())) == 'O' |
10076 | 275 && (buf[i++] = static_cast<char> (is.get ())) == 'C' |
276 && (buf[i++] = static_cast<char> (is.get ())) == 'S' | |
277 && (buf[i++] = static_cast<char> (is.get ())) == 'T' | |
278 && (buf[i++] = static_cast<char> (is.get ())) == 'R' | |
279 && (buf[i++] = static_cast<char> (is.get ())) == 'I' | |
280 && (buf[i++] = static_cast<char> (is.get ())) == 'N' | |
281 && (buf[i++] = static_cast<char> (is.get ())) == 'G' | |
282 && (buf[i++] = static_cast<char> (is.get ())) == '(') | |
10162
9f9eb9d2eefd
doc/interpreter/munge-texi.cc: untabify and delete emacs local variable settings
John W. Eaton <jwe@octave.org>
parents:
10076
diff
changeset
|
283 { |
9f9eb9d2eefd
doc/interpreter/munge-texi.cc: untabify and delete emacs local variable settings
John W. Eaton <jwe@octave.org>
parents:
10076
diff
changeset
|
284 while ((c = is.get ()) != EOF && c != ')') |
9f9eb9d2eefd
doc/interpreter/munge-texi.cc: untabify and delete emacs local variable settings
John W. Eaton <jwe@octave.org>
parents:
10076
diff
changeset
|
285 symbol_name += static_cast<char> (c); |
9014
71fca0fc2436
save source file names for functions as comments in .texi files
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
286 |
10162
9f9eb9d2eefd
doc/interpreter/munge-texi.cc: untabify and delete emacs local variable settings
John W. Eaton <jwe@octave.org>
parents:
10076
diff
changeset
|
287 if (is.eof ()) |
9f9eb9d2eefd
doc/interpreter/munge-texi.cc: untabify and delete emacs local variable settings
John W. Eaton <jwe@octave.org>
parents:
10076
diff
changeset
|
288 fatal ("end of file while reading @DOCSTRING command"); |
9f9eb9d2eefd
doc/interpreter/munge-texi.cc: untabify and delete emacs local variable settings
John W. Eaton <jwe@octave.org>
parents:
10076
diff
changeset
|
289 else |
9f9eb9d2eefd
doc/interpreter/munge-texi.cc: untabify and delete emacs local variable settings
John W. Eaton <jwe@octave.org>
parents:
10076
diff
changeset
|
290 { |
9f9eb9d2eefd
doc/interpreter/munge-texi.cc: untabify and delete emacs local variable settings
John W. Eaton <jwe@octave.org>
parents:
10076
diff
changeset
|
291 std::string doc_string = help_text[symbol_name]; |
9014
71fca0fc2436
save source file names for functions as comments in .texi files
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
292 |
10162
9f9eb9d2eefd
doc/interpreter/munge-texi.cc: untabify and delete emacs local variable settings
John W. Eaton <jwe@octave.org>
parents:
10076
diff
changeset
|
293 size_t len = doc_string.length (); |
9906 | 294 |
10162
9f9eb9d2eefd
doc/interpreter/munge-texi.cc: untabify and delete emacs local variable settings
John W. Eaton <jwe@octave.org>
parents:
10076
diff
changeset
|
295 int j = 0; |
9014
71fca0fc2436
save source file names for functions as comments in .texi files
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
296 |
10162
9f9eb9d2eefd
doc/interpreter/munge-texi.cc: untabify and delete emacs local variable settings
John W. Eaton <jwe@octave.org>
parents:
10076
diff
changeset
|
297 // If there is a leading comment with the file |
9f9eb9d2eefd
doc/interpreter/munge-texi.cc: untabify and delete emacs local variable settings
John W. Eaton <jwe@octave.org>
parents:
10076
diff
changeset
|
298 // name, copy it to the output. |
9f9eb9d2eefd
doc/interpreter/munge-texi.cc: untabify and delete emacs local variable settings
John W. Eaton <jwe@octave.org>
parents:
10076
diff
changeset
|
299 if (len > 1 |
9f9eb9d2eefd
doc/interpreter/munge-texi.cc: untabify and delete emacs local variable settings
John W. Eaton <jwe@octave.org>
parents:
10076
diff
changeset
|
300 && doc_string[j] == '@' |
9f9eb9d2eefd
doc/interpreter/munge-texi.cc: untabify and delete emacs local variable settings
John W. Eaton <jwe@octave.org>
parents:
10076
diff
changeset
|
301 && doc_string[j+1] == 'c') |
9f9eb9d2eefd
doc/interpreter/munge-texi.cc: untabify and delete emacs local variable settings
John W. Eaton <jwe@octave.org>
parents:
10076
diff
changeset
|
302 { |
9f9eb9d2eefd
doc/interpreter/munge-texi.cc: untabify and delete emacs local variable settings
John W. Eaton <jwe@octave.org>
parents:
10076
diff
changeset
|
303 j = 2; |
9f9eb9d2eefd
doc/interpreter/munge-texi.cc: untabify and delete emacs local variable settings
John W. Eaton <jwe@octave.org>
parents:
10076
diff
changeset
|
304 while (doc_string[j++] != '\n') |
9f9eb9d2eefd
doc/interpreter/munge-texi.cc: untabify and delete emacs local variable settings
John W. Eaton <jwe@octave.org>
parents:
10076
diff
changeset
|
305 /* find eol */; |
3301 | 306 |
10162
9f9eb9d2eefd
doc/interpreter/munge-texi.cc: untabify and delete emacs local variable settings
John W. Eaton <jwe@octave.org>
parents:
10076
diff
changeset
|
307 os << doc_string.substr (0, j); |
9f9eb9d2eefd
doc/interpreter/munge-texi.cc: untabify and delete emacs local variable settings
John W. Eaton <jwe@octave.org>
parents:
10076
diff
changeset
|
308 } |
3301 | 309 |
10162
9f9eb9d2eefd
doc/interpreter/munge-texi.cc: untabify and delete emacs local variable settings
John W. Eaton <jwe@octave.org>
parents:
10076
diff
changeset
|
310 while (doc_string[j] == ' ') |
9f9eb9d2eefd
doc/interpreter/munge-texi.cc: untabify and delete emacs local variable settings
John W. Eaton <jwe@octave.org>
parents:
10076
diff
changeset
|
311 j++; |
3301 | 312 |
10162
9f9eb9d2eefd
doc/interpreter/munge-texi.cc: untabify and delete emacs local variable settings
John W. Eaton <jwe@octave.org>
parents:
10076
diff
changeset
|
313 if (doc_string.substr (j, 15) == "-*- texinfo -*-") |
9f9eb9d2eefd
doc/interpreter/munge-texi.cc: untabify and delete emacs local variable settings
John W. Eaton <jwe@octave.org>
parents:
10076
diff
changeset
|
314 { |
9f9eb9d2eefd
doc/interpreter/munge-texi.cc: untabify and delete emacs local variable settings
John W. Eaton <jwe@octave.org>
parents:
10076
diff
changeset
|
315 j += 15; |
9906 | 316 |
10162
9f9eb9d2eefd
doc/interpreter/munge-texi.cc: untabify and delete emacs local variable settings
John W. Eaton <jwe@octave.org>
parents:
10076
diff
changeset
|
317 while (isspace (doc_string[j])) |
9f9eb9d2eefd
doc/interpreter/munge-texi.cc: untabify and delete emacs local variable settings
John W. Eaton <jwe@octave.org>
parents:
10076
diff
changeset
|
318 j++; |
3401 | 319 |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
320 // Make 'see also' references in functions |
10162
9f9eb9d2eefd
doc/interpreter/munge-texi.cc: untabify and delete emacs local variable settings
John W. Eaton <jwe@octave.org>
parents:
10076
diff
changeset
|
321 // possible using @anchor{TAG} (new with |
9f9eb9d2eefd
doc/interpreter/munge-texi.cc: untabify and delete emacs local variable settings
John W. Eaton <jwe@octave.org>
parents:
10076
diff
changeset
|
322 // Texinfo 4.0). |
9906 | 323 |
10162
9f9eb9d2eefd
doc/interpreter/munge-texi.cc: untabify and delete emacs local variable settings
John W. Eaton <jwe@octave.org>
parents:
10076
diff
changeset
|
324 if (symbol_name[0] == '@') |
9f9eb9d2eefd
doc/interpreter/munge-texi.cc: untabify and delete emacs local variable settings
John W. Eaton <jwe@octave.org>
parents:
10076
diff
changeset
|
325 symbol_name = "@" + symbol_name; |
9906 | 326 |
10162
9f9eb9d2eefd
doc/interpreter/munge-texi.cc: untabify and delete emacs local variable settings
John W. Eaton <jwe@octave.org>
parents:
10076
diff
changeset
|
327 os << "@anchor{doc-" << symbol_name << "}\n"; |
9891
1506a17832c9
doc building fixes for class methods
John W. Eaton <jwe@octave.org>
parents:
9794
diff
changeset
|
328 |
10162
9f9eb9d2eefd
doc/interpreter/munge-texi.cc: untabify and delete emacs local variable settings
John W. Eaton <jwe@octave.org>
parents:
10076
diff
changeset
|
329 os << doc_string.substr (j); |
9f9eb9d2eefd
doc/interpreter/munge-texi.cc: untabify and delete emacs local variable settings
John W. Eaton <jwe@octave.org>
parents:
10076
diff
changeset
|
330 } |
9f9eb9d2eefd
doc/interpreter/munge-texi.cc: untabify and delete emacs local variable settings
John W. Eaton <jwe@octave.org>
parents:
10076
diff
changeset
|
331 else |
9f9eb9d2eefd
doc/interpreter/munge-texi.cc: untabify and delete emacs local variable settings
John W. Eaton <jwe@octave.org>
parents:
10076
diff
changeset
|
332 os << doc_string; |
9f9eb9d2eefd
doc/interpreter/munge-texi.cc: untabify and delete emacs local variable settings
John W. Eaton <jwe@octave.org>
parents:
10076
diff
changeset
|
333 } |
9f9eb9d2eefd
doc/interpreter/munge-texi.cc: untabify and delete emacs local variable settings
John W. Eaton <jwe@octave.org>
parents:
10076
diff
changeset
|
334 } |
9f9eb9d2eefd
doc/interpreter/munge-texi.cc: untabify and delete emacs local variable settings
John W. Eaton <jwe@octave.org>
parents:
10076
diff
changeset
|
335 else |
9f9eb9d2eefd
doc/interpreter/munge-texi.cc: untabify and delete emacs local variable settings
John W. Eaton <jwe@octave.org>
parents:
10076
diff
changeset
|
336 bol = recover_from_macro (os, buf, i); |
9f9eb9d2eefd
doc/interpreter/munge-texi.cc: untabify and delete emacs local variable settings
John W. Eaton <jwe@octave.org>
parents:
10076
diff
changeset
|
337 } |
9f9eb9d2eefd
doc/interpreter/munge-texi.cc: untabify and delete emacs local variable settings
John W. Eaton <jwe@octave.org>
parents:
10076
diff
changeset
|
338 else if (c == 'E') |
9f9eb9d2eefd
doc/interpreter/munge-texi.cc: untabify and delete emacs local variable settings
John W. Eaton <jwe@octave.org>
parents:
10076
diff
changeset
|
339 { |
9f9eb9d2eefd
doc/interpreter/munge-texi.cc: untabify and delete emacs local variable settings
John W. Eaton <jwe@octave.org>
parents:
10076
diff
changeset
|
340 std::string file_name; |
9906 | 341 |
10162
9f9eb9d2eefd
doc/interpreter/munge-texi.cc: untabify and delete emacs local variable settings
John W. Eaton <jwe@octave.org>
parents:
10076
diff
changeset
|
342 if ( (buf[i++] = static_cast<char> (is.get ())) == 'X' |
10076 | 343 && (buf[i++] = static_cast<char> (is.get ())) == 'A' |
344 && (buf[i++] = static_cast<char> (is.get ())) == 'M' | |
345 && (buf[i++] = static_cast<char> (is.get ())) == 'P' | |
346 && (buf[i++] = static_cast<char> (is.get ())) == 'L' | |
347 && (buf[i++] = static_cast<char> (is.get ())) == 'E' | |
348 && (buf[i++] = static_cast<char> (is.get ())) == 'F' | |
349 && (buf[i++] = static_cast<char> (is.get ())) == 'I' | |
350 && (buf[i++] = static_cast<char> (is.get ())) == 'L' | |
351 && (buf[i++] = static_cast<char> (is.get ())) == 'E' | |
352 && (buf[i++] = static_cast<char> (is.get ())) == '(') | |
10162
9f9eb9d2eefd
doc/interpreter/munge-texi.cc: untabify and delete emacs local variable settings
John W. Eaton <jwe@octave.org>
parents:
10076
diff
changeset
|
353 { |
9f9eb9d2eefd
doc/interpreter/munge-texi.cc: untabify and delete emacs local variable settings
John W. Eaton <jwe@octave.org>
parents:
10076
diff
changeset
|
354 while ((c = is.get ()) != EOF && c != ')') |
9f9eb9d2eefd
doc/interpreter/munge-texi.cc: untabify and delete emacs local variable settings
John W. Eaton <jwe@octave.org>
parents:
10076
diff
changeset
|
355 file_name += static_cast<char> (c); |
9906 | 356 |
10162
9f9eb9d2eefd
doc/interpreter/munge-texi.cc: untabify and delete emacs local variable settings
John W. Eaton <jwe@octave.org>
parents:
10076
diff
changeset
|
357 file_name = top_srcdir + "/examples/" + file_name; |
9906 | 358 |
10162
9f9eb9d2eefd
doc/interpreter/munge-texi.cc: untabify and delete emacs local variable settings
John W. Eaton <jwe@octave.org>
parents:
10076
diff
changeset
|
359 process_example_file (file_name, os); |
9f9eb9d2eefd
doc/interpreter/munge-texi.cc: untabify and delete emacs local variable settings
John W. Eaton <jwe@octave.org>
parents:
10076
diff
changeset
|
360 } |
9f9eb9d2eefd
doc/interpreter/munge-texi.cc: untabify and delete emacs local variable settings
John W. Eaton <jwe@octave.org>
parents:
10076
diff
changeset
|
361 else |
9f9eb9d2eefd
doc/interpreter/munge-texi.cc: untabify and delete emacs local variable settings
John W. Eaton <jwe@octave.org>
parents:
10076
diff
changeset
|
362 bol = recover_from_macro (os, buf, i); |
9f9eb9d2eefd
doc/interpreter/munge-texi.cc: untabify and delete emacs local variable settings
John W. Eaton <jwe@octave.org>
parents:
10076
diff
changeset
|
363 } |
9f9eb9d2eefd
doc/interpreter/munge-texi.cc: untabify and delete emacs local variable settings
John W. Eaton <jwe@octave.org>
parents:
10076
diff
changeset
|
364 else |
9f9eb9d2eefd
doc/interpreter/munge-texi.cc: untabify and delete emacs local variable settings
John W. Eaton <jwe@octave.org>
parents:
10076
diff
changeset
|
365 bol = recover_from_macro (os, buf, i); |
9f9eb9d2eefd
doc/interpreter/munge-texi.cc: untabify and delete emacs local variable settings
John W. Eaton <jwe@octave.org>
parents:
10076
diff
changeset
|
366 } |
9f9eb9d2eefd
doc/interpreter/munge-texi.cc: untabify and delete emacs local variable settings
John W. Eaton <jwe@octave.org>
parents:
10076
diff
changeset
|
367 else |
9f9eb9d2eefd
doc/interpreter/munge-texi.cc: untabify and delete emacs local variable settings
John W. Eaton <jwe@octave.org>
parents:
10076
diff
changeset
|
368 os.put (static_cast<char> (c)); |
9f9eb9d2eefd
doc/interpreter/munge-texi.cc: untabify and delete emacs local variable settings
John W. Eaton <jwe@octave.org>
parents:
10076
diff
changeset
|
369 } |
3294 | 370 else |
10162
9f9eb9d2eefd
doc/interpreter/munge-texi.cc: untabify and delete emacs local variable settings
John W. Eaton <jwe@octave.org>
parents:
10076
diff
changeset
|
371 { |
9f9eb9d2eefd
doc/interpreter/munge-texi.cc: untabify and delete emacs local variable settings
John W. Eaton <jwe@octave.org>
parents:
10076
diff
changeset
|
372 if (c == '\n') |
9f9eb9d2eefd
doc/interpreter/munge-texi.cc: untabify and delete emacs local variable settings
John W. Eaton <jwe@octave.org>
parents:
10076
diff
changeset
|
373 bol = true; |
3294 | 374 |
10162
9f9eb9d2eefd
doc/interpreter/munge-texi.cc: untabify and delete emacs local variable settings
John W. Eaton <jwe@octave.org>
parents:
10076
diff
changeset
|
375 os.put (static_cast<char> (c)); |
9f9eb9d2eefd
doc/interpreter/munge-texi.cc: untabify and delete emacs local variable settings
John W. Eaton <jwe@octave.org>
parents:
10076
diff
changeset
|
376 } |
3294 | 377 } |
378 } | |
379 | |
380 int | |
381 main (int argc, char **argv) | |
382 { | |
10076 | 383 int retval = 0; |
384 | |
385 if (argc > 1) | |
386 { | |
387 top_srcdir = *++argv; | |
388 | |
389 while (*++argv) | |
390 process_doc_file (*argv); | |
9906 | 391 |
10076 | 392 process_texi_input_file (std::cin, std::cout); |
393 } | |
394 else | |
395 { | |
396 usage (); | |
3294 | 397 |
10076 | 398 retval = 1; |
399 } | |
3294 | 400 |
10076 | 401 return retval; |
402 | |
3294 | 403 } |