Link with C++ linker
[oweals/cde.git] / cde / programs / dtimsstart / xims.h
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these librararies and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 /* $XConsortium: xims.h /main/6 1996/04/17 16:25:50 pascale $ */
24
25 /*
26  * (c) Copyright 1996 Digital Equipment Corporation.
27  * (c) Copyright 1996 Hewlett-Packard Company.
28  * (c) Copyright 1996 International Business Machines Corp.
29  * (c) Copyright 1996 Sun Microsystems, Inc.
30  * (c) Copyright 1996 Novell, Inc. 
31  * (c) Copyright 1996 FUJITSU LIMITED.
32  * (c) Copyright 1996 Hitachi.
33  */
34
35 #ifndef _XIMS_H_
36 #define _XIMS_H_        1
37
38 #include        <X11/X.h>
39 #include        <X11/Xlib.h>
40 #include        <X11/Intrinsic.h>
41
42 #include        <stdio.h>
43 #include        <stdlib.h>
44 #include        <unistd.h>
45 #include        <string.h>
46 #include        <sys/param.h>
47 #include        <sys/time.h>
48
49 #include        "ximspath.h"
50 #include        "ximserr.h"
51
52
53     /* operation modes */
54 #define MODE_START              0       /* default */
55 #define MODE_MODE               1       /* -mode option */
56 #define MODE_STYLE              2       /* -style option */
57 #define MODE_LIST               3       /* -list option */      /* no window */
58 #define MODE_CURRENT            4       /* -current option */   /* no window */
59 #define MODE_REMCONF            5       /* -remoteconf */       /* no window */
60 #define MODE_LISTNAME           6       /* -listname option */  
61
62     /* operation flags */
63 #define FLAG_ENV                (1<<0)  /* -env option */
64 #define FLAG_NOSAVE             (1<<1)  /* -nosave option */
65 #define FLAG_NOSTART            (1<<2)  /* -nostart option (DEBUG) */
66 #define FLAG_NOWAIT             (1<<3)  /* -nowait option */
67 #define FLAG_NOTIMEOUT          (1<<4)  /* -notimeout option */
68 #define FLAG_NORESOURCE         (1<<5)  /* -noresource option */
69 #define FLAG_NOREMOTE           (1<<6)  /* -noremote option */
70 #define FLAG_NOTIFY             (1<<7)  /* -notify option */
71 #define FLAG_CONNECT            (1<<8)  /* -connect option */
72 #define FLAG_REMOTERUN          (1<<9)  /* -remoterun option */
73 #define FLAG_WINDOW             (1<<10) /* -window option */
74 #define FLAG_DT                 (1<<11) /* -dt option */
75 # ifdef old_hpux
76 #define FLAG_VUE                (1<<12) /* -vue option */
77 # endif /* old_hpux */
78
79 #define FLAG_DEFAULT            (FLAG_DT)
80 # ifdef old_hpux
81 #define USE_WINDOW_MASK         (FLAG_WINDOW|FLAG_VUE|FLAG_DT)
82 # else
83 #define USE_WINDOW_MASK         (FLAG_WINDOW|FLAG_DT)
84 # endif /* old_hpux */
85
86 #define MAXIMSENT               32      /* max # of ims for each locale */
87
88 #define MIN_INTERVAL            100     /* msec */
89 #define DEFAULT_INTERVAL        1000    /* msec */
90 #define MIN_TIMEOUT             1       /* sec */
91 #define DEFAULT_TIMEOUT         180     /* sec */
92 #define REMOTE_TIMEOUT          60      /* sec */
93
94 #define TAG_END_CHAR            ':'
95 #define TAG_SEP_CHAR            '.'
96 #define LIST_SEP_CHAR           ','
97 #define COMMENT_CHAR            '!'
98 #define COMMENT_CHAR2           '#'
99 #define COMMENT_CHARS           "!#"
100
101 #define NAME_NONE               "none"
102 #define NAME_LOCAL              "local"
103 #define NAME_BUILTIN            "builtin"
104 #define NAME_DEFAULT            "@"
105 #define NAME_DEFAULT_CHAR       '@'
106 #define DUMMY_SERVER_NAME       NAME_DEFAULT
107
108 #define STR_PREFIX_CHAR         '@'
109 #define STR_DEFAULTIMS          "DefaultIms"
110 #define STR_SELECTMODE          "SelectMode"
111 #define STR_IMSNAME             "ImsName"
112 #define STR_HOSTNAME            "HostName"
113 #define STR_ICONIC              "IconicMode"
114 #define STR_IMSOPTION           "ImsOption"
115 #define STR_ERRORCODE           "#ErrorCode"
116 #define STR_ERRORPATH           "#ErrorPath"
117 #define STR_CONFDATA            "#IMSSTART-CONFDATA-1.0"
118 #define STR_ICONIC_OPT          "-iconic"
119
120     /* protocol index */
121 #define Proto_None              0
122 #define Proto_XIM               1
123 #define Proto_Ximp              2
124 #define Proto_Xsi               3
125 # ifdef old_hpux
126 #define Proto_Xhp               4
127 #define NUM_PROTOCOLS           5
128 # else
129 #define NUM_PROTOCOLS           4
130 # endif /* old_hpux */
131     /* protocol flag */
132 #define ProtoBit(i)             (1<<(i))
133
134     /* window state */
135 #define WIN_ST_NONE             0
136 #define WIN_ST_INIT             1
137 #define WIN_ST_REMOTE_CONF      2
138 #define WIN_ST_REMOTE_RUN       3
139 #define WIN_ST_ACTION_DONE      4
140
141     /* ims server flag */
142 #define F_NO_SERVER             (1<<0)
143 #define F_NO_REMOTE             (1<<1)
144 #define F_NO_OPTION             (1<<2)
145 #define F_HAS_WINDOW            (1<<3)
146 #define F_TRY_CONNECT           (1<<4)
147 #define F_BUILTIN               (1<<8)
148
149     /* user selection flag */
150 #define F_SELECT_NONE           0
151 #define F_SELECT_FILE           (1<<0)
152 #define F_SELECT_WINDOW         (1<<1)
153 #define F_SELECT_CHANGED        (1<<4)
154
155     /* select_mode */
156 #define NUM_SEL_MODE            2
157 #define SEL_MODE_NOAUTO         0
158 #define SEL_MODE_AUTO           1
159 #define SEL_MODE_ONCE           2
160 #define SEL_MODE_NONE           -1
161 #define SEL_MODE_GIVEN          -2
162 #define SEL_MODE_QUERY          -3
163 #define SEL_MODE_WIN            -4
164
165     /* host type */
166 #define HOST_LOCAL              0
167 #define HOST_REMOTE             1
168 #define HOST_UNKNOWN            2
169
170 # ifdef old_hpux
171     /* index for XhpLocale */
172 #define XHP_JPN                 0
173 #define XHP_KOR                 1
174 #define XHP_CHS                 2
175 #define XHP_CHT                 3
176 #define XHP_LANG_NUM            4
177 # endif /* old_hpux */
178
179     /* message type for put_msg_win() */
180 #define MSGTYP_INFO             0
181 #define MSGTYP_WARN             1
182 #define MSGTYP_FATAL            2
183 #define MSGTYP_CONFIRM          3
184
185     /* help message type for ximsHelp() */
186 #define HELP_SELECTION          0
187 #define HELP_MODE               1
188
189     /* actions internally used */
190 #define ACT_GETREMCONF          0
191 #define ACT_RUNREMIMS           1
192 #define NUM_ACTIONS             2
193 #define ACTION_MASK             0xf0
194
195
196 typedef short           bool;
197
198     /* operation states */
199 typedef enum {
200     State_None = 0,
201     State_Init,
202     State_Init_Err,
203     State_Init_Done,
204     State_Select,
205     State_Select_Err,
206     State_Select_Canceled,
207     State_Select_Done,
208     State_Start,
209     State_Start_Err,
210     State_Start_Done,
211     State_Wait,
212     State_Wait_Err,
213     State_Wait_Done,
214     State_Finish,
215     State_Finish_Err,
216     State_Finish_Defered,
217     State_Finish_Done,
218     State_Mode,
219     State_Mode_Canceled,
220     State_Mode_Done,
221
222     State_Action_Invoked,
223     State_Action_Waiting,
224     State_Action_Done,
225     State_Action_Err,
226
227     State_Last
228 } OpStateVal;
229
230     /* structure definitions */
231
232 typedef struct {
233     char        *name;
234     char        *value;
235 } EnvEnt;
236
237 typedef struct {
238     char        *ims_name;
239     char        *opt_str;
240 } ImsOpt;
241
242 typedef struct {
243     EnvEnt      *set;
244     EnvEnt      *unset;
245 } OutEnv;
246
247 # ifdef old_hpux
248 typedef struct {
249     char        *name;
250     char        *aliases;
251 } LocaleAlias;
252
253 typedef struct {
254     char        type;
255     char        *locales;
256 } XhpLocale;
257
258 typedef struct {
259     char        *confDir;       /* override /etc/vue/config */
260     char        *userDir;       /* override .vue */
261     char        *uselite;       /* $HOME/.vue/sessions/usevuelite */
262     char        *resPath;       /* path of session resource (colon separated) */
263     char        *litePath;
264 } VueEnv;
265 # endif /* old_hpux */
266
267 typedef struct {
268     char        *confDir;       /* override /usr/dt/config */
269     char        *userDir;       /* override .dt */
270     char        *resPath;       /* path of session resource (colon separated) */
271 } DtEnv;
272
273 typedef struct {
274     bool        disabled;       /* disable remote execution */
275     bool        useRemsh;       /* use remsh(1) instead of action */
276     int         timeout;        /* timeout for remote execution */
277     char        *passEnv;       /* env vars passed to remote IMS */
278 } RemoteEnv;
279
280 typedef struct {
281     int         flags;
282     int         protocols;
283     int         timeout;
284     int         interval;
285     char        *servername;
286     char        *servername2;
287     char        *classname;
288     char        *property;
289     char        *cmd_path;
290     char        *cmd_param;
291     char        *env_set;
292     char        *env_unset;
293     char        *env_pass;
294 } ImsConf;
295
296 typedef struct {
297     int         status;
298     char        *name;
299     char        *fname;
300     char        *label;
301     ImsConf     *ims;
302 } ImsEnt;
303
304 typedef struct {
305     short       status;
306     short       default_idx;
307     short       def_selmode;
308     short       num_ent;
309     ImsEnt      **elist;
310 } ImsList;
311
312 typedef struct {
313     int         status;
314     int         wait_status;
315     pid_t       pid;
316     bool        is_remote;
317     int         proto;
318     char        *im_mod;
319     char        *atom_name;
320     char        *cmdbuf;
321     Atom        prop_atom;
322 } RunEnv;
323
324 typedef struct {
325     bool        dpy_specific;
326     short       select_mode;
327     short       iconic;
328     char        *name;
329     char        *hostname;
330     char        *com_opt;
331     ImsOpt      **opts;
332     char        *real_fname;            /* actually read */
333 } FileSel;
334
335 typedef struct {
336     int         flag;           /* F_SELECT_* */
337     int         status;         /* error code */
338     int         ims_idx;        /* index of selected ims to list->elist[] */
339     int         host_type;      /* host type: HOST_{LOCAL|REMOTE|UNKNOWN} */
340     int         iconic;         /* iconic mode: */
341     char        *name;          /* selected ims */
342     char        *hostname;      /* current host */
343     ImsList     *list;          /* current list */
344     ImsEnt      *ent;           /* selected ims ent */
345     FileSel     *fsel;          /* original selection on file */
346     RunEnv      *renv;          /* run env used on start.c & env.c */
347 } UserSelection;
348
349 typedef struct {
350     char        *hostname;
351     char        *username;
352     char        *locale;
353     char        *real_locale;
354     char        *CDE_locale;
355     char        **locale_aliases;
356     char        *homedir;
357     char        *displayname;
358     char        *displaydir;
359     char        *xmodifiers;
360     short       screen_num;
361 } UserEnv;
362
363 typedef struct {
364     char        *DisplayName;   /* override $DISPLAY */
365     char        *LocaleName;    /* override $LANG */
366     char        *ConfPath;      /* override $CONF/start.conf */
367     char        *UserPath;      /* override $HOME/.xims/<locale> */
368     char        *LogPath;       /* override $HOME/.xims/ximslog */
369     char        *ResourceFile;  /* resource file for IMS */
370     char        *ImsName;       /* IMS name */
371     char        *ImsOption;     /* IMS option */
372     char        *HostName;      /* remote host name */
373     char        *ShellName;     /* shell name */
374     int         Timeout;        /* wait timeout (sec) */
375     int         Interval;       /* check interval (msec) */
376     int         SelectMode;     /* SEL_MODE_* */
377     int         Listname;       /* Used only from dtstyle */
378 } CmdOpt;
379
380 typedef struct {
381     char        *imsConfDir;    /* [%I] /usr/dt/config/ims/ */
382     char        *imsAppDir;     /* [%R] /usr/dt/app-defaults/ */
383     char        *imsLogDir;     /* [%G] /var/dt/ */
384     char        *imsLogFile;    /* [%g] imslog */
385     char        *imsDir;        /* [%b] ims */
386     char        *userImsDir;    /* [%S] $HOME/.dt/ims/ */
387     char        *userTmpDir;    /* [%T] $HOME/.dt/tmp/ */
388     char        *userAltDir;    /* [%A] alt tmp /var/tmp/ */
389     char        *xmod[NUM_PROTOCOLS];   /* format of XMODIFIERS */
390     char        *atom[NUM_PROTOCOLS];   /* atom name to be examined */
391     char        *action[NUM_ACTIONS];   /* actions internally used */
392     DtEnv       *dt;
393     RemoteEnv   *remote;
394 # ifdef old_hpux
395     VueEnv      *vue;
396     XhpLocale   *xhp;
397     LocaleAlias **alias;
398 # endif /* old_hpux */
399 } CmdConf;
400
401 typedef struct {
402     int         status;
403     Display     *Dpy;
404     Widget      TopW;
405     Window      atom_owner;
406     Atom        atom_main;
407     Atom        atom_status;
408     Atom        atom_data;
409     XtAppContext        appC;
410 } WinEnv;
411
412     /* Global Variables */
413
414 extern char             *ProgramRevision;       /* on main.c */
415 extern Display          *Dpy;           /* display (on win.c) */
416 extern Widget           TopW;           /* toplevel-shell (on win.c) */
417 extern XtAppContext     appC;
418
419 # ifdef _EXTERN_DEFINE_
420 #define Extern
421 # else
422 #define Extern  extern
423 # endif /* _EXTERN_DEFINE_ */
424
425 Extern OpStateVal       OpState;
426 Extern int              OpMode;         /* one of MODE_* */
427 Extern int              OpFlag;         /* bitOR of FLAG_* */
428 Extern CmdOpt           Opt;            /* command line options */
429 Extern CmdConf          Conf;
430 Extern WinEnv           winEnv;
431 Extern UserEnv          userEnv;
432 Extern UserSelection    userSel;
433 Extern ImsList          *localList;
434
435 Extern char             *ProgramName;   /* invoked program name */
436 Extern int              ProgramType;    /* same as OpMode */
437 Extern int              Verbose;        /* verbose flag */
438 Extern int              DebugLvl;       /* debug flag */
439 Extern FILE             *LogFp;         /* log file */
440 Extern int              Wargc;          /* argc for XtAppInitialize */
441 Extern char             **Wargv;        /* argv for XtAppInitialize */
442 Extern bool             WaitingDialogReply;
443 Extern bool             WaitingActionDone;
444 Extern bool             UseMsgWindow;
445 Extern bool             IsRemote;
446 Extern int              LastErrMsg;
447
448 #undef  Extern
449
450 # ifdef old_hpux
451 #define isXsession()    ((OpFlag & (FLAG_VUE|FLAG_DT)) ? True : False)
452 #define isVUE()         ((OpFlag & FLAG_VUE) ? True : False)
453 # else
454 #define isXsession()    ((OpFlag & FLAG_DT) ? True : False)
455 #define isVUE()         (False)
456 # endif /* old_hpux */
457 #define isDT()          ((OpFlag & FLAG_DT) ? True : False)
458 #define useWINDOW()     \
459                 (((OpFlag & USE_WINDOW_MASK) || window_env_ok()) ? True : False)
460
461 #define RemoteOn()      \
462         (((OpFlag & FLAG_NOREMOTE) || Conf.remote->disabled) ? False : True)
463
464 #include        "ximsfunc.h"
465
466 #endif  /* _XIMS_H_ */