File: generr.c

package info (click to toggle)
netcdf-parallel 1%3A4.7.4-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 105,352 kB
  • sloc: ansic: 229,114; sh: 11,180; yacc: 2,561; makefile: 1,390; lex: 1,173; xml: 173; awk: 2
file content (130 lines) | stat: -rw-r--r-- 2,737 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/*********************************************************************
 *   Copyright 2018, UCAR/Unidata
 *   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() */

#ifndef vsnprintf
extern int vsnprintf(char*, size_t, const char*, va_list ap);
#endif

int error_count;

#if 0
#define vastart(argv,fmt) va_start(argv,fmt)
#define vaend(argv,fmt) va_end(argv)
#endif

/*
 * For logging error conditions.
 * Designed to be called by other vararg procedures
 */
void
vderror(const char *fmt, va_list argv)
{
    (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)
{
    (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;
    va_start(argv,fmt);
    vderror(fmt,argv);
}

/* Report version errors */
void
verror(const char *fmt, ...)
{
    char newfmt[2048];
    va_list argv;
    va_start(argv,fmt);
    strcpy(newfmt,"netCDF classic: not supported: ");
    strncat(newfmt,fmt,2000);
    vderror(newfmt,argv);
    va_end(argv);
}

void
semwarn(const int lno, const char *fmt, ...)
{
    va_list argv;
    va_start(argv,fmt);
    (void)fprintf(stderr,"%s: %s line %d: ", progname, cdlname, lno);
    vdwarn(fmt,argv);
}

void
semerror(const int lno, const char *fmt, ...)
{
    va_list argv;
    va_start(argv,fmt);
    (void)fprintf(stderr,"%s: %s line %d: ", progname, cdlname, lno);
    vderror(fmt,argv);
    finalize_netcdf(1); /* immediately fatal */
}

/* Capture potential version errors */
static char* markcdf4_msg = NULL;
void
markcdf4(const char* msg)
{
    enhanced_flag = 1;
    if(markcdf4_msg == NULL)
        markcdf4_msg = (char*)msg;
}

char*
getmarkcdf4(void)
{
    return markcdf4_msg;
}

/* 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;
}

/**************************************************/
/* 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;
    va_start(args,fmt);
    written = vsnprintf(buffer,size,fmt,args);
    if(written < 0 || written >= size) {
	PANIC("snprintf failure");
    }
}