forked from KolibriOS/kolibrios
man2html(by navichok26):
- Fixed Makefile.kos; - Added auto-opening to webview. git-svn-id: svn://kolibrios.org@9280 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
parent
4003f26194
commit
d3db09558e
@ -1,15 +1,19 @@
|
|||||||
TCC = /kolibrios/develop/tcc/tcc
|
KTCC_DIR = ../../develop/ktcc/trunk
|
||||||
|
|
||||||
NAME = man2html
|
NAME = man2html
|
||||||
|
|
||||||
|
KTCC = kos32-tcc
|
||||||
|
KPACK = kpack
|
||||||
|
|
||||||
SRC = man2html.c cgibase.c abbrev.c strdefs.c
|
SRC = man2html.c cgibase.c abbrev.c strdefs.c
|
||||||
|
|
||||||
CFLAGS = -D_KOLIBRI -DNOCGI
|
CFLAGS = -D_KOLIBRI -DNOCGI -I$(KTCC_DIR)/libc.obj/include -I inc
|
||||||
|
LFLAGS = -nostdlib -L$(KTCC_DIR)/bin/lib $(KTCC_DIR)/bin/lib/crt0.o
|
||||||
LIBS = -ltcc -lc.obj
|
LIBS = -ltcc -lc.obj
|
||||||
|
|
||||||
all:
|
all:
|
||||||
$(KTCC) $(CFLAGS) $(SRC) $(LIBS) -o $(NAME)
|
$(KTCC) $(CFLAGS) $(SRC) $(LFLAGS) $(LIBS) -o $(NAME)
|
||||||
|
$(KPACK) $(NAME)
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm $(NAME)
|
rm $(NAME)
|
||||||
|
@ -13,13 +13,13 @@
|
|||||||
* The default is to use cgibase. With relative html style
|
* The default is to use cgibase. With relative html style
|
||||||
* we generate URLs of the form "../manX/page.html".
|
* we generate URLs of the form "../manX/page.html".
|
||||||
*/
|
*/
|
||||||
static int relat_html_style = 0;
|
//static int relat_html_style = 0;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The default is to use cgibase. With current html style
|
* The default is to use cgibase. With current html style
|
||||||
* we generate URLs of the form "./page.html".
|
* we generate URLs of the form "./page.html".
|
||||||
*/
|
*/
|
||||||
static int current_html_style = 0;
|
static int current_html_style = 1;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Either the user is non-local (or local, but using httpd),
|
* Either the user is non-local (or local, but using httpd),
|
||||||
@ -27,11 +27,15 @@ static int current_html_style = 0;
|
|||||||
* and uses lynx, and we use lynxcgi:/home/httpd/cgi-bin.
|
* and uses lynx, and we use lynxcgi:/home/httpd/cgi-bin.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
|
||||||
static char *man2htmlpath = "/cgi-bin/man/man2html"; /* default */
|
static char *man2htmlpath = "/cgi-bin/man/man2html"; /* default */
|
||||||
static char *cgibase_format = "http://%s"; /* host.domain:port */
|
static char *cgibase_format = "http://%s"; /* host.domain:port */
|
||||||
static char *cgibase_ll_format = "lynxcgi:%s"; /* directory */
|
static char *cgibase_ll_format = "lynxcgi:%s"; /* directory */
|
||||||
static char *cgibase = "http://localhost"; /* default */
|
static char *cgibase = "http://localhost"; /* default */
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Separator between URL and argument string.
|
* Separator between URL and argument string.
|
||||||
*
|
*
|
||||||
@ -82,6 +86,7 @@ man_page_html(char *sec, char *h) {
|
|||||||
else
|
else
|
||||||
fprintf(out, "<A HREF=\"./%s.html\">%s</A>",
|
fprintf(out, "<A HREF=\"./%s.html\">%s</A>",
|
||||||
h, h);
|
h, h);
|
||||||
|
#if 0
|
||||||
} else if (relat_html_style) {
|
} else if (relat_html_style) {
|
||||||
if (!h)
|
if (!h)
|
||||||
fprintf(out, "<A HREF=\"../index.html\">"
|
fprintf(out, "<A HREF=\"../index.html\">"
|
||||||
@ -99,9 +104,11 @@ man_page_html(char *sec, char *h) {
|
|||||||
else
|
else
|
||||||
fprintf(out, "<A HREF=\"%s%s%c%s+%s\">%s</A>",
|
fprintf(out, "<A HREF=\"%s%s%c%s+%s\">%s</A>",
|
||||||
cgibase, man2htmlpath, sep, sec, h, h);
|
cgibase, man2htmlpath, sep, sec, h, h);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
ftp_html(char *f) {
|
ftp_html(char *f) {
|
||||||
fprintf(out, "<A HREF=\"ftp://%s\">%s</A>", f, f);
|
fprintf(out, "<A HREF=\"ftp://%s\">%s</A>", f, f);
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
#include <libgen.h>
|
||||||
|
|
||||||
#ifdef _KOLIBRI
|
#ifdef _KOLIBRI
|
||||||
#include <sys/ksys.h>
|
#include <sys/ksys.h>
|
||||||
@ -46,7 +47,7 @@ static char idxlabel[6] = "ixAAA";
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
char *fname;
|
char *fname;
|
||||||
char *directory;
|
//char *directory;
|
||||||
FILE *idxfile;
|
FILE *idxfile;
|
||||||
|
|
||||||
char eqndelimopen=0, eqndelimclose=0;
|
char eqndelimopen=0, eqndelimclose=0;
|
||||||
@ -454,10 +455,10 @@ Bug 2: incorrect font: after the .IP things are roman again.
|
|||||||
#define FO3 "<TT>"
|
#define FO3 "<TT>"
|
||||||
#define FC3 "</TT>"
|
#define FC3 "</TT>"
|
||||||
|
|
||||||
char *switchfont[16] = { "" , FC0 FO1, FC0 FO2, FC0 FO3,
|
char *switchfont[16] = { "", FC0 FO1, FC0 FO2, FC0 FO3,
|
||||||
FC1 FO0, "" , FC1 FO2, FC1 FO3,
|
FC1 FO0, "", FC1 FO2, FC1 FO3,
|
||||||
FC2 FO0, FC2 FO1, "" , FC2 FO3,
|
FC2 FO0, FC2 FO1, "" , FC2 FO3,
|
||||||
FC3 FO0, FC3 FO1, FC3 FO2, "" };
|
FC3 FO0, FC3 FO1, FC3 FO2, ""};
|
||||||
|
|
||||||
static char *
|
static char *
|
||||||
change_to_font(int nr)
|
change_to_font(int nr)
|
||||||
@ -1574,7 +1575,7 @@ scan_request(char *c) {
|
|||||||
*h=0;
|
*h=0;
|
||||||
if (scaninbuff && buffpos) {
|
if (scaninbuff && buffpos) {
|
||||||
buffer[buffpos]=0;
|
buffer[buffpos]=0;
|
||||||
printf("%s\n", buffer);
|
fprintf(out, "%s\n", buffer);
|
||||||
}
|
}
|
||||||
fprintf(stderr, "%s\n", c+2); /* XXX */
|
fprintf(stderr, "%s\n", c+2); /* XXX */
|
||||||
exit(0);
|
exit(0);
|
||||||
@ -1870,9 +1871,9 @@ scan_request(char *c) {
|
|||||||
char *t,*s;
|
char *t,*s;
|
||||||
t=strrchr(fname, '/');
|
t=strrchr(fname, '/');
|
||||||
if (!t) t=fname;
|
if (!t) t=fname;
|
||||||
fprintf(stderr, "ln -s %s.html %s.html\n", h, t);
|
//fprintf(stderr, "ln -s %s.html %s.html\n", h, t);
|
||||||
s=strrchr(t, '.');if (!s) s=t;
|
s=strrchr(t, '.');if (!s) s=t;
|
||||||
printf("<HTML><HEAD><TITLE> Manpage of %s</TITLE>\n"
|
fprintf(out,"<HTML><HEAD><TITLE> Manpage of %s</TITLE>\n"
|
||||||
"</HEAD><BODY>\n"
|
"</HEAD><BODY>\n"
|
||||||
"See the manpage for <A HREF=\"%s.html\">%s</A>.\n"
|
"See the manpage for <A HREF=\"%s.html\">%s</A>.\n"
|
||||||
"</BODY></HTML>\n",
|
"</BODY></HTML>\n",
|
||||||
@ -3027,23 +3028,19 @@ static char *scan_troff_mandoc(char *c, int san, char **result) {
|
|||||||
STRDEF *foundpages=NULL;
|
STRDEF *foundpages=NULL;
|
||||||
|
|
||||||
#define BUFSMSG 1024
|
#define BUFSMSG 1024
|
||||||
#define MSGLEN 2048
|
|
||||||
static void
|
static void
|
||||||
error_page(char *s, char *t, ...) {
|
error_page(char *s, char *t, ...) {
|
||||||
va_list p;
|
va_list p;
|
||||||
char msg[MSGLEN];
|
|
||||||
char buf[BUFSMSG];
|
char buf[BUFSMSG];
|
||||||
|
char notify_buf[BUFSMSG+5];
|
||||||
sprintf(msg, "'%s\n", s, s);
|
|
||||||
va_start(p, t);
|
va_start(p, t);
|
||||||
vsprintf(buf, t, p);
|
vsnprintf(buf, BUFSMSG, t, p);
|
||||||
va_end(p);
|
va_end(p);
|
||||||
#ifdef _KOLIBRI
|
#ifdef _KOLIBRI
|
||||||
sprintf(msg, "%s%s%s", msg, buf, "' -E");
|
snprintf(notify_buf, BUFSMSG+5, "'%s' -E", buf);
|
||||||
_ksys_exec("/sys/@notify", buf);
|
_ksys_exec("/sys/@notify", buf);
|
||||||
#else
|
#else
|
||||||
sprintf(msg, "%s%s%s", msg, buf, "'");
|
printf("%s %s\n", s, buf);
|
||||||
printf("%s", msg);
|
|
||||||
#endif
|
#endif
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
@ -3077,10 +3074,15 @@ xrealloc(void *ptr, size_t size) {
|
|||||||
|
|
||||||
static void
|
static void
|
||||||
usage(void) {
|
usage(void) {
|
||||||
error_page("man2html: bad invocation",
|
#ifdef _KOLIBRI
|
||||||
"Usage: man2html in_file [out_file.html]\n");
|
_ksys_exec("/sys/@notify", "'Usage: man2html in_file [out_file.html]' -I");
|
||||||
|
#else
|
||||||
|
puts("Usage: man2html in_file [out_file.html]");
|
||||||
|
#endif
|
||||||
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
static void
|
static void
|
||||||
goto_dir(char *path, char **dir, char **name) {
|
goto_dir(char *path, char **dir, char **name) {
|
||||||
char *s, *t, *u;
|
char *s, *t, *u;
|
||||||
@ -3109,15 +3111,27 @@ goto_dir(char *path, char **dir, char **name) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
char
|
||||||
|
*temp_file_name(char* in_path){
|
||||||
|
char* in_name = basename(in_path);
|
||||||
|
#define PST_SIZE 5
|
||||||
|
const char* pst = ".html";
|
||||||
|
#ifdef _KOLIBRI
|
||||||
|
#define TMP_PATH_SIZE 9
|
||||||
|
const char* tmp_path = "/tmp0/1/";
|
||||||
|
#else
|
||||||
|
#define TMP_PATH_SIZE 2
|
||||||
|
const char* tmp_path = "./";
|
||||||
|
#endif
|
||||||
|
char* full_name = xmalloc((TMP_PATH_SIZE+strlen(in_name)+PST_SIZE+1)*sizeof(char));
|
||||||
|
strcpy(full_name, tmp_path);
|
||||||
|
strcat(full_name, in_name);
|
||||||
|
strcat(full_name, pst);
|
||||||
|
return full_name;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Call: man2html [-l] [filename]
|
|
||||||
*
|
|
||||||
* The contents of FILENAME (or STDIN, in case FILENAME is "-" or absent)
|
|
||||||
* are converted from man-style nroff to html, and printed on STDOUT.
|
|
||||||
*
|
|
||||||
* Possible errors are reflected in the output. The return status is 0.
|
|
||||||
*/
|
|
||||||
int
|
int
|
||||||
main(int argc, char **argv) {
|
main(int argc, char **argv) {
|
||||||
FILE *f;
|
FILE *f;
|
||||||
@ -3125,34 +3139,29 @@ main(int argc, char **argv) {
|
|||||||
char *buf, *filename, *fnam = NULL;
|
char *buf, *filename, *fnam = NULL;
|
||||||
char *outfilename;
|
char *outfilename;
|
||||||
|
|
||||||
#ifdef _KOLIBRI
|
if (argc < 2){
|
||||||
outfilename = "/tmp0/1/out.html";
|
|
||||||
#else
|
|
||||||
outfilename = "./out.html";
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// printf("Content-type: text/html\n\n");
|
|
||||||
|
|
||||||
|
|
||||||
/* Find filename */
|
|
||||||
if (argc > 2) {
|
|
||||||
outfilename = argv[2];
|
|
||||||
} if (argc > 1) {
|
|
||||||
fnam = argv[1];
|
|
||||||
} else {
|
|
||||||
usage();
|
usage();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Find filename */
|
||||||
|
if (argc > 1) {
|
||||||
|
fnam = argv[1];
|
||||||
|
outfilename = temp_file_name(fnam);
|
||||||
|
}
|
||||||
|
if (argc > 2) {
|
||||||
|
outfilename = argv[2];
|
||||||
|
}
|
||||||
|
|
||||||
if ((out = fopen(outfilename, "w")) == NULL) {
|
if ((out = fopen(outfilename, "w")) == NULL) {
|
||||||
printf("Cannot open file %s", outfilename);
|
error_page("Error!", "Cannot open file %s", outfilename);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
filename = fnam;
|
filename = fnam;
|
||||||
directory = 0;
|
//directory = 0;
|
||||||
|
|
||||||
/* Open input file */
|
/* Open input file */
|
||||||
goto_dir(fnam, &directory, &fnam);
|
//goto_dir(fnam, &directory, &fnam);
|
||||||
|
|
||||||
f = fopen(fnam, "r");
|
f = fopen(fnam, "r");
|
||||||
if (f == NULL)
|
if (f == NULL)
|
||||||
@ -3203,7 +3212,7 @@ main(int argc, char **argv) {
|
|||||||
fprintf(out, "<HR>\n<A NAME=\"index\"> </A><H2>Index</H2>\n<DL>\n");
|
fprintf(out, "<HR>\n<A NAME=\"index\"> </A><H2>Index</H2>\n<DL>\n");
|
||||||
manidx[mip]=0;
|
manidx[mip]=0;
|
||||||
fprintf(out, "%s", manidx);
|
fprintf(out, "%s", manidx);
|
||||||
if (subs) printf("</DL>\n");
|
if (subs) fprintf(out,"</DL>\n");
|
||||||
fprintf(out, "</DL>\n");
|
fprintf(out, "</DL>\n");
|
||||||
print_sig();
|
print_sig();
|
||||||
fprintf(out, "</BODY>\n</HTML>\n");
|
fprintf(out, "</BODY>\n</HTML>\n");
|
||||||
@ -3226,5 +3235,10 @@ main(int argc, char **argv) {
|
|||||||
fclose(idxfile);
|
fclose(idxfile);
|
||||||
if (buf)
|
if (buf)
|
||||||
free(buf);
|
free(buf);
|
||||||
|
#ifdef _KOLIBRI
|
||||||
|
if(argc==2){
|
||||||
|
_ksys_exec("/sys/network/webview", outfilename);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user