r1596: Expanded c-test-fns
authorKevin M. Rosenberg <kevin@rosenberg.net>
Thu, 21 Mar 2002 04:04:45 +0000 (04:04 +0000)
committerKevin M. Rosenberg <kevin@rosenberg.net>
Thu, 21 Mar 2002 04:04:45 +0000 (04:04 +0000)
examples/c-test-fns.c
examples/c-test-fns.cl [new file with mode: 0644]
tests/c-test-fns.c
tests/c-test-fns.cl [new file with mode: 0644]

index 3ff1fde6d8ba938b6b2083cf0b6fb9a4c8970cc8..05244b80601358519d072453e65da11a8763d399 100644 (file)
@@ -6,7 +6,7 @@
  *  Programer:    Kevin M. Rosenberg
  *  Date Started: Mar 2002
  *
- *  CVS Id:   $Id: c-test-fns.c,v 1.1 2002/03/21 02:41:30 kevin Exp $
+ *  CVS Id:   $Id: c-test-fns.c,v 1.2 2002/03/21 04:04:45 kevin Exp $
  *
  * This file, part of UFFI, is Copyright (c) 2002 by Kevin M. Rosenberg
  *
  * you'll need to modify these for other compilers
  ***************************************************************************/
 
+#ifdef WIN32
+#include <windows.h>
+#endif
+
 #include <ctype.h>
 #include <stdlib.h>
 
 
 /* Test of constant input string */
 int
-cstring_count_upper (char* psz)
+#ifdef WIN32
+WINAPI
+#endif
+cs_count_upper (char* psz)
 {
   int count = 0;
-  while (*psz) {
-    if (isupper (*psz))
-      ++count;
-    ++psz;
-  }
+
+  if (psz) {
+    while (*psz) {
+      if (isupper (*psz))
+       ++count;
+      ++psz;
+    }
+    return count;
+  } else 
+    return -1;
 }
 
 /* Test of input and output of a string */
 void
-cstring_to_upper (char* psz)
+#ifdef WIN32
+WINAPI
+#endif
+cs_to_upper (char* psz)
 {
-  while (*psz) {
-    *psz = toupper (*psz);
-    ++psz;
+  if (psz) {
+    while (*psz) {
+      *psz = toupper (*psz);
+      ++psz;
+    }
   }
 }
 
 /* Test of an output only string */
 void
-cstring_make_random (int size, char* buffer)
+#ifdef WIN32
+WINAPI
+#endif
+cs_make_random (int size, char* buffer)
 {
   int i;
   for (i = 0; i < size; i++)
diff --git a/examples/c-test-fns.cl b/examples/c-test-fns.cl
new file mode 100644 (file)
index 0000000..3bb4f61
--- /dev/null
@@ -0,0 +1,66 @@
+;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; Base: 10 -*-
+;;;; *************************************************************************
+;;;; FILE IDENTIFICATION
+;;;;
+;;;; Name:          c-test-fns.cl
+;;;; Purpose:       UFFI Example file for zlib compression
+;;;; Programmer:    Kevin M. Rosenberg
+;;;; Date Started:  Mar 2002
+;;;;
+;;;; $Id: c-test-fns.cl,v 1.1 2002/03/21 04:04:45 kevin Exp $
+;;;;
+;;;; This file, part of UFFI, is Copyright (c) 2002 by Kevin M. Rosenberg
+;;;;
+;;;; UFFI users are granted the rights to distribute and use this software
+;;;; as governed by the terms of the Lisp Lesser GNU Public License
+;;;; (http://opensource.franz.com/preamble.html), also known as the LLGPL.
+;;;; *************************************************************************
+
+(in-package :cl-user)
+
+(unless (uffi:load-foreign-library 
+        (make-pathname :name "c-test-fns" 
+                       :type #+(or linux unix)"so" #+(or win32 mswindows) "dll"
+                       :defaults *load-truename*)
+        :supporting-libraries '("c")
+        :force-load t)
+  (warn "Unable to load c-test-fns library"))
+
+(uffi:def-function ("cs_to_upper" cs-to-upper)
+  ((input (* :unsigned-char)))
+  :returning :void
+  )
+
+(defun string-to-upper (str)
+  (uffi:with-foreign-string (str-foreign str)
+    (cs-to-upper str-foreign)
+    (uffi:convert-from-foreign-string str-foreign)))
+
+(uffi:def-function ("cs_count_upper" cs-count-upper)
+  ((input :cstring))
+  :returning :int
+  )
+
+(defun string-count-upper (str)
+  (uffi:with-cstring (str-cstring str)
+    (cs-count-upper str-cstring)))
+
+#+test-uffi
+(format t "~&(string-to-upper \"this is a test\") => ~A" 
+       (string-to-upper "this is a test"))
+
+#+test-uffi
+(format t "~&(string-to-upper nil) => ~A" 
+       (string-to-upper nil))
+
+#+test-uffi
+(format t "~&(string-count-upper \"This is a Test\") => ~A" 
+       (string-count-upper "This is a Test"))
+
+#+test-uffi
+(format t "~&(string-count-upper nil) => ~A" 
+       (string-count-upper nil))
+
+
+
+
index 3ff1fde6d8ba938b6b2083cf0b6fb9a4c8970cc8..05244b80601358519d072453e65da11a8763d399 100644 (file)
@@ -6,7 +6,7 @@
  *  Programer:    Kevin M. Rosenberg
  *  Date Started: Mar 2002
  *
- *  CVS Id:   $Id: c-test-fns.c,v 1.1 2002/03/21 02:41:30 kevin Exp $
+ *  CVS Id:   $Id: c-test-fns.c,v 1.2 2002/03/21 04:04:45 kevin Exp $
  *
  * This file, part of UFFI, is Copyright (c) 2002 by Kevin M. Rosenberg
  *
  * you'll need to modify these for other compilers
  ***************************************************************************/
 
+#ifdef WIN32
+#include <windows.h>
+#endif
+
 #include <ctype.h>
 #include <stdlib.h>
 
 
 /* Test of constant input string */
 int
-cstring_count_upper (char* psz)
+#ifdef WIN32
+WINAPI
+#endif
+cs_count_upper (char* psz)
 {
   int count = 0;
-  while (*psz) {
-    if (isupper (*psz))
-      ++count;
-    ++psz;
-  }
+
+  if (psz) {
+    while (*psz) {
+      if (isupper (*psz))
+       ++count;
+      ++psz;
+    }
+    return count;
+  } else 
+    return -1;
 }
 
 /* Test of input and output of a string */
 void
-cstring_to_upper (char* psz)
+#ifdef WIN32
+WINAPI
+#endif
+cs_to_upper (char* psz)
 {
-  while (*psz) {
-    *psz = toupper (*psz);
-    ++psz;
+  if (psz) {
+    while (*psz) {
+      *psz = toupper (*psz);
+      ++psz;
+    }
   }
 }
 
 /* Test of an output only string */
 void
-cstring_make_random (int size, char* buffer)
+#ifdef WIN32
+WINAPI
+#endif
+cs_make_random (int size, char* buffer)
 {
   int i;
   for (i = 0; i < size; i++)
diff --git a/tests/c-test-fns.cl b/tests/c-test-fns.cl
new file mode 100644 (file)
index 0000000..3bb4f61
--- /dev/null
@@ -0,0 +1,66 @@
+;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; Base: 10 -*-
+;;;; *************************************************************************
+;;;; FILE IDENTIFICATION
+;;;;
+;;;; Name:          c-test-fns.cl
+;;;; Purpose:       UFFI Example file for zlib compression
+;;;; Programmer:    Kevin M. Rosenberg
+;;;; Date Started:  Mar 2002
+;;;;
+;;;; $Id: c-test-fns.cl,v 1.1 2002/03/21 04:04:45 kevin Exp $
+;;;;
+;;;; This file, part of UFFI, is Copyright (c) 2002 by Kevin M. Rosenberg
+;;;;
+;;;; UFFI users are granted the rights to distribute and use this software
+;;;; as governed by the terms of the Lisp Lesser GNU Public License
+;;;; (http://opensource.franz.com/preamble.html), also known as the LLGPL.
+;;;; *************************************************************************
+
+(in-package :cl-user)
+
+(unless (uffi:load-foreign-library 
+        (make-pathname :name "c-test-fns" 
+                       :type #+(or linux unix)"so" #+(or win32 mswindows) "dll"
+                       :defaults *load-truename*)
+        :supporting-libraries '("c")
+        :force-load t)
+  (warn "Unable to load c-test-fns library"))
+
+(uffi:def-function ("cs_to_upper" cs-to-upper)
+  ((input (* :unsigned-char)))
+  :returning :void
+  )
+
+(defun string-to-upper (str)
+  (uffi:with-foreign-string (str-foreign str)
+    (cs-to-upper str-foreign)
+    (uffi:convert-from-foreign-string str-foreign)))
+
+(uffi:def-function ("cs_count_upper" cs-count-upper)
+  ((input :cstring))
+  :returning :int
+  )
+
+(defun string-count-upper (str)
+  (uffi:with-cstring (str-cstring str)
+    (cs-count-upper str-cstring)))
+
+#+test-uffi
+(format t "~&(string-to-upper \"this is a test\") => ~A" 
+       (string-to-upper "this is a test"))
+
+#+test-uffi
+(format t "~&(string-to-upper nil) => ~A" 
+       (string-to-upper nil))
+
+#+test-uffi
+(format t "~&(string-count-upper \"This is a Test\") => ~A" 
+       (string-count-upper "This is a Test"))
+
+#+test-uffi
+(format t "~&(string-count-upper nil) => ~A" 
+       (string-count-upper nil))
+
+
+
+