Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

vmdconio.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *cr
00003  *cr            (C) Copyright 2009 The Board of Trustees of the
00004  *cr                        University of Illinois
00005  *cr                         All Rights Reserved
00006  *cr
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  * RCS INFORMATION:
00011  *
00012  *      $RCSfile: vmdconio.h,v $
00013  *      $Author: johns $       $Locker:  $             $State: Exp $
00014  *      $Revision: 1.4 $       $Date: 2015/10/11 22:36:27 $
00015  *
00016  ***************************************************************************/
00017 
00024 #ifndef VMDCON_PLUGIN_H
00025 #define VMDCON_PLUGIN_H
00026 
00027 /* this has to correspond to vmdconsole.h */
00028 #define VMDCON_ALL       0      
00029 #define VMDCON_INFO      1      
00030 #define VMDCON_WARN      2      
00031 #define VMDCON_ERROR     3      
00032 #define VMDCON_ALWAYS    4      
00033 #define VMDCON_LOG       5      
00035 #include <stdio.h>
00036 #include <stdarg.h>
00037 #include <stdlib.h>
00038 
00039 #ifdef __cplusplus
00040 extern "C" {
00041 #endif
00042 
00043 /* set default */
00044 #if !defined(THISPLUGIN)
00045 #define THISPLUGIN plugin
00046 #endif
00047 
00048 /* forward declaration */
00049 static molfile_plugin_t THISPLUGIN;
00050 
00051 /* 
00052  * Emulate printf. unfortunately, we cannot rely on 
00053  * snprintf being available, so we have to write to
00054  * a very large buffer and then free it. :-( 
00055  */
00056 static int vmdcon_printf(int lvl, const char *fmt, ...) {
00057   va_list ap;
00058   char *buf;
00059   int len;
00060 
00061   /* expand formatted output into a single string */
00062   buf = (char *)malloc(MOLFILE_BIGBUFSIZ);
00063   va_start(ap, fmt);
00064   len = vsprintf(buf, fmt, ap);
00065 
00066   /* 
00067    * Check result. we may get a segfault, but if not
00068    * let the user know that he/she is in trouble. 
00069    */
00070   if (len >= MOLFILE_BIGBUFSIZ) {
00071     fprintf(stderr,"WARNING! buffer overflow in vmdcon_printf. %d vs %d.\n",
00072             len, MOLFILE_BIGBUFSIZ);
00073     free(buf);
00074 #if 0
00075     errno=ERANGE; /* this is inherently thread-unsafe */
00076 #endif
00077     return -1;
00078   }
00079 
00080   /* 
00081    * write to registered console output function.
00082    * fall back to stdout, if vmdcon not available. 
00083    */
00084   if (THISPLUGIN.cons_fputs) {
00085     (*THISPLUGIN.cons_fputs)(lvl, buf);
00086   } else {
00087     fputs(buf, stdout);
00088   }
00089   free(buf);
00090   return 0;    
00091 }
00092 
00093 #ifdef __cplusplus
00094 }
00095 #endif
00096 
00097 #endif /* VMDCON_PLUGIN_H */
00098 

Generated on Thu May 28 03:00:17 2020 for VMD Plugins (current) by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002