1998-09-29 22:36:29 +00:00
|
|
|
/* wdwrite.c - write key/value to 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
|
2004-10-12 21:28:27 +00:00
|
|
|
*
|
1998-09-29 22:36:29 +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,
|
1998-09-29 22:36:29 +00:00
|
|
|
* USA.
|
|
|
|
|
*/
|
|
|
|
|
|
1999-01-29 08:11:17 +00:00
|
|
|
#define PROG_VERSION "wdwrite (Window Maker) 0.2"
|
|
|
|
|
|
1998-09-29 22:36:29 +00:00
|
|
|
/*
|
|
|
|
|
* WindowMaker defaults DB writer
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "../src/wconfig.h"
|
|
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
2001-10-04 03:07:34 +00:00
|
|
|
#include <WINGs/WUtil.h>
|
|
|
|
|
|
1998-09-29 22:36:29 +00:00
|
|
|
#include <pwd.h>
|
|
|
|
|
|
2010-03-18 23:14:23 +01:00
|
|
|
extern char *__progname;
|
1998-09-29 22:36:29 +00:00
|
|
|
|
|
|
|
|
void wAbort()
|
|
|
|
|
{
|
2009-08-20 00:59:40 +02:00
|
|
|
exit(0);
|
1998-09-29 22:36:29 +00:00
|
|
|
}
|
|
|
|
|
|
2010-03-18 23:14:23 +01:00
|
|
|
void print_help()
|
1998-09-29 22:36:29 +00:00
|
|
|
{
|
2010-03-18 23:14:23 +01:00
|
|
|
printf("Usage: %s [OPTIONS] <domain> <option> <value>\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);
|
1998-09-29 22:36:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
|
{
|
2010-03-18 23:14:23 +01:00
|
|
|
char path[256];
|
2009-08-20 00:59:40 +02:00
|
|
|
WMPropList *dom, *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 < 4) {
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dom = WMCreatePLString(argv[1]);
|
|
|
|
|
key = WMCreatePLString(argv[2]);
|
|
|
|
|
value = WMCreatePropListFromDescription(argv[3]);
|
|
|
|
|
if (!value) {
|
2010-03-18 23:14:23 +01:00
|
|
|
printf("%s: syntax error in value \"%s\"", __progname, argv[3]);
|
2009-08-20 00:59:40 +02:00
|
|
|
exit(1);
|
|
|
|
|
}
|
2010-03-18 23:14:23 +01:00
|
|
|
|
|
|
|
|
snprintf(path, sizeof(path), wdefaultspathfordomain(argv[1]));
|
2009-08-20 00:59:40 +02:00
|
|
|
|
|
|
|
|
dict = WMReadPropListFromFile(path);
|
|
|
|
|
if (!dict) {
|
|
|
|
|
dict = WMCreatePLDictionary(key, value, NULL);
|
|
|
|
|
} else {
|
|
|
|
|
WMPutInPLDictionary(dict, key, value);
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-15 23:12:24 +01:00
|
|
|
WMWritePropListToFile(dict, path);
|
2009-08-20 00:59:40 +02:00
|
|
|
|
|
|
|
|
return 0;
|
1998-09-29 22:36:29 +00:00
|
|
|
}
|