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 |
#endif |
|
char *fname; |
char *directory; |
//char *directory; |
FILE *idxfile; |
|
char eqndelimopen=0, eqndelimclose=0; |
1574,7 → 1575,7 |
*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 |
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 |
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 |
|
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 |
} |
} |
} |
#endif |
|
/* |
* 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. |
*/ |
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; |
} |
|
int |
main(int argc, char **argv) { |
FILE *f; |
3125,34 → 3139,29 |
char *buf, *filename, *fnam = NULL; |
char *outfilename; |
|
#ifdef _KOLIBRI |
outfilename = "/tmp0/1/out.html"; |
#else |
outfilename = "./out.html"; |
#endif |
if (argc < 2){ |
usage(); |
} |
|
// printf("Content-type: text/html\n\n"); |
|
|
/* Find filename */ |
if (argc > 1) { |
fnam = argv[1]; |
outfilename = temp_file_name(fnam); |
} |
if (argc > 2) { |
outfilename = argv[2]; |
} if (argc > 1) { |
fnam = argv[1]; |
} else { |
usage(); |
} |
|
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 |
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 |
fclose(idxfile); |
if (buf) |
free(buf); |
#ifdef _KOLIBRI |
if(argc==2){ |
_ksys_exec("/sys/network/webview", outfilename); |
} |
#endif |
return 0; |
} |