home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The World of Computer Software
/
World_Of_Computer_Software-02-385-Vol-1of3.iso
/
d
/
dir_nm20.zip
/
Dir_NM_2.0
/
NM-Speak.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-07-16
|
19KB
|
655 lines
/* === NM-Speak.c ===
*
* int same(st1,st2)
* void into(newstate,wd,nxt,LINK)
* void ar(x,y)
* void gi(x,y)
* void ae(x,y)
* void j_(x,y)
* void au(x,y)
* void the(x,y)
* void sthe(x,y)
* void sh(x,y)
* void aee(x,y)
* void er(x,y)
* void wordin(LINK)
* void Word_I_O(ch_)
* void pronounce(word)
* void spell(word)
* void speak(word)
*
* void Tell(afile)
* void Voice(ch)
*
*/
#include "NM.h"
int i;
int same(st1,st2)
char *st1,*st2;
{
int k,short_;
if (strlen(st1)>strlen(st2)) short_=strlen(st2);else short_=strlen(st1);k=0;
do { k++; } while (toupper(st1[k-1])==toupper(st2[k-1]) && k!=short_);
if (toupper(st1[k-1])>toupper(st2[k-1])) return -1;
else
{
if (toupper(st1[k-1])<toupper(st2[k-1])) return 1;
else if (strlen(st1)>strlen(st2)) return -1;
else if (strlen(st1)<strlen(st2)) return 1;else return 0;
}
}
/* Local variables for Word_I_O: */
struct LOC_Word_I_O
{
char ch;
};
void into(newstate,wd,nxt)
stater **newstate,*nxt;
char *wd;
{
stater *WITH;
*newstate=(stater *)malloc(sizeof(stater));WITH=*newstate;
strcpy(WITH->word,wd);memcpy(WITH->say,sy,sizeof(ary16));WITH->nxtone=nxt;
}
void ar(x,y)
int x,y;
{
DrawEllipse(x,y,9,16,0,360);Line(x+9,y+7,x+12,y+17);
}
void gi(x,y)
int x,y;
{
Line(x-5,y-6,x+5,y-6);Line(x+3,y-6,x+1,y-1);Line(x+1,y-1,x+1,y+5);
DrawEllipse(x-5,y+1,6,8,0,-180);
}
void ae(x,y)
int x,y;
{
DrawEllipse(x,y,9,13,0,150);DrawEllipse(x,y,9,13,0,-170);
Line(x,y+8,x+9,y+8);
}
void j_(x,y)
int x,y;
{
Line(x,y,x,y+4);DrawEllipse(x-6,y,6,8,0,-180);
}
void au(x,y)
int x,y;
{
DrawEllipse(x,y,9,13,0,150);DrawEllipse(x,y,9,13,0,-160);
}
void the(x,y)
int x,y;
{
Line(x-2,y+1,x+8,y-9);DrawEllipse(x-11,y-6,20,28,0,100);
DrawEllipse(x+1,y+2,8,11,0,360);
}
void sthe(x,y)
int x,y;
{
DrawEllipse(x,y,9,15,0,360);Line(x,y+7,x+9,y+7);
}
void sh(x,y)
int x,y;
{
DrawEllipse(x-1,y,7,10,0,180);Line(x,y+4,x,y+15);
}
void aee(x,y)
int x,y;
{
DrawEllipse(x,y+2,8,7,22,190);Line(x+2,y+9,x+8,y+9);
DrawEllipse(x,y+7,10,9,-22,-190);
}
void er(x,y)
int x,y;
{
Line(x-6,y+14,x,y);Line(x,y,x+6,y+14);
}
void wordin(LINK)
struct LOC_Word_I_O *LINK;
{
int i,k,nx,ny,nz,mz;
XImage *back;
char STR1[256];
Rub(0,0,1139,862,"MediumBlue");XSetFunction(display,gc,GXcopy);
XSetLineAttributes(display,gc,2,0,0,0);SetColor("white");
DrawRectangle(320,200,500,400);Rub(321,201,498,398,"NavyBlue");
SetColor("white");for (i=1;i<=9;i++) Line(i*50+320,201,i*50+320,599);
for (i=1;i<=9;i++) Line(321,i*40+200,819,i*40+200);
S_bf=(char *)malloc(10);*S_bf='\0';
for (i=0;i<=9;i++)
{
for (k=0;k<=9;k++)
{
switch (i)
{
case 0:switch (k)
{
case 0:strcpy(S_bf," ");break;
case 1:strcpy(S_bf,"^^");break;
case 2:strcpy(S_bf," :");break;
case 3:strcpy(S_bf,"ai");break;
case 4:strcpy(S_bf,"au");break;
case 5:strcpy(S_bf,"b ");break;
case 6:strcpy(S_bf,"d ");break;
case 7:strcpy(S_bf,"d ");break;
case 8:strcpy(S_bf,"e ");break;
case 9:strcpy(S_bf,"ei");break;
}
break;
case 1:switch (k)
{
case 0:strcpy(S_bf,"f ");break;
case 1:strcpy(S_bf,"g ");break;
case 2:strcpy(S_bf,"h ");break;
case 3:strcpy(S_bf,"i ");break;
case 4:strcpy(S_bf,"i:");break;
case 5:strcpy(S_bf,"i ");break;
case 6:strcpy(S_bf,"j ");break;
case 7:strcpy(S_bf,"k ");break;
case 8:strcpy(S_bf,"l ");break;
case 9:strcpy(S_bf,"m ");break;
}
break;
case 2:switch (k)
{
case 0:strcpy(S_bf,"n ");break;
case 1:strcpy(S_bf,"n ");break;
case 2:strcpy(S_bf,"o ");break;
case 3:strcpy(S_bf,"ou");break;
case 4:strcpy(S_bf,"p ");break;
case 5:strcpy(S_bf,"r ");break;
case 6:strcpy(S_bf,"s ");break;
case 7:strcpy(S_bf,"t ");break;
case 8:strcpy(S_bf,"t");break;
case 9:strcpy(S_bf,"u ");break;
}
break;
case 3:switch (k)
{
case 0:strcpy(S_bf,"u:");break;
case 1:strcpy(S_bf,"u ");break;
case 2:strcpy(S_bf,"v ");break;
case 3:strcpy(S_bf,"w ");break;
case 4:strcpy(S_bf,"z ");break;
case 5:strcpy(S_bf," ");break;
case 6:strcpy(S_bf," ");break;
case 7:strcpy(S_bf," :");break;
case 8:strcpy(S_bf," i");break;
case 9:strcpy(S_bf," ");break;
}
break;
case 4:switch (k)
{
case 0:strcpy(S_bf," ");break;
case 1:strcpy(S_bf," :");break;
case 2:strcpy(S_bf," ");break;
case 3:strcpy(S_bf," e");break;
case 4:strcpy(S_bf," ");break;
case 5:strcpy(S_bf," ");break;
case 6:strcpy(S_bf," ");break;
case 7:strcpy(S_bf," ");break;
case 8:strcpy(S_bf," ");break;
case 9:strcpy(S_bf," ");break;
}
break;
case 5:switch (k)
{
case 0:strcpy(S_bf," ");break;
case 1:strcpy(S_bf," ");break;
case 2:strcpy(S_bf," ");break;
case 3:strcpy(S_bf," ");break;
case 4:strcpy(S_bf," ");break;
case 5:strcpy(S_bf," ");break;
case 6:strcpy(S_bf," ");break;
case 7:strcpy(S_bf," ");break;
case 8:strcpy(S_bf," ");break;
case 9:strcpy(S_bf," ");break;
}
break;
case 6:switch (k)
{
case 0:strcpy(S_bf,",");break;
case 1:strcpy(S_bf,". ");break;
case 2:strcpy(S_bf,"; ");break;
case 3:strcpy(S_bf,": ");break;
case 4:strcpy(S_bf,"` ");break;
case 5:strcpy(S_bf,"' ");break;
case 6:strcpy(S_bf,"\"");break;
case 7:strcpy(S_bf,"? ");break;
case 8:strcpy(S_bf,"! ");break;
case 9:strcpy(S_bf,"# ");break;
}
break;
case 7:switch (k)
{
case 0:strcpy(S_bf,"1 ");break;
case 1:strcpy(S_bf,"2 ");break;
case 2:strcpy(S_bf,"3 ");break;
case 3:strcpy(S_bf,"4 ");break;
case 4:strcpy(S_bf,"5 ");break;
case 5:strcpy(S_bf,"6 ");break;
case 6:strcpy(S_bf,"7 ");break;
case 7:strcpy(S_bf,"8 ");break;
case 8:strcpy(S_bf,"9 ");break;
case 9:strcpy(S_bf,"0 ");break;
}
break;
case 8:switch (k)
{
case 0:strcpy(S_bf,"+ ");break;
case 1:strcpy(S_bf,"- ");break;
case 2:strcpy(S_bf,"* ");break;
case 3:strcpy(S_bf,"/ ");break;
case 4:strcpy(S_bf,"< ");break;
case 5:strcpy(S_bf,"= ");break;
case 6:strcpy(S_bf,"> ");break;
case 7:strcpy(S_bf,"% ");break;
case 8:strcpy(S_bf,"& ");break;
case 9:strcpy(S_bf,"| ");break;
}
break;
case 9:switch (k)
{
case 0:strcpy(S_bf,"$ ");break;
case 1:strcpy(S_bf,"@ ");break;
case 2:strcpy(S_bf,"~ ");break;
case 3:strcpy(S_bf,"_ ");break;
case 4:strcpy(S_bf,"( ");break;
case 5:strcpy(S_bf,") ");break;
case 6:strcpy(S_bf,"[ ");break;
case 7:strcpy(S_bf,"] ");break;
case 8:strcpy(S_bf,"{ ");break;
case 9:strcpy(S_bf,"} ");break;
}
break;
}/* case */
SetColor("white");
if (i==4 && k==6) OutTextXY(k*50+337,i*40+230,S_bf);
else OutTextXY(k*50+337,i*40+230,S_bf);
}
}
ar(437,213);gi(705,227);ae(600,255);j_(396,309);sh(754,293);j_(754,306);
ae(401,336);gi(595,346);au(636,335);au(686,335);au(736,335);au(786,335);
ae(799,335);ae(337,376);ae(387,376);ae(449,376);ae(489,375);aee(435,374);
sthe(538,374);sh(593,372);j_(593,385);er(643,376);the(687,379);*wd='\0';
back=XGetImage(display,win,320,200,50,40,8,ZPixmap);i=1;nx=0;ny=0;nz=0;mz=0;
DrawRectangle(21,658,363,42);Rub(22,659,361,40,"magenta");SetColor("green");
OutTextXY(43,687,"Word spelling Unit group");
OutTextXY(450,160,"\\--finish Ecs--exit");highlight(20,736,20,25);
do {
do { } while (!(LINK->ch=GetKey()));
if (LINK->ch == '}' || LINK->ch == '{' || LINK->ch == ']' ||
LINK->ch == '[' || LINK->ch == '~' || LINK->ch == '`' ||
LINK->ch == '@' || LINK->ch == '|' ||
(LINK->ch & 255) >= 224 && (LINK->ch & 255) <= 228 ||
LINK->ch >= '[' && LINK->ch <= '\'' ||
LINK->ch >= '!' && LINK->ch <= '?' || LINK->ch == ' ' ||
isalpha(LINK->ch))
{
sprintf(wd+strlen(wd),"%c",LINK->ch);sprintf(STR1,"%c",LINK->ch);
highlight(i*20,736,20,25);
if (LINK->ch != '!') { SetColor("green");OutTextXY(i*20,760,STR1); }
i++;highlight(i*20,736,20,25);
}
} while (LINK->ch != '!' && LINK->ch != '\\' && LINK->ch != '&');
if (LINK->ch=='\\' || LINK->ch=='&') return;highlight(i*20,736,20,25);
k=0;highlight(400,730,50,40);highlight(320,200,50,40);
do {
LINK->ch=GetKey();
if (LINK->ch=='@' || LINK->ch=='>' || LINK->ch=='<' || LINK->ch =='?')
{
highlight(nx*50+320,ny*40+200,50,40);
switch (LINK->ch)
{
case '<':if (nx==0) nx=9;else nx--;break;
case '>':if (nx==9) nx=0;else nx++;break;
case '?':if (ny==0) ny=9;else ny--;break;
case '@':if (ny==9) ny=0;else ny++;break;
}
back=XGetImage(display,win,nx*50+320,ny*40+200,50,40,8,ZPixmap);
highlight(nx*50+320,ny*40+200,50,40);k=ny*10+nx;
}
else if (LINK->ch=='C'||LINK->ch=='Z')
{
highlight(nz*50+400,730,50,40);
if (LINK->ch=='Z') { if (nz>0) nz--;else nz=mz; }
else { if (nz==mz) nz=0;else nz++; }
highlight(nz*50+400,730,50,40);
} else if (LINK->ch=='!')
{
highlight(nz*50+400,730,50,40);
XPutImage(display,win,gc,back,0,0,nz*50+400,730,50,40);
if (nz<15)
{
nz++;if (nz>mz) mz=nz;
highlight(nz*50+400,730,50,40);sy[nz-1]=k;
}
else LINK->ch = '\\';
}
} while (LINK->ch != '\\' && LINK->ch != '&');
sy[mz]=0;free(back);
}
void Word_I_O(ch_)
char ch_;
{
int k;
struct LOC_Word_I_O V;
stater *WITH;
char *TEMP;
V.ch = ch_;
if ((wordfile=fopen("Dir_Song/IM.wrd","r"))!=NULL)
{
rewind(wordfile);size=1;mid=(midstate *)malloc(sizeof(midstate));
firststate=(stater *)malloc(sizeof(stater));
atstate=(stater *)malloc(sizeof(stater));
laststate=(stater *)malloc(sizeof(stater));
newstate=(stater *)malloc(sizeof(stater));
fread(mid,sizeof(midstate),1,wordfile);WITH=firststate;
strcpy(WITH->word,mid->word);memcpy(WITH->say,mid->say,sizeof(ary16));
WITH->nxtone=newstate;
while (!feof(wordfile))
{
size++;fread(mid,sizeof(midstate),1,wordfile);
strcpy(newstate->word,mid->word);
memcpy(newstate->say,mid->say,sizeof(ary16));
atstate=newstate;newstate=(stater *)malloc(sizeof(stater));
atstate->nxtone=newstate;
}
/* p2c: sp1.pas, line 177:
* Warning: Procedure release not yet supported [118] */
/* release((Anyptr)(&newstate)); */
atstate->nxtone=NULL;laststate=atstate;atstate=firststate;
if (wordfile != NULL) fclose(wordfile);
}
else
{
mid=(midstate *)malloc(sizeof(midstate));
firststate=(stater *)malloc(sizeof(stater));
atstate=(stater *)malloc(sizeof(stater));
laststate=(stater *)malloc(sizeof(stater));
newstate=(stater *)malloc(sizeof(stater));
WITH=newstate;strcpy(WITH->word,"A");WITH->say[0]=9;
WITH->say[1]=0;WITH->nxtone=NULL;firststate=newstate;
newstate=(stater *)malloc(sizeof(stater));WITH=newstate;
strcpy(WITH->word,"Z");WITH->say[0]=34;WITH->say[1]=14;WITH->say[2]=0;
WITH->nxtone=NULL;laststate=newstate;firststate->nxtone=laststate;
atstate=firststate;
if (wordfile != NULL) rewind(wordfile);else wordfile=tmpfile();
WITH=firststate;strcpy(mid->word,WITH->word);
memcpy(mid->say,WITH->say,sizeof(ary16));
fwrite(mid,sizeof(midstate),1,wordfile);WITH=laststate;
strcpy(mid->word,WITH->word);memcpy(mid->say,WITH->say,sizeof(ary16));
fwrite(mid,sizeof(midstate),1,wordfile);
if (wordfile != NULL) fclose(wordfile);size=2;
}
if (toupper(V.ch)=='I')
{
do {
wordin(&V);
if (*wd !='\0')
{
if (same(wd,atstate->word)==-1)
{
do {
laststate=atstate;atstate = atstate->nxtone;
} while (!((atstate->nxtone==NULL) | (same(wd,atstate->
word)==1) | (same(wd, atstate->word) == 0)));
if (same(wd,atstate->word)==0)
memcpy(atstate->say,sy,sizeof(ary16));
else if (same(wd,atstate->word) == 1)
{
into(&newstate,wd,atstate);
laststate->nxtone=newstate;
}
else
{
into(&newstate,wd,NULL);
atstate->nxtone=newstate;
}
}
else if (same(wd,atstate->word)==1)
{
if (same(wd,firststate->word)==1)
{
into(&newstate,wd,firststate);
firststate=newstate;atstate=newstate;
}
else
{
atstate=firststate;
do {
laststate=atstate;atstate=atstate->nxtone;
} while (!((same(wd,atstate->word)==1) |
(same(wd,atstate->word)==0)));
if (same(wd, atstate->word)==1)
{
into(&newstate,wd,atstate);
laststate->nxtone=newstate;
}
else memcpy(atstate->say, sy, sizeof(ary16));
}
}
else memcpy(atstate->say, sy, sizeof(ary16));
}
} while (V.ch != '&');
if (wordfile!=NULL) rewind(wordfile);else wordfile=tmpfile();
atstate=firststate;
while (atstate != NULL)
{
WITH = atstate;strcpy(mid->word,WITH->word);
memcpy(mid->say,WITH->say,sizeof(ary16));
fwrite(mid,sizeof(midstate),1,wordfile);atstate=atstate->nxtone;
}
if (wordfile != NULL) fclose(wordfile);
}
if (V.ch=='O')
{
XClearWindow(display,win);atstate = firststate;i = 1;k = 0;
while (atstate != NULL)
{
WITH=atstate;OutTextXY((int)i,70,WITH->word);j=1;
do {
printf("%3ld", WITH->say[j - 1]);j++;
} while (WITH->say[j - 1] != 0);
if (i==1) i=41;else { i=1;putchar('\n'); }
atstate = atstate->nxtone;k++;if (k % 46 != 0) continue;
OutTextXY(23, 70,"Esc--exit Bar--continue ...\n");
V.ch=GetKey();if (V.ch=='&') return;
}
putchar('\n');OutTextXY(33,80," words");Out_I_XY(33,80,size);
do { } while ((ch = GetKey())!=NULL);V.ch = GetKey();
}
if (V.ch=='D')
{
XClearWindow(display,win);;printf("which word ?");fgets(wd,17,stdin);
TEMP=strchr(wd,'\n');if (TEMP != NULL) *TEMP=0;
if (same(wd,firststate->word)==0) firststate=firststate->nxtone;
else
{
atstate=firststate;
do {
laststate=atstate;atstate=atstate->nxtone;
} while (same(wd,atstate->word) != 0 && atstate != NULL);
if (atstate==NULL) return;laststate->nxtone=atstate->nxtone;
}
if (wordfile != NULL) rewind(wordfile);else wordfile=tmpfile();
atstate=firststate;
while (atstate != NULL)
{
WITH=atstate;strcpy(mid->word,WITH->word);
memcpy(mid->say,WITH->say,sizeof(ary16));
fwrite(mid, sizeof(midstate),1,wordfile);atstate=atstate->nxtone;
}
if (wordfile != NULL) fclose(wordfile);
}
}
void pronounce(word)
char *word;
{
int i;
stater *WITH;
i=1;WITH=atstate;
do { ptr_.nt[0]=-WITH->say[i-1];Play();i++; } while (WITH->say[i-1]!=0);
/* delay(77); */
}
void spell(word)
char *word;
{
int i;
char STR1[256];
/* sound(360);delay(600);nosound();delay(700); */
i=1;
do {
atstate=firststate;
while (toupper(word[i-1])!=toupper(atstate->word[0]))
atstate=atstate->nxtone;
sprintf(STR1,"%c",word[i-1]);pronounce(STR1); /* delay(690); */
i++;
} while (i <= strlen(word));
/* delay(700);sound(327);delay(500);nosound();delay(700); */
}
void speak(word)
char *word;
{
int i,none;
char STR1[18];
atstate=firststate;none=0;i=0;
do {
i++;
while (toupper(word[i-1])!=toupper(atstate->word[i-1]) && !none)
{
laststate=atstate;atstate=atstate->nxtone;
sprintf(STR1,"%sS",laststate->word);
if ((atstate==NULL) | (same(word,atstate->word)==1) |
(same(STR1,word)==0))
none = 1;
}
} while (!(i==strlen(word) || none));
if (!none) { pronounce(word);return; } sprintf(STR1,"%sS",laststate->word);
if (same(STR1, word) != 0) { spell(word);return; }
ptr_.nt[0]=-26;ptr_.at=0;ptr_.cm=0;pronounce(word);Play();
}
void Tell(afile)
char *afile;
{
char buffer[1048],st[17],STR1[256];
filvar=fopen(afile,"r");rewind(filvar);setvbuf(filvar, buffer, _IOFBF, 1048);
/* Note: Make sure setvbuf() call occurs when file is open [200] */
while (!feof(filvar))
{
ch=getc(filvar);if (ch=='\n') ch=' ';*st='\0';
switch (ch)
{
case ' ':
case '\n':
case '\015':
case '\033':putchar(ch);break;
default:if (ch >= '!' && ch <= '?' || ch >= '[' && ch <= '\'' ||
(ch & 255)>=224 && (ch & 255)<=228 || (ch & 255)==234 ||
ch=='|' || ch=='@' || ch=='`' || ch=='~' || ch=='[' ||
ch == ']' || ch == '{' || ch == '}')
{ putchar(ch);sprintf(STR1,"%c",ch);speak(STR1); }
else if (isalpha(ch))
{
sprintf(st,"%c",ch);putchar(ch);
do {
if (strlen(st)==16) *st='\0';ch=getc(filvar);
if (ch=='\n') ch=' ';putchar(ch);
if (isalpha(ch)) sprintf(st+strlen(st),"%c",ch);
} while (isalpha(ch));
speak(st);*st = '\0';
if (ch!='\n' && ch!='\015' && ch!='\033' && ch!=' ')
{ sprintf(STR1,"%c",ch);speak(STR1); }
}
break;
}/*case*/
}
/* else begin write(ch);delay(2000);halt;end;*/
}
void Voice(ch)
char ch;
{
int k;
char str[256],STR1[256],*TEMP;
stater *WITH;
if ((wordfile=fopen("Dir_Song/IM.wrd","r"))==NULL) return;
printf("--- Voice ---\n\n");S_bf=(char *)malloc(17);*S_bf='\0';
rewind(wordfile);mid=(midstate *)malloc(sizeof(midstate));
firststate=(stater *)malloc(sizeof(stater));
atstate=(stater *)malloc(sizeof(stater));
laststate=(stater *)malloc(sizeof(stater));
newstate=(stater *)malloc(sizeof(stater));
fread(mid,sizeof(midstate),1,wordfile);
WITH=firststate;strcpy(WITH->word,mid->word);
memcpy(WITH->say, mid->say, sizeof(ary16));WITH->nxtone=newstate;
while (!feof(wordfile))
{
fread(mid,sizeof(midstate),1,wordfile);strcpy(newstate->word,mid->word);
memcpy(newstate->say,mid->say,sizeof(ary16));atstate=newstate;
newstate=(stater *)malloc(sizeof(stater));atstate->nxtone=newstate;
}
free(newstate);atstate->nxtone=NULL;laststate=atstate;atstate=firststate;
if (wordfile != NULL) fclose(wordfile);wordfile=NULL;
switch (ch)
{
case 'P':printf("Phrase= ");gets(str);strcat(str," ");i=strlen(str);k=0;
do {
k++;ch=str[k-1];*S_bf='\0';
if (ch>='!'&&ch<='?'||ch>='['&&ch<='\''||
(ch&255)>=224&&(ch&255)<=228||ch==' '||(ch&255)==234)
{ sprintf(STR1, "%c", ch);speak(STR1); }
else if (isalpha(ch))
{
sprintf(S_bf,"%c",ch);
do {
if (strlen(S_bf)==16) *S_bf='\0';
k++;ch=str[k-1];
if (isalpha(ch))
sprintf(S_bf+strlen(S_bf),"%c",ch);
} while (isalpha(ch));
speak(S_bf);*S_bf='\0';
if (ch !='\n' && ch !='!' && ch !=' ')
{ sprintf(STR1, "%c", ch);speak(STR1); }
}
} while (k != i);
break;
case 'F':printf("File name:");fgets(filname,100,stdin);
TEMP=strchr(filname,'\n');if (TEMP != NULL) *TEMP=0;
if ((wordfile=fopen(filname,"r"))!=NULL) Tell(filname);
else printf("No such file !\n");
break;
}
}