]> andersk Git - moira.git/blame - clients/mmoira/main.c
specify path to synctree
[moira.git] / clients / mmoira / main.c
CommitLineData
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>
698271c7 11#include <string.h>
9b7620ca 12#include <pwd.h>
c4095074 13#include <moira.h>
eef96006 14#include <com_err.h>
390907c0 15#include <X11/StringDefs.h>
c4095074 16#include <Xm/PushB.h>
17#include <Xm/BulletinB.h>
9b7620ca 18#include <Xm/RowColumn.h>
c4095074 19#include "mmoira.h"
20
21extern MenuItem MenuRoot;
22
892c98b2 23Widget CreateMenu(), CreateForm();
c4095074 24Widget BuildMenuTree();
9b7620ca 25void popup_error_hook(), mr_x_input(), EnterPressed(), CancelForm();
26void ExecuteForm(), DoHelp();
27
390907c0 28MoiraResources resources;
29
30static XrmOptionDescRec options[] = {
31 {"-db", "*database", XrmoptionSepArg, NULL},
35f012bb 32 {"-noauth", "*noAuth", XrmoptionNoArg, (caddr_t) "true"},
390907c0 33 {"-helpfile","*helpFile", XrmoptionSepArg, NULL},
35f012bb 34 {"-logsize","*logSize", XrmoptionSepArg, NULL},
390907c0 35};
36
37
38#define Offset(field) (XtOffset(MoiraResources *, field))
39
40static 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},
35f012bb 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},
390907c0 55};
56
57#undef Offset
58
9b7620ca 59XtActionsRec actions[] = {
60 { "next-or-do-it", EnterPressed },
61 { "cancel-form", CancelForm },
62 { "execute-form", ExecuteForm },
63 { "help", DoHelp }
64};
65
c4095074 66
67Widget toplevel;
68char *user, *program_name, *moira_server;
ca5beb9a 69int tty;
c4095074 70
71main(argc, argv)
72int argc;
73char *argv[];
74{
892c98b2 75 Widget button, bboard, menuwidget;
35f012bb 76 char *motd, *env, buf[256], host[64];
b2d21e59 77 int n, status;
390907c0 78 char *getlogin(), *getenv();
c4095074 79
eef96006 80 /* I know, this is a crock, but it makes the program work... */
390907c0 81 env = getenv("XFILESEARCHPATH");
82 if (env) {
83 char buf[256];
84 sprintf(buf, "%s:/afs/athena.mit.edu/system/moira/lib/%N", env);
85 setenv("XFILESEARCHPATH", buf, 1);
86 } else
87 setenv("XFILESEARCHPATH", "/afs/athena.mit.edu/system/moira/lib/%N", 1);
eef96006 88
ca5beb9a 89 if (getenv("DISPLAY"))
90 tty = 0;
91 else
92 tty = 1;
93
b2d21e59 94 if ((user = getlogin()) == NULL)
95 user = getpwuid((int) getuid())->pw_name;
9b7620ca 96 user = (user && strlen(user)) ? strsave(user) : "";
b2d21e59 97
698271c7 98 if ((program_name = strrchr(argv[0], '/')) == NULL)
b2d21e59 99 program_name = argv[0];
100 else
101 program_name++;
9b7620ca 102 program_name = strsave(program_name);
b2d21e59 103
ca5beb9a 104 resources.help_file = my_resources[3].default_addr;
105 resources.maxlogsize = (int) my_resources[6].default_addr;
106 resources.noauth = 0;
107 resources.db = "";
108 for (n = 1; n < argc; n++) {
109 if (!strcmp(argv[n], "-db") && n+1 < argc) {
110 resources.db = argv[n+1];
111 n++;
112 } else if (!strcmp(argv[n], "-helpfile") && n+1 < argc) {
113 resources.help_file = argv[n+1];
114 n++;
115 } else if (!strcmp(argv[n], "-logsize") && n+1 < argc) {
116 resources.maxlogsize = atoi(argv[n+1]);
117 n++;
118 } else if (!strcmp(argv[n], "-noauth")) {
119 resources.noauth = 1;
120 } else if (!strcmp(argv[n], "-tty")) {
121 tty = 1;
122 } else {
123 printf("%s: unknown option: %s\n", argv[0], argv[n]);
124 }
125 }
126
127 if (!tty) {
128 toplevel = XtInitialize("toplevel", "Moira", options,
129 XtNumber(options), &argc, argv);
390907c0 130
ca5beb9a 131 XtAppAddActions(XtWidgetToApplicationContext(toplevel),
132 actions, XtNumber(actions));
390907c0 133
ca5beb9a 134 XtGetApplicationResources(toplevel, (caddr_t) &resources,
135 my_resources, XtNumber(my_resources),
136 NULL, (Cardinal) 0);
137 }
390907c0 138
c4095074 139 moira_server = "";
390907c0 140 if (resources.db)
141 moira_server = resources.db;
c4095074 142
5f42070c 143#ifdef GDSS
144 initialize_gdss_error_table();
145#endif /* GDSS */
146
b2d21e59 147 status = mr_connect(moira_server);
148 if (status) {
149 com_err(program_name, status, " connecting to server");
150 exit(1);
151 }
152 status = mr_motd(&motd);
153 if (status) {
154 com_err(program_name, status, " connecting to server");
155 exit(1);
156 }
157 if (motd) {
158 fprintf(stderr, "The Moira server is currently unavailable:\n%s\n",
159 motd);
160 mr_disconnect();
161 exit(1);
162 }
163
35f012bb 164 if (!resources.noauth) {
165 status = mr_auth("mmoira");
166 if (status == MR_USER_AUTH) {
167 char buf[BUFSIZ];
168 com_err(program_name, status, "\nPress [RETURN] to continue");
169 gets(buf);
170 } else if (status) {
171 com_err(program_name, status, "; authorization failed - may need to run kinit");
172 exit(1);
173 }
b2d21e59 174 }
c4095074 175
ca5beb9a 176 if (!tty) {
177 bboard = XtCreateManagedWidget("bboard",
178 xmBulletinBoardWidgetClass,
179 toplevel, NULL, 0);
180 menuwidget = BuildMenuTree(bboard, &MenuRoot);
181 SetupLogWidget(bboard);
182
183 XtRealizeWidget(toplevel);
c4095074 184
ca5beb9a 185 set_com_err_hook(popup_error_hook);
186 mr_set_alternate_input(ConnectionNumber(XtDisplay(toplevel)),
187 mr_x_input);
188 }
c4095074 189
35f012bb 190 mr_host(host, sizeof(host));
191 if (resources.noauth)
192 sprintf(buf, "UNAUTHENTICATED connection to Moira server %s\n\n",
193 host);
194 else
195 sprintf(buf, "Connected to Moira server %s\n\n", host);
196 AppendToLog(buf);
197
ca5beb9a 198 if (tty)
199 TtyMainLoop();
200 else
201 XtMainLoop();
c4095074 202}
203
c4095074 204
205int MoiraQuery(query, argc, argv, callback, data)
206char *query;
207int argc;
208char **argv;
209int (*callback)();
210caddr_t data;
211{
212 int status;
213
ca5beb9a 214 if (!tty) {
215 MakeWatchCursor(toplevel);
216 XFlush(XtDisplay(toplevel));
217 }
c4095074 218 status = mr_query(query, argc, argv, callback, data);
892c98b2 219 if (status != MR_ABORTED && status != MR_NOT_CONNECTED) {
ca5beb9a 220 if (!tty)
221 MakeNormalCursor(toplevel);
892c98b2 222 return(status);
223 }
c4095074 224 status = mr_connect(moira_server);
225 if (status) {
226 com_err(program_name, status, " while re-connecting to server %s",
227 moira_server);
ca5beb9a 228 if (!tty)
229 MakeNormalCursor(toplevel);
c4095074 230 return(MR_ABORTED);
231 }
232 status = mr_auth("mmoira");
233 if (status) {
234 com_err(program_name, status, " while re-authenticating to server %s",
235 moira_server);
236 mr_disconnect();
ca5beb9a 237 if (!tty)
238 MakeNormalCursor(toplevel);
c4095074 239 return(MR_ABORTED);
240 }
241 status = mr_query(query, argc, argv, callback, data);
ca5beb9a 242 if (!tty)
243 MakeNormalCursor(toplevel);
c4095074 244 return(status);
245
246}
892c98b2 247
248
249DisplayForm(spec)
250EntryForm *spec;
251{
252 Widget w;
9b7620ca 253 int i, j;
254 static XtTranslations trans = NULL;
255
256 if (trans == NULL)
390907c0 257 trans = XtParseTranslationTable(resources.form_trans);
892c98b2 258
259 w = CreateForm(toplevel, spec);
260 XtManageChild(w);
9b7620ca 261 for (i = 0; spec->inputlines[i]; i++) {
262 XtOverrideTranslations(spec->inputlines[i]->mywidget, trans);
35f012bb 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);
9b7620ca 266 }
267 /* set the focus to the first line of the form */
268 _XmGrabTheFocus(spec->inputlines[0]->mywidget, NULL);
892c98b2 269}
270
271
272void popup_error_hook(who, code, fmt, arg1, arg2, arg3, arg4, arg5)
273char *who;
274long code;
275char *fmt;
276caddr_t arg1, arg2, arg3, arg4, arg5;
277{
278 char buf[BUFSIZ], *cp;
279
280 (void) strcpy(buf, who);
281 for (cp = buf; *cp; cp++);
282 *cp++ = ':';
283 *cp++ = ' ';
284 if (code) {
285 (void) strcpy(cp, error_message(code));
286 while (*cp)
287 cp++;
288 }
289 sprintf(cp, fmt, arg1, arg2, arg3, arg4, arg5);
290 display_error(buf);
291}
b2d21e59 292
293
294void mr_x_input()
295{
296 XEvent event;
eef96006 297 XtAppContext _XtDefaultAppContext();
b2d21e59 298
299 XtAppNextEvent(_XtDefaultAppContext(), &event);
300 XtDispatchEvent(&event);
301}
This page took 0.131087 seconds and 5 git commands to generate.