1 /*************************************************************************
2
3 Copyright 2011 Yuri Dario <mc6530@mclink.it>
4
5 Licensed under the Apache License, Version 2.0 (the "License");
6 you may not use this file except in compliance with the License.
7 You may obtain a copy of the License at
8
9 http://www.apache.org/licenses/LICENSE-2.0
10
11 Unless required by applicable law or agreed to in writing, software
12 distributed under the License is distributed on an "AS IS" BASIS,
13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 See the License for the specific language governing permissions and
15 limitations under the License.
16
17 ************************************************************************/
18
19 #define INCL_DOS
20 #ifdef OS2
21 #include <svpm.h>
22 #else
23 #include <os2.h>
24 #endif
25 #include <dlfcn.h>
26 #include <stdarg.h>
27 #include <stdlib.h>
28 #ifdef TESTME
29 #include <stdio.h>
30 #endif
31 #include "sal/types.h"
32
33 typedef APIRET _PMPRINTF(const char*, ...);
34 typedef _PMPRINTF* PMPRINTF;
35
36 static void* hmodPmPrintf = NULL;
37 static PMPRINTF pfnPmPrintf = NULL;
38
debug_printf(const char * format,...)39 int SAL_DLLPUBLIC_EXPORT debug_printf( const char* format, ...)
40 {
41 va_list args;
42 int cnt;
43
44 if (hmodPmPrintf == NULL) {
45 // try dll loading
46 hmodPmPrintf = dlopen( "PMPRINTF", 0);
47 if (hmodPmPrintf == NULL)
48 return -1;
49
50 // search function
51 pfnPmPrintf = dlsym(hmodPmPrintf, "PmPrintfVa");
52 if (!pfnPmPrintf)
53 return -1;
54
55 }
56
57 // function loaded, print data
58 va_start(args, format);
59 cnt = pfnPmPrintf(format, args);
60 va_end(args);
61
62 return cnt;
63 }
64
65
66 #ifdef TESTME
main(void)67 int main( void)
68 {
69 printf( "Test PMPRINTF.DLL output, check PM window.\n");
70 debug_printf( "Test PMPRINTF.DLL output, check PM window.");
71 debug_printf( "Test PMPRINTF.DLL output: integer %d", 12345);
72 debug_printf( "Test PMPRINTF.DLL output: float %f", 123.45);
73 debug_printf( "Test PMPRINTF.DLL output: string '%s'", "Hello World");
74 exit(0);
75 }
76 #endif // TESTME
77