1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 #include <stdio.h>
29 #include <Xm/Xm.h>
30 #include <sys/types.h>
31 #include <sys/param.h>
32 #include "nedit.h"
33 #include "server_common.h"
34 #include "../util/utils.h"
35 #include "../util/nedit_malloc.h"
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50 void CreateServerPropertyAtoms(
const char *serverName,
51 Atom *serverExistsAtomReturn,
52 Atom *serverRequestAtomReturn)
53 {
54 const char *userName = GetUserName();
55 const char *hostName = GetNameOfHost();
56
57 size_t serverNameLen = strlen(serverName);
58 size_t userNameLen = strlen(userName);
59 size_t hostNameLen = strlen(hostName);
60
61 size_t propNameMaxLen =
32 + serverNameLen + userNameLen + hostNameLen;
62 char *propName = NEditMalloc(propNameMaxLen);
63
64 snprintf(propName, propNameMaxLen,
"XNEDIT_SERVER_EXISTS_%s_%s_%s", hostName, userName, serverName);
65 *serverExistsAtomReturn = XInternAtom(TheDisplay, propName, False);
66 snprintf(propName, propNameMaxLen,
"XNEDIT_SERVER_REQUEST_%s_%s_%s", hostName, userName, serverName);
67 *serverRequestAtomReturn = XInternAtom(TheDisplay, propName, False);
68
69 NEditFree(propName);
70 }
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89 Atom CreateServerFileOpenAtom(
const char *serverName,
90 const char *path)
91 {
92 const char *userName = GetUserName();
93 const char *hostName = GetNameOfHost();
94
95 size_t serverNameLen = strlen(serverName);
96 size_t userNameLen = strlen(userName);
97 size_t hostNameLen = strlen(hostName);
98 size_t pathLen = strlen(path);
99
100 size_t propNameMaxLen =
32 + serverNameLen + userNameLen + hostNameLen + pathLen;
101 char *propName = NEditMalloc(propNameMaxLen);
102
103 Atom atom;
104
105 snprintf(propName, propNameMaxLen,
"XNEDIT_FILE_%s_%s_%s_%s_WF_OPEN", hostName, userName, serverName, path);
106 atom = XInternAtom(TheDisplay, propName, False);
107
108 NEditFree(propName);
109
110 return(atom);
111 }
112
113 Atom CreateServerFileClosedAtom(
const char *serverName,
114 const char *path,
115 Bool only_if_exist)
116 {
117 const char *userName = GetUserName();
118 const char *hostName = GetNameOfHost();
119 Atom atom;
120
121 size_t serverNameLen = strlen(serverName);
122 size_t userNameLen = strlen(userName);
123 size_t hostNameLen = strlen(hostName);
124 size_t pathLen = strlen(path);
125
126 size_t propNameMaxLen =
32 + serverNameLen + userNameLen + hostNameLen + pathLen;
127 char *propName = NEditMalloc(propNameMaxLen);
128
129 snprintf(propName, propNameMaxLen,
"XNEDIT_FILE_%s_%s_%s_%s_WF_CLOSED", hostName, userName, serverName, path);
130 atom = XInternAtom(TheDisplay, propName, only_if_exist);
131 NEditFree(propName);
132 return(atom);
133 }
134
135
136
137
138
139 void DeleteServerFileAtoms(
const char* serverName, Window rootWindow)
140 {
141 const char *userName = GetUserName();
142 const char *hostName = GetNameOfHost();
143
144 size_t serverNameLen = strlen(serverName);
145 size_t userNameLen = strlen(userName);
146 size_t hostNameLen = strlen(hostName);
147
148 size_t propNamePrefixMaxLen =
32 + serverNameLen + userNameLen + hostNameLen;
149 char *propNamePrefix = NEditMalloc(propNamePrefixMaxLen);
150
151 int length = snprintf(propNamePrefix, propNamePrefixMaxLen,
"XNEDIT_FILE_%s_%s_%s_", hostName, userName, serverName);
152
153 int nProperties;
154 Atom* atoms = XListProperties(TheDisplay, rootWindow, &nProperties);
155 if (atoms !=
NULL) {
156 int i;
157 for (i =
0; i < nProperties; i++) {
158
159 char *name = XGetAtomName(TheDisplay, atoms[i]);
160 if (name !=
NULL && strncmp(propNamePrefix, name, length) ==
0) {
161 XDeleteProperty(TheDisplay, rootWindow, atoms[i]);
162 }
163 XFree(name);
164 }
165 XFree((
char*)atoms);
166 }
167
168 NEditFree(propNamePrefix);
169 }
170