Remove old CVS $Id$ keyword
[uffi.git] / examples / atoifl.lisp
1 ;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; Base: 10 -*-
2 ;;;; *************************************************************************
3 ;;;; FILE IDENTIFICATION
4 ;;;;
5 ;;;; Name:          atoifl.cl
6 ;;;; Purpose:       UFFI Example file to atoi/atof/atol
7 ;;;; Programmer:    Kevin M. Rosenberg
8 ;;;; Date Started:  Mar 2002
9 ;;;;
10 ;;;; This file, part of UFFI, is Copyright (c) 2002-2010 by Kevin M. Rosenberg
11 ;;;;
12 ;;;; *************************************************************************
13
14 (in-package :cl-user)
15
16 (uffi:def-function ("atoi" c-atoi)
17     ((str :cstring))
18   :returning :int)
19
20 (uffi:def-function ("atol" c-atol)
21     ((str :cstring))
22   :returning :long)
23
24 (uffi:def-function ("atof" c-atof)
25     ((str :cstring))
26   :returning :double)
27
28 (defun atoi (str)
29   "Returns a int from a string."
30   (uffi:with-cstring (str-cstring str)
31     (c-atoi str-cstring)))
32
33 (defun atof (str)
34   "Returns a double float from a string."
35   (uffi:with-cstring (str-cstring str)
36     (c-atof str-cstring)))
37
38 #+examples-uffi
39 (progn
40   (flet ((print-results (str)
41            (format t "~&(atoi ~S) => ~S" str (atoi str))))
42     (print-results "55")))
43
44
45 #+test-uffi
46 (progn
47   (util.test:test (atoi "123") 123 :test #'eql
48                   :fail-info "Error with atoi")
49   (util.test:test (atoi "") 0 :test #'eql
50                   :fail-info "Error with atoi")
51   (util.test:test (atof "2.23") 2.23d0 :test #'eql
52                   :fail-info "Error with atof")
53   )
54