00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096 #include <errno.h>
00097 #include <unistd.h>
00098 #include <stdlib.h>
00099 #include <string.h>
00100 #include "udanax.h"
00101 #include "players.h"
00102
00103 #define MAX_PLAYERS 5
00104 int user = 0;
00105 PLAYER player[MAX_PLAYERS];
00106
00107 extern int errno;
00108 FILE *febelog = NULL;
00109 extern bool isxumain;
00110 bool maximumsetupsizehasbeenhit;
00111 extern int maximumsetupsize;
00112 bool logstuff;
00113 Session *sessx;
00114 FILE *interfaceinput = NULL;
00115 int backenddaemon;
00116
00117 extern bool getrequest(Session * sess, typerequest * requestptr);
00118 extern void processrcfile();
00119 extern void prompt(Session * sess, char *string);
00120 extern void putcreatenewdocument(Session * sess, IStreamAddr * newdocisaptr);
00121
00129
00130 void
00131 xanadu(
00132 Session *sess)
00133 {
00134 typerequest request;
00135
00136 logstuff = false;
00137 if (getrequest(sess, &request))
00138 (*requestfns[request]) (sess);
00139
00140
00141 logstuff = false;
00142 sess->free();
00143 }
00144
00152 int
00153 main(
00154 int argc,
00155 char *argv[])
00156 {
00157 Session sess;
00158
00159
00160
00161 isxumain = true;
00162
00163 setbuf(stderr, NULL);
00164 debug = false;
00165 processrcfile();
00166 init(0);
00167
00168
00169
00170 initsession("enf.enf");
00171 sessx = &sess;
00172 sess.getaccount(&sess.account);
00173 for (;;) {
00174 nsessorcommand++;
00175
00176
00177 xanadu(&sess);
00178 testforreservedness("main");
00179
00180 }
00181 return 0;
00182 }
00183
00191 bool
00192 setmaximumsetupsize(
00193 Session *sess)
00194 {
00195 char buff[100];
00196
00197 fprintf(sess->outp, "maximumsetupsize = ? ");
00198 maximumsetupsize = atoi(fgets(buff, 100, sess->inp));
00199 return true;
00200 }
00201
00209 bool
00210 getmuchtext(
00211 Session *sess,
00212 typetext *textptr)
00213 {
00214
00215
00216 int numinstring = 0;
00217 int temp;
00218
00219 numinstring = temp = 0;
00220 for (;;) {
00221 if (!fgets(textptr->string + numinstring, GRANTEXTLENGTH - numinstring, sess->inp)) {
00222 temp = 0;
00223 break;
00224 }
00225 temp = strlen(textptr->string + numinstring);
00226 if (temp < 1) {
00227 break;
00228 }
00229 numinstring += temp;
00230 if (numinstring >= GRANTEXTLENGTH) {
00231 break;
00232 }
00233 }
00234
00235 if (numinstring > GRANTEXTLENGTH)
00236 assert(0);
00237
00238 if (numinstring == 0) {
00239 textptr->length = 0;
00240 return false;
00241 }
00242
00243 textptr->length = numinstring;
00244 textptr->itemid = TEXTID;
00245 return true;
00246 }
00247
00255 void
00256 sourceunixcommand(
00257 Session *sess)
00258 {
00259 char unixcommand[132];
00260 char file[64];
00261 IStreamAddr docisa;
00262 typetext *textsetptr;
00263
00264 FILE *infile;
00265 int count, lines, bugger;
00266 int status;
00267
00268 count = 0;
00269 lines = 0;
00270 bugger = debug;
00271
00272 sprintf(file, "xum%d", getpid());
00273 prompt(sess, " Enter unix command : ");
00274 fgets(unixcommand, 132, sess->inp);
00275
00276 if (unixcommand[strlen(unixcommand) - 1] == '\n')
00277 unixcommand[strlen(unixcommand) - 1] = '\0';
00278
00279 strcat(unixcommand, " >");
00280 strcat(unixcommand, file);
00281
00282 if ((status = system(unixcommand)) != 0) {
00283 L("Exit status = %d\n", status);
00284 perror("Udanax(system call 0)");
00285
00286 }
00287 if (debug) {
00288 prompt(sess, "lines until debug : ");
00289 count = atoi(fgets(unixcommand, 132, sess->inp));
00290 if (count)
00291 debug = 0;
00292 }
00293
00294 docreatenewdocument(sess, &docisa);
00295
00296 putcreatenewdocument(sess, &docisa);
00297
00298 infile = sess->inp;
00299 if (!(sess->inp = fopen(file, "r"))) {
00300 perror("xanadu");
00301 L("Couldn't open %s\n", file);
00302 assert(0);
00303 }
00304 while ((textsetptr = new(sess) typetext) != NULL
00305
00306 && (getmuchtext(sess, textsetptr) || (textsetptr->length > 0))) {
00307 if (debug)
00308 L("line # %d\n", lines);
00309 textsetptr->next = NULL;
00310 textsetptr->itemid = TEXTID;
00311 textsetptr->length = strlen(textsetptr->string);
00312 doappend(sess, &docisa, textsetptr);
00313
00314 ++lines;
00315 sess->free();
00316 if (count && --count == 0)
00317 debug = bugger;
00318 }
00319 fclose(sess->inp);
00320 unlink(file);
00321 sess->inp = infile;
00322
00323
00324 }
00325
00333 bool
00334 decrementusers()
00335 {
00336 return (false);
00337 }
00338
00346 bool
00347 isthisusersdocument(
00348 Session *sess,
00349 Tumbler *tp)
00350 {
00351 return tumbleraccounteq(tp, &sess->account);
00352 }