MOO-cows Mailing List Archive

[Prev][Next][Index][Thread]

Server Patch - chr() and asc() functions - Ian




Hi.

In the search of great color, and methods to process the elusive ESCAPE 
character, I did a mod to the server code that will either return the 
character or the ASCII code of the character.

Under what system and with which machines this will work, I haven't the 
foggiest.  Perhaps someone more familiar with the *nix environment might 
comment.

The functions are:

-------------

STR chr(NUM)
This will return a string (length(string) = 1) that contains the 
character represented by the code NUM.

examples
========

chr(27)             = ESCAPE
chr(65)             = "A"
chr(256)            = E_INVARG
chr(0)              = E_INVARG

------------------

NUM asc(STR)
This will return the code NUM of the first character in the string STR.

examples
========

asc("A")            = 65
asc(chr(27))        = 27
asc(chr(1))         = 1
asc(chr(0))         = E_INVARG
asc(chr(255))       = 255

-------------------

Two files need to be patched.  numbers.c and list.c

Here are the patches.

-------------  PATCH FOR FILE numbers.c -------------------
260,277d259
< static package
< bf_asc(Var arglist, Byte next, void *vdata, Objid progr)
< {
<     int num = (unsigned char)arglist.v.list[1].v.str[0];
<     
<     free_var(arglist);
<     
<     if (num == 0) 
< 	return make_error_pack(E_INVARG);
<     else {
< 	Var r; 
< 
< 	r.type = TYPE_NUM;
< 	r.v.num = num;
< 	return make_var_pack(r);
<     }
< }
< 
281d262
<     (void) register_function("asc", 1, 1, bf_asc, TYPE_STR);
292c273
< char rcsid_numbers[] = "$Id: numbers.c,v 2.1 1995/05/17 10:15:55 ian Exp ian $";
---
> char rcsid_numbers[] = "$Id: numbers.c,v 1.9 1992/10/23 23:03:47 pavel Exp $";
295,300d275
<  * Revision 2.1  1995/05/17  10:15:55  ian
<  * Added function bf_asc (asc())
<  *
<  * Revision 2.0  1995/05/15  23:12:33  ian
<  * Initial revision as received from parcftp.xerox.com version 1.7.8p4
<  *
------------------------ END OF PATCH TO numbers.c ----------------


------------------------ PATCH FOR FILE list.c --------------------
808,829d807
< static package
< bf_chr(Var arglist, Byte next, void *vdata, Objid progr)
< {
<     int num = arglist.v.list[1].v.num;
<     
<     free_var(arglist);
<     
<     if (num == 0 || num > 255) 
< 	return make_error_pack(E_INVARG);
<     else {
< 	Var r; 
< 	char *s;
<         s = mymalloc(sizeof(char) * 2, M_STRING);
< 
< 	s[0] = (char)num;
< 	s[1] = '\0';
< 	r.type = TYPE_STR;
< 	r.v.str = s;
< 	return make_var_pack(r);
<     }
< }
< 
866d843
<     (void) register_function("chr", 1, 1, bf_chr, TYPE_NUM);
870c847
< char rcsid_list[] = "$Id: list.c,v 2.1 1995/05/17 09:56:19 ian Exp ian $";
---
> char rcsid_list[] = "$Id: list.c,v 1.12 1992/10/23 23:03:47 pavel Exp pavel $";
873,878d849
<  * Revision 2.1  1995/05/17  09:56:19  ian
<  * Added function bf_chr (chr())
<  *
<  * Revision 2.0  1995/05/15  23:12:33  ian
<  * Initial revision as received from parcftp.xerox.com version 1.7.8p4
<  *

------------------------ END OF PATCH TO list.c -------------------

It should work, but if it breaks, you get to keep all the pieces :)

However, if it breaks, and you fix it, please let me know.  Also, if it 
breaks and you can't fix it :)

For those who're not C programmers, would some other programmer like to 
comment on the patch after testing it, so the non C people know if it's 
safe to do?

Regards,

Ian.

+--------------------------------------------------------------------+
| Ian Macintosh         | P.O. Box 24-036 | Anything really worth    |
| General Manager       | Royal Oak       | doing, is worth doing    |
| Sytek New Zealand Ltd | Auckland 1      | badly.     - Duncan Shaw |
+--------------------------------------------------------------------+



Follow-Ups:

Home | Subject Index | Thread Index