Subversion Repositories Kolibri OS

Rev

Go to most recent revision | 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 = 0;
  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. static char *man2htmlpath = "/cgi-bin/man/man2html";    /* default */
  31. static char *cgibase_format = "http://%s";              /* host.domain:port */
  32. static char *cgibase_ll_format = "lynxcgi:%s";          /* directory */
  33. static char *cgibase = "http://localhost";              /* default */
  34.  
  35. /*
  36.  * Separator between URL and argument string.
  37.  *
  38.  * With http:<path to script>/a/b?c+d+e the script is called
  39.  * with PATH_INFO=/a/b and QUERY_STRING=c+d+e and args $1=c, $2=d, $3=e.
  40.  * With lynxcgi:<full path to script>?c+d+e no PATH_INFO is possible.
  41.  */
  42. static char sep = '?';                                  /* or '/' */
  43.  
  44. /* What shall we say in case of relat_html_style? */
  45. static char *signature = "<HR>\n"
  46. "This document was created by\n"
  47. "<A HREF=\"http://github.com/hamano/man2html/\">man2html</A>,\n"
  48. "using the manual pages.<BR>\n"
  49. "%s\n";
  50.  
  51. #define TIMEFORMAT "%T GMT, %B %d, %Y"
  52. #define TIMEBUFSZ       500
  53.  
  54. void print_sig()
  55. {
  56.     char timebuf[TIMEBUFSZ];
  57.     struct tm *timetm;
  58.     time_t clock;
  59.  
  60.     timebuf[0] = 0;
  61. #ifdef TIMEFORMAT
  62.     sprintf(timebuf, "Time: ");
  63.     clock=time(NULL);
  64.     timetm=localtime(&clock);
  65.     snprintf(timebuf, TIMEBUFSZ, "%s%s", timebuf, asctime(timetm));
  66.     timebuf[TIMEBUFSZ-1] = 0;
  67. #endif
  68.     fprintf(out, signature, timebuf);
  69. }
  70.  
  71. void
  72. include_file_html(char *g) {
  73.      fprintf(out, "<A HREF=\"file:/usr/include/%s\">%s</A>&gt;", g,g);
  74. }
  75.  
  76. void
  77. man_page_html(char *sec, char *h) {
  78.         if (current_html_style) {
  79.                 if (!h)
  80.                         fprintf(out, "<A HREF=\"./\">"
  81.                                "Return to Main Contents</A>");
  82.                 else
  83.                         fprintf(out, "<A HREF=\"./%s.html\">%s</A>",
  84.                                h, h);
  85.         } else if (relat_html_style) {
  86.                 if (!h)
  87.                         fprintf(out, "<A HREF=\"../index.html\">"
  88.                                "Return to Main Contents</A>");
  89.                 else
  90.                         fprintf(out, "<A HREF=\"../man%s/%s.%s.html\">%s</A>",
  91.                                sec, h, sec, h);
  92.         } else {
  93.                 if (!h)
  94.                         fprintf(out, "<A HREF=\"%s%s\">Return to Main Contents</A>",
  95.                                cgibase, man2htmlpath);
  96.                 else if (!sec)
  97.                         fprintf(out, "<A HREF=\"%s%s%c%s\">%s</A>",
  98.                                cgibase, man2htmlpath, sep, h, h);
  99.                 else
  100.                         fprintf(out, "<A HREF=\"%s%s%c%s+%s\">%s</A>",
  101.                                cgibase, man2htmlpath, sep, sec, h, h);
  102.         }
  103. }
  104.  
  105. void
  106. ftp_html(char *f) {
  107.      fprintf(out, "<A HREF=\"ftp://%s\">%s</A>", f, f);
  108. }
  109.  
  110. void
  111. www_html(char *f) {
  112.      fprintf(out, "<A HREF=\"http://%s\">%s</A>", f, f);
  113. }
  114.  
  115. void
  116. mailto_html(char *g) {
  117.      fprintf(out, "<A HREF=\"mailto:%s\">%s</A>", g, g);
  118. }
  119.  
  120. void
  121. url_html(char *g) {
  122.      fprintf(out, "<A HREF=\"%s\">%s</A>", g, g);
  123. }
  124.