mirror of
https://github.com/SEPPDROID/Digital-Research-Source-Code.git
synced 2025-10-23 08:24:18 +00:00
1 line
4.4 KiB
C
1 line
4.4 KiB
C
/* -*-c,save-*- */
|
||
|
||
/*
|
||
|
||
* quest.c - QUEST function
|
||
|
||
* Robert Heller. Created: Wed Mar 5, 1986 19:35:17.95
|
||
|
||
* Last Mod:
|
||
|
||
*
|
||
|
||
* (c) Copyright 1986 by Robert Heller
|
||
|
||
* All Rights Reserved
|
||
|
||
*
|
||
|
||
*
|
||
|
||
*/
|
||
|
||
|
||
|
||
#include <stdio.h>
|
||
|
||
|
||
|
||
#include "patdef.h"
|
||
|
||
|
||
|
||
#define LOCAL static
|
||
|
||
|
||
|
||
/* #define DEBUG /* debuging */
|
||
|
||
|
||
|
||
#ifdef DEBUG
|
||
|
||
#define LOCAL /* static */
|
||
|
||
#endif
|
||
|
||
|
||
|
||
LOCAL PATTERN_NODE *NEUT,*QUEST_QPA,*ID_V;
|
||
|
||
LOCAL PATTERN_NODE *BRA_QP1,*BRA_QN,*BRA_QVP_QL,*LO_HI,*BRASL;
|
||
|
||
ARG_DESCR *acons();
|
||
|
||
LOCAL STRING_DESCR QPA,V,QP1,QN,QVP,QL,QLOW,QHI;
|
||
|
||
char *malloc();
|
||
|
||
#include "phrase.h"
|
||
|
||
|
||
|
||
que_init()
|
||
|
||
{
|
||
|
||
ph_init();
|
||
|
||
NEUT = breakk_c("|()");
|
||
|
||
QUEST_QPA = concat(NEUT,
|
||
|
||
concat(c_lit_string("("),
|
||
|
||
concat(cassign(NEUT,acons(STRING,&QPA)),
|
||
|
||
concat(c_lit_string(")"),
|
||
|
||
alt(NEUT,REM)))));
|
||
|
||
ID_V = cassign(alt(span_c("0123456789"),NIL),acons(STRING,&V));
|
||
|
||
BRA_QP1 = concat(cassign(breakk_c("|"),acons(STRING,&QP1)),
|
||
|
||
c_lit_string("|"));
|
||
|
||
BRA_QN = concat(cassign(breakk_c("("),acons(STRING,&QN)),
|
||
|
||
c_lit_string("("));
|
||
|
||
BRA_QVP_QL = concat(cassign(breakk_c(")"),acons(STRING,&QVP)),
|
||
|
||
concat(c_lit_string(")"),
|
||
|
||
cassign(REM,acons(STRING,&QL))));
|
||
|
||
LO_HI = concat(cassign(breakk_c("."),acons(STRING,&QLOW)),
|
||
|
||
concat(c_lit_string("..."),
|
||
|
||
cassign(REM,acons(STRING,&QHI))));
|
||
|
||
BRASL = breakk_c("/");
|
||
|
||
}
|
||
|
||
quest(qs,argv)
|
||
|
||
register char *qs;
|
||
|
||
long int argv;
|
||
|
||
{
|
||
|
||
static STRING_DESCR matched;
|
||
|
||
register char *qp;
|
||
|
||
static char qmess[132],qi[132],qp1[132],fool[256];
|
||
|
||
register int len,stat;
|
||
|
||
|
||
|
||
if (pmatch(qs,BRASL,&matched) != MATCH_SUCCESS) return(-1);
|
||
|
||
len = matched.length;
|
||
|
||
if (len > 131) len = 131;
|
||
|
||
strncpy(qmess,matched.base+matched.offset,len);
|
||
|
||
qmess[len] = '\0';
|
||
|
||
qp = matched.base+matched.offset+matched.length+1;
|
||
|
||
for (;;) {
|
||
|
||
printf("\n%s? ",qmess);
|
||
|
||
gets(qi);
|
||
|
||
stat = questp(qi,qp,&argv);
|
||
|
||
if (stat >= 0) return(stat);
|
||
|
||
strcpy(qp1,qp);
|
||
|
||
while (pmatch(qp1,QUEST_QPA,&matched) == MATCH_SUCCESS) {
|
||
|
||
strncpy(matched.base+matched.offset,QPA.base+QPA.offset,
|
||
|
||
QPA.length);
|
||
|
||
strcpy(matched.base+matched.offset+QPA.length,
|
||
|
||
matched.base+matched.offset+matched.length);
|
||
|
||
}
|
||
|
||
if (strcmp(qi,"?") != 0) {
|
||
|
||
rsentence("Bad input, you <STUPID> <FOOL>.",fool);
|
||
|
||
printf("%s\n",fool);
|
||
|
||
}
|
||
|
||
printf("The correct form is %s\n",qp1);
|
||
|
||
}
|
||
|
||
}
|
||
|
||
LOCAL questp(qs,qp,argv)
|
||
|
||
register char *qs,*qp;
|
||
|
||
register long int *argv;
|
||
|
||
{
|
||
|
||
STRING_DESCR matched;
|
||
|
||
char qp1[132],qvp[132];
|
||
|
||
register int len,stat,qnn,qln;
|
||
|
||
register int qsn,qlown,qhin;
|
||
|
||
register int *qnp;
|
||
|
||
|
||
|
||
while (pmatch(qp,BRA_QP1,&matched) == MATCH_SUCCESS) {
|
||
|
||
len = QP1.length;
|
||
|
||
if (len > 131) len = 131;
|
||
|
||
strncpy(qp1,QP1.base+QP1.offset,len);
|
||
|
||
qp1[len] = '\0';
|
||
|
||
qp = matched.base+matched.offset+matched.length;
|
||
|
||
stat = questp(qs,qp1,argv);
|
||
|
||
if (stat >= 0) return(stat);
|
||
|
||
}
|
||
|
||
if (pmatch(qp,BRA_QN,&matched) != MATCH_SUCCESS) return(-1);
|
||
|
||
qp = matched.base+matched.offset+matched.length;
|
||
|
||
if (QN.length == 0) qnn = -1;
|
||
|
||
else qnn = atoi(QN.base+QN.offset);
|
||
|
||
pmatch(qp,BRA_QVP_QL,&matched);
|
||
|
||
strncpy(qvp,QVP.base+QVP.offset,QVP.length);
|
||
|
||
qvp[QVP.length] = '\0';
|
||
|
||
if (QL.length > 0) qln = atoi(QL.base+QL.offset);
|
||
|
||
else qln = 0;
|
||
|
||
if (strcmp(qvp,"ARB") == 0) {
|
||
|
||
if (qnn != -1) strcpy(argv[qnn],qs);
|
||
|
||
return(qln);
|
||
|
||
}
|
||
|
||
else if (pmatch(qvp,LO_HI,&matched) == MATCH_SUCCES) {
|
||
|
||
if (!isnumber(qs,strlen(qs))) return(-1);
|
||
|
||
qsn = atoi(qs);
|
||
|
||
if (!isnumber(QLOW.base+QLOW.offset,QLOW.length)) return(-1);
|
||
|
||
#ifdef DEBUG
|
||
|
||
printf("***In questp(): &qvp[0] = %08X, QLOW(base = %08X, offset = %d, length = %d\n",
|
||
|
||
qvp,QLOW.base,QLOW.offset,QLOW.length);
|
||
|
||
#endif
|
||
|
||
qlown = atoi(QLOW.base+QLOW.offset);
|
||
|
||
if (!isnumber(QHI.base+QHI.offset,QHI.length)) return(-1);
|
||
|
||
qhin = atoi(QHI.base+QHI.offset);
|
||
|
||
#ifdef DEBUG
|
||
|
||
printf("***In questp(): qvp=%s,qsn=%d,qlown=%d,qhin=%d\n",qvp,qsn,
|
||
|
||
qlown,qhin);
|
||
|
||
#endif
|
||
|
||
if (qlown > qsn) return(-1);
|
||
|
||
if (qsn > qhin) return(-1);
|
||
|
||
if (qnn != -1) {
|
||
|
||
qnp = (short int *) argv[qnn];
|
||
|
||
*qnp = qsn;
|
||
|
||
}
|
||
|
||
return(qln);
|
||
|
||
}
|
||
|
||
else if (strcmp(qs,qvp) == 0) {
|
||
|
||
if (qnn != -1) strcpy(argv[qnn],qs);
|
||
|
||
return(qln);
|
||
|
||
}
|
||
|
||
else return(-1);
|
||
|
||
}
|
||
|
||
LOCAL isnumber(s,l)
|
||
|
||
register char *s;
|
||
|
||
register int l;
|
||
|
||
{
|
||
|
||
char *index();
|
||
|
||
|
||
|
||
while (l-- > 0) {
|
||
|
||
if (index("0123456789",*s) == 0L) return(0);
|
||
|
||
s++;
|
||
|
||
}
|
||
|
||
return(1);
|
||
|
||
}
|
||
|
||
|