14
static volatile int timed_out = 0;
18
struct dl_node node[1];
19
char *name; // file name
20
char *pgno_str; // the pgno as given on the cmdline
21
int pgno, subno; // decoded pgno
22
struct export *export; // export data
23
struct vt_page vtp[1]; // the capture page data
29
usage(FILE *fp, int exitval)
31
fprintf(fp, "\nUsage: %s [options] ppp[.ss]...\n", prgname);
34
" Valid options:\t\tDefault:\n"
37
" -vbi <vbidev>\t\t/dev/vbi\n"
38
" -finetune <-4..4|auto>\t0\n"
39
//" -oldbttv\t\t\t(for bttv <0.5.20)\n"
40
" -charset latin-1/2\t\tlatin-1\n"
41
" -timeout <secs>\t\tnone\n"
42
" -name <filename>\t\tttext-%%s.%%e\n"
43
" -format <fmt[,options]>\tascii\n"
46
" ppp[.ss] stands for a page number and an\n"
47
" optional subpage number (ie 123.4). If\n"
48
" the subpage number is omitted the first\n"
49
" transmitted subpage is captured.\n"
58
struct export_module **ep;
62
"\nSyntax: -format Name[,Options]\n"
64
" Name\tExt.\tOptions\n"
65
" --------------------------------\n"
67
for (ep = modules; *ep; ep++)
69
fprintf(fp, " %-7s\t.%-4s", (*ep)->fmt_name, (*ep)->extension);
70
for (c = '\t', cp = (*ep)->options; cp && *cp; cp++, c = ',')
71
fprintf(fp, "%c%s", c, *cp);
76
"Common options: reveal,hide\n"
78
"Example: -format ansi,reveal,bg=none\n"
89
write(2, "*BREAK*\r\n", 9);
95
arg_pgno(char *p, int *subno)
103
pgno = strtol(p, &end, 16);
104
if ((*end == ':' || *end == '/' || *end == '.') && end[1])
105
*subno = strtol(end + 1, &end, 16);
107
if (pgno >= 0x100 && pgno <= 0x899)
108
if (*subno == ANY_SUB || (*subno >= 0x00 && *subno <= 0x3f7f))
111
fatal("%s: invalid page number", p);
116
option(int argc, char **argv, int *ind, char **arg)
118
static struct { char *nam, *altnam; int arg; } opts[] = {
119
{ "--help", "-h", 0 },
120
{ "--version", "-v", 0 },
121
{ "-copyright", "-�", 0 },
122
{ "-debug", "--debug", 0 },
123
{ "-vbi", "-dev", 1 },
124
{ "-newbttv", "-new", 0 },
125
{ "-oldbttv", "-old", 0 },
126
{ "-finetune", "-f", 1 },
127
{ "-charset", "-latin", 1 },
128
{ "-format", "-fmt", 1 },
129
{ "-name", "-o", 1 },
130
{ "-timeout", "-t", 1 },
137
*arg = argv[(*ind)++];
138
for (i = 0; i < NELEM(opts); ++i)
139
if (streq(*arg, opts[i].nam) || streq(*arg, opts[i].altnam))
143
*arg = argv[(*ind)++];
145
fatal("option %s requires an argument", *arg);
151
fatal("%s: invalid option", *arg);
161
event(struct dl_head *reqs, struct vt_event *ev)
163
struct req *req, *nxt;
167
case EV_PAGE: // new page
169
struct vt_page *vtp = ev->p1;
171
for (req = $ reqs->first; nxt = $ req->node->next; req = nxt)
172
if (req->pgno == vtp->pgno)
173
if (req->subno == ANY_SUB || req->subno == vtp->subno)
176
printf("captured page %x.%02x\n", vtp->pgno,
179
dl_insert_last(reqs + 1, dl_remove(req->node));
180
// the same page may be there in different formats.
191
main(int argc, char **argv)
193
char *vbi_name = "/dev/vbi";
194
int fine_tune = 1; // auto = 999;
197
char *fname = "ttext-%s.%e";
198
char *out_fmt = "ascii";
199
struct export *fmt = 0;
205
struct dl_head reqs[2]; // simple linear lists of requests & captures
210
dl_init(reqs); // the requests
211
dl_init(reqs+1); // the captured pages
214
while (opt = option(argc, argv, &ind, &arg))
221
printf("AleVT Version "VERSION"\n");
224
printf("Copyright 2000 by E. Toernig, froese@gmx.de\n");
239
if (streq(arg, "auto"))
242
fine_tune = strtol(arg, 0, 10);
245
if (streq(arg, "latin-1") || streq(arg, "1"))
247
else if (streq(arg, "latin-2") || streq(arg, "2"))
250
fatal("bad charset (not latin-1/2)");
253
if (streq(arg, "help") || streq(arg, "?") || streq(arg, "list"))
262
timeout = strtol(arg, 0, 10);
263
if (timeout < 1 || timeout > 999999)
264
fatal("bad timeout value", timeout);
266
case -1: // non-option arg
268
fmt = export_open(out_fmt);
270
fatal("%s", export_errstr());
271
if (not(req = malloc(sizeof(*req))))
272
out_of_mem(sizeof(*req));
275
req->pgno = arg_pgno(arg, &req->subno);
277
dl_insert_last(reqs, req->node);
282
fatal("no pages requested");
285
if (not(vbi = vbi_open(vbi_name, 0, fine_tune, newbttv)))
286
fatal("cannot open %s", vbi_name);
287
vbi_add_handler(vbi, event, reqs); // register event handler
289
signal(SIGUSR1, sig_handler);
290
signal(SIGALRM, sig_handler);
294
// capture pages (moves requests from reqs[0] to reqs[1])
295
while (not dl_empty(reqs) && not timed_out)
296
if (fdset_select(fds, 30000) == 0) // 30sec select time out
303
vbi_del_handler(vbi, event, reqs);
306
if (not dl_empty(reqs))
307
error("capture aborted. some pages are missing.");
309
for (req = $ reqs[1].first; req->node->next; req = $ req->node->next)
311
fname = export_mkname(req->export, req->name, req->vtp, req->pgno_str);
312
if (not fname || export(req->export, req->vtp, fname))
313
error("error saving page %s: %s", req->pgno_str, export_errstr());
318
exit(dl_empty(reqs) ? 0 : 1);