]>
Commit | Line | Data |
---|---|---|
c4095074 | 1 | /* $Header$ |
2 | * | |
3 | * Copyright 1991 by the Massachusetts Institute of Technology. | |
4 | * | |
5 | * For further information on copyright and distribution | |
6 | * see the file mit-copyright.h | |
7 | */ | |
8 | ||
9 | #include <mit-copyright.h> | |
10 | #include <stdio.h> | |
9b7620ca | 11 | #include <pwd.h> |
c4095074 | 12 | #include <moira.h> |
13 | #include <Xm/PushB.h> | |
14 | #include <Xm/BulletinB.h> | |
9b7620ca | 15 | #include <Xm/RowColumn.h> |
16 | #include <Xm/RowColumnP.h> | |
c4095074 | 17 | #include "mmoira.h" |
18 | ||
19 | extern MenuItem MenuRoot; | |
20 | ||
892c98b2 | 21 | Widget CreateMenu(), CreateForm(); |
c4095074 | 22 | Widget BuildMenuTree(); |
9b7620ca | 23 | void popup_error_hook(), mr_x_input(), EnterPressed(), CancelForm(); |
24 | void ExecuteForm(), DoHelp(); | |
25 | ||
26 | XtActionsRec actions[] = { | |
27 | { "next-or-do-it", EnterPressed }, | |
28 | { "cancel-form", CancelForm }, | |
29 | { "execute-form", ExecuteForm }, | |
30 | { "help", DoHelp } | |
31 | }; | |
32 | ||
c4095074 | 33 | |
34 | Widget toplevel; | |
35 | char *user, *program_name, *moira_server; | |
36 | ||
37 | main(argc, argv) | |
38 | int argc; | |
39 | char *argv[]; | |
40 | { | |
892c98b2 | 41 | Widget button, bboard, menuwidget; |
b2d21e59 | 42 | char *motd; |
43 | int n, status; | |
9b7620ca | 44 | char *getlogin(); |
c4095074 | 45 | |
b2d21e59 | 46 | if ((user = getlogin()) == NULL) |
47 | user = getpwuid((int) getuid())->pw_name; | |
9b7620ca | 48 | user = (user && strlen(user)) ? strsave(user) : ""; |
b2d21e59 | 49 | |
50 | if ((program_name = rindex(argv[0], '/')) == NULL) | |
51 | program_name = argv[0]; | |
52 | else | |
53 | program_name++; | |
9b7620ca | 54 | program_name = strsave(program_name); |
b2d21e59 | 55 | |
c4095074 | 56 | moira_server = ""; |
9b7620ca | 57 | for (n = 1; n < argc - 1; n++) |
58 | if (!strcmp(argv[n], "-db")) | |
59 | moira_server = argv[n + 1]; | |
c4095074 | 60 | |
5f42070c | 61 | #ifdef GDSS |
62 | initialize_gdss_error_table(); | |
63 | #endif /* GDSS */ | |
64 | ||
b2d21e59 | 65 | status = mr_connect(moira_server); |
66 | if (status) { | |
67 | com_err(program_name, status, " connecting to server"); | |
68 | exit(1); | |
69 | } | |
70 | status = mr_motd(&motd); | |
71 | if (status) { | |
72 | com_err(program_name, status, " connecting to server"); | |
73 | exit(1); | |
74 | } | |
75 | if (motd) { | |
76 | fprintf(stderr, "The Moira server is currently unavailable:\n%s\n", | |
77 | motd); | |
78 | mr_disconnect(); | |
79 | exit(1); | |
80 | } | |
81 | ||
82 | status = mr_auth("mmoira"); | |
83 | if (status == MR_USER_AUTH) { | |
84 | char buf[BUFSIZ]; | |
85 | com_err(program_name, status, "\nPress [RETURN] to continue"); | |
86 | gets(buf); | |
87 | } else if (status) { | |
9b7620ca | 88 | com_err(program_name, status, "; authorization failed - may need to run kinit"); |
b2d21e59 | 89 | exit(1); |
90 | } | |
c4095074 | 91 | |
92 | toplevel = XtInitialize("toplevel", "Moira", NULL, 0, | |
93 | &argc, argv); | |
94 | ||
9b7620ca | 95 | XtAppAddActions(XtWidgetToApplicationContext(toplevel), |
96 | actions, XtNumber(actions)); | |
97 | ||
c4095074 | 98 | bboard = XtCreateManagedWidget( "bboard", |
99 | xmBulletinBoardWidgetClass, | |
100 | toplevel, NULL, 0); | |
c4095074 | 101 | menuwidget = BuildMenuTree(bboard, &MenuRoot); |
892c98b2 | 102 | SetupLogWidget(bboard); |
c4095074 | 103 | |
104 | XtRealizeWidget(toplevel); | |
105 | ||
892c98b2 | 106 | set_com_err_hook(popup_error_hook); |
b2d21e59 | 107 | mr_set_alternate_input(ConnectionNumber(XtDisplay(toplevel)), |
108 | mr_x_input); | |
c4095074 | 109 | XtMainLoop(); |
110 | } | |
111 | ||
c4095074 | 112 | |
113 | int MoiraQuery(query, argc, argv, callback, data) | |
114 | char *query; | |
115 | int argc; | |
116 | char **argv; | |
117 | int (*callback)(); | |
118 | caddr_t data; | |
119 | { | |
120 | int status; | |
121 | ||
b2d21e59 | 122 | MakeWatchCursor(toplevel); |
78b2e8b4 | 123 | XFlush(XtDisplay(toplevel)); |
c4095074 | 124 | status = mr_query(query, argc, argv, callback, data); |
892c98b2 | 125 | if (status != MR_ABORTED && status != MR_NOT_CONNECTED) { |
b2d21e59 | 126 | MakeNormalCursor(toplevel); |
892c98b2 | 127 | return(status); |
128 | } | |
c4095074 | 129 | status = mr_connect(moira_server); |
130 | if (status) { | |
131 | com_err(program_name, status, " while re-connecting to server %s", | |
132 | moira_server); | |
b2d21e59 | 133 | MakeNormalCursor(toplevel); |
c4095074 | 134 | return(MR_ABORTED); |
135 | } | |
136 | status = mr_auth("mmoira"); | |
137 | if (status) { | |
138 | com_err(program_name, status, " while re-authenticating to server %s", | |
139 | moira_server); | |
140 | mr_disconnect(); | |
b2d21e59 | 141 | MakeNormalCursor(toplevel); |
c4095074 | 142 | return(MR_ABORTED); |
143 | } | |
144 | status = mr_query(query, argc, argv, callback, data); | |
b2d21e59 | 145 | MakeNormalCursor(toplevel); |
c4095074 | 146 | return(status); |
147 | ||
148 | } | |
892c98b2 | 149 | |
150 | ||
78b2e8b4 | 151 | char form_override_table[] = |
9b7620ca | 152 | "None<Key>Return: next-or-do-it()\n\ |
153 | Ctrl<Key>C: cancel-form()\n\ | |
154 | Shift<Key>Return: execute-form()\n\ | |
155 | Meta<Key>?: help()"; | |
156 | ||
157 | ||
892c98b2 | 158 | DisplayForm(spec) |
159 | EntryForm *spec; | |
160 | { | |
161 | Widget w; | |
9b7620ca | 162 | int i, j; |
163 | static XtTranslations trans = NULL; | |
164 | ||
165 | if (trans == NULL) | |
166 | trans = XtParseTranslationTable(form_override_table); | |
892c98b2 | 167 | |
168 | w = CreateForm(toplevel, spec); | |
169 | XtManageChild(w); | |
9b7620ca | 170 | for (i = 0; spec->inputlines[i]; i++) { |
171 | XtOverrideTranslations(spec->inputlines[i]->mywidget, trans); | |
172 | if (spec->inputlines[i]->type == FT_KEYWORD) { | |
173 | XmRowColumnWidget rc; | |
174 | ||
175 | rc = (XmRowColumnWidget) spec->inputlines[i]->mywidget; | |
176 | for (j = 0; j < rc->composite.num_children; j++) | |
177 | XtOverrideTranslations(rc->composite.children[j], trans); | |
178 | } | |
179 | } | |
180 | /* set the focus to the first line of the form */ | |
181 | _XmGrabTheFocus(spec->inputlines[0]->mywidget, NULL); | |
892c98b2 | 182 | } |
183 | ||
184 | ||
185 | void popup_error_hook(who, code, fmt, arg1, arg2, arg3, arg4, arg5) | |
186 | char *who; | |
187 | long code; | |
188 | char *fmt; | |
189 | caddr_t arg1, arg2, arg3, arg4, arg5; | |
190 | { | |
191 | char buf[BUFSIZ], *cp; | |
192 | ||
193 | (void) strcpy(buf, who); | |
194 | for (cp = buf; *cp; cp++); | |
195 | *cp++ = ':'; | |
196 | *cp++ = ' '; | |
197 | if (code) { | |
198 | (void) strcpy(cp, error_message(code)); | |
199 | while (*cp) | |
200 | cp++; | |
201 | } | |
202 | sprintf(cp, fmt, arg1, arg2, arg3, arg4, arg5); | |
203 | display_error(buf); | |
204 | } | |
b2d21e59 | 205 | |
206 | ||
207 | void mr_x_input() | |
208 | { | |
209 | XEvent event; | |
210 | ||
211 | XtAppNextEvent(_XtDefaultAppContext(), &event); | |
212 | XtDispatchEvent(&event); | |
213 | } |