summaryrefslogtreecommitdiffstats
path: root/options.i
diff options
context:
space:
mode:
authorHenning Makholm <henning@makholm.net>2006-04-16 18:00:00 (EDT)
committer Julien Jorge <julien.jorge@stuff-o-matic.com>2013-01-10 16:07:28 (EST)
commit83d97406fa275882067cd256b36eb8c3273d42be (patch)
treef3b74be6a88d069739b33e20ca9f4d4f456d575f /options.i
parent27f6ea800cfd66b1024b0379aa1ac9631e799ee7 (diff)
downloadxcftools-83d97406fa275882067cd256b36eb8c3273d42be.zip
xcftools-83d97406fa275882067cd256b36eb8c3273d42be.tar.gz
xcftools-83d97406fa275882067cd256b36eb8c3273d42be.tar.bz2
Import of release 1.0.3
Diffstat (limited to 'options.i')
-rw-r--r--options.i55
1 files changed, 33 insertions, 22 deletions
diff --git a/options.i b/options.i
index bc59e5a..79ac826 100644
--- a/options.i
+++ b/options.i
@@ -112,8 +112,9 @@ OPTION('b',--background,(color) select background color,
or
.B #rgb
hexadecimal values,
- or as an X11 color name that will be looked up in
- .BR /usr/lib/X11/rgb.txt .
+ or as an X11 color name
+ (which will only work if a color name database can be found
+ in one of a number of standard locations).
));
{
unsigned r,g,b ;
@@ -134,26 +135,36 @@ OPTION('b',--background,(color) select background color,
else if( strcasecmp(optarg,"white") == 0 )
r = g = b = 255 ;
else {
- const char filename[] = "/usr/lib/X11/rgb.txt" ;
- FILE *colortable = fopen(filename,"rt");
- if( colortable ) {
- int clen ;
- char colorbuf[80] ;
- do {
- if( !fgets(colorbuf,sizeof colorbuf,colortable) ) {
- r = (unsigned)-1 ;
- break ;
- }
- clen = strlen(colorbuf);
- while( clen && isspace(colorbuf[clen-1]) )
- clen-- ;
- colorbuf[clen] = '\0' ;
- clen = 0 ;
- sscanf(colorbuf," %u %u %u %n",&r,&g,&b,&clen);
- } while( clen == 0 || strcasecmp(colorbuf+clen,optarg) != 0 );
- } else {
- fprintf(stderr,_("Could not open color database file %s\n"),filename);
- r = (unsigned)-1 ;
+ const char *filenames[] = { "/etc/X11/rgb.txt",
+ "/usr/lib/X11/rgb.txt",
+ "/usr/share/X11/rgb.txt",
+ NULL };
+ const char **fnp ;
+ r = (unsigned)-1 ;
+ int any = 0 ;
+ for( fnp = filenames; r == (unsigned)-1 && fnp && *fnp; fnp++ ) {
+ FILE *colortable = fopen(*fnp,"rt");
+ if( colortable ) {
+ any = 1 ;
+ int clen ;
+ char colorbuf[80] ;
+ do {
+ if( !fgets(colorbuf,sizeof colorbuf,colortable) ) {
+ r = (unsigned)-1 ;
+ break ;
+ }
+ clen = strlen(colorbuf);
+ while( clen && isspace(colorbuf[clen-1]) )
+ clen-- ;
+ colorbuf[clen] = '\0' ;
+ clen = 0 ;
+ sscanf(colorbuf," %u %u %u %n",&r,&g,&b,&clen);
+ } while( clen == 0 || strcasecmp(colorbuf+clen,optarg) != 0 );
+ fclose(colortable) ;
+ }
+ }
+ if( !any ) {
+ fprintf(stderr,_("Could not find X11 color database\n"));
}
}
if( r == (unsigned)-1 )