Initial import of the CDE 2.1.30 sources from the Open Group.

This commit is contained in:
Peter Howkins
2012-03-10 18:21:40 +00:00
commit 83b6996daa
18978 changed files with 3945623 additions and 0 deletions

View File

@@ -0,0 +1,43 @@
XCOMM $XConsortium: Imakefile /main/5 1996/05/14 10:36:35 barstow $
#define DoNormalLib YES
#define DoSharedLib NO
#define DoDebugLib NO
#define DoProfileLib NO
#define LibName DtCmP
#define LibHeaders NO
#define LibInstall NO
INCLUDES = -I. -I$(CSASRC)
OSMAJORVERSION = OSMajorVersion
OSMINORVERSION = OSMinorVersion
DEFINES = -DRFC_MIME -DLINE_COUNT -DV2 -DOW_I18N -DSVR4 \
-DREL="$(OSMAJORVERSION)$(OSMINORVERSION)" \
-DRELMAJOR="$(OSMAJORVERSION)" -DRELMINOR="$(OSMINORVERSION)"
#ifdef SunArchitecture
XCOMM Uncomment to build using Federated Naming Services. To activate
XCOMM you must set the UseFNS resource to True before running dtcm.
XCOMM #define UseFNS
# ifdef UseFNS
EXTRA_DEFINES = -DFNS -DSunOS=$(OSMAJORVERSION)$(OSMINORVERSION)
# else
EXTRA_DEFINES = -DSunOS=$(OSMAJORVERSION)$(OSMINORVERSION)
# endif
EXTRA_CCOPTIONS = -xstrconst -Xc -v
#endif
SRCS = cm_tty.c cmfns.c dtfns.c \
getdate.c props.c resource.c \
timeops.c util.c
OBJS = cm_tty.o cmfns.o dtfns.o \
getdate.o props.o resource.o \
timeops.o util.o
#include <Library.tmpl>
DependTarget()

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,212 @@
/*******************************************************************************
**
** cm_tty.h
**
** static char sccsid[] = "@(#)cm_tty.h 1.35 95/07/27 Copyr 1991 Sun Microsystems, Inc.";
**
** $XConsortium: cm_tty.h /main/5 1996/10/10 14:49:30 barstow $
**
** RESTRICTED CONFIDENTIAL INFORMATION:
**
** The information in this document is subject to special
** restrictions in a confidential disclosure agreement between
** HP, IBM, Sun, USL, SCO and Univel. Do not distribute this
** document outside HP, IBM, Sun, USL, SCO, or Univel without
** Sun's specific written approval. This document and all copies
** and derivative works thereof must be returned or destroyed at
** Sun's request.
**
** Copyright 1993 Sun Microsystems, Inc. All rights reserved.
**
*******************************************************************************/
/* *
* (c) Copyright 1993, 1994 Hewlett-Packard Company *
* (c) Copyright 1993, 1994 International Business Machines Corp. *
* (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
* (c) Copyright 1993, 1994 Novell, Inc. *
*/
#ifndef CM_TTY_H
#define CM_TTY_H
#include <csa.h>
#include <nl_types.h>
#include "ansi_c.h"
#include "timeops.h"
#include "util.h"
#include "props.h"
#define DTCM_CAT "dtcm"
/*
* Enumerated type for use with appointment file parsing routines. For text,
* case is ignored!
*/
typedef enum {
NOT_A_KEY,
APPOINTMENT_START, /* "** Calendar Appointment **" */
DATE_KEY, /* "Date:" */
START_KEY, /* "Time:", "Start:", "From:" */
STOP_KEY, /* "Until:", "Stop:", "To:" */
DURATION_KEY, /* "Duration:" */
WHAT_KEY, /* "What:" */
REPEAT_KEY, /* "Repeat:" */
FOR_KEY, /* "For:" */
NEW_APPT_KEY /* "cm_appt_def:string:begin" */
} Parse_key_op;
/*
* Types used in the validation process for each appointment
*/
typedef enum {
COULD_NOT_OPEN_FILE,
CANCEL_APPT,
INVALID_DATE,
INVALID_START,
INVALID_STOP,
MISSING_DATE,
MISSING_START,
MISSING_WHAT,
INVALID_NOTIME_APPT,
REPEAT_FOR_MISMATCH,
INVALID_TIME_DUE,
INVALID_TIME,
MISSING_TIME,
VALID_APPT
} Validate_op;
/*
* Enumerated types used to access static strings for appointment information.
*/
typedef enum {
ONE_TIME,
DAILY,
WEEKLY,
EVERY_TWO_WEEKS,
MONTHLY_BY_DATE,
MONTHLY_BY_WEEKDAY,
YEARLY,
MONDAY_THRU_FRIDAY,
MON_WED_FRI,
TUESDAY_THURSDAY,
REPEAT_EVERY
} Repeat_menu_op;
typedef enum {
TWO,
THREE,
FOUR,
FIVE,
SIX,
SEVEN,
EIGHT,
NINE,
TEN,
ELEVEN,
TWELVE,
THIRTEEN,
FOURTEEN,
FOR_EVER
} For_menu_op;
typedef enum {
TIME_MINS,
TIME_HRS,
TIME_DAYS
} Time_scope_menu_op;
typedef enum {
REPEAT_DAYS,
REPEAT_WEEKS,
REPEAT_MONTHS
} Repeat_scope_menu_op;
typedef enum {
SUNDAY,
MONDAY,
TUESDAY,
WEDNESDAY,
THURSDAY,
FRIDAY,
SATURDAY
} Days_op;
typedef enum {
JANUARY,
FEBRUARY,
MARCH,
APRIL,
MAY,
JUNE,
JULY,
AUGUST,
SEPTEMBER,
OCTOBER,
NOVEMBER,
DECEMBER
} Months_op;
static const int NO_TIME = -1;
static const int ALL_DAY = -2;
/*
* External function definitions
*/
extern char *boolean_str P((boolean_t));
extern int cm_tty_delete P((nl_catd, CSA_session_handle, int, int, CSA_entry_handle*));
extern void cm_tty_format_header P((Props*, Tick, char*));
extern int cm_tty_insert P((nl_catd, CSA_session_handle, int, char*, char*,
char*, char*, char*, char*,
char*, Props*));
extern void cm_tty_load_props P((Props**));
extern int cm_tty_lookup P((nl_catd, CSA_session_handle, int, char*, char*,
CSA_entry_handle**, Props*));
extern boolean_t convert_boolean_str P((char*));
extern CSA_sint32 convert_privacy_str P((char*));
extern int convert_privacy_str_to_op P((char*));
extern SeparatorType convert_separator_str P((char*));
extern Time_scope_menu_op convert_time_scope_str P((char*));
extern char *day_str P((Days_op));
extern char *default_repeat_cnt_str P((Repeat_menu_op));
extern char *default_repeat_scope_str P((nl_catd, Repeat_menu_op));
extern char *for_str P((For_menu_op));
extern char *get_datemsg P((OrderingType,
SeparatorType));
extern Parse_key_op identify_parse_key P((char*));
extern void load_appt_defaults P((Dtcm_appointment*, Props*));
extern void load_reminder_props P((Dtcm_appointment*, Props*));
extern char *month_str P((Months_op));
extern Validate_op parse_appt_from_file P((nl_catd, char*, CmDataList*,
Props*, boolean_t(*)(void*),
void*, int));
extern char *parse_attrs_to_string P((Dtcm_appointment*, Props*,
char*));
extern char *attrs_to_string P((CSA_attribute *, int));
extern char *create_rfc_message P((char *, char *, char**, int));
extern char *parse_appt_to_string P((CSA_session_handle, CSA_entry_handle, Props*, int));
extern char *periodstr_from_period P((CSA_sint32, int));
extern char *privacy_str P((int));
extern char *privacy_str_old P((int));
extern char *repeat_str P((nl_catd, Repeat_menu_op));
extern char *repeat_scope_str P((nl_catd, Repeat_scope_menu_op));
extern char *privacy_str_411 P((int));
extern char *separator_str P((SeparatorType));
extern void str_to_period P((char*, CSA_sint32*, int*));
extern int timescopestring_to_tick P((char*));
extern char *time_scope_str P((Time_scope_menu_op));
extern char *time_scope_str_i18n P((nl_catd, Time_scope_menu_op));
extern boolean_t valid_time P((Props*, char*));
extern Validate_op validate_appt P((nl_catd, Dtcm_appointment*,
char*, char*, char*, int,
char*, char*, char*,
boolean_t(*)(void*), void*,
int));
extern Validate_op validate_dssw P((Dtcm_appointment*, char*,
char*, char*, int, char*,
boolean_t(*)(void*), void*));
extern Validate_op validate_rfp P((nl_catd, Dtcm_appointment*,
char*, char*, int));
extern Validate_op validate_reminders P((Dtcm_appointment*));
#endif

View File

@@ -0,0 +1,379 @@
/*******************************************************************************
**
** cmfns.c
**
** $XConsortium: cmfns.c /main/3 1995/11/03 10:37:19 rswiston $
**
** RESTRICTED CONFIDENTIAL INFORMATION:
**
** The information in this document is subject to special
** restrictions in a confidential disclosure agreement between
** HP, IBM, Sun, USL, SCO and Univel. Do not distribute this
** document outside HP, IBM, Sun, USL, SCO, or Univel without
** Sun's specific written approval. This document and all copies
** and derivative works thereof must be returned or destroyed at
** Sun's request.
**
** Copyright 1993 Sun Microsystems, Inc. All rights reserved.
**
*******************************************************************************/
/* *
* (c) Copyright 1993, 1994 Hewlett-Packard Company *
* (c) Copyright 1993, 1994 International Business Machines Corp. *
* (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
* (c) Copyright 1993, 1994 Novell, Inc. *
*/
#ifndef lint
static char sccsid[] = "@(#)cmfns.c 1.3 94/11/07 Copyr 1993 Sun Microsystems, Inc.";
#endif
/*
* Copyright 1993 Sun Microsystems, Inc. All rights reserved
*/
#ifdef FNS
#include <EUSCompat.h>
#include <sys/stat.h>
#include <unistd.h>
#include <stdio.h>
#include <fcntl.h>
#include <string.h>
#include <stdlib.h>
#include <netdb.h>
#include "cm_tty.h"
#include "debug.h"
#include "props.h"
#include "dtfns.h"
#include "cmfns.h"
extern char *strdup(const char *);
extern FILE *fdopen(int, const char *);
/*
* Returns 1 if we can use FNS, else 0
*
* The first call to this routine can be a little costly. Subsequent calls
* are very cheap. So avoid calling this routine at startup.
*/
int
cmfns_use_fns(Props *p)
{
static int init = 1;
static int fns_available;
static boolean_t use_fns;
if (init) {
use_fns = convert_boolean_str(get_char_prop(p, CP_USEFNS));
if ((fns_available = dtfns_available()) == -1) {
fns_available = 0;
}
init = 0;
}
if (use_fns && fns_available) {
return 1;
} else {
return 0;
}
}
/*
* Takes an absolute FNS name and attempts to generate an English
* description for it. I.e:
*
* org:ssi.eng:user:dipol -> dipol (in ssi.eng)
* org:ssi.eng:site:b21 -> b21 (a Site in ssi.eng)
* org:ssi.eng -> ssi.eng (Organization)
* host:sidewinder -> sidewinder (Host)
* dipol -> dipol
* dipol@sidewinder -> dipol@sidewinder
* org:ssi.eng:host:sidewinder -> sideiwnder (a Host in ssi.eng)
*
* Returns
* -1 buf not big enough
* 0 name is not an FNS name. No description generated
* 1 Success. Description is paced in buf
*/
int
cmfns_description(
const char *name,
char* buf,
int size) /* FNS name to generate description for */
{
char *tmp_buf;
char *head;
char *tail;
char *s = NULL;
char *org = NULL;
char len;
char *a_user_in = " (in %s)";
char *a_site_in = " (a Site in %s)";
char *a_host_in = " (a Host in %s)";
char *an_org = " (Organization)";
char *a_host = " (Host)";
char *a_site = " (Site)";
char *thisuser = "Me";
char *myorg = "My Organization";
char *hostorg = "This Host's Organization";
buf[size - 1] = '\0';
tmp_buf = strdup(name);
head = tmp_buf;
if ((tail = strchr(head, DTFNS_SEPERATOR)) == NULL) {
/*
* No colon. Either one of the special FNS names or
* it is not an FNS name
*/
if (strcmp(head, DTFNS_MYORG_NAME) == 0) {
strncpy(buf, myorg, size);
} else if (strcmp(head, DTFNS_HOSTORG_NAME) == 0) {
strncpy(buf, hostorg, size);
} else if (strcmp(head, DTFNS_THISUSER_NAME) == 0) {
strncpy(buf, thisuser, size);
} else {
/* Not an FNS name */
free(tmp_buf);
return 0;
}
goto EXIT;
}
*tail = '\0';
tail++;
if (strcmp(head, DTFNS_ORG_NAME) == 0) {
/* Starts with org:. Get org */
head = tail;
if ((tail = strchr(head, DTFNS_SEPERATOR)) == NULL) {
/* just org:orgname */
strncpy(buf, head, size);
size -= strlen(buf);
strncat(buf, an_org, size);
goto EXIT;
}
*tail = '\0';
org = head;
head = tail + 1;
if ((tail = strchr(head, DTFNS_SEPERATOR)) == NULL) {
/*
* Hmmm... We have "org:orgname:something"
* Just return the description for an organization
*/
strncpy(buf, org, size);
size -= strlen(buf);
strncat(buf, an_org, size);
goto EXIT;
}
*tail = '\0';
tail++;
}
if (strcmp(head, DTFNS_USER_NAME) == 0) {
s = org ? a_user_in : "";
} else if (strcmp(head, DTFNS_HOST_NAME) == 0) {
s = org ? a_host_in : a_host;
} else if (strcmp(head, DTFNS_SITE_NAME) == 0) {
s = org ? a_site_in : a_site;
}
if (s != NULL) {
strncpy(buf, tail, size);
len = strlen(buf);
size -= len;
if (org) {
if (size > (int)(strlen(org) + strlen(s) + 2)) {
sprintf(buf + len, s, org);
} else {
/* Buffer too small */
goto ERROR_EXIT;
}
} else {
strncat(buf, s, size);
}
}
EXIT:
free(tmp_buf);
return 1;
ERROR_EXIT:
free(tmp_buf);
return -1;
}
/*
*
* Get a calendar address from FNS
*
* 'name' may be an absolute Helix name:
* user:smith
* org:ssi.eng:user:smith
* user:smith:service
*
* 'name' may be an FNS shorthand name:
* dipol
* dipol@ssi.eng
*
* 'name' may be a calendar address:
* dipol@sidewinder
* In which case it is copied unmodified into addr_buf.
*
* 'buf' is a buffer provided by the caller in which the calendar address
* is placed.
*
* 'size' is the size of 'buf'
*
*
* Returns
*
* -1 Name not found / Error
* 0 FNS not available
* 1 Success
*
*/
int
cmfns_lookup_calendar(
const char *name,
char *addr_buf,
int addr_size
)
{
int rcode;
char fns_name[256];
char *types[4];
char *name_buf;
char *org, *tmp, *p;
DP(("cmfns_lookup_calendar: Looking up %s\n", name));
name_buf = strdup(name);
strncpy(addr_buf, name, addr_size);
addr_buf[addr_size - 1] = '\0';
if ((org = strchr(name_buf, '@')) != NULL) {
/* Either a calendar address or FNS shorthand */
*org = '\0';
org++;
if (gethostbyname(org) != NULL) {
/* Old style address. Just return it */
free(name_buf);
return 1;
}
}
/* Expand name to point at a calendar service */
rcode = dtfns_service_name(name_buf, "user", CMFNS_CALENDAR_SERVICE,
CMFNS_CALENDAR_TYPE, org, fns_name, sizeof(fns_name));
if (rcode <= 0) {
return rcode;
}
/* Specify the address types we support */
types[0] = CMFNS_CALENDAR_ADDR_TYPE;
types[1] = "SUNW_calendar";
types[2] = "SUNW_cal_deskset";
types[3] = NULL;
/* Get string bound to calendar service name */
rcode = dtfns_lookup_str(fns_name, types, addr_buf, addr_size,
NULL, 0);
if (rcode <= 0) {
return rcode;
}
if (strchr(addr_buf, '@') == NULL) {
/*
* Just the location (host) is bound in FNS. Pull
* the name of the object (user) out of the FNS
* name
*/
tmp = strdup(addr_buf);
if ((p = strstr(fns_name, ":service:")) == NULL) {
return -1;
}
*p = '\0';
while (*p != ':')
p--;
sprintf(addr_buf, "%s@%s", p + 1, tmp);
}
if (org != NULL) {
/*
* Crossing organizations. Is host qualified
* by domain?
*/
p = strchr(addr_buf, '@');
p++;
if (strchr(p, '.') == NULL) {
/*
* Host does not appear to have domain
* name. Add it
*/
strcat(addr_buf, ".");
strcat(addr_buf, org);
}
}
DP(("cmfns_lookup_calendar: FNS Lookup complete. address=%s",
addr_buf));
return rcode;
}
/*
* Register a calendar location in FNS.
*/
int
cmfns_register_calendar(const char *username, const char *location)
{
char buf[256];
int rcode;
char *types[4];
char *user;
char *p;
user = strdup(username);
if ((p = strchr(user, '@')) != NULL) {
*p = '\0';
}
DP(("register_calendar: Generating service name for %s\n", user));
/* Expand name to point at a calendar service */
rcode = dtfns_service_name(user, DTFNS_USER_NAME,
CMFNS_CALENDAR_SERVICE, CMFNS_CALENDAR_TYPE, NULL,
buf, sizeof(buf));
free(user);
if (rcode < 1)
return rcode;
types[0] = CMFNS_CALENDAR_ADDR_TYPE;
types[1] = "SUNW_calendar";
types[2] = "SUNW_cal_deskset";
types[3] = NULL;
DP(("register_calendar: Binding %s to %s\n", location, buf));
return dtfns_bind_str(buf, CMFNS_CALENDAR_TYPE, types, location);
}
#endif /* FNS */

View File

@@ -0,0 +1,39 @@
/* $XConsortium: cmfns.h /main/3 1995/11/03 10:37:28 rswiston $ */
/* @(#)cmfns.h 1.3 94/11/07 SMI */
/* *
* (c) Copyright 1993, 1994 Hewlett-Packard Company *
* (c) Copyright 1993, 1994 International Business Machines Corp. *
* (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
* (c) Copyright 1993, 1994 Novell, Inc. *
*/
#ifndef _CMFNS_H
#define _CMFNS_H
#ifdef FNS
#include "dtfns.h"
#define CMFNS_CALENDAR_SERVICE "calendar"
#define CMFNS_CALENDAR_TYPE "SUNW_fns_calendar"
#define CMFNS_CALENDAR_ADDR_TYPE "SUNW_cal_str"
#ifdef FNS_DEMO
#define FNS_FILE ".FNSName"
int cmfns_name_from_file(const char *path, char *name, int len);
#endif /* FNS_DEMO */
extern int cmfns_use_fns(Props *);
extern int cmfns_lookup_calendar(const char *name, char *addr_buf,
int addr_size);
extern int cmfns_description(const char *, char *, int);
extern int cmfns_register_calendar(const char *name, const char *calendar);
#endif /* FNS */
#endif /* _CMFNS_H */

View File

@@ -0,0 +1,972 @@
/*******************************************************************************
**
** dtfns.c
**
** $XConsortium: dtfns.c /main/3 1995/11/03 10:37:35 rswiston $
**
** RESTRICTED CONFIDENTIAL INFORMATION:
**
** The information in this document is subject to special
** restrictions in a confidential disclosure agreement between
** HP, IBM, Sun, USL, SCO and Univel. Do not distribute this
** document outside HP, IBM, Sun, USL, SCO, or Univel without
** Sun's specific written approval. This document and all copies
** and derivative works thereof must be returned or destroyed at
** Sun's request.
**
** Copyright 1993 Sun Microsystems, Inc. All rights reserved.
**
*******************************************************************************/
/* *
* (c) Copyright 1993, 1994 Hewlett-Packard Company *
* (c) Copyright 1993, 1994 International Business Machines Corp. *
* (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
* (c) Copyright 1993, 1994 Novell, Inc. *
*/
#ifndef lint
static char sccsid[] = "@(#)dtfns.c 1.3 94/11/07 Copyr 1993 Sun Microsystems, Inc.";
#endif
/*
* Copyright 1993 Sun Microsystems, Inc. All rights reserved
*/
#ifdef FNS
#include <EUSCompat.h>
#include <unistd.h>
#include <errno.h>
#include <netdb.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <fcntl.h>
#include <string.h>
#include <rpc/rpc.h>
#include <rpcsvc/nis.h>
#include <rpcsvc/nislib.h>
#include <rpcsvc/ypclnt.h>
#include <dlfcn.h>
#include <malloc.h>
#include <string.h>
#include <ctype.h>
#include <fns/fns.h>
#include "debug.h"
#include "util.h"
#include "dtfns.h"
extern char *strdup(const char *);
/*
* Names found in the initial context. Used by isa_helix_name()
*
* XXX We have a bug here. If a string happens to start with
* thisuser, myorg, etc we'll recognize it as an FNS name even
* though it may not be one.
*/
static char *initial_context_names[] = {
"user:",
"thisuser",
"org:",
"site:",
"myorg",
"hostorg",
"host:",
NULL,
};
static void *libfns_handle = NULL;
static int initialized = 0;
static NS_Context_t *initial_ctx = NULL;
/*
* These are dynamically bound entry points into libfns. We dlopen()
* libfns so that cm can still run even if libfns does not exist
*/
static NS_Context_t *(*NS_Context_get_initial_p)(NS_ContextStatus_t *);
static NS_ContextStatus_t *(*NS_ContextStatus_new_p)(void);
static void (*NS_ContextStatus_delete_p)(NS_ContextStatus_t *);
static NS_Reference_t *(*NS_Context_lookup_p)(const NS_Context_t *,
const NS_CompositeName_t *,
NS_ContextStatus_t *);
static int (*NS_Context_bind_p)(const NS_Context_t *,
const NS_CompositeName_t *,
const NS_Reference_t *,
unsigned,
NS_ContextStatus_t *);
static NS_Reference_t *(*NS_Reference_new_p)(const NS_String_t *);
static void (*NS_Reference_delete_p)(const NS_Reference_t *);
static NS_String_t *(*NS_Reference_type_p)(const NS_Reference_t *);
static int (*NS_Reference_count_p)(const NS_Reference_t *);
static NS_ReferenceAddress_t *(*NS_Reference_first_p)(const NS_Reference_t *,
void **);
static NS_ReferenceAddress_t *(*NS_Reference_next_p)(const NS_Reference_t *,
void **);
static int (*NS_Reference_append_addr_p)(NS_Reference_t *,
const NS_ReferenceAddress_t *);
static int (*NS_Reference_prepend_addr_p)(NS_Reference_t *,
const NS_ReferenceAddress_t *);
static int (*NS_Reference_insert_addr_p)(NS_Reference_t *,
void **,
const NS_ReferenceAddress_t *);
static int (*NS_Reference_delete_addr_p)(NS_Reference_t *,
void **);
static void (*NS_ReferenceAddress_delete_p)(
NS_ReferenceAddress_t *);
static NS_ReferenceAddress_t *(*NS_ReferenceAddress_new_p)(const NS_String_t *,
unsigned,
const void *);
static void * (*NS_ReferenceAddress_data_p)(const NS_ReferenceAddress_t *);
static unsigned (*NS_ReferenceAddress_length_p)(const NS_ReferenceAddress_t *);
static NS_String_t *(*NS_ReferenceAddress_type_p)(const NS_ReferenceAddress_t*);
static const char * (*NS_String_cstring_p)(const NS_String_t *);
static NS_String_t * (*NS_String_from_cstring_p)(const char *);
static NS_CompositeName_t * (*NS_CompositeName_from_cstring_p)(const char *);
static int get_helix_service_name(const char *name, const char *service,
const char *service_type, char **buf);
/*
* Initialization.
*
* Load libfns (with dlopen) and bind in the entry points we use (with dlsym).
*
* We dynamically load the FNS library so that we don't have an explicit
* dependency on it. This lets us run on systems which do not have FNS
* installed
*
* Returns
* 0 FNS not available
* 1 Success
*/
int
dtfns_init(void)
{
char *libfns = FNS_LIBRARY;
int error;
if (libfns_handle != NULL) {
return 1;
}
initialized = TRUE;
libfns_handle = dlopen(libfns, RTLD_LAZY);
if (libfns_handle == NULL) {
#ifdef CM_DEBUG
char *s = dlerror();
if (s == NULL) {
DP(("Could not dlopen %s\n", libfns));
} else {
DP(("Could not dlopen %s: %s\n", libfns, s));
}
#endif
return 0;
}
NS_Context_get_initial_p = (NS_Context_t *(*)(NS_ContextStatus_t *))
dlsym(libfns_handle, "NS_Context_get_initial");
NS_ContextStatus_new_p = (NS_ContextStatus_t *(*)(void))
dlsym(libfns_handle, "NS_ContextStatus_new");
NS_ContextStatus_delete_p = (void(*)(NS_ContextStatus_t *))
dlsym(libfns_handle, "NS_ContextStatus_delete");
NS_Context_lookup_p = (NS_Reference_t *(*)(const NS_Context_t *,
const NS_CompositeName_t *,
NS_ContextStatus_t *))
dlsym(libfns_handle, "NS_Context_lookup");
NS_Context_bind_p = (int(*)(const NS_Context_t *,
const NS_CompositeName_t *,
const NS_Reference_t *,
unsigned,
NS_ContextStatus_t *))
dlsym(libfns_handle, "NS_Context_bind");
NS_Reference_new_p = (NS_Reference_t *(*)(const NS_String_t *))
dlsym(libfns_handle, "NS_Reference_new");
NS_Reference_delete_p = (void(*)(const NS_Reference_t *))
dlsym(libfns_handle, "NS_Reference_delete");;
NS_Reference_type_p = (NS_String_t *(*)(const NS_Reference_t *))
dlsym(libfns_handle, "NS_Reference_type");
NS_Reference_count_p = (int(*)(const NS_Reference_t *))
dlsym(libfns_handle, "NS_Reference_count");
NS_Reference_first_p = (NS_ReferenceAddress_t *(*)
(const NS_Reference_t *, void **))
dlsym(libfns_handle, "NS_Reference_first");
NS_Reference_next_p = (NS_ReferenceAddress_t *(*)
(const NS_Reference_t *, void **))
dlsym(libfns_handle, "NS_Reference_next");
NS_Reference_append_addr_p = (int(*)(NS_Reference_t *,
const NS_ReferenceAddress_t *))
dlsym(libfns_handle, "NS_Reference_append_addr");
NS_Reference_prepend_addr_p = (int(*)(NS_Reference_t *,
const NS_ReferenceAddress_t *))
dlsym(libfns_handle, "NS_Reference_prepend_addr");
NS_Reference_insert_addr_p = (int(*)(NS_Reference_t *,
void **,
const NS_ReferenceAddress_t *))
dlsym(libfns_handle, "NS_Reference_insert_addr");
NS_Reference_delete_addr_p = (int(*)(NS_Reference_t *, void **))
dlsym(libfns_handle, "NS_Reference_delete_addr");
NS_ReferenceAddress_delete_p = (void(*)(NS_ReferenceAddress_t *))
dlsym(libfns_handle, "NS_ReferenceAddress_delete");
NS_ReferenceAddress_new_p = (NS_ReferenceAddress_t *(*)
(const NS_String_t *, unsigned, const void *))
dlsym(libfns_handle, "NS_ReferenceAddress_new");
NS_ReferenceAddress_data_p = (void *(*)(const NS_ReferenceAddress_t *))
dlsym(libfns_handle, "NS_ReferenceAddress_data");
NS_ReferenceAddress_length_p = (unsigned(*)
(const NS_ReferenceAddress_t *))
dlsym(libfns_handle, "NS_ReferenceAddress_length");
NS_ReferenceAddress_type_p = (NS_String_t *(*)
(const NS_ReferenceAddress_t *))
dlsym(libfns_handle, "NS_ReferenceAddress_type");
NS_String_cstring_p = (const char *(*)(const NS_String_t *))
dlsym(libfns_handle, "NS_String_cstring");
NS_String_from_cstring_p = (NS_String_t * (*)(const char *))
dlsym(libfns_handle, "NS_String_from_cstring");
NS_CompositeName_from_cstring_p =(NS_CompositeName_t *(*)(const char *))
dlsym(libfns_handle, "NS_CompositeName_from_cstring");
return 1;
}
/*
* Check if FNS is available for use.
*
* You must call dfsinit() before calling this routine.
*
* First call to this routine may be costly as we get the initial context.
* Subsequent calls are very cheap.
*
* Returns
* 1 Yes, FNS is available.
* 0 No, FNS is not available.
* -1 You haven't called dtfns_init().
*/
int
dtfns_available(void)
{
static int available;
static int called;
if (called) {
return available;
}
if (libfns_handle != NULL) {
/*
* libfns has been dlopened. Now see if an FNS namespace
* is reachable by getting the initial context.
*/
if (dtfns_get_initial_ctx() == NULL) {
available = 0;
} else {
available = 1;
}
} else if (initialized) {
/* dlopen must have failed. FNS is not installed */
available = 0;
} else {
available = -1;
}
called = 1;
return available;
}
/*
* Get the initial context. This routine caches the initial context.
* The first call to this routine may be costly, be subsequent calls
* are very cheap.
*/
NS_Context_t *
dtfns_get_initial_ctx(void)
{
DP(("dtfns_get_initial_ctx: Getting initial context\n"));
if (initial_ctx == NULL) {
NS_ContextStatus_t * status;
status = (*NS_ContextStatus_new_p)();
initial_ctx = (*NS_Context_get_initial_p)(status);
(*NS_ContextStatus_delete_p)(status);
}
return initial_ctx;
}
/*
* Generate a full Helix name for a service.
*
* 'name' may be a relative Helix name. I.e.:
* smith
* smith:service
* smith:service:calendar
* In this case dtfns_service_name() will use the type, service and org
* parameters (if needed) to construct the full Helix name.
*
* 'name' may also be an absolute Helix name. I.e.:
* user:smith
* org:ssi.eng:user:smith
* user:smith:service
* In this case dtfns_service_name() will use the type and service
* parameters (if needed) to construct the full Helix name. The org
* parameter should be NULL (since the organization is already
* determined by the absolute Helix name).
*
* 'type' specifies the type of object 'name' refers to (ie "user").
*
* 'service' specifies what service is desired (ie "calendar").
*
* 'service_type' specifies the reference type of the service
* (ie SUNW_fns_calendar);
*
* 'org' is the organization name. This must be NULL if 'name' is
* an absolute Helix name. 'org' may be NULL in all other cases if the
* default organization is to be used.
*
* 'buf' is a buffer provided by the caller in which the expanded name
* is placed.
*
* 'size' is the size of 'buf'
*
*
* The string returned in buf may be used in calls to dtfns_lookup_str() and
* dtfns_lookup_ref().
*
* Returns
* -1 Name not found / Error
* 0 FNS not available
* 1 Success
*/
int
dtfns_service_name(
const char *name, /* Name to lookup */
const char *type, /* Type of object name is (ie "user") */
const char *service, /* Service name (ie "calendar") */
const char *service_type, /* Service reference type */
/* (ie "SUNW_fns_calendar"); */
const char *org, /* Org name (ie "ssi"). NULL for default org */
char *buf, /* Buffer to place name in */
const int size) /* Size of value_buf */
{
char *tmp_buf;
char *type_str;
if (libfns_handle == NULL) {
return 0;
}
if (name == NULL) {
return -1;
}
if (org != NULL && *org != '\0') {
/* Sanity check for size */
if (strlen(org) + strlen(name) > (size_t)size - 50) {
return -1;
}
/*Construct Helix name from name and organization */
sprintf(buf,"%s:%s:%s:%s:%s:%s", DTFNS_ORG_NAME,
org, type, name, DTFNS_SERVICE_NAME, service);
} else if (dtfns_isa_helix_name(name)) {
/* Helix name. Expand it to point to calendar service */
if (get_helix_service_name(name, service, service_type,
&tmp_buf) < 0) {
return -1;
}
buf[size - 1] = '\0';
strncpy(buf, tmp_buf, size - 1);
free(tmp_buf);
} else {
/* Construct Helix name from name */
sprintf(buf,"%s:%s:%s:%s", type,
name, DTFNS_SERVICE_NAME, service);
}
return 1;
}
/*
* Return TRUE if 'name' is an absolute Helix name
*/
int
dtfns_isa_helix_name(const char *name)
{
int n, len;
char **p;
for (p = initial_context_names; *p != NULL; p++) {
len = strlen(*p);
if (strncmp(name, *p, len) == 0) {
return TRUE;
}
}
return FALSE;
}
/*
* Get the org name for "myorg" (ie ssi.eng)
*/
void
dtfns_myorg_name(char *buf, int len)
{
char *__nis_local_root();
static char *myorg_name;
char *principal_name;
char *host_domain;
char *root_domain;
char *pd = NULL;
char *myorg_p, *root_p;
if (myorg_name == NULL) {
principal_name = nis_local_principal();
host_domain = nis_local_directory();
root_domain = __nis_local_root();
if (principal_name) {
/* Get the domain this principal is in */
pd = nis_domain_of(principal_name);
if (pd && *pd == '.') {
pd = NULL;
}
}
/* If no domain for the principal, use the one for the host */
myorg_name = strdup(pd ? pd : (host_domain ? host_domain : ""));
/*
* We want to strip the root domain name off of the
* end of the myorg name. Set pointers to the end
* of each name
*/
myorg_p = myorg_name + strlen(myorg_name) - 1;
root_p = root_domain + strlen(root_domain) - 1;
while (tolower(*myorg_p) == tolower(*root_p)) {
if (root_p == root_domain) {
/* Matched all of root domain name. Truncate */
if (myorg_p != myorg_name) {
*--myorg_p = '\0';
}
break;
} else if (myorg_p == myorg_name) {
break;
}
--myorg_p;
--root_p;
}
}
if (myorg_name != NULL) {
buf[len - 1] = '\0';
strncpy(buf, myorg_name, len - 1);
}
return;
}
/*
* Return the string value bound to an absolute Helix name
*
* Returns
* -1 Error
* 0 FNS not available
* 1 Success
*/
int
dtfns_lookup_str(
const char *name, /* Absolute Helix name */
char *types[], /* Type of data to get */
char *dbuf, /* Buffer to place data value in */
int dsize, /* Size of dbuf */
char *tbuf, /* Buffer to place address type in */
int tsize) /* Size of tbuf */
{
NS_Reference_t * ref;
const NS_ReferenceAddress_t * addr;
void *iter_pos;
if (libfns_handle == NULL) {
return 0;
}
/* Get the reference from the name */
if ((ref = dtfns_lookup_ref(name)) == NULL) {
return -1;
}
/* Get the address that matches at least one of the specified types */
if ((addr = dtfns_addr_from_ref(ref, types, &iter_pos)) == NULL) {
(*NS_Reference_delete_p)(ref);
return -1;
}
(*NS_Reference_delete_p)(ref);
/* Return data bound to that address */
return dtfns_str_from_addr(addr, dbuf, dsize, tbuf, tsize);
}
/*
*
* Bind a string to a name.
*
* name Absolute Helix name to bind string to
*
* ref_type Reference type. We need this to create
* the reference if it does not already exist.
*
* types Array of address types. This routine looks for
* the address that matches at least one of these
* types. The first type is used when the new
* string is bound.
*
* new_str String to bind to name
*
* Returns
* -1 Error
* 0 FNS not available
* 1 Success
*/
int
dtfns_bind_str(
const char *name, /* Absolute Helix name */
const char *ref_type, /* Reference type */
char *types[], /* Address type of data to operate on */
const char *new_str /* String to bind to name */
)
{
NS_Reference_t *ref = NULL;
const NS_ReferenceAddress_t *addr = NULL;
NS_ReferenceAddress_t *new_addr = NULL;
NS_CompositeName_t *comp_name;
NS_ContextStatus_t *status = NULL;
NS_Context_t *ctx = NULL;
NS_String_t *nstr;
void *iter_pos = NULL;
char buf[256];
int rcode = -1;
if (libfns_handle == NULL) {
return 0;
}
/* Get the reference from the name */
if ((ref = dtfns_lookup_ref(name)) != NULL) {
/*
* A value is already bound to this name.
* Get the address that matches at least one of
* the specified types
*/
addr = dtfns_addr_from_ref(ref, types, &iter_pos);
if (addr != NULL) {
/* Get string bound to that address */
*buf = '\0';
dtfns_str_from_addr(addr, buf, sizeof(buf), NULL, 0);
/* Are we changing the string? */
if (strcmp(buf, new_str) == 0) {
/* Bound value is the same as new value */
rcode = 1;
goto EXIT;
} else {
/* Delete old address string */
(*NS_Reference_delete_addr_p)(ref, &iter_pos);
}
}
} else {
/* Nothing bound to name. Create an empty reference */
nstr = (*NS_String_from_cstring_p)(ref_type);
ref = (*NS_Reference_new_p)(nstr);
iter_pos = NULL;
}
/* Create new address */
if ((new_addr = dtfns_create_str_addr(new_str, types[0])) == NULL) {
goto EXIT;
}
/* Insert new address into reference */
if (dtfns_insert_addr(ref, &iter_pos, new_addr) < 1) {
goto EXIT;
}
/* Bind reference into name space */
if ((ctx = dtfns_get_initial_ctx()) == NULL) {
goto EXIT;
}
status = (*NS_ContextStatus_new_p)();
comp_name = (*NS_CompositeName_from_cstring_p)(name);
if ((*NS_Context_bind_p)(ctx, comp_name, ref, 0, status) < 1) {
goto EXIT;
}
rcode = 1;
EXIT:
/* Clean up and return */
if (new_addr != NULL) (*NS_ReferenceAddress_delete_p)(new_addr);
if (ref != NULL) (*NS_Reference_delete_p)(ref);
if (status != NULL) (*NS_ContextStatus_delete_p)(status);
return rcode;
}
/*
* Return the reference bound to an absolute Helix name
*
* Returns
* NULL Error
* NS_Reference_t * for reference
*/
NS_Reference_t *
dtfns_lookup_ref(
const char *name)/* Absolute Helix name to lookup */
{
NS_Reference_t * ref = NULL;
NS_ContextStatus_t * status = NULL;
NS_CompositeName_t * comp_name = NULL;
NS_Context_t * ctx;
if (libfns_handle == NULL) {
return NULL;
}
status = (*NS_ContextStatus_new_p)();
if ((ctx = dtfns_get_initial_ctx()) != NULL) {
/* Lookup the Helix name specified by "name" */
comp_name = (*NS_CompositeName_from_cstring_p)(name);
ref = (*NS_Context_lookup_p)(ctx, comp_name, status);
}
(*NS_ContextStatus_delete_p)(status);
return ref;
}
/*
* Takes a Helix name and converts it to a full name for a service.
* I.e. if service is "calendar":
*
* name buf
* org:ss-eng:user:dipol --> org:ss-eng:user:dipol:service:calendar
* org:ss-eng --> org:ss-eng:service:calendar
* org:ss-eng:service: --> org:ss-eng:service:calendar
*
* Returns
* -1 Error. buf not set
* 0 name already points to the service
* buf is a duplicate of name.
* 1 name resolved. buf is set. Caller
* is responsible for freeing memory.
*/
static int
get_helix_service_name(
const char *name,
const char *service,
const char *service_type,
char **buf)
{
int n;
char *tmp_name;
NS_Reference_t *ref;
NS_String_t *nstr;
const char *type;
char *p;
n = strlen(name);
tmp_name = strdup(name);
/* Remove trailing : if there is one */
if (tmp_name[n - 1] == ':') {
tmp_name[n - 1] = '\0';
n--;
}
/* Get reference and extract reference type */
if ((ref = dtfns_lookup_ref(tmp_name)) == NULL) {
return -1;
}
nstr = (*NS_Reference_type_p)(ref);
type = (*NS_String_cstring_p)(nstr);
(*NS_Reference_delete_p)(ref);
/* If name is already bound to a calendar service then we are done */
if (strcmp(type, service_type) == 0) {
*buf = strdup(name);
return 0;
}
if ((p = strrchr(tmp_name, ':')) != NULL) {
p++;
}
/*
* If name is a service context or the "service" null context
* then we want to append ":calendar"
*/
if (strcmp(type, DTFNS_SERVICE_CONTEXT_TYPE) == 0 ||
(strcmp(type, DTFNS_NULL_CONTEXT_TYPE) == 0 && p != NULL &&
strcmp(p, DTFNS_SERVICE_NAME) == 0)) {
*buf = (char *)malloc(n + strlen(service) + 2);
if (*buf == NULL) {
return -1;
}
strcpy(*buf, tmp_name);
strcat(*buf, ":");
strcat(*buf, service);
return 1;
} else {
/* Append ":service:calendar" */
*buf = (char *)malloc(n +
strlen(DTFNS_SERVICE_NAME) +
strlen(service) + 3);
sprintf(*buf, "%s:%s:%s", tmp_name,
DTFNS_SERVICE_NAME, service);
return 1;
}
}
/*
* Get an FNS Address from a Reference.
*
* ref The Reference to get the address from
*
* types NULL terminated array of one or more type strings.
* This routine returns the first address that matches
* a type specified in this array. NULL to just
* get the first address.
*
* iter_pos Updated to point after retrieved address.
*
* Returns
* Pointer to the found address
* NULL if no address is found
*
*/
const NS_ReferenceAddress_t *
dtfns_addr_from_ref(
const NS_Reference_t *ref, /* Reference to get addr from */
char *types[], /* Types of addrs to get */
void **iter_pos /* Returned pos where addr was found */
)
{
const NS_ReferenceAddress_t *addr;
char type[128];
char **p;
if (libfns_handle == NULL) {
return 0;
}
addr = (*NS_Reference_first_p)(ref, iter_pos);
if (types == NULL) {
return addr;
}
while (addr != NULL) {
/* Get the type, and see if it is one we want */
dtfns_str_from_addr(addr, NULL, 0, type, sizeof(type));
for (p = types; *p != NULL && strcmp(*p, type) != 0; *p++)
;
if (*p != NULL) {
/* Found it! */
break;
} else {
/* Get next address */
addr = (*NS_Reference_next_p)(ref, iter_pos);
}
}
return addr;
}
/*
* Get the string and type out of an Address
*
* Returns
* -1 Error
* 0 FNS not available
* 1 Success
*/
int
dtfns_str_from_addr(
const NS_ReferenceAddress_t *addr, /* Addr to get string from */
char *dbuf, /* Buf to hold string data */
int dbuf_size, /* Size of dbuf */
char *tbuf, /* Buf to hold string type */
int tbuf_size /* size of tbuf */
)
{
XDR xdr;
char *s = NULL;
NS_String_t *nstr;
const char *cs;
if (libfns_handle == NULL) {
return 0;
}
if (dbuf != NULL) {
/* Convert data from XDR to a string */
xdrmem_create(&xdr,
(caddr_t)(*NS_ReferenceAddress_data_p)(addr),
(*NS_ReferenceAddress_length_p)(addr), XDR_DECODE);
if (xdr_string(&xdr, &s, ~0) == FALSE) {
return -1;
}
dbuf[dbuf_size - 1] = '\0';
strncpy(dbuf, s, dbuf_size - 1);
free(s);
}
if (tbuf != NULL) {
tbuf[tbuf_size - 1] = '\0';
nstr = (*NS_ReferenceAddress_type_p)(addr);
cs = (*NS_String_cstring_p)(nstr);
strncpy(tbuf, cs, tbuf_size - 1);
}
return 1;
}
/*
* Create an Address of type "type" for the string specified by "data"
*
* Returns
* A new address contianing the specified data
* NULL on an error
*/
NS_ReferenceAddress_t *
dtfns_create_str_addr(
const char *data,
const char *type
)
{
XDR xdr;
u_char buf[1024];
NS_String_t *nstring;
if (libfns_handle == NULL) {
return NULL;
}
xdrmem_create(&xdr, (caddr_t)buf, sizeof(buf), XDR_ENCODE);
if (xdr_string(&xdr, (char**)&data, ~0) == FALSE) {
return NULL;
}
nstring = (*NS_String_from_cstring_p)(type);
return (*NS_ReferenceAddress_new_p)(nstring, xdr_getpos(&xdr), buf);
}
/*
* Add an address to a reference at the location specified by iter_pos.
* The address is inserted before iter_pos.
* If *iter_pos is NULL then put the address in the first slot.
*
* Returns
* -1 Error
* 0 FNS not available
* 1 Success
*/
int
dtfns_insert_addr(
NS_Reference_t *ref,
void **iter_pos,
const NS_ReferenceAddress_t *addr
)
{
if (libfns_handle == NULL) {
return 0;
}
if (*iter_pos == NULL) {
if ((*NS_Reference_prepend_addr_p)(ref, addr) < 1)
return -1;
} else {
if ((*NS_Reference_insert_addr_p)(ref, iter_pos, addr) < 1)
return -1;
}
return 1;
}
/*
* Delete the Address at position "iter_pos" from a Reference
*
* Returns
* -1 Error
* 0 FNS not available
* 1 Success
*/
int
dtfns_delete_addr(
NS_Reference_t *ref,
void **iter_pos
)
{
if (libfns_handle == NULL) {
return 0;
}
(*NS_Reference_delete_addr_p)(ref, iter_pos);
return 1;
}
#endif /* FNS */

View File

@@ -0,0 +1,86 @@
/* $XConsortium: dtfns.h /main/3 1995/11/03 10:37:45 rswiston $ */
/* @(#)dtfns.h 1.3 94/11/07 SMI */
/* *
* (c) Copyright 1993, 1994 Hewlett-Packard Company *
* (c) Copyright 1993, 1994 International Business Machines Corp. *
* (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
* (c) Copyright 1993, 1994 Novell, Inc. *
*/
#ifndef _DTFNS_H
#define _DTFNS_H
#ifdef FNS
#include <fns/fns.h>
#define DTFNS_SEPERATOR ':'
#define DTFNS_ORG_NAME "org"
#define DTFNS_ORG_LEN 3
#define DTFNS_SITE_NAME "site"
#define DTFNS_SITE_LEN 4
#define DTFNS_MYORG_NAME "myorg"
#define DTFNS_MYORG_LEN 5
#define DTFNS_HOSTORG_NAME "hostorg"
#define DTFNS_HOSTORG_LEN 7
#define DTFNS_HOST_NAME "host"
#define DTFNS_HOST_LEN 4
#define DTFNS_THISUSER_NAME "thisuser"
#define DTFNS_THISUSER_LEN 8
#define DTFNS_USER_NAME "user"
#define DTFNS_USER_LEN 4
#define DTFNS_SERVICE_NAME "service"
#define DTFNS_SERVICE_LEN 7
#define DTFNS_LONG_NAME_LEN 8 /* Longest of above names */
#define DTFNS_NULL_CONTEXT_TYPE "SUNW_nscontext_null"
#define DTFNS_SERVICE_CONTEXT_TYPE "SUNW_nscontext_service"
#define FNS_LIBRARY "libfns.so.1"
extern int dtfns_init(void);
extern int dtfns_available(void);
extern int dtfns_service_name(const char *name, const char *type,
const char *service, const char *service_type,
const char *org, char *buf, const int size);
extern int dtfns_isa_helix_name(const char *);
extern int dtfns_lookup_str(const char *, char **, char *, int,
char *, int);
extern int dtfns_str_from_ref(NS_Reference_t *, int posn,
char *addr_buf, int addr_size,
char *type_buf, int type_size);
extern int dtfns_append_to_ref(NS_Reference_t *, const char *addr,
const char *addr_type);
extern int dtfns_bind_str(const char *name, const char *ref_type,
char *types[], const char *new_str);
extern NS_Reference_t * dtfns_lookup_ref(const char *);
extern void dtfns_myorg_name(char *, int);
extern NS_Context_t * dtfns_get_initial_ctx(void);
extern const NS_ReferenceAddress_t * dtfns_addr_from_ref(const NS_Reference_t *,
char**, void**);
extern int dtfns_str_from_addr(const NS_ReferenceAddress_t *, char *dbuf, int,
char *tbuf, int);
extern NS_ReferenceAddress_t * dtfns_create_str_addr(const char *data,
const char *type);
extern int dtfns_insert_addr(NS_Reference_t *, void **,
const NS_ReferenceAddress_t *);
extern int dtfns_delete_addr(NS_Reference_t *, void **);
#endif /* FNS */
#endif /* _DTFNS_H */

View File

@@ -0,0 +1,66 @@
/*******************************************************************************
**
** getdate.h
**
** static char sccsid[] = "@(#)getdate.h 1.6 94/11/07 Copyr 1991 Sun Microsystems, Inc.";
**
** $XConsortium: getdate.h /main/3 1995/11/03 10:37:54 rswiston $
**
** RESTRICTED CONFIDENTIAL INFORMATION:
**
** The information in this document is subject to special
** restrictions in a confidential disclosure agreement between
** HP, IBM, Sun, USL, SCO and Univel. Do not distribute this
** document outside HP, IBM, Sun, USL, SCO, or Univel without
** Sun's specific written approval. This document and all copies
** and derivative works thereof must be returned or destroyed at
** Sun's request.
**
** Copyright 1993 Sun Microsystems, Inc. All rights reserved.
**
*******************************************************************************/
/* *
* (c) Copyright 1993, 1994 Hewlett-Packard Company *
* (c) Copyright 1993, 1994 International Business Machines Corp. *
* (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
* (c) Copyright 1993, 1994 Novell, Inc. *
*/
#ifndef _GETDATE_H
#define _GETDATE_H
#ifdef USG
struct timeb
{
time_t time;
unsigned short millitm;
short timezone;
short dstflag;
};
#else
#include <sys/timeb.h>
#endif
#include <time.h>
#include "ansi_c.h"
#define BOT_YEAR 1970
#define EOT_YEAR 2037
#define DATE_PARSE -1 /* date simply did not parse */
#define DATE_BBOT -2 /* date was before beginning of time */
#define DATE_AEOT -3 /* date was after end of time */
#define DATE_BMONTH -4 /* date had a bad month number */
#define DATE_BDAY -5 /* date had a bad day number */
#define DATE_BMIN -6 /* date had a bad minute number */
#define DATE_BHOUR -7 /* date had a bad hour number */
#define DATE_CONV -8 /* date converted poorly for am/pm/24hr */
extern time_t dateconv P((int, int, int, int, int, int, int, int, int));
extern time_t dayconv P((int, int, time_t));
extern time_t timeconv P((int, int, int, int));
extern time_t monthadd P((time_t, time_t));
extern time_t daylcorr P((time_t, time_t));
extern time_t cm_getdate P((char*, struct timeb *));
#endif

View File

@@ -0,0 +1,594 @@
/*******************************************************************************
**
** getdate.y
**
** $XConsortium: getdate.y /main/3 1995/11/03 10:38:01 rswiston $
**
** RESTRICTED CONFIDENTIAL INFORMATION:
**
** The information in this document is subject to special
** restrictions in a confidential disclosure agreement between
** HP, IBM, Sun, USL, SCO and Univel. Do not distribute this
** document outside HP, IBM, Sun, USL, SCO, or Univel without
** Sun's specific written approval. This document and all copies
** and derivative works thereof must be returned or destroyed at
** Sun's request.
**
** Copyright 1993 Sun Microsystems, Inc. All rights reserved.
**
*******************************************************************************/
/* *
* (c) Copyright 1993, 1994 Hewlett-Packard Company *
* (c) Copyright 1993, 1994 International Business Machines Corp. *
* (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
* (c) Copyright 1993, 1994 Novell, Inc. *
*/
%{
#ifndef lint
static char sccsid[] = "@(#)getdate.y 1.10 94/11/07 Copyr 1993 Sun Microsystems, Inc.";
#endif
%}
%token ID MONTH DAY MERIDIAN NUMBER UNIT MUNIT SUNIT ZONE DAYZONE AGO
%{
/* Steven M. Bellovin (unc!smb) */
/* Dept. of Computer Science */
/* University of North Carolina at Chapel Hill */
/* @(#)getdate.y 2.6 4/20/84 */
#include <EUSCompat.h>
#include <ctype.h>
#include <time.h>
#include "getdate.h"
#ifdef SVR4
#include <sys/time.h>
#endif /* SVR4 */
#ifndef NULL
#define NULL 0
#endif
#define daysec (24L*60L*60L)
static int timeflag, zoneflag, dateflag, dayflag, relflag;
static time_t relsec, relmonth;
static int hh, mm, ss, merid, daylightsavings;
static int dayord, dayreq;
static int month, day, year;
static int noyear;
static int ourzone;
#define AM 1
#define PM 2
#define DAYLIGHT 1
#define STANDARD 2
#define MAYBE 3
extern long timezone;
%}
%%
timedate: /* empty */
| timedate item;
item: tspec =
{timeflag++;}
| zone =
{zoneflag++;}
| dtspec =
{dateflag++;}
| dyspec =
{dayflag++;}
| rspec =
{relflag++;}
| nspec;
nspec: NUMBER =
{if (timeflag && dateflag && !relflag) year = $1;
else {timeflag++;hh = $1/100;mm = $1%100;ss = 0;merid = 24;}};
tspec: NUMBER MERIDIAN =
{hh = $1; mm = 0; ss = 0; merid = $2;}
| NUMBER ':' NUMBER =
{hh = $1; mm = $3; merid = 24;}
| NUMBER ':' NUMBER MERIDIAN =
{hh = $1; mm = $3; merid = $4;}
| NUMBER ':' NUMBER ':' NUMBER =
{hh = $1; mm = $3; ss = $5; merid = 24;}
| NUMBER ':' NUMBER ':' NUMBER MERIDIAN =
{hh = $1; mm = $3; ss = $5; merid = $6;};
zone: ZONE =
{ourzone = $1; daylightsavings = STANDARD;}
| DAYZONE =
{ourzone = $1; daylightsavings = DAYLIGHT;};
dyspec: DAY =
{dayord = 1; dayreq = $1;}
| DAY ',' =
{dayord = 1; dayreq = $1;}
| NUMBER DAY =
{dayord = $1; dayreq = $2;};
dtspec: NUMBER '/' NUMBER =
{month = $1; day = $3; noyear = 1;}
| NUMBER '/' NUMBER '/' NUMBER =
{month = $1; day = $3; year = $5;}
| NUMBER '-' NUMBER =
{month = $1; day = $3; noyear = 1;}
| NUMBER '-' NUMBER '-' NUMBER =
{month = $1; day = $3; year = $5;}
| MONTH NUMBER =
{month = $1; day = $2; noyear = 1;}
| MONTH NUMBER ',' NUMBER =
{month = $1; day = $2; year = $4;}
| NUMBER MONTH =
{month = $2; day = $1; noyear = 1;}
| NUMBER MONTH NUMBER =
{month = $2; day = $1; year = $3;};
rspec: NUMBER UNIT =
{relsec += 60L * $1 * $2;}
| NUMBER MUNIT =
{relmonth += $1 * $2;}
| NUMBER SUNIT =
{relsec += $1;}
| UNIT =
{relsec += 60L * $1;}
| MUNIT =
{relmonth += $1;}
| SUNIT =
{relsec++;}
| rspec AGO =
{relsec = -relsec; relmonth = -relmonth;};
%%
static int mdays[12] =
{31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
#define epoch BOT_YEAR
extern struct tm *localtime();
time_t dateconv(int mm,
int dd,
int yy,
int h,
int m,
int s,
int mer,
int zone,
int dayflag)
{
time_t tod, jdate;
register int i;
if (yy < 0) yy = -yy;
if (yy < 70)
yy += 2000;
else if (yy < 100)
yy += 1900;
mdays[1] = 28 + (yy%4 == 0);
if (yy < epoch)
return(DATE_BBOT);
if (yy > EOT_YEAR)
return(DATE_AEOT);
if (mm < 1 || mm > 12)
return(DATE_BMONTH);
if (dd < 1 || dd > mdays[--mm])
return(DATE_BDAY);
jdate = dd-1;
for (i=0; i<mm; i++) jdate += mdays[i];
for (i = epoch; i < yy; i++) jdate += 365 + (i%4 == 0);
jdate *= daysec;
jdate += zone * 60L;
if ((tod = timeconv(h, m, s, mer)) < 0) return (tod);
jdate += tod;
if (dayflag==DAYLIGHT || (dayflag==MAYBE&&localtime(&jdate)->tm_isdst))
jdate += -1*60*60;
return (jdate);
}
time_t dayconv(int ord, int day, time_t now)
{
register struct tm *loctime;
time_t tod;
tod = now;
loctime = localtime(&tod);
tod += daysec * ((day - loctime->tm_wday + 7) % 7);
tod += 7*daysec*(ord<=0?ord:ord-1);
return daylcorr(tod, now);
}
time_t timeconv(register int hh, int mm, int ss, int mer)
{
if (mm < 0 || mm > 59 || ss < 0 || ss > 59) return (DATE_BMIN);
switch (mer) {
case AM: if (hh < 1 || hh > 12) return(DATE_BHOUR);
return (60L * ((hh%12)*60L + mm)+ss);
case PM: if (hh < 1 || hh > 12) return(DATE_BHOUR);
return (60L * ((hh%12 +12)*60L + mm)+ss);
case 24: if (hh < 0 || hh > 23) return (DATE_BHOUR);
return (60L * (hh*60L + mm)+ss);
default: return (DATE_CONV);
}
}
time_t monthadd(time_t sdate, time_t relmonth)
{
struct tm *ltime;
int mm, yy;
if (relmonth == 0) return 0;
ltime = localtime(&sdate);
mm = 12*ltime->tm_year + ltime->tm_mon + relmonth;
yy = mm/12;
mm = mm%12 + 1;
return daylcorr(dateconv(mm, ltime->tm_mday, yy, ltime->tm_hour,
ltime->tm_min, ltime->tm_sec, 24, ourzone, MAYBE), sdate);
}
time_t daylcorr(time_t future, time_t now)
{
int fdayl, nowdayl;
nowdayl = (localtime(&now)->tm_hour+1) % 24;
fdayl = (localtime(&future)->tm_hour+1) % 24;
return (future-now) + 60L*60L*(nowdayl-fdayl);
}
struct table {
char *name;
int type, value;
};
struct table mdtab[] = {
{"January", MONTH, 1},
{"February", MONTH, 2},
{"March", MONTH, 3},
{"April", MONTH, 4},
{"May", MONTH, 5},
{"June", MONTH, 6},
{"July", MONTH, 7},
{"August", MONTH, 8},
{"September", MONTH, 9},
{"Sept", MONTH, 9},
{"October", MONTH, 10},
{"November", MONTH, 11},
{"December", MONTH, 12},
{"Sunday", DAY, 0},
{"Monday", DAY, 1},
{"Tuesday", DAY, 2},
{"Tues", DAY, 2},
{"Wednesday", DAY, 3},
{"Wednes", DAY, 3},
{"Thursday", DAY, 4},
{"Thur", DAY, 4},
{"Thurs", DAY, 4},
{"Friday", DAY, 5},
{"Saturday", DAY, 6},
{0, 0, 0}};
#define HRS *60
#define HALFHR 30
struct table mztab[] = {
{"a.m.", MERIDIAN, AM},
{"am", MERIDIAN, AM},
{"p.m.", MERIDIAN, PM},
{"pm", MERIDIAN, PM},
{"nst", ZONE, 3 HRS + HALFHR}, /* Newfoundland */
{"n.s.t.", ZONE, 3 HRS + HALFHR},
{"ast", ZONE, 4 HRS}, /* Atlantic */
{"a.s.t.", ZONE, 4 HRS},
{"adt", DAYZONE, 4 HRS},
{"a.d.t.", DAYZONE, 4 HRS},
{"est", ZONE, 5 HRS}, /* Eastern */
{"e.s.t.", ZONE, 5 HRS},
{"edt", DAYZONE, 5 HRS},
{"e.d.t.", DAYZONE, 5 HRS},
{"cst", ZONE, 6 HRS}, /* Central */
{"c.s.t.", ZONE, 6 HRS},
{"cdt", DAYZONE, 6 HRS},
{"c.d.t.", DAYZONE, 6 HRS},
{"mst", ZONE, 7 HRS}, /* Mountain */
{"m.s.t.", ZONE, 7 HRS},
{"mdt", DAYZONE, 7 HRS},
{"m.d.t.", DAYZONE, 7 HRS},
{"pst", ZONE, 8 HRS}, /* Pacific */
{"p.s.t.", ZONE, 8 HRS},
{"pdt", DAYZONE, 8 HRS},
{"p.d.t.", DAYZONE, 8 HRS},
{"yst", ZONE, 9 HRS}, /* Yukon */
{"y.s.t.", ZONE, 9 HRS},
{"ydt", DAYZONE, 9 HRS},
{"y.d.t.", DAYZONE, 9 HRS},
{"hst", ZONE, 10 HRS}, /* Hawaii */
{"h.s.t.", ZONE, 10 HRS},
{"hdt", DAYZONE, 10 HRS},
{"h.d.t.", DAYZONE, 10 HRS},
{"bst", ZONE, 11 HRS}, /* Bering */
{"b.s.t.", ZONE, 11 HRS},
{"bdt", DAYZONE, 11 HRS},
{"b.d.t.", DAYZONE, 11 HRS},
{"gmt", ZONE, 0 HRS},
{"g.m.t.", ZONE, 0 HRS},
{"aest", ZONE, -10 HRS}, /* Australian Eastern Time */
{"a.e.s.t.", ZONE, -10 HRS},
{"aesst", DAYZONE, -10 HRS}, /* Australian Eastern Summer Time */
{"a.e.s.s.t.", DAYZONE, -10 HRS},
{"acst", ZONE, -(9 HRS + HALFHR)}, /* Australian Central Time */
{"a.c.s.t.", ZONE, -(9 HRS + HALFHR)},
{"acsst", DAYZONE, -(9 HRS + HALFHR)}, /* Australian Central Summer */
{"a.c.s.s.t.", DAYZONE, -(9 HRS + HALFHR)},
{"awst", ZONE, -8 HRS}, /* Australian Western Time */
{"a.w.s.t.", ZONE, -8 HRS}, /* (no daylightsavings time there, I'm told */
{0, 0, 0}};
struct table unittb[] = {
{"year", MUNIT, 12},
{"month", MUNIT, 1},
{"fortnight", UNIT, 14*24*60},
{"week", UNIT, 7*24*60},
{"day", UNIT, 1*24*60},
{"hour", UNIT, 60},
{"minute", UNIT, 1},
{"min", UNIT, 1},
{"second", SUNIT, 1},
{"sec", SUNIT, 1},
{0, 0, 0}};
struct table othertb[] = {
{"tomorrow", UNIT, 1*24*60},
{"yesterday", UNIT, -1*24*60},
{"today", UNIT, 0},
{"now", UNIT, 0},
{"last", NUMBER, -1},
{"this", UNIT, 0},
{"next", NUMBER, 2},
{"first", NUMBER, 1},
/* {"second", NUMBER, 2}, */
{"third", NUMBER, 3},
{"fourth", NUMBER, 4},
{"fifth", NUMBER, 5},
{"sixth", NUMBER, 6},
{"seventh", NUMBER, 7},
{"eighth", NUMBER, 8},
{"ninth", NUMBER, 9},
{"tenth", NUMBER, 10},
{"eleventh", NUMBER, 11},
{"twelfth", NUMBER, 12},
{"ago", AGO, 1},
{0, 0, 0}};
struct table milzone[] = {
{"a", ZONE, 1 HRS},
{"b", ZONE, 2 HRS},
{"c", ZONE, 3 HRS},
{"d", ZONE, 4 HRS},
{"e", ZONE, 5 HRS},
{"f", ZONE, 6 HRS},
{"g", ZONE, 7 HRS},
{"h", ZONE, 8 HRS},
{"i", ZONE, 9 HRS},
{"k", ZONE, 10 HRS},
{"l", ZONE, 11 HRS},
{"m", ZONE, 12 HRS},
{"n", ZONE, -1 HRS},
{"o", ZONE, -2 HRS},
{"p", ZONE, -3 HRS},
{"q", ZONE, -4 HRS},
{"r", ZONE, -5 HRS},
{"s", ZONE, -6 HRS},
{"t", ZONE, -7 HRS},
{"u", ZONE, -8 HRS},
{"v", ZONE, -9 HRS},
{"w", ZONE, -10 HRS},
{"x", ZONE, -11 HRS},
{"y", ZONE, -12 HRS},
{"z", ZONE, 0 HRS},
{0, 0, 0}};
static int
lookup(char *id)
{
#define gotit (yylval=i->value, i->type)
#define getid for(j=idvar, k=id; *j++ = *k++; )
char idvar[20];
register char *j, *k;
register struct table *i;
int abbrev;
getid;
if (strlen(idvar) == 3) abbrev = 1;
else if (strlen(idvar) == 4 && idvar[3] == '.') {
abbrev = 1;
idvar[3] = '\0';
}
else abbrev = 0;
if (islower(*idvar)) *idvar = toupper(*idvar);
for (i = mdtab; i->name; i++) {
k = idvar;
for (j = i->name; *j++ == *k++;) {
if (abbrev && j==i->name+3) return gotit;
if (j[-1] == 0) return gotit;
}
}
getid;
for (i = mztab; i->name; i++)
if (strcmp(i->name, idvar) == 0) return gotit;
for (j = idvar; *j; j++) if (isupper(*j)) *j = tolower(*j);
for (i=mztab; i->name; i++)
if (strcmp(i->name, idvar) == 0) return gotit;
getid;
for (i=unittb; i->name; i++)
if (strcmp(i->name, idvar) == 0) return gotit;
if (idvar[strlen(idvar)-1] == 's') idvar[strlen(idvar)-1] = '\0';
for (i=unittb; i->name; i++)
if (strcmp(i->name, idvar) == 0) return gotit;
getid;
for (i = othertb; i->name; i++)
if (strcmp(i->name, idvar) == 0) return gotit;
getid;
if (strlen(idvar) == 1 && isalpha(*idvar)) {
if (isupper(*idvar)) *idvar = tolower(*idvar);
for (i = milzone; i->name; i++)
if (strcmp(i->name, idvar) == 0) return gotit;
}
return(ID);
}
static char *lptr;
yylex()
{
#if defined(__osf__)
extern long yylval;
#else /* __osf__ */
extern int yylval;
#endif /* __osf__ */
int sign;
register char c;
register char *p;
char idbuf[20];
int pcnt;
for (;;) {
while (isspace(*lptr)) lptr++;
if (isdigit(c = *lptr) || c == '-' || c == '+') {
if (c== '-' || c == '+') {
if (c=='-') sign = -1;
else sign = 1;
if (!isdigit(*++lptr)) {
/* yylval = sign; return (NUMBER); */
return yylex(); /* skip the '-' sign */
}
} else sign = 1;
yylval = 0;
while (isdigit(c = *lptr++)) yylval = 10*yylval + c - '0';
yylval *= sign;
lptr--;
return (NUMBER);
} else if (isalpha(c)) {
p = idbuf;
while (isalpha(c = *lptr++) || c=='.')
*p++ = c;
*p = '\0';
lptr--;
return (lookup(idbuf));
}
else if (c == '(') {
pcnt = 0;
do {
c = *lptr++;
if (c == '\0') return(c);
else if (c == '(') pcnt++;
else if (c == ')') pcnt--;
} while (pcnt > 0);
}
else return (*lptr++);
}
}
time_t cm_getdate(char *p, struct timeb *now)
{
#define mcheck(f) if (f>1) err++
int err;
struct tm *lt=NULL;
time_t sdate, tod;
struct timeb ftz;
lptr = p;
if (now == ((struct timeb *) NULL)) {
now = &ftz;
#ifdef SVR4
tod = time(0);
lt = localtime(&tod);
now->time = lt->tm_sec;
now->timezone = timezone/60;
#else
ftime(&ftz);
#endif /* SVR4 */
}
if (lt == NULL)
lt = localtime(&now->time);
year = lt->tm_year;
month = lt->tm_mon+1;
day = lt->tm_mday;
relsec = 0; relmonth = 0;
timeflag=zoneflag=dateflag=dayflag=relflag=0;
ourzone = now->timezone;
daylightsavings = MAYBE;
hh = mm = ss = 0;
merid = 24;
if (err = yyparse()) return (-1);
mcheck(timeflag);
mcheck(zoneflag);
mcheck(dateflag);
mcheck(dayflag);
if (err) return (-1);
/* Relflag also needs to set the sdate variable */
/* This fixes QAR 28447 */
if (dateflag || timeflag || dayflag || relflag) {
sdate = dateconv(month, day, year, hh, mm, ss, merid, ourzone,
daylightsavings);
if (sdate < 0) return(sdate);
/*
if more than 6 months ago, then probably means
next year
if (noyear && sdate < now->time - daysec*(365/2)) {
year++;
sdate = dateconv(month, day, year, hh, mm, ss,
merid, ourzone, daylightsavings);
} */
}
else {
sdate = now->time;
if (relflag == 0)
sdate -= (lt->tm_sec + lt->tm_min*60 +
lt->tm_hour*(60L*60L));
}
sdate += relsec;
sdate += monthadd(sdate, relmonth);
if (dayflag && !dateflag) {
tod = dayconv(dayord, dayreq, sdate);
sdate += tod;
}
return sdate;
}
yyerror(s) char *s;
{}

View File

@@ -0,0 +1,19 @@
$ $TOG: libdtcm.msg /main/1 1998/08/11 10:47:32 devobj $
$quote "
$set 1
$ Message 1 is used to set the date string format
$ "0" == mm/dd/yy US
$ "1" == dd/mm/yy European
$ "2" == yy/mm/dd Japanese
$ NOTE: DO NOT TRANSLATE
1 "0"
$ Message 2 is used to set the time string format
$ "0" == 12 hour clock US
$ "1" == 24 hour clock European, Japanese
$ NOTE: DO NOT TRANSLATE
2 "0"

View File

@@ -0,0 +1,446 @@
/*******************************************************************************
**
** props.c
**
** $TOG: props.c /main/7 1998/08/11 16:33:35 mgreess $
**
** RESTRICTED CONFIDENTIAL INFORMATION:
**
** The information in this document is subject to special
** restrictions in a confidential disclosure agreement between
** HP, IBM, Sun, USL, SCO and Univel. Do not distribute this
** document outside HP, IBM, Sun, USL, SCO, or Univel without
** Sun's specific written approval. This document and all copies
** and derivative works thereof must be returned or destroyed at
** Sun's request.
**
** Copyright 1993 Sun Microsystems, Inc. All rights reserved.
**
*******************************************************************************/
/* *
* (c) Copyright 1993, 1994 Hewlett-Packard Company *
* (c) Copyright 1993, 1994 International Business Machines Corp. *
* (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
* (c) Copyright 1993, 1994 Novell, Inc. *
*/
#ifndef lint
static char sccsid[] = "@(#)props.c 1.13 94/11/07 Copyr 1991 Sun Microsystems, Inc.";
#endif
#include <EUSCompat.h>
#include <sys/param.h>
#include <nl_types.h>
#include <stdio.h>
#include <stdlib.h>
#include "props.h"
#include "util.h"
/*******************************************************************************
**
** Constants
**
*******************************************************************************/
static const char *UPGRADED = "Upgraded";
static const char *CLASS_NAME = "deskset";
static const char *APP_NAME = "calendar";
static const char *RC_FILENAME = "/.cm.rc";
static const char *DS_FILENAME = "/.desksetdefaults";
static const char *OW_FILENAME = "/lib/app-defaults/Deskset";
static const char *X_FILENAME = "/.Xdefaults";
/*
** List of constant strings in ~/.desksetdefaults which we will pay attention
** to ... if you add a member to this array, be sure to add it to the
** enumerated type in props.h
*/
static const char *property_names[] = {
"BegOp",
"BeepOn",
"BeepAdvance",
"BeepUnit",
"FlashOn",
"FlashAdvance",
"FlashUnit",
"OpenOn",
"OpenAdvance",
"OpenUnit",
"MailOn",
"MailAdvance",
"MailUnit",
"MailTo",
"UnixOn",
"UnixAdvance",
"UnixCommand",
"DayBegin",
"DayEnd",
"CalendarList",
"DefaultView",
"DefaultDisplay",
"PrintDest",
"PrintPrivacy",
"PrinterName",
"PrintOptions",
"PrintDirName",
"PrintFileName",
"PrintRMargin",
"PrintBMargin",
"PrintLMargin",
"PrintTMargin",
"PrintLHeader",
"PrintRHeader",
"PrintLFooter",
"PrintRFooter",
"PrintUnit",
"PrintCopies",
"DefaultCal",
"Location",
"DateOrdering",
"DateSeparator",
"Privacy",
"UseFNS",
"ApptBegin",
"ApptDuration",
"EndOp"
};
/*
** List of constant strings containing hard-coded defaults. The program will
** also attempt to read some stuff from the environment if the hard-coded
** default is NULL (example: $PRINTER)
**
** If you add a member to this array, be sure to add it above and to the
** enumerated type in props.h
*/
static const char *def_props[] = {
"\0", /* BegOp */
"True", /* BeepOn */
"5", /* BeepAdvance */
"Mins", /* BeepUnit */
"False", /* FlashOn */
"5", /* FlashAdvance */
"Mins", /* FlashUnit */
"True", /* OpenOn */
"5", /* OpenAdvance */
"Mins", /* OpenUnit */
"False", /* MailOn */
"2", /* MainAdvance */
"Hrs", /* MailUnit */
"\0", /* MailTo */
"False", /* UnixOn */
"0", /* UnixAdvance */
"\0", /* UnixCommand */
"7", /* DayBegin */
"19", /* DayEnd */
"\0", /* CalendarList */
"1", /* DefaultView */
"0", /* DefaultDisplay */
"0", /* PrintDest */
"7", /* PrintPrivacy */
"\0", /* PrinterName */
"\0", /* PrintOptions */
"\0", /* PrintDirName */
"calendar.ps", /* PrintFileName */
"1.00 in", /* PrintRMargin */
"1.00 in", /* PrintBMargin */
"1.00 in", /* PrintLMargin */
"1.00 in", /* PrintTMargin */
"0", /* PrintLHeader - Date */
"1", /* PrintRHeader - User Id */
"2", /* PrintLFooter - Page No */
"3", /* PrintRFooter - Rpt Type */
"1", /* PrintUnit */
"1", /* PrintCopies */
"\0", /* DefaultCal */
"\0", /* CalendarLocation */
"0", /* DateOrdering */
"1", /* DateSeparator */
"Show Time And Text", /* Privacy */
"False", /* UseFNS */
"540", /* ApptBegin */
"60", /* ApptDuration */
"\0" /* EndOp */
};
/*******************************************************************************
**
** Functions static to props.c
**
*******************************************************************************/
static void
p_free_props_entries(Props_entry *e) {
if (!e)
return;
if (e->next)
p_free_props_entries(e->next);
if (e->property_name)
free(e->property_name);
if (e->property_value)
free(e->property_value);
free(e);
}
static Props_entry*
p_get_props_entry(Props *p, Props_op op) {
Props_op idx = CP_BEGOP + 1;
Props_entry *step = p->p_list;
while(step && (idx < op)) {
step = step->next;
++idx;
}
return step;
}
/*******************************************************************************
**
** Functions external to props.c
**
*******************************************************************************/
/*
** Moving .cm.rc properties to .desksetdefaults
*/
extern boolean_t
cal_convert_cmrc(Props *p) {
char *c_ptr, fn[MAXPATHLEN], *val;
Props_op op;
Resource *cm_rdb = NULL;
if (!p->rdb)
return B_FALSE;
if (get_resource(p->rdb, (char *)CLASS_NAME, (char *)APP_NAME,
(char *)UPGRADED, NULL))
return B_TRUE;
/*
** If we're here, the Upgraded resource hasn't been set, so read
** the old .cm.rc file then write it to .desksetdefaults.
*/
if (getenv("HOME") != NULL)
sprintf(fn, "%s%s", getenv("HOME"), RC_FILENAME);
else
return B_TRUE;
if (!load_resources(&cm_rdb, fn))
return B_TRUE;
for (op = CP_BEGOP + 1; op < CP_ENDOP; op++) {
if (!(val = get_resource(cm_rdb, (char *)CLASS_NAME,
(char *)APP_NAME, (char *)property_names[op], NULL)))
continue;
set_resource(&p->rdb, (char *)CLASS_NAME, (char *)APP_NAME,
(char *)property_names[op], val);
}
set_resource(&p->rdb, (char *)CLASS_NAME, (char *)APP_NAME,
(char *)UPGRADED, "True");
save_props(p);
free_resources(cm_rdb);
return B_TRUE;
}
extern char*
get_char_prop(Props *p, Props_op op) {
Props_entry *step = p_get_props_entry(p, op);
if (!step || !step->property_value || step->property_value == '\0')
return get_char_prop_default(op);
return (step->property_value);
}
extern char*
get_char_prop_default(Props_op op) {
char *val, *ptr, *user, *host;
switch(op) {
case CP_MAILTO:
user = (char *)cm_get_uname();
host = (char *)cm_get_local_host();
val = (char *)ckalloc(cm_strlen(user) + cm_strlen(host) + 2);
sprintf(val, "%s@%s", user, host);
break;
case CP_PRINTERNAME:
val = cm_def_printer();
break;
case CP_PRINTDIRNAME:
if (getenv("HOME") != NULL)
val = (char *)cm_strdup(getenv("HOME"));
else
val = (char *)cm_strdup("/");
break;
case CP_DEFAULTCAL:
user = (char *)cm_get_uname();
host = (char *)cm_get_local_host();
val = (char *)ckalloc(cm_strlen(user) + cm_strlen(host) + 2);
sprintf(val, "%s@%s", user, host);
break;
case CP_CALLOC:
val = (char *)cm_strdup(cm_get_local_host());
break;
default:
val = (char *)cm_strdup((char *)def_props[op]);
break;
}
return val;
}
extern int
get_int_prop(Props *p, Props_op op) {
Props_entry *step = p_get_props_entry(p, op);
if (!step || !step->property_value || step->property_value == '\0')
return (atoi(get_char_prop_default(op)));
return (atoi(step->property_value));
}
extern void
props_clean_up(Props *p) {
p_free_props_entries(p->p_list);
free_resources(p->rdb);
}
static void
init_props()
{
#define LIBDTCM_CAT "libdtcm"
static int is_inited = 0;
nl_catd libdtcm_catd;
const char *dflt, *str;
OrderingType ordering;
if (is_inited) return;
is_inited = 1;
libdtcm_catd = catopen(LIBDTCM_CAT, NL_CAT_LOCALE);
if ((nl_catd) -1 == libdtcm_catd) return;
dflt = def_props[CP_DATEORDERING];
str = catgets(libdtcm_catd, 1, 1, dflt);
def_props[CP_DATEORDERING] = strdup(str);
dflt = def_props[CP_DEFAULTDISP];
str = catgets(libdtcm_catd, 1, 2, dflt);
def_props[CP_DEFAULTDISP] = strdup(str);
}
extern boolean_t
read_props(Props *p) {
char *resource, buf[MAXPATHLEN];
char *home, *ow_home, *x_env, *ds_def;
Props_op op;
Resource *other_rdb = NULL;
Props_entry *entry_ptr, *last = NULL;
init_props();
if (getenv("HOME") != NULL)
home = getenv("HOME");
else
home = "/";
ow_home = getenv("OPENWINHOME");
x_env = getenv("XENVIRONMENT");
ds_def = getenv("DESKSETDEFAULTS");
if (p->rdb)
free_resources(p->rdb);
p->rdb = NULL;
if (ds_def)
sprintf(buf, "%s", ds_def);
else
sprintf(buf, "%s%s", home, DS_FILENAME);
load_resources(&p->rdb, buf);
if (ow_home) {
sprintf(buf, "%s%s", ow_home, OW_FILENAME);
load_resources(&other_rdb, buf);
}
if (home) {
sprintf(buf, "%s%s", home, X_FILENAME);
load_resources(&other_rdb, buf);
}
if (x_env) {
sprintf(buf, "%s%s", x_env, X_FILENAME);
load_resources(&other_rdb, buf);
}
p_free_props_entries(p->p_list);
for (op = CP_BEGOP + 1; op < CP_ENDOP; op++) {
entry_ptr = (Props_entry *)ckalloc(sizeof(Props_entry));
entry_ptr->property_name = (char *)
cm_strdup((char *)property_names[op]);
entry_ptr->update = B_FALSE;
if (last)
last->next = entry_ptr;
else
p->p_list = entry_ptr;
entry_ptr->next = NULL;
last = entry_ptr;
resource = (char *)get_resource(p->rdb, (char *)CLASS_NAME,
(char *)APP_NAME, entry_ptr->property_name, NULL);
if (!resource || *resource == '\0')
resource = (char *)get_resource(other_rdb,
(char *)CLASS_NAME, (char *)APP_NAME,
entry_ptr->property_name, NULL);
if (!resource || *resource == '\0')
entry_ptr->property_value = get_char_prop_default(op);
else
entry_ptr->property_value = (char *)cm_strdup(resource);
}
free_resources(other_rdb);
return B_TRUE;
}
extern boolean_t
save_props(Props *p)
{
char buf[MAXPATHLEN], *ds_def = getenv("DESKSETDEFAULTS");
Props_entry *p_ptr = p->p_list;
while(p_ptr) {
if (p_ptr->update && p_ptr->property_value)
set_resource(&p->rdb, (char *)CLASS_NAME,
(char *)APP_NAME, p_ptr->property_name,
p_ptr->property_value);
p_ptr = p_ptr->next;
}
if (ds_def)
sprintf(buf, "%s", ds_def);
else
if (getenv("HOME") != NULL)
sprintf(buf, "%s%s", getenv("HOME"), DS_FILENAME);
else
sprintf(buf, "/%s", DS_FILENAME);
return (save_resources(p->rdb, buf));
}
extern boolean_t
set_char_prop(Props *p, Props_op op, char *value) {
Props_entry *step = p_get_props_entry(p, op);
if (!step)
return B_FALSE;
if (step->property_value)
free(step->property_value);
step->property_value = (char *)cm_strdup(value);
step->update = B_TRUE;
return B_TRUE;
}
extern boolean_t
set_int_prop(Props *p, Props_op op, int value) {
char buf[MAXNAMELEN];
sprintf(buf, "%d", value);
return (set_char_prop(p, op, buf));
}

View File

@@ -0,0 +1,141 @@
/*******************************************************************************
**
** props.h
**
** static char sccsid[] = "@(#)props.h 1.6 94/11/07 Copyr 1991 Sun Microsystems, Inc.";
**
** $XConsortium: props.h /main/5 1996/03/29 17:28:13 rswiston $
**
** RESTRICTED CONFIDENTIAL INFORMATION:
**
** The information in this document is subject to special
** restrictions in a confidential disclosure agreement between
** HP, IBM, Sun, USL, SCO and Univel. Do not distribute this
** document outside HP, IBM, Sun, USL, SCO, or Univel without
** Sun's specific written approval. This document and all copies
** and derivative works thereof must be returned or destroyed at
** Sun's request.
**
** Copyright 1993 Sun Microsystems, Inc. All rights reserved.
**
*******************************************************************************/
/* *
* (c) Copyright 1993, 1994 Hewlett-Packard Company *
* (c) Copyright 1993, 1994 International Business Machines Corp. *
* (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
* (c) Copyright 1993, 1994 Novell, Inc. *
*/
#ifndef _PROPS_H
#define _PROPS_H
#include <sys/types.h>
#include "ansi_c.h"
#include "resource.h"
/*******************************************************************************
**
** Typedefs and supporting structures
**
*******************************************************************************/
typedef enum {
HOUR12,
HOUR24
} DisplayType;
typedef enum {
YEAR_VIEW,
MONTH_VIEW,
WEEK_VIEW,
DAY_VIEW
} ViewType;
typedef struct props_entry {
char *property_name;
char *property_value;
boolean_t update;
struct props_entry *next;
} Props_entry;
/*
** Enumerated type to access properties array. If you add a member to this
** enumeration, be sure to add it's value to the character array in props.c
*/
typedef enum {
CP_BEGOP, /* Don't put anything before this */
CP_BEEPON,
CP_BEEPADV,
CP_BEEPUNIT,
CP_FLASHON,
CP_FLASHADV,
CP_FLASHUNIT,
CP_OPENON,
CP_OPENADV,
CP_OPENUNIT,
CP_MAILON,
CP_MAILADV,
CP_MAILUNIT,
CP_MAILTO,
CP_UNIXON,
CP_UNIXADV,
CP_UNIXCOMMAND,
CP_DAYBEGIN,
CP_DAYEND,
CP_DAYCALLIST,
CP_DEFAULTVIEW,
CP_DEFAULTDISP,
CP_PRINTDEST,
CP_PRINTPRIVACY,
CP_PRINTERNAME,
CP_PRINTOPTIONS,
CP_PRINTDIRNAME,
CP_PRINTFILENAME,
CP_PRINTRMARGIN,
CP_PRINTBMARGIN,
CP_PRINTLMARGIN,
CP_PRINTTMARGIN,
CP_PRINTLHEADER,
CP_PRINTRHEADER,
CP_PRINTLFOOTER,
CP_PRINTRFOOTER,
CP_PRINTMONTHS,
CP_PRINTCOPIES,
CP_DEFAULTCAL,
CP_CALLOC,
CP_DATEORDERING,
CP_DATESEPARATOR,
CP_PRIVACY,
CP_USEFNS,
CP_APPTBEGIN,
CP_APPTDURATION,
CP_ENDOP /* Don't put anything after this */
} Props_op;
/*******************************************************************************
**
** The not-so-mighty props structure is simply an X resource database and the
** array of Props_entry's which contain the property information.
**
*******************************************************************************/
typedef struct {
Props_entry *p_list;
Resource *rdb;
} Props;
/*******************************************************************************
**
** External function declarations
**
*******************************************************************************/
extern boolean_t cal_convert_cmrc P((Props*));
extern char *get_char_prop P((Props*, Props_op));
extern char *get_char_prop_default P((Props_op));
extern int get_int_prop P((Props*, Props_op));
extern void props_clean_up P((Props*));
extern boolean_t read_props P((Props*));
extern boolean_t save_props P((Props*));
extern boolean_t set_char_prop P((Props*, Props_op, char*));
extern boolean_t set_int_prop P((Props*, Props_op, int));
#endif

View File

@@ -0,0 +1,258 @@
/*******************************************************************************
**
** resource.c
**
** $XConsortium: resource.c /main/3 1995/11/03 10:38:34 rswiston $
**
** RESTRICTED CONFIDENTIAL INFORMATION:
**
** The information in this document is subject to special
** restrictions in a confidential disclosure agreement between
** HP, IBM, Sun, USL, SCO and Univel. Do not distribute this
** document outside HP, IBM, Sun, USL, SCO, or Univel without
** Sun's specific written approval. This document and all copies
** and derivative works thereof must be returned or destroyed at
** Sun's request.
**
** Copyright 1993 Sun Microsystems, Inc. All rights reserved.
**
*******************************************************************************/
/* *
* (c) Copyright 1993, 1994 Hewlett-Packard Company *
* (c) Copyright 1993, 1994 International Business Machines Corp. *
* (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
* (c) Copyright 1993, 1994 Novell, Inc. *
*/
#ifndef lint
static char sccsid[] = "@(#)resource.c 1.9 94/11/07 Copyr 1993 Sun Microsystems, Inc.";
#endif
#include <EUSCompat.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/param.h>
#include "resource.h"
#include "util.h"
static const char COMMENT = '#';
static const char CONTINUATION = '\\';
#define MAXPROPLEN MAXNAMELEN * 6
/*
** free_resources will step the list of resources and free the allocated space
*/
extern void
free_resources(Resource *r) {
if (r) {
free_resources(r->next);
if (r->resource_name)
free(r->resource_name);
if (r->resource_value)
free(r->resource_value);
free(r);
}
}
/*
**
** get_resource will scan the list of resources for the resource
** class.application.name (example: deskset.calendar.start_time) passed and
** return that resource's value if found, otherwise, it will return the
** passed default.
**
*/
extern char*
get_resource(Resource *r, char *class_name, char *app_name, char *name,
char *default_value)
{
char *buf, *ret;
buf = (char *)ckalloc(cm_strlen(class_name) + cm_strlen(app_name)
+ cm_strlen(name) + 3);
sprintf(buf, "%s.%s.%s", class_name, app_name, name);
ret = get_resource_by_val(r, buf, default_value);
free(buf);
return ret;
}
/*
** Same as get_resource except it just takes the entire resource name instead
** of the class.application.name triplet.
*/
extern char*
get_resource_by_val(Resource *r, char *name, char *default_value) {
Resource *step = r;
while(step && strcasecmp(step->resource_name, name) != 0)
step = step->next;
if (!step)
return default_value;
return step->resource_value;
}
/*
** Given a file name, read the list of resources in that file into the
** passed Resource instance pointer.
*/
extern boolean_t
load_resources(Resource **r, char *file_name) {
int idx;
char *c_ptr, buffer[MAXPROPLEN], value[MAXPROPLEN];
FILE *rc_file;
boolean_t scan_complete, end_of_file = B_FALSE;
Resource *last = *r, *new_resource;
if (!(rc_file = fopen(file_name, "r")))
return B_FALSE;
while(last && last->next)
last = last->next;
while (!end_of_file && fgets(buffer, MAXPROPLEN-1, rc_file)) {
if (!(c_ptr = strchr(buffer, ':')))
continue;
/*
** Add the new property to the list
*/
*c_ptr = '\0';
new_resource = (Resource *)ckalloc(sizeof(Resource));
new_resource->resource_name = (char *)cm_strdup(buffer);
new_resource->resource_value = NULL;
new_resource->next = NULL;
if (last)
last->next = new_resource;
else
*r = new_resource;
last = new_resource;
/*
** Initialize and read the property value
*/
idx = 0;
scan_complete = B_FALSE;
memset(value, '\0', MAXPROPLEN);
c_ptr++;
while (!scan_complete) {
/*
** For the current buffer, skip the beginning white
** space
*/
while (*c_ptr != '\0' && *c_ptr != '\n'
&& (*c_ptr == ' ' || *c_ptr == '\t'))
c_ptr++;
if (*c_ptr == '\0' || *c_ptr == '\n') {
scan_complete = B_TRUE;
continue;
}
/*
** We've found a real character, save characters until
** we find a comment, continuation, end of line, or we
** run out of space.
*/
while (*c_ptr != '\0' && *c_ptr != '\n' &&
(idx < MAXPROPLEN - 2) && *c_ptr != COMMENT &&
*c_ptr != CONTINUATION)
value[idx++] = *c_ptr++;
/*
** Anything but continuation, cork value and bail
*/
if (*c_ptr != CONTINUATION) {
value[idx] = '\0';
scan_complete = B_TRUE;
continue;
}
/*
** A continued line. Providing we can read another
** line from the file, reset the buffer, insert a
** space, and continue the loop ...
*/
if (!fgets(buffer, MAXPROPLEN, rc_file)) {
value[idx] = '\0';
end_of_file = scan_complete = B_TRUE;
continue;
}
value[idx++] = ' ';
c_ptr = buffer;
}
new_resource->resource_value = (char *)cm_strdup(value);
}
fclose(rc_file);
return B_TRUE;
}
/*
** This function will write the resources to disk
*/
extern boolean_t
save_resources(Resource *r, char *file_name) {
char buf[MAXPROPLEN + 3];
FILE *rc_file;
Resource *step = r;
if (!(rc_file = fopen(file_name, "w")))
return B_FALSE;
while(step) {
sprintf(buf, "%s:\t%s\n",
step->resource_name, step->resource_value);
fputs(buf, rc_file);
step = step->next;
}
fclose(rc_file);
return B_TRUE;
}
/*
** This set's the value for a specified resource
*/
extern boolean_t
set_resource(Resource **r, char *class_name, char *app_name, char *name,
char *value)
{
boolean_t ret;
char *buf;
buf = (char *)ckalloc(cm_strlen(class_name) + cm_strlen(app_name)
+ cm_strlen(name) + 3);
sprintf(buf, "%s.%s.%s", class_name, app_name, name);
ret = set_resource_by_val(r, buf, value);
free(buf);
return ret;
}
/*
** As as set_resource except the name passed in the full name
*/
extern boolean_t
set_resource_by_val(Resource **r, char *name, char *value) {
Resource *step, *last;
last = step = *r;
while(step && strcasecmp(step->resource_name, name) != 0)
step = step->next;
if (step)
free(step->resource_value);
else {
step = (Resource *)ckalloc(sizeof(Resource));
step->resource_name = (char *)cm_strdup(name);
step->next = NULL;
while(last && last->next)
last = last->next;
if (last)
last->next = step;
else
*r = step;
}
step->resource_value = (char *)cm_strdup(value);
return B_TRUE;
}

View File

@@ -0,0 +1,59 @@
/*******************************************************************************
**
** resource.h
**
** static char sccsid[] = "@(#)resource.h 1.5 94/11/07 Copyr 1991 Sun Microsystems, Inc.";
**
** $XConsortium: resource.h /main/3 1995/11/03 10:38:43 rswiston $
**
** RESTRICTED CONFIDENTIAL INFORMATION:
**
** The information in this document is subject to special
** restrictions in a confidential disclosure agreement between
** HP, IBM, Sun, USL, SCO and Univel. Do not distribute this
** document outside HP, IBM, Sun, USL, SCO, or Univel without
** Sun's specific written approval. This document and all copies
** and derivative works thereof must be returned or destroyed at
** Sun's request.
**
** Copyright 1993 Sun Microsystems, Inc. All rights reserved.
**
*******************************************************************************/
/* *
* (c) Copyright 1993, 1994 Hewlett-Packard Company *
* (c) Copyright 1993, 1994 International Business Machines Corp. *
* (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
* (c) Copyright 1993, 1994 Novell, Inc. *
*/
#ifndef _RESOURCE_H
#define _RESOURCE_H
#include "ansi_c.h"
#include <sys/types.h>
/*
** Resource structure
*/
struct Resource {
char *resource_name;
char *resource_value;
struct Resource *next;
};
typedef struct Resource Resource;
/*
** Function declarations
*/
extern void free_resources P((Resource*));
extern char *get_resource P((Resource*, char *, char*,
char*, char*));
extern char *get_resource_by_val P((Resource*, char*, char*));
extern boolean_t load_resources P((Resource**, char*));
extern boolean_t save_resources P((Resource*, char*));
extern boolean_t set_resource P((Resource**, char*, char*,
char*, char*));
extern boolean_t set_resource_by_val P((Resource**, char*, char*));
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,129 @@
/*******************************************************************************
**
** timeops.h
**
** static char sccsid[] = "@(#)timeops.h 1.10 94/11/07 Copyr 1991 Sun Microsystems, Inc.";
**
** $XConsortium: timeops.h /main/3 1995/11/03 10:39:02 rswiston $
**
** RESTRICTED CONFIDENTIAL INFORMATION:
**
** The information in this document is subject to special
** restrictions in a confidential disclosure agreement between
** HP, IBM, Sun, USL, SCO and Univel. Do not distribute this
** document outside HP, IBM, Sun, USL, SCO, or Univel without
** Sun's specific written approval. This document and all copies
** and derivative works thereof must be returned or destroyed at
** Sun's request.
**
** Copyright 1993 Sun Microsystems, Inc. All rights reserved.
**
*******************************************************************************/
/* *
* (c) Copyright 1993, 1994 Hewlett-Packard Company *
* (c) Copyright 1993, 1994 International Business Machines Corp. *
* (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
* (c) Copyright 1993, 1994 Novell, Inc. *
*/
#ifndef _TIMEOPS_H
#define _TIMEOPS_H
#include <EUSCompat.h>
#include "ansi_c.h"
typedef enum {
minsec = 60,
fivemins = 300,
hrsec = 3600,
daysec = 86400,
wksec = 604800,
yrsec = 31536000,
leapyrsec = 31622400
} Unit;
/* use time_t typedef for Tick, not a hardcoded long */
typedef time_t Tick; /* tick = seconds since epoch */
extern Tick bot; /* beginning of time */
extern char *days[];
extern char *days2[];
extern char *days3[];
extern char *days4[];
extern Tick eot; /* end of time */
extern char *hours[];
extern int monthdays[];
extern char *months[];
extern char *months2[];
extern int monthsecs[];
extern char *numbers[];
extern int days_to_seconds P((int));
extern int dom P((Tick));
extern int dow P((Tick));
extern int fdom P((Tick));
extern Tick first_dom P((Tick));
extern Tick first_dow P((Tick));
extern Tick get_eot P(());
extern Tick get_bot P(());
extern long gmt_off P(());
extern int hour P((Tick));
extern int hours_to_seconds P((int));
extern void init_time P(());
extern Tick jan1 P((Tick));
extern Tick last_dom P((Tick));
extern Tick last_dow P((Tick));
extern Tick last_ndays P((Tick t, int));
extern int lastapptofweek P((u_int));
extern Tick lastjan1 P((Tick));
extern int ldom P((Tick));
extern Tick lower_bound P((int, Tick));
extern Tick lowerbound P((Tick));
extern boolean_t magic_time P((Tick t));
extern Tick midnight P(());
extern int minutes_to_seconds P((int));
extern int minute P((Tick));
extern int month P((Tick));
extern Tick monthdayyear P((int, int, int));
extern int monthlength P((Tick));
extern Tick next_ndays P((Tick, int));
extern Tick next_nhours P((Tick, int));
extern Tick next2weeks P((Tick));
extern Tick nextday P((Tick));
extern Tick nextjan1 P((Tick));
extern Tick nextmonth P((Tick t));
extern Tick next_nmonth P((Tick t, int n));
extern Tick nextmonth_exactday P((Tick t));
extern Tick nextweek P((Tick t));
extern Tick nextyear P((Tick));
extern Tick nextnyear P((Tick t, int n));
extern Tick now P(());
extern int ntimes_this_week P((u_int, int));
extern int numwks P((Tick));
extern Tick prev_nmonth P((Tick t, int n));
extern Tick prevmonth_exactday P((Tick));
extern Tick previousmonth P((Tick t));
extern Tick prevweek P((Tick t));
extern Tick prev2weeks P((Tick t));
extern Tick prevnyear P((Tick t, int n));
extern int seconds P((int n, Unit unit));
extern double seconds_dble P((double n, Unit unit));
extern int seconds_to_days P((int));
extern int seconds_to_hours P((int));
extern int seconds_to_minutes P((int));
extern int seconds_to_weeks P((int));
extern void set_timezone P((char*));
extern int timeok P((Tick t));
extern Tick upperbound P((Tick));
extern int weeks_to_seconds P((int));
extern int wom P((Tick));
extern boolean_t weekofmonth P((Tick, int*));
extern Tick xytoclock P((int, int, Tick));
extern int year P((Tick));
extern int adjust_dst P((Tick, Tick));
extern boolean_t adjust_hour P((int*));
extern int leapyr P((int));
extern Tick prevday P((Tick));
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,292 @@
/*******************************************************************************
**
** util.h
**
** static char sccsid[] = "@(#)util.h 1.38 94/12/20 Copyr 1991 Sun Microsystems, Inc.";
**
** $XConsortium: util.h /main/5 1995/11/03 10:39:22 rswiston $
**
** RESTRICTED CONFIDENTIAL INFORMATION:
**
** The information in this document is subject to special
** restrictions in a confidential disclosure agreement between
** HP, IBM, Sun, USL, SCO and Univel. Do not distribute this
** document outside HP, IBM, Sun, USL, SCO, or Univel without
** Sun's specific written approval. This document and all copies
** and derivative works thereof must be returned or destroyed at
** Sun's request.
**
** Copyright 1993 Sun Microsystems, Inc. All rights reserved.
**
*******************************************************************************/
/* *
* (c) Copyright 1993, 1994 Hewlett-Packard Company *
* (c) Copyright 1993, 1994 International Business Machines Corp. *
* (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
* (c) Copyright 1993, 1994 Novell, Inc. *
*/
#ifndef _UTIL_H
#define _UTIL_H
#include <sys/types.h>
#include <X11/Xlib.h>
#include <csa.h>
#include "ansi_c.h"
#include "timeops.h"
#include "props.h"
#define DATAVER1 1 /* RPC versions 1 & 2 */
#define DATAVER2 2 /* RPC version 3 */
#define DATAVER3 3 /* RPC version 4 and RPC version 5 with
old file store */
#define DATAVER4 4 /* RPC version 5 with new data store */
#define DATAVER_ARCHIVE -1 /* archive version. Nothing is read_only */
#define MAXSTRING 80
#define CERROR 1
#define PWERROR 2
#define FILEERROR 3
#define SPACEERROR 4
#define DOTS(a) (a[0]=='.' && (a[1]==0 || (a[1]=='.' && a[2]==0)))
typedef struct lines {
char *s;
struct lines *next;
} Lines;
typedef enum {appt_read, appt_write} Allocation_reason;
/*
** Structure for list of properties
*/
typedef struct Pentry {
char *property_name;
char *property_value;
struct Pentry *next;
} Pentry;
typedef enum {
ORDER_MDY,
ORDER_DMY,
ORDER_YMD
} OrderingType;
typedef enum {
SEPARATOR_BLANK,
SEPARATOR_SLASH,
SEPARATOR_DOT,
SEPARATOR_DASH
} SeparatorType;
/*
* This convenience structure is used by the utility functions to set pointers
* to the actual data array so hard coding indexes into the array elsewhere
* in the front end isn't necessary.
*/
typedef struct {
/*
* Read-only attributes
*/
CSA_attribute *identifier;
CSA_attribute *modified_time;
CSA_attribute *author;
CSA_attribute *number_recurrence;
/*
* Read-write attributes
*/
CSA_attribute *time;
CSA_attribute *type;
CSA_attribute *subtype;
CSA_attribute *private;
CSA_attribute *end_time;
CSA_attribute *show_time;
CSA_attribute *what;
CSA_attribute *state;
CSA_attribute *repeat_type;
CSA_attribute *repeat_times;
CSA_attribute *repeat_interval;
CSA_attribute *repeat_week_num;
CSA_attribute *recurrence_rule;
CSA_attribute *beep;
CSA_attribute *flash;
CSA_attribute *mail;
CSA_attribute *popup;
CSA_attribute *sequence_end_date;
/*
* The actual name array and count
*/
CSA_attribute_reference *names;
int num_names;
/*
* The actual data array and count
*/
CSA_attribute *attrs;
CSA_uint32 count;
/* Whether the structure has been filled in with a query */
int filled;
Allocation_reason reason;
/* the version of the back end this appointment structure
was intended for */
int version;
} Dtcm_appointment;
/*
* This convenience structure is used by the entry_to_cal, attrs_to_cal, and
* cal_to_attrs utility functions
*/
typedef struct {
/*
* Read-only attributes
*/
CSA_attribute *cal_name;
CSA_attribute *server_version;
CSA_attribute *num_entries;
CSA_attribute *cal_size;
/*
* Read-write attributes
*/
CSA_attribute *access_list;
CSA_attribute *time_zone;
/*
* The actual name array and count
*/
CSA_attribute_reference *names;
int num_names;
/*
* The actual data array and count
*/
CSA_attribute *attrs;
CSA_uint32 count;
/* Whether the structure has been filled in with a query */
int filled;
Allocation_reason reason;
/* the version of the back end this calendar structure
was intended for */
int version;
} Dtcm_calendar;
/*
* Utility functions to to provide pointers into the arrays passed back and
* forth to the backend. These functions and structures make hard coding
* indexes into the arrays unnecessary.
*/
extern Dtcm_appointment *allocate_appt_struct P((Allocation_reason , int, ...));
extern CSA_return_code query_appt_struct P((CSA_session_handle,
CSA_entry_handle,
Dtcm_appointment *));
extern Dtcm_calendar *allocate_cal_struct P((Allocation_reason, int, ...));
extern CSA_return_code query_cal_struct P((CSA_session_handle,
Dtcm_calendar *));
extern void free_appt_struct P((Dtcm_appointment**));
extern void free_cal_struct P((Dtcm_calendar**));
extern boolean_t cal_ident_index_ro P((int, int));
extern boolean_t entry_ident_index_ro P((int, int));
extern CSA_enum cal_ident_index_tag P((int));
extern CSA_enum entry_ident_index_tag P((int));
extern boolean_t ident_name_ro P((char*, int));
extern void initialize_cal_attr P((int, CSA_attribute*,
Allocation_reason, int));
extern void initialize_entry_attr P((int, CSA_attribute*,
Allocation_reason, int));
extern void set_appt_links P((Dtcm_appointment*));
extern void set_cal_links P((Dtcm_calendar*));
extern void scrub_cal_attr_list P((Dtcm_calendar*));
extern void setup_range P((CSA_attribute**,
CSA_enum**, int*, time_t,
time_t, CSA_sint32, CSA_sint32,
boolean_t, int));
extern void free_range P((CSA_attribute**,
CSA_enum**, int));
/*
* Other utilty functions
*/
extern int blank_buf P((char*));
extern int embedded_blank P((char*));
extern char *ckalloc P(());
extern char *cm_def_printer P(());
extern char *cm_get_credentials P(());
extern char *cm_get_local_domain P(());
extern char *cm_get_local_host P(());
extern char *cm_get_uname P(());
extern char *cm_pqtarget P((char*));
extern char *cm_strcat P((char*, char*));
extern char *cm_strcpy P((char*, char*));
extern char *cm_strdup P((char*));
extern int cm_strlen P((char*));
extern char *cm_target2domain P((char*));
extern char *cm_target2host P((char*));
extern char *cm_target2location P((char*));
extern char *cm_target2name P((char*));
extern char *cr_to_str P((char*));
extern void destroy_lines P((Lines*));
extern void expand_esc_chars P((char*));
extern char *get_head P((char*, char));
extern char *get_tail P((char*, char));
extern void print_tick P((time_t));
extern boolean_t same_path P((char*, char*));
extern boolean_t same_user P((char*, char*));
extern char *str_to_cr P((char*));
extern char *strncat P(());
extern char *substr P((char*, int, int n));
extern void syserr P((char*, int, int, int));
extern Lines *text_to_lines P((char*, int));
extern int get_data_version P((CSA_session_handle));
extern int get_server_version P((CSA_session_handle));
extern CSA_sint32 privacy_set P((Dtcm_appointment *));
extern CSA_sint32 showtime_set P((Dtcm_appointment *));
extern int max P((int, int));
extern int min P((int, int));
extern int parse_date P((OrderingType, SeparatorType, char*, char*, char*, char*));
extern int datestr2mdy P((char*, OrderingType, SeparatorType, char*));
extern void format_tick P((time_t, OrderingType, SeparatorType, char*));
extern void format_time P((Tick, DisplayType, char*));
/*
* In Motif you can't associate user data with items in a list. To get around
* this we have the following simple functions that maintain a list of
* user data. We use the intrinscs coding style to reinforce the
* relationship these routines have to the XmList* functions.
*/
typedef struct _CmDataItem {
struct _CmDataItem *next;
void *data;
} CmDataItem;
typedef struct _CmDataList {
CmDataItem *head;
CmDataItem *tail;
int count;
} CmDataList;
extern CmDataList *CmDataListCreate P((void));
extern void CmDataListDestroy P((CmDataList *, int));
extern int CmDataListAdd P((CmDataList *, void *, int));
extern void *CmDataListGetData P((CmDataList *, int));
extern void *CmDataListDeletePos P((CmDataList *, int, int));
extern void CmDataListDeleteAll P((CmDataList *, int));
#endif