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;
74 Widget button, bboard, menuwidget;
75 char *motd, *env, buf[256], host[64];
77 char *getlogin(), *getenv();
79 /* I know, this is a crock, but it makes the program work... */
80 env = getenv("XFILESEARCHPATH");
83 sprintf(buf, "%s:/afs/athena.mit.edu/system/moira/lib/%N", env);
84 setenv("XFILESEARCHPATH", buf, 1);
86 setenv("XFILESEARCHPATH", "/afs/athena.mit.edu/system/moira/lib/%N", 1);
88 if ((user = getlogin()) == NULL)
89 user = getpwuid((int) getuid())->pw_name;
90 user = (user && strlen(user)) ? strsave(user) : "";
92 if ((program_name = rindex(argv[0], '/')) == NULL)
93 program_name = argv[0];
96 program_name = strsave(program_name);
98 toplevel = XtInitialize("toplevel", "Moira", options,
99 XtNumber(options), &argc, argv);
101 XtAppAddActions(XtWidgetToApplicationContext(toplevel),
102 actions, XtNumber(actions));
104 XtGetApplicationResources(toplevel, (caddr_t) &resources,
105 my_resources, XtNumber(my_resources),
110 moira_server = resources.db;
113 initialize_gdss_error_table();
116 status = mr_connect(moira_server);
118 com_err(program_name, status, " connecting to server");
121 status = mr_motd(&motd);
123 com_err(program_name, status, " connecting to server");
127 fprintf(stderr, "The Moira server is currently unavailable:\n%s\n",
133 if (!resources.noauth) {
134 status = mr_auth("mmoira");
135 if (status == MR_USER_AUTH) {
137 com_err(program_name, status, "\nPress [RETURN] to continue");
140 com_err(program_name, status, "; authorization failed - may need to run kinit");
145 bboard = XtCreateManagedWidget( "bboard",
146 xmBulletinBoardWidgetClass,
148 menuwidget = BuildMenuTree(bboard, &MenuRoot);
149 SetupLogWidget(bboard);
151 XtRealizeWidget(toplevel);
153 set_com_err_hook(popup_error_hook);
154 mr_set_alternate_input(ConnectionNumber(XtDisplay(toplevel)),
156 mr_host(host, sizeof(host));
157 if (resources.noauth)
158 sprintf(buf, "UNAUTHENTICATED connection to Moira server %s\n\n",
161 sprintf(buf, "Connected to Moira server %s\n\n", host);
168 int MoiraQuery(query, argc, argv, callback, data)
177 MakeWatchCursor(toplevel);
178 XFlush(XtDisplay(toplevel));
179 status = mr_query(query, argc, argv, callback, data);
180 if (status != MR_ABORTED && status != MR_NOT_CONNECTED) {
181 MakeNormalCursor(toplevel);
184 status = mr_connect(moira_server);
186 com_err(program_name, status, " while re-connecting to server %s",
188 MakeNormalCursor(toplevel);
191 status = mr_auth("mmoira");
193 com_err(program_name, status, " while re-authenticating to server %s",
196 MakeNormalCursor(toplevel);
199 status = mr_query(query, argc, argv, callback, data);
200 MakeNormalCursor(toplevel);
211 static XtTranslations trans = NULL;
214 trans = XtParseTranslationTable(resources.form_trans);
216 w = CreateForm(toplevel, spec);
218 for (i = 0; spec->inputlines[i]; i++) {
219 XtOverrideTranslations(spec->inputlines[i]->mywidget, trans);
220 if (spec->inputlines[i]->type == FT_KEYWORD)
221 for (j = 0; j < NumChildren(spec->inputlines[i]->mywidget); j++)
222 XtOverrideTranslations(NthChild(spec->inputlines[i]->mywidget, j), trans);
224 /* set the focus to the first line of the form */
225 _XmGrabTheFocus(spec->inputlines[0]->mywidget, NULL);
229 void popup_error_hook(who, code, fmt, arg1, arg2, arg3, arg4, arg5)
233 caddr_t arg1, arg2, arg3, arg4, arg5;
235 char buf[BUFSIZ], *cp;
237 (void) strcpy(buf, who);
238 for (cp = buf; *cp; cp++);
242 (void) strcpy(cp, error_message(code));
246 sprintf(cp, fmt, arg1, arg2, arg3, arg4, arg5);
254 XtAppContext _XtDefaultAppContext();
256 XtAppNextEvent(_XtDefaultAppContext(), &event);
257 XtDispatchEvent(&event);