Tizen 2.1 base
[platform/upstream/hplip.git] / scan / sane / sanei_init_debug.c
1 /* sane - Scanner Access Now Easy.
2    Copyright (C) 1996, 1997 David Mosberger-Tang and Andreas Beck
3    This file is part of the SANE package.
4
5    This program is free software; you can redistribute it and/or
6    modify it under the terms of the GNU General Public License as
7    published by the Free Software Foundation; either version 2 of the
8    License, or (at your option) any later version.
9
10    This program is distributed in the hope that it will be useful, but
11    WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13    General Public License for more details.
14
15    You should have received a copy of the GNU General Public License
16    along with this program; if not, write to the Free Software
17    Foundation, Inc., 59 Temple Place - Suite 330, Boston,
18    MA 02111-1307, USA.
19
20    As a special exception, the authors of SANE give permission for
21    additional uses of the libraries contained in this release of SANE.
22
23    The exception is that, if you link a SANE library with other files
24    to produce an executable, this does not by itself cause the
25    resulting executable to be covered by the GNU General Public
26    License.  Your use of that executable is in no way restricted on
27    account of linking the SANE library code into it.
28
29    This exception does not, however, invalidate any other reasons why
30    the executable file might be covered by the GNU General Public
31    License.
32
33    If you submit changes to SANE to the maintainers to be included in
34    a subsequent release, you agree by submitting the changes that
35    those changes may be distributed with this exception intact.
36
37    If you write modifications of your own for SANE, it is your choice
38    whether to permit this exception to apply to your modifications.
39    If you do not wish that, delete this exception notice.  */
40
41 //#include "../include/sane/config.h"
42
43 #include <ctype.h>
44 #include <stdio.h>
45 #include <stdlib.h>
46 #ifdef HAVE_UNISTD_H
47 #include <unistd.h>
48 #endif
49 #include <string.h>
50 #include <stdarg.h>
51 #include <syslog.h>
52 #ifdef HAVE_OS2_H
53 #include <sys/types.h>
54 #endif
55 #include <sys/stat.h>
56
57 #ifdef HAVE_OS2_H
58 # define INCL_DOS
59 # include <os2.h>
60 #endif
61
62 #define BACKEND_NAME sanei_debug
63 #include "sanei_debug.h"
64
65 void 
66 sanei_init_debug (const char * backend, int * var)
67 {
68   char ch, buf[256] = "SANE_DEBUG_";
69   const char * val;
70   unsigned int i;
71
72   *var = 0;
73
74   for (i = 11; (ch = backend[i - 11]) != 0; ++i)
75     {
76       if (i >= sizeof (buf) - 1)
77         break;
78       buf[i] = toupper(ch);
79     }
80   buf[i] = '\0';
81
82   val = getenv (buf);
83
84   if (!val)
85     return;
86
87   *var = atoi (val);
88
89   DBG (0, "Setting debug level of %s to %d.\n", backend, *var);
90 }
91
92 void
93 sanei_debug_msg
94   (int level, int max_level, const char *be, const char *fmt, va_list ap)
95 {
96   if (max_level >= level)
97     {
98         fprintf (stderr, "[%s] ", be);
99         vfprintf (stderr, fmt, ap);
100     }
101 }
102
103 #ifdef NDEBUG
104 void
105 sanei_debug_ndebug (int level, const char *fmt, ...)
106 {
107   /* this function is never called */
108 }
109 #endif