* Separate the handling of OPEN flags between ports and directories.
[bpt/guile.git] / libguile / validate.h
index 4115c82..2212c27 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: validate.h,v 1.18 2000-10-25 11:01:03 dirk Exp $ */
+/* $Id: validate.h,v 1.25 2001-01-24 00:02:43 dirk Exp $ */
 /*     Copyright (C) 1999, 2000 Free Software Foundation, Inc.
  *
  * This program is free software; you can redistribute it and/or modify
@@ -63,6 +63,9 @@
 #define SCM_MISC_ERROR(str, args) \
   do { scm_misc_error (FUNC_NAME, str, args); } while (0)
 
+#define SCM_WRONG_NUM_ARGS() \
+  do { scm_wrong_num_args (scm_makfrom0str (FUNC_NAME)); } while (0)
+
 #define SCM_WRONG_TYPE_ARG(pos, obj) \
   do { scm_wrong_type_arg (FUNC_NAME, pos, obj); } while (0)
 
     cvar = SCM_CHAR (scm); \
   } while (0)
 
-#define SCM_VALIDATE_ROSTRING(pos, str) SCM_MAKE_VALIDATE (pos, str, ROSTRINGP)
-
-#define SCM_VALIDATE_ROSTRING_COPY(pos, str, cvar) \
-  do { \
-    SCM_ASSERT (SCM_ROSTRINGP (str), str, pos, FUNC_NAME); \
-    cvar = SCM_ROCHARS (str); \
-  } while (0)
-
-#define SCM_VALIDATE_NULLORROSTRING_COPY(pos, str, cvar) \
-  do { \
-    SCM_ASSERT (SCM_FALSEP (str) || SCM_ROSTRINGP (str), \
-                str, pos, FUNC_NAME); \
-    if (SCM_FALSEP(str)) \
-      cvar = NULL; \
-    else \
-      cvar = SCM_ROCHARS(str); \
-  } while (0)
-
 #define SCM_VALIDATE_STRING(pos, str) SCM_MAKE_VALIDATE (pos, str, STRINGP)
 
 #define SCM_VALIDATE_STRING_COPY(pos, str, cvar) \
     cvar = SCM_STRING_CHARS(str); \
   } while (0)
 
-#define SCM_VALIDATE_RWSTRING(pos, str) \
-  do { \
-    SCM_ASSERT (SCM_STRINGP (str), str, pos, FUNC_NAME); \
-    if (!SCM_RWSTRINGP (str)) \
-      scm_misc_error (FUNC_NAME, "argument is a read-only string", str); \
+/* validate a string and optional start/end arguments which default to
+   0/string-len.  this is unrelated to the old shared substring
+   support, so please do not deprecate it :) */
+#define SCM_VALIDATE_SUBSTRING_SPEC_COPY(pos_str, str, c_str, \
+                                         pos_start, start, c_start,\
+                                         pos_end, end, c_end) \
+  do {\
+    SCM_VALIDATE_STRING_COPY (pos_str, str, c_str);\
+    SCM_VALIDATE_INUM_DEF_COPY (pos_start, start, 0, c_start);\
+    SCM_VALIDATE_INUM_DEF_COPY (pos_end, end, SCM_STRING_LENGTH (str), c_end);\
+    SCM_ASSERT_RANGE (pos_start, start,\
+                      0 <= c_start && c_start <= SCM_STRING_LENGTH (str));\
+    SCM_ASSERT_RANGE (pos_end, end,\
+                     c_start <= c_end && c_end <= SCM_STRING_LENGTH (str));\
   } while (0)
 
 #define SCM_VALIDATE_REAL(pos, z) SCM_MAKE_VALIDATE (pos, z, REALP)
 
+#define SCM_VALIDATE_NUMBER(pos, z) SCM_MAKE_VALIDATE (pos, z, NUMBERP)
+
 #define SCM_VALIDATE_NUMBER_COPY(pos, z, cvar) \
   do {                                         \
     if (SCM_INUMP (z))                         \
 
 #define SCM_VALIDATE_SMOB(pos, obj, type) \
   do { \
-    SCM_ASSERT ((SCM_NIMP (obj) && SCM_TYP16 (obj) == scm_tc16_ ## type), \
+    SCM_ASSERT (SCM_TYP16_PREDICATE (scm_tc16_ ## type, obj), \
                 obj, pos, FUNC_NAME); \
   } while (0)
 
 
 #define SCM_VALIDATE_RGXP(pos, a) SCM_MAKE_VALIDATE (pos, a, RGXP)
 
-#define SCM_VALIDATE_OPDIR(pos, port) SCM_MAKE_VALIDATE (pos, port, OPDIRP)
-
 #define SCM_VALIDATE_DIR(pos, port) SCM_MAKE_VALIDATE (pos, port, DIRP)
 
 #define SCM_VALIDATE_PORT(pos, port) SCM_MAKE_VALIDATE (pos, port, PORTP)
 
 #define SCM_VALIDATE_STRINGORSUBSTR SCM_VALIDATE_STRING
 
+#define SCM_VALIDATE_ROSTRING(pos, str) SCM_MAKE_VALIDATE (pos, str, ROSTRINGP)
+
+#define SCM_VALIDATE_ROSTRING_COPY(pos, str, cvar) \
+  do { \
+    SCM_ASSERT (SCM_ROSTRINGP (str), str, pos, FUNC_NAME); \
+    cvar = SCM_ROCHARS (str); \
+  } while (0)
+
+#define SCM_VALIDATE_NULLORROSTRING_COPY(pos, str, cvar) \
+  do { \
+    SCM_ASSERT (SCM_FALSEP (str) || SCM_ROSTRINGP (str), \
+                str, pos, FUNC_NAME); \
+    if (SCM_FALSEP(str)) \
+      cvar = NULL; \
+    else \
+      cvar = SCM_ROCHARS(str); \
+  } while (0)
+
+#define SCM_VALIDATE_RWSTRING(pos, str) \
+  do { \
+    SCM_ASSERT (SCM_STRINGP (str), str, pos, FUNC_NAME); \
+    if (!SCM_RWSTRINGP (str)) \
+      scm_misc_error (FUNC_NAME, "argument is a read-only string", str); \
+  } while (0)
+
+#define SCM_VALIDATE_OPDIR(pos, port) SCM_MAKE_VALIDATE (pos, port, OPDIRP)
+
 #endif  /* SCM_DEBUG_DEPRECATED == 0 */
 
 #endif