xref: /aoo42x/main/vcl/os2/source/app/debug_printf.c (revision a76b9a7f)
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 
32 typedef APIRET _PMPRINTF(const char*, ...);
33 typedef _PMPRINTF* PMPRINTF;
34 
35 static void* 	hmodPmPrintf = NULL;
36 static PMPRINTF	pfnPmPrintf = NULL;
37 
debug_printf(const char * format,...)38 int _Export debug_printf( const char* format, ...)
39 {
40 	va_list	args;
41 	int		cnt;
42 
43 	if (hmodPmPrintf == NULL) {
44 		// try dll loading
45 		hmodPmPrintf = dlopen( "PMPRINTF", 0);
46 		if (hmodPmPrintf == NULL)
47 			return -1;
48 
49 		// search function
50 		pfnPmPrintf = dlsym(hmodPmPrintf, "PmPrintfVa");
51 		if (!pfnPmPrintf)
52 			return -1;
53 
54 	}
55 
56 	// function loaded, print data
57 	va_start(args, format);
58 	cnt = pfnPmPrintf(format, args);
59 	va_end(args);
60 
61 	return cnt;
62 }
63 
64 
65 #ifdef TESTME
main(void)66 int main( void)
67 {
68 	printf( "Test PMPRINTF.DLL output, check PM window.\n");
69 	debug_printf( "Test PMPRINTF.DLL output, check PM window.");
70 	debug_printf( "Test PMPRINTF.DLL output: integer %d", 12345);
71 	debug_printf( "Test PMPRINTF.DLL output: float %f", 123.45);
72 	debug_printf( "Test PMPRINTF.DLL output: string '%s'", "Hello World");
73 	exit(0);
74 }
75 #endif // TESTME
76