Linux kernel & device driver programming

Cross-Referenced Linux and Device Driver Code

[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ]
Version: [ 2.6.11.8 ] [ 2.6.25 ] [ 2.6.25.8 ] [ 2.6.31.13 ] Architecture: [ i386 ]
  1 /*
  2  * mtt - teletext test app.
  3  * 
  4  * This is just main() for the standalone version, the actual
  5  * code is in vbi-gui.c (motif) and vbi-tty.c (terminal).
  6  *
  7  *   (c) 2002 Gerd Knorr <kraxel@bytesex.org>
  8  * 
  9  */
 10 
 11 #include "config.h"
 12 
 13 #include <stdio.h>
 14 #include <stdlib.h>
 15 #include <unistd.h>
 16 #include <string.h>
 17 #include <errno.h>
 18 #include <iconv.h>
 19 #include <locale.h>
 20 #include <langinfo.h>
 21 #include <termios.h>
 22 #include <fcntl.h>
 23 #include <pthread.h>
 24 #include <sys/types.h>
 25 #include <sys/time.h>
 26 
 27 #include <X11/Xlib.h>
 28 #include <X11/Intrinsic.h>
 29 #include <Xm/Xm.h>
 30 #include <Xm/Form.h>
 31 #include <Xm/Label.h>
 32 #include <Xm/RowColumn.h>
 33 #include <Xm/CascadeB.h>
 34 #include <Xm/PushB.h>
 35 #include <Xm/DrawingA.h>
 36 #include <Xm/Protocols.h>
 37 
 38 #include "icons.h"
 39 #include "atoms.h"
 40 #include "vbi-data.h"
 41 #include "vbi-gui.h"
 42 #include "vbi-tty.h"
 43 
 44 #include "grab-ng.h"
 45 #include "channel.h"
 46 #include "frequencies.h"
 47 #include "commands.h"
 48 
 49 /* --------------------------------------------------------------------- */
 50 
 51 XtAppContext  app_context;
 52 Widget        app_shell;
 53 Display       *dpy;
 54 int           debug;
 55 
 56 static String fallback_ressources[] = {
 57 #include "mtt.h"
 58     NULL
 59 };
 60 
 61 struct ARGS {
 62     char  *device;
 63     int   help;
 64     int   tty;
 65     int   debug;
 66     int   sim;
 67 } args;
 68 
 69 XtResource args_desc[] = {
 70     /* name, class, type, size, offset, default_type, default_addr */
 71     {
 72         /* Strings */
 73         "device",
 74         XtCString, XtRString, sizeof(char*),
 75         XtOffset(struct ARGS*,device),
 76         XtRString, "/dev/vbi",
 77     },{
 78         /* Integer */
 79         "help",
 80         XtCValue, XtRInt, sizeof(int),
 81         XtOffset(struct ARGS*,help),
 82         XtRString, ""
 83     },{
 84         "tty",
 85         XtCValue, XtRInt, sizeof(int),
 86         XtOffset(struct ARGS*,tty),
 87         XtRString, ""
 88     },{
 89         "debug",
 90         XtCValue, XtRInt, sizeof(int),
 91         XtOffset(struct ARGS*,debug),
 92         XtRString, ""
 93     },{
 94         "sim",
 95         XtCValue, XtRInt, sizeof(int),
 96         XtOffset(struct ARGS*,sim),
 97         XtRString, ""
 98     }
 99 };
100 const int args_count = XtNumber(args_desc);
101 
102 XrmOptionDescRec opt_desc[] = {
103     { "-c",          "device",      XrmoptionSepArg, NULL },
104     { "-device",     "device",      XrmoptionSepArg, NULL },
105 
106     { "-tty",        "tty",         XrmoptionNoArg,  "1" },
107     { "-sim",        "sim",         XrmoptionNoArg,  "1" },
108     { "-debug",      "debug",       XrmoptionNoArg,  "1" },
109 
110     { "-h",          "help",        XrmoptionNoArg,  "1" },
111     { "-help",       "help",        XrmoptionNoArg,  "1" },
112     { "--help",      "help",        XrmoptionNoArg,  "1" },
113 };
114 const int opt_count = (sizeof(opt_desc)/sizeof(XrmOptionDescRec));
115 
116 /* --------------------------------------------------------------------- */
117 
118 static void
119 debug_action(Widget widget, XEvent *event,
120              String *params, Cardinal *num_params)
121 {
122     fprintf(stderr,"debug_action: called\n");
123 }
124 
125 static XtActionsRec actionTable[] = {
126     { "debug", debug_action },
127 };
128 
129 /* --------------------------------------------------------------------- */
130 
131 static void usage(void)
132 {
133     fprintf(stderr,
134             "\n"
135             "mtt -- teletext application\n"
136             "\n"
137             "usage: mtt [ options ]\n"
138             "options:\n"
139             "  -help         print this text\n"
140             "  -debug        enable debug messages\n"
141             "  -device <dev> use vbi device <dev> instead of /dev/vbi\n"
142             "  -tty          use terminal mode\n"
143             "\n"
144             "--\n"
145             "Gerd Knorr <kraxel@bytesex.org>\n");
146 }
147 
148 static void vbi_data(XtPointer data, int *fd, XtInputId *iproc)
149 {
150     struct vbi_state *vbi = data;
151     vbi_hasdata(vbi);
152 }
153 
154 static int main_tty(int argc, char **argv)
155 {
156     char *dev = "/dev/vbi";
157     int debug = 0;
158     int sim   = 0;
159 
160     argc--;
161     argv++;
162     for (;argc;) {
163         if (0 == strcmp(argv[0],"-c") ||
164             0 == strcmp(argv[0],"-device")) {
165             dev = argv[1];
166             argc -= 2;
167             argv += 2;
168             
169         } else if (0 == strcmp(argv[0],"-tty")) {
170             argc -= 1;
171             argv += 1;
172 
173         } else if (0 == strcmp(argv[0],"-debug")) {
174             debug = 1;
175             argc -= 1;
176             argv += 1;
177 
178         } else if (0 == strcmp(argv[0],"-sim")) {
179             sim   = 1;
180             argc -= 1;
181             argv += 1;
182 
183         } else if (0 == strcmp(argv[0],"-h") &&
184                    0 == strcmp(argv[0],"-help") &&
185                    0 == strcmp(argv[0],"--help")) {
186             usage();
187             exit(0);
188             
189         } else
190             break;
191     }
192     vbi_tty(dev,debug,sim);
193     exit(0);
194 }
195 
196 int
197 main(int argc, char **argv)
198 {
199     struct vbi_state *vbi;
200     char **av;
201     int ac;
202 
203     ac = argc;
204     av = malloc(sizeof(char*)*(argc+1));
205     memcpy(av,argv,sizeof(char*)*(argc+1));
206 
207     XtSetLanguageProc(NULL,NULL,NULL);
208     XtToolkitInitialize();
209     app_context = XtCreateApplicationContext();
210     XtAppSetFallbackResources(app_context,fallback_ressources);
211     dpy = XtOpenDisplay(app_context, NULL,
212                         NULL,"mtt",
213                         opt_desc, opt_count,
214                         &argc, argv);
215     if (NULL == dpy)
216         main_tty(ac,av);
217     app_shell = XtVaAppCreateShell(NULL,"mtt",
218                                    applicationShellWidgetClass,dpy,NULL);
219     XtAppAddActions(app_context,actionTable,
220                     sizeof(actionTable)/sizeof(XtActionsRec));
221     x11_icons_init(dpy,0);
222     init_atoms(dpy);
223     XtGetApplicationResources(app_shell,&args,
224                               args_desc,args_count,
225                               NULL,0);
226     if (args.help) {
227         usage();
228         exit(1);
229     }
230     if (args.tty)
231         main_tty(ac,av);
232 
233     freq_init();
234     read_config(NULL, &argc, argv);
235     parse_config();
236     do_va_cmd(2,"setfreqtab",(-1 != chantab)
237               ? chanlist_names[chantab].str : "europe-west");
238 
239     vbi = vbi_open(args.device,args.debug,args.sim);
240     if (NULL == vbi)
241         exit(1);
242     if (args.debug)
243         vbi_event_handler_add(vbi->dec,~0,vbi_dump_event,vbi);
244     XtAppAddInput(app_context, vbi->fd, (XtPointer) XtInputReadMask,
245                   vbi_data, vbi);
246 
247     vbi_create_widgets(app_shell,vbi);
248     XtRealizeWidget(app_shell);
249     XtAppMainLoop(app_context);
250     return 0;
251 }
252 
  This page was automatically generated by the LXR engine.