Rev 9278 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 9278 | Rev 9280 | ||
---|---|---|---|
Line 16... | Line 16... | ||
16 | 16 | ||
17 | #include |
17 | #include |
18 | #include |
18 | #include |
19 | #include |
19 | #include |
- | 20 | #include |
|
Line 20... | Line 21... | ||
20 | #include |
21 | #include |
21 | 22 | ||
22 | #ifdef _KOLIBRI |
23 | #ifdef _KOLIBRI |
23 | #include |
24 | #include |
Line 44... | Line 45... | ||
44 | #else |
45 | #else |
45 | #define INDEXFILE "./manindex.list" |
46 | #define INDEXFILE "./manindex.list" |
46 | #endif |
47 | #endif |
Line 47... | Line 48... | ||
47 | 48 | ||
48 | char *fname; |
49 | char *fname; |
49 | char *directory; |
50 | //char *directory; |
Line 50... | Line 51... | ||
50 | FILE *idxfile; |
51 | FILE *idxfile; |
51 | 52 | ||
Line 1572... | Line 1573... | ||
1572 | h=c+j; |
1573 | h=c+j; |
1573 | while (*h && *h !='\n') h++; |
1574 | while (*h && *h !='\n') h++; |
1574 | *h=0; |
1575 | *h=0; |
1575 | if (scaninbuff && buffpos) { |
1576 | if (scaninbuff && buffpos) { |
1576 | buffer[buffpos]=0; |
1577 | buffer[buffpos]=0; |
1577 | printf("%s\n", buffer); |
1578 | fprintf(out, "%s\n", buffer); |
1578 | } |
1579 | } |
1579 | fprintf(stderr, "%s\n", c+2); /* XXX */ |
1580 | fprintf(stderr, "%s\n", c+2); /* XXX */ |
1580 | exit(0); |
1581 | exit(0); |
1581 | break; |
1582 | break; |
1582 | case V('d','i'): |
1583 | case V('d','i'): |
Line 1868... | Line 1869... | ||
1868 | #if NOCGI |
1869 | #if NOCGI |
1869 | if (!out_length) { |
1870 | if (!out_length) { |
1870 | char *t,*s; |
1871 | char *t,*s; |
1871 | t=strrchr(fname, '/'); |
1872 | t=strrchr(fname, '/'); |
1872 | if (!t) t=fname; |
1873 | if (!t) t=fname; |
1873 | fprintf(stderr, "ln -s %s.html %s.html\n", h, t); |
1874 | //fprintf(stderr, "ln -s %s.html %s.html\n", h, t); |
1874 | s=strrchr(t, '.');if (!s) s=t; |
1875 | s=strrchr(t, '.');if (!s) s=t; |
1875 | printf(" |
1876 | fprintf(out," |
1876 | "\n" |
1877 | "\n" |
1877 | "See the manpage for %s.\n" |
1878 | "See the manpage for %s.\n" |
1878 | "\n", |
1879 | "\n", |
1879 | s, h, h); |
1880 | s, h, h); |
1880 | } else |
1881 | } else |
Line 3025... | Line 3026... | ||
3025 | } |
3026 | } |
Line 3026... | Line 3027... | ||
3026 | 3027 | ||
Line 3027... | Line 3028... | ||
3027 | STRDEF *foundpages=NULL; |
3028 | STRDEF *foundpages=NULL; |
3028 | - | ||
3029 | #define BUFSMSG 1024 |
3029 | |
3030 | #define MSGLEN 2048 |
3030 | #define BUFSMSG 1024 |
3031 | static void |
3031 | static void |
3032 | error_page(char *s, char *t, ...) { |
- | |
3033 | va_list p; |
3032 | error_page(char *s, char *t, ...) { |
3034 | char msg[MSGLEN]; |
- | |
3035 | char buf[BUFSMSG]; |
3033 | va_list p; |
3036 | 3034 | char buf[BUFSMSG]; |
|
3037 | sprintf(msg, "'%s\n", s, s); |
3035 | char notify_buf[BUFSMSG+5]; |
3038 | va_start(p, t); |
3036 | va_start(p, t); |
3039 | vsprintf(buf, t, p); |
3037 | vsnprintf(buf, BUFSMSG, t, p); |
3040 | va_end(p); |
3038 | va_end(p); |
3041 | #ifdef _KOLIBRI |
3039 | #ifdef _KOLIBRI |
3042 | sprintf(msg, "%s%s%s", msg, buf, "' -E"); |
3040 | snprintf(notify_buf, BUFSMSG+5, "'%s' -E", buf); |
3043 | _ksys_exec("/sys/@notify", buf); |
3041 | _ksys_exec("/sys/@notify", buf); |
3044 | #else |
- | |
3045 | sprintf(msg, "%s%s%s", msg, buf, "'"); |
3042 | #else |
3046 | printf("%s", msg); |
3043 | printf("%s %s\n", s, buf); |
3047 | #endif |
3044 | #endif |
Line 3048... | Line 3045... | ||
3048 | exit(0); |
3045 | exit(0); |
Line 3075... | Line 3072... | ||
3075 | return p; |
3072 | return p; |
3076 | } |
3073 | } |
Line 3077... | Line 3074... | ||
3077 | 3074 | ||
3078 | static void |
3075 | static void |
- | 3076 | usage(void) { |
|
3079 | usage(void) { |
3077 | #ifdef _KOLIBRI |
- | 3078 | _ksys_exec("/sys/@notify", "'Usage: man2html in_file [out_file.html]' -I"); |
|
3080 | error_page("man2html: bad invocation", |
3079 | #else |
- | 3080 | puts("Usage: man2html in_file [out_file.html]"); |
|
- | 3081 | #endif |
|
3081 | "Usage: man2html in_file [out_file.html]\n"); |
3082 | exit(0); |
Line -... | Line 3083... | ||
- | 3083 | } |
|
3082 | } |
3084 | |
3083 | 3085 | #if 0 |
|
3084 | static void |
3086 | static void |
Line 3085... | Line 3087... | ||
3085 | goto_dir(char *path, char **dir, char **name) { |
3087 | goto_dir(char *path, char **dir, char **name) { |
Line 3107... | Line 3109... | ||
3107 | error_page("Error", "man2html: could not chdir to %s", s); |
3109 | error_page("Error", "man2html: could not chdir to %s", s); |
3108 | #endif |
3110 | #endif |
3109 | } |
3111 | } |
3110 | } |
3112 | } |
3111 | } |
3113 | } |
- | 3114 | #endif |
|
- | 3115 | ||
- | 3116 | char |
|
- | 3117 | *temp_file_name(char* in_path){ |
|
- | 3118 | char* in_name = basename(in_path); |
|
- | 3119 | #define PST_SIZE 5 |
|
- | 3120 | const char* pst = ".html"; |
|
- | 3121 | #ifdef _KOLIBRI |
|
- | 3122 | #define TMP_PATH_SIZE 9 |
|
- | 3123 | const char* tmp_path = "/tmp0/1/"; |
|
- | 3124 | #else |
|
- | 3125 | #define TMP_PATH_SIZE 2 |
|
- | 3126 | const char* tmp_path = "./"; |
|
- | 3127 | #endif |
|
- | 3128 | char* full_name = xmalloc((TMP_PATH_SIZE+strlen(in_name)+PST_SIZE+1)*sizeof(char)); |
|
- | 3129 | strcpy(full_name, tmp_path); |
|
- | 3130 | strcat(full_name, in_name); |
|
- | 3131 | strcat(full_name, pst); |
|
- | 3132 | return full_name; |
|
- | 3133 | } |
|
Line 3112... | Line -... | ||
3112 | - | ||
3113 | /* |
- | |
3114 | * Call: man2html [-l] [filename] |
- | |
3115 | * |
- | |
3116 | * The contents of FILENAME (or STDIN, in case FILENAME is "-" or absent) |
- | |
3117 | * are converted from man-style nroff to html, and printed on STDOUT. |
- | |
3118 | * |
- | |
3119 | * Possible errors are reflected in the output. The return status is 0. |
- | |
3120 | */ |
3134 | |
3121 | int |
3135 | int |
3122 | main(int argc, char **argv) { |
3136 | main(int argc, char **argv) { |
3123 | FILE *f; |
3137 | FILE *f; |
3124 | int l, c; |
3138 | int l, c; |
3125 | char *buf, *filename, *fnam = NULL; |
3139 | char *buf, *filename, *fnam = NULL; |
Line 3126... | Line 3140... | ||
3126 | char *outfilename; |
3140 | char *outfilename; |
3127 | - | ||
3128 | #ifdef _KOLIBRI |
- | |
3129 | outfilename = "/tmp0/1/out.html"; |
3141 | |
3130 | #else |
3142 | if (argc < 2){ |
3131 | outfilename = "./out.html"; |
- | |
3132 | #endif |
- | |
3133 | - | ||
Line 3134... | Line 3143... | ||
3134 | // printf("Content-type: text/html\n\n"); |
3143 | usage(); |
- | 3144 | } |
|
- | 3145 | ||
- | 3146 | /* Find filename */ |
|
- | 3147 | if (argc > 1) { |
|
3135 | 3148 | fnam = argv[1]; |
|
3136 | 3149 | outfilename = temp_file_name(fnam); |
|
3137 | /* Find filename */ |
- | |
3138 | if (argc > 2) { |
- | |
3139 | outfilename = argv[2]; |
- | |
3140 | } if (argc > 1) { |
- | |
3141 | fnam = argv[1]; |
3150 | } |
Line 3142... | Line 3151... | ||
3142 | } else { |
3151 | if (argc > 2) { |
3143 | usage(); |
3152 | outfilename = argv[2]; |
3144 | } |
3153 | } |
3145 | 3154 | ||
Line 3146... | Line 3155... | ||
3146 | if ((out = fopen(outfilename, "w")) == NULL) { |
3155 | if ((out = fopen(outfilename, "w")) == NULL) { |
3147 | printf("Cannot open file %s", outfilename); |
3156 | error_page("Error!", "Cannot open file %s", outfilename); |
Line 3148... | Line 3157... | ||
3148 | return 0; |
3157 | return 0; |
3149 | } |
3158 | } |
Line 3150... | Line 3159... | ||
3150 | 3159 | ||
3151 | filename = fnam; |
3160 | filename = fnam; |
3152 | directory = 0; |
3161 | //directory = 0; |
3153 | 3162 | ||
Line 3201... | Line 3210... | ||
3201 | if (output_possible) { |
3210 | if (output_possible) { |
3202 | /* for mosaic users */ |
3211 | /* for mosaic users */ |
3203 | fprintf(out, "
|
3212 | fprintf(out, "
|
3204 | manidx[mip]=0; |
3213 | manidx[mip]=0; |
3205 | fprintf(out, "%s", manidx); |
3214 | fprintf(out, "%s", manidx); |
3206 | if (subs) printf("\n"); |
3215 | if (subs) fprintf(out,"\n"); |
3207 | fprintf(out, "\n"); |
3216 | fprintf(out, "\n"); |
3208 | print_sig(); |
3217 | print_sig(); |
3209 | fprintf(out, " |
\n