[12242] | 1 | /* |
---|
[12350] | 2 | * $Id: Tree.c,v 1.2 1999-01-22 23:17:03 ghudson Exp $ |
---|
[12242] | 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)) |
---|
| 12 | static char *rcsid = |
---|
[12350] | 13 | "$Id: Tree.c,v 1.2 1999-01-22 23:17:03 ghudson Exp $"; |
---|
[12242] | 14 | #endif |
---|
| 15 | |
---|
| 16 | #include "mit-copyright.h" |
---|
| 17 | #include <stdio.h> |
---|
| 18 | #include <ctype.h> |
---|
| 19 | #include "Jets.h" |
---|
| 20 | #include "Tree.h" |
---|
| 21 | |
---|
| 22 | #define offset(field) XjOffset(TreeJet,field) |
---|
| 23 | |
---|
| 24 | static XjResource resources[] = { |
---|
| 25 | { XjNx, XjCX, XjRInt, sizeof(int), |
---|
| 26 | offset(core.x), XjRString, XjInheritValue }, |
---|
| 27 | { XjNy, XjCY, XjRInt, sizeof(int), |
---|
| 28 | offset(core.y), XjRString, XjInheritValue }, |
---|
| 29 | { XjNwidth, XjCWidth, XjRInt, sizeof(int), |
---|
| 30 | offset(core.width), XjRString, XjInheritValue }, |
---|
| 31 | { XjNheight, XjCHeight, XjRInt, sizeof(int), |
---|
| 32 | offset(core.height), XjRString, XjInheritValue }, |
---|
| 33 | { XjNtree, XjCTree, XjRString, sizeof(char *), |
---|
| 34 | offset(tree.tree), XjRString, "" } |
---|
| 35 | }; |
---|
| 36 | |
---|
| 37 | #undef offset |
---|
| 38 | |
---|
| 39 | static void initialize(); |
---|
| 40 | |
---|
| 41 | TreeClassRec treeClassRec = { |
---|
| 42 | { |
---|
| 43 | /* class name */ "Tree", |
---|
| 44 | /* jet size */ sizeof(TreeRec), |
---|
| 45 | /* classInitialize */ NULL, |
---|
| 46 | /* classInitialized? */ 1, |
---|
| 47 | /* initialize */ initialize, |
---|
| 48 | /* prerealize */ NULL, |
---|
| 49 | /* realize */ NULL, |
---|
| 50 | /* event */ NULL, |
---|
| 51 | /* expose */ NULL, |
---|
| 52 | /* querySize */ NULL, |
---|
| 53 | /* move */ NULL, |
---|
| 54 | /* resize */ NULL, |
---|
| 55 | /* destroy */ NULL, |
---|
| 56 | /* resources */ resources, |
---|
| 57 | /* number of 'em */ XjNumber(resources) |
---|
| 58 | } |
---|
| 59 | }; |
---|
| 60 | |
---|
| 61 | JetClass treeJetClass = (JetClass)&treeClassRec; |
---|
| 62 | |
---|
| 63 | extern int numJetClasses; |
---|
| 64 | extern JetClass *jetClasses[]; |
---|
| 65 | |
---|
| 66 | static void initialize(me) |
---|
| 67 | TreeJet me; |
---|
| 68 | { |
---|
| 69 | int index, i; |
---|
| 70 | char *parse, class[50], name[50]; |
---|
| 71 | Jet parent, last; |
---|
| 72 | |
---|
| 73 | if (strlen(me->tree.tree) == 0) |
---|
| 74 | { |
---|
| 75 | char errtext[100]; |
---|
| 76 | |
---|
| 77 | sprintf(errtext, "empty tree: %s", me->core.name); |
---|
| 78 | XjWarning(errtext); |
---|
| 79 | return; |
---|
| 80 | } |
---|
| 81 | |
---|
| 82 | last = (Jet)me; |
---|
| 83 | parent = XjParent(me); |
---|
| 84 | parse = me->tree.tree; |
---|
| 85 | |
---|
| 86 | while (*parse != '\0') |
---|
| 87 | { |
---|
| 88 | while (isspace(*parse)) |
---|
| 89 | parse++; |
---|
| 90 | |
---|
| 91 | switch(*parse) |
---|
| 92 | { |
---|
| 93 | case '{': |
---|
| 94 | if (last == NULL) |
---|
| 95 | XjWarning("no consecutive {'s allowed; ignored"); |
---|
| 96 | else |
---|
| 97 | { |
---|
| 98 | parent = last; |
---|
| 99 | last = NULL; |
---|
| 100 | } |
---|
| 101 | parse++; |
---|
| 102 | break; |
---|
| 103 | |
---|
| 104 | case '}': |
---|
| 105 | last = parent; |
---|
| 106 | parent = XjParent(parent); |
---|
| 107 | if (last == (Jet)me) |
---|
| 108 | return; |
---|
| 109 | parse++; |
---|
| 110 | break; |
---|
| 111 | |
---|
| 112 | default: |
---|
| 113 | index = 0; |
---|
| 114 | while (isalnum(*parse)) |
---|
| 115 | class[index++] = *parse++; |
---|
| 116 | class[index] = '\0'; |
---|
| 117 | |
---|
| 118 | while (isspace(*parse)) |
---|
| 119 | parse++; |
---|
| 120 | |
---|
| 121 | index = 0; |
---|
| 122 | while (isalnum(*parse)) |
---|
| 123 | name[index++] = *parse++; |
---|
| 124 | name[index] = '\0'; |
---|
| 125 | |
---|
| 126 | if (*parse == ';') |
---|
| 127 | parse++; |
---|
| 128 | |
---|
| 129 | #ifdef DEBUG |
---|
| 130 | fprintf(stdout, "create a %s named %s, child of %s\n", |
---|
| 131 | class, name, parent->core.name); |
---|
| 132 | #endif |
---|
| 133 | |
---|
| 134 | if (strcasecmp("null", class) != 0) |
---|
| 135 | { |
---|
| 136 | for (i = 0; i < numJetClasses; i++) |
---|
| 137 | if (!strcmp(class, (*jetClasses[i])->core_class.className)) |
---|
| 138 | { |
---|
| 139 | last = XjVaCreateJet(name, |
---|
| 140 | (*jetClasses[i]), |
---|
| 141 | parent, |
---|
| 142 | NULL, NULL); |
---|
| 143 | break; |
---|
| 144 | } |
---|
| 145 | } |
---|
| 146 | else |
---|
| 147 | i = 0; |
---|
| 148 | |
---|
| 149 | if (i == numJetClasses) |
---|
| 150 | { |
---|
| 151 | char errtext[100]; |
---|
| 152 | |
---|
| 153 | sprintf(errtext, "unknown class: %s", class); |
---|
| 154 | XjWarning(errtext); |
---|
| 155 | } |
---|
| 156 | } |
---|
| 157 | } |
---|
| 158 | } |
---|