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 #include <string.h>
00091 #include <unistd.h>
00092 #include <stdlib.h>
00093 #include <ctype.h>
00094 #include "udanax.h"
00095
00096 bool getspecset(Session * sess, typespecset * specsetptr);
00097 void prompt(Session * sess, char *string);
00098 bool getisa(Session * sess, IStreamAddr * isaptr);
00099 bool getvsa(Session * sess, Tumbler * vsaptr);
00100 bool gettextset(Session * sess, typetextset * textsetptr);
00101 bool getnumber(Session * sess, int * numptr);
00102 bool getcutseq(Session * sess, typecutseq * cutseqptr);
00103 bool getspanset(Session * sess, typespanset * spansetptr, typeitemid id);
00104 bool getspan(Session * sess, typespan * spanptr, typeitemid id);
00105 bool gettumbler(Session * sess, Tumbler * tumblerptr);
00106 bool validaccount(Session * sess, IStreamAddr * accountptr);
00107 void error(Session * sess, char *string);
00108 bool gettext(Session * sess, typetext * textptr);
00109 bool getvspec(Session * sess, typevspec * vspecptr);
00110 bool validrequest(Session * sess, typerequest request);
00111
00119 bool
00120 getnum(
00121 Session *sess,
00122 int *numptr)
00123 {
00124 metachar c;
00125 int num;
00126
00127 bool flag = false;
00128 for (num = 0; (c = getc(sess->inp)) != EOF && isdigit(c);) {
00129 num = num * 10 + c - '0';
00130 flag = true;
00131 }
00132
00133 if (!flag) {
00134 fprintf(sess->errp, "no number\n");
00135 #ifndef DISTRIBUTION
00136 if (c == '?' || c == 'h') {
00137 system("cat /usr3/xu/requests.j");
00138 } else if (c == '!') {
00139 system("csh");
00140 }
00141 #endif
00142 } else {
00143 ungetc(c, sess->inp);
00144 *numptr = num;
00145 }
00146 return flag;
00147 }
00148
00156 bool
00157 eatchar(
00158 Session *sess,
00159 char c)
00160 {
00161 metachar m;
00162
00163 if ((m = getc(sess->inp)) != c) {
00164 ungetc(m, sess->inp);
00165 return false;
00166 } else
00167 return true;
00168 }
00169
00177 bool
00178 needchar(
00179 Session *sess,
00180 char c)
00181 {
00182 if (!eatchar(sess, c)) {
00183 fprintf(sess->errp, "needed a ");
00184
00185 if (c == '\n')
00186 fprintf(sess->errp, "newline\n");
00187 else
00188 fprintf(sess->errp, "%c\n", c);
00189
00190 return false;
00191 }
00192 return true;
00193 }
00194
00202 bool
00203 getnumber(
00204 Session *sess,
00205 int *numptr)
00206 {
00207 return getnum(sess, numptr) && needchar(sess, '\n');
00208 }
00209
00217 bool
00218 gettumbler(
00219 Session *sess,
00220 Tumbler *tumblerptr)
00221 {
00222 int i;
00223
00224 tumblerclear(tumblerptr);
00225 if (eatchar(sess, '-'))
00226 tumblerptr->sign = 1;
00227
00228 for (i = 0; i < NPLACES; ++i) {
00229 if (!getnum(sess, (int *) &tumblerptr->mantissa[i]))
00230 return false;
00231
00232 if (tumblerptr->mantissa[i] == 0 && i == 0) {
00233 --tumblerptr->exp;
00234 --i;
00235 }
00236
00237 if (!eatchar(sess, '.'))
00238 break;
00239 }
00240
00241 if (eatchar(sess, '.')) {
00242 fprintf(sess->errp, "tumbler overflow\n");
00243 return false;
00244 }
00245
00246 for (i = 0; i < NPLACES && tumblerptr->mantissa[i] == 0; ++i)
00247 ;
00248
00249 if (i == NPLACES)
00250 tumblerptr->exp = 0;
00251
00252 return needchar(sess, '\n');
00253 }
00254
00262 bool
00263 getbool(
00264 Session *sess,
00265 bool *boolptr)
00266 {
00267 prompt(sess, "(y/n) ");
00268 int c = getc(sess->inp);
00269 if (isupper(c))
00270 c = tolower(c);
00271
00272 eatchar(sess, '\n');
00273
00274 if (c == 'y') {
00275 *boolptr = true;
00276 return true;
00277
00278 } else if (c == 'n') {
00279 *boolptr = false;
00280 return true;
00281
00282 } else {
00283 error(sess, "need 'y' or 'n'");
00284 return false;
00285 }
00286 }
00287
00295 bool
00296 getisa(
00297 Session *sess,
00298 IStreamAddr *isaptr)
00299 {
00300 return gettumbler(sess, isaptr);
00301 }
00302
00310 bool
00311 getvsa(
00312 Session *sess,
00313 Tumbler *vsaptr)
00314 {
00315 return gettumbler(sess, vsaptr);
00316 }
00317
00325 bool
00326 getrequest(
00327 Session *sess,
00328 typerequest *requestptr)
00329 {
00330 prompt(sess, "\nrequest? ");
00331 int c = getc(sess->inp);
00332 if ((int) c == EOF) {
00333 L("endfile\n");
00334 sess->inp = stdin;
00335 }
00336
00337 ungetc(c, sess->inp);
00338 return getnumber(sess, requestptr) && validrequest(sess, *requestptr);
00339 }
00340
00348 bool
00349 validrequest(
00350 Session *sess,
00351 typerequest request)
00352 {
00353 if (request >= 0 && request < NREQUESTS && requestfns[request] != NULL)
00354 return true;
00355
00356 fprintf(sess->errp, "invalid request: %d\n", request);
00357 return false;
00358 }
00359
00367 bool
00368 validaccount(
00369 Session *sess,
00370 IStreamAddr *accountptr)
00371 {
00372 return (true);
00373 }
00374
00382 bool
00383 getspecset(
00384 Session *sess,
00385 typespecset *specsetptr)
00386 {
00387 bool any, type;
00388 typespec *specset;
00389
00390 for (;;) {
00391 prompt(sess, "any spans or vspecs? ");
00392 if (!getbool(sess, &any))
00393 return false;
00394
00395 if (!any) {
00396 *specsetptr = NULL;
00397 return true;
00398 }
00399
00400 prompt(sess, "a span? ");
00401 if (!getbool(sess, &type))
00402 return false;
00403
00404 if (type) {
00405 specset = (typespec *) new(sess) typespan;
00406
00407 if (!getspan(sess, (typespan *) specset, ISPANID))
00408 return false;
00409
00410 } else {
00411 specset = (typespec *) new(sess) typevspec;
00412
00413 if (!getvspec(sess, (typevspec *) specset))
00414 return false;
00415 }
00416 *specsetptr = specset;
00417 specsetptr = (typespecset *) & (((typevspec *) specset)->next);
00418 }
00419 }
00420
00428 bool
00429 getvspec(
00430 Session *sess,
00431 typevspec *vspecptr)
00432 {
00433 vspecptr->itemid = VSPECID;
00434 vspecptr->next = NULL;
00435
00436 prompt(sess, "document=> ");
00437 if (!(getisa(sess, &vspecptr->docisa) && getspanset(sess, &vspecptr->vspanset, VSPANID)))
00438 return false;
00439
00440 return true;
00441 }
00442
00450 bool
00451 getspanset(
00452 Session *sess,
00453 typespanset *spansetptr,
00454 typeitemid id)
00455 {
00456 bool any;
00457 typespan *spanset;
00458
00459 for (;;) {
00460 prompt(sess, "any spans? ");
00461 if (!getbool(sess, &any))
00462 return false;
00463
00464 if (!any) {
00465 *spansetptr = NULL;
00466 return true;
00467 }
00468
00469 spanset = new(sess) typespan;
00470
00471 if (!getspan(sess, spanset, id))
00472 return false;
00473
00474 *spansetptr = spanset;
00475 spansetptr = &spanset->next;
00476 }
00477 }
00478
00486 bool
00487 getspan(
00488 Session *sess,
00489 typespan *spanptr,
00490 typeitemid id)
00491 {
00492 prompt(sess, "enter span\n start=> ");
00493 if (!getisa(sess, (IStreamAddr *) &spanptr->stream))
00494 return false;
00495
00496 spanptr->itemid = id;
00497
00498 prompt(sess, " width=> ");
00499 if (!(getisa(sess, (IStreamAddr *) &spanptr->width)))
00500 return false;
00501
00502 return true;
00503 }
00504
00512 bool
00513 gettextset(
00514 Session *sess,
00515 typetextset *textsetptr)
00516 {
00517 typetext *textset;
00518
00519 for (;;) {
00520 textset = new(sess) typetext;
00521
00522 if (!gettext(sess, textset)) {
00523 *textsetptr = NULL;
00524 break;
00525 }
00526 *textsetptr = textset;
00527 textsetptr = &textset->next;
00528 }
00529 return true;
00530 }
00531
00539 bool
00540 gettext(
00541 Session *sess,
00542 typetext *textptr)
00543 {
00544 if (!fgets(textptr->string, GRANTEXTLENGTH, sess->inp)) {
00545 textptr->length = 0;
00546 return false;
00547 }
00548
00549 textptr->length = strlen(textptr->string);
00550 if (textptr->length <= 1)
00551 return false;
00552
00553
00554
00555
00556
00557
00558 textptr->itemid = TEXTID;
00559 return true;
00560 }
00561
00569 bool
00570 getcutseq(
00571 Session *sess,
00572 typecutseq *cutseqptr)
00573 {
00574 int i;
00575 bool anycuts;
00576
00577 i = 0;
00578 for (;;) {
00579 prompt(sess, "any cuts? ");
00580 if (!getbool(sess, &anycuts))
00581 return false;
00582
00583 if (!anycuts)
00584 break;
00585
00586 prompt(sess, "cut address=> ");
00587 if (!getvsa(sess, &cutseqptr->cutsarray[i]))
00588 return false;
00589
00590 if (++i > MAXCUTS)
00591 break;
00592
00593 cutseqptr->numberofcuts = i;
00594 }
00595 return true;
00596 }
00597
00605 bool
00606 getboolset(
00607 Session *sess,
00608 typeboolsetnode **boolsetptr)
00609 {
00610 bool disjunct;
00611 typeboolsetnode *boolset;
00612
00613 for (;;) {
00614 prompt(sess, "any disjunctions? ");
00615 if (!getbool(sess, &disjunct))
00616 return false;
00617
00618 if (!disjunct) {
00619 *boolsetptr = NULL;
00620 return true;
00621 }
00622
00623 boolset = new(sess) typeboolsetnode;
00624
00625
00626 prompt(sess, "enter disjunction=> ");
00627 if (!getspanset(sess, &boolset->val, ISPANID))
00628 return false;
00629
00630
00631 boolset->itemid = NODEID;
00632 *boolsetptr = boolset;
00633 boolsetptr = &boolset->next;
00634 }
00635 }