Bug 105765 - mdoc.samples(7) broken by man2html
Summary: mdoc.samples(7) broken by man2html
Status: RESOLVED FIXED
Alias: None
Product: kio
Classification: Frameworks and Libraries
Component: man (show other bugs)
Version: unspecified
Platform: unspecified Linux
: NOR normal
Target Milestone: ---
Assignee: Unassigned bugs mailing-list
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-05-16 15:23 UTC by Nicolas Goutte
Modified: 2018-06-24 13:37 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Nicolas Goutte 2005-05-16 15:23:47 UTC
Version:            (using KDE Devel)
Compiler:          gcc 3.3.1 -march=pentium2
OS:                Linux

The man page mdoc.samples(7) cannot be processed correctly by man2html and produces horrible results as well in the content as on the HTML syntax produced.

(The problem is the intensive use of mdoc. As for the HTML syntax, that is another matter.)

This includes bug #105764

Have a nice day!
Comment 1 Nicolas Goutte 2005-05-18 22:56:41 UTC
SVN commit 415544 by goutte:

- Fix section names of mdoc man pages
  (This fixes one problem of the many ones of mdoc.samples(7))
- Compile Solaris section names depending on #ifdef Q_OS_SOLARIS
CCBUG:105765


 M  +45 -41    trunk/KDE/kdebase/kioslave/man/man2html.cpp  


--- trunk/KDE/kdebase/kioslave/man/man2html.cpp #415543:415544
@@ -1926,43 +1926,8 @@
 }
 
 static const char *section_list[] = {
-    "1", "User Commands ",
-    "1C", "User Commands",
-    "1G", "User Commands",
-    "1S", "User Commands",
-    "1V", "User Commands ",
-    "2", "System Calls",
-    "2V", "System Calls",
-    "3", "C Library Functions",
-    "3C", "Compatibility Functions",
-    "3F", "Fortran Library Routines",
-    "3K", "Kernel VM Library Functions",
-    "3L", "Lightweight Processes Library",
-    "3M", "Mathematical Library",
-    "3N", "Network Functions",
-    "3R", "RPC Services Library",
-    "3S", "Standard I/O Functions",
-    "3V", "C Library Functions",
-    "3X", "Miscellaneous Library Functions",
-    "4", "Devices and Network Interfaces",
-    "4F", "Protocol Families",
-    "4I", "Devices and Network Interfaces",
-    "4M", "Devices and Network Interfaces",
-    "4N", "Devices and Network Interfaces",
-    "4P", "Protocols",
-    "4S", "Devices and Network Interfaces",
-    "4V", "Devices and Network Interfaces",
-    "5", "File Formats",
-    "5V", "File Formats",
-    "6", "Games and Demos",
-    "7", "Environments, Tables, and Troff Macros",
-    "7V", "Environments, Tables, and Troff Macros",
-    "8", "Maintenance Commands",
-    "8C", "Maintenance Commands",
-    "8S", "Maintenance Commands",
-    "8V", "Maintenance Commands",
-    "L", "Local Commands",
-/* for Solaris:
+#ifdef Q_OS_SOLARIS
+    // for Solaris
     "1", "User Commands",
     "1B", "SunOS/BSD Compatibility Package Commands",
     "1b", "SunOS/BSD Compatibility Package Commands",
@@ -2029,7 +1994,46 @@
     "9S", "DDI and DKI Data Structures",
     "9s", "DDI and DKI Data Structures",
     "L", "Local Commands",
-*/
+#else
+    // Other OS
+    "1", "User Commands ",
+    "1C", "User Commands",
+    "1G", "User Commands",
+    "1S", "User Commands",
+    "1V", "User Commands ",
+    "2", "System Calls",
+    "2V", "System Calls",
+    "3", "C Library Functions",
+    "3C", "Compatibility Functions",
+    "3F", "Fortran Library Routines",
+    "3K", "Kernel VM Library Functions",
+    "3L", "Lightweight Processes Library",
+    "3M", "Mathematical Library",
+    "3N", "Network Functions",
+    "3R", "RPC Services Library",
+    "3S", "Standard I/O Functions",
+    "3V", "C Library Functions",
+    "3X", "Miscellaneous Library Functions",
+    "4", "Devices and Network Interfaces",
+    "4F", "Protocol Families",
+    "4I", "Devices and Network Interfaces",
+    "4M", "Devices and Network Interfaces",
+    "4N", "Devices and Network Interfaces",
+    "4P", "Protocols",
+    "4S", "Devices and Network Interfaces",
+    "4V", "Devices and Network Interfaces",
+    "5", "File Formats",
+    "5V", "File Formats",
+    "6", "Games and Demos",
+    "7", "Environments, Tables, and Troff Macros",
+    "7V", "Environments, Tables, and Troff Macros",
+    "8", "Maintenance Commands",
+    "8C", "Maintenance Commands",
+    "8S", "Maintenance Commands",
+    "8V", "Maintenance Commands",
+    "L", "Local Commands",
+#endif
+    // The defaults
     NULL, "Misc. Reference Manual Pages",
     NULL, NULL
 };
@@ -2039,7 +2043,7 @@
     int i=0;
 
     if (!c) return "";
-    while (section_list[i] && strcmp(c,section_list[i])) i=i+2;
+    while (section_list[i] && qstrcmp(c,section_list[i])) i=i+2;
     if (section_list[i+1]) return section_list[i+1];
     else return c;
 }
@@ -3072,10 +3076,10 @@
                         out_html( scan_troff(wordlist[0], 0, NULL ) );
                     out_html( "</h1>\n" );
                     out_html("Section: " );
-                    if (words>4)
+                    if (!mandoc_command && words>4)
                             out_html(scan_troff(wordlist[4], 0, NULL) );
 		    else
-                            out_html(section_name(scan_troff(wordlist[1], 0, NULL)));
+                            out_html(section_name(wordlist[1]));
 		    out_html(" (");
                         out_html(scan_troff(wordlist[1], 0, NULL));
                     out_html(")\n");
Comment 2 Nicolas Goutte 2005-05-19 11:47:18 UTC
SVN commit 415679 by goutte:

- ignore correctly sequences preceded by \& (mdoc)
- \& is now again treated as a normal zero-width character (i.e. empty string)
BUG:105764
This a big step toward fully supporting the display of mdoc.samples(7)
CCBUG:105765


 M  +7 -15     trunk/KDE/kdebase/kioslave/man/man2html.cpp  


--- trunk/KDE/kdebase/kioslave/man/man2html.cpp #415678:415679
@@ -1033,17 +1033,8 @@
     case 'r':
     case 'u':
     case '\n':
+    case '&':
         h=""; break;
-    case '&': // ### FIXME
-    {
-        // We need to print the next character, to skip its special meaning
-        c++;
-        // As we need a zero-terminated string we use the array b
-        b[0]=*c;
-        b[1]=0;
-        h=b;
-        break;
-    }
     case '(':
        c++;
        i= c[0]*256+c[1];
@@ -3976,7 +3967,7 @@
 }
 */
 static int contained_tab=0;
-static int mandoc_line=0;	/* Signals whether to look for embedded mandoc
+static bool mandoc_line=false;	/* Signals whether to look for embedded mandoc
 				 * commands.
 				 */
 
@@ -4024,11 +4015,12 @@
 	    FLUSHIBP;
 	    h = scan_request(h);
 	    if (h && san && h[-1]=='\n') h--;
-	} else if (mandoc_line
+	} else if (mandoc_line // ### FIXME: a mdoc request must directly start after a space
+	           && *(h-1) && isspace(*(h-1)) // We can always go back, as there is at least the sequence at the start of line
 		   && *(h) && isupper(*(h))
 		   && *(h+1) && islower(*(h+1))
 		   && *(h+2) && isspace(*(h+2))) {
-	    /* BSD imbedded command eg ".It Fl Ar arg1 Fl Ar arg2" */
+	    // mdoc(7) embedded command eg ".It Fl Ar arg1 Fl Ar arg2"
 	    FLUSHIBP;
 	    h = scan_request(h);
 	    if (san && h[-1]=='\n') h--;
@@ -4172,8 +4164,8 @@
 {
     char *ret;
     char *end = c;
-    int oldval = mandoc_line;
-    mandoc_line = 1;
+    bool oldval = mandoc_line;
+    mandoc_line = true;
     while (*end && *end != '\n') {
         end++;
     }
Comment 3 Nicolas Goutte 2005-05-21 00:04:50 UTC
SVN commit 416239 by goutte:

Fix long function arguments (Requests .Fo .Fa .Fc)
CCBUG:105765


 M  +128 -40   trunk/KDE/kdebase/kioslave/man/man2html.cpp  
Comment 4 Nicolas Goutte 2005-05-21 01:10:15 UTC
SVN commit 416265 by goutte:

- fix standalone .Fa request, like the ones in mdoc.samples(7) (.Fo .Fa .Fc)
- fix .Fl request
- try to fix .Fn (not working yet)
CCBUG:105765


 M  +115 -63   trunk/KDE/kdebase/kioslave/man/man2html.cpp  
Comment 5 Nicolas Goutte 2005-05-21 11:51:58 UTC
SVN commit 416352 by goutte:

A few code change, especially on the operating system requests
(This does not fix these requests.)

As I seem to have to correct many mdoc(7) requests always nearly the same way,
I think that a new approach is needed than the one I used yesterday.
CCBUG:105765


 M  +10 -9     trunk/KDE/kdebase/kioslave/man/man2html.cpp  


--- trunk/KDE/kdebase/kioslave/man/man2html.cpp #416351:416352
@@ -3558,23 +3558,23 @@
 	    trans_char(c,'"','\a');
 	    c=c+j;
 	    if (*c=='\n') c++;
-                if (i==V('A','t'))
+                if (request==REQ_At)
 		{
                     out_html("AT&amp;T UNIX ");
 		    parsable=false;
 		}
-                else if (i==V('F','x'))
+                else if (request==REQ_Fx)
 		{
                     out_html("FreeBSD ");
 		    parsable=false;
 		}
-                else if (i==V('N','x'))
+                else if (request==REQ_Nx))
                     out_html("NetBSD ");
-                else if (i==V('O','x'))
+                else if (request==REQ_Ox)
                     out_html("OpenBSD ");
-                else if (i==V('B','x'))
+                else if (request==REQ_Bx)
                     out_html("BSD ");
-                else if (i==V('U','x'))
+                else if (request==REQ_Ux)
                     out_html("UNIX ");
 		if (parsable)
         	    c=scan_troff_mandoc(c,1,0);
@@ -3919,9 +3919,9 @@
                 else
                     curpos=0;
 	    break;
-	case REQ_Nm:	/* mdoc(7) */
+     case REQ_Nm:	// mdoc(7) "Name Macro" ### FIXME
 	  {
-	    static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = "";
+            static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; // ### TODO Use QCString
 	    trans_char(c,'"','\a');
 	    c=c+j;
 
@@ -3943,6 +3943,7 @@
             mandoc_name_count++;
 
 	    out_html(change_to_font('B'));
+            // ### FIXME: fill_words must be used
 	    while (*c == ' '|| *c == '\t') c++;
                 if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9'))
                 {
@@ -3972,7 +3973,7 @@
 	case REQ_Ic:	/* mdoc(7) */
 	case REQ_Ms:	/* mdoc(7) */
 	case REQ_Or:	/* mdoc(7) */
-	case REQ_Sy:	/* mdoc(7) */
+        case REQ_Sy:    /* mdoc(7) */
             /* parse one line in bold */
 	    out_html(change_to_font('B'));
 	    trans_char(c,'"','\a');
Comment 6 Nicolas Goutte 2005-06-03 21:05:40 UTC
SVN commit 421708 by goutte:

A few cleanups:
- add a function to check if a character is a punctuation in the sence
  of mdoc(7)
- fix macro .Fd
  (No need to tweak the ; character, as some defintions are not from functions,
  see man pahe of stdin(3))
- fix macro .Fn
  (Here too no ; tweaking and also fix the font used.)
- fix the unknown mdoc macros
  (The output of the macro name was mangled.)

This makes stdin(3) quite good (except the use of the .St command, but the
list is too long and the corresponding groff file is BSD with advertissement
clause and therefore cannot be included in KDE).

CCBUG:105765
(This make mdoc.samples(7) look a little better.)

 M  +39 -29    man2html.cpp  
Comment 7 Martin Koller 2011-01-07 19:14:11 UTC
SVN commit 1212624 by mkoller:

CCBUG: 238534
CCBUG: 105765
BUG: 106067
BUG: 195241
BUG: 247012

Fix a lot of HTML-generation bugs by implementing some additional macros,
escape sequences, etc, etc.
Also start to make the code more readable and introduce more Qt/C++
while eliminating old C code, which is horrible to maintain.
The request keywords are now looked up by a gperf hash function.
The generated gperf file is committed, so that noone has to rely on the
existence of gperf on the build machine.

If I broke the rendering of some man pages, please inform me.


 M  +1 -1      CMakeLists.txt  
 M  +586 -614  man2html.cpp  
 A             request_gperf.c   [License: GENERATED FILE]
 A             request_hash.cpp   [License: UNKNOWN]
 A             request_hash.h   [License: UNKNOWN]
 A             requests.gperf  
 M  +4 -1      tests/CMakeLists.txt  


WebSVN link: http://websvn.kde.org/?view=rev&revision=1212624
Comment 8 Martin Koller 2011-01-07 22:05:37 UTC
SVN commit 1212666 by mkoller:

Backport from trunk:

CCBUG: 238534
CCBUG: 105765
CCBUG: 106067
CCBUG: 195241
CCBUG: 247012

Fix a lot of HTML-generation bugs by implementing some additional macros,
escape sequences, etc, etc.
Also start to make the code more readable and introduce more Qt/C++
while eliminating old C code, which is horrible to maintain.
The request keywords are now looked up by a gperf hash function.
The generated gperf file is committed, so that noone has to rely on the
existence of gperf on the build machine.

If I broke the rendering of some man pages, please inform me.



 M  +1 -1      CMakeLists.txt  
 M  +586 -614  man2html.cpp  
 A             request_gperf.c   [License: GENERATED FILE]
 A             request_hash.cpp   [License: LGPL (v2+)]
 A             request_hash.h   [License: LGPL (v2+)]
 A             requests.gperf  
 M  +4 -1      tests/CMakeLists.txt  


WebSVN link: http://websvn.kde.org/?view=rev&revision=1212666
Comment 9 Julian Steinmann 2018-06-24 13:37:10 UTC
mdoc.samples is no longer broken as of KDE Frameworks 5.47.0, even though there is still a lot of whitespace around... But that's not really a bug, so I'll close the report for now. If you do still experience problems with mdoc.samples, please open a new report against frameworks-kio.