Files
wmaker/util/seticons.c
T

130 lines
3.2 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 Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
1998-09-29 22:36:29 +00:00
*/
2010-03-31 04:24:17 +02:00
#ifdef __GLIBC__
#define _GNU_SOURCE /* getopt_long */
#endif
#include "config.h"
2010-03-31 04:24:17 +02:00
#include <getopt.h>
1998-09-29 22:36:29 +00:00
#include <stdio.h>
2010-03-31 04:24:17 +02:00
#include <stdlib.h>
1998-09-29 22:36:29 +00:00
#include <string.h>
2010-03-31 04:24:17 +02:00
#ifdef HAVE_STDNORETURN
#include <stdnoreturn.h>
#endif
#include <WINGs/WUtil.h>
1998-09-29 22:36:29 +00:00
#include "../src/wconfig.h"
static const char *prog_name;
1998-09-29 22:36:29 +00:00
static noreturn void print_help(int print_usage, int exitval)
1999-01-29 08:11:17 +00:00
{
2015-04-06 17:57:58 +02:00
printf("Usage: %s [-h] [-v] file\n", prog_name);
2010-03-31 04:24:17 +02:00
if (print_usage) {
puts("Reads icon configuration from FILE and updates Window Maker.");
puts("");
puts(" -h, --help display this help and exit");
puts(" -v, --version output version information and exit");
}
exit(exitval);
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
{
2011-03-24 16:07:20 +01:00
WMPropList *window_name, *window_attrs, *icon_value;
2009-08-20 00:59:40 +02:00
WMPropList *all_windows, *iconset, *keylist;
2010-03-31 04:24:17 +02:00
int i, ch;
2009-08-20 00:59:40 +02:00
char *path = NULL;
2010-03-31 04:24:17 +02:00
struct option longopts[] = {
{ "version", no_argument, NULL, 'v' },
{ "help", no_argument, NULL, 'h' },
{ NULL, 0, NULL, 0 }
};
prog_name = argv[0];
2010-03-31 04:24:17 +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-03-31 04:24:17 +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-03-31 04:24:17 +02:00
argc -= optind;
argv += optind;
if (argc != 1)
print_help(0, 1);
2009-08-20 00:59:40 +02:00
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) {
printf("%s: could not load WindowMaker configuration file \"%s\".\n", prog_name, path);
2010-04-01 03:30:05 +02:00
return 1;
2009-08-20 00:59:40 +02:00
}
2010-03-31 04:24:17 +02:00
iconset = WMReadPropListFromFile(argv[0]);
2009-08-20 00:59:40 +02:00
if (!iconset) {
printf("%s: could not load icon set file \"%s\".\n", prog_name, argv[0]);
2010-04-01 03:30:05 +02:00
return 1;
2009-08-20 00:59:40 +02:00
}
keylist = WMGetPLDictionaryKeys(iconset);
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
2010-04-01 03:30:05 +02:00
return 0;
1998-09-29 22:36:29 +00:00
}