#include <stdio.h>
#include <Xm/Xm.h>
#include <sys/types.h>
#include <sys/param.h>
#include "nedit.h"
#include "server_common.h"
#include "../util/utils.h"
#include "../util/nedit_malloc.h"
void CreateServerPropertyAtoms(
const char *serverName,
Atom *serverExistsAtomReturn,
Atom *serverRequestAtomReturn)
{
const char *userName = GetUserName();
const char *hostName = GetNameOfHost();
size_t serverNameLen = strlen(serverName);
size_t userNameLen = strlen(userName);
size_t hostNameLen = strlen(hostName);
size_t propNameMaxLen =
32 + serverNameLen + userNameLen + hostNameLen;
char *propName = NEditMalloc(propNameMaxLen);
snprintf(propName, propNameMaxLen,
"XNEDIT_SERVER_EXISTS_%s_%s_%s", hostName, userName, serverName);
*serverExistsAtomReturn = XInternAtom(TheDisplay, propName, False);
snprintf(propName, propNameMaxLen,
"XNEDIT_SERVER_REQUEST_%s_%s_%s", hostName, userName, serverName);
*serverRequestAtomReturn = XInternAtom(TheDisplay, propName, False);
NEditFree(propName);
}
Atom CreateServerFileOpenAtom(
const char *serverName,
const char *path)
{
const char *userName = GetUserName();
const char *hostName = GetNameOfHost();
size_t serverNameLen = strlen(serverName);
size_t userNameLen = strlen(userName);
size_t hostNameLen = strlen(hostName);
size_t pathLen = strlen(path);
size_t propNameMaxLen =
32 + serverNameLen + userNameLen + hostNameLen + pathLen;
char *propName = NEditMalloc(propNameMaxLen);
Atom atom;
snprintf(propName, propNameMaxLen,
"XNEDIT_FILE_%s_%s_%s_%s_WF_OPEN", hostName, userName, serverName, path);
atom = XInternAtom(TheDisplay, propName, False);
NEditFree(propName);
return(atom);
}
Atom CreateServerFileClosedAtom(
const char *serverName,
const char *path,
Bool only_if_exist)
{
const char *userName = GetUserName();
const char *hostName = GetNameOfHost();
Atom atom;
size_t serverNameLen = strlen(serverName);
size_t userNameLen = strlen(userName);
size_t hostNameLen = strlen(hostName);
size_t pathLen = strlen(path);
size_t propNameMaxLen =
32 + serverNameLen + userNameLen + hostNameLen + pathLen;
char *propName = NEditMalloc(propNameMaxLen);
snprintf(propName, propNameMaxLen,
"XNEDIT_FILE_%s_%s_%s_%s_WF_CLOSED", hostName, userName, serverName, path);
atom = XInternAtom(TheDisplay, propName, only_if_exist);
NEditFree(propName);
return(atom);
}
void DeleteServerFileAtoms(
const char* serverName, Window rootWindow)
{
const char *userName = GetUserName();
const char *hostName = GetNameOfHost();
size_t serverNameLen = strlen(serverName);
size_t userNameLen = strlen(userName);
size_t hostNameLen = strlen(hostName);
size_t propNamePrefixMaxLen =
32 + serverNameLen + userNameLen + hostNameLen;
char *propNamePrefix = NEditMalloc(propNamePrefixMaxLen);
int length = snprintf(propNamePrefix, propNamePrefixMaxLen,
"XNEDIT_FILE_%s_%s_%s_", hostName, userName, serverName);
int nProperties;
Atom* atoms = XListProperties(TheDisplay, rootWindow, &nProperties);
if (atoms !=
NULL) {
int i;
for (i =
0; i < nProperties; i++) {
char *name = XGetAtomName(TheDisplay, atoms[i]);
if (name !=
NULL && strncmp(propNamePrefix, name, length) ==
0) {
XDeleteProperty(TheDisplay, rootWindow, atoms[i]);
}
XFree(name);
}
XFree((
char*)atoms);
}
NEditFree(propNamePrefix);
}