~ubuntu-branches/ubuntu/feisty/alevt/feisty

« back to all changes in this revision

Viewing changes to main.c

  • Committer: Bazaar Package Importer
  • Author(s): Thomas Schoepf
  • Date: 2002-03-17 15:09:36 UTC
  • Revision ID: james.westby@ubuntu.com-20020317150936-yglzziwcc0luz55k
Tags: upstream-1.6.0
Import upstream version 1.6.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <stdio.h>
 
2
#include <stdlib.h>
 
3
 
 
4
#include "vt.h"
 
5
#include "misc.h"
 
6
#include "fdset.h"
 
7
#include "xio.h"
 
8
#include "vbi.h"
 
9
#include "lang.h"
 
10
#include "cache.h"
 
11
#include "ui.h"
 
12
 
 
13
int debug = 0;
 
14
 
 
15
/* current args for next start() */
 
16
static char *geometry;
 
17
static char *dpy_name;
 
18
static char *vbi_name = "/dev/vbi";
 
19
static struct xio *xio;
 
20
static struct vbi *vbi;
 
21
static int fine_tune = 1; // auto = 999;
 
22
static int erc = 1;
 
23
static int newbttv = -1;
 
24
 
 
25
 
 
26
static void
 
27
usage(FILE *fp, int exitval)
 
28
{
 
29
    fprintf(fp, "\nUsage: %s [options]\n", prgname);
 
30
    fprintf(fp,
 
31
            "\n"
 
32
            "  Valid options:\t\tDefault:\n"
 
33
            "    --help\n"
 
34
            "    --version\n"
 
35
            "    -vbi <vbidev>\t\t/dev/vbi\n"
 
36
            "    -display <dpy>\t\t$DISPLAY\n"
 
37
            "    -geometry <geo>\t\t41x25\n"
 
38
            "    -finetune <-4..4|auto>\t0\n"
 
39
            "    -child ppp[.ss]\n"
 
40
            "    [-parent] ppp[.ss]\t\t900\n"
 
41
            //"    -oldbttv\t\t(for bttv <0.5.20)\n"
 
42
            "    -[no]erc\t\t\tenabled\n"
 
43
            "    -[no]bell\t\t\tenabled\n"
 
44
            "    -charset latin-1/2\t\tlatin-1\n"
 
45
            "\n"
 
46
            "  Order is important!  Each page number\n"
 
47
            "  opens a new window with the previously\n"
 
48
            "  given geometry, device, and display.\n"
 
49
            "\n"
 
50
            "  ppp[.ss] stands for a page number and an\n"
 
51
            "  optional subpage number (ie 123.4).  If\n"
 
52
            "  the subpage number is omitted the first\n"
 
53
            "  transmitted subpage is shown.\n"
 
54
            "\n"
 
55
            "  The -child option requires a parent\n"
 
56
            "  window.  So, it must be preceeded by\n"
 
57
            "  a parent or another child window.\n"
 
58
        );
 
59
    exit(exitval);
 
60
}
 
61
 
 
62
 
 
63
static int
 
64
arg_pgno(char *p, int *subno)
 
65
{
 
66
    char *end;
 
67
    int pgno;
 
68
 
 
69
    *subno = ANY_SUB;
 
70
    if (*p)
 
71
    {
 
72
        pgno = strtol(p, &end, 16);
 
73
        if ((*end == ':' || *end == '/' || *end == '.') && end[1])
 
74
            *subno = strtol(end + 1, &end, 16);
 
75
        if (*end == 0)
 
76
            if (pgno >= 0x100 && pgno <= 0x999)
 
77
                if (*subno == ANY_SUB || (*subno >= 0x00 && *subno <= 0x3f7f))
 
78
                    return pgno;
 
79
    }
 
80
    fatal("%s: invalid page number", p);
 
81
}
 
82
 
 
83
 
 
84
static struct vtwin *
 
85
start(int argc, char **argv, struct vtwin *parent, int pgno, int subno)
 
86
{
 
87
    struct vtwin *win;
 
88
 
 
89
    if (vbi == 0)
 
90
        vbi = vbi_open(vbi_name, cache_open(), fine_tune, newbttv);
 
91
    if (vbi == 0)
 
92
        fatal("cannot open %s", vbi_name);
 
93
    if (vbi->cache)
 
94
        vbi->cache->op->mode(vbi->cache, CACHE_MODE_ERC, erc);
 
95
 
 
96
    if (xio == 0)
 
97
        xio = xio_open_dpy(dpy_name, argc, argv);
 
98
    if (xio == 0)
 
99
        fatal("cannot open display");
 
100
 
 
101
    parent = vtwin_new(xio, vbi, geometry, parent, pgno, subno);
 
102
    if (parent == 0)
 
103
        fatal("cannot create window");
 
104
    return parent;
 
105
}
 
106
 
 
107
 
 
108
static int
 
109
option(int argc, char **argv, int *ind, char **arg)
 
110
{
 
111
    static struct { char *nam, *altnam; int arg; } opts[] = {
 
112
        { "-vbi", "-dev", 1 },
 
113
        { "-display", "-d", 1 },
 
114
        { "-geometry", "-g", 1 },
 
115
        { "-child", "-c", 1 },
 
116
        { "-editor", "-ed", 0 },
 
117
        { "-parent", "-p", 1 },
 
118
        { "--version", "-v", 0 },
 
119
        { "--help", "-h", 0 },
 
120
        { "-newbttv", "-new", 0 },
 
121
        { "-oldbttv", "-old", 0 },
 
122
        { "-finetune", "-f", 1 },
 
123
        { "-debug", "--debug", 0 },
 
124
        { "-copyright", "-�", 0 },
 
125
        { "-erc", "-e", 0 },
 
126
        { "-noerc", "-ne", 0 },
 
127
        { "-bell", "-b", 0 },
 
128
        { "-nobell", "-nb", 0 },
 
129
        { "-charset", "-latin", 1 },
 
130
    };
 
131
    int i;
 
132
 
 
133
    if (*ind >= argc)
 
134
        return 0;
 
135
 
 
136
    *arg = argv[(*ind)++];
 
137
    for (i = 0; i < NELEM(opts); ++i)
 
138
        if (streq(*arg, opts[i].nam) || streq(*arg, opts[i].altnam))
 
139
        {
 
140
            if (opts[i].arg)
 
141
                if (*ind < argc)
 
142
                    *arg = argv[(*ind)++];
 
143
                else
 
144
                    fatal("option %s requires an argument", *arg);
 
145
            return i+1;
 
146
        }
 
147
 
 
148
    if (**arg == '-')
 
149
    {
 
150
        fatal("%s: invalid option", *arg);
 
151
        usage(stderr, 1);
 
152
    }
 
153
 
 
154
    return -1;
 
155
}
 
156
 
 
157
 
 
158
 
 
159
int
 
160
main(int argc, char **argv)
 
161
{
 
162
    struct vtwin *parent = 0;
 
163
    int pgno, subno;
 
164
    int opt, ind;
 
165
    char *arg;
 
166
 
 
167
    setprgname(argv[0]);
 
168
 
 
169
    fdset_init(fds);
 
170
 
 
171
    ind = 1;
 
172
    while (opt = option(argc, argv, &ind, &arg))
 
173
        switch (opt)
 
174
        {
 
175
            case 1:     // vbi
 
176
                vbi_name = arg;
 
177
                vbi = 0;
 
178
                parent = 0;
 
179
                break;
 
180
            case 2:     // display
 
181
                dpy_name = arg;
 
182
                xio = 0;
 
183
                parent = 0;
 
184
                break;
 
185
            case 3:     // geometry
 
186
                geometry = arg;
 
187
                break;
 
188
            case 4:     // child
 
189
                if (parent == 0)
 
190
                    fatal("-child requires a parent window");
 
191
                pgno = arg_pgno(arg, &subno);
 
192
                parent = start(argc, argv, parent, pgno, subno);
 
193
                geometry = 0;
 
194
                break;
 
195
            case 5:     // editor
 
196
                enab_editor = 1;
 
197
                break;
 
198
            case 7:     // version
 
199
                printf("AleVT Version "VERSION"\n");
 
200
                exit(0);
 
201
            case 13:    // copyright
 
202
                printf("Copyright 2000 by E. Toernig, froese@gmx.de\n");
 
203
                exit(0);
 
204
            case 8:     // help
 
205
                usage(stdout, 0);
 
206
                break;
 
207
            case 9:     // newbttv
 
208
                newbttv = 1;
 
209
                break;
 
210
            case 10:    // oldbttv
 
211
                newbttv = 0;
 
212
                break;
 
213
            case 11:    // finetune
 
214
                if (streq(arg, "auto"))
 
215
                    fine_tune = 999;
 
216
                else
 
217
                    fine_tune = strtol(arg, 0, 10);
 
218
                break;
 
219
            case 14:    // erc
 
220
                erc = 1;
 
221
                break;
 
222
            case 15:    // noerc
 
223
                erc = 0;
 
224
                break;
 
225
            case 16:    // bell
 
226
                bell = 1;
 
227
                break;
 
228
            case 17:    // nobell
 
229
                bell = 0;
 
230
                break;
 
231
            case 18:    // charset
 
232
                if (streq(arg, "latin-1") || streq(arg, "1"))
 
233
                    latin1 = 1;
 
234
                else if (streq(arg, "latin-2") || streq(arg, "2"))
 
235
                    latin1 = 0;
 
236
                else
 
237
                    fatal("bad charset (not latin-1/2)");
 
238
                break;
 
239
            case 12:    // debug
 
240
                debug++;
 
241
                break;
 
242
            case 6:     // parent
 
243
            case -1:    // non-option arg
 
244
                pgno = arg_pgno(arg, &subno);
 
245
                parent = start(argc, argv, 0, pgno, subno);
 
246
                geometry = 0;
 
247
                break;
 
248
        }
 
249
 
 
250
    if (parent == 0)
 
251
        start(argc, argv, 0, 0x900, ANY_SUB);
 
252
 
 
253
    xio_event_loop();
 
254
 
 
255
    exit(0);
 
256
}