- word t2, t4, t5;
- bool wascompactified, found;
-
- if (app >= MAXAPPT) errsignal(RTEMEMOV);
- wascompactified = FALSE;
-
- if( compactify_allowed && thisp->force_compactification ){
- compactify();
- thisp->force_compactification=FALSE;
- wascompactified=TRUE;
- }
-
- if (thisp->freeitem != 0) /* reserve dictionary item */
- {
- *ah = thisp->freeitem;
- thisp->freeitem = M[ *ah ];
- }
- else
- {
- *ah = thisp->lastitem-2;
- if (*ah <= thisp->lastused + space) /* cannot take free item */
- {
- if( compactify_allowed )
- if( !wascompactified ) compactify(),wascompactified=TRUE;
- else ;
- else
- thisp->force_compactification=TRUE;
- *ah = thisp->lastitem-2;
- if (*ah <= thisp->lastused) errsignal(RTEMEMOV);
- }
-
- thisp->lastitem = *ah;
- M[ *ah+1 ] = 0; /* clear mark */
- } /* now we have a free dict. item */
-
-
- if (app == 2 && thisp->headk2 != 0) /* special case app=2 */
- {
- *am = thisp->headk2;
- thisp->headk2 = M[ *am+SHORTLINK ];
- }
- else
- {
- word t1 = thisp->headk;
- found = FALSE;
- t4 = 0;
- while (t1 != thisp->lower && !found)
- {
- t2 = M[ t1 ];
- if (t2 == app) found = TRUE;
- else
- if (t2-app >= 2) found = TRUE;
- else
- {
- t4 = t1;
- t1 = M[ t1+LONGLINK ];
- }
- }
- if( found ) {
- t5 = M[ t1+SHORTLINK ];
- if (t5 != 0) M[ t5+LONGLINK ] = M[ t1+LONGLINK ];
- else t5 = M[ t1+LONGLINK ];
- if (t4 == 0) thisp->headk = t5; else M[ t4+LONGLINK ] = t5;
- *am = t1;
- if (t2 > app) /* at least two extra words */
- {
- t5 = t1+app;
- M[ t5 ] = t2-app;
- sinsert(t5);
- }
- }
- else
- if ( thisp->lastitem - thisp->lastused > app + space )
- {
- *am = thisp->lastused+1;
- thisp->lastused += app;
- }
- else
- {
- M[ *ah ] = thisp->freeitem; /* return dictionary item */
- thisp->freeitem = *ah;
- if( compactify_allowed )
- if( !wascompactified ) compactify();
- else ;
- else
- thisp->force_compactification=TRUE;
- *ah = thisp->lastitem-2; /* reserve dictionary item */
- thisp->lastitem = *ah;
- M[ *ah+1 ] = 0; /* clear mark */
- if ( thisp->lastitem - thisp->lastused > app ) {
- *am = thisp->lastused+1;
- thisp->lastused += app;
- }
- else
- errsignal(RTEMEMOV);
- }
- }
-
- M[ *am ] = app;
- for (t2 = *am+1; t2 < *am+app; t2++ ) M[ t2 ] = 0;
- M[ *ah ] = *am;