Files
wmaker/util/wdread.c
T

91 lines
2.3 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
2004-10-12 21:28:27 +00:00
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
2001-02-09 16:05:49 +00:00
* USA.
*/
#define PROG_VERSION "wdread (Window Maker) 0.2"
/*
* WindowMaker defaults DB reader
*/
#include "../src/wconfig.h"
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <unistd.h>
#include <WINGs/WUtil.h>
2001-02-09 16:05:49 +00:00
#include <pwd.h>
2010-03-18 23:14:23 +01:00
extern char *__progname;
2001-02-09 16:05:49 +00:00
2009-08-20 00:59:40 +02:00
void wAbort()
2001-02-09 16:05:49 +00:00
{
2009-08-20 00:59:40 +02:00
exit(0);
2001-02-09 16:05:49 +00:00
}
2010-03-18 23:14:23 +01:00
void print_help()
2001-02-09 16:05:49 +00:00
{
2010-03-18 23:14:23 +01:00
printf("Usage: %s [OPTIONS] <domain> <option>\n", __progname);
2009-08-20 00:59:40 +02:00
puts("");
2010-03-18 23:14:23 +01:00
puts(" -h, --help display this help message");
puts(" -v, --version output version information and exit");
2009-08-20 00:59:40 +02:00
exit(1);
2001-02-09 16:05:49 +00:00
}
int main(int argc, char **argv)
{
2009-08-20 00:59:40 +02:00
char path[256];
WMPropList *key, *value, *dict;
int i;
for (i = 1; i < argc; i++) {
2010-03-18 23:14:23 +01:00
if (strcmp("-h", argv[i]) == 0 || strcmp("--help", argv[i]) == 0) {
print_help();
2009-08-20 00:59:40 +02:00
exit(0);
2010-03-18 23:14:23 +01:00
} else if (strcmp("-v", argv[i]) == 0 || strcmp("--version", argv[i]) == 0) {
2009-08-20 00:59:40 +02:00
puts(PROG_VERSION);
exit(0);
}
}
if (argc < 3) {
2010-03-18 23:14:23 +01:00
printf("%s: invalid argument format\n", __progname);
printf("Try '%s --help' for more information\n", __progname);
2009-08-20 00:59:40 +02:00
exit(1);
}
key = WMCreatePLString(argv[2]);
2010-03-18 23:14:23 +01:00
snprintf(path, sizeof(path), wdefaultspathfordomain(argv[1]));
2009-08-20 00:59:40 +02:00
if ((dict = WMReadPropListFromFile(path)) == NULL)
return 1; /* bad domain */
if ((value = WMGetFromPLDictionary(dict, key)) == NULL)
return 2; /* bad key */
printf("%s\n", WMGetPropListDescription(value, True));
return 0;
2001-02-09 16:05:49 +00:00
}