3 * Copyright 1991 by the Massachusetts Institute of Technology.
5 * For further information on copyright and distribution
6 * see the file mit-copyright.h
9 #include <mit-copyright.h>
15 #include <X11/StringDefs.h>
17 #include <Xm/BulletinB.h>
18 #include <Xm/RowColumn.h>
21 extern MenuItem MenuRoot;
23 Widget CreateMenu(), CreateForm();
24 Widget BuildMenuTree();
25 void popup_error_hook(), mr_x_input(), EnterPressed(), CancelForm();
26 void ExecuteForm(), DoHelp();
28 MoiraResources resources;
30 static XrmOptionDescRec options[] = {
31 {"-db", "*database", XrmoptionSepArg, NULL},
32 {"-noauth", "*noAuth", XrmoptionNoArg, (caddr_t) "true"},
33 {"-helpfile","*helpFile", XrmoptionSepArg, NULL},
34 {"-logsize","*logSize", XrmoptionSepArg, NULL},
38 #define Offset(field) (XtOffset(MoiraResources *, field))
40 static XtResource my_resources[] = {
41 {"formTranslations", XtCString, XtRString, sizeof(String),
42 Offset(form_trans), XtRImmediate, (caddr_t) NULL},
43 {"textTranslations", XtCString, XtRString, sizeof(String),
44 Offset(text_trans), XtRImmediate, (caddr_t) NULL},
45 {"logTranslations", XtCString, XtRString, sizeof(String),
46 Offset(log_trans), XtRImmediate, (caddr_t) NULL},
47 {"helpFile", XtCFile, XtRString, sizeof(String),
48 Offset(help_file), XtRImmediate, (caddr_t) "/afs/athena.mit.edu/system/moira/lib/mmoira.helpfile"},
49 {"database", XtCString, XtRString, sizeof(String),
50 Offset(db), XtRImmediate, (caddr_t) NULL},
51 {"noAuth", XtCBoolean, XtRBoolean, sizeof(Boolean),
52 Offset(noauth), XtRImmediate, (caddr_t) False},
53 {"logSize", XtCValue, XtRInt, sizeof(int),
54 Offset(maxlogsize), XtRImmediate, (caddr_t) MAXLOGSIZE},
59 XtActionsRec actions[] = {
60 { "next-or-do-it", EnterPressed },
61 { "cancel-form", CancelForm },
62 { "execute-form", ExecuteForm },
68 char *user, *program_name, *moira_server;
75 Widget button, bboard, menuwidget;
76 char *motd, *env, buf[256], host[64];
78 char *getlogin(), *getenv();
80 /* I know, this is a crock, but it makes the program work... */
81 env = getenv("XFILESEARCHPATH");
84 sprintf(buf, "%s:/afs/athena.mit.edu/system/moira/lib/%N", env);
85 setenv("XFILESEARCHPATH", buf, 1);
87 setenv("XFILESEARCHPATH", "/afs/athena.mit.edu/system/moira/lib/%N", 1);
89 if (getenv("DISPLAY"))
94 if ((user = getlogin()) == NULL)
95 user = getpwuid((int) getuid())->pw_name;
96 user = (user && strlen(user)) ? strsave(user) : "";
98 if ((program_name = strrchr(argv[0], '/')) == NULL)
99 program_name = argv[0];
102 program_name = strsave(program_name);
104 resources.help_file = my_resources[3].default_addr;
105 resources.maxlogsize = (int) my_resources[6].default_addr;
106 resources.noauth = 0;
108 for (n = 1; n < argc; n++) {
109 if (!strcmp(argv[n], "-db") && n+1 < argc) {
110 resources.db = argv[n+1];
112 } else if (!strcmp(argv[n], "-helpfile") && n+1 < argc) {
113 resources.help_file = argv[n+1];
115 } else if (!strcmp(argv[n], "-logsize") && n+1 < argc) {
116 resources.maxlogsize = atoi(argv[n+1]);
118 } else if (!strcmp(argv[n], "-noauth")) {
119 resources.noauth = 1;
120 } else if (!strcmp(argv[n], "-tty")) {
123 printf("%s: unknown option: %s\n", argv[0], argv[n]);
128 toplevel = XtInitialize("toplevel", "Moira", options,
129 XtNumber(options), &argc, argv);
131 XtAppAddActions(XtWidgetToApplicationContext(toplevel),
132 actions, XtNumber(actions));
134 XtGetApplicationResources(toplevel, (caddr_t) &resources,
135 my_resources, XtNumber(my_resources),
141 moira_server = resources.db;
144 initialize_gdss_error_table();
147 status = mr_connect(moira_server);
149 com_err(program_name, status, " connecting to server");
152 status = mr_motd(&motd);
154 com_err(program_name, status, " connecting to server");
158 fprintf(stderr, "The Moira server is currently unavailable:\n%s\n",
164 if (!resources.noauth) {
165 status = mr_auth("mmoira");
166 if (status == MR_USER_AUTH) {
168 com_err(program_name, status, "\nPress [RETURN] to continue");
171 com_err(program_name, status, "; authorization failed - may need to run kinit");
177 bboard = XtCreateManagedWidget("bboard",
178 xmBulletinBoardWidgetClass,
180 menuwidget = BuildMenuTree(bboard, &MenuRoot);
181 SetupLogWidget(bboard);
183 XtRealizeWidget(toplevel);
185 set_com_err_hook(popup_error_hook);
186 mr_set_alternate_input(ConnectionNumber(XtDisplay(toplevel)),
190 mr_host(host, sizeof(host));
191 if (resources.noauth)
192 sprintf(buf, "UNAUTHENTICATED connection to Moira server %s\n\n",
195 sprintf(buf, "Connected to Moira server %s\n\n", host);
205 int MoiraQuery(query, argc, argv, callback, data)
215 MakeWatchCursor(toplevel);
216 XFlush(XtDisplay(toplevel));
218 status = mr_query(query, argc, argv, callback, data);
219 if (status != MR_ABORTED && status != MR_NOT_CONNECTED) {
221 MakeNormalCursor(toplevel);
224 status = mr_connect(moira_server);
226 com_err(program_name, status, " while re-connecting to server %s",
229 MakeNormalCursor(toplevel);
232 status = mr_auth("mmoira");
234 com_err(program_name, status, " while re-authenticating to server %s",
238 MakeNormalCursor(toplevel);
241 status = mr_query(query, argc, argv, callback, data);
243 MakeNormalCursor(toplevel);
254 static XtTranslations trans = NULL;
257 trans = XtParseTranslationTable(resources.form_trans);
259 w = CreateForm(toplevel, spec);
261 for (i = 0; spec->inputlines[i]; i++) {
262 XtOverrideTranslations(spec->inputlines[i]->mywidget, trans);
263 if (spec->inputlines[i]->type == FT_KEYWORD)
264 for (j = 0; j < NumChildren(spec->inputlines[i]->mywidget); j++)
265 XtOverrideTranslations(NthChild(spec->inputlines[i]->mywidget, j), trans);
267 /* set the focus to the first line of the form */
268 _XmGrabTheFocus(spec->inputlines[0]->mywidget, NULL);
272 void popup_error_hook(who, code, fmt, arg1, arg2, arg3, arg4, arg5)
276 caddr_t arg1, arg2, arg3, arg4, arg5;
278 char buf[BUFSIZ], *cp;
280 (void) strcpy(buf, who);
281 for (cp = buf; *cp; cp++);
285 (void) strcpy(cp, error_message(code));
289 sprintf(cp, fmt, arg1, arg2, arg3, arg4, arg5);
297 XtAppContext _XtDefaultAppContext();
299 XtAppNextEvent(_XtDefaultAppContext(), &event);
300 XtDispatchEvent(&event);