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
|
||||
|
||||
KTCC = kos32-tcc
|
||||
KPACK = kpack
|
||||
|
||||
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
|
||||
|
||||
all:
|
||||
$(KTCC) $(CFLAGS) $(SRC) $(LIBS) -o $(NAME)
|
||||
|
||||
$(KTCC) $(CFLAGS) $(SRC) $(LFLAGS) $(LIBS) -o $(NAME)
|
||||
$(KPACK) $(NAME)
|
||||
|
||||
clean:
|
||||
rm $(NAME)
|
||||
|
@ -13,13 +13,13 @@
|
||||
* The default is to use cgibase. With relative html style
|
||||
* 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
|
||||
* 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),
|
||||
@ -27,11 +27,15 @@ static int current_html_style = 0;
|
||||
* and uses lynx, and we use lynxcgi:/home/httpd/cgi-bin.
|
||||
*/
|
||||
|
||||
#if 0
|
||||
|
||||
static char *man2htmlpath = "/cgi-bin/man/man2html"; /* default */
|
||||
static char *cgibase_format = "http://%s"; /* host.domain:port */
|
||||
static char *cgibase_ll_format = "lynxcgi:%s"; /* directory */
|
||||
static char *cgibase = "http://localhost"; /* default */
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Separator between URL and argument string.
|
||||
*
|
||||
@ -82,6 +86,7 @@ man_page_html(char *sec, char *h) {
|
||||
else
|
||||
fprintf(out, "<A HREF=\"./%s.html\">%s</A>",
|
||||
h, h);
|
||||
#if 0
|
||||
} else if (relat_html_style) {
|
||||
if (!h)
|
||||
fprintf(out, "<A HREF=\"../index.html\">"
|
||||
@ -99,9 +104,11 @@ man_page_html(char *sec, char *h) {
|
||||
else
|
||||
fprintf(out, "<A HREF=\"%s%s%c%s+%s\">%s</A>",
|
||||
cgibase, man2htmlpath, sep, sec, h, h);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ftp_html(char *f) {
|
||||
fprintf(out, "<A HREF=\"ftp://%s\">%s</A>", f, f);
|
||||
|
@ -18,6 +18,7 @@
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <libgen.h>
|
||||
|
||||
#ifdef _KOLIBRI
|
||||
#include <sys/ksys.h>
|
||||
@ -46,7 +47,7 @@ static char idxlabel[6] = "ixAAA";
|
||||
#endif
|
||||
|
||||
char *fname;
|
||||
char *directory;
|
||||
//char *directory;
|
||||
FILE *idxfile;
|
||||
|
||||
char eqndelimopen=0, eqndelimclose=0;
|
||||
@ -454,10 +455,10 @@ Bug 2: incorrect font: after the .IP things are roman again.
|
||||
#define FO3 "<TT>"
|
||||
#define FC3 "</TT>"
|
||||
|
||||
char *switchfont[16] = { "" , FC0 FO1, FC0 FO2, FC0 FO3,
|
||||
FC1 FO0, "" , FC1 FO2, FC1 FO3,
|
||||
char *switchfont[16] = { "", FC0 FO1, FC0 FO2, FC0 FO3,
|
||||
FC1 FO0, "", FC1 FO2, FC1 FO3,
|
||||
FC2 FO0, FC2 FO1, "" , FC2 FO3,
|
||||
FC3 FO0, FC3 FO1, FC3 FO2, "" };
|
||||
FC3 FO0, FC3 FO1, FC3 FO2, ""};
|
||||
|
||||
static char *
|
||||
change_to_font(int nr)
|
||||
@ -1574,7 +1575,7 @@ scan_request(char *c) {
|
||||
*h=0;
|
||||
if (scaninbuff && buffpos) {
|
||||
buffer[buffpos]=0;
|
||||
printf("%s\n", buffer);
|
||||
fprintf(out, "%s\n", buffer);
|
||||
}
|
||||
fprintf(stderr, "%s\n", c+2); /* XXX */
|
||||
exit(0);
|
||||
@ -1870,9 +1871,9 @@ scan_request(char *c) {
|
||||
char *t,*s;
|
||||
t=strrchr(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;
|
||||
printf("<HTML><HEAD><TITLE> Manpage of %s</TITLE>\n"
|
||||
fprintf(out,"<HTML><HEAD><TITLE> Manpage of %s</TITLE>\n"
|
||||
"</HEAD><BODY>\n"
|
||||
"See the manpage for <A HREF=\"%s.html\">%s</A>.\n"
|
||||
"</BODY></HTML>\n",
|
||||
@ -3027,23 +3028,19 @@ static char *scan_troff_mandoc(char *c, int san, char **result) {
|
||||
STRDEF *foundpages=NULL;
|
||||
|
||||
#define BUFSMSG 1024
|
||||
#define MSGLEN 2048
|
||||
static void
|
||||
error_page(char *s, char *t, ...) {
|
||||
va_list p;
|
||||
char msg[MSGLEN];
|
||||
char buf[BUFSMSG];
|
||||
|
||||
sprintf(msg, "'%s\n", s, s);
|
||||
char notify_buf[BUFSMSG+5];
|
||||
va_start(p, t);
|
||||
vsprintf(buf, t, p);
|
||||
vsnprintf(buf, BUFSMSG, t, p);
|
||||
va_end(p);
|
||||
#ifdef _KOLIBRI
|
||||
sprintf(msg, "%s%s%s", msg, buf, "' -E");
|
||||
snprintf(notify_buf, BUFSMSG+5, "'%s' -E", buf);
|
||||
_ksys_exec("/sys/@notify", buf);
|
||||
#else
|
||||
sprintf(msg, "%s%s%s", msg, buf, "'");
|
||||
printf("%s", msg);
|
||||
printf("%s %s\n", s, buf);
|
||||
#endif
|
||||
exit(0);
|
||||
}
|
||||
@ -3077,10 +3074,15 @@ xrealloc(void *ptr, size_t size) {
|
||||
|
||||
static void
|
||||
usage(void) {
|
||||
error_page("man2html: bad invocation",
|
||||
"Usage: man2html in_file [out_file.html]\n");
|
||||
#ifdef _KOLIBRI
|
||||
_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
|
||||
goto_dir(char *path, char **dir, char **name) {
|
||||
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
|
||||
main(int argc, char **argv) {
|
||||
FILE *f;
|
||||
@ -3125,34 +3139,29 @@ main(int argc, char **argv) {
|
||||
char *buf, *filename, *fnam = NULL;
|
||||
char *outfilename;
|
||||
|
||||
#ifdef _KOLIBRI
|
||||
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 {
|
||||
if (argc < 2){
|
||||
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) {
|
||||
printf("Cannot open file %s", outfilename);
|
||||
error_page("Error!", "Cannot open file %s", outfilename);
|
||||
return 0;
|
||||
}
|
||||
|
||||
filename = fnam;
|
||||
directory = 0;
|
||||
//directory = 0;
|
||||
|
||||
/* Open input file */
|
||||
goto_dir(fnam, &directory, &fnam);
|
||||
//goto_dir(fnam, &directory, &fnam);
|
||||
|
||||
f = fopen(fnam, "r");
|
||||
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");
|
||||
manidx[mip]=0;
|
||||
fprintf(out, "%s", manidx);
|
||||
if (subs) printf("</DL>\n");
|
||||
if (subs) fprintf(out,"</DL>\n");
|
||||
fprintf(out, "</DL>\n");
|
||||
print_sig();
|
||||
fprintf(out, "</BODY>\n</HTML>\n");
|
||||
@ -3226,5 +3235,10 @@ main(int argc, char **argv) {
|
||||
fclose(idxfile);
|
||||
if (buf)
|
||||
free(buf);
|
||||
#ifdef _KOLIBRI
|
||||
if(argc==2){
|
||||
_ksys_exec("/sys/network/webview", outfilename);
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user