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

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,117 @@
/* $TOG: Action.h /main/4 1998/05/06 15:55:18 rafi $ */
/*
* (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 _Dt_Action_h
#define _Dt_Action_h
#include <X11/Intrinsic.h>
#ifdef __cplusplus
extern "C" {
#endif
/*
* Argument types
*/
#define DtACTION_FILE 1 /* file argument */
#define DtACTION_BUFFER 2 /* buffer argument */
#define DtACTION_STRING 3 /* string argument */
#define DtACTION_NULLARG 4 /* untyped return-only argument */
typedef struct {
void *bp; /* location of buffer */
int size; /* size of buffer in bytes */
char *type; /* (opt.) type of buffer */
char *name; /* (opt.) name of buffer object */
Boolean writable; /* allow changes to buffer object? */
} DtActionBuffer;
typedef struct {
char *name;
} DtActionFile;
typedef struct {
/*
* Structure containing argument information
*/
int argClass; /* see argument types */
union {
DtActionFile file;
DtActionBuffer buffer;
} u;
} DtActionArg;
/*
* DtActionStatus codes
*/
typedef enum {
DtACTION_OK, /* If not any of the below */
DtACTION_INVALID_ID, /* ID is not valid */
DtACTION_INVOKED, /* the action invocation step is done */
DtACTION_STATUS_UPDATE, /* status update */
DtACTION_DONE, /* normal action termination code */
DtACTION_FAILED, /* error running action */
DtACTION_CANCELED /* normal action termination by cancel*/
} DtActionStatus;
typedef void (*DtDbReloadCallbackProc)(
XtPointer clientData);
/*
* DtActionInvocationID is the fundamental user-space handle to invoked
* actions.
*/
typedef unsigned long DtActionInvocationID;
typedef void (*DtActionCallbackProc) (
DtActionInvocationID id,
XtPointer client_data,
DtActionArg *actionArgPtr,
int actionArgCount,
DtActionStatus status);
/*
* Functions
*/
extern Boolean DtActionExists(
char *actionName);
extern char * DtActionLabel(
char *actionName);
extern char * DtActionDescription(
char *actionName);
extern void DtDbReloadNotify (
DtDbReloadCallbackProc proc,
XtPointer clientData);
extern void DtDbLoad(void);
extern DtActionInvocationID DtActionInvoke (
Widget w,
char *action,
DtActionArg *args,
int argCount,
char *termOpts,
char *execHost,
char *contextDir,
int useIndicator,
DtActionCallbackProc statusUpdateCb,
XtPointer client_data);
extern char * DtActionIcon(
char *actionName);
#ifdef __cplusplus
}
#endif
#endif /* _Dt_Action_h */

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,219 @@
/*****************************************************************************
*
* File: ActionDb.h
* RCS: $XConsortium: ActionDb.h /main/3 1995/10/26 14:58:38 rswiston $
* Description: Internal header file for the action database functions.
* Language: C
* Package: N/A
* Status: Experimental (Do Not Distribute)
*
*
** (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 _Dt_ActionDb_h
#define _Dt_ActionDb_h
/*
* The following constants are used by the database parsing code to
* identify the field names for an action definition.
*
* Recognized Field names for any action definition.
*/
#define _DtACTION_NAME "ACTION"
#define _DtACTION_TYPE "TYPE"
#define _DtACTION_LABEL "LABEL"
#define _DtACTION_ARG_CLASS "ARG_CLASS"
#define _DtACTION_ARG_MODE "ARG_MODE"
#define _DtACTION_ARG_TYPE "ARG_TYPE"
#define _DtACTION_ARG_COUNT "ARG_COUNT"
#define _DtACTION_DESCRIPTION "DESCRIPTION"
#define _DtACTION_ICON "ICON"
#define _DtACTION_INSTANCE_ICON "INSTANCE_ICON"
/*
* Miscellaneous syntax strings
*/
#define _DtACT_ANY "*"
#define _DtACT_LIST_SEPARATOR_CHAR ','
#define _DtACT_GT_CHAR '>'
#define _DtACT_LT_CHAR '<'
/*
* Valid values for ACTION_TYPE
*/
#define _DtACTION_MAP "MAP"
#define _DtACTION_COMMAND "COMMAND"
#define _DtACTION_TT_MSG "TT_MSG"
#ifdef _DT_ALLOW_DT_MSGS
#define _DtACTION_DT_REQUEST "DT_REQUEST"
#define _DtACTION_DT_NOTIFY "DT_NOTIFY"
#endif /* _DT_ALLOW_DT_MSGS */
/*
* Field names for "MAP" type actions
*/
#define _DtACTION_MAP_ACTION "MAP_ACTION"
/*
* Field names for the "COMMAND" type actions.
*/
#define _DtACTION_EXEC_STRING "EXEC_STRING"
#define _DtACTION_EXEC_HOST "EXEC_HOST"
#define _DtACTION_CWD "CWD"
#define _DtACTION_WINDOW_TYPE "WINDOW_TYPE"
#define _DtACTION_TERM_OPTS "TERM_OPTS"
/*
* Field names for "TT_MSG" type actions
*/
#define _DtACTION_TT_CLASS "TT_CLASS"
#define _DtACTION_TT_SCOPE "TT_SCOPE"
#define _DtACTION_TT_OPERATION "TT_OPERATION"
#define _DtACTION_TT_FILE "TT_FILE"
/* definitions to decifer TT_ARGn_* fields */
#define _DtACTION_TTN_ARG "TT_ARG"
#define _DtACTION_TTN_MODE "_MODE"
#define _DtACTION_TTN_VTYPE "_VTYPE"
#define _DtACTION_TTN_REP_TYPE "_REP_TYPE"
#define _DtACTION_TTN_VALUE "_VALUE"
#ifdef _DT_ALLOW_DT_MSGS
/*
* Field names for "DT_REQUEST" type actions
*/
#define _DtACTION_DT_REQUEST_NAME "DT_REQUEST_NAME"
#define _DtACTION_DT_SVC "DT_SVC"
/*
* Field names for "DT_NOTIFY" type actions
*/
#define _DtACTION_DT_NOTIFY_NAME "DT_NOTIFY_NAME"
#define _DtACTION_DT_NGROUP "DT_NGROUP"
/*
* Field names for DT ARGn (either request or notify)
*/
#define _DtACTION_DTN_ARG "DT_ARG"
#define _DtACTION_DTN_VALUE "_VALUE"
#endif /* _DT_ALLOW_DT_MSGS */
/*
* Valid Field value strings
* for Command Actions Window Types
*/
#define _DtACTION_TERMINAL "TERMINAL"
#define _DtACTION_PERM_TERMINAL "PERM_TERMINAL"
#define _DtACTION_NO_STDIO "NO_STDIO"
/*
* Valid Field values for ARG_CLASS records.
*/
#define _DtACTION_BUFFER "BUFFER"
#define _DtACTION_FILE "FILE"
#define _DtACTION_STRING "STRING"
/*
* Valid Field values for ARG_MODE
*/
#define _DtACT_ARG_MODE_WRITE "w"
#define _DtACT_ARG_MODE_NOWRITE "!w"
#define _DtACT_ARG_MODE_ANY _DtACT_ANY
/*
* Valid Field values for TT_CLASS records.
*/
#define _DtACTION_TT_NOTICE "TT_NOTICE"
#define _DtACTION_TT_REQUEST "TT_REQUEST"
/*
* Valid Field values for TT_SCOPE records.
*/
#define _DtACTION_TT_SESSION "TT_SESSION"
#define _DtACTION_TT_BOTH "TT_BOTH"
#define _DtACTION_TT_FILE_IN_SESSION "TT_FILE_IN_SESSION"
/* --- same as TT_MSG's TT_FILE field name --------
#define _DtACTION_TT_FILE "TT_FILE"
*/
/*
* Valid Field values for TT_ARGn_MODE
*/
#define _DtACTION_TT_MODE_IN "TT_IN"
#define _DtACTION_TT_MODE_OUT "TT_OUT"
#define _DtACTION_TT_MODE_INOUT "TT_INOUT"
/*
* Valid Field values for TT_ARGn_REP_TYPE
*/
#define _DtACTION_TT_RTYP_UND "TT_REP_UNDEFINED"
#define _DtACTION_TT_RTYP_INT "TT_REP_INTEGER"
#define _DtACTION_TT_RTYP_BUF "TT_REP_BUFFER"
#define _DtACTION_TT_RTYP_STR "TT_REP_STRING"
/*
* Action Keywords --
* these keywords appear in the action database files
* in the form: %<qualifier><keyword><prompt string>%
* where the optional qualifier in enclosed in: ()
* and the optional prompt string is enclosed in: ""
*/
#define _DtACT_DATABASEHOST_STR "DatabaseHost"
#define _DtACT_DISPLAYHOST_STR "DisplayHost"
#define _DtACT_LOCALHOST_STR "LocalHost"
#define _DtACT_SESSIONHOST_STR "SessionHost"
#define _DtACT_ARGS_STR "Args"
#define _DtACT_ARG_UNDER_STR "Arg_"
#define _DtACT_STRING_QUALIFIER "(String)"
#define _DtACT_FILE_QUALIFIER "(File)"
/*
* Default action field value definitions (these should be strings)
* for recognized fields.
*/
#define _DtACT_LBL_DFLT NULL
#define _DtACT_TYPE_DFLT _DtACTION_COMMAND
#define _DtACT_ARG_CLASS_DFLT _DtACT_ANY
#define _DtACT_ARG_MODE_DFLT _DtACT_ANY
#define _DtACT_ARG_TYPE_DFLT _DtACT_ANY
#define _DtACT_ARG_CNT_DFLT _DtACT_ANY
#define _DtACT_DESC_DFLT NULL
#define _DtACT_ICON_DFLT NULL
#define _DtACT_MAP_ACT_DFLT NULL
#define _DtACT_EXEC_STRG_DFLT NULL
#define _DtACT_EXEC_HOST_DFLT \
"%" _DtACT_DATABASEHOST_STR "%,%" _DtACT_LOCALHOST_STR "%"
#define _DtACT_CWD_DFLT NULL
#define _DtACT_WIN_TYPE_DFLT _DtACTION_PERM_TERMINAL
#define _DtACT_TERM_OPTS_DFLT NULL
#define _DtACT_TT_CLASS_DFLT NULL
#define _DtACT_TT_SCOPE_DFLT NULL
#define _DtACT_TT_OP_DFLT NULL
#define _DtACT_TT_FILE_DFLT NULL
#ifdef _DT_ALLOW_DT_MSGS
#define _DtACT_DT_REQ_DFLT NULL
#define _DtACT_DT_SVC_DFLT NULL
#define _DtACT_DT_NTFY_DFLT NULL
#define _DtACT_DT_NGRP_DFLT NULL
#endif /* _DT_ALLOW_DT_MSGS */
#endif /* _Dt_ActionDb_h */
/* DON'T ADD ANYTHING AFTER THIS #endif */

View File

@@ -0,0 +1,121 @@
/*****************************************************************************
*
* File: ActionDbP.h
* RCS: $XConsortium: ActionDbP.h /main/3 1995/10/26 14:58:53 rswiston $
* Description: Private header file for the action database functions.
* Language: C
* Package: N/A
*
*
** (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 _Dt_ActionDbP_h
#define _Dt_ActionDbP_h
#include <Dt/DbReader.h>
#include <Dt/ActionDb.h>
#define _DtMAX_NUM_FIELDS 30
#define _ActDb_MAX_NUM_FIELDS _DtMAX_NUM_FIELDS
/*
* Bitmask field definitions for the action converter bit mask.
* These are NOT the bits for the mask in struct ACTION.
*/
#define _ActDb_LABEL_SET (1<<0)
#define _ActDb_TYPE_SET (1<<1)
#define _ActDb_ARG_CLASS_SET (1<<2)
#define _ActDb_ARG_TYPE_SET (1<<3)
#define _ActDb_ARG_COUNT_SET (1<<4)
#define _ActDb_ARG_MODE_SET (1<<5)
#define _ActDb_DESCRIPTION_SET (1<<6)
#define _ActDb_ICON_SET (1<<7)
#define _ActDb_MAP_ACTION_SET (1<<10)
#define _ActDb_EXEC_STRING_SET (1<<12)
#define _ActDb_EXEC_HOST_SET (1<<13)
#define _ActDb_CWD_SET (1<<14)
#define _ActDb_WINDOW_TYPE_SET (1<<15)
#define _ActDb_TERM_OPTS_SET (1<<16)
#define _ActDb_TT_CLASS_SET (1<<18)
#define _ActDb_TT_SCOPE_SET (1<<19)
#define _ActDb_TT_OPERATION_SET (1<<20)
#define _ActDb_TT_FILE_SET (1<<21)
#define _ActDb_TT_ARGN_MODE_SET (1<<22)
#define _ActDb_TT_ARGN_VTYP_SET (1<<23)
#define _ActDb_TT_ARGN_RTYP_SET (1<<24)
#define _ActDb_TT_ARGN_VAL_SET (1<<25)
#ifdef _DT_ALLOW_DT_MSGS
#define _ActDb_DT_REQ_NAME_SET (1<<26)
#define _ActDb_DT_SVC_SET (1<<27)
#define _ActDb_DT_NTFY_NAME_SET (1<<28)
#define _ActDb_DT_NGROUP_SET (1<<29)
#define _ActDb_DT_ARGN_VAL_SET (1<<30)
/* no mask for ARGn strings */
#define _ActDb_DT_REQUEST_BITS ( _ActDb_DT_REQ_NAME_SET \
| _ActDb_DT_SVC_SET )
#define _ActDb_DT_NOTIFY_BITS ( _ActDb_DT_NTFY_NAME_SET \
| _ActDb_DT_NGROUP_SET )
#endif /* _DT_ALLOW_DT_MSGS */
#define _ActDb_TT_BITS ( _ActDb_TT_CLASS_SET \
| _ActDb_TT_SCOPE_SET \
| _ActDb_TT_OPERATION_SET \
| _ActDb_TT_ARGN_MODE_SET \
| _ActDb_TT_ARGN_VTYP_SET \
| _ActDb_TT_ARGN_RTYP_SET \
| _ActDb_TT_ARGN_VAL_SET \
| _ActDb_TT_FILE_SET )
#define _ActDb_CMD_BITS ( _ActDb_EXEC_STRING_SET \
| _ActDb_CWD_SET \
| _ActDb_WINDOW_TYPE_SET \
| _ActDb_TERM_OPTS_SET )
#define _ActDb_MAP_BITS ( _ActDb_MAP_ACTION_SET )
#define _ActDb_TT_ARGN_BITS ( _ActDb_TT_ARGN_MODE_SET \
| _ActDb_TT_ARGN_VTYP_SET \
| _ActDb_TT_ARGN_RTYP_SET \
| _ActDb_TT_ARGN_VAL_SET )
#ifdef _DT_ALLOW_DT_MSGS
#define _ActDb_ARGN_BITS ( _ActDb_TT_ARGN_BITS \
| _ActDb_DT_ARGN_VAL_SET )
#else
#define _ActDb_ARGN_BITS ( _ActDb_TT_ARGN_BITS )
#endif /* _DT_ALLOW_DT_MSGS */
/******************************************************************************
*
* Private (but external) entry points for internal use by Action Database
* Library code only.
*
*****************************************************************************/
# ifdef __cplusplus
extern "C" {
# endif
extern Boolean _DtActionConverter( DtDtsDbField *fields,
DtDbPathId pathId,
char *hostPrefix,
Boolean rejectionStatus);
# ifdef __cplusplus
}
# endif
#endif /* _Dt_ActionDbP_h */
/* DON'T ADD ANYTHING AFTER THIS #endif */

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,45 @@
/* $XConsortium: ActionFind.h /main/4 1995/10/26 14:59:41 rswiston $ */
/************************************<+>*************************************
****************************************************************************
**
** File: ActionFind.h
**
** Project: DT
**
** Description: Public include file for the ActionFind functions.
**
** (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 _Dt_ActionFind_h
#define _Dt_ActionFind_h
#include <X11/Xlib.h>
#include <X11/Xresource.h>
#include <Dt/ActionP.h>
#include <Dt/DtsDb.h>
#include <Dt/DtsMM.h>
# ifdef __cplusplus
extern "C" {
# endif
extern void _DtSortActionDb(void);
extern ActionPtr
_DtActionFindDBEntry( ActionRequest *reqp,
DtShmBoson actQuark );
# ifdef __cplusplus
}
# endif
#endif /* _Dt_ActionFind_h */
/* DON'T ADD ANYTHING AFTER THIS #endif */

View File

@@ -0,0 +1,827 @@
/* $XConsortium: ActionP.h /main/3 1995/10/26 14:59:56 rswiston $ */
/************************************<+>*************************************
****************************************************************************
**
** File: ActionP.h
**
** Project: DT
**
** Description: Private include file for the Action Library.
**
**
** (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 _ActionP_h
#define _ActionP_h
#include <Dt/DtP.h>
#include <Dt/DbReader.h>
#include <Dt/ActionDb.h>
#include <Dt/Action.h>
#include <Tt/tttk.h>
#include <Dt/DtShmDb.h>
/*
* Environment Variable Names
*/
#define ENV_SESSION_SVR "SESSION_SVR"
/*
* Define maximum static buffer size for action code.
*/
#define _DtAct_MAX_BUF_SIZE 1024
/*
* Data-type field which contains the template for producing filenames
* of a given type.
*/
#define _DtActNAME_TEMPLATE "NAME_TEMPLATE"
#define _DtActIS_EXECUTABLE "IS_EXECUTABLE"
/******************************************************************************
*
* MASK LAYOUT:
*
* The same layout is used for all the masks (defined herein);, independent of
* the data structure in which they are defined. That is, all bit fields for
* all masks are non-overlapping. In general, the mask in any given structure
* should ONLY contain information in the field appropriate for that structure.
*
* The action bit mask is broken into the following fields
*
* --------------------------------------------------------------------------
* |act'n |arg |arg |arg | win |args| request | object |treat| not |
* |type |class|count|typ | type | | status | status | as | |
* |bits |bits |bits |bit | bits |used| bits | bits |file |used |
* --------------------------------------------------------------------------
* 0 - 4,5 - 8,9 - 12, 13 ,14 - 17,18-19,20 ------- 22,23 ---- 28, 29 ,30-31
* | | | | | |
* |<-- action mask -->| |<- request->|<- obj. ->|< - >|
* mask data |
* mask msgCcomp.
* mask
******************************************************************************/
/*
* generic bit manipulation macros
*/
#define SET_ANY_BITS(mask,bits) ( mask |= (bits) )
#define RESET_ANY_BITS(mask,bits) ( mask &= ~(bits) )
#define TST_ANY_BITS(mask,bits) ( mask & (bits) )
/*
* Action type bits
*/
#define _DtAct_CMD_BIT (1<<0)
#define _DtAct_MAP_BIT (1<<1)
#define _DtAct_TT_MSG_BIT (1<<2)
#ifdef _DT_ALLOW_DT_MSGS
#define _DtAct_DT_REQ_MSG_BIT (1<<3)
#define _DtAct_DT_NTFY_MSG_BIT (1<<4)
#endif /* _DT_ALLOW_DT_MSGS */
/*
* Action structure mask bits
*/
#define _DtAct_ARG_CLASS_FILE_BIT (1<<5)
#define _DtAct_ARG_CLASS_STRING_BIT (1<<6)
#define _DtAct_ARG_CLASS_BUFFER_BIT (1<<7)
#define _DtAct_ARG_CLASS_WILD_BIT (1<<8)
#define _DtAct_ARG_COUNT_LT_BIT (1<<9)
#define _DtAct_ARG_COUNT_GT_BIT (1<<10)
#define _DtAct_ARG_COUNT_EQ_BIT (1<<11)
#define _DtAct_ARG_COUNT_WILD_BIT (1<<12)
#define _DtAct_ARG_TYPE_WILD_BIT (1<<13)
#define _DtAct_NO_STDIO_BIT (1<<14)
#define _DtAct_TERMINAL_BIT (1<<15)
#define _DtAct_PERM_TERM_BIT (1<<16)
/*
* Defines which reflect the actual number
* of %ARGn% instances found in the action definition
* NOTE: Is this JUST in the EXEC_STRING? or the total number of %ARGn%'s
* referenced in all parssed definitions?
*
*/
#define _DtAct_SINGLE_ARG_BIT (1<<18)
#define _DtAct_MULTI_ARG_BIT (1<<19)
#ifdef _DT_ALLOW_DT_MSGS
#define _DtAct_ACTION_TYPE_BITS ( _DtAct_CMD_BIT \
| _DtAct_MAP_BIT \
| _DtAct_DT_NTFY_MSG_BIT \
| _DtAct_DT_REQ_MSG_BIT \
| _DtAct_TT_MSG_BIT )
#else
#define _DtAct_ACTION_TYPE_BITS ( _DtAct_CMD_BIT \
| _DtAct_MAP_BIT \
| _DtAct_TT_MSG_BIT )
#endif /* _DT_ALLOW_DT_MSGS */
#define _DtAct_ARG_CLASS_BITS ( _DtAct_ARG_CLASS_FILE_BIT \
| _DtAct_ARG_CLASS_STRING_BIT\
| _DtAct_ARG_CLASS_BUFFER_BIT \
| _DtAct_ARG_CLASS_WILD_BIT )
#define _DtAct_ARG_TYPE_BITS ( _DtAct_ARG_TYPE_WILD_BIT )
#define _DtAct_ARG_COUNT_BITS ( _DtAct_ARG_COUNT_LT_BIT \
| _DtAct_ARG_COUNT_GT_BIT \
| _DtAct_ARG_COUNT_EQ_BIT \
| _DtAct_ARG_COUNT_WILD_BIT )
#define _DtAct_WINTYPE_BITS ( _DtAct_NO_STDIO_BIT \
| _DtAct_TERMINAL_BIT \
| _DtAct_PERM_TERM_BIT )
#define _DtAct_ARGS_USED_BITS ( _DtAct_SINGLE_ARG \
| _DtAct_MULTI_ARG )
#define _DtAct_ACTION_BITS ( _DtAct_ACTION_TYPE_BITS \
| _DtAct_ARG_CLASS_BITS \
| _DtAct_ARG_TYPE_BITS \
| _DtAct_ARG_COUNT_BITS \
| _DtAct_WINTYPE_BITS \
| _DtAct_ARGS_USED_BITS )
#define IS_CMD(mask) ( mask & _DtAct_CMD_BIT )
#define IS_MAP(mask) ( mask & _DtAct_MAP_BIT )
#define IS_TT_MSG(mask) ( mask & _DtAct_TT_MSG_BIT )
#ifdef _DT_ALLOW_DT_MSGS
#define IS_DT_REQ_MSG(mask) ( mask & _DtAct_DT_REQ_MSG_BIT )
#define IS_DT_NOTIFY_MSG(mask) ( mask & _DtAct_DT_NTFY_MSG_BIT )
#endif /* _DT_ALLOW_DT_MSGS */
#define SET_CMD_ACTION(mask) ( mask |= _DtAct_CMD_BIT )
#define SET_MAP_ACTION(mask) ( mask |= _DtAct_MAP_BIT )
#define SET_TT_MSG(mask) ( mask |= _DtAct_TT_MSG_BIT )
#ifdef _DT_ALLOW_DT_MSGS
#define SET_DT_REQUEST_MSG(mask) ( mask |= _DtAct_DT_REQ_MSG_BIT)
#define SET_DT_NOTIFY_MSG(mask) ( mask |= _DtAct_DT_NTFY_MSG_BIT)
#endif /* _DT_ALLOW_DT_MSGS */
#define RESET_CMD_ACTION(mask) ( mask &= ~(_DtAct_CMD_BIT))
#define RESET_MAP_ACTION(mask) ( mask &= ~(_DtAct_MAP_BIT))
#define RESET_TT_MSG(mask) ( mask &= ~(_DtAct_TT_MSG_BIT))
#ifdef _DT_ALLOW_DT_MSGS
#define RESET_DT_REQ_MSG(mask) ( mask &= ~(_DtAct_DT_REQ_MSG_BIT))
#define RESET_DT_NOTIFY_MSG(mask) ( mask &= ~(_DtAct_DT_NTFY_MSG_BIT))
#endif /* _DT_ALLOW_DT_MSGS */
#define IS_NO_STDIO(mask) ( mask & _DtAct_NO_STDIO_BIT )
#define IS_TERMINAL(mask) ( mask & _DtAct_TERMINAL_BIT )
#define IS_PERM_TERM(mask) ( mask & _DtAct_PERM_TERM_BIT)
#define SET_NO_STDIO(mask) ( mask |= _DtAct_NO_STDIO_BIT )
#define SET_TERMINAL(mask) ( mask |= _DtAct_TERMINAL_BIT )
#define SET_PERM_TERM(mask) ( mask |= _DtAct_PERM_TERM_BIT )
#define RESET_NO_STDIO(mask) ( mask &= ~(_DtAct_NO_STDIO_BIT ))
#define RESET_TERMINAL(mask) ( mask &= ~(_DtAct_TERMINAL_BIT ))
#define RESET_PERM_TERM(mask) ( mask &= ~(_DtAct_PERM_TERM_BIT ))
#define IS_ARG_CLASS_FILE(mask) ( mask & _DtAct_ARG_CLASS_FILE_BIT )
#define IS_ARG_CLASS_STRING(mask) ( mask & _DtAct_ARG_CLASS_STRING_BIT )
#define IS_ARG_CLASS_BUFFER(mask) ( mask & _DtAct_ARG_CLASS_BUFFER_BIT )
#define IS_ARG_CLASS_WILD(mask) ( mask & _DtAct_ARG_CLASS_WILD_BIT )
#define SET_ARG_CLASS_FILE(mask) ( mask |= _DtAct_ARG_CLASS_FILE_BIT )
#define SET_ARG_CLASS_STRING(mask) ( mask |= _DtAct_ARG_CLASS_STRING_BIT)
#define SET_ARG_CLASS_BUFFER(mask) ( mask |= _DtAct_ARG_CLASS_BUFFER_BIT)
#define SET_ARG_CLASS_WILD(mask) ( mask |= _DtAct_ARG_CLASS_WILD_BIT )
#define RESET_ARG_CLASS_FILE(mask) (mask &= ~(_DtAct_ARG_CLASS_FILE_BIT))
#define RESET_ARG_CLASS_STRING(mask) (mask &= ~(_DtAct_ARG_CLASS_STRING_BIT))
#define RESET_ARG_CLASS_BUFFER(mask) (mask &= ~(_DtAct_ARG_CLASS_BUFFER_BIT))
#define RESET_ARG_CLASS_WILD(mask) (mask &= ~(_DtAct_ARG_CLASS_WILD_BIT))
#define IS_ARG_TYPE_WILD(mask) ( mask & _DtAct_ARG_TYPE_WILD_BIT )
#define SET_ARG_TYPE_WILD(mask) ( mask |= _DtAct_ARG_TYPE_WILD_BIT )
#define RESET_ARG_TYPE_WILD(mask) ( mask &= ~(_DtAct_ARG_TYPE_WILD_BIT))
#define IS_ARG_COUNT_GT(mask) ( mask & _DtAct_ARG_COUNT_GT_BIT )
#define IS_ARG_COUNT_LT(mask) ( mask & _DtAct_ARG_COUNT_LT_BIT )
#define IS_ARG_COUNT_EQ(mask) ( mask & _DtAct_ARG_COUNT_EQ_BIT )
#define IS_ARG_COUNT_WILD(mask) ( mask & _DtAct_ARG_COUNT_WILD_BIT )
#define SET_ARG_COUNT_GT(mask) ( mask |= _DtAct_ARG_COUNT_GT_BIT )
#define SET_ARG_COUNT_LT(mask) ( mask |= _DtAct_ARG_COUNT_LT_BIT )
#define SET_ARG_COUNT_EQ(mask) ( mask |= _DtAct_ARG_COUNT_EQ_BIT )
#define SET_ARG_COUNT_WILD(mask) ( mask |= _DtAct_ARG_COUNT_WILD_BIT )
#define RESET_ARG_COUNT_GT(mask) ( mask &= ~(_DtAct_ARG_COUNT_GT_BIT ))
#define RESET_ARG_COUNT_LT(mask) ( mask &= ~(_DtAct_ARG_COUNT_LT_BIT ))
#define RESET_ARG_COUNT_EQ(mask) ( mask &= ~(_DtAct_ARG_COUNT_EQ_BIT ))
#define RESET_ARG_COUNT_WILD(mask) ( mask &= ~(_DtAct_ARG_COUNT_WILD_BIT ))
/*
* Use of the logical "NOT" operator(!) instead of the bitwise negation
* operator(~) is intentional in IS_ARG_NONE_FOUND.
*/
#define IS_ARG_NONE_FOUND(mask) !( mask & ( _DtAct_SINGLE_ARG_BIT \
| _DtAct_MULTI_ARG_BIT ))
#define IS_ARG_SINGLE_ARG(mask) ( mask & _DtAct_SINGLE_ARG_BIT )
#define IS_ARG_MULTI_ARG(mask) ( mask & _DtAct_MULTI_ARG_BIT )
#define SET_ARG_NONE_FOUND(mask) ( mask &= ~( _DtAct_SINGLE_ARG_BIT \
| _DtAct_MULTI_ARG_BIT ))
#define SET_ARG_SINGLE_ARG(mask) ((mask |= _DtAct_SINGLE_ARG_BIT), \
( mask &= ~(_DtAct_MULTI_ARG_BIT)))
#define SET_ARG_MULTI_ARG(mask) ((mask |= _DtAct_MULTI_ARG_BIT), \
( mask &= ~(_DtAct_SINGLE_ARG_BIT)))
#define RESET_ARG_SINGLE_ARG(mask) ( mask &= ~(_DtAct_SINGLE_ARG_BIT))
#define RESET_ARG_MULTI_ARG(mask) ( mask &= ~(_DtAct_MULTI_ARG_BIT))
/*
* ActionRequest structure mask bits
*/
#define _DtAct_REPROCESSING_BIT (1<<20)
#define _DtAct_TOO_MANY_MAPS_BIT (1<<21)
#define _DtAct_CLONED_REQUEST_BIT (1<<22)
#define _DtAct_ACTION_REQUEST_BITS ( _DtAct_REPROCESSING_BIT \
| _DtAct_TOO_MANY_MAPS_BIT \
| _DtAct_CLONED_REQUEST_BIT )
#define IS_REPROCESSING(mask) ( mask & _DtAct_REPROCESSING_BIT )
#define IS_TOO_MANY_MAPS(mask) ( mask & _DtAct_TOO_MANY_MAPS_BIT )
#define IS_CLONED_REQUEST(mask) ( mask & _DtAct_CLONED_REQUEST_BIT )
#define SET_REPROCESSING(mask) ( mask |= _DtAct_REPROCESSING_BIT )
#define SET_TOO_MANY_MAPS(mask) ( mask |= _DtAct_TOO_MANY_MAPS_BIT )
#define SET_CLONED_REQUEST(mask) ( mask |= _DtAct_CLONED_REQUEST_BIT )
#define RESET_REPROCESSING(mask) ( mask &= ~(_DtAct_REPROCESSING_BIT))
#define RESET_TOO_MANY_MAPS(mask) ( mask &= ~(_DtAct_TOO_MANY_MAPS_BIT))
#define RESET_CLONED_REQUEST(mask) ( mask &= ~(_DtAct_CLONED_REQUEST_BIT))
/*
* ObjectData structure mask bits
*
*/
#define _DtAct_WRITE_OBJ_BIT (1<<23)
#define _DtAct_FILE_OBJ_BIT (1<<24)
#define _DtAct_BUFFER_OBJ_BIT (1<<25)
#define _DtAct_STRING_OBJ_BIT (1<<26)
#define _DtAct_DIR_OBJ_BIT (1<<27)
#define _DtAct_UNKNOWN_IF_DIR_BIT (1<<28)
#define _DtAct_OBJ_DATA_BITS ( _DtAct_WRITE_OBJ_BIT \
| _DtAct_FILE_OBJ_BIT \
| _DtAct_DIR_OBJ_BIT \
| _DtAct_BUFFER_OBJ_BIT \
| _DtAct_STRING_OBJ_BIT \
| _DtAct_UNKNOWN_IF_DIR_BIT )
#define IS_WRITE_OBJ(mask) ( mask & _DtAct_WRITE_OBJ_BIT )
#define IS_FILE_OBJ(mask) ( mask & _DtAct_FILE_OBJ_BIT )
#define IS_BUFFER_OBJ(mask) ( mask & _DtAct_BUFFER_OBJ_BIT )
#define IS_STRING_OBJ(mask) ( mask & _DtAct_STRING_OBJ_BIT )
#define IS_UNKNOWN_IF_DIR(mask) ( mask & _DtAct_UNKNOWN_IF_DIR_BIT )
#define IS_DIR_OBJ(mask) ( mask & \
( _DtAct_UNKNOWN_IF_DIR_BIT \
| _DtAct_DIR_OBJ_BIT ) \
== _DtAct_DIR_OBJ_BIT)
#define SET_WRITE_OBJ(mask) ( mask |= _DtAct_WRITE_OBJ_BIT )
#define SET_FILE_OBJ(mask) ( mask |= _DtAct_FILE_OBJ_BIT )
#define SET_BUFFER_OBJ(mask) ( mask |= _DtAct_BUFFER_OBJ_BIT )
#define SET_STRING_OBJ(mask) ( mask |= _DtAct_STRING_OBJ_BIT )
#define SET_DIR_OBJ(mask) ( mask |= _DtAct_DIR_OBJ_BIT )
#define SET_UNKNOWN_IF_DIR(mask) ( mask |= _DtAct_UNKNOWN_IF_DIR_BIT)
#define RESET_WRITE_OBJ(mask) ( mask &= ~(_DtAct_WRITE_OBJ_BIT))
#define RESET_FILE_OBJ(mask) ( mask &= ~(_DtAct_FILE_OBJ_BIT))
#define RESET_BUFFER_OBJ(mask) ( mask &= ~(_DtAct_BUFFER_OBJ_BIT))
#define RESET_STRING_OBJ(mask) ( mask &= ~(_DtAct_STRING_OBJ_BIT))
#define RESET_DIR_OBJ(mask) ( mask &= ~(_DtAct_DIR_OBJ_BIT))
#define RESET_UNKNOWN_IF_DIR(mask) ( mask &= ~(_DtAct_UNKNOWN_IF_DIR_BIT))
/*
* MsgComponent structure mask bits (shared with Object Data?)
*/
#define _DtAct_TREAT_AS_FILE_BIT (1<<29)
#define _DtAct_MSG_COMP_BITS ( _DtAct_TREAT_AS_FILE_BIT )
#define IS_TREAT_AS_FILE(mask) ( mask & _DtAct_TREAT_AS_FILE_BIT )
#define SET_TREAT_AS_FILE(mask) ( mask |= _DtAct_TREAT_AS_FILE_BIT)
#define RESET_TREAT_AS_FILE(mask) ( mask &= ~(_DtAct_TREAT_AS_FILE_BIT))
/* Keyword defines */
#define NO_KEYWORD -1
#define LOCAL_HOST 0
#define DATA_HOST 1
#define DATABASE_HOST 2
#define ARG 3
#define DISPLAY_HOST 4
#define LABEL 5
#define SESSION_HOST 6
/* Special argNum values */
#define NO_ARG -1
#define ALL_ARGS 0
/*
* ToolTalk base representation type ( tt_argn_rep_type ) values
*/
#define DtACT_TT_REP_UNDEFINED 0
#define DtACT_TT_REP_INT 1
#define DtACT_TT_REP_BUFFER 2
#define DtACT_TT_REP_STRING 3
/*
* Resource name and class for the EXEC-HOST resource.
*/
#define DtEXEC_HOSTS_NAME "executionHosts"
#define DtEXEC_HOSTS_CLASS "ExecutionHosts"
#define DtEXEC_HOSTS_DEFAULT _DtACT_EXEC_HOST_DFLT
/* Flags to force special processing of filenames */
#define _DTAct_TT_VTYPE 1 << 0
#define _DTAct_TT_ARG 1 << 1
/* Structure used to hold the components of a message */
typedef struct {
char *precedingText;
char *prompt;
int keyword;
int argNum;
unsigned long mask; /* replaces isFile, isBuffer, isString boolean */
} MsgComponent;
typedef struct {
MsgComponent *parsedMessage;
int numMsgParts;
char *compiledMessage;
int msgLen;
} parsedMsg;
/******************************************************************************
*
* Structs used during the invocation of an action. Once DtActionInvoke()
* exits, these structs are generally freed.
*
*****************************************************************************/
typedef struct {
/*int winMask; ---> moved into the action mask*/
parsedMsg execString;
parsedMsg termOpts;
char *contextDir;
char *contextHost;
parsedMsg execHosts;
char **execHostArray;
int execHostCount;
} cmdAttr;
typedef struct {
DtShmBoson map_action;
} mapAttr;
typedef struct {
int tt_class;
int tt_scope;
parsedMsg tt_op;
parsedMsg tt_file; /* must be a single file name */
int *tt_argn_mode;
int mode_count;
parsedMsg *tt_argn_vtype;
int vtype_count;
parsedMsg *tt_argn_value;
int value_count;
int *tt_argn_rep_type; /* INT, STRING, BUFFER or UNDEFINED */
int rep_type_count;
} tt_msgAttr;
#ifdef _DT_ALLOW_DT_MSGS
typedef struct {
parsedMsg service; /* ICCCM service name */
parsedMsg request; /* request name string */
parsedMsg *argn_value;
int value_count;
} dt_reqAttr;
typedef struct {
parsedMsg ngroup; /* ICCCM notification group */
parsedMsg notify; /* notification to be sent */
parsedMsg *argn_value;
int value_count;
} dt_notifyAttr;
#endif /* _DT_ALLOW_DT_MSGS */
typedef struct {
DtShmBoson action; /* Might just use a char * here? */
DtDbPathId file_name_id; /* id of file wherein the action is defined */
char *label; /* localizable action label string */
char *description;
DtShmBoson *arg_types;
int type_count;
int arg_count; /* Number of arguments accepted by the action */
unsigned long mask; /* action mask -- class/type/arg info */
union { /* attributes for the different action kinds */
cmdAttr cmd;
mapAttr map;
tt_msgAttr tt_msg;
#ifdef _DT_ALLOW_DT_MSGS
dt_reqAttr dt_req;
dt_notifyAttr dt_notify;
#endif /* _DT_ALLOW_DT_MSGS */
} u;
} Action, *ActionPtr; /* new action structure and pointer */
/* Structure used to hold each of the object components */
typedef struct {
char * origFilename;
char * baseFilename;
char * origHostname;
int hostIndex;
int dirIndex;
void * bp; /* pointer to original buffer -- tmp files only */
int sizebp; /* size of original buf -- for tmp files only */
} fileAttr;
typedef struct {
char * string;
} stringAttr;
typedef struct {
int size;
void *bp;
} bufferAttr;
typedef struct {
DtShmBoson type;
unsigned long mask;
union {
fileAttr file;
stringAttr string;
bufferAttr buffer;
} u;
} ObjectData;
/*
* Structure attached to the button callbacks in the
* dialog used to collect missing parameters.
*
*/
typedef struct {
char *actionName;
int objOffset;
int objsUsed;
int numObjects;
ObjectData *objects;
int numPromptInputs;
char **promptInputs;
int numHostNames;
char **hostNames;
int numDirNames;
char **dirNames;
char *termOpts;
char *cwdHost;
char *cwdDir;
ActionPtr clonedAction;
unsigned long mask;
char *badHostList;
char *currentHost;
int hostIndex;
char *execHost;
DtActionInvocationID invocId;
unsigned long childId;
} ActionRequest;
/******************************************************************************
*
* Structs used to maintain information on invoked actions until they
* exit. A few select elements of the ActionRequest and Action structs
* will be copied into these strcuts.
*
*****************************************************************************/
/******************************************************************************
******************************************************************************
**
** Major data-structure diagram for the DtAction invocation layer:
**
** _DtActInvRec <=== _DtActInvRecArray[ actInvRecArraySize ]
** ------------------
** | info per |
** | DtActionInvoke |
** |----------------|
** | numChildren |
** |----------------|
** | childRecs[] | ===> _DtActChildRec
** ------------------ ------------------
** | info per |
** | child request |
** |----------------|
** | *request | ===> ActionRequest
** ------------------ ------------------
** | info on users |
** | action request |
** |----------------|
** Action <=== | *clonedAction |
** ------------------ ------------------
** |info on matching|
** | actionDB entry |
** |----------------|
** | cmd/map/tt/dt |
** | attributes of |
** | resulting msg |
** ------------------
**
** "ActionRequest" and "Action" were present in VUE 3.0, and have a
** scratch-pad like function within DtActionInvoke() to get actions
** started. They are not good long-term retainers of information.
** Action and ActionRequest are in fact freed when DtActionInvoke()
** exits.
**
** "_DtActInvRec" and "_DtActChildRec" have been introduced to retain
** information for the entire life of the actions. Some of the
** information from ActionRequest and Action will be copied (mirrored)
** up to these structures.
**
******************************************************************************
*****************************************************************************/
/******************************************************************************
*
* Child Status Macro Definitions -- These values are used in
* the status word of the _DtActChildRec child record.
*
* ****** IMPORTANT NOTE *** IMPORTANT NOTE *** IMPORTANT NOTE ******
*
* The _DtActCHILD_ macros are also used in cde1/dtexec/Main.c
* in the _DtActDtexecDone(Request) message, so in effect they
* are also protocol constants that should *never* be changed.
* If changed, libDtSvc and dtexec may mis-communicate status.
*
*****************************************************************************/
#define _DtActCHILD_UNKNOWN (1<<0) /* 1 - child status unknown */
#define _DtActCHILD_PENDING_START (1<<1) /* 2 - child start pending */
#define _DtActCHILD_ALIVE_UNKNOWN (1<<2) /* 4 - child alive but unknown*/
#define _DtActCHILD_ALIVE (1<<3) /* 8 - child alive and well */
#define _DtActCHILD_DONE (1<<4) /* 16 - child done */
#define _DtActCHILD_FAILED (1<<5) /* 32 - child failed */
#define _DtActCHILD_CANCELED (1<<6) /* 64 - child canceled */
#define _DtActCHILD_DONE_BITS ( (_DtActCHILD_DONE) | \
(_DtActCHILD_FAILED) | \
(_DtActCHILD_CANCELED) )
/*** IMPORTANT NOTE ABOVE *** IMPORTANT NOTE ABOVE *** IMPORTANT NOTE ABOVE ***/
#define ARE_CHILDREN_DONE(mask) ( (mask) & _DtActCHILD_DONE_BITS )
#define IS_CHILD_UNKNOWN(mask) ( (mask) == _DtActCHILD_UNKNOWN )
#define IS_CHILD_PENDING_START(mask) ( (mask) & _DtActCHILD_PENDING_START )
#define IS_CHILD_DONE(mask) ( (mask) & _DtActCHILD_DONE)
#define IS_CHILD_FAILED(mask) ( (mask) & _DtActCHILD_FAILED)
#define IS_CHILD_CANCELED(mask) ( (mask) & _DtActCHILD_CANCELED)
#define IS_CHILD_ALIVE(mask) ( (mask) & _DtActCHILD_ALIVE)
#define IS_CHILD_ALIVE_UNKOWN(mask) ( (mask) & _DtActCHILD_ALIVE_UNKNOWN)
/******************************************************************************
*
* Information per child of DtActionInvoke()
*
*****************************************************************************/
/*
* Structure useed to map returnable arguments to the child argument list.
*/
typedef struct {
int argN; /* Nth returned value (0 based for tooltalk) */
int argIdx; /* Nth child argument */
} _DtActArgMap;
typedef struct {
unsigned long childId; /* serial # with DtActInvId */
unsigned long childState; /* child state */
/*
* Information cloned from "ActionRequest *req"
*/
int numObjects; /* number of child args */
_DtActArgMap *argMap; /* map of returnable args to chd args */
/*
* Information cloned from "ActionPtr clonedAction"
*/
unsigned long mask; /* action type - IS_xxx() */
/* a list of tmp file names 5/11/94 --tomg */
union {
struct { /* COMMAND elements */
char *TTProcId; /* TT procID handle to child */
Tt_message reqMessage; /* Initiator TT Request */
Tt_pattern magic_cookie; /* dtexec to libDtSvc cookie */
} cmd;
struct { /* TT_MSG elements */
char *TTProcId; /* TT procID handle to child */
Tt_message reqMessage; /* Initiator TT Request */
int isTtMedia; /* handled by ttmedia_load ? */
Tttk_op TtMediaOp; /* if ttmedia_load, the op */
Tt_pattern *subConPats; /* for subcontract_manage */
} tt;
} u;
} _DtActChildRecT;
/******************************************************************************
*
* Invocation Status Macro Definitions -- These values are used in
* the state word of the _DtActInvRec invocation record.
*
*****************************************************************************/
#define _DtActINV_UNKNOWN 0 /* unknown invocation status */
#define _DtActINV_ERROR (1<<0) /* invocation error detected */
#define _DtActINV_CANCEL (1<<1) /* trying to cancel invocation*/
#define _DtActINV_PENDING (1<<2) /* invocation pending */
#define _DtActINV_WORKING (1<<3) /* invocation in process */
#define _DtActINV_DONE (1<<4) /* invocation step done */
#define _DtActINV_COMPLETE (1<<5) /* invocation steps all done */
#define _DtActINV_CB_CALLED (1<<6) /* invocation callback called */
#define _DtActINV_ID_RETURNED (1<<7) /* invocation id has returned */
#define _DtActINV_CMD_QUEUED (1<<8) /* command has been queued */
#define _DtActINV_INDICATOR_ON (1<<9) /* busy indicator active bit */
#define SET_INV_UNKNOWN(mask) (mask = 0)
#define SET_INV_ERROR(mask) (mask |= _DtActINV_ERROR)
#define SET_INV_CANCEL(mask) (mask |= _DtActINV_CANCEL)
#define SET_INV_PENDING(mask) (mask |= _DtActINV_PENDING)
#define SET_INV_WORKING(mask) (mask |= _DtActINV_WORKING)
#define SET_INV_DONE(mask) (mask |= _DtActINV_DONE)
#define SET_INV_COMPLETE(mask) (mask |= _DtActINV_COMPLETE)
#define SET_INV_CB_CALLED(mask) (mask |= _DtActINV_CB_CALLED)
#define SET_INV_ID_RETURNED(mask) (mask |= _DtActINV_ID_RETURNED)
#define SET_INV_CMD_QUEUED(mask) (mask |= _DtActINV_CMD_QUEUED)
#define SET_INV_INDICATOR_ON(mask) (mask |= _DtActINV_INDICATOR_ON)
#define RESET_INV_ERROR(mask) (mask &= ~(_DtActINV_ERROR))
#define RESET_INV_CANCEL(mask) (mask &= ~(_DtActINV_CANCEL))
#define RESET_INV_PENDING(mask) (mask &= ~(_DtActINV_PENDING))
#define RESET_INV_WORKING(mask) (mask &= ~(_DtActINV_WORKING))
#define RESET_INV_COMPLETE(mask) (mask &= ~(_DtActINV_COMPLETE))
#define RESET_INV_DONE(mask) (mask &= ~(_DtActINV_DONE))
#define RESET_INV_CB_CALLED(mask) (mask &= ~(_DtActINV_CB_CALLED))
#define RESET_INV_ID_RETURNED(mask) (mask &= ~(_DtActINV_ID_RETURNED))
#define RESET_INV_CMD_QUEUED(mask) (mask &= ~(_DtActINV_CMD_QUEUED))
#define RESET_INV_INDICATOR_ON(mask) (mask &= ~(_DtActINV_INDICATOR_ON))
#define IS_INV_FINISHED(mask) ( !((mask) & _DtActINV_CMD_QUEUED) \
&& ((mask) & (_DtActINV_COMPLETE \
| _DtActINV_CANCEL)) )
#define IS_INV_UNKNOWN(mask) ( (mask) == _DtActINV_UNKNOWN )
#define IS_INV_ERROR(mask) ((mask) & _DtActINV_ERROR )
#define IS_INV_CANCEL(mask) ((mask) & _DtActINV_CANCEL )
#define IS_INV_PENDING(mask) ((mask) & _DtActINV_PENDING )
#define IS_INV_WORKING(mask) ((mask) & _DtActINV_WORKING )
#define IS_INV_DONE(mask) ((mask) & _DtActINV_DONE )
#define IS_INV_COMPLETE(mask) ((mask) & _DtActINV_COMPLETE )
#define IS_INV_CB_CALLED(mask) ((mask) & _DtActINV_CB_CALLED )
#define IS_INV_ID_RETURNED(mask) ((mask) & _DtActINV_ID_RETURNED )
#define IS_INV_CMD_QUEUED(mask) ((mask) & _DtActINV_CMD_QUEUED )
#define IS_INV_INDICATOR_ON(mask) ((mask) & _DtActINV_INDICATOR_ON )
#define CALL_INV_CB(mask) ((IS_INV_FINISHED(mask)) && \
(IS_INV_ID_RETURNED(mask)) && \
!(IS_INV_CB_CALLED(mask)))
/******************************************************************************
*
* Information per DtActionInvoke()
*
* Note: For TT_MSG(NOTICE)'s during CDE 1.0, this struct will disappear
* immediately after the NOTICEs are sent.
*
*****************************************************************************/
typedef struct {
unsigned long mask; /* encodes object class and writable flag */
int size; /* original size (buffers only) */
char *type; /* original type (buffers only) */
char *name; /* encodes (tmp) file name associated with the
object (if any) */
} _DtActArgInfo;
typedef struct {
DtActionStatus userStatus;
DtActionArg *newArgp;
int newArgc;
} _DtActUpdateCache;
typedef struct _DtActInvRec {
unsigned long state; /* invocation state */
DtActionInvocationID id; /* identifying invocation ID */
Widget w; /* users widget id */
DtActionCallbackProc cb; /* users callback */
XtPointer client_data; /* users client data for cb */
_DtActArgInfo *info; /* template w/ .argClass info */
int ac; /* original # of arguments */
int numChildren; /* number of childRec's. */
_DtActChildRecT **childRec; /* array of child Rec's */
int cachedUploadCnt;/* cached callback updates */
_DtActUpdateCache *cachedUploads; /* data for */
} _DtActInvRecT;
/******************************************************************************
*
* Structs for dialogs/prompts
*
*****************************************************************************/
/* Structure used to hold a prompt string destined for a dialog */
typedef struct {
int argIndex;
char *prompt;
} PromptEntry;
/* Structure used to contain prompt dialog information */
typedef struct {
int argIndex;
Widget promptWidget;
} DialogPromptEntry;
typedef struct {
ActionRequest * request;
Widget topLevel;
Widget associatedWidget;
int numPrompts;
DialogPromptEntry * prompts;
} PromptDialog;
/* Structure used to contain abort/continue dialog information */
typedef struct {
ActionRequest * request;
Widget topLevel;
Widget associatedWidget;
int numPrompts;
PromptEntry * prompts;
} ContinueDialog;
/* Structure passed to request passed/failed callbacks */
typedef struct {
Widget associatedWidget;
char *actionLabel;
int offset;
ActionPtr actionPtr; /* Ptr to the action that
was invoked. */
ActionRequest *requestPtr;
DtActionInvocationID actInvId; /* A standard invocation id */
unsigned long childId; /* An id to further identify
children of actInvId */
} CallbackData;
/******************************************************************************
*
* Private External Function Declarations -- not for public consumption
*
******************************************************************************/
extern void _DtFreeActionStruct( ActionPtr action) ;
#endif /* _ActionP_h */
/* DON'T ADD ANYTHING AFTER THIS #endif */

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,92 @@
/* $XConsortium: ActionUtilP.h /main/3 1995/10/26 15:01:19 rswiston $ */
/************************************<+>*************************************
****************************************************************************
**
** File: ActionUtilP.h
**
** Project: DT
**
** Description: Private include file for the Action Library Utilities.
**
**
** (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 _ActionUtilP_h
#define _ActionUtilP_h
#include <X11/Intrinsic.h> /* for Display struct definition */
#include "ActionP.h"
/*****************************************************************************
*
* Macro to protect against sending a NULL pointer to certain
* library functions (i.e. sprintf, strlen, ...) with on some
* systems choke on a NULL pointer.
*
****************************************************************************/
#define _DtActNULL_GUARD(s) ((s) ? (s) : "")
/******************************************************************************
External Utility Function Declarations
These functions are for internal use and are not part of the
public Action API. Each of the following functions returns a
newly allocated version of the desired string. It is up to the
caller to free the strings obtained.
******************************************************************************/
extern char *_DtBasename(const char *s);
extern char *_DtDirname(const char *s);
extern char *_DtPathname(const char *s);
extern char *_DtHostString(const char *s);
extern char *_DtGetSessionHostName( void );
extern char *_DtGetDisplayHostName( Display *d);
extern char *_DtGetLocalHostName( void );
extern char *_DtGetExecHostsDefault (void);
extern char *_DtGetActionIconDefault (void);
extern char *_DtGetDtTmpDir(void);
extern char *_DtActGenerateTmpFile(char *dir,
char *format,
mode_t mode,
int *fd );
extern int _DtIsSameHost( const char *host1, const char *host2 );
extern void _DtRemoveTrailingBlanksInPlace(char **s);
extern int _DtExecuteAccess(const char *path);
extern DtActionInvocationID _DtActAllocID();
extern _DtActInvRecT *_DtActAllocInvRec();
extern _DtActChildRecT *_DtActAllocChildRec( _DtActInvRecT *recp );
extern int _DtActDeleteInvRec( DtActionInvocationID id);
extern _DtActInvRecT *_DtActFindInvRec( DtActionInvocationID id);
extern _DtActChildRecT *_DtActFindChildRec(
DtActionInvocationID id,
unsigned long childId);
extern unsigned long _DtActEvalChildren(DtActionInvocationID id);
extern void _DtActExecutionLeafNodeCleanup(
DtActionInvocationID id,
DtActionArg *newArgp,
int newArgc,
int respectQuitBlock);
extern DtActionArg *_DtActMallocEmptyArgArray(int ac);
extern void _DtActFreeArgArray( DtActionArg *argp, int ac );
extern void *_DtActReadTmpFileToBuffer (
char *fname,
int *sizep);
extern int _DtActGetCmdReturnArgs (
DtActionInvocationID invId,
_DtActChildRecT *childp,
DtActionArg **aargv );
/******************************************************************************/
#endif /* _ActionUtilP_h */
/* DON'T ADD ANYTHING AFTER THIS #endif */

View File

@@ -0,0 +1,177 @@
/* $XConsortium: CmdInv.h /main/6 1996/01/23 10:41:03 barstow $ */
/***************************************************************************
*
* File: CmdInv.h
* Description: Public header for the command invocation system.
* Language: C
*
** (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 _CmdInv_h
#define _CmdInv_h
#include <X11/Xlib.h>
#include <Dt/Message.h>
#include <Dt/Spc.h>
/******************************************************************************
*
* DtCmdInvExecuteProc - This type is is used to define the parameters
* needed in the callback functions for success and failure notification
* of a Command Invoker execution call.
*
*****************************************************************************/
typedef void (*DtCmdInvExecuteProc) (
char *message, /* NULL if the request is successful.
* Otherwise an error message. */
void *client_data
);
/******************************************************************************
*
* Function: void _DtInitializeCommandInvoker (
* Display *display,
* char *toolClass,
* char *applicationClass,
* DtSvcReceiveProc reloadDBHandler,
* XtAppContext appContext)
*
* Parameters:
*
* display - The X server display connection.
*
* toolClass - The BMS tool class of the client.
*
* applicationClass - The application class of the client (see
* XtInitialize). This is needed to add the
* Command Invoker's resources to the client's
* resources.
*
* reloadDBHandler - Function to be called if a RELOAD-TYPES-DB
* request is made. If the client does not read
* DT action and/or filetype databases, NULL must
* be used.
*
* appContext - The client's application context. Must be NULL
* if the client does not use an application
* context.
*
* Purpose:
*
* This function allows a client to internalize the functionality
* of the DT "Command Invoker". By using this library and the
* Action Library, requests for the Command Invoker will be done
* internally instead of sending a request to a separate Command
* Invoker process.
*
* For local execution, the "fork" and "execvp" system calls are
* used. For remote execution, the "SPCD" is used.
*
*****************************************************************************/
extern void
_DtInitializeCommandInvoker(
Display *display,
char *toolClass,
char *applicationClass,
DtSvcReceiveProc reloadDBHandler,
XtAppContext appContext);
/******************************************************************************
*
* Function: void _DtCommandInvokerExecute (
* char *request_name,
* char *context_host,
* char *context_dir,
* char *context_file,
* char *exec_parameters,
* char *exec_host,
* char *exec_string,
* DtCmdInvExecProc success_proc,
* void *success_data,
* DtCmdInvExecProc failure_proc,
* void *failure_data)
*
* Parameters:
*
* request_name - The request name (defined in "CommandM.h").
*
* context_host - Name of the host where request is executed from. If
* NULL, the "exec_host" parameter is used. Note: this
* should not be confused with execution host, described
* below.
*
* context_dir - Directory where the request should be executed. If
* NULL, the HOME directory is used.
*
* context_file - Not currently used by the Command Invoker.
*
* exec_parameters - Command Invoker execution parameters. See External
* Specification for more information.
* If set to NULL, "-" is used.
*
* exec_host - Name of the host where the request is executed.
*
* exec_string - The command line to execute.
*
* success_proc - The function to be invoked if the request is
* successfully executed.
*
* success_data - Client data for successful execution.
*
* failure_proc - The function to be invoked if an attempt to exeucte
* the request fails.
*
* failure_data - Client data for unsuccessful execution.
*
* Purpose:
*
* This function allows a client to use the DT "Command Invoker"
* Library for its' process execution. This function is intended
* for processes which do not use the Action Library.
*
* For local execution, the "fork" and "execvp" system calls are
* used. For remote execution, the "SPCD" is used.
*
* Notes:
*
* This function must be preceeded by a call to
* "_DtInitializeCommandInvoker".
*
*****************************************************************************/
extern void
_DtCommandInvokerExecute(
char *request_name,
char *context_host,
char *context_dir,
char *context_file,
char *exec_parameters,
char *exec_host,
char *exec_string,
DtCmdInvExecuteProc success_proc,
void *success_data,
DtCmdInvExecuteProc failure_proc,
void *failure_data);
extern SPC_Channel_Ptr _DtSPCOpen( char *hostname,
int iomode,
char *errorMessage); /* MODIFIED */
extern int _DtSPCSpawn(
char *path,
char *context,
char **args,
char **env,
SPC_Channel_Ptr chan,
char *execHost,
char *contextHost,
char *contextDir,
char *errorMessage); /* MODIFIED */
#endif /* _CmdInv_h */

View File

@@ -0,0 +1,184 @@
/* $TOG: CmdInvP.h /main/5 1998/07/30 12:10:30 mgreess $ */
/***************************************************************************
*
* File: CmdInvP.h
* Description: Command execution system private externs and includes
* Language: C
*
** (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 _CmdInvP_h
#define _CmdInvP_h
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/param.h> /* MAXPATHNAMELEN */
#include <X11/Intrinsic.h>
#include <Dt/DtP.h>
#include <Dt/DtNlUtils.h>
#include <Dt/Message.h>
#include <bms/SbEvent.h>
#include <bms/XeUserMsg.h>
#include <Dt/Spc.h>
#include <Dt/CmdInv.h>
#include <Dt/ActionP.h>
#include <Dt/Connect.h>
#ifndef CDE_INSTALLATION_TOP
#define CDE_INSTALLATION_TOP "/opt/dt"
#endif
/*
* Resource names and classes for the Command Invoker.
*/
#define DtLOCAL_TERMINAL_NAME "localTerminal"
#define DtLOCAL_TERMINAL_CLASS "LocalTerminal"
#define DtREMOTE_TERMINALS_NAME "remoteTerminals"
#define DtREMOTE_TERMINALS_CLASS "RemoteTerminals"
#define DtWAIT_TIME_NAME "waitTime"
#define DtWAIT_TIME_CLASS "WaitTime"
#define DtDTEXEC_PATH_NAME "dtexecPath"
#define DtDTEXEC_PATH_CLASS "DtexecPath"
#define DtEXECUTION_HOST_LOGGING_NAME "executionHostLogging"
#define DtEXECUTION_HOST_LOGGING_CLASS "ExecutionHostLogging"
/*
* Structure for saving the "state" of a remote request that is
* queued while waiting for a remote subprocess to terminate.
*/
typedef struct _Cmd_RequestQueue {
SPC_Channel_Ptr channel;
char *context;
char *exec_host;
char *exec_string;
char **argv;
int winType;
unsigned long request_num;
DtSvcMsgContext replyContext;
DtCmdInvExecuteProc success_proc;
void *success_data;
DtCmdInvExecuteProc failure_proc;
void *failure_data;
struct _Cmd_RequestQueue *next;
} Cmd_RequestQueue;
/*
* Command invocation resources.
*/
typedef struct {
char *localTerminal;
char **remoteHosts;
char **remoteTerminals;
int waitTime;
char *dtexecPath;
Boolean executionHostLogging;
} Cmd_Resources;
/*
* Command invocation global variables.
*/
typedef struct {
Boolean terminal_ok;
Boolean subprocess_ok;
XtAppContext app_context;
char **path_list;
char *error_directory_name_map;
char *error_subprocess;
char *error_terminal;
} Cmd_Globals;
/*
* Defaults for the Resources.
*/
#define DtWAIT_TIME_DEFAULT 3 /* In seconds. */
#define DtTERMINAL_DEFAULT "dtterm"
#define DtCMD_INV_SUB_PROCESS CDE_INSTALLATION_TOP "/bin/dtexec"
/*
* Temporary buffer size.
*/
#define MAX_BUF_SIZE 1024
/*
* Window types:
*/
#define NO_STDIO 0
#define TERMINAL 1
#define PERM_TERMINAL 2
/*
* Command execution return status:
*/
#define _CMD_EXECUTE_SUCCESS 1
#define _CMD_EXECUTE_FAILURE 2
#define _CMD_EXECUTE_QUEUED 3
#define _CMD_EXECUTE_FATAL 4
/*
* External declarations for the global Command Invoker variables.
*/
extern Cmd_Resources cmd_Resources;
extern Cmd_Globals cmd_Globals;
/*
******* Public Function Declarations for CmdSpc.c *******
*/
extern SbInputId _DtCmdSPCAddInputHandler (
int fd,
SbInputCallbackProc proc,
void *data);
extern SbInputId _DtCmdSPCAddExceptionHandler (
int fd,
SbInputCallbackProc proc,
void *data);
extern void _DtCmdLogErrorMessage(
char *message) ;
/*
******* Public Function Declarations for CmdProcess.c *******
*/
extern void _DtCmdCreateTerminalCommand(
char **theCommand,
int windowType,
char *execString,
char *execParms,
char *execHost,
char *procId,
char *tmpFiles) ;
extern Boolean _DtCmdCheckForExecutable(
char *fileName) ;
extern Boolean _DtCmdValidDir(
char *clientHost,
char *contextDir,
char *contextHost) ;
extern void _DtCmdGetResources(
Display *display);
/*
******* Public Function Declarations for CmdUtilityP.c *******
*/
extern void _DtCmdBuildPathList( void ) ;
/******** End Public Function Declarations ********/
#endif /* _CmdInvP_h */

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,792 @@
/* $TOG: CmdProcess.c /main/8 1998/04/09 17:47:13 mgreess $ */
/***************************************************************************
*
* File: CmdProcess.c
* Description: Miscellaneous functions for the command execution system
* Language: C
*
** (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.
***************************************************************************/
#include "CmdInvP.h"
#include <X11/Xproto.h>
#include <Dt/CommandM.h>
#include <Dt/DtNlUtils.h>
#include <Dt/ActionUtilP.h>
#include "myassertP.h"
#if defined(sun) || defined(USL) || defined(__uxp__)
#include <limits.h>
#endif
#if defined(__hp_osf) || defined (__osf__)
#include <sys/access.h>
#else
#if defined(__hpux)
#include <sys/getaccess.h>
#endif
#endif
#include <sys/socket.h>
#include <netdb.h>
#include <netinet/in.h>
#include <Tt/tt_c.h>
/*
* Global variables:
*/
Cmd_Resources cmd_Resources = { 0 };
Cmd_Globals cmd_Globals = { 0 };
/******** Static Function Declarations ********/
static char *_GetRemoteTerminalsResource (
Display *display,
char *appClass,
char *appName);
static void GetRemoteTerminalsResource (
Display *display,
char *appClass,
char *appName);
static void GetLocalTerminalResource (
Display *display,
char *appClass,
char *appName);
static void GetWaitTimeResource (
Display *display,
char *appClass,
char *appName);
static void GetDtexecPath (
Display *display,
char *appClass,
char *appName);
static void GetExecutionHostLoggingResource (
Display *display,
char *appClass,
char *appName);
static char *GetRemoteTerminal(
char *host);
/******** End Static Function Declarations ********/
/******************************************************************************
*
* _GetRemoteTerminalsResource - gets the value of the "remoteTerminals"
* resource.
*
* PARAMETERS:
*
* Display *display; The connection to the X server.
*
* char *appClass; The client's application class.
*
* char *appName; The client's application name.
*
* RETURNS: a pointer to the "remoteTerminals" resource or NULL if the
* resource is not defined.
*
* NOTES: The space for the returned string is "malloc'ed". The calling
* function should free the string.
*
*****************************************************************************/
static char
*_GetRemoteTerminalsResource (
Display *display,
char *appClass,
char *appName)
{
XrmValue resource_value;
XrmDatabase db;
char *rep_type;
char *name;
char *class;
char *terminals = NULL;
name = XtMalloc (strlen (DtREMOTE_TERMINALS_NAME) + strlen (appName) + 4);
sprintf (name, "%s*%s", appName, DtREMOTE_TERMINALS_NAME);
class = XtMalloc (strlen (DtREMOTE_TERMINALS_CLASS) + strlen (appClass) + 4);
sprintf (class, "%s*%s", appClass, DtREMOTE_TERMINALS_CLASS);
db = XtDatabase (display);
if (XrmGetResource (db, name, class, &rep_type, &resource_value))
terminals = (char *) XtNewString (resource_value.addr);
XtFree (name);
XtFree (class);
return (terminals);
}
/******************************************************************************
*
* GetRemoteTerminalsResource - initializes the "remoteTerminals" resource.
*
* PARAMETERS:
*
* Display *display; The connection to the X server.
*
* char *appClass; The client's application class.
*
* char *appName; The client's application name.
*
* MODIFIED:
*
* char *cmd_Resources.remoteTerminals; - Set to the list of remote
* terminals.
*
* char *cmd_Resources.remoteHosts; - Set to the list of remote hosts..
*
*****************************************************************************/
static void
GetRemoteTerminalsResource (
Display *display,
char *appClass,
char *appName)
{
int num, j;
char *terminals;
char *pch, *host;
if ((terminals = _GetRemoteTerminalsResource (display, appClass, appName))
== NULL) {
/*
* The resource was not specified, and no defaults are set.
*/
cmd_Resources.remoteHosts = (char **) NULL;
cmd_Resources.remoteTerminals = (char **) NULL;
return;
}
/*
* Find out how many terminals are specified by counting the number of
* colons.
*/
for (pch=terminals, num=0; pch != NULL ; ) {
if ((pch = DtStrchr (pch, ':')) != NULL) {
/*
* Move past the ':'.
*/
pch++;
num++;
}
}
if (num == 0) {
/*
* No "host:/terminal" pairs were found.
*/
cmd_Resources.remoteHosts = (char **) NULL;
cmd_Resources.remoteTerminals = (char **) NULL;
return;
}
/*
* Create space for the pointers to the hosts and terminals and
* make room for a NULL terminator.
*
* Note that the host names and terminal names are "vectorized" in
* place by replacing the ':' and ',' characters with '\0'.
*/
cmd_Resources.remoteHosts = (char **) XtMalloc (num * sizeof(char *));
cmd_Resources.remoteTerminals = (char **) XtMalloc (num * sizeof(char *));
for (pch=terminals, j=0; j < num && pch != NULL && *pch != '\0'; j++)
{
host = pch;
if ((pch = DtStrchr (pch, ':')) == NULL)
break;
/*
* Null terminate the host and then move past the ':'.
*/
*pch = '\0';
pch++;
if (*pch == '\0')
/*
* Found a host but nothing followed it.
*/
break;
cmd_Resources.remoteHosts[j] = host;
cmd_Resources.remoteTerminals[j] = pch;
/*
* Find the end of this entry and skip past it.
*/
if ((pch = DtStrchr (pch, ',')) == NULL) {
/*
* This is the last pair, advance "j" and break the loop.
*/
j++;
break;
}
/*
* End the terminal name.
*/
*pch = '\0';
pch++;
}
/*
* NULL terminate the arrays.
*/
cmd_Resources.remoteHosts[j] = (char *) NULL;
cmd_Resources.remoteTerminals[j] = (char *) NULL;
}
/******************************************************************************
*
* GetLocalTerminalResource - initializes the "localTerminal resource.
*
* PARAMETERS:
*
* Display *display; The connection to the X server.
*
* char *appClass; The client's application class.
*
* char *appName; The client's application name.
*
* MODIFIED:
*
* char *cmd_Resources.localTerminal; - Set to the "localTerminal"
* or to DtDEFUALT_TERMINAL.
*
* Boolean cmd_Globals.terminal_ok; - Set to True if "localTerminal"
* is executable and has the correct
* permissions; False otherwise.
*
*****************************************************************************/
static void
GetLocalTerminalResource (
Display *display,
char *appClass,
char *appName)
{
XrmValue resource_value;
char *rep_type;
char *name;
char *class;
XrmDatabase db = XtDatabase (display);
name = XtMalloc (strlen (DtLOCAL_TERMINAL_NAME) + strlen (appName) + 4);
sprintf (name, "%s*%s", appName, DtLOCAL_TERMINAL_NAME);
class = XtMalloc (strlen (DtLOCAL_TERMINAL_CLASS) + strlen (appClass) + 4);
sprintf (class, "%s*%s", appClass, DtLOCAL_TERMINAL_CLASS);
if (XrmGetResource (db, name, class, &rep_type, &resource_value))
cmd_Resources.localTerminal = (char *) XtNewString (resource_value.addr);
else
cmd_Resources.localTerminal = XtNewString (DtTERMINAL_DEFAULT);
/*
* Check to see if the execvp will potentially fail because the
* localTerminal is not accessable or it it is not executable. If not,
* log an error message.
*/
cmd_Globals.terminal_ok = True;
if (!(_DtCmdCheckForExecutable (cmd_Resources.localTerminal))) {
char *errorMessage = XtMalloc(MAX_BUF_SIZE);
cmd_Globals.terminal_ok = False;
if (errorMessage)
{
(void) sprintf (errorMessage,
cmd_Globals.error_terminal,
cmd_Resources.localTerminal);
_DtCmdLogErrorMessage (errorMessage);
XtFree(errorMessage);
}
}
XtFree (name);
XtFree (class);
}
/******************************************************************************
*
* GetWaitTimeResource - initializes the "waitTime" resource.
*
* PARAMETERS:
*
* Display *display; The connection to the X server.
*
* char *appClass; The client's application class.
*
* char *appName; The client's application name.
*
* MODIFIED:
*
* char *cmd_Resources.waitTime; - Set to the "waitTime" resource
* or "True" by default.
*
*****************************************************************************/
static void
GetWaitTimeResource (
Display *display,
char *appClass,
char *appName)
{
XrmValue resource_value;
char *rep_type;
char *name;
char *class;
XrmDatabase db= XtDatabase (display);
cmd_Resources.waitTime = DtWAIT_TIME_DEFAULT;
name = XtMalloc (strlen (DtWAIT_TIME_NAME) + strlen (appName) + 4);
sprintf (name, "%s*%s", appName, DtWAIT_TIME_NAME);
class = XtMalloc (strlen (DtWAIT_TIME_CLASS) + strlen (appClass) + 4);
sprintf (class, "%s*%s", appClass, DtWAIT_TIME_CLASS);
if (XrmGetResource (db, name, class, &rep_type, &resource_value)) {
cmd_Resources.waitTime = atoi (resource_value.addr);
if (cmd_Resources.waitTime < 0)
cmd_Resources.waitTime = DtWAIT_TIME_DEFAULT;
}
XtFree (name);
XtFree (class);
}
/******************************************************************************
*
* GetDtexecPath - initializes the "dtexecPath" resource.
*
* PARAMETERS:
*
* Display *display; The connection to the X server.
*
* char *appClass; The client's application class.
*
* char *appName; The client's application name.
*
* MODIFIED:
*
* char *cmd_Resources.dtexecPath; - Set to the "dtexecPath" resource
* or to DtCMD_INV_SUB_PROCESS.
*
*****************************************************************************/
static void
GetDtexecPath (
Display *display,
char *appClass,
char *appName)
{
XrmValue resource_value;
char *rep_type;
char errorMessage [MAX_BUF_SIZE];
char *name;
char *class;
XrmDatabase db = XtDatabase (display);
name = XtMalloc (strlen (DtDTEXEC_PATH_NAME) + strlen (appName) + 4);
sprintf (name, "%s*%s", appName, DtDTEXEC_PATH_NAME);
class = XtMalloc (strlen (DtDTEXEC_PATH_CLASS) + strlen (appClass) + 4);
sprintf (class, "%s*%s", appClass, DtDTEXEC_PATH_CLASS);
if (XrmGetResource (db, name, class, &rep_type, &resource_value))
cmd_Resources.dtexecPath = (char *) XtNewString (resource_value.addr);
else
cmd_Resources.dtexecPath = XtNewString (DtCMD_INV_SUB_PROCESS);
/*
* Check to see if the execvp will potentially fail because the
* subprocess is not accessable or it it is not executable. If not,
* log an error message.
*/
cmd_Globals.subprocess_ok = True;
if (!(_DtCmdCheckForExecutable (cmd_Resources.dtexecPath))) {
char *errorMessage = XtMalloc(MAX_BUF_SIZE);
cmd_Globals.subprocess_ok = False;
if (errorMessage)
{
(void) sprintf (errorMessage,
cmd_Globals.error_subprocess,
cmd_Resources.dtexecPath);
_DtCmdLogErrorMessage (errorMessage);
XtFree(errorMessage);
}
}
XtFree (name);
XtFree (class);
}
/******************************************************************************
*
* GetExecutionHostLoggingResources - initializes the "executionHostLogging"
*
*
* PARAMETERS:
*
* Display *display; The connection to the X server.
*
* char *appClass; The client's application class.
*
* char *appName; The client's application name.
*
* MODIFIED:
*
* char *cmd_Resources.executionHostLogging;
*
* - Set to the "executionHostLogging" resource or "False" by default.
*
*****************************************************************************/
static void
GetExecutionHostLoggingResource (
Display *display,
char *appClass,
char *appName)
{
XrmValue resource_value;
char *rep_type;
char *name;
char *class;
XrmDatabase db= XtDatabase (display);
cmd_Resources.executionHostLogging = False;
name = XtMalloc (strlen (DtEXECUTION_HOST_LOGGING_NAME) +
strlen (appName) + 4);
sprintf (name, "%s*%s", appName, DtEXECUTION_HOST_LOGGING_NAME);
class = XtMalloc (strlen (DtEXECUTION_HOST_LOGGING_CLASS) +
strlen (appClass) + 4);
sprintf (class, "%s*%s", appClass, DtEXECUTION_HOST_LOGGING_CLASS);
if (XrmGetResource (db, name, class, &rep_type, &resource_value)) {
if (((strcmp (resource_value.addr, "True")) == 0) ||
((strcmp (resource_value.addr, "true")) == 0) ||
((strcmp (resource_value.addr, "TRUE")) == 0))
cmd_Resources.executionHostLogging = True;
else if (((strcmp (resource_value.addr, "False")) == 0) ||
((strcmp (resource_value.addr, "false")) == 0) ||
((strcmp (resource_value.addr, "FALSE")) == 0))
cmd_Resources.executionHostLogging = False;
}
XtFree (name);
XtFree (class);
}
/******************************************************************************
*
* GetRemoteTerminal - takes a host name "host" and searches the list of remote
* host:terminal pairs for "host" and if found, returns the corresponding
* terminal emulator.
*
* PARAMETERS:
*
* char *host; - Name of the host to use as the key to find
* the terminal emulator name.
*
* RETURNS: If "host" is found, the corresponding terminal emulator is
* returned, otherwise "NULL" is returned.
*
*****************************************************************************/
static char *
GetRemoteTerminal(
char *host )
{
int i;
if (cmd_Resources.remoteHosts == NULL)
return (NULL);
for (i=0; cmd_Resources.remoteHosts[i] != NULL; i++) {
if ((strcmp (host, cmd_Resources.remoteHosts[i])) == 0)
return (cmd_Resources.remoteTerminals[i]);
}
return (NULL);
}
/******************************************************************************
*
* _DtCmdCreateTerminalCommand - takes a windowType, execString
* and execParms and creates an appropriate command to execute.
*
* Note that if valid execParms are found, they are simply added
* to the execution string, before the "-e" option.
*
* PARAMETERS:
*
* char **theCommand; - The command line to be expanded and returned.
* int windowType; - The request number (window number).
* char *execString; - The execution string to be expanded.
* char *execParms; - The execution parameters.
* char *procId - tooltalk procId for dtexec
* char *tmpFiles - string containing tmp file args for dtexec
*
* MODIFIED:
*
* char ** theCommand; - Contains the completed execution string.
*
*****************************************************************************/
void
_DtCmdCreateTerminalCommand(
char **theCommand,
int windowType,
char *execString,
char *execParms,
char *execHost,
char *procId,
char *tmpFiles)
{
char *pGeom = NULL;
char *pName = NULL;
char *pTitle = NULL;
char options[MAX_BUF_SIZE];
char *defaultTerminal;
strcpy(options,execParms);
/*
* Get the name of the terminal emulator to use.
*/
if ((defaultTerminal = GetRemoteTerminal (execHost)) == NULL)
defaultTerminal = cmd_Resources.localTerminal;
/*
* Create space for the expanded command line.
*/
*theCommand = (char *) XtMalloc ( strlen (defaultTerminal)
+ strlen(options)
+ strlen(cmd_Resources.dtexecPath)
+ strlen(" -open ") + 4 /* max waitTime len */
+ strlen(" -ttprocid ") + strlen(_DtActNULL_GUARD(procId))
+ strlen(_DtActNULL_GUARD(tmpFiles))
+ strlen(execString) + 9 /* 2 quotes, "-e", 7 blanks, null */ );
if (windowType == TERMINAL) {
(void) sprintf (*theCommand, "%s %s -e %s -open %d -ttprocid '%s' %s %s",
defaultTerminal, options, cmd_Resources.dtexecPath,
cmd_Resources.waitTime,
_DtActNULL_GUARD(procId),
_DtActNULL_GUARD(tmpFiles),
execString);
}
else {
(void) sprintf (*theCommand, "%s %s -e %s -open -1 -ttprocid '%s' %s %s",
defaultTerminal, options, cmd_Resources.dtexecPath,
_DtActNULL_GUARD(procId),
_DtActNULL_GUARD(tmpFiles),
execString);
}
}
/******************************************************************************
*
* _DtCmdCheckForExecutable - checks "fileName" to see if it is executable
* by the user.
*
* PARAMETERES:
*
* char *fileName; - The name of the file to check.
*
* RETURNS: "True" if the file is access'able && executable, "False" otherwise.
*
*****************************************************************************/
Boolean
_DtCmdCheckForExecutable(
char *fileName )
{
char **ppch;
int access;
/* First check to see if the fileName contains the complete path
* and is access'able.
*/
switch (access = _DtExecuteAccess(fileName))
{
/* execution access allowed for this process */
case 1: return True;
break;
/* file found -- not executable by this process */
case 0: return False;
break;
/* file not found -- yet */
case -1: /* fall through */
default:
break;
}
/* Append fileName to each entry in "cmd_Globals.path_list" and then see
* if that is accessable.
*/
for (ppch = cmd_Globals.path_list; *ppch != NULL; ppch++)
{
char *longName = XtMalloc(MAXPATHLEN);
if (longName)
{
(void) sprintf (longName, "%s/%s", *ppch, fileName);
switch (access = _DtExecuteAccess(longName))
{
/* execution access allowed for this process */
case 1: return True;
break;
/* file found -- not executable by this process */
case 0: return False;
break;
/* file not found -- yet */
case -1: /* fall through */
default:
break;
}
XtFree(longName);
}
}
return (False);
}
/******************************************************************************
*
* _DtCmdValidDir - takes the client host, context directory and a context host
* and checks to see if the directory is valid.
*
* PARAMETERS:
*
* char *clientHost; - Host where the client is running.
*
* char *contextDir; - Directory to "chdir" to.
*
* char *contextHost; - Host where 'contextDir' resides.
*
* NOTES:
*
* If the context directory is NULL, "chdir" is not run and "True" is
* returned.
*
* RETURNS: "True" if "chdir" succeeds and "False" otherwise.
*
*****************************************************************************/
Boolean
_DtCmdValidDir(
char *clientHost,
char *contextDir,
char *contextHost )
{
int retValue = 0;
if (contextDir == NULL)
/*
* Stay in the same directory.
*/
return (True);
if (contextHost == NULL)
/*
* Change to 'contextDir'.
*/
retValue = chdir (contextDir);
else if (_DtIsSameHost (clientHost, contextHost))
/*
* Just change to 'contextDir'.
*/
retValue = chdir (contextDir);
else {
/*
* Need to create a pathname for the directory.
*/
char *netfile;
char *path;
char *errorMessage = XtMalloc(MAX_BUF_SIZE);
/* Old syntax should no longer appear in contextHost/Dir */
myassert( *contextHost != '*' && *contextDir != '*' );
netfile = (char *) tt_host_file_netfile (contextHost, contextDir);
if (tt_pointer_error (netfile) != TT_OK) {
(void) sprintf (errorMessage, cmd_Globals.error_directory_name_map,
contextDir, contextHost,
tt_status_message (tt_pointer_error(netfile)));
_DtCmdLogErrorMessage (errorMessage);
return (False);
}
path = (char *) tt_netfile_file (netfile);
tt_free (netfile);
if (tt_pointer_error (path) != TT_OK) {
(void) sprintf (errorMessage, cmd_Globals.error_directory_name_map,
contextDir, contextHost,
tt_status_message (tt_pointer_error(path)));
_DtCmdLogErrorMessage (errorMessage);
return (False);
}
retValue = chdir (path);
tt_free (path);
if (errorMessage) XtFree(errorMessage);
}
if (retValue == -1)
return (False);
else
return (True);
}
/******************************************************************************
*
* _DtCmdGetResources - initializes the Command Invoker's resources.
*
* PARAMETERS:
*
* Display *display; The connection to the X server.
*
* char *appClass; The client's application class.
*
*****************************************************************************/
void
_DtCmdGetResources (
Display *display)
{
char *appClass = NULL;
char *appName = NULL;
/*
* Determine the name and class for this client.
*/
XtGetApplicationNameAndClass (display, &appName, &appClass);
GetLocalTerminalResource (display, appClass, appName);
GetRemoteTerminalsResource (display, appClass, appName);
GetWaitTimeResource (display, appClass, appName);
GetDtexecPath (display, appClass, appName);
GetExecutionHostLoggingResource (display, appClass, appName);
}

View File

@@ -0,0 +1,99 @@
/* $XConsortium: CmdSpc.c /main/4 1995/10/26 15:02:34 rswiston $ */
/***************************************************************************
*
* File: CmdSpc.c
* Description: Messaging support for the command execution system.
* Language: C
*
** (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.
***************************************************************************/
#include "CmdInvP.h"
#include <Dt/UserMsg.h>
#include <Dt/CommandM.h>
/******************************************************************************
*
* _DtCmdSPCAddInputHandler - Register the Command Invoker AddInputHandler
*
* PARAMETERS: Those need by a SPC Add Input Handler.
*
* NOTES:
*
* This function is needed by SPC to get a process termination
* callback to get invoked.
*
*****************************************************************************/
SbInputId
_DtCmdSPCAddInputHandler (
int fd,
SbInputCallbackProc proc,
void *data)
{
if (cmd_Globals.app_context == NULL)
return(XtAddInput(fd,
(XtPointer) XtInputReadMask,
proc,
data));
else
return(XtAppAddInput(cmd_Globals.app_context,
fd,
(XtPointer) XtInputReadMask,
proc,
data));
}
/******************************************************************************
*
* _DtCmdSPCAddExceptionHandler - Register the Command Invoker AddExceptionHandler
*
* PARAMETERS: Those need by a SPC Add Exception Input Handler.
*
* NOTES:
*
* This function is needed by SPC to get a process termination
* callback to get invoked.
*
*****************************************************************************/
SbInputId
_DtCmdSPCAddExceptionHandler (
int fd,
SbInputCallbackProc proc,
void *data)
{
if (cmd_Globals.app_context == NULL)
return(XtAddInput(fd,
(XtPointer) XtInputExceptMask,
proc,
data));
else
return(XtAppAddInput(cmd_Globals.app_context,
fd,
(XtPointer) XtInputExceptMask,
proc,
data));
}
/******************************************************************************
*
* _DtCmdLogErrorMessage - write an error message to the default log file.
*
* PARAMETERS:
*
* char *message; - The error message to log.
*
*****************************************************************************/
void
_DtCmdLogErrorMessage(
char *message )
{
_DtSimpleError (DtProgName, DtError, NULL, "%.2000s", message);
}

View File

@@ -0,0 +1,96 @@
/* $XConsortium: CmdUtilityP.c /main/4 1995/10/26 15:02:50 rswiston $ */
/***************************************************************************
*
* File: CmdUtilityP.c
* Description: Private Utility routines for the command invocation system.
* Language: C
*
** (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.
***************************************************************************/
#include "CmdInvP.h"
#include <stdio.h>
#include <sys/param.h>
#ifdef __apollo
#include "/sys5/usr/include/unistd.h"
#else
#include <unistd.h>
#endif
#include <limits.h>
#include <sys/stat.h>
#include <X11/Xlib.h>
#include <X11/Intrinsic.h>
#include <Dt/CommandM.h>
/*****************************************************************************
*
* _DtCmdBuildPathList - this functions builds a list of the path names
* that are part of the $PATH environment variable. This is done once
* during initialization and the list is then searched whenever
* a command is going to be executed.
*
* MODIFIED:
*
* char **cmd_Globals.path_list; - Initialized or set to NULL if
* $PATH is undefined
*
*****************************************************************************/
void
_DtCmdBuildPathList( void )
{
int i=0;
char *path;
int indx;
int n=0, pathLen;
char *pend, /* Points to the beginning of a directory */
*pbeg; /* Points to the end of a directory */
/* Get the PATH */
if ((path = (char *) (getenv ("PATH"))) == NULL) {
cmd_Globals.path_list = (char **) NULL;
return;
}
pathLen = strlen(path);
pbeg = path;
while (i < pathLen) {
n++;
cmd_Globals.path_list = (char **) XtRealloc ((char *)cmd_Globals.path_list, n * sizeof (char *));
if ((indx = DtStrcspn (pbeg, ":")) >= pathLen) {
/* At the end of the path */
i = pathLen;
pend = (char *) pbeg + indx;
}
else {
/* Found a ":" */
pend = (char *) pbeg + indx;
i += (pend - pbeg) +1;
}
cmd_Globals.path_list[n-1] = (char *) XtMalloc (((pend - pbeg) + 1) *
sizeof(char));
(void) strncpy (cmd_Globals.path_list[n-1], pbeg, (pend - pbeg));
/* Strncpy does not put a '\0' at the EOS if s2 >= s1 */
cmd_Globals.path_list[n-1][pend-pbeg] = '\0';
/* Move past the ":" */
if (i < pathLen)
pbeg = pend +1;
}
/* May need to NULL terminate cmd_Globals.path_list */
if (n > 0) {
n++;
cmd_Globals.path_list = (char **) XtRealloc ((char *) cmd_Globals.path_list, n * sizeof (char *));
cmd_Globals.path_list [n-1] = (char *) NULL;
}
}

View File

@@ -0,0 +1,304 @@
/*
* +SNOTICE
*
* $XConsortium: DbLoad.c /main/7 1996/08/28 14:38:07 rswiston $
*
* RESTRICTED CONFIDENTIAL INFORMATION:
*
* The information in this document is subject to special restrictions in a
* confidential disclosure agreement bertween HP, IBM, Sun, USL, SCO and
* Univel. Do not distribute this document outside HP, IBM, Sun, USL, SCO,
* or Univel wihtout Sun's specific written approval. This documment and all
* copies and derivative works thereof must be returned or destroyed at Sun's
* request.
*
* Copyright 1993 Sun Microsystems, Inc. All rights reserved.
*
* +ENOTICE
*/
/* *
* (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. *
*/
#include <stdio.h>
#include <sys/types.h>
#ifdef __hpux
#include <ndir.h>
#else
#if defined(sun) || defined(USL) || defined(sco) || defined(__uxp__)
#include <dirent.h>
#else
#include <sys/dir.h>
#endif /* sun || USL */
#endif /* __hpux */
#include <ctype.h>
#include <string.h>
#ifdef NLS16
#include <limits.h>
#endif
#include <sys/stat.h>
#include <sys/param.h> /* MAXPATHLEN, MAXHOSTNAMELEN */
#include <X11/Xlib.h>
#include <X11/Intrinsic.h>
#include <X11/StringDefs.h>
#include <Dt/DtP.h>
#include <Dt/Connect.h>
#include <Dt/FileUtil.h>
#include <Dt/DtNlUtils.h>
#include <Dt/Action.h>
#include <Dt/ActionDbP.h>
#include <Dt/ActionP.h>
#include <Dt/ActionFind.h>
#include <Dt/DbUtil.h>
#include <Dt/DtPStrings.h>
#include <Dt/Utility.h>
#include <Dt/DtsDb.h>
#include <Dt/Dts.h>
#include "myassertP.h"
#include "DtSvcLock.h"
extern void _DtDtsDCConverter(DtDtsDbField * fields,
DtDbPathId pathId,
char *hostPrefix,
Boolean rejectionStatus);
extern void _DtDtsDAConverter(DtDtsDbField * fields,
DtDbPathId pathId,
char *hostPrefix,
Boolean rejectionStatus);
extern void _DtDtsSeqReset(void);
extern int _DtDtsNextDCSeq(void);
extern int _DtDtsNextDASeq(void);
int use_in_memory_db = False;
static void
_DtOAConverter(DtDtsDbField * fields,
DtDbPathId pathId,
char *hostPrefix,
Boolean rejectionStatus)
{
DtDtsDbDatabase *dc_db;
DtDtsDbDatabase *da_db;
DtDtsDbRecord *dc_rec;
DtDtsDbRecord *da_rec;
DtDtsDbField *fld;
_DtSvcProcessLock();
dc_db = _DtDtsDbGet(DtDTS_DC_NAME);
da_db = _DtDtsDbGet(DtDTS_DA_NAME);
if ( _DtDtsDbGetRecordByName(dc_db,
fields[0].fieldValue) ||
_DtDtsDbGetRecordByName(da_db,
fields[0].fieldValue))
{
_DtSvcProcessUnlock();
return;
}
/*
* Synthesize criteria record -- for this action
*/
dc_rec = _DtDtsDbAddRecord(_DtDtsDbGet(DtDTS_DC_NAME));
dc_rec->recordName = XrmStringToQuark(fields[0].fieldValue);
dc_rec->seq = _DtDtsNextDCSeq();
dc_rec->pathId = (int)pathId;
fld = _DtDtsDbAddField(dc_rec);
fld->fieldName = XrmStringToQuark(DtDTS_NAME_PATTERN);
fld->fieldValue = strdup(fields[0].fieldValue);
fld = _DtDtsDbAddField(dc_rec);
fld->fieldName = XrmStringToQuark(DtDTS_MODE);
fld->fieldValue = strdup("fx");
fld = _DtDtsDbAddField(dc_rec);
fld->fieldName = XrmStringToQuark(DtDTS_DATA_ATTRIBUTES_NAME);
fld->fieldValue = strdup(fields[0].fieldValue);
/*
* Mark the criteria record as synthetic.
*/
fld = _DtDtsDbAddField(dc_rec);
fld->fieldName = XrmStringToQuark(DtDTS_DA_IS_SYNTHETIC);
fld->fieldValue = strdup("True");
/*
* Synthesize attribute record -- for this action
*/
da_rec = _DtDtsDbAddRecord(_DtDtsDbGet(DtDTS_DA_NAME));
da_rec->recordName = XrmStringToQuark(fields[0].fieldValue);
da_rec->seq = _DtDtsNextDASeq();
da_rec->pathId = (int)pathId;
fld = _DtDtsDbAddField(da_rec);
fld->fieldName = XrmStringToQuark(DtDTS_DA_ACTION_LIST);
fld->fieldValue = strdup(fields[0].fieldValue);
fld = _DtDtsDbAddField(da_rec);
fld->fieldName = XrmStringToQuark(DtDTS_DA_DATA_HOST);
fld->fieldValue = strdup(hostPrefix);
/*
* Mark the attribute record as synthetic.
*/
fld = _DtDtsDbAddField(da_rec);
fld->fieldName = XrmStringToQuark(DtDTS_DA_IS_SYNTHETIC);
fld->fieldValue = strdup("True");
fld = _DtDtsDbAddField(da_rec);
fld->fieldName = XrmStringToQuark(DtDTS_DA_IS_ACTION);
fld->fieldValue = strdup("True");
fld = _DtDtsDbAddField(da_rec);
fld->fieldName = XrmStringToQuark(DtDTS_DA_IS_TEXT);
fld->fieldValue = strdup("False");
/*
* Use the action name as the default copy_to action
*/
fld = _DtDtsDbAddField(da_rec);
fld->fieldName = XrmStringToQuark(DtDTS_DA_COPY_TO_ACTION);
fld->fieldValue = strdup(fields[0].fieldValue);
_DtSvcProcessUnlock();
}
/******************************************************************************
*
* DtDbLoad -
*
* Reads in the file types and action databases.
* From the Default DtDatabaseDirPaths.
*
*****************************************************************************/
void _DtDbLoad(DtDirPaths *dirs)
{
_DtDtsMMUnLoad();
}
void
DtDbLoad(void)
{
DtDirPaths *dirs;
/* Load the requested database files */
dirs = _DtGetDatabaseDirPaths();
_DtDbLoad(dirs);
_DtFreeDatabaseDirPaths(dirs);
}
/******************************************************************************
*
* _DtDbLoad(dirs) -
*
* Reads in the file types and action databases.
* From the the given directory path. This function is not part of the
* public API but may be used internally to avoid repeated generation of
* the default databasedir path.
*
*****************************************************************************/
int
_DtDtsMMCreateDb(DtDirPaths *dirs, const char *CacheFile, int override)
{
DtDbRecordDesc recordDescriptions[3];
DtDbConverter criteriaConverters[2];
DtDbConverter attributesConverters[2];
DtDbConverter actionConverters[3];
static int beenCalled = 0;
char **list;
int i;
_DtSvcProcessLock();
use_in_memory_db = TRUE;
if ( beenCalled ) {
/*
* Free up existing database.
*/
_DtDtsSeqReset();
DtDtsRelease();
_DtFreeActionDB();
}
beenCalled = 1;
/*
* Initialize the databases
* -- this call will initializae the Object databases then
* add the action database.
*/
(void) _DtDtsDbAddDatabase(_DtACTION_NAME);
if ( !dirs )
{
myassert(dirs); /* register an assertion failure */
_DtSvcProcessUnlock();
return(0);
}
/* Build up the record descriptions */
criteriaConverters[0] = (DtDbConverter) _DtDtsDCConverter;
criteriaConverters[1] = NULL;
recordDescriptions[0].recordKeyword = DtDTS_DC_NAME;
recordDescriptions[0].maxFields = _DtMAX_NUM_FIELDS;
recordDescriptions[0].converters = criteriaConverters;
/* Build up the ot record descriptions */
attributesConverters[0] = (DtDbConverter) _DtDtsDAConverter;
attributesConverters[1] = NULL;
recordDescriptions[1].recordKeyword = DtDTS_DA_NAME;
recordDescriptions[1].maxFields = _DtMAX_NUM_FIELDS;
recordDescriptions[1].converters = attributesConverters;
actionConverters[0] = (DtDbConverter) _DtActionConverter;
actionConverters[1] = (DtDbConverter) _DtOAConverter;
actionConverters[2] = NULL;
recordDescriptions[2].recordKeyword = _DtACTION_NAME;
recordDescriptions[2].maxFields = _ActDb_MAX_NUM_FIELDS;
recordDescriptions[2].converters = actionConverters;
_DtDbRead(dirs, ".dt", recordDescriptions, 3);
_DtSortActionDb();
/*
* we may eventually want to return a count of the new records.
* for now we return a non-zero value to register success.
*/
if ((!_DtDtsMMCreateFile(dirs, CacheFile)) ||
(!_DtDtsMMapDB(CacheFile)))
{
_DtSvcProcessUnlock();
return(0);
}
if(!override)
{
unlink(CacheFile);
}
/* now that we have built the databases delete the tmp Db memory
used for it (Too, bad we can't delete the memory associcated
with the Quarks) */
list = (char **)_DtsDbListDb();
for(i = 0; list[i]; i++)
{
_DtDtsDbDeleteDb(_DtDtsDbGet(list[i]));
free(list[i]);
}
free(list);
use_in_memory_db = FALSE;
_DtSvcProcessUnlock();
return(1);
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,166 @@
/*
* File: DbReader.h $XConsortium: DbReader.h /main/4 1995/10/26 15:03:35 rswiston $
*
* Description: Public include file for the database reader.
*
* (c) Copyright 1987, 1988, 1989 by Hewlett-Packard Company
*
* (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 _Dt_DbReader_h
#define _Dt_DbReader_h
#include <X11/Xlib.h>
#include <X11/Xresource.h>
#include <Dt/DbUtil.h>
#define DTRECORDIDENTIFIER NULL
#define DTUNLIMITEDFIELDS 0
/* one set of attribute/pair */
typedef struct
{
XrmQuark fieldName;
char *fieldValue;
} DtDtsDbField;
/*
* Opaque identifier used for identifying a database file name. The opaque
* identifier can be converted to an ascii string, using the function
* _DtDbPathIdToString().
*/
#define DtDbPathId long
/*
* All record converters should expect to be called with the parameters
* indicated below:
*
* fields: This is an array of keyword/value pair strings, each
* representing one field value for this database record. NOTE:
* the keywords have not been validated; this is the
* responsibility of the converter, and is usually accomplished
* by calling _DtValidateFieldNames(). The array is NULL
* terminated, with the last entry having both the 'fieldName'
* and 'fieldValue' pointers set to NULL. The first entry always
* represents the record identifier, with the 'fieldName' set
* to the record type string, and the 'fieldValue' set to any
* remaining data specified on the record identifier line.
*
* pathId: Is an opaque identifier, which can be used to retrieve the name
* of the database file from which this record was obtained. By
* calling _DtDbPathIdToString(), the database file, in
* "host:/path" format, can be obtained.
*
* hostPrefix: If the database file was loaded from a machine other than the
* local machine, then this string indicates the host prefix, in
* "/nfs/<host>" format. If the host was the local host, then
* this value is set to NULL.
*
* rejectionStatus: This flag indicates whether any of the earlier record
* converters had rejected this entry. Certain classes
* of converters may choose to ignore entries if they
* had already been rejected.
*
* It is the responsibility of the converter to perform any necessary
* verification of the passed in set of keywords; the function
* _DtValidateFieldNames() is provided as a convenience function for performing
* this type of validation. Typically, the converter will write an error to
* the user's errorlog file, if an invalid record is encountered.
*
* It is also the responsibility of the converter to allocate any memory needed
* to store the new record. The strings contained within the 'fields' array
* will all be freed when the converter returns to _DtDbRead(), so the
* converter should make copies of any information it wishes to use in the
* future. The converter is also responsible for adding the new record to
* whatever storage array it is using to save record information.
*
* If the converter decides to reject the record, then it should return a
* 'True' value. If the record was acceptable, then 'False' should be
* returned.
*/
typedef Boolean (*DtDbConverter) (DtDtsDbField * fields,
DtDbPathId pathId,
char * hostPrefix,
Boolean rejectionStatus);
/*
* This structure defines each record type which should be loaded by
* _DtDbRead(). Since _DtDbRead() is capable of loading multiple record types
* (i.e ACTION, DATA_CRITERIA, etc) in a single pass, the invoking function will
* pass in an array of these structures, for which each element will define a
* record type which should be loaded. Each record definition requires the
* following information:
*
* recordKeyword: This is the keyword which uniquely identifies the record
* which matches this definition. Examples are "ACTION" and
* "DATA_CRITERIA".
*
* maxFields: Indicates the maximum number of fields which is expected
* by this record type; typically, this corresponds to the
* number of distinct field keywords supported by this type
* of record. This feature is used to prevent runaway database
* records from getting out of hand; a runaway database record
* typically occurs when the user forgets to include line
* continuation characters, and a long 'description' field
* is entered. If this parameter is set to
* DTUNLIMITEDFIELDS, then the check for runaway records
* will be disabled for records of this type.
*
* converters: This is a NULL-terminated array of function pointers,
* corresponding to the set of record converters which will
* be called, whenever a record of this type is encountered.
* The converters are called in order, and all converters will
* be called, even if an earlier one rejects the record. The
* last entry in the array must be set to NULL.
*/
typedef struct {
char * recordKeyword;
int maxFields;
DtDbConverter * converters;
} DtDbRecordDesc;
/*
* _DtDbRead() is the function which causes the specified set of directories to
* be searched for files ending with the specified suffix. Although not
* required, the set of directories to search is typically obtained by calling
* _DtGetDatabaseDirPaths(). This function supports the loading of multiple
* field types, all in a single pass of the database files. This function does
* not attempt to manage the memory used to store the information extracted from
* the database files; it is the responsibility of the function calling this
* procedure to initialize any storage, and it is the responsibility of the
* record converters to allocate any memory needed to store and record, along
* with adding the record to the appropriate storage array.
*
* dirs: The set of directories to be searched for database files.
*
* suffix: The file suffix (i.e. ".vf") used to qualify which files within
* the database directories should be loaded.
*
* recordDescriptions: An array, where each entry describes a database record
* which should be loaded during this pass of _DtDbRead().
* See the definition for this structure, for more details.
*
* int numRecordDescriptions: The number of entries in the above array.
*/
extern void _DtDbRead (DtDirPaths * dirs,
char * suffix,
DtDbRecordDesc * recordDescriptions,
int numRecordDescriptions);
/*
* _DtDbPathIdToString() is used to map a filename identifier, represented
* by an opaque DtDbPathId value, into its corresponding ascii string
* representation. The returned string is owned by the calling application,
* which should free it up when no longer needed.
*/
extern char * _DtDbPathIdToString ( DtDbPathId pathId );
#endif /* _Dt_DbReader_h */
/* DON'T ADD ANYTHING AFTER THIS #endif */

View File

@@ -0,0 +1,890 @@
/*
* $TOG: DbUtil.c /main/13 1998/04/09 17:47:56 mgreess $
*
* (c) Copyright 1988, 1989, 1990, 1991, 1992, 1993
* by Hewlett-Packard Company, 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. *
*/
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <dirent.h>
#include <ctype.h>
#include <string.h>
#ifdef NLS16
#include <limits.h>
#endif
#include <sys/stat.h>
#include <sys/param.h> /* MAXPATHLEN, MAXHOSTNAMELEN */
#include <X11/Xlib.h>
#include <X11/Intrinsic.h>
#include <X11/StringDefs.h>
#define X_INCLUDE_DIRENT_H
#define XOS_USE_XT_LOCKING
#include <X11/Xos_r.h>
#include <Dt/DtP.h>
#include <Dt/Connect.h>
#include <Dt/FileUtil.h>
#include <Dt/DtNlUtils.h>
#include <Dt/Action.h>
#include <Dt/ActionP.h>
#include <Dt/ActionDbP.h>
#include <Dt/ActionUtilP.h>
#include <Dt/DbUtil.h>
#include <Dt/Utility.h>
#include <Dt/ActionDb.h>
#ifndef S_ISLNK
/* This macro is normally defined in stat.h, but not on USL systems. */
# define S_ISLNK(_M) ((_M & S_IFMT)==S_IFLNK) /* test for symbolic link */
#endif
#ifndef CDE_INSTALLATION_TOP
#define CDE_INSTALLATION_TOP "/opt/dt"
#endif
#ifndef CDE_CONFIGURATION_TOP
#define CDE_CONFIGURATION_TOP "/etc/opt/dt"
#endif
#define TRUE 1
#define FALSE 0
#define FILE_INCREMENT 20
/* The following string holds the default value of the Dt database
* search path. This default search path has the following major
* components:
*
* $HOME/.dt/types[/%L] A location for the user's personal
* actions and filetypes.
*
* <config-location>/appconfig/types[/%L]
* The DT location for system-wide
* customizations.
*
* <top-of-dt>/types/[%L] The DT location for default
* system-wide actions and filetypes.
*/
static char DTDATABASESEARCHPATH_DEFAULT[] =
"%s/.dt/types/%%L,"
"%s/.dt/types,"
CDE_CONFIGURATION_TOP "/appconfig/types/%%L,"
CDE_CONFIGURATION_TOP "/appconfig/types,"
CDE_INSTALLATION_TOP "/appconfig/types/%%L,"
CDE_INSTALLATION_TOP "/appconfig/types";
/**** Substitution records used by XtFindFile() in _DtExpandLang() ****/
static SubstitutionRec langSubstitutions[] =
{
{'L', (char *)NULL},
{'l', (char *)NULL},
{'t', (char *)NULL},
{'c', (char *)NULL}
};
static int nLangSubstitutions = XtNumber(langSubstitutions);
/******** Static Function Declarations ********/
static Boolean __testPath(
String str );
static void __setupLangSubstitutions(
void );
static void __freeLangSubstitutions(
void );
static char *_DtExpandLang(
char *string ) ;
static char _DtIsDir(
char *path,
char *name) ;
static void _DtFreeDirVector(
char **dir_vector) ;
static void __swap(
int i ,
DtDirPaths *data );
static void _DtSortFiles(
int low,
int n,
DtDirPaths *data) ;
/******** End Static Function Declarations ********/
/******************
*
* Function Name: __testPath
*
* Description:
*
* This function is needed by XtFindFile(). Always returns True.
*
* Synopsis:
*
* path = XtFindFile(..., __testPath);
*
******************/
static Boolean
__testPath(String str)
{
return True;
}
/******************
*
* Function Name: __setupLangSubstitutions
*
* Description:
*
* This function initializes langSubstitutions[] for use by
* XtFindFile().
*
* Synopsis:
*
* __setupLangSubstitutions();
*
******************/
static void
__setupLangSubstitutions(void)
{
char *lang;
char *languagePart;
char *territoryPart;
char *codesetPart;
char *tlPtr, *ttPtr, *tcPtr, *endPtr;
/*
* We should really be calling setlocale to determine the "default"
* locale but setlocale's return value is not standardized across
* the various vendor platforms nor is it consistent within differnt
* revs of individual OS's. (e.g. its changing between HP-UX 9.0 and
* HP-UX 10.0). The "right" call would be the following line:
*
* if ((lang = getenv ("LANG")) || (lang = setlocale(LC_C_TYPE,NULL)))
*
* Here we hard code the default to "C" instead of leaving it NULL.
*/
languagePart = territoryPart = codesetPart = (char *)NULL;
if ((lang = getenv ("LANG")) == (char *)NULL)
lang = "C";
lang = XtNewString(lang); /* free'd in __freeLangSubstitutions() */
tlPtr = lang;
endPtr = (char *)NULL;
if ((ttPtr = DtStrchr(tlPtr, '_')) != (char *)NULL)
ttPtr++;
if ((tcPtr = DtStrchr(ttPtr ? ttPtr : tlPtr, '.')) != (char *)NULL)
{
endPtr = tcPtr++;
if (*tcPtr != '\0')
codesetPart =
XtNewString(tcPtr); /* free'd in __freeLangSubstitutions() */
}
if (ttPtr)
{
if (endPtr)
{
int ttLen = endPtr - ttPtr;
if (ttLen > 0)
{
/* free'd in __freeLangSubstitutions() */
territoryPart = (char *)XtMalloc((ttLen + 1) * sizeof(char));
strncpy(territoryPart, ttPtr, ttLen);
territoryPart[ttLen] = '\0';
}
}
else territoryPart =
XtNewString(ttPtr); /* free'd in __freeLangSubstitutions() */
endPtr = ttPtr - 1;
}
if (endPtr)
{
int tlLen = endPtr - tlPtr;
if (tlLen > 0)
{
/* free'd in __freeLangSubstitutions() */
languagePart = (char *)XtMalloc((tlLen + 1) * sizeof(char));
strncpy(languagePart, tlPtr, tlLen);
languagePart[tlLen] = '\0';
}
}
else languagePart =
XtNewString(tlPtr); /* free'd in __freeLangSubstitutions() */
langSubstitutions[0].substitution = lang;
langSubstitutions[1].substitution = languagePart;
langSubstitutions[2].substitution = territoryPart;
langSubstitutions[3].substitution = codesetPart;
}
/******************
*
* Function Name: __freeLangSubstitutions
*
* Description:
*
* This function free's the strings allocated by
* __setupLangSubstitutions and placed into langSubstitutions[]
*
* Synopsis:
*
* __freeLangSubstitutions();
*
******************/
static void
__freeLangSubstitutions(void)
{
int i;
for (i = 0; i < nLangSubstitutions; i++)
XtFree(langSubstitutions[i].substitution);
}
/******************
*
* Function Name: _DtExpandLang
*
* Description:
*
* This function takes the string "string", and performs the following
* replacements:
* %L : contents of LANG environment variable.
* %l : language part of the LANG environment variable.
* %t : territory part of the LANG environment variable.
* %c : codeset part of the LANG environment variable.
* %% : % (e.g. %%L would be replaced by %L, and
* no substitution would be performed on %L)
*
* If $LANG is not defined, the $LANG is assumed to be "C".
*
* Synopsis:
*
* ret_string = _DtExpandLang (string);
*
* char *ret_string; Returns NULL if "string" is NULL, or it points
* to the expanded string.
*
* char *string; The comma-separated pathnames to expand.
*
* Note: The caller is responsible for free'ing the returned string.
*
******************/
static char *
_DtExpandLang(
char *string )
{
char *thisPath;
char *newPath;
char *modPath;
int pathLen, maxPathLen;
int nColons;
char *tmpPtr, *tmpPtr1;
char *newString;
char *tokPtr;
if (string == NULL)
return (NULL);
/*
* We're going to use XtFindFile() to perform the replacements;
* the colon character ':' is used as a delimiter in XtFindFile,
* so we escape all colon characters in our string before
* passing it along.
*/
for (nColons = 0, tmpPtr = string;
(tmpPtr = DtStrchr(tmpPtr, ':')) != (char *)NULL;
nColons++, tmpPtr++)
/* EMPTY */
;
newString =
(char *)XtCalloc(1, (strlen(string) + nColons + 1) * sizeof(char));
for (tmpPtr = string;
(tmpPtr1 = DtStrchr(tmpPtr, ':')) != (char *)NULL;
tmpPtr = tmpPtr1 + 1)
{
strncat(newString, tmpPtr, tmpPtr1 - tmpPtr);
strcat(newString, "%:");
}
strcat(newString, tmpPtr);
__setupLangSubstitutions();
/*
* XtFindFile() assumes that the string into which it's making
* substitutions is a path, and therefore it assumes that the
* length of the string does not exceed MAXPATHLEN. Since
* our string is a series of paths, it CAN exceed MAXPATHLEN.
* So, we split our string into individual paths which we then
* pass off to XtFindFile().
*/
pathLen = maxPathLen = 0;
newPath = (char *)NULL;
for (thisPath = DtStrtok_r(newString, ",", &tokPtr);
thisPath != (char *)NULL;
thisPath = DtStrtok_r((char *)NULL, ",", &tokPtr))
{
modPath = XtFindFile(thisPath, langSubstitutions,
nLangSubstitutions, __testPath);
if (modPath)
{
char *origPath = modPath;
int modLen;
/*
* For some reason, XtFindFile() collapses all '/'
* characters EXCEPT at the beginning of the path!
* For backwards compatibility, we collapse those here.
*/
if (*modPath == '/')
{
while (*(modPath + 1) == '/')
modPath++;
}
modLen = strlen(modPath);
if (pathLen + modLen + 2 > maxPathLen)
{
maxPathLen =
((pathLen + modLen + 2 + MAXPATHLEN) / MAXPATHLEN) *
MAXPATHLEN;
newPath =
(char *)XtRealloc(newPath, maxPathLen * sizeof(char));
}
if (pathLen > 0)
newPath[pathLen++] = ',';
strcpy(&(newPath[pathLen]), modPath);
pathLen += modLen;
XtFree(origPath);
}
}
__freeLangSubstitutions();
XtFree(newString);
return newPath;
}
/******************
*
* Function Name: _DtIsDir
*
* Description:
*
* This function tests a pathname to see if it is a directory.
* The path name is received in two pieces, which makes it easy
* for the calling function to test a bunch of files in a directory
* to see if any are subdirectories.
*
* This function does NOT handle Softbench-style pathnames with
* embedded hostnames.
*
* Synopsis:
*
* dir = _DtIsDir (path, name);
*
* char dir; Returns 0 if the item is not a directory,
* 1 if it is.
* char *path; The first part of the pathname. Typically
* the directory containing the item of interest.
* char *name; The second half of the pathname. Typically
* the name of the item of interest.
*
******************/
static char
_DtIsDir(
char *path,
char *name )
{
struct stat stat_buf;
char *stat_name;
stat_name = XtMalloc ((Cardinal)(strlen(path) + strlen(name) + 2));
(void)strcpy (stat_name, path);
(void)strcat (stat_name, "/");
(void)strcat (stat_name, name);
if(stat (stat_name, &stat_buf))
{
stat_buf.st_mode = 0;
}
XtFree (stat_name);
if (stat_buf.st_mode & S_IFDIR)
return (TRUE);
else
return (FALSE);
}
/******************************
*
* Function Name: _DtFreeDirVector
*
* Description:
*
* This function frees a database-directory string vector.
*
* Synoposis:
*
* FreeDatabaseDirs (dirs);
*
* char **dirs; The string vector to free.
*
********************************/
static void
_DtFreeDirVector(
char **dir_vector )
{
char **v;
if (dir_vector)
{
for (v = dir_vector; *v != NULL; v++)
XtFree ((char *)*v);
XtFree ((char *)dir_vector);
}
}
/******************************
*
* Function Name: __swap
*
* Description:
*
* This function exchanges two elements in an array of DtDirPaths.
*
* Synoposis:
*
* __swap (i, data);
*
* int i; The base index to change.
* DtDirPaths *data; The data to change.
*
********************************/
static void
__swap(
int i ,
DtDirPaths *data )
{
char *tmp;
/* The "names" field of the structure is not touched because
* this field is "NULL" for all of the entries.
*/
tmp = data->dirs[i];
data->dirs[i] = data->dirs[i+1]; data->dirs[i+1] = tmp;
tmp = data->paths[i];
data->paths[i] = data->paths[i+1]; data->paths[i+1] = tmp;
}
/******************************
*
* Function Name: _DtSortFiles
*
* Description:
*
* Given an index, an array of "char" data and the number of elements to
* sort, this function sorts the data. The sorting algorithm is based
* on a bubble sort because the number of elements is usually less than
* ten.
*
* Synoposis:
*
* _DtSortFiles (index, n, data);
*
* int low; The base of the array to begin the sorting.
* int n; The number of elements to sort.
* DtDirPaths *data; The data to sort.
*
********************************/
static void
_DtSortFiles(
int low,
int n,
DtDirPaths *data )
{
int i, j;
int high = low + n;
/*
* This sorting routine needs to be able to sort any portion of
* an array - it does not always start at element '0'.
*/
for (i = low; i < (high - 1); i++)
for (j = low; j < (high - 1); j++)
#ifndef NO_MESSAGE_CATALOG
if ((strcoll (data->paths[j], data->paths[j+1])) > 0)
#else
if ((strcmp (data->paths[j], data->paths[j+1])) > 0)
#endif
__swap (j, data);
}
/******************
*
* Function Name: _DtFindMatchingFiles
*
* Description:
*
* This function takes a string vector of directory names (which
* are in "host:/path/file" format) and a filename suffix and
* finds all of the files in those directories with the specified
* suffix. It returns a string vector of the filenames.
*
* You will typically first call _DtGetDatabaseDirPaths() to get the
* 'dirs' info.
*
* Use _DtFreeDatabaseDirPaths() to free up the return structure.
*
* Synopsis:
*
* filev = _DtFindMatchingFiles (dirs, suffix, sort_files);
*
* DtDirPaths *filev; A structure containing the names
* of all the files that were found.
* DtDirPaths *dirs; A structure of directories to be
* searched.
* char *suffix; The suffix string which is compared
* to the end of the filenames. This
* string must contain a "." if it is
* part of the suffix you want to match
* on (e.g. ".c").
* Boolean sort_files; Should the files within a directory be sorted.
*
*
******************/
DtDirPaths *
_DtFindMatchingFiles(
DtDirPaths *dirs,
char *suffix,
Boolean sort_files )
{
/* LOCAL VARIABLES */
register DtDirPaths *files; /* An array of pointers to the filenames which
have been found. */
int max_files; /* The total number of filenames that can be
stored in the "files" array before it must
be reallocd. */
int num_found; /* The number of files which have been found. */
register DIR *dirp; /* Variables for walking through the directory
entries. */
char * next_file;
struct dirent *dp = NULL;
char *file_suffix;
int suffixLen, nameLen;
int nextIndex;
register char * next_path;
int files_in_this_directory;
int base;
_Xreaddirparams dirEntryBuf;
struct dirent *result;
/* CODE */
if (dirs == NULL)
return(NULL);
files = (DtDirPaths *) XtMalloc((Cardinal)(sizeof(DtDirPaths)));
files->dirs = (char **) XtMalloc(sizeof(char *) * FILE_INCREMENT);
files->paths = (char **) XtMalloc(sizeof(char *) * FILE_INCREMENT);
max_files = FILE_INCREMENT;
num_found = 0;
nextIndex = 0;
/* Process each one of the directories in priority order. */
while (dirs->paths[nextIndex] != NULL) {
next_path = dirs->paths[nextIndex];
dirp = opendir (next_path);
base = num_found;
files_in_this_directory = 0;
while ((result = _XReaddir(dirp, dirEntryBuf)) != NULL) {
/* Check the name to see if it matches the suffix and is
a file. */
if (strlen (result->d_name) >= strlen(suffix))
{
/* Find the end of the name and compare it to the suffix. */
/* Get the number of chars (not bytes) in each string */
suffixLen = DtCharCount(suffix);
nameLen = DtCharCount(result->d_name);
file_suffix = _DtGetNthChar(result->d_name, nameLen - suffixLen);
if (file_suffix && (strcmp(file_suffix, suffix) == 0) &&
!_DtIsDir((char *)next_path, (char *)result->d_name))
{
/* The file is a match. See if there is room in the array
or whether we need to realloc. The "-1" is to save room
for the terminating NULL pointer. */
if (num_found == max_files - 1) {
files->dirs = (char **) XtRealloc ((char *)files->dirs,
(Cardinal)(sizeof(char *) * (max_files + FILE_INCREMENT)));
files->paths = (char **) XtRealloc ((char *)files->paths,
(Cardinal)(sizeof(char *) * (max_files + FILE_INCREMENT)));
max_files += FILE_INCREMENT;
}
/* Get some memory and copy the filename to the array. */
files->dirs[num_found] = next_file = (char *)
XtMalloc((Cardinal)(strlen(dirs->dirs[nextIndex]) +
strlen (result->d_name) + 2));
(void)strcpy(next_file, dirs->dirs[nextIndex]);
(void)strcat(next_file, "/");
(void)strcat(next_file, result->d_name);
files->paths[num_found] = next_file = (char *)
XtMalloc((Cardinal)(strlen(next_path) +
strlen (result->d_name) + 2));
(void)strcpy(next_file, next_path);
(void)strcat(next_file, "/");
(void)strcat(next_file, result->d_name);
num_found++;
files_in_this_directory++;
}
}
}
closedir (dirp);
if (sort_files && (files_in_this_directory > 1))
_DtSortFiles (base, files_in_this_directory, files);
nextIndex++;
}
files->dirs[num_found] = NULL;
files->paths[num_found] = NULL;
return (files);
}
/******************************************************************************
*
* _DtDbGetDataBaseEnv( )
* ------------------------
* This function provides a PRIVATE API for internal manipulation of the
* DTDATABASEDIRPATH environment variable before loading the databases.
* -- used by the front panel code in dtwm.
*
* If the environment variable it returns a default path.
*
* NOTE: This function returns a freshly malloc'ed string. It is up to
* the caller to free it.
*
******************************************************************************/
char *
_DtDbGetDataBaseEnv( void )
{
char *nwh_dir;
char *temp_buf;
char *temp_s;
nwh_dir = getenv ("HOME");
/*
* Get the DTDATABASESEARCHPATH environment variable. If it is not set,
* create the default value.
*/
if ( temp_s = getenv ("DTDATABASESEARCHPATH"))
if ( *temp_s != 0 ) return XtNewString(temp_s);
temp_buf =
XtMalloc((2*strlen(nwh_dir)) + strlen(DTDATABASESEARCHPATH_DEFAULT) + 1);
sprintf (temp_buf, DTDATABASESEARCHPATH_DEFAULT, nwh_dir, nwh_dir);
return temp_buf;
}
/******************************
*
* Function Name: _DtGetDatabaseDirPaths
*
* Description:
*
* This function returns a structure containing the external
* and internal forms for all of the database directories that must be
* searched for Dt database files.
* The structure is freed using _DtFreeDatabaseDirPaths().
*
* The directories are all guaranteed to be fully-specified names;
* i.e. host:/path/dir.
*
* THIS IS TYPICALLY CALLED BEFORE USING ANY OF THE FOLLOWING:
*
* DtReadDatabases()
* DtPrepareToolboxDirs()
* _DtDbRead()
* _DtFindMatchingFiles()
*
* Synoposis:
*
* DtDirPaths * _DtGetDatabaseDirPaths ();
*
********************************/
DtDirPaths *
_DtGetDatabaseDirPaths( void )
{
XrmValue resource_value;
char *rep_type;
char *dir_string, *remote_hosts;
char *nwh_host; /* Holds the host portion of the user's
network-home. */
char **dir_vector; /* The list of directories are turned into
a vector of strings. This points to the
start of the vector. */
char **hosts_vector;
char **next_dir; /* A pointer used to walk through dir_vector. */
char **next_host;
char *dir; /* Points to next dir being processed */
int valid_dirs; /* A count of the number of valid directories
found. */
char *home;
char *nextc;
DtDirPaths * ret_paths;
char * internal;
int i;
char *tmp_dir_string;
/* Get our host name, and the user's home directory */
nwh_host = _DtGetLocalHostName ();
tmp_dir_string = _DtDbGetDataBaseEnv();
dir_string = _DtExpandLang (tmp_dir_string);
XtFree (tmp_dir_string);
/* Prepare the input vector and the two output vectors. */
dir_vector = _DtVectorizeInPlace (dir_string, ',');
ret_paths = (DtDirPaths *)XtMalloc(sizeof(DtDirPaths));
ret_paths->dirs = NULL;
ret_paths->paths = NULL;
valid_dirs = 0;
for (next_dir = dir_vector; *next_dir != NULL; next_dir++) {
if (DtStrchr (*next_dir, '/') == NULL){
/* It must be a relative path. */
/* Ignore relative paths */
continue;
}
/* If the name is not a valid directory, get rid of it. */
if (!_DtIsOpenableDirContext (*next_dir, &internal)) {
continue;
}
else {
/* If not already in the list, add it to the structure. */
for (i = 0; i < valid_dirs; i++)
{
if (strcmp(ret_paths->paths[i], internal) == 0)
{
break;
}
}
if (i == valid_dirs)
{
valid_dirs++;
ret_paths->dirs = (char **) XtRealloc ((char *)ret_paths->dirs,
(Cardinal) (sizeof (char *) * valid_dirs));
/* Make sure the directory name is fully-qualified with a host
component. */
if (DtStrchr (*next_dir, ':') != NULL)
dir = XtNewString(*next_dir);
/* If there is no host component, see if there is
an absolute path. */
else if (
#ifdef NLS16
(!is_multibyte || (mblen(*next_dir, MB_LEN_MAX) == 1)) &&
#endif
(**next_dir == '/')) {
dir = XtMalloc ((Cardinal) (strlen (nwh_host) + 2 +
strlen (*next_dir)));
(void) sprintf (dir, "%s:%s", nwh_host, *next_dir);
}
else
dir = XtNewString(*next_dir);
ret_paths->dirs[valid_dirs - 1] = dir;
ret_paths->paths = (char **) XtRealloc ((char *)ret_paths->paths,
(Cardinal) (sizeof (char *) * valid_dirs));
ret_paths->paths[valid_dirs - 1] = internal;
}
else {
XtFree(internal);
}
}
}
/* The three vectors must be NULL terminated. */
ret_paths->dirs = (char **) XtRealloc ((char *)ret_paths->dirs,
(Cardinal) (sizeof (char *) *
(valid_dirs + 1)));
ret_paths->dirs[valid_dirs] = NULL;
ret_paths->paths = (char **) XtRealloc ((char *)ret_paths->paths,
(Cardinal) (sizeof (char *) *
(valid_dirs + 1)));
ret_paths->paths[valid_dirs] = NULL;
XtFree ((char *) dir_string);
XtFree ((char *) nwh_host);
XtFree ((char *) dir_vector);
return(ret_paths);
}
/***************************
* void _DtFreeDatabaseDirPaths (paths)
*
* DtDirPaths * paths;
*
* This function will free up each of the arrays within the directory
* information structure, and will then free the structure itself.
*
**************************/
void
_DtFreeDatabaseDirPaths(
DtDirPaths *paths )
{
_DtFreeDirVector(paths->dirs);
_DtFreeDirVector(paths->paths);
XtFree((char *)paths);
}

View File

@@ -0,0 +1,81 @@
/*
* File: DbUtil.h $XConsortium: DbUtil.h /main/4 1995/10/26 15:04:04 rswiston $
* Language: C
*
* (c) Copyright 1988, Hewlett-Packard Company, 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 _Dt_DbUtil_h
#define _Dt_DbUtil_h
#include <X11/Intrinsic.h> /* Boolean */
/*
* This structure is used by many of the database functions. It is used to
* specify a collection of filenames or directory names. Each file/directory
* name is returned in two forms:
*
* dirs[n] The fully host-qualified pathname for the file or directory,
* in "host:/path" format.
*
* paths[n] The internal format of the file or directory anme, which
* can be passed to any of the standard tools which expect a
* valid filename; i.e. /nfs/host/path.
*
* Both of the arrays are NULL-terminated.
*/
typedef struct {
char ** dirs;
char ** paths;
} DtDirPaths;
/*****************************************************************************
*
*
*
****************************************************************************/
extern DtDirPaths * _DtFindMatchingFiles( DtDirPaths * dirs,
char * suffix,
Boolean sortFiles );
/*****************************************************************************
*
* _DtGetDatabaseDirPaths() returns a NULL-terminated array of directories,
* which are to be searched for database files. The paths are obtained by
* querying the DTDATABASESEARCHPATH environment variable, which specifies
* a set of comma separated pathnames, int "host:/path" format. The
* return structure should be freed up, when no longer needed, by invoking
* _DtFreeDatabaseDirPaths().
*
* The returned directory names are represented in two formats:
*
* 1) Fully host qualified; i.e. "host:/path"
* 2) Internal format; i.e. "/nfs/host/path"
*
****************************************************************************/
extern DtDirPaths * _DtGetDatabaseDirPaths( void );
/*****************************************************************************
*
* _DtFreeDatabaseDirPaths() is used to free the memory occupied by the
* passed-in instance of the DtDirPaths structure. Typically, this
* information was originally obtained by a call to DtGetDatabasePaths()
* or _DtFindMatchingFiles().
*
* Parameters:
*
* dirs The structure which is to be freed up.
*
****************************************************************************/
extern void _DtFreeDatabaseDirPaths( DtDirPaths * dirs );
#endif /* _Dt_DbUtil_h */
/* DON'T ADD ANYTHING AFTER THIS #endif */

467
cde/lib/DtSvc/DtUtil1/Dnd.c Normal file
View File

@@ -0,0 +1,467 @@
/* $TOG: Dnd.c /main/7 1998/10/23 13:47:10 mgreess $ */
/*********************************************************************
*
* File: Dnd.c
*
* Description: Implemenation of DND Convenience API.
*
*********************************************************************
*
*+SNOTICE
*
* 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 documment 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.
*
*+ENOTICE
*/
#include <stdlib.h>
#include <stdarg.h>
#include <sys/utsname.h>
#include <X11/Intrinsic.h>
#include <Xm/Xm.h>
#include <Xm/DragDrop.h>
#include <Xm/DropTrans.h>
#include <Dt/UserMsg.h>
#include "Dnd.h"
#include "DndP.h"
#include "DtSvcLock.h"
/*********************************************************************
*
* Data Transfer Selection Targets
*
*********************************************************************/
Atom XA_TARGETS;
Atom XA_TIMESTAMP;
Atom XA_MULTIPLE;
Atom XA_DELETE;
Atom XA_NULL;
Atom XA_TEXT;
Atom XA_HOST_NAME;
Atom XA_SUN_FILE_HOST_NAME;
Atom XA_SUN_ENUM_COUNT;
Atom XA_SUN_DATA_LABEL;
Atom XA_SUN_SELN_READONLY;
Atom XA_SUN_ATM_FILE_NAME;
Atom XA_SUN_ATM_METHODS;
static void
dndInitTargets(
Display *dpy)
{
_DtSvcProcessLock();
if (XA_TARGETS != 0) {
_DtSvcProcessUnlock();
return;
}
XA_TARGETS = DtGetAtom(dpy,"TARGETS");
XA_TIMESTAMP = DtGetAtom(dpy,"TIMESTAMP");
XA_MULTIPLE = DtGetAtom(dpy,"MULTIPLE");
XA_DELETE = DtGetAtom(dpy,"DELETE");
XA_NULL = DtGetAtom(dpy,"NULL");
XA_TEXT = DtGetAtom(dpy,"TEXT");
XA_HOST_NAME = DtGetAtom(dpy,"HOST_NAME");
XA_SUN_FILE_HOST_NAME = DtGetAtom(dpy,"_SUN_FILE_HOST_NAME");
XA_SUN_ENUM_COUNT = DtGetAtom(dpy,"_SUN_ENUMERATION_COUNT");
XA_SUN_DATA_LABEL = DtGetAtom(dpy,"_SUN_DATA_LABEL");
XA_SUN_SELN_READONLY = DtGetAtom(dpy,"_SUN_SELN_IS_READONLY");
XA_SUN_ATM_FILE_NAME = DtGetAtom(dpy,"_SUN_ATM_FILE_NAME");
XA_SUN_ATM_METHODS = DtGetAtom(dpy,
"_SUN_ALTERNATE_TRANSPORT_METHODS");
_DtSvcProcessUnlock();
}
/*********************************************************************
*
* Data Transfer Protocol Method Functions
*
*********************************************************************/
static DtDndProtocol dndProtocolList[] = {
DtDND_FILENAME_TRANSFER,
DtDND_BUFFER_TRANSFER,
DtDND_TEXT_TRANSFER,
DtDND_NOOP_TRANSFER
};
extern DtDndMethods *_DtDndBuffTransferProtocolInitialize(Display*);
extern DtDndMethods *_DtDndFileTransferProtocolInitialize(Display*);
extern DtDndMethods *_DtDndTextTransferProtocolInitialize(Display*);
/*
* dndGetTransferMethods
*
* Return the transfer methods for a particular protocol
*/
static DtDndMethods *
dndGetTransferMethods(
Display * display,
DtDndProtocol protocol)
{
DtDndMethods * methods = NULL;
switch (protocol) {
case DtDND_BUFFER_TRANSFER:
methods = _DtDndBuffTransferProtocolInitialize(display);
break;
case DtDND_FILENAME_TRANSFER:
methods = _DtDndFileTransferProtocolInitialize(display);
break;
case DtDND_TEXT_TRANSFER:
methods = _DtDndTextTransferProtocolInitialize(display);
break;
}
return methods;
}
/*
* _DtDndCreateExportTransfer
*
* Returns a transfer suitable for use by a drag initiator
*/
DtDndTransfer *
_DtDndCreateExportTransfer(
DtDragInfo * dtDragInfo)
{
Display * dpy = XtDisplayOfObject(dtDragInfo->dragInitiator);
DtDndTransfer * transfer;
dndInitTargets(dpy);
transfer = (DtDndTransfer *)XtMalloc(sizeof(DtDndTransfer));
transfer->methods = dndGetTransferMethods(dpy,dtDragInfo->protocol);
(*transfer->methods->getExportTargets)(dtDragInfo,
&(transfer->targets), &(transfer->numTargets));
return transfer;
}
/*
* _DtDndCreateImportTransfers
*
* Create the list of transfers specified by the protocols.
*/
DtDndTransfer *
_DtDndCreateImportTransfers(
DtDropInfo * dtDropInfo,
Cardinal * numTransfers)
{
Display * dpy = XtDisplayOfObject(dtDropInfo->dropReceiver);
DtDndTransfer * transfers;
DtDndTransfer * transfer;
Cardinal ii, jj;
dndInitTargets(dpy);
*numTransfers = 0;
for (ii = 0; dndProtocolList[ii] != DtDND_NOOP_TRANSFER; ii++) {
if (dtDropInfo->protocols & dndProtocolList[ii]) {
(*numTransfers)++;
}
}
if (*numTransfers == 0)
return (DtDndTransfer *)NULL;
transfers = (DtDndTransfer *)XtMalloc(
*numTransfers * sizeof(DtDndTransfer));
for (ii = 0, jj = 0; dndProtocolList[ii] != DtDND_NOOP_TRANSFER; ii++) {
if (dtDropInfo->protocols & dndProtocolList[ii]) {
transfer = &transfers[jj++];
transfer->methods =
dndGetTransferMethods(dpy,dndProtocolList[ii]);
(*transfer->methods->getImportTargets)(dtDropInfo,
&(transfer->targets), &(transfer->numTargets));
}
}
return transfers;
}
/*
* _DtDndDestroyTransfers
*
* Destroy the transfer list created by
* _DtDndCreateExportTransfer() or _DtDndCreateImportTransfers()
*/
void
_DtDndDestroyTransfers(
DtDndTransfer * transfers,
Cardinal numTransfers)
{
Cardinal ii;
for (ii = 0; ii < numTransfers; ii++) {
XtFree((char *)transfers[ii].targets);
}
XtFree((char *)transfers);
}
/*
* _DtDndTransferFromTargets
*
* Returns the transfer method that matches the target list
*/
DtDndTransfer *
_DtDndTransferFromTargets(
DtDndTransfer * transfers,
Cardinal numTransfers,
Atom * targets,
Cardinal numTargets)
{
Cardinal ii, jj, kk;
for (ii = 0; ii < numTransfers; ii++) {
for (jj = 0; jj < transfers[ii].numTargets; jj++) {
for (kk = 0; kk < numTargets; kk++) {
if (transfers[ii].targets[jj] == targets[kk]) {
return &transfers[ii];
}
}
}
}
return (DtDndTransfer *)NULL;
}
/*
* _DtDndTransferAdd
*
* Add the targets to the requested transfer targets list
* and call XmDropTransferAdd() to request them
*/
void
_DtDndTransferAdd(
Widget dropTransfer,
DtDropInfo * dtDropInfo,
Atom * transferTargets,
Cardinal numTransferTargets)
{
DtTransferInfo *transferInfo = dtDropInfo->transferInfo;
XmDropTransferEntryRec * transferEntries;
Cardinal numTransfers;
int ii, jj;
transferEntries = (XmDropTransferEntryRec *)
XtMalloc(numTransferTargets * sizeof(XmDropTransferEntryRec));
numTransfers = transferInfo->numTransferTargets + numTransferTargets;
transferInfo->transferTargets = (Atom *)XtRealloc(
(char *)transferInfo->transferTargets,
numTransfers * sizeof(Atom));
jj = transferInfo->numTransferTargets;
for (ii = 0; ii < numTransferTargets; ii++) {
transferEntries[ii].target = transferTargets[ii];
transferEntries[ii].client_data = (XtPointer)dtDropInfo;
transferInfo->transferTargets[ii+jj] = transferTargets[ii];
}
transferInfo->numTransferTargets = numTransfers;
XmDropTransferAdd(dropTransfer, transferEntries, numTransferTargets);
XtFree((char *)transferEntries);
}
/*********************************************************************
*
* Misc Debugging Functions
*
*********************************************************************/
#ifdef DEBUG
void
_DtDndPrintTargets(
Display *display,
Atom *targets,
Cardinal numTargets)
{
Cardinal ii;
char *name;
for (ii = 0; ii < numTargets; ii++) {
name = XGetAtomName(display, targets[ii]);
if (name) {
printf("%s ", name);
XFree(name);
} else {
printf("(null) ");
}
}
printf("\n");
}
void
_DtDndPrintTransfers(
Display *display,
DtDndTransfer *transfers,
Cardinal numTransfers)
{
Cardinal ii;
for (ii = 0; ii < numTransfers; ii++) {
printf("%s\tTargets: ",transfers[ii].methods->name);
_DtDndPrintTargets(display,
transfers[ii].targets,transfers[ii].numTargets);
}
}
#endif
/*********************************************************************
*
* Misc Utility Functions
*
*********************************************************************/
/*
* Copy CallbackList
*/
XtCallbackList
_DtDndCopyCallbackList(
XtCallbackList callbacks)
{
XtCallbackList cl;
int ii, count;
if (callbacks == NULL)
return NULL;
count = 1;
for (cl = callbacks; cl->callback != NULL; cl++) {
count++;
}
cl = (XtCallbackList)XtMalloc(count * sizeof(XtCallbackRec));
for (ii = 0; ii < count; ii++) {
cl[ii].callback = callbacks[ii].callback;
cl[ii].closure = callbacks[ii].closure;
}
return cl;
}
/*
* Call CallbackList
*/
void
_DtDndCallCallbackList(
Widget widget,
XtCallbackList callbacks,
XtPointer calldata)
{
XtCallbackList cl;
if (callbacks == NULL)
return;
for (cl = callbacks; cl->callback != NULL; cl++) {
(*cl->callback)(widget, cl->closure, calldata);
}
}
/*
* Misc Varargs Utility Functions
*/
int
_DtDndCountVarArgs(
va_list vaList)
{
XtPointer argPtr;
Cardinal argCount;
argCount = 0;
for (argPtr = va_arg(vaList,String);
argPtr != NULL;
argPtr = va_arg(vaList,String)) {
va_arg(vaList, XtArgVal);
argCount++;
}
return argCount;
}
void
_DtDndArgListFromVarArgs(
va_list vaList,
Cardinal maxArgs,
ArgList *argListReturn,
Cardinal *argCountReturn)
{
ArgList argList;
Cardinal argCount;
XtPointer argPtr;
if (0 == maxArgs)
{
*argListReturn = NULL;
*argCountReturn = 0;
return;
}
argList = (ArgList)XtMalloc((unsigned)(maxArgs * sizeof(Arg)));
argCount = 0;
for (argPtr = va_arg(vaList,String);
argPtr != NULL;
argPtr = va_arg(vaList,String)) {
XtSetArg(argList[argCount], argPtr, va_arg(vaList,XtArgVal));
argCount++;
}
*argListReturn = argList;
*argCountReturn = argCount;
}
/*
* Returns the network node/host name.
*/
String
_DtDndGetHostName()
{
static char *nodename;
_DtSvcProcessLock();
if (nodename == NULL) {
struct utsname un;
if (uname(&un) == -1) {
_DtSimpleError(DtProgName,DtError, NULL, "uname", NULL);
nodename = XtNewString("nodename");
} else {
nodename = XtNewString(un.nodename);
}
}
_DtSvcProcessUnlock();
return nodename;
}

188
cde/lib/DtSvc/DtUtil1/Dnd.h Normal file
View File

@@ -0,0 +1,188 @@
/* $XConsortium: Dnd.h /main/3 1995/10/26 15:04:35 rswiston $ */
/*
* (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 _Dt_Dnd_h
#define _Dt_Dnd_h
#include <Xm/DragIcon.h>
#include <Xm/DragC.h>
#ifdef __cplusplus
extern "C" {
#endif
/*
* Constants
*/
/* Dnd Callback Reasons */
enum {
DtCR_DND_CONVERT_DATA,
DtCR_DND_CONVERT_DELETE,
DtCR_DND_DRAG_FINISH,
DtCR_DND_TRANSFER_DATA,
DtCR_DND_DROP_ANIMATE,
DtCR_DND_ROOT_TRANSFER
};
#define DtCR_DND_TRANSFER DtCR_DND_TRANSFER_DATA
/*
* Dnd Drag Start Resources
* dropOnRootCallback is private and should not be used
*/
#define DtNdropOnRootCallback "dropOnRootCallback"
#define DtCDropOnRootCallback "DropOnRootCallback"
#define DtNsourceIcon "sourceIcon"
#define DtCSourceIcon "SourceIcon"
#define DtNbufferIsText "bufferIsText"
#define DtCBufferIsText "BufferIsText"
/*
*Dnd Drop Register Resources
*/
#define DtNdropAnimateCallback "dropAnimateCallback"
#define DtCDropAnimateCallback "DropAnimateCallback"
#define DtNpreserveRegistration "preserveRegistration"
#define DtCPreserveRegistration "PreserveRegistration"
#define DtNregisterChildren "registerChildren"
#define DtCRegisterChildren "RegisterChildren"
#define DtNtextIsBuffer "textIsBuffer"
#define DtCTextIsBuffer "TextIsBuffer"
/*
* Types
*/
typedef enum {
DtDND_SUCCESS,
DtDND_FAILURE
} DtDndStatus;
typedef unsigned long DtDndProtocol;
enum {
DtDND_NOOP_TRANSFER = 0L,
DtDND_TEXT_TRANSFER = (1L << 0),
DtDND_FILENAME_TRANSFER = (1L << 1),
DtDND_BUFFER_TRANSFER = (1L << 2)
};
typedef struct _DtDndBuffer {
void * bp;
int size;
String name;
} DtDndBuffer;
typedef struct _DtDndContext {
DtDndProtocol protocol;
Cardinal numItems;
union {
XmString * strings;
String * files;
DtDndBuffer * buffers;
} data;
} DtDndContext;
/*
* Dnd Callback Structures
*/
typedef struct _DtDndConvertCallbackStruct {
int reason;
XEvent * event;
DtDndContext * dragData;
DtDndStatus status;
} DtDndConvertCallbackStruct, *DtDndConvertCallback;
typedef struct _DtDndDragFinishCallbackStruct {
int reason;
XEvent * event;
DtDndContext * dragData;
Widget sourceIcon;
} DtDndDragFinishCallbackStruct, *DtDndDragFinishCallback;
typedef struct _DtDndTransferCallbackStruct {
int reason;
XEvent * event;
Position x, y;
unsigned char operation;
DtDndContext * dropData;
Widget dragContext;
Boolean completeMove;
DtDndStatus status;
} DtDndTransferCallbackStruct, *DtDndTransferCallback;
typedef DtDndTransferCallbackStruct DtDndDropCallbackStruct, *DtDndDropCallback;
typedef struct _DtDndDropAnimateCallbackStruct {
int reason;
XEvent * event;
Position x, y;
unsigned char operation;
DtDndContext * dropData;
} DtDndDropAnimateCallbackStruct, *DtDndDropAnimateCallback;
/*
* Functions
*/
extern Widget DtDndCreateSourceIcon(
Widget widget,
Pixmap source,
Pixmap mask);
extern Widget DtDndDragStart(
Widget dragInitiator,
XEvent* event,
DtDndProtocol protocol,
Cardinal numItems,
unsigned char operations,
XtCallbackList convertCallback,
XtCallbackList dragFinishCallback,
ArgList argList,
Cardinal argCount);
extern Widget DtDndVaDragStart(
Widget dragInitiator,
XEvent* event,
DtDndProtocol protocol,
Cardinal numItems,
unsigned char operations,
XtCallbackList convertCallback,
XtCallbackList dragFinishCallback,
...);
extern void DtDndDropRegister(
Widget dropSite,
DtDndProtocol protocols,
unsigned char operations,
XtCallbackList transferCallback,
ArgList argList,
Cardinal argCount);
extern void DtDndVaDropRegister(
Widget dropSite,
DtDndProtocol protocols,
unsigned char operations,
XtCallbackList transferCallback,
...);
extern void DtDndDropUnregister(
Widget widget);
#ifdef __cplusplus
}
#endif
#endif /* _Dt_Dnd_h */

View File

@@ -0,0 +1,723 @@
/* $XConsortium: DndBuff.c /main/5 1996/06/21 17:30:55 ageorge $ */
/*********************************************************************
*
* File: DndBuff.c
*
* Description: Implementation of the Buffer Transfer routines
* FOR the DND Convenience API.
*
*********************************************************************
*
*
* RESTRICTED CONFIDENTIAL INFORMATION:
*
* The information in this document is subject to special
* restrictions in a confidential disclosure agreement bertween
* HP, IBM, Sun, USL, SCO and Univel. Do not distribute this
* document outside HP, IBM, Sun, USL, SCO, or Univel wihtout
* Sun's specific written approval. This documment 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.
*
*/
#include <stdlib.h>
#include <X11/Intrinsic.h>
#include <Xm/AtomMgr.h>
#include <Xm/DragC.h>
#include <Xm/DropSMgr.h>
#include <Xm/DropTrans.h>
#include "Dnd.h"
#include "DndP.h"
#include "DtSvcLock.h"
/*
* Buffer Transfer Protocol Function Prototypes
*/
static void dndBuffGetTargets(Boolean, Boolean, Atom**, Cardinal*);
static void dndBuffGetAvailTargets(DtDragInfo*, Atom**, Cardinal*);
static void dndBuffGetExportTargets(DtDragInfo*, Atom**, Cardinal*);
static void dndBuffGetImportTargets(DtDropInfo*, Atom**, Cardinal*);
static void dndBuffConvertInit(DtDragInfo*);
static Boolean dndBuffConvert(Widget, DtDragInfo*, Atom*, Atom*,
Atom*, XtPointer*, unsigned long*, int*,
XSelectionRequestEvent*);
static void dndBuffConvertFinish(DtDragInfo*);
static void dndBuffTransferTargets(DtDropInfo*,
Atom*, Cardinal, Atom**, Cardinal*);
static void dndBuffTransfer(Widget, DtDropInfo*, Atom*, Atom*, Atom*,
XtPointer, unsigned long*, int*);
static void dndBuffTransferFinish(DtDropInfo*);
/*
* Buffer Transfer Support Functions
*/
static void dndBufferDataToSelectionValue(DtDndBuffer *, Cardinal,
XtPointer *, unsigned long *, Boolean);
static void dndBufferLengthsToSelectionValue(DtDndBuffer *, Cardinal,
XtPointer *, unsigned long *);
static void dndBufferNamesToSelectionValue(DtDndBuffer *, Cardinal,
XtPointer *, unsigned long *);
static void dndTextSelectionValueToBuffer(Display *,
Atom *, XtPointer, unsigned long *, int *, String,
XtPointer *, unsigned long *,
DtDndBuffer **, Cardinal *);
static void dndSelectionValueToBuffer(XtPointer, unsigned long,
XtPointer, unsigned long, XtPointer, unsigned long,
DtDndBuffer **, Cardinal *);
/*
* Buffer Transfer Selection Targets
*/
static Atom XA_DT_BUFFER_DATA;
static Atom XA_DT_BUFFER_LENGTHS;
static Atom XA_DT_BUFFER_NAMES;
/*
* Buffer Transfer Protocol Methods
*/
static DtDndMethods dndBuffTransferProtocol = {
"DtDndBufferTransfer", /* name */
(DtDndProtocol)DtDND_BUFFER_TRANSFER, /* protocol */
DtDND_DRAG_SOURCE_DATA, /* sourceType */
dndBuffGetAvailTargets, /* getAvailTargets */
dndBuffGetExportTargets, /* getExportTargets */
dndBuffGetImportTargets, /* getImportTargets */
dndBuffConvertInit, /* convertInit */
dndBuffConvert, /* convert */
dndBuffConvertFinish, /* convertFinish */
dndBuffTransferTargets, /* transferTargets */
dndBuffTransfer, /* transfer */
dndBuffTransferFinish, /* transferFinish */
};
typedef struct _TransferState {
XtPointer dataValue;
unsigned long dataLength;
XtPointer lengthsValue;
unsigned long lengthsLength;
XtPointer namesValue;
unsigned long namesLength;
String dataLabel;
Atom textTarget;
} TransferState;
/*
* Buffer transfer protocol initialization
*/
DtDndMethods *
_DtDndBuffTransferProtocolInitialize(
Display * dpy)
{
_DtSvcProcessLock();
if (XA_DT_BUFFER_DATA == 0) {
XA_DT_BUFFER_DATA = DtGetAtom(dpy,"_DT_BUFFER_DATA");
XA_DT_BUFFER_LENGTHS = DtGetAtom(dpy,"_DT_BUFFER_LENGTHS");
XA_DT_BUFFER_NAMES = DtGetAtom(dpy,"_DT_BUFFER_NAMES");
}
_DtSvcProcessUnlock();
return &dndBuffTransferProtocol;
}
/*
* Returns export/import targets for buffer transfers
*/
static void
dndBuffGetTargets(
Boolean includeText,
Boolean owCompat,
Atom ** targets,
Cardinal * numTargets)
{
int ii = 0;
*numTargets = 3 + (includeText ? 2 : 0) + (owCompat ? 1 : 0);
*targets = (Atom *)XtMalloc(*numTargets * sizeof(Atom));
(*targets)[ii++] = XA_DT_BUFFER_DATA;
(*targets)[ii++] = XA_DT_BUFFER_LENGTHS;
(*targets)[ii++] = XA_DT_BUFFER_NAMES;
if (includeText) {
(*targets)[ii++] = XA_TEXT;
(*targets)[ii++] = XA_STRING;
}
if (owCompat) {
(*targets)[ii++] = XA_SUN_DATA_LABEL;
}
}
/*
* Returns available targets for buffer transfers
*/
static void
dndBuffGetAvailTargets(
DtDragInfo * dtDragInfo,
Atom ** availTargets,
Cardinal * numAvailTargets)
{
dndBuffGetTargets(True, True, availTargets, numAvailTargets);
}
/*
* Returns export targets for buffer transfers
*/
static void
dndBuffGetExportTargets(
DtDragInfo * dtDragInfo,
Atom ** exportTargets,
Cardinal * numExportTargets)
{
dndBuffGetTargets(dtDragInfo->bufferIsText, True,
exportTargets, numExportTargets);
}
/*
* Returns import targets for buffer transfers
*/
static void
dndBuffGetImportTargets(
DtDropInfo * dtDropInfo,
Atom ** importTargets,
Cardinal * numImportTargets)
{
dndBuffGetTargets(dtDropInfo->textIsBuffer, True,
importTargets, numImportTargets);
}
/*
* Initialize protocol specific part of drag data
*/
static void
dndBuffConvertInit(
DtDragInfo * dtDragInfo)
{
DtDndContext * dragData = dtDragInfo->dragData;
dragData->data.buffers = (DtDndBuffer *)
XtCalloc(dragData->numItems, sizeof(DtDndBuffer));
}
/*
* Convert the buffers into selection data
*/
static Boolean
dndBuffConvert(
Widget dragContext,
DtDragInfo * dtDragInfo,
Atom * selection,
Atom * target,
Atom * returnType,
XtPointer * returnValue,
unsigned long * returnLength,
int * returnFormat,
XSelectionRequestEvent * selectionRequestEvent)
{
DtDndContext * dragData = dtDragInfo->dragData;
/*
* TEXT or STRING
* Convert the buffer data to a text selection
*/
if (*target == XA_TEXT || *target == XA_STRING) {
*returnType = XA_STRING;
*returnFormat = 8;
dndBufferDataToSelectionValue(
dragData->data.buffers, dragData->numItems,
returnValue, returnLength, True);
/*
* _SUN_DATA_LABEL
* Convert the first buffer name to a selection
*/
} else if (*target == XA_SUN_DATA_LABEL) {
*returnType = XA_STRING;
*returnFormat = 8;
*returnValue = XtNewString(dragData->data.buffers[0].name);
*returnLength = strlen(*returnValue)+1;
/*
* _DT_BUFFER_DATA
* Convert the buffer data to a selection
*/
} else if (*target == XA_DT_BUFFER_DATA) {
*returnType = XA_DT_BUFFER_DATA;
*returnFormat = 8;
dndBufferDataToSelectionValue(
dragData->data.buffers, dragData->numItems,
returnValue, returnLength, False);
/*
* _DT_BUFFER_LENGTHS
* Convert the buffer lengths to a selection
*/
} else if (*target == XA_DT_BUFFER_LENGTHS) {
*returnType = XA_INTEGER;
*returnFormat = 32;
dndBufferLengthsToSelectionValue(
dragData->data.buffers, dragData->numItems,
returnValue, returnLength);
/*
* _DT_BUFFER_NAMES
* Convert the buffer names to a selection
*/
} else if (*target == XA_DT_BUFFER_NAMES) {
*returnType = XA_STRING;
*returnFormat = 8;
dndBufferNamesToSelectionValue(
dragData->data.buffers, dragData->numItems,
returnValue, returnLength);
} else {
return False;
}
return True;
}
/*
* Clean up from the convert init proc
*/
static void
dndBuffConvertFinish(
DtDragInfo * dtDragInfo)
{
DtDndContext * dragData = dtDragInfo->dragData;
if (dragData->data.buffers) {
XtFree((char *)dragData->data.buffers);
dragData->data.buffers = NULL;
}
}
/*
* Returns the transfer targets selected from the export targets
* Prefer buffers over TEXT/STRING
*/
static void
dndBuffTransferTargets(
DtDropInfo * dtDropInfo,
Atom * exportTargets,
Cardinal numExportTargets,
Atom ** transferTargets,
Cardinal * numTransferTargets)
{
Boolean foundData, foundLengths, foundNames,
foundDataLabel, foundText, foundString;
int ii;
TransferState * xferState;
xferState = (TransferState *)XtCalloc(1,sizeof(TransferState));
dtDropInfo->transferInfo->clientData = (XtPointer)xferState;
foundData = foundLengths = foundNames = False;
foundDataLabel = foundText = foundString = False;
for (ii = 0; ii < numExportTargets; ii++) {
if (exportTargets[ii] == XA_DT_BUFFER_DATA) {
foundData = True;
} else if (exportTargets[ii] == XA_DT_BUFFER_LENGTHS) {
foundLengths = True;
} else if (exportTargets[ii] == XA_DT_BUFFER_NAMES) {
foundNames = True;
} else if (exportTargets[ii] == XA_SUN_DATA_LABEL) {
foundDataLabel = True;
} else if (exportTargets[ii] == XA_TEXT) {
foundText = True;
} else if (exportTargets[ii] == XA_STRING) {
foundString = True;
}
}
*numTransferTargets = 2; /* max number of transfer targets */
*transferTargets = (Atom *)XtMalloc(*numTransferTargets * sizeof(Atom));
ii = 0;
if (foundData && foundLengths && foundNames) {
*numTransferTargets = 2;
(*transferTargets)[ii++] = XA_DT_BUFFER_NAMES;
(*transferTargets)[ii++] = XA_DT_BUFFER_LENGTHS;
} else if (foundDataLabel && (foundText || foundString)) {
*numTransferTargets = 2;
(*transferTargets)[ii++] = XA_SUN_DATA_LABEL;
(*transferTargets)[ii++] = foundText ? XA_TEXT : XA_STRING;
xferState->textTarget = foundText ? XA_TEXT : XA_STRING;
} else if (foundText || foundString) {
*numTransferTargets = 1;
(*transferTargets)[ii++] = foundText ? XA_TEXT : XA_STRING;
} else {
*numTransferTargets = 0;
*transferTargets = NULL;
return;
}
}
/*
* Transfer the selection data into buffers
*/
static void
dndBuffTransfer(
Widget dropTransfer,
DtDropInfo * dtDropInfo,
Atom * selection,
Atom * target,
Atom * type,
XtPointer value,
unsigned long * length,
int * format)
{
Display * display = XtDisplayOfObject(dropTransfer);
DtDndContext * dropData = dtDropInfo->dropData;
TransferState * xferState =
(TransferState *)dtDropInfo->transferInfo->clientData;
/*
* Ignore if we've already transferred
*/
if (dropData->data.buffers) {
XtFree(value);
return;
}
/*
* TEXT or STRING
*
* Convert the text selection into buffers
*/
if (*target == XA_TEXT || *target == XA_STRING) {
dndTextSelectionValueToBuffer(display,
type, value, length, format, xferState->dataLabel,
&(xferState->dataValue), &(xferState->dataLength),
&(dropData->data.buffers), &(dropData->numItems));
/*
* _SUN_DATA_LABEL
*
* Save the buffer name selection for later conversion
* Request the text data transfer
*/
} else if (*target == XA_SUN_DATA_LABEL &&
*type == XA_STRING &&
*format == 8) {
xferState->dataLabel = (String)value;
_DtDndTransferAdd(dropTransfer, dtDropInfo,
&(xferState->textTarget), 1);
/*
* _DT_BUFFER_DATA
*
* Save the buffer data selection for later conversion
*/
} else if (*target == XA_DT_BUFFER_DATA &&
*type == XA_DT_BUFFER_DATA &&
*format == 8) {
xferState->dataValue = value;
xferState->dataLength = *length;
dndSelectionValueToBuffer(
xferState->dataValue, xferState->dataLength,
xferState->lengthsValue, xferState->lengthsLength,
xferState->namesValue, xferState->namesLength,
&(dropData->data.buffers), &(dropData->numItems));
/*
* _DT_BUFFER_LENGTHS
*
* Save the buffer lengths selection for later conversion
* Request the buffer data transfer
*/
} else if (*target == XA_DT_BUFFER_LENGTHS &&
*type == XA_INTEGER &&
*format == 32) {
xferState->lengthsValue = value;
xferState->lengthsLength = *length;
_DtDndTransferAdd(dropTransfer, dtDropInfo,
&XA_DT_BUFFER_DATA, 1);
/*
* _DT_BUFFER_NAMES
*
* Save the buffer names selection for later conversion
*/
} else if (*target == XA_DT_BUFFER_NAMES &&
*type == XA_STRING &&
*format == 8) {
xferState->namesValue = value;
xferState->namesLength = *length;
/*
* Ignore transfers we don't understand
*/
} else {
XtFree(value);
return;
}
}
/*
* Clean up from the transfer proc
*/
static void
dndBuffTransferFinish(
DtDropInfo * dtDropInfo)
{
DtDndContext * dropData = dtDropInfo->dropData;
TransferState * xferState =
(TransferState *)dtDropInfo->transferInfo->clientData;
dtDropInfo->transferInfo->clientData = NULL;
if (xferState->dataValue)
XtFree(xferState->dataValue);
if (xferState->lengthsValue)
XtFree(xferState->lengthsValue);
if (xferState->namesValue)
XtFree(xferState->namesValue);
if (xferState->dataLabel)
XtFree(xferState->dataLabel);
XtFree((char *)xferState);
XtFree((char *)dropData->data.buffers);
}
/*
* Convert buffer data into a single chunk of memory
*/
static void
dndBufferDataToSelectionValue(
DtDndBuffer * buffers,
Cardinal numBuffers,
XtPointer * returnValue,
unsigned long * returnLength,
Boolean isText)
{
int ii;
char *bufferPtr;
*returnLength = 0;
for (ii = 0; ii < numBuffers; ii++) {
*returnLength += buffers[ii].size;
if (isText) {
*returnLength += 1;
}
}
*returnValue = (XtPointer) XtMalloc(*returnLength);
bufferPtr = (XtPointer)*returnValue;
for (ii = 0; ii < numBuffers; ii++) {
memcpy(bufferPtr, buffers[ii].bp, buffers[ii].size);
bufferPtr += buffers[ii].size;
if (isText) {
*bufferPtr = '\0';
bufferPtr++;
}
}
if (isText) {
*returnLength -= 1;
}
}
/*
* Convert buffer lengths into a list of integers
*/
static void
dndBufferLengthsToSelectionValue(
DtDndBuffer * buffers,
Cardinal numBuffers,
XtPointer * returnValue,
unsigned long * returnLength)
{
int ii;
unsigned long * lengths;
*returnLength = numBuffers;
*returnValue = (XtPointer) XtMalloc(*returnLength * sizeof(long));
lengths = (unsigned long *)*returnValue;
for (ii = 0; ii < numBuffers; ii++) {
lengths[ii] = buffers[ii].size;
}
}
/*
* Convert buffer names into a single chunk of memory
*/
static void
dndBufferNamesToSelectionValue(
DtDndBuffer * buffers,
Cardinal numBuffers,
XtPointer * returnValue,
unsigned long * returnLength)
{
int ii, len;
char * namePtr;
*returnLength = 0;
for (ii = 0; ii < numBuffers; ii++) {
if (buffers[ii].name != NULL) {
*returnLength += strlen(buffers[ii].name) + 1;
} else {
*returnLength += 1;
}
}
*returnValue = (XtPointer) XtMalloc(*returnLength);
namePtr = (char *)*returnValue;
for (ii = 0; ii < numBuffers; ii++) {
if (buffers[ii].name == NULL) {
*namePtr = '\0';
namePtr++;
} else {
len = strlen(buffers[ii].name) + 1;
memcpy(namePtr, buffers[ii].name, len);
namePtr += len;
}
}
}
/*
* Split text selection data into multiple buffers
*/
static void
dndTextSelectionValueToBuffer(
Display * display,
Atom * type,
XtPointer value,
unsigned long * length,
int * format,
String dataLabel,
XtPointer * returnValue,
unsigned long * returnLength,
DtDndBuffer ** buffers,
Cardinal * numBuffers)
{
XTextProperty textProp;
char ** text;
char * bufPtr;
int ii, status, textCount, textLen;
textProp.value = (unsigned char *)value;
textProp.encoding = *type;
textProp.format = *format;
textProp.nitems = *length;
status = XmbTextPropertyToTextList(display, &textProp,
&text, &textCount);
if (status != Success) {
*numBuffers = 1;
(*buffers) = (DtDndBuffer *)XtMalloc(sizeof(DtDndBuffer));
(*buffers)[0].bp = value;
(*buffers)[0].size = *length;
(*buffers)[0].name = dataLabel ? dataLabel : (String)NULL;
*returnValue = value;
*returnLength = *length;
return;
}
*numBuffers = textCount;
(*buffers) = (DtDndBuffer *)XtMalloc(*numBuffers * sizeof(DtDndBuffer));
textLen = 0;
for (ii = 0; ii < *numBuffers; ii++) {
(*buffers)[ii].size = strlen(text[ii]);
(*buffers)[ii].name = (String)NULL;
textLen += (*buffers)[ii].size+1;
}
(*returnValue) = XtMalloc(textLen * sizeof(char));
(*returnLength) = textLen;
bufPtr = (*returnValue);
for (ii = 0; ii < *numBuffers; ii++) {
(*buffers)[ii].bp = bufPtr;
memcpy(bufPtr,text[ii],(*buffers)[ii].size+1);
bufPtr += (*buffers)[ii].size+1;
}
if (dataLabel)
(*buffers)[0].name = dataLabel;
XtFree(value);
XFreeStringList(text);
}
/*
* Split data/lengths/names selection data into multiple buffers
*/
static void
dndSelectionValueToBuffer(
XtPointer dataValue,
unsigned long dataLength,
XtPointer lengthsValue,
unsigned long lengthsLength,
XtPointer namesValue,
unsigned long namesLength,
DtDndBuffer ** buffers,
Cardinal * numBuffers)
{
int ii;
char * bufPtr;
char * namePtr;
unsigned long * lenList;
if (lengthsLength == 0 || lengthsValue == NULL) {
*numBuffers = 1;
(*buffers) = (DtDndBuffer *)XtMalloc(sizeof(DtDndBuffer));
(*buffers)[0].bp = dataValue;
(*buffers)[0].size = dataLength;
(*buffers)[0].name = (String)NULL;
return;
}
*numBuffers = lengthsLength;
(*buffers) = (DtDndBuffer *)XtMalloc(*numBuffers * sizeof(DtDndBuffer));
lenList = (unsigned long *)lengthsValue;
bufPtr = dataValue;
namePtr = namesValue;
for (ii = 0; ii < *numBuffers; ii++) {
(*buffers)[ii].bp = bufPtr;
(*buffers)[ii].size = lenList[ii];
(*buffers)[ii].name = namePtr;
bufPtr += lenList[ii];
namePtr = strchr(namePtr, '\0');
namePtr++;
}
}

View File

@@ -0,0 +1,819 @@
/* $XConsortium: DndDrag.c /main/5 1996/09/27 19:00:40 drk $ */
/*********************************************************************
*
* File: DndDrag.c
*
* Description: Implemenation of DND Drag Initator
*
*********************************************************************
*
*+SNOTICE
*
* 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 documment 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.
*
*+ENOTICE
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <X11/Intrinsic.h>
#include <Xm/AtomMgr.h>
#include <Xm/DragDrop.h>
#include <Xm/DragC.h>
#include <Xm/DragCP.h>
#include <Xm/DragOverSP.h>
#include "Dnd.h"
#include "DndP.h"
#include "DtSvcLock.h"
/*
* Drag Initiator Callbacks
*/
static Boolean dndConvertProc(Widget, Atom*, Atom*, Atom*, XtPointer *,
unsigned long*, int*);
static void dndAppConvert(Widget, int, XEvent*, DtDragInfo*);
static void dndDropStartCallback(Widget, XtPointer, XtPointer);
static void dndDropFinishCallback(Widget, XtPointer, XtPointer);
static void dndDragDropFinishCallback(Widget, XtPointer, XtPointer);
static void dndTopLevelEnterCallback(Widget, XtPointer, XtPointer);
static void dndTopLevelLeaveCallback(Widget, XtPointer, XtPointer);
/*
* Drag Initiator Resources
*/
typedef struct {
XtCallbackList dropOnRootCallback;
Widget sourceIcon;
Boolean bufferIsText;
} DragSettings;
#define Offset(field) XtOffsetOf(DragSettings, field)
static XtResource dragResources[] = {
{ DtNdropOnRootCallback, DtCDropOnRootCallback,
XtRCallback, sizeof(XtCallbackList), Offset(dropOnRootCallback),
XtRImmediate, (XtPointer)NULL},
{ DtNsourceIcon, DtCSourceIcon,
XtRWidget, sizeof(Widget), Offset(sourceIcon),
XtRImmediate, (XtPointer)NULL },
{ DtNbufferIsText, DtCBufferIsText,
XtRBoolean, sizeof(Boolean), Offset(bufferIsText),
XtRImmediate, (XtPointer)False },
};
#undef Offset
/*
* DtDndVaDragStart
*
* Drag Start - varargs version
*/
Widget
DtDndVaDragStart(
Widget dragInitiator,
XEvent* event,
DtDndProtocol protocol,
Cardinal numItems,
unsigned char operations,
XtCallbackList dragConvertCallback,
XtCallbackList dragFinishCallback,
...)
{
Widget dragContext;
va_list vaList;
ArgList argList;
Cardinal argCount;
_DtSvcWidgetToAppContext(dragInitiator);
_DtSvcAppLock(app);
va_start(vaList, dragFinishCallback);
argCount = _DtDndCountVarArgs(vaList);
va_end(vaList);
va_start(vaList, dragFinishCallback);
_DtDndArgListFromVarArgs(vaList, argCount, &argList, &argCount);
va_end(vaList);
dragContext = DtDndDragStart(dragInitiator, event, protocol,
numItems, operations,
dragConvertCallback, dragFinishCallback,
argList, argCount);
XtFree((char *)argList);
_DtSvcAppUnlock(app);
return dragContext;
}
/*
* DtDndVaDragStart
*
* Drag Start - arglist version
*/
Widget
DtDndDragStart(
Widget dragInitiator,
XEvent* event,
DtDndProtocol protocol,
Cardinal numItems,
unsigned char operations,
XtCallbackList dragConvertCallback,
XtCallbackList dragFinishCallback,
ArgList argList,
Cardinal argCount)
{
XtCallbackRec dragDropFinishCbRec[] = { {dndDragDropFinishCallback,
NULL}, {NULL, NULL} };
XtCallbackRec topLevelEnterCbRec[] = { {dndTopLevelEnterCallback,
NULL}, {NULL, NULL} };
XtCallbackRec topLevelLeaveCbRec[] = { {dndTopLevelLeaveCallback,
NULL}, {NULL, NULL} };
XtCallbackRec dropStartCbRec[] = { {dndDropStartCallback,
NULL}, {NULL, NULL} };
XtCallbackRec dropFinishCbRec[] = { {dndDropFinishCallback,
NULL}, {NULL, NULL} };
Display * display = XtDisplayOfObject(dragInitiator);
Screen * screen = XtScreenOfObject(dragInitiator);
Window rootWindow = RootWindowOfScreen(screen);
DtDragInfo * dtDragInfo;
DragSettings settings;
DtDndDragSource sourceType;
DtDndTransfer * transfer;
Arg * args;
int ii, nn, savedEventType;
Atom * exportTargets;
Cardinal numExportTargets;
_DtSvcWidgetToAppContext(dragInitiator);
_DtSvcAppLock(app);
/*
* Reject the drag if noop or multiple protocols specified
*/
switch (protocol) {
case DtDND_BUFFER_TRANSFER:
case DtDND_FILENAME_TRANSFER:
case DtDND_TEXT_TRANSFER:
break;
case DtDND_NOOP_TRANSFER:
default:
_DtSvcAppUnlock(app);
return (Widget)NULL;
}
/*
* Parse resources into dragResources
*/
XtGetSubresources(dragInitiator, &settings,
(String)NULL, (String)NULL,
dragResources, XtNumber(dragResources),
argList, argCount);
/*
* Initialize DragInfo
*/
dtDragInfo = (DtDragInfo *) XtMalloc(sizeof(DtDragInfo));
dtDragInfo->dragInitiator = dragInitiator;
dtDragInfo->dragContext = NULL;
dtDragInfo->protocol = protocol;
dtDragInfo->numItems = numItems;
dtDragInfo->operations = operations;
dtDragInfo->sourceIcon = settings.sourceIcon;
dtDragInfo->bufferIsText = settings.bufferIsText;
dtDragInfo->dragData = NULL;
dtDragInfo->inRoot = False;
dtDragInfo->status = DtDND_SUCCESS;
dtDragInfo->clientData = NULL;
dtDragInfo->backdropWindow
= DtWsmGetCurrentBackdropWindow(display, rootWindow);
dtDragInfo->dragConvertCallback
= _DtDndCopyCallbackList(dragConvertCallback);
dtDragInfo->dragFinishCallback
= _DtDndCopyCallbackList(dragFinishCallback);
dtDragInfo->dropOnRootCallback
= _DtDndCopyCallbackList(settings.dropOnRootCallback);
dtDragInfo->dragData = (DtDndContext *)XtCalloc(1,sizeof(DtDndContext));
dtDragInfo->dragData->protocol = dtDragInfo->protocol;
dtDragInfo->dragData->numItems = 0;
/*
* Get data transfer method
* Use the transfer targets as export targets
*/
dtDragInfo->transfer = _DtDndCreateExportTransfer(dtDragInfo);
exportTargets = dtDragInfo->transfer->targets;
numExportTargets = dtDragInfo->transfer->numTargets;
#ifdef DEBUG
printf("DtDndDragStart: drag from widget 0x%p\n", dragInitiator);
_DtDndPrintTransfers(display,dtDragInfo->transfer,1);
#endif
/*
* Set up drag icon
*/
if (numItems > 1) {
sourceType = DtDND_DRAG_SOURCE_MULTIPLE;
} else {
sourceType = dtDragInfo->transfer->methods->sourceType;
}
_DtDndSelectDragSource(dragInitiator, sourceType,
dtDragInfo->sourceIcon);
/*
* Construct argument list
*/
#define NUM_DRAG_ARGS 30
args = (Arg *) XtMalloc(sizeof(Arg) * (NUM_DRAG_ARGS + argCount));
#undef NUM_DRAG_ARGS
/*
* Copy in passed arguments
*/
nn = 0;
for (ii = 0; ii < argCount; ii++) {
XtSetArg(args[nn], argList[ii].name, argList[ii].value); nn++;
}
/*
* Set basic drag start arguments
*/
XtSetArg(args[nn], XmNexportTargets, exportTargets);
nn++;
XtSetArg(args[nn], XmNnumExportTargets, numExportTargets);
nn++;
XtSetArg(args[nn], XmNdragOperations, operations);
nn++;
XtSetArg(args[nn], XmNblendModel, XmBLEND_ALL);
nn++;
XtSetArg(args[nn], XmNcursorBackground, WhitePixelOfScreen(screen));
nn++;
XtSetArg(args[nn], XmNcursorForeground, BlackPixelOfScreen(screen));
nn++;
XtSetArg(args[nn], XmNclientData, dtDragInfo);
nn++;
if (dtDragInfo->sourceIcon != NULL) {
XtSetArg(args[nn],XmNsourcePixmapIcon, dtDragInfo->sourceIcon);
nn++;
XtSetArg(args[nn],XmNsourceCursorIcon, dtDragInfo->sourceIcon);
nn++;
}
/*
* Set up DnD callbacks for Motif
*/
XtSetArg(args[nn], XmNconvertProc, dndConvertProc);
nn++;
dragDropFinishCbRec[0].closure = (XtPointer) dtDragInfo;
dropFinishCbRec[0].closure = (XtPointer) dtDragInfo;
dtDragInfo->dragDropFinishCallback
= _DtDndCopyCallbackList(dragDropFinishCbRec);
dtDragInfo->dropFinishCallback
= _DtDndCopyCallbackList(dropFinishCbRec);
XtSetArg(args[nn], XmNdragDropFinishCallback, dtDragInfo->dragDropFinishCallback);
nn++;
XtSetArg(args[nn], XmNdropFinishCallback, dtDragInfo->dropFinishCallback);
nn++;
/*
* Only use top-level-enter/leave callbacks if also doing drop-on-root
*/
if (dtDragInfo->dropOnRootCallback != NULL) {
topLevelEnterCbRec[0].closure = (XtPointer) dtDragInfo;
topLevelLeaveCbRec[0].closure = (XtPointer) dtDragInfo;
dropStartCbRec[0].closure = (XtPointer) dtDragInfo;
dtDragInfo->topLevelEnterCallback
= _DtDndCopyCallbackList(topLevelEnterCbRec);
dtDragInfo->topLevelLeaveCallback
= _DtDndCopyCallbackList(topLevelLeaveCbRec);
dtDragInfo->dropStartCallback
= _DtDndCopyCallbackList(dropStartCbRec);
XtSetArg(args[nn], XmNtopLevelEnterCallback, dtDragInfo->topLevelEnterCallback);
nn++;
XtSetArg(args[nn], XmNtopLevelLeaveCallback, dtDragInfo->topLevelLeaveCallback);
nn++;
XtSetArg(args[nn], XmNdropStartCallback, dtDragInfo->dropStartCallback);
nn++;
}
/*
* Fake a button press. This is necessary because Motif requires
* a drag to start on a button press. We need to be able to start
* a drag on a mouse motion event when Bselect is held down. Since
* the motion event has the fields necessary for Motif this works.
*/
savedEventType = event->type;
if (event->type == MotionNotify) {
event->type = ButtonPress;
}
/*
* Start the drag
*/
dtDragInfo->dragContext = XmDragStart(dragInitiator, event, args, nn);
XtFree((char *)args);
event->type = savedEventType;
_DtSvcAppUnlock(app);
return (dtDragInfo->dragContext);
}
/*********************************************************************
*
* Drag Initiator Callbacks
*
*********************************************************************/
/*
* dndDropStartCallback
*
*
*/
static void
dndDropStartCallback(
Widget dragContext,
XtPointer clientData,
XtPointer callData)
{
DtDragInfo *dtDragInfo = (DtDragInfo *) clientData;
DtDndContext *dragData;
XmDragContext xmDragContext = (XmDragContext)dtDragInfo->dragContext;
XmDropStartCallbackStruct *xmDropInfo = (XmDropStartCallback) callData;
DtDndTransferCallbackStruct dropCallData;
int posOffsetX, posOffsetY;
/*
* If the user has cancelled the drop, or the drop isn't on the
* root, or there are no dropOnRoot or convert callbacks
* then reject the drop.
*/
if (xmDragContext->drag.dragCompletionStatus == XmDROP_CANCEL ||
dtDragInfo->inRoot == False ||
dtDragInfo->dropOnRootCallback == NULL ||
dtDragInfo->dragConvertCallback == NULL ) {
xmDropInfo->dropSiteStatus = XmINVALID_DROP_SITE;
xmDropInfo->dropAction = XmDROP_CANCEL;
return;
}
/*
* The following is to handle the dropOnRoot situation.
* We handle both the convert and transfer sides of the
* transaction here. First we get the application drag data
* and then we call the application dropOnRoot callback.
*/
/*
* Initialize protocol specific dragData
*/
dtDragInfo->dragData->numItems = dtDragInfo->numItems;
(*dtDragInfo->transfer->methods->convertInit)(dtDragInfo);
/*
* Invoke the application convert callback
*/
dndAppConvert(dragContext, DtCR_DND_CONVERT_DATA,
xmDropInfo->event, dtDragInfo);
if (dtDragInfo->status == DtDND_FAILURE) {
return;
}
/*
* Setup dropOnRootcall data and invoke the dropOnroot callback
*/
_DtDndGetIconOffset(dtDragInfo->dragContext,
dtDragInfo->transfer->methods->sourceType,
&posOffsetX, &posOffsetY);
dropCallData.reason = DtCR_DND_ROOT_TRANSFER;
dropCallData.event = xmDropInfo->event;
dropCallData.x = xmDropInfo->x + posOffsetX;
dropCallData.y = xmDropInfo->y + posOffsetY;
dropCallData.operation = xmDropInfo->operation;
dropCallData.dropData = dtDragInfo->dragData;
dropCallData.completeMove = False;
dropCallData.status = DtDND_SUCCESS;
_DtDndCallCallbackList(dragContext, dtDragInfo->dropOnRootCallback,
(XtPointer)&dropCallData);
/*
* Tell Motif that the root is a valid drop site
*/
xmDropInfo->dropSiteStatus = XmVALID_DROP_SITE;
xmDropInfo->dropAction = XmDROP;
}
/*
* dndConvertProc
*
*
*/
static Boolean
dndConvertProc(
Widget dragContext,
Atom *selection,
Atom *target,
Atom *returnType,
XtPointer *returnValue,
unsigned long *returnLength,
int *returnFormat)
{
Atom realSelectionAtom; /* Motif hides the selection atom */
DtDragInfo *dtDragInfo = NULL;
XSelectionRequestEvent *selectionRequestEvent;
Boolean status;
#ifdef DEBUG
{
Display *display = XtDisplayOfObject(dragContext);
char *atomname = XGetAtomName(display,*target);
printf("dndConvertProc: target = %s\n",(atomname ? atomname : "Null"));
if (atomname) XFree(atomname);
}
#endif
/*
* Get the DtDragInfo
*/
XtVaGetValues(dragContext, XmNclientData, &dtDragInfo, NULL);
if (dtDragInfo == NULL || dtDragInfo->status == DtDND_FAILURE) {
return False;
}
/*
* Get selection request event
*/
XtVaGetValues(dragContext, XmNiccHandle, &realSelectionAtom, NULL);
selectionRequestEvent = XtGetSelectionRequest(dragContext,
realSelectionAtom, NULL); /* REMIND: NULL for atomic transfer */
/*
* Get the application drag data if necessary
*/
if (dtDragInfo->dragData->numItems == 0) {
dtDragInfo->dragData->numItems = dtDragInfo->numItems;
(*dtDragInfo->transfer->methods->convertInit)(dtDragInfo);
dndAppConvert(dragContext, DtCR_DND_CONVERT_DATA,
(XEvent *)selectionRequestEvent, dtDragInfo);
if (dtDragInfo->status == DtDND_FAILURE) {
return False;
}
}
/*
* Handle transfer protocol independent target conversions
*/
if (*target == XA_TARGETS) {
/*
* TARGETS Construct a list of targets consisting of those
* the dnd library supports plus those supported by
* the drag initiator.
*/
int ii, LIBRARY_TARGETS = 6;
Atom * availTargets;
Atom * allTargets;
Cardinal numAvailTargets;
Cardinal numAllTargets;
(*dtDragInfo->transfer->methods->getAvailTargets)(dtDragInfo,
&availTargets, &numAvailTargets);
numAllTargets = numAvailTargets + LIBRARY_TARGETS;
allTargets = (Atom *)XtMalloc(sizeof(Atom) * numAllTargets);
for (ii = 0; ii < numAvailTargets; ii++) {
allTargets[ii] = availTargets[ii];
}
XtFree((char *)availTargets);
ii = numAvailTargets;
allTargets[ii++] = XA_TARGETS;
allTargets[ii++] = XA_TIMESTAMP;
allTargets[ii++] = XA_MULTIPLE;
allTargets[ii++] = XA_HOST_NAME;
allTargets[ii++] = XA_SUN_FILE_HOST_NAME;
allTargets[ii++] = XA_DELETE;
*returnType = XA_ATOM;
*returnFormat = 32;
*returnValue = (XtPointer)allTargets;
*returnLength = numAllTargets * sizeof(Atom)/4;
status = True;
} else if (*target == XA_TIMESTAMP || *target == XA_MULTIPLE) {
/*
* TIMESTAMP and MULTIPLE are handled by the Intrinsics
*/
status = True;
} else if (*target == XA_HOST_NAME ||
*target == XA_SUN_FILE_HOST_NAME) {
/*
* HOST_NAME, _SUN_FILE_HOST_NAME The name of this host
*/
*returnType = XA_STRING;
*returnValue = (XtPointer)XtNewString(_DtDndGetHostName());
*returnLength = strlen((char *)*returnValue) + 1;
*returnFormat = 8;
status = True;
} else if (*target == XA_DELETE) {
/*
* DELETE Set up convert callback data to specify
* deletion and invoke the application-defined
* convertCallback() to perform the delete.
*/
*returnType = XA_NULL;
*returnFormat = 32;
*returnValue = (XtPointer) NULL;
*returnLength = 0;
dndAppConvert(dragContext, DtCR_DND_CONVERT_DELETE,
(XEvent *)selectionRequestEvent, dtDragInfo);
status = True;
} else if (*target == XA_SUN_ENUM_COUNT) {
/*
* _SUN_ENUMERATION_COUNT The number of items available
*/
int *count = XtNew(int);
if (dtDragInfo->dragData->numItems == 1) {
count[0] = 1;
} else {
count[0] = 0;
dtDragInfo->status = DtDND_FAILURE;
}
*returnType = XA_INTEGER;
*returnValue = (XtPointer)count;
*returnLength = 1;
*returnFormat = 32;
status = True;
} else {
/*
* Invoke protocol specific convert method
*/
status = (*dtDragInfo->transfer->methods->convert)(
dragContext, dtDragInfo,
selection, target,
returnType, returnValue,
returnLength, returnFormat,
selectionRequestEvent);
}
return status;
}
/*
* dndAppConvert
*
* Call the application convert callback
*/
static void
dndAppConvert(
Widget dragContext,
int reason,
XEvent * event,
DtDragInfo * dtDragInfo)
{
DtDndConvertCallbackStruct convertCallData;
convertCallData.reason = reason;
convertCallData.event = event;
convertCallData.dragData = dtDragInfo->dragData;
convertCallData.status = DtDND_SUCCESS;
_DtDndCallCallbackList(dragContext, dtDragInfo->dragConvertCallback,
(XtPointer)&convertCallData);
dtDragInfo->status = convertCallData.status;
if (reason == DtCR_DND_CONVERT_DATA &&
dtDragInfo->dragData->numItems <= 0) {
dtDragInfo->status = DtDND_FAILURE;
}
}
/*
* dndDropFinishCallback
*
* Handle drop-on-root case
*/
static void
dndDropFinishCallback(
Widget dragContext,
XtPointer clientData,
XtPointer callData)
{
DtDragInfo *dtDragInfo = (DtDragInfo *) clientData;
XmDropFinishCallbackStruct *xmDropFinishCallData =
(XmDropFinishCallbackStruct *) callData;
if (dtDragInfo->dropOnRootCallback != NULL &&
dtDragInfo->inRoot &&
xmDropFinishCallData->dropSiteStatus == XmVALID_DROP_SITE) {
xmDropFinishCallData->completionStatus = XmDROP_SUCCESS;
XtVaSetValues(dtDragInfo->dragContext,
XmNblendModel, XmBLEND_NONE, NULL);
}
}
/*
* dndDragDropFinishCallback
*
* Call the application dragFinishCallback
*/
static void
dndDragDropFinishCallback(
Widget dragContext,
XtPointer clientData,
XtPointer callData)
{
XmDragDropFinishCallbackStruct *xmDndFinishInfo =
(XmDragDropFinishCallbackStruct *)callData;
DtDragInfo *dtDragInfo = (DtDragInfo *)clientData;
DtDndDragFinishCallbackStruct dragFinishCallData;
/*
* Invoke application dragFinishCallback
*/
dragFinishCallData.reason = DtCR_DND_DRAG_FINISH;
dragFinishCallData.event = xmDndFinishInfo->event;
dragFinishCallData.sourceIcon = dtDragInfo->sourceIcon;
dragFinishCallData.dragData = dtDragInfo->dragData;
_DtDndCallCallbackList(dragContext, dtDragInfo->dragFinishCallback,
(XtPointer)&dragFinishCallData);
/*
* Restore motif default drag cursors
*/
_DtDndSelectDragSource(dragContext, DtDND_DRAG_SOURCE_DEFAULT, NULL);
/*
* Invoke protocol specific convertFinish
*/
(*dtDragInfo->transfer->methods->convertFinish)(dtDragInfo);
/*
* Free data structures allocated during the drag
*/
XtFree((char *)dtDragInfo->transfer->targets);
XtFree((char *)dtDragInfo->transfer);
XtFree((char *)dtDragInfo->dragConvertCallback);
XtFree((char *)dtDragInfo->dragFinishCallback);
XtFree((char *)dtDragInfo->dragDropFinishCallback);
XtFree((char *)dtDragInfo->dropFinishCallback);
if (dtDragInfo->dropOnRootCallback != NULL) {
XtFree((char *)dtDragInfo->topLevelEnterCallback);
XtFree((char *)dtDragInfo->topLevelLeaveCallback);
XtFree((char *)dtDragInfo->dropStartCallback);
}
XtFree((char *)dtDragInfo->dropOnRootCallback);
XtFree((char *)dtDragInfo->dragData);
XtFree((char *)dtDragInfo);
}
/*
* dndTopLevelEnterCallback -- Support for drop-on-root callback.
* When a drop-on-root callback has been set, determines if
* the drag has entered the root window (or equivalents)
* and sneakily changes Motif's idea that the root is an
* invalid drop site to think that it's really a valid one.
* Also updates dtDragInfo.inRoot as needed.
*/
static void
dndTopLevelEnterCallback(
Widget dragContext,
XtPointer clientData,
XtPointer callData)
{
XmTopLevelEnterCallbackStruct *xmEnterInfo =
(XmTopLevelEnterCallbackStruct *) callData;
DtDragInfo *dtDragInfo = (DtDragInfo *) clientData;
XmDragContext xmDragContext = (XmDragContext) dragContext;
XmDragOverShellWidget dragOverShell = xmDragContext->drag.curDragOver;
if (xmEnterInfo->window == RootWindowOfScreen(xmEnterInfo->screen) ||
dtDragInfo->backdropWindow == xmEnterInfo->window ) {
dragOverShell->drag.cursorState = XmVALID_DROP_SITE;
_XmDragOverChange((Widget)dragOverShell,
dragOverShell->drag.cursorState);
dtDragInfo->inRoot = True;
} else {
dtDragInfo->inRoot = False;
}
}
/*
* dndTopLevelLeaveCallback -- Support for drop-on-root callback.
* When a drop-on-root callback has been set, determines if
* the drag is exiting the root window and restores Motif's
* internal state back to thinking that the root window is
* an invalid drop site. We don't update dtDragInfo->inRoot
* here since the top-level-leave callback is called before
* the drop callback which needs to know if we're in the root
* or not.
*/
static void
dndTopLevelLeaveCallback(
Widget dragContext,
XtPointer clientData,
XtPointer callData)
{
XmTopLevelLeaveCallbackStruct *xmLeaveInfo =
(XmTopLevelLeaveCallbackStruct *) callData;
DtDragInfo *dtDragInfo = (DtDragInfo *) clientData;
XmDragContext xmDragContext = (XmDragContext) dragContext;
XmDragOverShellWidget dragOverShell = xmDragContext->drag.curDragOver;
if (xmLeaveInfo->window == RootWindowOfScreen(xmLeaveInfo->screen) ||
dtDragInfo->backdropWindow == xmLeaveInfo->window ) {
dragOverShell->drag.cursorState = XmINVALID_DROP_SITE;
_XmDragOverChange((Widget)dragOverShell,
dragOverShell->drag.cursorState);
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,644 @@
/* $TOG: DndFile.c /main/5 1998/04/09 17:48:19 mgreess $ */
/*********************************************************************
*
* File: DndFile.c
*
* Description: Implementation of the File Transfer routines
* for the DND Convenience API.
*
*********************************************************************
*
*
* 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 documment 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.
*/
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/param.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <X11/Intrinsic.h>
#include <Xm/AtomMgr.h>
#include <Xm/DragC.h>
#include <Xm/DropSMgr.h>
#include <Xm/DropTrans.h>
#include <Tt/tt_c.h>
#include "Dnd.h"
#include "DndP.h"
#include "DtSvcLock.h"
/*
* File Transfer Protocol Function Prototypes
*/
static void dndFileGetTargets(Boolean, Boolean, Atom**, Cardinal*);
static void dndFileGetAvailTargets(DtDragInfo*, Atom**, Cardinal*);
static void dndFileGetExportTargets(DtDragInfo*, Atom**, Cardinal*);
static void dndFileGetImportTargets(DtDropInfo*, Atom**, Cardinal*);
static void dndFileConvertInit(DtDragInfo*);
static Boolean dndFileConvert(Widget, DtDragInfo*, Atom*, Atom*,
Atom*, XtPointer*, unsigned long*, int*,
XSelectionRequestEvent*);
static void dndFileConvertFinish(DtDragInfo*);
static void dndFileTransferTargets(DtDropInfo*,
Atom*, Cardinal, Atom**, Cardinal*);
static void dndFileTransfer(Widget, DtDropInfo*, Atom*, Atom*, Atom*,
XtPointer, unsigned long*, int*);
static void dndFileTransferFinish(DtDropInfo*);
/*
* File Transfer Support Functions
*/
static Boolean dndFileContentsToSelectionValue(String,
Atom*, XtPointer*, unsigned long*, int*);
static Boolean dndFileListToSelectionValue(String*, Cardinal, Boolean,
Atom*, XtPointer*, unsigned long*, int*);
static Boolean dndSelectionValueToFileList(Atom, XtPointer, unsigned long, int,
Boolean, String**, Cardinal*);
static String dndFileEncode(String, Boolean);
static String dndFileDecode(String, Boolean);
/*
* File Transfer Selection Targets
*/
static Atom XA_FILE_NAME;
static Atom XA_DT_NETFILE;
/*
* File Transfer Protocol Methods
*/
static DtDndMethods dndFileTransferProtocol = {
"DtDndFileNameTransfer", /* name */
(DtDndProtocol)DtDND_FILENAME_TRANSFER, /* protocol */
DtDND_DRAG_SOURCE_DATA, /* sourceType */
dndFileGetAvailTargets, /* getAvailTargets */
dndFileGetExportTargets, /* getExportTargets */
dndFileGetImportTargets, /* getImportTargets */
dndFileConvertInit, /* convertInit */
dndFileConvert, /* convert */
dndFileConvertFinish, /* convertFinish */
dndFileTransferTargets, /* transferTargets */
dndFileTransfer, /* transfer */
dndFileTransferFinish, /* transferFinish */
};
typedef struct _ConvertState {
Boolean owCompat;
} ConvertState;
/*
* File transfer protocol initialization
*/
DtDndMethods *
_DtDndFileTransferProtocolInitialize(
Display * dpy)
{
_DtSvcProcessLock();
if (XA_FILE_NAME == 0) {
XA_FILE_NAME = DtGetAtom(dpy,"FILE_NAME");
XA_DT_NETFILE = DtGetAtom(dpy,"_DT_NETFILE");
}
_DtSvcProcessUnlock();
return &dndFileTransferProtocol;
}
/*
* Returns generic export/import targets for filename transfers
*/
static void
dndFileGetTargets(
Boolean doHost,
Boolean owCompat,
Atom ** targets,
Cardinal * numTargets)
{
int ii = 0;
*numTargets = 2 + (doHost ? 1 : 0) + (owCompat ? 4 : 0);
*targets = (Atom *)XtMalloc(*numTargets * sizeof(Atom));
(*targets)[ii++] = XA_DT_NETFILE;
(*targets)[ii++] = XA_FILE_NAME;
if (doHost) {
(*targets)[ii++] = XA_HOST_NAME;
}
if (owCompat) {
(*targets)[ii++] = XA_TEXT;
(*targets)[ii++] = XA_STRING;
(*targets)[ii++] = XA_SUN_DATA_LABEL;
(*targets)[ii++] = XA_SUN_ATM_METHODS;
}
}
/*
* Returns available targets for filename transfers
*/
static void
dndFileGetAvailTargets(
DtDragInfo * dtDragInfo,
Atom ** availTargets,
Cardinal * numAvailTargets)
{
dndFileGetTargets(True, True, availTargets, numAvailTargets);
}
/*
* Returns export targets for filename transfers
*/
static void
dndFileGetExportTargets(
DtDragInfo * dtDragInfo,
Atom ** exportTargets,
Cardinal * numExportTargets)
{
dndFileGetTargets(True, False, exportTargets, numExportTargets);
}
/*
* Returns import targets for filename transfers
*/
static void
dndFileGetImportTargets(
DtDropInfo * dtDropInfo,
Atom ** importTargets,
Cardinal * numImportTargets)
{
dndFileGetTargets(False, False, importTargets, numImportTargets);
}
/*
* Initialize protocol specific part of drag data
*/
static void
dndFileConvertInit(
DtDragInfo * dtDragInfo)
{
DtDndContext * dragData = dtDragInfo->dragData;
ConvertState * cvtState;
dragData->data.files = (String *)
XtMalloc(dragData->numItems * sizeof(String));
cvtState = (ConvertState *)XtCalloc(1,sizeof(ConvertState));
dtDragInfo->clientData = (XtPointer)cvtState;
}
/*
* Convert the file names into selection data
*/
static Boolean
dndFileConvert(
Widget dragContext,
DtDragInfo * dtDragInfo,
Atom * selection,
Atom * target,
Atom * returnType,
XtPointer * returnValue,
unsigned long * returnLength,
int * returnFormat,
XSelectionRequestEvent * selectionRequestEvent)
{
DtDndContext * dragData = dtDragInfo->dragData;
ConvertState * cvtState = (ConvertState *)dtDragInfo->clientData;
*returnType = XA_NULL;
*returnValue = (XtPointer)NULL;
*returnLength = 0;
*returnFormat = 8;
/*
* Determine file encoding style.
* Handle Sun ATM file name.
* Reject unknown targets.
*/
if (*target == XA_FILE_NAME || *target == XA_DT_NETFILE) {
if (!dndFileListToSelectionValue(
dragData->data.files, dragData->numItems,
(*target == XA_DT_NETFILE),
returnType, returnValue,
returnLength, returnFormat)) {
return False;
}
} else if (*target == XA_TEXT || *target == XA_STRING) {
if (dragData->numItems > 1 || !cvtState->owCompat)
return False;
if (!dndFileContentsToSelectionValue(dragData->data.files[0],
returnType, returnValue,
returnLength, returnFormat)) {
return False;
}
} else if (*target == XA_SUN_SELN_READONLY) {
cvtState->owCompat = True;
} else if (*target == XA_SUN_DATA_LABEL) {
String name;
if (dragData->numItems > 1)
return False;
if ((name = strrchr(dragData->data.files[0],'/')) != NULL)
name++;
else
name = dragData->data.files[0];
*returnType = XA_STRING;
*returnValue = (XtPointer)XtNewString(name);
*returnLength = strlen(*returnValue);
*returnFormat = 8;
cvtState->owCompat = True;
} else if (*target == XA_SUN_ATM_METHODS) {
Atom *atmAtom = XtNew(Atom);
atmAtom[0] = XA_SUN_ATM_FILE_NAME;
*returnType = XA_ATOM;
*returnValue = (XtPointer)atmAtom;
*returnLength = 1;
*returnFormat = 32;
cvtState->owCompat = True;
} else {
return False;
}
return True;
}
/*
* Clean up from the convert init proc
*/
static void
dndFileConvertFinish(
DtDragInfo * dtDragInfo)
{
DtDndContext * dragData = dtDragInfo->dragData;
if (dragData->data.files) {
XtFree((char *)dragData->data.files);
dragData->data.files = NULL;
}
if (dtDragInfo->clientData)
XtFree((char *)dtDragInfo->clientData);
}
/*
* Returns the transfer targets selected from the export targets
* Prefer _DT_NETFILE over FILE_NAME; prefer local host file names
*/
static void
dndFileTransferTargets(
DtDropInfo * dtDropInfo,
Atom * exportTargets,
Cardinal numExportTargets,
Atom ** transferTargets,
Cardinal * numTransferTargets)
{
Boolean foundNetFile, foundFileName, foundHostName;
Atom target;
int ii;
foundNetFile = foundFileName = foundHostName = False;
for (ii = 0; ii < numExportTargets; ii++) {
if (exportTargets[ii] == XA_DT_NETFILE) {
foundNetFile = True;
} else if (exportTargets[ii] == XA_FILE_NAME) {
foundFileName = True;
} else if (exportTargets[ii] == XA_HOST_NAME) {
foundHostName = True;
}
}
if (foundNetFile && foundFileName && foundHostName) {
target = XA_HOST_NAME;
} else if (foundNetFile) {
target = XA_DT_NETFILE;
} else if (foundFileName) {
target = XA_FILE_NAME;
} else {
*numTransferTargets = 0;
*transferTargets = NULL;
return;
}
*numTransferTargets = 1;
*transferTargets = (Atom *)XtMalloc(*numTransferTargets * sizeof(Atom));
(*transferTargets)[0] = target;
}
/*
* Transfer the selection data into file names
*/
static void
dndFileTransfer(
Widget dropTransfer,
DtDropInfo * dtDropInfo,
Atom * selection,
Atom * target,
Atom * type,
XtPointer value,
unsigned long * length,
int * format)
{
DtDndContext * dropData = dtDropInfo->dropData;
/*
* Ignore if we've already transferred
*/
if (dropData->data.files) {
XtFree(value);
return;
}
/*
* If hosts are the same then request FILE_NAME else request NETFILE
*/
if (*target == XA_HOST_NAME) {
Atom target;
if (strcmp(_DtDndGetHostName(),(char *)value) == 0)
target = XA_FILE_NAME;
else
target = XA_DT_NETFILE;
_DtDndTransferAdd(dropTransfer, dtDropInfo, &target, 1);
/*
* Convert NETFILE or FILE_NAME selection to file list
*/
} else if (*target == XA_DT_NETFILE || *target == XA_FILE_NAME) {
if (!dndSelectionValueToFileList(*type, value,
*length, *format, (*target == XA_DT_NETFILE),
&(dropData->data.files), &(dropData->numItems))) {
dtDropInfo->status = DtDND_FAILURE;
}
}
if (value != NULL)
XtFree(value);
}
/*
* Clean up from the transfer proc
*/
static void
dndFileTransferFinish(
DtDropInfo * dtDropInfo)
{
DtDndContext * dropData = dtDropInfo->dropData;
int ii;
for (ii = 0; ii < dropData->numItems; ii++) {
XtFree((char *)dropData->data.files[ii]);
}
XtFree((char *)dropData->data.files);
}
/*
* Convert the file contents into a STRING selection
*/
static Boolean
dndFileContentsToSelectionValue(
String fileName,
Atom * returnType,
XtPointer * returnValue,
unsigned long * returnLength,
int * returnFormat)
{
String fullPath;
struct stat stBuf;
int fd;
unsigned long bufLen, bytesRead;
char * buf;
fullPath = dndFileEncode(fileName, False);
if (stat(fullPath,&stBuf) == -1)
return False;
if ((fd = open(fullPath, O_RDONLY)) == -1)
return False;
bufLen = stBuf.st_size;
buf = (void *)XtMalloc(bufLen + 1);
bytesRead = read(fd, buf, bufLen);
if (bytesRead == -1 || bytesRead != bufLen) {
XtFree((char *)buf);
return False;
}
buf[bufLen] = '\0';
*returnType = XA_STRING;
*returnValue = (XtPointer)buf;
*returnLength = bufLen;
*returnFormat = 8;
XtFree(fullPath);
return True;
}
/*
* Convert the filename list into a STRING selection
*/
static Boolean
dndFileListToSelectionValue(
String * fileList,
Cardinal numFiles,
Boolean doNetFile,
Atom * returnType,
XtPointer * returnValue,
unsigned long * returnLength,
int * returnFormat)
{
XTextProperty textProp;
Status status;
String * tmpList;
Cardinal ii;
/*
* Encode the file list
*/
tmpList = (String *)XtMalloc(numFiles * sizeof(String));
for (ii = 0; ii < numFiles; ii++) {
tmpList[ii] = dndFileEncode(fileList[ii], doNetFile);
}
/*
* Convert the encoded file list into a string property
*/
status = XStringListToTextProperty(tmpList, numFiles, &textProp);
for (ii = 0; ii < numFiles; ii++) {
XtFree(tmpList[ii]);
}
XtFree((char *)tmpList);
if (status == 0)
return False;
*returnType = textProp.encoding;
*returnValue = (XtPointer)textProp.value;
*returnLength = textProp.nitems;
*returnFormat = textProp.format;
return True;
}
/*
* Convert the STRING selection into a filename list
*/
static Boolean
dndSelectionValueToFileList(
Atom type,
XtPointer value,
unsigned long length,
int format,
Boolean doNetFile,
String ** returnFileList,
Cardinal * returnNumFiles)
{
XTextProperty textProp;
Status status;
String * tmpList;
String * fileList;
int ii, numFiles;
/*
* Convert text prop to file list
*/
textProp.encoding = type;
textProp.value = (unsigned char *)value;
textProp.nitems = length;
textProp.format = format;
status = XTextPropertyToStringList(&textProp, &tmpList, &numFiles);
if (status == 0)
return False;
/*
* Decode the file list
*/
fileList = (String *)XtMalloc(numFiles * sizeof(String));
for (ii = 0; ii < numFiles; ii++) {
fileList[ii] = dndFileDecode(tmpList[ii], doNetFile);
}
XFreeStringList(tmpList);
*returnFileList = fileList;
*returnNumFiles = numFiles;
return True;
}
/*
* Encodes a file name
* Either into ToolTalk NetFile or into a full path if needed
*/
static String
dndFileEncode(
String fileName,
Boolean doNetFile)
{
String netFile;
String retFile;
if (doNetFile) {
netFile = tt_file_netfile(fileName);
if (tt_ptr_error(netFile) == TT_OK) {
retFile = XtNewString(netFile);
} else {
retFile = XtNewString(fileName);
}
tt_free(netFile);
} else if (fileName[0] != '/') {
char cwd[MAXPATHLEN];
char *realPath;
if (getcwd(cwd,MAXPATHLEN) == NULL) {
strcpy(cwd,"/");
}
realPath = XtMalloc(strlen(cwd) + strlen(fileName) + 2);
sprintf(realPath,"%s/%s",cwd,fileName);
retFile = realPath;
} else {
retFile = XtNewString(fileName);
}
return retFile;
}
/*
* Decodes a file name; possibly from a ToolTalk NetFile
*/
static String
dndFileDecode(
String fileName,
Boolean doNetFile)
{
String file;
String retFile;
if (doNetFile) {
file = tt_netfile_file(fileName);
if (tt_ptr_error(file) == TT_OK) {
retFile = XtNewString(file);
} else {
retFile = XtNewString(fileName);
}
tt_free(file);
} else {
retFile = XtNewString(fileName);
}
return retFile;
}

View File

@@ -0,0 +1,548 @@
/* $XConsortium: DndIcon.c /main/5 1996/06/21 17:28:34 ageorge $ */
/*********************************************************************
*
* File: DndIcon.c
*
* Description: Implemenation of DND drag icons
*
*********************************************************************
*
*+SNOTICE
*
* 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 documment 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.
*
*+ENOTICE
*/
#include <stdlib.h>
#include <X11/Xlib.h>
#include <X11/Intrinsic.h>
#include <Xm/Screen.h>
#include <Xm/DragIcon.h>
#include "Dnd.h"
#include "DndP.h"
#include "DndIconI.h"
#include "DtSvcLock.h"
/*
* Component types of a drag icon (source/state/operation)
*/
enum {
DtDND_DRAG_SOURCE,
DtDND_DRAG_STATE,
DtDND_DRAG_OPERATION
};
/*
* The XmDragIcon widgets for the state & operation components
* of a Drag Icon
*/
typedef struct _DragIcons {
Widget validIcon, invalidIcon, noneIcon;
Widget moveIcon, copyIcon, linkIcon;
} DragIcons;
/*
* Collection of drag icons for text & data drags
*/
typedef struct _DragCollection {
DtDndDragSource sourceType;
DragIcons text;
DragIcons data;
Widget textSource;
Widget dataSource;
Widget multipleSource;
} DragCollection;
/*
* The context that the DragCollection is stored against.
* Used in getDragCollection() and destroyDragCollection().
*/
static XContext dragCollectionContext;
/*
* Creates an XmDragIcon for use as the source component of the drag icon.
*/
Widget
DtDndCreateSourceIcon(
Widget widget,
Pixmap pixmap,
Pixmap mask)
{
Widget dragIcon;
Window rootWindow;
int pixmapX, pixmapY;
unsigned int pixmapWidth, pixmapHeight, pixmapBorder, pixmapDepth;
Arg args[20];
Cardinal nn = 0;
_DtSvcWidgetToAppContext(widget);
_DtSvcAppLock(app);
while (XmIsGadget(widget)) {
widget = XtParent(widget);
}
XGetGeometry (XtDisplayOfObject(widget), pixmap, &rootWindow,
&pixmapX, &pixmapY, &pixmapWidth, &pixmapHeight,
&pixmapBorder, &pixmapDepth);
XtSetArg(args[nn], XmNwidth, pixmapWidth); nn++;
XtSetArg(args[nn], XmNheight, pixmapHeight); nn++;
XtSetArg(args[nn], XmNmaxWidth, pixmapWidth); nn++;
XtSetArg(args[nn], XmNmaxHeight, pixmapHeight); nn++;
XtSetArg(args[nn], XmNpixmap, pixmap); nn++;
XtSetArg(args[nn], XmNmask, mask); nn++;
XtSetArg(args[nn], XmNdepth, pixmapDepth); nn++;
dragIcon = XmCreateDragIcon(widget, "sourceIcon", args, nn);
_DtSvcAppUnlock(app);
return(dragIcon);
}
/*
* Calculates the x,y offsets for the state cursor relative to the source
*/
static void
calcStateIconOffset(
Widget sourceIcon,
int *stateOffsetX,
int *stateOffsetY)
{
Display *dpy = XtDisplayOfObject(sourceIcon);
Pixmap pixmap;
Window root;
int pixmapX, pixmapY;
unsigned int pixmapW, pixmapH, junk;
XtVaGetValues(sourceIcon, XmNpixmap, &pixmap, NULL);
if (pixmap == None)
return;
XGetGeometry(dpy, pixmap, &root,
&pixmapX, &pixmapY, &pixmapW, &pixmapH,
&junk, &junk);
if (pixmapH == 16) {
*stateOffsetX = *stateOffsetY = 8;
} else {
*stateOffsetX = *stateOffsetY = 16;
}
}
/*
* Selects or activates the request type of source by setting
* the default drag icon resources on the XmScreen widget.
*/
static void
selectDragSource(
DragCollection *dc,
Widget xmScreen,
DtDndDragSource sourceType,
Widget sourceIcon)
{
Display *dpy = XtDisplayOfObject(xmScreen);
Widget validIcon, invalidIcon, noneIcon,
moveIcon, copyIcon, linkIcon,
defSourceIcon;
int hotX, hotY,
stateOffsetX, stateOffsetY,
offsetDeltaX, offsetDeltaY;
Arg args[30];
Cardinal nn = 0;
/*
* Choose the state/operation/default-source drag icons based
* on the requested drag-source-type
*/
switch (sourceType) {
case DtDND_DRAG_SOURCE_TEXT:
validIcon = dc->text.validIcon;
invalidIcon = dc->text.invalidIcon;
noneIcon = dc->text.noneIcon;
moveIcon = dc->text.moveIcon;
copyIcon = dc->text.copyIcon;
linkIcon = dc->text.linkIcon;
defSourceIcon = dc->textSource;
hotX = text_x_hot;
hotY = text_y_hot;
stateOffsetX = text_x_offset_state;
stateOffsetY = text_y_offset_state;
offsetDeltaX = text_x_offset_delta;
offsetDeltaY = text_y_offset_delta;
break;
case DtDND_DRAG_SOURCE_DATA:
validIcon = dc->data.validIcon;
invalidIcon = dc->data.invalidIcon;
noneIcon = dc->data.noneIcon;
moveIcon = dc->data.moveIcon;
copyIcon = dc->data.copyIcon;
linkIcon = dc->data.linkIcon;
defSourceIcon = dc->dataSource;
hotX = data_x_hot;
hotY = data_y_hot;
stateOffsetX = data_x_offset_state;
stateOffsetY = data_y_offset_state;
offsetDeltaX = data_x_offset_delta;
offsetDeltaY = data_y_offset_delta;
break;
case DtDND_DRAG_SOURCE_MULTIPLE:
validIcon = dc->data.validIcon;
invalidIcon = dc->data.invalidIcon;
noneIcon = dc->data.noneIcon;
moveIcon = dc->data.moveIcon;
copyIcon = dc->data.copyIcon;
linkIcon = dc->data.linkIcon;
defSourceIcon = dc->multipleSource;
hotX = data_x_hot;
hotY = data_y_hot;
stateOffsetX = data_x_offset_state;
stateOffsetY = data_y_offset_state;
offsetDeltaX = data_x_offset_delta;
offsetDeltaY = data_y_offset_delta;
break;
default:
case DtDND_DRAG_SOURCE_DEFAULT:
validIcon = NULL;
invalidIcon = NULL;
noneIcon = NULL;
moveIcon = NULL;
copyIcon = NULL;
linkIcon = NULL;
defSourceIcon = NULL;
hotX = motif_x_hot;
hotY = motif_y_hot;
stateOffsetX = motif_x_offset_state;
stateOffsetY = motif_y_offset_state;
offsetDeltaX = motif_x_offset_delta;
offsetDeltaY = motif_y_offset_delta;
break;
}
/*
* Calculate the offsets of the state icon from the
* DtDND_DRAG_SOURCE_DATA source icon if specified
*/
if (sourceIcon && sourceType == DtDND_DRAG_SOURCE_DATA) {
calcStateIconOffset(sourceIcon, &stateOffsetX, &stateOffsetY);
}
nn = 0;
XtSetArg(args[nn], XmNhotX, hotX); nn++;
XtSetArg(args[nn], XmNhotY, hotY); nn++;
XtSetArg(args[nn], XmNoffsetX, stateOffsetX); nn++;
XtSetArg(args[nn], XmNoffsetY, stateOffsetY); nn++;
if (validIcon)
XtSetValues(validIcon, args, nn);
if (invalidIcon)
XtSetValues(invalidIcon, args, nn);
if (noneIcon)
XtSetValues(noneIcon, args, nn);
nn = 0;
XtSetArg(args[nn], XmNoffsetX, stateOffsetX + offsetDeltaX); nn++;
XtSetArg(args[nn], XmNoffsetY, stateOffsetY + offsetDeltaY); nn++;
if (moveIcon)
XtSetValues(moveIcon, args, nn);
if (copyIcon)
XtSetValues(copyIcon, args, nn);
if (linkIcon)
XtSetValues(linkIcon, args, nn);
/*
* Set the default drag cursor icons for the XmScreen widget
*/
XtVaSetValues(xmScreen,
XmNdefaultValidCursorIcon, validIcon,
XmNdefaultInvalidCursorIcon, invalidIcon,
XmNdefaultNoneCursorIcon, noneIcon,
XmNdefaultMoveCursorIcon, moveIcon,
XmNdefaultCopyCursorIcon, copyIcon,
XmNdefaultLinkCursorIcon, linkIcon,
XmNdefaultSourceCursorIcon, defSourceIcon,
NULL);
dc->sourceType = sourceType;
}
/*
* Create a drag icon widget from the passed bits
*/
static Widget
makeDragIconFromData(
Widget widget,
unsigned char *bits,
unsigned char *maskbits,
int width,
int height,
int component)
{
Widget icon;
Pixmap pixmap, mask;
Display *dpy = XtDisplayOfObject(widget);
Screen *screen = XtScreenOfObject(widget);
Window root = RootWindowOfScreen(screen);
String name;
Arg args[30];
Cardinal nn = 0;
pixmap = XCreatePixmapFromBitmapData(dpy, root,
(char *)bits, width, height,
1, 0, 1);
mask = XCreatePixmapFromBitmapData(dpy, root,
(char *)maskbits, width, height,
1, 0, 1);
switch (component) {
case DtDND_DRAG_SOURCE:
name = "sourceIcon";
break;
case DtDND_DRAG_STATE:
name = "stateIcon";
XtSetArg(args[nn], XmNattachment, XmATTACH_NORTH_WEST); nn++;
XtSetArg(args[nn], XmNoffsetX, -6); nn++;
XtSetArg(args[nn], XmNoffsetY, -6); nn++;
XtSetArg(args[nn], XmNhotX, 3); nn++;
XtSetArg(args[nn], XmNhotY, 3); nn++;
break;
case DtDND_DRAG_OPERATION:
name = "operationIcon";
XtSetArg(args[nn], XmNattachment, XmATTACH_NORTH_WEST); nn++;
XtSetArg(args[nn], XmNoffsetX, 1); nn++;
XtSetArg(args[nn], XmNoffsetY, 1); nn++;
break;
}
XtSetArg(args[nn], XmNwidth, width); nn++;
XtSetArg(args[nn], XmNheight, height); nn++;
XtSetArg(args[nn], XmNmaxWidth, width); nn++;
XtSetArg(args[nn], XmNmaxHeight, height); nn++;
XtSetArg(args[nn], XmNpixmap, pixmap); nn++;
XtSetArg(args[nn], XmNmask, mask); nn++;
XtSetArg(args[nn], XmNdepth, 1); nn++;
icon = XmCreateDragIcon(widget, name, args, nn);
return icon;
}
/*
* Create the collection of text & data drag icons; state/operation
* cursors and source icons.
*/
static DragCollection *
makeDragCollection(
Widget widget)
{
DragCollection *dc = XtNew(DragCollection);
Display *dpy = XtDisplayOfObject(widget);
Screen *screen = XtScreenOfObject(widget);
Window root = RootWindowOfScreen(screen);
Widget xmScreen = XmGetXmScreen(screen);
/*
* Text & Data State Cursors
*/
dc->text.invalidIcon = makeDragIconFromData(widget,
text_invalid_bits, text_invalid_m_bits,
text_invalid_width, text_invalid_height,
DtDND_DRAG_STATE);
dc->text.validIcon = makeDragIconFromData(widget,
text_valid_bits, text_valid_m_bits,
text_valid_width, text_valid_height,
DtDND_DRAG_STATE);
dc->text.noneIcon = makeDragIconFromData(widget,
text_none_bits, text_none_m_bits,
text_none_width, text_none_height,
DtDND_DRAG_STATE);
dc->data.invalidIcon = makeDragIconFromData(widget,
data_invalid_bits, data_invalid_m_bits,
data_invalid_width, data_invalid_height,
DtDND_DRAG_STATE);
dc->data.validIcon = makeDragIconFromData(widget,
data_valid_bits, data_valid_m_bits,
data_valid_width, data_valid_height,
DtDND_DRAG_STATE);
dc->data.noneIcon = makeDragIconFromData(widget,
data_none_bits, data_none_m_bits,
data_none_width, data_none_height,
DtDND_DRAG_STATE);
/*
* Text & Data Operation Cursors
*/
dc->data.moveIcon = makeDragIconFromData(widget,
data_move_bits, data_move_m_bits,
data_move_width, data_move_height,
DtDND_DRAG_OPERATION);
dc->data.copyIcon = makeDragIconFromData(widget,
data_copy_bits, data_copy_m_bits,
data_copy_width, data_copy_height,
DtDND_DRAG_OPERATION);
dc->data.linkIcon = makeDragIconFromData(widget,
data_link_bits, data_link_m_bits,
data_link_width, data_link_height,
DtDND_DRAG_OPERATION);
dc->text.moveIcon = dc->data.moveIcon;
dc->text.copyIcon = dc->data.copyIcon;
dc->text.linkIcon = dc->data.linkIcon;
/*
* Text & Data Source Cursors
*/
dc->textSource = makeDragIconFromData(widget,
text_source_bits, text_source_m_bits,
text_source_width, text_source_height,
DtDND_DRAG_SOURCE);
dc->dataSource = makeDragIconFromData(widget,
data_single_bits, data_single_m_bits,
data_single_width, data_single_height,
DtDND_DRAG_SOURCE);
dc->multipleSource = makeDragIconFromData(widget,
data_multiple_bits, data_multiple_m_bits,
data_multiple_width, data_multiple_height,
DtDND_DRAG_SOURCE);
dc->sourceType = DtDND_DRAG_SOURCE_DEFAULT;
return dc;
}
/*
* Destroys the cached DragCollection and context for it
*/
static void
destroyDragCollection(
Widget widget,
XtPointer clientData,
XtPointer callData)
{
DragCollection *dc = (DragCollection *)clientData;
XtFree((char *)dc);
XDeleteContext(XtDisplayOfObject(widget),
RootWindowOfScreen(XtScreenOfObject(widget)),
dragCollectionContext);
}
/*
* Returns the cached DragCollection; will create one if needed
*/
static DragCollection *
getDragCollection(
Widget xmScreen)
{
DragCollection *dc = NULL;
Display *dpy = XtDisplayOfObject(xmScreen);
Screen *screen = XtScreenOfObject(xmScreen);
Window root = RootWindowOfScreen(screen);
int status;
_DtSvcProcessLock();
if (dragCollectionContext == (XContext)NULL) {
dragCollectionContext = XUniqueContext();
}
_DtSvcProcessUnlock();
status = XFindContext(dpy, root, dragCollectionContext, (XtPointer)&dc);
if (status != 0) {
dc = makeDragCollection(xmScreen);
XSaveContext(dpy, root, dragCollectionContext, (XtPointer)dc);
XtAddCallback(xmScreen, XmNdestroyCallback,
destroyDragCollection, (XtPointer)dc);
}
return dc;
}
/*
* Module-public function to select/activate a source type drag icon
*/
void
_DtDndSelectDragSource(
Widget widget,
DtDndDragSource sourceType,
Widget sourceIcon)
{
Widget xmScreen = XmGetXmScreen(XtScreenOfObject(widget));
DragCollection *dc = getDragCollection(xmScreen);
selectDragSource(dc, xmScreen, sourceType, sourceIcon);
}
void
_DtDndGetIconOffset(
Widget dragContext,
DtDndDragSource sourceType,
int * offsetX,
int * offsetY)
{
Widget sourceIcon;
int stateOffsetX, stateOffsetY;
switch (sourceType) {
default:
case DtDND_DRAG_SOURCE_DEFAULT:
*offsetX = -(motif_x_hot + motif_x_offset_state);
*offsetY = -(motif_y_hot + motif_y_offset_state);
break;
case DtDND_DRAG_SOURCE_TEXT:
*offsetX = -(text_x_hot + text_x_offset_state);
*offsetY = -(text_y_hot + text_y_offset_state);
break;
case DtDND_DRAG_SOURCE_DATA:
case DtDND_DRAG_SOURCE_MULTIPLE:
*offsetX = -(data_x_hot + data_x_offset_state);
*offsetY = -(data_y_hot + data_y_offset_state);
XtVaGetValues(dragContext,
XmNsourcePixmapIcon, &sourceIcon,
NULL);
if (sourceIcon != NULL) {
calcStateIconOffset(sourceIcon,
&stateOffsetX, &stateOffsetY);
*offsetX = -(data_x_hot + stateOffsetX);
*offsetY = -(data_y_hot + stateOffsetY);
}
break;
}
}

View File

@@ -0,0 +1,401 @@
/* $XConsortium: DndIconI.h /main/3 1995/10/26 15:05:58 rswiston $ */
/*********************************************************************
*
* File: DndIconI.h
*
* Description: Private include file containing DND drag icons bitmaps
*
*********************************************************************
*
*+SNOTICE
*
* 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 documment 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.
*
*+ENOTICE
*/
#ifndef _Dt_DndIconI_h
#define _Dt_DndIconI_h
#ifdef __cplusplus
extern "C" {
#endif
/*-------------------------------------------------------------------
* Motif Defaults
*-------------------------------------------------------------------*/
#define motif_x_hot 1
#define motif_y_hot 1
#define motif_x_offset_state -8
#define motif_y_offset_state -2
#define motif_x_offset_delta 0
#define motif_y_offset_delta 0
/*-------------------------------------------------------------------
* Text Drags: Cursors
*-------------------------------------------------------------------*/
#define text_x_hot 1
#define text_y_hot 1
#define text_x_offset_state 1
#define text_y_offset_state 1
#define text_x_offset_delta 7
#define text_y_offset_delta 3
/*
* Text: State Valid
*/
#define text_valid_width 16
#define text_valid_height 16
static unsigned char text_valid_bits[] = {
#ifdef OLDTEXTVALID
0x00, 0x00, 0x02, 0x00, 0x06, 0x00, 0x0e, 0x00, 0x1e, 0x00, 0x3e, 0x00,
0x7e, 0x00, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
#else
0x00, 0x00, 0xfe, 0x01, 0xfe, 0x00, 0x7e, 0x00, 0x3e, 0x00, 0x1e, 0x00,
0x0e, 0x00, 0x06, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
#endif
static unsigned char text_valid_m_bits[] = {
#ifdef OLDTEXTVALID
0x03, 0x00, 0x07, 0x00, 0x0f, 0x00, 0x1f, 0x00, 0x3f, 0x00, 0x7f, 0x00,
0xff, 0x00, 0xff, 0x01, 0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
#else
0xff, 0x07, 0xff, 0x03, 0xff, 0x01, 0xff, 0x00, 0x7f, 0x00, 0x3f, 0x00,
0x1f, 0x00, 0x0f, 0x00, 0x07, 0x00, 0x03, 0x00, 0x01, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
#endif
/*
* Text: State Invalid
*/
#define text_invalid_width 16
#define text_invalid_height 16
static unsigned char text_invalid_bits[] = {
0x00, 0x00, 0xe0, 0x03, 0xf8, 0x0f, 0x1c, 0x1c, 0x0c, 0x1e, 0x06, 0x37,
0x86, 0x33, 0xc6, 0x31, 0xe6, 0x30, 0x76, 0x30, 0x3c, 0x18, 0x1c, 0x1c,
0xf8, 0x0f, 0xe0, 0x03, 0x00, 0x00, 0x00, 0x00};
static unsigned char text_invalid_m_bits[] = {
0xe0, 0x03, 0xf8, 0x0f, 0xfc, 0x1f, 0xfe, 0x3f, 0x1e, 0x3f, 0x8f, 0x7f,
0xcf, 0x7f, 0xef, 0x7b, 0xff, 0x79, 0xff, 0x78, 0x7e, 0x3c, 0xfe, 0x3f,
0xfc, 0x1f, 0xf8, 0x0f, 0xe0, 0x03, 0x00, 0x00};
/*
* Text: None
*/
#define text_none_width 16
#define text_none_height 16
static unsigned char text_none_bits[] = {
0x00, 0x00, 0xe0, 0x03, 0xf8, 0x0f, 0x1c, 0x1c, 0x0c, 0x1e, 0x06, 0x37,
0x86, 0x33, 0xc6, 0x31, 0xe6, 0x30, 0x76, 0x30, 0x3c, 0x18, 0x1c, 0x1c,
0xf8, 0x0f, 0xe0, 0x03, 0x00, 0x00, 0x00, 0x00};
static unsigned char text_none_m_bits[] = {
0xe0, 0x03, 0xf8, 0x0f, 0xfc, 0x1f, 0xfe, 0x3f, 0x1e, 0x3f, 0x8f, 0x7f,
0xcf, 0x7f, 0xef, 0x7b, 0xff, 0x79, 0xff, 0x78, 0x7e, 0x3c, 0xfe, 0x3f,
0xfc, 0x1f, 0xf8, 0x0f, 0xe0, 0x03, 0x00, 0x00};
/*-------------------------------------------------------------------
* Text Drags: Operation Cursors
*-------------------------------------------------------------------*/
/* Use Data Operation Cursors */
/*
* Text: Operation Move
*/
/*
* Text: Operation Copy
*/
/*
* Text: Operation Link
*/
/*-------------------------------------------------------------------
* Text Drags: Source Cursor
*-------------------------------------------------------------------*/
#define text_source_width 32
#define text_source_height 32
static unsigned char text_source_bits[] = {
#ifdef OLDTEXTSOURCE
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xd8, 0xdb, 0xcd, 0x0d, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xbe, 0x7f, 0x1f,
0x00, 0x00, 0x00, 0x00, 0xb8, 0xf6, 0xfd, 0x16, 0x00, 0x00, 0x00, 0x00,
0xe8, 0x7b, 0x76, 0x0f, 0x00, 0x00, 0x00, 0x00, 0xb8, 0xbb, 0xff, 0x06,
0x00, 0x00, 0x00, 0x00, 0xd8, 0xde, 0x7b, 0x1d, 0x00, 0x00, 0x00, 0x00,
0x78, 0xd7, 0xb4, 0x0b, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xad, 0xd5, 0x0f,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
#else
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0xc0, 0xcd, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00, 0xb0, 0x7f, 0x1f,
0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0xfd, 0x16, 0x00, 0x00, 0x00, 0x00,
0x00, 0x7b, 0x76, 0x0f, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xbb, 0xff, 0x06,
0x00, 0x00, 0x00, 0x00, 0xf0, 0xde, 0x7b, 0x1d, 0x00, 0x00, 0x00, 0x00,
0x78, 0x77, 0xb7, 0x0b, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xbd, 0xdd, 0x0f,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
#endif
static unsigned char text_source_m_bits[] = {
#ifdef OLDTEXTSOURCE
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0xff, 0xff, 0x3f,
0xfc, 0xff, 0xff, 0x3f, 0xfc, 0xff, 0xff, 0x3f, 0xfc, 0xff, 0xff, 0x3f,
0xfc, 0xff, 0xff, 0x3f, 0xfc, 0xff, 0xff, 0x3f, 0xfc, 0xff, 0xff, 0x3f,
0xfc, 0xff, 0xff, 0x3f, 0xfc, 0xff, 0xff, 0x3f, 0xfc, 0xff, 0xff, 0x3f,
0xfc, 0xff, 0xff, 0x3f, 0xfc, 0xff, 0xff, 0x3f, 0xfc, 0xff, 0xff, 0x3f,
0xfc, 0xff, 0xff, 0x3f, 0xfc, 0xff, 0xff, 0x3f, 0xfc, 0xff, 0xff, 0x3f,
0xfc, 0xff, 0xff, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
#else
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0xff, 0x3f,
0x00, 0xf0, 0xff, 0x3f, 0x00, 0xf8, 0xff, 0x3f, 0x00, 0xfc, 0xff, 0x3f,
0x00, 0xfe, 0xff, 0x3f, 0x00, 0xff, 0xff, 0x3f, 0x80, 0xff, 0xff, 0x3f,
0xc0, 0xff, 0xff, 0x3f, 0xe0, 0xff, 0xff, 0x3f, 0xf0, 0xff, 0xff, 0x3f,
0xf8, 0xff, 0xff, 0x3f, 0xfc, 0xff, 0xff, 0x3f, 0xfc, 0xff, 0xff, 0x3f,
0xfc, 0xff, 0xff, 0x3f, 0xfc, 0xff, 0xff, 0x3f, 0xfc, 0xff, 0xff, 0x3f,
0xfc, 0xff, 0xff, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
#endif
/*-------------------------------------------------------------------
* Data Drags: Cursors
*------------------------------------------------------------------*/
#define data_x_hot 3
#define data_y_hot 3
#define data_x_offset_state 11
#define data_y_offset_state 11
#define data_x_offset_delta 7
#define data_y_offset_delta 7
/*
* Data: State Valid
*/
#define data_valid_width 16
#define data_valid_height 16
static unsigned char data_valid_bits[] = {
0x00, 0x00, 0x06, 0x00, 0x1e, 0x00, 0x7c, 0x00, 0xfc, 0x01, 0xf8, 0x07,
0xf8, 0x07, 0xf0, 0x01, 0xf0, 0x03, 0x60, 0x07, 0x60, 0x0e, 0x00, 0x1c,
0x00, 0x38, 0x00, 0x70, 0x00, 0x60, 0x00, 0x00};
static unsigned char data_valid_m_bits[] = {
0x07, 0x00, 0x1f, 0x00, 0x7f, 0x00, 0xfe, 0x01, 0xfe, 0x07, 0xfc, 0x0f,
0xfc, 0x0f, 0xf8, 0x07, 0xf8, 0x07, 0xf0, 0x0f, 0xf0, 0x1f, 0x60, 0x3e,
0x00, 0x7c, 0x00, 0xf8, 0x00, 0xf0, 0x00, 0x60};
/*
* Data: State Invalid
*/
#define data_invalid_width 16
#define data_invalid_height 16
static unsigned char data_invalid_bits[] = {
0x00, 0x00, 0xe0, 0x03, 0xf8, 0x0f, 0x1c, 0x1c, 0x0c, 0x1e, 0x06, 0x37,
0x86, 0x33, 0xc6, 0x31, 0xe6, 0x30, 0x76, 0x30, 0x3c, 0x18, 0x1c, 0x1c,
0xf8, 0x0f, 0xe0, 0x03, 0x00, 0x00, 0x00, 0x00};
static unsigned char data_invalid_m_bits[] = {
0xe0, 0x03, 0xf8, 0x0f, 0xfc, 0x1f, 0xfe, 0x3f, 0x1e, 0x3f, 0x8f, 0x7f,
0xcf, 0x7f, 0xef, 0x7b, 0xff, 0x79, 0xff, 0x78, 0x7e, 0x3c, 0xfe, 0x3f,
0xfc, 0x1f, 0xf8, 0x0f, 0xe0, 0x03, 0x00, 0x00};
/*
* Data: State None
*/
#define data_none_width 16
#define data_none_height 16
static unsigned char data_none_bits[] = {
0x00, 0x00, 0xe0, 0x03, 0xf8, 0x0f, 0x1c, 0x1c, 0x0c, 0x1e, 0x06, 0x37,
0x86, 0x33, 0xc6, 0x31, 0xe6, 0x30, 0x76, 0x30, 0x3c, 0x18, 0x1c, 0x1c,
0xf8, 0x0f, 0xe0, 0x03, 0x00, 0x00, 0x00, 0x00};
static unsigned char data_none_m_bits[] = {
0xe0, 0x03, 0xf8, 0x0f, 0xfc, 0x1f, 0xfe, 0x3f, 0x1e, 0x3f, 0x8f, 0x7f,
0xcf, 0x7f, 0xef, 0x7b, 0xff, 0x79, 0xff, 0x78, 0x7e, 0x3c, 0xfe, 0x3f,
0xfc, 0x1f, 0xf8, 0x0f, 0xe0, 0x03, 0x00, 0x00};
/*-------------------------------------------------------------------
* Data Drags: Operation Cursors
*-------------------------------------------------------------------*/
/*
* Data: Operation Move
*/
#define data_move_width 16
#define data_move_height 16
static unsigned char data_move_bits[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
static unsigned char data_move_m_bits[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
/*
* Data: Operation Copy
*/
#define data_copy_width 16
#define data_copy_height 16
static unsigned char data_copy_bits[] = {
0x00, 0x00, 0xfe, 0x01, 0x02, 0x01, 0x02, 0x01, 0x02, 0x1f, 0x02, 0x11,
0x02, 0x11, 0x02, 0x11, 0x02, 0x11, 0x02, 0x11, 0xfe, 0x11, 0x20, 0x10,
0x20, 0x10, 0xe0, 0x1f, 0x00, 0x00, 0x00, 0x00};
static unsigned char data_copy_m_bits[] = {
0xff, 0x03, 0xff, 0x03, 0xff, 0x03, 0xff, 0x3f, 0xff, 0x3f, 0xff, 0x3f,
0xff, 0x3f, 0xff, 0x3f, 0xff, 0x3f, 0xff, 0x3f, 0xff, 0x3f, 0xff, 0x3f,
0xf0, 0x3f, 0xf0, 0x3f, 0xf0, 0x3f, 0x00, 0x00};
/*
* Data: Operation Link
*/
#define data_link_width 16
#define data_link_height 16
static unsigned char data_link_bits[] = {
0x00, 0x00, 0xfe, 0x03, 0x02, 0x02, 0x02, 0x02, 0x32, 0x02, 0x32, 0x3e,
0x42, 0x20, 0x82, 0x20, 0x02, 0x21, 0x3e, 0x26, 0x20, 0x26, 0x20, 0x20,
0x20, 0x20, 0xe0, 0x3f, 0x00, 0x00, 0x00, 0x00};
static unsigned char data_link_m_bits[] = {
0xff, 0x07, 0xff, 0x07, 0xff, 0x07, 0xff, 0x07, 0xff, 0x7f, 0xff, 0x7f,
0xff, 0x7f, 0xff, 0x7f, 0xff, 0x7f, 0xff, 0x7f, 0xff, 0x7f, 0xf0, 0x7f,
0xf0, 0x7f, 0xf0, 0x7f, 0xf0, 0x7f, 0x00, 0x00};
/*-------------------------------------------------------------------
* Data Drags: Source Icons
*-------------------------------------------------------------------*/
/*
* Data Source: Single
*/
#define data_single_width 32
#define data_single_height 32
static unsigned char data_single_bits[] = {
0x00, 0x00, 0x00, 0x00, 0xf0, 0xff, 0x7f, 0x00, 0x10, 0x00, 0xc0, 0x00,
0x10, 0x00, 0x40, 0x01, 0x10, 0x00, 0x40, 0x02, 0x10, 0x00, 0x40, 0x04,
0x10, 0x00, 0xc0, 0x0f, 0x10, 0x00, 0x00, 0x08, 0x10, 0x00, 0x00, 0x08,
0x10, 0x00, 0x00, 0x08, 0x10, 0x00, 0x00, 0x08, 0x10, 0x00, 0x00, 0x08,
0x10, 0x00, 0x00, 0x08, 0x10, 0x00, 0x00, 0x08, 0x10, 0x00, 0x00, 0x08,
0x10, 0x00, 0x00, 0x08, 0x10, 0x00, 0x00, 0x08, 0x10, 0x00, 0x00, 0x08,
0x10, 0x00, 0x00, 0x08, 0x10, 0x00, 0x00, 0x08, 0x10, 0x00, 0x00, 0x08,
0x10, 0x00, 0x00, 0x08, 0x10, 0x00, 0x00, 0x08, 0x10, 0x00, 0x00, 0x08,
0x10, 0x00, 0x00, 0x08, 0x10, 0x00, 0x00, 0x08, 0x10, 0x00, 0x00, 0x08,
0x10, 0x00, 0x00, 0x08, 0x10, 0x00, 0x00, 0x08, 0x10, 0x00, 0x00, 0x08,
0x10, 0x00, 0x00, 0x08, 0xf0, 0xff, 0xff, 0x0f};
static unsigned char data_single_m_bits[] = {
0x00, 0x00, 0x00, 0x00, 0xf0, 0xff, 0x7f, 0x00, 0xf0, 0xff, 0xff, 0x00,
0xf0, 0xff, 0xff, 0x01, 0xf0, 0xff, 0xff, 0x03, 0xf0, 0xff, 0xff, 0x07,
0xf0, 0xff, 0xff, 0x0f, 0xf0, 0xff, 0xff, 0x0f, 0xf0, 0xff, 0xff, 0x0f,
0xf0, 0xff, 0xff, 0x0f, 0xf0, 0xff, 0xff, 0x0f, 0xf0, 0xff, 0xff, 0x0f,
0xf0, 0xff, 0xff, 0x0f, 0xf0, 0xff, 0xff, 0x0f, 0xf0, 0xff, 0xff, 0x0f,
0xf0, 0xff, 0xff, 0x0f, 0xf0, 0xff, 0xff, 0x0f, 0xf0, 0xff, 0xff, 0x0f,
0xf0, 0xff, 0xff, 0x0f, 0xf0, 0xff, 0xff, 0x0f, 0xf0, 0xff, 0xff, 0x0f,
0xf0, 0xff, 0xff, 0x0f, 0xf0, 0xff, 0xff, 0x0f, 0xf0, 0xff, 0xff, 0x0f,
0xf0, 0xff, 0xff, 0x0f, 0xf0, 0xff, 0xff, 0x0f, 0xf0, 0xff, 0xff, 0x0f,
0xf0, 0xff, 0xff, 0x0f, 0xf0, 0xff, 0xff, 0x0f, 0xf0, 0xff, 0xff, 0x0f,
0xf0, 0xff, 0xff, 0x0f, 0xf0, 0xff, 0xff, 0x0f};
/*
* Data Source: Multiple
*/
#define data_multiple_width 32
#define data_multiple_height 32
static unsigned char data_multiple_bits[] = {
0xfc, 0xff, 0x0f, 0x00, 0x04, 0x00, 0x30, 0x00, 0x04, 0x00, 0xd0, 0x1f,
0x04, 0x00, 0x90, 0x10, 0x04, 0x00, 0x10, 0xf1, 0x04, 0x00, 0xf0, 0x93,
0x04, 0x00, 0x00, 0x92, 0x04, 0x00, 0x00, 0x92, 0x04, 0x00, 0x00, 0x92,
0x04, 0x00, 0x00, 0x92, 0x04, 0x00, 0x00, 0x92, 0x04, 0x00, 0x00, 0x92,
0x04, 0x00, 0x00, 0x92, 0x04, 0x00, 0x00, 0x92, 0x04, 0x00, 0x00, 0x92,
0x04, 0x00, 0x00, 0x92, 0x04, 0x00, 0x00, 0x92, 0x04, 0x00, 0x00, 0x92,
0x04, 0x00, 0x00, 0x92, 0x04, 0x00, 0x00, 0x92, 0x04, 0x00, 0x00, 0x92,
0x04, 0x00, 0x00, 0x92, 0x04, 0x00, 0x00, 0x92, 0x04, 0x00, 0x00, 0x92,
0x04, 0x00, 0x00, 0x92, 0x04, 0x00, 0x00, 0x92, 0x04, 0x00, 0x00, 0x92,
0xfc, 0xff, 0xff, 0x93, 0x20, 0x00, 0x00, 0x90, 0xe0, 0xff, 0xff, 0x9f,
0x00, 0x01, 0x00, 0x80, 0x00, 0xff, 0xff, 0xff};
static unsigned char data_multiple_m_bits[] = {
0xfc, 0xff, 0x0f, 0x00, 0xfc, 0xff, 0x3f, 0x00, 0xfc, 0xff, 0xff, 0x1f,
0xfc, 0xff, 0xff, 0x1f, 0xfc, 0xff, 0xff, 0xff, 0xfc, 0xff, 0xff, 0xff,
0xfc, 0xff, 0xff, 0xff, 0xfc, 0xff, 0xff, 0xff, 0xfc, 0xff, 0xff, 0xff,
0xfc, 0xff, 0xff, 0xff, 0xfc, 0xff, 0xff, 0xff, 0xfc, 0xff, 0xff, 0xff,
0xfc, 0xff, 0xff, 0xff, 0xfc, 0xff, 0xff, 0xff, 0xfc, 0xff, 0xff, 0xff,
0xfc, 0xff, 0xff, 0xff, 0xfc, 0xff, 0xff, 0xff, 0xfc, 0xff, 0xff, 0xff,
0xfc, 0xff, 0xff, 0xff, 0xfc, 0xff, 0xff, 0xff, 0xfc, 0xff, 0xff, 0xff,
0xfc, 0xff, 0xff, 0xff, 0xfc, 0xff, 0xff, 0xff, 0xfc, 0xff, 0xff, 0xff,
0xfc, 0xff, 0xff, 0xff, 0xfc, 0xff, 0xff, 0xff, 0xfc, 0xff, 0xff, 0xff,
0xfc, 0xff, 0xff, 0xff, 0xe0, 0xff, 0xff, 0xff, 0xe0, 0xff, 0xff, 0xff,
0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff};
#ifdef __cplusplus
}
#endif
#endif /* _Dt_DndIconI_h */

View File

@@ -0,0 +1,310 @@
/* $XConsortium: DndP.h /main/4 1996/06/21 17:28:31 ageorge $ */
/*********************************************************************
*
* File: DndP.h
*
* Description: Private include file for DND Convenience API.
*
*********************************************************************
*
*+SNOTICE
*
* RESTRICTED CONFIDENTIAL INFORMATION:
*
* The information in this document is subject to special
* restrictions in a confidential disclosure agreement bertween
* HP, IBM, Sun, USL, SCO and Univel. Do not distribute this
* document outside HP, IBM, Sun, USL, SCO, or Univel wihtout
* Sun's specific written approval. This documment 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.
*
*+ENOTICE
*/
#ifndef _Dt_DndP_h
#define _Dt_DndP_h
#include <stdarg.h>
#ifdef __cplusplus
extern "C" {
#endif
/*
* Drag and Drop selection targets
*/
extern Atom XA_TARGETS;
extern Atom XA_TIMESTAMP;
extern Atom XA_MULTIPLE;
extern Atom XA_DELETE;
extern Atom XA_NULL;
extern Atom XA_TEXT;
extern Atom XA_HOST_NAME;
extern Atom XA_SUN_FILE_HOST_NAME;
extern Atom XA_SUN_ENUM_COUNT;
extern Atom XA_SUN_DATA_LABEL;
extern Atom XA_SUN_SELN_READONLY;
extern Atom XA_SUN_ATM_FILE_NAME;
extern Atom XA_SUN_ATM_METHODS;
#define DtGetAtom(display, atomname) \
XmInternAtom((display),(atomname),False)
/*
* Drag Icon Styles
*/
typedef enum {
DtDND_DRAG_SOURCE_DEFAULT,
DtDND_DRAG_SOURCE_TEXT,
DtDND_DRAG_SOURCE_DATA,
DtDND_DRAG_SOURCE_MULTIPLE
} DtDndDragSource;
/*
* Drag-n-Drop Data Transfer Protocol
*/
typedef struct _DtDndTransfer {
Atom * targets;
Cardinal numTargets;
struct _DtDndMethods * methods;
} DtDndTransfer;
/*
* Drag Initiator Structure
*/
typedef struct _DtDragInfo {
Widget dragInitiator;
Widget dragContext;
DtDndProtocol protocol;
Cardinal numItems;
unsigned char operations;
XtCallbackList dragConvertCallback;
XtCallbackList dragFinishCallback;
XtCallbackList dropOnRootCallback;
XtCallbackList dragDropFinishCallback;
XtCallbackList dropFinishCallback;
XtCallbackList topLevelEnterCallback;
XtCallbackList topLevelLeaveCallback;
XtCallbackList dropStartCallback;
Widget sourceIcon;
Boolean bufferIsText;
DtDndTransfer * transfer;
DtDndContext * dragData;
Boolean inRoot;
Window backdropWindow;
DtDndStatus status;
XtPointer clientData;
} DtDragInfo;
/*
* Drop Receiver Existing Registration Structure
*/
typedef struct _DtDropSiteInfo {
XtCallbackProc dropProc;
unsigned char operations;
Atom * importTargets;
int numImportTargets;
} DtDropSiteInfo;
/*
* Drop Receiver Data Transfer Structure
*/
typedef struct _DtTransferInfo {
Widget dragContext;
DtDndProtocol protocol;
unsigned char operation;
struct _DtDndMethods * methods;
Atom * transferTargets;
Cardinal numTransferTargets;
Cardinal currentTransfer;
Boolean appTransferCalled;
XEvent * event;
Position x, y;
XtPointer clientData;
XtCallbackList dropAnimateCallback;
} DtTransferInfo;
/*
* Drop Receiver Registration Structure
*/
typedef struct _DtDropInfo {
Widget dropReceiver;
DtDndProtocol protocols;
unsigned char operations;
XtCallbackList dropTransferCallback;
XtCallbackList dropAnimateCallback;
Boolean textIsBuffer;
DtDropSiteInfo * dropSiteInfo;
DtDndTransfer * transfers;
Cardinal numTransfers;
DtTransferInfo * transferInfo;
DtDndContext * dropData;
DtDndStatus status;
} DtDropInfo;
/*
* Drag-n-Drop Data Transfer Protocol Function Prototypes
*/
typedef void
(*DtDndGetAvailTargetsProc)(
DtDragInfo * dtDragInfo,
Atom ** returnAvailTargetsList,
Cardinal * returnNumAvailTargets);
typedef void
(*DtDndGetExportTargetsProc)(
DtDragInfo * dtDragInfo,
Atom ** returnExportTargetsList,
Cardinal * returnNumExportTargets);
typedef void
(*DtDndGetImportTargetsProc)(
DtDropInfo * dtDropInfo,
Atom ** returnImportTargetsList,
Cardinal * returnNumImportTargets);
typedef void
(*DtDndConvertInitProc)(
DtDragInfo * dtDragInfo);
typedef Boolean
(*DtDndConvertProc)(
Widget dragContext,
DtDragInfo * dtDragInfo,
Atom * selection,
Atom * target,
Atom * returnType,
XtPointer * returnValue,
unsigned long * returnLength,
int * returnFormat,
XSelectionRequestEvent *selectionRequestEvent);
typedef void
(*DtDndConvertFinishProc)(
DtDragInfo * dtDragInfo);
typedef void
(*DtDndTransferTargetsProc)(
DtDropInfo * dtDropInfo,
Atom * exportTargets,
Cardinal numExportTargets,
Atom ** returnTransferTargetsList,
Cardinal * returnNumTransferTargets);
typedef void
(*DtDndTransferProc)(
Widget dropTransfer,
DtDropInfo * dtDropInfo,
Atom * selection,
Atom * target,
Atom * type,
XtPointer value,
unsigned long * length,
int * format);
typedef void
(*DtDndTransferFinishProc)(
DtDropInfo * dtDropInfo);
/*
* Drag-n-Drop Data Transfer Methods
*/
typedef struct _DtDndMethods {
String name;
DtDndProtocol protocol;
DtDndDragSource sourceType;
DtDndGetAvailTargetsProc getAvailTargets;
DtDndGetExportTargetsProc getExportTargets;
DtDndGetImportTargetsProc getImportTargets;
DtDndConvertInitProc convertInit;
DtDndConvertProc convert;
DtDndConvertFinishProc convertFinish;
DtDndTransferTargetsProc transferTargets;
DtDndTransferProc transfer;
DtDndTransferFinishProc transferFinish;
} DtDndMethods;
/*
* Drag-n-Drop Private Utility Functions
*/
extern DtDndTransfer *
_DtDndCreateExportTransfer(
DtDragInfo * dtDragInfo);
extern DtDndTransfer *
_DtDndCreateImportTransfers(
DtDropInfo * dtDropInfo,
Cardinal * numTransfers);
extern void
_DtDndDestroyTransfers(
DtDndTransfer * transfers,
Cardinal numTransfers);
extern DtDndTransfer *
_DtDndTransferFromTargets(
DtDndTransfer * transfers,
Cardinal numTransfers,
Atom * targets,
Cardinal numTargets);
extern void
_DtDndTransferAdd(
Widget dropTransfer,
DtDropInfo * dtDropInfo,
Atom * transferTargets,
Cardinal numTransferTargets);
extern XtCallbackList
_DtDndCopyCallbackList(
XtCallbackList callbacks);
extern void
_DtDndCallCallbackList(
Widget widget,
XtCallbackList callbacks,
XtPointer calldata);
extern void
_DtDndSelectDragSource(
Widget anyWidget,
DtDndDragSource sourceType,
Widget sourceIcon);
extern void
_DtDndGetIconOffset(
Widget dragContext,
DtDndDragSource sourceType,
int * offsetXReturn,
int * offsetYReturn);
extern String
_DtDndGetHostName(void);
#ifdef DEBUG
extern void _DtDndPrintTargets(Display*,Atom*,Cardinal);
extern void _DtDndPrintTransfers(Display*,DtDndTransfer*,Cardinal);
#endif
#ifdef __cplusplus
}
#endif
#endif /* _Dt_DndP_h */

View File

@@ -0,0 +1,385 @@
/* $XConsortium: DndText.c /main/5 1996/08/28 17:46:27 drk $ */
/*********************************************************************
*
* File: DndText.c
*
* Description: Implementation of the Text Transfer routines
* for the DND Convenience API.
*
*********************************************************************
*
*+SNOTICE
*
* RESTRICTED CONFIDENTIAL INFORMATION:
*
* The information in this document is subject to special
* restrictions in a confidential disclosure agreement bertween
* HP, IBM, Sun, USL, SCO and Univel. Do not distribute this
* document outside HP, IBM, Sun, USL, SCO, or Univel wihtout
* Sun's specific written approval. This documment 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.
*
*+ENOTICE
*/
#include <stdlib.h>
#include <locale.h>
#include <X11/Intrinsic.h>
#include <Xm/AtomMgr.h>
#include <Xm/DragC.h>
#include <Xm/DropSMgr.h>
#include <Xm/DropTrans.h>
#include "Dnd.h"
#include "DndP.h"
#include "DtSvcLock.h"
/*
* Text Transfer Function Prototypes
*/
static void dndTextGetTargets(Atom**, Cardinal*);
static void dndTextGetAvailTargets(DtDragInfo*, Atom**, Cardinal*);
static void dndTextGetExportTargets(DtDragInfo*, Atom**, Cardinal*);
static void dndTextGetImportTargets(DtDropInfo*, Atom**, Cardinal*);
static void dndTextConvertInit(DtDragInfo*);
static Boolean dndTextConvert(Widget, DtDragInfo*, Atom*, Atom*,
Atom*, XtPointer*, unsigned long*, int*,
XSelectionRequestEvent*);
static void dndTextConvertFinish(DtDragInfo*);
static void dndTextTransferTargets(DtDropInfo*,
Atom*, Cardinal, Atom**, Cardinal*);
static void dndTextTransfer(Widget, DtDropInfo*, Atom*, Atom*,
Atom*, XtPointer, unsigned long*, int*);
static void dndTextTransferFinish(DtDropInfo*);
/*
* Text Transfer Selection Target
*/
static Atom XA_COMPOUND_TEXT;
static Boolean dndPreferString;
/*
* Text Transfer ProtocolInfo
*/
static DtDndMethods dndTextTransferProtocol = {
"DtDndTextTransfer", /* name */
(DtDndProtocol)DtDND_TEXT_TRANSFER, /* protocol */
DtDND_DRAG_SOURCE_TEXT, /* sourceType */
dndTextGetAvailTargets, /* getAvailTargets */
dndTextGetExportTargets, /* getExportTargets */
dndTextGetImportTargets, /* getImportTargets */
dndTextConvertInit, /* convertInit */
dndTextConvert, /* convert */
dndTextConvertFinish, /* convertFinish */
dndTextTransferTargets, /* transferTargets */
dndTextTransfer, /* transfer */
dndTextTransferFinish, /* transferFinish */
};
/*
* Text transfer protocol initialization
*/
DtDndMethods *
_DtDndTextTransferProtocolInitialize(
Display * display)
{
_DtSvcProcessLock();
if (XA_COMPOUND_TEXT == 0) {
XA_COMPOUND_TEXT = DtGetAtom(display, "COMPOUND_TEXT");
dndPreferString = (strcmp(setlocale(LC_CTYPE,NULL),"C") == 0);
#ifdef DEBUG
printf("locale = %s, dndPreferString = %d\n",
setlocale(LC_CTYPE,NULL), dndPreferString);
#endif
}
_DtSvcProcessUnlock();
return &dndTextTransferProtocol;
}
/*
* Returns generic export/import targets for text transfers
*/
static void
dndTextGetTargets(
Atom ** targets,
Cardinal * numTargets)
{
int ii = 0;
*numTargets = 3;
*targets = (Atom *)XtMalloc(*numTargets * sizeof(Atom));
(*targets)[ii++] = XA_COMPOUND_TEXT;
(*targets)[ii++] = XA_TEXT;
(*targets)[ii++] = XA_STRING;
}
/*
* Returns available targets for text transfers
*/
static void
dndTextGetAvailTargets(
DtDragInfo * dtDragInfo,
Atom ** availTargets,
Cardinal * numAvailTargets)
{
dndTextGetTargets(availTargets, numAvailTargets);
}
/*
* Returns export targets for text transfers
*/
static void
dndTextGetExportTargets(
DtDragInfo * dtDragInfo,
Atom ** exportTargets,
Cardinal * numExportTargets)
{
dndTextGetTargets(exportTargets, numExportTargets);
}
/*
* Returns import targets for text transfers
*/
static void
dndTextGetImportTargets(
DtDropInfo * dtDropInfo,
Atom ** importTargets,
Cardinal * numImportTargets)
{
dndTextGetTargets(importTargets, numImportTargets);
}
/*
* Initialize protocol specific part of drag data
*/
static void
dndTextConvertInit(
DtDragInfo * dtDragInfo)
{
DtDndContext * dragData = dtDragInfo->dragData;
dragData->data.strings = (XmString *)
XtMalloc(dragData->numItems * sizeof(XmString));
}
/*
* Convert the motif strings into selection data
*/
static Boolean
dndTextConvert(
Widget dragContext,
DtDragInfo * dtDragInfo,
Atom * selection,
Atom * target,
Atom * returnType,
XtPointer * returnValue,
unsigned long * returnLength,
int * returnFormat,
XSelectionRequestEvent * selectionRequestEvent)
{
DtDndContext * dragData = dtDragInfo->dragData;
Display * dpy = XtDisplayOfObject(dragContext);
XmString * stringList;
Cardinal numStrings;
XTextProperty textProp;
XmICCEncodingStyle encStyle;
int status;
/*
* Select the text encoding style; reject unknown targets
*/
if (*target == XA_COMPOUND_TEXT) {
encStyle = XmSTYLE_COMPOUND_TEXT;
} else if (*target == XA_STRING) {
encStyle = XmSTYLE_STRING;
} else if (*target == XA_TEXT) {
encStyle = XmSTYLE_TEXT;
} else {
return False;
}
/*
* Convert the XmString list into a string list
*/
numStrings = dragData->numItems;
stringList = dragData->data.strings;
status = XmCvtXmStringTableToTextProperty(dpy, stringList, numStrings,
encStyle, &textProp);
if (status != Success)
return False;
/*
* Return the text property
*/
*returnType = textProp.encoding;
*returnValue = (XtPointer)textProp.value;
*returnLength = textProp.nitems;
*returnFormat = textProp.format;
return True;
}
/*
* Clean up from the convert init proc
*/
static void
dndTextConvertFinish(
DtDragInfo * dtDragInfo)
{
DtDndContext * dragData = dtDragInfo->dragData;
if (dragData->data.strings) {
XtFree((char *)dragData->data.strings);
dragData->data.strings = NULL;
}
}
/*
* Returns the transfer targets selected from the export targets
*/
static void
dndTextTransferTargets(
DtDropInfo * dtDropInfo,
Atom * exportTargets,
Cardinal numExportTargets,
Atom ** transferTargets,
Cardinal * numTransferTargets)
{
Boolean foundCT, foundText, foundString;
Atom target;
int ii;
foundCT = foundText = foundString = False;
for (ii = 0; ii < numExportTargets; ii++) {
if (exportTargets[ii] == XA_COMPOUND_TEXT) {
foundCT = True;
} else if (exportTargets[ii] == XA_TEXT) {
foundText = True;
} else if (exportTargets[ii] == XA_STRING) {
foundString = True;
}
}
if (dndPreferString && foundString) {
target = XA_STRING;
} else if (foundCT) {
target = XA_COMPOUND_TEXT;
} else if (foundText) {
target = XA_TEXT;
} else if (foundString) {
target = XA_STRING;
} else {
*numTransferTargets = 0;
*transferTargets = NULL;
return;
}
*numTransferTargets = 1;
*transferTargets = (Atom *)XtMalloc(*numTransferTargets * sizeof(Atom));
(*transferTargets)[0] = target;
}
/*
* Transfer the selection data into motif strings
*/
static void
dndTextTransfer(
Widget dropTransfer,
DtDropInfo * dtDropInfo,
Atom * selection,
Atom * target,
Atom * type,
XtPointer value,
unsigned long * length,
int * format)
{
Display * display = XtDisplayOfObject(dropTransfer);
DtDndContext * dropData = dtDropInfo->dropData;
XmString * stringList;
XTextProperty textProp;
char ** text;
int ii, status, textCount;
/*
* Ignore transfers we don't understand or if we've already transferred
*/
if (value == NULL || dropData->data.strings ||
(*target != XA_COMPOUND_TEXT &&
*target != XA_TEXT &&
*target != XA_STRING) ) {
if (value != NULL)
XtFree(value);
return;
}
/*
* Convert the text property to a text list
*/
textProp.value = (unsigned char *)value;
textProp.encoding = *type;
textProp.format = *format;
textProp.nitems = *length;
status = XmbTextPropertyToTextList(display, &textProp,
&text, &textCount);
XtFree((char *)value);
if (status != Success) {
dtDropInfo->status = DtDND_FAILURE;
return;
}
/*
* Convert the text list into a XmString list
*/
stringList = (XmString *)XtMalloc(textCount * sizeof(XmString));
for (ii = 0; ii < textCount; ii++) {
stringList[ii] = XmStringCreateLocalized(text[ii]);
}
XFreeStringList(text);
dropData->numItems = textCount;
dropData->data.strings = stringList;
}
/*
* Clean up from the transfer proc
*/
static void
dndTextTransferFinish(
DtDropInfo * dtDropInfo)
{
DtDndContext * dropData = dtDropInfo->dropData;
int ii;
for (ii = 0; ii < dropData->numItems; ii++) {
XmStringFree(dropData->data.strings[ii]);
}
XtFree((char *)dropData->data.strings);
}

View File

@@ -0,0 +1,23 @@
/* $XConsortium: Dt.c /main/4 1995/12/04 10:04:04 rswiston $ */
/*
* (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. *
*/
/*********************************************************************
*
* File: Dt.c
*
* Description: Repository for libDtSvc-wide information.
*
*********************************************************************/
#include <Dt/Dt.h>
/* CDE Version information */
externaldef(dtversion) const int DtVersion = DtVERSION_NUMBER;
externaldef(dtversionstring) const char* DtVersionString = DtVERSION_STRING;

View File

@@ -0,0 +1,71 @@
/* $TOG: Dt.h /main/12 1999/10/18 14:49:57 samborn $ */
/*
* (c) Copyright 1997, The Open Group
*/
/*
* (c) Copyright 1996 Digital Equipment Corporation.
* (c) Copyright 1993,1994,1996 Hewlett-Packard Company.
* (c) Copyright 1993,1994,1996 International Business Machines Corp.
* (c) Copyright 1993-1996 Sun Microsystems, Inc.
* (c) Copyright 1993,1994,1996 Novell, Inc.
* (c) Copyright 1996 FUJITSU LIMITED.
* (c) Copyright 1996 Hitachi.
*/
#ifndef _Dt_Dt_h
#define _Dt_Dt_h
#include <X11/Intrinsic.h>
#ifdef __cplusplus
extern "C" {
#endif
/*
* Constants
*/
/* CDE Version information */
#define DtVERSION 2
#define DtREVISION 1
#define DtUPDATE_LEVEL 30
#define DtVERSION_NUMBER (DtVERSION * 10000 + \
DtREVISION * 100 + \
DtUPDATE_LEVEL)
#define DtVERSION_STRING "CDE Version 2.1.30"
/*
* CDE Version information
*/
externalref const int DtVersion;
externalref const char *DtVersionString;
/*
* Functions
*/
extern Boolean DtInitialize(
Display *display,
Widget widget,
char *name,
char *tool_class);
extern Boolean DtAppInitialize(
XtAppContext app_context,
Display *display,
Widget widget,
char *name,
char *tool_class);
#ifdef __cplusplus
}
#endif
#endif /* _Dt_Dt_h */

View File

@@ -0,0 +1,299 @@
/* $XConsortium: DtHash.c /main/4 1996/05/09 04:21:56 drk $ */
/*
Name: hash.c
Synopsis:
#include "DtHash.h"
void * _DtUtilMakeHash(int size)
void * _DtUtilMakeIHash(int size)
void ** _DtUtilGetHash(void * tbl, unsigned char * key)
void ** _DtUtilFindHash(void * tbl,unsigned char * key)
void ** _DtUtilDelHash(void * tbl, unsigned char * key)
int _DtUtilOperateHash(void * tbl, void (*op_func)(), void * usr_arg)
void _DtUtilDestroyHash(void * tbl, int (*des_func)(), void * usr_arg)
Description:
These routines provide a general purpose hash table facility that
supports multiple open hash tables. Each entry in the table consists of a
key and a data ptr. The key is a null terminated character string, while
the data ptr is opaque. Since all the entries are maintained in a doubly
linked lists, deletions and operations on entire table execute very quickly.
This make these routines suitable for use when the tables may be very ephemeral.
DtUtilMakeHash returns a pointer to the created table. The size argument
indicate the number of buckets the routine is to allocate. This should be ~
the max number of items expected in the table for maximum performance....
but /2 or /3 should still be ok. Note that for maximum efficiency the hash
table size should be a prime number (a side effect of the hash alorithm).
DtUtilMakeIHash performs the same function as DtUtilMakeHash, except that the hash
routines will use the key arguments as arbitrary integers rather than strings.
DtUtilGetHash searches the specified hash table tbl for an entry with the
specified key. If the entry does not exist, it is created with a NULL data
ptr. The routine returns a ptr to the area where the data ptr is (can be)
stored.
DtUtilFindHash searchs the table for an entry with the specified key. If the
entry is found, the address of the data pointer associated with the key is
returned. If no such entry exists, the routine returns NULL.
DtUtilDelHash deletes the specified table entry and returns the associated data
ptr. If the entry did not exist ( or the data ptr was NULL), the routine
returns NULL.
DtUtilOperateHash calls the routine pointed to by op_func once for each entry
in tbl, with three arguments: the data ptr, the usr_arg ptr and a ptr to the
key for that entry (which should NOT be altered). This is useful for
transversing a hash table quickly and operating on the entries. Note that
the order of the traversal of the hash table is the reverse order of
insertion.
DtUtilDestroyHash destroys the specified hash table after operating on it
with the specified des_func function as described for DtUtilOperateHash. All storage
allocated by the hash routines is reclaimed.
Author: Bart Smaalders 1/89
*/
#include <stdio.h> /* grab NULL define */
#include "DtHash.h"
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
static int hash_string(const unsigned char * s, int modulo);
typedef struct hash_entry {
struct hash_entry
* next_entry,
* right_entry,
* left_entry;
unsigned char * key;
void * data;
} hash_entry;
typedef struct hash {
int size;
hash_entry ** table;
hash_entry * start;
enum hash_type { String_Key = 0 , Integer_Key = 1} hash_type;
} hash;
DtHashTbl _DtUtilMakeHash(int size)
{
hash * ptr;
ptr = (hash *) malloc(sizeof(*ptr));
ptr->size = size;
ptr->table = (hash_entry **) malloc( (unsigned) (sizeof(hash_entry *) * size) );
(void)memset((char *) ptr->table, (char) 0, sizeof(hash_entry *)*size);
ptr->start = NULL;
ptr->hash_type = String_Key;
return((DtHashTbl)ptr);
}
DtHashTbl _DtUtilMakeIHash(int size)
{
hash * ptr;
ptr = (hash *) malloc(sizeof(*ptr));
ptr->size = size;
ptr->table = (hash_entry **) malloc( (unsigned) (sizeof(hash_entry *) * size) );
(void)memset((char *) ptr->table, (char) 0, sizeof(hash_entry *)*size);
ptr->start = NULL;
ptr->hash_type = Integer_Key;
return((DtHashTbl) ptr);
}
void ** _DtUtilGetHash(DtHashTbl t, const unsigned char * key)
{
hash * tbl = (hash *) t;
register int bucket;
register hash_entry * tmp;
hash_entry * new;
if(tbl->hash_type == String_Key)
tmp = tbl->table[bucket = hash_string(key, tbl->size)];
else
tmp = tbl->table[bucket = abs((int)key) % tbl->size];
if(tbl->hash_type == String_Key)
while(tmp!=NULL)
{
if(strcmp((char *)tmp->key, (char*)key)==0)
return(&tmp->data);
tmp = tmp->next_entry;
}
else
while(tmp!=NULL)
{
if(tmp->key == key)
return(&tmp->data);
tmp = tmp->next_entry;
}
/*
not found....
insert new entry into bucket...
*/
new = (hash_entry *) malloc(sizeof(*new));
new->key = (unsigned char *)((tbl->hash_type == String_Key)?(unsigned char *)strdup((char*)key):key);
/*
hook into chain from tbl...
*/
new->right_entry = NULL;
new->left_entry = tbl->start;
tbl->start = new;
/*
hook into bucket chain
*/
new->next_entry = tbl->table[bucket];
tbl->table[bucket] = new;
new->data = NULL; /* so we know that it is new */
return((void*)& new->data);
}
void ** _DtUtilFindHash(DtHashTbl t, const unsigned char * key)
{
register hash * tbl = (hash *) t;
register hash_entry * tmp;
if(tbl->hash_type == String_Key)
{
tmp = tbl->table[hash_string(key, tbl->size)];
for(;tmp!=NULL; tmp = tmp->next_entry)
if(!strcmp((char*)tmp->key, (char*)key))
return((void *)&tmp->data);
}
else
{
tmp = tbl->table[abs((int)key) % tbl->size];
for(;tmp!=NULL; tmp = tmp->next_entry)
if(tmp->key == key)
return((void *)&tmp->data);
}
return(NULL);
}
void * _DtUtilDelHash(DtHashTbl t, const unsigned char * key)
{
register hash * tbl = (hash *) t;
register int bucket;
register hash_entry * tmp, * prev = NULL;
if(tbl->hash_type == String_Key)
bucket = hash_string(key, tbl->size);
else
bucket = abs((int)key) % tbl->size;
if((tmp = tbl->table[bucket])==NULL)
return(NULL);
else
{
if(tbl->hash_type == String_Key)
while(tmp!=NULL)
{
if(!strcmp((char*)tmp->key, (char*)key))
break; /* found item to delete ! */
prev = tmp;
tmp = tmp->next_entry;
}
else
while(tmp!=NULL)
{
if(tmp->key == key)
break;
prev = tmp;
tmp = tmp->next_entry;
}
if(tmp == NULL)
return(NULL); /* not found */
}
/* tmp now points to entry marked for deletion, prev to
item preceeding in bucket chain or NULL if tmp is first.
remove from bucket chain first....
*/
if(tbl->hash_type == String_Key)
free(tmp->key);
if(prev!=NULL)
prev->next_entry = tmp->next_entry;
else
tbl->table[bucket] = tmp->next_entry;
/*
now remove from tbl chain....
*/
if(tmp->right_entry !=NULL) /* not first in chain.... */
tmp->right_entry->left_entry = (tmp->left_entry ?
tmp->left_entry->right_entry: NULL);
else
tbl->start = (tmp->left_entry ?tmp->left_entry->right_entry: NULL);
return(tmp->data);
}
int _DtUtilOperateHash(DtHashTbl t, void (*ptr)(), void * usr_arg)
{
hash * tbl = (hash *) t;
register hash_entry * tmp = tbl->start;
int c = 0;
while(tmp)
{
(*ptr)(tmp->data,usr_arg, tmp->key);
tmp = tmp->left_entry;
c++;
}
return(c);
}
void _DtUtilDestroyHash(DtHashTbl t, int (*ptr)(), void * usr_arg)
{
hash * tbl = (hash *) t;
register hash_entry * tmp = tbl->start, * prev;
while(tmp)
{
if(ptr)
(*ptr)(tmp->data,usr_arg, tmp->key);
if(tbl->hash_type == String_Key)
free(tmp->key);
prev = tmp;
tmp = tmp->left_entry;
free((char *)prev);
}
free((char *)tbl->table);
free(tbl);
}
static int hash_string(register const unsigned char * s, int modulo)
{
register unsigned result = 0;
register int i=1;
while(*s!=0)
result += (*s++ << i++);
return(result % modulo);
}

View File

@@ -0,0 +1,27 @@
/* $XConsortium: DtHash.h /main/5 1996/08/29 15:42:13 cde-dec $ */
#ifndef _DtHash_h
#define _DtHash_h
typedef void * DtHashTbl;
DtHashTbl _DtUtilMakeHash(int size);
DtHashTbl _DtUtilMakeIHash(int size);
void ** _DtUtilGetHash(DtHashTbl tbl, const unsigned char * key);
void ** _DtUtilFindHash(DtHashTbl tbl,const unsigned char * key);
void * _DtUtilDelHash(DtHashTbl tbl, const unsigned char * key);
int _DtUtilOperateHash(DtHashTbl tbl, void (*op_func)(), void * usr_arg);
void _DtUtilDestroyHash(DtHashTbl tbl, int (*des_func)(), void * usr_arg);
typedef void (*DtHashOperateFunc)();
typedef int (*DtHashDestroyFunc)();
#endif /* _DtHash_h */

View File

@@ -0,0 +1,54 @@
/* $XConsortium: DtShmDb.h /main/4 1996/05/09 04:22:30 drk $ */
#ifndef DtShmDb_h
#define DtShmDb_h
/*
this include file provides prototypes for the various
shared memory database routines
*/
typedef void * DtShmProtoStrtab;
typedef void * DtShmProtoInttab;
typedef void * DtShmProtoIntList;
typedef const void * DtShmStrtab;
typedef const void * DtShmInttab;
typedef const int * DtShmIntList;
typedef int DtShmBoson;
/*
routines used while building shared memory databases
*/
DtShmProtoStrtab _DtShmProtoInitStrtab (int estimated_entries);
DtShmBoson _DtShmProtoAddStrtab (DtShmProtoStrtab prototab, const char * string, int * isnew);
const char * _DtShmProtoLookUpStrtab (DtShmProtoStrtab prototab, DtShmBoson boson);
int _DtShmProtoSizeStrtab (DtShmProtoStrtab prototab);
DtShmStrtab _DtShmProtoCopyStrtab (DtShmProtoStrtab prototab, void * dataspace);
int _DtShmProtoDestroyStrtab (DtShmProtoStrtab prototab);
DtShmProtoInttab _DtShmProtoInitInttab (int estimated_entries);
int _DtShmProtoAddInttab (DtShmProtoInttab prototab, unsigned int keyin, int datain);
int * _DtShmProtoLookUpInttab (DtShmProtoInttab prototab, unsigned int keyin);
int _DtShmProtoSizeInttab (DtShmProtoInttab prototab);
DtShmInttab _DtShmProtoCopyInttab (DtShmProtoInttab prototab, void * dataspace);
int _DtShmProtoDestroyInttab (DtShmProtoInttab prototab);
DtShmProtoIntList _DtShmProtoInitIntLst (int estimated_entries);
int * _DtShmProtoAddIntLst (DtShmProtoIntList protolist, int size, int * index_value);
int _DtShmProtoSizeIntLst (DtShmProtoIntList protolist);
DtShmIntList _DtShmProtoCopyIntLst (DtShmProtoIntList protolist, void * dataspace);
int _DtShmProtoDestroyIntLst (DtShmProtoIntList protolist);
/*
run-time routines once shared memory area is built
*/
DtShmBoson _DtShmStringToBoson (DtShmStrtab tab, const char * string);
const char * _DtShmBosonToString (DtShmStrtab tab, DtShmBoson boson);
const int * _DtShmFindIntTabEntry (DtShmInttab tab, unsigned int key);
#endif /* DtShmDb_h */

2235
cde/lib/DtSvc/DtUtil1/Dts.c Normal file

File diff suppressed because it is too large Load Diff

159
cde/lib/DtSvc/DtUtil1/Dts.h Normal file
View File

@@ -0,0 +1,159 @@
/* $XConsortium: Dts.h /main/5 1996/03/05 13:30:59 drk $ */
/*
* (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 _Dt_Dts_h
#define _Dt_Dts_h
#include <sys/stat.h>
#include <X11/Intrinsic.h>
#ifdef __cplusplus
extern "C" {
#endif
/*
* Constants
*/
#define DtDTS_DC_NAME "DATA_CRITERIA"
#define DtDTS_NAME_PATTERN "NAME_PATTERN"
#define DtDTS_PATH_PATTERN "PATH_PATTERN"
#define DtDTS_CONTENT "CONTENT"
#define DtDTS_MODE "MODE"
#define DtDTS_LINK_PATH "LINK_PATH"
#define DtDTS_LINK_NAME "LINK_NAME"
#define DtDTS_DATA_ATTRIBUTES_NAME "DATA_ATTRIBUTES_NAME"
#define DtDTS_DT_RECURSIVE_LINK "RECURSIVE_LINK"
#define DtDTS_DT_BROKEN_LINK "BROKEN_LINK"
#define DtDTS_DT_UNKNOWN "UNKNOWN"
#define DtDTS_DA_IS_SYNTHETIC "IS_SYNTHETIC"
#define DtDTS_DA_LABEL "LABEL"
#define DtDTS_DA_NAME "DATA_ATTRIBUTES"
#define DtDTS_DA_DESCRIPTION "DESCRIPTION"
#define DtDTS_DA_DATA_HOST "DATA_HOST"
#define DtDTS_DA_ICON "ICON"
#define DtDTS_DA_INSTANCE_ICON "INSTANCE_ICON"
#define DtDTS_DA_PROPERTIES "PROPERTIES"
#define DtDTS_DA_ACTION_LIST "ACTIONS"
#define DtDTS_DA_NAME_TEMPLATE "NAME_TEMPLATE"
#define DtDTS_DA_MODE_TEMPLATE "MODE_TEMPLATE"
#define DtDTS_DA_MOVE_TO_ACTION "MOVE_TO_ACTION"
#define DtDTS_DA_COPY_TO_ACTION "COPY_TO_ACTION"
#define DtDTS_DA_LINK_TO_ACTION "LINK_TO_ACTION"
#define DtDTS_DA_IS_TEXT "IS_TEXT"
#define DtDTS_DA_MEDIA "MEDIA"
#define DtDTS_DA_MIME_TYPE "MIME_TYPE"
#define DtDTS_DA_MIME_TO_MEDIA_FILTER "MIME_TO_MEDIA_FILTER"
#define DtDTS_DA_MEDIA_TO_MIME_FILTER "MEDIA_TO_MIME_FILTER"
#define DtDTS_DA_X400_TYPE "X400_TYPE"
#define DtDTS_DA_X400_TO_MEDIA_FILTER "X400_TO_MEDIA_FILTER"
#define DtDTS_DA_MEDIA_TO_X400_FILTER "MEDIA_TO_X400_FILTER"
#define DtDTS_DA_IS_ACTION "IS_ACTION"
#define DtDTS_DA_IS_EXECUTABLE "IS_EXECUTABLE"
#define DtDTS_DT_DIR ".DtDirDataType"
/*
* Types
*/
typedef struct _DtDtsAttribute
{
char *name;
char *value;
} DtDtsAttribute;
/*
* Functions
*/
extern void DtDtsLoadDataTypes(void);
extern void DtDtsRelease(void);
extern char *DtDtsDataToDataType(
const char *filepath,
const void *buffer,
const int size,
const struct stat *stat_buff,
const char *link_name,
const struct stat *link_stat_buff,
const char *opt_name);
extern char *DtDtsFileToDataType(
const char *filepath);
extern char *DtDtsFileToAttributeValue(
const char *filepath,
const char *attr);
extern DtDtsAttribute **DtDtsFileToAttributeList(
const char *filepath);
extern char *DtDtsBufferToDataType(
const void *buffer,
const int size,
const char *opt_name);
extern char *DtDtsBufferToAttributeValue(
const void *buffer,
const int size,
const char *attr,
const char *opt_name);
extern DtDtsAttribute **DtDtsBufferToAttributeList(
const void *buffer,
const int size,
const char *opt_name);
extern char *DtDtsDataTypeToAttributeValue(
const char *datatype,
const char *attr,
const char *opt_name);
extern DtDtsAttribute **DtDtsDataTypeToAttributeList(
const char *datatype,
const char *opt_name);
extern void DtDtsFreeDataTypeNames(
char **namelist);
extern void DtDtsFreeAttributeList(
DtDtsAttribute **attr_list);
extern void DtDtsFreeAttributeValue(
char *attr_value);
extern void DtDtsFreeDataType(
char *datatype);
extern char **DtDtsDataTypeNames(void);
extern char **DtDtsFindAttribute(
const char *name,
const char *value);
extern char *DtDtsSetDataType(
const char *filepath,
const char *datatype,
const int override);
extern int DtDtsDataTypeIsAction(
const char *datatype);
extern Boolean DtDtsIsTrue(
const char *str);
#ifdef __cplusplus
}
#endif
#endif /* _Dt_Dts_h */

View File

@@ -0,0 +1,539 @@
/*
* (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. *
*/
/*
*+SNOTICE
*
* $TOG: DtsDb.c /main/10 1998/10/23 13:48:04 mgreess $
*
* RESTRICTED CONFIDENTIAL INFORMATION:
*
* The information in this document is subject to special
* restrictions in a confidential disclosure agreement bertween
* HP, IBM, Sun, USL, SCO and Univel. Do not distribute this
* document outside HP, IBM, Sun, USL, SCO, or Univel wihtout
* Sun's specific written approval. This documment and all copies
* and derivative works thereof must be returned or destroyed at
* Sun's request.
*
* Copyright 1993 Sun Microsystems, Inc. All rights reserved.
*
*+ENOTICE
*/
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#ifdef SUN_DB
#include <sys/mman.h>
#endif
#include <string.h>
#include <Dt/DbReader.h>
#include "Dt/DtsDb.h"
#include <Dt/UserMsg.h>
#include "DtSvcLock.h"
extern char *strdup(const char *);
#define PADMEM 10
typedef int (*genfunc)(const void *, const void *);
static DtDtsDbDatabase **db_list;
static int num_db = 0;
_DtDtsDbPrintFields(DtDtsDbRecord *rec_ptr, FILE *fd)
{
int fld;
DtDtsDbField *fld_ptr;
for(fld = 0; fld < rec_ptr->fieldCount; fld++)
{
fld_ptr = rec_ptr->fieldList[fld];
fprintf(fd, "\t\t[%d]\t%s\t%s\n", fld,
XrmQuarkToString(fld_ptr->fieldName),
fld_ptr->fieldValue?
fld_ptr->fieldValue:"(NULL)");
}
}
_DtDtsDbPrintRecords(DtDtsDbDatabase *db_ptr, FILE *fd)
{
int rec;
DtDtsDbRecord *rec_ptr;
_DtSvcProcessLock();
fprintf(fd, "%d Records\n", db_ptr->recordCount);
for(rec = 0; rec < db_ptr->recordCount; rec++)
{
rec_ptr = db_ptr->recordList[rec];
fprintf(fd, "\tRec[%d] name = %s\n\t%d Fields\n", rec,
XrmQuarkToString(rec_ptr->recordName),
rec_ptr->fieldCount);
_DtDtsDbPrintFields(rec_ptr, fd);
}
_DtSvcProcessUnlock();
}
void
_DtDtsDbPrint(FILE *org_fd)
{
int db;
int rec;
DtDtsDbDatabase *db_ptr;
DtDtsDbRecord *rec_ptr;
FILE *fd = org_fd;
_DtSvcProcessLock();
for(db = 0; db < num_db; db++)
{
if(!db_list[db])
{
continue;
}
db_ptr = db_list[db];
if(fd == 0)
{
chdir("/tmp");
if((fd = fopen(db_ptr->databaseName, "w")) == NULL)
{
_DtSimpleError(
DtProgName, DtError, NULL,
db_ptr->databaseName, NULL);
continue;
}
}
fprintf(fd, "DB[%d] ", db);
fprintf(fd, "name = %s\n", db_ptr->databaseName);
_DtDtsDbPrintRecords(db_ptr, fd);
if(org_fd == 0)
{
fclose(fd);
fd = 0;
}
}
_DtSvcProcessUnlock();
}
int
_DtDtsDbCompareRecordNames(DtDtsDbRecord **a, DtDtsDbRecord **b)
{
return ((*a)->recordName - (*b)->recordName);
}
int
_DtDtsDbCompareFieldNames(DtDtsDbField **a, DtDtsDbField **b)
{
return ((*a)->fieldName - (*b)->fieldName);
}
#include <Dt/Dts.h>
DtDtsDbDatabase **
_DtDtsDbInit(void)
{
DtDtsDbDatabase **db;
_DtSvcProcessLock();
num_db = 0;
db = db_list = (DtDtsDbDatabase **)calloc(num_db+3, sizeof(DtDtsDbDatabase *));
db_list[0] = (DtDtsDbDatabase *)calloc(1, sizeof(DtDtsDbDatabase));
db_list[0]->databaseName = (char *)strdup(DtDTS_DC_NAME);
db_list[0]->ActionSequenceNumber = 0;
num_db++;
db_list[1] = (DtDtsDbDatabase *)calloc(1, sizeof(DtDtsDbDatabase));
db_list[1]->databaseName = (char *)strdup(DtDTS_DA_NAME);
db_list[1]->ActionSequenceNumber = 0;
num_db++;
_DtSvcProcessUnlock();
return(db);
}
char **
_DtsDbListDb()
{
int i;
char **list = 0;
_DtSvcProcessLock();
for ( i = 0; db_list[i]; i++ );
if(i > 0)
{
list = (char **)calloc(i+1, sizeof(char *));
for ( i = 0; db_list[i]; i++ )
{
list[i] = (char *)strdup(db_list[i]->databaseName);
}
}
_DtSvcProcessUnlock();
return(list);
}
DtDtsDbDatabase *
_DtDtsDbAddDatabase( char *db_name )
{
int i = 0;
DtDtsDbDatabase **new_db_list;
DtDtsDbDatabase *ret_db;
_DtSvcProcessLock();
if ( !db_list )
{
_DtDtsDbInit();
}
for ( i = 0; db_list[i]; i++ )
{
if ( !strcmp(db_list[i]->databaseName,db_name) )
{
/*
* A database with the given name already exists.
* return a pointer to the existing database.
*/
ret_db = db_list[i];
_DtSvcProcessUnlock();
return ret_db;
}
}
/*
* We now have a count of the existing databases.
* allocate enough space for the existing databases + the new one
* + a NULL pointer to terminate the vector.
*/
new_db_list = (DtDtsDbDatabase **)calloc(i+2,sizeof(DtDtsDbDatabase *));
memmove(new_db_list,db_list,sizeof(DtDtsDbDatabase *) * i );
new_db_list[i] = (DtDtsDbDatabase *)calloc(1, sizeof(DtDtsDbDatabase));
new_db_list[i]->databaseName = strdup(db_name);
new_db_list[i]->ActionSequenceNumber = 0;
free(db_list);
db_list = new_db_list;
num_db++;
ret_db = db_list[i];
_DtSvcProcessUnlock();
return ret_db;
}
int
_DtDtsDbDeleteDb(DtDtsDbDatabase *db)
{
int i;
int flag = 0;
_DtSvcProcessLock();
_DtDtsDbDeleteRecords(db);
if(db->databaseName) free(db->databaseName);
if(db) free(db);
for(i = 0; db_list[i]; i++)
{
if(db_list[i] == db)
{
flag = 1;
db_list[i] = 0;
}
if(flag)
{
db_list[i] = db_list[i+1];
}
}
if(db_list[0] == 0)
{
if(db_list)free(db_list);
db_list = 0;
}
_DtSvcProcessUnlock();
return(0);
}
DtDtsDbDatabase *
_DtDtsDbGet(char *name)
{
DtDtsDbDatabase *ret_db;
int i;
_DtSvcProcessLock();
if(!db_list)
{
_DtDtsDbInit();
}
for(i = 0; db_list && db_list[i] && db_list[i]->databaseName; i++)
{
if(strcmp(db_list[i]->databaseName, name) == 0)
{
ret_db = db_list[i];
_DtSvcProcessUnlock();
return(ret_db);
}
}
_DtSvcProcessUnlock();
return(NULL);
}
void
_DtDtsDbFieldSort(DtDtsDbRecord *rec, _DtDtsDbFieldCompare compare)
{
if(compare == NULL)
{
compare = _DtDtsDbCompareFieldNames;
}
qsort(rec->fieldList,
rec->fieldCount,
sizeof(DtDtsDbField *),
(genfunc)compare);
rec->compare = compare;
}
void
_DtDtsDbRecordSort(DtDtsDbDatabase *db, _DtDtsDbRecordCompare compare)
{
if(compare == NULL)
{
compare = _DtDtsDbCompareRecordNames;
}
qsort(db->recordList,
db->recordCount,
sizeof(DtDtsDbRecord *),
(genfunc)compare);
db->compare = compare;
}
DtDtsDbField *
_DtDtsDbGetField(DtDtsDbRecord *rec, char *name)
{
register int i;
/*
* Field names have been quarked so quark 'name' and
* do a linear search for the quark'ed field name.
*/
XrmQuark tmp = XrmStringToQuark (name);
for (i = 0; i < rec->fieldCount; i++)
{
if (rec->fieldList[i]->fieldName == tmp)
{
return (rec->fieldList[i]);
}
}
return(NULL);
}
char *
_DtDtsDbGetFieldByName(DtDtsDbRecord *rec, char *name)
{
DtDtsDbField *result;
result = _DtDtsDbGetField(rec, name);
if(result)
{
return(result->fieldValue);
}
else
{
return(NULL);
}
}
DtDtsDbRecord *
_DtDtsDbGetRecordByName(DtDtsDbDatabase *db, char *name)
{
DtDtsDbRecord srch;
DtDtsDbRecord **result;
DtDtsDbRecord *s = &srch;
register int i;
XrmQuark name_quark = XrmStringToQuark(name);
/*
* If the fields are not sorted in alphanumeric order
* by name a binary search will fail. So do the slow but
* sure linear search.
*/
if(db->compare != _DtDtsDbCompareRecordNames)
{
for (i = 0; i < db->recordCount; i++)
{
if (db->recordList[i]->recordName == name_quark)
{
return (db->recordList[i]);
}
}
return NULL;
}
srch.recordName = name_quark;
if(db->recordCount == 0 || db->recordList == NULL)
{
result = NULL;
}
else
{
result = (DtDtsDbRecord **)bsearch(&s,
db->recordList,
db->recordCount,
sizeof(DtDtsDbRecord *),
(genfunc)_DtDtsDbCompareRecordNames);
}
if(result)
{
return(*result);
}
else
{
return(NULL);
}
}
DtDtsDbRecord *
_DtDtsDbAddRecord(DtDtsDbDatabase *db)
{
DtDtsDbRecord **newlist;
int rec = db->recordCount;
db->compare = (_DtDtsDbRecordCompare)NULL;
if(rec%PADMEM == 0)
{
newlist = (DtDtsDbRecord **)calloc(rec+PADMEM,
sizeof(DtDtsDbRecord *));
if(db->recordList)
{
memmove(newlist, db->recordList,
rec*sizeof(DtDtsDbRecord *));
if(db->recordList) free(db->recordList);
}
db->recordList = newlist;
}
db->recordList[rec] = (DtDtsDbRecord *)calloc(1, sizeof(DtDtsDbRecord));
db->recordCount++;
return(db->recordList[rec]);
}
int
_DtDtsDbDeleteRecord(DtDtsDbRecord *rec, DtDtsDbDatabase *db)
{
int i;
_DtDtsDbDeleteFields(rec);
if(rec) free(rec);
for(i = 0; i < db->recordCount; i++)
{
if(db->recordList[i] == rec)
{
memmove( &(db->recordList[i]),
&(db->recordList[i+1]),
(db->recordCount - i - 1)*
sizeof(DtDtsDbRecord *));
db->recordCount--;
return(1);
}
}
return(0);
}
int
_DtDtsDbDeleteRecords(DtDtsDbDatabase *db)
{
int i;
for(i = 0; i < db->recordCount; i++)
{
_DtDtsDbDeleteFields(db->recordList[i]);
if(db->recordList[i])
free(db->recordList[i]);
}
if(db->recordList)
free(db->recordList);
db->recordList = 0;
return(0);
}
DtDtsDbField *
_DtDtsDbAddField(DtDtsDbRecord *rec)
{
DtDtsDbField **newlist;
int flds = rec->fieldCount;
if(flds%PADMEM == 0)
{
newlist = (DtDtsDbField **)calloc(flds+PADMEM,
sizeof(DtDtsDbField *));
if(rec->fieldList)
{
memmove(newlist, rec->fieldList,
flds*sizeof(DtDtsDbField *));
if(rec->fieldList)
free(rec->fieldList);
}
rec->fieldList = newlist;
}
rec->fieldList[flds] = (DtDtsDbField *)calloc(1, sizeof(DtDtsDbField));
rec->fieldCount++;
return(rec->fieldList[flds]);
}
int
_DtDtsDbDeleteField(DtDtsDbField *fld, DtDtsDbRecord *rec)
{
int i;
if(fld) free(fld);
for(i = 0; i < rec->fieldCount; i++)
{
if(rec->fieldList[i] == fld)
{
memmove( &(rec->fieldList[i]),
&(rec->fieldList[i+1]),
(rec->fieldCount - i - 1)*
sizeof(DtDtsDbField *));
rec->fieldCount--;
return(1);
}
}
return(0);
}
int
_DtDtsDbDeleteFields(DtDtsDbRecord *rec)
{
int i;
for(i = 0; i < rec->fieldCount; i++)
{
if(rec->fieldList[i]->fieldValue)
free(rec->fieldList[i]->fieldValue);
if(rec->fieldList[i])
free(rec->fieldList[i]);
}
if(rec->fieldList) free(rec->fieldList);
rec->fieldList = 0;
return(0);
}
int
_DtDtsMMCreateFile(DtDirPaths *dirs, const char *CacheFile)
{
return _MMWriteDb(dirs, num_db, db_list, CacheFile);
}

View File

@@ -0,0 +1,132 @@
/*
* (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. *
*/
/*
*+SNOTICE
*
* $XConsortium: DtsDb.h /main/5 1996/08/28 14:32:17 rswiston $
*
* RESTRICTED CONFIDENTIAL INFORMATION:
*
* The information in this document is subject to special
* restrictions in a confidential disclosure agreement bertween
* HP, IBM, Sun, USL, SCO and Univel. Do not distribute this
* document outside HP, IBM, Sun, USL, SCO, or Univel wihtout
* Sun's specific written approval. This documment and all copies
* and derivative works thereof must be returned or destroyed at
* Sun's request.
*
* Copyright 1993 Sun Microsystems, Inc. All rights reserved.
*
*+ENOTICE
*/
#ifndef DT_DTS_DB_H
#define DT_DTS_DB_H
#include <X11/Xresource.h>
#include <Dt/DbReader.h>
typedef int OtBoolean;
/* typedefs for casting comparison functions if needed */
typedef int (*_DtDtsDbFieldCompare)(DtDtsDbField **fld1, DtDtsDbField **fld2);
/* entry of a list of attribute/pairs */
typedef struct
{
XrmQuark recordName;
_DtDtsDbFieldCompare compare;
long pathId;
int seq;
int fieldCount;
DtDtsDbField **fieldList;
} DtDtsDbRecord;
/* typedefs for casting record comparison functions if needed */
typedef int (*_DtDtsDbRecordCompare)(DtDtsDbRecord **rec1, DtDtsDbRecord **rec2);
/* a "database" of a collection of entrys (i.e. OBJECT-TYPE, ACTION, FILE-TYPE
This is a private Structure to the DtDtsDb component.
*/
typedef struct
{
char *databaseName;
_DtDtsDbRecordCompare compare;
int recordCount;
DtDtsDbRecord **recordList;
unsigned long ActionSequenceNumber;
} DtDtsDbDatabase;
/* for the mmaped database this the use_in_memory_db variable is used
to call the old API while the database is being built and is set to
false when the mmaped versions are being accessed.
*/
extern int use_in_memory_db;
/*
* adds a new database to the list of databases -- returns a pointer to the
* new database. If a database of the given name already exists it returns
* a pointer to that database.
*/
extern DtDtsDbDatabase *_DtDtsDbAddDatabase( char *dbname );
/* returns the handle for the database where name is the Database name */
extern DtDtsDbDatabase *_DtDtsDbGet(char *name);
extern char **_DtDtsDbListDb(void);
/* Record Sort function:
* sorts the specified database, usually obtained from _DtDtsDbGet(), in the
* order specified by the comparison function. If (*compare) == 0 then
* _DtDtsDbCompareRecordNames() is used as the (*compare) function.
*/
extern void _DtDtsDbRecordSort(DtDtsDbDatabase *database,
_DtDtsDbRecordCompare compare);
/* Field Sort function:
* sorts the specified Record in the order specified by the comparison function
* If (*compare) == 0 then _DtDtsDbCompareFieldNames() is used as the
* (*compare) function.
*/
extern void _DtDtsDbFieldSort(DtDtsDbRecord *record,
_DtDtsDbFieldCompare compare);
/* Name Comparison functions:
* These routines can be passed in to the corresponding sort function to
* sort by name.
*
*/
extern int _DtDtsDbCompareRecordNames(DtDtsDbRecord **entry1, DtDtsDbRecord **entry2);
extern int _DtDtsDbCompareFieldNames(DtDtsDbField **entry1, DtDtsDbField **entry2);
/* retrieves the Record that matches the specified entry from the record */
extern DtDtsDbField *_DtDtsDbGetField(DtDtsDbRecord *record,
char *value);
/* retrieves the entry of the specified entry from the specified database */
extern DtDtsDbRecord *_DtDtsDbGetRecord(DtDtsDbDatabase *database,
DtDtsDbRecord *value);
/* Get By Name functions:
* retrieves the entry of the specified name from the specified database
* ** IF ** the _DtDtsDb*Sort routine has been called with the corresponding
* _DtDtsDbCompare*Name comparison function. Otherwise use the standard
* _DtDtsDbGet* functions.
*/
extern char *_DtDtsDbGetFieldByName(DtDtsDbRecord *record, char *name);
extern DtDtsDbRecord *_DtDtsDbGetRecordByName(DtDtsDbDatabase *database, char *name);
extern DtDtsDbRecord *_DtDtsDbAddRecord(DtDtsDbDatabase *db);
extern DtDtsDbField *_DtDtsDbAddField(DtDtsDbRecord *rec);
extern int _DtDtsDbDeleteDb(DtDtsDbDatabase *db);
extern int _DtDtsDbDeleteRecord(DtDtsDbRecord *rec, DtDtsDbDatabase *db);
extern int _DtDtsDbDeleteRecords(DtDtsDbDatabase *db);
extern int _DtDtsDbDeleteField(DtDtsDbField *fld, DtDtsDbRecord *rec);
extern int _DtDtsDbDeleteFields(DtDtsDbRecord *rec);
#endif

View File

@@ -0,0 +1,227 @@
/*
* (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. *
*/
/*
* +SNOTICE
*
* $XConsortium: DtsInit.c /main/5 1996/08/28 16:08:50 rswiston $
*
* RESTRICTED CONFIDENTIAL INFORMATION:
*
* The information in this document is subject to special restrictions in a
* confidential disclosure agreement bertween HP, IBM, Sun, USL, SCO and
* Univel. Do not distribute this document outside HP, IBM, Sun, USL, SCO,
* or Univel wihtout Sun's specific written approval. This documment and all
* copies and derivative works thereof must be returned or destroyed at Sun's
* request.
*
* Copyright 1993 Sun Microsystems, Inc. All rights reserved.
*
* +ENOTICE
*/
#include <stdio.h>
#include <sys/types.h>
#ifdef __hpux
#include <ndir.h>
#else
#if defined(sun) || defined(USL) || defined(sco) || defined(__uxp__)
#include <dirent.h>
#else
#include <sys/dir.h>
#endif /* sun || USL */
#endif /* __hpux */
#include <ctype.h>
#include <string.h>
#ifdef NLS16
#include <limits.h>
#endif
#include <sys/stat.h>
#include <sys/param.h> /* MAXPATHLEN, MAXHOSTNAMELEN */
#include <Dt/DbReader.h>
#include <Dt/DtsDb.h>
#include <Dt/Dts.h>
#include "DtSvcLock.h"
extern char *strdup(const char *);
static int cur_dc_count = 0;
static int cur_da_count = 0;
#define _DtFT_NUM_FIELDS 20
int
_DtDtsNextDCSeq()
{
int nextDCSeq;
_DtSvcProcessLock();
nextDCSeq = ++cur_dc_count;
_DtSvcProcessUnlock();
return(nextDCSeq);
}
int
_DtDtsNextDASeq()
{
int nextDASeq;
_DtSvcProcessLock();
nextDASeq = ++cur_da_count;
_DtSvcProcessUnlock();
return(nextDASeq);
}
void
_DtDtsSeqReset()
{
_DtSvcProcessLock();
cur_dc_count = 0;
cur_da_count = 0;
_DtSvcProcessUnlock();
}
void
_DtDtsDCConverter(DtDtsDbField * fields,
DtDbPathId pathId,
char *hostPrefix,
Boolean rejectionStatus)
{
DtDtsDbDatabase *db;
DtDtsDbRecord *rec;
DtDtsDbField *fld;
int i = 0;
_DtSvcProcessLock();
db = _DtDtsDbGet(DtDTS_DC_NAME);
while (fields[i].fieldName && fields[i].fieldValue)
{
if (i == 0)
{
if(rec=_DtDtsDbGetRecordByName(db,fields[i].fieldValue))
{
char *value = _DtDtsDbGetFieldByName(rec,DtDTS_DA_IS_SYNTHETIC);
/*
* Check if the record is SYNTHETIC --
* if so then replace it with this real
* definition -- otherwise return.
*/
if (value && !strcmp(value,"True") )
{
/* free up the current record */
_DtDtsDbDeleteRecord(rec,db);
}
else
{
_DtSvcProcessUnlock();
return;
}
}
rec = _DtDtsDbAddRecord(db);
rec->recordName = XrmStringToQuark(fields[i].fieldValue);
rec->seq = _DtDtsNextDCSeq();
rec->pathId = (int)pathId;
}
else
{
fld = _DtDtsDbAddField(rec);
fld->fieldName = fields[i].fieldName;
fld->fieldValue = strdup(fields[i].fieldValue);
}
i++;
}
_DtSvcProcessUnlock();
}
void
_DtDtsDAConverter(DtDtsDbField * fields,
DtDbPathId pathId,
char *hostPrefix,
Boolean rejectionStatus)
{
DtDtsDbDatabase *db;
DtDtsDbRecord *rec;
DtDtsDbField *fld;
int i = 0;
_DtSvcProcessLock();
db = _DtDtsDbGet(DtDTS_DA_NAME);
while (fields[i].fieldName && fields[i].fieldValue)
{
if (i == 0)
{
if(rec = _DtDtsDbGetRecordByName(db, fields[i].fieldValue))
{
char *value = _DtDtsDbGetFieldByName(rec,DtDTS_DA_IS_SYNTHETIC);
/*
* Check if the record is SYNTHETIC --
* if so then replace it with this real
* definition -- otherwise return.
*/
if (value && !strcmp(value,"True") )
{
/* free up the current record */
_DtDtsDbDeleteRecord(rec,db);
}
else
{
_DtSvcProcessUnlock();
return;
}
}
rec = _DtDtsDbAddRecord(db);
rec->recordName = XrmStringToQuark(fields[i].fieldValue);
rec->seq = _DtDtsNextDASeq();
fld = _DtDtsDbAddField(rec);
fld->fieldName = XrmStringToQuark(DtDTS_DA_DATA_HOST);
fld->fieldValue = hostPrefix?strdup(hostPrefix):(char *) 0;
rec->pathId = (int)pathId;
}
else
{
fld = _DtDtsDbAddField(rec);
fld->fieldName = fields[i].fieldName;
fld->fieldValue = strdup(fields[i].fieldValue);
}
i++;
}
_DtSvcProcessUnlock();
}
/******************************************************************************
*
* DtDtsLoadDataTypes -
*
* Reads in the file types and action databases.
*
* Also initializes the variable DtMaxFileTypes to the number
* of entries in the file types database.
*
* MODIFIED:
*
* DtMaxFtFileTypes
* DtMaxFileTypes - set to the number of real filetypes
* ( Holdovers from previous filetypes stuff -- still used by
* some clients. i.e. dtfile )
*
*****************************************************************************/
void
DtDtsLoadDataTypes(void)
{
/* with new mmap database this function is not needed to
* load the database. Just to initialize it.
*/
_DtDtsMMUnLoad();
}

View File

@@ -0,0 +1,752 @@
/*
* $TOG: DtsMM.c /main/16 1998/10/23 13:48:28 mgreess $
*
* RESTRICTED CONFIDENTIAL INFORMATION:
*
* (c) Copyright 1993,1994,1995 Sun Microsystems, Inc.
* All rights reserved.
*/
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#define SUN_DB
#ifdef SUN_DB
#include <sys/utsname.h>
#include <dirent.h>
#include <sys/mman.h>
#include <sys/param.h>
#endif
#include <string.h>
#define X_INCLUDE_DIRENT_H
#define XOS_USE_XT_LOCKING
#include <X11/Xos_r.h>
#include <Dt/DbReader.h>
#include "Dt/DtsMM.h"
#include "Dt/DtNlUtils.h"
#include <Dt/UserMsg.h>
#include "DtSvcLock.h"
extern char *strdup(const char *);
static int MMValidateDb(DtDirPaths *dirs, char *suffix);
static int _debug_print_name(char *name, char *label);
typedef int (*genfunc)(const void *, const void *);
static DtDtsMMDatabase *db_list;
static caddr_t mmaped_db = 0;
static size_t mmaped_size = 0;
static int mmaped_fd = 0;
static DtDtsMMHeader *head = 0;
void *
_DtDtsMMGetPtr(int index)
{
DtShmIntList int_list;
_DtSvcProcessLock();
if(!mmaped_db)
{
_DtDtsMMInit(0);
}
int_list = (DtShmIntList)&mmaped_db[sizeof(DtDtsMMHeader)];
_DtSvcProcessUnlock();
return((void *)&int_list[index]);
}
int
_DtDtsMMGetPtrSize(int index)
{
DtShmIntList int_list;
_DtSvcProcessLock();
if(!mmaped_db)
{
_DtDtsMMInit(0);
}
int_list = (DtShmIntList)&mmaped_db[sizeof(DtDtsMMHeader)];
_DtSvcProcessUnlock();
return(int_list[index-1]);
}
int *
_DtDtsMMGetDCNameIndex(int *size)
{
int *result;
_DtSvcProcessLock();
*size = _DtDtsMMGetPtrSize(head->name_list_offset);
result = (int*) _DtDtsMMGetPtr(head->name_list_offset);
_DtSvcProcessUnlock();
return(result);
}
int *
_DtDtsMMGetDbName(DtDtsMMDatabase *db, DtShmBoson boson)
{
DtShmInttab tab = (DtShmInttab)_DtDtsMMGetPtr(db->nameIndex);
return((int *)_DtShmFindIntTabEntry(tab, boson));
}
int *
_DtDtsMMGetNoNameIndex(int *size)
{
int *result;
_DtSvcProcessLock();
if(head->no_name_offset == -1)
{
*size = 0;
_DtSvcProcessUnlock();
return(0);
}
*size = _DtDtsMMGetPtrSize(head->no_name_offset);
result = (int *) _DtDtsMMGetPtr(head->no_name_offset);
_DtSvcProcessUnlock();
return(result);
}
/* returns the pointer to buffer only name list */
int *
_DtDtsMMGetBufferIndex(int *size)
{
int *list = (int*)_DtDtsMMGetNoNameIndex(size);
int *bufferIndex;
_DtSvcProcessLock();
*size -= head->buffer_start_index;
bufferIndex = &list[head->buffer_start_index];
_DtSvcProcessUnlock();
return(bufferIndex);
}
DtShmInttab
_DtDtsMMGetFileList(void)
{
DtShmInttab file_index;
_DtSvcProcessLock();
file_index = (DtShmStrtab)_DtDtsMMGetPtr(head->files_offset);
_DtSvcProcessUnlock();
return(file_index);
}
const char *
_DtDtsMMBosonToString(DtShmBoson boson)
{
DtShmStrtab str_table;
if (boson == 0)
return(0);
_DtSvcProcessLock();
if(!mmaped_db)
{
_DtDtsMMInit(0);
}
str_table = (DtShmStrtab)_DtDtsMMGetPtr(head->str_tbl_offset);
_DtSvcProcessUnlock();
return(_DtShmBosonToString(str_table, boson));
}
DtShmBoson
_DtDtsMMStringToBoson(const char *string)
{
DtShmStrtab str_table;
if ((string == (char *)NULL) || (*string == '\0'))
return(-1);
_DtSvcProcessLock();
if(!mmaped_db)
{
_DtDtsMMInit(0);
}
str_table = (DtShmStrtab)_DtDtsMMGetPtr(head->str_tbl_offset);
_DtSvcProcessUnlock();
return(_DtShmStringToBoson(str_table, string));
}
void
_DtDtsMMPrintFld(int fld, DtDtsMMField *fld_ptr, FILE *fd_in)
{
const char *tmp;
const char *tmpv;
FILE *fd = fd_in;
if(!fd) fd = stdout;
tmp = _DtDtsMMBosonToString(fld_ptr->fieldName);
tmpv = _DtDtsMMBosonToString(fld_ptr->fieldValue);
fprintf(fd, "\t\t[%d]\t%s(%d)\t%s(%d)\n", fld, tmp,fld_ptr->fieldName,
tmpv?tmpv:"(NULL)", fld_ptr->fieldValue);
}
void
_DtDtsMMPrintRec(int rec, DtDtsMMRecord *rec_ptr, FILE *fd_in)
{
int fld;
DtDtsMMField *fld_ptr;
DtDtsMMField *fld_ptr_list;
const char *tmp;
FILE *fd = fd_in;
if(!fd) fd = stdout;
tmp = _DtDtsMMBosonToString(rec_ptr->recordName);
fprintf(fd, "\tRec[%d] name = %s(%d)\n\t%d Fields\n", rec,
tmp, rec_ptr->recordName,
rec_ptr->fieldCount);
fld_ptr_list = _DtDtsMMGetPtr(rec_ptr->fieldList);
for(fld = 0; fld < rec_ptr->fieldCount; fld++)
{
fld_ptr = &fld_ptr_list[fld];
_DtDtsMMPrintFld(fld, fld_ptr, fd);
}
}
void
_DtDtsMMPrintDb(int db, DtDtsMMDatabase *db_ptr, FILE *fd_in)
{
int rec;
DtDtsMMRecord *rec_ptr;
DtDtsMMRecord *rec_ptr_list;
const char *tmp;
FILE *fd = fd_in;
if(!fd) fd = stdout;
fprintf(fd, "DB[%d] ", db);
tmp = _DtDtsMMBosonToString(db_ptr->databaseName);
fprintf(fd, "name = %s(%d)\n", tmp, db_ptr->databaseName);
fprintf(fd, "%d Records\n", db_ptr->recordCount);
rec_ptr_list = _DtDtsMMGetPtr(db_ptr->recordList);
for(rec = 0; rec < db_ptr->recordCount; rec++)
{
rec_ptr = &rec_ptr_list[rec];
_DtDtsMMPrintRec(rec, rec_ptr, fd);
}
}
void
_DtDtsMMPrint(FILE *org_fd)
{
int db;
DtDtsMMDatabase *db_ptr;
FILE *fd = org_fd;
const char *tmp;
_DtSvcProcessLock();
if(!mmaped_db)
{
_DtDtsMMInit(0);
}
for(db = 0; db < head->num_db; db++)
{
db_ptr = &db_list[db];
if(fd == 0)
{
chdir("/tmp");
tmp = _DtDtsMMBosonToString(db_ptr->databaseName);
if((fd = fopen(tmp, "w")) == NULL)
{
_DtSimpleError(
DtProgName, DtError, NULL,
(char*) tmp, NULL);
continue;
}
}
_DtDtsMMPrintDb(db, db_ptr, fd);
if(org_fd == 0)
{
fclose(fd);
fd = 0;
}
}
_DtSvcProcessUnlock();
}
int
_DtDtsMMCompareRecordNames(DtDtsMMRecord *a, DtDtsMMRecord *b)
{
return (a->recordName - b->recordName);
}
int
_DtDtsMMCompareFieldNames(DtDtsMMField *a, DtDtsMMField *b)
{
return (a->fieldName - b->fieldName);
}
#include <Dt/Dts.h>
int
_DtDtsMMInit(int override)
{
DtDirPaths *dirs = _DtGetDatabaseDirPaths();
char *CacheFile = _DtDtsMMCacheName(1);
if(override)
{
if (!_DtDtsMMCreateDb(dirs, CacheFile, override))
{
free(CacheFile);
_DtFreeDatabaseDirPaths(dirs);
return 0;
}
_debug_print_name(CacheFile, "Init");
}
else
{
int success = _DtDtsMMapDB(CacheFile);
if(success)
{
if(!MMValidateDb(dirs, ".dt"))
{
success = 0;
}
else
{
_debug_print_name(CacheFile, "Mapped");
}
}
if(!success)
{
free(CacheFile);
CacheFile = _DtDtsMMCacheName(0);
_debug_print_name(CacheFile, "Private");
/* Check return status, and pass status to caller. */
if (!_DtDtsMMCreateDb(dirs, CacheFile, override))
{
free(CacheFile);
_DtFreeDatabaseDirPaths(dirs);
return 0;
}
}
}
free(CacheFile);
_DtFreeDatabaseDirPaths(dirs);
return 1;
}
char **
_DtsMMListDb()
{
int i;
char **list;
_DtSvcProcessLock();
if(!mmaped_db)
{
_DtDtsMMInit(0);
}
list = (char **)malloc((head->num_db+1)*sizeof(char *));
for ( i = 0; i < head->num_db; i++ )
{
list[i] = (char *)_DtDtsMMBosonToString(db_list[i].databaseName);
}
list[i] = 0;
_DtSvcProcessUnlock();
return(list);
}
DtDtsMMDatabase *
_DtDtsMMGet(const char *name)
{
int i;
DtShmBoson boson = _DtDtsMMStringToBoson(name);
DtDtsMMDatabase *ret_db;
_DtSvcProcessLock();
if(!mmaped_db)
{
_DtDtsMMInit(0);
}
for(i = 0; i < head->num_db; i++)
{
if(db_list[i].databaseName == boson)
{
ret_db = &db_list[i];
_DtSvcProcessUnlock();
return(ret_db);
}
}
_DtSvcProcessUnlock();
return(NULL);
}
DtDtsMMField *
_DtDtsMMGetField(DtDtsMMRecord *rec, const char *name)
{
register int i;
int fld;
DtDtsMMField *fld_ptr;
DtDtsMMField *fld_ptr_list;
/*
* Field names have been quarked so quark 'name' and
* do a linear search for the quark'ed field name.
*/
DtShmBoson tmp = _DtDtsMMStringToBoson (name);
fld_ptr_list = _DtDtsMMGetPtr(rec->fieldList);
for (i = 0; i < rec->fieldCount; i++)
{
fld_ptr = &fld_ptr_list[i];
if (fld_ptr->fieldName == tmp)
{
return (fld_ptr);
}
}
return(NULL);
}
const char *
_DtDtsMMGetFieldByName(DtDtsMMRecord *rec, const char *name)
{
DtDtsMMField *result;
result = _DtDtsMMGetField(rec, name);
if(result)
{
return(_DtDtsMMBosonToString(result->fieldValue));
}
else
{
return(NULL);
}
}
DtDtsMMRecord *
_DtDtsMMGetRecordByName(DtDtsMMDatabase *db, const char *name)
{
DtDtsMMRecord srch;
DtDtsMMRecord *result;
DtDtsMMRecord *s = &srch;
register int i;
DtShmBoson name_quark = _DtDtsMMStringToBoson(name);
DtDtsMMRecord *rec_ptr;
DtDtsMMRecord *rec_ptr_list;
/*
* If the fields are not sorted in alphanumeric order
* by name a binary search will fail. So do the slow but
* sure linear search.
*/
rec_ptr_list = _DtDtsMMGetPtr(db->recordList);
for (i = 0; i < db->recordCount; i++)
{
rec_ptr = &rec_ptr_list[i];
if (rec_ptr->recordName == name_quark)
{
return (rec_ptr);
}
}
return NULL;
}
int
_DtDtsMMPathHash(DtDirPaths *dirs)
{
int pathhash = 0;
DIR *dirp;
struct dirent *dp = NULL;
int suffixLen;
int nameLen;
char *file_suffix;
char *next_path;
char *suffix = ".dt";
int i;
char *cur_dir = getcwd(0,MAXPATHLEN);
struct stat buf;
_Xreaddirparams dirEntryBuf;
struct dirent *result;
for(i = 0; dirs->paths[i] ; i++)
{
if(chdir(dirs->paths[i]) == -1)
{
continue;
}
dirp = opendir (".");
while ((result = _XReaddir(dirp, dirEntryBuf)) != NULL)
{
if ((int)strlen (result->d_name) >= (int)strlen(suffix))
{
suffixLen = DtCharCount(suffix);
nameLen = DtCharCount(result->d_name);
file_suffix = (char *)_DtGetNthChar(result->d_name,
nameLen - suffixLen);
stat(result->d_name, &buf);
if (file_suffix &&
(strcmp(file_suffix, suffix) == 0) &&
(buf.st_mode&S_IFREG))
{
char *c = dirs->paths[i];
while(*c)
{
pathhash += (int)*c;
c++;
}
break;
}
}
}
closedir(dirp);
}
chdir(cur_dir);
free(cur_dir);
return(pathhash);
}
char *
_DtDtsMMCacheName(int override)
{
char *dsp = getenv("DISPLAY");
char *results = 0;
char *c;
if(override && dsp)
{
results = malloc(strlen(_DTDTSMMTEMPDIR)+
strlen(_DTDTSMMTEMPFILE)+
strlen(dsp)+3);
sprintf(results, "%s/%s%s\0",
_DTDTSMMTEMPDIR,
_DTDTSMMTEMPFILE,
dsp);
c = strchr(results, ':');
c = strchr(c, '.');
if(c)
{
*c = '\0';
}
}
else
{
/* tempnam(3) is affected by the TMPDIR environment variable. */
/* This creates problems for rename() if "tmpfile" and "cacheFile" */
/* are on different file systems. Use tmpnam(3) to create the */
/* unique file name instead. */
char tmpnam_buf[L_tmpnam + 1];
results = (char *)malloc(sizeof(_DTDTSMMTEMPDIR) +
sizeof(_DTDTSMMTEMPFILE) +
L_tmpnam + 3);
tmpnam(tmpnam_buf);
sprintf(results, "%s/%s%s", _DTDTSMMTEMPDIR, _DTDTSMMTEMPFILE,
basename(tmpnam_buf));
}
return(results);
}
int
_DtDtsMMapDB(const char *CacheFile)
{
struct stat buf;
int success = FALSE;
_DtSvcProcessLock();
if (mmaped_fd > 0)
{
/* Already have a file memory-mapped. Unload it. */
_DtDtsMMUnLoad();
}
mmaped_fd = open(CacheFile, O_RDONLY, 0400);
if(mmaped_fd != -1)
{
if(fstat(mmaped_fd, &buf) == 0 && buf.st_uid == getuid())
{
mmaped_db = (char *)mmap(NULL,
buf.st_size,
PROT_READ,
#if defined(sun) || defined(USL)
/* MAP_NORESERVE is only supported
on sun and novell platforms */
MAP_SHARED|MAP_NORESERVE,
#else
MAP_SHARED,
#endif
mmaped_fd,
NULL);
if(mmaped_db != (void *) -1)
{
success = TRUE;
mmaped_size = buf.st_size;
head = (DtDtsMMHeader *)mmaped_db;
db_list = (DtDtsMMDatabase *)_DtDtsMMGetPtr(head->db_offset);
}
else
{
_DtSimpleError(
DtProgName, DtError, NULL,
(char*) CacheFile, NULL);
}
}
}
if(!success)
{
mmaped_db = 0;
}
_DtSvcProcessUnlock();
return(success);
}
static int
MMValidateDb(DtDirPaths *dirs, char *suffix)
{
DIR *dirp;
struct dirent *direntp;
struct stat buf;
struct stat new_buf;
int size = sizeof(buf.st_mtime);
DtShmBoson *boson_list = 0;
time_t *mtime_list;
int count = 0;
int i;
const char *file;
int pathhash = _DtDtsMMPathHash(dirs);
_DtSvcProcessLock();
if(head->pathhash != pathhash)
{
_DtSvcProcessUnlock();
return(0);
}
count = head->files_count;
mtime_list = _DtDtsMMGetPtr(head->mtimes_offset);
boson_list = _DtDtsMMGetPtr(head->files_offset);
for(i = 0; i < count; i++)
{
file = _DtDtsMMBosonToString(boson_list[i]);
stat(file, &buf);
if(mtime_list[i] != buf.st_mtime)
{
_DtSvcProcessUnlock();
return(0);
}
}
_DtSvcProcessUnlock();
return(1);
}
char *
_DtDtsMMExpandValue(const char *value)
{
char *newval;
if(!value)
{
return NULL;
}
newval = (char *)malloc(1024);
strcpy(newval, value);
_DtDbFillVariables(&newval);
return(newval);
}
void
_DtDtsMMSafeFree(char *value)
{
if(value && !_DtDtsMMIsMemory(value))
{
free(value);
}
}
int
_DtDtsMMIsMemory(const char *value)
{
_DtSvcProcessLock();
if((caddr_t)value < mmaped_db || (caddr_t)value > mmaped_db+mmaped_size)
{
_DtSvcProcessUnlock();
return(0);
}
else
{
_DtSvcProcessUnlock();
return(1);
}
}
int
_DtDtsMMUnLoad()
{
int error = 0;
_DtSvcProcessLock();
_DtDtsClear();
if(mmaped_db == 0)
{
_DtSvcProcessUnlock();
return(error);
}
if(munmap(mmaped_db, mmaped_size) == -1)
{
_DtSimpleError(DtProgName, DtError, NULL,
"munmap of dts_cache file", NULL);
error = -1;
}
if(close(mmaped_fd) == -1)
{
_DtSimpleError(DtProgName, DtError, NULL,
"close of dts_cache file", NULL);
}
db_list = 0;
mmaped_db = 0;
mmaped_size = 0;
mmaped_fd = 0;
head = 0;
_DtSvcProcessUnlock();
return(error);
}
#include "Dt/UserMsg.h"
static int
_debug_print_name(char *name, char *label)
{
#ifdef DEBUG
static char *db = (char *)-1;
_DtSvcProcessLock();
if(db == (char *)-1)
{
db = getenv("MMAP_DEBUG");
}
_DtSvcProcessUnlock();
if(db)
_DtSimpleError(db,
DtInformation,
NULL,
"%s - db name = %s\n", label,
name);
#endif /* DEBUG */
return(0);
}

View File

@@ -0,0 +1,152 @@
/* $XConsortium: DtsMM.h /main/8 1996/08/28 14:27:26 rswiston $ */
/*
*
* RESTRICTED CONFIDENTIAL INFORMATION:
*
*
* Copyright 1993 Sun Microsystems, Inc. All rights reserved.
*
*+ENOTICE
*/
#ifndef DT_DTS_MM_H
#define DT_DTS_MM_H
#include <stdio.h>
#include <Dt/DtShmDb.h>
#include <X11/Intrinsic.h>
#include "Dt/DbReader.h"
#define DTDTSDB_TMPDATABASENAME "%s/.dt/.tmp_dt_db_cache.%s\0"
#define DTDTSDB_DATABASENAME "%s/.dt/.dt_db_cache.%s\0"
#define _DTDTSMMTEMPFILE "dtdbcache_"
/*
* NOTE: _DTDTSMMTEMPDIR affects the location of the dtdbcache
* file, and therefore affects the Xsession.src, Xreset.src, and
* Xstartup.src scripts in dtlogin/config.
*/
#ifdef __osf__
# define _DTDTSMMTEMPDIR "/var/tmp"
#else
# define _DTDTSMMTEMPDIR "/tmp"
#endif
typedef int DtDtsMMSeqNo; /* the order it occures in db */
typedef int DtDtsMMFieldCount; /* number of fields in record */
typedef int DtDtsMMRecordCount; /* number of records in field */
typedef int DtDtsMMDataBaseCount; /* how many databases */
typedef int DtDtsMMFieldStart; /* index in table where field list starts */
typedef int DtDtsMMRecordStart; /* index in table where record list starts */
typedef int DtDtsMMDataBaseStart; /* index in table where database list starts */
typedef int DtDtsMMIndexOffset;
typedef int DtDtsMMNameIndex;
typedef int DtDtsMMPathHash;
typedef struct
{
DtDtsMMPathHash pathhash; /* hash of dir. we visit */
DtDtsMMDataBaseCount num_db; /* number of databases */
DtDtsMMDataBaseStart db_offset; /* index to databases */
DtDtsMMNameIndex name_list_offset; /* index to name list */
DtDtsMMNameIndex no_name_offset; /* index to nonunique names */
DtDtsMMNameIndex buffer_start_index; /* index to list of buffers */
DtDtsMMIndexOffset str_tbl_offset; /* index to table of strings */
DtDtsMMIndexOffset files_count; /* number of loaded files */
DtDtsMMIndexOffset files_offset; /* index to list of loaded files */
DtDtsMMIndexOffset mtimes_offset; /* index to modified times of files */
} DtDtsMMHeader;
/* one set of attribute/pair */
typedef struct
{
DtShmBoson fieldName; /* name of attribute */
DtShmBoson fieldValue; /* value of attribute */
} DtDtsMMField;
/* typedefs for casting comparison functions if needed */
typedef int (*_DtDtsMMFieldCompare)(DtDtsMMField *fld1, DtDtsMMField *fld2);
/* entry of a list of attribute/pairs */
typedef struct
{
DtShmBoson recordName; /* name of this entry */
DtShmBoson pathId; /* file entry is located in */
DtDtsMMSeqNo seq; /* sequence this got loaded */
DtDtsMMFieldCount fieldCount; /* number of fields in record */
DtDtsMMFieldStart fieldList; /* index to field table */
} DtDtsMMRecord;
/* typedefs for casting record comparison functions if needed */
typedef int (*_DtDtsMMRecordCompare)(DtDtsMMRecord *rec1, DtDtsMMRecord *rec2);
/* a "database" of a collection of entrys (i.e. OBJECT-TYPE, ACTION, FILE-TYPE
This is a private Structure to the DtDtsMM component.
*/
typedef struct
{
DtShmBoson databaseName; /* name of database */
DtDtsMMIndexOffset nameIndex; /* index for DataCriteria quick find */
DtDtsMMRecordCount recordCount; /* number of records */
DtDtsMMRecordStart recordList; /* index to records table */
} DtDtsMMDatabase;
/* Db Internal pointers */
int * _DtDtsMMGetDCNameIndex(int *size);
int * _DtDtsMMGetBufferIndex(int *size);
int * _DtDtsMMGetNoNameIndex(int *size);
void * _DtDtsMMGetPtr(int index);
DtShmInttab _DtDtsMMGetFileList(void);
int _DtDtsMMGetPtrSize(int index);
int _DtDtsMMInit(int);
void _DtDtsMMPrint(FILE *org_fd);
int _DtDtsMMCreateDb(DtDirPaths *dirs, const char *CacheFile, int override);
int _DtDtsMMCreateFile(DtDirPaths *dirs, const char *CacheFile);
char * _DtDtsMMCacheName(int);
int _DtDtsMMapDB(const char *CacheFile);
const char * _DtDtsMMBosonToString(DtShmBoson boson);
DtShmBoson _DtDtsMMStringToBoson(const char *string);
extern int use_in_memory_db;
/* returns the handle for the database where name is the Database name */
extern DtDtsMMDatabase *_DtDtsMMGet(const char *name);
extern char **_DtDtsMMListDb(void);
/* Name Comparison functions:
* These routines can be passed in to the corresponding sort function to
* sort by name.
*
*/
extern int _DtDtsMMCompareRecordNames(DtDtsMMRecord *entry1, DtDtsMMRecord *entry2);
extern int _DtDtsMMCompareFieldNames(DtDtsMMField *entry1, DtDtsMMField *entry2);
/* retrieves the Record that matches the specified entry from the record */
extern DtDtsMMField *_DtDtsMMGetField(DtDtsMMRecord *record,
const char *value);
extern const char *_DtDtsMMGetFieldByName(DtDtsMMRecord *rec, const char *name);
/* retrieves the entry of the specified entry from the specified database */
extern DtDtsMMRecord *_DtDtsMMGetRecord(DtDtsMMDatabase *database,
DtDtsMMRecord *value);
extern DtDtsMMRecord *_DtDtsMMGetRecordByName(DtDtsMMDatabase *database,
const char *value);
/* Get By Name functions:
* retrieves the entry of the specified name from the specified database
* ** IF ** the _DtDtsMM*Sort routine has been called with the corresponding
* _DtDtsMMCompare*Name comparison function. Otherwise use the standard
* _DtDtsMMGet* functions.
*/
char * _DtDtsMMExpandValue(const char *value);
void _DtDtsMMSafeFree(char *value);
int _DtDtsMMIsMemory(const char *value);
extern DtShmBoson _DtDtsMMNameStringToBoson(const char *string);
#endif /* DT_DTS_MM_H */

View File

@@ -0,0 +1,451 @@
/*
* (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. *
*/
/*
*+SNOTICE
*
* $XConsortium: DtsSort.c /main/6 1996/11/21 19:56:08 drk $
*
* RESTRICTED CONFIDENTIAL INFORMATION:
*
* The information in this document is subject to special
* restrictions in a confidential disclosure agreement bertween
* HP, IBM, Sun, USL, SCO and Univel. Do not distribute this
* document outside HP, IBM, Sun, USL, SCO, or Univel wihtout
* Sun's specific written approval. This documment and all copies
* and derivative works thereof must be returned or destroyed at
* Sun's request.
*
* Copyright 1993 Sun Microsystems, Inc. All rights reserved.
*
*+ENOTICE
*/
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <sys/stat.h>
#define X_INCLUDE_STRING_H
#define XOS_USE_XT_LOCKING
#include <X11/Xos_r.h>
#include <Dt/DbReader.h>
#include "Dt/DtsDb.h"
#include "Dt/Dts.h"
extern char *strdup(const char *);
static char *
get_value(DtDtsDbRecord *ce_entry, char *value)
{
int i=0;
XrmQuark tmp = XrmStringToQuark (value);
for(i = 0; i < ce_entry->fieldCount; i++)
{
if(ce_entry->fieldList[i]->fieldName == tmp)
{
return(ce_entry->fieldList[i]->fieldValue);
}
}
return(NULL);
}
void
parts_of_pattern(char *c, int *spec, int *count, int *front)
{
int nested = 0;
int found = 0;
int len;
(*count) = 0;
(*spec) = 0;
(*front) = 0;
while(*c)
{
if((len = mblen(c, MB_CUR_MAX)) > 1) {
(*count) += len;
if(!found)
(*front) += len;
c += len;
continue;
}
switch(*c)
{
case '*':
if(!nested)
{
(*spec) += 100;
found = 1;
}
break;
case '?':
if(!nested)
{
(*spec) += 1;
found = 1;
}
break;
case '[':
(*spec) += 10;
nested ++;
found = 1;
break;
case ']':
if(nested)
{
nested --;
}
break;
case '\\':
if(!nested)
{
if((len = mblen(c + 1, MB_CUR_MAX)) > 1) {
(*count) += len + 1;
c += len;
}
else {
(*count) += 2;
c++;
}
}
break;
default:
(*count)++;
if(!found)
{
(*front)++;
}
}
c++;
}
}
int
check_pattern(char *value1, char *value2)
{
int spec1 = 0,count1 = 0, front1 = 0;
int spec2 = 0,count2 = 0, front2 = 0;
if(value1 && value2)
{
parts_of_pattern(value1, &spec1, &count1, &front1);
parts_of_pattern(value2, &spec2, &count2, &front2);
}
else if(!value1 && !value2)
{
return(0);
}
else if(value1)
{
return(-1);
}
else
{
return(1);
}
if(front1 != front2)
{
return(front2 - front1);
}
if(spec1 != spec2)
{
return(spec1 - spec2);
}
if(count1 != count2)
{
return(count2-count1);
}
return (0);
}
int
mode_count(char *c)
{
int count = 0;
while(c && *c)
{
if(strchr("fcbdlrwx", *c))
{
count++;
}
c++;
}
return(count);
}
#ifdef DEBUG
static int
bool(int i)
{
if(i > 0) return(1);
if(i < 0) return(-1);
else return(0);
}
#endif
check_content(char *val1, char *val2)
{
char *v1 = strdup(val1);
char *v2 = strdup(val2);
char *loc1;
char *loc2;
char *type1;
char *type2;
char *cnt1;
char *cnt2;
int ret = 0;
_Xstrtokparams strtok_buf;
loc1 = _XStrtok(v1, "\t \n", strtok_buf);
type1 = _XStrtok(NULL, "\t \n", strtok_buf);
cnt1 = &type1[strlen(type1)+1];
while(isspace((u_char)*cnt1))cnt1++;
loc2 = _XStrtok(v2, "\t \n", strtok_buf);
type2 = _XStrtok(NULL, "\t \n", strtok_buf);
cnt2 = &type2[strlen(type2)+1];
while(isspace((u_char)*cnt2))cnt2++;
ret = strcmp(type1, type2);
if(loc1 && loc2 && ret == 0)
{
int l1 = atoi(loc1);
int l2 = atoi(loc2);
int sl1 = strlen(cnt1);
int sl2 = strlen(cnt2);
char sym;
if (sl1 > sl2) ret = -1;
else if (sl1 < sl2) ret = 1;
else if (l1 > l2 ) ret = 1;
else if (l1 < l2 ) ret = -1;
else ret = strcmp(cnt1,cnt2);
#ifdef DEBUG
switch(bool(ret))
{
case 0:
sym = '=';
break;
case -1:
sym = '>';
break;
case 1:
sym = '<';
}
printf("cc (%d,%d) for \"%s\" %c \"%s\"\n", l1, l2, cnt1, sym, cnt2);
#endif
}
free(v1);
free(v2);
return(ret);
}
static int
sfe(DtDtsDbRecord * item1, DtDtsDbRecord * item2)
{
int test1 = 0;
int test2 = 0;
int loc1;
int loc2;
char *value1, *value2;
DtDtsDbRecord *rec;
DtDtsDbField *fld;
int val;
test1 |= get_value(item1, DtDTS_CONTENT) ? 2 : 0;
test2 |= get_value(item2, DtDTS_CONTENT) ? 2 : 0;
value1 = get_value(item1, DtDTS_NAME_PATTERN);
if (value1)
{
if ((strlen(value1) == 1) && (*value1 == '*'))
{
test1 |= 0;
}
else
{
test1 |= 1;
}
}
value2 = get_value(item2, DtDTS_NAME_PATTERN);
if (value2)
{
if ((strlen(value2) == 1) && (*value2 == '*'))
{
test2 |= 0;
}
else
{
test2 |= 1;
}
}
if (!(test1 & 1))
{
test1 |= get_value(item1, DtDTS_PATH_PATTERN) ? 1 : 0;
}
if (!(test2 & 1))
{
test2 |= get_value(item2, DtDTS_PATH_PATTERN) ? 1 : 0;
}
switch (test1)
{
case 0:
loc1 = 4;
break;
case 1:
loc1 = 2;
break;
case 2:
loc1 = 3;
break;
case 3:
loc1 = 1;
break;
}
switch (test2)
{
case 0:
loc2 = 4;
break;
case 1:
loc2 = 2;
break;
case 2:
loc2 = 3;
break;
case 3:
loc2 = 1;
break;
}
if (loc1 - loc2)
{
return (loc1 - loc2);
}
if (loc1 == 2) /* loc1 == loc2 */
{
val = check_pattern(get_value(item1, DtDTS_PATH_PATTERN),
get_value(item2, DtDTS_PATH_PATTERN));
if(val)
{
return(val);
}
val = check_pattern(get_value(item1, DtDTS_NAME_PATTERN),
get_value(item2, DtDTS_NAME_PATTERN));
if(val)
{
return(val);
}
}
if( loc1 == 3)
{
val = check_content(get_value(item1, DtDTS_CONTENT),
get_value(item2, DtDTS_CONTENT));
if(val)
{
return(val);
}
}
/*
* neither pattern nor content, only needs to compare the
* number of fields. If they are equal then which has shorter
* record name will be more specific
*/
if (item2->fieldCount - item1->fieldCount)
{
return (item2->fieldCount - item1->fieldCount);
}
val = mode_count(get_value(item2, DtDTS_MODE)) -
mode_count(get_value(item1, DtDTS_MODE));
if(val)
{
return(val);
}
val = strlen(XrmQuarkToString(item1->recordName)) -
strlen(XrmQuarkToString(item2->recordName));
if(val)
{
return(val);
}
else
{
return(item1->recordName - item2->recordName);
}
}
int
cde_dc_compare(DtDtsDbRecord ** a, DtDtsDbRecord ** b)
{
DtDtsDbRecord **x = (DtDtsDbRecord **) a;
DtDtsDbRecord **y = (DtDtsDbRecord **) b;
int results;
char c;
results = sfe(*x, *y);
return(results);
}
static int
cde_ft_field_value(XrmQuark name_quark)
{
if (name_quark == XrmStringToQuark(DtDTS_PATH_PATTERN))
return (1);
else if (name_quark == XrmStringToQuark(DtDTS_NAME_PATTERN))
return (2);
else if (name_quark == XrmStringToQuark(DtDTS_MODE))
return (3);
else if (name_quark == XrmStringToQuark(DtDTS_LINK_PATH))
return (4);
else if (name_quark == XrmStringToQuark(DtDTS_LINK_NAME))
return (5);
else if (name_quark == XrmStringToQuark(DtDTS_CONTENT))
return (6);
else if (name_quark == XrmStringToQuark(DtDTS_DATA_ATTRIBUTES_NAME))
return (7);
else if (name_quark == XrmStringToQuark(DtDTS_DA_IS_SYNTHETIC))
return (8);
else
return (9);
}
int
cde_dc_field_compare(DtDtsDbField ** a, DtDtsDbField ** b)
{
return (cde_ft_field_value((*a)->fieldName) -
cde_ft_field_value((*b)->fieldName));
}
cde_da_compare(DtDtsDbRecord ** a, DtDtsDbRecord ** b)
{
int results = ((*a)->recordName) - ((*b)->recordName);
if (!results)
{
results = (*a)->seq - (*b)->seq;
}
return (results);
}

View File

@@ -0,0 +1,190 @@
/* $XConsortium: GetMwmW.c /main/5 1996/05/20 16:07:08 drk $
*
* (c) Copyright 1996 Digital Equipment Corporation.
* (c) Copyright 1990,1993,1994,1996 Hewlett-Packard Company.
* (c) Copyright 1993,1994,1996 International Business Machines Corp.
* (c) Copyright 1993,1994,1996 Sun Microsystems, Inc.
* (c) Copyright 1993,1994,1996 Novell, Inc.
* (c) Copyright 1996 FUJITSU LIMITED.
* (c) Copyright 1996 Hitachi.
*/
/************************************<+>*************************************
****************************************************************************
**
** File: GetMwmW.c
**
** Project: DT Workspace Manager
**
** Description: Gets the mwm window id.
**
****************************************************************************
************************************<+>*************************************/
#include <stdio.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <Xm/MwmUtil.h>
#include <Xm/Xm.h>
#include <Xm/AtomMgr.h>
/******** Public Function Declarations ********/
extern int _DtGetMwmWindow(
Display *display,
Window root,
Window *pMwmWindow) ;
/******** End Public Function Declarations ********/
/******** Static Function Declarations ********/
static int _GetMwmWindow(
Display *display,
Window root,
Window *pMwmWindow,
Atom property) ;
/******** End Static Function Declarations ********/
/*************************************<->*************************************
*
* int _GetMwmWindow (display, root, pMwmWindow, property)
*
*
* Description:
* -----------
* Get the Motif Window manager window
*
*
* Inputs:
* ------
* display - display
* root - root window of screen
* pMwmWindow - pointer to a window (to be returned)
* property - the property atom
*
* Outputs:
* --------
* *pMwmWindow - mwm window id, if successful
* Return - status from XGetWindowProperty
*
* Comments:
* --------
* This can fail if mwm is not managing the screen for the root window
* passed in.
*
*************************************<->***********************************/
static int
_GetMwmWindow(
Display *display,
Window root,
Window *pMwmWindow,
Atom property )
{
Atom actualType;
int actualFormat;
unsigned long nitems;
unsigned long leftover;
PropMotifWmInfo *pWmInfo = NULL;
int rcode;
Window wroot, wparent, *pchildren;
unsigned int nchildren;
*pMwmWindow = NULL;
if ((rcode=XGetWindowProperty(display,root,
property,0L, PROP_MWM_INFO_ELEMENTS,
False,property,
&actualType,&actualFormat,
&nitems,&leftover,(unsigned char **)&pWmInfo))==Success)
{
if (actualType != property)
{
/* wrong type, force failure */
rcode = BadValue;
}
else
{
rcode = BadWindow; /* assume the worst */
/*
* The mwm window should be a direct child of root
*/
if (XQueryTree (display, root, &wroot, &wparent,
&pchildren, &nchildren))
{
int i;
for (i = 0; (i < nchildren) && (rcode != Success); i++)
{
if (pchildren[i] == pWmInfo->wmWindow)
{
rcode = Success;
}
}
}
if (rcode == Success);
{
*pMwmWindow = pWmInfo->wmWindow;
}
if (pchildren)
{
XFree ((char *)pchildren);
}
}
if (pWmInfo)
{
XFree ((char *)pWmInfo);
}
}
return(rcode);
} /* END OF FUNCTION _GetMwmWindow */
/*************************************<->*************************************
*
* int _DtGetMwmWindow (display, root, pMwmWindow)
*
*
* Description:
* -----------
* Get the Motif Window manager window
*
*
* Inputs:
* ------
* display - display
* root - root window of screen
* pMwmWindow - pointer to a window (to be returned)
*
* Outputs:
* --------
* *pMwmWindow - mwm window id, if successful
* Return - status from XGetWindowProperty
*
* Comments:
* --------
* This can fail if mwm is not managing the screen for the root window
* passed in.
*
*************************************<->***********************************/
int
_DtGetMwmWindow(
Display *display,
Window root,
Window *pMwmWindow )
{
Atom xa_MWM_INFO;
xa_MWM_INFO = XmInternAtom (display, _XA_MWM_INFO, False);
return (_GetMwmWindow (display, root, pMwmWindow, xa_MWM_INFO));
}

View File

@@ -0,0 +1,167 @@
/* $XConsortium: GetVWmHint.c /main/5 1996/05/20 16:07:19 drk $
*
* (c) Copyright 1996 Digital Equipment Corporation.
* (c) Copyright 1991,1993,1994,1996 Hewlett-Packard Company.
* (c) Copyright 1993,1994,1996 International Business Machines Corp.
* (c) Copyright 1993,1994,1996 Sun Microsystems, Inc.
* (c) Copyright 1993,1994,1996 Novell, Inc.
* (c) Copyright 1996 FUJITSU LIMITED.
* (c) Copyright 1996 Hitachi.
*/
/************************************<+>*************************************
****************************************************************************
**
** File: GetVwmHint.c
**
** Project: DT Workspace Manager
**
** Description: Get Dt Window manager hints
**
****************************************************************************
************************************<+>*************************************/
#include <stdio.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <Dt/Wsm.h>
#include <Dt/WsmP.h>
#include <Xm/Xm.h>
#include <Xm/AtomMgr.h>
/*************************************<->*************************************
*
* int _DtWsmGetDtWmHints (display, window, ppDtWmHints)
*
*
* Description:
* -----------
* Get the contents of the _DT_WM_HINTS property on a window
*
*
* Inputs:
* ------
* display - display
* window - window to get hints from
* ppDtWmHints- pointer to a pointer to return
*
* Outputs:
* --------
* *ppDtWmHints-points to the DtWmHints structure retrieved from
* the window (NOTE: This should be freed using XFree)
*
* Comments:
* ---------
*
*************************************<->***********************************/
int
_DtWsmGetDtWmHints(
Display *display,
Window window,
DtWmHints **ppDtWmHints)
{
Atom actualType;
int actualFormat;
unsigned long leftover, items, length;
int rcode;
Atom property;
#ifdef HP_VUE
unsigned long oldlength;
#endif /* HP_VUE */
property = XmInternAtom(display, _XA_DT_WM_HINTS, False);
length = sizeof (DtWmHints) / sizeof (long);
*ppDtWmHints = NULL;
if ((rcode=XGetWindowProperty(
display,
window,
property,
0L, /* offset */
length,
False, /* delete */
property, /* req_type */
&actualType,
&actualFormat,
&items, /* items returned */
&leftover,
(unsigned char **)ppDtWmHints))==Success)
{
if ((actualType != property) || (items < length))
{
/* wrong type, force failure */
rcode = BadValue;
if (actualType != None)
{
XFree ((char *)*ppDtWmHints);
}
*ppDtWmHints = NULL;
}
}
#ifdef HP_VUE
else {
/*
* Didn't get the Dt hints, try to get the Vue hints.
* Not that the Vue hints had the same structure, just
* under a different property name.
*/
property = XmInternAtom(display, _XA_VUE_WM_HINTS, False);
/*
* Property previously existed without attachWindow.
*/
oldlength = length - (sizeof(Window)/sizeof(long));
*ppDtWmHints = NULL;
if ((rcode=XGetWindowProperty(
display,
window,
property,
0L, /* offset */
length,
False, /* delete */
property, /* req_type */
&actualType,
&actualFormat,
&items, /* items returned */
&leftover,
(unsigned char **)ppDtWmHints))==Success)
{
if ((actualType != property) ||
(items < oldlength))
{
/* wrong type, force failure */
rcode = BadValue;
if (actualType != None)
{
XFree ((char *)*ppDtWmHints);
}
*ppDtWmHints = NULL;
}
if (*ppDtWmHints && (items < length))
{
DtWmHints *pvh;
/* assume old property, return full sized
property with empty values */
pvh = (DtWmHints *) malloc (length * sizeof (long));
pvh->flags = (*ppDtWmHints)->flags;
pvh->functions = (*ppDtWmHints)->functions;
pvh->behaviors = (*ppDtWmHints)->behaviors;
pvh->attachWindow = NULL;
XFree ((char *) *ppDtWmHints);
*ppDtWmHints = pvh;
}
}
}
#endif /* HP_VUE */
return(rcode);
} /* END OF FUNCTION _DtWsmGetDtWmHints */

View File

@@ -0,0 +1,167 @@
XCOMM $XConsortium: Imakefile /main/6 1996/08/20 14:48:27 drk $
#define DoNormalLib NormalLibDtSvc
#define DoSharedLib SharedLibDtSvc
#define DoDebugLib DebugLibDtSvc
#define DoProfileLib ProfileLibDtSvc
#define LibName DtSvc
#define SoRev SODTSVCREV
#define IncSubdir Dt
#define LibCreate NO
#define LargePICTable YES
#include <Threads.tmpl>
#ifndef DtSvcDefines
# define DtSvcDefines -DXK_MISCELLANY -DMULTIBYTE
#endif
DEFINES = DtSvcDefines \
-DCDE_INSTALLATION_TOP=\"$(CDE_INSTALLATION_TOP)\" \
-DCDE_CONFIGURATION_TOP=\"$(CDE_CONFIGURATION_TOP)\"
INCLUDES = -I. -I../include
HEADERS = \
Action.h \
ActionDb.h \
ActionDbP.h \
ActionP.h \
ActionFind.h \
ActionUtilP.h \
CmdInv.h \
CmdInvP.h \
DbReader.h \
DbUtil.h \
Dnd.h \
DndP.h \
DndIconI.h \
Dt.h \
Dts.h \
DtsDb.h \
DtsMM.h \
DtHash.h \
DtShmDb.h \
Qualify.h \
Saver.h \
SaverP.h \
Session.h \
SessionM.h \
SessionP.h \
Wsm.h \
WsmM.h \
WsmP.h
SRCS = \
Action.c \
ActionTt.c \
ActionDb.c \
ActionFind.c \
ActionUtil.c \
DbReader.c \
DbUtil.c \
CmdSpc.c \
CmdMain.c \
CmdProcess.c \
CmdUtilityP.c \
Dnd.c \
DndDrag.c \
DndDrop.c \
DndIcon.c \
DndBuff.c \
DndFile.c \
DndText.c \
Dt.c \
Dts.c \
DtsDb.c \
DtsSort.c \
DbLoad.c \
DtsInit.c \
DtHash.c \
intarray.c \
inttab.c \
strtab.c \
DtsMM.c \
MMDb.c \
GetVWmHint.c \
GetMwmW.c \
Qualify.c \
Saver.c \
SetVWmHint.c \
SmComm.c \
SmUtil.c \
WmAddDelWs.c \
WmBackWin.c \
WmChBackD.c \
WmGWsInfo.c \
WmGWsList.c \
WmMarquee.c \
WmRestart.c \
WmRmWsFcn.c \
WmSetTitle.c \
WmWsCallB.c \
WmSetWs.c \
WmWsHints.c \
WmWsOccupy.c
/* WARNING!!!!
* Any .o's added to this list need to be added to DTUTIL1_OBJS1
* and SHARED_DTUTIL1_OBJS1 in the DtSvc Imakefile.
*/
OBJS = \
Action.o \
ActionTt.o \
ActionDb.o \
ActionFind.o \
ActionUtil.o \
DbReader.o \
DbUtil.o \
CmdSpc.o \
CmdMain.o \
CmdProcess.o \
CmdUtilityP.o \
Dnd.o \
DndDrag.o \
DndDrop.o \
DndIcon.o \
DndBuff.o \
DndFile.o \
DndText.o \
Dt.o \
Dts.o \
DtsDb.o \
DtsSort.o \
DbLoad.o \
DtsInit.o \
DtHash.o \
intarray.o \
inttab.o \
strtab.o \
DtsMM.o \
MMDb.o \
GetVWmHint.o \
GetMwmW.o \
Qualify.o \
Saver.o \
SetVWmHint.o \
SmComm.o \
SmUtil.o \
WmAddDelWs.o \
WmBackWin.o \
WmChBackD.o \
WmGWsInfo.o \
WmGWsList.o \
WmMarquee.o \
WmRestart.o \
WmRmWsFcn.o\
WmSetTitle.o \
WmWsCallB.o \
WmSetWs.o \
WmWsHints.o \
WmWsOccupy.o
#include <Library.tmpl>
SubdirLibraryRule($(OBJS))
DependTarget()

View File

@@ -0,0 +1,717 @@
/* $TOG: MMDb.c /main/19 1998/10/23 13:48:52 mgreess $ */
/*
* +SNOTICE
*
* Copyright 1995 Sun Microsystems, Inc. All rights reserved.
*
* +ENOTICE
*/
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <malloc.h>
#include <sys/utsname.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#ifdef NLS16
#include <limits.h>
#endif
#include <sys/stat.h>
#include <sys/param.h> /* MAXPATHLEN, MAXHOSTNAMELEN */
#define X_INCLUDE_DIRENT_H
#define XOS_USE_XT_LOCKING
#include <X11/Xos_r.h>
#include <Dt/DbReader.h>
#include <Dt/DtsDb.h>
#include <Dt/DtsMM.h>
#include <Dt/DtShmDb.h>
#include <Dt/Dts.h>
#include <Dt/ActionP.h>
#include <Dt/ActionDbP.h>
#include <Dt/ActionUtilP.h>
#include <Dt/DtNlUtils.h>
#include <Dt/UserMsg.h>
#include "myassertP.h"
#include "DtSvcLock.h"
static void build_file_list(DtShmProtoIntList, DtDirPaths *,
DtDtsMMHeader *, const char *);
extern int cde_dc_field_compare(DtDtsDbField **, DtDtsDbField **);
extern int cde_dc_compare(DtDtsDbRecord **, DtDtsDbRecord **);
static void _DtMMSortDataTypes(DtShmProtoStrtab str_handle);
static void _DtMMAddActionsToDataAttribute(DtDtsDbDatabase *db_ptr);
static int write_db(DtDtsMMHeader *header, void *index, int size,
const char *CacheFile);
static int build_new_db(DtShmProtoStrtab, DtShmProtoIntList, int, DtDtsDbDatabase **);
static int build_name_list(DtDtsDbDatabase *, DtShmProtoIntList, DtDtsMMHeader *);
static DtShmProtoStrtab shm_handle = 0;
static DtShmProtoIntList int_handle = 0;
#define QtB(a) _DtShmProtoAddStrtab(shm_handle, XrmQuarkToString(a), &isnew)
int
_MMWriteDb(DtDirPaths *dirs, int num_db, DtDtsDbDatabase **db_list,
const char *CacheFile)
{
DtDtsMMHeader header;
char *suffix = ".dt";
int tbl_size;
void *tbl_data;
DtDtsDbDatabase *db;
int returnCode;
_DtSvcProcessLock();
memset(&header, '\0', sizeof(header));
int_handle = _DtShmProtoInitIntLst(50000);
shm_handle = _DtShmProtoInitStrtab(10000);
build_file_list(int_handle, dirs, &header, suffix);
_DtMMSortDataTypes(shm_handle);
db = (DtDtsDbDatabase *) _DtDtsDbGet(DtDTS_DA_NAME);
_DtMMAddActionsToDataAttribute(db);
header.pathhash = _DtDtsMMPathHash(dirs);
header.num_db = num_db;
header.db_offset = build_new_db(shm_handle, int_handle, num_db,
db_list);
db = (DtDtsDbDatabase *) _DtDtsDbGet("DATA_CRITERIA");
build_name_list(db, int_handle, &header);
tbl_size = _DtShmProtoSizeStrtab(shm_handle);
tbl_data = (void *) _DtShmProtoAddIntLst(int_handle,
tbl_size/sizeof(int), &header.str_tbl_offset);
_DtShmProtoCopyStrtab(shm_handle, tbl_data);
tbl_size = _DtShmProtoSizeIntLst(int_handle);
tbl_data = (void *)malloc(tbl_size);
memset(tbl_data, '\0', tbl_size);
tbl_data = (void *)_DtShmProtoCopyIntLst(int_handle, tbl_data);
returnCode = write_db(&header, tbl_data, tbl_size, CacheFile);
_DtShmProtoDestroyStrtab(shm_handle);
_DtShmProtoDestroyIntLst(int_handle);
_DtSvcProcessUnlock();
free(tbl_data);
return returnCode;
}
static void
build_file_list(DtShmProtoIntList int_handle, DtDirPaths *dirs,
DtDtsMMHeader *header, const char *suffix)
{
DIR *dirp;
struct dirent *dp = NULL;
struct stat buf;
char cur_path[MAXPATHLEN+1];
void *data;
int size = sizeof(buf.st_mtime);
int i;
int isnew;
DtShmBoson *boson_list = 0;
time_t *mtime_list = 0;
int count = 0;
_Xreaddirparams dirEntryBuf;
struct dirent *result;
/* Theses here to make sure it gets into the string tables
because actions uses it in its "types" field. */
_DtShmProtoAddStrtab(shm_handle, DtDTS_DT_UNKNOWN, &isnew);
_DtShmProtoAddStrtab(shm_handle, DtDTS_DT_RECURSIVE_LINK, &isnew);
_DtShmProtoAddStrtab(shm_handle, DtDTS_DT_BROKEN_LINK, &isnew);
getcwd(cur_path, sizeof(cur_path));
for(i = 0; dirs->paths[i]; i++)
{
chdir(dirs->paths[i]);
stat(".", &buf);
count++;
boson_list = (int *)realloc(boson_list, count*sizeof(int));
mtime_list = (time_t *)realloc(mtime_list, count*sizeof(time_t));
mtime_list[count-1] = buf.st_mtime;
boson_list[count-1] = _DtShmProtoAddStrtab(shm_handle, dirs->paths[i], &isnew);
dirp = opendir(".");
while ((result = _XReaddir(dirp, dirEntryBuf)) != NULL)
{
char *c = strrchr(result->d_name, suffix[0]);
if(c && strcmp(c, suffix) == 0)
{
char *pathname = malloc(MAXPATHLEN+1);
sprintf(pathname, "%s/%s", dirs->paths[i], result->d_name);
stat(result->d_name, &buf);
count++;
boson_list = (int *)realloc(boson_list, count*sizeof(int));
mtime_list = (time_t *)realloc(mtime_list, count*sizeof(time_t));
mtime_list[count-1] = buf.st_mtime;
boson_list[count-1] = _DtShmProtoAddStrtab(shm_handle,
pathname, &isnew);
if (pathname) free(pathname);
continue;
}
}
(void)closedir( dirp );
}
chdir(cur_path);
data = _DtShmProtoAddIntLst(int_handle, count, &header->files_offset);
memcpy(data, boson_list, count*sizeof(int));
data = _DtShmProtoAddIntLst(int_handle, count*sizeof(time_t)/sizeof(int), &header->mtimes_offset);
memcpy(data, mtime_list, count*sizeof(time_t));
header->files_count = count;
if(boson_list)free(boson_list);
if(mtime_list)free(mtime_list);
return;
}
static int
db_table_size(int num_db, DtDtsDbDatabase **db_list)
{
int db;
DtDtsDbDatabase *db_ptr;
int rec;
DtDtsDbRecord *rec_ptr;
int fld;
DtDtsDbField *fld_ptr;
int size = 0;
size += num_db*sizeof(DtDtsMMDatabase);
for(db = 0; db < num_db; db++)
{
db_ptr = db_list[db];
size += db_ptr->recordCount * sizeof(DtDtsMMRecord);
for(rec = 0; rec < db_ptr->recordCount; rec++)
{
rec_ptr = db_ptr->recordList[rec];
size += rec_ptr->fieldCount * sizeof(DtDtsMMField);
}
}
return(size/sizeof(int));
}
static void
_DtMMSortDataTypes(DtShmProtoStrtab str_handle)
{
DtDtsDbDatabase *dc;
DtDtsDbDatabase *da;
int i;
_DtSvcProcessLock();
dc = (DtDtsDbDatabase *) _DtDtsDbGet(DtDTS_DC_NAME);
da = (DtDtsDbDatabase *) _DtDtsDbGet(DtDTS_DA_NAME);
/*_DtDtsDbPrintRecords(dc, stdout);*/
for(i = 0; i < dc->recordCount; i++)
{
if(dc->recordList[i]->compare != cde_dc_field_compare)
{
_DtDtsDbFieldSort(dc->recordList[i],
cde_dc_field_compare);
}
}
_DtDtsDbRecordSort(dc, cde_dc_compare);
for(i = 0; i < da->recordCount; i++)
{
if(da->recordList[i]->compare !=
_DtDtsDbCompareFieldNames)
{
_DtDtsDbFieldSort(da->recordList[i],
_DtDtsDbCompareFieldNames);
}
}
_DtDtsDbRecordSort(da, _DtDtsDbCompareRecordNames);
/*_DtDtsDbPrintRecords(dc, stdout);*/
_DtSvcProcessUnlock();
}
static void
add_if_missing(DtDtsDbRecord *rec_ptr, XrmQuark name, char *value)
{
DtDtsDbField *fld_ptr;
int fld;
int found = 0;
for(fld = 0; fld < rec_ptr->fieldCount; fld++)
{
fld_ptr = rec_ptr->fieldList[fld];
if(name == fld_ptr->fieldName)
{
found = 1;
break;
}
}
if(found)
{
return;
}
fld_ptr = _DtDtsDbAddField(rec_ptr);
fld_ptr->fieldName = name;
fld_ptr->fieldValue = value;
_DtDtsDbFieldSort(rec_ptr, 0);
return;
}
static void
_DtMMAddActionsToDataAttribute(DtDtsDbDatabase *db_ptr)
{
int rec;
DtDtsDbRecord *rec_ptr;
int action_flag = 0;
int sort_flag = 0;
int found_flag = 0;
int n;
const char *tmp;
XrmQuark desc_qrk = XrmStringToQuark(DtDTS_DA_DESCRIPTION);
XrmQuark icon_qrk = XrmStringToQuark(DtDTS_DA_ICON);
XrmQuark label_qrk = XrmStringToQuark(DtDTS_DA_LABEL);
for(rec = 0; rec < db_ptr->recordCount; rec++)
{
int found_des = 0;
int found_icon = 0;
int found_label = 0;
char *obj_type;
rec_ptr = db_ptr->recordList[rec];
obj_type = XrmQuarkToString(rec_ptr->recordName);
if ( _DtDtsDbGetFieldByName(rec_ptr,
DtDTS_DA_IS_ACTION) == 0 )
{
continue;
}
add_if_missing(rec_ptr, desc_qrk,
DtActionDescription(obj_type));
add_if_missing(rec_ptr, icon_qrk, DtActionIcon(obj_type));
add_if_missing(rec_ptr, label_qrk, DtActionLabel(obj_type));
}
}
static int
build_new_db(DtShmProtoStrtab shm_handle, DtShmProtoIntList int_handle, int num_db, DtDtsDbDatabase **db_list)
{
DtDtsMMDatabase *new_db_list;
int db;
DtDtsDbDatabase *db_ptr;
DtDtsMMDatabase *new_db_ptr;
int rec;
DtDtsDbRecord *rec_ptr;
DtDtsMMRecord *new_rec_ptr;
DtDtsMMRecord *new_rec_ptr_list;
int fld;
DtDtsDbField *fld_ptr;
DtDtsMMField *new_fld_ptr;
DtDtsMMField *new_fld_ptr_list;
int index;
int db_index;
int isnew;
char *tmp;
/* create a space to hold the list of database structures */
new_db_list = (DtDtsMMDatabase *)_DtShmProtoAddIntLst(int_handle,
num_db*sizeof(DtDtsMMDatabase)/sizeof(int),
&db_index);
for(db = 0; db < num_db; db++)
{
int last_boson = -1;
int list_count = 0;
DtShmProtoInttab nameIndex;
int size;
int *idx;
new_db_ptr = &new_db_list[db];
db_ptr = db_list[db];
new_db_ptr->databaseName = _DtShmProtoAddStrtab(shm_handle, db_ptr->databaseName, &isnew);
new_db_ptr->recordCount = db_ptr->recordCount;
/* create space to hold record list */
new_rec_ptr_list = (DtDtsMMRecord *)_DtShmProtoAddIntLst(int_handle,
db_ptr->recordCount*sizeof(DtDtsMMRecord)/sizeof(int),
&index);
new_db_ptr->recordList = index;
/* create index to names list */
nameIndex = _DtShmProtoInitInttab(db_ptr->recordCount);
for(rec = 0; rec < db_ptr->recordCount; rec++)
{
new_rec_ptr = &new_rec_ptr_list[rec];
rec_ptr = db_ptr->recordList[rec];
new_rec_ptr->recordName = QtB(rec_ptr->recordName);
if(new_rec_ptr->recordName != last_boson)
{
/* save name position */
_DtShmProtoAddInttab(nameIndex, new_rec_ptr->recordName, rec);
last_boson = new_rec_ptr->recordName;
}
new_rec_ptr->pathId = _DtShmProtoAddStrtab(shm_handle,
tmp = _DtDbPathIdToString(rec_ptr->pathId),
&isnew);
XtFree(tmp);
new_rec_ptr->seq = rec_ptr->seq;
new_rec_ptr->fieldCount = rec_ptr->fieldCount;
/* create space for field list */
new_fld_ptr_list = (DtDtsMMField *)_DtShmProtoAddIntLst(int_handle,
rec_ptr->fieldCount*sizeof(DtDtsMMField)/sizeof(int),
&index);
new_rec_ptr->fieldList = index;
for(fld = 0; fld < rec_ptr->fieldCount; fld++)
{
new_fld_ptr = &new_fld_ptr_list[fld];
fld_ptr = rec_ptr->fieldList[fld];
new_fld_ptr->fieldName = QtB(fld_ptr->fieldName);
new_fld_ptr->fieldValue = fld_ptr->fieldValue?_DtShmProtoAddStrtab(shm_handle,
fld_ptr->fieldValue, &isnew):0;
}
}
/* create table for index and save it */
size = _DtShmProtoSizeInttab(nameIndex);
idx = _DtShmProtoAddIntLst(int_handle, size/sizeof(int), &new_db_ptr->nameIndex);
_DtShmProtoCopyInttab(nameIndex, (void *)idx);
_DtShmProtoDestroyInttab(nameIndex);
}
return(db_index);
}
struct list
{
DtShmBoson boson;
int rec;
};
static int
srch(const void *a, const void *b)
{
int results = ((struct list *)a)->boson - ((struct list *)b)->boson;
if(results == 0)
{
results = ((struct list *)a)->rec - ((struct list *)b)->rec;
}
return(results);
}
static void
showtable(
DtDtsDbDatabase *db,
struct list *name_index,
struct list *other,
DtDtsMMHeader *head,
int other_break)
{
int i;
printf("============== names =====================\n");
for(i = 0; name_index[i].boson; i++)
{
printf("%20s -> %s\n",
XrmQuarkToString(db->recordList[name_index[i].rec]->recordName),
_DtShmProtoLookUpStrtab(shm_handle,
name_index[i].boson));
}
printf("%d entries\n", i);
printf("============= other ======================\n");
for(i = 0; i < other_break; i++)
{
printf("%s\n",
XrmQuarkToString(db->recordList[other[i].rec]->recordName));
}
printf("%d entries\n", i);
}
static int
build_name_list(DtDtsDbDatabase *db,
DtShmProtoIntList int_handle,
DtDtsMMHeader *head)
{
struct list *other;
int i;
char *c;
int isnew;
struct list *name_index;
int next = 0;
int other_break = 0;
DtShmProtoInttab indexList = 0;
DtShmBoson last_boson = -1;
int *list_of_recs = 0;
int list_count = 0;
int index = 0;
int size;
void *space;
/* create tmp space for two lists */
name_index = (struct list *)calloc(db->recordCount*2,
sizeof(struct list));
other = (struct list *)calloc(db->recordCount, sizeof(struct list));
/* step through all records */
for(i = 0; i < db->recordCount; i++)
{
DtShmBoson boson;
char *attr;
char *t;
/* see if a name pattern exist */
attr = _DtDtsDbGetFieldByName(db->recordList[i],
DtDTS_NAME_PATTERN);
if(!attr)
{
/* it didn't so check path pattern */
attr = _DtDtsDbGetFieldByName(db->recordList[i],
DtDTS_PATH_PATTERN);
if(!attr)
{
/* neither exist so save it as plain buffer */
if(!head->buffer_start_index)
{
head->buffer_start_index = other_break;
}
other[other_break++].rec = i;
continue; /* go to next record */
}
}
/* we have a name now find its final component */
c = strrchr(attr, '/');
if(c)
{
c++;
}
if(!c)
{
c = attr;
}
else
{
attr = c;
}
/* now see if that final component has any *,?,[ */
while(c && *c &&
!(*c == '*' ||
*c == '[' ||
*c == '?' ||
*c == '$' ))
{
c++;
}
if(c && *c == '\0')
{
/* it doesn't so save it in the name index */
name_index[next].boson =
_DtShmProtoAddStrtab(shm_handle,
(const char *)attr, &isnew);
name_index[next++].rec = i;
continue; /* next record */
}
/* the name had something in it now lets get the suffix */
c = strrchr(attr, '.');
attr = c;
/* lets see if the suffix has any *,?,[ */
while(c && *c &&
!(*c == '*' ||
*c == '[' ||
*c == '?' ||
*c == '$' ))
{
c++;
}
if(c && *c == '\0')
{
/* it doesn't so save it in the name index */
name_index[next].boson =
_DtShmProtoAddStrtab(shm_handle,
(const char *)attr, &isnew);
name_index[next++].rec = i;
}
else
{
/* couldn't find any thing so save it as other */
other[other_break++].rec = i;
}
}
if (next > 0)
{
qsort(name_index, next, sizeof(struct list), srch);
}
/*
showtable(db, name_index, other, head, other_break);
printf(" next = %d\n", next);
printf(" other_break = %d\n", other_break);
printf("head->buffer_start_index = %d\n", head->buffer_start_index);
*/
/* create a table and add the records to it. However
duplicates need to be in separate lists.
*/
indexList = _DtShmProtoInitInttab(next+3);
for(i = 0; i <= next; i++)
{
if(i != next && (last_boson == -1 || name_index[i].boson == last_boson))
{
/* this a new list of records or an addition to one */
list_of_recs = (int *)realloc(list_of_recs,
++list_count*sizeof(int));
last_boson = name_index[i].boson;
list_of_recs[list_count-1] = name_index[i].rec;
}
else
{
/* we reached the end of a list now we check how many
are in the list.
*/
if(list_count == 1)
{
/* if just one just add it in the index */
_DtShmProtoAddInttab(indexList,
last_boson, list_of_recs[0]);
}
else
{
/* if there are multiple items in the list
create a table for them */
int *list = _DtShmProtoAddIntLst(int_handle,
list_count, &index);
/* write the list to the to the table */
memcpy(list, list_of_recs,
list_count*sizeof(int));
/* then index on the negative of the boson
so that we know it is a list */
_DtShmProtoAddInttab(indexList,
last_boson, -index);
list_count = 0;
list_of_recs = (int *)realloc(list_of_recs,
++list_count*sizeof(int));
}
if ( i != next )
{
/* reset for the next set */
last_boson = name_index[i].boson;
list_of_recs[list_count-1] = name_index[i].rec;
}
}
}
/* same thing but they all go into a separate list */
if(other_break > 0)
{
/* create the space */
int *list = _DtShmProtoAddIntLst(int_handle,
other_break, &head->no_name_offset);
/* copy it into the list */
for(i = 0; i < other_break; i++)
{
list[i] = other[i].rec;
}
}
else
{
head->no_name_offset = -1;
}
/* make the real space */
size = _DtShmProtoSizeInttab(indexList);
space = _DtShmProtoAddIntLst(int_handle, size/sizeof(int),
&head->name_list_offset);
_DtShmProtoCopyInttab(indexList, space);
_DtShmProtoDestroyInttab(indexList);
if(name_index)free(name_index);
if(list_of_recs)free(list_of_recs);
if(other)free(other);
return(index);
}
static int
write_db(DtDtsMMHeader *header, void *index, int size, const char *CacheFile)
{
int fd;
mode_t cmask = umask((mode_t)077);
char *tmpfile;
/* tempnam(3) is affected by the TMPDIR environment variable. */
/* This creates problems for rename() is "tmpfile" and "cacheFile" */
/* are on different file systems. Use tmpnam(3) to create the */
/* unique file name instead. */
char tmpnam_buf[L_tmpnam + 1];
tmpfile = (char *)malloc(sizeof(_DTDTSMMTEMPDIR) +
sizeof(_DTDTSMMTEMPFILE) + L_tmpnam + 3);
tmpnam(tmpnam_buf);
sprintf(tmpfile, "%s/%s%s", _DTDTSMMTEMPDIR, _DTDTSMMTEMPFILE,
basename(tmpnam_buf));
fd = open(tmpfile, O_RDWR|O_CREAT, 0600);
umask(cmask);
if(fd == -1)
{
_DtSimpleError(
DtProgName, DtError, NULL,
(char*) tmpfile, NULL);
return(0);
}
/* Remove file on write failure - we don't */
/* want a partial dtdbcache file. */
if ((write(fd, header, sizeof(DtDtsMMHeader))
!= sizeof(DtDtsMMHeader)) ||
(write(fd, index, size) != size))
{
close(fd);
unlink(tmpfile);
free(tmpfile);
return(0);
}
close(fd);
if(rename((const char *)tmpfile, CacheFile) == -1)
{
_DtSimpleError(
DtProgName, DtError, NULL,
(char*) CacheFile, NULL);
unlink(CacheFile); /* Just in case? */
unlink(tmpfile);
free(tmpfile);
return(0);
}
free(tmpfile);
return(1);
}
_DtActionCompareRecordBoson(
DtDtsMMRecord *record1,
DtDtsMMRecord *record2 )
{
int results = (int)record1->recordName - (int)record2->recordName;
if (results)
return(results);
return((int)record1 - (int)record2);
}

View File

@@ -0,0 +1,92 @@
/************************************<+>*************************************
****************************************************************************
**
** File: Qualify.c
**
** RCS: $XConsortium: Qualify.c /main/3 1995/10/26 15:09:47 rswiston $
**
** Project: DT
**
** Description: Fully qualify a file with the first path found
** in a list of colon-separated paths
**
** (c) Copyright 1993 by Hewlett-Packard Company
**
****************************************************************************
************************************<+>*************************************/
#include <stdio.h>
#include <string.h>
/*********************************************************************
* _DtQualifyWithFirst
*
* takes: an unqualified filename like foo.txt, and
* a colon-separated list of pathnames, such as
* /etc/dt:/usr/dt/config
*
* returns: a fully qualified filename. Space for the filename
* has been allocated off the heap using malloc. It is
* the responsibility of the calling function to dispose
* of the space using free.
*
* example: ...
* char * filename;
* ...
* filename = _DtQualifyWithFirst("configFile",
* "/foo/first/location:/foo/second/choice");
* < use filename >
* free(filename);
*
**********************************************************************/
char * _DtQualifyWithFirst
(
char * filename,
char * searchPath
)
{
char * paths = searchPath;
char * path;
char * chance;
FILE * f;
/* assert that the arguments cannot be NULL and cannot be empty */
if (filename == NULL || searchPath == NULL ||
filename[0] == 0 || searchPath[0] == 0)
return NULL;
while (1) {
/* if there is a :, zero it */
if ((path = strchr(paths, ':')) != NULL)
*path = 0;
/* allocate space and create the qualified filename */
chance = (char *)malloc(strlen(paths) + strlen(filename) + 2);
if (filename[0] == '/')
sprintf(chance,"%s%s",paths,filename);
else
sprintf(chance,"%s/%s",paths,filename);
/* see if it is there by opening it for reading */
if (f = fopen(chance,"r")) {
fclose(f); /* it's there so close it, .... */
if (path) /* ... restore the colon, .... */
*path = ':';
return chance; /* return the fully qualified filename */
}
free(chance);
if (path == NULL) /* reached the end of the list of paths */
break;
*path = ':'; /* restore the colon */
paths = path + 1; /* try the next path */
}
return NULL;
}

View File

@@ -0,0 +1,56 @@
/*****************************************************************************
*
* File: Qualify.h
* RCS: $XConsortium: Qualify.h /main/3 1995/10/26 15:10:03 rswiston $
* Description: Public header file for the Qualify routine
* Project: DT Runtime Library
* Language: C
* Package: N/A
*
* (c) Copyright 1993 by Hewlett-Packard Company
*
*****************************************************************************/
/*********************************************************************
* _DtQualifyWithFirst
*
* takes: an unqualified filename like foo.txt, and
* a colon-separated list of pathnames, such as
* /etc/dt:/usr/dt/config
*
* returns: a fully qualified filename. Space for the filename
* has been allocated off the heap using malloc. It is
* the responsibility of the calling function to dispose
* of the space using free.
*
* example: ...
* char * filename;
* ...
* filename = _DtQualifyWithFirst("configFile",
* "/foo/first/location:/foo/second/choice");
* < use filename >
* free(filename);
*
**********************************************************************/
#ifndef _Dt_Qualify_h
#define _Dt_Qualify_h
# ifdef __cplusplus
extern "C" {
# endif
extern char * _DtQualifyWithFirst
(
char *, /* file to locate */
char * /* list of colon-separated paths in which to look */
);
# ifdef __cplusplus
}
# endif
#endif /* _Dt_Qualify_h */
/* DON'T ADD ANYTHING AFTER THIS #endif */

View File

@@ -0,0 +1,515 @@
/* $XConsortium: Saver.c /main/8 1996/11/21 19:56:41 drk $ */
/* *
* (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. *
*/
/*************************************<+>*************************************
*****************************************************************************
**
** File: Saver.c
**
** Description:
** -----------
** This file contains public and private screen saver utilities.
**
** Public:
** DtSaverGetWindows() - return array of windows on which saver can draw
**
** Private:
** _DtSaverStart() - launch specified screen saver
** _DtSaverStop() - kill specified screen saver
**
*****************************************************************************
*************************************<+>*************************************/
#include <stdio.h>
#include <stdlib.h>
#define X_INCLUDE_STRING_H
#define XOS_USE_XT_LOCKING
#include <X11/Xos_r.h>
#include <X11/Intrinsic.h>
#include <Saver.h>
#include <SaverP.h>
#include "DtSvcLock.h"
/*
* Constants global to this file.
*/
#define DT_SAVER_MAX_SCREENS 10
struct saver_state {
unsigned short serial;
Window xid;
struct saver_state *next;
};
static Atom xa_saver_register;
static struct saver_state saver_list = {0, (Window)0, NULL};
/*
* Local functions.
*/
static void RegisterSaverCB(
Widget w,
XtPointer client_data,
XEvent *event,
Boolean *continue_to_dispatch
);
/*************************************<->*************************************
*
* _DtSaverStart() - start a screen saver
*
* Description:
* -----------
* _DtSaverStart() is one of a suite of screen saver API's used in the
* desktop. These APIs are:
*
* _DtSaverStart() starts a screen saver (private)
* _DtSaverStop() stops a screen saver (private)
* DtSaverGetWindows() return array of windows on which saver can draw
*
* The _DtSaverStart() API allocates a state variable for the screen saver
* which contains a serial number and NIL window ID. A list of these state
* variables is maintained, one for each call to _DtSaverStart().
* DtSaverStart() then sets up the DTSAVERINFO environment variable containing
* the serial number, window count and window list provided. Finally, it
* launches the provided action and returns an opaque pointer to the state
* variable. The action is expected to be a screen saver which makes use
* of the DtSaverGetWindows() API.
*
* When the screen saver starts, it calls the DtSaverGetWindows() API. From
* the screen saver perspective, the API returns an array of windows on which
* the screen saver can draw. To to this, the API obtains the DTSAVERINFO
* environment variable, and parses out the window array. The API also
* creates a window and sends a ClientMessage to the first DTSAVERINFO window
* containing the serial number and newly created window id.
*
* RegisterSaverCB() is a callback called when the ClientMessage arrives from
* a screen saver. This callback first searches the screen saver state list
* by serial number. If a state variable is not found, RegisterSaverCB()
* assumes the screen saver must have been stopped by a call to
* _DtSaverStop(), so kills the client via XKillClient() using the window id
* provided in the message. If the state variable is located,
* RegisterSaverCB() stores the window id in the state variable.
*
* _DtSaverStop() searches the screen saver list using the serial number
* provided in the input state variable. It should always be found. When
* found, if the state variable window id is set, _DtSaverStop() kills the
* screen saver client via XKillClient(), deletes the state variable from
* the list and deallocates the state variable.
*
* Inputs:
* ------
* display - display structure
* drawArea - array of widgets to be stored drawn upon by saver
* count - number of elements in drawArea array
* saverAction - screen saver action name to invoke
* wAction - widget on which possible DtActionInvoke() errors should display
*
* Outputs:
* -------
*
* Return:
* -------
* state - pointer to opaque state structure
*
* Comments:
* --------
* This function uses DtActionInvoke() to launch an action. As a result,
* the caller is responsible for loading and maintaining the action database
* using the DtDbLoad() function and procedures. The caller
* must call _DtSaverStop() to terminate screen saver
*
*************************************<->***********************************/
void *
_DtSaverStart(
Display *display,
Widget *drawArea,
int count,
char *saverAction,
Widget wAction)
{
static char envdata[(DT_SAVER_MAX_SCREENS * 12) + 20];
struct saver_state *state;
struct saver_state *p;
int i;
_DtSvcProcessLock();
/*
* If first time in, insert envdata in process environment.
*/
if (saver_list.serial == 0)
{
putenv(envdata);
envdata[0] = '\0';
xa_saver_register = XInternAtom(display, "_DT_SAVER_REGISTER", False);
}
/*
* Add event handler (it might already be there - that's ok).
*/
XtAddEventHandler(drawArea[0], 0, True, RegisterSaverCB, NULL);
/*
* Allocate state structure for this saver.
*/
if (!(state = (struct saver_state *)malloc(sizeof(struct saver_state))))
{
_DtSvcProcessUnlock();
return(NULL);
}
/*
* Initialize state structure and append to saver_list.
*/
state->serial = saver_list.serial++;
state->xid = (Window)0;
state->next = NULL;
p = &saver_list;
while (p->next != NULL)
{
p = p->next;
}
p->next = state;
/*
* Set up environment. It will look like:
* DTSAVERINFO="<serial> <count> <win0> <win1> ... <winN>"
*/
sprintf(envdata, "DTSAVERINFO=%u %i %lx",
state->serial, count, XtWindow(drawArea[0]));
for (i = 1; i < count; i++)
{
char *pe = envdata + strlen(envdata);
sprintf(pe, " %lx", XtWindow(drawArea[i]));
}
_DtSvcProcessUnlock();
/*
* Launch saver.
*/
DtActionInvoke(wAction, saverAction, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL);
/*
* Return array as state information.
*/
return((void *)state);
}
/*************************************<->*************************************
*
* _DtSaverStop() - stop a screen saver
*
* Description:
* -----------
* Stop an external screen saver started with DtStartSaver().
*
* _DtSaverStop() searches the screen saver list using the serial number
* provided in the input state variable. It should always be found. When
* found, if the state variable window id is set, _DtSaverStop() kills the
* screen saver client via XKillClient(), deletes the state variable from
* the list and deallocates the state variable.
*
* Inputs:
* ------
* display - display structure
* state - state returned from _DtSaverStart()
*
* Outputs:
* -------
*
* Return:
* -------
*
* Comments:
* --------
*
*************************************<->***********************************/
void
_DtSaverStop(
Display *display,
void *pstate)
{
struct saver_state *state = (struct saver_state *)pstate;
struct saver_state *p;
_DtSvcProcessLock();
/*
* Unlink from saver_list.
*/
p = &saver_list;
while (p->next != state)
{
p = p->next;
}
p->next = state->next;
_DtSvcProcessUnlock();
/*
* Kill client using window id provided by RegisterSaverCB().
*/
if (state->xid != (Window)0)
{
XKillClient(display, state->xid);
}
/*
* Free state allocated by _DtSaverStart();
*/
free(pstate);
}
/*************************************<->*************************************
*
* DtSaverGetWindows() - return array of windows on which saver can draw
*
* Description:
* -----------
*
* This is a PUBLIC API.
*
* When the screen saver starts, it calls the DtSaverGetWindows() API. From
* the screen saver perspective, the API returns an array of windows on which
* the screen saver can draw. To to this, the API obtains the DTSAVERINFO
* environment variable, and parses out the window array. The API also
* creates a window and sends a ClientMessage to the first DTSAVERINFO window
* containing the serial number and newly created window id.
*
* Inputs:
* ------
* display - display structure
* window - pointer to memory in which to place pointer to array
* count - pointer to memory in which to place count
*
* Outputs:
* -------
* *window - pointer to array
* *count - count
*
* Return:
* -------
* True - window list returned
* False - window list not returned
*
* Comments:
* --------
* The array memory should be freed by the caller via free().
*
*************************************<->***********************************/
Boolean
DtSaverGetWindows(
Display *display,
Window **window,
int *count)
{
char *envdata, *p, *q;
unsigned short serial;
int envcount;
XClientMessageEvent event;
Window xid_window;
_Xstrtokparams strtok_buf;
_DtSvcDisplayToAppContext(display);
_DtSvcAppLock(app);
*window = NULL;
*count = 0;
_DtSvcProcessLock();
xa_saver_register = XInternAtom(display, "_DT_SAVER_REGISTER", False);
/*
* Get invocation information from environment.
*/
envdata = getenv("DTSAVERINFO");
if (!envdata)
{
_DtSvcProcessUnlock();
_DtSvcAppUnlock(app);
return(False);
}
/*
* Copy string for later strtok() use.
*/
p = strdup(envdata);
if (!p)
{
_DtSvcProcessUnlock();
_DtSvcAppUnlock(app);
return(False);
}
/*
* Extract serial.
*/
q = _XStrtok(p, " ", strtok_buf);
serial = (unsigned short)strtoul(q, NULL, 10);
/*
* Extract envcount.
*/
q = _XStrtok(NULL, " ", strtok_buf);
envcount = (int)strtoul(q, NULL, 10);
/*
* Allocate memory for window array.
*/
*window = (Window *)malloc((envcount)*sizeof(Window *));
if (!*window)
{
free(p);
_DtSvcProcessUnlock();
_DtSvcAppUnlock(app);
return(False);
}
/*
* Populate result array and envcount.
*/
for (*count = 0; *count < envcount; (*count)++)
{
q = _XStrtok(NULL, " ", strtok_buf);
(*window)[*count] = (Window)strtoul(q, NULL, 16);
}
/*
* Free temp copy of envdata.
*/
free(p);
/*
* Create dummy window to obtain XID.
*/
xid_window = XCreateWindow(display, DefaultRootWindow(display),
0, 0, 1, 1, 0,
CopyFromParent, InputOutput, CopyFromParent,
0, NULL);
if (xid_window == (Window)0)
{
/*
* Could not create dummy window.
*/
free((char *)*window);
*window = NULL;
*count = 0;
_DtSvcProcessUnlock();
_DtSvcAppUnlock(app);
return(False);
}
/*
* Send client message to win0 to register.
*/
event.type = ClientMessage;
event.window = (*window)[0];
event.message_type = xa_saver_register;
event.format = 32;
event.data.l[0] = (Atom)0;
event.data.l[1] = (long)serial;
event.data.l[2] = (long)xid_window;
event.data.l[3] = CurrentTime;
XSendEvent(display, (*window)[0], False, NoEventMask,
(XEvent *) &event);
_DtSvcProcessUnlock();
/*
* Ensure window creation and client message have been processed by
* the server before continuing.
*/
XSync(display, False);
_DtSvcAppUnlock(app);
return(True);
}
/*************************************<->*************************************
*
* RegisterSaverCB() - register a screen saver
*
* Description:
* -----------
* RegisterSaverCB() is a callback called when the ClientMessage arrives from
* a screen saver. This callback first searches the screen saver state list
* by serial number. If a state variable is not found, RegisterSaverCB()
* assumes the screen saver must have been stopped by a call to
* _DtSaverStop(), so kills the client via XKillClient() using the window id
* provided in the message. If the state variable is located,
* RegisterSaverCB() stores the window id in the state variable.
*
* Inputs:
* ------
* w - widget from which we derive the display
* client_data - pointer to client data (unused)
* event - ClientMessage event structure
* continue_to_dispatch - dispatch to remaining event handlers (unused)
*
* Outputs:
* -------
*
* Return:
* -------
*
* Comments:
* --------
*
*************************************<->***********************************/
static void
RegisterSaverCB(
Widget w,
XtPointer client_data,
XEvent *event,
Boolean *continue_to_dispatch)
{
if (event->type == ClientMessage)
{
XClientMessageEvent *cEvent = (XClientMessageEvent *) event;
_DtSvcProcessLock();
if (cEvent->message_type == xa_saver_register)
{
unsigned short serial = (unsigned short)cEvent->data.l[1];
Window win = (Window)cEvent->data.l[2];
struct saver_state *state;
/*
* Find event in saver list.
*/
state = saver_list.next;
while (state != NULL && state->serial != serial)
{
state = state->next;
}
if (state != NULL)
{
/*
* _DtSaverStop() not yet called for this saver. Store xid in
* saver's state for _DtSaverStop()'s use.
*/
state->xid = win;
}
else
{
/*
* _DtSaverStop() has already been called for this saver, but at the
* time, the saver had not yet registered. Kill the saver client.
*/
XKillClient(XtDisplay(w), win);
}
}
_DtSvcProcessUnlock();
}
}

View File

@@ -0,0 +1,30 @@
/* $XConsortium: Saver.h /main/3 1995/10/26 15:10:29 rswiston $ */
/*
* (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 _dtsaver_h
#define _dtsaver_h
#ifdef __cplusplus
extern "C" {
#endif
/*
* Functions
*/
extern Boolean DtSaverGetWindows(
Display *display,
Window **window,
int *count);
#ifdef __cplusplus
} /* Close scope of 'extern "C"' declaration which encloses file. */
#endif
#endif /*_dtsaver_h*/
/* DON'T ADD ANYTHING AFTER THIS #endif */

View File

@@ -0,0 +1,90 @@
/* $XConsortium: SaverP.h /main/4 1995/10/26 15:10:42 rswiston $ */
/* *
* (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. *
*/
/************************************<+>*************************************
****************************************************************************
**
** File: Saver.h
**
** Description
** -----------
** Variables and declarations needed for
** managing external screen savers
**
****************************************************************************
************************************<+>*************************************/
#ifndef _dtsaverp_h
#define _dtsaverp_h
/*************************************<->*************************************
*
* _DtSaverStart()
*
*
* Description:
* -----------
* Store provided array of windows on root window property
* _DT_SAVER_WINDOWS and launch specified screen saver. Screen savers
* will attempt to use these windows as drawables.
*
* Inputs:
* ------
* display - display structure
* drawArea - array of widgets to be drawn upon by screen saver
* count - number of elements in drawArea array
* saverAction - screen saver action to invoke
* wAction - action UI widget
*
* Outputs:
* -------
*
* Return:
* -------
* state - pointer to opaque state structure
*
* Comments:
* --------
* This function uses _DtActionInvoke() to launch an action. As a result,
* the caller is responsible for loading and maintaining the action database
* using the DtDbLoad() function and procedures. The caller
* must call _DtSaverStop() to terminate screen saver
*
*************************************<->***********************************/
extern void * _DtSaverStart(Display *, Widget *, int, char *, Widget);
/*************************************<->*************************************
*
* _DtSaverStop()
*
*
* Description:
* -----------
* Stop an external screen saver started with DtStartSaver(). Deletes
* _DT_SAVER_WINDOWS property from root window.
*
* Inputs:
* ------
* display - display structure
* state - state returned from _DtSaverStart()
*
* Outputs:
* -------
*
* Return:
* -------
*
* Comments:
* --------
*
*************************************<->***********************************/
extern void _DtSaverStop(Display *, void *);
#endif /*_dtsaverp_h*/
/* DON'T ADD ANYTHING AFTER THIS #endif */

View File

@@ -0,0 +1,37 @@
/* $XConsortium: Session.h /main/3 1995/10/26 15:10:56 rswiston $ */
/*
* (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 _Dt_Session_h
#define _Dt_Session_h
#include <X11/Intrinsic.h>
#ifdef __cplusplus
extern "C" {
#endif
/*
* Functions
*/
extern Boolean DtSessionSavePath(
Widget widget,
char **save_path,
char **save_file);
extern Boolean DtSessionRestorePath(
Widget widget,
char **restore_path,
char *restore_file);
#ifdef __cplusplus
}
#endif
#endif /* _Dt_Session_h */

View File

@@ -0,0 +1,228 @@
/* $TOG: SessionM.h /main/8 1998/07/30 12:10:49 mgreess $ */
/*
* (c) Copyright 1996 Digital Equipment Corporation.
* (c) Copyright 1993, 1994, 1996 Hewlett-Packard Company
* (c) Copyright 1993, 1994, 1996 International Business Machines Corp.
* (c) Copyright 1993, 1994, 1996 Sun Microsystems, Inc.
* (c) Copyright 1993, 1994, 1996 Novell, Inc.
* (c) Copyright 1996 FUJITSU LIMITED.
* (c) Copyright 1996 Hitachi.
*/
/*************************************<+>*************************************
*****************************************************************************
**
** File: SessionM.h
**
** Description:
** -----------
** Contains all variables needed for SM messaging. All messages serviced,
** and the tool class name for the session manager
**
**
**
*******************************************************************
** (c) Copyright Hewlett-Packard Company, 1990. All rights are
** reserved. Copying or other reproduction of this program
** except for archival purposes is prohibited without prior
** written consent of Hewlett-Packard Company.
********************************************************************
**
**
*****************************************************************************
*************************************<+>*************************************/
#ifndef _SessionM_h
#define _SessionM_h
/*
* Include files
*/
/* If <X11/Intrinsic.h> is included along with this file, <X11/Intrinsic.h>
MUST be included first due to "typedef Boolean ..." problems. The following
conditional #define is also part of the solution to this problem. */
#include <X11/X.h>
#include <X11/Intrinsic.h>
/*
* Tool class for the session manager
*/
#define DtSM_TOOL_CLASS "SESSIONMGR"
/*
* SM_STARTUP_CHANGE an SM_STATE parameters
*/
#define DtSM_VERBOSE_MODE 1
#define DtSM_QUIET_MODE 2
#define DtSM_ASK_STATE 0
#define DtSM_HOME_STATE 3
#define DtSM_CURRENT_STATE 4
/*
* Atoms for session manager/style manager communication
*/
#define _XA_DT_SM_STM_PROTOCOL "_DT_SM_STM_PROTOCOL"
#define _XA_DT_SM_SAVE_TO_HOME "_DT_SM_SAVE_TO_HOME"
#define _XA_DT_SM_STATE_CHANGE "_DT_SM_STATE_CHANGE"
#define _XA_DT_SM_RESTORE_DEFAULT "_DT_SM_RESTORE_DEFAULT"
#define _XA_DT_SM_PREFERENCES "_DT_SM_PREFERENCES"
/*
* Atoms for lock changes
*/
#define _XA_DT_SM_LOCK_CHANGE "_DT_SM_LOCK_CHANGE"
#define CoverScreenMask (1L<<0)
#define LockOnTimeoutMask (1L<<1)
/*
* Parameters to be sent into session manager
*/
/*
* Atoms for communicating configuration changes and state
*/
/*
* Defines needed for getting/setting the sm window property on the root
*/
#define PROP_DT_SM_WINDOW_INFO_ELEMENTS 2
#define _XA_DT_SM_WINDOW_INFO "_DT_SM_WINDOW_INFO"
/*
* Defines needed for getting the session manager state off it's window
*/
#define PROP_DT_SM_STATE_INFO_ELEMENTS 13
#define _XA_DT_SM_STATE_INFO "_DT_SM_STATE_INFO"
/*
* Defines needed for the screen saver list property.
*/
#define _XA_DT_SM_SAVER_INFO "_DT_SM_SAVER_INFO"
/*
* Defines needed for the screen saver property
*/
#define PROP_DT_SM_SCREEN_INFO_ELEMENTS 5
#define _XA_DT_SM_SCREEN_INFO "_DT_SM_SCREEN_INFO"
/*
* Defines needed for the audio property
*/
#define PROP_DT_SM_AUDIO_INFO_ELEMENTS 4
#define _XA_DT_SM_AUDIO_INFO "_DT_SM_AUDIO_INFO"
/*
* Defines needed for the keyboard property
*/
#define PROP_DT_SM_KEYBOARD_INFO_ELEMENTS 3
#define _XA_DT_SM_KEYBOARD_INFO "_DT_SM_KEYBOARD_INFO"
/*
* Define needed for the font info property
*/
#define _XA_DT_SM_FONT_INFO "_DT_SM_FONT_INFO"
/*
* Define needed for the font info property
*/
#define _XA_DT_SM_POINTER_INFO "_DT_SM_POINTER_INFO"
/*
* Define needed for the preeditType info property
*/
#define _XA_DT_SM_PREEDIT_INFO "_DT_SM_PREEDIT_INFO"
/* bit definitions for SmStateInfo.flags */
#define SM_STATE_NONE 0
#define SM_STATE_START (1L << 0)
#define SM_STATE_CONFIRM (1L << 1)
#define SM_STATE_COMPAT (1L << 2)
#define SM_STATE_SEND (1L << 3)
#define SM_STATE_COVER (1L << 4) /* Obsolete */
#define SM_STATE_LOTOUT (1L << 5) /* Obsolete */
#define SM_STATE_LOTOUTSTAT (1L << 6)
#define SM_STATE_CYCLETIMEOUT (1L << 7)
#define SM_STATE_LOCKTIMEOUT (1L << 8)
#define SM_STATE_SAVERTIMEOUT (1L << 9)
#define SM_STATE_RANDOM (1L << 10)
#define SM_STATE_DISP_SESSION (1L << 11)
#define SM_STATE_ALL (SM_STATE_START | SM_STATE_CONFIRM |\
SM_STATE_COMPAT | SM_STATE_SEND |\
SM_STATE_COVER | SM_STATE_LOTOUT |\
SM_STATE_LOTOUTSTAT | SM_STATE_CYCLETIMEOUT |\
SM_STATE_LOCKTIMEOUT | SM_STATE_SAVERTIMEOUT |\
SM_STATE_RANDOM | SM_STATE_DISP_SESSION)
/*
* typedef statements for structures to be returned
*/
typedef struct
{
int flags;
int smStartState;
int smConfirmMode;
Boolean smCompatMode;
Boolean smSendSettings;
Boolean smCoverScreen; /* Obsolete */
Boolean smLockOnTimeout; /* Obsolete */
Boolean smLockOnTimeoutStatus;
int smCycleTimeout;
int smLockTimeout;
int smSaverTimeout;
Boolean smRandom;
Boolean smDisplaySpecific; /* If True, the currently running
session is for a specific display */
} SmStateInfo;
typedef struct
{
char *saverList;
} SmSaverInfo;
typedef struct
{
int flags;
int smTimeout;
int smInterval;
int smPreferBlank;
int smAllowExp;
} SmScreenInfo;
typedef struct
{
int flags;
int smBellPercent;
unsigned int smBellPitch;
unsigned int smBellDuration;
} SmAudioInfo;
typedef struct
{
int flags;
int smKeyClickPercent;
int smGlobalAutoRepeat;
} SmKeyboardInfo;
/*
* Function definitions
*/
extern Status _DtGetSmWindow(Display *, Window, Window *) ;
extern Status _DtGetSmState(Display *, Window, SmStateInfo *);
extern Status _DtSetSmState(Display *, Window, SmStateInfo *);
extern Status _DtGetSmSaver(Display *, Window, SmSaverInfo *);
extern void _DtSetSmSaver(Display *, Window, SmSaverInfo *);
extern Status _DtGetSmScreen(Display *, Window, Atom, SmScreenInfo *);
extern Status _DtGetSmAudio(Display *, Window, Atom, SmAudioInfo *);
extern Status _DtGetSmKeyboard(Display *, Window, Atom, SmKeyboardInfo *);
extern Status _DtGetSmFont(Display *, Window, Atom, char **);
extern Status _DtGetSmPointer(Display *, Window, Atom, char **);
extern Status _DtGetSmPreedit(Display *, Window, Atom, char **);
#endif /* _SessionM_h */

View File

@@ -0,0 +1,108 @@
/* $TOG: SessionP.h /main/5 1998/07/30 12:11:06 mgreess $ */
/* *
* (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. *
*/
/*************************************<+>*************************************
*****************************************************************************
**
** File: SessionP.h
**
** Description: Private header for Session Management routines
** -----------
**
*******************************************************************
** (c) Copyright Hewlett-Packard Company, 1990. All rights are
** reserved. Copying or other reproduction of this program
** except for archival purposes is prohibited without prior
** written consent of Hewlett-Packard Company.
********************************************************************
**
**
**
*****************************************************************************
*************************************<+>*************************************/
#ifndef _SessionP_h
#define _SessionP_h
/*
* include statements
*/
/*
* define statements
*/
/*
* typedef statements
*/
/*
* Definition for the _DT_SM_WINDOW_INFO property.
*/
typedef struct
{
unsigned long flags;
unsigned long smWindow;
} PropDtSmWindowInfo;
/*
* Definition for the _DT_SM_STATE_INFO property
*/
typedef struct
{
unsigned long flags;
unsigned long smStartState;
unsigned long smConfirmMode;
unsigned long smCompatMode;
unsigned long smSendSettings;
unsigned long smCoverScreen;
unsigned long smLockOnTimeout;
unsigned long smLockOnTimeoutStatus;
unsigned long smCycleTimeout;
unsigned long smLockTimeout;
unsigned long smSaverTimeout;
unsigned long smRandom;
unsigned long smDisplaySpecific;
} PropDtSmStateInfo;
/*
* Definition for the _DT_SM_SCREEN_INFO property
*/
typedef struct
{
unsigned long flags;
unsigned long smTimeout;
unsigned long smInterval;
unsigned long smPreferBlank;
unsigned long smAllowExp;
} PropDtSmScreenInfo;
/*
* Definition for the _DT_SM_AUDIO_INFO property
*/
typedef struct
{
unsigned long flags;
unsigned long smBellPercent;
unsigned long smBellPitch;
unsigned long smBellDuration;
} PropDtSmAudioInfo;
/*
* Definition for the _DT_SM_KEYBOARD_INFO property
*/
typedef struct
{
unsigned long flags;
unsigned long smKeyClickPercent;
unsigned long smGlobalAutoRepeat;
} PropDtSmKeyboardInfo;
#endif /* _SessionP_h */
/* Do not add anything after this endif. */

View File

@@ -0,0 +1,95 @@
/*
* (c) Copyright 1993, 1994 International Business Machines Corp. *
* (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
* (c) Copyright 1993, 1994 Novell, Inc. *
*/
/************************************<+>*************************************
****************************************************************************
**
** File: SetVWmHint.c
**
** RCS: $XConsortium: SetVWmHint.c /main/4 1995/10/26 15:11:34 rswiston $
**
** Project: DT Workspace Manager
**
** Description: Set Dt Wm hints.
**
** (c) Copyright 1991, 1993, 1994 by Hewlett-Packard Company
**
****************************************************************************
************************************<+>*************************************/
#include <stdio.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <Dt/Wsm.h>
#include <Dt/WsmP.h>
#include <Xm/Xm.h>
#include <Xm/AtomMgr.h>
/*************************************<->*************************************
*
* _DtWsmSetDtWmHints (display, window, pHints)
*
*
* Description:
* -----------
* Set the contents of the _DT_WM_HINTS property on a window
*
*
* Inputs:
* ------
* display - display
* window - window to set hints on
* pHints - pointer the hints to set
*
* Comments:
* ---------
* No error checking
*
*************************************<->***********************************/
void
_DtWsmSetDtWmHints(
Display *display,
Window window,
DtWmHints *pHints)
{
Atom property;
DtWmHints vh;
property = XmInternAtom (display, _XA_DT_WM_HINTS, False);
/*
* Copy hints to make sure we have one of the right size.
* This is for backward compatibility.
*/
vh.flags = pHints->flags;
if (pHints->flags & DtWM_HINTS_FUNCTIONS) {
vh.functions = pHints->functions;
} else {
vh.functions = 0L;
}
if (pHints->flags & DtWM_HINTS_BEHAVIORS) {
vh.behaviors = pHints->behaviors;
} else {
vh.behaviors = 0L;
}
if (pHints->flags & DtWM_HINTS_ATTACH_WINDOW) {
vh.attachWindow = pHints->attachWindow;
} else {
vh.attachWindow = None;
}
XChangeProperty (
display,
window,
property,
property,
32,
PropModeReplace,
(unsigned char *)&vh,
(sizeof (DtWmHints)/sizeof (long)));
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,300 @@
/* $XConsortium: SmUtil.c /main/5 1996/06/21 17:26:03 ageorge $ */
/* *
* (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. *
*/
/******************************************************************************
*
* File Name: SmUtil.c
*
* Contains the DT functions used by an application to communicate with
* dtsession.
*
*****************************************************************************/
#if 0
#include <sys/param.h>
#include <sys/types.h>
#endif
#include <sys/stat.h>
#include <X11/Xlib.h>
#include <X11/Xatom.h>
#include <Dt/WsmP.h>
#include <Dt/DtP.h>
#include <Dt/Session.h>
#include <Dt/SmCreateDirs.h>
#include "DtSvcLock.h"
#ifndef CDE_INSTALLATION_TOP
#define CDE_INSTALLATION_TOP "/opt/dt"
#endif
/******** Static Function Declarations ********/
static char *getSessionName(Display *, Atom);
static Boolean getSessionPath( Widget, char *, char **, char **);
/******** End Static Function Declarations ********/
/*************************************<->*************************************
*
* getSessionName (display, prop )
*
*
* Description:
* -----------
* Returns the session name.
*
* Inputs:
* ------
* display - the display
* prop - the property name of the save or restore session
*
* Outputs:
* -------
*
* Return:
* ------
* Returns the session name string or NULL if it could not be obtained.
* This value should be freed with XFree().
*
*
*************************************<->***********************************/
static char *
getSessionName(
Display *display,
Atom prop)
{
int propStatus;
Atom actualType;
int actualFormat;
unsigned long nitems;
unsigned long leftover;
char *property = NULL;
propStatus = XGetWindowProperty (display, RootWindow(display, 0),
prop, 0L,
1000000L, False,
AnyPropertyType, &actualType,
&actualFormat, &nitems, &leftover,
(unsigned char **)&property);
if(propStatus == Success &&
actualType != None &&
actualFormat == 8 &&
nitems != 0)
{
return(property);
}
if (property)
{
XFree(property);
}
return(NULL);
}
/*************************************<->*************************************
*
* getSessionPath (widget, propstring, savePath, saveFile)
*
*
* Description:
* -----------
* This function generates a full path name for an application's state
* file. If *saveFile is NULL, a new file name is generated, else
* *saveFile is used. It returns True if the path is returned, False
* otherwise.
*
*
* Inputs:
* ------
* widget - a widget to use to get the display
* propstring - session name property
* savePath - pointer to memory in which to place pointer to path
* saveFile - pointer to filename. If *saveFile is NULL, a new filename
* will be allocated and returned in *saveFile, else *saveFile
* will be used to generate path name
*
* Outputs:
* -------
* True - path name returned
* False - path name not returned
*
*************************************<->***********************************/
static Boolean
getSessionPath(
Widget widget,
char *propstring,
char **savePath,
char **saveFile )
{
Display *display;
char *tmpPath = NULL;
char *property = NULL;
char *fileName;
struct stat buf;
int status;
display = XtDisplay(widget);
tmpPath = _DtCreateDtDirs(display);
if (tmpPath == NULL) goto abort;
property = getSessionName(display,
XInternAtom(display, propstring, False));
if (property == NULL) goto abort;
/*
* NOTE: it is assumed that _DtCreateDtDirs() returns a buffer of
* size MAXPATHLEN+1. This allows us to avoid a extra alloc
* and copy -- at the expense of code maintainability.
*/
if ((strlen(tmpPath) + 1 + strlen(property)) > MAXPATHLEN) goto abort;
/*
* parse the property string and create directory if needed
*/
(void)strcat(tmpPath, "/");
(void)strcat(tmpPath, property);
status = stat(tmpPath, &buf);
/*
* directory does not exist.
*/
if(status == -1)
{
status = mkdir(tmpPath, 0000);
if(status == -1) goto abort;
(void)chmod(tmpPath, 0755);
}
(void)strcat(tmpPath, "/");
if (*saveFile == NULL)
{
/*
* No saveFile name was provided, so generate a new one.
*/
int len = strlen(tmpPath);
(void)strcat(tmpPath, "dtXXXXXX");
(void)mktemp(tmpPath);
*saveFile = (char *) XtMalloc(15 * sizeof(char));
if(*saveFile == NULL) goto abort;
(void)strcpy(*saveFile, tmpPath+len);
}
else
{
/*
* A saveFile name was provided, so use it.
*/
(void)strcat(tmpPath, *saveFile);
}
*savePath = tmpPath;
XFree ((char *)property);
return(True);
abort:
/*
* ObGoto: if it clarifies the logic and reduces code,
* goto's are ok by me.
*/
*savePath = NULL;
if (tmpPath) XtFree ((char *)tmpPath);
if (property) XFree ((char *)property);
return(False);
}
/*************************************<->*************************************
*
* DtSessionSavePath (widget, savePath, saveFile)
*
*
* Description:
* -----------
* This function returns (in it's parameters) the full path name for an
* application to save to, as well as the file name to save away for later
* restoration. It returns True if the path is returned, False
* otherwise.
*
*
* Inputs:
* ------
* widget - a widget to use to get the display
*
* Outputs:
* -------
* returns a status value
*
*************************************<->***********************************/
Boolean
DtSessionSavePath(
Widget widget,
char **savePath,
char **saveFile )
{
Boolean result;
_DtSvcWidgetToAppContext(widget);
_DtSvcAppLock(app);
*saveFile = NULL;
result = getSessionPath(widget, _XA_DT_SAVE_MODE, savePath, saveFile);
_DtSvcAppUnlock(app);
return(result);
} /* END OF FUNCTION DtSessionSavePath */
/*************************************<->*************************************
*
* DtSessionRestorePath (widget, restorePath, restoreFile)
*
*
* Description:
* -----------
* This function returns (in its parameters), the path where the application
* is to restore its file from.
* It returns True if the path is returned, False
* otherwise.
*
*
* Inputs:
* ------
* widget - a widget to use to get the display
*
* Outputs:
* -------
* returns a status value
*
*************************************<->***********************************/
Boolean
DtSessionRestorePath(
Widget widget,
char **savePath,
char *saveFile )
{
Boolean result;
_DtSvcWidgetToAppContext(widget);
_DtSvcAppLock(app);
result = getSessionPath(widget, _XA_DT_RESTORE_MODE, savePath, &saveFile);
_DtSvcAppUnlock(app);
return(result);
} /* END OF FUNCTION DtSessionRestorePath */

View File

@@ -0,0 +1,223 @@
/* $XConsortium: WmAddDelWs.c /main/7 1996/05/22 12:01:11 drk $
*
* (c) Copyright 1996 Digital Equipment Corporation.
* (c) Copyright 1993,1994,1996 Hewlett-Packard Company.
* (c) Copyright 1993,1994,1996 International Business Machines Corp.
* (c) Copyright 1993,1994,1996 Sun Microsystems, Inc.
* (c) Copyright 1993,1994,1996 Novell, Inc.
* (c) Copyright 1996 FUJITSU LIMITED.
* (c) Copyright 1996 Hitachi.
*/
/************************************<+>*************************************
****************************************************************************
**
** File: WmAddDelWs.c
**
** Project: DT Workspace Manager
**
** Description: Add/Delete a workspace
**
****************************************************************************
************************************<+>*************************************/
#include <stdio.h>
#include <X11/Intrinsic.h>
#include <Dt/Wsm.h>
#include <Dt/WsmP.h>
#include <Dt/WsmM.h>
#include <Dt/Service.h>
#include <Xm/Xm.h>
#include <Xm/AtomMgr.h>
#include <Tt/tttk.h>
/*************************************<->*************************************
*
* int DtWsmDeleteWorkspace (widget, aWs)
*
*
* Description:
* -----------
* Delete a workspace
*
*
* Inputs:
* ------
* widget - a widget (with a window!)
* aWs - atom of workspace to delete
*
* Outputs:
* --------
* Return - Success if communication to workspace manager
* was successful. Note that this is *not* the same
* value _DtWsmDeleteWorkspace returns.
*
* Comments:
* ---------
* public interface to _DtWsmDeleteWorkspace()
*
*************************************<->***********************************/
int
DtWsmDeleteWorkspace (
Widget widget,
Atom aWs)
{
int rcode = _DtWsmDeleteWorkspace(widget, aWs);
if (rcode == dtmsg_SUCCESS)
return Success;
else /* rcode == dtmsg_FAIL */
return rcode;
}
/*************************************<->*************************************
*
* int _DtWsmDeleteWorkspace (widget, aWs)
*
*
* Description:
* -----------
* Delete a workspace
*
*
* Inputs:
* ------
* widget - a widget (with a window!)
* aWs - atom of workspace to delete
*
* Outputs:
* --------
* Return - 1 (*not* Success) if communication to workspace manager
* was successful.
*
* Comments:
* ---------
*
*************************************<->***********************************/
int
_DtWsmDeleteWorkspace (
Widget widget,
Atom aWs)
{
char pch[40];
Tt_message msg;
Tt_status status;
sprintf (pch, "0x%lx", aWs);
msg = tttk_message_create(0, TT_REQUEST, TT_SESSION, 0,
"DtWorkspace_Delete", 0);
status = tt_ptr_error(msg);
if (status != TT_OK) {
return dtmsg_FAIL;
}
status = tt_message_arg_add(msg, TT_IN, Tttk_string, pch);
if (status != TT_OK) {
return dtmsg_FAIL;
}
status = tt_message_callback_add(msg, _DtWsmConsumeReply);
if (status != TT_OK) {
return dtmsg_FAIL;
}
status = tt_message_send(msg);
if (status != TT_OK) {
return dtmsg_FAIL;
}
return (dtmsg_SUCCESS);
} /* END OF FUNCTION _DtWsmDeleteWorkspace */
/*************************************<->*************************************
*
* int DtWsmAddWorkspace (widget, pchTitle)
*
*
* Description:
* -----------
* Add a workspace
*
*
* Inputs:
* ------
* widget - a widget (with a window!)
* pchTitle - user-visible title of the workspace
*
* Outputs:
* --------
* Return - Success if communication to workspace manager
* was successful. Note that this is *not* the
* same value _DtWsmCreateWorkspace returns.
*
* Comments:
* ---------
* public interface to _DtWsmCreateWorkspace()
*
*************************************<->***********************************/
int
DtWsmAddWorkspace (Widget widget, char * pchTitle)
{
int rcode = _DtWsmCreateWorkspace(widget, pchTitle);
if (rcode == dtmsg_SUCCESS)
return Success;
else /* rcode == dtmsg_FAIL */
return rcode;
}
/*************************************<->*************************************
*
* int _DtWsmCreateWorkspace (widget, pchTitle)
*
*
* Description:
* -----------
* Add a workspace
*
*
* Inputs:
* ------
* widget - a widget (with a window!)
* pchTitle - user-visible title of the workspace
*
* Outputs:
* --------
* Return - 1 (*not* Success) if communication to workspace manager
* was successful.
*
* Comments:
* ---------
* The odd-ball successful return value is a CDE 1.0 bug being
* preserved for backward compatibility.
*
*************************************<->***********************************/
int
_DtWsmCreateWorkspace (Widget widget, char * pchTitle)
{
Tt_message msg;
Tt_status status;
msg = tttk_message_create(0, TT_REQUEST, TT_SESSION, 0,
"DtWorkspace_Add", 0);
status = tt_ptr_error(msg);
if (status != TT_OK) {
return dtmsg_FAIL;
}
status = tt_message_arg_add(msg, TT_IN, Tttk_string, pchTitle);
if (status != TT_OK) {
return dtmsg_FAIL;
}
status = tt_message_callback_add(msg, _DtWsmConsumeReply);
if (status != TT_OK) {
return dtmsg_FAIL;
}
status = tt_message_send(msg);
if (status != TT_OK) {
return dtmsg_FAIL;
}
return (dtmsg_SUCCESS);
} /* END OF FUNCTION _DtWsmCreateWorkspace */

View File

@@ -0,0 +1,171 @@
/*
* (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. *
*/
/************************************<+>*************************************
****************************************************************************
**
** File: WmBackWin.c
**
** RCS: $XConsortium: WmBackWin.c /main/4 1995/10/26 15:12:20 rswiston $
** Project: DT Workspace Manager
**
** Description: Identify backdrop windows
**
** (c) Copyright 1993 by Hewlett-Packard Company
**
****************************************************************************
************************************<+>*************************************/
#include <stdio.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <Dt/Wsm.h>
#include <Xm/Xm.h>
#include <Xm/AtomMgr.h>
/******** Public Function Declarations ********/
extern Window DtWsmGetCurrentBackdropWindow(
Display *display,
Window root);
extern Boolean _DtWsmIsBackdropWindow(
Display *display,
int screen_num,
Window window );
/******** End Public Function Declarations ********/
/*************************************<->*************************************
*
* Window DtWsmGetCurrentBackdropWindow (display, root)
*
*
* Description:
* -----------
* Returns the window used for the backdrop for the current workspace
*
*
* Inputs:
* ------
* display - display
* root - root window
*
* Return - window used for current workspace
* None if no backdrop window or error
*
* Comments:
* --------
*
*
*************************************<->***********************************/
Window
DtWsmGetCurrentBackdropWindow(
Display *display ,
Window root )
{
Window wReturn = None;
Atom aWS;
DtWsmWorkspaceInfo *pWsInfo;
Status status;
status = DtWsmGetCurrentWorkspace (display, root, &aWS);
if (status == Success)
{
status = DtWsmGetWorkspaceInfo(display, root, aWS, &pWsInfo);
if (status == Success)
{
if (pWsInfo->numBackdropWindows > 0)
{
/* copy backdrop window (there should be at most one) */
wReturn = pWsInfo->backdropWindows[0];
}
DtWsmFreeWorkspaceInfo (pWsInfo);
}
}
return (wReturn);
} /* END OF FUNCTION DtWsmGetCurrentBackdropWindow */
/*************************************<->*************************************
*
* Boolean _DtWsmIsBackdropWindow (display, screen_num, window)
*
*
* Description:
* -----------
* Returns true if the window passed in is a backdrop window.
*
*
* Inputs:
* ------
* display - display
* screen_num - number of screen we're interested in
* window - window we want to test
*
* Outputs:
* -------
* Return - True if window is a backdrop window
* False otherwise.
*
* Comments:
* --------
*
*************************************<->***********************************/
Boolean
_DtWsmIsBackdropWindow(
Display *display,
int screen_num,
Window window )
{
Boolean rval = False;
Status status;
Atom *pWorkspaceList;
int ix, iw, numWorkspaces;
DtWsmWorkspaceInfo *pWsInfo;
Window root;
root = XRootWindow (display, screen_num);
status = DtWsmGetWorkspaceList (display, root,
&pWorkspaceList, &numWorkspaces);
if ((status == Success) &&
(numWorkspaces > 0) &&
(pWsInfo = (DtWsmWorkspaceInfo *)
malloc (numWorkspaces * sizeof(DtWsmWorkspaceInfo))))
{
for (ix=0;
(!rval) && (ix < numWorkspaces) && (status == Success);
ix++)
{
status = DtWsmGetWorkspaceInfo (display,
root,
pWorkspaceList[ix],
&pWsInfo);
if (status == Success)
{
for (iw = 0; iw < pWsInfo->numBackdropWindows; iw++)
{
if (pWsInfo->backdropWindows[iw] == window)
{
rval = True;
}
}
DtWsmFreeWorkspaceInfo(pWsInfo);
}
}
XFree ((char *)pWorkspaceList);
}
return (rval);
} /* END OF FUNCTION _DtWsmIsBackdropWindow */

View File

@@ -0,0 +1,147 @@
/* $TOG: WmChBackD.c /main/7 1998/07/30 12:11:23 mgreess $
*
* (c) Copyright 1996 Digital Equipment Corporation.
* (c) Copyright 1991,1993,1994,1996 Hewlett-Packard Company.
* (c) Copyright 1993,1994,1996 International Business Machines Corp.
* (c) Copyright 1993,1994,1996 Sun Microsystems, Inc.
* (c) Copyright 1993,1994,1996 Novell, Inc.
* (c) Copyright 1996 FUJITSU LIMITED.
* (c) Copyright 1996 Hitachi.
*/
/************************************<+>*************************************
****************************************************************************
**
** File: WmChBackD.c
**
** Description: Request backdrop change of the workspace manager
**
****************************************************************************
************************************<+>*************************************/
#include <stdio.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xatom.h>
#include <Dt/Wsm.h>
#include <Dt/WsmP.h>
#include <Xm/Xm.h>
#include <Xm/AtomMgr.h>
#define SYS_FILE_SEARCH_PATH "DTICONSEARCHPATH"
/*************************************<->*************************************
*
* DtWsmChangeBackdrop (display, root, path, pixmap)
*
*
* Description:
* -----------
* Request the CDE workspace manager to change the backdrop
*
*
* Inputs:
* ------
* display - display
* root - root window of screen
* path - file path to bitmap file
* pixmap - pixmap id of backdrop pixmap
*
* Returns:
* --------
* Success if request sent
*
* Comments:
* ---------
* public interface to _DtWsmChangeBackdrop()
*
*************************************<->***********************************/
int
DtWsmChangeBackdrop (
Display *display,
Window root,
char *path,
Pixmap pixmap)
{
return _DtWsmChangeBackdrop(display, root, path, pixmap);
}
/*************************************<->*************************************
*
* _DtWsmChangeBackdrop (display, root, path, pixmap)
*
*
* Description:
* -----------
* Request the CDE workspace manager to change the backdrop
*
*
* Inputs:
* ------
* display - display
* root - root window of screen
* path - file path to bitmap file
* pixmap - pixmap id of backdrop pixmap
*
* Returns:
* --------
* Success if request sent
*
* Comments:
* ---------
*
*************************************<->***********************************/
int
_DtWsmChangeBackdrop (
Display *display,
Window root,
char *path,
Pixmap pixmap)
{
int rval = BadAtom;
Window wmWindow;
if (!path)
{
rval = BadValue;
}
else
/*
* Get the workspace manager window
*/
if ((rval=_DtGetMwmWindow (display, root, &wmWindow)) == Success)
{
char *pch;
int len;
/*
* Build up the NULL-terminated request string
*/
len = strlen (DTWM_REQ_CHANGE_BACKDROP) + 1;
len += strlen (path) + 1;
len += 30; /* fudge for ascii-ized pixmap id */
pch = (char *) XtMalloc (len * sizeof(char));
sprintf (pch, "%s %s %lx", DTWM_REQ_CHANGE_BACKDROP, path,
pixmap);
/*
* Make the request by appending the string to
* the _DT_WM_REQUEST property
*/
rval = XChangeProperty (display, wmWindow,
XmInternAtom(display, _XA_DT_WM_REQUEST, False),
XA_STRING, 8, PropModeAppend,
(unsigned char *)pch,
1+strlen(pch));
}
return (rval);
} /* END OF FUNCTION _DtWsmChangeBackdrop */

View File

@@ -0,0 +1,254 @@
/* $TOG: WmGWsInfo.c /main/7 1997/11/13 14:03:00 bill $
*
* (c) Copyright 1996 Digital Equipment Corporation.
* (c) Copyright 1992-1994,1996 Hewlett-Packard Company.
* (c) Copyright 1993,1994,1996 International Business Machines Corp.
* (c) Copyright 1993,1994,1996 Sun Microsystems, Inc.
* (c) Copyright 1993,1994,1996 Novell, Inc.
* (c) Copyright 1996 FUJITSU LIMITED.
* (c) Copyright 1996 Hitachi.
*/
/************************************<+>*************************************
****************************************************************************
**
** File: WmGWsInfo.c
**
** Project: DT Workspace Manager
**
** Description: Get Dt Workspace Info
**
****************************************************************************
************************************<+>*************************************/
#include <stdio.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <Dt/Wsm.h>
#include <Dt/WsmP.h>
#include <Xm/Xm.h>
#include <Xm/AtomMgr.h>
#include <X11/Xatom.h>
#include "DtSvcLock.h"
/*************************************<->*************************************
*
* int DtWsmGetWorkspaceInfo (display, root, aWS, ppWsInfo)
*
*
* Description:
* -----------
* Get the contents of the _DT_WORKSPACE_INFO_<name> property
* for workspace <name>.
*
*
* Inputs:
* ------
* display - display
* root - root window of screen of interest
* aWS - atom for workspace
* ppWsInfo - ptr to WS info buffer ptr (to be returned)
*
* Outputs:
* --------
* *ppWsInfo - returned ptr to WS Info. (free with XtFree).
*
*
* Comments:
* ---------
* ptr to WorkspaceInfo should be freed by calling
* DtWsmFreeWorkspaceInfo.
*
*************************************<->***********************************/
int
DtWsmGetWorkspaceInfo(
Display *display,
Window root,
Atom aWS,
DtWsmWorkspaceInfo **ppWsInfo)
{
int rcode;
Atom aProperty;
Window wmWindow;
DtWsmWorkspaceInfo *pWsInfo;
char *pchName, *pch;
int iLen;
int i;
Window *pWin;
XTextProperty tp;
char **ppchList;
int count, item;
_DtSvcDisplayToAppContext(display);
_DtSvcAppLock(app);
/*
* Construct atom name
*/
pchName = (char *) XGetAtomName (display, aWS);
iLen = strlen(pchName) + strlen (_XA_DT_WORKSPACE_INFO) + 4;
pch = (char *) XtMalloc (iLen);
strcpy (pch, _XA_DT_WORKSPACE_INFO);
strcat (pch, "_");
strcat (pch, pchName);
aProperty = XInternAtom (display, pch, FALSE);
XFree ((char *) pchName);
XtFree ((char *) pch);
pch = NULL;
/*
* Get window where property is
*/
if ((rcode=_DtGetMwmWindow (display, root, &wmWindow)) == Success)
{
if ((rcode=XGetTextProperty(
display,
wmWindow,
&tp,
aProperty))>=Success)
{
if (rcode=XmbTextPropertyToTextList (
display,
&tp,
&ppchList,
&count) >= Success)
{
pWsInfo = (DtWsmWorkspaceInfo *)
XtCalloc(1, sizeof(DtWsmWorkspaceInfo));
pWsInfo->workspace = aWS;
item = 0;
/* title */
if (item < count)
{
pWsInfo->pchTitle = (char *)
XtNewString ((String) ppchList[item]);
item++;
}
/* pixel set id */
if (item < count)
{
pWsInfo->colorSetId = atoi (ppchList[item]);
item++;
}
/* backdrop window (moved to end!) */
/* backdrop background */
if (item < count)
{
pWsInfo->bg = (unsigned long)
strtol (ppchList[item], (char **) NULL, 0);
item++;
}
/* backdrop foreground */
if (item < count)
{
pWsInfo->fg = (unsigned long)
strtol (ppchList[item], (char **) NULL, 0);
item++;
}
/* backdrop name (atom) */
if (item < count)
{
pWsInfo->backdropName =
(Atom) strtol (ppchList[item], (char **) NULL, 0);
item++;
}
/* number of backdrop windows */
if (item < count)
{
pWsInfo->numBackdropWindows =
(int) strtol (ppchList[item], (char **) NULL, 0);
item++;
}
/* list of backdrop windows */
if (pWsInfo->numBackdropWindows > 0 &&
(item + pWsInfo->numBackdropWindows) <= count)
{
pWin = (Window *)
XtMalloc (pWsInfo->numBackdropWindows *
sizeof (Window));
for (i=0; i<pWsInfo->numBackdropWindows; i++)
{
pWin[i] = (Window)
strtol (ppchList[item], (char **) NULL, 0);
item++;
}
pWsInfo->backdropWindows = pWin;
}
else
{
/* Bogus backdrop windows info */
pWsInfo->numBackdropWindows = 0;
}
/* pass back ptr to filled in structure */
*ppWsInfo = pWsInfo;
/* free the converted data */
XFreeStringList (ppchList);
}
else
{
/* conversion failed */
*ppWsInfo = NULL;
}
/* free the property data */
if (tp.value)
XFree (tp.value);
}
}
if (rcode >= Success) rcode=Success;
_DtSvcAppUnlock(app);
return(rcode);
} /* END OF FUNCTION DtWsmGetWorkspaceInfo */
/*************************************<->*************************************
*
* void DtWsmFreeWorkspaceInfo (pWsInfo)
*
*
* Description:
* -----------
* Free a WorkspaceInfo buffer
*
*
* Inputs:
* ------
* pWsInfo - ptr to WS info buffer
*
* Outputs:
* --------
* None
*
* Comments:
* ---------
*
*************************************<->***********************************/
void
DtWsmFreeWorkspaceInfo(
DtWsmWorkspaceInfo *pWsInfo)
{
if (pWsInfo)
{
if (pWsInfo->pchTitle)
XtFree (pWsInfo->pchTitle);
if (pWsInfo->backdropWindows)
XtFree ((char *)pWsInfo->backdropWindows);
XtFree ((char *)pWsInfo);
}
} /* END OF FUNCTION DtWsmFreeWorkspaceInfo */

View File

@@ -0,0 +1,206 @@
/* $XConsortium: WmGWsList.c /main/6 1996/06/21 17:24:26 ageorge $
*
* (c) Copyright 1996 Digital Equipment Corporation.
* (c) Copyright 1992-1994,1996 Hewlett-Packard Company.
* (c) Copyright 1993,1994,1996 International Business Machines Corp.
* (c) Copyright 1993,1994,1996 Sun Microsystems, Inc.
* (c) Copyright 1993,1994,1996 Novell, Inc.
* (c) Copyright 1996 FUJITSU LIMITED.
* (c) Copyright 1996 Hitachi.
*/
/************************************<+>*************************************
****************************************************************************
**
** File: WmGetWsLis.c
**
** Project: DT Workspace Manager
**
** Description: Get Dt Workspace List
**
****************************************************************************
************************************<+>*************************************/
#include <stdio.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <Dt/Wsm.h>
#include <Dt/WsmP.h>
#include <Xm/Xm.h>
#include <Xm/AtomMgr.h>
#include <X11/Xatom.h>
#include "DtSvcLock.h"
/*************************************<->*************************************
*
* int DtWsmGetWorkspaceList (display, root, ppWorkspaceList,
* pNumWorkspaces)
*
*
* Description:
* -----------
* Get the contents of the _DT_WORKSPACE_LIST property
*
*
* Inputs:
* ------
* display - display
* root - root window of screen of interest
* pNumWorkspaces - the number of workspaces returned
* ppWorkspaceList - pointer to a pointer to return
*
* Outputs:
* --------
* *ppDtWmHints-points to the Workspace List
* (NOTE: This should be freed using XFree)
*
* Comments:
* ---------
*
*************************************<->***********************************/
int
DtWsmGetWorkspaceList(
Display *display,
Window root,
Atom **ppWorkspaceList,
int *pNumWorkspaces)
{
Atom actualType;
int actualFormat;
unsigned long leftover, items, length, oldlength;
int rcode;
Atom property;
Window wmWindow;
_DtSvcDisplayToAppContext(display);
_DtSvcAppLock(app);
if ((rcode=_DtGetMwmWindow (display, root, &wmWindow)) == Success)
{
property = XmInternAtom(display, _XA_DT_WORKSPACE_LIST, False);
length = BUFSIZ;
*ppWorkspaceList = NULL;
if ((rcode=XGetWindowProperty(
display,
wmWindow,
property,
0L, /* offset */
length,
False, /* delete */
XA_ATOM, /* req_type */
&actualType,
&actualFormat,
&items, /* items returned */
&leftover,
(unsigned char **)ppWorkspaceList))==Success)
{
if (actualType != XA_ATOM)
{
/* wrong type, force failure */
rcode = BadValue;
if (actualType != None)
{
XFree ((char *)*ppWorkspaceList);
}
*ppWorkspaceList = NULL;
}
else
{
*pNumWorkspaces = (int) items;
}
}
}
_DtSvcAppUnlock(app);
return(rcode);
} /* END OF FUNCTION DtWsmGetWorkspaceList */
/*************************************<->*************************************
*
* int DtWsmGetCurrentWorkspace (display, root, paWorkspace)
*
*
* Description:
* -----------
* Get the contents of the _DT_WORKSPACE_CURRENT property
*
*
* Inputs:
* ------
* display - display
* root - root window of screen of interest
* paWorkspace - pointer to a Atom of current workspace (returned)
*
* Outputs:
* --------
* *paWorkspace - atom for current workspace (represents "name"
* of workspace).
*
* Comments:
* ---------
* The Atom is copied to the caller's space. Nothing needs to be
* freed.
*
*************************************<->***********************************/
int
DtWsmGetCurrentWorkspace (
Display *display,
Window root,
Atom *paWorkspace)
{
Atom actualType;
int actualFormat;
unsigned long leftover, items, length;
int rcode;
Atom property;
Window wmWindow;
Atom *paTemp;
_DtSvcDisplayToAppContext(display);
_DtSvcAppLock(app);
if ((rcode=_DtGetMwmWindow (display, root, &wmWindow)) == Success)
{
property = XmInternAtom(display, _XA_DT_WORKSPACE_CURRENT, False);
length = 1;
if ((rcode=XGetWindowProperty(
display,
wmWindow,
property,
0L, /* offset */
length,
False, /* delete */
XA_ATOM, /* req_type */
&actualType,
&actualFormat,
&items, /* items returned */
&leftover,
(unsigned char **)&paTemp))==Success)
{
if (actualType != XA_ATOM)
{
/* wrong type, force failure */
rcode = BadValue;
if (actualType != None)
{
XFree ((char *)paTemp);
}
}
else
{
*paWorkspace = *paTemp;
XFree((char *) paTemp);
}
}
}
_DtSvcAppUnlock(app);
return(rcode);
} /* END OF FUNCTION DtWsmGetCurrentWorkspace */

View File

@@ -0,0 +1,230 @@
/************************************<+>*************************************
****************************************************************************
**
** File: WmMarquee.c
**
** RCS: $XConsortium: WmMarquee.c /main/4 1995/10/26 15:12:59 rswiston $
**
** Project: DT Workspace Manager
**
** Description: Get Marquee Selection Data
**
** (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.
**
****************************************************************************
************************************<+>*************************************/
#include <stdio.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <Tt/tttk.h>
#include <Dt/Wsm.h>
#include <Dt/WsmM.h>
#include "WsmP.h"
#include <Dt/Service.h>
#include <Xm/Xm.h>
/*************************************<->*************************************
*
* Tt_callback_action _WsSelectionCB (Tt_message m, Tt_pattern p)
*
*
* Description:
* -----------
* Internal function called for a marquee selection
*
*
* Inputs:
* ------
* m - ToolTalk message
* p - ToolTalk pattern
*
* Outputs:
* --------
* Return - ToolTalk callback status
*
* Comments:
* ---------
*
*************************************<->***********************************/
static Tt_callback_action
_WsSelectionCB (Tt_message m, Tt_pattern p)
{
struct _DtWsmCBContext *pCbCtx;
int type, val;
Position x, y;
Dimension width, height;
Widget widget;
DtWsmMarqueeSelectionProc marquee_selection;
XtPointer client_data;
/*
* user data 0: Widget widget;
* user data 1: DtWsmWsModifiedProc ws_modify;
* user data 2: XtPointer client_data;
*/
widget = (Widget)tt_pattern_user(p, 0);
marquee_selection = (DtWsmMarqueeSelectionProc)tt_pattern_user(p, 1);
client_data = (XtPointer)tt_pattern_user(p, 2);
/*
* 0th arg: screen number, string, not used
*/
tt_message_arg_ival(m, 1, &type); /* type */
tt_message_arg_ival(m, 2, &val); /* x */
x = val;
tt_message_arg_ival(m, 3, &val); /* y */
y = val;
tt_message_arg_ival(m, 4, &val); /* width */
width = val;
tt_message_arg_ival(m, 5, &val); /* height */
height = val;
/*
* Call registered callback function.
*/
(*marquee_selection)(widget, type, x, y, width, height, client_data);
return TT_CALLBACK_PROCESSED;
} /* END OF FUNCTION _DtWsmWsModifyHandler */
/*************************************<->*************************************
*
* DtWsmCBContext * DtWsmAddMarqueeSelectionCallback (widget,
* marquee_select,
* client_data)
*
*
* Description:
* -----------
* Register a function to be called when a marquee selection is made
*
*
* Inputs:
* ------
* widget - widget for this client
* marquee_select - function to call for marquee select
* client_data - additional data to pass back to client when called.
*
* Outputs:
* --------
* Return - ptr to callback context data (opaque)
*
* Comments:
* ---------
* The callback context data ptr should be saved if you intend to
* removed this callback at some point in the future.
*
*************************************<->***********************************/
DtWsmCBContext
_DtWsmAddMarqueeSelectionCallback (
Widget widget,
DtWsmMarqueeSelectionProc marquee_selection,
XtPointer client_data)
{
struct _DtWsmCBContext *pCbCtx;
int screen;
String sName;
char sNum[32];
Tt_status status;
Tt_pattern pattern;
char * sessId;
/*
* This function register a ToolTalk pattern for every
* callback added.
*/
_DtSvcInitToolTalk(widget);
pattern = tt_pattern_create();
status = tt_ptr_error(pattern);
if (status != TT_OK) {
return NULL;
}
if (tt_pattern_category_set(pattern, TT_OBSERVE) != TT_OK) {
return NULL;
}
if (tt_pattern_scope_add(pattern, TT_SESSION) != TT_OK) {
return NULL;
}
sessId = tt_default_session();
if (tt_pattern_session_add(pattern, sessId) != TT_OK) {
return NULL;
}
tt_free(sessId);
screen = XScreenNumberOfScreen(XtScreen(widget));
sprintf(sNum, "%d", screen);
sName = _DtWsmSelectionNameForScreen (screen);
/*
* Only receive DtMarquee_Selection notice from the screen
* we registered with.
*/
status = tt_pattern_arg_add(pattern, TT_IN, Tttk_string, sNum);
if (status != TT_OK) {
return NULL;
}
if (tt_pattern_op_add(pattern, "DtMarquee_Selection") != TT_OK) {
return NULL;
}
if (tt_pattern_state_add(pattern, TT_SENT) != TT_OK) {
return NULL;
}
/*
* Store information needed by the callback in the user data
* fields of the pattern.
*/
status = tt_pattern_user_set(pattern, 0, (void *)widget);
if (status != TT_OK) {
return NULL;
}
status = tt_pattern_user_set(pattern, 1, (void *)marquee_selection);
if (status != TT_OK) {
return NULL;
}
status = tt_pattern_user_set(pattern, 2, (void *)client_data);
if (status != TT_OK) {
return NULL;
}
/*
* _WsSelectionCB is the ToolTalk callback which will call
* the user callback.
*/
if (tt_pattern_callback_add(pattern, _WsSelectionCB) != TT_OK) {
return NULL;
}
if (tt_pattern_register(pattern) != TT_OK) {
return NULL;
}
/*
* Allocate data to remember stuff about this callback
*/
pCbCtx = (struct _DtWsmCBContext * )
XtMalloc (sizeof(struct _DtWsmCBContext));
/*
* Save what we want to remember
*/
pCbCtx->pattern = pattern;
pCbCtx->widget = widget;
pCbCtx->ws_cb = marquee_selection;
pCbCtx->client_data = client_data;
XtFree (sName);
return (pCbCtx);
} /* END OF FUNCTION DtWsmAddMarqueeSelectionCallback */

View File

@@ -0,0 +1,120 @@
/*
* (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. *
*/
/************************************<+>*************************************
****************************************************************************
**
** File: WmRequest.c
**
** RCS: $XConsortium: WmRequest.c /main/4 1995/10/26 15:13:08 rswiston $
** Project: HP DT Workspace Manager
**
** Description: Send a function request to the window manager
**
** (c) Copyright 1992, 1993 by Hewlett-Packard Company
**
****************************************************************************
************************************<+>*************************************/
#include <stdio.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xatom.h>
#include <Dt/Wsm.h>
#include <Dt/WsmP.h>
#include <Xm/Xm.h>
#include <Xm/AtomMgr.h>
/*************************************<->*************************************
*
* _DtWmRequestMultiple (display, root, char *pchRequest, int len)
*
*
* Description:
* -----------
* Send one or more function requests to the window manager.
*
*
* Inputs:
* ------
* display - display
* root - root window of screen
* pchRequest - string request (possibly multiple)
* (usu. of form "f.<func> [<arg>]")
* len - length of request, counting terminating NULL
*
* Returns:
* --------
* Success if request sent
*
*************************************<->***********************************/
Status
_DtWmRequestMultiple (
Display *display,
Window root,
char *pchRequest,
int len)
{
Status rval = BadAtom;
Window wmWindow;
/*
* Get the workspace manager window
*/
if ((rval=_DtGetMwmWindow (display, root, &wmWindow)) == Success)
{
/*
* Make the request by appending the request
* to the _DT_WM_REQUEST property
*/
rval = XChangeProperty (display, wmWindow,
XmInternAtom(display, _XA_DT_WM_REQUEST, False),
XA_STRING, 8, PropModeAppend,
(unsigned char *)pchRequest,
len);
}
return (rval);
} /* END OF FUNCTION _DtWmRequestMultiple */
#if 0
/*************************************<->*************************************
*
* DtWmRequest (display, root, char *pchRequest)
*
*
* Description:
* -----------
* Send a function request to the window manager.
*
*
* Inputs:
* ------
* display - display
* root - root window of screen
* pchRequest - NULL terminated string request
* (usu. of form "f.<func> [<arg>]")
*
* Returns:
* --------
* Success if request sent
*
*************************************<->***********************************/
Status
DtWmRequest (Display *display, Window root, char *pchRequest)
{
return (_DtWmRequestMultiple (display, root,
pchRequest, 1+strlen(pchRequest)));
} /* END OF FUNCTION DtWmRequest */
#endif

View File

@@ -0,0 +1,144 @@
/* $XConsortium: WmRestart.c /main/5 1996/05/20 16:08:04 drk $
*
* (c) Copyright 1996 Digital Equipment Corporation.
* (c) Copyright 1991,1993,1994,1996 Hewlett-Packard Company.
* (c) Copyright 1993,1994,1996 International Business Machines Corp.
* (c) Copyright 1993,1994,1996 Sun Microsystems, Inc.
* (c) Copyright 1993,1994,1996 Novell, Inc.
* (c) Copyright 1996 FUJITSU LIMITED.
* (c) Copyright 1996 Hitachi.
*/
/************************************<+>*************************************
****************************************************************************
**
** File: WmRestart.c
**
** Project: HP DT Workspace Manager
**
** Description: Request restart of the HP DT workspace manager
**
****************************************************************************
************************************<+>*************************************/
#include <stdio.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xatom.h>
#include <Dt/Wsm.h>
#include <Dt/WsmP.h>
#include <Xm/Xm.h>
#include <Xm/AtomMgr.h>
/*************************************<->*************************************
*
* _DtWmRestart (display, root)
*
*
* Description:
* -----------
* Request the window manager to restart
*
*
* Inputs:
* ------
* display - display
* root - root window of screen
*
* Returns:
* --------
* Success if request sent
*
*************************************<->***********************************/
int
_DtWmRestart (Display *display, Window root)
{
int rval = BadAtom;
Window wmWindow;
/*
* Get the workspace manager window
*/
if ((rval=_DtGetMwmWindow (display, root, &wmWindow)) == Success)
{
/*
* Make the request by appending the restart request
* name to the _DT_WM_REQUEST property
*/
rval = XChangeProperty (display, wmWindow,
XmInternAtom(display, _XA_DT_WM_REQUEST, False),
XA_STRING, 8, PropModeAppend,
(unsigned char *)DTWM_REQ_RESTART,
1+strlen(DTWM_REQ_RESTART));
XFlush (display); /* do it now */
}
return (rval);
} /* END OF FUNCTION _DtWmRestart */
/*************************************<->*************************************
*
* int _DtWmRestartNoConfirm (display, root)
*
*
* Description:
* -----------
* Request the window manager to restart with no confirmation dialog
*
*
* Inputs:
* ------
* display - display
* root - root window of screen
*
* Returns:
* --------
* Success if request sent
*
*************************************<->***********************************/
int
_DtWmRestartNoConfirm (Display *display, Window root)
{
int rval;
Window wmWindow;
char buffer[80];
/*
* Make the request by appending the restart request
* name to the _DT_WM_REQUEST property
*/
strcpy (&buffer[0], DTWM_REQ_RESTART);
strcat (&buffer[0], " ");
strcat (&buffer[0], DTWM_REQP_NO_CONFIRM);
/*
* Get the workspace manager window
*/
if ((rval=_DtGetMwmWindow (display, root, &wmWindow)) == Success)
{
/*
* Make the request by appending the restart request
* name to the _DT_WM_REQUEST property
*/
rval = XChangeProperty (display, wmWindow,
XmInternAtom(display, _XA_DT_WM_REQUEST, False),
XA_STRING, 8, PropModeAppend,
(unsigned char *)buffer,
1+strlen(buffer));
XFlush (display); /* do it now */
}
return (rval);
} /* END OF FUNCTION _DtWmRestartNoConfirm */

View File

@@ -0,0 +1,250 @@
/*
* (c) Copyright 1993, 1994 International Business Machines Corp. *
* (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
* (c) Copyright 1993, 1994 Novell, Inc. *
*/
/************************************<+>*************************************
****************************************************************************
**
** File: WmRmWsFcn.c
**
** RCS: $XConsortium: WmRmWsFcn.c /main/5 1996/06/21 17:24:22 ageorge $
** Project: HP DT Workspace Manager
**
** Description: Remove the Workspace functions on a client
**
** (c) Copyright 1991, 1993, 1994 by Hewlett-Packard Company
**
****************************************************************************
************************************<+>*************************************/
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xatom.h>
#include <Dt/Wsm.h>
#include <Dt/WsmP.h>
#include <Xm/AtomMgr.h>
#include "DtSvcLock.h"
/*************************************<->*************************************
*
* DtWsmRemoveWorkspaceFunctions (display, client)
*
*
* Description:
* -----------
* Request the window manager to disallow workspace functions
* for this client.
*
*
* Inputs:
* ------
* display - display
* root - root window of screen
*
* Returns:
* --------
* none
*
*
* Comments:
* ---------
* Disables f.workspace_presence, f.remove, f.occupy_all for this
* client.
*
*************************************<->***********************************/
void
DtWsmRemoveWorkspaceFunctions (Display *display, Window client)
{
DtWmHints vHints, *pHints;
long functions;
Boolean bSetHints = False;
_DtSvcDisplayToAppContext(display);
_DtSvcAppLock(app);
if (_DtWsmGetDtWmHints (display, client, &pHints) != Success)
{
/*
* There were no existing workspace hints, so we'll
* just use our own variable
*/
pHints = &vHints;
pHints->flags = 0;
}
if (pHints->flags & DtWM_HINTS_FUNCTIONS)
{
functions = pHints->functions &
(DtWM_FUNCTION_OCCUPY_WS | DtWM_FUNCTION_ALL);
if (functions & DtWM_FUNCTION_ALL)
{
/*
* The flags are a list of functions to remove. If
* the workspace functions aren't on this list, make
* sure that it's put there.
*/
if (!(functions & DtWM_FUNCTION_OCCUPY_WS))
{
/* remove workspace functions */
pHints->functions |= DtWM_FUNCTION_OCCUPY_WS;
bSetHints = True;
}
}
else
{
/*
* The flags are a list of functions to add. If
* the workspace functions are on the list, make
* sure they get removed.
*/
if (functions & DtWM_FUNCTION_OCCUPY_WS)
{
/* remove workspace functions */
pHints->functions &= ~DtWM_FUNCTION_OCCUPY_WS;
bSetHints = True;
}
}
}
else
{
/*
* The hints didn't have workspace functions specified.
* Set the flag and remove workspace functions.
*/
pHints->flags |= DtWM_HINTS_FUNCTIONS;
pHints->functions = DtWM_FUNCTION_OCCUPY_WS | DtWM_FUNCTION_ALL;
bSetHints = True;
}
/*
* If something needs to be changed, then change it.
*/
if (bSetHints)
_DtWsmSetDtWmHints (display, client, pHints);
/*
* If we read these hints off the window, then be sure to free
* them.
*/
if (pHints && (pHints != &vHints))
{
XFree ((char *)pHints);
}
_DtSvcAppUnlock(app);
} /* END OF FUNCTION DtWsmRemoveWorkspaceFunctions */
/*************************************<->*************************************
*
* DtWsmAddWorkspaceFunctions (display, client)
*
*
* Description:
* -----------
* Request the window manager to allow workspace functions
* for this client.
*
*
* Inputs:
* ------
* display - display
* root - root window of screen
*
* Returns:
* --------
* none
*
*
* Comments:
* ---------
* Enables f.workspace_presence, f.remove, f.occupy_all for this
* client.
*
*************************************<->***********************************/
void
DtWsmAddWorkspaceFunctions (Display *display, Window client)
{
DtWmHints vHints, *pHints;
long functions;
Boolean bSetHints = False;
_DtSvcDisplayToAppContext(display);
_DtSvcAppLock(app);
if (_DtWsmGetDtWmHints (display, client, &pHints) != Success)
{
/*
* There were no existing workspace hints, so we'll
* just use our own variable
*/
pHints = &vHints;
pHints->flags = 0;
}
if (pHints->flags & DtWM_HINTS_FUNCTIONS)
{
functions = pHints->functions &
(DtWM_FUNCTION_OCCUPY_WS | DtWM_FUNCTION_ALL);
if (functions & DtWM_FUNCTION_ALL)
{
/*
* The flags are a list of functions to remove. If
* the workspace functions are on this list, make
* sure that they're removed.
*/
if (functions & DtWM_FUNCTION_OCCUPY_WS)
{
/* add workspace functions */
pHints->functions &= ~DtWM_FUNCTION_OCCUPY_WS;
bSetHints = True;
}
}
else
{
/*
* The flags are a list of functions to add. If
* the workspace functions aren't on the list, make
* sure they get added.
*/
if (!(functions & DtWM_FUNCTION_OCCUPY_WS))
{
/* remove workspace functions */
pHints->functions |= DtWM_FUNCTION_OCCUPY_WS;
bSetHints = True;
}
}
}
else
{
/*
* The hints didn't have workspace functions specified.
* Set the flag and add workspace functions.
*/
pHints->flags |= DtWM_HINTS_FUNCTIONS;
pHints->functions = DtWM_FUNCTION_OCCUPY_WS;
bSetHints = True;
}
/*
* If something needs to be changed, then change it.
*/
if (bSetHints)
_DtWsmSetDtWmHints (display, client, pHints);
/*
* If we read these hints off the window, then be sure to free
* them.
*/
if (pHints && (pHints != &vHints))
{
XFree ((char *)pHints);
}
_DtSvcAppUnlock(app);
} /* END OF FUNCTION DtWsmAddWorkspaceFunctions */

View File

@@ -0,0 +1,149 @@
/* $XConsortium: WmSetTitle.c /main/6 1996/05/20 16:08:13 drk $
*
* (c) Copyright 1996 Digital Equipment Corporation.
* (c) Copyright 1993,1994,1996 Hewlett-Packard Company.
* (c) Copyright 1993,1994,1996 International Business Machines Corp.
* (c) Copyright 1993,1994,1996 Sun Microsystems, Inc.
* (c) Copyright 1993,1994,1996 Novell, Inc.
* (c) Copyright 1996 FUJITSU LIMITED.
* (c) Copyright 1996 Hitachi.
*/
/************************************<+>*************************************
****************************************************************************
**
** File: WmSetTitle.c
**
** Project: DT Workspace Manager
**
** Description: Set the title for a workspace
**
****************************************************************************
************************************<+>*************************************/
#include <stdio.h>
#include <X11/Intrinsic.h>
#include <Dt/Wsm.h>
#include <Dt/WsmP.h>
#include <Dt/WsmM.h>
#include <Dt/Service.h>
#include <Xm/Xm.h>
#include <Xm/AtomMgr.h>
#include <Tt/tttk.h>
/*************************************<->*************************************
*
* int DtWsmSetWorkspaceTitle (widget, aWs, pchNewName)
*
*
* Description:
* -----------
* Rename a workspace
*
*
* Inputs:
* ------
* widget - a widget
* aWs - atom of workspace
* pchNewName - new name for the workspace
*
* Outputs:
* --------
* Return - Success if communication to workspace manager
* was successful. Note that this is *not* the same
* value _DtWsmSetWorkspaceTitle returns.
*
* Comments:
* ---------
* public interface to _DtWsmSetWorkspaceTitle()
*
*************************************<->***********************************/
int
DtWsmSetWorkspaceTitle (
Widget widget,
Atom aWs,
char * pchNewName)
{
int rcode = _DtWsmSetWorkspaceTitle(widget, aWs, pchNewName);
if (rcode == DT_SVC_SUCCESS)
return Success;
else /* rcode == DT_SVC_FAIL || rcode == dtmsg_FAIL */
return rcode;
}
/*************************************<->*************************************
*
* int _DtWsmSetWorkspaceTitle (widget, aWs, pchNewName)
*
*
* Description:
* -----------
* Rename a workspace
*
*
* Inputs:
* ------
* widget - a widget
* aWs - atom of workspace
* pchNewName - new name for the workspace
*
* Outputs:
* --------
* Return - 1 (*not* Success) if communication to workspace manager
* was successful.
*
* Comments:
* ---------
* The odd-ball successful return value is a CDE 1.0 bug being
* preserved for backward compatibility.
*
*************************************<->***********************************/
int
_DtWsmSetWorkspaceTitle (
Widget widget,
Atom aWs,
char * pchNewName)
{
Tt_status status;
Tt_message msg;
char pch[40];
sprintf (pch, "0x%lx", aWs);
msg = tttk_message_create(0, TT_REQUEST, TT_SESSION, 0,
"DtWorkspace_Title_Set", 0);
status = tt_ptr_error(msg);
if (status != TT_OK) {
return DT_SVC_FAIL;
}
status = tt_message_arg_add(msg, TT_IN, "integer", NULL);
if (status != TT_OK) {
return DT_SVC_FAIL;
}
status = tt_message_arg_ival_set(msg, 0,
XScreenNumberOfScreen(XtScreen(widget)) % 1000);
if (status != TT_OK) {
return DT_SVC_FAIL;
}
status = tt_message_arg_add(msg, TT_IN, Tttk_string, pch);
if (status != TT_OK) {
return DT_SVC_FAIL;
}
status = tt_message_arg_add(msg, TT_IN, Tttk_string, pchNewName);
if (status != TT_OK) {
return DT_SVC_FAIL;
}
status = tt_message_callback_add(msg, _DtWsmConsumeReply);
if (status != TT_OK) {
return dtmsg_FAIL;
}
status = tt_message_send(msg);
if (status != TT_OK) {
return DT_SVC_FAIL;
}
return DT_SVC_SUCCESS;
} /* END OF FUNCTION DtWsmSetWorkspaceTitle */

View File

@@ -0,0 +1,112 @@
/* $XConsortium: WmSetWs.c /main/6 1996/06/21 17:24:17 ageorge $
*
* (c) Copyright 1996 Digital Equipment Corporation.
* (c) Copyright 1993,1994,1996 Hewlett-Packard Company.
* (c) Copyright 1993,1994,1996 International Business Machines Corp.
* (c) Copyright 1993,1994,1996 Sun Microsystems, Inc.
* (c) Copyright 1993,1994,1996 Novell, Inc.
* (c) Copyright 1996 FUJITSU LIMITED.
* (c) Copyright 1996 Hitachi.
*/
/************************************<+>*************************************
****************************************************************************
**
** File: WmSetWs.c
**
** Project: DT Workspace Manager
**
** Description: Set the current workspace
**
****************************************************************************
************************************<+>*************************************/
#include <stdio.h>
#include <X11/Intrinsic.h>
#include <Dt/Wsm.h>
#include <Dt/WsmP.h>
#include <Dt/WsmM.h>
#include <Dt/Service.h>
#include <Xm/Xm.h>
#include <Xm/AtomMgr.h>
#include <Tt/tttk.h>
#include "DtSvcLock.h"
/*************************************<->*************************************
*
* int DtWsmSetCurrentWorkspace (widget, aWs)
*
*
* Description:
* -----------
* Set the current workspace
*
*
* Inputs:
* ------
* screen_num - screen number, integer
* aWs - atom of workspace
*
* Outputs:
* --------
* Return - 1 (*not* Success) if communication to workspace manager
* was successful.
*
* Comments:
* ---------
* The odd-ball successful return value is a CDE 1.0 bug being
* preserved for backward compatibility.
*
*************************************<->***********************************/
int
DtWsmSetCurrentWorkspace (
Widget widget,
Atom aWs)
{
String pStr[2];
char pch[40];
Tt_message msg;
Tt_status status;
_DtSvcWidgetToAppContext(widget);
_DtSvcAppLock(app);
sprintf (pch, "0x%lx", aWs);
pStr[0] = (String) &pch[0];
pStr[1] = NULL;
msg = tttk_message_create(0, TT_REQUEST, TT_SESSION, 0,
"DtWorkspace_SetCurrent", 0);
status = tt_ptr_error(msg);
if (status != TT_OK) {
_DtSvcAppUnlock(app);
return dtmsg_FAIL;
}
status = tt_message_arg_add(msg, TT_IN, "integer", NULL);
if (status != TT_OK) {
_DtSvcAppUnlock(app);
return dtmsg_FAIL;
}
status = tt_message_arg_ival_set(msg, 0,
XScreenNumberOfScreen(XtScreen(widget)) % 1000);
if (status != TT_OK) {
_DtSvcAppUnlock(app);
return dtmsg_FAIL;
}
status = tt_message_arg_add(msg, TT_IN, Tttk_string, pStr[0]);
if (status != TT_OK) {
_DtSvcAppUnlock(app);
return dtmsg_FAIL;
}
status = tt_message_callback_add(msg, _DtWsmConsumeReply);
if (status != TT_OK) {
_DtSvcAppUnlock(app);
return dtmsg_FAIL;
}
status = tt_message_send(msg);
if (status != TT_OK) {
_DtSvcAppUnlock(app);
return dtmsg_FAIL;
}
_DtSvcAppUnlock(app);
return (dtmsg_SUCCESS);
} /* END OF FUNCTION DtWsmSetCurrentWorkspace */

View File

@@ -0,0 +1,475 @@
/************************************<+>*************************************
****************************************************************************
**
** File: WmWsCallB.c
**
** RCS: $XConsortium: WmWsCallB.c /main/6 1996/11/06 18:42:04 drk $
**
** Project: DT Workspace Manager
**
** Description: Workspace change callback functions
**
** (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.
**
****************************************************************************
************************************<+>*************************************/
#include <Tt/tttk.h>
#include <Dt/Service.h>
#include <Dt/Wsm.h>
#include <Dt/WsmM.h>
#include "WsmP.h"
#include "DtSvcLock.h"
/*************************************<->*************************************
*
* DtWsmWsModifiedProc _DtWsmWsChangeHandler (widget, aWS,
* reason, client_data);
*
*
* Description:
* -----------
* Internal function called when workspace changes.
*
*
* Inputs:
* ------
* widget - widget (for window where service is registered)
* aWS - Atom for workspace identification
* reason - type of workspace modification
* client_data - pointer to data
*
* Outputs:
* --------
* Return - none
*
* Comments:
* ---------
*
*************************************<->***********************************/
static void
_DtWsmWsChangeHandler (
Widget widget,
Atom aWS,
DtWsmWsReason reason,
XtPointer client_data)
{
struct _DtWsmCBContext *pCbCtx;
pCbCtx = (struct _DtWsmCBContext *) client_data;
/*
* We only deal with the workspace changes
*/
if (reason == DtWSM_REASON_CURRENT)
{
/*
* Call registered callback function.
*/
(*(pCbCtx->ws_cb)) (pCbCtx->widget, aWS,
pCbCtx->client_data);
}
} /* END OF FUNCTION _DtWsmWsChangeHandler */
/*************************************<->*************************************
*
* DtWsmCBContext * DtWsmAddCurrentWorkspaceCallback (widget,
* ws_change,
* client_data)
*
*
* Description:
* -----------
* Register a function to be called when the workspace changes.
*
*
* Inputs:
* ------
* widget - widget for this client
* ws_change - function to call when workspace changes
* client_data - additional data to pass back to client when called.
*
* Outputs:
* --------
* Return - ptr to callback context data (opaque)
*
* Comments:
* ---------
* The callback context data ptr should be saved if you intend to
* removed this callback at some point in the future.
*
*************************************<->***********************************/
DtWsmCBContext
DtWsmAddCurrentWorkspaceCallback (
Widget widget,
DtWsmWsChangeProc ws_change,
XtPointer client_data)
{
struct _DtWsmCBContext *pCbCtx;
_DtSvcWidgetToAppContext(widget);
_DtSvcAppLock(app);
/*
* Allocate data to remember stuff about this callback
*/
pCbCtx = (struct _DtWsmCBContext * )
XtMalloc (sizeof(struct _DtWsmCBContext));
/*
* Save what we want to remember
*/
pCbCtx->widget = widget;
pCbCtx->ws_cb = ws_change;
pCbCtx->client_data = client_data;
/*
* Register interest in the workspace change message
*/
pCbCtx->nested_context = (XtPointer)
DtWsmAddWorkspaceModifiedCallback (widget,
(DtWsmWsModifiedProc)_DtWsmWsChangeHandler,
(XtPointer) pCbCtx);
_DtSvcAppUnlock(app);
return (pCbCtx);
} /* END OF FUNCTION DtWsmAddCurrentWorkspaceCallback */
/*
----------------------------------------------------------------------
*/
/*************************************<->*************************************
*
* Tt_callback_action _WsModifiedCB (Tt_message m, tt_pattern p)
*
*
* Description:
* -----------
* Internal function called when a workspace is modified.
*
*
* Inputs:
* ------
* m - ToolTalk message
* p - ToolTalk pattern
*
* Outputs:
* --------
* Return - ToolTalk callback status
*
* Comments:
* ---------
*
*************************************<->***********************************/
static Tt_callback_action
_WsModifiedCB (Tt_message m, Tt_pattern p)
{
struct _DtWsmCBContext *pCbCtx;
Atom aWs;
DtWsmWsReason reason;
Widget widget;
DtWsmWsModifiedProc ws_modify;
XtPointer client_data;
/*
* user data 0: Widget widget;
* user data 1: DtWsmWsModifiedProc ws_modify;
* user data 2: XtPointer client_data;
*/
widget = (Widget)tt_pattern_user(p, 0);
ws_modify = (DtWsmWsModifiedProc)tt_pattern_user(p, 1);
client_data = (XtPointer)tt_pattern_user(p, 2);
/*
* 0th arg: screen number, string, not used
*/
/*
* Convert the atom to binary.
*/
aWs = (Atom)strtoul(tt_message_arg_val(m, 1), (char **)NULL, 0);
/*
* Convert "reason" of workspace modification
*/
reason = (DtWsmWsReason)strtoul(tt_message_arg_val(m, 2), (char **)NULL, 0);
/*
* Call registered callback function.
*/
(*ws_modify)(widget, aWs, reason, client_data);
return TT_CALLBACK_PROCESSED;
} /* END OF FUNCTION _DtWsmWsModifyHandler */
/*************************************<->*************************************
*
* DtWsmCBContext * DtWsmAddWorkspaceModifiedCallback (widget,
* ws_modify,
* client_data)
*
*
* Description:
* -----------
* Register a function to be called when the workspace is modified.
*
*
* Inputs:
* ------
* widget - widget for this client
* ws_modify - function to call when workspace is modified
* client_data - additional data to pass back to client when called.
*
* Outputs:
* --------
* Return - ptr to callback context data (opaque)
*
* Comments:
* ---------
* The callback context data ptr should be saved if you intend to
* removed this callback at some point in the future.
*
*************************************<->***********************************/
DtWsmCBContext
DtWsmAddWorkspaceModifiedCallback (
Widget widget,
DtWsmWsModifiedProc ws_modify,
XtPointer client_data)
{
struct _DtWsmCBContext *pCbCtx;
int screen;
String sName;
char sNum[32];
Tt_status status;
Tt_pattern pattern;
char * sessId;
_DtSvcWidgetToAppContext(widget);
_DtSvcAppLock(app);
/*
* This function register a ToolTalk pattern for every
* callback added.
*/
_DtSvcInitToolTalk(widget);
pattern = tt_pattern_create();
status = tt_ptr_error(pattern);
if (status != TT_OK) {
_DtSvcAppUnlock(app);
return NULL;
}
if (tt_pattern_scope_add(pattern, TT_SESSION) != TT_OK) {
_DtSvcAppUnlock(app);
return NULL;
}
if (tt_pattern_category_set(pattern, TT_OBSERVE) != TT_OK) {
_DtSvcAppUnlock(app);
return NULL;
}
if (tt_pattern_class_add(pattern, TT_NOTICE) != TT_OK) {
_DtSvcAppUnlock(app);
return NULL;
}
if (tt_pattern_state_add(pattern, TT_SENT) != TT_OK) {
_DtSvcAppUnlock(app);
return NULL;
}
sessId = tt_default_session();
if (tt_pattern_session_add(pattern, sessId) != TT_OK) {
_DtSvcAppUnlock(app);
return NULL;
}
tt_free( sessId );
screen = XScreenNumberOfScreen(XtScreen(widget));
sprintf(sNum, "%d", screen);
sName = _DtWsmSelectionNameForScreen (screen);
/*
* Only receive DtWorkspace_Modified notice from the screen
* we registered with.
*/
status = tt_pattern_arg_add(pattern, TT_IN, Tttk_string, sNum);
if (status != TT_OK) {
_DtSvcAppUnlock(app);
return NULL;
}
if (tt_pattern_op_add(pattern, "DtWorkspace_Modified") != TT_OK) {
_DtSvcAppUnlock(app);
return NULL;
}
/*
* Store information needed by the callback in the user data
* fields of the pattern.
*/
status = tt_pattern_user_set(pattern, 0, (void *)widget);
if (status != TT_OK) {
_DtSvcAppUnlock(app);
return NULL;
}
status = tt_pattern_user_set(pattern, 1, (void *)ws_modify);
if (status != TT_OK) {
_DtSvcAppUnlock(app);
return NULL;
}
status = tt_pattern_user_set(pattern, 2, (void *)client_data);
if (status != TT_OK) {
_DtSvcAppUnlock(app);
return NULL;
}
/*
* _WsModifiedCB is the ToolTalk callback which will call
* the user callback.
*/
if (tt_pattern_callback_add(pattern, _WsModifiedCB) != TT_OK) {
_DtSvcAppUnlock(app);
return NULL;
}
if (tt_pattern_register(pattern) != TT_OK) {
_DtSvcAppUnlock(app);
return NULL;
}
/*
* Allocate data to remember stuff about this callback
*/
pCbCtx = (struct _DtWsmCBContext * )
XtMalloc (sizeof(struct _DtWsmCBContext));
/*
* Save what we want to remember
*/
pCbCtx->pattern = pattern;
pCbCtx->widget = widget;
pCbCtx->ws_cb = ws_modify;
pCbCtx->client_data = client_data;
pCbCtx->nested_context = NULL;
XtFree (sName);
_DtSvcAppUnlock(app);
return (pCbCtx);
} /* END OF FUNCTION DtWsmAddWorkspaceModifiedCallback */
/*************************************<->*************************************
*
* DtWsmRemoveWorkspaceCallback (pCbCtx)
*
* Description:
* -----------
* Unregister a workspace callback.
*
*
* Inputs:
* ------
* pCbCtx - ptr to context returned when callback added
*
* Outputs:
* --------
* Return - none
*
* Comments:
* ---------
*
*************************************<->***********************************/
void
DtWsmRemoveWorkspaceCallback (DtWsmCBContext pCbCtx)
{
/*
* Is this somewhat valid?
*/
if (pCbCtx && (pCbCtx->widget != NULL)) {
_DtSvcWidgetToAppContext(pCbCtx->widget);
_DtSvcAppLock(app);
if (pCbCtx->nested_context) {
/*
* This was a convenience callback for just the workspace
* change info.
*/
DtWsmRemoveWorkspaceCallback (
(DtWsmCBContext) pCbCtx->nested_context);
}
else {
/*
* Unregister interest in this message
*/
tt_pattern_destroy(pCbCtx->pattern);
}
/*
* Free previously allocated data
*/
XtFree((char *) pCbCtx);
_DtSvcAppUnlock(app);
}
} /* END OF FUNCTION DtWsmRemoveWorkspaceCallback */
/*************************************<->*************************************
*
* _DtWsmSelectionNameForScreen (scr)
*
* Description:
* -----------
* Returns a string containing the selection name used for
* communication with the workspace manager on this screen
*
*
* Inputs:
* ------
* scr - number of screen
*
* Outputs:
* --------
* Return - ptr to string with selection name (free with XtFree)
*
* Comments:
* ---------
* Assumes the screen number is < 1000.
*
*************************************<->***********************************/
String
_DtWsmSelectionNameForScreen (
int scr)
{
String sName;
sName = (String) XtMalloc (strlen(DtWSM_TOOL_CLASS) + 4 + 1);
sprintf ((char *)sName, "%s_%d", DtWSM_TOOL_CLASS, (scr % 1000));
return (sName);
} /* END OF FUNCTION _DtWsmSelectionNameForScreen */
Tt_callback_action
_DtWsmConsumeReply(
Tt_message msg,
Tt_pattern pat )
{
switch (tt_message_state( msg )) {
case TT_HANDLED:
case TT_FAILED:
tttk_message_destroy( msg );
return TT_CALLBACK_PROCESSED;
default:
return TT_CALLBACK_CONTINUE;
}
}

View File

@@ -0,0 +1,268 @@
/* $XConsortium: WmWsHints.c /main/5 1996/05/20 16:08:33 drk $
*
* (c) Copyright 1996 Digital Equipment Corporation.
* (c) Copyright 1993,1994,1996 Hewlett-Packard Company.
* (c) Copyright 1993,1994,1996 International Business Machines Corp.
* (c) Copyright 1993,1994,1996 Sun Microsystems, Inc.
* (c) Copyright 1993,1994,1996 Novell, Inc.
* (c) Copyright 1996 FUJITSU LIMITED.
* (c) Copyright 1996 Hitachi.
*/
/************************************<+>*************************************
****************************************************************************
**
** File: WmWsHints.c
**
** Project: DT Workspace Manager
**
** Description: Set and Get workspace hints.
**
****************************************************************************
************************************<+>*************************************/
#include <stdio.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <Dt/Wsm.h>
#include <Dt/WsmP.h>
#include <Xm/Xm.h>
#include <Xm/AtomMgr.h>
/*************************************<->*************************************
*
* _DtWsmSetWorkspaceHints (display, window, pWsHints)
*
*
* Description:
* -----------
* Set the contents of the _DT_WORKSPACE_HINTS property on a window
*
*
* Inputs:
* ------
* display - display
* window - window to get hints from
* pWsHints - pointer to workspace hints
*
* Comments:
* ---------
* The internal form of the property is a structure. The structure
* must be unwound and turned into a simple array of "long"s before
* being written out.
*
* This function currently only deals with version 1 of the property
* structure. The passed in pWsHints->version is ignored.
*
*************************************<->***********************************/
void
_DtWsmSetWorkspaceHints(
Display *display,
Window window,
DtWorkspaceHints *pWsHints)
{
unsigned int iSizeWsHints;
Atom property;
long *pPropValue, *pP;
int i;
/*
* Unwind structure into a simple array of longs.
*
* Compute size of property to write (don't count
* pointer to workspaces, it will be unwound).
*/
iSizeWsHints = sizeof(DtWorkspaceHints) - sizeof(long);
if (pWsHints->flags & DT_WORKSPACE_HINTS_WORKSPACES)
{
iSizeWsHints += pWsHints->numWorkspaces * sizeof(long);
}
pP = pPropValue = (long *) XtMalloc (iSizeWsHints);
*pP++ = 1; /* only deals with version 1 !! */
*pP++ = pWsHints->flags;
if (pWsHints->flags & DT_WORKSPACE_HINTS_WSFLAGS)
*pP++ = pWsHints->wsflags;
else
*pP++ = 0L;
if (pWsHints->flags & DT_WORKSPACE_HINTS_WORKSPACES)
{
*pP++ = pWsHints->numWorkspaces;
for (i=0; i<pWsHints->numWorkspaces; i++)
{
*pP++ = pWsHints->pWorkspaces[i];
}
}
else
{
*pP++ = 0L; /* numWorkspaces */
}
property = XmInternAtom (display, _XA_DT_WORKSPACE_HINTS, False);
XChangeProperty (display, window, property,
property, 32, PropModeReplace,
(unsigned char *)pPropValue, (iSizeWsHints/sizeof(long)));
}
/*************************************<->*************************************
*
* int _DtWsmGetWorkspaceHints (display, window, ppWsHints)
*
*
* Description:
* -----------
* Get the contents of the _DT_WORKSPACE_HINTS property from a window
*
*
* Inputs:
* ------
* display - display
* window - window to get hints from
* ppWsHints - pointer to pointer to workspace hints
*
* Outputs:
* *ppWsHints - allocated workspace hints data.
*
* Comments:
* ---------
* The internal form of the property is a structure. The property
* is read in and packed into data allocated for the structure.
* Free the workspace hints by calling _DtWsmFreeWorkspaceHints.
*
* This function currently only deals with version 1 of the property
* structure.
*
*************************************<->***********************************/
int
_DtWsmGetWorkspaceHints(
Display *display,
Window window,
DtWorkspaceHints **ppWsHints)
{
unsigned int iSizeWsHints;
Atom property;
DtWorkspaceHints *pWsH;
long *pP = NULL;
long *pProp = NULL;
int i;
Atom actualType;
int actualFormat;
unsigned long leftover, lcount;
int rcode;
property = XmInternAtom (display, _XA_DT_WORKSPACE_HINTS, False);
if ((rcode = XGetWindowProperty(
display,
window,
property,
0L,
(long)BUFSIZ,
False,
property,
&actualType,
&actualFormat,
&lcount,
&leftover,
(unsigned char **)&pProp))==Success)
{
if (actualType != property)
{
/* wrong type, force failure */
rcode = BadValue;
}
else
{
pP = pProp;
pWsH = (DtWorkspaceHints *)
XtMalloc (sizeof(DtWorkspaceHints) * sizeof(long));
pWsH->version = *pP++;
/*
* Only handles version 1
*
* (Fudge the test a little so that newer versions
* won't be treated as older versions. This assumes
* that customers will migrate their software after
* a couple of revisions of these hints.)
*/
if (pWsH->version > 5)
{
/*
* Assume old version of hints which was a simple
* list of atoms.
*/
pWsH->version = 1;
pWsH->flags = DT_WORKSPACE_HINTS_WORKSPACES;
pWsH->wsflags = 0;
pWsH->numWorkspaces = lcount;
/* reset pointer to first atom in list */
pP--;
}
else
{
pWsH->flags = *pP++;
pWsH->wsflags = *pP++;
pWsH->numWorkspaces = *pP++;
}
if (pWsH->flags & DT_WORKSPACE_HINTS_WORKSPACES)
{
pWsH->pWorkspaces = (Atom *)
XtMalloc (pWsH->numWorkspaces * sizeof (Atom));
for (i=0; i<pWsH->numWorkspaces; i++)
{
pWsH->pWorkspaces[i] = *pP++;
}
}
else
{
pWsH->pWorkspaces = NULL;
}
*ppWsHints = pWsH;
}
if (pProp && (actualType != None))
{
XFree ((char *)pProp);
}
}
return (rcode);
}
/*************************************<->*************************************
*
* _DtWsmFreeWorkspaceHints (pWsHints)
*
*
* Description:
* -----------
* Free a workspace hints structure returned from _DtWsmGetWorkspaceHints
*
* Inputs:
* ------
* pWsHints - pointer to workspace hints
*
* Outputs:
*
* Comments:
* ---------
*************************************<->***********************************/
void
_DtWsmFreeWorkspaceHints(
DtWorkspaceHints *pWsHints)
{
if (pWsHints)
{
if (pWsHints->pWorkspaces)
{
XtFree ((char *) pWsHints->pWorkspaces);
}
XtFree ((char *)pWsHints);
}
}

View File

@@ -0,0 +1,353 @@
/* $XConsortium: WmWsOccupy.c /main/6 1996/06/21 17:24:10 ageorge $
*
* (c) Copyright 1996 Digital Equipment Corporation.
* (c) Copyright 1993,1994,1996 Hewlett-Packard Company.
* (c) Copyright 1993,1994,1996 International Business Machines Corp.
* (c) Copyright 1993,1994,1996 Sun Microsystems, Inc.
* (c) Copyright 1993,1994,1996 Novell, Inc.
* (c) Copyright 1996 FUJITSU LIMITED.
* (c) Copyright 1996 Hitachi.
*/
/************************************<+>*************************************
****************************************************************************
**
** File: WmWsOccupy.c
**
** Project: DT Workspace Manager
**
** Description: Get/Set workspace occupancy of a window
**
****************************************************************************
************************************<+>*************************************/
#include <stdio.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <Dt/Wsm.h>
#include <Dt/WsmP.h>
#include <Xm/Xm.h>
#include <Xm/AtomMgr.h>
#include "DtSvcLock.h"
/******** Public Function Declarations ********/
extern int DtGetWorkspacesOccupied(
Display *display,
Window window,
Atom **ppaWs,
unsigned long *pNumWs) ;
extern void DtWsmSetWorkspacesOccupied(
Display *display,
Window window,
Atom *pWsHints,
unsigned long numHints) ;
/******** End Public Function Declarations ********/
/******** Static Function Declarations ********/
static int _GetWorkspacesOccupied(
Display *display,
Window window,
Atom **ppaWs,
unsigned long *pNumWs,
Atom property) ;
#ifdef HP_VUE
static int _GetWorkspacePresence(
Display *display,
Window window,
Atom **ppWsPresence,
unsigned long *pNumPresence,
Atom property ) ;
#endif /* HP_VUE */
/******** End Static Function Declarations ********/
/*************************************<->*************************************
*
* int _GetWorkspacesOccupied (display, window, ppaWs,
* pNumWs, property)
*
*
* Description:
* -----------
* Get the contents of a property on a window that is a list of atoms
*
*
* Inputs:
* ------
* display - display
* window - window to get hints from
* ppaWs - pointer to a pointer to return
* pNumWs - pointer to a number to return
* property - the property atom
*
* Outputs:
* --------
* *ppaWs - points to the list of workspace info structures
* (NOTE: This should be freed using XFree)
* *pNumWs - the number of workspace info structure in the list
* Return - status from XGetWindowProperty
*
* Comments:
* ---------
* Assumes that less than BUFSIZ bytes will be returned. This code
* won't work for very large amounts of info (lots of workspaces).
*
*************************************<->***********************************/
static int
_GetWorkspacesOccupied(
Display *display,
Window window,
Atom **ppaWs,
unsigned long *pNumWs,
Atom property )
{
Atom actualType;
int actualFormat;
unsigned long leftover;
int rcode;
*ppaWs = NULL;
if ((rcode=XGetWindowProperty(display,window,
property,0L, (long)BUFSIZ,
False,property,
&actualType,&actualFormat,
pNumWs,&leftover,(unsigned char **)ppaWs))==Success)
{
if (actualType != property)
{
/* wrong type, force failure */
*pNumWs = 0;
rcode = BadValue;
if (actualType != None)
{
XFree ((char *)*ppaWs);
}
}
}
return(rcode);
} /* END OF FUNCTION GetWorkspacesOccupied */
#ifdef HP_VUE
/*************************************<->*************************************
*
* int _GetWorkspacePresence (display, window, ppWsPresence,
* pNumPresence, property)
*
*
* Description:
* -----------
* Get the contents of the _DT_WORKSPACE_PRESENCE property on a window
*
*
* Inputs:
* ------
* display - display
* window - window to get hints from
* ppWsPresence - pointer to a pointer to return
* pNumPresence - pointer to a number to return
* property - the property atom
*
* Outputs:
* --------
* *ppWsPresence - points to the list of workspace info structures
* (NOTE: This should be freed using XFree)
* *pNumPresence - the number of workspace info structure in the list
* Return - status from XGetWindowProperty
*
* Comments:
* ---------
* Assumes that less than BUFSIZ bytes will be returned. This code
* won't work for very large amounts of info (lots of workspaces).
*
*************************************<->***********************************/
static int
_GetWorkspacePresence(
Display *display,
Window window,
Atom **ppWsPresence,
unsigned long *pNumPresence,
Atom property )
{
Atom actualType;
int actualFormat;
unsigned long leftover;
int rcode;
*ppWsPresence = NULL;
if ((rcode=XGetWindowProperty(display,window,
property,0L, (long)BUFSIZ,
False,property,
&actualType,&actualFormat,
pNumPresence,&leftover,(unsigned char **)ppWsPresence))==Success)
{
if (actualType != property)
{
/* wrong type, force failure */
*pNumPresence = 0;
rcode = BadValue;
if (actualType != None)
{
XFree ((char *)*ppWsPresence);
}
}
}
return(rcode);
} /* END OF FUNCTION GetWorkspacePresence */
#endif /* HP_VUE */
/*************************************<->*************************************
*
* int DtWsmGetWorkspacesOccupied (display, window, ppaWs, pNumWs)
*
*
* Description:
* -----------
* Get the list of workspaces that this window is in.
*
*
* Inputs:
* ------
* display - display
* window - window to get info from
* ppaWs - pointer to an atom pointer (to be returned)
* pNumWs - pointer to a number (to be returned)
*
* Outputs:
* -------
* *ppaWs - pointer to a list of workspace atoms
* (NOTE: This should be freed using XFree)
* *pNumWs - number of workspace in the list
* Return - Success if something returned
* not Success otherwise.
*
* Comments:
* --------
* Use XFree to free the returned data.
*
*************************************<->***********************************/
int
DtWsmGetWorkspacesOccupied(
Display *display,
Window window,
Atom **ppaWs,
unsigned long *pNumWs)
{
int rcode;
_DtSvcDisplayToAppContext(display);
_DtSvcAppLock(app);
rcode = _GetWorkspacesOccupied (display, window, ppaWs,
pNumWs,
XmInternAtom(display, _XA_DT_WORKSPACE_PRESENCE,
False));
#ifdef HP_VUE
/*
* Be compatible with HP VUE
*/
if (rcode != Success)
{
rcode = _GetWorkspacePresence (display, window, ppaWs,
pNumWs,
XmInternAtom(display, _XA_VUE_WORKSPACE_PRESENCE,
False));
}
#endif /* HP_VUE */
_DtSvcAppUnlock(app);
return (rcode);
}
/*************************************<->*************************************
*
* DtWsmSetWorkspacesOccupied (display, window, pWsHints, numHints)
*
*
* Description:
* -----------
* Set the set of workspaces to be occupied by this client.
*
*
* Inputs:
* ------
* display - display
* window - window to get hints from
* pWsHints - pointer to a list of workspace atoms
* numHints - number of atoms in list
*
* Comments:
* ---------
* No error checking
*
*************************************<->***********************************/
void
DtWsmSetWorkspacesOccupied(
Display *display,
Window window,
Atom *pWsHints,
unsigned long numHints )
{
DtWorkspaceHints wsh;
_DtSvcDisplayToAppContext(display);
_DtSvcAppLock(app);
wsh.flags = DT_WORKSPACE_HINTS_WORKSPACES;
wsh.pWorkspaces = pWsHints;
wsh.numWorkspaces = numHints;
_DtWsmSetWorkspaceHints(display, window, &wsh);
_DtSvcAppUnlock(app);
}
/*************************************<->*************************************
*
* DtWsmOccupyAllWorkspaces (display, window)
*
*
* Description:
* -----------
* Occupy all the workspaces on this screen (including new ones
* as they are created)
*
*
* Inputs:
* ------
* display - display
* window - window to get hints from
*
* Comments:
* ---------
*
*************************************<->***********************************/
void
DtWsmOccupyAllWorkspaces(
Display *display,
Window window)
{
DtWorkspaceHints wsh;
_DtSvcDisplayToAppContext(display);
_DtSvcAppLock(app);
wsh.flags = DT_WORKSPACE_HINTS_WSFLAGS;
wsh.wsflags = DT_WORKSPACE_FLAGS_OCCUPY_ALL;
_DtWsmSetWorkspaceHints(display, window, &wsh);
_DtSvcAppUnlock(app);
}

167
cde/lib/DtSvc/DtUtil1/Wsm.h Normal file
View File

@@ -0,0 +1,167 @@
/* $XConsortium: Wsm.h /main/5 1996/05/20 16:08:50 drk $
*
* (c) Copyright 1996 Digital Equipment Corporation.
* (c) Copyright 1993,1994,1996 Hewlett-Packard Company.
* (c) Copyright 1993,1994,1996 International Business Machines Corp.
* (c) Copyright 1993,1994,1996 Sun Microsystems, Inc.
* (c) Copyright 1993,1994,1996 Novell, Inc.
* (c) Copyright 1996 FUJITSU LIMITED.
* (c) Copyright 1996 Hitachi.
*/
#ifndef _Dt_Wsm_h
#define _Dt_Wsm_h
#include <X11/Intrinsic.h>
#ifdef __cplusplus
extern "C" {
#endif
/*
* Constants
*/
#define DtWSM_REASON_ADD 0
#define DtWSM_REASON_DELETE 1
#define DtWSM_REASON_BACKDROP 2
#define DtWSM_REASON_TITLE 3
#define DtWSM_REASON_CURRENT 4
/*
* Types
*/
/* Workspace property information */
typedef struct _DtWsmWorkspaceInfo {
Atom workspace;
unsigned long bg;
unsigned long fg;
Atom backdropName;
int colorSetId;
char *pchTitle;
Window *backdropWindows;
int numBackdropWindows;
} DtWsmWorkspaceInfo;
/* Workspace modified callback reasons */
typedef int DtWsmWsReason;
/* Workspace callback context (opaque) */
typedef struct _DtWsmCBContext * DtWsmCBContext;
/* Workspace callback prototype */
typedef void (*DtWsmWsChangeProc)(
Widget widget,
Atom aWs,
XtPointer client_data);
/* Workspace modified callback prototype */
typedef void (*DtWsmWsModifiedProc)(
Widget widget,
Atom aWs,
DtWsmWsReason reason,
XtPointer client_data);
/*
* Functions
*/
extern void DtWsmAddWorkspaceFunctions(
Display *display,
Window client);
extern void DtWsmRemoveWorkspaceFunctions(
Display *display,
Window client);
extern int DtWsmGetWorkspaceInfo(
Display *display,
Window root,
Atom aWS,
DtWsmWorkspaceInfo **ppWsInfo);
extern void DtWsmFreeWorkspaceInfo(
DtWsmWorkspaceInfo *pWsInfo);
extern int DtWsmGetWorkspaceList(
Display *display,
Window root,
Atom **ppWorkspaceList,
int *pNumWorkspaces);
extern int DtWsmGetCurrentWorkspace(
Display *display,
Window root,
Atom *paWorkspace);
extern DtWsmCBContext DtWsmAddCurrentWorkspaceCallback(
Widget widget,
DtWsmWsChangeProc ws_change,
XtPointer client_data);
extern void DtWsmRemoveWorkspaceCallback(
DtWsmCBContext pCbCtx);
extern int DtWsmSetCurrentWorkspace(
Widget widget,
Atom aWs);
extern int DtWsmGetWorkspacesOccupied(
Display *display,
Window window,
Atom **ppaWs,
unsigned long *pNumWs);
extern void DtWsmSetWorkspacesOccupied(
Display *display,
Window window,
Atom *pWsHints,
unsigned long numHints);
extern void DtWsmOccupyAllWorkspaces(
Display *display,
Window window);
extern DtWsmCBContext DtWsmAddWorkspaceModifiedCallback(
Widget widget,
DtWsmWsModifiedProc ws_modified,
XtPointer client_data);
extern Window DtWsmGetCurrentBackdropWindow(
Display *display,
Window root);
extern int DtWsmSetWorkspaceTitle(
Widget widget,
Atom aWs,
char *title);
extern int DtWsmChangeBackdrop(
Display *display,
Window root,
char *path,
Pixmap pixmap);
extern int DtWsmAddWorkspace(
Widget widget,
char *title);
extern int DtWsmDeleteWorkspace(
Widget widget,
Atom aWs);
#ifdef __cplusplus
}
#endif
#endif /* _Dt_Wsm_h */

View File

@@ -0,0 +1,111 @@
/*****************************<+>*************************************
*********************************************************************
**
** File: WsmM.h
**
** RCS: $XConsortium: WsmM.h /main/3 1995/10/26 15:14:36 rswiston $
** Project: DT Workspace Manager
**
** Description: Defines parameters necessary for messaging with
** the workspace manager.
**
** (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 _Dt_WsmM_h
#define _Dt_WsmM_h
/*
* Messaging definitions
*/
/* Workspace manager tool class (for old messages) */
#define DtWM_TOOL_CLASS "WORKSPACEMGR"
/* Workspace manager tool class (for new messages) */
#define DtWSM_TOOL_CLASS "WORKSPACE_MANAGER"
/* Workspace manager tool class (for front panel messages) */
#define DtFP_TOOL_CLASS "FRONTPANEL"
/* Request from dtstyle to change backdrop */
#define DtWM_BACKDROP_CHANGE "BACKDROP_CHANGE"
/* Request from session manager to unlock the display (depress button) */
#define DtWM_UNLOCK_DISPLAY "UNLOCK_DISPLAY"
/* Request from session manager to cancel an exit (depress button) */
#define DtWM_CANCEL_EXIT "CANCEL_EXIT"
/* Request from session manager to retore the front panel to default state */
#define DtWM_RESTORE_PANEL "RESTORE_PANEL"
/* Notification from Workspace manager of a new workspace */
#define DtWSM_NEW_WORKSPACE "ACTIVE_WORKSPACE"
#define DtWSM_NEW_WORKSPACE_ARG_NAME 0
#define DtWSM_NEW_WORKSPACE_ARG_ATOM 1
/* Request to set the current workspace */
#define DtWSM_SET_WORKSPACE "SET_WORKSPACE"
#define DtWSM_SET_WORKSPACE_ARG_ATOM 0
/* Request to change the title of a workspace */
#define DtWSM_SET_WORKSPACE_TITLE "SET_WORKSPACE_TITLE"
#define DtWSM_SET_WORKSPACE_TITLE_ARG_ATOM 0
#define DtWSM_SET_WORKSPACE_TITLE_ARG_TITLE 1
/* Request to add a workspace */
#define DtWSM_ADD_WORKSPACE "ADD_WORKSPACE"
#define DtWSM_ADD_WORKSPACE_ARG_TITLE 0
/* Request to delete a workspace */
#define DtWSM_DELETE_WORKSPACE "DELETE_WORKSPACE"
#define DtWSM_DELETE_WORKSPACE_ARG_ATOM 0
/* Notification from Workspace manager of a modified workspace */
#define DtWSM_MODIFY_WORKSPACE "MODIFY_WORKSPACE"
#define DtWSM_MODIFY_WORKSPACE_ARG_ATOM 0
#define DtWSM_MODIFY_WORKSPACE_ARG_TYPE 1
#define DtWSM_MODIFY_WORKSPACE_TYPE_ADD 0
#define DtWSM_MODIFY_WORKSPACE_TYPE_DELETE 1
#define DtWSM_MODIFY_WORKSPACE_TYPE_BACKDROP 2
#define DtWSM_MODIFY_WORKSPACE_TYPE_TITLE 3
#define DtWSM_MODIFY_WORKSPACE_TYPE_ACTIVE 4
/* Notification from Workspace manager of a modified workspace */
#define DtWSM_MARQUEE_SELECTION "MARQUEE_SELECTION"
#define DtWSM_MARQUEE_SELECTION_ARG_TYPE 0
#define DtWSM_MARQUEE_SELECTION_ARG_X 1
#define DtWSM_MARQUEE_SELECTION_ARG_Y 2
#define DtWSM_MARQUEE_SELECTION_ARG_WIDTH 3
#define DtWSM_MARQUEE_SELECTION_ARG_HEIGHT 4
#define DtWSM_MARQUEE_SELECTION_TYPE_BEGIN 1
#define DtWSM_MARQUEE_SELECTION_TYPE_CONTINUE 2
#define DtWSM_MARQUEE_SELECTION_TYPE_END 3
#define DtWSM_MARQUEE_SELECTION_TYPE_CANCEL 4
/*
* Macros to set and fetch argument fields into a message
*
* (NOTE: Since sending the request breaks out the zero'th
* field, there is a difference of one in these two macros.)
*/
#define DtWSM_SET_FIELD(fields,ix,value) ((fields)[(ix)]=(value))
#define DtWSM_GET_FIELD(fields,ix) ((fields)[((ix)+1)])
#endif /* _Dt_WsmM_h */
/* Do not add anything after this endif. */

View File

@@ -0,0 +1,913 @@
/* $XConsortium: WsmP.h /main/8 1996/05/20 16:08:59 drk $ */
/************************************<+>*************************************
****************************************************************************
**
** File: WsmP.h
**
** Project: DT Workspace Manager
**
** Description: Defines PRIVATE properties, structures, and
** parameters used for communication with the
** workspace manager. This also includes some
** backward compatibility stuff for HP_VUE.
**
** (c) Copyright 1996 Digital Equipment Corporation.
** (c) Copyright 1993,1994,1996 Hewlett-Packard Company.
** (c) Copyright 1993,1994,1996 International Business Machines Corp.
** (c) Copyright 1993,1994,1996 Sun Microsystems, Inc.
** (c) Copyright 1993,1994,1996 Novell, Inc.
** (c) Copyright 1996 FUJITSU LIMITED.
** (c) Copyright 1996 Hitachi.
**
****************************************************************************
************************************<+>*************************************/
#ifndef _Dt_WsmP_h
#define _Dt_WsmP_h
#include <Dt/Wsm.h>
#include <X11/Intrinsic.h>
#include <Dt/Service.h>
#include <Tt/tt_c.h>
/**********************************************************************
* Workspace atom names
**********************************************************************/
#define _XA_DT_MARQUEE_SELECTION "_DT_MARQUEE_SELECTION"
#define _XA_DT_WORKSPACE_EMBEDDED_CLIENTS \
"_DT_WORKSPACE_EMBEDDED_CLIENTS"
#define _XA_DT_WM_REQUEST "_DT_WM_REQUEST"
#define _XA_DT_WORKSPACE_HINTS "_DT_WORKSPACE_HINTS"
#define _XA_DT_WORKSPACE_PRESENCE "_DT_WORKSPACE_PRESENCE"
#define _XA_DT_WORKSPACE_INFO "_DT_WORKSPACE_INFO"
#define _XA_DT_WM_HINTS "_DT_WM_HINTS"
#define _XA_DT_WORKSPACE_LIST "_DT_WORKSPACE_LIST"
#define _XA_DT_WORKSPACE_CURRENT "_DT_WORKSPACE_CURRENT"
/**********************************************************************
* Name to request ``all'' workspaces (for a persistent window)
**********************************************************************/
#define _XA_DT_WORKSPACE_ALL "all"
/**********************************************************************
* Workspace function definitions
**********************************************************************/
#define DtWM_FUNC_OCCUPY_WS DtWM_FUNCTION_OCCUPY_WS
#define DtWM_FUNC_ALL DtWM_FUNC_OCCUPY_WS
/**********************************************************************
* Workspace property information
**********************************************************************/
/*
*
* NOTE: The "(client -> dtwm)" indication calls out the direction
* of information flow. In this case, the client writes the
* property and dtwm reads the property.
*
*
* _DT_WORKSPACE_HINTS (client -> dtwm)
*
* This property is a list of atoms placed by a client on its
* top level window(s). Each atom is an "interned" string name
* for a workspace. The workspace manager looks at this property
* when it manages the window (e.g. when the window is mapped)
* and will place the window in the workspaces listed.
*
* _DT_WORKSPACE_PRESENCE (dtwm -> client)
*
* This property is a list of atoms placed on a client by dtwm.
* Each atom is an "interned" string name for a workspace. This
* property lists the workspaces that this client lives in.
*
* _DT_WORKSPACE_LIST (dtwm -> clients)
*
* This property is a list of atoms. Each atom represents a
* name of a workspace. The list is in "order" such that
* the first element is for the first workspace and so on.
* This proeprty is placed on the mwm ("wmWindow") window.
*
* _DT_WORKSPACE_CURRENT (dtwm -> clients)
*
* This property is a single atom, representing the current
* workspace. It is updated each time the workspace changes.
* This proeprty is placed on the mwm window.
*
* _DT_WORKSPACE_INFO_<name> (dtwm -> clients)
*
* There is one property of this form for each workspace in
* _DT_WORKSPACE_LIST. This property is a sequence of ISO-LATIN1
* NULL-terminated strings representing the elements in a
* structure. This information was formerly in _DT_WORKSPACE_INFO
* but was broken out to allow for extensibility.
* This proeprty is placed on the mwm window.
*
* _DT_WM_HINTS (client -> dtwm)
*
* This property requests specific window/workspace management behavior.
* The functions member of the property allows a client to enable or
* disable workspace management functions. The behavior member is
* used to indicate front panels and slide-ups.
*
*/
/**********************************************************************
* Property structures
**********************************************************************/
typedef struct _DtWmHints
{
long flags; /* marks valid fields */
long functions; /* special dtwm functions */
long behaviors; /* special dtwm behaviors */
Window attachWindow; /* (reserved) */
} DtWmHints;
/* DtWmHints "flags" definitions */
#define DtWM_HINTS_FUNCTIONS (1L << 0)
#define DtWM_HINTS_BEHAVIORS (1L << 1)
#define DtWM_HINTS_ATTACH_WINDOW (1L << 2) /* (reserved) */
/* DtWmHints "functions" definitions */
#define DtWM_FUNCTION_ALL (1L << 0)
#define DtWM_FUNCTION_OCCUPY_WS (1L << 16)
/* DtWmHints "behaviors" definitions */
#define DtWM_BEHAVIOR_PANEL (1L << 1)
#define DtWM_BEHAVIOR_SUBPANEL (1L << 2)
#define DtWM_BEHAVIOR_SUB_RESTORED (1L << 3)
#ifdef HP_VUE
/*
* For Compatibility with some old HP VUE clients
*/
#define _XA_VUE_WORKSPACE_INFO "_VUE_WORKSPACE_INFO"
#define _XA_VUE_WORKSPACE_HINTS "_VUE_WORKSPACE_HINTS"
#define _XA_VUE_WORKSPACE_PRESENCE "_VUE_WORKSPACE_PRESENCE"
#define _XA_VUE_WM_REQUEST "_VUE_WM_REQUEST"
#define _XA_VUE_WM_HINTS "_VUE_WM_HINTS"
#endif /* HP_VUE */
/**********************************************************************
* Session atom names
**********************************************************************/
#define _XA_DT_SESSION_HINTS "_DT_SESSION_HINTS"
#define _XA_DT_SAVE_MODE "_DT_SAVE_MODE"
#define _XA_DT_RESTORE_MODE "_DT_RESTORE_MODE"
#define _XA_DT_RESTORE_DIR "_DT_RESTORE_DIR"
#define _XA_DT_SM_WM_PROTOCOL "_DT_SM_WM_PROTOCOL"
#define _XA_DT_SM_START_ACK_WINDOWS "_DT_SM_START_ACK_WINDOWS"
#define _XA_DT_SM_STOP_ACK_WINDOWS "_DT_SM_STOP_ACK_WINDOWS"
#define _XA_DT_WM_WINDOW_ACK "_DT_WM_WINDOW_ACK"
#define _XA_DT_WM_EXIT_SESSION "_DT_WM_EXIT_SESSION"
#define _XA_DT_WM_LOCK_DISPLAY "_DT_WM_LOCK_DISPLAY"
#define _XA_DT_WM_READY "_DT_WM_READY"
/**********************************************************************
* Workspace special character definitions
**********************************************************************/
#define DTWM_CH_ESC_NEXT "\\"
/**********************************************************************
* Marquee selection callback prototype
**********************************************************************/
typedef void (*DtWsmMarqueeSelectionProc) ();
/*
Widget widget;
int type;
Position x, y;
Dimension width, height;
XtPointer client_data;
*/
/**********************************************************************
* Marquee Select
**********************************************************************/
#define DT_WSM_MARQUEE_SELECTION_TYPE_BEGIN 1
#define DT_WSM_MARQUEE_SELECTION_TYPE_CONTINUE 2
#define DT_WSM_MARQUEE_SELECTION_TYPE_END 3
#define DT_WSM_MARQUEE_SELECTION_TYPE_CANCEL 4
/**********************************************************************
* Workspace request definitions
*
* NOTE: These functions do not necessarily match the other
* window manager f.* functions!
**********************************************************************/
#define DTWM_REQ_CHANGE_BACKDROP "f.change_backdrop"
#define DTWM_REQ_RESTART "f.restart"
/**********************************************************************
* Workspace request parameter definitions
**********************************************************************/
#define DTWM_REQP_BACKDROP_NONE "NoBackdrop"
#define DTWM_REQP_NO_CONFIRM "-noconfirm"
/**********************************************************************
* Resource converter definitions
*
* NOTE: This has been lifted from mwm.
* Please keep syncronized with the current version of mwm/dtwm.
* (See WmGlobal.h)
**********************************************************************/
/* icon placement values (iconPlacement, ...): */
#define ICON_PLACE_LEFT_PRIMARY (1L << 0)
#define ICON_PLACE_RIGHT_PRIMARY (1L << 1)
#define ICON_PLACE_TOP_PRIMARY (1L << 2)
#define ICON_PLACE_BOTTOM_PRIMARY (1L << 3)
#define ICON_PLACE_LEFT_SECONDARY (1L << 4)
#define ICON_PLACE_RIGHT_SECONDARY (1L << 5)
#define ICON_PLACE_TOP_SECONDARY (1L << 6)
#define ICON_PLACE_BOTTOM_SECONDARY (1L << 7)
#define ICON_PLACE_EDGE (1L << 8)
#define ICON_PLACE_TIGHT (1L << 9)
#define ICON_PLACE_RESERVE (1L << 10)
/**********************************************************************
* Workspace property information
**********************************************************************/
/*
*
* NOTE: The "(client -> dtwm)" indication calls out the direction
* of information flow. In this case, the client writes the
* property and dtwm reads the property.
*
*/
#ifdef HP_VUE
/*
* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
* % _VUE_WORKSPACE_INFO is obsolete, but maintained for %
* % backward compatiblity. Its function has been %
* % replaced by %
* % _DT_WORKSPACE_LIST %
* % _DT_WORKSPACE_INFO_<name> %
* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
* _VUE_WORKSPACE_INFO (dtwm -> client)
*
* This property is a list of structures that contain information
* on each workspace. Each structure contains the atom representing
* the workspace string name and the window id of the background
* window for the workspace (if any). The first workspace in the
* list is the "active" workspace for the screen. This property is
* placed on the window identified by the "wmWindow" member of
* the _MOTIF_WM_INFO property.
*/
#endif /* HP_VUE */
/*
*
* _DT_WM_REQUEST (client -> dtwm)
*
* This property of type string that is used to communication
* function requests to dtwm. This property is placed on the mwm
* window. Dtwm listens for changes to this property and dequeues
* requests off the top of the list. Requests are NULL-terminated
* strings in the format:
*
* <req_type> <req_parms>
*
* Each request ends with a literal '\0' character to insure
* separation from the next request.
*
* Clients must always add requests to the end of the property
* (mode=PropModeAppend). Use of convenience routines is
* recommended since they take care of proper formatting of the
* requests.
*
*/
/**********************************************************************
* Property structures
**********************************************************************/
/* Internal form of this property */
typedef struct _DtWorkspaceHints
{
long version; /* indicates structure changes */
long flags; /* marks valid fields */
long wsflags; /* special workspace information */
long numWorkspaces; /* number of workspaces */
Atom * pWorkspaces; /* list of atoms for workspaces */
} DtWorkspaceHints;
/* DtWorkspaceHints "flags" definitions */
#define DT_WORKSPACE_HINTS_WSFLAGS (1L << 0)
/* The following definitions enables both the numWorkspaces
and pWorkspaces fields */
#define DT_WORKSPACE_HINTS_WORKSPACES (1L << 1)
/* DtWorkspaceHints "wsflags" definitions */
#define DT_WORKSPACE_FLAGS_OCCUPY_ALL (1L << 0)
#ifdef HP_VUE
/*
* Obsolete WorkspaceInfo structure
*/
typedef struct _WorkspaceInfo
{
Atom workspace; /* workspace "name" */
Window backgroundWindow; /* backdrop window ID (if any) */
unsigned long bg; /* backdrop background pixel */
unsigned long fg; /* backdrop foreground pixel */
Atom backdropName; /* atomized name for backdrop */
} WorkspaceInfo;
#endif /* HP_VUE */
/**********************************************************************
* Marquee Selection Structures
**********************************************************************/
typedef struct _DtMarqueeSelectData
{
long state; /* current property state */
Position x; /* NW corner of select area */
Position y; /* NW corner of select area */
Dimension width; /* size of select area */
Dimension height; /* size of select area */
} DtMarqueeSelectData;
typedef struct _DtMarqueeSelectProp
{
long state; /* current property state */
long x; /* NW corner of select area */
long y; /* NW corner of select area */
long width; /* size of select area */
long height; /* size of select area */
} DtMarqueeSelectProperty;
/**********************************************************************
* Marquee Selection Definitions
**********************************************************************/
#define DT_MARQUEE_SELECT_BEGIN 1
#define DT_MARQUEE_SELECT_CONTINUE 2
#define DT_MARQUEE_SELECT_END 3
#define DT_MARQUEE_SELECT_CANCEL 4
/**********************************************************************
* Workspace change callback context (opaque)
**********************************************************************/
typedef void (*DtWsmCBProc) ();
struct _DtWsmCBContext
{
Tt_pattern pattern;
Widget widget;
DtWsmCBProc ws_cb;
XtPointer client_data;
XtPointer nested_context;
};
/**********************************************************************
* Convenience Routines
**********************************************************************/
#ifdef HP_VUE
/*************************************<->*************************************
*
* Status DtGetWorkspaceInfo (display, root, ppWsInfo, pNumInfo)
*
*
* Description:
* -----------
* Get the contents of the _DT_WORKSPACE_INFO property on a window
*
*
* Inputs:
* ------
* display - display
* root - root window of screen being managed
* ppWsInfo - pointer to a pointer (to be returned)
* pNumInfo - pointer to a number (to be returned)
*
* Outputs:
* -------
* *ppWsInfo - pointer to a list of workspace info structures
* *pNumInfo - number of workspace info structures in list
* Return - Success if property fetched ok.
* Failure returns are from XGetWindowProperty
*
*************************************<->***********************************/
extern Status
DtGetWorkspaceInfo(
Display *display,
Window root,
WorkspaceInfo **ppWsInfo,
unsigned long *pNumInfo) ;
#endif /* HP_VUE */
/*************************************<->*************************************
*
* int _DtGetMwmWindow (display, root, pMwmWindow)
*
*
* Description:
* -----------
* Get the Motif Window manager window
*
*
* Inputs:
* ------
* display - display
* root - root window of screen
* pMwmWindow - pointer to a window (to be returned)
*
* Outputs:
* --------
* *pMwmWindow - mwm window id, if successful
* Return - status from XGetWindowProperty
*
* Comments:
* --------
* This can fail if mwm is not managing the screen for the root window
* passed in.
*
*************************************<->***********************************/
extern int
_DtGetMwmWindow(
Display *display,
Window root,
Window *pMwmWindow) ;
/*************************************<->*************************************
*
* int _DtGetEmbeddedClients (display, root, ppEmbeddedClients,
* pNumEmbeddedClients)
*
*
* Description:
* -----------
* Get the contents of the _DT_WORKSPACE_EMBEDDED_CLIENTS property
* from a root window. This is a list (array) of top-level windows that
* are embedded in the front panel of the window manager. They would
* not be picked up ordinarily by a session manager in a normal
* search for top-level windows because they are reparented to
* the front panel which itself is a top-level window.
*
*
* Inputs:
* ------
* display - display
* root - root window to get info from
* ppEmbeddedClients - pointer to a pointer (to be returned)
* pNumEmbeddedClients - pointer to a number (to be returned)
*
* Outputs:
* -------
* *ppEmbeddedClients - pointer to a array of window IDs (top-level
* windows for embedded clients)
* (NOTE: This should be freed using XFree)
* *pNumEmbeddedClients- number of window IDs in array
* Return - Success if property fetched ok.
* Failure returns are from XGetWindowProperty
*
* Comments:
* --------
* Use XFree to free the returned data.
*
*************************************<->***********************************/
extern int
_DtGetEmbeddedClients(
Display *display,
Window root,
Atom **ppEmbeddedClients,
unsigned long *pNumEmbeddedClients );
/*************************************<->*************************************
*
* int _DtWmRestart (display, root)
*
*
* Description:
* -----------
* Requests the window manager to restart itself
*
*
* Inputs:
* ------
* display - display
* root - root window for screen
*
* Returns:
* --------
* Success if request was sent
*
* Comments:
* ---------
*
*************************************<->***********************************/
extern int
_DtWmRestart(
Display *display,
Window root) ;
/*************************************<->*************************************
*
* int _DtWsmChangeBackdrop (display, root, path, pixmap)
*
*
* Description:
* -----------
* Request the HP DT workspace manager to change the backdrop
*
*
* Inputs:
* ------
* display - display
* root - root window of screen
* path - file path to bitmap file
* pixmap - pixmap id of backdrop pixmap
*
* Returns:
* --------
* Success if request sent
*
*************************************<->***********************************/
extern int
_DtWsmChangeBackdrop (
Display *display,
Window root,
char *path,
Pixmap pixmap);
/*************************************<->*************************************
*
* _DtWmCvtStringToIPlace (args, numArgs, fromVal, toVal)
*
*
* Description:
* -----------
* This function converts a string to an icon placement scheme description.
*
*
* Inputs:
* ------
* args = NULL (don't care)
*
* numArgs = 0 (don't care)
*
* fromVal = resource value to convert
*
*
* Outputs:
* -------
* toVal = descriptor to use to return converted value
*
*************************************<->***********************************/
extern void
_DtWmCvtStringToIPlace (
XrmValue *args,
Cardinal numArgs,
XrmValue *fromVal,
XrmValue *toVal);
/*************************************<->*************************************
*
* Boolean _DtWsmIsBackdropWindow (display, screen_num, window)
*
*
* Description:
* -----------
* Returns true if the window passed in is a backdrop window.
*
*
* Inputs:
* ------
* display - display
* screen_num - number of screen we're interested in
* window - window we want to test
*
* Outputs:
* -------
* Return - True if window is a backdrop window
* False otherwise.
*
* Comments:
* --------
*
*************************************<->***********************************/
Boolean
_DtWsmIsBackdropWindow(
Display *display,
int screen_num,
Window window );
/*************************************<->*************************************
*
* int DtWsmSetWorkspaceTitle (widget, aWs, pchNewName)
*
*
* Description:
* -----------
* Rename a workspace
*
*
* Inputs:
* ------
* widget - a widget
* aWs - atom of workspace
* pchNewName - new name for the workspace
*
* Outputs:
* --------
* Return - 1 (*not* Success) if communication to workspace manager
* was successful.
*
* Comments:
* ---------
* The odd-ball successful return value is a CDE 1.0 bug being
* preserved for backward compatibility.
*
*************************************<->***********************************/
int
_DtWsmSetWorkspaceTitle (
Widget widget,
Atom aWs,
char * pchNewName);
/*************************************<->*************************************
*
* int _DtWsmDeleteWorkspace (widget, aWs)
*
*
* Description:
* -----------
* Delete a workspace
*
*
* Inputs:
* ------
* widget - a widget (with a window!)
* aWs - atom of workspace to delete
*
* Outputs:
* --------
* Return - 1 (*not* Success) if communication to workspace manager
* was successful.
*
* Comments:
* ---------
* The odd-ball successful return value is a CDE 1.0 bug being
* preserved for backward compatibility.
*
*************************************<->***********************************/
int
_DtWsmDeleteWorkspace (
Widget widget,
Atom aWs);
/*************************************<->*************************************
*
* int _DtWsmCreateWorkspace (widget, pchTitle)
*
*
* Description:
* -----------
* Add a workspace
*
*
* Inputs:
* ------
* widget - a widget (with a window!)
* pchTitle - user-visible title of the workspace
*
* Outputs:
* --------
* Return - 1 (*not* Success) if communication to workspace manager
* was successful.
*
* Comments:
* ---------
* The odd-ball successful return value is a CDE 1.0 bug being
* preserved for backward compatibility.
*
*************************************<->***********************************/
int
_DtWsmCreateWorkspace (Widget widget, char * pchTitle);
/*************************************<->*************************************
*
* _DtWsmSetWorkspaceHints (display, window, pWsHints)
*
*
* Description:
* -----------
* Set the contents of the _DT_WORKSPACE_HINTS property on a window
*
*
* Inputs:
* ------
* display - display
* window - window to get hints from
* pWsHints - pointer to workspace hints
*
* Comments:
* ---------
* The internal form of the property is a structure. The structure
* must be unwound and turned into a simple array of "long"s before
* being written out.
*
* This function currently only deals with version 1 of the property
* structure. The passed in pWsHints->version is ignored.
*
*************************************<->***********************************/
extern void
_DtWsmSetWorkspaceHints(
Display *display,
Window window,
DtWorkspaceHints *pWsHints);
/*************************************<->*************************************
*
* int _DtWsmGetWorkspaceHints (display, window, ppWsHints)
*
*
* Description:
* -----------
* Get the contents of the _DT_WORKSPACE_HINTS property from a window
*
*
* Inputs:
* ------
* display - display
* window - window to get hints from
* ppWsHints - pointer to pointer to workspace hints
*
* Outputs:
* *ppWsHints - allocated workspace hints data.
*
* Comments:
* ---------
* The internal form of the property is a structure. The property
* is read in and packed into data allocated for the structure.
* Free the workspace hints by calling _DtWsmFreeWorkspaceHints.
*
* This function currently only deals with version 1 of the property
* structure.
*
*************************************<->***********************************/
extern int
_DtWsmGetWorkspaceHints(
Display *display,
Window window,
DtWorkspaceHints **ppWsHints);
/*************************************<->*************************************
*
* _DtWsmFreeWorkspaceHints (pWsHints)
*
*
* Description:
* -----------
* Free a workspace hints structure returned from _DtWsmGetWorkspaceHints
*
* Inputs:
* ------
* pWsHints - pointer to workspace hints
*
* Outputs:
*
* Comments:
* ---------
*************************************<->***********************************/
extern void
_DtWsmFreeWorkspaceHints(
DtWorkspaceHints *pWsHints);
/*************************************<->*************************************
*
* DtWsmCBContext * _DtWsmAddMarqueeSelectionCallback (widget,
* marquee_select,
* client_data)
*
*
* Description:
* -----------
* Register a function to be called when a marquee selection is made
*
*
* Inputs:
* ------
* widget - widget for this client
* marquee_select - function to call for marquee select
* client_data - additional data to pass back to client when called.
*
* Outputs:
* --------
* Return - ptr to callback context data (opaque)
*
* Comments:
* ---------
* The callback context data ptr should be saved if you intend to
* removed this callback at some point in the future.
*
*************************************<->***********************************/
DtWsmCBContext
_DtWsmAddMarqueeSelectionCallback (
Widget widget,
DtWsmMarqueeSelectionProc marquee_select,
XtPointer client_data);
/*************************************<->*************************************
*
* _DtWsmSetDtWmHints (display, window, pHints)
*
*
* Description:
* -----------
* Set the contents of the _DT_WM_HINTS property on a window
*
*
* Inputs:
* ------
* display - display
* window - window to set hints on
* pHints - pointer the hints to set
*
* Comments:
* ---------
* No error checking
*
*************************************<->***********************************/
extern void
_DtWsmSetDtWmHints( Display *display,
Window window,
DtWmHints *pHints);
/*************************************<->*************************************
*
* int _DtWsmGetDtWmHints (display, window, ppDtWmHints)
*
*
* Description:
* -----------
* Get the contents of the _DT_WM_HINTS property on a window
*
*
* Inputs:
* ------
* display - display
* window - window to get hints from
* ppDtWmHints - pointer to a pointer to return
*
* Outputs:
* --------
* *ppDtWmHints-points to the DtWmHints structure retrieved from
* the window (NOTE: This should be freed using XFree)
*
* Comments:
* ---------
*
*************************************<->***********************************/
extern int
_DtWsmGetDtWmHints(
Display *display,
Window window,
DtWmHints **ppDtWmHints);
/*************************************<->*************************************
*
* _DtWsmSelectionNameForScreen (scr)
*
* Description:
* -----------
* Returns a string containing the selection name used for
* communication with the workspace manager on this screen
*
*
* Inputs:
* ------
* scr - number of screen
*
* Outputs:
* --------
* Return - ptr to string with selection name (free with XtFree)
*
* Comments:
* ---------
* Assumes the screen number is < 1000.
*
*************************************<->***********************************/
extern String
_DtWsmSelectionNameForScreen (int scr);
extern Tt_callback_action
_DtWsmConsumeReply (
Tt_message msg,
Tt_pattern pat );
#endif /* _Dt_WsmP_h */
/* Do not add anything after this endif. */

View File

@@ -0,0 +1,91 @@
/* $XConsortium: intarray.c /main/4 1996/05/09 04:23:20 drk $ */
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <malloc.h>
#include <string.h>
#include "DtHash.h"
#include "DtShmDb.h"
typedef struct intent {
struct intent * next;
int size;
int data[1];
} intent_t;
typedef struct intarray {
intent_t * first;
intent_t ** next;
int num_ints;
} intarray_t;
/* ARGSUSED */
void *
_DtShmProtoInitIntLst(int estimated_entries)
{
intarray_t * ptr = (intarray_t *) malloc(sizeof(*ptr));
ptr->first = (intent_t*)malloc(sizeof(intent_t));
ptr->next = &ptr->first->next;
ptr->first->size = 1;
ptr->first->data[0] = 0;
ptr->num_ints = 2;
return((void*)ptr);
}
int *
_DtShmProtoAddIntLst(DtShmProtoIntList handle, int size, int * index)
{
intarray_t * ptr = (intarray_t *) handle;
intent_t * e = (intent_t *) malloc(sizeof(intent_t) + sizeof(int) * (size-1));
e->size = size;
e->next = NULL;
*index = ptr->num_ints + 1;
ptr->num_ints += size + 1;
*(ptr->next) = e;
ptr->next = &e->next;
return(e->data);
}
int
_DtShmProtoSizeIntLst(DtShmProtoIntList handle)
{
intarray_t * ptr = (intarray_t *) handle;
return(sizeof(int) * ptr->num_ints);
}
DtShmIntList
_DtShmProtoCopyIntLst(DtShmProtoIntList handle, void * destination)
{
intarray_t * ptr = (intarray_t *) handle;
intent_t * a = ptr->first;
int * d = (int*) destination;
while(a) {
int size = a->size;
*d++ = size;
memcpy(d, a->data, sizeof(int) * size);
d+=size;
a = a->next;
}
return((DtShmIntList) destination);
}
int
_DtShmProtoDestroyIntLst(DtShmProtoIntList handle)
{
intarray_t * ptr = (intarray_t *) handle;
intent_t * a= ptr->first;
intent_t * b;
while(a) {
b = a->next;
free(a);
a = b;
}
free(ptr);
return(0);
}

View File

@@ -0,0 +1,159 @@
/* $XConsortium: inttab.c /main/5 1996/05/09 04:23:37 drk $ */
/*
routines to implement a table of int, int value pairs.
the data is relocatable to allow use at various addresses
(eg shared memory)
-1 is an illegal key
Tables are limited to 64K entries
*/
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <malloc.h>
#include <string.h>
#include "DtHash.h"
#include "DtShmDb.h"
#define NOT_AN_INDEX 0
static int build_it(int * data, void * usr_arg, int key);
typedef struct inttab {
int key;
int data;
unsigned short first;
unsigned short next;
} inttab_t;
typedef struct intlist {
int num_entries;
void * tbl;
} intlist_t;
typedef struct builder {
int counter;
intlist_t * intlist_ptr;
inttab_t * inttab_ptr;
} builder_t;
/*
first entry is header block;
contains key = size (not counting header)
*/
const int *
_DtShmFindIntTabEntry(DtShmInttab inttab, unsigned int key)
{
register const inttab_t * ptr = (const inttab_t *) inttab;
register int i;
if ( !ptr->key)
return(0);
i = ptr[key % ptr->key + 1].first;
while(i && key != ptr[i].key)
i = ptr[i].next;
return(i?(&ptr[i].data):(const int *)NULL);
}
DtShmProtoInttab
_DtShmProtoInitInttab(int sizeguess)
{
intlist_t * ptr = (intlist_t *)malloc(sizeof(*ptr));
ptr->tbl = _DtUtilMakeIHash(sizeguess);;
ptr->num_entries = 0;
return((void*)ptr);
}
_DtShmProtoAddInttab(DtShmProtoInttab intlist, unsigned int keyin, int datain)
{
intlist_t * ptr = (intlist_t *) intlist;
int ** data;
data = (int**)_DtUtilGetHash(ptr->tbl, (unsigned char *)keyin);
if(!*data) /* new */ {
*data = (int *) malloc(sizeof(int));
ptr->num_entries++;
}
**data = datain;
return(0);
}
int
_DtShmProtoSizeInttab(DtShmProtoInttab intlist)
{
intlist_t * ptr = (intlist_t * ) intlist;
return(sizeof(inttab_t) * (ptr->num_entries +1));
}
DtShmInttab
_DtShmProtoCopyInttab(DtShmProtoInttab intlist, void * destination)
{
builder_t build;
build.counter = 1;
build.intlist_ptr = (intlist_t * ) intlist;
build.inttab_ptr = (inttab_t *) destination;
memset(destination, 0, (build.intlist_ptr->num_entries+1)*sizeof(inttab_t));
build.inttab_ptr->key = build.intlist_ptr->num_entries;
_DtUtilOperateHash(build.intlist_ptr->tbl, (DtHashOperateFunc)build_it, &build);
return(0);
}
int
_DtShmProtoDestroyInttab(DtShmProtoInttab intlist)
{
intlist_t * ptr = (intlist_t *)intlist;
_DtUtilDestroyHash(ptr->tbl, (DtHashDestroyFunc)free, NULL);
free(intlist);
return(0);
}
static int build_it(int * data, void * usr_arg, int key)
{
builder_t * ptr = (builder_t *) usr_arg;
inttab_t * a;
inttab_t * b;
unsigned short * add_ptr;
int bucket = key % (ptr->intlist_ptr->num_entries) + 1;
a = ptr->inttab_ptr + ptr->counter;
a->key = key;
a->data = *data;
a->next = NOT_AN_INDEX;
b = ptr->inttab_ptr + bucket;
if(b->first == NOT_AN_INDEX) {
add_ptr = &b->first;
} else {
b = ptr->inttab_ptr + b->first;
while(b->next != NOT_AN_INDEX)
b = ptr->inttab_ptr + b->next;
add_ptr = &b->next;
}
*add_ptr = ptr->counter++;
return(0);
}

View File

@@ -0,0 +1,37 @@
/* $XConsortium: myassertP.h /main/4 1995/10/26 15:14:54 rswiston $ */
/************************************<+>*************************************
****************************************************************************
**
** File: myassertP.h
**
** Project: DT
**
** Description: Private include file for the Action Library.
**
**
** (c) Copyright 1993 by Hewlett-Packard Company
**
**
**
****************************************************************************
************************************<+>*************************************/
#ifndef MY_ASSERT_INCLUDED
# define MY_ASSERT_INCLUDED
# ifndef NDEBUG
# if defined(__STDC__) || defined(__cplusplus) || defined(c_plusplus)
/* ANSI Version */
# define myassert(EX) \
((EX)? 1 : (fprintf(stderr,"STDC Assertion failed: \""#EX"\"\n\tFile: %s\n\tLine: %d\n",__FILE__,__LINE__),0))
# else
/* NON-ANSI C */
# define myassert(EX) \
((EX)? 1 : (fprintf(stderr,"NOSTDC Assertion failed: \"EX\"\n\tFile: %s\n\tLine: %d\n",__FILE__,__LINE__),0))
# endif /* STD_C */
# else
# define myassert(EX) (1)
# endif
#endif /* MY_ASSERT_INCLUDED */

View File

@@ -0,0 +1,280 @@
/* $XConsortium: strtab.c /main/4 1996/05/09 04:23:54 drk $ */
/*
routines to implement a string -> unique ptr table & access functions
suitable for use with shared memory
*/
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include "DtHash.h"
#include "DtShmDb.h"
typedef struct strtab {
unsigned int st_size; /* size in bytes */
unsigned int st_stroffset; /* offset (bytes) from this structure to contained strings */
unsigned int st_taboffset; /* offset (bytes) from this structure to table offset */
unsigned int st_count; /* number of elements in this string table */
} strtab_t;
typedef struct strtab_entry {
unsigned int key; /* offset into contained strings */
unsigned short first; /* offset in table to first string to hash to this spot */
unsigned short next; /* offset in table to next item to hash to this spot */
} strtab_entry_t;
typedef struct strlist {
DtHashTbl sl_hash; /* hash table to hold strings during definition */
DtHashTbl sl_bosons; /* reverse hash table for Nolan's lookup function */
unsigned int sl_charcount; /* count of current bytes of strings */
} strlist_t;
struct strtab_build {
unsigned int index; /* iteration */
unsigned char * strstart; /* start of strings */
strtab_entry_t * tabstart; /* start of table */
strtab_t * strtab; /* pointer to head */
};
#define NOT_AN_INDEX ((unsigned short) 0xffff)
static void inc_it (int * a, int * b, unsigned char * key);
static void build_it(int a, struct strtab_build * ptr, unsigned char * key);
extern char * strdup(const char *);
typedef int (*des_func)(void *);
/*
client routine
returns offset in string table where string is found,
else -1 if string is not found.
*/
const char * _DtShmBosonToString(DtShmStrtab strtab, int boson)
{
const char * s = (const char *) strtab + ((strtab_t *) strtab)->st_stroffset;
return(s+boson);
}
DtShmBoson _DtShmStringToBoson(DtShmStrtab strtab, const char * string)
{
register unsigned int i,j;
register unsigned const char * s;
register strtab_entry_t * ptr = (strtab_entry_t *) ((unsigned char *) strtab +
((strtab_t *) strtab) -> st_taboffset);
/*
hash the input string
*/
i = 1;
j = 0;
s = (unsigned const char *) string;
while(*s!=0)
j += (*s++ << i++);
i = j % ((strtab_t *) strtab)->st_count;
/*
check bucket first pointer....
*/
if((i=(ptr+i)->first) == NOT_AN_INDEX)
return(-1);
/*
loop through other buckets on hash table, looking for
our string. Note that we reused s.
*/
s = (unsigned const char *) strtab + ((strtab_t *) strtab)->st_stroffset;
while(strcmp( (char *) (s + ptr[i].key), string))
if((i= ptr[i].next) == NOT_AN_INDEX)
return(-1);
return(ptr[i].key);
}
DtShmProtoStrtab
_DtShmProtoInitStrtab(int sizeguess)
{
strlist_t * ptr = (strlist_t *) malloc(sizeof(*ptr));
if(!ptr)
return(NULL);
if(!(ptr->sl_hash = _DtUtilMakeHash(sizeguess))) {
free(ptr);
return(NULL);
}
if(!(ptr->sl_bosons = _DtUtilMakeIHash(sizeguess))) {
(void)_DtUtilDestroyHash(ptr->sl_hash, NULL, NULL);
free(ptr);
return(NULL);
}
ptr->sl_charcount = 1;
return((DtShmProtoStrtab) ptr);
}
int
_DtShmProtoDestroyStrtab(DtShmProtoStrtab strlist)
{
strlist_t * ptr = (strlist_t *) strlist;
_DtUtilDestroyHash(ptr->sl_hash, NULL, NULL);
_DtUtilDestroyHash(ptr->sl_bosons, (des_func)free, NULL);
free(ptr);
return(0);
}
DtShmBoson
_DtShmProtoAddStrtab(DtShmProtoStrtab strlist, const char * string, int * isnew)
{
strlist_t * ptr = (strlist_t *) strlist;
int * bucket = (int *) _DtUtilGetHash(ptr->sl_hash, (const unsigned char *)string);
int ret = *bucket;
if(*bucket == NULL) /* new */ {
unsigned char ** sptr;
*isnew = 1;
*bucket = ret = ptr->sl_charcount;
sptr = (unsigned char**)_DtUtilGetHash(ptr->sl_bosons, (const unsigned char *)ret);
*sptr = (unsigned char*)strdup(string);
ptr->sl_charcount += strlen(string) + 1;
}
else {
*isnew = 0;
}
return((DtShmBoson)ret);
}
const char *
_DtShmProtoLookUpStrtab (DtShmProtoStrtab prototab, DtShmBoson boson)
{
strlist_t * ptr = (strlist_t *) prototab;
unsigned char ** sptr;
sptr = (unsigned char **) _DtUtilFindHash(ptr->sl_bosons, (const unsigned char *) boson);
return(sptr?((const char *)*sptr):NULL);
}
int
_DtShmProtoSizeStrtab(DtShmProtoStrtab strlist)
{
int foo[2];
int size;
strlist_t * ptr = (strlist_t * ) strlist;
foo[1] = foo[0] = 0;
_DtUtilOperateHash(ptr->sl_hash, inc_it, &foo);
size = sizeof(strtab_t) + (foo[0]) * sizeof(strtab_entry_t) + foo[0] + foo[1] + 3 ;
/* header */ /* table */ /* for string + terminator */ /* padding */
/*
fix size so that it is always a multiple of 4 for ease of programming
*/
size = (~3) & (size+3);
return(size);
}
DtShmStrtab
_DtShmProtoCopyStrtab(DtShmProtoStrtab in, void * destination)
{
strlist_t * strlist = (strlist_t *) in;
strtab_t * ptr = (strtab_t *) destination;
int foo[2];
int size;
struct strtab_build building;
foo[0] = foo[1] = 0;
_DtUtilOperateHash(strlist->sl_hash, inc_it, &foo);
size = sizeof(strtab_t) + (foo[0]) * sizeof(strtab_entry_t) + (foo[0] + foo[1] + 3) & ~3 ;
/* header */ /* table */ /* for string + terminator */
memset((char *) ptr, 255, size);
ptr-> st_size= size;
ptr-> st_stroffset = sizeof(*ptr);
ptr-> st_taboffset = sizeof(*ptr) + (foo[0] + foo[1] + 3) & ~3;
ptr-> st_count = foo[0]; /* patch alignment */
building.index = 0;
building.strstart = (unsigned char *) ptr + ptr->st_stroffset;
building.tabstart = (strtab_entry_t *) ((unsigned char *) ptr + ptr->st_taboffset);
building.strtab = ptr;
_DtUtilOperateHash(strlist->sl_hash, build_it, & building);
return((DtShmStrtab) destination);
}
static void build_it(int a, struct strtab_build * ptr, unsigned char * key)
{
register unsigned int i,j;
register unsigned char * s;
register strtab_entry_t * e;
register unsigned short * add_ptr;
strcpy((char *) ptr->strstart + a, (const char *)key);
i = 1;
j = 0;
s = key;
while(*s!=0)
j += (*s++ << i++);
i = j % ((strtab_t *) ptr->strtab)->st_count;
e = ptr->tabstart + ptr->index;
e -> key = a; /* save key value in our block */
e -> next = NOT_AN_INDEX;
e = ptr->tabstart + i;
if(e->first == NOT_AN_INDEX)
add_ptr = & e->first;
else {
e = ptr->tabstart + e->first;
while( e->next != NOT_AN_INDEX)
e = ptr->tabstart + e->next;
add_ptr = & e->next;
}
*add_ptr = ptr->index++;
}
/* ARGSUSED */
static void inc_it(int * a, int * b, unsigned char * key)
{
b[0]++;
b[1] += strlen((const char *)key) + 1;
}