home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / evbl0627.zip / everblue_20010627.zip / x11 / Xlib_StrToText.c < prev    next >
C/C++ Source or Header  |  1999-11-02  |  3KB  |  91 lines

  1. /* $XConsortium: StrToText.c,v 1.5 94/04/17 20:21:13 gildea Exp $ */
  2. /*
  3.  
  4. Copyright (c) 1989  X Consortium
  5.  
  6. Permission is hereby granted, free of charge, to any person obtaining a copy
  7. of this software and associated documentation files (the "Software"), to deal
  8. in the Software without restriction, including without limitation the rights
  9. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. copies of the Software, and to permit persons to whom the Software is
  11. furnished to do so, subject to the following conditions:
  12.  
  13. The above copyright notice and this permission notice shall be included in
  14. all copies or substantial portions of the Software.
  15.  
  16. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
  19. X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
  20. AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  21. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22.  
  23. Except as contained in this notice, the name of the X Consortium shall not be
  24. used in advertising or otherwise to promote the sale, use or other dealings
  25. in this Software without prior written authorization from the X Consortium.
  26.  
  27. */
  28.  
  29. #include "Xlib_private.h"
  30. #include <X11/Xatom.h>
  31. #include <X11/Xutil.h>
  32.  
  33. /*
  34.  * XStringListToTextProperty - fill in TextProperty structure with 
  35.  * concatenated list of null-separated strings.  Return True if successful 
  36.  * else False.  Allocate room on end for trailing NULL, but don't include in
  37.  * count.
  38.  */
  39.  
  40. Status XStringListToTextProperty (argv, argc, textprop)
  41.     char **argv;
  42.     int argc;
  43.     XTextProperty *textprop;
  44. {
  45.     DBUG_ENTER("XStringListToTextProperty")
  46.     register int i;
  47.     register unsigned int nbytes;
  48.     XTextProperty proto;
  49.  
  50.     /* figure out how much space we'll need for this list */
  51.     for (i = 0, nbytes = 0; i < argc; i++) {
  52.     nbytes += (unsigned) ((argv[i] ? strlen (argv[i]) : 0) + 1);
  53.     }
  54.  
  55.     /* fill in a prototype containing results so far */
  56.     proto.encoding = XA_STRING;
  57.     proto.format = 8;
  58.     if (nbytes)
  59.     proto.nitems = nbytes - 1;    /* subtract one for trailing <NUL> */
  60.     else
  61.     proto.nitems = 0;
  62.     proto.value = NULL;
  63.  
  64.     /* build concatenated list of strings */
  65.     if (nbytes > 0) {
  66.     register char *buf = Xmalloc (nbytes);
  67.     if (!buf) DBUG_RETURN(False);
  68.  
  69.     proto.value = (unsigned char *) buf;
  70.     for (i = 0; i < argc; i++) {
  71.         char *arg = argv[i];
  72.  
  73.         if (arg) {
  74.         (void) strcpy (buf, arg);
  75.         buf += (strlen (arg) + 1);
  76.         } else {
  77.         *buf++ = '\0';
  78.         }
  79.     }
  80.     } else {
  81.     proto.value = (unsigned char *) Xmalloc (1);    /* easier for client */
  82.     if (!proto.value) DBUG_RETURN(False);
  83.  
  84.     proto.value[0] = '\0';
  85.     }
  86.  
  87.     /* we were successful, so set return value */
  88.     *textprop = proto;
  89.     DBUG_RETURN(True);
  90. }
  91.