1 /* Copyright (C) 1995,1996 Free Software Foundation, Inc.
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2, or (at your option)
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this software; see the file COPYING. If not, write to
15 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
17 * As a special exception, the Free Software Foundation gives permission
18 * for additional uses of the text contained in its release of GUILE.
20 * The exception is that, if you link the GUILE library with other files
21 * to produce an executable, this does not by itself cause the
22 * resulting executable to be covered by the GNU General Public License.
23 * Your use of that executable is in no way restricted on account of
24 * linking the GUILE library code into it.
26 * This exception does not however invalidate any other reasons why
27 * the executable file might be covered by the GNU General Public License.
29 * This exception applies only to the code released by the
30 * Free Software Foundation under the name GUILE. If you copy
31 * code from other Free Software Foundation releases into a copy of
32 * GUILE, as the General Public License permits, the exception does
33 * not apply to the code that you add in this way. To avoid misleading
34 * anyone as to the status of such modified files, you must delete
35 * this exception notice from them.
37 * If you write modifications of your own for GUILE, it is your choice
38 * whether to permit this exception to apply to your modifications.
39 * If you do not wish that, delete this exception notice.
51 SCM_PROC(s_char_p
, "char?", 1, 0, 0, scm_char_p
);
61 return SCM_ICHRP(x
) ? SCM_BOOL_T
: SCM_BOOL_F
;
64 SCM_PROC1 (s_char_eq_p
, "char=?", scm_tc7_rpsubr
, scm_char_eq_p
);
67 scm_char_eq_p(SCM x
, SCM y
)
75 SCM_ASSERT(SCM_ICHRP(x
), x
, SCM_ARG1
, s_char_eq_p
);
76 SCM_ASSERT(SCM_ICHRP(y
), y
, SCM_ARG2
, s_char_eq_p
);
77 return (SCM_ICHR(x
) == SCM_ICHR(y
)) ? SCM_BOOL_T
: SCM_BOOL_F
;
81 SCM_PROC1 (s_char_less_p
, "char<?", scm_tc7_rpsubr
, scm_char_less_p
);
84 scm_char_less_p(SCM x
, SCM y
)
92 SCM_ASSERT(SCM_ICHRP(x
), x
, SCM_ARG1
, s_char_less_p
);
93 SCM_ASSERT(SCM_ICHRP(y
), y
, SCM_ARG2
, s_char_less_p
);
94 return (SCM_ICHR(x
) < SCM_ICHR(y
)) ? SCM_BOOL_T
: SCM_BOOL_F
;
97 SCM_PROC1 (s_char_leq_p
, "char<=?", scm_tc7_rpsubr
, scm_char_leq_p
);
100 scm_char_leq_p(SCM x
, SCM y
)
108 SCM_ASSERT(SCM_ICHRP(x
), x
, SCM_ARG1
, s_char_leq_p
);
109 SCM_ASSERT(SCM_ICHRP(y
), y
, SCM_ARG2
, s_char_leq_p
);
110 return (SCM_ICHR(x
) <= SCM_ICHR(y
)) ? SCM_BOOL_T
: SCM_BOOL_F
;
113 SCM_PROC1 (s_char_gr_p
, "char>?", scm_tc7_rpsubr
, scm_char_gr_p
);
116 scm_char_gr_p(SCM x
, SCM y
)
124 SCM_ASSERT(SCM_ICHRP(x
), x
, SCM_ARG1
, s_char_gr_p
);
125 SCM_ASSERT(SCM_ICHRP(y
), y
, SCM_ARG2
, s_char_gr_p
);
126 return (SCM_ICHR(x
) > SCM_ICHR(y
)) ? SCM_BOOL_T
: SCM_BOOL_F
;
129 SCM_PROC1 (s_char_geq_p
, "char>=?", scm_tc7_rpsubr
, scm_char_geq_p
);
132 scm_char_geq_p(SCM x
, SCM y
)
140 SCM_ASSERT(SCM_ICHRP(x
), x
, SCM_ARG1
, s_char_geq_p
);
141 SCM_ASSERT(SCM_ICHRP(y
), y
, SCM_ARG2
, s_char_geq_p
);
142 return (SCM_ICHR(x
) >= SCM_ICHR(y
)) ? SCM_BOOL_T
: SCM_BOOL_F
;
145 SCM_PROC1 (s_char_ci_eq_p
, "char-ci=?", scm_tc7_rpsubr
, scm_char_ci_eq_p
);
148 scm_char_ci_eq_p(SCM x
, SCM y
)
151 scm_char_ci_eq_p(x
, y
)
156 SCM_ASSERT(SCM_ICHRP(x
), x
, SCM_ARG1
, s_char_ci_eq_p
);
157 SCM_ASSERT(SCM_ICHRP(y
), y
, SCM_ARG2
, s_char_ci_eq_p
);
158 return (scm_upcase(SCM_ICHR(x
))==scm_upcase(SCM_ICHR(y
))) ? SCM_BOOL_T
: SCM_BOOL_F
;
161 SCM_PROC1 (s_char_ci_less_p
, "char-ci<?", scm_tc7_rpsubr
, scm_char_ci_less_p
);
164 scm_char_ci_less_p(SCM x
, SCM y
)
167 scm_char_ci_less_p(x
, y
)
172 SCM_ASSERT(SCM_ICHRP(x
), x
, SCM_ARG1
, s_char_ci_less_p
);
173 SCM_ASSERT(SCM_ICHRP(y
), y
, SCM_ARG2
, s_char_ci_less_p
);
174 return (scm_upcase(SCM_ICHR(x
)) < scm_upcase(SCM_ICHR(y
))) ? SCM_BOOL_T
: SCM_BOOL_F
;
177 SCM_PROC1 (s_char_ci_leq_p
, "char-ci<=?", scm_tc7_rpsubr
, scm_char_ci_leq_p
);
180 scm_char_ci_leq_p(SCM x
, SCM y
)
183 scm_char_ci_leq_p(x
, y
)
188 SCM_ASSERT(SCM_ICHRP(x
), x
, SCM_ARG1
, s_char_ci_leq_p
);
189 SCM_ASSERT(SCM_ICHRP(y
), y
, SCM_ARG2
, s_char_ci_leq_p
);
190 return (scm_upcase(SCM_ICHR(x
)) <= scm_upcase(SCM_ICHR(y
))) ? SCM_BOOL_T
: SCM_BOOL_F
;
193 SCM_PROC1 (s_char_ci_gr_p
, "char-ci>?", scm_tc7_rpsubr
, scm_char_ci_gr_p
);
196 scm_char_ci_gr_p(SCM x
, SCM y
)
199 scm_char_ci_gr_p(x
, y
)
204 SCM_ASSERT(SCM_ICHRP(x
), x
, SCM_ARG1
, s_char_ci_gr_p
);
205 SCM_ASSERT(SCM_ICHRP(y
), y
, SCM_ARG2
, s_char_ci_gr_p
);
206 return (scm_upcase(SCM_ICHR(x
)) > scm_upcase(SCM_ICHR(y
))) ? SCM_BOOL_T
: SCM_BOOL_F
;
209 SCM_PROC1 (s_char_ci_geq_p
, "char-ci>=?", scm_tc7_rpsubr
, scm_char_ci_geq_p
);
212 scm_char_ci_geq_p(SCM x
, SCM y
)
215 scm_char_ci_geq_p(x
, y
)
220 SCM_ASSERT(SCM_ICHRP(x
), x
, SCM_ARG1
, s_char_ci_geq_p
);
221 SCM_ASSERT(SCM_ICHRP(y
), y
, SCM_ARG2
, s_char_ci_geq_p
);
222 return (scm_upcase(SCM_ICHR(x
)) >= scm_upcase(SCM_ICHR(y
))) ? SCM_BOOL_T
: SCM_BOOL_F
;
226 SCM_PROC(s_char_alphabetic_p
, "char-alphabetic?", 1, 0, 0, scm_char_alphabetic_p
);
229 scm_char_alphabetic_p(SCM chr
)
232 scm_char_alphabetic_p(chr
)
236 SCM_ASSERT(SCM_ICHRP(chr
), chr
, SCM_ARG1
, s_char_alphabetic_p
);
237 return (isascii(SCM_ICHR(chr
)) && isalpha(SCM_ICHR(chr
))) ? SCM_BOOL_T
: SCM_BOOL_F
;
240 SCM_PROC(s_char_numeric_p
, "char-numeric?", 1, 0, 0, scm_char_numeric_p
);
243 scm_char_numeric_p(SCM chr
)
246 scm_char_numeric_p(chr
)
250 SCM_ASSERT(SCM_ICHRP(chr
), chr
, SCM_ARG1
, s_char_numeric_p
);
251 return (isascii(SCM_ICHR(chr
)) && isdigit(SCM_ICHR(chr
))) ? SCM_BOOL_T
: SCM_BOOL_F
;
254 SCM_PROC(s_char_whitespace_p
, "char-whitespace?", 1, 0, 0, scm_char_whitespace_p
);
257 scm_char_whitespace_p(SCM chr
)
260 scm_char_whitespace_p(chr
)
264 SCM_ASSERT(SCM_ICHRP(chr
), chr
, SCM_ARG1
, s_char_whitespace_p
);
265 return (isascii(SCM_ICHR(chr
)) && isspace(SCM_ICHR(chr
))) ? SCM_BOOL_T
: SCM_BOOL_F
;
270 SCM_PROC(s_char_upper_case_p
, "char-upper-case?", 1, 0, 0, scm_char_upper_case_p
);
273 scm_char_upper_case_p(SCM chr
)
276 scm_char_upper_case_p(chr
)
280 SCM_ASSERT(SCM_ICHRP(chr
), chr
, SCM_ARG1
, s_char_upper_case_p
);
281 return (isascii(SCM_ICHR(chr
)) && isupper(SCM_ICHR(chr
))) ? SCM_BOOL_T
: SCM_BOOL_F
;
285 SCM_PROC(s_char_lower_case_p
, "char-lower-case?", 1, 0, 0, scm_char_lower_case_p
);
288 scm_char_lower_case_p(SCM chr
)
291 scm_char_lower_case_p(chr
)
295 SCM_ASSERT(SCM_ICHRP(chr
), chr
, SCM_ARG1
, s_char_lower_case_p
);
296 return (isascii(SCM_ICHR(chr
)) && islower(SCM_ICHR(chr
))) ? SCM_BOOL_T
: SCM_BOOL_F
;
301 SCM_PROC (s_char_is_both_p
, "char-is-both?", 1, 0, 0, scm_char_is_both_p
);
304 scm_char_is_both_p (SCM chr
)
307 scm_char_is_both_p (chr
)
311 SCM_ASSERT(SCM_ICHRP(chr
), chr
, SCM_ARG1
, s_char_upper_case_p
);
312 return ((isascii(SCM_ICHR(chr
)) && (isupper(SCM_ICHR(chr
)) || islower(SCM_ICHR(chr
))))
320 SCM_PROC(s_char_to_integer
, "char->integer", 1, 0, 0, scm_char_to_integer
);
323 scm_char_to_integer(SCM chr
)
326 scm_char_to_integer(chr
)
330 SCM_ASSERT(SCM_ICHRP(chr
), chr
, SCM_ARG1
, s_char_to_integer
);
331 return scm_ulong2num((unsigned long)SCM_ICHR(chr
));
336 SCM_PROC(s_integer_to_char
, "integer->char", 1, 0, 0, scm_integer_to_char
);
339 scm_integer_to_char(SCM n
)
342 scm_integer_to_char(n
)
348 ni
= 0xffff & scm_num2ulong (n
, (char *)SCM_ARG1
, s_integer_to_char
);
349 return SCM_MAKICHR(SCM_INUM(n
));
353 SCM_PROC(s_char_upcase
, "char-upcase", 1, 0, 0, scm_char_upcase
);
356 scm_char_upcase(SCM chr
)
363 SCM_ASSERT(SCM_ICHRP(chr
), chr
, SCM_ARG1
, s_char_upcase
);
364 return SCM_MAKICHR(scm_upcase(SCM_ICHR(chr
)));
368 SCM_PROC(s_char_downcase
, "char-downcase", 1, 0, 0, scm_char_downcase
);
371 scm_char_downcase(SCM chr
)
374 scm_char_downcase(chr
)
378 SCM_ASSERT(SCM_ICHRP(chr
), chr
, SCM_ARG1
, s_char_downcase
);
379 return SCM_MAKICHR(scm_downcase(SCM_ICHR(chr
)));
386 static unsigned char scm_upcase_table
[SCM_CHAR_SCM_CODE_LIMIT
];
387 static unsigned char scm_downcase_table
[SCM_CHAR_SCM_CODE_LIMIT
];
388 static unsigned char scm_lowers
[] = "abcdefghijklmnopqrstuvwxyz";
389 static unsigned char scm_uppers
[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
393 scm_tables_prehistory (void)
396 scm_tables_prehistory ()
400 for (i
= 0; i
< SCM_CHAR_SCM_CODE_LIMIT
; i
++)
401 scm_upcase_table
[i
] = scm_downcase_table
[i
] = i
;
402 for (i
= 0; i
< sizeof scm_lowers
/ sizeof (char); i
++)
404 scm_upcase_table
[scm_lowers
[i
]] = scm_uppers
[i
];
405 scm_downcase_table
[scm_uppers
[i
]] = scm_lowers
[i
];
411 scm_upcase (unsigned int c
)
418 if (c
< sizeof (scm_upcase_table
))
419 return scm_upcase_table
[c
];
426 scm_downcase (unsigned int c
)
433 if (c
< sizeof (scm_downcase_table
))
434 return scm_downcase_table
[c
];
443 # if (('\n'=='\025') && (' '=='\100') && ('a'=='\201') && ('A'=='\301'))
445 # endif /* (('\n'=='\025') && (' '=='\100') && ('a'=='\201') && ('A'=='\301')) */
446 # if (('\n'=='\012') && (' '=='\040') && ('a'=='\141') && ('A'=='\101'))
448 # endif /* (('\n'=='\012') && (' '=='\040') && ('a'=='\141') && ('A'=='\101')) */
449 #endif /* def _DCC */
453 char *scm_charnames
[] =
455 "nul","soh","stx","etx", "pf", "ht", "lc","del",
456 0 , 0 ,"smm", "vt", "ff", "cr", "so", "si",
457 "dle","dc1","dc2","dc3","res", "nl", "bs", "il",
458 "can", "em", "cc", 0 ,"ifs","igs","irs","ius",
459 "ds","sos", "fs", 0 ,"byp", "lf","eob","pre",
460 0 , 0 , "sm", 0 , 0 ,"enq","ack","bel",
461 0 , 0 ,"syn", 0 , "pn", "rs", "uc","eot",
462 0 , 0 , 0 , 0 ,"dc4","nak", 0 ,"sub",
463 "space", scm_s_newline
, "tab", "backspace", "return", "page", "null"};
465 char scm_charnums
[] =
466 "\000\001\002\003\004\005\006\007\
467 \010\011\012\013\014\015\016\017\
468 \020\021\022\023\024\025\026\027\
469 \030\031\032\033\034\035\036\037\
470 \040\041\042\043\044\045\046\047\
471 \050\051\052\053\054\055\056\057\
472 \060\061\062\063\064\065\066\067\
473 \070\071\072\073\074\075\076\077\
475 #endif /* def EBCDIC */
477 char *scm_charnames
[] =
479 "nul","soh","stx","etx","eot","enq","ack","bel",
480 "bs", "ht", "nl", "vt", "np", "cr", "so", "si",
481 "dle","dc1","dc2","dc3","dc4","nak","syn","etb",
482 "can", "em","sub","esc", "fs", "gs", "rs", "us",
483 "space", "newline", "tab", "backspace", "return", "page", "null", "del"};
484 char scm_charnums
[] =
485 "\000\001\002\003\004\005\006\007\
486 \010\011\012\013\014\015\016\017\
487 \020\021\022\023\024\025\026\027\
488 \030\031\032\033\034\035\036\037\
490 #endif /* def ASCII */
492 int scm_n_charnames
= sizeof (scm_charnames
) / sizeof (char *);
499 scm_init_chars (void)