root/libutil/die.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. setquiet
  2. setverbose
  3. setdebug
  4. sethandler
  5. die
  6. die_with_code
  7. message
  8. warning

   1 /*
   2  * Copyright (c) 1997, 1998, 1999, 2000, 2001, 2002, 2003
   3  *      Tama Communications Corporation
   4  *
   5  * This file is part of GNU GLOBAL.
   6  *
   7  * This program is free software: you can redistribute it and/or modify
   8  * it under the terms of the GNU General Public License as published by
   9  * the Free Software Foundation, either version 3 of the License, or
  10  * (at your option) any later version.
  11  * 
  12  * This program is distributed in the hope that it will be useful,
  13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15  * GNU General Public License for more details.
  16  * 
  17  * You should have received a copy of the GNU General Public License
  18  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  19  */
  20 
  21 #ifdef HAVE_CONFIG_H
  22 #include <config.h>
  23 #endif
  24 #include <stdio.h>
  25 #ifdef STDC_HEADERS
  26 #include <stdlib.h>
  27 #endif
  28 
  29 #include "die.h"
  30 
  31 static int quiet;
  32 static int verbose;
  33 static int debug;
  34 static void (*exit_proc)(void);
  35 
  36 void
  37 setquiet(void)
  38 {
  39         quiet = 1;
  40 }
  41 void
  42 setverbose(void)
  43 {
  44         verbose = 1;
  45 }
  46 void
  47 setdebug(void)
  48 {
  49         debug = 1;
  50 }
  51 void
  52 sethandler(void (*proc)(void))
  53 {
  54         exit_proc = proc;
  55 }
  56 void
  57 die(const char *s, ...)
  58 {
  59         va_list ap;
  60 
  61         if (!quiet) {
  62                 fprintf(stderr, "%s: ", progname);
  63                 va_start(ap, s);
  64                 (void)vfprintf(stderr, s, ap);
  65                 va_end(ap);
  66                 fputs("\n", stderr);
  67         }
  68         if (exit_proc)
  69                 (*exit_proc)();
  70         if (debug)
  71                 abort();
  72         exit(1);
  73 }
  74 
  75 void
  76 die_with_code(int n, const char *s, ...)
  77 {
  78         va_list ap;
  79 
  80         if (!quiet) {
  81                 fprintf(stderr, "%s: ", progname);
  82                 va_start(ap, s);
  83                 (void)vfprintf(stderr, s, ap);
  84                 va_end(ap);
  85                 fputs("\n", stderr);
  86         }
  87         if (exit_proc)
  88                 (*exit_proc)();
  89         if (debug)
  90                 abort();
  91         exit(n);
  92 }
  93 void
  94 message(const char *s, ...)
  95 {
  96         va_list ap;
  97 
  98         if (!quiet && verbose) {
  99                 va_start(ap, s);
 100                 (void)vfprintf(stderr, s, ap);
 101                 va_end(ap);
 102                 fputs("\n", stderr);
 103         }
 104 }
 105 void
 106 warning(const char *s, ...)
 107 {
 108         va_list ap;
 109 
 110         if (!quiet) {
 111                 fputs("Warning: ", stderr);
 112                 va_start(ap, s);
 113                 (void)vfprintf(stderr, s, ap);
 114                 va_end(ap);
 115                 fputs("\n", stderr);
 116         }
 117 }

/* [previous][next][first][last][top][bottom][index][help] */