aboutsummaryrefslogtreecommitdiffstats
path: root/spo256/spo.c
blob: 5c4f7ec5388944c362e1795d0fd86f0ff701effc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/*
 * SPO256 low level operations.
 * $Id: spo.c 1.2 Mon, 24 Mar 1997 12:25:37 -0500 dyfet $
 * Copyright (c) 1997 by Tycho Softworks.
 * For conditions on distribution and reuse see product license.
 *
 * Abstract:
 *	Key SPO translation modules.  This includes the word substution
 *	module, the numeric pronounciation system, pause control, and 
 *	other low level spo services.
 */

#include <other/config.h>
#include <other/string.h>
#include "speak.h"

/*
 * Flags and operating mode properties that may now be effected by
 * server commands.
 */

bool	echo = FALSE;	/* echo SPO output to user?	*/
bool	spell = FALSE;	/* spell all words?		*/
bool	lit = FALSE;	/* literally pronounce as is?	*/

/*
 * A new 'init' function is added to initialize operating state for
 * each new connection.  This assures that spo command sequences
 * issued from a previous session are not left in effect.
 */

void	spo_init(void)
{
	echo = FALSE;	/* echo off by default	*/
	spell = FALSE;
	lit = FALSE;
};

/*
 * Interpret server specific commands embedded in <ESC><cmd> 
 * sequences.  The SPO has limited options to effect in this manner.
 */

void	spo_cmd(char *str)
{
	if(!stricmp(str, "echo"))
	{
		echo = TRUE;
		return;
	}

	if(!stricmp(str, "/echo"))
	{
		echo = FALSE;
		return;
	}

	if(!stricmp(str, "spell"))
	{
		spell = TRUE;
		return;
	}

	if(!stricmp(str, "/spell"))
	{
		spell = FALSE;
		return;
	}

	if(!stricmp(str, "lit"))
	{
		lit = TRUE;
		return;
	}

	if(!stricmp(str, "/lit"))
	{
		lit = FALSE;
		return;
	}
};

/*
 * Pause spo output between words, numbers, and empty lines, so that
 * words are properly announciated.  This is typically accomplished with 
 * spaces and newline control. 
 */

void	spo_pause(PAUSE p)
{
	switch(p)
	{
	case P_WORD:
		write(spo, " ", 1);
		if(echo)
			puttcp(" ", io); 
		break;
	case P_SENTANCE:
		write(spo, " \n", 2);
		if(echo)
			puttcp(" \n", io);
		break;
	case P_LINE:
		write(spo, " \r\n", 3);
		if(echo)
			puttcp(" \r\n", io);
		break;
	case P_END:
		write(spo, "\r\n", 2);
	}
}

/*	Announce quoted text. */

void	spo_begquote(void)
{
	spo_word("quote");
}

void	spo_endquote(void)
{
	spo_word("end");
	spo_begquote();
}

/* 
 * This performs low level lookup and pronounciation of words, either
 * in the originally submitted spelling, or in the spo dictionary
 * spelling.
 */

void	spo_word(char *word)			
{
	char	*p = find(widx, word);
	if(!p)
		p = word;

	if(lit)
		p = word;

	if(spell)
	{
		p = word;
		while(*p)
		{
			write(spo, p, 1);
			if(echo)
				fputc(*p, io);
			spo_pause(P_WORD);
			++p;
		}
	}
	else
	{
		write(spo, p, strlen(p));
		if(echo)
			puttcp(p, io);
	}
	spo_pause(P_WORD);
}