PLplot
5.10.0
|
00001 // Get device info from PLplot driver module 00002 // 00003 // Copyright (C) 2003 Rafael Laboissiere 00004 // Copyright (C) 2004 Joao Cardoso 00005 // 00006 // This file is part of PLplot. 00007 // 00008 // PLplot is free software; you can redistribute it and/or modify it under 00009 // the terms of the GNU Library General Public License as published by the 00010 // Free Software Foundation; either version 2 of the License, or (at your 00011 // option) any later version. 00012 // 00013 // PLplot is distributed in the hope that it will be useful, but WITHOUT ANY 00014 // WARRANTY; without even the implied warranty of MERCHANTABILITY 00015 // or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library 00016 // General Public License for more details. 00017 // 00018 // You should have received a copy of the GNU Library General Public License 00019 // along with the GNU C Library; see the file COPYING.LIB. If not, write to 00020 // the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 00021 // MA 02110-1301, USA. 00022 // 00023 00024 #include "plplotP.h" 00025 #ifndef LTDL_WIN32 00026 #include <ltdl.h> 00027 #else 00028 #include "ltdl_win32.h" 00029 #endif 00030 #include <stdio.h> 00031 #include <signal.h> 00032 #include <stdlib.h> 00033 00034 #define SYM_LEN 300 00035 #define DRVSPEC_LEN 400 00036 00037 // function prototype 00038 RETSIGTYPE catch_segv( int sig ); 00039 00040 // SEGV signal handler 00041 RETSIGTYPE 00042 catch_segv( int PL_UNUSED( sig ) ) 00043 { 00044 fprintf( stderr, "libltdl error: %s\n", lt_dlerror() ); 00045 exit( 1 ); 00046 } 00047 00048 int 00049 main( int PL_UNUSED( argc ), char* argv[] ) 00050 { 00051 lt_dlhandle dlhand; 00052 char sym[SYM_LEN]; 00053 char * drvnam = argv[1]; 00054 char drvspec[ DRVSPEC_LEN ]; 00055 char ** info; 00056 00057 // Establish a handler for SIGSEGV signals. 00058 signal( SIGSEGV, catch_segv ); 00059 00060 lt_dlinit(); 00061 #if defined ( LTDL_WIN32 ) || defined ( __CYGWIN__ ) 00062 snprintf( drvspec, DRVSPEC_LEN, "%s", drvnam ); 00063 #else 00064 snprintf( drvspec, DRVSPEC_LEN, "%s/%s", plGetDrvDir(), drvnam ); 00065 #endif // LTDL_WIN32 00066 dlhand = lt_dlopenext( drvspec ); 00067 if ( dlhand == NULL ) 00068 { 00069 fprintf( stderr, "Could not open driver module %s\n" 00070 "libltdl error: %s\n", drvspec, lt_dlerror() ); 00071 exit( 1 ); 00072 } 00073 snprintf( sym, SYM_LEN, "plD_DEVICE_INFO_%s", drvnam ); 00074 info = (char **) lt_dlsym( dlhand, sym ); 00075 if ( info != NULL ) 00076 { 00077 printf( "%s", *info ); 00078 exit( 0 ); 00079 } 00080 else 00081 { 00082 fprintf( stderr, "Could not read symbol %s in driver module %s\n" 00083 "libltdl error: %s\n", sym, drvspec, lt_dlerror() ); 00084 exit( 1 ); 00085 } 00086 }