File: PapyError3.c

package info (click to toggle)
papyrus 3.7.1%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 6,216 kB
  • sloc: ansic: 49,488; cpp: 21,301; asm: 284; makefile: 221; sh: 152
file content (257 lines) | stat: -rwxr-xr-x 10,472 bytes parent folder | download | duplicates (4)
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
/********************************************************************************/
/*                                                                              */
/* Papyrus 3 library.                                                           */
/* This library constitutes a DICOM file system which helps reading and writing */
/* DICOM files and DICOMDIR files.                                              */
/*                                                                              */
/* Copyright (C) 2004 - Service of  Medical Informatics -                       */
/* University Hospitals of Geneva (HUG), Geneva, Switzerland                    */
/*                                                                              */
/* This library is a free software; you can redistribute it and/or modify it    */
/* under the terms of the GNU Lesser General Public License as published by the */
/*  Free Software Foundation; either version 2.1 of the License, or             */
/* (at your option) any later version.                                          */
/*                                                                              */
/* This library is distributed in the hope that it will be useful,              */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of               */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                         */
/* See the GNU Lesser General Public License for more details.                  */
/*                                                                              */
/* You should have received a copy of the GNU Lesser General Public License     */
/* along with this library; if not, write to                                    */
/* the Free Software Foundation, Inc.,                                          */
/* 59 Temple Place, Suite 330,                                                  */
/* Boston, MA 02111-1307 USA                                                    */
/*                                                                              */
/* You can contact us for more information at osiris@sim.hcuge.ch               */
/* or by writing to Papyrus,                                                    */
/* Unite d'Imagerie Numerique / Service d'Informatique Medicale / HUG,          */
/* 24, Micheli-du-Crest street, 1211 Geneva 14, Switzerland.                    */
/*                                                                              */
/* The University Hopitals of Geneva, hereby disclaims all copyright interest   */
/* in the library `Papyrus' (a library for reading and writing DICOM files).    */
/*                                                                              */
/* Geneva, april 2004                                                           */
/* Antoine Geissbuhler, head of the Service of Medical Informatics,             */
/* University Hospitals of Geneva, Switzerland                                  */
/*                                                                              */
/********************************************************************************/

/********************************************************************************/
/*                                                                              */
/*	Project  : P A P Y R U S  Toolkit                                           */
/*	File     : PapyError3.c                                                     */
/*	Function : error management                                                 */
/*	Authors  : Jean-Francois Vurlod	                                            */
/*             Christian Girard                                                 */
/*             Marianne Logean                                                  */
/*                                                                              */
/*	History  : 06.1993	version 2.0                                             */
/*             06.1994	version 3.0                                             */
/*             06.1995	version 3.1                                             */
/*             02.1996	version 3.3                                             */
/*             02.1999	version 3.6                                             */
/*             04.2001	version 3.7                                             */
/*             09.2001  version 3.7   on CVS                                    */
/*             10.2001  version 3.71  MAJ Dicom par CHG                         */
/*                                                                              */
/********************************************************************************/

#include <stdio.h>

#ifndef FILENAME83		/* this is for the normal machines ... */

#ifndef PapyTypeDef3H
#include "PapyTypeDef3.h"
#endif

#ifndef PapyError3H
#include "PapyError3.h"
#endif

#else				/* FILENAME83 defined for the DOS machines */

#ifndef PapyTypeDef3H
#include "PAPYDEF3.h"
#endif

#ifndef PapyError3H
#include "PAPERR3.h"
#endif

#endif 				/* FILENAME83 defined */


#define 		kMax_Error_Level	10

static char		sERRMSG[]	= "Error detected in library Papyrus 3";
static int		sExitWhenError	= TRUE;
static int		sCrtErrLevel	= -1;
EPapyError3		gPapyErrNo	= papNoError;
EPapyError3		gFirstError	= papNoError;
int			gPapyErrLigne 	[kMax_Error_Level];
char			*gPapyErrFileP 	[kMax_Error_Level];



/* 	enumeration of the error messages	*/


char	*PapyErrorList [] =
    {
/*  0 */"No error",
/* -1 */"See the error # in the var gPapyErrNo",
/* -2 */"Not implemented",
/* -3 */"Standard C library error",
/* -4 */"Not enough memory",
/* -5 */"UID unknow",
/* -6 */"Read group failed",
/* -7 */"Write group failed",
/* -8 */"Overlay is not in the interval [0x6000,0x601E]",
/* -9 */"UINOverlay is not in the interval [0x6001,0x6FFF]",
/*-10 */"All element of type 1 must be filled",
/*-11 */"Missing a group 0x0008",
/*-12 */"Image file name not defined",
/*-13 */"The length of the string is not even",
/*-14 */"Internal problem in Value",
/*-15 */"Internal problem in Ascii",
/*-16 */"Internal problem in Def",
/*-17 */"You want to write too many images",
/*-18 */"Enum group",
/*-19 */"Array index is greater than the size of the array",
/*-20 */"Create a papyrus file with 0 image",
/*-21 */"The maximum number of open file as been reached",
/*-22 */"The file already exist",
/*-23 */"File creation failed",
/*-24 */"Opening file in read only mode failed",
/*-25 */"Reserved 25",
/*-26 */"Reserved 26",
/*-27 */"Reserved 27",
/*-28 */"Reserved 28",
/*-29 */"Not found",
/*-30 */"Open file",
/*-31 */"Close file",
/*-32 */"Reading data in the file failed",
/*-33 */"Write file",
/*-34 */"The filename is not correct",
/*-35 */"Positioning pointer in the file failed",
/*-36 */"Wrong element number",
/*-37 */"Wrong element size",
/*-38 */"Group error",
/*-39 */"Group number",
/*-40 */"Bad argument",
/*-41 */"Error in list",
/*-42 */"This transfert syntax is not implemented",
/*-43 */"This compression algorithm is not yet implemented ",
/*-44 */"Unknown imaging modality",
/*-45 */"Mandatory module missing",
/*-46 */"Not a Papyrus file",
/*-47 */"Deleting file failed",
/*-48 */"A wrong value has been found in the file",
/*-49 */"The version of this file is newer than the version of the PAPYRUS toolkit"
    };


static char *sPapyErrorDecoP = "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n";


/******************************************************************************/
/*									      */
/*	PapyPrintErrMsg3 : this function prints the error messages to the     */
/*	standard error device						      */
/*	return : /							      */
/*									      */
/******************************************************************************/

void PapyPrintErrMsg3 (char *inFileP, PapyShort inLine)
{
#ifndef DLL
    PapyShort	i, theMax, theNb = 0;

    fprintf (stderr, "%s", sPapyErrorDecoP);
    if (sCrtErrLevel >= 0)
    {
	fprintf (stderr, "%s\n", sERRMSG);
	fprintf (stderr, "File : %s\nLine : %d\n", inFileP, inLine);
	
	if (sCrtErrLevel >= kMax_Error_Level)
	{
	    fprintf (stderr, "... .. .\n");
	    theMax = kMax_Error_Level - 1;
	}
	else
	    theMax = sCrtErrLevel;

	for (i = theMax; i >= 0; i--)
	{
	    static char	StrEmpty [] = "";
	    theNb += 2;
            fprintf(stderr,"%*sFile : %s\n%*sLine : %d\n",
                        theNb, StrEmpty,
                        gPapyErrFileP [i],
                        theNb, StrEmpty,
                        gPapyErrLigne [i]);
	    
	} /* for */

	if ((gPapyErrNo > papLastErrorNb) && (gPapyErrNo <= 0))
	    fprintf (stderr, "\nError : %s\n", PapyErrorList [-gPapyErrNo]);
	else
	    fprintf (stderr, "\nError : %d\n", gPapyErrNo);
    } /* if ...sCrtErrLevel >= 0 */
    else
	fprintf (stderr, "No e%s\n", &sERRMSG [1]);
	
    fprintf (stderr, "%s", sPapyErrorDecoP);
#endif
    
} /* endof PapyPrintErrMsg3 */


/******************************************************************************/
/*									      */
/*	PAPY3PRINTERRMSG : this function interfaces the error messages for    */
/*	Papy3PrintErrMsg						      */
/*	return : /							      */
/*									      */
/******************************************************************************/

void CALLINGCONV
PAPY3PRINTERRMSG ()
{
#if qDebug
    PapyPrintErrMsg3 (__FILE__, __LINE__);
#endif
}


/******************************************************************************/
/*									      */
/*	Papy3CheckError : this function checks in which file and in which line */
/*	the given error has occurred					      */
/*	return : /							      */
/*									      */
/******************************************************************************/

void Papy3CheckError (int inCodeErr, char *inFileP, int inLine)
{
    if (inCodeErr > 0)
    {
	sCrtErrLevel = -1;
	return;
    }
    gPapyErrNo = (EPapyError3) inCodeErr;
    if (gPapyErrNo)
    {
	sCrtErrLevel++;
	if (sCrtErrLevel < kMax_Error_Level)
	{
	    if (!sCrtErrLevel) gFirstError = gPapyErrNo;
	    gPapyErrLigne [sCrtErrLevel] = inLine;
	    gPapyErrFileP [sCrtErrLevel] = inFileP;
	}
    }
    else
	sCrtErrLevel = -1;
	
} /* endof Papy3CheckError */