|
Packit |
5bd3a9 |
/*
|
|
Packit |
5bd3a9 |
|
|
Packit |
5bd3a9 |
Copyright 1989, 1998 The Open Group
|
|
Packit |
5bd3a9 |
|
|
Packit |
5bd3a9 |
Permission to use, copy, modify, distribute, and sell this software and its
|
|
Packit |
5bd3a9 |
documentation for any purpose is hereby granted without fee, provided that
|
|
Packit |
5bd3a9 |
the above copyright notice appear in all copies and that both that
|
|
Packit |
5bd3a9 |
copyright notice and this permission notice appear in supporting
|
|
Packit |
5bd3a9 |
documentation.
|
|
Packit |
5bd3a9 |
|
|
Packit |
5bd3a9 |
The above copyright notice and this permission notice shall be included in
|
|
Packit |
5bd3a9 |
all copies or substantial portions of the Software.
|
|
Packit |
5bd3a9 |
|
|
Packit |
5bd3a9 |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
Packit |
5bd3a9 |
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
Packit |
5bd3a9 |
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
Packit |
5bd3a9 |
OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
|
|
Packit |
5bd3a9 |
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
Packit |
5bd3a9 |
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
Packit |
5bd3a9 |
|
|
Packit |
5bd3a9 |
Except as contained in this notice, the name of The Open Group shall not be
|
|
Packit |
5bd3a9 |
used in advertising or otherwise to promote the sale, use or other dealings
|
|
Packit |
5bd3a9 |
in this Software without prior written authorization from The Open Group.
|
|
Packit |
5bd3a9 |
|
|
Packit |
5bd3a9 |
*/
|
|
Packit |
5bd3a9 |
|
|
Packit |
5bd3a9 |
#ifdef HAVE_CONFIG_H
|
|
Packit |
5bd3a9 |
#include <config.h>
|
|
Packit |
5bd3a9 |
#endif
|
|
Packit |
5bd3a9 |
#include <X11/Xlibint.h>
|
|
Packit |
5bd3a9 |
#include <X11/Xatom.h>
|
|
Packit |
5bd3a9 |
#include <X11/Xutil.h>
|
|
Packit |
5bd3a9 |
|
|
Packit |
5bd3a9 |
/*
|
|
Packit |
5bd3a9 |
* XStringListToTextProperty - fill in TextProperty structure with
|
|
Packit |
5bd3a9 |
* concatenated list of null-separated strings. Return True if successful
|
|
Packit |
5bd3a9 |
* else False. Allocate room on end for trailing NULL, but don't include in
|
|
Packit |
5bd3a9 |
* count.
|
|
Packit |
5bd3a9 |
*/
|
|
Packit |
5bd3a9 |
|
|
Packit |
5bd3a9 |
Status XStringListToTextProperty (
|
|
Packit |
5bd3a9 |
char **argv,
|
|
Packit |
5bd3a9 |
int argc,
|
|
Packit |
5bd3a9 |
XTextProperty *textprop)
|
|
Packit |
5bd3a9 |
{
|
|
Packit |
5bd3a9 |
register int i;
|
|
Packit |
5bd3a9 |
register unsigned int nbytes;
|
|
Packit |
5bd3a9 |
XTextProperty proto;
|
|
Packit |
5bd3a9 |
|
|
Packit |
5bd3a9 |
/* figure out how much space we'll need for this list */
|
|
Packit |
5bd3a9 |
for (i = 0, nbytes = 0; i < argc; i++) {
|
|
Packit |
5bd3a9 |
nbytes += (unsigned) ((argv[i] ? strlen (argv[i]) : 0) + 1);
|
|
Packit |
5bd3a9 |
}
|
|
Packit |
5bd3a9 |
|
|
Packit |
5bd3a9 |
/* fill in a prototype containing results so far */
|
|
Packit |
5bd3a9 |
proto.encoding = XA_STRING;
|
|
Packit |
5bd3a9 |
proto.format = 8;
|
|
Packit |
5bd3a9 |
if (nbytes)
|
|
Packit |
5bd3a9 |
proto.nitems = nbytes - 1; /* subtract one for trailing <NUL> */
|
|
Packit |
5bd3a9 |
else
|
|
Packit |
5bd3a9 |
proto.nitems = 0;
|
|
Packit |
5bd3a9 |
proto.value = NULL;
|
|
Packit |
5bd3a9 |
|
|
Packit |
5bd3a9 |
/* build concatenated list of strings */
|
|
Packit |
5bd3a9 |
if (nbytes > 0) {
|
|
Packit |
5bd3a9 |
register char *buf = Xmalloc (nbytes);
|
|
Packit |
5bd3a9 |
if (!buf) return False;
|
|
Packit |
5bd3a9 |
|
|
Packit |
5bd3a9 |
proto.value = (unsigned char *) buf;
|
|
Packit |
5bd3a9 |
for (i = 0; i < argc; i++) {
|
|
Packit |
5bd3a9 |
char *arg = argv[i];
|
|
Packit |
5bd3a9 |
|
|
Packit |
5bd3a9 |
if (arg) {
|
|
Packit |
5bd3a9 |
(void) strcpy (buf, arg);
|
|
Packit |
5bd3a9 |
buf += (strlen (arg) + 1);
|
|
Packit |
5bd3a9 |
} else {
|
|
Packit |
5bd3a9 |
*buf++ = '\0';
|
|
Packit |
5bd3a9 |
}
|
|
Packit |
5bd3a9 |
}
|
|
Packit |
5bd3a9 |
} else {
|
|
Packit |
5bd3a9 |
proto.value = Xmalloc (1); /* easier for client */
|
|
Packit |
5bd3a9 |
if (!proto.value) return False;
|
|
Packit |
5bd3a9 |
|
|
Packit |
5bd3a9 |
proto.value[0] = '\0';
|
|
Packit |
5bd3a9 |
}
|
|
Packit |
5bd3a9 |
|
|
Packit |
5bd3a9 |
/* we were successful, so set return value */
|
|
Packit |
5bd3a9 |
*textprop = proto;
|
|
Packit |
5bd3a9 |
return True;
|
|
Packit |
5bd3a9 |
}
|