blob: f85bbb484b73d6e44c2affaa1c0dfb63ce7c1ff4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
#include <u.h>
#include <libc.h>
#include <bio.h>
#include <draw.h>
#include <html.h>
#include "dat.h"
char *url = "";
int aflag;
int width = 70;
int defcharset;
void
usage(void)
{
fprint(2, "usage: htmlfmt [-c charset] [-u URL] [-a] [-l length] [file ...]\n");
exits("usage");
}
void
main(int argc, char *argv[])
{
int i, fd;
char *p, *err, *file;
char errbuf[ERRMAX];
ARGBEGIN{
case 'a':
aflag++;
break;
case 'c':
p = smprint("<meta charset=\"%s\">", EARGF(usage()));
defcharset = charset(p);
free(p);
break;
case 'l': case 'w':
err = EARGF(usage());
width = atoi(err);
if(width <= 0)
usage();
break;
case 'u':
url = EARGF(usage());
aflag++;
break;
default:
usage();
}ARGEND
err = nil;
file = "<stdin>";
if(argc == 0)
err = loadhtml(0);
else
for(i=0; err==nil && i<argc; i++){
file = argv[i];
fd = open(file, OREAD);
if(fd < 0){
errstr(errbuf, sizeof errbuf);
err = errbuf;
break;
}
err = loadhtml(fd);
close(fd);
if(err)
break;
}
if(err)
fprint(2, "htmlfmt: processing %s: %s\n", file, err);
exits(err);
}
|