Subversion Repositories Kolibri OS

Rev

Rev 9278 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. /*
  2.  * Here are the routines of man2html that output a HREF string.
  3.  */
  4.  
  5. #include <stdlib.h>
  6. #include <stdio.h>
  7. #include <time.h>
  8. #include <ctype.h>              /* tolower() */
  9. #include <string.h>             /* strlen() */
  10. #include "defs.h"
  11.  
  12. /*
  13.  * The default is to use cgibase. With relative html style
  14.  * we generate URLs of the form "../manX/page.html".
  15.  */
  16. //static int relat_html_style = 0;
  17.  
  18. /*
  19.  * The default is to use cgibase. With current html style
  20.  * we generate URLs of the form "./page.html".
  21.  */
  22. static int current_html_style = 1;
  23.  
  24. /*
  25.  * Either the user is non-local (or local, but using httpd),
  26.  * in which case we use http:/cgi-bin, or the user is local
  27.  * and uses lynx, and we use lynxcgi:/home/httpd/cgi-bin.
  28.  */
  29.  
  30. #if 0
  31.  
  32. static char *man2htmlpath = "/cgi-bin/man/man2html";    /* default */
  33. static char *cgibase_format = "http://%s";              /* host.domain:port */
  34. static char *cgibase_ll_format = "lynxcgi:%s";          /* directory */
  35. static char *cgibase = "http://localhost";              /* default */
  36.  
  37. #endif
  38.  
  39. /*
  40.  * Separator between URL and argument string.
  41.  *
  42.  * With http:<path to script>/a/b?c+d+e the script is called
  43.  * with PATH_INFO=/a/b and QUERY_STRING=c+d+e and args $1=c, $2=d, $3=e.
  44.  * With lynxcgi:<full path to script>?c+d+e no PATH_INFO is possible.
  45.  */
  46. static char sep = '?';                                  /* or '/' */
  47.  
  48. /* What shall we say in case of relat_html_style? */
  49. static char *signature = "<HR>\n"
  50. "This document was created by\n"
  51. "<A HREF=\"http://github.com/hamano/man2html/\">man2html</A>,\n"
  52. "using the manual pages.<BR>\n"
  53. "%s\n";
  54.  
  55. #define TIMEFORMAT "%T GMT, %B %d, %Y"
  56. #define TIMEBUFSZ       500
  57.  
  58. void print_sig()
  59. {
  60.     char timebuf[TIMEBUFSZ];
  61.     struct tm *timetm;
  62.     time_t clock;
  63.  
  64.     timebuf[0] = 0;
  65. #ifdef TIMEFORMAT
  66.     sprintf(timebuf, "Time: ");
  67.     clock=time(NULL);
  68.     timetm=localtime(&clock);
  69.     snprintf(timebuf, TIMEBUFSZ, "%s%s", timebuf, asctime(timetm));
  70.     timebuf[TIMEBUFSZ-1] = 0;
  71. #endif
  72.     fprintf(out, signature, timebuf);
  73. }
  74.  
  75. void
  76. include_file_html(char *g) {
  77.      fprintf(out, "<A HREF=\"file:/usr/include/%s\">%s</A>&gt;", g,g);
  78. }
  79.  
  80. void
  81. man_page_html(char *sec, char *h) {
  82.         if (current_html_style) {
  83.                 if (!h)
  84.                         fprintf(out, "<A HREF=\"./\">"
  85.                                "Return to Main Contents</A>");
  86.                 else
  87.                         fprintf(out, "<A HREF=\"./%s.html\">%s</A>",
  88.                                h, h);
  89. #if 0
  90.         } else if (relat_html_style) {
  91.                 if (!h)
  92.                         fprintf(out, "<A HREF=\"../index.html\">"
  93.                                "Return to Main Contents</A>");
  94.                 else
  95.                         fprintf(out, "<A HREF=\"../man%s/%s.%s.html\">%s</A>",
  96.                                sec, h, sec, h);
  97.         } else {
  98.                 if (!h)
  99.                         fprintf(out, "<A HREF=\"%s%s\">Return to Main Contents</A>",
  100.                                cgibase, man2htmlpath);
  101.                 else if (!sec)
  102.                         fprintf(out, "<A HREF=\"%s%s%c%s\">%s</A>",
  103.                                cgibase, man2htmlpath, sep, h, h);
  104.                 else
  105.                         fprintf(out, "<A HREF=\"%s%s%c%s+%s\">%s</A>",
  106.                                cgibase, man2htmlpath, sep, sec, h, h);
  107. #endif
  108.         }
  109. }
  110.  
  111.  
  112. void
  113. ftp_html(char *f) {
  114.      fprintf(out, "<A HREF=\"ftp://%s\">%s</A>", f, f);
  115. }
  116.  
  117. void
  118. www_html(char *f) {
  119.      fprintf(out, "<A HREF=\"http://%s\">%s</A>", f, f);
  120. }
  121.  
  122. void
  123. mailto_html(char *g) {
  124.      fprintf(out, "<A HREF=\"mailto:%s\">%s</A>", g, g);
  125. }
  126.  
  127. void
  128. url_html(char *g) {
  129.      fprintf(out, "<A HREF=\"%s\">%s</A>", g, g);
  130. }
  131.