Remove old CVS $Id$ keyword
[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  * This file, part of UFFI, is Copyright (c) 2002-2010 by Kevin M. Rosenberg
10  *
11  * These variables are correct for GCC
12  * you'll need to modify these for other compilers
13  ***************************************************************************/
14
15 #if defined(WIN32)||defined(WIN64)
16 #include <windows.h>
17
18 BOOL WINAPI DllEntryPoint(HINSTANCE hinstdll,
19                           DWORD fdwReason,
20                           LPVOID lpvReserved)
21 {
22         return 1;
23 }
24
25 #define DLLEXPORT __declspec(dllexport)
26
27 #else
28 #define DLLEXPORT
29 #endif
30
31 #include <ctype.h>
32 #include <stdlib.h>
33 #include <math.h>
34
35
36 /* Test of constant input string */
37 DLLEXPORT
38 int
39 cs_count_upper (char* psz)
40 {
41   int count = 0;
42
43   if (psz) {
44     while (*psz) {
45       if (isupper (*psz))
46         ++count;
47       ++psz;
48     }
49     return count;
50   } else
51     return -1;
52 }
53
54 /* Test of input and output of a string */
55 DLLEXPORT
56 void
57 cs_to_upper (char* psz)
58 {
59   if (psz) {
60     while (*psz) {
61       *psz = toupper (*psz);
62       ++psz;
63     }
64   }
65 }
66
67 /* Test of an output only string */
68 DLLEXPORT
69 void
70 cs_make_random (int size, char* buffer)
71 {
72   int i;
73   for (i = 0; i < size; i++)
74     buffer[i] = 'A' + (rand() % 26);
75 }
76
77
78 /* Test of input/output vector */
79 DLLEXPORT
80 void
81 half_double_vector (int size, double* vec)
82 {
83   int i;
84   for (i = 0; i < size; i++)
85     vec[i] /= 2.;
86 }
87
88
89