home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / clients / editres / setvalues.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-03-20  |  3.6 KB  |  120 lines

  1. /*
  2.  * $XConsortium: setvalues.c,v 1.4 91/03/20 17:08:49 gildea Exp $
  3.  *
  4.  * Copyright 1989 Massachusetts Institute of Technology
  5.  *
  6.  * Permission to use, copy, modify, distribute, and sell this software and its
  7.  * documentation for any purpose is hereby granted without fee, provided that
  8.  * the above copyright notice appear in all copies and that both that
  9.  * copyright notice and this permission notice appear in supporting
  10.  * documentation, and that the name of M.I.T. not be used in advertising or
  11.  * publicity pertaining to distribution of the software without specific,
  12.  * written prior permission.  M.I.T. makes no representations about the
  13.  * suitability of this software for any purpose.  It is provided "as is"
  14.  * without express or implied warranty.
  15.  *
  16.  * M.I.T. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
  17.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL M.I.T.
  18.  * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  19.  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  20.  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 
  21.  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  22.  *
  23.  * Author:  Chris D. Peterson, MIT X Consortium
  24.  */
  25.  
  26. #include <X11/Intrinsic.h>
  27. #include <X11/StringDefs.h>
  28. #include <X11/Xresource.h>
  29.  
  30. #include <stdio.h>
  31.  
  32. #include <X11/Xaw/AsciiText.h>
  33. #include <X11/Xaw/Cardinals.h>    
  34. #include <X11/Xfuncs.h>
  35. #include <X11/Xos.h>
  36. #include "editresP.h"
  37.  
  38. extern WNode * FindNode();
  39. extern void AddString();
  40.  
  41. #define RESOURCE_NAME ("name")
  42. #define RESOURCE_CLASS ("Class")
  43.  
  44. /*    Function Name: PrintSetValuesError
  45.  *    Description: Allow the SetValues error to be printed.
  46.  *    Arguments: event - the set values call that caused this event.
  47.  *    Returns: str - a string contining the errors.
  48.  */
  49.  
  50. char *
  51. PrintSetValuesError(event)
  52. Event * event;
  53. {
  54.     char * errors = NULL;
  55.     WNode * node;
  56.     int i;
  57.     SetValuesEvent * sv_event = (SetValuesEvent *) event;
  58.     char buf[BUFSIZ];
  59.  
  60.     if (sv_event->num_entries == 0) 
  61.     return(XtNewString("SetValues was Successful."));
  62.  
  63.     for (i = 0 ; i < (int)sv_event->num_entries ; i++) {
  64.     node = FindNode(global_tree_info->top_node,
  65.             sv_event->info[i].widgets.ids, 
  66.             sv_event->info[i].widgets.num_widgets);
  67.  
  68.     if (node == NULL) {
  69.         sprintf(buf, "Editres Internal Error: Unable to FindNode.\n");
  70.         AddString(&errors, buf); 
  71.         continue;
  72.     }
  73.  
  74.     sprintf(buf, "%s(0x%lx) - %s\n", node->name, node->id,
  75.         sv_event->info[i].message);
  76.     AddString(&errors, buf);
  77.     }
  78.     return(errors);
  79. }
  80.  
  81. /*    Function Name: GetResourceValueForSetValues(node);
  82.  *    Description: Returns the value that should be sent to SetValues.
  83.  *    Arguments: node - the node which contains the resource box.
  84.  *    Returns: value - allocated value.
  85.  */
  86.  
  87. char *
  88. GetResourceValueForSetValues(node, size)
  89. WNode * node;
  90. unsigned short * size;
  91. {
  92.     Arg args[1];
  93.     char *ptr, *temp;
  94.     XrmDatabase db = NULL;
  95.     XrmValue value;
  96.  
  97.     XtSetArg(args[0], XtNstring, &ptr);
  98.     XtGetValues(node->resources->res_box->value_wid, args, ONE);
  99.  
  100.     /*
  101.      * This makes sure that exactly the same thing happens during a set
  102.      * values, that would happend of we were to insert this value into
  103.      * the resource database.
  104.      */
  105.  
  106.     temp = XtMalloc(sizeof(char) * (strlen(ptr) + strlen(RESOURCE_NAME) + 2));
  107.     sprintf(temp, "%s:%s", RESOURCE_NAME, ptr);
  108.     XrmPutLineResource(&db, temp);
  109.     XtFree(temp);
  110.  
  111.     XrmGetResource(db, RESOURCE_NAME, RESOURCE_CLASS, &temp, &value);
  112.  
  113.     ptr = XtMalloc(sizeof(char) * value.size);
  114.     bcopy(value.addr, ptr, value.size);
  115.     XrmDestroyDatabase(db);
  116.     
  117.     *size = (unsigned short) value.size;
  118.     return(ptr);
  119. }
  120.