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 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
|
/*
hello.c
Copyright (C) 1998 Ulric Eriksson <ulric@edu.stockholm.se>
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <X11/StringDefs.h>
#include <X11/Intrinsic.h>
#include <X11/Xaw/Label.h>
static Widget topLevel;
/* Plugin stuff */
static void win(char *p)
{
printf("250 %lx\n", (unsigned long) XtWindow(topLevel));
}
static void quit(char *p)
{
printf("221 Over and out\n");
exit(0);
}
static struct {
char *verb;
void (*cb) (char *);
} plugin_cmds[] = {
{"WIN", win},
{"QUIT", quit},
{ NULL, NULL }
};
static void read_plugin_cmd(XtPointer client_data, int *fid, XtInputId * id)
{
char b[1024], *p;
int i, n;
if ((n = read(*fid, b, 1020)) == -1)
return;
b[n] = '\0';
if ((p = strchr(b, '\n')) == NULL) {
printf("501 Incomplete command\n");
fflush(stdout);
return;
}
*p = '\0';
for (i = 0; plugin_cmds[i].verb; i++) {
if (!strncmp(b, plugin_cmds[i].verb,
strlen(plugin_cmds[i].verb)))
break;
}
if (plugin_cmds[i].verb)
(*plugin_cmds[i].cb) (b + strlen(plugin_cmds[i].verb));
else
printf("500 What are you talking about\n");
fflush(stdout);
}
void mainloop(void)
{
XtAppAddInput(XtWidgetToApplicationContext(topLevel),
fileno(stdin), (XtPointer) XtInputReadMask,
read_plugin_cmd, NULL);
printf("220 Hello plugin\n");
fflush(stdout);
XtAppMainLoop(XtWidgetToApplicationContext(topLevel));
}
int main(int argc, char **argv)
{
XtAppContext ac;
topLevel = XtAppInitialize(&ac, "Hello",
NULL, 0, &argc, argv, NULL, NULL, 0);
XtVaCreateManagedWidget("hello",
labelWidgetClass, topLevel,
XtNlabel, "Hello, World", (char *)0);
XtRealizeWidget(topLevel);
mainloop();
return 0;
}
|