* 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++)
--- /dev/null
+;;;; -*- 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))
+
+
+
+
* 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++)
--- /dev/null
+;;;; -*- 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))
+
+
+
+