fdc17b8ea38717203f3ea23d25b4732de38149de
[uffi.git] / examples / c-test-fns.c
1 /***************************************************************************
2  * FILE IDENTIFICATION
3  *  
4  *  Name:         c-test-fns.c
5  *  Purpose:      Test functions in C for UFFI library
6  *  Programer:    Kevin M. Rosenberg
7  *  Date Started: Mar 2002
8  *
9  *  CVS Id:   $Id$
10  *
11  * This file, part of UFFI, is Copyright (c) 2002 by Kevin M. Rosenberg
12  *
13  * UFFI users are granted the rights to distribute and use this software
14  * as governed by the terms of the Lisp Lesser GNU Public License
15  * (http://opensource.franz.com/preamble.html), also known as the LLGPL.
16
17  * These variables are correct for GCC
18  * you'll need to modify these for other compilers
19  ***************************************************************************/
20
21 #ifdef WIN32
22 #include <windows.h>
23
24 BOOL WINAPI DllEntryPoint(HINSTANCE hinstdll,
25                           DWORD fdwReason,
26                           LPVOID lpvReserved)
27 {
28         return 1;
29 }
30        
31 #define DLLEXPORT __declspec(dllexport)
32
33 #else
34 #define DLLEXPORT 
35 #endif
36
37 #include <ctype.h>
38 #include <stdlib.h>
39 #include <math.h>
40
41
42 /* Test of constant input string */
43 DLLEXPORT
44 int
45 cs_count_upper (char* psz)
46 {
47   int count = 0;
48
49   if (psz) {
50     while (*psz) {
51       if (isupper (*psz))
52         ++count;
53       ++psz;
54     }
55     return count;
56   } else 
57     return -1;
58 }
59
60 /* Test of input and output of a string */
61 DLLEXPORT
62 void
63 cs_to_upper (char* psz)
64 {
65   if (psz) {
66     while (*psz) {
67       *psz = toupper (*psz);
68       ++psz;
69     }
70   }
71 }
72
73 /* Test of an output only string */
74 DLLEXPORT
75 void
76 cs_make_random (int size, char* buffer)
77 {
78   int i;
79   for (i = 0; i < size; i++)
80     buffer[i] = 'A' + (rand() % 26);
81 }
82
83     
84 /* Test of input/output vector */
85 DLLEXPORT
86 void
87 half_double_vector (int size, double* vec)
88 {
89   int i;
90   for (i = 0; i < size; i++)
91     vec[i] /= 2.;
92 }
93
94     
95