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 librararies 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>
62 /*******************************************************************************
66 *******************************************************************************/
67 static const char *UPGRADED = "Upgraded";
68 static const char *CLASS_NAME = "deskset";
69 static const char *APP_NAME = "calendar";
70 static const char *RC_FILENAME = "/.cm.rc";
71 static const char *DS_FILENAME = "/.desksetdefaults";
72 static const char *OW_FILENAME = "/lib/app-defaults/Deskset";
73 static const char *X_FILENAME = "/.Xdefaults";
76 ** List of constant strings in ~/.desksetdefaults which we will pay attention
77 ** to ... if you add a member to this array, be sure to add it to the
78 ** enumerated type in props.h
80 static const char *property_names[] = {
131 ** List of constant strings containing hard-coded defaults. The program will
132 ** also attempt to read some stuff from the environment if the hard-coded
133 ** default is NULL (example: $PRINTER)
135 ** If you add a member to this array, be sure to add it above and to the
136 ** enumerated type in props.h
138 static const char *def_props[] = {
141 "5", /* BeepAdvance */
142 "Mins", /* BeepUnit */
143 "False", /* FlashOn */
144 "5", /* FlashAdvance */
145 "Mins", /* FlashUnit */
147 "5", /* OpenAdvance */
148 "Mins", /* OpenUnit */
149 "False", /* MailOn */
150 "2", /* MainAdvance */
151 "Hrs", /* MailUnit */
153 "False", /* UnixOn */
154 "0", /* UnixAdvance */
155 "\0", /* UnixCommand */
158 "\0", /* CalendarList */
159 "1", /* DefaultView */
160 "0", /* DefaultDisplay */
162 "7", /* PrintPrivacy */
163 "\0", /* PrinterName */
164 "\0", /* PrintOptions */
165 "\0", /* PrintDirName */
166 "calendar.ps", /* PrintFileName */
167 "1.00 in", /* PrintRMargin */
168 "1.00 in", /* PrintBMargin */
169 "1.00 in", /* PrintLMargin */
170 "1.00 in", /* PrintTMargin */
171 "0", /* PrintLHeader - Date */
172 "1", /* PrintRHeader - User Id */
173 "2", /* PrintLFooter - Page No */
174 "3", /* PrintRFooter - Rpt Type */
176 "1", /* PrintCopies */
177 "\0", /* DefaultCal */
178 "\0", /* CalendarLocation */
179 "0", /* DateOrdering */
180 "1", /* DateSeparator */
181 "Show Time And Text", /* Privacy */
182 "False", /* UseFNS */
183 "540", /* ApptBegin */
184 "60", /* ApptDuration */
188 /*******************************************************************************
190 ** Functions static to props.c
192 *******************************************************************************/
194 p_free_props_entries(Props_entry *e) {
198 p_free_props_entries(e->next);
200 if (e->property_name)
201 free(e->property_name);
202 if (e->property_value)
203 free(e->property_value);
208 p_get_props_entry(Props *p, Props_op op) {
209 Props_op idx = CP_BEGOP + 1;
210 Props_entry *step = p->p_list;
212 while(step && (idx < op)) {
219 /*******************************************************************************
221 ** Functions external to props.c
223 *******************************************************************************/
225 ** Moving .cm.rc properties to .desksetdefaults
228 cal_convert_cmrc(Props *p) {
229 char *c_ptr, fn[MAXPATHLEN], *val;
231 Resource *cm_rdb = NULL;
235 if (get_resource(p->rdb, (char *)CLASS_NAME, (char *)APP_NAME,
236 (char *)UPGRADED, NULL))
240 ** If we're here, the Upgraded resource hasn't been set, so read
241 ** the old .cm.rc file then write it to .desksetdefaults.
243 if (getenv("HOME") != NULL)
244 sprintf(fn, "%s%s", getenv("HOME"), RC_FILENAME);
248 if (!load_resources(&cm_rdb, fn))
251 for (op = CP_BEGOP + 1; op < CP_ENDOP; op++) {
252 if (!(val = get_resource(cm_rdb, (char *)CLASS_NAME,
253 (char *)APP_NAME, (char *)property_names[op], NULL)))
256 set_resource(&p->rdb, (char *)CLASS_NAME, (char *)APP_NAME,
257 (char *)property_names[op], val);
259 set_resource(&p->rdb, (char *)CLASS_NAME, (char *)APP_NAME,
260 (char *)UPGRADED, "True");
262 free_resources(cm_rdb);
268 get_char_prop(Props *p, Props_op op) {
269 Props_entry *step = p_get_props_entry(p, op);
271 if (!step || !step->property_value || step->property_value == '\0')
272 return get_char_prop_default(op);
273 return (step->property_value);
277 get_char_prop_default(Props_op op) {
278 char *val, *ptr, *user, *host;
282 user = (char *)cm_get_uname();
283 host = (char *)cm_get_local_host();
284 val = (char *)ckalloc(cm_strlen(user) + cm_strlen(host) + 2);
285 sprintf(val, "%s@%s", user, host);
288 val = cm_def_printer();
290 case CP_PRINTDIRNAME:
291 if (getenv("HOME") != NULL)
292 val = (char *)cm_strdup(getenv("HOME"));
294 val = (char *)cm_strdup("/");
297 user = (char *)cm_get_uname();
298 host = (char *)cm_get_local_host();
299 val = (char *)ckalloc(cm_strlen(user) + cm_strlen(host) + 2);
300 sprintf(val, "%s@%s", user, host);
303 val = (char *)cm_strdup(cm_get_local_host());
306 val = (char *)cm_strdup((char *)def_props[op]);
314 get_int_prop(Props *p, Props_op op) {
315 Props_entry *step = p_get_props_entry(p, op);
317 if (!step || !step->property_value || step->property_value == '\0')
318 return (atoi(get_char_prop_default(op)));
319 return (atoi(step->property_value));
323 props_clean_up(Props *p) {
324 p_free_props_entries(p->p_list);
325 free_resources(p->rdb);
331 #define LIBDTCM_CAT "libdtcm"
332 static int is_inited = 0;
333 nl_catd libdtcm_catd;
334 const char *dflt, *str;
335 OrderingType ordering;
337 if (is_inited) return;
341 libdtcm_catd = catopen(LIBDTCM_CAT, NL_CAT_LOCALE);
342 if ((nl_catd) -1 == libdtcm_catd) return;
344 dflt = def_props[CP_DATEORDERING];
345 str = catgets(libdtcm_catd, 1, 1, dflt);
346 def_props[CP_DATEORDERING] = strdup(str);
348 dflt = def_props[CP_DEFAULTDISP];
349 str = catgets(libdtcm_catd, 1, 2, dflt);
350 def_props[CP_DEFAULTDISP] = strdup(str);
354 read_props(Props *p) {
355 char *resource, buf[MAXPATHLEN];
356 char *home, *ow_home, *x_env, *ds_def;
358 Resource *other_rdb = NULL;
359 Props_entry *entry_ptr, *last = NULL;
363 if (getenv("HOME") != NULL)
364 home = getenv("HOME");
368 ow_home = getenv("OPENWINHOME");
369 x_env = getenv("XENVIRONMENT");
370 ds_def = getenv("DESKSETDEFAULTS");
373 free_resources(p->rdb);
376 sprintf(buf, "%s", ds_def);
378 sprintf(buf, "%s%s", home, DS_FILENAME);
380 load_resources(&p->rdb, buf);
383 sprintf(buf, "%s%s", ow_home, OW_FILENAME);
384 load_resources(&other_rdb, buf);
387 sprintf(buf, "%s%s", home, X_FILENAME);
388 load_resources(&other_rdb, buf);
391 sprintf(buf, "%s%s", x_env, X_FILENAME);
392 load_resources(&other_rdb, buf);
395 p_free_props_entries(p->p_list);
396 for (op = CP_BEGOP + 1; op < CP_ENDOP; op++) {
397 entry_ptr = (Props_entry *)ckalloc(sizeof(Props_entry));
398 entry_ptr->property_name = (char *)
399 cm_strdup((char *)property_names[op]);
400 entry_ptr->update = B_FALSE;
402 last->next = entry_ptr;
404 p->p_list = entry_ptr;
405 entry_ptr->next = NULL;
408 resource = (char *)get_resource(p->rdb, (char *)CLASS_NAME,
409 (char *)APP_NAME, entry_ptr->property_name, NULL);
410 if (!resource || *resource == '\0')
411 resource = (char *)get_resource(other_rdb,
412 (char *)CLASS_NAME, (char *)APP_NAME,
413 entry_ptr->property_name, NULL);
414 if (!resource || *resource == '\0')
415 entry_ptr->property_value = get_char_prop_default(op);
417 entry_ptr->property_value = (char *)cm_strdup(resource);
419 free_resources(other_rdb);
426 char buf[MAXPATHLEN], *ds_def = getenv("DESKSETDEFAULTS");
427 Props_entry *p_ptr = p->p_list;
430 if (p_ptr->update && p_ptr->property_value)
431 set_resource(&p->rdb, (char *)CLASS_NAME,
432 (char *)APP_NAME, p_ptr->property_name,
433 p_ptr->property_value);
438 sprintf(buf, "%s", ds_def);
440 if (getenv("HOME") != NULL)
441 sprintf(buf, "%s%s", getenv("HOME"), DS_FILENAME);
443 sprintf(buf, "/%s", DS_FILENAME);
445 return (save_resources(p->rdb, buf));
449 set_char_prop(Props *p, Props_op op, char *value) {
450 Props_entry *step = p_get_props_entry(p, op);
455 if (step->property_value)
456 free(step->property_value);
457 step->property_value = (char *)cm_strdup(value);
458 step->update = B_TRUE;
463 set_int_prop(Props *p, Props_op op, int value) {
464 char buf[MAXNAMELEN];
466 sprintf(buf, "%d", value);
467 return (set_char_prop(p, op, buf));