* alist.c, arbiters.c, async.h, backtrace.h, boolean.c, chars.c,
[bpt/guile.git] / libguile / chars.c
index 57859f4..229da4b 100644 (file)
@@ -1,4 +1,4 @@
-/*     Copyright (C) 1995,1996,1998 Free Software Foundation, Inc.
+/*     Copyright (C) 1995,1996,1998, 2000, 2001 Free Software Foundation, Inc.
  * 
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * whether to permit this exception to apply to your modifications.
  * If you do not wish that, delete this exception notice.  */
 
-/* Software engineering face-lift by Greg J. Badros, 11-Dec-1999,
-   gjb@cs.washington.edu, http://www.cs.washington.edu/homes/gjb */
 
 \f
 
-#include <stdio.h>
 #include <ctype.h>
-#include "_scm.h"
-#include "scm_validate.h"
+#include "libguile/_scm.h"
+#include "libguile/validate.h"
 
-#include "chars.h"
+#include "libguile/chars.h"
 \f
 
 SCM_DEFINE (scm_char_p, "char?", 1, 0, 0, 
             (SCM x),
-"Return #t iff X is a character, else #f.")
+           "Return @code{#t} iff @var{x} is a character, else @code{#f}.")
 #define FUNC_NAME s_scm_char_p
 {
-  return SCM_BOOL(SCM_ICHRP(x));
+  return SCM_BOOL(SCM_CHARP(x));
 }
 #undef FUNC_NAME
 
 SCM_DEFINE1 (scm_char_eq_p, "char=?", scm_tc7_rpsubr,
              (SCM x, SCM y),
-"Return #t iff X is the same character as Y, else #f.")
+            "Return @code{#t} iff @var{x} is the same character as @var{y}, else @code{#f}.")
 #define FUNC_NAME s_scm_char_eq_p
 {
-  SCM_VALIDATE_CHAR (1,x);
-  SCM_VALIDATE_CHAR (2,y);
-  return SCM_BOOL(SCM_ICHR(x) == SCM_ICHR(y));
+  SCM_VALIDATE_CHAR (1, x);
+  SCM_VALIDATE_CHAR (2, y);
+  return SCM_BOOL (SCM_EQ_P (x, y));
 }
 #undef FUNC_NAME
 
 
 SCM_DEFINE1 (scm_char_less_p, "char<?", scm_tc7_rpsubr, 
              (SCM x, SCM y),
-"Return #t iff X is less than Y in the Ascii sequence, else #f.")
+            "Return @code{#t} iff @var{x} is less than @var{y} in the ASCII sequence,\n"
+            "else @code{#f}.")
 #define FUNC_NAME s_scm_char_less_p
 {
   SCM_VALIDATE_CHAR (1,x);
   SCM_VALIDATE_CHAR (2,y);
-  return SCM_BOOL(SCM_ICHR(x) < SCM_ICHR(y));
+  return SCM_BOOL(SCM_CHAR(x) < SCM_CHAR(y));
 }
 #undef FUNC_NAME
 
 SCM_DEFINE1 (scm_char_leq_p, "char<=?", scm_tc7_rpsubr,
              (SCM x, SCM y),
-"Return #t iff X is less than or equal to Y in the Ascii sequence, else #f.")
+            "Return @code{#t} iff @var{x} is less than or equal to @var{y} in the\n"
+            "ASCII sequence, else @code{#f}.")
 #define FUNC_NAME s_scm_char_leq_p
 {
   SCM_VALIDATE_CHAR (1,x);
   SCM_VALIDATE_CHAR (2,y);
-  return SCM_BOOL(SCM_ICHR(x) <= SCM_ICHR(y));
+  return SCM_BOOL(SCM_CHAR(x) <= SCM_CHAR(y));
 }
 #undef FUNC_NAME
 
 SCM_DEFINE1 (scm_char_gr_p, "char>?", scm_tc7_rpsubr,
              (SCM x, SCM y),
-"Return #t iff X is greater than Y in the Ascii sequence, else #f.")
+            "Return @code{#t} iff @var{x} is greater than @var{y} in the ASCII\n"
+            "sequence, else @code{#f}.")
 #define FUNC_NAME s_scm_char_gr_p
 {
   SCM_VALIDATE_CHAR (1,x);
   SCM_VALIDATE_CHAR (2,y);
-  return SCM_BOOL(SCM_ICHR(x) > SCM_ICHR(y));
+  return SCM_BOOL(SCM_CHAR(x) > SCM_CHAR(y));
 }
 #undef FUNC_NAME
 
 SCM_DEFINE1 (scm_char_geq_p, "char>=?", scm_tc7_rpsubr,
              (SCM x, SCM y),
-"Return #t iff X is greater than or equal to Y in the Ascii sequence, else #f.")
+            "Return @code{#t} iff @var{x} is greater than or equal to @var{y} in the\n"
+            "ASCII sequence, else @code{#f}.")
 #define FUNC_NAME s_scm_char_geq_p
 {
   SCM_VALIDATE_CHAR (1,x);
   SCM_VALIDATE_CHAR (2,y);
-  return SCM_BOOL(SCM_ICHR(x) >= SCM_ICHR(y));
+  return SCM_BOOL(SCM_CHAR(x) >= SCM_CHAR(y));
 }
 #undef FUNC_NAME
 
 SCM_DEFINE1 (scm_char_ci_eq_p, "char-ci=?", scm_tc7_rpsubr,
              (SCM x, SCM y),
-"Return #t iff X is the same character as Y ignoring case, else #f.")
+            "Return @code{#t} iff @var{x} is the same character as @var{y} ignoring\n"
+            "case, else @code{#f}.")
 #define FUNC_NAME s_scm_char_ci_eq_p
 {
   SCM_VALIDATE_CHAR (1,x);
   SCM_VALIDATE_CHAR (2,y);
-  return SCM_BOOL(scm_upcase(SCM_ICHR(x))==scm_upcase(SCM_ICHR(y)));
+  return SCM_BOOL(scm_upcase(SCM_CHAR(x))==scm_upcase(SCM_CHAR(y)));
 }
 #undef FUNC_NAME
 
 SCM_DEFINE1 (scm_char_ci_less_p, "char-ci<?", scm_tc7_rpsubr,
              (SCM x, SCM y),
-"Return #t iff X is less than Y in the Ascii sequence ignoring case, else #f.")
+            "Return @code{#t} iff @var{x} is less than @var{y} in the ASCII sequence\n"
+            "ignoring case, else @code{#f}.")
 #define FUNC_NAME s_scm_char_ci_less_p
 {
   SCM_VALIDATE_CHAR (1,x);
   SCM_VALIDATE_CHAR (2,y);
-  return SCM_BOOL((scm_upcase(SCM_ICHR(x))) < scm_upcase(SCM_ICHR(y)));
+  return SCM_BOOL((scm_upcase(SCM_CHAR(x))) < scm_upcase(SCM_CHAR(y)));
 }
 #undef FUNC_NAME
 
 SCM_DEFINE1 (scm_char_ci_leq_p, "char-ci<=?", scm_tc7_rpsubr,
              (SCM x, SCM y),
-"Return #t iff X is less than or equal to Y in the Ascii sequence ignoring case, else #f.")
+            "Return @code{#t} iff @var{x} is less than or equal to @var{y} in the\n"
+            "ASCII sequence ignoring case, else @code{#f}.")
 #define FUNC_NAME s_scm_char_ci_leq_p
 {
   SCM_VALIDATE_CHAR (1,x);
   SCM_VALIDATE_CHAR (2,y);
-  return SCM_BOOL(scm_upcase(SCM_ICHR(x)) <= scm_upcase(SCM_ICHR(y)));
+  return SCM_BOOL(scm_upcase(SCM_CHAR(x)) <= scm_upcase(SCM_CHAR(y)));
 }
 #undef FUNC_NAME
 
 SCM_DEFINE1 (scm_char_ci_gr_p, "char-ci>?", scm_tc7_rpsubr,
              (SCM x, SCM y),
-"Return #t iff X is greater than Y in the Ascii sequence ignoring case, else #f.")
+            "Return @code{#t} iff @var{x} is greater than @var{y} in the ASCII\n"
+            "sequence ignoring case, else @code{#f}.")
 #define FUNC_NAME s_scm_char_ci_gr_p
 {
   SCM_VALIDATE_CHAR (1,x);
   SCM_VALIDATE_CHAR (2,y);
-  return SCM_BOOL(scm_upcase(SCM_ICHR(x)) > scm_upcase(SCM_ICHR(y)));
+  return SCM_BOOL(scm_upcase(SCM_CHAR(x)) > scm_upcase(SCM_CHAR(y)));
 }
 #undef FUNC_NAME
 
 SCM_DEFINE1 (scm_char_ci_geq_p, "char-ci>=?", scm_tc7_rpsubr,
              (SCM x, SCM y),
-"Return #t iff X is greater than or equal to Y in the Ascii sequence ignoring case, else #f.")
+            "Return @code{#t} iff @var{x} is greater than or equal to @var{y} in the\n"
+            "ASCII sequence ignoring case, else @code{#f}.")
 #define FUNC_NAME s_scm_char_ci_geq_p
 {
   SCM_VALIDATE_CHAR (1,x);
   SCM_VALIDATE_CHAR (2,y);
-  return SCM_BOOL(scm_upcase(SCM_ICHR(x)) >= scm_upcase(SCM_ICHR(y)));
+  return SCM_BOOL(scm_upcase(SCM_CHAR(x)) >= scm_upcase(SCM_CHAR(y)));
 }
 #undef FUNC_NAME
 
 
 SCM_DEFINE (scm_char_alphabetic_p, "char-alphabetic?", 1, 0, 0,
            (SCM chr),
-"Return #t iff CHR is alphabetic, else #f.
-Alphabetic means the same thing as the isalpha C library function.")
+           "Return @code{#t} iff @var{chr} is alphabetic, else @code{#f}.\n"
+           "Alphabetic means the same thing as the isalpha C library function.")
 #define FUNC_NAME s_scm_char_alphabetic_p
 {
   SCM_VALIDATE_CHAR (1,chr);
-  return SCM_BOOL(isascii(SCM_ICHR(chr)) && isalpha(SCM_ICHR(chr)));
+  return SCM_BOOL(isascii(SCM_CHAR(chr)) && isalpha(SCM_CHAR(chr)));
 }
 #undef FUNC_NAME
 
 SCM_DEFINE (scm_char_numeric_p, "char-numeric?", 1, 0, 0, 
            (SCM chr),
-"Return #t iff CHR is numeric, else #f.
-Numeric means the same thing as the isdigit C library function.")
+           "Return @code{#t} iff @var{chr} is numeric, else @code{#f}.\n"
+           "Numeric means the same thing as the isdigit C library function.")
 #define FUNC_NAME s_scm_char_numeric_p
 {
   SCM_VALIDATE_CHAR (1,chr);
-  return SCM_BOOL(isascii(SCM_ICHR(chr)) && isdigit(SCM_ICHR(chr)));
+  return SCM_BOOL(isascii(SCM_CHAR(chr)) && isdigit(SCM_CHAR(chr)));
 }
 #undef FUNC_NAME
 
 SCM_DEFINE (scm_char_whitespace_p, "char-whitespace?", 1, 0, 0, 
            (SCM chr),
-"Return #t iff CHR is whitespace, else #f.
-Whitespace means the same thing as the isspace C library function.")
+           "Return @code{#t} iff @var{chr} is whitespace, else @code{#f}.\n"
+           "Whitespace means the same thing as the isspace C library function.")
 #define FUNC_NAME s_scm_char_whitespace_p
 {
   SCM_VALIDATE_CHAR (1,chr);
-  return SCM_BOOL(isascii(SCM_ICHR(chr)) && isspace(SCM_ICHR(chr)));
+  return SCM_BOOL(isascii(SCM_CHAR(chr)) && isspace(SCM_CHAR(chr)));
 }
 #undef FUNC_NAME
 
@@ -210,24 +216,24 @@ Whitespace means the same thing as the isspace C library function.")
 
 SCM_DEFINE (scm_char_upper_case_p, "char-upper-case?", 1, 0, 0, 
            (SCM chr),
-"Return #t iff CHR is uppercase, else #f.
-Uppercase means the same thing as the isupper C library function.")
+           "Return @code{#t} iff @var{chr} is uppercase, else @code{#f}.\n"
+           "Uppercase means the same thing as the isupper C library function.")
 #define FUNC_NAME s_scm_char_upper_case_p
 {
   SCM_VALIDATE_CHAR (1,chr);
-  return SCM_BOOL(isascii(SCM_ICHR(chr)) && isupper(SCM_ICHR(chr)));
+  return SCM_BOOL(isascii(SCM_CHAR(chr)) && isupper(SCM_CHAR(chr)));
 }
 #undef FUNC_NAME
 
 
 SCM_DEFINE (scm_char_lower_case_p, "char-lower-case?", 1, 0, 0, 
            (SCM chr),
-"Return #t iff CHR is lowercase, else #f.
-Lowercase means the same thing as the islower C library function.")
+           "Return @code{#t} iff @var{chr} is lowercase, else @code{#f}.\n"
+           "Lowercase means the same thing as the islower C library function.")
 #define FUNC_NAME s_scm_char_lower_case_p
 {
   SCM_VALIDATE_CHAR (1,chr);
-  return SCM_BOOL(isascii(SCM_ICHR(chr)) && islower(SCM_ICHR(chr)));
+  return SCM_BOOL(isascii(SCM_CHAR(chr)) && islower(SCM_CHAR(chr)));
 }
 #undef FUNC_NAME
 
@@ -235,13 +241,13 @@ Lowercase means the same thing as the islower C library function.")
 
 SCM_DEFINE (scm_char_is_both_p, "char-is-both?", 1, 0, 0, 
             (SCM chr),
-"Return #t iff CHR is either uppercase or lowercase, else #f.
-Uppercase and lowercase are as defined by the isupper and islower
-C library functions.")
+           "Return @code{#t} iff @var{chr} is either uppercase or lowercase, else @code{#f}.\n"
+           "Uppercase and lowercase are as defined by the isupper and islower\n"
+           "C library functions.")
 #define FUNC_NAME s_scm_char_is_both_p
 {
   SCM_VALIDATE_CHAR (1,chr);
-  return SCM_BOOL(isascii(SCM_ICHR(chr)) && (isupper(SCM_ICHR(chr)) || islower(SCM_ICHR(chr))));
+  return SCM_BOOL(isascii(SCM_CHAR(chr)) && (isupper(SCM_CHAR(chr)) || islower(SCM_CHAR(chr))));
 }
 #undef FUNC_NAME
 
@@ -250,11 +256,12 @@ C library functions.")
 
 SCM_DEFINE (scm_char_to_integer, "char->integer", 1, 0, 0, 
             (SCM chr),
-"Return the number corresponding to ordinal position of CHR in the Ascii sequence.")
+           "Return the number corresponding to ordinal position of @var{chr} in the\n"
+           "ASCII sequence.")
 #define FUNC_NAME s_scm_char_to_integer
 {
   SCM_VALIDATE_CHAR (1,chr);
-  return scm_ulong2num((unsigned long)SCM_ICHR(chr));
+  return scm_ulong2num((unsigned long)SCM_CHAR(chr));
 }
 #undef FUNC_NAME
 
@@ -262,33 +269,33 @@ SCM_DEFINE (scm_char_to_integer, "char->integer", 1, 0, 0,
 
 SCM_DEFINE (scm_integer_to_char, "integer->char", 1, 0, 0, 
            (SCM n),
-"Return the character at position N in the Ascii sequence.")
+           "Return the character at position @var{n} in the ASCII sequence.")
 #define FUNC_NAME s_scm_integer_to_char
 {
-  unsigned long ni = 0xffff & SCM_NUM2ULONG (1,n);
-  return SCM_MAKICHR(ni);
+  SCM_VALIDATE_INUM_RANGE (1, n, 0, 256);
+  return SCM_MAKE_CHAR (SCM_INUM (n));
 }
 #undef FUNC_NAME
 
 
 SCM_DEFINE (scm_char_upcase, "char-upcase", 1, 0, 0, 
            (SCM chr),
-"Return the uppercase character version of CHR.")
+           "Return the uppercase character version of @var{chr}.")
 #define FUNC_NAME s_scm_char_upcase
 {
   SCM_VALIDATE_CHAR (1,chr);
-  return SCM_MAKICHR(scm_upcase(SCM_ICHR(chr)));
+  return SCM_MAKE_CHAR(scm_upcase(SCM_CHAR(chr)));
 }
 #undef FUNC_NAME
 
 
 SCM_DEFINE (scm_char_downcase, "char-downcase", 1, 0, 0, 
            (SCM chr),
-"Return the lowercase character version of CHR.")
+           "Return the lowercase character version of @var{chr}.")
 #define FUNC_NAME s_scm_char_downcase
 {
   SCM_VALIDATE_CHAR (1,chr);
-  return SCM_MAKICHR(scm_downcase(SCM_ICHR(chr)));
+  return SCM_MAKE_CHAR(scm_downcase(SCM_CHAR(chr)));
 }
 #undef FUNC_NAME
 
@@ -397,6 +404,14 @@ int scm_n_charnames = sizeof (scm_charnames) / sizeof (char *);
 void
 scm_init_chars ()
 {
-#include "chars.x"
+#ifndef SCM_MAGIC_SNARFER
+#include "libguile/chars.x"
+#endif
 }
 
+
+/*
+  Local Variables:
+  c-file-style: "gnu"
+  End:
+*/