2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these libraries and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /*******************************************************************************
27 ** $TOG: props.c /main/7 1998/08/11 16:33:35 mgreess $
29 ** RESTRICTED CONFIDENTIAL INFORMATION:
31 ** The information in this document is subject to special
32 ** restrictions in a confidential disclosure agreement between
33 ** HP, IBM, Sun, USL, SCO and Univel. Do not distribute this
34 ** document outside HP, IBM, Sun, USL, SCO, or Univel without
35 ** Sun's specific written approval. This document and all copies
36 ** and derivative works thereof must be returned or destroyed at
39 ** Copyright 1993 Sun Microsystems, Inc. All rights reserved.
41 *******************************************************************************/
44 * (c) Copyright 1993, 1994 Hewlett-Packard Company *
45 * (c) Copyright 1993, 1994 International Business Machines Corp. *
46 * (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
47 * (c) Copyright 1993, 1994 Novell, Inc. *
51 static char sccsid[] = "@(#)props.c 1.13 94/11/07 Copyr 1991 Sun Microsystems, Inc.";
54 #include <EUSCompat.h>
55 #include <sys/param.h>
63 /*******************************************************************************
67 *******************************************************************************/
68 static const char *UPGRADED = "Upgraded";
69 static const char *CLASS_NAME = "deskset";
70 static const char *APP_NAME = "calendar";
71 static const char *RC_FILENAME = "/.cm.rc";
72 static const char *DS_FILENAME = "/.desksetdefaults";
73 static const char *OW_FILENAME = "/lib/app-defaults/Deskset";
74 static const char *X_FILENAME = "/.Xdefaults";
77 ** List of constant strings in ~/.desksetdefaults which we will pay attention
78 ** to ... if you add a member to this array, be sure to add it to the
79 ** enumerated type in props.h
81 static const char *property_names[] = {
132 ** List of constant strings containing hard-coded defaults. The program will
133 ** also attempt to read some stuff from the environment if the hard-coded
134 ** default is NULL (example: $PRINTER)
136 ** If you add a member to this array, be sure to add it above and to the
137 ** enumerated type in props.h
139 static const char *def_props[] = {
142 "5", /* BeepAdvance */
143 "Mins", /* BeepUnit */
144 "False", /* FlashOn */
145 "5", /* FlashAdvance */
146 "Mins", /* FlashUnit */
148 "5", /* OpenAdvance */
149 "Mins", /* OpenUnit */
150 "False", /* MailOn */
151 "2", /* MainAdvance */
152 "Hrs", /* MailUnit */
154 "False", /* UnixOn */
155 "0", /* UnixAdvance */
156 "\0", /* UnixCommand */
159 "\0", /* CalendarList */
160 "1", /* DefaultView */
161 "0", /* DefaultDisplay */
163 "7", /* PrintPrivacy */
164 "\0", /* PrinterName */
165 "\0", /* PrintOptions */
166 "\0", /* PrintDirName */
167 "calendar.ps", /* PrintFileName */
168 "1.00 in", /* PrintRMargin */
169 "1.00 in", /* PrintBMargin */
170 "1.00 in", /* PrintLMargin */
171 "1.00 in", /* PrintTMargin */
172 "0", /* PrintLHeader - Date */
173 "1", /* PrintRHeader - User Id */
174 "2", /* PrintLFooter - Page No */
175 "3", /* PrintRFooter - Rpt Type */
177 "1", /* PrintCopies */
178 "\0", /* DefaultCal */
179 "\0", /* CalendarLocation */
180 "0", /* DateOrdering */
181 "1", /* DateSeparator */
182 "Show Time And Text", /* Privacy */
183 "False", /* UseFNS */
184 "540", /* ApptBegin */
185 "60", /* ApptDuration */
189 /*******************************************************************************
191 ** Functions static to props.c
193 *******************************************************************************/
195 p_free_props_entries(Props_entry *e) {
199 p_free_props_entries(e->next);
201 if (e->property_name)
202 free(e->property_name);
203 if (e->property_value)
204 free(e->property_value);
209 p_get_props_entry(Props *p, Props_op op) {
210 Props_op idx = CP_BEGOP + 1;
211 Props_entry *step = p->p_list;
213 while(step && (idx < op)) {
220 /*******************************************************************************
222 ** Functions external to props.c
224 *******************************************************************************/
226 ** Moving .cm.rc properties to .desksetdefaults
229 cal_convert_cmrc(Props *p) {
230 char *c_ptr, fn[MAXPATHLEN], *val;
232 Resource *cm_rdb = NULL;
236 if (get_resource(p->rdb, (char *)CLASS_NAME, (char *)APP_NAME,
237 (char *)UPGRADED, NULL))
241 ** If we're here, the Upgraded resource hasn't been set, so read
242 ** the old .cm.rc file then write it to .desksetdefaults.
244 if (getenv("HOME") != NULL)
245 sprintf(fn, "%s%s", getenv("HOME"), RC_FILENAME);
249 if (!load_resources(&cm_rdb, fn))
252 for (op = CP_BEGOP + 1; op < CP_ENDOP; op++) {
253 if (!(val = get_resource(cm_rdb, (char *)CLASS_NAME,
254 (char *)APP_NAME, (char *)property_names[op], NULL)))
257 set_resource(&p->rdb, (char *)CLASS_NAME, (char *)APP_NAME,
258 (char *)property_names[op], val);
260 set_resource(&p->rdb, (char *)CLASS_NAME, (char *)APP_NAME,
261 (char *)UPGRADED, "True");
263 free_resources(cm_rdb);
269 get_char_prop(Props *p, Props_op op) {
270 Props_entry *step = p_get_props_entry(p, op);
272 if (!step || !step->property_value || step->property_value == '\0')
273 return get_char_prop_default(op);
274 return (step->property_value);
278 get_char_prop_default(Props_op op) {
279 char *val, *ptr, *user, *host;
283 user = (char *)cm_get_uname();
284 host = (char *)cm_get_local_host();
285 val = (char *)ckalloc(cm_strlen(user) + cm_strlen(host) + 2);
286 sprintf(val, "%s@%s", user, host);
289 val = cm_def_printer();
291 case CP_PRINTDIRNAME:
292 if (getenv("HOME") != NULL)
293 val = (char *)cm_strdup(getenv("HOME"));
295 val = (char *)cm_strdup("/");
298 user = (char *)cm_get_uname();
299 host = (char *)cm_get_local_host();
300 val = (char *)ckalloc(cm_strlen(user) + cm_strlen(host) + 2);
301 sprintf(val, "%s@%s", user, host);
304 val = (char *)cm_strdup(cm_get_local_host());
307 val = (char *)cm_strdup((char *)def_props[op]);
315 get_int_prop(Props *p, Props_op op) {
316 Props_entry *step = p_get_props_entry(p, op);
318 if (!step || !step->property_value || step->property_value == '\0')
319 return (atoi(get_char_prop_default(op)));
320 return (atoi(step->property_value));
324 props_clean_up(Props *p) {
325 p_free_props_entries(p->p_list);
326 free_resources(p->rdb);
332 #define LIBDTCM_CAT "libdtcm"
333 static int is_inited = 0;
334 nl_catd libdtcm_catd;
335 const char *dflt, *str;
336 OrderingType ordering;
338 if (is_inited) return;
342 libdtcm_catd = catopen(LIBDTCM_CAT, NL_CAT_LOCALE);
343 if ((nl_catd) -1 == libdtcm_catd) return;
345 dflt = def_props[CP_DATEORDERING];
346 str = catgets(libdtcm_catd, 1, 1, dflt);
347 def_props[CP_DATEORDERING] = strdup(str);
349 dflt = def_props[CP_DEFAULTDISP];
350 str = catgets(libdtcm_catd, 1, 2, dflt);
351 def_props[CP_DEFAULTDISP] = strdup(str);
355 read_props(Props *p) {
356 char *resource, buf[MAXPATHLEN];
357 char *home, *ow_home, *x_env, *ds_def;
359 Resource *other_rdb = NULL;
360 Props_entry *entry_ptr, *last = NULL;
364 if (getenv("HOME") != NULL)
365 home = getenv("HOME");
369 ow_home = getenv("OPENWINHOME");
370 x_env = getenv("XENVIRONMENT");
371 ds_def = getenv("DESKSETDEFAULTS");
374 free_resources(p->rdb);
377 sprintf(buf, "%s", ds_def);
379 sprintf(buf, "%s%s", home, DS_FILENAME);
381 load_resources(&p->rdb, buf);
384 sprintf(buf, "%s%s", ow_home, OW_FILENAME);
385 load_resources(&other_rdb, buf);
388 sprintf(buf, "%s%s", home, X_FILENAME);
389 load_resources(&other_rdb, buf);
392 sprintf(buf, "%s%s", x_env, X_FILENAME);
393 load_resources(&other_rdb, buf);
396 p_free_props_entries(p->p_list);
397 for (op = CP_BEGOP + 1; op < CP_ENDOP; op++) {
398 entry_ptr = (Props_entry *)ckalloc(sizeof(Props_entry));
399 entry_ptr->property_name = (char *)
400 cm_strdup((char *)property_names[op]);
401 entry_ptr->update = B_FALSE;
403 last->next = entry_ptr;
405 p->p_list = entry_ptr;
406 entry_ptr->next = NULL;
409 resource = (char *)get_resource(p->rdb, (char *)CLASS_NAME,
410 (char *)APP_NAME, entry_ptr->property_name, NULL);
411 if (!resource || *resource == '\0')
412 resource = (char *)get_resource(other_rdb,
413 (char *)CLASS_NAME, (char *)APP_NAME,
414 entry_ptr->property_name, NULL);
415 if (!resource || *resource == '\0')
416 entry_ptr->property_value = get_char_prop_default(op);
418 entry_ptr->property_value = (char *)cm_strdup(resource);
420 free_resources(other_rdb);
427 char buf[MAXPATHLEN], *ds_def = getenv("DESKSETDEFAULTS");
428 Props_entry *p_ptr = p->p_list;
431 if (p_ptr->update && p_ptr->property_value)
432 set_resource(&p->rdb, (char *)CLASS_NAME,
433 (char *)APP_NAME, p_ptr->property_name,
434 p_ptr->property_value);
439 snprintf(buf, MAXPATHLEN, "%s", ds_def);
441 if (getenv("HOME") != NULL)
442 snprintf(buf, MAXPATHLEN, "%s%s",
443 getenv("HOME"), DS_FILENAME);
445 snprintf(buf, MAXPATHLEN, "/%s", DS_FILENAME);
447 return (save_resources(p->rdb, buf));
451 set_char_prop(Props *p, Props_op op, char *value) {
452 Props_entry *step = p_get_props_entry(p, op);
457 if (step->property_value)
458 free(step->property_value);
459 step->property_value = (char *)cm_strdup(value);
460 step->update = B_TRUE;
465 set_int_prop(Props *p, Props_op op, int value) {
466 char buf[MAXNAMELEN];
468 sprintf(buf, "%d", value);
469 return (set_char_prop(p, op, buf));