• Main Page
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

test-drv-info.c

Go to the documentation of this file.
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., 59 Temple Place - Suite 330, 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 // SEGV signal handler
00038 RETSIGTYPE
00039 catch_segv( int sig )
00040 {
00041     fprintf( stderr, "libltdl error: %s\n", lt_dlerror() );
00042     exit( 1 );
00043 }
00044 
00045 int
00046 main( int argc, char* argv[] )
00047 {
00048     lt_dlhandle dlhand;
00049     char        sym[SYM_LEN];
00050     char        * drvnam = argv[1];
00051     char        drvspec[ DRVSPEC_LEN ];
00052     char        ** info;
00053 
00054     // Establish a handler for SIGSEGV signals.
00055     signal( SIGSEGV, catch_segv );
00056 
00057     lt_dlinit();
00058 #if defined ( LTDL_WIN32 ) || defined ( __CYGWIN__ )
00059     snprintf( drvspec, DRVSPEC_LEN, "%s", drvnam );
00060 #else
00061     snprintf( drvspec, DRVSPEC_LEN, "%s/%s", plGetDrvDir(), drvnam );
00062 #endif // LTDL_WIN32
00063     dlhand = lt_dlopenext( drvspec );
00064     if ( dlhand == NULL )
00065     {
00066         fprintf( stderr, "Could not open driver module %s\n"
00067             "libltdl error: %s\n", drvspec, lt_dlerror() );
00068         return 1;
00069     }
00070     snprintf( sym, SYM_LEN, "plD_DEVICE_INFO_%s", drvnam );
00071     info = (char **) lt_dlsym( dlhand, sym );
00072     if ( info != NULL )
00073     {
00074         printf( "%s", *info );
00075         return 0;
00076     }
00077     else
00078     {
00079         fprintf( stderr, "Could not read symbol %s in driver module %s\n"
00080             "libltdl error: %s\n", sym, drvspec, lt_dlerror() );
00081         return 1;
00082     }
00083 }

Generated on Wed Oct 12 2011 20:42:23 for PLplot by  doxygen 1.7.1