CP1251 or support russian (and other) code pages

115 views
Skip to first unread message

Viacheslav N. Mezentsev

unread,
Nov 19, 2007, 9:06:45 PM11/19/07
to CLIPSESG
Dear CLIPS support,

How I can use in names of the facts, of templates and rules the
characters with codes ASCII are more 127 (192-255)?
I want to build CLIPS in my application. I'm programmer, so if it is
not so difficult I want to try make changes manually in source files.

Thank you.
Viacheslav N. Mezentsev

CLIPS Support

unread,
Nov 19, 2007, 10:49:46 PM11/19/07
to CLIPSESG
The code that forms tokens from characters is in scanner.c. If you
step through the code while parsing tokens containing extended ASCII
characters, you should come across the point at which the characters
are rejected. My guess would be that either the isalpha or isprint
tests are failing for the extended characters.

On Nov 19, 8:06 pm, "Viacheslav N. Mezentsev" <unihome...@yandex.ru>
wrote:

Viacheslav N. Mezentsev

unread,
Nov 19, 2007, 11:37:28 PM11/19/07
to CLIPSESG
I'm sorry, have forgotten to add (Display.c):

// .....
unsigned char text[2];

text[0] = (unsigned char) wParam;
text[1] = '\0';

if (isprint (text[0]) || isspace(text[0]) || ( ( text[ 0 ] >=
192 ) ) ) // <===
// .....

unsigned char for text[2].

Now I look in "SCANNER MODULE"

Viacheslav N. Mezentsev

unread,
Nov 20, 2007, 12:01:42 AM11/20/07
to CLIPSESG
And the answer for:

(deftemplate person (slot _russain_tex_))

is

[PRNUTIL2] Syntax Error: Check appropriate syntax for deftemplate.

ERROR:
(deftemplate MAIN::person
(slot <<<unprintable character>>>
CLIPS>

Ok. The problem maybe is in isprint(). I dont know can I make
replacement char to unsignet char.
Also I need EOF (255 ?) character. It is the last letter in russian
alphabet in CP1251.
Viacheslav N. Mezentsev

CLIPS Support

unread,
Nov 20, 2007, 12:29:00 AM11/20/07
to CLIPSESG
I think you probably want to make the check as

( ((int) wParam) > = 192

rather than

( text[ 0 ] >= 192

so that -1 is not converted to 255 when it is cast to a char.

On Nov 19, 11:01 pm, "Viacheslav N. Mezentsev" <unihome...@yandex.ru>
wrote:

Viacheslav N. Mezentsev

unread,
Nov 20, 2007, 1:07:33 AM11/20/07
to CLIPSESG
Of course, you right :-D

For full russian alphabet:

if ( isprint ( text[ 0 ] )
|| isspace( text[ 0 ] )
|| ( ( ( int ) wParam ) >= 192 )
|| ( ( ( int ) wParam ) == 184 )
|| ( ( ( int ) wParam ) == 168 )
)

http://www-sbras.nsc.ru/gif/inter/cp-cp1251.gif

But to enter characters is only half of work.
I shall think further.
Thank you.

Viacheslav N. Mezentsev

unread,
Nov 20, 2007, 1:27:39 AM11/20/07
to CLIPSESG
Much better:

if ( isprint ( text[ 0 ] )
|| isspace( text[ 0 ] )
|| ( LOBYTE( wParam ) >= 0xC0 )
|| ( LOBYTE( wParam ) == 0xA8 )
|| ( LOBYTE( wParam ) == 0xB8 )
)
MSDN: WM_CHAR

LRESULT CALLBACK WindowProc(
HWND hwnd, // handle to window
UINT uMsg, // WM_CHAR
WPARAM wParam, // character code (TCHAR)
LPARAM lParam // key data
);

wParam - 2 bytes. (int) wParam when I execute the program for 0xA8 rus
char -> 65448 or 0xFFA8 I get in wParam. It always is more than the
full ASCII table :)

Viacheslav N. Mezentsev

unread,
Nov 20, 2007, 1:39:29 AM11/20/07
to CLIPSESG
Final version :)

if ( isprint ( text[ 0 ] )
|| isspace( text[ 0 ] )
|| ( ( ( int ) wParam ) >= 0xFFC0 )
|| ( ( ( int ) wParam ) == 0xFFA8 )
|| ( ( ( int ) wParam ) == 0xFFB8 )
)

Viacheslav N. Mezentsev

unread,
Nov 20, 2007, 2:51:31 AM11/20/07
to CLIPSESG
> MSDN: WM_CHAR
>
> LRESULT CALLBACK WindowProc(
> HWND hwnd, // handle to window
> UINT uMsg, // WM_CHAR
> WPARAM wParam, // character code (TCHAR)
> LPARAM lParam // key data
> );
>
> wParam - 2 bytes. (int) wParam when I execute the program for 0xA8 rus
> char -> 65448 or 0xFFA8 I get in wParam. It always is more than the
> full ASCII table :)

2 bytes - for 16 bit Windows like 3.10, 3.11 I think.
For modern systems all parameters have size DWORD - 32 bits.

I study code of the program under the debugger MS Visual C++ 6.0
wParam = 2 bytes when I run the program and set break point.

CLIPS shell is very old.
:) "Microsoft Windows Version 3.0 01/31/02" in WINDOWS MAIN MODULE

Also I'm interesting how convert exe project to dll.
I need to write def file? Where to include:
Microsoft (R) COFF Binary File Dumper Version 3.00.5270
Copyright (C) Microsoft Corp 1992-1995. All rights reserved.


Dump of file clips.dll

File Type: DLL

Section contains the following Exports for CLIPS.dll

0 characteristics
3EC7E50A time date stamp Mon May 19 01:54:50 2003
0.00 version
1 ordinal base
1637 number of functions
1637 number of names

ordinal hint name

1 0 AbortExit (00067AD0)
2 1 AbsFunction (000050F0)
3 2 AcosFunction (0001F460)
4 3 AcoshFunction (0001FA40)
5 4 AcotFunction (0001F6E0)
6 5 AcothFunction (0001FC60)
7 6 AcscFunction (0001F660)
8 7 AcschFunction (0001FBF0)
9 8 ActualPoolSize (00045D40)
10 9 AddAbortBloadFunction (000046B0)
11 A AddActivation (00001100)
12 B AddAfterBloadFunction (00004630)
13 C AddAfterModuleChangeFunction (0004A0D0)
14 D AddAfterModuleDefinedFunction (0004A170)
15 E AddAssertFunction (0002A780)
16 F AddBeforeBloadFunction (000045F0)
17 10 AddBinaryItem (00005B40)
............................
1625 658 genmemcpy (00045D90)
1626 659 genrand (00074DB0)
1627 65A genrealloc (00046980)
1628 65B genremove (00074DE0)
1629 65C genrename (00074E40)
1630 65D genseed (00074DC0)
1631 65E gensystem (00074BD0)
1632 65F gentime (00074B80)
1633 660 gm1 (00046870)
1634 661 gm2 (000468E0)
1635 662 gm3 (00046930)
1636 663 rm (00046550)
1637 664 rm3 (000465C0)

Summary

E000 .data
13000 .rdata
6000 .reloc
1000 .rsrc
8B000 .text

How to initialize CLIPS engine in dll? I want try to use russian
version of this dll in my little project. If it's possible, of course.

CLIPS Support

unread,
Nov 20, 2007, 11:54:30 AM11/20/07
to CLIPSESG
Here's some reference information on building a DLL: http://www.codeproject.com/dll/.

Your DLL should probably support multiple applications using it
simultaneously. So you'd want to call CreateEnvironment for each
invocation to initialize a new engine and somehow pass that value back
to the invoking application.

On Nov 20, 1:51 am, "Viacheslav N. Mezentsev" <unihome...@yandex.ru>
wrote:

Viacheslav N. Mezentsev

unread,
Nov 20, 2007, 1:58:33 PM11/20/07
to CLIPSESG
> Here's some reference information on building a DLL:http://www.codeproject.com/dll/.
>
> Your DLL should probably support multiple applications using it
> simultaneously. So you'd want to call CreateEnvironment for each
> invocation to initialize a new engine and somehow pass that value back
> to the invoking application.

How to create dll it's known to me. The clips features aren't known
for me.

For localization it is enough to add 2 lines (WinMain.c):

// .....

#include <locale.h>

// .....

/*=============================*/
/* Application initialization. */
/*=============================*/

setlocale( LC_ALL, ".1251" ); // Add by Viacheslav N. Mezentsev

InitializeEnvironment();

// .....

Screenshot: http://i032.radikal.ru/0711/34/af572480c1b8.gif

Now I shall initiate with writing dll and testing of the localized
version.

CLIPS Support

unread,
Nov 21, 2007, 12:11:02 AM11/21/07
to CLIPSESG
If you use version 6.24 of CLIPS, you can set the locale from within
CLIPS using the set-locale command.

CLIPS> (set-locale ".1251")
"C"
CLIPS>

On Nov 20, 12:58 pm, "Viacheslav N. Mezentsev" <unihome...@yandex.ru>
wrote:

Viacheslav N. Mezentsev

unread,
Nov 21, 2007, 2:15:35 PM11/21/07
to CLIPSESG
CLIPS Support wrote:
> If you use version 6.24 of CLIPS, you can set the locale from within
> CLIPS using the set-locale command.
>
> CLIPS> (set-locale ".1251")
> "C"
> CLIPS>

Thank you, CLIPS Support. Long think.
I using 6.22 as was visible on a screenshot.
Now downloading 6.24.

(set-locale) is dangerous command as well as (system).
Is it possible to execute (set-locale) at once at a loading? (Not
manually)
But not updating a sourece code as I did.

As you probably know in Russia there was a translation of the book
about a CLIPS system (with CD).
I shall try more to read documentation to set less problems here.
Nice work.

Viacheslav N. Mezentsev
Message has been deleted

Viacheslav N. Mezentsev

unread,
Nov 21, 2007, 2:22:25 PM11/21/07
to CLIPSESG
> CLIPS> (set-locale ".1251")

Unfortunately, it doesn't work, since except for a engine there is a
shell.
I can't enter russian characters after run this command.

Viacheslav N. Mezentsev

unread,
Nov 21, 2007, 7:17:02 PM11/21/07
to CLIPSESG
I think you have a bug. Look at the picture.

http://i048.radikal.ru/0711/5c/604e4e9a9d31.gif

The right answer in any case should be: "Russian_Russia.1251"
But not "С" or just "Russian".

When I have entered (set-locale "Russian_Russia.1251") I have
"Russian".
But in both cases I can't enter russian characters.

Ok. I like 6.22 version with sources. dll is much more interesting to
me.

On Nov 22, 12:22 am, "Viacheslav N. Mezentsev" <unihome...@yandex.ru>
wrote:

rzeno

unread,
Nov 21, 2007, 8:13:00 PM11/21/07
to CLIP...@googlegroups.com
On Wed, Nov 21, 2007 at 04:17:02PM -0800, Viacheslav N. Mezentsev wrote:
>
> I think you have a bug. Look at the picture.
>
> http://i048.radikal.ru/0711/5c/604e4e9a9d31.gif
>
I think you have a bug, his name is microsoft stuff, :))

> The right answer in any case should be: "Russian_Russia.1251"
> But not "С" or just "Russian".
>
> When I have entered (set-locale "Russian_Russia.1251") I have
> "Russian".
> But in both cases I can't enter russian characters.
>
> Ok. I like 6.22 version with sources. dll is much more interesting to
> me.
>

The problem you want to solve is a very complicated one and even if you
find now a solution, sun or latter you'll have another problem.

From my point of view, but maybe I'm wrong, having deftemplate names or
other clips code stuff in russian or other non-latin encoding does not
help a non-programmer user because he can't deal with clips code,
so is useless for him.

I guess that you want to build a interface for the user, in russian,
and a mechanism to bind to clips code, so the simple way is to write
two function to convert the names from whatever encoding you want into a
latin transcription and back.

GUI---> russian-to-latin ---> clips-code
A |
\----- latin-to-russian <------/


--
"We must be systematic, but we should keep our systems open."
-- Alfred North Whitehead, Modes of Thought --

rzeno

unread,
Nov 21, 2007, 8:44:09 PM11/21/07
to CLIP...@googlegroups.com
Maybe you could find some help here:

http://2cyr.com/decode/

PS: I have that in mind before previous replay but I forget to include
the link, sorry, :-)

Viacheslav N. Mezentsev

unread,
Nov 21, 2007, 9:09:22 PM11/21/07
to CLIPSESG
clips - interpreter, which one works with strings.
If it is designed according to the standard ANSI C and will use
functions which work with strings from standard libraries, there
should not be problems.
That is why I have used setlocale().

>I guess that you want to build a interface for the user, in russian,
>and a mechanism to bind to clips code, so the simple way is to write
>two function to convert the names from whatever encoding you want into a
>latin transcription and back.

Yes you are right. Thank you, but I guess is a bad idea :)
What if I (as the user) shall want to have direct access to the facts,
rules and templates?
Or save them? I should everywhere have a translator.
I already have tried my approach on more composite examples and it
works.

>The problem you want to solve is a very complicated one and even if you
>find now a solution, sun or latter you'll have another problem.

Yes, maybe you are right, but I am not afraid of other problems and
will correct a code if it will be necessary.
I only hope for the standards and MSDN :)

CLIPS Support

unread,
Nov 22, 2007, 12:25:53 AM11/22/07
to CLIPSESG
The set-locale function sets the locale for the format and read-number
functions so that local formats are used when printing/reading
numbers. It would appear that's insufficient for displaying Russian
characters. I believe that setting the locale globally will change the
CLIPS definition of a float for some locales (if a comma is used for a
decimal point instead of a period).

On Nov 21, 1:22 pm, "Viacheslav N. Mezentsev" <unihome...@yandex.ru>
wrote:

CLIPS Support

unread,
Nov 22, 2007, 12:36:15 AM11/22/07
to CLIPSESG
The value returned by set-locale is the last locale value you
specified. The initial value is determined by CLIPS by calling the
setlocale function with a locale string of NULL. The default is the
standard C locale or "C".

On Nov 21, 6:17 pm, "Viacheslav N. Mezentsev" <unihome...@yandex.ru>

Viacheslav N. Mezentsev

unread,
Nov 22, 2007, 5:33:00 AM11/22/07
to CLIPSESG
Thanks for explanations
Now it is much better:
http://i018.radikal.ru/0711/8e/5af4e2b9d9a4.gif
Reply all
Reply to author
Forward
0 new messages