From d5e4894a4d66611f1a585cbe53c692af8fabff5d Mon Sep 17 00:00:00 2001 From: "Kevin M. Rosenberg" Date: Thu, 21 Mar 2002 04:04:45 +0000 Subject: [PATCH] r1596: Expanded c-test-fns --- examples/c-test-fns.c | 44 ++++++++++++++++++++-------- examples/c-test-fns.cl | 66 ++++++++++++++++++++++++++++++++++++++++++ tests/c-test-fns.c | 44 ++++++++++++++++++++-------- tests/c-test-fns.cl | 66 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 196 insertions(+), 24 deletions(-) create mode 100644 examples/c-test-fns.cl create mode 100644 tests/c-test-fns.cl diff --git a/examples/c-test-fns.c b/examples/c-test-fns.c index 3ff1fde..05244b8 100644 --- a/examples/c-test-fns.c +++ b/examples/c-test-fns.c @@ -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 * @@ -18,35 +18,55 @@ * you'll need to modify these for other compilers ***************************************************************************/ +#ifdef WIN32 +#include +#endif + #include #include /* 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 index 0000000..3bb4f61 --- /dev/null +++ b/examples/c-test-fns.cl @@ -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)) + + + + diff --git a/tests/c-test-fns.c b/tests/c-test-fns.c index 3ff1fde..05244b8 100644 --- a/tests/c-test-fns.c +++ b/tests/c-test-fns.c @@ -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 * @@ -18,35 +18,55 @@ * you'll need to modify these for other compilers ***************************************************************************/ +#ifdef WIN32 +#include +#endif + #include #include /* 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 index 0000000..3bb4f61 --- /dev/null +++ b/tests/c-test-fns.cl @@ -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)) + + + + -- 2.34.1