| @@ -16,6 +16,8 @@ include "daytime.m"; · 15 unmodified lines |
| 16 | 16 | include "string.m"; |
| 17 | 17 | str: String; |
| 18 | 18 | |
| 19 | +include "arg.m"; |
| 20 | + |
| 19 | 21 | Man2html: module |
| 20 | 22 | { |
| 21 | 23 | init: fn(ctxt: ref Draw->Context, args: list of string); |
| @@ -315,10 +317,12 @@ Global: adt { · 293 unmodified lines |
| 315 | 317 | softp: fn(g: self ref Global): string; |
| 316 | 318 | }; |
| 317 | 319 | |
| 320 | +header := "<HTML><HEAD>"; |
| 321 | +trailer := "</BODY></HTML>"; |
| 318 | 322 | |
| 319 | 323 | usage() |
| 320 | 324 | { |
| 321 | | − sys->fprint(stderr, "Usage: man2html file [section]\n"); |
| 325 | + sys->fprint(stderr, "Usage: man2html [-h header] [-t trailer] file [section]\n"); |
| 322 | 326 | raise "fail:usage"; |
| 323 | 327 | } |
| 324 | 328 | |
| @@ -329,11 +333,20 @@ init(nil: ref Draw->Context, args: list of string) · 4 unmodified lines |
| 329 | 333 | stderr = sys->fildes(2); |
| 330 | 334 | str = load String String->PATH; |
| 331 | 335 | dt = load Daytime Daytime->PATH; |
| 332 | | − g := Global_init(); |
| 333 | | − if(args != nil) |
| 334 | | − args = tl args; |
| 336 | + arg := load Arg Arg->PATH; |
| 337 | + arg->init(args); |
| 338 | + arg->setusage("man2html [-h header] [-t trailer] file [section]"); |
| 339 | + while((o := arg->opt()) != 0) |
| 340 | + case o { |
| 341 | + 'h' => header = arg->earg(); |
| 342 | + 't' => trailer = arg->earg(); |
| 343 | + * => arg->usage(); |
| 344 | + } |
| 345 | + args = arg->argv(); |
| 335 | 346 | if(args == nil) |
| 336 | | − usage(); |
| 347 | + arg->usage(); |
| 348 | + arg = nil; |
| 349 | + g := Global_init(); |
| 337 | 350 | page := hd args; |
| 338 | 351 | args = tl args; |
| 339 | 352 | section := "1"; |
| @@ -341,6 +354,7 @@ init(nil: ref Draw->Context, args: list of string) · 1 unmodified line |
| 341 | 354 | section = hd args; |
| 342 | 355 | hit := Hit ("", "man", section, page); |
| 343 | 356 | domanpage(g, hit); |
| 357 | + g.print(trailer+"\n"); |
| 344 | 358 | g.bufio->g.bout.flush(); |
| 345 | 359 | } |
| 346 | 360 | |
| @@ -1342,7 +1356,7 @@ title(g: ref Global, t: string, search: int) · 995 unmodified lines |
| 1342 | 1356 | { |
| 1343 | 1357 | if(search) |
| 1344 | 1358 | ; # not yet used |
| 1345 | | − g.print("<HTML><HEAD>\n"); |
| 1359 | + g.print(header+"\n"); |
| 1346 | 1360 | g.print(sprint("<TITLE>Inferno's %s</TITLE>\n", demark(t))); |
| 1347 | 1361 | g.print("</HEAD>\n"); |
| 1348 | 1362 | g.print("<BODY bgcolor=\"#FFFFFF\">\n"); |