Files
wmaker/util/wdread.c
T

111 lines
2.6 KiB
C
Raw Normal View History

2001-02-09 16:05:49 +00:00
/* wdread.c - read value from defaults database
*
* WindowMaker window manager
2004-10-12 21:28:27 +00:00
*
2003-01-16 23:30:45 +00:00
* Copyright (c) 1997-2003 Alfredo K. Kojima
2001-02-09 16:05:49 +00:00
* (cowardly remade from wdwrite.c; by judas@hell on Jan 26 2001)
2004-10-12 21:28:27 +00:00
*
2001-02-09 16:05:49 +00:00
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
2001-02-09 16:05:49 +00:00
*/
2010-04-01 03:30:05 +02:00
#ifdef __GLIBC__
#define _GNU_SOURCE /* getopt_long */
#endif
2001-02-09 16:05:49 +00:00
/*
* WindowMaker defaults DB reader
*/
#include "config.h"
2001-02-09 16:05:49 +00:00
2010-04-01 03:30:05 +02:00
#include <getopt.h>
#include <limits.h>
#include <stdio.h>
2001-02-09 16:05:49 +00:00
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#ifdef HAVE_STDNORETURN
#include <stdnoreturn.h>
#endif
#include <WINGs/WUtil.h>
2010-04-01 03:30:05 +02:00
#include "../src/wconfig.h"
2001-02-09 16:05:49 +00:00
static const char *prog_name;
2001-02-09 16:05:49 +00:00
static noreturn void print_help(int print_usage, int exitval)
2001-02-09 16:05:49 +00:00
{
printf("Usage: %s [OPTIONS] <domain> <key>\n", prog_name);
2010-04-01 03:30:05 +02:00
if (print_usage) {
puts("Read <key> from <domain>'s database");
puts("");
puts(" -h, --help display this help message");
puts(" -v, --version output version information and exit");
}
exit(exitval);
2001-02-09 16:05:49 +00:00
}
int main(int argc, char **argv)
{
2010-04-01 03:30:05 +02:00
char path[PATH_MAX];
2009-08-20 00:59:40 +02:00
WMPropList *key, *value, *dict;
2010-04-01 03:30:05 +02:00
int ch;
struct option longopts[] = {
{ "version", no_argument, NULL, 'v' },
{ "help", no_argument, NULL, 'h' },
{ NULL, 0, NULL, 0 }
};
prog_name = argv[0];
2010-04-01 03:30:05 +02:00
while ((ch = getopt_long(argc, argv, "hv", longopts, NULL)) != -1)
switch(ch) {
case 'v':
printf("%s (Window Maker %s)\n", prog_name, VERSION);
2010-04-01 03:30:05 +02:00
return 0;
/* NOTREACHED */
case 'h':
print_help(1, 0);
/* NOTREACHED */
case 0:
break;
default:
print_help(0, 1);
/* NOTREACHED */
2009-08-20 00:59:40 +02:00
}
2010-04-01 03:30:05 +02:00
argc -= optind;
argv += optind;
if (argc != 2)
print_help(0, 1);
2009-08-20 00:59:40 +02:00
2010-04-01 03:30:05 +02:00
key = WMCreatePLString(argv[1]);
2009-08-20 00:59:40 +02:00
2010-04-01 03:30:05 +02:00
snprintf(path, sizeof(path), "%s", wdefaultspathfordomain(argv[0]));
2009-08-20 00:59:40 +02:00
2010-04-01 03:30:05 +02:00
dict = WMReadPropListFromFile(path);
if (dict == NULL)
2009-08-20 00:59:40 +02:00
return 1; /* bad domain */
2010-04-01 03:30:05 +02:00
value = WMGetFromPLDictionary(dict, key);
if (value == NULL)
2009-08-20 00:59:40 +02:00
return 2; /* bad key */
printf("%s\n", WMGetPropListDescription(value, True));
return 0;
2001-02-09 16:05:49 +00:00
}