2 * cwc - a crossword compiler. Copyright 1999 Lars Christensen
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
24 //////////////////////////////////////////////////////////////////////
27 char symbol::alphabet
[32];
28 symbol
symbol::alphindex
[256];
30 int symbol::symballoc
= 0;
31 symbol
symbol::outside
;
35 symbol
symbol::symbolbit(symbolset ss
) {
37 for (symbolset i
=1,n
=0; i
; i
<<=1,n
++) {
44 symbol
symbol::alloc(char ch
) {
46 if (symballoc
>= 32) {
47 for (int i
=0; i
<32;i
++) cout
<< alphabet
[i
]; cout
<< endl
;
48 cout
<< ch
<< ' ' << int(ch
) << endl
;
49 throw error("Too many symbols");
54 alphabet
[s
.symb
] = ch
;
55 alphindex
[(unsigned char)ch
].symb
= s
.symb
;
59 void symbol::buildindex() {
60 for (int i
=0;i
<32;i
++)
62 for (int i
=0;i
<256;i
++)
63 alphindex
[i
].symb
= UNDEF
;
65 none
= symbol::alloc('/');
66 empty
= symbol::alloc('+');
67 outside
= symbol::alloc(' ');
70 symbol::symbol(char ch
) {
71 symb
= alphindex
[(unsigned char)ch
].symb
;
73 *this = symbol::alloc(ch
);
76 symbolset
pickbit(symbolset
&ss
) {
78 for (int i
=1; i
; i
<<=1) {
83 symbolset bit
= a
[rand()%n
];
88 int wordlen(symbol
*st
) {
90 while (st
[n
] != symbol::outside
) n
++;
94 ostream
&operator <<(ostream
&os
, symbol
*s
) {
95 while (*s
!= symbol::outside
) {
102 int numones(symbolset ss
) {
104 for (int i
=1; i
; i
<<= 1) {
111 int symbol::numalpha() {
113 for (int i
=0; i
<32; i
++)
114 if (isalpha(alphabet
[i
]))