1 /* -*- coding: utf-8 -*- */
2 /**
3 \ingroup anespec errores eop fichero general geodesia geom geopot gshhs marea
4 \ingroup matriz mmcc orden snx texto
5 @{
6 \file errores.c
7 \brief Definición de funciones para el tratamiento de errores.
8
9 En el momento de la compilación ha de seleccionarse el comportamiento de la
10 función \ref GeocError. Para realizar la selección es necesario definir las
11 variables para el preprocesador \em ESCRIBE_MENSAJE_ERROR si se quiere que la
12 función imprima un mensaje de error y/o \em FIN_PROGRAMA_ERROR si se quiere que
13 la función termine la ejecución del programa en curso. Si no se define ninguna
14 variable, la función no ejecuta ninguna acción. En \p gcc, las variables para el
15 preprocesador se pasan como \em -DXXX, donde \em XXX es la variable a
16 introducir.
17 \author José Luis García Pallero, jgpallero@gmail.com
18 \date 09 de enero de 2011
19 \section Licencia Licencia
20 Copyright (c) 2009-2011, José Luis García Pallero. All rights reserved.
21
22 Redistribution and use in source and binary forms, with or without modification,
23 are permitted provided that the following conditions are met:
24
25 - Redistributions of source code must retain the above copyright notice, this
26 list of conditions and the following disclaimer.
27 - Redistributions in binary form must reproduce the above copyright notice, this
28 list of conditions and the following disclaimer in the documentation and/or
29 other materials provided with the distribution.
30 - Neither the name of the copyright holders nor the names of its contributors
31 may be used to endorse or promote products derived from this software without
32 specific prior written permission.
33
34 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
35 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
36 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
37 DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDER BE LIABLE FOR ANY DIRECT,
38 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
39 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
40 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
41 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
42 OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
43 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
44 */
45 /******************************************************************************/
46 /******************************************************************************/
47 #include"libgeoc/errores.h"
48 /******************************************************************************/
49 /******************************************************************************/
GeocTipoError(void)50 int GeocTipoError(void)
51 {
52 //variable de salida
53 int valor=GEOC_TIPO_ERR_NADA;
54 ////////////////////////////////////////////////////////////////////////////
55 ////////////////////////////////////////////////////////////////////////////
56 //distinguimos los posibles casos según las variables del preprocesador
57 #if defined(ESCRIBE_MENSAJE_ERROR) && defined(FIN_PROGRAMA_ERROR)
58 //mensaje de error y terminación del programa
59 valor = GEOC_TIPO_ERR_MENS_Y_EXIT;
60 #elif defined(ESCRIBE_MENSAJE_ERROR)
61 //mensaje de error
62 valor = GEOC_TIPO_ERR_MENS;
63 #elif defined(FIN_PROGRAMA_ERROR)
64 //terminación del programa
65 valor = GEOC_TIPO_ERR_EXIT;
66 #endif
67 ////////////////////////////////////////////////////////////////////////////
68 ////////////////////////////////////////////////////////////////////////////
69 //salimos de la función
70 return valor;
71 }
72 /******************************************************************************/
73 /******************************************************************************/
GeocError(const char mensaje[],const char funcion[])74 void GeocError(const char mensaje[],
75 const char funcion[])
76 {
77 //hacemos una copia para que en la compilación no dé warning si sólo se
78 //termina la ejecución del programa o no se hace nada
79 mensaje = mensaje;
80 funcion = funcion;
81 ////////////////////////////////////////////////////////////////////////////
82 ////////////////////////////////////////////////////////////////////////////
83 //distinguimos los posibles casos según las variables del preprocesador
84 #if defined(ESCRIBE_MENSAJE_ERROR) && defined(FIN_PROGRAMA_ERROR)
85 //imprimimos el nombre de la función y el mensaje
86 fprintf(stderr,"En la función '%s'\n",funcion);
87 fprintf(stderr,"%s\n",mensaje);
88 //indicamos que el programa finalizará
89 fprintf(stderr,"El programa finalizará mediante la llamada a la función "
90 "'exit(EXIT_FAILURE)'\n");
91 //detenemos la ejecución del programa
92 exit(EXIT_FAILURE);
93 #elif defined(ESCRIBE_MENSAJE_ERROR)
94 //imprimimos el nombre de la función y el mensaje
95 fprintf(stderr,"En la función '%s'\n",funcion);
96 fprintf(stderr,"%s\n",mensaje);
97 //salimos de la función
98 return;
99 #elif defined(FIN_PROGRAMA_ERROR)
100 //indicamos que el programa finalizará
101 fprintf(stderr,"El programa finalizará mediante la llamada a la función "
102 "'exit(EXIT_FAILURE)'\n");
103 //detenemos la ejecución del programa
104 exit(EXIT_FAILURE);
105 #else
106 //salimos de la función
107 return;
108 #endif
109 }
110 /******************************************************************************/
111 /******************************************************************************/
112 /** @} */
113 /******************************************************************************/
114 /******************************************************************************/
115 /* kate: encoding utf-8; end-of-line unix; syntax c; indent-mode cstyle; */
116 /* kate: replace-tabs on; space-indent on; tab-indents off; indent-width 4; */
117 /* kate: line-numbers on; folding-markers on; remove-trailing-space on; */
118 /* kate: backspace-indents on; show-tabs on; */
119 /* kate: word-wrap-column 80; word-wrap-marker-color #D2D2D2; word-wrap off; */
120