1 /* Copyright 2004,2007 ENSEIRB, INRIA & CNRS
2 **
3 ** This file is part of the Scotch software package for static mapping,
4 ** graph partitioning and sparse matrix ordering.
5 **
6 ** This software is governed by the CeCILL-C license under French law
7 ** and abiding by the rules of distribution of free software. You can
8 ** use, modify and/or redistribute the software under the terms of the
9 ** CeCILL-C license as circulated by CEA, CNRS and INRIA at the following
10 ** URL: "http://www.cecill.info".
11 **
12 ** As a counterpart to the access to the source code and rights to copy,
13 ** modify and redistribute granted by the license, users are provided
14 ** only with a limited warranty and the software's author, the holder of
15 ** the economic rights, and the successive licensors have only limited
16 ** liability.
17 **
18 ** In this respect, the user's attention is drawn to the risks associated
19 ** with loading, using, modifying and/or developing or reproducing the
20 ** software by the user in light of its specific status of free software,
21 ** that may mean that it is complicated to manipulate, and that also
22 ** therefore means that it is reserved for developers and experienced
23 ** professionals having in-depth computer knowledge. Users are therefore
24 ** encouraged to load and test the software's suitability as regards
25 ** their requirements in conditions enabling the security of their
26 ** systems and/or data to be ensured and, more generally, to use and
27 ** operate it in the same conditions as regards security.
28 **
29 ** The fact that you are presently reading this means that you have had
30 ** knowledge of the CeCILL-C license and that you accept its terms.
31 */
32 /************************************************************/
33 /**                                                        **/
34 /**   NAME       : common_error.c                          **/
35 /**                                                        **/
36 /**   AUTHORS    : David GOUDIN                            **/
37 /**                Pascal HENON                            **/
38 /**                Francois PELLEGRINI                     **/
39 /**                Pierre RAMET                            **/
40 /**                                                        **/
41 /**   FUNCTION   : Part of a parallel direct block solver. **/
42 /**                This module handles errors.             **/
43 /**                                                        **/
44 /**   DATES      : # Version 0.0  : from : 08 may 1998     **/
45 /**                                 to     02 oct 1998     **/
46 /**                                                        **/
47 /************************************************************/
48 
49 /*
50 **  The defines and includes.
51 */
52 
53 #define COMMON_ERROR
54 
55 #include "common.h"
56 
57 /********************************/
58 /*                              */
59 /* The error handling routines. */
60 /*                              */
61 /********************************/
62 
63 static char                 errorProgName[32] = "";
64 
65 /* This routine sets the program name for
66 ** error reporting.
67 ** It returns:
68 ** - VOID  : in all cases.
69 */
70 
71 void
errorProg(const char * const progstr)72 errorProg (
73 const char * const          progstr)              /*+ Program name +*/
74 {
75   strncpy (errorProgName, progstr, 29);
76   errorProgName[29] = '\0';
77   strcat  (errorProgName, ": ");
78 
79 }
80 
81 /* This routine prints an error message with
82 ** a variable number of arguments, as printf ()
83 ** does, and exits.
84 ** It returns:
85 ** - EXIT  : in all cases.
86 */
87 
88 void
errorPrint(const char * const errstr,...)89 errorPrint (
90 const char * const          errstr,               /*+ printf-like variable argument list */
91 ...)
92 {
93   va_list             errlist;                    /* Argument list of the call */
94 
95   fprintf  (stderr, "%sERROR: ", errorProgName);
96   va_start (errlist, errstr);
97   vfprintf (stderr, errstr, errlist);             /* Print arguments */
98   va_end   (errlist);
99   fprintf  (stderr, "\n");
100   fflush   (stderr);                              /* In case it has been set to buffered mode */
101 }
102 
103 /* This routine prints a warning message with
104 ** a variable number of arguments, as printf ()
105 ** does.
106 ** It returns:
107 ** - VOID  : in all cases.
108 */
109 
110 void
errorPrintW(const char * const errstr,...)111 errorPrintW (
112 const char * const          errstr,               /*+ printf-like variable argument list */
113 ...)
114 {
115   va_list             errlist;                    /* Argument list of the call */
116 
117   fprintf  (stderr, "%sWARNING: ", errorProgName);
118   va_start (errlist, errstr);
119   vfprintf (stderr, errstr, errlist);             /* Print arguments */
120   va_end   (errlist);
121   fprintf  (stderr, "\n");
122   fflush   (stderr);                              /* In case it has been set to buffered mode */
123 }
124