File: server_common.c

package info (click to toggle)
nedit 1%3A5.5-2
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 7,124 kB
  • ctags: 6,957
  • sloc: ansic: 92,920; xml: 1,427; yacc: 621; makefile: 342; awk: 40; sh: 10
file content (139 lines) | stat: -rw-r--r-- 5,391 bytes parent folder | download | duplicates (3)
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/*******************************************************************************
*									       *
* server_common.c -- Nirvana Editor common server stuff			       *
*									       *
* Copyright (C) 1999 Mark Edel						       *
*									       *
* This is free software; you can redistribute it and/or modify it under the    *
* terms of the GNU General Public License as published by the Free Software    *
* Foundation; either version 2 of the License, or (at your option) any later   *
* version. In addition, you may distribute version of this program linked to   *
* Motif or Open Motif. See README for details.                                 *
* 									       *
* This software is distributed in the hope that it will be useful, but WITHOUT *
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or        *
* FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License *
* for more details.							       *
* 									       *
* You should have received a copy of the GNU General Public License along with *
* software; if not, write to the Free Software Foundation, Inc., 59 Temple     *
* Place, Suite 330, Boston, MA  02111-1307 USA		                       *
*									       *
* Nirvana Text Editor	    						       *
* November, 1995							       *
*									       *
* Written by Mark Edel							       *
*									       *
*******************************************************************************/
#include <stdio.h>
#include <Xm/Xm.h>
#include <sys/types.h>
#ifdef VMS
#include "../util/VMSparam.h"
#else
#ifndef __MVS__
#include <sys/param.h>
#endif
#endif /*VMS*/
#include "textBuf.h"
#include "nedit.h"
#include "server_common.h"
#include "../util/utils.h"

/*
 * Create the server property atoms for the server with serverName.
 * Atom names are generated as follows:
 * 
 * NEDIT_SERVER_EXISTS_<host_name>_<user>_<server_name>
 * NEDIT_SERVER_REQUEST_<host_name>_<user>_<server_name>
 * 
 * <server_name> is the name that can be set by the user to allow
 * for multiple servers to run on the same display. <server_name>
 * defaults to "" if not supplied by the user.
 * 
 * <user> is the user name of the current user.
 */
void CreateServerPropertyAtoms(const char *serverName, 
			       Atom *serverExistsAtomReturn, 
			       Atom *serverRequestAtomReturn)
{
    char propName[20+1+MAXNODENAMELEN+1+MAXUSERNAMELEN+1+MAXSERVERNAMELEN];
    const char *userName = GetUserName();
    const char *hostName = GetNameOfHost();

    sprintf(propName, "NEDIT_SERVER_EXISTS_%s_%s_%s", hostName, userName, serverName);
    *serverExistsAtomReturn = XInternAtom(TheDisplay, propName, False);
    sprintf(propName, "NEDIT_SERVER_REQUEST_%s_%s_%s", hostName, userName, serverName);
    *serverRequestAtomReturn = XInternAtom(TheDisplay, propName, False);
}

/*
 * Create the individual property atoms for each file being
 * opened by the server with serverName. This atom is used
 * by nc to monitor if the file has been closed.
 *
 * Atom names are generated as follows:
 * 
 * NEDIT_FILE_<host_name>_<user>_<server_name>_<path>
 * 
 * <server_name> is the name that can be set by the user to allow
 * for multiple servers to run on the same display. <server_name>
 * defaults to "" if not supplied by the user.
 * 
 * <user> is the user name of the current user.
 * 
 * <path> is the path of the file being edited.
 */
Atom CreateServerFileOpenAtom(const char *serverName, 
	                      const char *path)
{
    char propName[10+1+MAXNODENAMELEN+1+MAXUSERNAMELEN+1+MAXSERVERNAMELEN+1+MAXPATHLEN+1+7];
    const char *userName = GetUserName();
    const char *hostName = GetNameOfHost();
    Atom        atom;

    sprintf(propName, "NEDIT_FILE_%s_%s_%s_%s_WF_OPEN", hostName, userName, serverName, path);
    atom = XInternAtom(TheDisplay, propName, False);
    return(atom);
}

Atom CreateServerFileClosedAtom(const char *serverName, 
	                        const char *path,
                                Bool only_if_exist)
{
    char propName[10+1+MAXNODENAMELEN+1+MAXUSERNAMELEN+1+MAXSERVERNAMELEN+1+MAXPATHLEN+1+9];
    const char *userName = GetUserName();
    const char *hostName = GetNameOfHost();
    Atom        atom;

    sprintf(propName, "NEDIT_FILE_%s_%s_%s_%s_WF_CLOSED", hostName, userName, serverName, path);
    atom = XInternAtom(TheDisplay, propName, only_if_exist);
    return(atom);
}

/*
 * Delete all File atoms that belong to this server (as specified by
 * <host_name>_<user>_<server_name>).
 */
void DeleteServerFileAtoms(const char* serverName, Window rootWindow)
{
    char propNamePrefix[10+1+MAXNODENAMELEN+1+MAXUSERNAMELEN+1+MAXSERVERNAMELEN+1];
    const char *userName = GetUserName();
    const char *hostName = GetNameOfHost();
    int length = sprintf(propNamePrefix, "NEDIT_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++) {
            /* XGetAtomNames() is more efficient, but doesn't exist in X11R5. */
            char *name = XGetAtomName(TheDisplay, atoms[i]);
            if (name != NULL && strncmp(propNamePrefix, name, length) == 0) {
                XDeleteProperty(TheDisplay, rootWindow, atoms[i]);
            }
            XFree(name);
        }
        XFree((char*)atoms);
    }
}