Index: c2man/html.c
diff -c c2man/html.c:1.2 c2man/html.c:1.3
*** c2man/html.c:1.2 Sun Jan 30 15:22:15 2000
--- c2man/html.c Sun Jan 30 16:06:49 2000
***************
*** 271,305 ****
boolean new_line = TRUE;
/* correct punctuation a bit as it goes out */
! for (;*text;text++)
! {
! int c = *text;
!
! if (new_line && (c == '-' || c == '*' || c == '\n' ||
! is_numbered(text)))
! {
! output->break_line();
! state = CAPITALISE;
}
! else if (new_line && c == '\n') { /* Two newlines - Paragraph break */
! output->blank_line();
! }
! else if (c == '.')
! state = PERIOD;
! else if (isspace(c) && state == PERIOD)
! state = CAPITALISE;
! else if (isalnum(c) || ispunct(c))
! {
! if (islower(c) && state == CAPITALISE) c = toupper(c);
! state = TEXT;
! }
!
! output->character(c);
! new_line = c == '\n';
}
!
! /* do a full stop if there wasn't one */
! if (state == TEXT) output->character('.');
}
/* ideally, this should be made aware of embedded html commands */
--- 271,316 ----
boolean new_line = TRUE;
/* correct punctuation a bit as it goes out */
! for (;*text;text++) {
! int c = *text;
!
! if (new_line && html_in_code && c != '\t') {
! html_code_end();
! }
!
! if (new_line && c == '\t') {
! if (!html_in_code) {
! html_code_start();
! state = TEXT;
}
! }
! else if (new_line && (c == '-' || c == '*' || c == '\n' ||
! is_numbered(text))) {
! output->break_line();
! state = CAPITALISE;
! }
! else if (new_line && c == '\n') { /* Two newlines - Paragraph break */
! output->blank_line();
! }
! else if (c == '.')
! state = PERIOD;
! else if (isspace(c) && state == PERIOD)
! state = CAPITALISE;
! else if (isalnum(c) || ispunct(c)) {
! if (islower(c) && state == CAPITALISE) c = toupper(c);
! state = TEXT;
! }
!
! output->character(c);
! new_line = c == '\n';
}
!
! if ( html_in_code ) { /* end verbatim section at end of comments */
! html_code_end();
! } else /* no extra point after verbatim section */
! /* do a full stop if there wasn't one */
! if (state == TEXT) output->character('.');
!
}
/* ideally, this should be made aware of embedded html commands */
Index: c2man/latex.c
diff -c c2man/latex.c:1.3 c2man/latex.c:1.4
*** c2man/latex.c:1.3 Sun Jan 30 15:26:22 2000
--- c2man/latex.c Sun Jan 30 16:06:49 2000
***************
*** 70,76 ****
put_string("\\documentstyle{article}\n");
output_warning();
! put_string("\\begin{document}\n");
}
void latex_dash() { put_string("---"); }
--- 70,77 ----
put_string("\\documentstyle{article}\n");
output_warning();
! put_string("\\begin{document}\n");
! put_string("\\setlength{\\parindent}{0pt}\n");
}
void latex_dash() { put_string("---"); }
***************
*** 91,97 ****
put_string("}\n");
}
! void latex_break_line() { /* put_string("\\newline\n"); */ }
void latex_blank_line() { put_string("\n"); }
void latex_code_start() { put_string("\\begin{verbatim}\n"); verbatim = TRUE; }
--- 92,98 ----
put_string("}\n");
}
! void latex_break_line() { /* put_string("\\\n"); */}
void latex_blank_line() { put_string("\n"); }
void latex_code_start() { put_string("\\begin{verbatim}\n"); verbatim = TRUE; }
***************
*** 186,216 ****
boolean new_line = TRUE;
/* correct punctuation a bit as it goes out */
! for (;*text;text++)
! {
! int c = *text;
!
! if (new_line && (c == '-' || c == '*'))
! {
! output->break_line();
! state = CAPITALISE;
}
! else if (c == '.')
! state = PERIOD;
! else if (isspace(c) && state == PERIOD)
! state = CAPITALISE;
! else if (isalnum(c) || ispunct(c))
! {
! if (islower(c) && state == CAPITALISE) c = toupper(c);
! state = TEXT;
! }
!
! output->character(c);
! new_line = c == '\n';
}
! /* do a full stop if there wasn't one */
! if (state == TEXT) output->character('.');
}
/* ideally, this should be made aware of embedded latex commands */
--- 187,228 ----
boolean new_line = TRUE;
/* correct punctuation a bit as it goes out */
! for (;*text;text++) {
! int c = *text;
!
! if (new_line && verbatim && c != '\t') {
! latex_code_end(); /* \end{verbatim}; verbatim=FALSE; */
! }
!
! if (new_line && c == '\t') {
! if (!verbatim) {
! latex_code_start(); /* \begin{verbatim}; verbatim=TRUE; */
}
! } else if (new_line && (c == '-' || c == '*')) {
! /* latex output-> break_line() does nothing
! * output->break_line();
! */
! put_string("\\\\\n");
! state = CAPITALISE;
! }
! else if (c == '.')
! state = PERIOD;
! else if (isspace(c) && state == PERIOD)
! state = CAPITALISE;
! else if (isalnum(c) || ispunct(c)) {
! if (islower(c) && state == CAPITALISE) c = toupper(c);
! state = TEXT;
! }
!
! output->character(c);
! new_line = c == '\n';
}
! if ( verbatim ) { /* end verbatim section at end of comments */
! latex_code_end();
! } else /* no extra point after verbatim section */
! /* do a full stop if there wasn't one */
! if (state == TEXT) output->character('.');
}
/* ideally, this should be made aware of embedded latex commands */
Index: c2man/lex.l
diff -c c2man/lex.l:1.1.1.1 c2man/lex.l:1.2
*** c2man/lex.l:1.1.1.1 Sun Jan 30 15:11:46 2000
--- c2man/lex.l Sun Jan 30 16:06:49 2000
***************
*** 79,84 ****
--- 79,85 ----
%}
WS [ \t]
+ CWS [ ]
WLF [ \t\n\f]*
LETTER [A-Za-z_]
DIGIT [0-9]
***************
*** 286,292 ****
}
}
! ^{WS}*"/*"[*=-]*{WS}+ {
comment_caller = YYSTATE;
start_comment(FALSE);
BEGIN COMMENT; }
--- 287,293 ----
}
}
! ^{WS}*"/*"[*=-]*{CWS}+ {
comment_caller = YYSTATE;
start_comment(FALSE);
BEGIN COMMENT; }
***************
*** 295,301 ****
comment_caller = YYSTATE;
start_comment(FALSE);
BEGIN COMMENT; }
! "/*"[*=-]*{WS}+ {
comment_caller = YYSTATE;
start_comment(TRUE);
BEGIN COMMENT; }
--- 296,302 ----
comment_caller = YYSTATE;
start_comment(FALSE);
BEGIN COMMENT; }
! "/*"[*=-]*{CWS}+ {
comment_caller = YYSTATE;
start_comment(TRUE);
BEGIN COMMENT; }
***************
*** 304,315 ****
comment_caller = YYSTATE;
start_comment(TRUE);
BEGIN COMMENT; }
! ^{WS}*"/"+{WS}* |
! ^{WS}*"/"*"*"*{WS}+ BEGIN COMMENT;
^{WS}*"/"*"*"*[^/] { yyless(yyleng-1); BEGIN COMMENT; }
. { yyless(0); BEGIN COMMENT; }
\n newline_comment();
! {WS}*"*"+"/"{WS}*\n{WS}*"/*""*"*{WS}+ newline_comment();
{WS}*"*"+"/"{WS}*\n{WS}*"/*""*"*[^/] {
yyless(yyleng-1); newline_comment(); }
{WS}*[*=-]*"*/"{WS}*$ { int ret = end_comment(TRUE);
--- 305,316 ----
comment_caller = YYSTATE;
start_comment(TRUE);
BEGIN COMMENT; }
! ^{CWS}*"/"+{CWS}* |
! ^{CWS}*"/"*"*"*{CWS}+ BEGIN COMMENT;
^{WS}*"/"*"*"*[^/] { yyless(yyleng-1); BEGIN COMMENT; }
. { yyless(0); BEGIN COMMENT; }
\n newline_comment();
! {WS}*"*"+"/"{WS}*\n{WS}*"/*""*"*{CWS}+ newline_comment();
{WS}*"*"+"/"{WS}*\n{WS}*"/*""*"*[^/] {
yyless(yyleng-1); newline_comment(); }
{WS}*[*=-]*"*/"{WS}*$ { int ret = end_comment(TRUE);
***************
*** 318,324 ****
{WS}*[*=-]*"*/" { int ret = end_comment(FALSE);
BEGIN comment_caller;
if (ret) return ret; }
! [^*\n \t]* |
{WS}* |
"*"+[^*/\n]* add_comment(yytext);
{WS}*\n { newline_comment(); BEGIN COMMLINE; }
--- 319,325 ----
{WS}*[*=-]*"*/" { int ret = end_comment(FALSE);
BEGIN comment_caller;
if (ret) return ret; }
! [^*\n ]* |
{WS}* |
"*"+[^*/\n]* add_comment(yytext);
{WS}*\n { newline_comment(); BEGIN COMMLINE; }
Index: c2man/nroff.c
diff -c c2man/nroff.c:1.4 c2man/nroff.c:1.5
*** c2man/nroff.c:1.4 Sun Jan 30 15:26:22 2000
--- c2man/nroff.c Sun Jan 30 16:06:49 2000
***************
*** 7,19 ****
#include "semantic.h"
#include
- void nroff_text(text)
- const char *text;
- {
- // put_string(text);
- while(*text)
- nroff_char(*text++);
- }
void nroff_char(c)
const int c;
--- 7,12 ----
***************
*** 29,34 ****
--- 22,34 ----
}
}
+ void nroff_text(text)
+ const char *text;
+ {
+ while(*text)
+ nroff_char(*text++);
+ }
+
void nroff_comment() { put_string(".\\\" "); }
void nroff_header(firstpage, input_files, grouped, name, terse, section)
***************
*** 237,278 ****
enum { TEXT, PERIOD, CAPITALISE } state = CAPITALISE;
boolean new_line = TRUE;
boolean dot_command = FALSE;
/* correct punctuation a bit as it goes out */
! for (;*text;text++)
! {
! int c = *text;
!
! if (dot_command)
! {
! if (c == '\n') dot_command = FALSE;
}
! else if (new_line && c == '.')
! dot_command = TRUE;
! else if (new_line && (c == '-' || c == '*' || is_numbered(text)))
! {
! output->break_line();
! state = CAPITALISE;
! }
! else if (c == '.')
! state = PERIOD;
! else if (isspace(c) && state == PERIOD)
! state = CAPITALISE;
! else if (isalnum(c) || ispunct(c))
! {
! if (islower(c) && state == CAPITALISE) c = toupper(c);
! state = TEXT;
! }
!
! if (new_line && c == '\'')
! output->character('\\');
!
! output->character(c);
! new_line = c == '\n';
}
!
! /* do a full stop if there wasn't one */
! if (!dot_command && state == TEXT) output->character('.');
}
void
--- 237,289 ----
enum { TEXT, PERIOD, CAPITALISE } state = CAPITALISE;
boolean new_line = TRUE;
boolean dot_command = FALSE;
+ boolean verbatim = FALSE;
/* correct punctuation a bit as it goes out */
! for (;*text;text++) {
! int c = *text;
!
! if (new_line && verbatim && c != '\t') {
! verbatim = FALSE;
! output->text(".fi\n");
! }
!
! if (dot_command) {
! if (c == '\n') dot_command = FALSE;
! }
! else if (new_line && c == '\t') {
! if (!verbatim) {
! output->text(".nf\n");
! verbatim = TRUE;
}
! }
! else if (new_line && c == '.')
! dot_command = TRUE;
! else if (new_line && (c == '-' || c == '*' || is_numbered(text))) {
! output->break_line();
! state = CAPITALISE;
! }
! else if (c == '.')
! state = PERIOD;
! else if (isspace(c) && state == PERIOD)
! state = CAPITALISE;
! else if (isalnum(c) || ispunct(c)) {
! if (islower(c) && state == CAPITALISE) c = toupper(c);
! state = TEXT;
! }
!
! if (new_line && c == '\'')
! output->character('\\');
!
! output->character(c);
! new_line = c == '\n';
}
!
! if ( verbatim ) { /* end verbatim section at end of comments */
! output->text("\n.fi\n");
! } else /* no extra point after verbatim section */
! /* do a full stop if there wasn't one */
! if (!dot_command && state == TEXT) output->character('.');
}
void
Index: c2man/semantic.h
diff -c c2man/semantic.h:1.1.1.1 c2man/semantic.h:1.2
*** c2man/semantic.h:1.1.1.1 Sun Jan 30 15:11:46 2000
--- c2man/semantic.h Sun Jan 30 16:06:49 2000
***************
*** 119,121 ****
--- 119,122 ----
boolean has_parameters _((const Declarator *d));
boolean is_function_declarator _((const Declarator *d));
+ boolean is_numbered(const char *text);
Index: c2man/test/README.backslash
diff -c c2man/test/README.backslash:1.1 c2man/test/README.backslash:1.2
*** c2man/test/README.backslash:1.1 Sun Jan 30 15:26:26 2000
--- c2man/test/README.backslash Sun Jan 30 16:06:54 2000
***************
*** 9,14 ****
latex: '\0' --> '$\backslash$0'
nroff: '\0' --> '\\0'
! I added this behaviour to the files 'nroff.c' and 'latex.c'.
For an example use backslash.h and take a look at the output
or try to do 'latex backslash.tex' with or without this patch.
--- 9,14 ----
latex: '\0' --> '$\backslash$0'
nroff: '\0' --> '\\0'
! I added this behavior to the files 'nroff.c' and 'latex.c'.
For an example use backslash.h and take a look at the output
or try to do 'latex backslash.tex' with or without this patch.
Index: c2man/test/README.verbatim
diff -c /dev/null c2man/test/README.verbatim:1.1
*** /dev/null Sun Jan 30 16:12:50 2000
--- c2man/test/README.verbatim Sun Jan 30 16:06:54 2000
***************
*** 0 ****
--- 1,79 ----
+
+ I added a feature to c2man to insert verbatim text (e.g. pre-formated
+ sourcecode in an example section) into the c2man text output.
+
+ With the original c2man you can achieve this via output specific
+ commands in the documented source files like '.nf' and '.fi' for nroff,
+ '' and '
for html and '\begin{verbatim}' and
+ '\end{verbatim} for latex output.
+
+ To avoid this output specific including of format statements in the documented
+ source code I added to c2man, that consecutive comment lines beginning with an
+ tabulator character are formated as verbatim.
+
+ Original behavior:
+ /* * This is best demonstrated by the including of formated source code
+ * examples in the documented source code, like this:
+ * int verbatim_feature(void) {
+ * // mind of C style comments not possible in comments
+ * return true;
+ * }
+ * Now I hope this example keeps its formated style in the various output
+ * formats.
+ */
+ int verbatim_feature(void);
+
+ leads to the following unix man page output:
+ verbatim_feature(3) verbatim_feature(3)
+
+
+ NAME
+ verbatim_feature - test the verbatim output feature.
+
+ SYNOPSIS
+ #include
+
+ int verbatim_feature(void);
+
+ DESCRIPTION
+ This is best demonstrated by the including of formated
+ source code examples in the documented source code, like
+ this: int verbatim_feature(void) { // mind of C style com
+ ments not possible in comments return true; } Now I hope
+ this example keeps its formated style in the various out
+ put formats.
+
+ After applying my patch c2man produces the following, much more beautiful
+ output:
+
+ verbatim_feature(3) verbatim_feature(3)
+
+
+ NAME
+ verbatim_feature - test the verbatim output feature.
+
+ SYNOPSIS
+ #include
+
+ int verbatim_feature(void);
+
+ DESCRIPTION
+ This is best demonstrated by the including of formated
+ source code examples in the documented source code, like
+ this:
+ int verbatim_feature(void) {
+ // mind of C style comments not possible in comments
+ return true;
+ }
+ Now I hope this example keeps its formated style in the
+ various output formats.
+
+
+
+ The same behavior is added for the html and latex output. I never used
+ the texinfo or autodoc feature, so I changed nothing for this two output
+ formats.
+
+ A full example can be found in the file 'verbatim.h' with the
+ original nroff output of c2man in 'verbatim_feature.3_orig' and
+ the advanced output in 'verbatim_feature.3'.
Index: c2man/test/verbatim.h
diff -c /dev/null c2man/test/verbatim.h:1.1
*** /dev/null Sun Jan 30 16:12:50 2000
--- c2man/test/verbatim.h Sun Jan 30 16:06:54 2000
***************
*** 0 ****
--- 1,21 ----
+ /*
+ * test the verbatim output feature.
+ * This is a test for the verbatim output feature. Consecutive lines of
+ * comments beginning with an tabulator character should be formated in
+ * a verbatim style for nroff, latex and html.
+ *
+ * This is best demonstrated by the including of formated source code
+ * examples in the documented source code, like this:
+ * int verbatim_feature(void) {
+ * // mind of C style comments not possible in comments
+ * return true;
+ * }
+ * Now I hope this example keeps its formated style in the various output
+ * formats.
+ * And as I hope that I have not added any side effects this is
+ * a test of tabulator characters in the middle of the text like
+ * here (--> <--).
+ */
+ int verbatim_feature(char *text /* A little test for the behavior of
+ * c2man for very long function
+ * parameter descriptions */);
Index: c2man/test/verbatim_feature.3
diff -c /dev/null c2man/test/verbatim_feature.3:1.1
*** /dev/null Sun Jan 30 16:12:50 2000
--- c2man/test/verbatim_feature.3 Sun Jan 30 16:06:54 2000
***************
*** 0 ****
--- 1,35 ----
+ .\" WARNING! THIS FILE WAS GENERATED AUTOMATICALLY BY c2man!
+ .\" DO NOT EDIT! CHANGES MADE TO THIS FILE WILL BE LOST!
+ .TH "verbatim_feature" 3 "29 January 2000" "c2man verbatim.h"
+ .SH "NAME"
+ verbatim_feature \- test the verbatim output feature.
+ .SH "SYNOPSIS"
+ .ft B
+ #include
+ .sp
+ int verbatim_feature(char *text);
+ .ft R
+ .SH "PARAMETERS"
+ .TP
+ .B "char *text"
+ A little test for the behavior of
+ c2man for very long function
+ parameter descriptions.
+ .SH "DESCRIPTION"
+ This is a test for the verbatim output feature. Consecutive lines of
+ comments beginning with an tabulator character should be formated in
+ a verbatim style for nroff, latex and html.
+
+ This is best demonstrated by the including of formated source code
+ examples in the documented source code, like this:
+ .nf
+ int verbatim_feature(void) {
+ // mind of C style comments not possible in comments
+ return true;
+ }
+ .fi
+ Now I hope this example keeps its formated style in the various output
+ formats.
+ And as I hope that I have not added any side effects this is
+ a test of tabulator characters in the middle of the text like
+ here (--> <--).
Index: c2man/test/verbatim_feature.3_orig
diff -c /dev/null c2man/test/verbatim_feature.3_orig:1.1
*** /dev/null Sun Jan 30 16:12:50 2000
--- c2man/test/verbatim_feature.3_orig Sun Jan 30 16:06:54 2000
***************
*** 0 ****
--- 1,33 ----
+ .\" WARNING! THIS FILE WAS GENERATED AUTOMATICALLY BY c2man!
+ .\" DO NOT EDIT! CHANGES MADE TO THIS FILE WILL BE LOST!
+ .TH "verbatim_feature" 3 "29 January 2000" "c2man verbatim.h"
+ .SH "NAME"
+ verbatim_feature \- test the verbatim output feature.
+ .SH "SYNOPSIS"
+ .ft B
+ #include
+ .sp
+ int verbatim_feature(char *text);
+ .ft R
+ .SH "PARAMETERS"
+ .TP
+ .B "char *text"
+ A little test for the behavior of
+ c2man for very long function
+ parameter descriptions.
+ .SH "DESCRIPTION"
+ This is a test for the verbatim output feature. Consecutive lines of
+ comments beginning with an tabulator character should be formated in
+ a verbatim style for nroff, latex and html.
+
+ This is best demonstrated by the including of formated source code
+ examples in the documented source code, like this:
+ int verbatim_feature(void) {
+ // mind of C style comments not possible in comments
+ return true;
+ }
+ Now I hope this example keeps its formated style in the various output
+ formats.
+ And as I hope that I have not added any side effects this is
+ a test of tabulator characters in the middle of the text like
+ here (--> <--).