Files
wmaker/util/seticons.c
T

113 lines
3.1 KiB
C
Raw Normal View History

1998-09-29 22:36:29 +00:00
/* seticons.c - sets icon configuration in WindowMaker
*
* 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 "seticons (Window Maker) 0.1"
1998-09-29 22:36:29 +00:00
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <WINGs/WUtil.h>
1998-09-29 22:36:29 +00:00
#include "../src/wconfig.h"
2010-03-18 23:14:23 +01:00
extern char *__progname;
1998-09-29 22:36:29 +00:00
2009-08-20 00:59:40 +02:00
void print_help()
1999-01-29 08:11:17 +00:00
{
2010-03-18 23:14:23 +01:00
printf("Usage: %s [OPTIONS] FILE\n", __progname);
2009-08-20 00:59:40 +02:00
puts("Reads icon configuration from FILE and updates Window Maker.");
puts("");
2010-03-18 23:14:23 +01:00
puts(" -h, --help display this help and exit");
puts(" -v, --version output version information and exit");
1999-01-29 08:11:17 +00:00
}
2009-08-20 00:59:40 +02:00
int main(int argc, char **argv)
1998-09-29 22:36:29 +00:00
{
2009-08-20 00:59:40 +02:00
WMPropList *window_name, *icon_key, *window_attrs, *icon_value;
WMPropList *all_windows, *iconset, *keylist;
int i;
char *path = NULL;
if (argc < 2) {
2010-03-18 23:14:23 +01:00
printf("%s: missing argument\n", __progname);
printf("Try '%s --help' for more information\n", __progname);
exit(1);
2009-08-20 00:59:40 +02:00
}
for (i = 1; i < argc; i++) {
if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) {
print_help();
exit(0);
2010-03-18 23:14:23 +01:00
} else if (strcmp(argv[i], "-v") == 0 || strcmp(argv[i], "--version") == 0) {
2009-08-20 00:59:40 +02:00
puts(PROG_VERSION);
exit(0);
} else {
if (path) {
2010-03-18 23:14:23 +01:00
printf("%s: invalid argument '%s'\n", __progname, argv[i]);
printf("Try '%s --help' for more information\n", __progname);
2009-08-20 00:59:40 +02:00
exit(1);
}
path = argv[i];
}
}
2010-03-18 23:14:23 +01:00
path = wdefaultspathfordomain("WMWindowAttributes");
2009-08-20 00:59:40 +02:00
all_windows = WMReadPropListFromFile(path);
if (!all_windows) {
2010-03-18 23:14:23 +01:00
printf("%s: could not load WindowMaker configuration file \"%s\".\n", __progname, path);
2009-08-20 00:59:40 +02:00
exit(1);
}
iconset = WMReadPropListFromFile(argv[1]);
if (!iconset) {
2010-03-18 23:14:23 +01:00
printf("%s: could not load icon set file \"%s\".\n", __progname, argv[1]);
2009-08-20 00:59:40 +02:00
exit(1);
}
keylist = WMGetPLDictionaryKeys(iconset);
icon_key = WMCreatePLString("Icon");
for (i = 0; i < WMGetPropListItemCount(keylist); i++) {
window_name = WMGetFromPLArray(keylist, i);
if (!WMIsPLString(window_name))
continue;
icon_value = WMGetFromPLDictionary(iconset, window_name);
if (!icon_value || !WMIsPLDictionary(icon_value))
continue;
window_attrs = WMGetFromPLDictionary(all_windows, window_name);
if (window_attrs) {
if (WMIsPLDictionary(window_attrs)) {
WMMergePLDictionaries(window_attrs, icon_value, True);
}
} else {
WMPutInPLDictionary(all_windows, window_name, icon_value);
}
}
2010-03-15 23:12:24 +01:00
WMWritePropListToFile(all_windows, path);
2009-08-20 00:59:40 +02:00
exit(0);
1998-09-29 22:36:29 +00:00
}