00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074 #include <memory.h>
00075 #include "udanax.h"
00076
00077
00078
00086 static bool
00087 fillupcbcseq(
00088 typecbc *ptr,
00089 Tumbler *crumboundary,
00090 typegranbottomcruminfo *info)
00091 {
00092 char temp[GRANTEXTLENGTH];
00093
00095
00096
00097 int crumlength = ptr->cinfo.granstuff.textstuff.textlength;
00098 int remainingroom = GRANTEXTLENGTH - crumlength;
00099 int textlength = info->granstuff.textstuff.textlength;
00100
00101 if (remainingroom > textlength) {
00102 movmem(&info->granstuff.textstuff.textstring, (char *)(&(ptr->cinfo.granstuff.textstuff)) + crumlength, textlength);
00103 ptr->cinfo.granstuff.textstuff.textlength = crumlength + textlength;
00104 tumblerincrement(crumboundary, 0, textlength, crumboundary);
00105 return false;
00106
00107 } else {
00108 movmem(&info->granstuff.textstuff.textstring, (char *)(&(ptr->cinfo.granstuff.textstuff)) + crumlength,
00109 remainingroom);
00110 ptr->cinfo.granstuff.textstuff.textlength = GRANTEXTLENGTH;
00111 tumblerincrement(crumboundary, 0, remainingroom, crumboundary);
00112 }
00113
00114
00115 info->granstuff.textstuff.textlength -= remainingroom;
00116
00117 movmem(&info->granstuff.textstuff.textstring[remainingroom], temp, info->granstuff.textstuff.textlength);
00118 clear(info->granstuff.textstuff.textstring, GRANTEXTLENGTH);
00119 movmem(temp, info->granstuff.textstuff.textstring, info->granstuff.textstuff.textlength);
00120
00121 return true;
00122 }
00123
00131 void
00132 insertseq(
00133 typecuc *fullcrumptr,
00134 Tumbler *address,
00135 typegranbottomcruminfo *info)
00136 {
00137 typedsp reach;
00138
00139 Tumbler nextaddress;
00140 movetumbler(address, &nextaddress);
00141
00142 CrumContext *context = retrievecrums(fullcrumptr, address, WIDTH);
00143 typecbc *ptr = context->corecrum;
00144
00145 typedsp offset;
00146 clear(&offset, sizeof(offset));
00147 movewisp(&context->totaloffset, &offset);
00148
00149 crumcontextfree(context);
00150
00151 if ( info->infotype == GRANTEXT && ptr->cinfo.infotype == GRANTEXT && ptr->cinfo.granstuff.textstuff.textlength < GRANTEXTLENGTH) {
00152 if (!fillupcbcseq(ptr, &nextaddress, info)) {
00153 ivemodified((typecorecrum *) ptr);
00154 return;
00155 }
00156 }
00157 reserve((typecorecrum *) ptr);
00158
00159 typecorecrum *newcc = createcrum(0, (int) ptr->cenftype);
00160 reserve(newcc);
00161
00162 adopt(newcc, RIGHTBRO, (typecorecrum *) ptr);
00163 ivemodified(newcc);
00164
00165 bool splitsomething = splitcrumupwards(findfather(newcc));
00166
00167 if (info->infotype == GRANORGL)
00168 info->granstuff.orglstuff.orglptr->leftbroorfather = newcc;
00169
00170 moveinfo((typebottomcruminfo *) info, (typebottomcruminfo *) &((typecbc *) newcc)->cinfo);
00171 if (iszerotumbler(&ptr->cwid.dsas[WIDTH])) {
00172 tumblerclear(&newcc->cwid.dsas[WIDTH]);
00173 tumblersub(&nextaddress, &offset.dsas[WIDTH], &ptr->cwid.dsas[WIDTH]);
00174 } else {
00175 dspadd(&offset, &ptr->cwid, &reach, GRAN);
00176 tumblersub(&reach.dsas[WIDTH], &nextaddress, &newcc->cwid.dsas[WIDTH]);
00177 tumblersub(&nextaddress, &offset.dsas[WIDTH], &ptr->cwid.dsas[WIDTH]);
00178 }
00179
00180 ivemodified((typecorecrum *) ptr);
00181 setwispupwards(findfather((typecorecrum *) ptr), 0);
00182 setwispupwards(findfather((typecorecrum *) newcc), 1);
00183 splitsomething |= splitcrumupwards(findfather((typecorecrum *) ptr));
00184 rejuvinate((typecorecrum *) ptr);
00185 rejuvinate(newcc);
00186
00187 if (splitsomething)
00188 recombine(fullcrumptr);
00189 }