~ubuntu-branches/ubuntu/karmic/x11-xserver-utils/karmic

« back to all changes in this revision

Viewing changes to rgb/showrgb.c

  • Committer: Bazaar Package Importer
  • Author(s): Brice Goglin, Julien Cristau, Brice Goglin
  • Date: 2007-08-17 09:58:34 UTC
  • Revision ID: james.westby@ubuntu.com-20070817095834-ywge2nyzj1s3rqnd
Tags: 7.3+1
[ Julien Cristau ]
* iceauth 1.0.2.
  + removes blank line in the manpage (closes: #25285).
* xmodmap 1.0.3.
  + manpage updated to state that -pm is the default (closes: #236198)
* xgamma 1.0.2.
  + the manpage now explains how to print the gamma value more clearly
    (closes: #296021).
* xsetroot 1.0.2.
* xrdb 1.0.4.
  + fixes manpage typo (closes: #276286).
* Add upstream URL to debian/copyright, and update it from xgamma's COPYING
  file.

[ Brice Goglin ]
* Add menu entries for xrefresh and xvidtune.
* sessreg 1.0.3.
* xset 1.0.3.
* Add myself to Uploaders, and remove Branden with his permission.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * $Xorg: showrgb.c,v 1.4 2001/02/09 02:05:35 xorgcvs Exp $
 
3
 * $XdotOrg: app/rgb/showrgb.c,v 1.5 2005/11/08 06:33:31 jkj Exp $
 
4
 *
 
5
Copyright 1989, 1998  The Open Group
 
6
 
 
7
Permission to use, copy, modify, distribute, and sell this software and its
 
8
documentation for any purpose is hereby granted without fee, provided that
 
9
the above copyright notice appear in all copies and that both that
 
10
copyright notice and this permission notice appear in supporting
 
11
documentation.
 
12
 
 
13
The above copyright notice and this permission notice shall be included in
 
14
all copies or substantial portions of the Software.
 
15
 
 
16
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 
17
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
18
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
 
19
OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
 
20
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 
21
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
22
 
 
23
Except as contained in this notice, the name of The Open Group shall not be
 
24
used in advertising or otherwise to promote the sale, use or other dealings
 
25
in this Software without prior written authorization from The Open Group.
 
26
 *
 
27
 * Author:  Jim Fulton, MIT X Consortium
 
28
 */
 
29
 
 
30
/* $XFree86: xc/programs/rgb/showrgb.c,v 3.8 2001/12/14 20:01:04 dawes Exp $ */
 
31
 
 
32
#ifdef HAVE_CONFIG_H
 
33
# include "config.h"
 
34
#endif
 
35
 
 
36
#ifndef USE_RGB_TXT
 
37
#ifdef NDBM
 
38
#include <ndbm.h>
 
39
#else
 
40
#if defined(SVR4)
 
41
#include <rpcsvc/dbm.h>
 
42
#else
 
43
#include <dbm.h>
 
44
#endif
 
45
#define dbm_open(name,flags,mode) (!dbminit(name))
 
46
#define dbm_firstkey(db) (firstkey())
 
47
#define dbm_fetch(db,key) (fetch(key))
 
48
#define dbm_close(db) dbmclose()
 
49
#endif
 
50
#endif /* USE_RGB_TXT */
 
51
 
 
52
#undef NULL
 
53
#include <stdio.h>
 
54
#include <X11/Xos.h>
 
55
#include <stdlib.h>
 
56
#ifndef USE_RGB_TXT
 
57
#include "rgb.h"                        /* off in server/include/ */
 
58
#include "site.h"
 
59
#endif
 
60
#include <X11/Xfuncs.h>
 
61
 
 
62
char *ProgramName;
 
63
static void dumprgb(char *filename);
 
64
 
 
65
int
 
66
main (int argc, char *argv[])
 
67
{
 
68
    char *dbname = RGB_DB;
 
69
 
 
70
    ProgramName = argv[0];
 
71
    if (argc == 2)
 
72
        dbname = argv[1];
 
73
 
 
74
    dumprgb (dbname);
 
75
    exit (0);
 
76
}
 
77
 
 
78
#ifndef USE_RGB_TXT
 
79
static void
 
80
dumprgb (filename)
 
81
    char *filename;
 
82
{
 
83
#ifdef NDBM
 
84
    DBM *rgb_dbm;
 
85
#else
 
86
    int rgb_dbm;
 
87
#endif
 
88
    datum key;
 
89
 
 
90
    rgb_dbm = dbm_open (filename, O_RDONLY, 0);
 
91
    if (!rgb_dbm) {
 
92
        fprintf (stderr, "%s:  unable to open rgb database \"%s\"\n",
 
93
                 ProgramName, filename);
 
94
        exit (1);
 
95
    }
 
96
 
 
97
#ifndef NDBM
 
98
#define dbm_nextkey(db) (nextkey(key))  /* need variable called key */
 
99
#endif
 
100
 
 
101
    for (key = dbm_firstkey(rgb_dbm); key.dptr != NULL;
 
102
         key = dbm_nextkey(rgb_dbm)) {
 
103
        datum value;
 
104
 
 
105
        value = dbm_fetch(rgb_dbm, key);
 
106
        if (value.dptr) {
 
107
            RGB rgb;
 
108
            unsigned short r, g, b;
 
109
            memcpy( (char *)&rgb, value.dptr, sizeof rgb);
 
110
#define N(x) (((x) >> 8) & 0xff)
 
111
            r = N(rgb.red);
 
112
            g = N(rgb.green);
 
113
            b = N(rgb.blue);
 
114
#undef N
 
115
            printf ("%3u %3u %3u\t\t", r, g, b);
 
116
            fwrite (key.dptr, 1, key.dsize, stdout);
 
117
            putchar ('\n');
 
118
        } else {
 
119
            fprintf (stderr, "%s:  no value found for key \"", ProgramName);
 
120
            fwrite (key.dptr, 1, key.dsize, stderr);
 
121
            fprintf (stderr, "\"\n");
 
122
        }
 
123
    }
 
124
 
 
125
    dbm_close (rgb_dbm);
 
126
}
 
127
 
 
128
#else /* USE_RGB_TXT */
 
129
static void
 
130
dumprgb (filename)
 
131
    char *filename;
 
132
{
 
133
    FILE *rgb;
 
134
    char *path;
 
135
    char line[BUFSIZ];
 
136
    char name[BUFSIZ];
 
137
    int lineno = 0;
 
138
    int red, green, blue;
 
139
 
 
140
#ifdef __UNIXOS2__
 
141
    char *root = (char*)getenv("X11ROOT");
 
142
    sprintf(line,"%s%s.txt",root,filename);
 
143
    path = (char *)malloc(strlen(line) + 1);
 
144
    strcpy(path,line);
 
145
#else
 
146
    path = (char *)malloc(strlen(filename) + 5);
 
147
    strcpy(path, filename);
 
148
    strcat(path, ".txt");
 
149
#endif
 
150
 
 
151
    if (!(rgb = fopen(path, "r"))) {
 
152
        fprintf (stderr, "%s:  unable to open rgb database \"%s\"\n",
 
153
                 ProgramName, filename);
 
154
        free(path);
 
155
        exit (1);
 
156
    }
 
157
 
 
158
    while(fgets(line, sizeof(line), rgb)) {
 
159
        lineno++;
 
160
#ifndef __UNIXOS2__
 
161
        if (sscanf(line, "%d %d %d %[^\n]\n", &red, &green, &blue, name) == 4) {
 
162
#else
 
163
        if (sscanf(line, "%d %d %d %[^\n\r]\n", &red, &green, &blue, name) == 4) {
 
164
#endif
 
165
            if (red >= 0 && red <= 0xff &&
 
166
                green >= 0 && green <= 0xff &&
 
167
                blue >= 0 && blue <= 0xff) {
 
168
                printf ("%3u %3u %3u\t\t%s\n", red, green, blue, name);
 
169
            } else {
 
170
                fprintf(stderr, "%s:  value for \"%s\" out of range: %s:%d\n",
 
171
                        ProgramName, name, path, lineno);
 
172
            }
 
173
        } else if (*line && *line != '!') {
 
174
            fprintf(stderr, "%s:  syntax error: %s:%d\n", ProgramName,
 
175
                    path, lineno);
 
176
        }
 
177
    }
 
178
 
 
179
    free(path);
 
180
    fclose(rgb);
 
181
}
 
182
 
 
183
#endif /* USE_RGB_TXT */