source: trunk/athena/lib/Xj/Tree.c @ 12242

Revision 12242, 3.3 KB checked in by ghudson, 26 years ago (diff)
Move Jets sources here from athena/bin/dash/src/lib, and autoconfiscate.
Line 
1/*
2 * $Source: /afs/dev.mit.edu/source/repository/athena/lib/Xj/Tree.c,v $
3 * $Author: ghudson $
4 *
5 * Copyright 1990, 1991 by the Massachusetts Institute of Technology.
6 *
7 * For copying and distribution information, please see the file
8 * <mit-copyright.h>.
9 *
10 */
11
12#if  (!defined(lint))  &&  (!defined(SABER))
13static char *rcsid =
14"$Header: /afs/dev.mit.edu/source/repository/athena/lib/Xj/Tree.c,v 1.1 1998-12-17 16:23:09 ghudson Exp $";
15#endif
16
17#include "mit-copyright.h"
18#include <stdio.h>
19#include <ctype.h>
20#include "Jets.h"
21#include "Tree.h"
22
23#define offset(field) XjOffset(TreeJet,field)
24
25static XjResource resources[] = {
26  { XjNx, XjCX, XjRInt, sizeof(int),
27     offset(core.x), XjRString, XjInheritValue },
28  { XjNy, XjCY, XjRInt, sizeof(int),
29     offset(core.y), XjRString, XjInheritValue },
30  { XjNwidth, XjCWidth, XjRInt, sizeof(int),
31     offset(core.width), XjRString, XjInheritValue },
32  { XjNheight, XjCHeight, XjRInt, sizeof(int),
33     offset(core.height), XjRString, XjInheritValue },
34  { XjNtree, XjCTree, XjRString, sizeof(char *),
35     offset(tree.tree), XjRString, "" }
36};
37
38#undef offset
39
40static void initialize();
41
42TreeClassRec treeClassRec = {
43  {
44    /* class name */            "Tree",
45    /* jet size */              sizeof(TreeRec),
46    /* classInitialize */       NULL,
47    /* classInitialized? */     1,
48    /* initialize */            initialize,
49    /* prerealize */            NULL,
50    /* realize */               NULL,
51    /* event */                 NULL,
52    /* expose */                NULL,
53    /* querySize */             NULL,
54    /* move */                  NULL,
55    /* resize */                NULL,
56    /* destroy */               NULL,
57    /* resources */             resources,
58    /* number of 'em */         XjNumber(resources)
59  }
60};
61
62JetClass treeJetClass = (JetClass)&treeClassRec;
63
64extern int numJetClasses;
65extern JetClass *jetClasses[];
66
67static void initialize(me)
68     TreeJet me;
69{
70  int index, i;
71  char *parse, class[50], name[50];
72  Jet parent, last;
73
74  if (strlen(me->tree.tree) == 0)
75    {
76      char errtext[100];
77
78      sprintf(errtext, "empty tree: %s", me->core.name);
79      XjWarning(errtext);
80      return;
81    }
82
83  last = (Jet)me;
84  parent = XjParent(me);
85  parse = me->tree.tree;
86
87  while (*parse != '\0')
88    {
89      while (isspace(*parse))
90        parse++;
91
92      switch(*parse)
93        {
94        case '{':
95          if (last == NULL)
96            XjWarning("no consecutive {'s allowed; ignored");
97          else
98            {
99              parent = last;
100              last = NULL;
101            }
102          parse++;
103          break;
104
105        case '}':
106          last = parent;
107          parent = XjParent(parent);
108          if (last == (Jet)me)
109            return;
110          parse++;
111          break;
112
113        default:
114          index = 0;
115          while (isalnum(*parse))
116            class[index++] = *parse++;
117          class[index] = '\0';
118
119          while (isspace(*parse))
120            parse++;
121
122          index = 0;
123          while (isalnum(*parse))
124             name[index++] = *parse++;
125          name[index] = '\0';
126
127          if (*parse == ';')
128            parse++;
129
130#ifdef DEBUG
131          fprintf(stdout, "create a %s named %s, child of %s\n",
132                  class, name, parent->core.name);
133#endif
134         
135          if (strcasecmp("null", class) != 0)
136            {
137              for (i = 0; i < numJetClasses; i++)
138                if (!strcmp(class, (*jetClasses[i])->core_class.className))
139                  {
140                    last = XjVaCreateJet(name,
141                                         (*jetClasses[i]),
142                                         parent,
143                                         NULL, NULL);
144                    break;
145                  }
146            }
147          else
148            i = 0;
149
150          if (i == numJetClasses)
151            {
152              char errtext[100];
153
154              sprintf(errtext, "unknown class: %s", class);
155              XjWarning(errtext);
156            }
157        }
158    }
159}
Note: See TracBrowser for help on using the repository browser.