2010-06-03 21:24:43 +08:00
|
|
|
/*********************************************************************
|
2018-12-07 06:40:43 +08:00
|
|
|
* Copyright 2018, UCAR/Unidata
|
2010-06-03 21:24:43 +08:00
|
|
|
* See netcdf/COPYRIGHT file for copying and redistribution conditions.
|
|
|
|
* $Header: /upc/share/CVS/netcdf-3/ncgen/generr.c,v 1.1 2009/09/25 18:22:22 dmh Exp $
|
|
|
|
*********************************************************************/
|
|
|
|
|
|
|
|
#include "includes.h"
|
|
|
|
#include <ctype.h> /* for isprint() */
|
|
|
|
|
2019-01-16 05:36:07 +08:00
|
|
|
#ifndef vsnprintf
|
|
|
|
extern int vsnprintf(char*, size_t, const char*, va_list ap);
|
|
|
|
#endif
|
2018-12-06 10:20:43 +08:00
|
|
|
|
2012-03-15 07:26:48 +08:00
|
|
|
int error_count;
|
2010-06-03 21:24:43 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* For logging error conditions.
|
|
|
|
* Designed to be called by other vararg procedures
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
vderror(const char *fmt, va_list argv)
|
2015-11-20 04:44:07 +08:00
|
|
|
{
|
|
|
|
(void) vdwarn(fmt,argv);
|
|
|
|
error_count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* For logging error conditions.
|
|
|
|
* Designed to be called by other vararg procedures
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
vdwarn(const char *fmt, va_list argv)
|
2010-06-03 21:24:43 +08:00
|
|
|
{
|
|
|
|
(void) vfprintf(stderr,fmt,argv) ;
|
|
|
|
(void) fputc('\n',stderr) ;
|
|
|
|
(void) fflush(stderr); /* to ensure log files are current */
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
derror(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list argv;
|
2018-11-16 01:00:38 +08:00
|
|
|
va_start(argv,fmt);
|
2010-06-03 21:24:43 +08:00
|
|
|
vderror(fmt,argv);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Report version errors */
|
|
|
|
void
|
|
|
|
verror(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
char newfmt[2048];
|
|
|
|
va_list argv;
|
2018-11-16 01:00:38 +08:00
|
|
|
va_start(argv,fmt);
|
2021-05-15 01:33:03 +08:00
|
|
|
strncpy(newfmt,"netCDF classic: not supported: ",sizeof(newfmt));
|
|
|
|
strlcat(newfmt,fmt,sizeof(newfmt));
|
2010-06-03 21:24:43 +08:00
|
|
|
vderror(newfmt,argv);
|
2018-11-16 01:00:38 +08:00
|
|
|
va_end(argv);
|
2010-06-03 21:24:43 +08:00
|
|
|
}
|
|
|
|
|
2012-02-14 08:25:32 +08:00
|
|
|
void
|
|
|
|
semwarn(const int lno, const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list argv;
|
2018-11-16 01:00:38 +08:00
|
|
|
va_start(argv,fmt);
|
2012-02-14 08:25:32 +08:00
|
|
|
(void)fprintf(stderr,"%s: %s line %d: ", progname, cdlname, lno);
|
2015-11-20 04:44:07 +08:00
|
|
|
vdwarn(fmt,argv);
|
2012-02-14 08:25:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
semerror(const int lno, const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list argv;
|
2018-11-16 01:00:38 +08:00
|
|
|
va_start(argv,fmt);
|
2012-02-14 08:25:32 +08:00
|
|
|
(void)fprintf(stderr,"%s: %s line %d: ", progname, cdlname, lno);
|
|
|
|
vderror(fmt,argv);
|
2017-11-01 04:03:57 +08:00
|
|
|
finalize_netcdf(1); /* immediately fatal */
|
2012-02-14 08:25:32 +08:00
|
|
|
}
|
|
|
|
|
2011-05-13 01:51:32 +08:00
|
|
|
/* Capture potential version errors */
|
|
|
|
static char* markcdf4_msg = NULL;
|
|
|
|
void
|
|
|
|
markcdf4(const char* msg)
|
|
|
|
{
|
2012-02-14 08:25:32 +08:00
|
|
|
enhanced_flag = 1;
|
2011-05-13 01:51:32 +08:00
|
|
|
if(markcdf4_msg == NULL)
|
|
|
|
markcdf4_msg = (char*)msg;
|
|
|
|
}
|
|
|
|
|
2014-08-16 05:50:49 +08:00
|
|
|
char*
|
2011-05-13 01:51:32 +08:00
|
|
|
getmarkcdf4(void)
|
|
|
|
{
|
|
|
|
return markcdf4_msg;
|
|
|
|
}
|
|
|
|
|
2015-11-07 08:03:28 +08:00
|
|
|
/* Capture potential version errors */
|
|
|
|
static char* markcdf5_msg = NULL;
|
|
|
|
void
|
|
|
|
markcdf5(const char* msg)
|
|
|
|
{
|
|
|
|
cdf5_flag = 1;
|
|
|
|
if(markcdf5_msg == NULL)
|
|
|
|
markcdf5_msg = (char*)msg;
|
|
|
|
}
|
|
|
|
|
|
|
|
char*
|
|
|
|
getmarkcdf5(void)
|
|
|
|
{
|
|
|
|
return markcdf5_msg;
|
|
|
|
}
|
|
|
|
|
2010-06-03 21:24:43 +08:00
|
|
|
/**************************************************/
|
|
|
|
/* Provide a version of snprintf that panics if*/
|
|
|
|
/* the buffer is overrun*/
|
|
|
|
|
|
|
|
void
|
|
|
|
nprintf(char* buffer, size_t size, const char *fmt, ...)
|
|
|
|
{
|
|
|
|
long written;
|
|
|
|
va_list args;
|
2018-11-16 01:00:38 +08:00
|
|
|
va_start(args,fmt);
|
2010-06-03 21:24:43 +08:00
|
|
|
written = vsnprintf(buffer,size,fmt,args);
|
|
|
|
if(written < 0 || written >= size) {
|
|
|
|
PANIC("snprintf failure");
|
|
|
|
}
|
|
|
|
}
|