diff options
author | Greg J. Badros <gjb@cs.washington.edu> | 1999-12-12 02:36:16 +0000 |
---|---|---|
committer | Greg J. Badros <gjb@cs.washington.edu> | 1999-12-12 02:36:16 +0000 |
commit | 1bbd0b849f6b90f1ffe57e586e4ee5a884f84a11 (patch) | |
tree | 79120a96365e0fa3324174bfd08d731ca8311d64 /libguile/chars.c | |
parent | 6e7069385db8cf96dfbe51cf65ace161942a32c9 (diff) | |
download | guile-1bbd0b849f6b90f1ffe57e586e4ee5a884f84a11.tar.gz |
* *.c: Pervasive software-engineering-motivated rewrite of
function headers and argument checking. Switched SCM_PROC,
SCM_PROC1 macros to be GUILE_PROC, GUILE_PROC1 (may change names
later, but was useful to keep old versions around while migrate)
that has docstrings and argument lists embedded in the GUILE_PROC
macro invocations that expand into a function header. Use lots of
new SCM_VALIDATE_* macros to simplify error checking and reduce
tons of redundancy. This is very similar to what I did for Scwm.
Note that none of the extraction of the docstrings, nor software
engineering checks of Scwm is yet added to Guile. I'll work on
that tomorrow, I expect.
* Makefile.am: Added scm_validate.h to modinclude_HEADERS.
* chars.c: Added docstrings for the primitives defined in here.
* snarf.h: Added GUILE_PROC, GUILE_PROC1. Added
SCM_REGISTER_PROC to be like old SCM_PROC, though old SCM_PROC
still remains for now. Changed naming convention for the s_foo
string name of the primitive to be s_scm_foo for ease of use with
the macro.
* scm_validate.h: Lots of new SCM_VALIDATE macros to simplify
argument checking through guile. Maybe some of these should be
folded into the header file for the types they check, but for now
it was easiest to just stick them all in one place.
Diffstat (limited to 'libguile/chars.c')
-rw-r--r-- | libguile/chars.c | 332 |
1 files changed, 164 insertions, 168 deletions
diff --git a/libguile/chars.c b/libguile/chars.c index f5f7fd402..121d133ca 100644 --- a/libguile/chars.c +++ b/libguile/chars.c @@ -38,263 +38,259 @@ * If you write modifications of your own for GUILE, it is your choice * 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 */ + #include <stdio.h> #include <ctype.h> #include "_scm.h" +#include "scm_validate.h" #include "chars.h" - - -SCM_PROC(s_char_p, "char?", 1, 0, 0, scm_char_p); - -SCM -scm_char_p(x) - SCM x; +GUILE_PROC (scm_char_p, "char?", 1, 0, 0, + (SCM x), +"Return #t iff X is a character, else #f.") +#define FUNC_NAME s_scm_char_p { return SCM_ICHRP(x) ? SCM_BOOL_T : SCM_BOOL_F; } +#undef FUNC_NAME -SCM_PROC1 (s_char_eq_p, "char=?", scm_tc7_rpsubr, scm_char_eq_p); - -SCM -scm_char_eq_p(x, y) - SCM x; - SCM y; +GUILE_PROC1 (scm_char_eq_p, "char=?", scm_tc7_rpsubr, + (SCM x, SCM y), +"Return #t iff X is the same character as Y, else #f.") +#define FUNC_NAME s_scm_char_eq_p { - SCM_ASSERT(SCM_ICHRP(x), x, SCM_ARG1, s_char_eq_p); - SCM_ASSERT(SCM_ICHRP(y), y, SCM_ARG2, s_char_eq_p); - return (SCM_ICHR(x) == SCM_ICHR(y)) ? SCM_BOOL_T : SCM_BOOL_F; + SCM_VALIDATE_CHAR(1,x); + SCM_VALIDATE_CHAR(2,y); + return SCM_BOOL(SCM_ICHR(x) == SCM_ICHR(y)); } +#undef FUNC_NAME -SCM_PROC1 (s_char_less_p, "char<?", scm_tc7_rpsubr, scm_char_less_p); - -SCM -scm_char_less_p(x, y) - SCM x; - SCM y; +GUILE_PROC1 (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.") +#define FUNC_NAME s_scm_char_less_p { - SCM_ASSERT(SCM_ICHRP(x), x, SCM_ARG1, s_char_less_p); - SCM_ASSERT(SCM_ICHRP(y), y, SCM_ARG2, s_char_less_p); - return (SCM_ICHR(x) < SCM_ICHR(y)) ? SCM_BOOL_T : SCM_BOOL_F; + SCM_VALIDATE_CHAR(1,x); + SCM_VALIDATE_CHAR(2,y); + return SCM_BOOL(SCM_ICHR(x) < SCM_ICHR(y)); } +#undef FUNC_NAME -SCM_PROC1 (s_char_leq_p, "char<=?", scm_tc7_rpsubr, scm_char_leq_p); - -SCM -scm_char_leq_p(x, y) - SCM x; - SCM y; +GUILE_PROC1 (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.") +#define FUNC_NAME s_scm_char_leq_p { - SCM_ASSERT(SCM_ICHRP(x), x, SCM_ARG1, s_char_leq_p); - SCM_ASSERT(SCM_ICHRP(y), y, SCM_ARG2, s_char_leq_p); - return (SCM_ICHR(x) <= SCM_ICHR(y)) ? SCM_BOOL_T : SCM_BOOL_F; + SCM_VALIDATE_CHAR(1,x); + SCM_VALIDATE_CHAR(2,y); + return SCM_BOOL(SCM_ICHR(x) <= SCM_ICHR(y)); } +#undef FUNC_NAME -SCM_PROC1 (s_char_gr_p, "char>?", scm_tc7_rpsubr, scm_char_gr_p); - -SCM -scm_char_gr_p(x, y) - SCM x; - SCM y; +GUILE_PROC1 (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.") +#define FUNC_NAME s_scm_char_gr_p { - SCM_ASSERT(SCM_ICHRP(x), x, SCM_ARG1, s_char_gr_p); - SCM_ASSERT(SCM_ICHRP(y), y, SCM_ARG2, s_char_gr_p); - return (SCM_ICHR(x) > SCM_ICHR(y)) ? SCM_BOOL_T : SCM_BOOL_F; + SCM_VALIDATE_CHAR(1,x); + SCM_VALIDATE_CHAR(2,y); + return SCM_BOOL(SCM_ICHR(x) > SCM_ICHR(y)); } +#undef FUNC_NAME -SCM_PROC1 (s_char_geq_p, "char>=?", scm_tc7_rpsubr, scm_char_geq_p); - -SCM -scm_char_geq_p(x, y) - SCM x; - SCM y; +GUILE_PROC1 (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.") +#define FUNC_NAME s_scm_char_geq_p { - SCM_ASSERT(SCM_ICHRP(x), x, SCM_ARG1, s_char_geq_p); - SCM_ASSERT(SCM_ICHRP(y), y, SCM_ARG2, s_char_geq_p); - return (SCM_ICHR(x) >= SCM_ICHR(y)) ? SCM_BOOL_T : SCM_BOOL_F; + SCM_VALIDATE_CHAR(1,x); + SCM_VALIDATE_CHAR(2,y); + return SCM_BOOL(SCM_ICHR(x) >= SCM_ICHR(y)); } +#undef FUNC_NAME -SCM_PROC1 (s_char_ci_eq_p, "char-ci=?", scm_tc7_rpsubr, scm_char_ci_eq_p); - -SCM -scm_char_ci_eq_p(x, y) - SCM x; - SCM y; +GUILE_PROC1 (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.") +#define FUNC_NAME s_scm_char_ci_eq_p { - SCM_ASSERT(SCM_ICHRP(x), x, SCM_ARG1, s_char_ci_eq_p); - SCM_ASSERT(SCM_ICHRP(y), y, SCM_ARG2, s_char_ci_eq_p); - return (scm_upcase(SCM_ICHR(x))==scm_upcase(SCM_ICHR(y))) ? SCM_BOOL_T : SCM_BOOL_F; + SCM_VALIDATE_CHAR(1,x); + SCM_VALIDATE_CHAR(2,y); + return SCM_BOOL(scm_upcase(SCM_ICHR(x))==scm_upcase(SCM_ICHR(y))); } +#undef FUNC_NAME -SCM_PROC1 (s_char_ci_less_p, "char-ci<?", scm_tc7_rpsubr, scm_char_ci_less_p); - -SCM -scm_char_ci_less_p(x, y) - SCM x; - SCM y; +GUILE_PROC1 (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.") +#define FUNC_NAME s_scm_char_ci_less_p { - SCM_ASSERT(SCM_ICHRP(x), x, SCM_ARG1, s_char_ci_less_p); - SCM_ASSERT(SCM_ICHRP(y), y, SCM_ARG2, s_char_ci_less_p); - return (scm_upcase(SCM_ICHR(x)) < scm_upcase(SCM_ICHR(y))) ? SCM_BOOL_T : SCM_BOOL_F; + SCM_VALIDATE_CHAR(1,x); + SCM_VALIDATE_CHAR(2,y); + return SCM_BOOL((scm_upcase(SCM_ICHR(x))) < scm_upcase(SCM_ICHR(y))); } +#undef FUNC_NAME -SCM_PROC1 (s_char_ci_leq_p, "char-ci<=?", scm_tc7_rpsubr, scm_char_ci_leq_p); - -SCM -scm_char_ci_leq_p(x, y) - SCM x; - SCM y; +GUILE_PROC1 (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.") +#define FUNC_NAME s_scm_char_ci_leq_p { - SCM_ASSERT(SCM_ICHRP(x), x, SCM_ARG1, s_char_ci_leq_p); - SCM_ASSERT(SCM_ICHRP(y), y, SCM_ARG2, s_char_ci_leq_p); - return (scm_upcase(SCM_ICHR(x)) <= scm_upcase(SCM_ICHR(y))) ? SCM_BOOL_T : SCM_BOOL_F; + SCM_VALIDATE_CHAR(1,x); + SCM_VALIDATE_CHAR(2,y); + return SCM_BOOL(scm_upcase(SCM_ICHR(x)) <= scm_upcase(SCM_ICHR(y))); } +#undef FUNC_NAME -SCM_PROC1 (s_char_ci_gr_p, "char-ci>?", scm_tc7_rpsubr, scm_char_ci_gr_p); - -SCM -scm_char_ci_gr_p(x, y) - SCM x; - SCM y; +GUILE_PROC1 (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.") +#define FUNC_NAME s_scm_char_ci_gr_p { - SCM_ASSERT(SCM_ICHRP(x), x, SCM_ARG1, s_char_ci_gr_p); - SCM_ASSERT(SCM_ICHRP(y), y, SCM_ARG2, s_char_ci_gr_p); - return (scm_upcase(SCM_ICHR(x)) > scm_upcase(SCM_ICHR(y))) ? SCM_BOOL_T : SCM_BOOL_F; + SCM_VALIDATE_CHAR(1,x); + SCM_VALIDATE_CHAR(2,y); + return SCM_BOOL(scm_upcase(SCM_ICHR(x)) > scm_upcase(SCM_ICHR(y))); } +#undef FUNC_NAME -SCM_PROC1 (s_char_ci_geq_p, "char-ci>=?", scm_tc7_rpsubr, scm_char_ci_geq_p); - -SCM -scm_char_ci_geq_p(x, y) - SCM x; - SCM y; +GUILE_PROC1 (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.") +#define FUNC_NAME s_scm_char_ci_geq_p { - SCM_ASSERT(SCM_ICHRP(x), x, SCM_ARG1, s_char_ci_geq_p); - SCM_ASSERT(SCM_ICHRP(y), y, SCM_ARG2, s_char_ci_geq_p); - return (scm_upcase(SCM_ICHR(x)) >= scm_upcase(SCM_ICHR(y))) ? SCM_BOOL_T : SCM_BOOL_F; + SCM_VALIDATE_CHAR(1,x); + SCM_VALIDATE_CHAR(2,y); + return SCM_BOOL(scm_upcase(SCM_ICHR(x)) >= scm_upcase(SCM_ICHR(y))); } +#undef FUNC_NAME -SCM_PROC(s_char_alphabetic_p, "char-alphabetic?", 1, 0, 0, scm_char_alphabetic_p); - -SCM -scm_char_alphabetic_p(chr) - SCM chr; +GUILE_PROC(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.") +#define FUNC_NAME s_scm_char_alphabetic_p { - SCM_ASSERT(SCM_ICHRP(chr), chr, SCM_ARG1, s_char_alphabetic_p); - return (isascii(SCM_ICHR(chr)) && isalpha(SCM_ICHR(chr))) ? SCM_BOOL_T : SCM_BOOL_F; + SCM_VALIDATE_CHAR(1,chr); + return SCM_BOOL(isascii(SCM_ICHR(chr)) && isalpha(SCM_ICHR(chr))); } +#undef FUNC_NAME -SCM_PROC(s_char_numeric_p, "char-numeric?", 1, 0, 0, scm_char_numeric_p); - -SCM -scm_char_numeric_p(chr) - SCM chr; +GUILE_PROC(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.") +#define FUNC_NAME s_scm_char_numeric_p { - SCM_ASSERT(SCM_ICHRP(chr), chr, SCM_ARG1, s_char_numeric_p); - return (isascii(SCM_ICHR(chr)) && isdigit(SCM_ICHR(chr))) ? SCM_BOOL_T : SCM_BOOL_F; + SCM_VALIDATE_CHAR(1,chr); + return SCM_BOOL(isascii(SCM_ICHR(chr)) && isdigit(SCM_ICHR(chr))); } +#undef FUNC_NAME -SCM_PROC(s_char_whitespace_p, "char-whitespace?", 1, 0, 0, scm_char_whitespace_p); - -SCM -scm_char_whitespace_p(chr) - SCM chr; +GUILE_PROC(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.") +#define FUNC_NAME s_scm_char_whitespace_p { - SCM_ASSERT(SCM_ICHRP(chr), chr, SCM_ARG1, s_char_whitespace_p); - return (isascii(SCM_ICHR(chr)) && isspace(SCM_ICHR(chr))) ? SCM_BOOL_T : SCM_BOOL_F; + SCM_VALIDATE_CHAR(1,chr); + return SCM_BOOL(isascii(SCM_ICHR(chr)) && isspace(SCM_ICHR(chr))); } +#undef FUNC_NAME -SCM_PROC(s_char_upper_case_p, "char-upper-case?", 1, 0, 0, scm_char_upper_case_p); - -SCM -scm_char_upper_case_p(chr) - SCM chr; +GUILE_PROC(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.") +#define FUNC_NAME s_scm_char_upper_case_p { - SCM_ASSERT(SCM_ICHRP(chr), chr, SCM_ARG1, s_char_upper_case_p); - return (isascii(SCM_ICHR(chr)) && isupper(SCM_ICHR(chr))) ? SCM_BOOL_T : SCM_BOOL_F; + SCM_VALIDATE_CHAR(1,chr); + return SCM_BOOL(isascii(SCM_ICHR(chr)) && isupper(SCM_ICHR(chr))); } +#undef FUNC_NAME -SCM_PROC(s_char_lower_case_p, "char-lower-case?", 1, 0, 0, scm_char_lower_case_p); - -SCM -scm_char_lower_case_p(chr) - SCM chr; +GUILE_PROC(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.") +#define FUNC_NAME s_scm_char_lower_case_p { - SCM_ASSERT(SCM_ICHRP(chr), chr, SCM_ARG1, s_char_lower_case_p); - return (isascii(SCM_ICHR(chr)) && islower(SCM_ICHR(chr))) ? SCM_BOOL_T : SCM_BOOL_F; + SCM_VALIDATE_CHAR(1,chr); + return SCM_BOOL(isascii(SCM_ICHR(chr)) && islower(SCM_ICHR(chr))); } +#undef FUNC_NAME -SCM_PROC (s_char_is_both_p, "char-is-both?", 1, 0, 0, scm_char_is_both_p); - -SCM -scm_char_is_both_p (chr) - SCM chr; +GUILE_PROC (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.") +#define FUNC_NAME s_scm_char_is_both_p { - SCM_ASSERT(SCM_ICHRP(chr), chr, SCM_ARG1, s_char_upper_case_p); - return ((isascii(SCM_ICHR(chr)) && (isupper(SCM_ICHR(chr)) || islower(SCM_ICHR(chr)))) - ? SCM_BOOL_T - : SCM_BOOL_F); + SCM_VALIDATE_CHAR(1,chr); + return SCM_BOOL(isascii(SCM_ICHR(chr)) && (isupper(SCM_ICHR(chr)) || islower(SCM_ICHR(chr)))); } +#undef FUNC_NAME -SCM_PROC(s_char_to_integer, "char->integer", 1, 0, 0, scm_char_to_integer); - -SCM -scm_char_to_integer(chr) - SCM chr; +GUILE_PROC (scm_char_to_integer, "char->integer", 1, 0, 0, + (SCM chr), +"Return the number corresponding to ordinal position of CHR in the Ascii sequence.") +#define FUNC_NAME s_scm_char_to_integer { - SCM_ASSERT(SCM_ICHRP(chr), chr, SCM_ARG1, s_char_to_integer); + SCM_VALIDATE_CHAR(1,chr); return scm_ulong2num((unsigned long)SCM_ICHR(chr)); } +#undef FUNC_NAME -SCM_PROC(s_integer_to_char, "integer->char", 1, 0, 0, scm_integer_to_char); - -SCM -scm_integer_to_char(n) - SCM n; +GUILE_PROC(scm_integer_to_char, "integer->char", 1, 0, 0, + (SCM n), +"Return the character at position N in the Ascii sequence.") +#define FUNC_NAME s_scm_integer_to_char { - unsigned long ni; - - ni = 0xffff & scm_num2ulong (n, (char *)SCM_ARG1, s_integer_to_char); - return SCM_MAKICHR(SCM_INUM(n)); + unsigned long ni = 0xffff & scm_num2ulong (n, (char *)SCM_ARG1, FUNC_NAME); + return SCM_MAKICHR(ni); } +#undef FUNC_NAME -SCM_PROC(s_char_upcase, "char-upcase", 1, 0, 0, scm_char_upcase); - -SCM -scm_char_upcase(chr) - SCM chr; +GUILE_PROC(scm_char_upcase, "char-upcase", 1, 0, 0, + (SCM chr), +"Return the uppercase character version of CHR.") +#define FUNC_NAME s_scm_char_upcase { - SCM_ASSERT(SCM_ICHRP(chr), chr, SCM_ARG1, s_char_upcase); + SCM_VALIDATE_CHAR(1,chr); return SCM_MAKICHR(scm_upcase(SCM_ICHR(chr))); } +#undef FUNC_NAME -SCM_PROC(s_char_downcase, "char-downcase", 1, 0, 0, scm_char_downcase); - -SCM -scm_char_downcase(chr) - SCM chr; +GUILE_PROC(scm_char_downcase, "char-downcase", 1, 0, 0, + (SCM chr), +"Return the lowercase character version of CHR.") +#define FUNC_NAME s_scm_char_downcase { - SCM_ASSERT(SCM_ICHRP(chr), chr, SCM_ARG1, s_char_downcase); + SCM_VALIDATE_CHAR(1,chr); return SCM_MAKICHR(scm_downcase(SCM_ICHR(chr))); } +#undef FUNC_NAME |