cfad47cfa3/t2compiler/tads2/voccomp.c

4b825dc642cb6eb9a060e54bf8d69288fbee4904cfad47cfa334b206c65f22086bcc5d63e6f70944
1
#ifdef RCSID
2
static char RCSid[] =
3
"$Header: d:/cvsroot/tads/TADS2/VOCCOMP.C,v 1.2 1999/05/17 02:52:13 MJRoberts Exp $";
4
#endif
5
6
/* 
7
 *   Copyright (c) 1992, 2002 Michael J. Roberts.  All Rights Reserved.
8
 *   
9
 *   Please see the accompanying license file, LICENSE.TXT, for information
10
 *   on using and copying this software.  
11
 */
12
/*
13
Name
14
  voccomp.c - vocabulary routines not used in runtime
15
Function
16
  some extra vocabulary routines not needed in runtime
17
Notes
18
  removed from base voc.c to save space in runtime
19
Modified
20
  12/18/92 MJRoberts     - creation
21
*/
22
23
#include "os.h"
24
#include "voc.h"
25
26
/* delete all inherited vocabulary records */
27
void vocdelinh(voccxdef *ctx)
28
{
29
    int       i;
30
    vocdef   *v;
31
    vocdef   *prv;
32
    vocdef   *nxt;
33
    vocdef  **vp;
34
    vocwdef  *vw;
35
    vocwdef  *prvw;
36
    vocwdef  *nxtw;
37
    uint      idx;
38
    uint      nxtidx;
39
    int       deleted_vocdef;
40
    
41
    /* go through each hash value looking for matching words */
42
    for (i = VOCHASHSIZ, vp = ctx->voccxhsh ; i ; ++vp, --i)
43
    {
44
        /* go through all words in this hash chain */
45
        for (prv = (vocdef *)0, v = *vp ; v ; v = nxt)
46
        {
47
            nxt = v->vocnxt;
48
            deleted_vocdef = FALSE;
49
50
            /* go through each vocwdef relation in the word's list */
51
            for (prvw = 0, idx = v->vocwlst, vw = vocwget(ctx, idx) ; vw ;
52
                 vw = nxtw, idx = nxtidx)
53
            {
54
                /* remember the next item in the vocwdef list */
55
                nxtidx = vw->vocwnxt;
56
                nxtw = vocwget(ctx, nxtidx);
57
58
                /* delete word if it's inherited */
59
                if (vw->vocwflg & VOCFINH)
60
                {
61
                    /* unlink this vocwdef from the vocdef's list */
62
                    if (prvw)
63
                        prvw->vocwnxt = vw->vocwnxt;
64
                    else
65
                        v->vocwlst = vw->vocwnxt;
66
67
                    /* link the vocwdef into the vocwdef free list */
68
                    vw->vocwnxt = ctx->voccxwfre;
69
                    ctx->voccxwfre = idx;
70
71
                    /*
72
                     *   if there's nothing left in the vocdef's list,
73
                     *   delete the vocdef as well 
74
                     */
75
                    if (v->vocwlst == VOCCXW_NONE)
76
                    {
77
                        /* unlink from hash chain */
78
                        if (prv) prv->vocnxt = v->vocnxt;
79
                        else *vp = v->vocnxt;
80
                        
81
                        /* link into free chain */
82
                        v->vocnxt = ctx->voccxfre;
83
                        ctx->voccxfre = v;
84
85
                        /* note that it's been deleted */
86
                        deleted_vocdef = TRUE;
87
                    }
88
                }
89
                else
90
                    prvw = vw;  /* this one is still in list - it's now prv */
91
            }
92
93
            /* if we didn't delete this vocdef, advance prv onto it */
94
            if (!deleted_vocdef)
95
                prv = v;
96
        }
97
    }
98
}
99
100
/* renumber an object (used with 'modify') */
101
void vociren(voccxdef *ctx, objnum oldnum, objnum newnum)
102
{
103
    int       i;
104
    vocdef   *v;
105
    vocdef  **vp;
106
    vocwdef  *vw;
107
108
109
    /* make sure we have a page table entry for the original object */
110
    vocialo(ctx, newnum);
111
112
    /* move the old object's inheritance record to the new slot */
113
    vocinh(ctx, newnum) = vocinh(ctx, oldnum);
114
    vocinh(ctx, oldnum) = 0;
115
116
    /* make the old object an honorary class object */
117
    vocinh(ctx, newnum)->vociflg |= VOCIFCLASS;
118
119
    /* 
120
     *   Renumber any vocabulary associated with the old object to the new
121
     *   object.
122
     */
123
    for (i = VOCHASHSIZ, vp = ctx->voccxhsh ; i != 0 ; ++vp, --i)
124
    {
125
        /* go through all words in this hash chain */
126
        for (v = *vp ; v != 0 ; v = v->vocnxt)
127
        {
128
            /* go through all vocwdef's defined for this word */
129
            for (vw = vocwget(ctx, v->vocwlst) ; vw ;
130
                 vw = vocwget(ctx, vw->vocwnxt))
131
            {
132
                /* 
133
                 *   renumber this word and mark it as being associated
134
                 *   with a class if it's associated with the original
135
                 *   object 
136
                 */
137
                if (vw->vocwobj == oldnum)
138
                {
139
                    vw->vocwobj = newnum;
140
                    vw->vocwflg |= VOCFCLASS;
141
                }
142
            }
143
        }
144
    }
145
}
146