Fix our use of $em_tab_dist after it was changed to 0 for 'turned of'.
[nedit.git] / source / server_common.c
blob601a46e44abf38b40df84e09f00da237d41bb65f
1 /*******************************************************************************
2 * *
3 * server_common.c -- Nirvana Editor common server stuff *
4 * *
5 * Copyright (C) 1999 Mark Edel *
6 * *
7 * This is free software; you can redistribute it and/or modify it under the *
8 * terms of the GNU General Public License as published by the Free Software *
9 * Foundation; either version 2 of the License, or (at your option) any later *
10 * version. In addition, you may distribute versions of this program linked to *
11 * Motif or Open Motif. See README for details. *
12 * *
13 * This software is distributed in the hope that it will be useful, but WITHOUT *
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
15 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for *
16 * more details. *
17 * *
18 * You should have received a copy of the GNU General Public License along with *
19 * software; if not, write to the Free Software Foundation, Inc., 59 Temple *
20 * Place, Suite 330, Boston, MA 02111-1307 USA *
21 * *
22 * Nirvana Text Editor *
23 * November, 1995 *
24 * *
25 * Written by Mark Edel *
26 * *
27 *******************************************************************************/
28 #include <stdio.h>
29 #include <Xm/Xm.h>
30 #include <sys/types.h>
31 #ifdef VMS
32 #include "../util/VMSparam.h"
33 #else
34 #ifndef __MVS__
35 #include <sys/param.h>
36 #endif
37 #endif /*VMS*/
38 #include "nedit.h"
39 #include "server_common.h"
40 #include "../util/utils.h"
43 * Create the server property atoms for the server with serverName.
44 * Atom names are generated as follows:
46 * NEDIT_SERVER_EXISTS_<host_name>_<user>_<server_name>
47 * NEDIT_SERVER_REQUEST_<host_name>_<user>_<server_name>
49 * <server_name> is the name that can be set by the user to allow
50 * for multiple servers to run on the same display. <server_name>
51 * defaults to "" if not supplied by the user.
53 * <user> is the user name of the current user.
55 void CreateServerPropertyAtoms(const char *serverName,
56 Atom *serverExistsAtomReturn,
57 Atom *serverRequestAtomReturn)
59 char propName[20+1+MAXNODENAMELEN+1+MAXUSERNAMELEN+1+MAXSERVERNAMELEN];
60 const char *userName = GetUserName();
61 const char *hostName = GetNameOfHost();
63 sprintf(propName, "NEDIT_SERVER_EXISTS_%s_%s_%s", hostName, userName, serverName);
64 *serverExistsAtomReturn = XInternAtom(TheDisplay, propName, False);
65 sprintf(propName, "NEDIT_SERVER_REQUEST_%s_%s_%s", hostName, userName, serverName);
66 *serverRequestAtomReturn = XInternAtom(TheDisplay, propName, False);
70 * Create the individual property atoms for each file being
71 * opened by the server with serverName. This atom is used
72 * by nc to monitor if the file has been closed.
74 * Atom names are generated as follows:
76 * NEDIT_FILE_<host_name>_<user>_<server_name>_<path>
78 * <server_name> is the name that can be set by the user to allow
79 * for multiple servers to run on the same display. <server_name>
80 * defaults to "" if not supplied by the user.
82 * <user> is the user name of the current user.
84 * <path> is the path of the file being edited.
86 Atom CreateServerFileOpenAtom(const char *serverName,
87 const char *path)
89 char propName[10+1+MAXNODENAMELEN+1+MAXUSERNAMELEN+1+MAXSERVERNAMELEN+1+MAXPATHLEN+1+7];
90 const char *userName = GetUserName();
91 const char *hostName = GetNameOfHost();
92 Atom atom;
94 sprintf(propName, "NEDIT_FILE_%s_%s_%s_%s_WF_OPEN", hostName, userName, serverName, path);
95 atom = XInternAtom(TheDisplay, propName, False);
96 return(atom);
99 Atom CreateServerFileClosedAtom(const char *serverName,
100 const char *path,
101 Bool only_if_exist)
103 char propName[10+1+MAXNODENAMELEN+1+MAXUSERNAMELEN+1+MAXSERVERNAMELEN+1+MAXPATHLEN+1+9];
104 const char *userName = GetUserName();
105 const char *hostName = GetNameOfHost();
106 Atom atom;
108 sprintf(propName, "NEDIT_FILE_%s_%s_%s_%s_WF_CLOSED", hostName, userName, serverName, path);
109 atom = XInternAtom(TheDisplay, propName, only_if_exist);
110 return(atom);
114 * Delete all File atoms that belong to this server (as specified by
115 * <host_name>_<user>_<server_name>).
117 void DeleteServerFileAtoms(const char* serverName, Window rootWindow)
119 char propNamePrefix[10+1+MAXNODENAMELEN+1+MAXUSERNAMELEN+1+MAXSERVERNAMELEN+1];
120 const char *userName = GetUserName();
121 const char *hostName = GetNameOfHost();
122 int length = sprintf(propNamePrefix, "NEDIT_FILE_%s_%s_%s_", hostName, userName, serverName);
124 int nProperties;
125 Atom* atoms = XListProperties(TheDisplay, rootWindow, &nProperties);
126 if (atoms != NULL) {
127 int i;
128 for (i = 0; i < nProperties; i++) {
129 /* XGetAtomNames() is more efficient, but doesn't exist in X11R5. */
130 char *name = XGetAtomName(TheDisplay, atoms[i]);
131 if (name != NULL && strncmp(propNamePrefix, name, length) == 0) {
132 XDeleteProperty(TheDisplay, rootWindow, atoms[i]);
134 XFree(name);
136 XFree((char*)atoms);