PLplot: test-drv-info.c Source File

PLplot 5.10.0

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
test-drv-info.c
Go to the documentation of this file.
1 // Get device info from PLplot driver module
2 //
3 // Copyright (C) 2003 Rafael Laboissiere
4 // Copyright (C) 2004 Joao Cardoso
5 //
6 // This file is part of PLplot.
7 //
8 // PLplot is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Library General Public License as published by the
10 // Free Software Foundation; either version 2 of the License, or (at your
11 // option) any later version.
12 //
13 // PLplot is distributed in the hope that it will be useful, but WITHOUT ANY
14 // WARRANTY; without even the implied warranty of MERCHANTABILITY
15 // or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library
16 // General Public License for more details.
17 //
18 // You should have received a copy of the GNU Library General Public License
19 // along with the GNU C Library; see the file COPYING.LIB. If not, write to
20 // the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21 // MA 02110-1301, USA.
22 //
23
24 #include "plplotP.h"
25 #ifndef LTDL_WIN32
26 #include <ltdl.h>
27 #else
28 #include "ltdl_win32.h"
29 #endif
30 #include <stdio.h>
31 #include <signal.h>
32 #include <stdlib.h>
33
34 #define SYM_LEN 300
35 #define DRVSPEC_LEN 400
36
37 // function prototype
38 RETSIGTYPE catch_segv( int sig );
39
40 // SEGV signal handler
41 RETSIGTYPE
42 catch_segv( int PL_UNUSED( sig ) )
43 {
44 fprintf( stderr, "libltdl error: %s\n", lt_dlerror() );
45 exit( 1 );
46 }
47
48 int
49 main( int PL_UNUSED( argc ), char* argv[] )
50 {
51 lt_dlhandle dlhand;
52 char sym[SYM_LEN];
53 char * drvnam = argv[1];
54 char drvspec[ DRVSPEC_LEN ];
55 char ** info;
56
57 // Establish a handler for SIGSEGV signals.
58 signal( SIGSEGV, catch_segv );
59
60 lt_dlinit();
61 #if defined ( LTDL_WIN32 ) || defined ( __CYGWIN__ )
62 snprintf( drvspec, DRVSPEC_LEN, "%s", drvnam );
63 #else
64 snprintf( drvspec, DRVSPEC_LEN, "%s/%s", plGetDrvDir(), drvnam );
65 #endif // LTDL_WIN32
66 dlhand = lt_dlopenext( drvspec );
67 if ( dlhand == NULL )
68 {
69 fprintf( stderr, "Could not open driver module %s\n"
70 "libltdl error: %s\n", drvspec, lt_dlerror() );
71 exit( 1 );
72 }
73 snprintf( sym, SYM_LEN, "plD_DEVICE_INFO_%s", drvnam );
74 info = (char **) lt_dlsym( dlhand, sym );
75 if ( info != NULL )
76 {
77 printf( "%s", *info );
78 exit( 0 );
79 }
80 else
81 {
82 fprintf( stderr, "Could not read symbol %s in driver module %s\n"
83 "libltdl error: %s\n", sym, drvspec, lt_dlerror() );
84 exit( 1 );
85 }
86 }