1 #-------------------------------------------------------------------------------
3 # | ____| _| |_ / __ \ /\ | \/ |
4 # | |__ _ __ ___ ___ / \| | | | / \ | \ / |
5 # | __| '__/ _ \/ _ ( (| |) ) | | |/ /\ \ | |\/| |
6 # | | | | | __/ __/\_ _/| |__| / ____ \| | | |
7 # |_| |_| \___|\___| |_| \____/_/ \_\_| |_|
9 # FreeFOAM: The Cross-Platform CFD Toolkit
11 # Copyright (C) 2008-2009 Michael Wild <themiwi@users.sf.net>
12 # Gerber van der Graaf <gerber_graaf@users.sf.net>
13 #-------------------------------------------------------------------------------
15 # This file is part of FreeFOAM.
17 # FreeFOAM is free software; you can redistribute it and/or modify it
18 # under the terms of the GNU General Public License as published by the
19 # Free Software Foundation; either version 2 of the License, or (at your
20 # option) any later version.
22 # FreeFOAM is distributed in the hope that it will be useful, but WITHOUT
23 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
24 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
27 # You should have received a copy of the GNU General Public License
28 # along with FreeFOAM; if not, write to the Free Software Foundation,
29 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
35 # Transform human-readable tags such as 'Description' into the Asciidoc
36 # equivalent. It takes the variables 'name', 'exe_prefix',
37 # 'exe_prefix_upper' and 'version' as arguments (the last one is required).
39 #------------------------------------------------------------------------------
42 function new_section
(name
) {
44 current_section=n_sections
;
45 text
[current_section
] =
"";
46 section_titles
[current_section
] = name
;
47 section_indices
[name
] = current_section
;
51 function delete_section
(name
) {
52 idx=section_indices
[name
];
53 delete section_titles
[idx
];
54 delete section_indices
[name
];
58 # add text to the buffer
59 function add_text
(str
) {
60 text
[current_section
] = text
[current_section
] str
;
63 # set default text in a section and create the secion if it doesn't exist
64 function set_default_text
(str
,sect_name
) {
65 bak = current_section
;
66 if( !
(sect_name in section_indices
) ) {
67 new_section
( sect_name
);
69 current_section = section_indices
[sect_name
];
70 if( !
length(text
[current_section
]) ) {
73 current_section = bak
;
76 # if necessary, push a list level (worker function)
77 function push_list
(type
,indent
){
78 if( indent
>list_indents
[list_level
] ||
79 ( indent==list_indents
[list_level
] &&
80 type
!=list_stack
[list_level
] ) ){
82 list_stack
[list_level
]=type
;
83 list_indents
[list_level
]=indent
;
91 # pop a list level without asking (worker function)
92 function pop_list_work
(){
93 delete list_stack
[list_level
];
94 delete list_indents
[list_level
];
96 if( list_level
> 0 ) {
101 # if necessary, pop list levels
102 function pop_list
(type
,indent
){
104 if( type ==
"term" ){
105 while( list_indents
[list_level
] >= indent
) {
111 while( list_indents
[list_level
] > indent
||
112 list_stack
[list_level
] != type
){
118 if( in_list
&& popped_list
)
123 function flush_lists
(){
125 pop_list
("term",list_indents
[1]);
130 # the general list element handler to be called by code
131 function handle_list
(type
){
132 ispace=gensub
(/^
( *)[^
].
*$
/,"\\1",1,$
0);
133 indent=
length(ispace
);
134 if( type ==
"term" ) {
135 pop_list
(type
,indent
);
138 if( push_list
(type
,indent
) ) return;
139 pop_list
(type
,indent
);
148 commentbar=
"/////////////////////////////////////////////////////////";
156 strip_regex=
"^[[:space:]]*";
160 if( !
length(name
) ) {
161 name=gensub
(/\..
*$
/,"","g",gensub
(/^.
*\
//,"","g",FILENAME));
163 if( !
length(version
) ) {
164 print "Variable 'version' not provided on the command line." > "/dev/stderr";
167 name_upper = exe_prefix_upper
toupper(name
);
168 name = exe_prefix name
;
170 print "THIS FILE WAS AUTOMATICALLY GENERATED FROM:";
172 print "CHANGES TO THIS FILE WILL BE LOST! EDIT THE";
173 print "ABOVE MENTIONED SOURCE FILE INSTEAD.";
175 print "= " name_upper
"(1) =";
176 print ":mansource: FreeFOAM";
177 print ":manversion: " version
;
178 print ":manmanual: FreeFOAM Manual";
184 # the header comments start
190 # the header comments stop
198 # the first paragraph will be 'brief' and the others 'detail'
199 in_head
&& /^Description
/{
203 new_section
("Brief");
208 in_doc
&& /^
(Notes?
|Usage
|Author
|See
*Also
)$
/{
210 sub(/See
*Also
/,"SeeAlso",$
0);
211 sub(/Notes?
/,"Note",$
0);
216 # strip leading indent from documentation text
221 # watch out for the end of the brief paragraph
225 new_section
("Description");
232 # swallow the "- name [OPTIONS]" line with the following paragraph in the "Usage" section
233 # TODO find a better solutio for the swallowd paragraph. But mostly it is the same as the brief
234 # description anyways...
235 in_doc
&& section_titles
[current_section
] ==
"Usage" && /^
[[:space
:]]*- .
*\
[OPTIONS?\
]/,/^$
/ {
239 # formatting commands
240 #####################
243 /[\\@
](em?
|a
)[[:space
:]]+[^
[:space
:]]+/ {
244 $
0 = gensub
(/[\\@
](em?
|a
)[[:space
:]]+([^
[:space
:]]+)/,"__\\2__","g",$
0);
249 gsub(/<\
/?em
>/,"__",$
0);
253 /[\\@
]b
[[:space
:]]+[^
[:space
:]]+/ {
254 $
0 = gensub
(/[\\@
]b
[[:space
:]]+([^
[:space
:]]+)/,"**\\1**","g",$
0);
259 gsub(/<\
/?b
>/,"**",$
0);
263 /[\\@
][cp
][[:space
:]]+[^
[:space
:]]+/ {
264 $
0 = gensub
(/[\\@
][cp
][[:space
:]]+([^
[:space
:]]+)/,"++\\1++","g",$
0);
269 gsub(/<\
/?tt
>/,"++",$
0);
274 $
0 = gensub
(/[\\@
]todo
/,"**TODO**","g",$
0);
279 str =
".............\n";
284 nindent =
length( gensub
(/^
([[:space
:]]*).
*$
/,"\\1",1,$
0) );
285 strip_regex =
"^[[:space:]]{1," nindnet
"}";
291 str =
".............\n";
296 strip_regex =
"^[[:space:]]*";
302 $
0 = gensub
(/\\([<>])/,"\\1","g",$
0);
309 /^
[[:space
:]]*[\\@
]param
[[:space
:]]+/ {
310 handle_list
("param");
311 sub(/[[:space
:]]*(\\n
)?$
/,"",$
0);
312 # special treatment for Usage section (ugly)
313 if( section_titles
[current_section
] ==
"Usage" ) {
314 # check whether it is a -opt option
315 if( $
0 ~
/^
[[:space
:]]*[\\@
]param
[[:space
:]]*-[^
[:space
:]]+/ ) {
316 opt = gensub
(/^
[[:space
:]]*[\\@
]param
[[:space
:]]*([^
:]*[^
[:space
:]])([[:space
:]]+:.
*)?$
/,"\\1",1,$
0);
317 options = options
" [" gensub
(/^
([^
[:space
:]]+)[[:space
:]]+(.
*)/,"\\1 '\\2'",1,opt
) "]";
318 $
0 = gensub
(/^
[[:space
:]]*[\\@
]param
[[:space
:]]+([^
[:space
:]]+)[[:space
:]]*([[:space
:]][^
:]+[^
[:space
:]])?
[[:space
:]]*(:[[:space
:]]*(.
*))?$
/,
319 "*\\1*\\2 ::\\4","g",$
0);
320 $
0 = gensub
(/^
[[:space
:]]*(\
*[^
[:space
:]]+\
*)[[:space
:]]*([^
[:space
:]].
*[^
[:space
:]])[[:space
:]]*::/,"\\1 '\\2' ::",1,$
0);
322 # no, it is an argument
323 opt = gensub
(/^
[[:space
:]]*[\\@
]param
[[:space
:]]*([^
:]*[^
[:space
:]])([[:space
:]]+:.
*)?$
/,"\\1",1,$
0);
324 options = options
" '" opt
"'";
325 $
0 = gensub
(/^
[[:space
:]]*[\\@
]param
[[:space
:]]+(<[^
>]+>)$
/, "'\\1' ::","g",$
0);
328 $
0 = gensub
(/^
([[:space
:]]*)[\\@
]param
[[:space
:]]+([^
:]+[^
\t])( *: *(.
*))?$
/,"\\1'\\2'::\n\\4","g",$
0);
334 handle_list
("ordered");
340 handle_list
("unordered");
344 /^
[[:space
:]]* \.$
/ {
352 # all doc lines are printed with all leading space stripped
354 sub(strip_regex
,"",$
0);
358 # do nothing by default
361 # write text and boilerplate footer
363 set_default_text
(" **TODO** brief description\n","Brief");
364 set_default_text
("**TODO** extended description\n","Description");
365 print name
" -" text
[section_indices
["Brief"]] "\n";
368 print "*" gensub
(/^
(freefoam
)-/,"\\1 ",1,name
) "*" options
" [-help] [-doc] [-srcDoc]\n";
371 print text
[section_indices
["Description"]];
374 set_default_text
("**TODO** add 'Usage' section\n","Usage");
375 print text
[section_indices
["Usage"]];
376 delete_section
("Brief");
377 delete_section
("Description");
378 delete_section
("Usage");
379 for( sect in section_indices
) {
380 if( sect
!= "SeeAlso" ) {
381 idx = section_indices
[sect
];
383 print gensub
(/.
/,"-","g",sect
);
389 if( length(text
[section_indices
["SeeAlso"]]) ) {
390 print text
[section_indices
["SeeAlso"]];
393 An overview of FreeFOAM is given in linkff:freefoam[7]. For information\n\
394 on the configuration of FreeFOAM, refer to linkff:freefoam-config[7].\n\
398 set_default_text
("OpenCFD Ltd.\n","Author");
399 print text
[section_indices
["Author"]];
402 Part of the linkff:freefoam[7] suite.\n\
406 Copyright (C) 2009 Michael Wild.\n\
407 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\
408 Permission is granted to copy, distribute and/or modify this document under the\n\
409 terms of the GNU Free Documentation License, Version 1.3 or any later version\n\
410 published by the Free Software Foundation; with no Invariant Sections, no\n\
411 Front-Cover Texts, and no Back-Cover Texts. A copy of the license is available\n\
412 from http://www.gnu.org/copyleft/fdl.html\n\
414 Copyright (C) 1991-2009 OpenCFD Ltd.\n\
415 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\
416 OpenFOAM is free software; you can redistribute it and/or modify\n\
417 it under the terms of the GNU General Public License as published by the Free\n\
418 Software Foundation; either version 2 of the License, or (at your option) any\n\
419 later version. A copy of the license is available from\n\
420 http://www.gnu.org/licenses/old-licenses/gpl-2.0.html\n\
422 Copyright (C) 2008-2009 Michael Wild.\n\
423 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\
424 FreeFOAM is free software; you can redistribute it and/or modify it under the\n\
425 terms of the GNU General Public License as published by the Free Software\n\
426 Foundation; either version 2 of the License, or (at your option) any later\n\
427 version. A copy of the license is available from\n\
428 http://www.gnu.org/licenses/old-licenses/gpl-2.0.html"
429 print "\n" commentbar
"\nvim: set ft=asciidoc:\n" commentbar
;
433 # ------------------------- vim: set sw=3 sts=3 et: --------------- end-of-file