]>
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> | |
11 | #include <moira.h> | |
12 | #include <Xm/PushB.h> | |
13 | #include <Xm/BulletinB.h> | |
14 | #include "mmoira.h" | |
15 | ||
16 | extern MenuItem MenuRoot; | |
17 | ||
892c98b2 | 18 | Widget CreateMenu(), CreateForm(); |
c4095074 | 19 | Widget BuildMenuTree(); |
b2d21e59 | 20 | void popup_error_hook(), mr_x_input(); |
c4095074 | 21 | |
22 | Widget toplevel; | |
23 | char *user, *program_name, *moira_server; | |
24 | ||
25 | main(argc, argv) | |
26 | int argc; | |
27 | char *argv[]; | |
28 | { | |
892c98b2 | 29 | Widget button, bboard, menuwidget; |
b2d21e59 | 30 | char *motd; |
31 | int n, status; | |
c4095074 | 32 | |
b2d21e59 | 33 | if ((user = getlogin()) == NULL) |
34 | user = getpwuid((int) getuid())->pw_name; | |
35 | user = (user && strlen(user)) ? Strsave(user) : ""; | |
36 | ||
37 | if ((program_name = rindex(argv[0], '/')) == NULL) | |
38 | program_name = argv[0]; | |
39 | else | |
40 | program_name++; | |
41 | program_name = Strsave(program_name); | |
42 | ||
43 | /* Need to parse command line argument here */ | |
c4095074 | 44 | moira_server = ""; |
45 | ||
b2d21e59 | 46 | status = mr_connect(moira_server); |
47 | if (status) { | |
48 | com_err(program_name, status, " connecting to server"); | |
49 | exit(1); | |
50 | } | |
51 | status = mr_motd(&motd); | |
52 | if (status) { | |
53 | com_err(program_name, status, " connecting to server"); | |
54 | exit(1); | |
55 | } | |
56 | if (motd) { | |
57 | fprintf(stderr, "The Moira server is currently unavailable:\n%s\n", | |
58 | motd); | |
59 | mr_disconnect(); | |
60 | exit(1); | |
61 | } | |
62 | ||
63 | status = mr_auth("mmoira"); | |
64 | if (status == MR_USER_AUTH) { | |
65 | char buf[BUFSIZ]; | |
66 | com_err(program_name, status, "\nPress [RETURN] to continue"); | |
67 | gets(buf); | |
68 | } else if (status) { | |
69 | if (status >= ERROR_TABLE_BASE_krb && | |
70 | status <= ERROR_TABLE_BASE_krb + 256) | |
71 | com_err(program_name, status, "; authorization failed - please run kinit"); | |
72 | else | |
73 | com_err(program_name, status, "; authorization failed"); | |
74 | exit(1); | |
75 | } | |
c4095074 | 76 | |
77 | toplevel = XtInitialize("toplevel", "Moira", NULL, 0, | |
78 | &argc, argv); | |
79 | ||
80 | bboard = XtCreateManagedWidget( "bboard", | |
81 | xmBulletinBoardWidgetClass, | |
82 | toplevel, NULL, 0); | |
c4095074 | 83 | menuwidget = BuildMenuTree(bboard, &MenuRoot); |
892c98b2 | 84 | SetupLogWidget(bboard); |
c4095074 | 85 | |
86 | XtRealizeWidget(toplevel); | |
87 | ||
892c98b2 | 88 | set_com_err_hook(popup_error_hook); |
b2d21e59 | 89 | mr_set_alternate_input(ConnectionNumber(XtDisplay(toplevel)), |
90 | mr_x_input); | |
c4095074 | 91 | XtMainLoop(); |
92 | } | |
93 | ||
c4095074 | 94 | |
95 | int MoiraQuery(query, argc, argv, callback, data) | |
96 | char *query; | |
97 | int argc; | |
98 | char **argv; | |
99 | int (*callback)(); | |
100 | caddr_t data; | |
101 | { | |
102 | int status; | |
103 | ||
b2d21e59 | 104 | MakeWatchCursor(toplevel); |
c4095074 | 105 | status = mr_query(query, argc, argv, callback, data); |
892c98b2 | 106 | if (status != MR_ABORTED && status != MR_NOT_CONNECTED) { |
b2d21e59 | 107 | MakeNormalCursor(toplevel); |
892c98b2 | 108 | return(status); |
109 | } | |
c4095074 | 110 | status = mr_connect(moira_server); |
111 | if (status) { | |
112 | com_err(program_name, status, " while re-connecting to server %s", | |
113 | moira_server); | |
b2d21e59 | 114 | MakeNormalCursor(toplevel); |
c4095074 | 115 | return(MR_ABORTED); |
116 | } | |
117 | status = mr_auth("mmoira"); | |
118 | if (status) { | |
119 | com_err(program_name, status, " while re-authenticating to server %s", | |
120 | moira_server); | |
121 | mr_disconnect(); | |
b2d21e59 | 122 | MakeNormalCursor(toplevel); |
c4095074 | 123 | return(MR_ABORTED); |
124 | } | |
125 | status = mr_query(query, argc, argv, callback, data); | |
b2d21e59 | 126 | MakeNormalCursor(toplevel); |
c4095074 | 127 | return(status); |
128 | ||
129 | } | |
892c98b2 | 130 | |
131 | ||
132 | DisplayForm(spec) | |
133 | EntryForm *spec; | |
134 | { | |
135 | Widget w; | |
136 | ||
137 | w = CreateForm(toplevel, spec); | |
138 | XtManageChild(w); | |
139 | } | |
140 | ||
141 | ||
142 | void popup_error_hook(who, code, fmt, arg1, arg2, arg3, arg4, arg5) | |
143 | char *who; | |
144 | long code; | |
145 | char *fmt; | |
146 | caddr_t arg1, arg2, arg3, arg4, arg5; | |
147 | { | |
148 | char buf[BUFSIZ], *cp; | |
149 | ||
150 | (void) strcpy(buf, who); | |
151 | for (cp = buf; *cp; cp++); | |
152 | *cp++ = ':'; | |
153 | *cp++ = ' '; | |
154 | if (code) { | |
155 | (void) strcpy(cp, error_message(code)); | |
156 | while (*cp) | |
157 | cp++; | |
158 | } | |
159 | sprintf(cp, fmt, arg1, arg2, arg3, arg4, arg5); | |
160 | display_error(buf); | |
161 | } | |
b2d21e59 | 162 | |
163 | ||
164 | void mr_x_input() | |
165 | { | |
166 | XEvent event; | |
167 | ||
168 | XtAppNextEvent(_XtDefaultAppContext(), &event); | |
169 | XtDispatchEvent(&event); | |
170 | } |