PLplot: test-drv-info.c Source File

PLplot 5.15.0

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 #include <string.h>
34
35 #define SYM_LEN 300
36 #define DRVSPEC_LEN 400
37
38 // function prototype
39 RETSIGTYPE catch_segv( int sig );
40
41 // SEGV signal handler
42 RETSIGTYPE
43 catch_segv( int PL_UNUSED( sig ) )
44 {
45 fprintf( stderr, "libltdl error: %s\n", lt_dlerror() );
46 exit( 1 );
47 }
48
49 int
50 main( int argc, char* argv[] )
51 {
52 lt_dlhandle dlhand;
53 char sym[SYM_LEN];
54 char * library_target_prefix;
55 char * drvnam;
56 char drvspec[ DRVSPEC_LEN ];
57 char ** info;
58 char *string, *token, *saveptr;
59
60 if ( argc == 3 )
61 {
62 library_target_prefix = argv[1];
63 drvnam = argv[2];
64 }
65 else
66 {
67 fprintf( stderr, "%s needs to be invoked with two additional string arguments (library target prefix and driver name) beyond the application name\n", argv[0] );
68 exit( 1 );
69 }
70
71 // Establish a handler for SIGSEGV signals.
72 signal( SIGSEGV, catch_segv );
73
74 lt_dlinit();
75 #if defined ( LTDL_WIN32 ) || defined ( __CYGWIN__ )
76 snprintf( drvspec, DRVSPEC_LEN, "%s%s", library_target_prefix, drvnam );
77 #else
78 snprintf( drvspec, DRVSPEC_LEN, "%s/%s%s", plGetDrvDir(), library_target_prefix, drvnam );
79 #endif // LTDL_WIN32
80 dlhand = lt_dlopenext( drvspec );
81 if ( dlhand == NULL )
82 {
83 fprintf( stderr, "Could not open driver module %s\n"
84 "libltdl error: %s\n", drvspec, lt_dlerror() );
85 exit( 1 );
86 }
87 snprintf( sym, SYM_LEN, "plD_DEVICE_INFO_%s", drvnam );
88 info = (char **) lt_dlsym( dlhand, sym );
89 if ( info != NULL )
90 {
91 printf( "%s", *info );
92 exit( 0 );
93 }
94 else
95 {
96 fprintf( stderr, "Could not read symbol %s in driver module %s\n"
97 "libltdl error: %s\n", sym, drvspec, lt_dlerror() );
98 exit( 1 );
99 }
100 }
plplotP.h
argv
static char ** argv
Definition: qt.cpp:49
catch_segv
RETSIGTYPE catch_segv(int sig)
RETSIGTYPE
#define RETSIGTYPE
Definition: plplot_config.h:270
argc
static int argc
Definition: qt.cpp:48
ltdl_win32.h
SYM_LEN
#define SYM_LEN
Definition: test-drv-info.c:35
snprintf
#define snprintf
Definition: plplotP.h:235
main
int main(int argc, char *argv[])
Definition: test-drv-info.c:50
PL_UNUSED
#define PL_UNUSED(x)
Definition: plplot.h:138
lt_dlopenext
lt_dlhandle lt_dlopenext(char *dllname)
Definition: ltdl_win32.c:74
lt_dlerror
PLCHAR_VECTOR lt_dlerror()
Definition: ltdl_win32.c:97
lt_dlinit
void lt_dlinit(void)
Definition: ltdl_win32.c:43
DRVSPEC_LEN
#define DRVSPEC_LEN
Definition: test-drv-info.c:36
lt_dlsym
void * lt_dlsym(lt_dlhandle dlhandle, PLCHAR_VECTOR symbol)
Definition: ltdl_win32.c:112
__dlhandle
Definition: ltdl_win32.h:29