File: atoifl.lisp

package info (click to toggle)
cl-uffi 1.5.17-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 732 kB
  • ctags: 389
  • sloc: lisp: 3,496; xml: 2,979; makefile: 249; ansic: 169; sh: 82
file content (56 lines) | stat: -rw-r--r-- 1,461 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
;;;; -*- 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.lisp 10608 2005-07-01 00:39:48Z kevin $
;;;;
;;;; This file, part of UFFI, is Copyright (c) 2002-2005 by Kevin M. Rosenberg
;;;;
;;;; *************************************************************************

(in-package :cl-user)

(uffi:def-function ("atoi" c-atoi) 
    ((str :cstring))
  :returning :int)

(uffi:def-function ("atol" c-atol) 
    ((str :cstring))
  :returning :long)

(uffi:def-function ("atof" c-atof) 
    ((str :cstring))
  :returning :double)

(defun atoi (str)
  "Returns a int from a string."
  (uffi:with-cstring (str-cstring str)
    (c-atoi str-cstring)))

(defun atof (str)
  "Returns a double float from a string."
  (uffi:with-cstring (str-cstring str)
    (c-atof str-cstring)))
  
#+examples-uffi
(progn
  (flet ((print-results (str)
	   (format t "~&(atoi ~S) => ~S" str (atoi str))))
    (print-results "55")))


#+test-uffi
(progn
  (util.test:test (atoi "123") 123 :test #'eql
		  :fail-info "Error with atoi")
  (util.test:test (atoi "") 0 :test #'eql
		  :fail-info "Error with atoi")
  (util.test:test (atof "2.23") 2.23d0 :test #'eql
		  :fail-info "Error with atof")
  )