1 /*******************************************************************************
3 * server_common.c -- Nirvana Editor common server stuff *
5 * Copyright (C) 1999 Mark Edel *
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. *
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 *
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 *
22 * Nirvana Text Editor *
25 * Written by Mark Edel *
27 *******************************************************************************/
30 #include <sys/types.h>
32 #include "../util/VMSparam.h"
35 #include <sys/param.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
,
89 char propName
[10+1+MAXNODENAMELEN
+1+MAXUSERNAMELEN
+1+MAXSERVERNAMELEN
+1+MAXPATHLEN
+1+7];
90 const char *userName
= GetUserName();
91 const char *hostName
= GetNameOfHost();
94 sprintf(propName
, "NEDIT_FILE_%s_%s_%s_%s_WF_OPEN", hostName
, userName
, serverName
, path
);
95 atom
= XInternAtom(TheDisplay
, propName
, False
);
99 Atom
CreateServerFileClosedAtom(const char *serverName
,
103 char propName
[10+1+MAXNODENAMELEN
+1+MAXUSERNAMELEN
+1+MAXSERVERNAMELEN
+1+MAXPATHLEN
+1+9];
104 const char *userName
= GetUserName();
105 const char *hostName
= GetNameOfHost();
108 sprintf(propName
, "NEDIT_FILE_%s_%s_%s_%s_WF_CLOSED", hostName
, userName
, serverName
, path
);
109 atom
= XInternAtom(TheDisplay
, propName
, only_if_exist
);
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
);
125 Atom
* atoms
= XListProperties(TheDisplay
, rootWindow
, &nProperties
);
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
]);