r1654: Added atoifl example
authorKevin M. Rosenberg <kevin@rosenberg.net>
Mon, 25 Mar 2002 01:24:35 +0000 (01:24 +0000)
committerKevin M. Rosenberg <kevin@rosenberg.net>
Mon, 25 Mar 2002 01:24:35 +0000 (01:24 +0000)
examples/atoifl.cl [new file with mode: 0644]
test-examples.cl
tests/atoifl.cl [new file with mode: 0644]

diff --git a/examples/atoifl.cl b/examples/atoifl.cl
new file mode 100644 (file)
index 0000000..d6e48fd
--- /dev/null
@@ -0,0 +1,36 @@
+;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; Base: 10 -*-
+;;;; *************************************************************************
+;;;; FILE IDENTIFICATION
+;;;;
+;;;; Name:          atoifl.cl
+;;;; Purpose:       UFFI Example file to atoi/atof/atol
+;;;; Programmer:    Kevin M. Rosenberg
+;;;; Date Started:  Mar 2002
+;;;;
+;;;; $Id: atoifl.cl,v 1.1 2002/03/25 01:24:35 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)
+
+(uffi:def-function ("atoi" c-atoi) 
+    ((str :cstring))
+  :returning :int)
+
+(defun atoi (str)
+  "Returns a int from a string."
+  (uffi:with-cstring (str-cstring str)
+    (c-atoi str-cstring)))
+  
+#+test-uffi
+(progn
+  (flet ((print-results (str)
+          (format t "~&(atoi ~S) => ~S" str (atoi str))))
+    (print-results "55")))
+
+
index 301e9cdecf5ebcdab685a9c1667eea09daf70ebd..4d1dcbf9cdc8b340c34b906e8d5ded999f1e1795 100644 (file)
@@ -7,7 +7,7 @@
 ;;;; Programmer:    Kevin M. Rosenberg
 ;;;; Date Started:  Feb 2002
 ;;;;
-;;;; $Id: test-examples.cl,v 1.7 2002/03/21 07:56:45 kevin Exp $
+;;;; $Id: test-examples.cl,v 1.8 2002/03/25 01:24:35 kevin Exp $
 ;;;;
 ;;;; This file, part of UFFI, is Copyright (c) 2002 by Kevin M. Rosenberg
 ;;;;
@@ -31,6 +31,7 @@
   (load-test "arrays")
   (load-test "union")
   (load-test "strtol")
+  (load-test "atoifl")
   (load-test "gettime")
   (load-test "getenv")
   (load-test "gethostname")
diff --git a/tests/atoifl.cl b/tests/atoifl.cl
new file mode 100644 (file)
index 0000000..d6e48fd
--- /dev/null
@@ -0,0 +1,36 @@
+;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; Base: 10 -*-
+;;;; *************************************************************************
+;;;; FILE IDENTIFICATION
+;;;;
+;;;; Name:          atoifl.cl
+;;;; Purpose:       UFFI Example file to atoi/atof/atol
+;;;; Programmer:    Kevin M. Rosenberg
+;;;; Date Started:  Mar 2002
+;;;;
+;;;; $Id: atoifl.cl,v 1.1 2002/03/25 01:24:35 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)
+
+(uffi:def-function ("atoi" c-atoi) 
+    ((str :cstring))
+  :returning :int)
+
+(defun atoi (str)
+  "Returns a int from a string."
+  (uffi:with-cstring (str-cstring str)
+    (c-atoi str-cstring)))
+  
+#+test-uffi
+(progn
+  (flet ((print-results (str)
+          (format t "~&(atoi ~S) => ~S" str (atoi str))))
+    (print-results "55")))
+
+