/* This is the code for learning affixes and primitives */ #include "MacTeach23.h" //#include "teach1.h" #include void main(void) /* This is the main file. It initializes the Mac, opens the resource file if necessary, initializes the teach source and enters the event loop */ { initMac(); initteach(); eventloop(); } void doseek(void) /* This routine displays the lookup dialog. It selects for prims or affixes depending on whether it is MT2 or MT3. A modal dialog allows one to change the default selection, or do a text search. Invalid control buttons are hidden. */ { enum {dSearch=1,dDone,dEword,dAffix,dLword,dText}; DialogRecord dRecord; /*Dialog record storage*/ DialogPtr lDialog; /* Dialog pointer of lookup dialog*/ Handle lookHdl[7]; /*used for storing handles of items in search dialog*/ short ctlno,i,itemHit,theType; short j; char txt[30]; char *str; const short lookupID = 5; /* Resource # of lookup dialog */ lDialog = GetNewDialog(lookupID,&dRecord,(DialogPtr)-1L); if (gSDI) SetDialogCancelItem(lDialog,2); for (i=1; i<7; ++i) GetDialogItem(lDialog,i,&theType,&lookHdl[i],&gItemBox); ctlno = (prog=='2') ?dAffix : dLword; SetControlValue((ControlHandle)lookHdl[ctlno],BtnOn); outlin(dSearch,lDialog); while(1) { ModalDialog(0L,&itemHit); switch(itemHit) { case dSearch: HideControl((ControlHandle)lookHdl[dSearch]); HideControl((ControlHandle)lookHdl[dDone]); GetDialogItemText(lookHdl[dText],(unsigned char *)txt); PtoCstr((unsigned char *)txt); j = 0; for (i=0; i= '5' + drillflg) flasharray[n].flag[curflag] = '1'; } } void setaffix(short val) /* On entry val represents an affixflag which should be '0' or '1' (30H or 31H). A new value is set. As changing this value causes the program to end a session, the number tested is reset. The value prog indicates the mode of the program. '4' is for recalling affix sets, '2' for recognizing single affixes. Other values are for Recall and recognition of primitives. The appropriate window items are adjusted accordingly. The ladder is then displayed*/ { tested = 0; if (prog=='4') { SetControlTitle((ControlHandle)gMainHdl[18], (unsigned char *)"\pRecognize the source of an affix set"); SetControlTitle((ControlHandle)gMainHdl[19], (unsigned char *)"\pRecall all the affixes of a given source"); } else if (prog=='2') { SetControlTitle((ControlHandle)gMainHdl[18], (unsigned char *)"\pRecognize the source of a given affix"); SetControlTitle((ControlHandle)gMainHdl[19], (unsigned char *)"\pRecall all the affixes of a given source"); } else{ SetControlTitle((ControlHandle)gMainHdl[18], (unsigned char *)"\pRecognize the English meaning"); SetControlTitle((ControlHandle)gMainHdl[19], (unsigned char *)"\pRecall the Loglan word"); } affixflag = val; /*Reset the flag*/ display(); } void show4(short n) /* On entry n is the card number whose field4 is to be displayed. This is the 'primitive' field, which must be converted to a Pascal string */ { strcpy(instring,flasharray[n].prim); SetDialogItemText(gItemHdl[fPrim],CtoPstr(instring)); } void show5(short n) /* On entry n is the card number whose field5 is to be displayed. This is the 'affix' field, which must be converted to a Pascal string */ { sprintf(instring,"%s",flasharray[n].affix); SetDialogItemText(gItemHdl[fAffix],CtoPstr(instring)); } void show611(short n) /* On entry n is the card number whose fields 6 and 11 are to be displayed. These is the 'English' field, and the English extension field. Before printing hyphens must be converted to spaces, and underlines to hyphens for the entire text, and then the text is split at the first '/'. The first part is field 6. The second part, if present, is field 11. If field 11 is present, field 9 'Or' is also printed. The strings must be converted to Pascal strings for Mac display */ { char *rest; mycpy(instring,flasharray[n].trans); rest = instring; while (*rest++) { if (*(rest-1) == '-') *(rest-1) = ' '; if (*(rest-1) == '_') *(rest-1) = '-'; } rest = instring; while ( *rest++ != '/' && *rest){} if (*rest) *(rest-1) = NUL; if (*rest && strlen(rest)) { SetDialogItemText(gItemHdl[fSyn],CtoPstr(rest)); SetDialogItemText(gItemHdl[9],(unsigned char *)"\pOr:"); } SetDialogItemText(gItemHdl[fTrans],CtoPstr(instring)); } void show7(short n) /* On entry n is the card number whose field 7 is to be displayed. This is the 'English extension' field, which must be converted to a Pascal string */ { sprintf(instring,"(%s)",flasharray[n].extn); SetDialogItemText(gItemHdl[fExtn],CtoPstr(instring)); } short showsel(short n) /* On entry n is the card number to be displayed for selection purposes. showcard is called to display the modal dialog, and then the various fields are displayed. A selection count is maintained and displayed. On leaving the itemHit is returned, which indicates whether the next, pass, or quit button was selected.*/ { char mystr[15]; short itemHit; showcard(cSelect); show4(n); show5(n); show611(n); show7(n); sprintf(mystr,"%3d Selected.",selection); /* JPJ: changed \p string to c-string */ SetDialogItemText(gItemHdl[3],CtoPstr(mystr)); ++selection; ModalDialog(0L,&itemHit); CloseDialog(gTestDialog); return itemHit; } short showtest(short n, short dlgid) /* This is used for display of a card n for review or test. These are different dialogs whose number is given in dlgid on entry.*/ {// pascal Boolean Timeget(); /* measures time to first keystroke */ short itemHit; char mystr[15]; showcard(dlgid); switch(curflag) { case 0: show4(n); show5(n); break; case 3: show4(n); break; case 1: show611(n); show7(n); break; case 2: show5(n); break; default: break; } if (reviewflag) { /*Review displays card&count, returns user choice*/ sprintf(mystr,"%3d Left",left); /* JPJ: removed \p-string */ SetDialogItemText(gItemHdl[3],CtoPstr(mystr)); --left; ModalDialog(NewModalFilterProc((ProcPtr)Timeget),&itemHit); if (itemHit==fStop) { CloseDialog(gTestDialog); return itemHit; } } else { macticks = TickCount(); /*elapsed time to first keystroke*/ ind1 = 0; countflag(); /* find count in each rung including EB & Top*/ sprintf(mystr,"%3d Left",r[rungflag-'0']); /* JPJ: removed \p string */ SetDialogItemText(gItemHdl[12],CtoPstr(mystr)); ModalDialog(NewModalFilterProc((ProcPtr)Timeget),&itemHit); if (itemHit==fStop) { CloseDialog(gTestDialog); return itemHit; } GetDialogItemText(gItemHdl[fIn],(unsigned char *)instring); /*Read user entry*/ PtoCstr((unsigned char *)instring); statdo(ticks); /* update the statistics */ switch(curflag) { /*test for correctness*/ case 0: strcpy(istring,flasharray[n].trans); mycomp(istring,instring) ? promote(n) : demote(n); break; case 1: case 2: strcmp(instring,flasharray[n].prim)? demote(n):promote(n); break; case 3: strcmp(instring,flasharray[n].affix)? demote(n):promote(n); break; } } switch(curflag) { /*Display the correct answer */ case 1: show4(n); show5(n); break; case 3: case 0: case 2: show4(n); show5(n); show611(n); show7(n); break; } ModalDialog(0L,&itemHit); /*Wait for user response*/ CloseDialog(gTestDialog); return itemHit; }