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

« back to all changes in this revision

Viewing changes to rgb/rgb.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
/* $Xorg: rgb.c,v 1.4 2001/02/09 02:05:35 xorgcvs Exp $ */
 
2
/* $XdotOrg: app/rgb/rgb.c,v 1.4 2005/11/08 06:33:31 jkj Exp $ */
 
3
/*
 
4
 
 
5
Copyright 1985, 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
 
14
in all copies or substantial portions of the Software.
 
15
 
 
16
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 
17
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 
18
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 
19
IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
 
20
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
 
21
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 
22
OTHER DEALINGS IN THE SOFTWARE.
 
23
 
 
24
Except as contained in this notice, the name of The Open Group shall
 
25
not be used in advertising or otherwise to promote the sale, use or
 
26
other dealings in this Software without prior written authorization
 
27
from The Open Group.
 
28
 
 
29
*/
 
30
/* $XFree86: xc/programs/rgb/rgb.c,v 3.8tsi Exp $ */
 
31
 
 
32
 
 
33
/* reads from standard input lines of the form:
 
34
        red green blue name
 
35
   where red/green/blue are decimal values, and inserts them in a database.
 
36
 */
 
37
 
 
38
#ifdef HAVE_CONFIG_H
 
39
# include "config.h"
 
40
#endif
 
41
 
 
42
#ifdef NDBM
 
43
#include <ndbm.h>
 
44
#else
 
45
#if defined(SVR4)
 
46
#include <rpcsvc/dbm.h>
 
47
#else
 
48
#include <dbm.h>
 
49
#endif
 
50
#define dbm_open(name,flags,mode) (!dbminit(name))
 
51
#define dbm_store(db,key,content,flags) (store(key,content))
 
52
#define dbm_close(db) dbmclose()
 
53
#endif
 
54
 
 
55
#undef NULL
 
56
#include <stdio.h>
 
57
#include <stdlib.h>
 
58
#include <X11/Xos.h>
 
59
#include "rgb.h"
 
60
#include "site.h"
 
61
#include <ctype.h>
 
62
 
 
63
#include <errno.h>
 
64
 
 
65
char *ProgramName;
 
66
 
 
67
char *SysError ()
 
68
{
 
69
    register char *s = strerror(errno);
 
70
    return s ? s : "?";
 
71
}
 
72
 
 
73
int
 
74
main(argc, argv)
 
75
    int argc;
 
76
    char **argv;
 
77
{
 
78
    char *dbname;
 
79
    char line[512];
 
80
    int red, green, blue;
 
81
    RGB rgb;
 
82
    datum key, content;
 
83
    char name[512];
 
84
    int items;
 
85
    int lineno;
 
86
    int i, n;
 
87
    int fd;
 
88
#ifdef NDBM
 
89
    DBM *rgb_dbm;
 
90
#else
 
91
    int rgb_dbm;
 
92
#endif
 
93
 
 
94
    ProgramName = argv[0];
 
95
 
 
96
    if (argc == 2)
 
97
        dbname = argv[1];
 
98
    else
 
99
        dbname = RGB_DB;
 
100
 
 
101
    strcpy (name, dbname);
 
102
    strcat (name, ".dir");
 
103
    fd = open (name, O_WRONLY|O_CREAT, 0666);
 
104
    if (fd < 0) {
 
105
        fprintf (stderr, 
 
106
                 "%s:  unable to create dbm file \"%s\" (error %d, %s)\n",
 
107
                 ProgramName, name, errno, strerror(errno));
 
108
        exit (1);
 
109
    }
 
110
    (void) close (fd);
 
111
 
 
112
    strcpy (name, dbname);
 
113
    strcat (name, ".pag");
 
114
    fd = open (name, O_WRONLY|O_CREAT, 0666);
 
115
    if (fd < 0) {
 
116
        fprintf (stderr, 
 
117
                 "%s:  unable to create dbm file \"%s\" (error %d, %s)\n",
 
118
                 ProgramName, name, errno, strerror(errno));
 
119
        exit (1);
 
120
    }
 
121
    (void) close (fd);
 
122
 
 
123
    rgb_dbm = dbm_open (dbname, O_RDWR|O_CREAT, 0666);
 
124
    if (!rgb_dbm) {
 
125
        fprintf (stderr,
 
126
                 "%s:  unable to open dbm database \"%s\" (error %d, %s)\n",
 
127
                 ProgramName, dbname, errno, strerror(errno));
 
128
        exit (1);
 
129
    }
 
130
 
 
131
    key.dptr = name;
 
132
    content.dptr = (char *) &rgb;
 
133
    content.dsize = sizeof (rgb);
 
134
    lineno = 0;
 
135
    while (fgets (line, sizeof (line), stdin)) {
 
136
        lineno++;
 
137
        if (line[0] == '!')
 
138
            continue;
 
139
        items = sscanf (line, "%d %d %d %[^\n]\n", &red, &green, &blue, name);
 
140
        if (items != 4) {
 
141
            fprintf (stderr, "syntax error on line %d\n", lineno);
 
142
            fflush (stderr);
 
143
            continue;
 
144
        }
 
145
        if (red < 0 || red > 0xff ||
 
146
            green < 0 || green > 0xff ||
 
147
            blue < 0 || blue > 0xff) {
 
148
            fprintf (stderr, "value for %s out of range\n", name);
 
149
            fflush (stderr);
 
150
            continue;
 
151
        }
 
152
        n = strlen (name);
 
153
        for (i = 0; i < n; i++) {
 
154
            if (isupper (name[i]))
 
155
                name[i] = tolower (name[i]);
 
156
        }
 
157
        key.dsize = n;
 
158
        rgb.red = (red * 65535) / 255;
 
159
        rgb.green = (green * 65535) / 255;
 
160
        rgb.blue = (blue * 65535) / 255;
 
161
        if (dbm_store (rgb_dbm, key, content, DBM_REPLACE)) {
 
162
            fprintf (stderr, "%s:  store of entry \"%s\" failed\n",
 
163
                     ProgramName, name);
 
164
            fflush (stderr);
 
165
        }
 
166
    }
 
167
 
 
168
    dbm_close(rgb_dbm);
 
169
 
 
170
    exit(0);
 
171
}