source: trunk/athena/lib/Xj/VaCreateJet.c @ 20159

Revision 20159, 4.8 KB checked in by rbasch, 21 years ago (diff)
Use stdarg instead of varargs.
Line 
1/*
2 * $Id: VaCreateJet.c,v 1.3 2004-02-25 21:21:37 rbasch Exp $
3 *
4 * Copyright 1990, 1991 by the Massachusetts Institute of Technology.
5 *
6 * For copying and distribution information, please see the file
7 * <mit-copyright.h>.
8 *
9 */
10
11#if  (!defined(lint))  &&  (!defined(SABER))
12static char *rcsid =
13"$Id: VaCreateJet.c,v 1.3 2004-02-25 21:21:37 rbasch Exp $";
14#endif
15
16#include "mit-copyright.h"
17#include "Jets.h"
18#include <stdarg.h>
19#include <stdio.h>
20
21#define MAXNAMELEN 500
22static char className[MAXNAMELEN]; /* deserve to lose long before this */
23static char instanceName[MAXNAMELEN];
24
25/*
26 * This function is broken...
27 * In fact, lots of things are broken.
28 * C is broken... Unix is broken... Why break such a fine tradition?
29 * (Watch out for paradoxes!)
30 */
31#ifdef notdef
32void XjCopyValue(where, resource, value)
33     Jet where;
34     XjResource *resource;
35     XjArgVal value;
36{
37  memcpy((char *) where + resource->resource_offset,
38         &value,
39        (resource->resource_size > sizeof(void*)) ? sizeof(void*) :
40         resource->resource_size);
41}
42#endif
43
44#define XjCopyValue(where, resource, value) \
45  memcpy((char *)(where) + (resource)->resource_offset, \
46        &(value), \
47        ((resource)->resource_size > sizeof(void*)) ? sizeof(void*) : \
48         (resource)->resource_size)
49
50Jet XjVaCreateJet(char *name, JetClass class, Jet parent, char *valName, ...)
51{
52  va_list args;
53  char *classPtr, *instPtr;
54  int resCount;
55  XjArgVal val;
56
57  Jet jet, thisJet;
58  int len;
59  Boolean validName;
60
61  jet = (Jet)XjMalloc((unsigned) class->core_class.jetSize);
62
63  memset(jet, 0, class->core_class.jetSize);
64
65  jet->core.classRec = class;
66  jet->core.name = XjNewString(name);
67  jet->core.display = parent->core.display;
68  jet->core.window = parent->core.window; /* may get its own window later */
69  jet->core.borderWidth = 0;    /* Jet must change this if desired; supplied
70                                   for reasonable geometry management */
71  jet->core.need_expose = False; /* it'll get an expose soon enough... */
72
73  jet->core.parent = parent;
74  jet->core.sibling = parent->core.child;
75  jet->core.child = NULL;
76
77  parent->core.child = jet;
78
79  /* now call the ClassInitialize procedure */
80  if (! jet->core.classRec->core_class.classInitialized
81      &&  jet->core.classRec->core_class.classInitialize != NULL)
82    {
83      jet->core.classRec->core_class.classInitialize(jet);
84      jet->core.classRec->core_class.classInitialized = 1;
85    }
86
87  /* Generate the class and instance names */
88
89  /*
90   * Initialize the pointers to the place after the null, since
91   * inside the loop we backup the length + 1 of the string to
92   * add in order to skip over the '.' that we might want...
93   * This hack makes it unnecessary to special case inside the
94   * loop.
95   */
96  classPtr = className + MAXNAMELEN;
97  instPtr = instanceName + MAXNAMELEN;
98  classPtr[-1] = '\0'; instPtr[-1] = '\0';
99  thisJet = jet;
100  validName = True;
101
102  while (thisJet != NULL)
103    {
104      if (thisJet->core.name)
105        len = strlen(thisJet->core.name);
106      else
107        {
108          validName = False;
109          break;
110        }
111
112      if (len < (instPtr - instanceName)) /* includes '.' */
113        {
114          instPtr -= len + 1;
115          memcpy(instPtr, thisJet->core.name, len);
116          instPtr[-1] = '.';
117        }
118      else
119        {
120          XjWarning("Full jet instance name too long.");
121          validName = False;
122          break;
123        }
124
125      /* now do it all again for the class... */
126      if (thisJet->core.classRec->core_class.className)
127        len = strlen(thisJet->core.classRec->core_class.className);
128      else
129        {
130          validName = False;
131          break;
132        }
133
134      if (len < (classPtr - className)) /* includes . */
135        {
136          classPtr -= len + 1;
137          memcpy(classPtr, thisJet->core.classRec->core_class.className, len);
138          classPtr[-1] = '.';
139        }
140      else
141        {
142          XjWarning("Full jet class name too long.");
143          validName = False;
144          break;
145        }
146
147      thisJet = thisJet->core.parent;
148    }
149
150/*
151  fprintf(stdout, "%s\n%s\n",
152          classPtr, instPtr);
153*/
154
155  if (validName)
156    XjLoadFromResources(jet->core.display,
157                        jet->core.window,
158                        classPtr,
159                        instPtr,
160                        jet->core.classRec->core_class.resources,
161                        jet->core.classRec->core_class.num_resources,
162                        (caddr_t) jet);
163
164  va_start(args, valName);
165
166  while (NULL != valName)
167    {
168      val = va_arg(args, XjArgVal);
169/*      fprintf(stdout, "%d\n", val); */
170
171      for (resCount = 0;
172           resCount < jet->core.classRec->core_class.num_resources;
173           resCount++)
174        if (!strcmp(valName, jet->core.classRec->
175                    core_class.resources[resCount].resource_name))
176          {
177            XjCopyValue(jet,
178                        &jet->core.classRec->core_class.resources[resCount],
179                        val);
180            break;
181          }
182
183      if (resCount == jet->core.classRec->core_class.num_resources)
184        fprintf(stdout, "no such resource name: %s\n", valName);
185      valName = va_arg(args, char *);
186    }
187
188  val = va_arg(args, XjArgVal); /* pop the last one */
189  va_end(args);
190
191  /* now call the initialize procedure */
192  if (jet->core.classRec->core_class.initialize != NULL)
193    jet->core.classRec->core_class.initialize(jet);
194
195  return jet;
196}
Note: See TracBrowser for help on using the repository browser.